X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=62de9abab0320ca56ae20fbb130e42c6ec7a4d60;hb=fec78f7f01a03f10f8ff75c9b87929bf8c2d61e4;hp=064786fb82baf42403588ec4f789c23b3e1f6d2e;hpb=be413456f57da06e918ae7bf4c4f35e5198ff7ce;p=blobs.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 064786f..62de9ab 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -6,6 +6,7 @@ #include "../graphics/Viewport.hpp" #include +#include namespace blobs { @@ -164,22 +165,72 @@ void State::OnQuit() { } -Assets::Assets() { +Assets::Assets() +: path("assets/") +, tile_path(path + "tiles/") +, skin_path(path + "skins/") { graphics::Format format; textures.tiles.Bind(); - textures.tiles.Reserve(1, 1, 3, format); - std::uint8_t texdata[] = { - 0xFF, 0x00, 0x00, 0xFF, - 0x00, 0xFF, 0x00, 0xFF, - 0x00, 0x00, 0xFF, 0xFF, - }; - textures.tiles.Data(0, format, texdata); - textures.tiles.Data(1, format, texdata + 4); - textures.tiles.Data(2, format, texdata + 8); + textures.tiles.Reserve(256, 256, 14, format); + LoadTileTexture("algae", textures.tiles, 0); + LoadTileTexture("desert", textures.tiles, 1); + LoadTileTexture("forest", textures.tiles, 2); + LoadTileTexture("grass", textures.tiles, 3); + LoadTileTexture("ice", textures.tiles, 4); + LoadTileTexture("jungle", textures.tiles, 5); + LoadTileTexture("mountain", textures.tiles, 6); + LoadTileTexture("ocean", textures.tiles, 7); + LoadTileTexture("rock", textures.tiles, 8); + LoadTileTexture("sand", textures.tiles, 9); + LoadTileTexture("taiga", textures.tiles, 10); + LoadTileTexture("tundra", textures.tiles, 11); + LoadTileTexture("water", textures.tiles, 12); + LoadTileTexture("wheat", textures.tiles, 13); + textures.skins.Bind(); + textures.skins.Reserve(256, 256, 9, format); + LoadSkinTexture("1", textures.skins, 0); + LoadSkinTexture("2", textures.skins, 1); + LoadSkinTexture("3", textures.skins, 2); + LoadSkinTexture("4", textures.skins, 3); + LoadSkinTexture("5", textures.skins, 4); + LoadSkinTexture("6", textures.skins, 5); + LoadSkinTexture("7", textures.skins, 6); + LoadSkinTexture("8", textures.skins, 7); + LoadSkinTexture("9", textures.skins, 8); } Assets::~Assets() { } +void Assets::LoadTileTexture(const std::string &name, graphics::ArrayTexture &tex, int layer) const { + std::string path = tile_path + name + ".png"; + SDL_Surface *srf = IMG_Load(path.c_str()); + if (!srf) { + throw SDLError("IMG_Load"); + } + try { + tex.Data(layer, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); +} + +void Assets::LoadSkinTexture(const std::string &name, graphics::ArrayTexture &tex, int layer) const { + std::string path = skin_path + name + ".png"; + SDL_Surface *srf = IMG_Load(path.c_str()); + if (!srf) { + throw SDLError("IMG_Load"); + } + try { + tex.Data(layer, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); +} + } }