Pārlūkot izejas kodu

Allow for different priorities in game and draw tick levels.

legacy
Sam Hocevar sam pirms 14 gadiem
vecāks
revīzija
54a05e0c2c
25 mainītis faili ar 78 papildinājumiem un 110 dzēšanām
  1. +1
    -4
      src/debugfps.cpp
  2. +0
    -1
      src/debugfps.h
  3. +1
    -4
      src/debugrecord.cpp
  4. +0
    -1
      src/debugrecord.h
  5. +0
    -5
      src/debugsphere.cpp
  6. +0
    -1
      src/debugsphere.h
  7. +0
    -5
      src/debugsprite.cpp
  8. +0
    -1
      src/debugsprite.h
  9. +1
    -4
      src/debugstats.cpp
  10. +0
    -1
      src/debugstats.h
  11. +4
    -6
      src/entity.cpp
  12. +26
    -13
      src/entity.h
  13. +2
    -5
      src/font.cpp
  14. +0
    -1
      src/font.h
  15. +0
    -5
      src/game.cpp
  16. +0
    -1
      src/game.h
  17. +0
    -5
      src/mapviewer.cpp
  18. +0
    -1
      src/mapviewer.h
  19. +1
    -4
      src/sdlinput.cpp
  20. +0
    -1
      src/sdlinput.h
  21. +38
    -29
      src/ticker.cpp
  22. +2
    -5
      src/tileset.cpp
  23. +0
    -1
      src/tileset.h
  24. +2
    -5
      src/world.cpp
  25. +0
    -1
      src/world.h

+ 1
- 4
src/debugfps.cpp Parādīt failu

@@ -33,11 +33,8 @@ DebugFps::DebugFps()
data = new DebugFpsData();

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

Entity::Group DebugFps::GetGroup()
{
return GROUP_AFTER;
drawgroup = DRAWGROUP_HUD;
}

void DebugFps::TickDraw(float deltams)


+ 0
- 1
src/debugfps.h Parādīt failu

@@ -22,7 +22,6 @@ public:
virtual ~DebugFps();

protected:
virtual Group GetGroup();
virtual void TickDraw(float deltams);

private:


+ 1
- 4
src/debugrecord.cpp Parādīt failu

@@ -46,11 +46,8 @@ DebugRecord::DebugRecord(char const *path)
#if defined USE_PIPI
data->sequence = NULL;
#endif
}

Entity::Group DebugRecord::GetGroup()
{
return GROUP_DRAW_CAPTURE;
drawgroup = DRAWGROUP_CAPTURE;
}

void DebugRecord::TickGame(float deltams)


+ 0
- 1
src/debugrecord.h Parādīt failu

@@ -22,7 +22,6 @@ public:
virtual ~DebugRecord();

protected:
virtual Group GetGroup();
virtual void TickGame(float deltams);
virtual void TickDraw(float deltams);



+ 0
- 5
src/debugsphere.cpp Parādīt failu

@@ -110,11 +110,6 @@ DebugSphere::DebugSphere()
data->time = 0.0f;
}

Entity::Group DebugSphere::GetGroup()
{
return GROUP_DEFAULT;
}

void DebugSphere::TickGame(float deltams)
{
Entity::TickGame(deltams);


+ 0
- 1
src/debugsphere.h Parādīt failu

@@ -22,7 +22,6 @@ public:
virtual ~DebugSphere();

protected:
virtual Group GetGroup();
virtual void TickGame(float deltams);
virtual void TickDraw(float deltams);



+ 0
- 5
src/debugsprite.cpp Parādīt failu

@@ -42,11 +42,6 @@ DebugSprite::DebugSprite(Game *game)
data->z = 0;
}

Entity::Group DebugSprite::GetGroup()
{
return GROUP_DEFAULT;
}

