Browse Source

Rename "asset" to "entity". It's way cooler.

legacy
Sam Hocevar sam 14 years ago
parent
commit
4d63ad6ada
21 changed files with 110 additions and 99 deletions
  1. +1
    -1
      src/Makefile.am
  2. +2
    -2
      src/debugfps.cpp
  3. +2
    -2
      src/debugfps.h
  4. +3
    -3
      src/debugrecord.cpp
  5. +2
    -2
      src/debugrecord.h
  6. +3
    -3
      src/debugsprite.cpp
  7. +2
    -2
      src/debugsprite.h
  8. +12
    -12
      src/entity.cpp
  9. +10
    -10
      src/entity.h
  10. +2
    -2
      src/font.cpp
  11. +3
    -3
      src/font.h
  12. +4
    -4
      src/game.cpp
  13. +3
    -3
      src/game.h
  14. +1
    -1
      src/gtk/editor.cpp
  15. +14
    -3
      src/scene.cpp
  16. +2
    -2
      src/sdlinput.cpp
  17. +2
    -2
      src/sdlinput.h
  18. +34
    -34
      src/ticker.cpp
  19. +3
    -3
      src/ticker.h
  20. +2
    -2
      src/tileset.cpp
  21. +3
    -3
      src/tileset.h

+ 1
- 1
src/Makefile.am View File

@@ -6,7 +6,7 @@ noinst_LIBRARIES = libcommon.a
libcommon_a_SOURCES = \
game.cpp game.h tiler.cpp tiler.h tileset.cpp tileset.h \
scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \
joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h \
joystick.cpp joystick.h entity.cpp entity.h ticker.cpp ticker.h \
forge.cpp forge.h video.cpp video.h timer.cpp timer.h \
profiler.cpp profiler.h \
debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \


+ 2
- 2
src/debugfps.cpp View File

@@ -38,14 +38,14 @@ DebugFps::DebugFps()
data->frame = 0;
}

Asset::Group DebugFps::GetGroup()
Entity::Group DebugFps::GetGroup()
{
return GROUP_AFTER;
}

