* Make Sprite an IMMObject.
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 18:28:33 +0000 (20:28 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 18:28:33 +0000 (20:28 +0200)
 * Add SpriteManager (forgotten in last commit). SpriteManager now also
 stores CMMPointers instead of normal pointers.

ABM2/Amaltheia/Sprite.h
ABM2/Engine/SpriteManager.cpp [new file with mode: 0644]
ABM2/Engine/SpriteManager.h [new file with mode: 0644]

index f7a0c347a885d6ad9e40c1109d537652d16a70a2..a58575daf8a6a0f712bcdcfa73dcad2d78577e3e 100644 (file)
@@ -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 (file)
index 0000000..9a6fc24
--- /dev/null
@@ -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<Sprite>(s);
+               }
+               sd++;
+       }
+}
+
+CMMPointer<Sprite> 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 (file)
index 0000000..785bd02
--- /dev/null
@@ -0,0 +1,29 @@
+#if !defined(SPRITE_MANAGER_H__INCLUDED)
+#define SPRITE_MANAGER_H__INCLUDED
+
+#include <vector>
+#include <cassert>
+#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<Sprite> getSprite(unsigned int id);
+private:
+       std::vector< CMMPointer<Sprite> > loadedSprites;
+};
+#endif // SPRITE_MANAGER_H__INCLUDED