From 7415b9cca278e86db5ba00b84aa535057279ef37 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 14 May 2011 17:25:45 +0000 Subject: (svn r22456) -Codechange: Derive NewGRFSpriteLayout from DrawTileSprites for spritelayouts allocated on the heap, and make use of constructors and destructors. --- src/newgrf_commons.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/newgrf_commons.cpp') 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(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(num_sprites + 1); + sprites[num_sprites].MakeTerminator(); + this->seq = sprites; +} -- cgit v1.2.3-54-g00ecf