(svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
authorrubidium
Sun, 20 Apr 2008 08:22:59 +0000
changeset 9005 d6b0e0a54ef2
parent 9004 0f9d87665433
child 9006 7666e7b47088
(svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
src/animated_tile.cpp
src/animated_tile_func.h
src/functions.h
src/industry_cmd.cpp
src/misc.cpp
src/newgrf_house.cpp
src/newgrf_industrytiles.cpp
src/newgrf_station.cpp
src/openttd.cpp
src/station_cmd.cpp
src/texteff.cpp
src/town_map.h
src/vehicle.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/animated_tile.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -0,0 +1,135 @@
+/* $Id$ */
+
+/** @file animated_tile.cpp Everything related to animated tiles. */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "saveload.h"
+#include "landscape.h"
+#include "core/alloc_func.hpp"
+#include "functions.h"
+
+/** 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)
+{
+	for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
+		if (tile == *ti) {
+			/* Remove the hole
+			 * The order of the remaining elements must stay the same, otherwise the animation loop
+			 * may miss a tile; that's why we must use memmove instead of just moving the last element.
+			 */
+			memmove(ti, ti + 1, (_animated_tile_list + _animated_tile_count - (ti + 1)) * sizeof(*ti));
+			_animated_tile_count--;
+			MarkTileDirtyByTile(tile);
+			return;
+		}
+	}
+}
+
+/**
+ * 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)
+{
+	MarkTileDirtyByTile(tile);
+
+	for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
+		if (tile == *ti) return;
+	}
+
+	/* 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 = _animated_tile_list;
+	while (ti < _animated_tile_list + _animated_tile_count) {
+		const TileIndex curr = *ti;
+		AnimateTile(curr);
+		/* During the AnimateTile call, DeleteAnimatedTile could have been called,
+		 * deleting an element we've already processed and pushing the rest one
+		 * slot to the left. We can detect this by checking whether the index
+		 * in the current slot has changed - if it has, an element has been deleted,
+		 * and we should process the current slot again instead of going forward.
+		 * NOTE: this will still break if more than one animated tile is being
+		 *       deleted during the same AnimateTile call, but no code seems to
+		 *       be doing this anyway.
+		 */
+		if (*ti == curr) ++ti;
+	}
+}
+
+/**
+ * Initialize all animated tile variables to some known begin point
+ */
+void InitializeAnimatedTiles()
+{
+	_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, 256);
+	_animated_tile_count = 0;
+	_animated_tile_allocated = 256;
+}
+
+/**
+ * Save the ANIT chunk.
+ */
+static void Save_ANIT()
+{
+	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', Save_ANIT, Load_ANIT, CH_RIFF | CH_LAST},
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/animated_tile_func.h	Sun Apr 20 08:22:59 2008 +0000
@@ -0,0 +1,15 @@
+/* $Id$ */
+
+/** @file animated_tile.h Tile animation! */
+
+#ifndef ANIMATED_TILE_H
+#define ANIMATED_TILE_H
+
+#include "tile_type.h"
+
+void AddAnimatedTile(TileIndex tile);
+void DeleteAnimatedTile(TileIndex tile);
+void AnimateAnimatedTiles();
+void InitializeAnimatedTiles();
+
+#endif /* ANIMATED_TILE_H */
--- a/src/functions.h	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/functions.h	Sun Apr 20 08:22:59 2008 +0000
@@ -22,12 +22,6 @@
 bool CheckOwnership(Owner owner);
 bool CheckTileOwnership(TileIndex tile);
 
-/* texteff.cpp */
-void AddAnimatedTile(TileIndex tile);
-void DeleteAnimatedTile(TileIndex tile);
-void AnimateAnimatedTiles();
-void InitializeAnimatedTiles();
-
 /* misc_cmd.cpp */
 void PlaceTreesRandomly();
 
--- a/src/industry_cmd.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/industry_cmd.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -39,6 +39,7 @@
 #include "sound_func.h"
 #include "station_base.h"
 #include "oldpool_func.h"
+#include "animated_tile_func.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/misc.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/misc.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -25,6 +25,7 @@
 #include "texteff.hpp"
 #include "gfx_func.h"
 #include "core/alloc_type.hpp"
+#include "animated_tile_func.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/newgrf_house.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/newgrf_house.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -21,6 +21,7 @@
 #include "transparency.h"
 #include "functions.h"
 #include "player_func.h"
+#include "animated_tile_func.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
--- a/src/newgrf_industrytiles.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/newgrf_industrytiles.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -23,6 +23,7 @@
 #include "functions.h"
 #include "town.h"
 #include "command_func.h"
+#include "animated_tile_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/newgrf_station.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/newgrf_station.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -22,6 +22,7 @@
 #include "gfx_func.h"
 #include "date_func.h"
 #include "player_func.h"
+#include "animated_tile_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/openttd.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/openttd.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -58,6 +58,7 @@
 #include "date_func.h"
 #include "vehicle_func.h"
 #include "cheat_func.h"
+#include "animated_tile_func.h"
 
 #include "newgrf.h"
 #include "newgrf_config.h"
--- a/src/station_cmd.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/station_cmd.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -42,6 +42,7 @@
 #include "string_func.h"
 #include "signal_func.h"
 #include "oldpool_func.h"
+#include "animated_tile_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
--- a/src/texteff.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/texteff.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -4,10 +4,8 @@
 
 #include "stdafx.h"
 #include "openttd.h"
-#include "tile_cmd.h"
 #include "landscape.h"
 #include "gfx_func.h"
-#include "saveload.h"
 #include "console.h"
 #include "variables.h"
 #include "blitter/factory.hpp"
@@ -423,128 +421,3 @@
 		default: NOT_REACHED();
 	}
 }
