From 8f745df0558da3dcb4f1aac51e5e3fe36831c74b Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 13 Jul 2018 01:04:41 +0300 Subject: [PATCH] [Server] Bring Actor functions in line with Object functions, part 1 The last received ActorList can now be copied into the write-only ActorList that can be sent in packets. Changing the pid of the write-only ActorList can now be done separately from clearing its contents. --- apps/openmw-mp/Script/Functions/Actors.cpp | 22 +++++++++++++-- apps/openmw-mp/Script/Functions/Actors.hpp | 33 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 82f0b81e2..2324a89fc 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -32,16 +32,25 @@ void ActorFunctions::ReadCellActorList(const char* cellDescription) noexcept readActorList = serverCell->getActorList(); } -void ActorFunctions::InitializeActorList(unsigned short pid) noexcept +void ActorFunctions::ClearActorList() noexcept +{ + writeActorList.cell.blank(); + writeActorList.baseActors.clear(); +} + +void ActorFunctions::SetActorListPid(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player, ); - writeActorList.cell.blank(); - writeActorList.baseActors.clear(); writeActorList.guid = player->guid; } +void ActorFunctions::CopyLastActorListToStore() noexcept +{ + writeActorList = *readActorList; +} + unsigned int ActorFunctions::GetActorListSize() noexcept { return readActorList->count; @@ -439,3 +448,10 @@ void ActorFunctions::SendActorCellChange() noexcept actorPacket->Send(writeActorList.guid); } +// All methods below are deprecated versions of methods from above + +void ActorFunctions::InitializeActorList(unsigned short pid) noexcept +{ + ClearActorList(); + SetActorListPid(pid); +} diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index eb3904b4a..42552e764 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -4,7 +4,11 @@ #define ACTORAPI \ {"ReadLastActorList", ActorFunctions::ReadLastActorList},\ {"ReadCellActorList", ActorFunctions::ReadCellActorList},\ - {"InitializeActorList", ActorFunctions::InitializeActorList},\ + \ + {"ClearActorList", ActorFunctions::ClearActorList},\ + {"SetActorListPid", ActorFunctions::SetActorListPid},\ + \ + {"CopyLastActorListToStore", ActorFunctions::CopyLastActorListToStore},\ \ {"GetActorListSize", ActorFunctions::GetActorListSize},\ {"GetActorListAction", ActorFunctions::GetActorListAction},\ @@ -86,7 +90,9 @@ {"SendActorStatsDynamic", ActorFunctions::SendActorStatsDynamic},\ {"SendActorEquipment", ActorFunctions::SendActorEquipment},\ {"SendActorAI", ActorFunctions::SendActorAI},\ - {"SendActorCellChange", ActorFunctions::SendActorCellChange} + {"SendActorCellChange", ActorFunctions::SendActorCellChange},\ + \ + {"InitializeActorList", ActorFunctions::InitializeActorList} class ActorFunctions { @@ -113,12 +119,26 @@ public: /** * \brief Clear the data from the last actor list sent by the server. * - * This is used to initialize the sending of new Actor packets. + * \return void + */ + static void ClearActorList() noexcept; + + /** + * \brief Set the pid attached to the ActorList. * * \param pid The player ID to whom the actor list should be attached. * \return void */ - static void InitializeActorList(unsigned short pid) noexcept; + static void SetActorListPid(unsigned short pid) noexcept; + + /** + * \brief Take the contents of the read-only actor list last received by the + * server from a player and move its contents to the stored object list + * that can be sent by the server. + * + * \return void + */ + static void CopyLastActorListToStore() noexcept; /** * \brief Get the number of indexes in the read actor list. @@ -704,6 +724,11 @@ public: * \return void */ static void SendActorCellChange() noexcept; + + + // All methods below are deprecated versions of methods from above + + static void InitializeActorList(unsigned short pid) noexcept; };