Commits

Mihael Peklar committed e4b053f Merge

Merged with bdemovic.

  • Participants
  • Parent commits 412e4b2, dfa26ef

Comments (0)

Files changed (5)

 CFLAGS=$(MY_CFLAGS)
 CXXFLAGS=$(MY_CXXFLAGS)
 LDFLAGS=-lSDL -lSDL_mixer -lSDL_image -lSDL_ttf -lGL -lGLU $(MY_LDFLAGS)
-OBJECTS=audiomgr.o    gamemode.o    gm_battle.o   texture.o  map.o tile.o tileset.o thecombat.o unit.o font.o button.o tiledesc.o order.o unitcontainer.o
+OBJECTS=audiomgr.o    gamemode.o    gm_battle.o   texture.o  map.o tile.o tileset.o thecombat.o unit.o font.o button.o tiledesc.o order.o unitcontainer.o  texture_manager.o
 
 all: thecombat
 

File skirmish1.thecombatmap

-6 6
+12 12
 test.tileset
-1 1 1 1 1 1
-1 0 2 2 1 1
-1 2 1 2 1 1
-1 1 1 1 1 1
-1 2 2 2 2 1
-2 2 2 2 2 2
+1 1 1 1 1 1 1 1 1 1 1 1
+1 0 2 2 1 1 1 0 2 2 1 1
+1 2 1 2 1 1 1 0 2 2 1 1
+1 1 1 1 1 1 1 0 2 2 1 1
+1 2 2 2 2 1 1 0 2 2 1 1
+2 2 2 2 2 2 1 1 1 1 1 1
+1 0 2 2 1 1 1 0 2 2 1 1
+1 2 1 2 1 1 1 0 2 2 1 1
+1 1 1 1 1 1 1 0 2 2 1 1
+1 2 2 2 2 1 1 0 2 2 1 1
+2 2 2 2 2 2 1 0 2 2 1 1
+1 1 1 1 1 1 1 0 2 2 1 1
+

File texture_manager.cpp

+#include "texture_manager.h"
+#include "texture.h"
+
+#include<map>
+#include<string>
+
+TextureManager* TextureManager::instance;
+TextureManager::TextureManager()
+{
+	isLoadedBool=false;
+}
+
+
+TextureManager::~TextureManager(){}
+
+
+Texture* TextureManager::getTexture(std::string filename)
+{
+	if(textures.count(filename)==0)
+	{
+		Texture *tmpTexture = new Texture(filename);
+		texturesIter=textures.end();
+		textures.insert(texturesIter, std::pair<std::string, Texture*>(filename, tmpTexture));
+		return tmpTexture;
+		
+	}
+	else
+	{
+		return textures.find(filename)->second;
+	}
+	
+}

File texture_manager.h

+#ifndef TEXTURE_MANAGER_INCLUDED
+#define TEXTURE_MANAGER_INCLUDED
+
+#include <map>
+#include "texture.h"
+#include <string>
+
+class TextureManager
+{
+	public:
+		TextureManager();
+		~TextureManager();
+
+		static TextureManager* getInstance()
+		{
+			if(!instance)
+				instance = new TextureManager();
+
+			return instance;
+		}
+		
+		
+		
+		static void destroyInstance() { delete instance; instance = NULL; }
+
+		bool isLoaded() { return isLoadedBool; }
+	
+		Texture *getTexture(std::string filename);
+		
+		
+		
+		
+	private:
+		std::map<std::string,Texture*> textures;
+		std::map<std::string,Texture*>::iterator texturesIter;
+		
+		bool isLoadedBool;
+		static TextureManager* instance;
+
+};
+
+
+
+#endif
 #include<cstdlib>
 #include "unit.h"
 #include "texture.h"
+#include "texture_manager.h"
 #include"order.h"
 
 #define SGN(x) ((x) ? (x)/(x) : 0)
 
 Unit::Unit()
 {
-	this->tex = new Texture("zombie.png");
-	this->selector =new Texture("selector.png");
+	this->tex = TextureManager::getInstance()->getTexture("zombie.png");
+	this->selector = TextureManager::getInstance()->getTexture("selector.png");
 	this->aniProgress = 0;
 	this->dir = 6;
 
 	{
 		
 		glColor4f(1.0,1.0,1.0,1.0);
-			this->_paintSelector(getX(), getY() + 16, getWidth(), getHeight());
+		this->_paintSelector(getX(), getY() + 16, getWidth(), getHeight());
 	
 		
 	}