void DebugSprite::TickGame(float deltams)
{
Entity::TickGame(deltams);


+ 0
- 1
src/debugsprite.h Parādīt failu

@@ -23,7 +23,6 @@ public:
virtual ~DebugSprite();

protected:
virtual Group GetGroup();
virtual void TickGame(float deltams);
virtual void TickDraw(float deltams);



+ 1
- 4
src/debugstats.cpp Parādīt failu

@@ -32,11 +32,8 @@ DebugStats::DebugStats(char const *path)
{
data = new DebugStatsData();
data->fp = fopen(path, "w+");
}

Entity::Group DebugStats::GetGroup()
{
return GROUP_AFTER;
gamegroup = GAMEGROUP_AFTER;
}

void DebugStats::TickGame(float deltams)


+ 0
- 1
src/debugstats.h Parādīt failu

@@ -22,7 +22,6 @@ public:
virtual ~DebugStats();

protected:
virtual Group GetGroup();
virtual void TickGame(float deltams);

private:


+ 4
- 6
src/entity.cpp Parādīt failu

@@ -17,13 +17,16 @@
*/

Entity::Entity() :
next(0),
gamenext(0),
drawnext(0),
ref(0),
destroy(0)
{
#if !FINAL_RELEASE
state = STATE_IDLE;
#endif
gamegroup = GAMEGROUP_DEFAULT;
drawgroup = DRAWGROUP_DEFAULT;
Ticker::Register(this);
}

@@ -40,11 +43,6 @@ char const *Entity::GetName()
return "<entity>";
}

Entity::Group Entity::GetGroup()
{
return GROUP_DEFAULT;
}

void Entity::TickGame(float deltams)
{
#if !FINAL_RELEASE


+ 26
- 13
src/entity.h Parādīt failu

@@ -23,29 +23,42 @@ class Entity
friend class Dict;

protected:
typedef enum
{
GROUP_BEFORE = 0,
GROUP_DEFAULT,
GROUP_AFTER,
GROUP_DRAW_CAPTURE,
// Must be the last element
GROUP_COUNT
}
Group;

Entity();
virtual ~Entity();

virtual char const *GetName();
virtual Group GetGroup();

virtual void TickGame(float deltams);
virtual void TickDraw(float deltams);

Entity *next, *autonext;
Entity *gamenext, *drawnext, *autonext;
int ref, autorelease, destroy;

enum
{
GAMEGROUP_BEFORE = 0,
GAMEGROUP_DEFAULT,
GAMEGROUP_AFTER,
// Must be the last element
GAMEGROUP_END
}
gamegroup;

enum
{
DRAWGROUP_BEFORE = GAMEGROUP_END,
DRAWGROUP_DEFAULT,
DRAWGROUP_HUD,
DRAWGROUP_CAPTURE,
// Must be the last element
DRAWGROUP_END
}
drawgroup;

static int const GAMEGROUP_BEGIN = 0;
static int const DRAWGROUP_BEGIN = GAMEGROUP_END;
static int const ALLGROUP_END = DRAWGROUP_END;

#if !FINAL_RELEASE
enum
{


+ 2
- 5
src/font.cpp Parādīt failu

@@ -58,6 +58,8 @@ Font::Font(char const *path)
SDL_Quit();
exit(1);
}

drawgroup = DRAWGROUP_BEFORE;
}

Font::~Font()
@@ -65,11 +67,6 @@ Font::~Font()
delete data;
}

Entity::Group Font::GetGroup()
{
return GROUP_BEFORE;
}

void Font::TickDraw(float deltams)
{
Entity::TickDraw(deltams);


+ 0
- 1
src/font.h Parādīt failu

@@ -24,7 +24,6 @@ public:
protected:
/* Inherited from Entity */
virtual char const *GetName();
virtual Group GetGroup();
virtual void TickDraw(float deltams);

public:


+ 0
- 5
src/game.cpp Parādīt failu

@@ -47,11 +47,6 @@ Game::~Game()
delete data;
}

Entity::Group Game::GetGroup()
{
return Entity::GetGroup();
}

