[Client] Send packets with floats when their floors change

This helps prevent frame-by-frame packet spam from floats used as timers.

Additionally, clean up the comments regarding clientside variables.
This commit is contained in:
David Cernat 2020-02-14 01:18:24 +02:00
parent 2390e951bb
commit 60ca72a70a

View File

@ -234,8 +234,8 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_LOCAL packet every time a local short changes its value Send an ID_CLIENT_SCRIPT_LOCAL packet when a local float changes its value as long as
in a script approved for packet sending it is being set in a script that has been approved for packet sending
*/ */
if (sendPackets) if (sendPackets)
{ {
@ -267,8 +267,13 @@ namespace MWScript
Start of tes3mp addition Start of tes3mp addition
Avoid setting a local to a value it already is, preventing packet spam Avoid setting a local to a value it already is, preventing packet spam
Additionally, record the old value to check it below when determining if
it has changed enough to warrant sending a packet about it
*/ */
if (mLocals->mFloats.at(index) == value) return; float oldValue = mLocals->mFloats.at(index);
if (oldValue == value) return;
/* /*
End of tes3mp addition End of tes3mp addition
*/ */
@ -278,11 +283,11 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_SCRIPT_LOCAL_FLOAT packet every time a local float changes its value Send an ID_CLIENT_SCRIPT_LOCAL packet when a local float changes its value as long as
to one without decimals (to avoid packet spam for timers) in a script approved its value has changed enough and it is being set in a script that has been approved for
for packet sending packet sending
*/ */
if (sendPackets && value == (int) value) if (floor(oldValue) != floor(value) && sendPackets)
{ {
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset(); objectList->reset();
@ -383,7 +388,7 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global long changes its value as long as
it is being set in a script that has been approved for packet sending or the global itself 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 has been set to always be synchronized
*/ */
@ -404,8 +409,13 @@ namespace MWScript
Start of tes3mp addition Start of tes3mp addition
Avoid setting a global to a value it already is, preventing packet spam Avoid setting a global to a value it already is, preventing packet spam
Additionally, record the old value to check it below when determining if
it has changed enough to warrant sending a packet about it
*/ */
if (getGlobalFloat(name) == value) return; float oldValue = getGlobalFloat(name);
if (oldValue == value) return;
/* /*
End of tes3mp addition End of tes3mp addition
*/ */
@ -413,11 +423,11 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global short changes its value as long as Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global float changes its value as long as
it is being set in a script that has been approved for packet sending or the global itself its value has changed enough and it is being set in a script that has been approved for
has been set to always be synchronized packet sending or the global itself has been set to always be synchronized
*/ */
if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) if (floor(oldValue) != floor(value) && (sendPackets || mwmp::Main::isValidPacketGlobal(name)))
{ {
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value); mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value);
} }