summaryrefslogtreecommitdiff
path: root/src/newgrf_commons.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-05-14 17:25:45 +0000
committerfrosch <frosch@openttd.org>2011-05-14 17:25:45 +0000
commit7415b9cca278e86db5ba00b84aa535057279ef37 (patch)
tree9f01e323319a68661a0ebcd8d846fdf52c70e0d3 /src/newgrf_commons.cpp
parent3183cb79079a20739e68966de2c0c0356e3c67b1 (diff)
downloadopenttd-7415b9cca278e86db5ba00b84aa535057279ef37.tar.xz
(svn r22456) -Codechange: Derive NewGRFSpriteLayout from DrawTileSprites for spritelayouts allocated on the heap, and make use of constructors and destructors.
Diffstat (limited to 'src/newgrf_commons.cpp')
-rw-r--r--src/newgrf_commons.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index edb3212bf..ce4a6807a 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -434,3 +434,34 @@ uint32 GetNearbyTileInformation(TileIndex tile)
byte terrain_type = GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1;
return tile_type << 24 | z << 16 | terrain_type << 8 | tileh;
}
+
+/**
+ * Clone the building sprites of a spritelayout.
+ * @param source The building sprites to copy.
+ */
+void NewGRFSpriteLayout::Clone(const DrawTileSeqStruct *source)
+{
+ assert(this->seq == NULL);
+ assert(source != NULL);
+
+ size_t count = 1; // 1 for the terminator
+ const DrawTileSeqStruct *element;
+ foreach_draw_tile_seq(element, source) count++;
+
+ DrawTileSeqStruct *sprites = MallocT<DrawTileSeqStruct>(count);
+ MemCpyT(sprites, source, count);
+ this->seq = sprites;
+}
+
+/**
+ * Allocate a spritelayout for \a num_sprites building sprites.
+ * @param num_sprites Number of building sprites to allocate memory for. (not counting the terminator)
+ */
+void NewGRFSpriteLayout::Allocate(uint num_sprites)
+{
+ assert(this->seq == NULL);
+
+ DrawTileSeqStruct *sprites = CallocT<DrawTileSeqStruct>(num_sprites + 1);
+ sprites[num_sprites].MakeTerminator();
+ this->seq = sprites;
+}