From 4d63ad6ada87d5b838d7430270f7f7eecafcb740 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 21 Aug 2010 02:20:33 +0000 Subject: [PATCH] Rename "asset" to "entity". It's way cooler. --- src/Makefile.am | 2 +- src/debugfps.cpp | 4 +-- src/debugfps.h | 4 +-- src/debugrecord.cpp | 6 ++-- src/debugrecord.h | 4 +-- src/debugsprite.cpp | 6 ++-- src/debugsprite.h | 4 +-- src/{asset.cpp => entity.cpp} | 24 ++++++------- src/{asset.h => entity.h} | 20 +++++------ src/font.cpp | 4 +-- src/font.h | 6 ++-- src/game.cpp | 8 ++--- src/game.h | 6 ++-- src/gtk/editor.cpp | 2 +- src/scene.cpp | 17 +++++++-- src/sdlinput.cpp | 4 +-- src/sdlinput.h | 4 +-- src/ticker.cpp | 68 +++++++++++++++++------------------ src/ticker.h | 6 ++-- src/tileset.cpp | 4 +-- src/tileset.h | 6 ++-- 21 files changed, 110 insertions(+), 99 deletions(-) rename src/{asset.cpp => entity.cpp} (60%) rename src/{asset.h => entity.h} (73%) diff --git a/src/Makefile.am b/src/Makefile.am index 9311bb4b..d955da8a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/debugfps.cpp b/src/debugfps.cpp index 13011e03..b963a8bd 100644 --- a/src/debugfps.cpp +++ b/src/debugfps.cpp @@ -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++; diff --git a/src/debugfps.h b/src/debugfps.h index 7c4e0bff..dfb50555 100644 --- a/src/debugfps.h +++ b/src/debugfps.h @@ -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(); diff --git a/src/debugrecord.cpp b/src/debugrecord.cpp index 7e5265c0..fa33ace1 100644 --- a/src/debugrecord.cpp +++ b/src/debugrecord.cpp @@ -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(); diff --git a/src/debugrecord.h b/src/debugrecord.h index cf1404bf..7ebd09f5 100644 --- a/src/debugrecord.h +++ b/src/debugrecord.h @@ -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); diff --git a/src/debugsprite.cpp b/src/debugsprite.cpp index 363dbd8b..f60bc96b 100644 --- a/src/debugsprite.cpp +++ b/src/debugsprite.cpp @@ -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); diff --git a/src/debugsprite.h b/src/debugsprite.h index 9e00136e..c5787299 100644 --- a/src/debugsprite.h +++ b/src/debugsprite.h @@ -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); diff --git a/src/asset.cpp b/src/entity.cpp similarity index 60% rename from src/asset.cpp rename to src/entity.cpp index b9229283..f72a5feb 100644 --- a/src/asset.cpp +++ b/src/entity.cpp @@ -10,14 +10,14 @@ #include #include -#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; } diff --git a/src/asset.h b/src/entity.h similarity index 73% rename from src/asset.h rename to src/entity.h index 6aa1a97a..f85db501 100644 --- a/src/asset.h +++ b/src/entity.h @@ -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 -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__ diff --git a/src/font.cpp b/src/font.cpp index 9b491faf..f7d342ec 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -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() diff --git a/src/font.h b/src/font.h index 04e1d026..1c54c707 100644 --- a/src/font.h +++ b/src/font.h @@ -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); diff --git a/src/game.cpp b/src/game.cpp index 39dd7f36..4ec84218 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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(); diff --git a/src/game.h b/src/game.h index 22b4ef09..c2ea0d9f 100644 --- a/src/game.h +++ b/src/game.h @@ -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); diff --git a/src/gtk/editor.cpp b/src/gtk/editor.cpp index c6b5a974..6e748f2c 100644 --- a/src/gtk/editor.cpp +++ b/src/gtk/editor.cpp @@ -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; diff --git a/src/scene.cpp b/src/scene.cpp index 08446f68..03a58b62 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -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++) diff --git a/src/sdlinput.cpp b/src/sdlinput.cpp index ee89be1a..23396ba7 100644 --- a/src/sdlinput.cpp +++ b/src/sdlinput.cpp @@ -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; diff --git a/src/sdlinput.h b/src/sdlinput.h index 4a1582b5..e1224fb4 100644 --- a/src/sdlinput.h +++ b/src/sdlinput.h @@ -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); diff --git a/src/ticker.cpp b/src/ticker.cpp index bd9eb66c..aa453088 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -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 } diff --git a/src/ticker.h b/src/ticker.h index 0f33b6a7..84acf597 100644 --- a/src/ticker.h +++ b/src/ticker.h @@ -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 -#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(); diff --git a/src/tileset.cpp b/src/tileset.cpp index e09d8539..1efc707b 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -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) { diff --git a/src/tileset.h b/src/tileset.h index 7ad37101..b47fecb4 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -16,18 +16,18 @@ #include -#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);