-
-/** 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)
-{
-	for (TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
-		if (tile == *ti) {
-			/* Remove the hole
-			 * The order of the remaining elements must stay the same, otherwise the animation loop
-			 * may miss a tile; that's why we must use memmove instead of just moving the last element.
-			 */
-			memmove(ti, ti + 1, (_animated_tile_list + _animated_tile_count - (ti + 1)) * sizeof(*ti));
-			_animated_tile_count--;
-			MarkTileDirtyByTile(tile);
-			return;
-		}
-	}
-}
-
-/**
- * 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)
-{
-	MarkTileDirtyByTile(tile);
-
-	for (const TileIndex *ti = _animated_tile_list; ti < _animated_tile_list + _animated_tile_count; ti++) {
-		if (tile == *ti) return;
-	}
-
-	/* 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 = _animated_tile_list;
-	while (ti < _animated_tile_list + _animated_tile_count) {
-		const TileIndex curr = *ti;
-		AnimateTile(curr);
-		/* During the AnimateTile call, DeleteAnimatedTile could have been called,
-		 * deleting an element we've already processed and pushing the rest one
-		 * slot to the left. We can detect this by checking whether the index
-		 * in the current slot has changed - if it has, an element has been deleted,
-		 * and we should process the current slot again instead of going forward.
-		 * NOTE: this will still break if more than one animated tile is being
-		 *       deleted during the same AnimateTile call, but no code seems to
-		 *       be doing this anyway.
-		 */
-		if (*ti == curr) ++ti;
-	}
-}
-
-/**
- * Initialize all animated tile variables to some known begin point
- */
-void InitializeAnimatedTiles()
-{
-	_animated_tile_list = ReallocT<TileIndex>(_animated_tile_list, 256);
-	_animated_tile_count = 0;
-	_animated_tile_allocated = 256;
-}
-
-/**
- * Save the ANIT chunk.
- */
-static void Save_ANIT()
-{
-	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', Save_ANIT, Load_ANIT, CH_RIFF | CH_LAST},
-};
--- a/src/town_map.h	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/town_map.h	Sun Apr 20 08:22:59 2008 +0000
@@ -9,6 +9,7 @@
 #include "date_func.h"
 #include "tile_map.h"
 #include "functions.h"
+#include "animated_tile_func.h"
 
 /**
  * Get the index of which town this house/street is attached to.
--- a/src/vehicle.cpp	Sat Apr 19 23:34:42 2008 +0000
+++ b/src/vehicle.cpp	Sun Apr 20 08:22:59 2008 +0000
@@ -47,6 +47,7 @@
 #include "settings_type.h"
 #include "oldpool_func.h"
 #include "depot_map.h"
+#include "animated_tile_func.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"