void Game::TickGame(float deltams)
{
Entity::TickGame(deltams);


+ 0
- 1
src/game.h Parādīt failu

@@ -24,7 +24,6 @@ public:

protected:
/* Inherited from Entity */
virtual Group GetGroup();
virtual void TickGame(float deltams);
virtual void TickDraw(float deltams);



+ 0
- 5
src/mapviewer.cpp Parādīt failu

@@ -47,11 +47,6 @@ MapViewer::~MapViewer()
delete data;
}

Entity::Group MapViewer::GetGroup()
{
return Entity::GetGroup();
}

void MapViewer::TickGame(float deltams)
{
Entity::TickGame(deltams);


+ 0
- 1
src/mapviewer.h Parādīt failu

@@ -24,7 +24,6 @@ public:

protected:
/* Inherited from Entity */
virtual Group GetGroup();
virtual void TickGame(float deltams);
virtual void TickDraw(float deltams);



+ 1
- 4
src/sdlinput.cpp Parādīt failu

@@ -34,11 +34,8 @@ SdlInput::SdlInput()

data = new SdlInputData();
SDL_GetMouseState(&data->mx, &data->my);
}

Entity::Group SdlInput::GetGroup()
{
return GROUP_BEFORE;
gamegroup = GAMEGROUP_BEFORE;
}

void SdlInput::TickGame(float deltams)


+ 0
- 1
src/sdlinput.h Parādīt failu

@@ -23,7 +23,6 @@ public:
virtual ~SdlInput();

protected:
virtual Group GetGroup();
virtual void TickGame(float deltams);

private:


+ 38
- 29
src/ticker.cpp Parādīt failu

@@ -27,7 +27,7 @@ public:
nentities(0),
frame(0), deltams(0), bias(0)
{
for (int i = 0; i < Entity::GROUP_COUNT; i++)
for (int i = 0; i < Entity::ALLGROUP_END; i++)
list[i] = NULL;
}

@@ -51,7 +51,7 @@ public:
private:
/* Entity management */
Entity *todolist, *autolist;
Entity *list[Entity::GROUP_COUNT];
Entity *list[Entity::ALLGROUP_END];
int nentities;

/* Fixed framerate management */
@@ -72,7 +72,7 @@ void Ticker::Register(Entity *entity)
/* If we are called from its constructor, the object's vtable is not
* ready yet, so we do not know which group this entity belongs to. Wait
* until the first tick. */
entity->next = data->todolist;
entity->gamenext = data->todolist;
data->todolist = entity;
/* Objects are autoreleased by default. Put them in a circular list. */
entity->autorelease = 1;
@@ -99,10 +99,7 @@ void Ticker::Ref(Entity *entity)
{
if (e == entity)
{
if (prev)
prev->autonext = e->autonext;
else
data->autolist = e->autonext;
(prev ? prev->autonext : data->autolist) = e->autonext;
break;
}
}
@@ -132,12 +129,16 @@ void Ticker::TickGame()

#if 0
fprintf(stderr, "-------------------------------------\n");
for (int i = 0; i < Entity::GROUP_COUNT; i++)
for (int i = 0; i < Entity::ALLGROUP_END; i++)
{
fprintf(stderr, "Group %i\n", i);
fprintf(stderr, "%s Group %i\n",
(i < Entity::GAMEGROUP_END) ? "Game" : "Draw", i);

for (Entity *e = data->list[i]; e; e = e->next)
for (Entity *e = data->list[i]; e; )
{
fprintf(stderr, " \\-- %s (ref %i, destroy %i)\n", e->GetName(), e->ref, e->destroy);
e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext;
}
}
#endif

@@ -147,30 +148,37 @@ void Ticker::TickGame()
data->bias += data->deltams;

