From 297b8424e345587679aac4648d09b904301445f1 Mon Sep 17 00:00:00 2001 From: uramer Date: Fri, 20 Mar 2020 22:45:00 +0100 Subject: [PATCH 1/8] [General] Ambient lighting for dynamic cell records --- .../Script/Functions/RecordsDynamic.cpp | 65 +++++++++++++++++++ .../Script/Functions/RecordsDynamic.hpp | 42 ++++++++++++ apps/openmw/mwmp/RecordHelper.cpp | 11 ++++ components/openmw-mp/Base/BaseWorldstate.hpp | 5 ++ .../Worldstate/PacketRecordDynamic.cpp | 17 +++++ 5 files changed, 140 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index b46e2678b..b26571853 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -1465,6 +1465,71 @@ void RecordsDynamicFunctions::SetRecordScriptText(const char* scriptText) noexce tempOverrides.hasScriptText = true; } +void RecordsDynamicFunctions::SetRecordHasAmbient(bool hasAmbi) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + tempCell.data.mHasAmbi = hasAmbi; + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set has ambient for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasHasAmbi = true; +} + +void RecordsDynamicFunctions::SetRecordAmbientColor(unsigned int red, unsigned int green, unsigned int blue) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + tempCell.data.mAmbi.mAmbient = red + (green << 8) + (blue << 16); + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set ambient color for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasAmbientColor = true; +} + +void RecordsDynamicFunctions::SetRecordSunlightColor(unsigned int red, unsigned int green, unsigned int blue) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + tempCell.data.mAmbi.mSunlight = red + (green << 8) + (blue << 16); + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set ambient color for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasSunlightColor = true; +} + +void RecordsDynamicFunctions::SetRecordFog(unsigned int red, unsigned int green, unsigned int blue, double density) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + tempCell.data.mAmbi.mFog = red + (green << 8) + (blue << 16); + tempCell.data.mAmbi.mFogDensity = density; + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set ambient color for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasFog = true; +} + void RecordsDynamicFunctions::SetRecordIdByIndex(unsigned int index, const char* id) noexcept { unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp index 3c0e7180d..75b5e6760 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp @@ -104,6 +104,11 @@ \ {"SetRecordScriptText", RecordsDynamicFunctions::SetRecordScriptText},\ \ + {"SetRecordHasAmbient", RecordsDynamicFunctions::SetRecordHasAmbient},\ + {"SetRecordAmbientColor", RecordsDynamicFunctions::SetRecordAmbientColor},\ + {"SetRecordSunlightColor", RecordsDynamicFunctions::SetRecordSunlightColor},\ + {"SetRecordFog", RecordsDynamicFunctions::SetRecordFog},\ + \ {"SetRecordIdByIndex", RecordsDynamicFunctions::SetRecordIdByIndex},\ {"SetRecordEnchantmentIdByIndex", RecordsDynamicFunctions::SetRecordEnchantmentIdByIndex},\ \ @@ -876,6 +881,43 @@ public: */ static void SetRecordScriptText(const char* scriptText) noexcept; + /** + * \brief Set the has ambient of the temporary record stored on the server for the + * currently specified record type. + * + * \param bool Has ambient of the record + * \return void + */ + static void SetRecordHasAmbient(bool hasAmbi) noexcept; + + /** + * \brief Set the ambient color of the temporary record stored on the server for the + * currently specified record type. + * + * \param color Ambient color of the record + * \return void + */ + static void SetRecordAmbientColor(unsigned int red, unsigned int green, unsigned int blue) noexcept; + + /** + * \brief Set the sunlight color of the temporary record stored on the server for the + * currently specified record type. + * + * \param color Sunlight color of the record + * \return void + */ + static void SetRecordSunlightColor(unsigned int red, unsigned int green, unsigned int blue) noexcept; + + /** + * \brief Set the fog of the temporary record stored on the server for the + * currently specified record type. + * + * \param color Fog color of the record + * \param density Fog density of the record + * \return void + */ + static void SetRecordFog(unsigned int red, unsigned int green, unsigned int blue, double density) noexcept; + /** * \brief Set the id of the record at a certain index in the records stored on the server. * diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index 94a17a057..c38cf3f45 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -351,6 +351,17 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) finalData.mName = recordData.mName; finalData.mCellId.mWorldspace = Misc::StringUtils::lowerCase(recordData.mName); + if (record.baseOverrides.hasHasAmbi) + finalData.mHasAmbi= recordData.mHasAmbi; + if (record.baseOverrides.hasAmbientColor) + finalData.mAmbi.mAmbient = recordData.mAmbi.mAmbient; + if (record.baseOverrides.hasSunlightColor) + finalData.mAmbi.mSunlight = recordData.mAmbi.mSunlight; + if (record.baseOverrides.hasFog) { + finalData.mAmbi.mFog = recordData.mAmbi.mFog; + finalData.mAmbi.mFogDensity = recordData.mAmbi.mFogDensity; + } + world->unloadCell(finalData); world->clearCellStore(finalData); world->getModifiableStore().overrideRecord(finalData); diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 8810e3d4f..361d61226 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -138,6 +138,11 @@ namespace mwmp bool hasCloseSound = false; bool hasScriptText = false; + + bool hasHasAmbi = true; + bool hasAmbientColor = true; + bool hasSunlightColor = true; + bool hasFog = true; }; struct ActivatorRecord diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index ed28b55be..d7aba4b5d 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -495,6 +495,23 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) RW(record.baseId, send, true); RW(recordData.mName, send, true); + RW(recordData.mHasAmbi, send, true); + // don't send ambient lighting information to fix black lighting in cell records that lack this information + if (recordData.mHasAmbi) { + RW(recordData.mAmbi.mAmbient, send, true); + RW(recordData.mAmbi.mSunlight, send, true); + RW(recordData.mAmbi.mFog, send, true); + RW(recordData.mAmbi.mFogDensity, send, true); + } + + if (!record.baseId.empty()) + { + auto&& overrides = record.baseOverrides; + RW(overrides.hasHasAmbi, send); + RW(overrides.hasAmbientColor, send); + RW(overrides.hasSunlightColor, send); + RW(overrides.hasFog, send); + } } } else if (worldstate->recordsType == mwmp::RECORD_TYPE::CONTAINER) From 6a4968e6e01f7603382c0b3c9b1c0ee16b72add1 Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 21 Mar 2020 13:34:00 +0100 Subject: [PATCH 2/8] [General] Send cell record ambient information correctly --- components/openmw-mp/Base/BaseWorldstate.hpp | 8 ++++---- .../Packets/Worldstate/PacketRecordDynamic.cpp | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 361d61226..1845ab9a5 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -139,10 +139,10 @@ namespace mwmp bool hasScriptText = false; - bool hasHasAmbi = true; - bool hasAmbientColor = true; - bool hasSunlightColor = true; - bool hasFog = true; + bool hasHasAmbi = false; + bool hasAmbientColor = false; + bool hasSunlightColor = false; + bool hasFog = false; }; struct ActivatorRecord diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index d7aba4b5d..35f79624d 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -496,13 +496,12 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) RW(record.baseId, send, true); RW(recordData.mName, send, true); RW(recordData.mHasAmbi, send, true); - // don't send ambient lighting information to fix black lighting in cell records that lack this information - if (recordData.mHasAmbi) { - RW(recordData.mAmbi.mAmbient, send, true); - RW(recordData.mAmbi.mSunlight, send, true); - RW(recordData.mAmbi.mFog, send, true); - RW(recordData.mAmbi.mFogDensity, send, true); - } + RW(recordData.mAmbi.mAmbient, send, true); + RW(recordData.mAmbi.mSunlight, send, true); + RW(recordData.mAmbi.mFog, send, true); + RW(recordData.mAmbi.mFogDensity, send, true); + RW(recordData.mData.mFlags, send, true); + RW(recordData.mWater, send, true); if (!record.baseId.empty()) { From 3111f7e988d322d03e53dad205a89cfbcda2612e Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 21 Mar 2020 14:12:00 +0100 Subject: [PATCH 3/8] [General] Cell record water level information --- .../Script/Functions/RecordsDynamic.cpp | 35 +++++++++++++++++++ .../Script/Functions/RecordsDynamic.hpp | 20 +++++++++++ apps/openmw/mwmp/RecordHelper.cpp | 11 ++++++ components/openmw-mp/Base/BaseWorldstate.hpp | 3 ++ .../Worldstate/PacketRecordDynamic.cpp | 2 ++ 5 files changed, 71 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index b26571853..a156b7f27 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -1530,6 +1530,41 @@ void RecordsDynamicFunctions::SetRecordFog(unsigned int red, unsigned int green, tempOverrides.hasFog = true; } +void RecordsDynamicFunctions::SetRecordHasWater(bool hasWater) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + if(hasWater) + tempCell.data.mData.mFlags |= ESM::Cell::Flags::HasWater; + else + tempCell.data.mData.mFlags &= ~ESM::Cell::Flags::HasWater; + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set ambient color for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasHasWater = true; +} + +void RecordsDynamicFunctions::SetRecordWaterLevel(double waterLevel) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + tempCell.data.mWater = waterLevel; + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set ambient color for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasWaterLevel = true; +} + void RecordsDynamicFunctions::SetRecordIdByIndex(unsigned int index, const char* id) noexcept { unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp index 75b5e6760..fa853693f 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp @@ -108,6 +108,8 @@ {"SetRecordAmbientColor", RecordsDynamicFunctions::SetRecordAmbientColor},\ {"SetRecordSunlightColor", RecordsDynamicFunctions::SetRecordSunlightColor},\ {"SetRecordFog", RecordsDynamicFunctions::SetRecordFog},\ + {"SetRecordHasWater", RecordsDynamicFunctions::SetRecordHasWater},\ + {"SetRecordWaterLevel", RecordsDynamicFunctions::SetRecordWaterLevel},\ \ {"SetRecordIdByIndex", RecordsDynamicFunctions::SetRecordIdByIndex},\ {"SetRecordEnchantmentIdByIndex", RecordsDynamicFunctions::SetRecordEnchantmentIdByIndex},\ @@ -918,6 +920,24 @@ public: */ static void SetRecordFog(unsigned int red, unsigned int green, unsigned int blue, double density) noexcept; + /** + * \brief Set the has water of the temporary record stored on the server for the + * currently specified record type. + * + * \param hasWater Has water of the record + * \return void + */ + static void SetRecordHasWater(bool hasWater) noexcept; + + /** + * \brief Set the water level of the temporary record stored on the server for the + * currently specified record type. + * + * \param waterLevel waterLevel of the record + * \return void + */ + static void SetRecordWaterLevel(double waterLevel) noexcept; + /** * \brief Set the id of the record at a certain index in the records stored on the server. * diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index c38cf3f45..420c9f0cb 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -361,10 +361,21 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) finalData.mAmbi.mFog = recordData.mAmbi.mFog; finalData.mAmbi.mFogDensity = recordData.mAmbi.mFogDensity; } + if (record.baseOverrides.hasHasWater) { + bool hasWater = recordData.mData.mFlags & ESM::Cell::Flags::HasWater; + if (hasWater) + finalData.mData.mFlags |= ESM::Cell::Flags::HasWater; + else + finalData.mData.mFlags &= ~ESM::Cell::Flags::HasWater; + } + if (record.baseOverrides.hasWaterLevel) { + finalData.mWater = recordData.mWater; + } world->unloadCell(finalData); world->clearCellStore(finalData); world->getModifiableStore().overrideRecord(finalData); + } else { diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 1845ab9a5..7a64b34fa 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -143,6 +143,9 @@ namespace mwmp bool hasAmbientColor = false; bool hasSunlightColor = false; bool hasFog = false; + bool hasHasWater = false; + bool hasWaterLevel = false; + }; struct ActivatorRecord diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index 35f79624d..289b5db55 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -510,6 +510,8 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) RW(overrides.hasAmbientColor, send); RW(overrides.hasSunlightColor, send); RW(overrides.hasFog, send); + RW(overrides.hasHasWater, send); + RW(overrides.hasWaterLevel, send); } } } From 0143acf08e1f0d9a2c8eb9f574fdef252dedb276 Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 21 Mar 2020 14:16:00 +0100 Subject: [PATCH 4/8] [General] Rename hasHas overrides into has...State --- apps/openmw-mp/Script/Functions/RecordsDynamic.cpp | 4 ++-- apps/openmw-mp/Script/Functions/RecordsDynamic.hpp | 8 ++++---- apps/openmw/mwmp/RecordHelper.cpp | 4 ++-- components/openmw-mp/Base/BaseWorldstate.hpp | 4 ++-- .../openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index a156b7f27..6bd4afabd 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -1478,7 +1478,7 @@ void RecordsDynamicFunctions::SetRecordHasAmbient(bool hasAmbi) noexcept return; } - tempOverrides.hasHasAmbi = true; + tempOverrides.hasAmbiState = true; } void RecordsDynamicFunctions::SetRecordAmbientColor(unsigned int red, unsigned int green, unsigned int blue) noexcept @@ -1546,7 +1546,7 @@ void RecordsDynamicFunctions::SetRecordHasWater(bool hasWater) noexcept return; } - tempOverrides.hasHasWater = true; + tempOverrides.hasWaterState = true; } void RecordsDynamicFunctions::SetRecordWaterLevel(double waterLevel) noexcept diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp index fa853693f..930584ade 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp @@ -884,10 +884,10 @@ public: static void SetRecordScriptText(const char* scriptText) noexcept; /** - * \brief Set the has ambient of the temporary record stored on the server for the + * \brief Set the ambient state of the temporary record stored on the server for the * currently specified record type. * - * \param bool Has ambient of the record + * \param bool Ambient state of the record * \return void */ static void SetRecordHasAmbient(bool hasAmbi) noexcept; @@ -921,10 +921,10 @@ public: static void SetRecordFog(unsigned int red, unsigned int green, unsigned int blue, double density) noexcept; /** - * \brief Set the has water of the temporary record stored on the server for the + * \brief Set the water state of the temporary record stored on the server for the * currently specified record type. * - * \param hasWater Has water of the record + * \param hasWater Water state of the record * \return void */ static void SetRecordHasWater(bool hasWater) noexcept; diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index 420c9f0cb..5836abc2e 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -351,7 +351,7 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) finalData.mName = recordData.mName; finalData.mCellId.mWorldspace = Misc::StringUtils::lowerCase(recordData.mName); - if (record.baseOverrides.hasHasAmbi) + if (record.baseOverrides.hasAmbiState) finalData.mHasAmbi= recordData.mHasAmbi; if (record.baseOverrides.hasAmbientColor) finalData.mAmbi.mAmbient = recordData.mAmbi.mAmbient; @@ -361,7 +361,7 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) finalData.mAmbi.mFog = recordData.mAmbi.mFog; finalData.mAmbi.mFogDensity = recordData.mAmbi.mFogDensity; } - if (record.baseOverrides.hasHasWater) { + if (record.baseOverrides.hasWaterState) { bool hasWater = recordData.mData.mFlags & ESM::Cell::Flags::HasWater; if (hasWater) finalData.mData.mFlags |= ESM::Cell::Flags::HasWater; diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 7a64b34fa..7bc3a7140 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -139,11 +139,11 @@ namespace mwmp bool hasScriptText = false; - bool hasHasAmbi = false; + bool hasAmbiState = false; bool hasAmbientColor = false; bool hasSunlightColor = false; bool hasFog = false; - bool hasHasWater = false; + bool hasWaterState = false; bool hasWaterLevel = false; }; diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index 289b5db55..bcb8aab9d 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -506,11 +506,11 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) if (!record.baseId.empty()) { auto&& overrides = record.baseOverrides; - RW(overrides.hasHasAmbi, send); + RW(overrides.hasAmbiState, send); RW(overrides.hasAmbientColor, send); RW(overrides.hasSunlightColor, send); RW(overrides.hasFog, send); - RW(overrides.hasHasWater, send); + RW(overrides.hasWaterState, send); RW(overrides.hasWaterLevel, send); } } From b67c28cd48408e099f1fc7745c00f4709b428b65 Mon Sep 17 00:00:00 2001 From: uramer Date: Sun, 22 Mar 2020 16:12:00 +0100 Subject: [PATCH 5/8] [General] Don't compress floats and ints in cell record packets --- .../openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index bcb8aab9d..3067f75e7 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -495,13 +495,13 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) RW(record.baseId, send, true); RW(recordData.mName, send, true); - RW(recordData.mHasAmbi, send, true); + RW(recordData.mHasAmbi, send); RW(recordData.mAmbi.mAmbient, send, true); RW(recordData.mAmbi.mSunlight, send, true); RW(recordData.mAmbi.mFog, send, true); - RW(recordData.mAmbi.mFogDensity, send, true); - RW(recordData.mData.mFlags, send, true); - RW(recordData.mWater, send, true); + RW(recordData.mAmbi.mFogDensity, send); + RW(recordData.mData.mFlags, send); + RW(recordData.mWater, send); if (!record.baseId.empty()) { From d6101ce7b636d63f49ad3840bbe8ee25d52ac4b2 Mon Sep 17 00:00:00 2001 From: uramer Date: Mon, 23 Mar 2020 20:11:00 +0100 Subject: [PATCH 6/8] Add Utils::setFlag, refactor duplicate code --- .../Script/Functions/RecordsDynamic.cpp | 13 +++---------- apps/openmw/mwmp/RecordHelper.cpp | 19 ++++++++----------- components/openmw-mp/Utils.hpp | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index 6bd4afabd..bcb97392e 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -8,6 +8,7 @@ #include #include "RecordsDynamic.hpp" +#include "Utils.hpp" using namespace std; using namespace mwmp; @@ -735,16 +736,11 @@ void RecordsDynamicFunctions::SetRecordAutoCalc(int autoCalc) noexcept tempEnchantment.data.mData.mAutocalc = autoCalc; else if (writeRecordsType == mwmp::RECORD_TYPE::NPC) { + Utils::setFlag(tempNpc.data.mFlags, ESM::NPC::Autocalc, autoCalc); if (autoCalc) - { - tempNpc.data.mFlags |= ESM::NPC::Autocalc; tempNpc.data.mNpdtType = ESM::NPC::NPC_WITH_AUTOCALCULATED_STATS; - } else - { - tempNpc.data.mFlags &= ~ESM::NPC::Autocalc; tempNpc.data.mNpdtType = ESM::NPC::NPC_DEFAULT; - } } else { @@ -1535,10 +1531,7 @@ void RecordsDynamicFunctions::SetRecordHasWater(bool hasWater) noexcept unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { - if(hasWater) - tempCell.data.mData.mFlags |= ESM::Cell::Flags::HasWater; - else - tempCell.data.mData.mFlags &= ~ESM::Cell::Flags::HasWater; + Utils::setFlag(tempCell.data.mData.mFlags, ESM::Cell::Flags::HasWater, hasWater); } else { diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index 5836abc2e..dff4a608a 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -4,6 +4,7 @@ #include "../mwworld/worldimp.hpp" #include "RecordHelper.hpp" +#include void RecordHelper::overrideRecord(const mwmp::ActivatorRecord& record) { @@ -337,7 +338,7 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) if (record.baseId.empty()) { - recordData.mData.mFlags |= ESM::Cell::Flags::Interior; + Utils::setFlag(recordData.mData.mFlags, ESM::Cell::Flags::Interior, true); recordData.mCellId.mWorldspace = Misc::StringUtils::lowerCase(recordData.mName); world->unloadCell(recordData); @@ -362,11 +363,11 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) finalData.mAmbi.mFogDensity = recordData.mAmbi.mFogDensity; } if (record.baseOverrides.hasWaterState) { - bool hasWater = recordData.mData.mFlags & ESM::Cell::Flags::HasWater; - if (hasWater) - finalData.mData.mFlags |= ESM::Cell::Flags::HasWater; - else - finalData.mData.mFlags &= ~ESM::Cell::Flags::HasWater; + Utils::setFlag( + finalData.mData.mFlags, + ESM::Cell::Flags::HasWater, + recordData.mData.mFlags + ); } if (record.baseOverrides.hasWaterLevel) { finalData.mWater = recordData.mWater; @@ -1061,11 +1062,7 @@ void RecordHelper::overrideRecord(const mwmp::NpcRecord& record) if (record.baseOverrides.hasAutoCalc) { finalData.mNpdtType = recordData.mNpdtType; - - if ((recordData.mFlags & ESM::NPC::Autocalc) != 0) - finalData.mFlags |= ESM::NPC::Autocalc; - else - finalData.mFlags &= ~ESM::NPC::Autocalc; + Utils::setFlag(finalData.mFlags, ESM::NPC::Autocalc, recordData.mFlags); } if (!record.inventoryBaseId.empty() && doesRecordIdExist(record.inventoryBaseId)) diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index 65bfc3a6d..3e9fe77e4 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -65,5 +65,21 @@ namespace Utils std::string intToHexStr(unsigned val); unsigned int hexStrToInt(std::string hexString); + + template + void setFlag(T& flags, E bit, bool value) { + if (value) + flags |= bit; + else + flags &= ~bit; + } + + template + void setFlag(T& flags, E bit, T source) { + if (source & bit) + flags |= bit; + else + flags &= ~bit; + } } #endif //UTILS_HPP From 32e51ed3e05bcfbdf92bc9beb4a8fb192bcf1e74 Mon Sep 17 00:00:00 2001 From: uramer Date: Mon, 23 Mar 2020 21:13:00 +0100 Subject: [PATCH 7/8] [General] NoSleep, QuasiEx and Region properties of cell custom records --- .../Script/Functions/RecordsDynamic.cpp | 49 +++++++++++++++++++ .../Script/Functions/RecordsDynamic.hpp | 28 +++++++++++ apps/openmw/mwmp/RecordHelper.cpp | 17 +++++++ components/openmw-mp/Base/BaseWorldstate.hpp | 3 ++ .../Worldstate/PacketRecordDynamic.cpp | 3 ++ 5 files changed, 100 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index bcb97392e..6654ce2cb 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -1558,6 +1558,55 @@ void RecordsDynamicFunctions::SetRecordWaterLevel(double waterLevel) noexcept tempOverrides.hasWaterLevel = true; } +void RecordsDynamicFunctions::SetRecordNoSleep(bool noSleep) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + Utils::setFlag(tempCell.data.mData.mFlags, ESM::Cell::Flags::NoSleep, noSleep); + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set no sleep state for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasNoSleep = true; +} + +void RecordsDynamicFunctions::SetRecordQuasiEx(bool quasiEx) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + Utils::setFlag(tempCell.data.mData.mFlags, ESM::Cell::Flags::QuasiEx, quasiEx); + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set quasi exterior state for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasQuasiEx = true; +} + +void RecordsDynamicFunctions::SetRecordRegion(const char* region) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CELL) { + tempCell.data.mRegion = region; + } + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set quasi exterior state for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasRegion = true; +} + + void RecordsDynamicFunctions::SetRecordIdByIndex(unsigned int index, const char* id) noexcept { unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp index 930584ade..f62da688c 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp @@ -110,6 +110,9 @@ {"SetRecordFog", RecordsDynamicFunctions::SetRecordFog},\ {"SetRecordHasWater", RecordsDynamicFunctions::SetRecordHasWater},\ {"SetRecordWaterLevel", RecordsDynamicFunctions::SetRecordWaterLevel},\ + {"SetRecordNoSleep", RecordsDynamicFunctions::SetRecordNoSleep},\ + {"SetRecordQuasiEx", RecordsDynamicFunctions::SetRecordQuasiEx},\ + {"SetRecordRegion", RecordsDynamicFunctions::SetRecordRegion},\ \ {"SetRecordIdByIndex", RecordsDynamicFunctions::SetRecordIdByIndex},\ {"SetRecordEnchantmentIdByIndex", RecordsDynamicFunctions::SetRecordEnchantmentIdByIndex},\ @@ -938,6 +941,31 @@ public: */ static void SetRecordWaterLevel(double waterLevel) noexcept; + /** + * \brief Set whether players are allowed to sleep in the temporary record + * stored on the server for the currently specified record type. + * + * \param noSleep Whether players are allowed to sleep + * \return void + */ + static void SetRecordNoSleep(bool noSleep) noexcept; + + /** + * \brief Set whether the temporary record stored on the server for the + * currently specified record type is a quasi exterior. + * \param quasiEx Whether the record is a quasi exterior. + * \return void + */ + static void SetRecordQuasiEx(bool quasiEx) noexcept; + + /** + * \brief Set region of the temporary record stored on the server for the + * currently specified record type. + * \param region The region of the record + * \return void + */ + static void SetRecordRegion(const char* region) noexcept; + /** * \brief Set the id of the record at a certain index in the records stored on the server. * diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index dff4a608a..87e6b39d7 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -372,6 +372,23 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) if (record.baseOverrides.hasWaterLevel) { finalData.mWater = recordData.mWater; } + if (record.baseOverrides.hasNoSleep) { + Utils::setFlag( + finalData.mData.mFlags, + ESM::Cell::Flags::NoSleep, + recordData.mData.mFlags + ); + } + if (record.baseOverrides.hasQuasiEx) { + Utils::setFlag( + finalData.mData.mFlags, + ESM::Cell::Flags::QuasiEx, + recordData.mData.mFlags + ); + } + if (record.baseOverrides.hasRegion) { + finalData.mRegion = recordData.mRegion; + } world->unloadCell(finalData); world->clearCellStore(finalData); diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 7bc3a7140..245143e17 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -145,6 +145,9 @@ namespace mwmp bool hasFog = false; bool hasWaterState = false; bool hasWaterLevel = false; + bool hasNoSleep = false; + bool hasQuasiEx = false; + bool hasRegion = false; }; diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index 3067f75e7..ee5a4c4fc 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -512,6 +512,9 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) RW(overrides.hasFog, send); RW(overrides.hasWaterState, send); RW(overrides.hasWaterLevel, send); + RW(overrides.hasNoSleep, send); + RW(overrides.hasQuasiEx, send); + RW(overrides.hasRegion, send); } } } From 4d179157ba1d4b4235f873411bd10efd0b6ba921 Mon Sep 17 00:00:00 2001 From: Dave Corley Date: Mon, 25 Sep 2023 17:58:12 -0500 Subject: [PATCH 8/8] Fix(client): Included bad code --- apps/openmw-mp/Script/Functions/RecordsDynamic.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index 60609b0bb..dff58f4b3 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -746,8 +746,6 @@ void RecordsDynamicFunctions::SetRecordAutoCalc(int autoCalc) noexcept if (writeRecordsType == mwmp::RECORD_TYPE::POTION) tempPotion.data.mData.mAutoCalc = autoCalc; - else if (writeRecordsType == mwmp::RECORD_TYPE::ENCHANTMENT) - tempEnchantment.data.mData.mAutocalc = autoCalc; else if (writeRecordsType == mwmp::RECORD_TYPE::NPC) { Utils::setFlag(tempNpc.data.mFlags, ESM::NPC::Autocalc, autoCalc);