X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fstandalone%2FMasterState.cpp;h=6d457385d3f6d5074a2757bdbf4d2088db766980;hb=bc171dfe0897bccbbf9d9114d128be0801a1aff9;hp=9cc154387e3f6becb55bf756b5df29606514f2fd;hpb=80a9a59d71a7b144c12f64cbef4644751bd54745;p=blank.git diff --git a/src/standalone/MasterState.cpp b/src/standalone/MasterState.cpp index 9cc1543..6d45738 100644 --- a/src/standalone/MasterState.cpp +++ b/src/standalone/MasterState.cpp @@ -3,6 +3,7 @@ #include "../app/Config.hpp" #include "../app/Environment.hpp" #include "../app/init.hpp" +#include "../geometry/distance.hpp" #include "../io/WorldSave.hpp" #include @@ -36,6 +37,7 @@ MasterState::MasterState( , chunk_renderer(player.GetChunks()) , spawner(world, res.models, env.rng) , sky(env.loader.LoadCubeMap("skybox")) +, cli(world) , preload(env, chunk_loader, chunk_renderer) , unload(env, world.Chunks(), save) , chat(env, *this, *this) { @@ -52,8 +54,6 @@ MasterState::MasterState( chunk_renderer.FogDensity(wc.fog_density); if (save.Exists(player)) { save.Read(player); - glm::vec3 orient(glm::eulerAngles(player.GetEntity().Orientation())); - input.TurnHead(orient.x, orient.y); } else { spawn_player = true; } @@ -99,6 +99,11 @@ void MasterState::Handle(const SDL_Event &event) { case SDL_KEYDOWN: // TODO: move to interface if (event.key.keysym.sym == SDLK_RETURN) { + chat.Clear(); + env.state.Push(&chat); + hud.KeepMessages(true); + } else if (event.key.keysym.sym == SDLK_SLASH) { + chat.Preset("/"); env.state.Push(&chat); hud.KeepMessages(true); } else { @@ -129,7 +134,8 @@ void MasterState::Handle(const SDL_Event &event) { } void MasterState::Update(int dt) { - input.Update(dt); + spawner.Update(dt); + world.Update(dt); if (input.BlockFocus()) { hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block); } else if (input.EntityFocus()) { @@ -139,8 +145,6 @@ void MasterState::Update(int dt) { } hud.Display(res.block_types[player.GetInventorySlot() + 1]); hud.Update(dt); - spawner.Update(dt); - world.Update(dt); chunk_loader.Update(dt); chunk_renderer.Update(dt); @@ -153,12 +157,13 @@ void MasterState::Update(int dt) { } void MasterState::Render(Viewport &viewport) { - viewport.WorldPosition( - player.GetEntity().Transform(player.GetEntity().ChunkCoords()) - * player.GetEntity().GetModel().EyesTransform()); + viewport.WorldPosition(player.GetEntity().ViewTransform(player.GetEntity().ChunkCoords())); if (config.video.world) { chunk_renderer.Render(viewport); world.Render(viewport); + if (config.video.debug) { + world.RenderDebug(viewport); + } sky.Render(viewport); } hud.Render(viewport); @@ -201,13 +206,26 @@ void MasterState::SetDebug(bool b) { } } +void MasterState::NextCamera() { + if (iszero(env.viewport.CameraOffset())) { + env.viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, -5.0f)); + } else { + env.viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, 0.0f)); + } +} + void MasterState::Exit() { save.Write(player); env.state.Switch(&unload); } void MasterState::OnLineSubmit(const std::string &line) { - if (!line.empty()) { + if (line.empty()) { + return; + } + if (line[0] == '/' && line.size() > 1 && line[1] != '/') { + cli.Execute(player, line.substr(1)); + } else { hud.PostMessage(line); } }