]> git.localhorst.tv Git - blobs.git/blobdiff - src/app/app.cpp
basic sky box
[blobs.git] / src / app / app.cpp
index e4dc1a58eef0de9166254142f5ea19073810c9e3..0f50aa75d00104a21fe5a32a988bef297a98580f 100644 (file)
@@ -175,7 +175,9 @@ Assets::Assets()
 , data_path(path + "data/")
 , font_path(path + "fonts/")
 , skin_path(path + "skins/")
+, sky_path(path + "skies/")
 , tile_path(path + "tiles/")
+, random(0x6283B64CEFE57925)
 , fonts{
        graphics::Font(font_path + "DejaVuSans.ttf", 32),
        graphics::Font(font_path + "DejaVuSans.ttf", 24),
@@ -215,16 +217,18 @@ Assets::Assets()
 
        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);
+       LoadSkinTexture("plain", textures.skins, 0);
+       LoadSkinTexture("stripes", textures.skins, 1);
+       LoadSkinTexture("dots", textures.skins, 2);
+       LoadSkinTexture("lines", textures.skins, 3);
+       LoadSkinTexture("spots", textures.skins, 4);
+       LoadSkinTexture("circles", textures.skins, 5);
        textures.skins.FilterTrilinear();
+
+       textures.sky.Bind();
+       LoadSkyTexture("blue", textures.sky);
+       textures.sky.FilterTrilinear();
+       textures.sky.WrapEdge();
 }
 
 Assets::~Assets() {
@@ -251,6 +255,11 @@ void Assets::ReadResources(io::TokenStreamReader &in) {
                        in.Skip(io::Token::EQUALS);
                        if (name == "label") {
                                in.ReadString(data.resources[id].label);
+                       } else if (name == "density") {
+                               data.resources[id].density = in.GetDouble();
+                       } else if (name == "energy") {
+                               data.resources[id].energy = in.GetDouble();
+                               data.resources[id].inverse_energy = 1.0 / data.resources[id].energy;
                        } else if (name == "state") {
                                in.ReadIdentifier(name);
                                if (name == "solid") {
@@ -264,6 +273,26 @@ void Assets::ReadResources(io::TokenStreamReader &in) {
                                } else {
                                        throw std::runtime_error("unknown resource state '" + name + "'");
                                }
+                       } else if (name == "base_color") {
+                               in.ReadVec(data.resources[id].base_color);
+                       } else if (name == "compatibility") {
+                               in.Skip(io::Token::ANGLE_BRACKET_OPEN);
+                               while (in.Peek().type != io::Token::ANGLE_BRACKET_CLOSE) {
+                                       in.ReadIdentifier(name);
+                                       int sub_id = 0;
+                                       if (data.resources.Has(name)) {
+                                               sub_id = data.resources[name].id;
+                                       } else {
+                                               world::Resource res;
+                                               res.name = name;
+                                               sub_id = data.resources.Add(res);
+                                       }
+                                       in.Skip(io::Token::COLON);
+                                       double value = in.GetDouble();
+                                       in.Skip(io::Token::SEMICOLON);
+                                       data.resources[id].compatibility[sub_id] = value;
+                               }
+                               in.Skip(io::Token::ANGLE_BRACKET_CLOSE);
                        } else {
                                throw std::runtime_error("unknown resource property '" + name + "'");
                        }
@@ -362,5 +391,71 @@ void Assets::LoadSkinTexture(const string &name, graphics::ArrayTexture &tex, in
        SDL_FreeSurface(srf);
 }
 
+void Assets::LoadSkyTexture(const string &name, graphics::CubeMap &cm) const {
+       string full = sky_path + name;
+       string right = full + "-right.png";
+       string left = full + "-left.png";
+       string top = full + "-top.png";
+       string bottom = full + "-bottom.png";
+       string back = full + "-back.png";
+       string front = full + "-front.png";
+
+       SDL_Surface *srf = nullptr;
+
+       if (!(srf = IMG_Load(right.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(graphics::CubeMap::RIGHT, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+
+       if (!(srf = IMG_Load(left.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(graphics::CubeMap::LEFT, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+
+       if (!(srf = IMG_Load(top.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(graphics::CubeMap::TOP, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+
+       if (!(srf = IMG_Load(bottom.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(graphics::CubeMap::BOTTOM, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+
+       if (!(srf = IMG_Load(back.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(graphics::CubeMap::BACK, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+
+       if (!(srf = IMG_Load(front.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(graphics::CubeMap::FRONT, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+}
+
 }
 }