From 4da2ae6f12d7cf4594edb2d560c5c112e9bcd094 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 19 Oct 2015 12:43:19 +0200 Subject: [PATCH] use seconds as world time unit --- src/ai/ai.cpp | 6 +++--- src/client/NetworkedInput.hpp | 4 ++-- src/client/net.cpp | 4 ++-- src/ui/ui.cpp | 2 +- src/world/Entity.hpp | 2 +- src/world/World.hpp | 2 ++ src/world/world.cpp | 26 ++++++++++++-------------- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index 7ada5a3..7dfe042 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -16,8 +16,8 @@ Chaser::Chaser(World &world, Entity &ctrl, Entity &tgt) noexcept : Controller(ctrl) , world(world) , tgt(tgt) -, chase_speed(0.002f) -, flee_speed(-0.005f) +, chase_speed(2.0f) +, flee_speed(-5.0f) , stop_dist(10) , flee_dist(5) { tgt.Ref(); @@ -109,7 +109,7 @@ void RandomWalk::Change() noexcept { start_vel = target_vel; start_rot = target_rot; - constexpr float base = 0.000001f; + constexpr float base = 0.001f; target_vel.x = base * (random.Next() % 1024); target_vel.y = base * (random.Next() % 1024); diff --git a/src/client/NetworkedInput.hpp b/src/client/NetworkedInput.hpp index 36382b9..a670222 100644 --- a/src/client/NetworkedInput.hpp +++ b/src/client/NetworkedInput.hpp @@ -37,9 +37,9 @@ private: struct PlayerHistory { EntityState state; glm::vec3 tgt_vel; - int delta_t; + float delta_t; std::uint16_t packet; - PlayerHistory(EntityState s, const glm::vec3 &tv, int dt, std::uint16_t p) + PlayerHistory(EntityState s, const glm::vec3 &tv, float dt, std::uint16_t p) : state(s), tgt_vel(tv), delta_t(dt), packet(p) { } }; std::list player_hist; diff --git a/src/client/net.cpp b/src/client/net.cpp index 8a49304..c3bbb67 100644 --- a/src/client/net.cpp +++ b/src/client/net.cpp @@ -332,12 +332,12 @@ void NetworkedInput::PushPlayerUpdate(int dt) { InventorySlot() ); if (player_hist.size() < 16) { - player_hist.emplace_back(state, GetPlayer().GetEntity().TargetVelocity(), dt, packet); + player_hist.emplace_back(state, GetPlayer().GetEntity().TargetVelocity(), dt * 0.001f, packet); } else { auto entry = player_hist.begin(); entry->state = state; entry->tgt_vel = GetPlayer().GetEntity().TargetVelocity(); - entry->delta_t = dt; + entry->delta_t = dt * 0.001f; entry->packet = packet; player_hist.splice(player_hist.end(), player_hist, entry); } diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 9638619..5b0eec8 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -83,7 +83,7 @@ void PlayerController::Invalidate() noexcept { } void PlayerController::UpdatePlayer() noexcept { - constexpr float max_vel = 0.005f; + constexpr float max_vel = 5.0f; // in m/s if (dirty) { player.GetEntity().Orientation(glm::quat(glm::vec3(pitch, yaw, 0.0f))); player.GetEntity().TargetVelocity(glm::rotateY(move_dir * max_vel, yaw)); diff --git a/src/world/Entity.hpp b/src/world/Entity.hpp index 1ac9223..7e85591 100644 --- a/src/world/Entity.hpp +++ b/src/world/Entity.hpp @@ -56,7 +56,7 @@ public: return state.Diff(other.state); } - /// direction is rotation axis, magnitude is speed in rad/ms + /// direction is rotation axis, magnitude is speed in rad/s const glm::vec3 &AngularVelocity() const noexcept { return state.ang_vel; } void AngularVelocity(const glm::vec3 &v) noexcept { state.ang_vel = v; } diff --git a/src/world/World.hpp b/src/world/World.hpp index c24ccf3..4755b18 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -89,7 +89,9 @@ public: std::list &Entities() noexcept { return entities; } const std::list &Entities() const noexcept { return entities; } + // dt in ms void Update(int dt); + // dt in s void Update(Entity &, float dt); void Render(Viewport &); diff --git a/src/world/world.cpp b/src/world/world.cpp index 750cd2d..15f1cab 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -342,7 +342,7 @@ bool World::Intersection(const Entity &e, const EntityState &s, std::vector