Switched around the texutre manager a bit internally, functions the same but it uses a Texture struct now
This commit is contained in:
3
TODO.txt
3
TODO.txt
@@ -16,6 +16,9 @@ x -> complete
|
|||||||
[x] Dot product
|
[x] Dot product
|
||||||
[x] Cross product (3d)
|
[x] Cross product (3d)
|
||||||
[ ] Other functions for max, min, magnitude, unitvec all that
|
[ ] Other functions for max, min, magnitude, unitvec all that
|
||||||
|
[ ] Resource management
|
||||||
|
[ ] Texture map class, owned by entity, stores texture references from the textrue manager
|
||||||
|
[ ] Sound at some point
|
||||||
[ ] Entity system
|
[ ] Entity system
|
||||||
[ ] Entity manager
|
[ ] Entity manager
|
||||||
[ ] Ability to make entities and manage textures between them
|
[ ] Ability to make entities and manage textures between them
|
||||||
|
|||||||
Binary file not shown.
@@ -20,8 +20,8 @@ bool TextureManager::registerTexture(std::string textureSource, std::string text
|
|||||||
}
|
}
|
||||||
SDL_FreeSurface(loadSurface);
|
SDL_FreeSurface(loadSurface);
|
||||||
|
|
||||||
m_textureSources[textureName] = textureSource;
|
Texture* temp = new Texture(textureName, textureSource, texture);
|
||||||
m_registerdTextures[textureName] = texture;
|
m_registerdTextures[textureName] = temp;
|
||||||
|
|
||||||
Logger::info("Loaded texture " + textureSource + " as " + textureName);
|
Logger::info("Loaded texture " + textureSource + " as " + textureName);
|
||||||
|
|
||||||
@@ -29,22 +29,21 @@ bool TextureManager::registerTexture(std::string textureSource, std::string text
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureManager::unregisterTexture(std::string textureName) {
|
void TextureManager::unregisterTexture(std::string textureName) {
|
||||||
SDL_DestroyTexture(m_registerdTextures[textureName]);
|
SDL_DestroyTexture(m_registerdTextures[textureName]->texture);
|
||||||
|
|
||||||
delete &m_textureSources[textureName];
|
|
||||||
delete &m_registerdTextures[textureName];
|
delete &m_registerdTextures[textureName];
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Texture* TextureManager::getTexture(std::string textureName) {
|
SDL_Texture* TextureManager::getTexture(std::string textureName) {
|
||||||
return m_registerdTextures[textureName];
|
return m_registerdTextures[textureName]->texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TextureManager::getTextureSource(std::string textureName) {
|
std::string TextureManager::getTextureSource(std::string textureName) {
|
||||||
return m_textureSources[textureName];
|
return m_registerdTextures[textureName]->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureManager::~TextureManager() {
|
TextureManager::~TextureManager() {
|
||||||
for (std::map<std::string, SDL_Texture*>::iterator it = m_registerdTextures.begin(); it != m_registerdTextures.end(); it++) {
|
for (std::map<std::string, Texture*>::iterator it = m_registerdTextures.begin(); it != m_registerdTextures.end(); it++) {
|
||||||
SDL_DestroyTexture(m_registerdTextures[it->first]);
|
SDL_DestroyTexture(m_registerdTextures[it->first]->texture);
|
||||||
|
delete m_registerdTextures[it->first];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,16 @@
|
|||||||
|
|
||||||
#include "../renderengine/renderer.h"
|
#include "../renderengine/renderer.h"
|
||||||
|
|
||||||
|
struct Texture {
|
||||||
|
Texture(std::string name, std::string source, SDL_Texture* texture)
|
||||||
|
: name(name), source(source), texture(texture) { }
|
||||||
|
Texture(std::string name, std::string source)
|
||||||
|
: name(name), source(source) { }
|
||||||
|
std::string name;
|
||||||
|
std::string source;
|
||||||
|
SDL_Texture* texture;
|
||||||
|
};
|
||||||
|
|
||||||
class TextureManager {
|
class TextureManager {
|
||||||
public:
|
public:
|
||||||
TextureManager(Renderer* renderer);
|
TextureManager(Renderer* renderer);
|
||||||
@@ -19,7 +29,6 @@ public:
|
|||||||
|
|
||||||
virtual ~TextureManager();
|
virtual ~TextureManager();
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> m_textureSources;
|
std::map<std::string, Texture*> m_registerdTextures;
|
||||||
std::map<std::string, SDL_Texture*> m_registerdTextures;
|
|
||||||
Renderer* m_renderer;
|
Renderer* m_renderer;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user