X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=be62988769130a8dbdd27ed4cfeeeceea5b0278c;hb=20d0a76d2519c71009c3b3babec0df27529f8142;hp=f0a3f35c7b984825d2dcffbc4c529a8c0d9815cb;hpb=80a9a59d71a7b144c12f64cbef4644751bd54745;p=blank.git diff --git a/src/client/client.cpp b/src/client/client.cpp index f0a3f35..be62988 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -4,6 +4,7 @@ #include "../app/Environment.hpp" #include "../app/init.hpp" +#include "../geometry/distance.hpp" #include "../model/Model.hpp" #include "../io/WorldSave.hpp" #include "../world/ChunkIndex.hpp" @@ -56,12 +57,15 @@ InteractiveState::InteractiveState(MasterState &master, uint32_t player_id) , manip(master.GetEnv().audio, sounds, player.GetEntity()) , input(world, player, master.GetClient()) , interface(master.GetConfig(), master.GetEnv().keymap, input, *this) -, chunk_receiver(world.Chunks(), save) +, chunk_receiver(master.GetClient(), world.Chunks(), save) , chunk_renderer(player.GetChunks()) , loop_timer(16) +, stat_timer(1000) , sky(master.GetEnv().loader.LoadCubeMap("skybox")) , update_status() -, chat(master.GetEnv(), *this, *this) { +, chat(master.GetEnv(), *this, *this) +, time_skipped(0) +, packets_skipped(0) { if (!save.Exists()) { save.Write(master.GetWorldConf()); } @@ -75,9 +79,7 @@ InteractiveState::InteractiveState(MasterState &master, uint32_t player_id) chunk_renderer.LoadTextures(master.GetEnv().loader, res.tex_index); chunk_renderer.FogDensity(master.GetWorldConf().fog_density); loop_timer.Start(); - if (save.Exists(player)) { - save.Read(player); - } + stat_timer.Start(); } void InteractiveState::OnResume() { @@ -105,6 +107,11 @@ void InteractiveState::Handle(const SDL_Event &event) { case SDL_KEYDOWN: // TODO: move to interface if (event.key.keysym.sym == SDLK_RETURN) { + chat.Clear(); + master.GetEnv().state.Push(&chat); + hud.KeepMessages(true); + } else if (event.key.keysym.sym == SDLK_SLASH) { + chat.Preset("/"); master.GetEnv().state.Push(&chat); hud.KeepMessages(true); } else { @@ -135,20 +142,11 @@ void InteractiveState::Handle(const SDL_Event &event) { } void InteractiveState::Update(int dt) { - input.Update(dt); - if (input.BlockFocus()) { - hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block); - } else if (input.EntityFocus()) { - hud.FocusEntity(*input.EntityFocus().entity); - } else { - hud.FocusNone(); - } - hud.Display(res.block_types[player.GetInventorySlot() + 1]); loop_timer.Update(dt); + stat_timer.Update(dt); master.Update(dt); chunk_receiver.Update(dt); - hud.Update(dt); int world_dt = 0; while (loop_timer.HitOnce()) { world.Update(loop_timer.Interval()); @@ -157,9 +155,28 @@ void InteractiveState::Update(int dt) { } chunk_renderer.Update(dt); + if (input.BlockFocus()) { + hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block); + } else if (input.EntityFocus()) { + hud.FocusEntity(input.EntityFocus().GetEntity()); + } else { + hud.FocusNone(); + } if (world_dt > 0) { - input.PushPlayerUpdate(world_dt); + if (input.UpdateImportant() || packets_skipped >= master.NetStat().SuggestedPacketSkip()) { + input.PushPlayerUpdate(time_skipped + world_dt); + time_skipped = 0; + packets_skipped = 0; + } else { + time_skipped += world_dt; + ++packets_skipped; + } + } + hud.Display(res.block_types[player.GetInventorySlot() + 1]); + if (stat_timer.Hit()) { + hud.UpdateNetStats(master.NetStat()); } + hud.Update(dt); glm::mat4 trans = player.GetEntity().Transform(player.GetEntity().ChunkCoords()); glm::vec3 dir(trans * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f)); @@ -170,12 +187,13 @@ void InteractiveState::Update(int dt) { } void InteractiveState::Render(Viewport &viewport) { - viewport.WorldPosition( - player.GetEntity().Transform(player.GetEntity().ChunkCoords()) - * player.GetEntity().GetModel().EyesTransform()); + viewport.WorldPosition(player.GetEntity().ViewTransform(player.GetEntity().ChunkCoords())); if (master.GetConfig().video.world) { chunk_renderer.Render(viewport); world.Render(viewport); + if (master.GetConfig().video.debug) { + world.RenderDebug(viewport); + } sky.Render(viewport); } hud.Render(viewport); @@ -192,8 +210,6 @@ void InteractiveState::Handle(const Packet::SpawnEntity &pack) { if (model_id > 0 && model_id <= res.models.size()) { res.models.Get(model_id).Instantiate(entity.GetModel()); } - cout << "spawned entity #" << entity_id << " (" << entity.Name() - << ") at " << entity.AbsolutePosition() << endl; } void InteractiveState::Handle(const Packet::DespawnEntity &pack) { @@ -203,7 +219,6 @@ void InteractiveState::Handle(const Packet::DespawnEntity &pack) { for (Entity &entity : world.Entities()) { if (entity.ID() == entity_id) { entity.Kill(); - cout << "despawned entity #" << entity_id << " (" << entity.Name() << ") at " << entity.AbsolutePosition() << endl; return; } } @@ -333,6 +348,14 @@ void InteractiveState::SetDebug(bool b) { } } +void InteractiveState::NextCamera() { + if (iszero(master.GetEnv().viewport.CameraOffset())) { + master.GetEnv().viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, -5.0f)); + } else { + master.GetEnv().viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, 0.0f)); + } +} + void InteractiveState::Exit() { save.Write(player); master.Quit(); @@ -373,7 +396,7 @@ void MasterState::OnEnter() { } -void MasterState::Handle(const SDL_Event &event) { +void MasterState::Handle(const SDL_Event &) { } @@ -427,7 +450,7 @@ void MasterState::On(const Packet::Join &pack) { env.state.Push(state.get()); } -void MasterState::On(const Packet::Part &pack) { +void MasterState::On(const Packet::Part &) { Quit(); if (state) { // kicked