]> git.localhorst.tv Git - blank.git/commitdiff
also simulate world collisions in replay
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 1 Oct 2015 14:07:15 +0000 (16:07 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 1 Oct 2015 15:33:45 +0000 (17:33 +0200)
src/client/net.cpp
src/ui/PlayerController.hpp

index 6e8d00cc69de3922c063d912fdf34b82b46927b1..7d8681aecd15f1a4b324bfb2614423a4f3b13808 100644 (file)
@@ -8,6 +8,7 @@
 #include "../world/Chunk.hpp"
 #include "../world/ChunkStore.hpp"
 #include "../world/Player.hpp"
 #include "../world/Chunk.hpp"
 #include "../world/ChunkStore.hpp"
 #include "../world/Player.hpp"
+#include "../world/World.hpp"
 
 #include <iostream>
 #include <zlib.h>
 
 #include <iostream>
 #include <zlib.h>
@@ -320,24 +321,30 @@ void NetworkedInput::MergePlayerCorrection(uint16_t seq, const EntityState &corr
                }
        }
 
                }
        }
 
-       EntityState replay_state(corrected_state);
        EntityState &player_state = GetPlayer().GetEntity().GetState();
        EntityState &player_state = GetPlayer().GetEntity().GetState();
+       Entity replay(GetPlayer().GetEntity());
+       replay.SetState(corrected_state);
 
        if (entry != end) {
 
        if (entry != end) {
-               entry->state.chunk_pos = replay_state.chunk_pos;
-               entry->state.block_pos = replay_state.block_pos;
+               entry->state.chunk_pos = replay.GetState().chunk_pos;
+               entry->state.block_pos = replay.GetState().block_pos;
                ++entry;
        }
 
                ++entry;
        }
 
+       vector<WorldCollision> col;
        while (entry != end) {
        while (entry != end) {
-               replay_state.velocity = entry->state.velocity;
-               replay_state.Update(entry->delta_t);
-               entry->state.chunk_pos = replay_state.chunk_pos;
-               entry->state.block_pos = replay_state.block_pos;
+               replay.Velocity(entry->state.velocity);
+               replay.Update(entry->delta_t);
+               if (GetWorld().Intersection(replay, col)) {
+                       GetWorld().Resolve(replay, col);
+                       col.clear();
+               }
+               entry->state.chunk_pos = replay.GetState().chunk_pos;
+               entry->state.block_pos = replay.GetState().block_pos;
                ++entry;
        }
 
                ++entry;
        }
 
-       glm::vec3 displacement(replay_state.Diff(player_state));
+       glm::vec3 displacement(replay.GetState().Diff(player_state));
        const float disp_squared = dot(displacement, displacement);
 
        if (disp_squared < 16.0f * numeric_limits<float>::epsilon()) {
        const float disp_squared = dot(displacement, displacement);
 
        if (disp_squared < 16.0f * numeric_limits<float>::epsilon()) {
@@ -351,8 +358,8 @@ void NetworkedInput::MergePlayerCorrection(uint16_t seq, const EntityState &corr
        constexpr float max_disp = 0.0001f; // (1/100)^2
 
        if (disp_squared > warp_thresh) {
        constexpr float max_disp = 0.0001f; // (1/100)^2
 
        if (disp_squared > warp_thresh) {
-               player_state.chunk_pos = replay_state.chunk_pos;
-               player_state.block_pos = replay_state.block_pos;
+               player_state.chunk_pos = replay.GetState().chunk_pos;
+               player_state.block_pos = replay.GetState().block_pos;
        } else if (disp_squared < max_disp) {
                player_state.block_pos += displacement;
        } else {
        } else if (disp_squared < max_disp) {
                player_state.block_pos += displacement;
        } else {
index b29795b7313cf9cb5b8d2308e72cfcfa0f03a182..9b4057b380d02c7a20582763103dc877580857fe 100644 (file)
@@ -17,6 +17,8 @@ class PlayerController {
 public:
        PlayerController(World &, Player &);
 
 public:
        PlayerController(World &, Player &);
 
+       World &GetWorld() noexcept { return world; }
+       const World &GetWorld() const noexcept { return world; }
        Player &GetPlayer() noexcept { return player; }
        const Player &GetPlayer() const noexcept { return player; }
 
        Player &GetPlayer() noexcept { return player; }
        const Player &GetPlayer() const noexcept { return player; }