/* * 2D Game Engine * AssetStore.cpp: * Based on pikuma.com 2D game engine in C++ and Lua course * Copyright (c) 2021 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 12/02/2021. */ #include #include #include #include void AssetStore::clearStore() { for(auto texture: this->textures) { SDL_DestroyTexture(texture.second); } this->textures.clear(); } void AssetStore::addTexture(SDL_Renderer *renderer, const std::string &assetId, const std::string &filePath) { SDL_Surface *surface = IMG_Load(filePath.c_str()); if (!surface) { Logger::Error("Error opening texture '%s' (path: '%s')", assetId.c_str(), filePath.c_str()); return; } SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); SDL_FreeSurface(surface); Logger::Info("New texture added to the Asset Store id=%s", assetId.c_str()); this->textures.emplace(assetId, texture); } SDL_Texture *AssetStore::getTexture(const std::string &assetId) { if (!this->textures[assetId]) { Logger::Warning("Assert '%s' requested but can't be found.", assetId.c_str()); } return this->textures[assetId]; }