mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
text edit improvments (not finished)
This commit is contained in:
@@ -24,14 +24,15 @@
|
||||
|
||||
#include "dispatcher.h"
|
||||
#include "platform.h"
|
||||
#include "engine.h"
|
||||
|
||||
Dispatcher g_dispatcher;
|
||||
|
||||
void Dispatcher::poll(int ticks)
|
||||
void Dispatcher::poll()
|
||||
{
|
||||
while(!m_taskList.empty()) {
|
||||
Task *task = m_taskList.top();
|
||||
if(ticks < task->ticks)
|
||||
if(g_engine.getLastFrameTicks() < task->ticks)
|
||||
break;
|
||||
|
||||
task->callback();
|
||||
|
@@ -49,7 +49,7 @@ public:
|
||||
Dispatcher() { }
|
||||
|
||||
/// Execute scheduled events
|
||||
void poll(int ticks);
|
||||
void poll();
|
||||
|
||||
/// Add an event
|
||||
void addTask(const Callback& callback);
|
||||
|
@@ -53,8 +53,8 @@ void Engine::terminate()
|
||||
void Engine::run()
|
||||
{
|
||||
Font *defaultFont = g_fonts.getDefaultFont();
|
||||
int ticks = Platform::getTicks();
|
||||
int lastFpsTicks = ticks;
|
||||
m_lastFrameTicks = Platform::getTicks();
|
||||
int lastFpsTicks = m_lastFrameTicks;
|
||||
int frameCount = 0;
|
||||
int fps = 0;
|
||||
m_running = true;
|
||||
@@ -66,18 +66,18 @@ void Engine::run()
|
||||
// poll network events
|
||||
g_connections.poll();
|
||||
|
||||
ticks = Platform::getTicks();
|
||||
m_lastFrameTicks = Platform::getTicks();
|
||||
|
||||
// poll diaptcher tasks
|
||||
g_dispatcher.poll(ticks);
|
||||
g_dispatcher.poll();
|
||||
|
||||
// render only when visible
|
||||
if(Platform::isWindowVisible()) {
|
||||
// calculate and fps
|
||||
if(m_calculateFps) {
|
||||
frameCount++;
|
||||
if(ticks - lastFpsTicks >= 1000) {
|
||||
lastFpsTicks = ticks;
|
||||
if(m_lastFrameTicks - lastFpsTicks >= 1000) {
|
||||
lastFpsTicks = m_lastFrameTicks;
|
||||
fps = frameCount;
|
||||
frameCount = 0;
|
||||
}
|
||||
|
@@ -61,6 +61,8 @@ public:
|
||||
/// Enable FPS counter on screen
|
||||
void enableFpsCounter(bool enable = true) { m_calculateFps = enable; };
|
||||
|
||||
int getLastFrameTicks() const { return m_lastFrameTicks; }
|
||||
|
||||
private:
|
||||
/// Called to render every frame
|
||||
void render();
|
||||
@@ -70,6 +72,7 @@ private:
|
||||
bool m_calculateFps;
|
||||
|
||||
GameState *m_currentState;
|
||||
int m_lastFrameTicks;
|
||||
};
|
||||
|
||||
extern Engine g_engine;
|
||||
|
Reference in New Issue
Block a user