[Client] Clean up getting and resetting of WorldEvent

This commit is contained in:
David Cernat 2017-04-05 09:04:41 +03:00
parent d7a760490e
commit 9759764699
15 changed files with 59 additions and 38 deletions

View file

@ -107,7 +107,8 @@ namespace MWGui
Send an ID_CONTAINER packet every time an item starts being dragged Send an ID_CONTAINER packet every time an item starts being dragged
from a container 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->cell = *mPtr.getCell()->getCell();
worldEvent->action = mwmp::BaseEvent::REMOVE; 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 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->cell = *mPtr.getCell()->getCell();
worldEvent->action = mwmp::BaseEvent::ADD; 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 Send an ID_CONTAINER packet every time the Take All button is used on
a container 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->cell = *mPtr.getCell()->getCell();
worldEvent->action = mwmp::BaseEvent::SET; worldEvent->action = mwmp::BaseEvent::SET;

View file

@ -64,7 +64,7 @@ namespace MWGui
Send an ID_OBJECT_PLACE packet every time an object is dropped into the world from Send an ID_OBJECT_PLACE packet every time an object is dropped into the world from
the inventory screen the inventory screen
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectPlace(dropped); worldEvent->sendObjectPlace(dropped);
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -644,7 +644,7 @@ namespace MWGui
Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained
by the player by the player
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectDelete(object); worldEvent->sendObjectDelete(object);
mwmp::Main::get().getLocalPlayer()->sendInventory(); mwmp::Main::get().getLocalPlayer()->sendInventory();
/* /*

View file

@ -63,7 +63,7 @@ namespace MWMechanics
Send an ID_OBJECT_UNLOCK packet every time an object is unlocked 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); worldEvent->sendObjectUnlock(lock);
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -1067,11 +1067,8 @@ LocalPlayer *Networking::getLocalPlayer()
return mwmp::Main::get().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; return &worldEvent;
} }

View file

@ -40,7 +40,8 @@ namespace mwmp
bool isConnected(); bool isConnected();
WorldEvent *resetWorldEvent(); WorldEvent *getWorldEvent();
LocalPlayer *getLocalPlayer();
private: private:
bool connected; bool connected;
@ -55,7 +56,6 @@ namespace mwmp
void processPlayerPacket(RakNet::Packet *packet); void processPlayerPacket(RakNet::Packet *packet);
void processWorldPacket(RakNet::Packet *packet); void processWorldPacket(RakNet::Packet *packet);
void receiveMessage(RakNet::Packet *packet); void receiveMessage(RakNet::Packet *packet);
LocalPlayer *getLocalPlayer();
void preInit(std::vector<std::string> &content, Files::Collections &collections); void preInit(std::vector<std::string> &content, Files::Collections &collections);
}; };

View file

@ -35,6 +35,13 @@ Networking *WorldEvent::getNetworking()
return mwmp::Main::get().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) void WorldEvent::addObject(WorldObject worldObject)
{ {
objectChanges.objects.push_back(worldObject); objectChanges.objects.push_back(worldObject);
@ -42,9 +49,9 @@ void WorldEvent::addObject(WorldObject worldObject)
void WorldEvent::sendActors(MWWorld::CellStore* cellStore) void WorldEvent::sendActors(MWWorld::CellStore* cellStore)
{ {
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); reset();
worldEvent->cell = *cellStore->getCell(); cell = *cellStore->getCell();
worldEvent->action = BaseEvent::SET; action = BaseEvent::SET;
MWWorld::CellRefList<ESM::NPC> *npcList = cellStore->getNpcs(); MWWorld::CellRefList<ESM::NPC> *npcList = cellStore->getNpcs();
@ -58,7 +65,7 @@ void WorldEvent::sendActors(MWWorld::CellStore* cellStore)
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.mpNum = ptr.getCellRef().getMpNum(); worldObject.mpNum = ptr.getCellRef().getMpNum();
worldEvent->addObject(worldObject); addObject(worldObject);
} }
MWWorld::CellRefList<ESM::Creature> *creatureList = cellStore->getCreatures(); MWWorld::CellRefList<ESM::Creature> *creatureList = cellStore->getCreatures();
@ -73,18 +80,18 @@ void WorldEvent::sendActors(MWWorld::CellStore* cellStore)
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.mpNum = ptr.getCellRef().getMpNum(); 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(); mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->Send();
} }
void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) void WorldEvent::sendContainers(MWWorld::CellStore* cellStore)
{ {
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); reset();
worldEvent->cell = *cellStore->getCell(); cell = *cellStore->getCell();
worldEvent->action = BaseEvent::SET; action = BaseEvent::SET;
MWWorld::CellRefList<ESM::Container> *containerList = cellStore->getContainers(); MWWorld::CellRefList<ESM::Container> *containerList = cellStore->getContainers();
@ -112,16 +119,17 @@ void WorldEvent::sendContainers(MWWorld::CellStore* cellStore)
worldObject.containerChanges.items.push_back(containerItem); 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(); mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->Send();
} }
void WorldEvent::sendObjectPlace(MWWorld::Ptr ptr) void WorldEvent::sendObjectPlace(MWWorld::Ptr ptr)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
@ -152,6 +160,7 @@ void WorldEvent::sendObjectPlace(MWWorld::Ptr ptr)
void WorldEvent::sendObjectDelete(MWWorld::Ptr ptr) void WorldEvent::sendObjectDelete(MWWorld::Ptr ptr)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
@ -166,6 +175,7 @@ void WorldEvent::sendObjectDelete(MWWorld::Ptr ptr)
void WorldEvent::sendObjectLock(MWWorld::Ptr ptr, int lockLevel) void WorldEvent::sendObjectLock(MWWorld::Ptr ptr, int lockLevel)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
@ -181,6 +191,7 @@ void WorldEvent::sendObjectLock(MWWorld::Ptr ptr, int lockLevel)
void WorldEvent::sendObjectUnlock(MWWorld::Ptr ptr) void WorldEvent::sendObjectUnlock(MWWorld::Ptr ptr)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
@ -195,6 +206,7 @@ void WorldEvent::sendObjectUnlock(MWWorld::Ptr ptr)
void WorldEvent::sendObjectScale(MWWorld::Ptr ptr, int scale) void WorldEvent::sendObjectScale(MWWorld::Ptr ptr, int scale)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; 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) void WorldEvent::sendObjectAnimPlay(MWWorld::Ptr ptr, std::string group, int mode)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; 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) void WorldEvent::sendDoorState(MWWorld::Ptr ptr, int state)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
@ -245,6 +259,7 @@ void WorldEvent::sendDoorState(MWWorld::Ptr ptr, int state)
void WorldEvent::sendMusicPlay(std::string filename) void WorldEvent::sendMusicPlay(std::string filename)
{ {
reset();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
worldObject.filename = filename; worldObject.filename = filename;
addObject(worldObject); addObject(worldObject);
@ -255,6 +270,7 @@ void WorldEvent::sendMusicPlay(std::string filename)
void WorldEvent::sendVideoPlay(std::string filename, bool allowSkipping) void WorldEvent::sendVideoPlay(std::string filename, bool allowSkipping)
{ {
reset();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
worldObject.filename = filename; worldObject.filename = filename;
worldObject.allowSkipping = allowSkipping; 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) void WorldEvent::sendScriptLocalShort(MWWorld::Ptr ptr, int index, int shortVal)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; 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) void WorldEvent::sendScriptLocalFloat(MWWorld::Ptr ptr, int index, float floatVal)
{ {
reset();
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::WorldObject worldObject; 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) void WorldEvent::sendScriptMemberShort(std::string refId, int index, int shortVal)
{ {
reset();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
worldObject.refId = refId; worldObject.refId = refId;
worldObject.index = index; 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) void WorldEvent::sendScriptGlobalShort(std::string varName, int shortVal)
{ {
reset();
mwmp::WorldObject worldObject; mwmp::WorldObject worldObject;
worldObject.varName = varName; worldObject.varName = varName;
worldObject.shortVal = shortVal; worldObject.shortVal = shortVal;

View file

@ -15,6 +15,7 @@ namespace mwmp
WorldEvent(); WorldEvent();
virtual ~WorldEvent(); virtual ~WorldEvent();
void reset();
void addObject(WorldObject worldObject); void addObject(WorldObject worldObject);
void sendActors(MWWorld::CellStore* cellStore); void sendActors(MWWorld::CellStore* cellStore);

View file

@ -71,7 +71,7 @@ namespace MWScript
*/ */
if (mwmp::Main::isValidPacketScript(ptr.getClass().getScript(ptr))) 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); worldEvent->sendObjectAnimPlay(ptr, group, mode);
} }
/* /*

View file

@ -202,7 +202,7 @@ namespace MWScript
*/ */
if (sendPackets) if (sendPackets)
{ {
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendScriptLocalShort(mReference, index, value); worldEvent->sendScriptLocalShort(mReference, index, value);
} }
/* /*
@ -234,7 +234,7 @@ namespace MWScript
*/ */
if (sendPackets && value == (int) value) 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); worldEvent->sendScriptLocalFloat(mReference, index, value);
} }
/* /*
@ -291,7 +291,7 @@ namespace MWScript
*/ */
if (sendPackets) if (sendPackets)
{ {
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendScriptGlobalShort(name, value); worldEvent->sendScriptGlobalShort(name, value);
} }
/* /*
@ -626,7 +626,7 @@ namespace MWScript
*/ */
if (sendPackets && !global) if (sendPackets && !global)
{ {
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendScriptMemberShort(id, index, value); worldEvent->sendScriptMemberShort(id, index, value);
} }
/* /*

View file

@ -95,7 +95,7 @@ namespace MWScript
Send an ID_VIDEO_PLAY packet every time a video is played Send an ID_VIDEO_PLAY packet every time a video is played
through a script through a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendVideoPlay(name, allowSkipping); worldEvent->sendVideoPlay(name, allowSkipping);
/* /*
End of tes3mp addition End of tes3mp addition
@ -205,7 +205,7 @@ namespace MWScript
Send an ID_OBJECT_LOCK packet every time an object is locked Send an ID_OBJECT_LOCK packet every time an object is locked
through a script through a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectLock(ptr, lockLevel); worldEvent->sendObjectLock(ptr, lockLevel);
/* /*
End of tes3mp addition End of tes3mp addition
@ -243,7 +243,7 @@ namespace MWScript
Send an ID_OBJECT_UNLOCK packet every time an object is unlocked Send an ID_OBJECT_UNLOCK packet every time an object is unlocked
through a script through a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectUnlock(ptr); worldEvent->sendObjectUnlock(ptr);
/* /*
End of tes3mp addition End of tes3mp addition
@ -715,7 +715,7 @@ namespace MWScript
Send an ID_OBJECT_DELETE packet every time an object is deleted Send an ID_OBJECT_DELETE packet every time an object is deleted
through a script through a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectDelete(ptr); worldEvent->sendObjectDelete(ptr);
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -79,7 +79,7 @@ namespace MWScript
Send an ID_MUSIC_PLAY packet every time new music is streamed through Send an ID_MUSIC_PLAY packet every time new music is streamed through
a script a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendMusicPlay(sound); worldEvent->sendMusicPlay(sound);
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -52,7 +52,7 @@ namespace MWScript
Send an ID_OBJECT_SCALE every time an object's scale is changed Send an ID_OBJECT_SCALE every time an object's scale is changed
through a script through a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectScale(ptr, scale); worldEvent->sendObjectScale(ptr, scale);
/* /*
End of tes3mp addition 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 Send an ID_OBJECT_PLACE packet every time an object is placed in the world
through a script through a script
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectPlace(ptr); worldEvent->sendObjectPlace(ptr);
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -34,7 +34,7 @@ namespace MWWorld
Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained Send an ID_PLAYER_INVENTORY packet as well because of the item thus gained
by the player by the player
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->sendObjectDelete(getTarget()); worldEvent->sendObjectDelete(getTarget());
mwmp::Main::get().getLocalPlayer()->sendInventory(); mwmp::Main::get().getLocalPlayer()->sendInventory();
/* /*

View file

@ -2324,7 +2324,7 @@ namespace MWWorld
Send an ID_DOOR_STATE packet every time a door is activated 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); worldEvent->sendDoorState(door, state);
/* /*
End of tes3mp addition End of tes3mp addition
@ -2341,7 +2341,7 @@ namespace MWWorld
Send an ID_DOOR_STATE packet every time a door is activated 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); worldEvent->sendDoorState(door, state);
/* /*
End of tes3mp addition End of tes3mp addition