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.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/newgrf_commons.h') diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index 171ccf759..1ddfdc181 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -16,14 +16,42 @@ #define NEWGRF_COMMONS_H #include "tile_type.h" +#include "sprite.h" +#include "core/alloc_type.hpp" -/** Contextx for tile accesses */ +/** Context for tile accesses */ enum TileContext { TCX_NORMAL, ///< Nothing special. TCX_UPPER_HALFTILE, ///< Querying information about the upper part of a tile with halftile foundation. TCX_ON_BRIDGE, ///< Querying information about stuff on the bridge (via some bridgehead). }; +/** + * NewGRF supplied spritelayout. + * In contrast to #DrawTileSprites this struct is for allocated + * layouts on the heap. It allocates data and frees them on destruction. + */ +struct NewGRFSpriteLayout : ZeroedMemoryAllocator, DrawTileSprites { + void Allocate(uint num_sprites); + void Clone(const DrawTileSeqStruct *source); + + /** + * Clone a spritelayout. + * @param source The spritelayout to copy. + */ + void Clone(const DrawTileSprites *source) + { + assert(source != NULL && this != source); + this->ground = source->ground; + this->Clone(source->seq); + } + + virtual ~NewGRFSpriteLayout() + { + free(const_cast(this->seq)); + } +}; + /** * Maps an entity id stored on the map to a GRF file. * Entities are objects used ingame (houses, industries, industry tiles) for -- cgit v1.2.3-54-g00ecf