From d932627a498f8315d348c48e809779e8215563c4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 25 Nov 2012 21:26:13 +0000 Subject: Add client-side movement for projectiles. --- src/core/gameconnection.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index 70d19ef..b4778e0 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -9,10 +9,13 @@ #include "sys/sys.h" #include "filesystem/filesystem.h" +#include "core/application.h" #include "core/cvar.h" +#include "core/entityprojectile.h" #include "core/gameconnection.h" #include "core/net.h" + namespace core { const unsigned long INFOTIMEOUT = 2500; // 2500ms info request timeout @@ -220,10 +223,24 @@ void GameConnection::frame(unsigned long timestamp) return; } - //update_clientstate(); - // get incoming messages connection_network->frame(); + + // update client-sde state + for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { + Entity *entity = (*it).second; + + if (entity->type() == Entity::Projectile) { + EntityProjectile *projectile = static_cast(entity); + if (projectile->state() == Entity::Normal) { + unsigned long elapsed = application()->timestamp() - projectile->timestamp(); + if (elapsed > 0) { + projectile->set_location(projectile->location() + projectile->axis().forward() * projectile->speed() * ((float) elapsed / 1000.0f)); + projectile->set_timestamp(application()->timestamp()); + } + } + } + } float f = 0; if (core::Cvar::net_framerate->value()) { -- cgit v1.2.3