From 2872675f5e54769f62afc3732d1d99d7788d4918 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 15 Apr 2017 13:42:30 +0300 Subject: [PATCH] [General] Send and read ActorAnimPlay packets --- apps/openmw/mwmechanics/character.cpp | 1 - apps/openmw/mwmp/ActorList.cpp | 16 +++++++++++++ apps/openmw/mwmp/ActorList.hpp | 3 +++ apps/openmw/mwmp/Cell.cpp | 23 +++++++++++++++++++ apps/openmw/mwmp/Cell.hpp | 1 + apps/openmw/mwmp/CellController.cpp | 13 +++++++++++ apps/openmw/mwmp/CellController.hpp | 1 + apps/openmw/mwmp/DedicatedActor.cpp | 7 ++++-- apps/openmw/mwmp/LocalActor.cpp | 10 ++++++++ apps/openmw/mwmp/LocalActor.hpp | 1 + apps/openmw/mwmp/Networking.cpp | 2 ++ components/openmw-mp/Base/BaseActor.hpp | 1 - .../Packets/Actor/PacketActorAnimPlay.cpp | 5 +++- .../Packets/Actor/PacketActorTest.cpp | 15 ------------ 14 files changed, 79 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index b2e0ae12d..608b76829 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -2155,7 +2155,6 @@ bool CharacterController::playGroup(const std::string &groupname, int mode, int if (mwmp::Main::get().getCellController()->isLocalActor(mPtr)) { mwmp::LocalActor *actor = mwmp::Main::get().getCellController()->getLocalActor(mPtr); - actor->hasAnimation = true; actor->animation.groupname = groupname; actor->animation.mode = mode; actor->animation.count = count; diff --git a/apps/openmw/mwmp/ActorList.cpp b/apps/openmw/mwmp/ActorList.cpp index 2e716700c..6a848c7c5 100644 --- a/apps/openmw/mwmp/ActorList.cpp +++ b/apps/openmw/mwmp/ActorList.cpp @@ -29,6 +29,7 @@ void ActorList::reset() baseActors.clear(); positionActors.clear(); animFlagsActors.clear(); + animPlayActors.clear(); guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid; } @@ -52,6 +53,11 @@ void ActorList::addAnimFlagsActor(LocalActor localActor) animFlagsActors.push_back(localActor); } +void ActorList::addAnimPlayActor(LocalActor localActor) +{ + animPlayActors.push_back(localActor); +} + void ActorList::sendPositionActors() { if (positionActors.size() > 0) @@ -72,6 +78,16 @@ void ActorList::sendAnimFlagsActors() } } +void ActorList::sendAnimPlayActors() +{ + if (animPlayActors.size() > 0) + { + baseActors = animPlayActors; + Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_PLAY)->setActorList(this); + Main::get().getNetworking()->getActorPacket(ID_ACTOR_ANIM_PLAY)->Send(); + } +} + // TODO: Finish this void ActorList::editActorsInCell(MWWorld::CellStore* cellStore) { diff --git a/apps/openmw/mwmp/ActorList.hpp b/apps/openmw/mwmp/ActorList.hpp index 0eeafb6a1..7a73b2aeb 100644 --- a/apps/openmw/mwmp/ActorList.hpp +++ b/apps/openmw/mwmp/ActorList.hpp @@ -23,9 +23,11 @@ namespace mwmp void addPositionActor(LocalActor localActor); void addAnimFlagsActor(LocalActor localActor); + void addAnimPlayActor(LocalActor localActor); void sendPositionActors(); void sendAnimFlagsActors(); + void sendAnimPlayActors(); void editActorsInCell(MWWorld::CellStore* cellStore); @@ -36,6 +38,7 @@ namespace mwmp std::vector positionActors; std::vector animFlagsActors; + std::vector animPlayActors; }; } diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index 69ae59d3d..5df8d4153 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -54,6 +54,7 @@ void Cell::updateLocal(bool forceUpdate) actorList->sendPositionActors(); actorList->sendAnimFlagsActors(); + actorList->sendAnimPlayActors(); } void Cell::updateDedicated(float dt) @@ -109,6 +110,28 @@ void Cell::readAnimFlags(ActorList& actorList) } } +void Cell::readAnimPlay(ActorList& actorList) +{ + initializeDedicatedActors(actorList); + + BaseActor baseActor; + + for (unsigned int i = 0; i < actorList.count; i++) + { + baseActor = actorList.baseActors.at(i); + std::string mapIndex = Main::get().getCellController()->generateMapIndex(baseActor); + + if (dedicatedActors.count(mapIndex) > 0) + { + DedicatedActor *actor = dedicatedActors[mapIndex]; + actor->animation.groupname = baseActor.animation.groupname; + actor->animation.mode = baseActor.animation.mode; + actor->animation.count = baseActor.animation.count; + actor->animation.persist = baseActor.animation.persist; + } + } +} + void Cell::initializeLocalActors() { ESM::Cell esmCell = *store->getCell(); diff --git a/apps/openmw/mwmp/Cell.hpp b/apps/openmw/mwmp/Cell.hpp index 036dfcb59..64138d36f 100644 --- a/apps/openmw/mwmp/Cell.hpp +++ b/apps/openmw/mwmp/Cell.hpp @@ -20,6 +20,7 @@ namespace mwmp void readPositions(ActorList& actorList); void readAnimFlags(ActorList& actorList); + void readAnimPlay(ActorList& actorList); void initializeLocalActors(); void initializeDedicatedActors(ActorList& actorList); diff --git a/apps/openmw/mwmp/CellController.cpp b/apps/openmw/mwmp/CellController.cpp index c8887a5b4..66ac4541e 100644 --- a/apps/openmw/mwmp/CellController.cpp +++ b/apps/openmw/mwmp/CellController.cpp @@ -115,6 +115,19 @@ void CellController::readAnimFlags(ActorList& actorList) } } +void CellController::readAnimPlay(ActorList& actorList) +{ + std::string mapIndex = actorList.cell.getDescription(); + + initializeCell(actorList.cell); + + // If this now exists, send it the data + if (cellsActive.count(mapIndex) > 0) + { + cellsActive[mapIndex]->readAnimPlay(actorList); + } +} + void CellController::setLocalActorRecord(std::string actorIndex, std::string cellIndex) { localActorsToCells[actorIndex] = cellIndex; diff --git a/apps/openmw/mwmp/CellController.hpp b/apps/openmw/mwmp/CellController.hpp index b3ff6363e..6034cf63b 100644 --- a/apps/openmw/mwmp/CellController.hpp +++ b/apps/openmw/mwmp/CellController.hpp @@ -24,6 +24,7 @@ namespace mwmp void readPositions(mwmp::ActorList& actorList); void readAnimFlags(mwmp::ActorList& actorList); + void readAnimPlay(mwmp::ActorList& actorList); void setLocalActorRecord(std::string actorIndex, std::string cellIndex); void removeLocalActorRecord(std::string actorIndex); diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index d6f50fb29..5604900a0 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -17,6 +17,7 @@ DedicatedActor::DedicatedActor() { drawState = 0; movementFlags = 0; + animation.groupname = ""; } DedicatedActor::~DedicatedActor() @@ -28,7 +29,7 @@ void DedicatedActor::update(float dt) { move(dt); setDrawState(); - //setAnimation(); + setAnimation(); } void DedicatedActor::move(float dt) @@ -65,10 +66,12 @@ void DedicatedActor::setDrawState() void DedicatedActor::setAnimation() { - if (hasAnimation) + if (!animation.groupname.empty()) { MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, animation.groupname, animation.mode, animation.count, animation.persist); + + animation.groupname.clear(); } } diff --git a/apps/openmw/mwmp/LocalActor.cpp b/apps/openmw/mwmp/LocalActor.cpp index 507c8f845..27ac13c84 100644 --- a/apps/openmw/mwmp/LocalActor.cpp +++ b/apps/openmw/mwmp/LocalActor.cpp @@ -36,6 +36,7 @@ void LocalActor::update(bool forceUpdate) { updatePosition(forceUpdate); updateAnimFlags(forceUpdate); + updateAnimPlay(); } void LocalActor::updatePosition(bool forceUpdate) @@ -111,6 +112,15 @@ void LocalActor::updateAnimFlags(bool forceUpdate) } } +void LocalActor::updateAnimPlay() +{ + if (!animation.groupname.empty()) + { + mwmp::Main::get().getNetworking()->getActorList()->addAnimPlayActor(*this); + animation.groupname.clear(); + } +} + MWWorld::Ptr LocalActor::getPtr() { return ptr; diff --git a/apps/openmw/mwmp/LocalActor.hpp b/apps/openmw/mwmp/LocalActor.hpp index e93499afc..198e408d7 100644 --- a/apps/openmw/mwmp/LocalActor.hpp +++ b/apps/openmw/mwmp/LocalActor.hpp @@ -18,6 +18,7 @@ namespace mwmp void updatePosition(bool forceUpdate); void updateAnimFlags(bool forceUpdate); + void updateAnimPlay(); MWWorld::Ptr getPtr(); void setPtr(const MWWorld::Ptr& newPtr); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 90c5a59d1..0dc7cae64 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -879,6 +879,8 @@ void Networking::processActorPacket(RakNet::Packet *packet) } case ID_ACTOR_ANIM_PLAY: { + //Main::get().getCellController()->readAnimPlay(actorList); + break; } case ID_ACTOR_ATTACK: diff --git a/components/openmw-mp/Base/BaseActor.hpp b/components/openmw-mp/Base/BaseActor.hpp index bfd0ffe4e..51b159696 100644 --- a/components/openmw-mp/Base/BaseActor.hpp +++ b/components/openmw-mp/Base/BaseActor.hpp @@ -33,7 +33,6 @@ namespace mwmp float headYaw; Animation animation; - bool hasAnimation; }; class BaseActorList diff --git a/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp b/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp index e8e3fe8fc..79bac8ba8 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAnimPlay.cpp @@ -38,7 +38,10 @@ void PacketActorAnimPlay::Packet(RakNet::BitStream *bs, bool send) RW(actor.refNumIndex, send); RW(actor.mpNum, send); - // TODO: Fill this in + RW(actor.animation.groupname, send); + RW(actor.animation.mode, send); + RW(actor.animation.count, send); + RW(actor.animation.persist, send); if (!send) { diff --git a/components/openmw-mp/Packets/Actor/PacketActorTest.cpp b/components/openmw-mp/Packets/Actor/PacketActorTest.cpp index 521b884de..54c718be5 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorTest.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorTest.cpp @@ -37,21 +37,6 @@ void PacketActorTest::Packet(RakNet::BitStream *bs, bool send) RW(actor.refId, send); RW(actor.refNumIndex, send); RW(actor.mpNum, send); - RW(actor.position, send); - RW(actor.drawState, send); - - RW(actor.headPitch, send); - RW(actor.headYaw, send); - - RW(actor.hasAnimation, send); - - if (actor.hasAnimation) - { - RW(actor.animation.groupname, send); - RW(actor.animation.mode, send); - RW(actor.animation.count, send); - RW(actor.animation.persist, send); - } if (!send) {