change how ticks works

This commit is contained in:
Eduardo Bart 2011-03-20 20:15:17 -03:00
parent 71b6fb0590
commit 9f27ed75d5
8 changed files with 19 additions and 12 deletions

View File

@ -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()

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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)

View File

@ -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;

View File

@ -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)
{
}

View File

@ -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;