]> git.localhorst.tv Git - blank.git/commitdiff
update entity model on state change
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 22 Oct 2015 09:39:58 +0000 (11:39 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 22 Oct 2015 09:49:47 +0000 (11:49 +0200)
src/client/client.cpp
src/client/net.cpp
src/world/Entity.hpp
tst/net/PacketTest.cpp

index 9e4ba501b141f3420b2b8eb957429da39e7be5be..08f62112f49e36ccbc18cd376a58fd17ca8645cf 100644 (file)
@@ -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());
index f0a9eee6af31c04608670c8cfae0d3ef960e3800..b1076ba56c41a98d97cb882168dcecff5118aab3 100644 (file)
@@ -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() {
index 4f0d3c435f58e709a4c33dba335453f03b75d81b..6affc21762a2bae9354d223c2203e5133d4317fa 100644 (file)
@@ -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; }
index 27ee32c7151773b29d7b6ade1c1cbf0a3dd0cb6b..9759bfcaa73d3af82efd3fbebb596e049fb7eb53 100644 (file)
@@ -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;