Browse Source

Store the frame number in the Ticker instead of duplicating the information

in each class that uses it.
legacy
Sam Hocevar sam 14 years ago
parent
commit
c1851f2c2b
6 changed files with 50 additions and 48 deletions
  1. +2
    -5
      src/debugfps.cpp
  2. +26
    -26
      src/gtk/glmapview.cpp
  3. +9
    -9
      src/gtk/glmapview.h
  4. +2
    -5
      src/profiler.cpp
  5. +10
    -3
      src/ticker.cpp
  6. +1
    -0
      src/ticker.h

+ 2
- 5
src/debugfps.cpp View File

@@ -22,7 +22,6 @@ class DebugFpsData

private:
int fontid;
int frame;
};

/*
@@ -34,7 +33,6 @@ DebugFps::DebugFps()
data = new DebugFpsData();

data->fontid = Forge::Register("gfx/font/ascii.png");
data->frame = 0;
}

Entity::Group DebugFps::GetGroup()
@@ -46,13 +44,12 @@ void DebugFps::TickDraw(float deltams)
{
Entity::TickDraw(deltams);

data->frame++;

char buf[1024];
Font *font = Forge::GetFont(data->fontid);

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

sprintf(buf, "Game % 7.2f % 7.2f",


+ 26
- 26
src/gtk/glmapview.cpp View File

@@ -118,9 +118,9 @@ gboolean GlMapView::Destroy()
return TRUE;
}

gboolean GlMapView::Draw(GdkEventExpose *event)
gboolean GlMapView::Draw(GdkEventExpose *e)
{
if (event->count > 0)
if (e->count > 0)
return 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;
}

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;
xpan = event->x;
ypan = event->y;
xpan = e->x;
ypan = e->y;
GdkCursor *cursor = gdk_cursor_new(GDK_HAND1);
gdk_window_set_cursor(glarea->window, cursor);
gdk_cursor_unref(cursor);
return FALSE;
}
else if (event->type == GDK_BUTTON_RELEASE && event->button == 2)
else if (e->type == GDK_BUTTON_RELEASE && e->button == 2)
{
panning = FALSE;
gdk_window_set_cursor(glarea->window, NULL);
@@ -208,28 +208,28 @@ gboolean GlMapView::MouseButton(GdkEventButton *event)
return TRUE;
}

gboolean GlMapView::MouseMotion(GdkEventMotion *event)
gboolean GlMapView::MouseMotion(GdkEventMotion *e)
{
if (panning)
{
if (event->x != xpan)
if (e->x != xpan)
{
double val = gtk_adjustment_get_value(hadj);
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)
val = map_width - glarea->allocation.width;
gtk_adjustment_set_value(hadj, val);
gtk_adjustment_value_changed(hadj);
}

if (event->y != ypan)
if (e->y != ypan)
{
double val = gtk_adjustment_get_value(vadj);
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)
val = map_height - glarea->allocation.height;
gtk_adjustment_set_value(vadj, val);
@@ -240,9 +240,9 @@ gboolean GlMapView::MouseMotion(GdkEventMotion *event)
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_Down: MoveAdjustments( 0.0, 10.0); break;
@@ -272,39 +272,39 @@ gboolean GlMapView::DestroySignal(GtkWidget *w, GlMapView *that)
return that->Destroy();
}

gboolean GlMapView::DrawSignal(GtkWidget *w, GdkEventExpose *event,
gboolean GlMapView::DrawSignal(GtkWidget *w, GdkEventExpose *e,
GlMapView *that)
{
(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)
{
(void)w;
(void)event;
(void)e;
return that->Setup();
}

gboolean GlMapView::MouseButtonSignal(GtkWidget *w, GdkEventButton *event,
gboolean GlMapView::MouseButtonSignal(GtkWidget *w, GdkEventButton *e,
GlMapView *that)
{
(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)
{
(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)
{
(void)w;
return that->KeyPress(event);
return that->KeyPress(e);
}


+ 9
- 9
src/gtk/glmapview.h View File

@@ -20,26 +20,26 @@ private:
gboolean IdleTick();
gboolean Setup();
gboolean Destroy();
gboolean Draw(GdkEventExpose *event);
gboolean Draw(GdkEventExpose *e);
gboolean UpdateAdjustments();
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 */
static gboolean IdleTickSignal(GlMapView *that);
static gboolean SetupSignal(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);
static gboolean ReshapeSignal(GtkWidget *w, GdkEventConfigure *event,
static gboolean ReshapeSignal(GtkWidget *w, GdkEventConfigure *e,
GlMapView *that);
static gboolean MouseButtonSignal(GtkWidget *w, GdkEventButton *event,
static gboolean MouseButtonSignal(GtkWidget *w, GdkEventButton *e,
GlMapView *that);
static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *event,
static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *e,
GlMapView *that);
static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *event,
static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *e,
GlMapView *that);

private:


+ 2
- 5
src/profiler.cpp View File

@@ -21,21 +21,19 @@ static class ProfilerData
{
friend class Profiler;

static int const HISTORY = 30;
static int const HISTORY = 32;

public:
ProfilerData()
{
for (int i = 0; i < HISTORY; i++)
history[i] = 0.0f;
frame = 0;
avg = max = 0.0f;
}

private:
float history[HISTORY];
Timer timer;
int frame;
float avg, max;
}
data[Profiler::STAT_COUNT];
@@ -53,8 +51,7 @@ void Profiler::Stop(int id)
{
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].max = 0.0f;



+ 10
- 3
src/ticker.cpp View File

@@ -23,12 +23,11 @@ static class TickerData

public:
TickerData() :
todo(0),
nentities(0)
todo(0), nentities(0),
frame(0), deltams(0), bias(0)
{
for (int i = 0; i < Entity::GROUP_COUNT; i++)
list[i] = NULL;
bias = 0.0f;
}

~TickerData()
@@ -46,6 +45,7 @@ private:
int nentities;

/* Fixed framerate management */
int frame;
Timer timer;
float deltams, bias;
}
@@ -73,6 +73,8 @@ void Ticker::TickGame()

Profiler::Start(Profiler::STAT_TICK_GAME);

data->frame++;

data->deltams = data->timer.GetMs();
data->bias += data->deltams;

@@ -162,3 +164,8 @@ void Ticker::ClampFps(float deltams)
data->bias -= deltams;
}

int Ticker::GetFrameNum()
{
return data->frame;
}


+ 1
- 0
src/ticker.h View File

@@ -24,6 +24,7 @@ public:
static void TickGame();
static void TickDraw();
static void ClampFps(float deltams);
static int GetFrameNum();
};

#endif // __DH_TICKER_H__


Loading…
Cancel
Save