1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 20:36:42 +00:00

[General] Add handling of longs to ClientScriptLocal

Use better wording in comments related to ClientScriptLocal and ClientScriptGlobal.
This commit is contained in:
David Cernat 2020-02-18 02:02:31 +02:00
parent 8db396d10a
commit ab794f0068
2 changed files with 51 additions and 21 deletions

View file

@ -869,15 +869,15 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
std::string valueAsString; std::string valueAsString;
std::string variableTypeAsString; std::string variableTypeAsString;
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT) if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT || baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
{ {
variableTypeAsString = baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long";
valueAsString = std::to_string(baseObject.clientVariable.intValue); valueAsString = std::to_string(baseObject.clientVariable.intValue);
variableTypeAsString = "short";
} }
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{ {
valueAsString = std::to_string(baseObject.clientVariable.floatValue);
variableTypeAsString = "float"; variableTypeAsString = "float";
valueAsString = std::to_string(baseObject.clientVariable.floatValue);
} }
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i, index: %i, type %s, value: %s", baseObject.refId.c_str(), LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i, index: %i, type %s, value: %s", baseObject.refId.c_str(),
@ -892,6 +892,8 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT) if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT)
ptrFound.getRefData().getLocals().mShorts.at(baseObject.index) = baseObject.clientVariable.intValue; ptrFound.getRefData().getLocals().mShorts.at(baseObject.index) = baseObject.clientVariable.intValue;
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
ptrFound.getRefData().getLocals().mLongs.at(baseObject.index) = baseObject.clientVariable.intValue;
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
ptrFound.getRefData().getLocals().mFloats.at(baseObject.index) = baseObject.clientVariable.floatValue; ptrFound.getRefData().getLocals().mFloats.at(baseObject.index) = baseObject.clientVariable.floatValue;
} }
@ -1310,21 +1312,21 @@ void ObjectList::sendClientScriptLocal()
for (const auto &baseObject : baseObjects) for (const auto &baseObject : baseObjects)
{ {
std::string valueAsString; std::string valueAsString;
std::string variableType; std::string variableTypeAsString;
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT) if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT || baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
{ {
variableTypeAsString = baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long";
valueAsString = std::to_string(baseObject.clientVariable.intValue); valueAsString = std::to_string(baseObject.clientVariable.intValue);
variableType = "short";
} }
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{ {
variableTypeAsString = "float";
valueAsString = std::to_string(baseObject.clientVariable.floatValue); valueAsString = std::to_string(baseObject.clientVariable.floatValue);
variableType = "float";
} }
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i, index: %i, type %s, value: %s", baseObject.refId.c_str(), LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i, index: %i, type %s, value: %s", baseObject.refId.c_str(),
baseObject.refNum, baseObject.mpNum, baseObject.clientVariable.index, variableType.c_str(), valueAsString.c_str()); baseObject.refNum, baseObject.mpNum, baseObject.clientVariable.index, variableTypeAsString.c_str(), valueAsString.c_str());
} }
mwmp::Main::get().getNetworking()->getObjectPacket(ID_CLIENT_SCRIPT_LOCAL)->setObjectList(this); mwmp::Main::get().getNetworking()->getObjectPacket(ID_CLIENT_SCRIPT_LOCAL)->setObjectList(this);

View file

@ -234,7 +234,7 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_LOCAL packet when a local float changes its value as long as Send an ID_CLIENT_SCRIPT_LOCAL packet when a local short changes its value if
it is being set in a script that has been approved for packet sending it is being set in a script that has been approved for packet sending
*/ */
if (sendPackets) if (sendPackets)
@ -255,7 +255,35 @@ namespace MWScript
if (!mLocals) if (!mLocals)
throw std::runtime_error ("local variables not available in this context"); throw std::runtime_error ("local variables not available in this context");
/*
Start of tes3mp addition
Avoid setting a local to a value it already is, preventing packet spam
*/
if (mLocals->mLongs.at(index) == value) return;
/*
End of tes3mp addition
*/
mLocals->mLongs.at (index) = value; mLocals->mLongs.at (index) = value;
/*
Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_LOCAL packet when a local long changes its value if
it is being set in a script that has been approved for packet sending
*/
if (sendPackets)
{
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
objectList->addClientScriptLocal(mReference, index, value, mwmp::VARIABLE_TYPE::LONG);
objectList->sendClientScriptLocal();
}
/*
End of tes3mp addition
*/
} }
void InterpreterContext::setLocalFloat (int index, float value) void InterpreterContext::setLocalFloat (int index, float value)
@ -283,9 +311,9 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_LOCAL packet when a local float changes its value as long as Send an ID_CLIENT_SCRIPT_LOCAL packet when a local float changes its value if
its value has changed enough and it is being set in a script that has been approved for its value has changed enough and it is being set in a script that has been approved
packet sending for packet sending
*/ */
if (floor(oldValue) != floor(value) && sendPackets) if (floor(oldValue) != floor(value) && sendPackets)
{ {
@ -358,9 +386,9 @@ 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 short changes its value if
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
has been set to always be synchronized itself has been set to always be synchronized
*/ */
if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
{ {
@ -388,9 +416,9 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global long changes its value as long as Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global long changes its value if
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
has been set to always be synchronized itself has been set to always be synchronized
*/ */
if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
{ {
@ -423,9 +451,9 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global float changes its value as long as Send an ID_CLIENT_SCRIPT_GLOBAL packet when a global float changes its value if
its value has changed enough and it is being set in a script that has been approved for its value has changed enough and it is being set in a script that has been approved
packet sending or the global itself has been set to always be synchronized for packet sending or the global itself has been set to always be synchronized
*/ */
if (floor(oldValue) != floor(value) && (sendPackets || mwmp::Main::isValidPacketGlobal(name))) if (floor(oldValue) != floor(value) && (sendPackets || mwmp::Main::isValidPacketGlobal(name)))
{ {