[Client] Create LocalEvent class and use it instead of WorldEvent

pull/163/head
David Cernat 8 years ago
parent ee86c9161d
commit 624b85347a

@ -96,7 +96,7 @@ add_openmw_dir (mwbase
inputmanager windowmanager statemanager
)
add_openmw_dir (mwmp DedicatedPlayer LocalPlayer Networking Main GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList WorldController)
add_openmw_dir (mwmp DedicatedPlayer LocalEvent LocalPlayer Networking Main GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList WorldController)
# Main executable

@ -1,8 +1,8 @@
#include "hud.hpp"
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include "../mwworld/cellstore.hpp"
#include <MyGUI_RenderManager.h>
@ -66,10 +66,9 @@ namespace MWGui
dropped.getCellRef().setRefNumIndex(cellStore->getLastRefNumIndex());
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *dropped.getCell()->getCell();
event->cellRef.mRefID = dropped.getCellRef().getRefId();
event->cellRef.mRefNum = dropped.getCellRef().getRefNum();
event->addCellRef(dropped.getCellRef());
// Make sure we send the RefData position instead of the CellRef one, because that's what
// we actually see on this client
@ -79,14 +78,11 @@ namespace MWGui
// automatically for stacks of gold
event->count = dropped.getRefData().getCount();
// Get the real count of gold in a stack
event->cellRef.mGoldValue = dropped.getCellRef().getGoldValue();
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE\n- cellRef: %s, %i\n- count: %i",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
dropped.getCellRef().getRefId().c_str(),
dropped.getCellRef().getRefNum().mIndex,
event->count);
return dropped;

@ -16,9 +16,9 @@
#include <components/settings/settings.hpp>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwbase/world.hpp"
@ -635,10 +635,9 @@ namespace MWGui
MWWorld::Ptr newObject = *player.getClass().getContainerStore (player).add (object, object.getRefData().getCount(), player);
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *object.getCell()->getCell();
event->cellRef.mRefID = object.getCellRef().getRefId();
event->cellRef.mRefNum = object.getCellRef().getRefNum();
event->addCellRef(object.getCellRef());
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(event);
// remove from world

@ -1,8 +1,8 @@
#include "security.hpp"
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include "../mwworld/cellstore.hpp"
@ -59,10 +59,9 @@ namespace MWMechanics
if (Misc::Rng::roll0to99() <= x)
{
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *lock.getCell()->getCell();
event->cellRef.mRefID = lock.getCellRef().getRefId();
event->cellRef.mRefNum = lock.getCellRef().getRefNum();
event->addCellRef(lock.getCellRef());
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(event);
lock.getClass().unlock(lock);

@ -0,0 +1,33 @@
#include "LocalEvent.hpp"
#include "Networking.hpp"
#include "Main.hpp"
using namespace mwmp;
using namespace std;
LocalEvent::LocalEvent(RakNet::RakNetGUID guid)
{
this->guid = guid;
}
LocalEvent::~LocalEvent()
{
}
Networking *LocalEvent::getNetworking()
{
return mwmp::Main::get().getNetworking();
}
void LocalEvent::addCellRef(MWWorld::CellRef worldCellRef)
{
cellRef.mRefID = worldCellRef.getRefId();
cellRef.mRefNum = worldCellRef.getRefNum();
cellRef.mGoldValue = worldCellRef.getGoldValue();
}
void LocalEvent::addRefId(std::string refId)
{
cellRef.mRefID = refId;
}

@ -0,0 +1,27 @@
#ifndef OPENMW_LOCALEVENT_HPP
#define OPENMW_LOCALEVENT_HPP
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwworld/cellstore.hpp"
#include <RakNetTypes.h>
namespace mwmp
{
class Networking;
class LocalEvent : public WorldEvent
{
public:
LocalEvent(RakNet::RakNetGUID guid);
virtual ~LocalEvent();
void addCellRef(MWWorld::CellRef worldCellRef);
void addRefId(std::string refId);
private:
Networking *getNetworking();
};
}
#endif //OPENMW_LOCALEVENT_HPP

@ -26,7 +26,6 @@
#include "../mwstate/statemanagerimp.hpp"
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/Version.hpp>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "DedicatedPlayer.hpp"
#include "LocalPlayer.hpp"
#include "GUIController.hpp"
@ -732,7 +731,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
pl = Players::getPlayer(guid);
WorldPacket *myPacket = worldController.GetPacket(packet->data[0]);
WorldEvent *event = new WorldEvent(guid);
LocalEvent *event = new LocalEvent(guid);
myPacket->Packet(&bsIn, event, false);
switch (packet->data[0])
@ -1123,9 +1122,9 @@ LocalPlayer *Networking::getLocalPlayer()
return mwmp::Main::get().getLocalPlayer();
}
WorldEvent *Networking::createWorldEvent()
LocalEvent *Networking::createLocalEvent()
{
return new WorldEvent(getLocalPlayer()->guid);
return new LocalEvent(getLocalPlayer()->guid);
}
bool Networking::isDedicatedPlayer(const MWWorld::Ptr &ptr)

