Changeset 111


Ignore:
Timestamp:
Aug 14, 2010, 11:15:43 PM (10 years ago)
Author:
sam
Message:

The frame counter is now an asset object.

Location:
trunk/src
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r109 r111  
    88    scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \
    99    joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h \
    10     video.cpp video.h
     10    forge.cpp forge.h video.cpp video.h \
     11    debugfps.cpp debugfps.h
    1112libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`
    1213
  • trunk/src/asset.cpp

    r106 r111  
    2828Asset::~Asset()
    2929{
    30 #if !defined FINAL_RELEASE
     30#if !FINAL_RELEASE
    3131    if (!destroy)
    3232        fprintf(stderr, "ERROR: asset destructor called directly\n");
  • trunk/src/font.cpp

    r100 r111  
    3333
    3434private:
     35    char *name;
     36
    3537    SDL_Surface *img;
    3638    GLuint texture[1];
     
    4446{
    4547    data = new FontData();
     48    data->name = strdup(path);
    4649    data->img = NULL;
    4750
     
    7477}
    7578
     79Asset::Group Font::GetGroup()
     80{
     81    return GROUP_BEFORE;
     82}
     83
     84void Font::TickRender(float delta_time)
     85{
     86    Asset::TickRender(delta_time);
     87}
     88
     89char const *Font::GetName()
     90{
     91    return data->name;
     92}
     93
    7694void Font::Print(int x, int y, char const *str)
    7795{
  • trunk/src/font.h

    r100 r111  
    1212#define __DH_FONT_H__
    1313
     14#include "asset.h"
     15
    1416class FontData;
    1517
    16 class Font
     18class Font : public Asset
    1719{
    1820public:
    1921    Font(char const *path);
    2022    ~Font();
     23
     24protected:
     25    /* Inherited from Asset */
     26    virtual Group GetGroup();
     27    virtual void TickRender(float delta_time);
     28
     29public:
     30    /* New methods */
     31    char const *GetName();
    2132
    2233    void Print(int x, int y, char const *str);
  • trunk/src/game.cpp

    r106 r111  
    1212#include "game.h"
    1313#include "map.h"
    14 #include "font.h"
    1514
    1615/*
     
    2423private:
    2524    Map *map;
    26     Font *font;
    2725    int x, y;
    2826    int mousex, mousey;
     
    4038    data = new GameData();
    4139    data->map = new Map(mapname);
    42     data->font = new Font("gfx/font/ascii.png");
    4340    data->x = data->y = 0;
    4441    data->done = 0;
     
    4845Game::~Game()
    4946{
    50     delete data->font;
    5147    delete data->map;
    5248    delete data;
     
    7369    scene->Render();
    7470    delete scene;
    75 
    76     char buf[1024];
    77     sprintf(buf, "Frame %i", data->frame++);
    78     data->font->Print(10, 10, buf);
    7971}
    8072
  • trunk/src/gtk/editor.cpp

    r110 r111  
    1616
    1717#include "ticker.h"
     18#include "debugfps.h"
    1819#include "video.h"
    1920#include "game.h"
     
    147148    // FIXME: detect when the game is killed
    148149    new Game("maps/testmap.tmx");
     150    new DebugFps();
    149151
    150152    //gtk_idle_add(tick, glarea);
  • trunk/src/test-map.cpp

    r108 r111  
    1414
    1515#include "sdlinput.h"
     16#include "debugfps.h"
    1617#include "game.h"
    1718#include "ticker.h"
     
    5051    Game *game = new Game("maps/testmap.tmx");
    5152
    52     /* Register an input driver */
     53    /* Register an input driver and some debug stuff */
    5354    new SdlInput(game);
     55    new DebugFps();
    5456
    5557    while (!game->Finished())
  • trunk/src/ticker.cpp

    r104 r111  
    2525public:
    2626    TickerData() :
     27        todo(0),
    2728        nassets(0)
    2829    {
     
    3334    ~TickerData()
    3435    {
     36#if !FINAL_RELEASE
    3537        if (nassets)
    3638            fprintf(stderr, "ERROR: still %i assets in ticker\n", nassets);
     39#endif
    3740    }
    3841
    3942private:
     43    Asset *todo;
    4044    Asset *list[Asset::GROUP_COUNT];
    4145    int nassets;
     
    5155void Ticker::Register(Asset *asset)
    5256{
    53     int i = asset->GetGroup();
    54     asset->next = data->list[i];
    55     data->list[i] = asset;
    56     data->nassets++;
     57    /* If we are called from its constructor, the object's vtable is not
     58     * ready yet, so we do not know which group this asset belongs to. Wait
     59     * until the first tick. */
     60    asset->next = data->todo;
     61    data->todo = asset;
    5762}
    5863
    5964void Ticker::TickGame(float delta_time)
    6065{
     66    /* Insert waiting objects in the appropriate lists */
     67    while (data->todo)
     68    {
     69        Asset *a = data->todo;
     70        data->todo = a->next;
     71
     72        int i = a->GetGroup();
     73        a->next = data->list[i];
     74        data->list[i] = a;
     75        data->nassets++;
     76    }
     77
    6178    /* Garbage collect objects that can be destroyed */
    6279    for (int i = 0; i < Asset::GROUP_COUNT; i++)
Note: See TracChangeset for help on using the changeset viewer.