diff options
author | rubidium <rubidium@openttd.org> | 2009-02-23 17:54:02 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-02-23 17:54:02 +0000 |
commit | 9ab8a2aab1783199fd5c33665ed891e4b487a7e8 (patch) | |
tree | 52608fad0b8c58f9fc141f8ff4e5d203be54f7fc /src/spriteloader | |
parent | 44821e60eb6bc9cb4eb1561c8a6d11c98a8f07ae (diff) | |
download | openttd-9ab8a2aab1783199fd5c33665ed891e4b487a7e8.tar.xz |
(svn r15556) -Change: don't temporary malloc+free when encoding sprites, just reuse the same piece of allocated memory for each encoding.
Diffstat (limited to 'src/spriteloader')
-rw-r--r-- | src/spriteloader/spriteloader.hpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/spriteloader/spriteloader.hpp b/src/spriteloader/spriteloader.hpp index 9b431fb4f..762831ae4 100644 --- a/src/spriteloader/spriteloader.hpp +++ b/src/spriteloader/spriteloader.hpp @@ -5,6 +5,8 @@ #ifndef SPRITELOADER_HPP #define SPRITELOADER_HPP +#include "../core/alloc_type.hpp" + class SpriteLoader { public: struct CommonPixel { @@ -22,9 +24,6 @@ public: * This to prevent thousands of malloc + frees just to load a sprite. */ struct Sprite { - Sprite() : data(NULL) {} - ~Sprite() { assert(this->data == NULL || this->data == Sprite::mem); } - uint16 height; ///< Height of the sprite uint16 width; ///< Width of the sprite int16 x_offs; ///< The x-offset of where the sprite will be drawn @@ -35,12 +34,10 @@ public: * Allocate the sprite data of this sprite. * @param size the minimum size of the data field. */ - void AllocateData(size_t size); + void AllocateData(size_t size) { this->data = Sprite::buffer.ZeroAllocate(size); } private: /** Allocated memory to pass sprite data around */ - static SpriteLoader::CommonPixel *mem; - /** Size (in items) of the above memory. */ - static size_t size; + static ReusableBuffer<SpriteLoader::CommonPixel> buffer; }; /** |