From d7a760490e908b9670a63694fc691a11d231367f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 5 Apr 2017 08:43:35 +0300 Subject: [PATCH] [Client] Simplify sending of world packets, part 2 --- apps/openmw/mwmp/WorldEvent.cpp | 125 +++++++++++++++++++ apps/openmw/mwmp/WorldEvent.hpp | 9 ++ apps/openmw/mwscript/animationextensions.cpp | 13 +- apps/openmw/mwscript/interpretercontext.cpp | 59 +-------- apps/openmw/mwscript/miscextensions.cpp | 9 +- apps/openmw/mwscript/soundextensions.cpp | 8 +- apps/openmw/mwworld/worldimp.cpp | 32 +---- 7 files changed, 143 insertions(+), 112 deletions(-) diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index f272220c4..7a3d99a9e 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -208,6 +208,131 @@ void WorldEvent::sendObjectScale(MWWorld::Ptr ptr, int scale) mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send(); } +void WorldEvent::sendObjectAnimPlay(MWWorld::Ptr ptr, std::string group, int mode) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + worldObject.animGroup = group; + worldObject.animMode = mode; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->Send(); +} + +void WorldEvent::sendDoorState(MWWorld::Ptr ptr, int state) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + worldObject.doorState = state; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_STATE)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_STATE)->Send(); + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Door activation 1\n- cellRef: %s, %i\n- cell: %s\n- state: %s", + worldObject.refId.c_str(), worldObject.refNumIndex, cell.getDescription().c_str(), + worldObject.doorState ? "true" : "false"); +} + +void WorldEvent::sendMusicPlay(std::string filename) +{ + mwmp::WorldObject worldObject; + worldObject.filename = filename; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->Send(); +} + +void WorldEvent::sendVideoPlay(std::string filename, bool allowSkipping) +{ + mwmp::WorldObject worldObject; + worldObject.filename = filename; + worldObject.allowSkipping = allowSkipping; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->Send(); +} + +void WorldEvent::sendScriptLocalShort(MWWorld::Ptr ptr, int index, int shortVal) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + worldObject.index = index; + worldObject.shortVal = shortVal; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_SHORT)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_SHORT)->Send(); + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_SHORT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- shortVal: %i", + worldObject.refId.c_str(), worldObject.refNumIndex, cell.getDescription().c_str(), + worldObject.index, worldObject.shortVal); +} + +void WorldEvent::sendScriptLocalFloat(MWWorld::Ptr ptr, int index, float floatVal) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + worldObject.index = index; + worldObject.floatVal = floatVal; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_FLOAT)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_FLOAT)->Send(); + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_FLOAT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- floatVal: %f", + worldObject.refId.c_str(), worldObject.refNumIndex, cell.getDescription().c_str(), + worldObject.index, worldObject.floatVal); +} + +void WorldEvent::sendScriptMemberShort(std::string refId, int index, int shortVal) +{ + mwmp::WorldObject worldObject; + worldObject.refId = refId; + worldObject.index = index; + worldObject.shortVal = shortVal; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_MEMBER_SHORT)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_MEMBER_SHORT)->Send(); + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_MEMBER_SHORT\n- cellRef: %s\n- index: %i\n- shortVal: %i", + worldObject.refId.c_str(), worldObject.index, worldObject.shortVal); +} + +void WorldEvent::sendScriptGlobalShort(std::string varName, int shortVal) +{ + mwmp::WorldObject worldObject; + worldObject.varName = varName; + worldObject.shortVal = shortVal; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_GLOBAL_SHORT)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_GLOBAL_SHORT)->Send(); + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_GLOBAL_SHORT\n- varName: %s\n- shortVal: %i", + worldObject.varName.c_str(), worldObject.shortVal); +} + void WorldEvent::editActors(MWWorld::CellStore* cellStore) { WorldObject worldObject; diff --git a/apps/openmw/mwmp/WorldEvent.hpp b/apps/openmw/mwmp/WorldEvent.hpp index a6c2e81e9..c023e7b11 100644 --- a/apps/openmw/mwmp/WorldEvent.hpp +++ b/apps/openmw/mwmp/WorldEvent.hpp @@ -19,11 +19,20 @@ namespace mwmp void sendActors(MWWorld::CellStore* cellStore); void sendContainers(MWWorld::CellStore* cellStore); + void sendObjectPlace(MWWorld::Ptr ptr); void sendObjectDelete(MWWorld::Ptr ptr); void sendObjectLock(MWWorld::Ptr ptr, int lockLevel); void sendObjectUnlock(MWWorld::Ptr ptr); void sendObjectScale(MWWorld::Ptr ptr, int scale); + void sendObjectAnimPlay(MWWorld::Ptr ptr, std::string group, int mode); + void sendDoorState(MWWorld::Ptr ptr, int state); + void sendMusicPlay(std::string filename); + void sendVideoPlay(std::string filename, bool allowSkipping); + void sendScriptLocalShort(MWWorld::Ptr ptr, int index, int shortVal); + void sendScriptLocalFloat(MWWorld::Ptr ptr, int index, float floatVal); + void sendScriptMemberShort(std::string refId, int index, int shortVal); + void sendScriptGlobalShort(std::string varName, int shortVal); void editActors(MWWorld::CellStore* cellStore); void editContainers(MWWorld::CellStore* cellStore); diff --git a/apps/openmw/mwscript/animationextensions.cpp b/apps/openmw/mwscript/animationextensions.cpp index 9e6d41d94..63e6924ce 100644 --- a/apps/openmw/mwscript/animationextensions.cpp +++ b/apps/openmw/mwscript/animationextensions.cpp @@ -72,18 +72,7 @@ namespace MWScript if (mwmp::Main::isValidPacketScript(ptr.getClass().getScript(ptr))) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *ptr.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = ptr.getCellRef().getRefId(); - worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; - worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldObject.animGroup = group; - worldObject.animMode = mode; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->Send(); + worldEvent->sendObjectAnimPlay(ptr, group, mode); } /* End of tes3mp addition diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 1f4fa20c6..2f8ea6929 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -203,22 +203,7 @@ namespace MWScript if (sendPackets) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *mReference.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = mReference.getCellRef().getRefId(); - worldObject.refNumIndex = mReference.getCellRef().getRefNum().mIndex; - worldObject.mpNum = mReference.getCellRef().getMpNum(); - worldObject.index = index; - worldObject.shortVal = value; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_SHORT)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_SHORT)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_SHORT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- shortVal: %i", - worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(), - worldObject.index, worldObject.shortVal); + worldEvent->sendScriptLocalShort(mReference, index, value); } /* End of tes3mp addition @@ -250,22 +235,7 @@ namespace MWScript if (sendPackets && value == (int) value) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *mReference.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = mReference.getCellRef().getRefId(); - worldObject.refNumIndex = mReference.getCellRef().getRefNum().mIndex; - worldObject.mpNum = mReference.getCellRef().getMpNum(); - worldObject.index = index; - worldObject.floatVal = value; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_FLOAT)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_FLOAT)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_FLOAT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- floatVal: %f", - worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(), - worldObject.index, worldObject.floatVal); + worldEvent->sendScriptLocalFloat(mReference, index, value); } /* End of tes3mp addition @@ -322,17 +292,7 @@ namespace MWScript if (sendPackets) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - - mwmp::WorldObject worldObject; - worldObject.varName = name; - worldObject.shortVal = value; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_GLOBAL_SHORT)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_GLOBAL_SHORT)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_GLOBAL_SHORT\n- varName: %s\n- shortVal: %i", - worldObject.varName.c_str(), worldObject.shortVal); + worldEvent->sendScriptGlobalShort(name, value); } /* End of tes3mp addition @@ -667,18 +627,7 @@ namespace MWScript if (sendPackets && !global) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - - mwmp::WorldObject worldObject; - worldObject.refId = id; - worldObject.index = index; - worldObject.shortVal = value; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_MEMBER_SHORT)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_MEMBER_SHORT)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_MEMBER_SHORT\n- cellRef: %s\n- index: %i\n- shortVal: %i", - worldObject.refId.c_str(), worldObject.index, worldObject.shortVal); + worldEvent->sendScriptMemberShort(id, index, value); } /* End of tes3mp addition diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 604bc023c..8379417a3 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -96,14 +96,7 @@ namespace MWScript through a script */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - - mwmp::WorldObject worldObject; - worldObject.filename = name; - worldObject.allowSkipping = allowSkipping; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->Send(); + worldEvent->sendVideoPlay(name, allowSkipping); /* End of tes3mp addition */ diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index d09a17f88..5b09d9a74 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -80,13 +80,7 @@ namespace MWScript a script */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - - mwmp::WorldObject worldObject; - worldObject.filename = sound; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->Send(); + worldEvent->sendMusicPlay(sound); /* End of tes3mp addition */ diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 1b1993fcc..764244f6d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2325,21 +2325,7 @@ namespace MWWorld Send an ID_DOOR_STATE packet every time a door is activated */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *door.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = door.getCellRef().getRefId(); - worldObject.refNumIndex = door.getCellRef().getRefNum().mIndex; - worldObject.mpNum = door.getCellRef().getMpNum(); - worldObject.doorState = state; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_STATE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_STATE)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Door activation 1\n- cellRef: %s, %i\n- cell: %s\n- state: %s", - worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(), - worldObject.doorState ? "true" : "false"); + worldEvent->sendDoorState(door, state); /* End of tes3mp addition */ @@ -2356,21 +2342,7 @@ namespace MWWorld Send an ID_DOOR_STATE packet every time a door is activated */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *door.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = door.getCellRef().getRefId(); - worldObject.refNumIndex = door.getCellRef().getRefNum().mIndex; - worldObject.mpNum = door.getCellRef().getMpNum(); - worldObject.doorState = state; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_STATE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_STATE)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Door activation 2\n- cellRef: %s, %i\n- cell: %s\n- state: %s", - worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str(), - worldObject.doorState ? "true" : "false"); + worldEvent->sendDoorState(door, state); /* End of tes3mp addition */