@ -9,6 +9,7 @@
#include <BitStream.h>
#include <string>
#include "LocalEvent.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Controllers/PlayerPacketController.hpp>
#include <components/openmw-mp/Controllers/WorldPacketController.hpp>
@ -39,7 +40,7 @@ namespace mwmp
bool isConnected();
WorldEvent *createWorldEvent();
LocalEvent *createLocalEvent();
private:
bool connected;

@ -3,9 +3,9 @@
#include <stdexcept>
#include <limits>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/class.hpp"
@ -66,10 +66,9 @@ namespace MWScript
// Added by tes3mp to check and set whether packets should be sent about this script
if (mwmp::Main::isValidPacketScript(ptr.getClass().getScript(ptr)))
{
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->cellRef.mRefID = ptr.getCellRef().getRefId();
event->cellRef.mRefNum = ptr.getCellRef().getRefNum();
event->addCellRef(ptr.getCellRef());
event->animGroup = group;
event->animMode = mode;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->Send(event);

@ -10,10 +10,10 @@
#include <components/esm/cellid.hpp>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include <components/openmw-mp/Log.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include "../mwworld/esmstore.hpp"
@ -189,17 +189,16 @@ namespace MWScript
// Added by tes3mp
if (sendPackets)
{
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *mReference.getCell()->getCell();
event->cellRef.mRefID = mReference.getCellRef().getRefId();
event->cellRef.mRefNum = mReference.getCellRef().getRefNum();
event->addCellRef(mReference.getCellRef());
event->index = index;
event->shortVal = value;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_SHORT)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_SHORT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- shortVal: %i",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
mReference.getCellRef().getRefId().c_str(),
mReference.getCellRef().getRefNum().mIndex,
event->cell.getDescription().c_str(),
event->index,
event->shortVal);
@ -226,17 +225,16 @@ namespace MWScript
// Only send a packet if this float has no decimals (to avoid spam)
if (sendPackets && value == (int) value)
{
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *mReference.getCell()->getCell();
event->cellRef.mRefID = mReference.getCellRef().getRefId();
event->cellRef.mRefNum = mReference.getCellRef().getRefNum();
event->addCellRef(mReference.getCellRef());
event->index = index;
event->floatVal = value;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_LOCAL_FLOAT)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_LOCAL_FLOAT\n- cellRef: %s, %i\n- cell: %s\n- index: %i\n- floatVal: %f",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
mReference.getCellRef().getRefId().c_str(),
mReference.getCellRef().getRefNum().mIndex,
event->cell.getDescription().c_str(),
event->index,
event->floatVal);
@ -287,7 +285,7 @@ namespace MWScript
// Added by tes3mp
if (sendPackets)
{
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->varName = name;
event->shortVal = value;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_GLOBAL_SHORT)->Send(event);
@ -620,14 +618,14 @@ namespace MWScript
// Added by tes3mp
if (sendPackets && !global)
{
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
event->cellRef.mRefID = id;
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->addRefId(id);
event->index = index;
event->shortVal = value;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_SCRIPT_MEMBER_SHORT)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_SCRIPT_MEMBER_SHORT\n- cellRef: %s\n- index: %i\n- shortVal: %i",
event->cellRef.mRefID.c_str(),
id.c_str(),
event->index,
event->shortVal);
}

