mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 10:23:51 +00:00
[Server] Clean up WorldFunctions by using readEvent pointer
Also rename scriptEvent into writeEvent, along with matching methods, for clarity.
This commit is contained in:
parent
809b4d78ba
commit
b54560a362
2 changed files with 63 additions and 55 deletions
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
|
|
||||||
BaseEvent scriptEvent;
|
BaseEvent *readEvent;
|
||||||
|
BaseEvent writeEvent;
|
||||||
|
|
||||||
WorldObject tempWorldObject;
|
WorldObject tempWorldObject;
|
||||||
const WorldObject emptyWorldObject = {};
|
const WorldObject emptyWorldObject = {};
|
||||||
|
@ -18,138 +19,143 @@ const WorldObject emptyWorldObject = {};
|
||||||
ContainerItem tempContainerItem;
|
ContainerItem tempContainerItem;
|
||||||
const ContainerItem emptyContainerItem = {};
|
const ContainerItem emptyContainerItem = {};
|
||||||
|
|
||||||
void WorldFunctions::InitScriptEvent(unsigned short pid) noexcept
|
void WorldFunctions::ReadLastEvent() noexcept
|
||||||
|
{
|
||||||
|
readEvent = mwmp::Networking::getPtr()->getLastEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldFunctions::InitiateEvent(unsigned short pid) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, );
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
scriptEvent.cell.blank();
|
writeEvent.cell.blank();
|
||||||
scriptEvent.objectChanges.objects.clear();
|
writeEvent.objectChanges.objects.clear();
|
||||||
scriptEvent.guid = player->guid;
|
writeEvent.guid = player->guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WorldFunctions::GetObjectChangesSize() noexcept
|
unsigned int WorldFunctions::GetObjectChangesSize() noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.count;
|
return readEvent->objectChanges.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char WorldFunctions::GetLastEventAction() noexcept
|
unsigned char WorldFunctions::GetEventAction() noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->action;
|
return readEvent->action;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *WorldFunctions::GetObjectRefId(unsigned int i) noexcept
|
const char *WorldFunctions::GetObjectRefId(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).refId.c_str();
|
return readEvent->objectChanges.objects.at(i).refId.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectRefNumIndex(unsigned int i) noexcept
|
int WorldFunctions::GetObjectRefNumIndex(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).refNumIndex;
|
return readEvent->objectChanges.objects.at(i).refNumIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectMpNum(unsigned int i) noexcept
|
int WorldFunctions::GetObjectMpNum(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).mpNum;
|
return readEvent->objectChanges.objects.at(i).mpNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectCount(unsigned int i) noexcept
|
int WorldFunctions::GetObjectCount(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).count;
|
return readEvent->objectChanges.objects.at(i).count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectCharge(unsigned int i) noexcept
|
int WorldFunctions::GetObjectCharge(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).charge;
|
return readEvent->objectChanges.objects.at(i).charge;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectGoldValue(unsigned int i) noexcept
|
int WorldFunctions::GetObjectGoldValue(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).goldValue;
|
return readEvent->objectChanges.objects.at(i).goldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double WorldFunctions::GetObjectScale(unsigned int i) noexcept
|
double WorldFunctions::GetObjectScale(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).scale;
|
return readEvent->objectChanges.objects.at(i).scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectDoorState(unsigned int i) noexcept
|
int WorldFunctions::GetObjectDoorState(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).doorState;
|
return readEvent->objectChanges.objects.at(i).doorState;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectLockLevel(unsigned int i) noexcept
|
int WorldFunctions::GetObjectLockLevel(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).lockLevel;
|
return readEvent->objectChanges.objects.at(i).lockLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
double WorldFunctions::GetObjectPosX(unsigned int i) noexcept
|
double WorldFunctions::GetObjectPosX(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).position.pos[0];
|
return readEvent->objectChanges.objects.at(i).position.pos[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
double WorldFunctions::GetObjectPosY(unsigned int i) noexcept
|
double WorldFunctions::GetObjectPosY(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).position.pos[1];
|
return readEvent->objectChanges.objects.at(i).position.pos[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
double WorldFunctions::GetObjectPosZ(unsigned int i) noexcept
|
double WorldFunctions::GetObjectPosZ(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).position.pos[2];
|
return readEvent->objectChanges.objects.at(i).position.pos[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
double WorldFunctions::GetObjectRotX(unsigned int i) noexcept
|
double WorldFunctions::GetObjectRotX(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).position.rot[0];
|
return readEvent->objectChanges.objects.at(i).position.rot[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
double WorldFunctions::GetObjectRotY(unsigned int i) noexcept
|
double WorldFunctions::GetObjectRotY(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).position.rot[1];
|
return readEvent->objectChanges.objects.at(i).position.rot[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
double WorldFunctions::GetObjectRotZ(unsigned int i) noexcept
|
double WorldFunctions::GetObjectRotZ(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(i).position.rot[2];
|
return readEvent->objectChanges.objects.at(i).position.rot[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WorldFunctions::GetContainerChangesSize(unsigned int objectIndex) noexcept
|
unsigned int WorldFunctions::GetContainerChangesSize(unsigned int objectIndex) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(objectIndex).containerChanges.count;
|
return readEvent->objectChanges.objects.at(objectIndex).containerChanges.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *WorldFunctions::GetContainerItemRefId(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
const char *WorldFunctions::GetContainerItemRefId(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(objectIndex)
|
return readEvent->objectChanges.objects.at(objectIndex)
|
||||||
.containerChanges.items.at(itemIndex).refId.c_str();
|
.containerChanges.items.at(itemIndex).refId.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetContainerItemCount(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
int WorldFunctions::GetContainerItemCount(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(objectIndex)
|
return readEvent->objectChanges.objects.at(objectIndex)
|
||||||
.containerChanges.items.at(itemIndex).count;
|
.containerChanges.items.at(itemIndex).count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetContainerItemCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
int WorldFunctions::GetContainerItemCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(objectIndex)
|
return readEvent->objectChanges.objects.at(objectIndex)
|
||||||
.containerChanges.items.at(itemIndex).charge;
|
.containerChanges.items.at(itemIndex).charge;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
int WorldFunctions::GetContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex) noexcept
|
||||||
{
|
{
|
||||||
return mwmp::Networking::getPtr()->getLastEvent()->objectChanges.objects.at(objectIndex)
|
return readEvent->objectChanges.objects.at(objectIndex)
|
||||||
.containerChanges.items.at(itemIndex).actionCount;
|
.containerChanges.items.at(itemIndex).actionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SetScriptEventCell(const char* cellDescription) noexcept
|
void WorldFunctions::SetEventCell(const char* cellDescription) noexcept
|
||||||
{
|
{
|
||||||
scriptEvent.cell = Utils::getCellFromDescription(cellDescription);
|
writeEvent.cell = Utils::getCellFromDescription(cellDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SetScriptEventAction(unsigned char action) noexcept
|
void WorldFunctions::SetEventAction(unsigned char action) noexcept
|
||||||
{
|
{
|
||||||
scriptEvent.action = action;
|
writeEvent.action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SetObjectRefId(const char* refId) noexcept
|
void WorldFunctions::SetObjectRefId(const char* refId) noexcept
|
||||||
|
@ -228,7 +234,7 @@ void WorldFunctions::SetContainerItemCharge(int charge) noexcept
|
||||||
|
|
||||||
void WorldFunctions::AddWorldObject() noexcept
|
void WorldFunctions::AddWorldObject() noexcept
|
||||||
{
|
{
|
||||||
scriptEvent.objectChanges.objects.push_back(tempWorldObject);
|
writeEvent.objectChanges.objects.push_back(tempWorldObject);
|
||||||
|
|
||||||
tempWorldObject = emptyWorldObject;
|
tempWorldObject = emptyWorldObject;
|
||||||
}
|
}
|
||||||
|
@ -242,44 +248,44 @@ void WorldFunctions::AddContainerItem() noexcept
|
||||||
|
|
||||||
void WorldFunctions::SendObjectDelete() noexcept
|
void WorldFunctions::SendObjectDelete() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->setEvent(&scriptEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->setEvent(&writeEvent);
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->Send(scriptEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SendObjectPlace() noexcept
|
void WorldFunctions::SendObjectPlace() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->setEvent(&scriptEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->setEvent(&writeEvent);
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->Send(scriptEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SendObjectScale() noexcept
|
void WorldFunctions::SendObjectScale() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->setEvent(&scriptEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->setEvent(&writeEvent);
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->Send(scriptEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SendObjectLock() noexcept
|
void WorldFunctions::SendObjectLock() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->setEvent(&scriptEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->setEvent(&writeEvent);
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->Send(scriptEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SendObjectUnlock() noexcept
|
void WorldFunctions::SendObjectUnlock() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_UNLOCK)->setEvent(&scriptEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_UNLOCK)->setEvent(&writeEvent);
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_UNLOCK)->Send(scriptEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_UNLOCK)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SendDoorState() noexcept
|
void WorldFunctions::SendDoorState() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->setEvent(&scriptEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->setEvent(&writeEvent);
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->Send(scriptEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SendContainer() noexcept
|
void WorldFunctions::SendContainer() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER)->setEvent(&scriptEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER)->setEvent(&writeEvent);
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER)->Send(scriptEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept
|
void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
#define OPENMW_WORLDAPI_HPP
|
#define OPENMW_WORLDAPI_HPP
|
||||||
|
|
||||||
#define WORLDAPI \
|
#define WORLDAPI \
|
||||||
{"InitScriptEvent", WorldFunctions::InitScriptEvent},\
|
{"ReadLastEvent", WorldFunctions::ReadLastEvent},\
|
||||||
|
{"InitiateEvent", WorldFunctions::InitiateEvent},\
|
||||||
\
|
\
|
||||||
{"GetObjectChangesSize", WorldFunctions::GetObjectChangesSize},\
|
{"GetObjectChangesSize", WorldFunctions::GetObjectChangesSize},\
|
||||||
{"GetLastEventAction", WorldFunctions::GetLastEventAction},\
|
{"GetEventAction", WorldFunctions::GetEventAction},\
|
||||||
\
|
\
|
||||||
{"GetObjectRefId", WorldFunctions::GetObjectRefId},\
|
{"GetObjectRefId", WorldFunctions::GetObjectRefId},\
|
||||||
{"GetObjectRefNumIndex", WorldFunctions::GetObjectRefNumIndex},\
|
{"GetObjectRefNumIndex", WorldFunctions::GetObjectRefNumIndex},\
|
||||||
|
@ -29,8 +30,8 @@
|
||||||
{"GetContainerItemCharge", WorldFunctions::GetContainerItemCharge},\
|
{"GetContainerItemCharge", WorldFunctions::GetContainerItemCharge},\
|
||||||
{"GetContainerItemActionCount", WorldFunctions::GetContainerItemActionCount},\
|
{"GetContainerItemActionCount", WorldFunctions::GetContainerItemActionCount},\
|
||||||
\
|
\
|
||||||
{"SetScriptEventCell", WorldFunctions::SetScriptEventCell},\
|
{"SetEventCell", WorldFunctions::SetEventCell},\
|
||||||
{"SetScriptEventAction", WorldFunctions::SetScriptEventAction},\
|
{"SetEventAction", WorldFunctions::SetEventAction},\
|
||||||
\
|
\
|
||||||
{"SetObjectRefId", WorldFunctions::SetObjectRefId},\
|
{"SetObjectRefId", WorldFunctions::SetObjectRefId},\
|
||||||
{"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\
|
{"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\
|
||||||
|
@ -67,10 +68,11 @@ class WorldFunctions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static void InitScriptEvent(unsigned short pid) noexcept;
|
static void ReadLastEvent() noexcept;
|
||||||
|
static void InitiateEvent(unsigned short pid) noexcept;
|
||||||
|
|
||||||
static unsigned int GetObjectChangesSize() noexcept;
|
static unsigned int GetObjectChangesSize() noexcept;
|
||||||
static unsigned char GetLastEventAction() noexcept;
|
static unsigned char GetEventAction() noexcept;
|
||||||
|
|
||||||
static const char *GetObjectRefId(unsigned int i) noexcept;
|
static const char *GetObjectRefId(unsigned int i) noexcept;
|
||||||
static int GetObjectRefNumIndex(unsigned int i) noexcept;
|
static int GetObjectRefNumIndex(unsigned int i) noexcept;
|
||||||
|
@ -94,8 +96,8 @@ public:
|
||||||
static int GetContainerItemCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept;
|
static int GetContainerItemCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept;
|
||||||
static int GetContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex) noexcept;
|
static int GetContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex) noexcept;
|
||||||
|
|
||||||
static void SetScriptEventCell(const char* cellDescription) noexcept;
|
static void SetEventCell(const char* cellDescription) noexcept;
|
||||||
static void SetScriptEventAction(unsigned char action) noexcept;
|
static void SetEventAction(unsigned char action) noexcept;
|
||||||
|
|
||||||
static void SetObjectRefId(const char* refId) noexcept;
|
static void SetObjectRefId(const char* refId) noexcept;
|
||||||
static void SetObjectRefNumIndex(int refNumIndex) noexcept;
|
static void SetObjectRefNumIndex(int refNumIndex) noexcept;
|
||||||
|
|
Loading…
Reference in a new issue