in each class that uses it.legacy
@@ -22,7 +22,6 @@ class DebugFpsData | |||||
private: | private: | ||||
int fontid; | int fontid; | ||||
int frame; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -34,7 +33,6 @@ DebugFps::DebugFps() | |||||
data = new DebugFpsData(); | data = new DebugFpsData(); | ||||
data->fontid = Forge::Register("gfx/font/ascii.png"); | data->fontid = Forge::Register("gfx/font/ascii.png"); | ||||
data->frame = 0; | |||||
} | } | ||||
Entity::Group DebugFps::GetGroup() | Entity::Group DebugFps::GetGroup() | ||||
@@ -46,13 +44,12 @@ void DebugFps::TickDraw(float deltams) | |||||
{ | { | ||||
Entity::TickDraw(deltams); | Entity::TickDraw(deltams); | ||||
data->frame++; | |||||
char buf[1024]; | char buf[1024]; | ||||
Font *font = Forge::GetFont(data->fontid); | Font *font = Forge::GetFont(data->fontid); | ||||
sprintf(buf, "%2.2f fps (%i)", | sprintf(buf, "%2.2f fps (%i)", | ||||
1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), data->frame); | |||||
1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), | |||||
Ticker::GetFrameNum()); | |||||
font->PrintBold(10, 10, buf); | font->PrintBold(10, 10, buf); | ||||
sprintf(buf, "Game % 7.2f % 7.2f", | sprintf(buf, "Game % 7.2f % 7.2f", | ||||
@@ -118,9 +118,9 @@ gboolean GlMapView::Destroy() | |||||
return TRUE; | return TRUE; | ||||
} | } | ||||
gboolean GlMapView::Draw(GdkEventExpose *event) | |||||
gboolean GlMapView::Draw(GdkEventExpose *e) | |||||
{ | { | ||||
if (event->count > 0) | |||||
if (e->count > 0) | |||||
return TRUE; | return TRUE; | ||||
/* OpenGL functions can be called only if make_current returns true */ | /* OpenGL functions can be called only if make_current returns true */ | ||||
@@ -186,19 +186,19 @@ gboolean GlMapView::MoveAdjustments(double dx, double dy) | |||||
return TRUE; | return TRUE; | ||||
} | } | ||||
gboolean GlMapView::MouseButton(GdkEventButton *event) | |||||
gboolean GlMapView::MouseButton(GdkEventButton *e) | |||||
{ | { | ||||
if (event->type == GDK_BUTTON_PRESS && event->button == 2) | |||||
if (e->type == GDK_BUTTON_PRESS && e->button == 2) | |||||
{ | { | ||||
panning = TRUE; | panning = TRUE; | ||||
xpan = event->x; | |||||
ypan = event->y; | |||||
xpan = e->x; | |||||
ypan = e->y; | |||||
GdkCursor *cursor = gdk_cursor_new(GDK_HAND1); | GdkCursor *cursor = gdk_cursor_new(GDK_HAND1); | ||||
gdk_window_set_cursor(glarea->window, cursor); | gdk_window_set_cursor(glarea->window, cursor); | ||||
gdk_cursor_unref(cursor); | gdk_cursor_unref(cursor); | ||||
return FALSE; | return FALSE; | ||||
} | } | ||||
else if (event->type == GDK_BUTTON_RELEASE && event->button == 2) | |||||
else if (e->type == GDK_BUTTON_RELEASE && e->button == 2) | |||||
{ | { | ||||
panning = FALSE; | panning = FALSE; | ||||
gdk_window_set_cursor(glarea->window, NULL); | gdk_window_set_cursor(glarea->window, NULL); | ||||
@@ -208,28 +208,28 @@ gboolean GlMapView::MouseButton(GdkEventButton *event) | |||||
return TRUE; | return TRUE; | ||||
} | } | ||||
gboolean GlMapView::MouseMotion(GdkEventMotion *event) | |||||
gboolean GlMapView::MouseMotion(GdkEventMotion *e) | |||||
{ | { | ||||
if (panning) | if (panning) | ||||
{ | { | ||||
if (event->x != xpan) | |||||
if (e->x != xpan) | |||||
{ | { | ||||
double val = gtk_adjustment_get_value(hadj); | double val = gtk_adjustment_get_value(hadj); | ||||
int map_width = mapviewer->GetWidth(); | int map_width = mapviewer->GetWidth(); | ||||
val += xpan - event->x; | |||||
xpan = event->x; | |||||
val += xpan - e->x; | |||||
xpan = e->x; | |||||
if (val + glarea->allocation.width > map_width) | if (val + glarea->allocation.width > map_width) | ||||
val = map_width - glarea->allocation.width; | val = map_width - glarea->allocation.width; | ||||
gtk_adjustment_set_value(hadj, val); | gtk_adjustment_set_value(hadj, val); | ||||
gtk_adjustment_value_changed(hadj); | gtk_adjustment_value_changed(hadj); | ||||
} | } | ||||
if (event->y != ypan) | |||||
if (e->y != ypan) | |||||
{ | { | ||||
double val = gtk_adjustment_get_value(vadj); | double val = gtk_adjustment_get_value(vadj); | ||||
int map_height = mapviewer->GetHeight(); | int map_height = mapviewer->GetHeight(); | ||||
val += ypan - event->y; | |||||
ypan = event->y; | |||||
val += ypan - e->y; | |||||
ypan = e->y; | |||||
if (val + glarea->allocation.height > map_height) | if (val + glarea->allocation.height > map_height) | ||||
val = map_height - glarea->allocation.height; | val = map_height - glarea->allocation.height; | ||||
gtk_adjustment_set_value(vadj, val); | gtk_adjustment_set_value(vadj, val); | ||||
@@ -240,9 +240,9 @@ gboolean GlMapView::MouseMotion(GdkEventMotion *event) | |||||
return TRUE; | return TRUE; | ||||
} | } | ||||
gboolean GlMapView::KeyPress(GdkEventKey *event) | |||||
gboolean GlMapView::KeyPress(GdkEventKey *e) | |||||
{ | { | ||||
switch (event->keyval) | |||||
switch (e->keyval) | |||||
{ | { | ||||
case GDK_Up: MoveAdjustments( 0.0, -10.0); break; | case GDK_Up: MoveAdjustments( 0.0, -10.0); break; | ||||
case GDK_Down: MoveAdjustments( 0.0, 10.0); break; | case GDK_Down: MoveAdjustments( 0.0, 10.0); break; | ||||
@@ -272,39 +272,39 @@ gboolean GlMapView::DestroySignal(GtkWidget *w, GlMapView *that) | |||||
return that->Destroy(); | return that->Destroy(); | ||||
} | } | ||||
gboolean GlMapView::DrawSignal(GtkWidget *w, GdkEventExpose *event, | |||||
gboolean GlMapView::DrawSignal(GtkWidget *w, GdkEventExpose *e, | |||||
GlMapView *that) | GlMapView *that) | ||||
{ | { | ||||
(void)w; | (void)w; | ||||
return that->Draw(event); | |||||
return that->Draw(e); | |||||
} | } | ||||
gboolean GlMapView::ReshapeSignal(GtkWidget *w, GdkEventConfigure *event, | |||||
gboolean GlMapView::ReshapeSignal(GtkWidget *w, GdkEventConfigure *e, | |||||
GlMapView *that) | GlMapView *that) | ||||
{ | { | ||||
(void)w; | (void)w; | ||||
(void)event; | |||||
(void)e; | |||||
return that->Setup(); | return that->Setup(); | ||||
} | } | ||||
gboolean GlMapView::MouseButtonSignal(GtkWidget *w, GdkEventButton *event, | |||||
gboolean GlMapView::MouseButtonSignal(GtkWidget *w, GdkEventButton *e, | |||||
GlMapView *that) | GlMapView *that) | ||||
{ | { | ||||
(void)w; | (void)w; | ||||
return that->MouseButton(event); | |||||
return that->MouseButton(e); | |||||
} | } | ||||
gboolean GlMapView::MouseMotionSignal(GtkWidget *w, GdkEventMotion *event, | |||||
gboolean GlMapView::MouseMotionSignal(GtkWidget *w, GdkEventMotion *e, | |||||
GlMapView *that) | GlMapView *that) | ||||
{ | { | ||||
(void)w; | (void)w; | ||||
return that->MouseMotion(event); | |||||
return that->MouseMotion(e); | |||||
} | } | ||||
gboolean GlMapView::KeyPressSignal(GtkWidget *w, GdkEventKey *event, | |||||
gboolean GlMapView::KeyPressSignal(GtkWidget *w, GdkEventKey *e, | |||||
GlMapView *that) | GlMapView *that) | ||||
{ | { | ||||
(void)w; | (void)w; | ||||
return that->KeyPress(event); | |||||
return that->KeyPress(e); | |||||
} | } | ||||
@@ -20,26 +20,26 @@ private: | |||||
gboolean IdleTick(); | gboolean IdleTick(); | ||||
gboolean Setup(); | gboolean Setup(); | ||||
gboolean Destroy(); | gboolean Destroy(); | ||||
gboolean Draw(GdkEventExpose *event); | |||||
gboolean Draw(GdkEventExpose *e); | |||||
gboolean UpdateAdjustments(); | gboolean UpdateAdjustments(); | ||||
gboolean MoveAdjustments(double dx, double dy); | gboolean MoveAdjustments(double dx, double dy); | ||||
gboolean MouseButton(GdkEventButton *event); | |||||
gboolean MouseMotion(GdkEventMotion *event); | |||||
gboolean KeyPress(GdkEventKey *event); | |||||
gboolean MouseButton(GdkEventButton *e); | |||||
gboolean MouseMotion(GdkEventMotion *e); | |||||
gboolean KeyPress(GdkEventKey *e); | |||||
/* Private signal slots */ | /* Private signal slots */ | ||||
static gboolean IdleTickSignal(GlMapView *that); | static gboolean IdleTickSignal(GlMapView *that); | ||||
static gboolean SetupSignal(GtkWidget *w, GlMapView *that); | static gboolean SetupSignal(GtkWidget *w, GlMapView *that); | ||||
static gboolean DestroySignal(GtkWidget *w, GlMapView *that); | static gboolean DestroySignal(GtkWidget *w, GlMapView *that); | ||||
static gboolean DrawSignal(GtkWidget *w, GdkEventExpose *event, | |||||
static gboolean DrawSignal(GtkWidget *w, GdkEventExpose *e, | |||||
GlMapView *that); | GlMapView *that); | ||||
static gboolean ReshapeSignal(GtkWidget *w, GdkEventConfigure *event, | |||||
static gboolean ReshapeSignal(GtkWidget *w, GdkEventConfigure *e, | |||||
GlMapView *that); | GlMapView *that); | ||||
static gboolean MouseButtonSignal(GtkWidget *w, GdkEventButton *event, | |||||
static gboolean MouseButtonSignal(GtkWidget *w, GdkEventButton *e, | |||||
GlMapView *that); | GlMapView *that); | ||||
static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *event, | |||||
static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *e, | |||||
GlMapView *that); | GlMapView *that); | ||||
static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *event, | |||||
static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *e, | |||||
GlMapView *that); | GlMapView *that); | ||||
private: | private: | ||||
@@ -21,21 +21,19 @@ static class ProfilerData | |||||
{ | { | ||||
friend class Profiler; | friend class Profiler; | ||||
static int const HISTORY = 30; | |||||
static int const HISTORY = 32; | |||||
public: | public: | ||||
ProfilerData() | ProfilerData() | ||||
{ | { | ||||
for (int i = 0; i < HISTORY; i++) | for (int i = 0; i < HISTORY; i++) | ||||
history[i] = 0.0f; | history[i] = 0.0f; | ||||
frame = 0; | |||||
avg = max = 0.0f; | avg = max = 0.0f; | ||||
} | } | ||||
private: | private: | ||||
float history[HISTORY]; | float history[HISTORY]; | ||||
Timer timer; | Timer timer; | ||||
int frame; | |||||
float avg, max; | float avg, max; | ||||
} | } | ||||
data[Profiler::STAT_COUNT]; | data[Profiler::STAT_COUNT]; | ||||
@@ -53,8 +51,7 @@ void Profiler::Stop(int id) | |||||
{ | { | ||||
float deltams = data[id].timer.GetMs(); | float deltams = data[id].timer.GetMs(); | ||||
data[id].history[data->frame % ProfilerData::HISTORY] = deltams; | |||||
data[id].frame++; | |||||
data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams; | |||||
data[id].avg = 0.0f; | data[id].avg = 0.0f; | ||||
data[id].max = 0.0f; | data[id].max = 0.0f; | ||||
@@ -23,12 +23,11 @@ static class TickerData | |||||
public: | public: | ||||
TickerData() : | TickerData() : | ||||
todo(0), | |||||
nentities(0) | |||||
todo(0), nentities(0), | |||||
frame(0), deltams(0), bias(0) | |||||
{ | { | ||||
for (int i = 0; i < Entity::GROUP_COUNT; i++) | for (int i = 0; i < Entity::GROUP_COUNT; i++) | ||||
list[i] = NULL; | list[i] = NULL; | ||||
bias = 0.0f; | |||||
} | } | ||||
~TickerData() | ~TickerData() | ||||
@@ -46,6 +45,7 @@ private: | |||||
int nentities; | int nentities; | ||||
/* Fixed framerate management */ | /* Fixed framerate management */ | ||||
int frame; | |||||
Timer timer; | Timer timer; | ||||
float deltams, bias; | float deltams, bias; | ||||
} | } | ||||
@@ -73,6 +73,8 @@ void Ticker::TickGame() | |||||
Profiler::Start(Profiler::STAT_TICK_GAME); | Profiler::Start(Profiler::STAT_TICK_GAME); | ||||
data->frame++; | |||||
data->deltams = data->timer.GetMs(); | data->deltams = data->timer.GetMs(); | ||||
data->bias += data->deltams; | data->bias += data->deltams; | ||||
@@ -162,3 +164,8 @@ void Ticker::ClampFps(float deltams) | |||||
data->bias -= deltams; | data->bias -= deltams; | ||||
} | } | ||||
int Ticker::GetFrameNum() | |||||
{ | |||||
return data->frame; | |||||
} | |||||
@@ -24,6 +24,7 @@ public: | |||||
static void TickGame(); | static void TickGame(); | ||||
static void TickDraw(); | static void TickDraw(); | ||||
static void ClampFps(float deltams); | static void ClampFps(float deltams); | ||||
static int GetFrameNum(); | |||||
}; | }; | ||||
#endif // __DH_TICKER_H__ | #endif // __DH_TICKER_H__ | ||||