]> git.localhorst.tv Git - blank.git/blobdiff - src/app/app.cpp
merge common parts of pre- and unload states
[blank.git] / src / app / app.cpp
index 48a59502ad974dac9d98eed82d49eaaeaa13487b..2d5aa4fd05b6eb5df3653878d0bd7af6551a1317 100644 (file)
@@ -9,6 +9,7 @@
 #include "init.hpp"
 #include "../audio/Sound.hpp"
 #include "../graphics/ArrayTexture.hpp"
+#include "../graphics/CubeMap.hpp"
 #include "../graphics/Font.hpp"
 #include "../graphics/Texture.hpp"
 #include "../io/TokenStreamReader.hpp"
@@ -97,6 +98,8 @@ void HeadlessApplication::Run() {
 
 void HeadlessApplication::Loop(int dt) {
        env.counter.EnterFrame();
+       HandleEvents();
+       if (!HasState()) return;
        Update(dt);
        CommitStates();
        if (!HasState()) return;
@@ -270,6 +273,17 @@ void StateControl::Commit(HeadlessApplication &app) {
                                        app.PopState();
                                }
                                break;
+                       case POP_AFTER:
+                               while (app.HasState() && &app.GetState() != m.state) {
+                                       app.PopState();
+                               }
+                               break;
+                       case POP_UNTIL:
+                               while (app.HasState()) {
+                                       if (app.PopState() == m.state) {
+                                               break;
+                                       }
+                               }
                }
        }
 }
@@ -337,6 +351,34 @@ void AssetLoader::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry
                                type.collision = in.GetBool();
                        } else if (name == "collide_block") {
                                type.collide_block = in.GetBool();
+                       } else if (name == "generate") {
+                               type.generate = in.GetBool();
+                       } else if (name == "min_solidity") {
+                               type.min_solidity = in.GetFloat();
+                       } else if (name == "mid_solidity") {
+                               type.mid_solidity = in.GetFloat();
+                       } else if (name == "max_solidity") {
+                               type.max_solidity = in.GetFloat();
+                       } else if (name == "min_humidity") {
+                               type.min_humidity = in.GetFloat();
+                       } else if (name == "mid_humidity") {
+                               type.mid_humidity = in.GetFloat();
+                       } else if (name == "max_humidity") {
+                               type.max_humidity = in.GetFloat();
+                       } else if (name == "min_temperature") {
+                               type.min_temperature = in.GetFloat();
+                       } else if (name == "mid_temperature") {
+                               type.mid_temperature = in.GetFloat();
+                       } else if (name == "max_temperature") {
+                               type.max_temperature = in.GetFloat();
+                       } else if (name == "min_richness") {
+                               type.min_richness = in.GetFloat();
+                       } else if (name == "mid_richness") {
+                               type.mid_richness = in.GetFloat();
+                       } else if (name == "max_richness") {
+                               type.max_richness = in.GetFloat();
+                       } else if (name == "commonness") {
+                               type.commonness = in.GetFloat();
                        } else if (name == "shape") {
                                in.ReadIdentifier(shape_name);
                                if (shape_name == "block") {
@@ -363,6 +405,79 @@ void AssetLoader::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry
        }
 }
 
+CubeMap AssetLoader::LoadCubeMap(const string &name) const {
+       string full = textures + 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";
+
+       CubeMap cm;
+       cm.Bind();
+       SDL_Surface *srf;
+
+       if (!(srf = IMG_Load(right.c_str()))) throw SDLError("IMG_Load");
+       try {
+               cm.Data(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(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(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(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(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(CubeMap::FRONT, *srf);
+       } catch (...) {
+               SDL_FreeSurface(srf);
+               throw;
+       }
+       SDL_FreeSurface(srf);
+
+       cm.FilterNearest();
+       cm.WrapEdge();
+
+       return cm;
+}
+
 Font AssetLoader::LoadFont(const string &name, int size) const {
        string full = fonts + name + ".ttf";
        return Font(full.c_str(), size);