0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 23:33:41 +00:00

Compare commits

..

1 Commits

8 changed files with 8 additions and 28 deletions

2
.gitignore vendored
View File

@ -6,8 +6,6 @@ Makefile
install_manifest.txt install_manifest.txt
.cache/ .cache/
build/ build/
cmake-build-debug/
.idea/
# Compiled files # Compiled files
*.suo *.suo

View File

@ -36,12 +36,14 @@ public:
void addMusic(std::string id, const char* path); void addMusic(std::string id, const char* path);
SDL_Texture* getTexture(std::string id);
Mix_Chunk* getSound(std::string id); Mix_Chunk* getSound(std::string id);
Mix_Music* getMusic(std::string id); Mix_Music* getMusic(std::string id);
private: private:
Manager* man; Manager* man;
std::map<std::string, SDL_Texture*> textures;
std::map<std::string, Mix_Chunk*> soundEffects; std::map<std::string, Mix_Chunk*> soundEffects;
std::map<std::string, Mix_Music*> music; std::map<std::string, Mix_Music*> music;
}; };

View File

@ -51,7 +51,6 @@ public:
~SpriteComponent(); ~SpriteComponent();
void setTexture(Textures texture); void setTexture(Textures texture);
void setMapTileTexture(const char* path);
void init() override; void init() override;
void update() override; void update() override;

View File

@ -16,9 +16,6 @@ class TextureManager
for (auto& it : this->texture_cache) { for (auto& it : this->texture_cache) {
SDL_DestroyTexture(it.second); SDL_DestroyTexture(it.second);
} }
for (auto& it : this->mapTile_texture_cache) {
SDL_DestroyTexture(it.second);
}
} }
void addSingleTexture(Textures texture, const char* filePath); void addSingleTexture(Textures texture, const char* filePath);

View File

@ -31,6 +31,9 @@ void AssetManager::addMusic(std::string id, const char* path)
music.emplace(id, this->man->getGame()->soundManager->loadMusic(path)); music.emplace(id, this->man->getGame()->soundManager->loadMusic(path));
} }
SDL_Texture* AssetManager::getTexture(std::string id) {
return textures.at(id);
}
Mix_Chunk* AssetManager::getSound(std::string id) { Mix_Chunk* AssetManager::getSound(std::string id) {
return soundEffects.at(id); return soundEffects.at(id);

View File

@ -98,8 +98,6 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
// loading music // loading music
// assets->addMusic("background_music", "assets/sound/background_music.mp3"); // assets->addMusic("background_music", "assets/sound/background_music.mp3");
this->gameInstance = GameFactory::instance().create(this); this->gameInstance = GameFactory::instance().create(this);
this->gameInstance->init(); this->gameInstance->init();
} }

View File

@ -3,7 +3,6 @@
#include <SDL_timer.h> #include <SDL_timer.h>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <magic_enum/magic_enum.hpp>
#include "AnimationHandler.h" #include "AnimationHandler.h"
#include "Direction.h" #include "Direction.h"
@ -19,13 +18,11 @@
SpriteComponent::SpriteComponent(Textures texture, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(0), textureYOffset(0) SpriteComponent::SpriteComponent(Textures texture, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(0), textureYOffset(0)
{ {
this->textureEnum = texture; this->textureEnum = texture;
this->path = "";
} }
SpriteComponent::SpriteComponent(Textures texture, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) SpriteComponent::SpriteComponent(Textures texture, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset)
{ {
this->textureEnum = texture; this->textureEnum = texture;
this->path = "";
} }
SpriteComponent::SpriteComponent(const char* path, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) { SpriteComponent::SpriteComponent(const char* path, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) {
@ -47,8 +44,6 @@ SpriteComponent::SpriteComponent(
playAnimation(defaultAnimation); playAnimation(defaultAnimation);
this->textureEnum = texture; this->textureEnum = texture;
this->path = "";
} }
SpriteComponent::~SpriteComponent() {} SpriteComponent::~SpriteComponent() {}
@ -60,12 +55,7 @@ void SpriteComponent::setTexture(Textures texture)
void SpriteComponent::init() void SpriteComponent::init()
{ {
if (this->path == "") { setTexture(this->textureEnum);
setTexture(this->textureEnum);
}
else {
setMapTileTexture(this->path);
}
this->transform = &entity->getComponent<TransformComponent>(); this->transform = &entity->getComponent<TransformComponent>();
@ -108,7 +98,3 @@ void SpriteComponent::setDirection(Direction direction)
{ {
this->flipped = direction == Direction::RIGHT; this->flipped = direction == Direction::RIGHT;
} }
void SpriteComponent::setMapTileTexture(const char *path) {
this->texture = VEGO_Game().textureManager->loadMapTileTexture(path);
}

View File

@ -46,13 +46,10 @@ SDL_Texture* TextureManager::loadMapTileTexture(const char *path) {
//returns tile if it exists already //returns tile if it exists already
if(mapTile_texture_cache.contains(std::string(path))) if(mapTile_texture_cache.contains(std::string(path)))
return mapTile_texture_cache.find(std::string(path))->second; return mapTile_texture_cache.at(std::string(path));
auto newTexture = IMG_LoadTexture(VEGO_Game().renderer, path); auto newTexture = IMG_LoadTexture(VEGO_Game().renderer, path);
if (newTexture == nullptr)
throw std::runtime_error(std::string("Couldn't load texture '") + path + "'");
this->mapTile_texture_cache.emplace(std::string(path), newTexture); this->mapTile_texture_cache.emplace(std::string(path), newTexture);
return newTexture; return newTexture;