From: Matthijs Kooijman Date: Mon, 11 Jun 2007 18:28:33 +0000 (+0200) Subject: * Make Sprite an IMMObject. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=c873a192c271934bf6202ff40278b9c9429e8c22;p=matthijs%2FABM2.git * Make Sprite an IMMObject. * Add SpriteManager (forgotten in last commit). SpriteManager now also stores CMMPointers instead of normal pointers. --- diff --git a/ABM2/Amaltheia/Sprite.h b/ABM2/Amaltheia/Sprite.h index f7a0c34..a58575d 100644 --- a/ABM2/Amaltheia/Sprite.h +++ b/ABM2/Amaltheia/Sprite.h @@ -22,6 +22,7 @@ #define _SPRITE #include "Graphics.h" +#include "Engine/mmanager.h" /* @@ -29,7 +30,7 @@ Class: Sprite Represents a sprite */ -class Sprite +class Sprite : public IMMObject { private: Texture *tex; @@ -74,7 +75,7 @@ parameters: dy - tile index in Y colour - the colour mask to use*/ void blit(int x, int y, float scalex, float scaley, int dx, int dy, colour c); - + AUTO_SIZE; }; #endif diff --git a/ABM2/Engine/SpriteManager.cpp b/ABM2/Engine/SpriteManager.cpp new file mode 100644 index 0000000..9a6fc24 --- /dev/null +++ b/ABM2/Engine/SpriteManager.cpp @@ -0,0 +1,26 @@ +#include "SpriteManager.h" + + + +CSpriteManager::CSpriteManager(Graphics *g, SpriteData *sd) +{ + /* Load all sprites */ + while (sd->id != 0) + { + /* Colour given is for transparency, Sprite has no constructor + * without a key colour... */ + Sprite* s = new Sprite(sd->filename, COLOUR_RGBA(248, 0, 248, 255), sd->width, sd->height, g); + if (s) { + /* Ensure the needed spot is present */ + while (this->loadedSprites.size() <= sd->id) + this->loadedSprites.push_back(NULL); + this->loadedSprites[sd->id] = CMMPointer(s); + } + sd++; + } +} + +CMMPointer CSpriteManager::getSprite(unsigned int id) +{ + return this->loadedSprites[id]; +} diff --git a/ABM2/Engine/SpriteManager.h b/ABM2/Engine/SpriteManager.h new file mode 100644 index 0000000..785bd02 --- /dev/null +++ b/ABM2/Engine/SpriteManager.h @@ -0,0 +1,29 @@ +#if !defined(SPRITE_MANAGER_H__INCLUDED) +#define SPRITE_MANAGER_H__INCLUDED + +#include +#include +#include "Engine/mmanager.h" +#include "Amaltheia/Sprite.h" +#include "Amaltheia/Graphics.h" + +/** + * Used to hold data about default sprites. + */ +struct SpriteData { + unsigned int id; + char* filename; + int width; + int height; +}; + + +class CSpriteManager +{ +public: + CSpriteManager(Graphics* g, SpriteData *sd); + CMMPointer getSprite(unsigned int id); +private: + std::vector< CMMPointer > loadedSprites; +}; +#endif // SPRITE_MANAGER_H__INCLUDED