1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 22:45:34 +00:00

[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);
}
void WorldstateFunctions::AddClientGlobalInteger(const char* id, int intValue) noexcept
void WorldstateFunctions::AddClientGlobalInteger(const char* id, int intValue, unsigned int variableType) noexcept
{
mwmp::ClientVariable clientVariable;
clientVariable.id = id;
clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER;
clientVariable.variableType = variableType;
clientVariable.intValue = intValue;
writeWorldstate.clientGlobals.push_back(clientVariable);

View file

@ -419,10 +419,11 @@ public:
* \brief Add a new client global integer to the client globals.
*
* \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.
* \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.

View file

@ -867,21 +867,21 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
for (const auto &baseObject : baseObjects)
{
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);
variableType = "integer";
variableTypeAsString = "short";
}
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{
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(),
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);
@ -890,7 +890,7 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Found %s %i-%i", ptrFound.getCellRef().getRefId().c_str(),
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;
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
ptrFound.getRefData().getLocals().mFloats.at(baseObject.index) = baseObject.clientVariable.floatValue;
@ -1166,13 +1166,13 @@ void ObjectList::addVideoPlay(std::string filename, bool allowSkipping)
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();
mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr);
baseObject.clientVariable.index = index;
baseObject.clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER;
baseObject.clientVariable.variableType = variableType;
baseObject.clientVariable.intValue = value;
addBaseObject(baseObject);
}
@ -1312,10 +1312,10 @@ void ObjectList::sendClientScriptLocal()
std::string valueAsString;
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);
variableType = "integer";
variableType = "short";
}
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 addMusicPlay(std::string filename);
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 addScriptMemberShort(std::string refId, int index, int shortVal);

View file

@ -349,13 +349,24 @@ void Worldstate::setClientGlobals()
if (!debugMessage.empty())
debugMessage += ", ";
std::string valueAsString = clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER ?
std::to_string(clientGlobal.intValue) : std::to_string(clientGlobal.floatValue);
std::string variableTypeAsString;
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);
}
debugMessage += clientGlobal.id + ": " + variableTypeAsString + " " + valueAsString;
}
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::INTEGER)
if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientGlobal.variableType == mwmp::VARIABLE_TYPE::LONG)
MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.intValue);
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
MWBase::Environment::get().getWorld()->setGlobalInt(clientGlobal.id, clientGlobal.floatValue);
@ -419,16 +430,24 @@ void Worldstate::setWeather()
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();
mwmp::ClientVariable clientVariable;
clientVariable.id = varName;
clientVariable.variableType = mwmp::VARIABLE_TYPE::INTEGER;
clientVariable.variableType = variableType;
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);

View file

@ -23,7 +23,7 @@ namespace mwmp
void setMapExplored();
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 sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData);
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();
objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(getContextType());
objectList->addClientScriptLocal(mReference, index, value);
objectList->addClientScriptLocal(mReference, index, value, mwmp::VARIABLE_TYPE::SHORT);
objectList->sendClientScriptLocal();
}
/*
@ -364,7 +364,7 @@ namespace MWScript
*/
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
@ -394,7 +394,7 @@ namespace MWScript
*/
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

View file

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

View file

@ -15,7 +15,7 @@ void PacketClientScriptLocal::Object(BaseObject &baseObject, bool send)
RW(baseObject.clientVariable.index, 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);
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
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.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);
else if (clientGlobal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
RW(clientGlobal.floatValue, send);