Threading for renderer, textures, entities, game state

This commit is contained in:
2026-03-11 09:01:10 +01:00
parent 755e14ad62
commit d748ca63a0
12 changed files with 218 additions and 30 deletions

33
src/renderer/texture.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <renderer/texture.hpp>
namespace Game::Renderer {
Texture::Texture(std::string& path, Renderer* renderer, std::string id)
: mTex(nullptr), mId(id) {
SDL_Surface* surf = IMG_Load(path.c_str());
if (!surf) {
ERROR("Failed to load image at " << path);
return;
}
mTex = SDL_CreateTextureFromSurface(renderer->getSDLRenderer(), surf);
SDL_DestroySurface(surf);
}
Texture::Texture(const Texture& other) {
// Copy the references, since copying memory would require re-initing a bunch of things - for now
this->mTex = other.mTex;
}
Texture& Texture::operator=(const Texture& other) {
// Same reasoning
this->mTex = other.mTex;
return *this;
}
Texture::~Texture() {
if (mTex)
SDL_DestroyTexture(mTex);
LOG("Destroyed texture '" << mId << "'")
}
}