]> git.localhorst.tv Git - blank.git/commitdiff
rearrange init of standalone state a little
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 8 Oct 2015 07:23:38 +0000 (09:23 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 8 Oct 2015 18:48:41 +0000 (20:48 +0200)
src/standalone/MasterState.cpp
src/standalone/MasterState.hpp
src/world/Player.hpp
src/world/world.cpp

index ced107d1a85573c2462defb16c48e7d2eaf47aba..68e49a966fc607e07e84f6d65c17d2e62eb84da6 100644 (file)
@@ -26,6 +26,7 @@ MasterState::MasterState(
 , world(block_types, wc)
 , spawn_index(world.Chunks().MakeIndex(wc.spawn, 3))
 , player(*world.AddPlayer(config.player.name))
+, spawn_player(false)
 , hud(env, config, player)
 , manip(env, player.GetEntity())
 , input(world, player, manip)
@@ -49,7 +50,7 @@ MasterState::MasterState(
        if (save.Exists(player)) {
                save.Read(player);
        } else {
-               // TODO: spawn
+               spawn_player = true;
        }
 }
 
@@ -58,9 +59,21 @@ MasterState::~MasterState() {
 }
 
 
-void MasterState::OnEnter() {
-       env.state.Push(&preload);
-       env.window.GrabMouse();
+void MasterState::OnResume() {
+       if (spawn_index.MissingChunks() > 0) {
+               env.state.Push(&preload);
+       }
+       if (config.input.mouse) {
+               env.window.GrabMouse();
+       }
+       if (spawn_player) {
+               // TODO: spawn
+               spawn_player = false;
+       }
+}
+
+void MasterState::OnPause() {
+       env.window.ReleaseMouse();
 }
 
 
index 84c331523e43a4602a52a07d4eed6cdd7bbd22a1..9e0b8e4c68e119fade7c03636bff1b71f79e30fb 100644 (file)
@@ -43,7 +43,8 @@ public:
        );
        ~MasterState();
 
-       void OnEnter() override;
+       void OnResume() override;
+       void OnPause() override;
 
        void Handle(const SDL_Event &) override;
        void Update(int dt) override;
@@ -66,6 +67,7 @@ private:
        World world;
        ChunkIndex &spawn_index;
        Player &player;
+       bool spawn_player;
        HUD hud;
        InteractiveManipulator manip;
        DirectInput input;
index 1f9af84118af1ca88e80d415257dcef7307453ca..c1a3e0b36a54a788a9c91211115dde565cc1d721 100644 (file)
@@ -6,6 +6,7 @@
 
 namespace blank {
 
+class BlockLookup;
 class ChunkIndex;
 
 class Player {
@@ -23,6 +24,8 @@ public:
        void SetInventorySlot(int i) noexcept { inv_slot = i; }
        int GetInventorySlot() const noexcept { return inv_slot; }
 
+       bool SuitableSpawn(BlockLookup &) const noexcept;
+
        void Update(int dt);
 
 private:
index 8ea99fec247734e6b592c6e65fc231f9350a49c7..e4fb968ddfbb8014004a2b7a6a7647be53b2c2a5 100644 (file)
@@ -136,6 +136,19 @@ Player::~Player() {
 
 }
 
+bool Player::SuitableSpawn(BlockLookup &spawn_block) const noexcept {
+       if (!spawn_block || spawn_block.GetType().collide_block) {
+               return false;
+       }
+
+       BlockLookup head_block(spawn_block.Next(Block::FACE_UP));
+       if (!head_block || head_block.GetType().collide_block) {
+               return false;
+       }
+
+       return true;
+}
+
 void Player::Update(int dt) {
        chunks.Rebase(entity.ChunkCoords());
 }