@ -2,9 +2,9 @@
#include <cstdlib>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include <components/compiler/extensions.hpp>
#include <components/compiler/opcodes.hpp>
@ -90,7 +90,7 @@ namespace MWScript
runtime.pop();
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->filename = name;
event->allowSkipping = allowSkipping;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->Send(event);
@ -194,10 +194,9 @@ namespace MWScript
}
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->cellRef.mRefID = ptr.getCellRef().getRefId();
event->cellRef.mRefNum = ptr.getCellRef().getRefNum();
event->addCellRef(ptr.getCellRef());
event->lockLevel = lockLevel;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->Send(event);
@ -228,10 +227,9 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime);
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->cellRef.mRefID = ptr.getCellRef().getRefId();
event->cellRef.mRefNum = ptr.getCellRef().getRefNum();
event->addCellRef(ptr.getCellRef());
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(event);
ptr.getClass().unlock (ptr);
@ -695,10 +693,9 @@ namespace MWScript
if (parameter == 1)
{
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->cellRef.mRefID = ptr.getCellRef().getRefId();
event->cellRef.mRefNum = ptr.getCellRef().getRefNum();
event->addCellRef(ptr.getCellRef());
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(event);
MWBase::Environment::get().getWorld()->deleteObject(ptr);

@ -1,8 +1,8 @@
#include "extensions.hpp"
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include <components/compiler/extensions.hpp>
#include <components/compiler/opcodes.hpp>
@ -71,7 +71,7 @@ namespace MWScript
runtime.pop();
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->filename = sound;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->Send(event);

@ -1,8 +1,8 @@
#include <iostream>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include <components/sceneutil/positionattitudetransform.hpp>
@ -47,10 +47,9 @@ namespace MWScript
runtime.pop();
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->cellRef.mRefID = ptr.getCellRef().getRefId();
event->cellRef.mRefNum = ptr.getCellRef().getRefNum();
event->addCellRef(ptr.getCellRef());
event->cellRef.mPos = ptr.getCellRef().getPosition();
event->scale = scale;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send(event);
@ -547,10 +546,9 @@ namespace MWScript
ptr.getCellRef().setRefNumIndex(cellStore->getLastRefNumIndex());
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *ptr.getCell()->getCell();
event->cellRef.mRefID = ptr.getCellRef().getRefId();
event->cellRef.mRefNum = ptr.getCellRef().getRefNum();
event->addCellRef(ptr.getCellRef());
// Make sure we send the RefData position instead of the CellRef one, because that's what
// we actually see on this client
@ -560,8 +558,8 @@ namespace MWScript
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE\n- cellRef: %s, %i\n- count: %i",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
ptr.getCellRef().getRefId().c_str(),
ptr.getCellRef().getRefNum().mIndex,
event->count);
}
}

@ -1,9 +1,9 @@
#include "actiontake.hpp"
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include <components/openmw-mp/Log.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include "../mwmp/LocalPlayer.hpp"
#include "../mwworld/cellstore.hpp"
@ -26,15 +26,14 @@ namespace MWWorld
MWWorld::Ptr newitem = *actor.getClass().getContainerStore (actor).add (getTarget(), getTarget().getRefData().getCount(), actor);
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *getTarget().getCell()->getCell();
event->cellRef.mRefID = getTarget().getCellRef().getRefId();
event->cellRef.mRefNum = getTarget().getCellRef().getRefNum();
event->addCellRef(getTarget().getCellRef());
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_DELETE about\n- cellRef: %s, %i\n- cell: %s.",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
getTarget().getCellRef().getRefId().c_str(),
getTarget().getCellRef().getRefNum().mIndex,
event->cell.getDescription().c_str());
// LocalPlayer's inventory has changed, so send a packet with it

@ -5,9 +5,9 @@
#include <osg/Group>
#include <osg/ComputeBoundsVisitor>
#include <components/openmw-mp/Base/WorldEvent.hpp>
#include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp"
#include "../mwmp/LocalEvent.hpp"
#include <components/esm/esmreader.hpp>
#include <components/esm/esmwriter.hpp>
@ -2266,16 +2266,15 @@ namespace MWWorld
}
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *door.getCell()->getCell();
event->cellRef.mRefID = door.getCellRef().getRefId();
event->cellRef.mRefNum = door.getCellRef().getRefNum();
event->addCellRef(door.getCellRef());
event->state = state;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_ACTIVATE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Door activation 1\n- cellRef: %s, %i\n- cell: %s\n- state: %s",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
door.getCellRef().getRefId().c_str(),
door.getCellRef().getRefNum().mIndex,
event->cell.getDescription().c_str(),
event->state ? "true" : "false");
@ -2286,16 +2285,15 @@ namespace MWWorld
void World::activateDoor(const Ptr &door, int state)
{
// Added by tes3mp
mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent();
mwmp::LocalEvent *event = mwmp::Main::get().getNetworking()->createLocalEvent();
event->cell = *door.getCell()->getCell();
event->cellRef.mRefID = door.getCellRef().getRefId();
event->cellRef.mRefNum = door.getCellRef().getRefNum();
event->addCellRef(door.getCellRef());
event->state = state;
mwmp::Main::get().getNetworking()->getWorldPacket(ID_DOOR_ACTIVATE)->Send(event);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Door activation 2\n- cellRef: %s, %i\n- cell: %s\n- state: %s",
event->cellRef.mRefID.c_str(),
event->cellRef.mRefNum.mIndex,
door.getCellRef().getRefId().c_str(),
door.getCellRef().getRefNum().mIndex,
event->cell.getDescription().c_str(),
event->state ? "true" : "false");

Loading…
Cancel
Save