X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fclient%2Fclient.cpp;h=6a2dd32993b1fb45031ef9485428ce256ae0f4a7;hb=bc2806164f55b7ac48dbb6d224b7d4b55683decf;hp=ada697b6f90668747d9ca29bc070f815dcde1d50;hpb=9240fdf2e68ee014da0d0a89a7fb2f29ebf28e2d;p=blank.git diff --git a/src/client/client.cpp b/src/client/client.cpp index ada697b..6a2dd32 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1,4 +1,3 @@ -#include "ChunkRequester.hpp" #include "InitialState.hpp" #include "InteractiveState.hpp" #include "MasterState.hpp" @@ -6,7 +5,7 @@ #include "../app/Environment.hpp" #include "../app/init.hpp" #include "../app/TextureIndex.hpp" -#include "../model/CompositeModel.hpp" +#include "../model/Model.hpp" #include "../io/WorldSave.hpp" #include "../world/ChunkIndex.hpp" #include "../world/ChunkStore.hpp" @@ -20,63 +19,6 @@ using namespace std; namespace blank { namespace client { -ChunkRequester::ChunkRequester( - ChunkStore &store, - const WorldSave &save -) noexcept -: store(store) -, save(save) { - -} - -void ChunkRequester::Update(int dt) { - // check if there's chunks waiting to be loaded - LoadN(10); - - // store a few chunks as well - constexpr int max_save = 10; - int saved = 0; - for (Chunk &chunk : store) { - if (chunk.ShouldUpdateSave()) { - save.Write(chunk); - ++saved; - if (saved >= max_save) { - break; - } - } - } -} - -int ChunkRequester::ToLoad() const noexcept { - return store.EstimateMissing(); -} - -void ChunkRequester::LoadOne() { - if (!store.HasMissing()) return; - - Chunk::Pos pos = store.NextMissing(); - Chunk *chunk = store.Allocate(pos); - if (!chunk) { - // chunk store corrupted? - return; - } - - if (save.Exists(pos)) { - save.Read(*chunk); - // TODO: request chunk from server with cache tag - } else { - // TODO: request chunk from server - } -} - -void ChunkRequester::LoadN(std::size_t n) { - std::size_t end = std::min(n, std::size_t(ToLoad())); - for (std::size_t i = 0; i < end && store.HasMissing(); ++i) { - LoadOne(); - } -} - - InitialState::InitialState(MasterState &master) : master(master) , message() { @@ -106,6 +48,7 @@ void InitialState::Render(Viewport &viewport) { // TODO: this clutter is a giant mess InteractiveState::InteractiveState(MasterState &master, uint32_t player_id) : master(master) +, shapes() , block_types() , save(master.GetEnv().config.GetWorldPath(master.GetWorldConf().name, master.GetConfig().net.host)) , world(block_types, master.GetWorldConf()) @@ -114,9 +57,7 @@ InteractiveState::InteractiveState(MasterState &master, uint32_t player_id) , manip(master.GetEnv(), player.GetEntity()) , input(world, player, master.GetClient()) , interface(master.GetConfig(), master.GetEnv().keymap, input, *this) -// TODO: looks like chunk requester and receiver can and should be merged -, chunk_requester(world.Chunks(), save) -, chunk_receiver(world.Chunks()) +, chunk_receiver(world.Chunks(), save) , chunk_renderer(player.GetChunks()) , skeletons() , loop_timer(16) @@ -125,11 +66,12 @@ InteractiveState::InteractiveState(MasterState &master, uint32_t player_id) save.Write(master.GetWorldConf()); } TextureIndex tex_index; - master.GetEnv().loader.LoadBlockTypes("default", block_types, tex_index); + master.GetEnv().loader.LoadShapes("default", shapes); + master.GetEnv().loader.LoadBlockTypes("default", block_types, tex_index, shapes); + skeletons.Load(shapes, tex_index); interface.SetInventorySlots(block_types.size() - 1); chunk_renderer.LoadTextures(master.GetEnv().loader, tex_index); chunk_renderer.FogDensity(master.GetWorldConf().fog_density); - skeletons.Load(); loop_timer.Start(); if (save.Exists(player)) { save.Read(player); @@ -181,7 +123,6 @@ void InteractiveState::Update(int dt) { loop_timer.Update(dt); master.Update(dt); chunk_receiver.Update(dt); - chunk_requester.Update(dt); hud.Update(dt); int world_dt = 0; @@ -388,7 +329,7 @@ void MasterState::On(const Packet::SpawnEntity &pack) { pack.ReadEntity(entity); uint32_t skel_id; pack.ReadSkeletonID(skel_id); - CompositeModel *skel = state->GetSkeletons().ByID(skel_id); + Model *skel = state->GetSkeletons().ByID(skel_id); if (skel) { skel->Instantiate(entity.GetModel()); }