From 7bf933d5f688e8bf49550cbd4b2ea799ce58f9d7 Mon Sep 17 00:00:00 2001 From: wraitii Date: Sat, 28 Nov 2020 08:57:15 +0000 Subject: [PATCH] Fix VisualActor tech changes for mirages Correctly recompute the actor when something changes that could modify it (ownership change, ...). Make sure mirages are updated when they reappear after being hidden. Make sure foundations have proper identity classes. Make sure mirages don't respond to value modifications in the visual component. Clarify a few comments. Earlier work by: Sandarac Fixes #2907 Differential Revision: https://code.wildfiregames.com/D576 This was SVN commit r24279. --- .../public/simulation/components/Fogging.js | 2 + .../public/simulation/components/Mirage.js | 7 +-- .../simulation/components/ModifiersManager.js | 2 +- .../templates/special/filter/construction.xml | 1 + .../templates/special/filter/mirage.xml | 2 + .../components/CCmpVisualActor.cpp | 43 +++++++++++++------ source/simulation2/components/ICmpVisual.cpp | 3 +- source/simulation2/components/ICmpVisual.h | 7 ++- 8 files changed, 48 insertions(+), 19 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Fogging.js b/binaries/data/mods/public/simulation/components/Fogging.js index 8097448035..59a20e6beb 100644 --- a/binaries/data/mods/public/simulation/components/Fogging.js +++ b/binaries/data/mods/public/simulation/components/Fogging.js @@ -109,6 +109,8 @@ Fogging.prototype.LoadMirage = function(player) error("Failed to copy the visual data of the fogged entity " + this.entity); return; } + + cmpMirageVisualActor.RecomputeActorName(); cmpMirageVisualActor.SetActorSeed(cmpParentVisualActor.GetActorSeed()); // Store valuable information into the mirage component (especially for the GUI) diff --git a/binaries/data/mods/public/simulation/components/Mirage.js b/binaries/data/mods/public/simulation/components/Mirage.js index fa82248cca..e305437ce2 100644 --- a/binaries/data/mods/public/simulation/components/Mirage.js +++ b/binaries/data/mods/public/simulation/components/Mirage.js @@ -73,9 +73,10 @@ Mirage.prototype.Mirages = function(iid) Mirage.prototype.CopyIdentity = function(cmpIdentity) { this.miragedIids.add(IID_Identity); - // In almost all cases we want to ignore mirage entities when querying Identity components of owned entities. - // To avoid adding a test everywhere, we don't transfer the classeslist in the template but here. - // We clone this since the classes list is not synchronized and since the mirage should be a snapshot of the entity at the given time. + // Mirages don't get identity classes via the template-filter, so that code can query + // identity components via Engine.QueryInterface without having to explicitly check for mirages. + // This is cloned as otherwise we get a reference to Identity's property, + // and that array is deleted when serializing (as it's not seralized), which ends in OOS. this.classesList = clone(cmpIdentity.GetClassesList()); }; diff --git a/binaries/data/mods/public/simulation/components/ModifiersManager.js b/binaries/data/mods/public/simulation/components/ModifiersManager.js index 1c4b24714f..25320e2c2b 100755 --- a/binaries/data/mods/public/simulation/components/ModifiersManager.js +++ b/binaries/data/mods/public/simulation/components/ModifiersManager.js @@ -161,7 +161,7 @@ ModifiersManager.prototype.ApplyModifiers = function(propertyName, originalValue newValue = originalValue; - let cmpIdentity = Engine.QueryInterface(entity, IID_Identity); + let cmpIdentity = QueryMiragedInterface(entity, IID_Identity); if (!cmpIdentity) return originalValue; let classesList = cmpIdentity.GetClassesList(); diff --git a/binaries/data/mods/public/simulation/templates/special/filter/construction.xml b/binaries/data/mods/public/simulation/templates/special/filter/construction.xml index c7f7da7ea2..24b3b2ee51 100644 --- a/binaries/data/mods/public/simulation/templates/special/filter/construction.xml +++ b/binaries/data/mods/public/simulation/templates/special/filter/construction.xml @@ -1,6 +1,7 @@ + diff --git a/binaries/data/mods/public/simulation/templates/special/filter/mirage.xml b/binaries/data/mods/public/simulation/templates/special/filter/mirage.xml index ad328e0503..13dc304870 100644 --- a/binaries/data/mods/public/simulation/templates/special/filter/mirage.xml +++ b/binaries/data/mods/public/simulation/templates/special/filter/mirage.xml @@ -9,6 +9,8 @@ + diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp index 9381050360..e2ce6ed8cc 100644 --- a/source/simulation2/components/CCmpVisualActor.cpp +++ b/source/simulation2/components/CCmpVisualActor.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,12 +24,13 @@ #include "ICmpFootprint.h" #include "ICmpIdentity.h" -#include "ICmpUnitRenderer.h" +#include "ICmpMirage.h" #include "ICmpOwnership.h" #include "ICmpPosition.h" #include "ICmpTemplateManager.h" #include "ICmpTerrain.h" #include "ICmpUnitMotion.h" +#include "ICmpUnitRenderer.h" #include "ICmpValueModificationManager.h" #include "ICmpVisibility.h" #include "ICmpSound.h" @@ -295,11 +296,14 @@ public: { case MT_OwnershipChanged: { + RecomputeActorName(); + if (!m_Unit) break; const CMessageOwnershipChanged& msgData = static_cast (msg); m_Unit->GetModel().SetPlayerID(msgData.to); + break; } case MT_TerrainChanged: @@ -313,20 +317,17 @@ public: } case MT_ValueModification: { + // Mirages don't respond to technology modifications. + CmpPtr cmpMirage(GetEntityHandle()); + if (cmpMirage) + return; + const CMessageValueModification& msgData = static_cast (msg); if (msgData.component != L"VisualActor") break; - CmpPtr cmpValueModificationManager(GetSystemEntity()); - std::wstring newActorName; - if (m_IsFoundationActor) - newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/FoundationActor", m_BaseActorName, GetEntityId()); - else - newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/Actor", m_BaseActorName, GetEntityId()); - if (newActorName != m_ActorName) - { - ParseActorName(newActorName); - ReloadActor(); - } + + RecomputeActorName(); + break; } case MT_InterpolatedPositionChanged: @@ -528,6 +529,22 @@ public: ReloadActor(); } + virtual void RecomputeActorName() + { + CmpPtr cmpValueModificationManager(GetSystemEntity()); + std::wstring newActorName; + if (m_IsFoundationActor) + newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/FoundationActor", m_BaseActorName, GetEntityId()); + else + newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/Actor", m_BaseActorName, GetEntityId()); + + if (newActorName != m_ActorName) + { + ParseActorName(newActorName); + ReloadActor(); + } + } + virtual bool HasConstructionPreview() const { return m_ConstructionPreview; diff --git a/source/simulation2/components/ICmpVisual.cpp b/source/simulation2/components/ICmpVisual.cpp index e9658d5ff7..911146e185 100644 --- a/source/simulation2/components/ICmpVisual.cpp +++ b/source/simulation2/components/ICmpVisual.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -33,5 +33,6 @@ DEFINE_INTERFACE_METHOD_4("SetShadingColor", void, ICmpVisual, SetShadingColor, DEFINE_INTERFACE_METHOD_2("SetVariable", void, ICmpVisual, SetVariable, std::string, float) DEFINE_INTERFACE_METHOD_CONST_0("GetActorSeed", u32, ICmpVisual, GetActorSeed) DEFINE_INTERFACE_METHOD_1("SetActorSeed", void, ICmpVisual, SetActorSeed, u32) +DEFINE_INTERFACE_METHOD_0("RecomputeActorName", void, ICmpVisual, RecomputeActorName) DEFINE_INTERFACE_METHOD_CONST_0("HasConstructionPreview", bool, ICmpVisual, HasConstructionPreview) END_INTERFACE_WRAPPER(Visual) diff --git a/source/simulation2/components/ICmpVisual.h b/source/simulation2/components/ICmpVisual.h index 9c90197f9a..78ec9cf80a 100644 --- a/source/simulation2/components/ICmpVisual.h +++ b/source/simulation2/components/ICmpVisual.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -152,6 +152,11 @@ public: */ virtual void SetActorSeed(u32 seed) = 0; + /** + * Recalculate the actor name, applying modifiers. + */ + virtual void RecomputeActorName() = 0; + /** * Returns true if this entity should have a construction preview */