Browse Source

change how ticks works

Eduardo Bart 10 years ago
parent
commit
9f27ed75d5

+ 3
- 3
src/framework/engine.cpp View File

@@ -72,7 +72,7 @@ void Engine::run()
72 72
 
73 73
         // update
74 74
         ticks = Platform::getTicks();
75
-        update(ticks - lastFrameTicks);
75
+        update(ticks, ticks - lastFrameTicks);
76 76
         lastFrameTicks = ticks;
77 77
 
78 78
         // render only when visible
@@ -111,10 +111,10 @@ void Engine::render()
111 111
     g_graphics.endRender();
112 112
 }
113 113
 
114
-void Engine::update(int elapsedTicks)
114
+void Engine::update(int ticks, int elapsedTicks)
115 115
 {
116 116
     if(m_currentState)
117
-        m_currentState->update(elapsedTicks);
117
+        m_currentState->update(ticks, elapsedTicks);
118 118
 }
119 119
 
120 120
 void Engine::onClose()

+ 1
- 1
src/framework/engine.h View File

@@ -63,7 +63,7 @@ private:
63 63
     /// Called to render every frame
64 64
     void render();
65 65
     /// Called between renders
66
-    void update(int elapsedTicks);
66
+    void update(int ticks, int elapsedTicks);
67 67
 
68 68
     bool m_stopping;
69 69
     bool m_running;

+ 1
- 1
src/framework/gamestate.h View File

@@ -40,7 +40,7 @@ public:
40 40
     virtual void onInputEvent(InputEvent *event) = 0;
41 41
 
42 42
     virtual void render() = 0;
43
-    virtual void update(int elapsedTicks) = 0;
43
+    virtual void update(int ticks, int elapsedTicks) = 0;
44 44
 };
45 45
 
46 46
 #endif // GAMESTATE_H

+ 2
- 2
src/framework/platform.h View File

@@ -35,8 +35,8 @@ namespace Platform
35 35
     /// Poll platform input/window events
36 36
     void poll();
37 37
 
38
-    /// Get current time in milliseconds since first frame render
39
-    unsigned long getTicks();
38
+    /// Get current time in milliseconds since init
39
+    int getTicks();
40 40
     /// Sleep in current thread
41 41
     void sleep(unsigned long miliseconds);
42 42
 

+ 6
- 2
src/framework/win32platform.cpp View File

@@ -88,9 +88,13 @@ void Platform::poll()
88 88
     }
89 89
 }
90 90
 
91
-unsigned long Platform::getTicks()
91
+int Platform::getTicks()
92 92
 {
93
-    return GetTickCount();
93
+    static unsigned long firstTick = 0;
94
+    if(!firstTick)
95
+        firstTick = GetTickCount64();
96
+    
97
+    return (uint32_t)(GetTickCount64() - firstTick);
94 98
 }
95 99
 
96 100
 void Platform::sleep(unsigned long miliseconds)

+ 4
- 1
src/framework/x11platform.cpp View File

@@ -255,6 +255,9 @@ void Platform::init(const char *appName)
255 255
     x11.atomWindowState = XInternAtom(x11.display, "_NET_WM_STATE", False);
256 256
     x11.atomWindowMaximizedVert = XInternAtom(x11.display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
257 257
     x11.atomWindowMaximizedHorz = XInternAtom(x11.display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
258
+
259
+    // force first tick
260
+    Platform::getTicks();
258 261
 }
259 262
 
260 263
 void Platform::terminate()
@@ -449,7 +452,7 @@ void Platform::poll()
449 452
     }
450 453
 }
451 454
 
452
-unsigned long Platform::getTicks()
455
+int Platform::getTicks()
453 456
 {
454 457
     static timeval tv;
455 458
     static unsigned long firstTick = 0;

+ 1
- 1
src/menustate.cpp View File

@@ -79,7 +79,7 @@ void MenuState::render()
79 79
     g_graphics.drawTexturedRect(Rect(0, 0, screenSize), m_background.get(), texCoords);
80 80
 }
81 81
 
82
-void MenuState::update(int elapsedTicks)
82
+void MenuState::update(int ticks, int elapsedTicks)
83 83
 {
84 84
 
85 85
 }

+ 1
- 1
src/menustate.h View File

@@ -42,7 +42,7 @@ public:
42 42
     void onInputEvent(InputEvent *event);
43 43
 
44 44
     void render();
45
-    void update(int elapsedTicks);
45
+    void update(int ticks, int elapsedTicks);
46 46
 
47 47
 private:
48 48
     TexturePtr m_background;

Loading…
Cancel
Save