zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Timer.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <zeni_core.h>
19 
20 #if defined(_DEBUG) && defined(_WINDOWS)
21 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
22 #define new DEBUG_NEW
23 #endif
24 
25 #include <Zeni/Chronometer.hxx>
26 #include <Zeni/Singleton.hxx>
27 
28 namespace Zeni {
29 
31  : m_ticks(ticks)
32  {
33  }
34 
36  : m_ticks(get_Timer().get_ticks())
37  {
38  }
39 
40  void Timer::update() {
41 #ifdef ANDROID
42  Timer_HQ &tr = get_Timer_HQ();
43  m_ticks = 1000lu * tr.get_ticks() / tr.get_ticks_per_second();
44 #else
45  m_ticks = SDL_GetTicks();
46 #endif
47  }
48 
49  template class Singleton<Timer>;
50  template class Chronometer<Time>;
51 
52  Timer * Timer::create() {
53  return new Timer;
54  }
55 
56  Singleton<Timer>::Uninit Timer::g_uninit;
57  Singleton<Timer>::Reinit Timer::g_reinit;
58 
59  Timer::Timer() {
60  Core::remove_post_reinit(&g_reinit);
61 
62  // Ensure Core is initialized
63  Core &cr = get_Core();
64 
65  cr.lend_pre_uninit(&g_uninit);
66  cr.lend_post_reinit(&g_reinit);
67  }
68 
69  Timer::~Timer() {
70  Core::remove_pre_uninit(&g_uninit);
71  }
72 
74  return Timer::get();
75  }
76 
77 }
A High Quality Timer Singleton.
Definition: Timer_HQ.h:115
Timer_HQ & get_Timer_HQ()
Get access to the singleton.
Definition: Timer_HQ.cpp:123
static void remove_post_reinit(Event::Handler *const &handler)
Time()
Initialize to the current time.
Definition: Timer.cpp:35
HQ_Tick_Type get_ticks()
Get the number of ticks passed since instantiation.
Definition: Timer_HQ.hxx:51
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
Definition: SDL_systimer.c:44
Timer & get_Timer()
Get access to the singleton.
Definition: Timer.cpp:73
static void remove_pre_uninit(Event::Handler *const &handler)
A Timer Singleton.
Definition: Timer.h:97
static Timer & get()
size_t Tick_Type
Definition: Timer.h:65
Core & get_Core()
Get access to the singleton.
Definition: Core.cpp:71
HQ_Tick_Type get_ticks_per_second()
Get the number of ticks per second.
Definition: Timer_HQ.hxx:60