From: Daniel Karbach Date: Thu, 22 Oct 2015 09:39:58 +0000 (+0200) Subject: update entity model on state change X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7f15e27277382f0176a23dd21702f9d113581763;p=blank.git update entity model on state change --- diff --git a/src/client/client.cpp b/src/client/client.cpp index 9e4ba50..08f6211 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -201,6 +201,7 @@ void InteractiveState::Handle(const Packet::EntityUpdate &pack) { glm::ivec3 base; pack.ReadEntityCount(count); pack.ReadChunkBase(base); + EntityState state; for (uint32_t i = 0; i < count; ++i) { uint32_t entity_id = 0; @@ -215,7 +216,8 @@ void InteractiveState::Handle(const Packet::EntityUpdate &pack) { } if (world_iter->ID() == entity_id) { if (UpdateEntity(entity_id, pack.Seq())) { - pack.ReadEntityState(world_iter->GetState(), base, i); + pack.ReadEntityState(state, base, i); + world_iter->SetState(state); } } } @@ -399,9 +401,9 @@ void MasterState::On(const Packet::Join &pack) { pack.ReadPlayerID(player_id); state.reset(new InteractiveState(*this, player_id)); - pack.ReadPlayerState(state->GetPlayer().GetEntity().GetState()); - glm::vec3 orient(glm::eulerAngles(state->GetPlayer().GetEntity().Orientation())); - state->GetPlayerController().TurnHead(orient.x, orient.y); + EntityState player_state; + pack.ReadPlayerState(player_state); + state->GetPlayer().GetEntity().SetState(player_state); env.state.PopAfter(this); env.state.Push(state.get()); diff --git a/src/client/net.cpp b/src/client/net.cpp index f0a9eee..b1076ba 100644 --- a/src/client/net.cpp +++ b/src/client/net.cpp @@ -376,7 +376,7 @@ void NetworkedInput::MergePlayerCorrection(uint16_t seq, const EntityState &corr } } - EntityState &player_state = GetPlayer().GetEntity().GetState(); + EntityState player_state = GetPlayer().GetEntity().GetState(); Entity replay(GetPlayer().GetEntity()); replay.SetState(corrected_state); @@ -418,6 +418,7 @@ void NetworkedInput::MergePlayerCorrection(uint16_t seq, const EntityState &corr displacement *= 0.01f / sqrt(disp_squared); player_state.block_pos += displacement; } + GetPlayer().GetEntity().SetState(player_state); } void NetworkedInput::StartPrimaryAction() { diff --git a/src/world/Entity.hpp b/src/world/Entity.hpp index 4f0d3c4..6affc21 100644 --- a/src/world/Entity.hpp +++ b/src/world/Entity.hpp @@ -74,8 +74,7 @@ public: /// get a ray in entity's face direction originating from center of vision Ray Aim(const Chunk::Pos &chunk_offset) const noexcept; - void SetState(const EntityState &s) noexcept { state = s; } - EntityState &GetState() noexcept { return state; } + void SetState(const EntityState &s) noexcept { state = s; UpdateModel(); } const EntityState &GetState() const noexcept { return state; } void Ref() noexcept { ++ref_count; } diff --git a/tst/net/PacketTest.cpp b/tst/net/PacketTest.cpp index 27ee32c..9759bfc 100644 --- a/tst/net/PacketTest.cpp +++ b/tst/net/PacketTest.cpp @@ -112,12 +112,14 @@ void PacketTest::testJoin() { Entity write_entity; write_entity.ID(534574); - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().pitch = 0.3f; - write_entity.GetState().yaw = -2.3f; + EntityState write_state; + write_state.chunk_pos = { 7, 2, -3 }; + write_state.block_pos = { 1.5f, 0.9f, 12.0f }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); uint32_t read_id = 0; EntityState read_state; pack.WritePlayer(write_entity); @@ -207,13 +209,16 @@ void PacketTest::testSpawnEntity() { write_entity.ID(534574); Model model; model.ID(23); + model.Enumerate(); model.Instantiate(write_entity.GetModel()); - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().pitch = 0.3f; - write_entity.GetState().yaw = -2.3f; + EntityState write_state; + write_state.chunk_pos = { 7, 2, -3 }; + write_state.block_pos = { 1.5f, 0.9f, 12.0f }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); write_entity.Bounds({{ -1, -1, -1 }, { 1, 1, 1 }}); write_entity.WorldCollidable(true); write_entity.Name("blah"); @@ -298,12 +303,14 @@ void PacketTest::testEntityUpdate() { Entity write_entity; write_entity.ID(8567234); - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().pitch = 0.3f; - write_entity.GetState().yaw = -2.3f; + EntityState write_state; + write_state.chunk_pos = { 7, 2, -3 }; + write_state.block_pos = { 1.5f, 0.9f, 12.0f }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); pack.WriteEntity(write_entity, write_base, 1); pack.WriteEntity(write_entity, write_base, 0); pack.WriteEntity(write_entity, write_base, 2); @@ -336,12 +343,14 @@ void PacketTest::testPlayerCorrection() { ); Entity write_entity; - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().pitch = 0.3f; - write_entity.GetState().yaw = -2.3f; + EntityState write_state; + write_state.chunk_pos = { 7, 2, -3 }; + write_state.block_pos = { 1.5f, 0.9f, 12.0f }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); pack.WritePlayer(write_entity); EntityState read_state;