From e9c3abc2c3a925f2879fa99e70d4b90b3ce6ffda Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 10 Apr 2017 02:37:43 +0300 Subject: [PATCH] [Server] Reset variables more elegantly in WorldFunctions --- apps/openmw-mp/Script/Functions/World.cpp | 28 +++++++---------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 3a6b3dbf7..ccae84ff2 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -10,8 +10,12 @@ using namespace mwmp; BaseEvent scriptEvent; + WorldObject tempWorldObject; +const WorldObject emptyWorldObject = {}; + ContainerItem tempContainerItem; +const ContainerItem emptyContainerItem = {}; std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$"); @@ -243,32 +247,16 @@ void WorldFunctions::SetContainerItemCharge(int charge) noexcept void WorldFunctions::AddWorldObject() noexcept { - WorldObject worldObject; - worldObject.refId = tempWorldObject.refId; - worldObject.refNumIndex = tempWorldObject.refNumIndex; - worldObject.mpNum = tempWorldObject.mpNum; - worldObject.count = tempWorldObject.count; - worldObject.charge = tempWorldObject.charge; - worldObject.goldValue = tempWorldObject.goldValue; - worldObject.scale = tempWorldObject.scale; - worldObject.doorState = tempWorldObject.doorState; - worldObject.lockLevel = tempWorldObject.lockLevel; - worldObject.pos = tempWorldObject.pos; - worldObject.containerChanges.items = tempWorldObject.containerChanges.items; - - scriptEvent.objectChanges.objects.push_back(worldObject); + scriptEvent.objectChanges.objects.push_back(tempWorldObject); - tempWorldObject.containerChanges.items.clear(); + tempWorldObject = emptyWorldObject; } void WorldFunctions::AddContainerItem() noexcept { - ContainerItem containerItem; - containerItem.refId = tempContainerItem.refId; - containerItem.count = tempContainerItem.count; - containerItem.charge = tempContainerItem.charge; + tempWorldObject.containerChanges.items.push_back(tempContainerItem); - tempWorldObject.containerChanges.items.push_back(containerItem); + tempContainerItem = emptyContainerItem; } void WorldFunctions::SendObjectDelete() noexcept