text edit improvments (not finished)

This commit is contained in:
Eduardo Bart
2011-04-14 23:13:53 -03:00
parent e01bd17510
commit f1475c0569
16 changed files with 375 additions and 226 deletions

View File

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

View File

@@ -49,7 +49,7 @@ public:
Dispatcher() { }
/// Execute scheduled events
void poll(int ticks);
void poll();
/// Add an event
void addTask(const Callback& callback);

View File

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

View File

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