summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-10-08 19:56:21 +0000
committerrubidium <rubidium@openttd.org>2007-10-08 19:56:21 +0000
commit91ac1310140ff093a7d7e310c8ce75baf71df35d (patch)
tree295671fd71cd266fc143493e768dba2346f91326 /src
parent2313b7a144e124734b1c474d00a1e6af585ad64f (diff)
downloadopenttd-91ac1310140ff093a7d7e310c8ce75baf71df35d.tar.xz
(svn r11228) -Codechange: implement the "moreanimation" feature of TTDP, so we can properly support newindustries.
Diffstat (limited to 'src')
-rw-r--r--src/functions.h2
-rw-r--r--src/newgrf.cpp2
-rw-r--r--src/oldloader.cpp9
-rw-r--r--src/saveload.cpp2
-rw-r--r--src/texteff.cpp108
5 files changed, 88 insertions, 35 deletions
diff --git a/src/functions.h b/src/functions.h
index 8ab4af5a1..f6df7a988 100644
--- a/src/functions.h
+++ b/src/functions.h
@@ -78,7 +78,7 @@ uint32 InteractiveRandom(); // Used for random sequences that are not the same o
uint InteractiveRandomRange(uint max);
/* texteff.cpp */
-bool AddAnimatedTile(TileIndex tile);
+void AddAnimatedTile(TileIndex tile);
void DeleteAnimatedTile(TileIndex tile);
void AnimateAnimatedTiles();
void InitializeAnimatedTiles();
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index fb24a9637..5c8ce421c 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -4705,7 +4705,7 @@ static void InitializeGRFSpecial()
| (1 << 0x19) // newhouses
| (1 << 0x1A) // newbridges
| (1 << 0x1B) // newtownnames
- | (0 << 0x1C) // moreanimations
+ | (1 << 0x1C) // moreanimation
| ((_patches.wagon_speed_limits ? 1 : 0) << 0x1D) // wagonspeedlimits
| (1 << 0x1E) // newshistory
| (0 << 0x1F); // custombridgeheads
diff --git a/src/oldloader.cpp b/src/oldloader.cpp
index e6227d9a4..a7b93fe92 100644
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -376,7 +376,8 @@ static void FixOldVehicles()
#define REMAP_TOWN_IDX(x) ((x) - (0x0459154 - 0x0458EF0)) / 94
#define REMAP_ORDER_IDX(x) ((x) - (0x045AB08 - 0x0458EF0)) / 2
-extern TileIndex _animated_tile_list[256];
+extern TileIndex *_animated_tile_list;
+extern uint _animated_tile_count;
extern char _name_array[512][32];
static byte _old_vehicle_multiplier;
@@ -1422,7 +1423,7 @@ static const OldChunks main_chunk[] = {
OCL_CHUNK(5000, LoadOldOrder ),
OCL_ASSERT( 0x4328 ),
- OCL_VAR ( OC_TILE, 256, &_animated_tile_list[0] ),
+ OCL_VAR ( OC_TILE, 256, _animated_tile_list ),
OCL_NULL( 4 ), ///< old end-of-order-list-pointer, no longer in use
OCL_CHUNK( 255, LoadOldDepot ),
@@ -1553,6 +1554,10 @@ static bool LoadOldMain(LoadgameState *ls)
_m[i].m4 = _old_map3[i * 2 + 1];
}
+ for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
+ if (_animated_tile_list[_animated_tile_count] == 0) break;
+ }
+
for (i = 0; i < OLD_MAP_SIZE; i ++) {
switch (GetTileType(i)) {
case MP_STATION:
diff --git a/src/saveload.cpp b/src/saveload.cpp
index 7782178c8..a3f531431 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -29,7 +29,7 @@
#include "strings.h"
#include <list>
-extern const uint16 SAVEGAME_VERSION = 79;
+extern const uint16 SAVEGAME_VERSION = 80;
uint16 _sl_version; ///< the major savegame version identifier
byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
diff --git a/src/texteff.cpp b/src/texteff.cpp
index 2bdd05c3d..c376e42b4 100644
--- a/src/texteff.cpp
+++ b/src/texteff.cpp
@@ -25,7 +25,6 @@ enum {
MAX_TEXTMESSAGE_LENGTH = 200,
INIT_NUM_TEXT_MESSAGES = 20,
MAX_CHAT_MESSAGES = 10,
- MAX_ANIMATED_TILES = 256,
};
struct TextEffect {
@@ -50,7 +49,6 @@ struct ChatMessage {
/* used for text effects */
static TextEffect *_text_effect_list = NULL;
static uint16 _num_text_effects = INIT_NUM_TEXT_MESSAGES;
-TileIndex _animated_tile_list[MAX_ANIMATED_TILES];
/* used for chat window */
static ChatMessage _chatmsg_list[MAX_CHAT_MESSAGES];
@@ -422,62 +420,112 @@ void DrawTextEffects(DrawPixelInfo *dpi)
}
}
+/** The table/list with animated tiles. */
+TileIndex *_animated_tile_list = NULL;
+/** The number of animated tiles in the current state. */
+uint _animated_tile_count = 0;
+/** The number of slots for animated tiles allocated currently. */
+static uint _animated_tile_allocated = 0;
+
+/**
+ * Removes the given tile from the animated tile table.
+ * @param tile the tile to remove
+ */
void DeleteAnimatedTile(TileIndex tile)
{
- TileIndex *ti;
-
- for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
+ for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
if (tile == *ti) {
- /* remove the hole */
- memmove(ti, ti + 1, (lastof(_animated_tile_list) - ti) * sizeof(*ti));
- /* and clear last item */
- *lastof(_animated_tile_list) = 0;
+ /* Remove the hole */
+ *ti = _animated_tile_list[_animated_tile_count - 1];
+ _animated_tile_count--;
MarkTileDirtyByTile(tile);
return;
}
}
}
-bool AddAnimatedTile(TileIndex tile)
+/**
+ * Add the given tile to the animated tile table (if it does not exist
+ * on that table yet). Also increases the size of the table if necessary.
+ * @param tile the tile to make animated
+ */
+void AddAnimatedTile(TileIndex tile)
{
- TileIndex *ti;
+ MarkTileDirtyByTile(tile);
- for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
- if (tile == *ti || *ti == 0) {
- *ti = tile;
- MarkTileDirtyByTile(tile);
- return true;
- }
+ for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
+ if (tile == *ti) return;
}
- return false;
+ /* Table not large enough, so make it larger */
+ if (_animated_tile_count == _animated_tile_allocated) {
+ _animated_tile_allocated *= 2;
+ _animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, _animated_tile_allocated);
+ }
+
+ _animated_tile_list[_animated_tile_count] = tile;
+ _animated_tile_count++;
}
+/**
+ * Animate all tiles in the animated tile list, i.e.\ call AnimateTile on them.
+ */
void AnimateAnimatedTiles()
{
- const TileIndex* ti;
-
- for (ti = _animated_tile_list; ti != endof(_animated_tile_list) && *ti != 0; ti++) {
+ for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
AnimateTile(*ti);
}
}
+/**
+ * Initialize all animated tile variables to some known begin point
+ */
void InitializeAnimatedTiles()
{
- memset(_animated_tile_list, 0, sizeof(_animated_tile_list));
+ _animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, 256);
+ _animated_tile_count = 0;
+ _animated_tile_allocated = 256;
}
-static void SaveLoad_ANIT()
+/**
+ * Save the ANIT chunk.
+ */
+static void Save_ANIT()
{
- /* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
- if (CheckSavegameVersion(6)) {
- SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_FILE_U16 | SLE_VAR_U32);
- } else {
- SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32);
- }
+ SlSetLength(_animated_tile_count * sizeof(*_animated_tile_list));
+ SlArray(_animated_tile_list, _animated_tile_count, SLE_UINT32);
}
+/**
+ * Load the ANIT chunk; the chunk containing the animated tiles.
+ */
+static void Load_ANIT()
+{
+ /* Before version 80 we did NOT have a variable length animated tile table */
+ if (CheckSavegameVersion(80)) {
+ /* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
+ SlArray(_animated_tile_list, 256, CheckSavegameVersion(6) ? (SLE_FILE_U16 | SLE_VAR_U32) : SLE_UINT32);
+ for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
+ if (_animated_tile_list[_animated_tile_count] == 0) break;
+ }
+ return;
+ }
+
+ _animated_tile_count = SlGetFieldLength() / sizeof(*_animated_tile_list);
+
+ /* Determine a nice rounded size for the amount of allocated tiles */
+ _animated_tile_allocated = 256;
+ while (_animated_tile_allocated < _animated_tile_count) _animated_tile_allocated *= 2;
+
+ _animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, _animated_tile_allocated);
+ SlArray(_animated_tile_list, _animated_tile_count, SLE_UINT32);
+}
+
+/**
+ * "Definition" imported by the saveload code to be able to load and save
+ * the animated tile table.
+ */
extern const ChunkHandler _animated_tile_chunk_handlers[] = {
- { 'ANIT', SaveLoad_ANIT, SaveLoad_ANIT, CH_RIFF | CH_LAST},
+ { 'ANIT', Save_ANIT, Load_ANIT, CH_RIFF | CH_LAST},
};