void DebugFps::TickRender(float delta_time)
{
Asset::TickRender(delta_time);
Entity::TickRender(delta_time);

data->frame++;



+ 2
- 2
src/debugfps.h View File

@@ -11,11 +11,11 @@
#if !defined __DH_DEBUGFPS_H__
#define __DH_DEBUGFPS_H__

#include "asset.h"
#include "entity.h"

class DebugFpsData;

class DebugFps : public Asset
class DebugFps : public Entity
{
public:
DebugFps();


+ 3
- 3
src/debugrecord.cpp View File

@@ -42,19 +42,19 @@ DebugRecord::DebugRecord(char const *path)
data->sequence = NULL;
}

Asset::Group DebugRecord::GetGroup()
Entity::Group DebugRecord::GetGroup()
{
return GROUP_RENDER_CAPTURE;
}

void DebugRecord::TickGame(float delta_time)
{
Asset::TickGame(delta_time);
Entity::TickGame(delta_time);
}

void DebugRecord::TickRender(float delta_time)
{
Asset::TickRender(delta_time);
Entity::TickRender(delta_time);

int width = Video::GetWidth();
int height = Video::GetHeight();


+ 2
- 2
src/debugrecord.h View File

@@ -11,11 +11,11 @@
#if !defined __DH_DEBUGRECORD_H__
#define __DH_DEBUGRECORD_H__

#include "asset.h"
#include "entity.h"

class DebugRecordData;

class DebugRecord : public Asset
class DebugRecord : public Entity
{
public:
DebugRecord(char const *path);


+ 3
- 3
src/debugsprite.cpp View File

@@ -38,19 +38,19 @@ DebugSprite::DebugSprite(Game *game)
data->tiler = Tiler::Register("art/test/character-dress.png");
}

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

void DebugSprite::TickGame(float delta_time)
{
Asset::TickGame(delta_time);
Entity::TickGame(delta_time);
}

void DebugSprite::TickRender(float delta_time)
{
Asset::TickRender(delta_time);
Entity::TickRender(delta_time);

data->game->GetScene()->AddTile((data->tiler << 16) | 15, 320, 240, 32, 1);
data->game->GetScene()->AddTile((data->tiler << 16) | 31, 320, 240, 0, 1);


+ 2
- 2
src/debugsprite.h View File

@@ -11,12 +11,12 @@
#if !defined __DH_DEBUGSPRITE_H__
#define __DH_DEBUGSPRITE_H__

#include "asset.h"
#include "entity.h"
#include "game.h"

class DebugSpriteData;

class DebugSprite : public Asset
class DebugSprite : public Entity
{
public:
DebugSprite(Game *game);


src/asset.cpp → src/entity.cpp View File

@@ -10,14 +10,14 @@
#include <cstdlib>
#include <cstdio>

#include "asset.h"
#include "entity.h"
#include "ticker.h"

/*
* Public Asset class
* Public Entity class
*/

Asset::Asset() :
Entity::Entity() :
next(0),
ref(0),
destroy(0)
@@ -28,43 +28,43 @@ Asset::Asset() :
Ticker::Register(this);
}

Asset::~Asset()
Entity::~Entity()
{
#if !FINAL_RELEASE
if (!destroy)
fprintf(stderr, "ERROR: asset destructor called directly\n");
fprintf(stderr, "ERROR: entity destructor called directly\n");
#endif
}

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

void Asset::TickGame(float delta_time)
void Entity::TickGame(float delta_time)
{
#if !FINAL_RELEASE
if (state != STATE_PRETICK_GAME)
fprintf(stderr, "ERROR: invalid asset game tick\n");
fprintf(stderr, "ERROR: invalid entity game tick\n");
state = STATE_POSTTICK_GAME;
#endif
}

void Asset::TickRender(float delta_time)
void Entity::TickRender(float delta_time)
{
#if !FINAL_RELEASE
if (state != STATE_PRETICK_RENDER)
fprintf(stderr, "ERROR: invalid asset render tick\n");
fprintf(stderr, "ERROR: invalid entity render tick\n");
state = STATE_POSTTICK_RENDER;
#endif
}

void Asset::Ref()
void Entity::Ref()
{
ref++;
}

int Asset::Unref()
int Entity::Unref()
{
return --ref;
}

src/asset.h → src/entity.h View File

@@ -4,19 +4,19 @@
//

//
// The Asset class
// The Entity class
// ---------------
// Assets are objects that can be ticked by the game loop and/or the render
// loop. Assets are implemented as one or several linked lists. See the
// Entities are objects that can be ticked by the game loop and/or the render
// loop. Entities are implemented as one or several linked lists. See the
// Ticker class for the ticking logic and the linked list implementation.
//

#if !defined __DH_ASSET_H__
#define __DH_ASSET_H__
#if !defined __DH_ENTITY_H__
#define __DH_ENTITY_H__

#include <stdint.h>

class Asset
class Entity
{
friend class Ticker;
friend class TickerData;
@@ -37,15 +37,15 @@ protected:
}
Group;

Asset();
virtual ~Asset();
Entity();
virtual ~Entity();

virtual Group GetGroup();

virtual void TickGame(float delta_time);
virtual void TickRender(float delta_time);

Asset *next;
Entity *next;
int ref, destroy;

#if !FINAL_RELEASE
@@ -61,5 +61,5 @@ protected:
#endif
};

#endif // __DH_ASSET_H__
#endif // __DH_ENTITY_H__


+ 2
- 2
src/font.cpp View File

@@ -76,14 +76,14 @@ Font::~Font()
delete data;
}

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

void Font::TickRender(float delta_time)
{
Asset::TickRender(delta_time);
Entity::TickRender(delta_time);
}

char const *Font::GetName()


+ 3
- 3
src/font.h View File

@@ -11,18 +11,18 @@
#if !defined __DH_FONT_H__
#define __DH_FONT_H__

#include "asset.h"
#include "entity.h"

class FontData;

class Font : public Asset
class Font : public Entity
{
public:
Font(char const *path);
~Font();

protected:
/* Inherited from Asset */
/* Inherited from Entity */
virtual Group GetGroup();
virtual void TickRender(float delta_time);



+ 4
- 4
src/game.cpp View File

@@ -48,19 +48,19 @@ Game::~Game()
delete data;
}

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

void Game::TickGame(float delta_time)
{
Asset::TickGame(delta_time);
Entity::TickGame(delta_time);
}

void Game::TickRender(float delta_time)
{
Asset::TickRender(delta_time);
Entity::TickRender(delta_time);

GetScene();



+ 3
- 3
src/game.h View File

@@ -11,19 +11,19 @@
#if !defined __DH_GAME_H__
#define __DH_GAME_H__

#include "asset.h"
#include "entity.h"
#include "scene.h"

class GameData;

class Game : public Asset
class Game : public Entity
{
public:
Game(char const *mapname);
~Game();

protected:
/* Inherited from Asset */
/* Inherited from Entity */
virtual Group GetGroup();
virtual void TickGame(float delta_time);
virtual void TickRender(float delta_time);


+ 1
- 1
src/gtk/editor.cpp View File

@@ -38,7 +38,7 @@ static gboolean tick(void *widget)
{
// FIXME: do not do anything if the previous tick was too recent?

// FIXME: only quit if all assets have been cleaned
// FIXME: only quit if all entities have been cleaned
if (quit)
return FALSE;



+ 14
- 3
src/scene.cpp View File

@@ -83,6 +83,16 @@ void Scene::AddTile(uint32_t code, int x, int y, int z, int o)

void Scene::Render() // XXX: rename to Blit()
{
#if 0
// Randomise, then sort.
for (int i = 0; i < data->ntiles; i++)
{
Tile tmp = data->tiles[i];
int j = rand() % data->ntiles;
data->tiles[i] = data->tiles[j];
data->tiles[j] = tmp;
}
#endif
qsort(data->tiles, data->ntiles, sizeof(Tile), SceneData::Compare);

// XXX: debug stuff
@@ -91,9 +101,10 @@ void Scene::Render() // XXX: rename to Blit()
f += 0.05f;
glTranslatef(320.0f, 240.0f, 0.0f);
glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
//glRotatef(5.0f + 3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
//glRotatef(20.0f * cosf(f), 0.0f, 0.0f, 1.0f);
//glRotatef(30.0f, 0.0f, 0.0f, 1.0f);
#if 0
glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
glRotatef(8.0f * cosf(f), 0.0f, 0.0f, 1.0f);
#endif
glTranslatef(-320.0f, -240.0f, 0.0f);

for (int i = 0; i < data->ntiles; i++)


+ 2
- 2
src/sdlinput.cpp View File

@@ -35,14 +35,14 @@ SdlInput::SdlInput(Game *game)
data->game = game;
}

Asset::Group SdlInput::GetGroup()
Entity::Group SdlInput::GetGroup()
{
return GROUP_BEFORE;
}

void SdlInput::TickGame(float delta_time)
{
Asset::TickGame(delta_time);
Entity::TickGame(delta_time);

if (data->game->Finished())
destroy = 1;


+ 2
- 2
src/sdlinput.h View File

@@ -11,12 +11,12 @@
#if !defined __DH_SDLINPUT_H__
#define __DH_SDLINPUT_H__

#include "asset.h"
#include "entity.h"
#include "game.h"

class SdlInputData;

class SdlInput : public Asset
class SdlInput : public Entity
{
public:
SdlInput(Game *game);


+ 34
- 34
src/ticker.cpp View File

@@ -13,7 +13,7 @@

#include "profiler.h"
#include "ticker.h"
#include "asset.h"
#include "entity.h"
#include "timer.h"

/*
@@ -27,9 +27,9 @@ static class TickerData
public:
TickerData() :
todo(0),
nassets(0)
nentities(0)
{
for (int i = 0; i < Asset::GROUP_COUNT; i++)
for (int i = 0; i < Entity::GROUP_COUNT; i++)
list[i] = NULL;
bias = 0.0f;
}
@@ -37,16 +37,16 @@ public:
~TickerData()
{
#if !FINAL_RELEASE
if (nassets)
fprintf(stderr, "ERROR: still %i assets in ticker\n", nassets);
if (nentities)
fprintf(stderr, "ERROR: still %i entities in ticker\n", nentities);
#endif
}

private:
/* Asset management */
Asset *todo;
Asset *list[Asset::GROUP_COUNT];
int nassets;
/* Entity management */
Entity *todo;
Entity *list[Entity::GROUP_COUNT];
int nentities;

/* Fixed framerate management */
Timer timer;
@@ -60,13 +60,13 @@ static TickerData * const data = &tickerdata;
* Ticker public class
*/

void Ticker::Register(Asset *asset)
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 asset belongs to. Wait
* ready yet, so we do not know which group this entity belongs to. Wait
* until the first tick. */
asset->next = data->todo;
data->todo = asset;
entity->next = data->todo;
data->todo = entity;
}

void Ticker::TickGame()
@@ -82,8 +82,8 @@ void Ticker::TickGame()
/* 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 < Asset::GROUP_COUNT; i++)
for (Asset *a = data->list[i], *prev = NULL; a; prev = a, a = a->next)
for (int i = 0; i < Entity::GROUP_COUNT; i++)
for (Entity *a = data->list[i], *prev = NULL; a; prev = a, a = a->next)
if (a->destroy)
{
if (prev)
@@ -91,37 +91,37 @@ void Ticker::TickGame()
else
data->list[i] = a->next;

data->nassets--;
data->nentities--;
delete a;
}

/* Insert waiting objects into the appropriate lists */
while (data->todo)
{
Asset *a = data->todo;
Entity *a = data->todo;
data->todo = a->next;

int i = a->GetGroup();
a->next = data->list[i];
data->list[i] = a;
data->nassets++;
data->nentities++;
}

/* Tick objects for the game loop */
for (int i = 0; i < Asset::GROUP_COUNT; i++)
for (Asset *a = data->list[i]; a; a = a->next)
for (int i = 0; i < Entity::GROUP_COUNT; i++)
for (Entity *a = data->list[i]; a; a = a->next)
if (!a->destroy)
{
#if !FINAL_RELEASE
if (a->state != Asset::STATE_IDLE)
fprintf(stderr, "ERROR: asset not idle for game tick\n");
a->state = Asset::STATE_PRETICK_GAME;
if (a->state != Entity::STATE_IDLE)
fprintf(stderr, "ERROR: entity not idle for game tick\n");
a->state = Entity::STATE_PRETICK_GAME;
#endif
a->TickGame(data->delta_time);
#if !FINAL_RELEASE
if (a->state != Asset::STATE_POSTTICK_GAME)
fprintf(stderr, "ERROR: asset missed super game tick\n");
a->state = Asset::STATE_IDLE;
if (a->state != Entity::STATE_POSTTICK_GAME)
fprintf(stderr, "ERROR: entity missed super game tick\n");
a->state = Entity::STATE_IDLE;
#endif
}

@@ -133,20 +133,20 @@ void Ticker::TickRender()
Profiler::Start(Profiler::STAT_TICK_RENDER);

/* Tick objects for the render loop */
for (int i = 0; i < Asset::GROUP_COUNT; i++)
for (Asset *a = data->list[i]; a; a = a->next)
for (int i = 0; i < Entity::GROUP_COUNT; i++)
for (Entity *a = data->list[i]; a; a = a->next)
if (!a->destroy)
{
#if !FINAL_RELEASE
if (a->state != Asset::STATE_IDLE)
fprintf(stderr, "ERROR: asset not idle for render tick\n");
a->state = Asset::STATE_PRETICK_RENDER;
if (a->state != Entity::STATE_IDLE)
fprintf(stderr, "ERROR: entity not idle for render tick\n");
a->state = Entity::STATE_PRETICK_RENDER;
#endif
a->TickRender(data->delta_time);
#if !FINAL_RELEASE
if (a->state != Asset::STATE_POSTTICK_RENDER)
fprintf(stderr, "ERROR: asset missed super render tick\n");
a->state = Asset::STATE_IDLE;
if (a->state != Entity::STATE_POSTTICK_RENDER)
fprintf(stderr, "ERROR: entity missed super render tick\n");
a->state = Entity::STATE_IDLE;
#endif
}



+ 3
- 3
src/ticker.h View File

@@ -6,7 +6,7 @@
//
// The Ticker class
// ----------------
// The Ticker is a static class that registers assets and ticks them.
// The Ticker is a static class that registers entities and ticks them.
//

#if !defined __DH_TICKER_H__
@@ -14,12 +14,12 @@

#include <stdint.h>

#include "asset.h"
#include "entity.h"

class Ticker
{
public:
static void Register(Asset *asset);
static void Register(Entity *entity);

static void TickGame();
static void TickRender();


+ 2
- 2
src/tileset.cpp View File

@@ -74,14 +74,14 @@ TileSet::~TileSet()
delete data;
}

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

void TileSet::TickRender(float delta_time)
{
Asset::TickRender(delta_time);
Entity::TickRender(delta_time);

if (data->img)
{


+ 3
- 3
src/tileset.h View File

@@ -16,18 +16,18 @@

#include <stdint.h>

#include "asset.h"
#include "entity.h"

class TileSetData;

class TileSet : public Asset
class TileSet : public Entity
{
public:
TileSet(char const *path);
virtual ~TileSet();

protected:
/* Inherited from Asset */
/* Inherited from Entity */
virtual Group GetGroup();
virtual void TickRender(float delta_time);



Loading…
Cancel
Save