summaryrefslogtreecommitdiff
path: root/src/spriteloader
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-23 17:54:02 +0000
committerrubidium <rubidium@openttd.org>2009-02-23 17:54:02 +0000
commit3ba802e99524797571e69ba57b6a30a12b031b72 (patch)
tree52608fad0b8c58f9fc141f8ff4e5d203be54f7fc /src/spriteloader
parent0c1b8ea602de72a96573b7e3301589e8e3249ca1 (diff)
downloadopenttd-3ba802e99524797571e69ba57b6a30a12b031b72.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.hpp11
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;
};
/**