(svn r15556) -Change: don't temporary malloc+free when encoding sprites, just reuse the same piece of allocated memory for each encoding.

This commit is contained in:
rubidium
2009-02-23 17:54:02 +00:00
parent 44821e60eb
commit 9ab8a2aab1
4 changed files with 66 additions and 23 deletions

View File

@@ -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;
};
/**