[General] Implement ClientScriptSettings packet, part 2

The packet can now set which client globals get packets sent about them when their values change on clients.
pull/541/head
David Cernat 5 years ago
parent 3acfbad55d
commit e424bd9bc3

@ -158,6 +158,11 @@ void WorldstateFunctions::AddSynchronizedClientScriptId(const char *scriptId) no
writeWorldstate.synchronizedClientScriptIds.push_back(scriptId);
}
void WorldstateFunctions::AddSynchronizedClientGlobalId(const char *globalId) noexcept
{
writeWorldstate.synchronizedClientGlobalIds.push_back(globalId);
}
void WorldstateFunctions::AddEnforcedCollisionRefId(const char *refId) noexcept
{
writeWorldstate.enforcedCollisionRefIds.push_back(refId);
@ -168,6 +173,11 @@ void WorldstateFunctions::ClearSynchronizedClientScriptIds() noexcept
writeWorldstate.synchronizedClientScriptIds.clear();
}
void WorldstateFunctions::ClearSynchronizedClientGlobalIds() noexcept
{
writeWorldstate.synchronizedClientGlobalIds.clear();
}
void WorldstateFunctions::ClearEnforcedCollisionRefIds() noexcept
{
writeWorldstate.enforcedCollisionRefIds.clear();

@ -44,9 +44,11 @@
{"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\
\
{"AddSynchronizedClientScriptId", WorldstateFunctions::AddSynchronizedClientScriptId},\
{"AddSynchronizedClientGlobalId", WorldstateFunctions::AddSynchronizedClientGlobalId},\
{"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\
\
{"ClearSynchronizedClientScriptIds", WorldstateFunctions::ClearSynchronizedClientScriptIds},\
{"ClearSynchronizedClientGlobalIds", WorldstateFunctions::ClearSynchronizedClientGlobalIds},\
{"ClearEnforcedCollisionRefIds", WorldstateFunctions::ClearEnforcedCollisionRefIds},\
\
{"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\
@ -298,14 +300,23 @@ public:
static void UseActorCollisionForPlacedObjects(bool useActorCollision) noexcept;
/**
* \brief Add an ID to the list of script IDs whose variables should all be synchronized
* across players.
* \brief Add an ID to the list of script IDs whose variable changes should be sent to the
* the server by clients.
*
* \param scriptId The ID.
* \return void
*/
static void AddSynchronizedClientScriptId(const char* scriptId) noexcept;
/**
* \brief Add an ID to the list of global IDs whose value changes should be sent to the
* server by clients.
*
* \param globalId The ID.
* \return void
*/
static void AddSynchronizedClientGlobalId(const char* globalId) noexcept;
/**
* \brief Add a refId to the list of refIds for which collision should be enforced
* irrespective of other settings.
@ -316,13 +327,21 @@ public:
static void AddEnforcedCollisionRefId(const char* refId) noexcept;
/**
* \brief Clear the list of script IDs whose variables should all be synchronized
* across players.
* \brief Clear the list of script IDs whose variable changes should be sent to the
* the server by clients.
*
* \return void
*/
static void ClearSynchronizedClientScriptIds() noexcept;
/**
* \brief Clear the list of global IDs whose value changes should be sent to the
* the server by clients.
*
* \return void
*/
static void ClearSynchronizedClientGlobalIds() noexcept;
/**
* \brief Clear the list of refIds for which collision should be enforced irrespective
* of other settings.

@ -232,11 +232,21 @@ CellController *Main::getCellController() const
return mCellController;
}
bool Main::isValidPacketScript(std::string script)
bool Main::isValidPacketScript(std::string scriptId)
{
mwmp::BaseWorldstate *worldstate = get().getNetworking()->getWorldstate();
if (Utils::vectorContains(worldstate->synchronizedClientScriptIds, script))
if (Utils::vectorContains(worldstate->synchronizedClientScriptIds, scriptId))
return true;
return false;
}
bool Main::isValidPacketGlobal(std::string globalId)
{
mwmp::BaseWorldstate *worldstate = get().getNetworking()->getWorldstate();
if (Utils::vectorContains(worldstate->synchronizedClientGlobalIds, globalId))
return true;
return false;

@ -26,7 +26,9 @@ namespace mwmp
static const Main &get();
static void frame(float dt);
static bool isValidPacketScript(std::string script);
static bool isValidPacketScript(std::string scriptId);
static bool isValidPacketGlobal(std::string globalId);
static std::string getResDir();
Networking *getNetworking() const;

@ -18,7 +18,21 @@ namespace mwmp
virtual void Do(WorldstatePacket &packet, Worldstate &worldstate)
{
// Placeholder
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_CLIENT_SCRIPT_SETTINGS making us send packets for the following globals:");
std::string debugMessage = "";
for (const auto &globalId : worldstate.synchronizedClientGlobalIds)
{
if (TimedLog::GetLevel() <= TimedLog::LOG_INFO)
{
if (!debugMessage.empty())
debugMessage += ", ";
debugMessage += globalId;
}
}
LOG_APPEND(TimedLog::LOG_INFO, "- %s", debugMessage.c_str());
}
};
}

@ -323,10 +323,11 @@ namespace MWScript
/*
Start of tes3mp addition
Send an ID_SCRIPT_GLOBAL_SHORT packet every time a global short changes its value
in a script approved for packet sending
Send an ID_SCRIPT_GLOBAL_SHORT packet when a global short changes its value as long as
it is being set in a script that has been approved for packet sending or the global itself
has been set to always be synchronized
*/
if (sendPackets)
if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
{
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset();

@ -308,6 +308,7 @@ namespace mwmp
mwmp::Time time;
std::vector<std::string> synchronizedClientScriptIds;
std::vector<std::string> synchronizedClientGlobalIds;
bool hasPlayerCollision;
bool hasActorCollision;

@ -30,4 +30,22 @@ void PacketClientScriptSettings::Packet(RakNet::BitStream *bs, bool send)
{
RW(clientScriptId, send);
}
uint32_t clientGlobalsCount;
if (send)
clientGlobalsCount = static_cast<uint32_t>(worldstate->synchronizedClientGlobalIds.size());
RW(clientGlobalsCount, send);
if (!send)
{
worldstate->synchronizedClientGlobalIds.clear();
worldstate->synchronizedClientGlobalIds.resize(clientGlobalsCount);
}
for (auto &&clientGlobalId : worldstate->synchronizedClientGlobalIds)
{
RW(clientGlobalId, send);
}
}

Loading…
Cancel
Save