/* Garbage collect objects that can be destroyed. We can do this
* before inserting awaiting objects, because there is no way these
* are already marked for destruction. */
for (int i = 0; i < Entity::GROUP_COUNT; i++)
* before inserting awaiting objects, because only objects already in
* the tick lists can be marked for destruction. */
for (int i = 0; i < Entity::ALLGROUP_END; i++)
for (Entity *e = data->list[i], *prev = NULL; e; )
{
if (e->destroy)
if (e->destroy && i < Entity::GAMEGROUP_END)
{
/* If entity is to be destroyed, remove it from the
* game tick list. */
(prev ? prev->gamenext : data->list[i]) = e->gamenext;

e = e->gamenext;
}
else if (e->destroy)
{
if (prev)
prev->next = e->next;
else
data->list[i] = e->next;
/* If entity is to be destroyed, remove it from the
* draw tick list and destroy it. */
(prev ? prev->drawnext : data->list[i]) = e->drawnext;

Entity *tmp = e;
e = e->next;
e = e->drawnext; /* Can only be in a draw group list */
delete tmp;

data->nentities--;
}
else
{
if (e->ref <= 0)
if (e->ref <= 0 && i >= Entity::DRAWGROUP_BEGIN)
e->destroy = 1;
prev = e;
e = e->next;
e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext;
}
}

@@ -178,16 +186,17 @@ void Ticker::TickGame()
while (data->todolist)
{
Entity *e = data->todolist;
data->todolist = e->next;
data->todolist = e->gamenext;

int i = e->GetGroup();
e->next = data->list[i];
data->list[i] = e;
e->gamenext = data->list[e->gamegroup];
data->list[e->gamegroup] = e;
e->drawnext = data->list[e->drawgroup];
data->list[e->drawgroup] = e;
}

/* Tick objects for the game loop */
for (int i = 0; i < Entity::GROUP_COUNT; i++)
for (Entity *e = data->list[i]; e; e = e->next)
for (int i = Entity::GAMEGROUP_BEGIN; i < Entity::GAMEGROUP_END; i++)
for (Entity *e = data->list[i]; e; e = e->gamenext)
if (!e->destroy)
{
#if !FINAL_RELEASE
@@ -211,8 +220,8 @@ void Ticker::TickDraw()
Profiler::Start(Profiler::STAT_TICK_DRAW);

/* Tick objects for the draw loop */
for (int i = 0; i < Entity::GROUP_COUNT; i++)
for (Entity *e = data->list[i]; e; e = e->next)
for (int i = Entity::DRAWGROUP_BEGIN; i < Entity::DRAWGROUP_END; i++)
for (Entity *e = data->list[i]; e; e = e->drawnext)
if (!e->destroy)
{
#if !FINAL_RELEASE


+ 2
- 5
src/tileset.cpp Parādīt failu

@@ -71,6 +71,8 @@ TileSet::TileSet(char const *path)
data->ntiles = data->nw * data->nh;
data->tx = 32.0f / data->img->w;
data->ty = 32.0f / data->img->h;

drawgroup = DRAWGROUP_BEFORE;
}

TileSet::~TileSet()
@@ -80,11 +82,6 @@ TileSet::~TileSet()
delete data;
}

Entity::Group TileSet::GetGroup()
{
return GROUP_BEFORE;
}

void TileSet::TickDraw(float deltams)
{
Entity::TickDraw(deltams);


+ 0
- 1
src/tileset.h Parādīt failu

@@ -29,7 +29,6 @@ public:
protected:
/* Inherited from Entity */
virtual char const *GetName();
virtual Group GetGroup();
virtual void TickDraw(float deltams);

public:


+ 2
- 5
src/world.cpp Parādīt failu

@@ -35,6 +35,8 @@ World::World()
data = new WorldData();
data->width = 0;
data->height = 0;

drawgroup = DRAWGROUP_BEFORE;
}

World::~World()
@@ -42,11 +44,6 @@ World::~World()
delete data;
}

Entity::Group World::GetGroup()
{
return GROUP_BEFORE;
}

char const *World::GetName()
{
return "<world>";


+ 0
- 1
src/world.h Parādīt failu

@@ -24,7 +24,6 @@ public:
protected:
/* Inherited from Entity */
virtual char const *GetName();
virtual Group GetGroup();
virtual void TickGame(float deltams);
virtual void TickDraw(float deltams);



Notiek ielāde…
Atcelt
Saglabāt