From 9759764699eabb6df26b55892df3f0e1f0eac183 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 5 Apr 2017 09:04:41 +0300 Subject: [PATCH] [Client] Clean up getting and resetting of WorldEvent --- apps/openmw/mwgui/container.cpp | 9 ++-- apps/openmw/mwgui/hud.cpp | 2 +- apps/openmw/mwgui/inventorywindow.cpp | 2 +- apps/openmw/mwmechanics/security.cpp | 2 +- apps/openmw/mwmp/Networking.cpp | 5 +-- apps/openmw/mwmp/Networking.hpp | 4 +- apps/openmw/mwmp/WorldEvent.cpp | 42 ++++++++++++++----- apps/openmw/mwmp/WorldEvent.hpp | 1 + apps/openmw/mwscript/animationextensions.cpp | 2 +- apps/openmw/mwscript/interpretercontext.cpp | 8 ++-- apps/openmw/mwscript/miscextensions.cpp | 8 ++-- apps/openmw/mwscript/soundextensions.cpp | 2 +- .../mwscript/transformationextensions.cpp | 4 +- apps/openmw/mwworld/actiontake.cpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 4 +- 15 files changed, 59 insertions(+), 38 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 311409e78..8b1a26a52 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -107,7 +107,8 @@ namespace MWGui Send an ID_CONTAINER packet every time an item starts being dragged from a container */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); + worldEvent->reset(); worldEvent->cell = *mPtr.getCell()->getCell(); worldEvent->action = mwmp::BaseEvent::REMOVE; @@ -168,7 +169,8 @@ namespace MWGui Send an ID_CONTAINER packet every time an item is dropped in a container */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); + worldEvent->reset(); worldEvent->cell = *mPtr.getCell()->getCell(); worldEvent->action = mwmp::BaseEvent::ADD; @@ -325,7 +327,8 @@ namespace MWGui Send an ID_CONTAINER packet every time the Take All button is used on a container */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); + worldEvent->reset(); worldEvent->cell = *mPtr.getCell()->getCell(); worldEvent->action = mwmp::BaseEvent::SET; diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index b353bc8be..9a82205d0 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -64,7 +64,7 @@ namespace MWGui Send an ID_OBJECT_PLACE packet every time an object is dropped into the world from the inventory screen */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectPlace(dropped); /* End of tes3mp addition diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 0b9ffa95d..21a0606a9 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -644,7 +644,7 @@ namespace MWGui Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained by the player */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectDelete(object); mwmp::Main::get().getLocalPlayer()->sendInventory(); /* diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index 6d0048c47..ae5ff383a 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -63,7 +63,7 @@ namespace MWMechanics Send an ID_OBJECT_UNLOCK packet every time an object is unlocked */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectUnlock(lock); /* End of tes3mp addition diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 2e49556ef..b4a1e24de 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -1067,11 +1067,8 @@ LocalPlayer *Networking::getLocalPlayer() return mwmp::Main::get().getLocalPlayer(); } -WorldEvent *Networking::resetWorldEvent() +WorldEvent *Networking::getWorldEvent() { - worldEvent.cell.blank(); - worldEvent.objectChanges.objects.clear(); - worldEvent.guid = getLocalPlayer()->guid; return &worldEvent; } diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index 694114407..abd0940b3 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -40,7 +40,8 @@ namespace mwmp bool isConnected(); - WorldEvent *resetWorldEvent(); + WorldEvent *getWorldEvent(); + LocalPlayer *getLocalPlayer(); private: bool connected; @@ -55,7 +56,6 @@ namespace mwmp void processPlayerPacket(RakNet::Packet *packet); void processWorldPacket(RakNet::Packet *packet); void receiveMessage(RakNet::Packet *packet); - LocalPlayer *getLocalPlayer(); void preInit(std::vector &content, Files::Collections &collections); }; diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 7a3d99a9e..59f3fd8ef 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -35,6 +35,13 @@ Networking *WorldEvent::getNetworking() return mwmp::Main::get().getNetworking(); } +void WorldEvent::reset() +{ + cell.blank(); + objectChanges.objects.clear(); + guid = mwmp::Main::get().getNetworking()->getLocalPlayer()->guid; +} + void WorldEvent::addObject(WorldObject worldObject) { objectChanges.objects.push_back(worldObject); @@ -42,9 +49,9 @@ void WorldEvent::addObject(WorldObject worldObject) void WorldEvent::sendActors(MWWorld::CellStore* cellStore) { - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *cellStore->getCell(); - worldEvent->action = BaseEvent::SET; + reset(); + cell = *cellStore->getCell(); + action = BaseEvent::SET; MWWorld::CellRefList *npcList = cellStore->getNpcs(); @@ -58,7 +65,7 @@ void WorldEvent::sendActors(MWWorld::CellStore* cellStore) worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldEvent->addObject(worldObject); + addObject(worldObject); } MWWorld::CellRefList *creatureList = cellStore->getCreatures(); @@ -73,18 +80,18 @@ void WorldEvent::sendActors(MWWorld::CellStore* cellStore) worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldEvent->addObject(worldObject); + addObject(worldObject); } - mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->setEvent(worldEvent); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->setEvent(this); mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->Send(); } void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) { - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *cellStore->getCell(); - worldEvent->action = BaseEvent::SET; + reset(); + cell = *cellStore->getCell(); + action = BaseEvent::SET; MWWorld::CellRefList *containerList = cellStore->getContainers(); @@ -112,16 +119,17 @@ void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) worldObject.containerChanges.items.push_back(containerItem); } - worldEvent->addObject(worldObject); + addObject(worldObject); } - mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->setEvent(worldEvent); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->setEvent(this); mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->Send(); } void WorldEvent::sendObjectPlace(MWWorld::Ptr ptr) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -152,6 +160,7 @@ void WorldEvent::sendObjectPlace(MWWorld::Ptr ptr) void WorldEvent::sendObjectDelete(MWWorld::Ptr ptr) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -166,6 +175,7 @@ void WorldEvent::sendObjectDelete(MWWorld::Ptr ptr) void WorldEvent::sendObjectLock(MWWorld::Ptr ptr, int lockLevel) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -181,6 +191,7 @@ void WorldEvent::sendObjectLock(MWWorld::Ptr ptr, int lockLevel) void WorldEvent::sendObjectUnlock(MWWorld::Ptr ptr) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -195,6 +206,7 @@ void WorldEvent::sendObjectUnlock(MWWorld::Ptr ptr) void WorldEvent::sendObjectScale(MWWorld::Ptr ptr, int scale) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -210,6 +222,7 @@ void WorldEvent::sendObjectScale(MWWorld::Ptr ptr, int scale) void WorldEvent::sendObjectAnimPlay(MWWorld::Ptr ptr, std::string group, int mode) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -226,6 +239,7 @@ void WorldEvent::sendObjectAnimPlay(MWWorld::Ptr ptr, std::string group, int mod void WorldEvent::sendDoorState(MWWorld::Ptr ptr, int state) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -245,6 +259,7 @@ void WorldEvent::sendDoorState(MWWorld::Ptr ptr, int state) void WorldEvent::sendMusicPlay(std::string filename) { + reset(); mwmp::WorldObject worldObject; worldObject.filename = filename; addObject(worldObject); @@ -255,6 +270,7 @@ void WorldEvent::sendMusicPlay(std::string filename) void WorldEvent::sendVideoPlay(std::string filename, bool allowSkipping) { + reset(); mwmp::WorldObject worldObject; worldObject.filename = filename; worldObject.allowSkipping = allowSkipping; @@ -266,6 +282,7 @@ void WorldEvent::sendVideoPlay(std::string filename, bool allowSkipping) void WorldEvent::sendScriptLocalShort(MWWorld::Ptr ptr, int index, int shortVal) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -286,6 +303,7 @@ void WorldEvent::sendScriptLocalShort(MWWorld::Ptr ptr, int index, int shortVal) void WorldEvent::sendScriptLocalFloat(MWWorld::Ptr ptr, int index, float floatVal) { + reset(); cell = *ptr.getCell()->getCell(); mwmp::WorldObject worldObject; @@ -306,6 +324,7 @@ void WorldEvent::sendScriptLocalFloat(MWWorld::Ptr ptr, int index, float floatVa void WorldEvent::sendScriptMemberShort(std::string refId, int index, int shortVal) { + reset(); mwmp::WorldObject worldObject; worldObject.refId = refId; worldObject.index = index; @@ -321,6 +340,7 @@ void WorldEvent::sendScriptMemberShort(std::string refId, int index, int shortVa void WorldEvent::sendScriptGlobalShort(std::string varName, int shortVal) { + reset(); mwmp::WorldObject worldObject; worldObject.varName = varName; worldObject.shortVal = shortVal; diff --git a/apps/openmw/mwmp/WorldEvent.hpp b/apps/openmw/mwmp/WorldEvent.hpp index c023e7b11..791c2454d 100644 --- a/apps/openmw/mwmp/WorldEvent.hpp +++ b/apps/openmw/mwmp/WorldEvent.hpp @@ -15,6 +15,7 @@ namespace mwmp WorldEvent(); virtual ~WorldEvent(); + void reset(); void addObject(WorldObject worldObject); void sendActors(MWWorld::CellStore* cellStore); diff --git a/apps/openmw/mwscript/animationextensions.cpp b/apps/openmw/mwscript/animationextensions.cpp index 63e6924ce..8c975f38d 100644 --- a/apps/openmw/mwscript/animationextensions.cpp +++ b/apps/openmw/mwscript/animationextensions.cpp @@ -71,7 +71,7 @@ namespace MWScript */ if (mwmp::Main::isValidPacketScript(ptr.getClass().getScript(ptr))) { - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectAnimPlay(ptr, group, mode); } /* diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 2f8ea6929..55056045d 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -202,7 +202,7 @@ namespace MWScript */ if (sendPackets) { - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendScriptLocalShort(mReference, index, value); } /* @@ -234,7 +234,7 @@ namespace MWScript */ if (sendPackets && value == (int) value) { - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendScriptLocalFloat(mReference, index, value); } /* @@ -291,7 +291,7 @@ namespace MWScript */ if (sendPackets) { - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendScriptGlobalShort(name, value); } /* @@ -626,7 +626,7 @@ namespace MWScript */ if (sendPackets && !global) { - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendScriptMemberShort(id, index, value); } /* diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 8379417a3..f1357794f 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -95,7 +95,7 @@ namespace MWScript Send an ID_VIDEO_PLAY packet every time a video is played through a script */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendVideoPlay(name, allowSkipping); /* End of tes3mp addition @@ -205,7 +205,7 @@ namespace MWScript Send an ID_OBJECT_LOCK packet every time an object is locked through a script */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectLock(ptr, lockLevel); /* End of tes3mp addition @@ -243,7 +243,7 @@ namespace MWScript Send an ID_OBJECT_UNLOCK packet every time an object is unlocked through a script */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectUnlock(ptr); /* End of tes3mp addition @@ -715,7 +715,7 @@ namespace MWScript Send an ID_OBJECT_DELETE packet every time an object is deleted through a script */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectDelete(ptr); /* End of tes3mp addition diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index 5b09d9a74..f6569fd9b 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -79,7 +79,7 @@ namespace MWScript Send an ID_MUSIC_PLAY packet every time new music is streamed through a script */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendMusicPlay(sound); /* End of tes3mp addition diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index dd49883df..61df5fa5f 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -52,7 +52,7 @@ namespace MWScript Send an ID_OBJECT_SCALE every time an object's scale is changed through a script */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectScale(ptr, scale); /* End of tes3mp addition @@ -547,7 +547,7 @@ namespace MWScript Send an ID_OBJECT_PLACE packet every time an object is placed in the world through a script */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectPlace(ptr); /* End of tes3mp addition diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 3be492c89..ccaa14bd2 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -34,7 +34,7 @@ namespace MWWorld Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained by the player */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendObjectDelete(getTarget()); mwmp::Main::get().getLocalPlayer()->sendInventory(); /* diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 764244f6d..5ae907923 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2324,7 +2324,7 @@ namespace MWWorld Send an ID_DOOR_STATE packet every time a door is activated */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendDoorState(door, state); /* End of tes3mp addition @@ -2341,7 +2341,7 @@ namespace MWWorld Send an ID_DOOR_STATE packet every time a door is activated */ - mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->sendDoorState(door, state); /* End of tes3mp addition