From 1101ff1e28b6459506bfc1d3137bc15053d0c33c Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 7 Apr 2017 15:51:34 +0300 Subject: [PATCH] [Client] Update DedicatedActors every frame to allow interpolation --- apps/openmw/mwmp/Cell.cpp | 18 ++++++++++++------ apps/openmw/mwmp/Cell.hpp | 1 + apps/openmw/mwmp/CellController.cpp | 8 ++++++++ apps/openmw/mwmp/CellController.hpp | 2 ++ apps/openmw/mwmp/DedicatedActor.cpp | 18 +++++++++++------- apps/openmw/mwmp/DedicatedActor.hpp | 4 ++-- apps/openmw/mwmp/Main.cpp | 1 + 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index 6db8bb66b..0178d30ec 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -68,6 +68,18 @@ void Cell::updateLocal() Main::get().getNetworking()->getWorldPacket(ID_ACTOR_FRAME)->Send(); } +void Cell::updateDedicated(float dt) +{ + if (dedicatedActors.empty()) return; + + for (std::map::iterator it = dedicatedActors.begin(); it != dedicatedActors.end(); ++it) + { + DedicatedActor *actor = it->second; + + actor->update(dt); + } +} + void Cell::initializeLocalActors() { ESM::Cell esmCell = *store->getCell(); @@ -137,12 +149,6 @@ void Cell::readCellFrame(WorldEvent& worldEvent) actor->direction = worldObject.direction; actor->drawState = worldObject.drawState; actor->movementFlags = worldObject.movementFlags; - actor->headPitch = worldObject.headPitch; - actor->headYaw = worldObject.headYaw; - actor->move(); - actor->setDrawState(); - actor->setMovementFlags(); - actor->setAnimation(); } } } diff --git a/apps/openmw/mwmp/Cell.hpp b/apps/openmw/mwmp/Cell.hpp index abbee6abf..e75b706e1 100644 --- a/apps/openmw/mwmp/Cell.hpp +++ b/apps/openmw/mwmp/Cell.hpp @@ -16,6 +16,7 @@ namespace mwmp ~Cell(); void updateLocal(); + void updateDedicated(float dt); void initializeLocalActors(); void uninitializeLocalActors(); void readCellFrame(mwmp::WorldEvent& worldEvent); diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index baf3110ee..3130a5908 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -45,6 +45,14 @@ void CellController::updateLocal() } } +void CellController::updateDedicated(float dt) +{ + for (std::map::iterator it = cellsActive.begin(); it != cellsActive.end(); ++it) + { + it->second->updateDedicated(dt); + } +} + void CellController::initializeCellLocal(const ESM::Cell& cell) { MWWorld::CellStore *cellStore = getCell(cell); diff --git a/apps/openmw/mwmp/CellController.hpp b/apps/openmw/mwmp/CellController.hpp index adfc554b8..670c902a5 100644 --- a/apps/openmw/mwmp/CellController.hpp +++ b/apps/openmw/mwmp/CellController.hpp @@ -17,6 +17,8 @@ namespace mwmp ~CellController(); void updateLocal(); + void updateDedicated(float dt); + void initializeCellLocal(const ESM::Cell& cell); void readCellFrame(mwmp::WorldEvent& worldEvent); diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index b8593dcc1..b5f31ba32 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -1,4 +1,5 @@ #include "../mwbase/environment.hpp" +#include "../mwmechanics/mechanicsmanagerimp.hpp" #include "../mwmechanics/movement.hpp" #include "../mwmechanics/npcstats.hpp" #include "../mwrender/animation.hpp" @@ -20,21 +21,24 @@ DedicatedActor::~DedicatedActor() } -void DedicatedActor::update() +void DedicatedActor::update(float dt) { - + move(dt); + setDrawState(); + setMovementFlags(); + setAnimation(); } -void DedicatedActor::move() +void DedicatedActor::move(float dt) { MWBase::World *world = MWBase::Environment::get().getWorld(); world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]); - MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr); - move->mPosition[0] = direction.pos[0]; - move->mPosition[1] = direction.pos[1]; - move->mPosition[2] = direction.pos[2]; + MWMechanics::Movement& move = ptr.getClass().getMovementSettings(ptr); + move.mPosition[0] = direction.pos[0]; + move.mPosition[1] = direction.pos[1]; + move.mPosition[2] = direction.pos[2]; world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]); } diff --git a/apps/openmw/mwmp/DedicatedActor.hpp b/apps/openmw/mwmp/DedicatedActor.hpp index f4c8814e4..a2ab60eee 100644 --- a/apps/openmw/mwmp/DedicatedActor.hpp +++ b/apps/openmw/mwmp/DedicatedActor.hpp @@ -14,8 +14,8 @@ namespace mwmp DedicatedActor(); virtual ~DedicatedActor(); - void update(); - void move(); + void update(float dt); + void move(float dt); void setDrawState(); void setMovementFlags(); void setAnimation(); diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index c0ad4c85f..ac15b339d 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -182,6 +182,7 @@ void Main::frame(float dt) get().getNetworking()->update(); Players::update(dt); + get().getCellController()->updateDedicated(dt); get().updateWorld(dt); get().getGUIController()->update(dt);