Changeset 167


Ignore:
Timestamp:
Aug 22, 2010, 7:52:12 PM (10 years ago)
Author:
sam
Message:

Store the frame number in the Ticker instead of duplicating the information
in each class that uses it.

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debugfps.cpp

    r154 r167  
    2323private:
    2424    int fontid;
    25     int frame;
    2625};
    2726
     
    3534
    3635    data->fontid = Forge::Register("gfx/font/ascii.png");
    37     data->frame = 0;
    3836}
    3937
     
    4745    Entity::TickDraw(deltams);
    4846
    49     data->frame++;
    50 
    5147    char buf[1024];
    5248    Font *font = Forge::GetFont(data->fontid);
    5349
    5450    sprintf(buf, "%2.2f fps (%i)",
    55             1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), data->frame);
     51            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
     52            Ticker::GetFrameNum());
    5653    font->PrintBold(10, 10, buf);
    5754
  • trunk/src/gtk/glmapview.cpp

    r166 r167  
    119119}
    120120
    121 gboolean GlMapView::Draw(GdkEventExpose *event)
    122 {
    123     if (event->count > 0)
     121gboolean GlMapView::Draw(GdkEventExpose *e)
     122{
     123    if (e->count > 0)
    124124        return TRUE;
    125125
     
    187187}
    188188
    189 gboolean GlMapView::MouseButton(GdkEventButton *event)
    190 {
    191     if (event->type == GDK_BUTTON_PRESS && event->button == 2)
     189gboolean GlMapView::MouseButton(GdkEventButton *e)
     190{
     191    if (e->type == GDK_BUTTON_PRESS && e->button == 2)
    192192    {
    193193        panning = TRUE;
    194         xpan = event->x;
    195         ypan = event->y;
     194        xpan = e->x;
     195        ypan = e->y;
    196196        GdkCursor *cursor = gdk_cursor_new(GDK_HAND1);
    197197        gdk_window_set_cursor(glarea->window, cursor);
     
    199199        return FALSE;
    200200    }
    201     else if (event->type == GDK_BUTTON_RELEASE && event->button == 2)
     201    else if (e->type == GDK_BUTTON_RELEASE && e->button == 2)
    202202    {
    203203        panning = FALSE;
     
    209209}
    210210
    211 gboolean GlMapView::MouseMotion(GdkEventMotion *event)
     211gboolean GlMapView::MouseMotion(GdkEventMotion *e)
    212212{
    213213    if (panning)
    214214    {
    215         if (event->x != xpan)
     215        if (e->x != xpan)
    216216        {
    217217            double val = gtk_adjustment_get_value(hadj);
    218218            int map_width = mapviewer->GetWidth();
    219             val += xpan - event->x;
    220             xpan = event->x;
     219            val += xpan - e->x;
     220            xpan = e->x;
    221221            if (val + glarea->allocation.width > map_width)
    222222                val = map_width - glarea->allocation.width;
     
    225225        }
    226226
    227         if (event->y != ypan)
     227        if (e->y != ypan)
    228228        {
    229229            double val = gtk_adjustment_get_value(vadj);
    230230            int map_height = mapviewer->GetHeight();
    231             val += ypan - event->y;
    232             ypan = event->y;
     231            val += ypan - e->y;
     232            ypan = e->y;
    233233            if (val + glarea->allocation.height > map_height)
    234234                val = map_height - glarea->allocation.height;
     
    241241}
    242242
    243 gboolean GlMapView::KeyPress(GdkEventKey *event)
    244 {
    245     switch (event->keyval)
     243gboolean GlMapView::KeyPress(GdkEventKey *e)
     244{
     245    switch (e->keyval)
    246246    {
    247247    case GDK_Up:    MoveAdjustments(  0.0, -10.0); break;
     
    273273}
    274274
    275 gboolean GlMapView::DrawSignal(GtkWidget *w, GdkEventExpose *event,
     275gboolean GlMapView::DrawSignal(GtkWidget *w, GdkEventExpose *e,
    276276                               GlMapView *that)
    277277{
    278278    (void)w;
    279     return that->Draw(event);
    280 }
    281 
    282 gboolean GlMapView::ReshapeSignal(GtkWidget *w, GdkEventConfigure *event,
     279    return that->Draw(e);
     280}
     281
     282gboolean GlMapView::ReshapeSignal(GtkWidget *w, GdkEventConfigure *e,
    283283                                  GlMapView *that)
    284284{
    285285    (void)w;
    286     (void)event;
     286    (void)e;
    287287    return that->Setup();
    288288}
    289289
    290 gboolean GlMapView::MouseButtonSignal(GtkWidget *w, GdkEventButton *event,
     290gboolean GlMapView::MouseButtonSignal(GtkWidget *w, GdkEventButton *e,
    291291                                      GlMapView *that)
    292292{
    293293    (void)w;
    294     return that->MouseButton(event);
    295 }
    296 
    297 gboolean GlMapView::MouseMotionSignal(GtkWidget *w, GdkEventMotion *event,
     294    return that->MouseButton(e);
     295}
     296
     297gboolean GlMapView::MouseMotionSignal(GtkWidget *w, GdkEventMotion *e,
    298298                                      GlMapView *that)
    299299{
    300300    (void)w;
    301     return that->MouseMotion(event);
    302 }
    303 
    304 gboolean GlMapView::KeyPressSignal(GtkWidget *w, GdkEventKey *event,
     301    return that->MouseMotion(e);
     302}
     303
     304gboolean GlMapView::KeyPressSignal(GtkWidget *w, GdkEventKey *e,
    305305                                   GlMapView *that)
    306306{
    307307    (void)w;
    308     return that->KeyPress(event);
    309 }
    310 
     308    return that->KeyPress(e);
     309}
     310
  • trunk/src/gtk/glmapview.h

    r166 r167  
    2121    gboolean Setup();
    2222    gboolean Destroy();
    23     gboolean Draw(GdkEventExpose *event);
     23    gboolean Draw(GdkEventExpose *e);
    2424    gboolean UpdateAdjustments();
    2525    gboolean MoveAdjustments(double dx, double dy);
    26     gboolean MouseButton(GdkEventButton *event);
    27     gboolean MouseMotion(GdkEventMotion *event);
    28     gboolean KeyPress(GdkEventKey *event);
     26    gboolean MouseButton(GdkEventButton *e);
     27    gboolean MouseMotion(GdkEventMotion *e);
     28    gboolean KeyPress(GdkEventKey *e);
    2929
    3030    /* Private signal slots */
     
    3232    static gboolean SetupSignal(GtkWidget *w, GlMapView *that);
    3333    static gboolean DestroySignal(GtkWidget *w, GlMapView *that);
    34     static gboolean DrawSignal(GtkWidget *w, GdkEventExpose *event,
     34    static gboolean DrawSignal(GtkWidget *w, GdkEventExpose *e,
    3535                               GlMapView *that);
    36     static gboolean ReshapeSignal(GtkWidget *w, GdkEventConfigure *event,
     36    static gboolean ReshapeSignal(GtkWidget *w, GdkEventConfigure *e,
    3737                                  GlMapView *that);
    38     static gboolean MouseButtonSignal(GtkWidget *w, GdkEventButton *event,
     38    static gboolean MouseButtonSignal(GtkWidget *w, GdkEventButton *e,
    3939                                      GlMapView *that);
    40     static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *event,
     40    static gboolean MouseMotionSignal(GtkWidget *w, GdkEventMotion *e,
    4141                                      GlMapView *that);
    42     static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *event,
     42    static gboolean KeyPressSignal(GtkWidget *w, GdkEventKey *e,
    4343                                   GlMapView *that);
    4444
  • trunk/src/profiler.cpp

    r154 r167  
    2222    friend class Profiler;
    2323
    24     static int const HISTORY = 30;
     24    static int const HISTORY = 32;
    2525
    2626public:
     
    2929        for (int i = 0; i < HISTORY; i++)
    3030            history[i] = 0.0f;
    31         frame = 0;
    3231        avg = max = 0.0f;
    3332    }
     
    3635    float history[HISTORY];
    3736    Timer timer;
    38     int frame;
    3937    float avg, max;
    4038}
     
    5452    float deltams = data[id].timer.GetMs();
    5553
    56     data[id].history[data->frame % ProfilerData::HISTORY] = deltams;
    57     data[id].frame++;
     54    data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
    5855    data[id].avg = 0.0f;
    5956    data[id].max = 0.0f;
  • trunk/src/ticker.cpp

    r154 r167  
    2424public:
    2525    TickerData() :
    26         todo(0),
    27         nentities(0)
     26        todo(0), nentities(0),
     27        frame(0), deltams(0), bias(0)
    2828    {
    2929        for (int i = 0; i < Entity::GROUP_COUNT; i++)
    3030            list[i] = NULL;
    31         bias = 0.0f;
    3231    }
    3332
     
    4746
    4847    /* Fixed framerate management */
     48    int frame;
    4949    Timer timer;
    5050    float deltams, bias;
     
    7373
    7474    Profiler::Start(Profiler::STAT_TICK_GAME);
     75
     76    data->frame++;
    7577
    7678    data->deltams = data->timer.GetMs();
     
    163165}
    164166
     167int Ticker::GetFrameNum()
     168{
     169    return data->frame;
     170}
     171
  • trunk/src/ticker.h

    r154 r167  
    2525    static void TickDraw();
    2626    static void ClampFps(float deltams);
     27    static int GetFrameNum();
    2728};
    2829
Note: See TracChangeset for help on using the changeset viewer.