From 9102df7fde03b12c257d746a9d23806178513ace Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 28 Jun 2018 04:53:00 +0300 Subject: [PATCH] [General] Make WorldCollisionOverride also work with specific refIds For now, this only makes it possible to enforce collision for specific refIds for placed objects. --- .../openmw-mp/Script/Functions/Worldstate.cpp | 10 ++++++++++ .../openmw-mp/Script/Functions/Worldstate.hpp | 20 +++++++++++++++++++ apps/openmw/mwclass/apparatus.cpp | 3 ++- apps/openmw/mwclass/armor.cpp | 3 ++- apps/openmw/mwclass/book.cpp | 3 ++- apps/openmw/mwclass/clothing.cpp | 3 ++- apps/openmw/mwclass/ingredient.cpp | 3 ++- apps/openmw/mwclass/misc.cpp | 3 ++- apps/openmw/mwclass/potion.cpp | 3 ++- apps/openmw/mwclass/repair.cpp | 3 ++- apps/openmw/mwclass/weapon.cpp | 3 ++- components/openmw-mp/Base/BaseWorldstate.hpp | 2 ++ .../PacketWorldCollisionOverride.cpp | 18 +++++++++++++++++ 13 files changed, 68 insertions(+), 9 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index 6a4bc9393..2379263e2 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -93,6 +93,16 @@ void WorldstateFunctions::UseActorCollisionForPlacedObjects(bool useActorCollisi writeWorldstate.useActorCollisionForPlacedObjects = useActorCollision; } +void WorldstateFunctions::AddEnforcedCollisionRefId(const char *refId) noexcept +{ + writeWorldstate.enforcedCollisionRefIds.push_back(refId); +} + +void WorldstateFunctions::ClearEnforcedCollisionRefIds() noexcept +{ + writeWorldstate.enforcedCollisionRefIds.clear(); +} + void WorldstateFunctions::SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept { if (index >= readWorldstate->mapChanges.mapTiles.size()) diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index f45ed8ab9..640d1b711 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -27,6 +27,9 @@ {"SetPlacedObjectCollisionState", WorldstateFunctions::SetPlacedObjectCollisionState},\ {"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\ \ + {"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\ + {"ClearEnforcedCollisionRefIds", WorldstateFunctions::ClearEnforcedCollisionRefIds},\ + \ {"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\ {"LoadMapTileImageFile", WorldstateFunctions::LoadMapTileImageFile},\ \ @@ -173,6 +176,23 @@ public: */ static void UseActorCollisionForPlacedObjects(bool useActorCollision) noexcept; + /** + * \brief Add a refId to the list of refIds for which collision should be enforced + * irrespective of other settings. + * + * \param refId The refId. + * \return void + */ + static void AddEnforcedCollisionRefId(const char* refId) noexcept; + + /** + * \brief Clear the list of refIdsd for which collision should be enforced irrespective + * of other settings. + * + * \return void + */ + static void ClearEnforcedCollisionRefIds() noexcept; + /** * \brief Save the .png image data of the map tile at a certain index in the read worldstate's * map changes. diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index ae16b289a..d8ec93742 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -52,7 +53,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 6220c79d5..e6096e73f 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -58,7 +59,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index e16a99398..de7e2d4e8 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -55,7 +56,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 2f790e559..e5cba7f98 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -54,7 +55,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 6c03f31ef..a41469860 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -55,7 +56,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 0625dfdd6..eaa40a01c 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -62,7 +63,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 475b4ef50..7fd4b4666 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -56,7 +57,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index ec84bb803..c9b24ce2b 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -52,7 +53,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 4d0b7411b..7bb3ccb32 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -5,6 +5,7 @@ Include additional headers for multiplayer purposes */ +#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" /* @@ -56,7 +57,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 12839fbc2..863dd7abc 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -52,6 +52,8 @@ namespace mwmp bool hasPlacedObjectCollision; bool useActorCollisionForPlacedObjects; + std::vector enforcedCollisionRefIds; + MapChanges mapChanges; bool isValid; diff --git a/components/openmw-mp/Packets/Worldstate/PacketWorldCollisionOverride.cpp b/components/openmw-mp/Packets/Worldstate/PacketWorldCollisionOverride.cpp index ee9720600..5570d37ec 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketWorldCollisionOverride.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldCollisionOverride.cpp @@ -17,4 +17,22 @@ void PacketWorldCollisionOverride::Packet(RakNet::BitStream *bs, bool send) RW(worldstate->hasActorCollision, send); RW(worldstate->hasPlacedObjectCollision, send); RW(worldstate->useActorCollisionForPlacedObjects, send); + + uint32_t enforcedCollisionCount; + + if (send) + enforcedCollisionCount = static_cast(worldstate->enforcedCollisionRefIds.size()); + + RW(enforcedCollisionCount, send); + + if (!send) + { + worldstate->enforcedCollisionRefIds.clear(); + worldstate->enforcedCollisionRefIds.resize(enforcedCollisionCount); + } + + for (auto &&enforcedCollisionRefId : worldstate->enforcedCollisionRefIds) + { + RW(enforcedCollisionRefId, send); + } }