forked from mirrors/0ad
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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());
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Entity filtered="">
|
||||
<Footprint merge=""/>
|
||||
<Identity merge=""/> <!-- Necessary for foundation preview to get visualactor modifiers. -->
|
||||
<Ownership merge=""/>
|
||||
<Position merge=""/>
|
||||
<VisualActor merge=""/>
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
<History merge=""/>
|
||||
<Icon merge=""/>
|
||||
<Undeletable merge=""/>
|
||||
<!-- Classes are explicitly not added to avoid having to check for mirages
|
||||
in unexpected places. -->
|
||||
</Identity>
|
||||
<Minimap merge=""/>
|
||||
<Mirage replace=""/>
|
||||
|
||||
@@ -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<const CMessageOwnershipChanged&> (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<ICmpMirage> cmpMirage(GetEntityHandle());
|
||||
if (cmpMirage)
|
||||
return;
|
||||
|
||||
const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg);
|
||||
if (msgData.component != L"VisualActor")
|
||||
break;
|
||||
CmpPtr<ICmpValueModificationManager> 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<ICmpValueModificationManager> 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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user