change how ticks works
This commit is contained in:
parent
71b6fb0590
commit
9f27ed75d5
|
@ -72,7 +72,7 @@ void Engine::run()
|
|||
|
||||
// update
|
||||
ticks = Platform::getTicks();
|
||||
update(ticks - lastFrameTicks);
|
||||
update(ticks, ticks - lastFrameTicks);
|
||||
lastFrameTicks = ticks;
|
||||
|
||||
// render only when visible
|
||||
|
@ -111,10 +111,10 @@ void Engine::render()
|
|||
g_graphics.endRender();
|
||||
}
|
||||
|
||||
void Engine::update(int elapsedTicks)
|
||||
void Engine::update(int ticks, int elapsedTicks)
|
||||
{
|
||||
if(m_currentState)
|
||||
m_currentState->update(elapsedTicks);
|
||||
m_currentState->update(ticks, elapsedTicks);
|
||||
}
|
||||
|
||||
void Engine::onClose()
|
||||
|
|
|
@ -63,7 +63,7 @@ private:
|
|||
/// Called to render every frame
|
||||
void render();
|
||||
/// Called between renders
|
||||
void update(int elapsedTicks);
|
||||
void update(int ticks, int elapsedTicks);
|
||||
|
||||
bool m_stopping;
|
||||
bool m_running;
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual void onInputEvent(InputEvent *event) = 0;
|
||||
|
||||
virtual void render() = 0;
|
||||
virtual void update(int elapsedTicks) = 0;
|
||||
virtual void update(int ticks, int elapsedTicks) = 0;
|
||||
};
|
||||
|
||||
#endif // GAMESTATE_H
|
||||
|
|
|
@ -35,8 +35,8 @@ namespace Platform
|
|||
/// Poll platform input/window events
|
||||
void poll();
|
||||
|
||||
/// Get current time in milliseconds since first frame render
|
||||
unsigned long getTicks();
|
||||
/// Get current time in milliseconds since init
|
||||
int getTicks();
|
||||
/// Sleep in current thread
|
||||
void sleep(unsigned long miliseconds);
|
||||
|
||||
|
|
|
@ -88,9 +88,13 @@ void Platform::poll()
|
|||
}
|
||||
}
|
||||
|
||||
unsigned long Platform::getTicks()
|
||||
int Platform::getTicks()
|
||||
{
|
||||
return GetTickCount();
|
||||
static unsigned long firstTick = 0;
|
||||
if(!firstTick)
|
||||
firstTick = GetTickCount64();
|
||||
|
||||
return (uint32_t)(GetTickCount64() - firstTick);
|
||||
}
|
||||
|
||||
void Platform::sleep(unsigned long miliseconds)
|
||||
|
|
|
@ -255,6 +255,9 @@ void Platform::init(const char *appName)
|
|||
x11.atomWindowState = XInternAtom(x11.display, "_NET_WM_STATE", False);
|
||||
x11.atomWindowMaximizedVert = XInternAtom(x11.display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
|
||||
x11.atomWindowMaximizedHorz = XInternAtom(x11.display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
|
||||
|
||||
// force first tick
|
||||
Platform::getTicks();
|
||||
}
|
||||
|
||||
void Platform::terminate()
|
||||
|
@ -449,7 +452,7 @@ void Platform::poll()
|
|||
}
|
||||
}
|
||||
|
||||
unsigned long Platform::getTicks()
|
||||
int Platform::getTicks()
|
||||
{
|
||||
static timeval tv;
|
||||
static unsigned long firstTick = 0;
|
||||
|
|
|
@ -79,7 +79,7 @@ void MenuState::render()
|
|||
g_graphics.drawTexturedRect(Rect(0, 0, screenSize), m_background.get(), texCoords);
|
||||
}
|
||||
|
||||
void MenuState::update(int elapsedTicks)
|
||||
void MenuState::update(int ticks, int elapsedTicks)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
void onInputEvent(InputEvent *event);
|
||||
|
||||
void render();
|
||||
void update(int elapsedTicks);
|
||||
void update(int ticks, int elapsedTicks);
|
||||
|
||||
private:
|
||||
TexturePtr m_background;
|
||||
|
|
Loading…
Reference in New Issue