From: Daniel Karbach Date: Thu, 8 Oct 2015 07:23:38 +0000 (+0200) Subject: rearrange init of standalone state a little X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=04531ab5fc3d82ba5b5d456bcc277fe6499e1150;p=blank.git rearrange init of standalone state a little --- diff --git a/src/standalone/MasterState.cpp b/src/standalone/MasterState.cpp index ced107d..68e49a9 100644 --- a/src/standalone/MasterState.cpp +++ b/src/standalone/MasterState.cpp @@ -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(); } diff --git a/src/standalone/MasterState.hpp b/src/standalone/MasterState.hpp index 84c3315..9e0b8e4 100644 --- a/src/standalone/MasterState.hpp +++ b/src/standalone/MasterState.hpp @@ -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; diff --git a/src/world/Player.hpp b/src/world/Player.hpp index 1f9af84..c1a3e0b 100644 --- a/src/world/Player.hpp +++ b/src/world/Player.hpp @@ -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: diff --git a/src/world/world.cpp b/src/world/world.cpp index 8ea99fe..e4fb968 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -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()); }