[General] Distinguish between shorts & longs in ClientScriptGlobal

Adjust ClientScriptLocal so it refers to its previously handled integers as shorts.
This commit is contained in:
David Cernat 2020-02-17 18:19:03 +02:00
parent a4b10c75e1
commit 8db396d10a
10 changed files with 49 additions and 28 deletions

View File

@ -215,11 +215,11 @@ void WorldstateFunctions::AddKill(const char* refId, int number) noexcept
writeWorldstate.killChanges.push_back(kill); writeWorldstate.killChanges.push_back(kill);
} }
void WorldstateFunctions::AddClientGlobalInteger(const char* id, int intValue) noexcept void WorldstateFunctions::AddClientGlobalInteger(const char* id, int intValue, unsigned int variableType) noexcept
{ {
mwmp::ClientVariable clientVariable; mwmp::ClientVariable clientVariable;
clientVariable.id = id; clientVariable.id = id;
clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER; clientVariable.variableType = variableType;
clientVariable.intValue = intValue; clientVariable.intValue = intValue;
writeWorldstate.clientGlobals.push_back(clientVariable); writeWorldstate.clientGlobals.push_back(clientVariable);

View File

@ -419,10 +419,11 @@ public:
* \brief Add a new client global integer to the client globals. * \brief Add a new client global integer to the client globals.
* *
* \param id The id of the client global. * \param id The id of the client global.
* \param variableType The variable type (0 for SHORT, 1 for LONG).
* \param intValue The integer value of the client global. * \param intValue The integer value of the client global.
* \return void * \return void
*/ */
static void AddClientGlobalInteger(const char* id, int intValue) noexcept; static void AddClientGlobalInteger(const char* id, int intValue, unsigned int variableType = 0) noexcept;
/** /**
* \brief Add a new client global float to the client globals. * \brief Add a new client global float to the client globals.

View File

@ -867,21 +867,21 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
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::INTEGER) if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT)
{ {
valueAsString = std::to_string(baseObject.clientVariable.intValue); valueAsString = std::to_string(baseObject.clientVariable.intValue);
variableType = "integer"; 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); valueAsString = std::to_string(baseObject.clientVariable.floatValue);
variableType = "float"; variableTypeAsString = "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.index, variableType.c_str(), valueAsString.c_str()); baseObject.refNum, baseObject.mpNum, baseObject.index, variableTypeAsString.c_str(), valueAsString.c_str());
MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum); MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum);
@ -890,7 +890,7 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Found %s %i-%i", ptrFound.getCellRef().getRefId().c_str(), LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Found %s %i-%i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum()); ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::INTEGER) 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::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;
@ -1166,13 +1166,13 @@ void ObjectList::addVideoPlay(std::string filename, bool allowSkipping)
addBaseObject(baseObject); addBaseObject(baseObject);
} }
void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value) void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value, mwmp::VARIABLE_TYPE variableType)
{ {
cell = *ptr.getCell()->getCell(); cell = *ptr.getCell()->getCell();
mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr); mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr);
baseObject.clientVariable.index = index; baseObject.clientVariable.index = index;
baseObject.clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER; baseObject.clientVariable.variableType = variableType;
baseObject.clientVariable.intValue = value; baseObject.clientVariable.intValue = value;
addBaseObject(baseObject); addBaseObject(baseObject);
} }
@ -1312,10 +1312,10 @@ void ObjectList::sendClientScriptLocal()
std::string valueAsString; std::string valueAsString;
std::string variableType; std::string variableType;
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::INTEGER) if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT)
{ {
valueAsString = std::to_string(baseObject.clientVariable.intValue); valueAsString = std::to_string(baseObject.clientVariable.intValue);
variableType = "integer"; variableType = "short";
} }
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{ {

View File

@ -66,7 +66,7 @@ namespace mwmp
void addDoorState(const MWWorld::Ptr& ptr, MWWorld::DoorState state); void addDoorState(const MWWorld::Ptr& ptr, MWWorld::DoorState state);
void addMusicPlay(std::string filename); void addMusicPlay(std::string filename);
void addVideoPlay(std::string filename, bool allowSkipping); void addVideoPlay(std::string filename, bool allowSkipping);
void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value); void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value, mwmp::VARIABLE_TYPE variableType);
void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, float value); void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, float value);
void addScriptMemberShort(std::string refId, int index, int shortVal); void addScriptMemberShort(std::string refId, int index, int shortVal);

View File

@ -349,13 +349,24 @@ void Worldstate::setClientGlobals()
if (!debugMessage.empty()) if (!debugMessage.empty())
debugMessage += ", "; debugMessage += ", ";
std::string valueAsString = clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER ? std::string variableTypeAsString;
std::to_string(clientGlobal.intValue) : std::to_string(clientGlobal.floatValue); std::string valueAsString;
debugMessage += clientGlobal.id + ": " + valueAsString; if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG)
{
variableTypeAsString = clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long";
valueAsString = std::to_string(clientGlobal.intValue);
}
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{
variableTypeAsString = "float";
valueAsString = std::to_string(clientGlobal.floatValue);
} }
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER) debugMessage += clientGlobal.id + ": " + variableTypeAsString + " " + valueAsString;
}
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG)
MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.intValue); MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.intValue);
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT) else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.floatValue); MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.floatValue);
@ -419,16 +430,24 @@ void Worldstate::setWeather()
weather.queuedWeather, weather.transitionFactor, forceWeather); weather.queuedWeather, weather.transitionFactor, forceWeather);
} }
void Worldstate::sendClientGlobal(std::string varName, int value) void Worldstate::sendClientGlobal(std::string varName, int value, mwmp::VARIABLE_TYPE variableType)
{ {
clientGlobals.clear(); clientGlobals.clear();
mwmp::ClientVariable clientVariable; mwmp::ClientVariable clientVariable;
clientVariable.id = varName; clientVariable.id = varName;
clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER; clientVariable.variableType = variableType;
clientVariable.intValue = value; clientVariable.intValue = value;
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_CLIENT_SCRIPT_GLOBAL with name %s, type integer, value %i", varName.c_str(), value); std::string variableTypeAsString;
if (variableType == mwmp::VARIABLE_TYPE::SHORT)
variableTypeAsString = "short";
else if (variableType == mwmp::VARIABLE_TYPE::LONG)
variableTypeAsString = "long";
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_CLIENT_SCRIPT_GLOBAL with name %s, type %s, value %i",
varName.c_str(), variableTypeAsString.c_str(), value);
clientGlobals.push_back(clientVariable); clientGlobals.push_back(clientVariable);

View File

@ -23,7 +23,7 @@ namespace mwmp
void setMapExplored(); void setMapExplored();
void setWeather(); void setWeather();
void sendClientGlobal(std::string varName, int value); void sendClientGlobal(std::string varName, int value, mwmp::VARIABLE_TYPE variableType);
void sendClientGlobal(std::string varName, float value); void sendClientGlobal(std::string varName, float value);
void sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData); void sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData);
void sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor); void sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor);

View File

@ -242,7 +242,7 @@ namespace MWScript
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset(); objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType()); objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
objectList->addClientScriptLocal(mReference, index, value); objectList->addClientScriptLocal(mReference, index, value, mwmp::VARIABLE_TYPE::SHORT);
objectList->sendClientScriptLocal(); objectList->sendClientScriptLocal();
} }
/* /*
@ -364,7 +364,7 @@ namespace MWScript
*/ */
if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
{ {
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value); mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value, mwmp::VARIABLE_TYPE::SHORT);
} }
/* /*
End of tes3mp addition End of tes3mp addition
@ -394,7 +394,7 @@ namespace MWScript
*/ */
if (sendPackets || mwmp::Main::isValidPacketGlobal(name)) if (sendPackets || mwmp::Main::isValidPacketGlobal(name))
{ {
mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value); mwmp::Main::get().getNetworking()->getWorldstate()->sendClientGlobal(name, value, mwmp::VARIABLE_TYPE::LONG);
} }
/* /*
End of tes3mp addition End of tes3mp addition

View File

@ -22,7 +22,8 @@ namespace mwmp
enum VARIABLE_TYPE enum VARIABLE_TYPE
{ {
INTEGER, SHORT,
LONG,
FLOAT FLOAT
}; };

View File

@ -15,7 +15,7 @@ void PacketClientScriptLocal::Object(BaseObject &baseObject, bool send)
RW(baseObject.clientVariable.index, send); RW(baseObject.clientVariable.index, send);
RW(baseObject.clientVariable.variableType, send); RW(baseObject.clientVariable.variableType, send);
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::INTEGER) if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT || baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
RW(baseObject.clientVariable.intValue, send); RW(baseObject.clientVariable.intValue, send);
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT) else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
RW(baseObject.clientVariable.floatValue, send); RW(baseObject.clientVariable.floatValue, send);

View File

@ -31,7 +31,7 @@ void PacketClientScriptGlobal::Packet(RakNet::BitStream *newBitstream, bool send
RW(clientGlobal.id, send, true); RW(clientGlobal.id, send, true);
RW(clientGlobal.variableType, send); RW(clientGlobal.variableType, send);
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER) if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG)
RW(clientGlobal.intValue, send); RW(clientGlobal.intValue, send);
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT) else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
RW(clientGlobal.floatValue, send); RW(clientGlobal.floatValue, send);