0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 09:03:42 +00:00

added new Map for tile-textures as they wont work with our current enum-class maps.

This commit is contained in:
freezarite 2024-11-17 16:59:46 +01:00
parent 1a8a196e95
commit ac217e931b
3 changed files with 23 additions and 3 deletions

View File

@ -23,7 +23,11 @@ class TextureManager
SDL_Texture* loadTexture(Textures texture);
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);
static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false);
SDL_Texture* loadMapTileTexture(const char* path);
private:
Manager* manager;
std::map<Textures, SDL_Texture*> texture_cache;
std::map<std::string, SDL_Texture*> mapTile_texture_cache;
};

View File

@ -104,7 +104,7 @@ void Map::loadTileLayer(const tmx::TileLayer& layer)
tmx::Vector2i textureSize;
SDL_QueryTexture(
VEGO_Game().textureManager->loadTexture(texturePath),
VEGO_Game().textureManager->loadMapTileTexture(texturePath),
nullptr,
nullptr,
&(textureSize.x),
@ -170,6 +170,7 @@ void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int
tile.addComponent<TransformComponent>(x, y, mapTileSize.x, mapTileSize.y, 1);
tile.addComponent<SpriteComponent>(texturePath.c_str(), v, u, zIndex); // why does uv need to be reversed?
//TODO: also implement updated map stuff for this
if (hasCollision) {
// tag currently does not have a clear purposes, TODO: figure out appropriate tag name

View File

@ -3,12 +3,14 @@
#include <memory>
#include <stdexcept>
#include <string>
#include <VEGO.h>
#include <linux/soundcard.h>
#include "GameInternal.h"
void TextureManager::addSingleTexture(Textures texture, const char* filePath) {
auto sdlTexture = IMG_LoadTexture(this->manager->getGame()->renderer, filePath);
auto sdlTexture = IMG_LoadTexture(VEGO_Game().renderer, filePath);
if (sdlTexture == nullptr)
throw std::runtime_error(std::string("Couldn't load texture '") + filePath + "'");
@ -39,3 +41,16 @@ void TextureManager::draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect
SDL_RendererFlip flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
SDL_RenderCopyEx(renderer, texture, &src, &dest, 0, NULL, flip);
}
SDL_Texture* TextureManager::loadMapTileTexture(const char *path) {
//returns tile if it exists already
if(mapTile_texture_cache.contains(std::string(path)))
return mapTile_texture_cache.at(std::string(path));
auto newTexture = IMG_LoadTexture(VEGO_Game().renderer, path);
this->mapTile_texture_cache.emplace(std::string(path), newTexture);
return newTexture;
}