forked from 0ad/0ad
Don't poll territory in Position component
CmpPosition::TurnStart checks whether the territory changed underneath each entityevery turn. The only user of this is TerritoryDecay (structures, for the most part). It is rather inefficient to have this done for all entities. The simplest solution is to listen to position-changed messages in TerritoryDecay instead. This should hardly ever happen in vanilla 0 A.D., except in Atlas, so it's basically free. This sort of reverts19965ce37a
(original implementation) andc44b48bd59
. Accepted By: Freagarach (concept only) Differential Revision: https://code.wildfiregames.com/D5009 This was SVN commit r27673.
This commit is contained in:
parent
2a17a2866e
commit
7350b9042e
@ -131,7 +131,7 @@ TerritoryDecay.prototype.OnTerritoriesChanged = function(msg)
|
||||
this.UpdateDecayState();
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.OnTerritoryPositionChanged = function(msg)
|
||||
TerritoryDecay.prototype.OnPositionChanged = function(msg)
|
||||
{
|
||||
if (this.territoryOwnership)
|
||||
this.UpdateOwner();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -301,21 +301,6 @@ public:
|
||||
CVector3D pos1;
|
||||
};
|
||||
|
||||
/*Sent whenever the territory type (neutral,own,enemy) differs from the former type*/
|
||||
class CMessageTerritoryPositionChanged final : public CMessage
|
||||
{
|
||||
public:
|
||||
DEFAULT_MESSAGE_IMPL(TerritoryPositionChanged)
|
||||
|
||||
CMessageTerritoryPositionChanged(entity_id_t entity, player_id_t newTerritory) :
|
||||
entity(entity), newTerritory(newTerritory)
|
||||
{
|
||||
}
|
||||
|
||||
entity_id_t entity;
|
||||
player_id_t newTerritory;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sent by CCmpUnitMotion during Update if an event happened that might interest other components.
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -44,7 +44,6 @@ MESSAGE(Destroy)
|
||||
MESSAGE(OwnershipChanged)
|
||||
MESSAGE(PositionChanged)
|
||||
MESSAGE(InterpolatedPositionChanged)
|
||||
MESSAGE(TerritoryPositionChanged)
|
||||
MESSAGE(MotionUpdate)
|
||||
MESSAGE(RangeUpdate)
|
||||
MESSAGE(TerrainChanged)
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "simulation2/serialization/SerializedTypes.h"
|
||||
|
||||
#include "ICmpTerrain.h"
|
||||
#include "ICmpTerritoryManager.h"
|
||||
#include "ICmpVisual.h"
|
||||
#include "ICmpWaterManager.h"
|
||||
|
||||
@ -90,8 +89,6 @@ public:
|
||||
// relative to the parent entity
|
||||
entity_angle_t m_RotX, m_RotY, m_RotZ;
|
||||
|
||||
player_id_t m_Territory;
|
||||
|
||||
entity_id_t m_TurretParent;
|
||||
CFixedVector3D m_TurretPosition;
|
||||
std::set<entity_id_t> m_Turrets;
|
||||
@ -161,7 +158,6 @@ public:
|
||||
m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0);
|
||||
m_InterpolatedRotX = m_InterpolatedRotY = m_InterpolatedRotZ = 0.f;
|
||||
m_LastInterpolatedRotX = m_LastInterpolatedRotZ = 0.f;
|
||||
m_Territory = INVALID_PLAYER;
|
||||
|
||||
m_TurretParent = INVALID_ENTITY;
|
||||
m_TurretPosition = CFixedVector3D();
|
||||
@ -187,7 +183,7 @@ public:
|
||||
serialize.NumberFixed_Unbounded("last y diff", m_LastYDifference);
|
||||
serialize.NumberFixed_Unbounded("last z", m_LastZ);
|
||||
}
|
||||
serialize.NumberI32_Unbounded("territory", m_Territory);
|
||||
|
||||
serialize.NumberFixed_Unbounded("rot x", m_RotX);
|
||||
serialize.NumberFixed_Unbounded("rot y", m_RotY);
|
||||
serialize.NumberFixed_Unbounded("rot z", m_RotZ);
|
||||
@ -246,7 +242,7 @@ public:
|
||||
deserialize.NumberFixed_Unbounded("last y diff", m_LastYDifference);
|
||||
deserialize.NumberFixed_Unbounded("last z", m_LastZ);
|
||||
}
|
||||
deserialize.NumberI32_Unbounded("territory", m_Territory);
|
||||
|
||||
deserialize.NumberFixed_Unbounded("rot x", m_RotX);
|
||||
deserialize.NumberFixed_Unbounded("rot y", m_RotY);
|
||||
deserialize.NumberFixed_Unbounded("rot z", m_RotZ);
|
||||
@ -839,29 +835,6 @@ public:
|
||||
m_LastZ = m_Z;
|
||||
m_LastYDifference = entity_pos_t::Zero();
|
||||
|
||||
|
||||
// warn when a position change also causes a territory change under the entity
|
||||
if (m_InWorld)
|
||||
{
|
||||
player_id_t newTerritory;
|
||||
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSystemEntity());
|
||||
if (cmpTerritoryManager)
|
||||
newTerritory = cmpTerritoryManager->GetOwner(m_X, m_Z);
|
||||
else
|
||||
newTerritory = INVALID_PLAYER;
|
||||
if (newTerritory != m_Territory)
|
||||
{
|
||||
m_Territory = newTerritory;
|
||||
CMessageTerritoryPositionChanged posMsg(GetEntityId(), m_Territory);
|
||||
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), posMsg);
|
||||
}
|
||||
}
|
||||
else if (m_Territory != INVALID_PLAYER)
|
||||
{
|
||||
m_Territory = INVALID_PLAYER;
|
||||
CMessageTerritoryPositionChanged posMsg(GetEntityId(), m_Territory);
|
||||
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), posMsg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MT_TerrainChanged:
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -247,24 +247,6 @@ CMessage* CMessageInterpolatedPositionChanged::FromJSVal(const ScriptInterface&
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
JS::Value CMessageTerritoryPositionChanged::ToJSVal(const ScriptInterface& scriptInterface) const
|
||||
{
|
||||
TOJSVAL_SETUP();
|
||||
SET_MSG_PROPERTY(entity);
|
||||
SET_MSG_PROPERTY(newTerritory);
|
||||
return JS::ObjectValue(*obj);
|
||||
}
|
||||
|
||||
CMessage* CMessageTerritoryPositionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
|
||||
{
|
||||
FROMJSVAL_SETUP();
|
||||
GET_MSG_PROPERTY(entity_id_t, entity);
|
||||
GET_MSG_PROPERTY(player_id_t, newTerritory);
|
||||
return new CMessageTerritoryPositionChanged(entity, newTerritory);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
const std::array<const char*, CMessageMotionUpdate::UpdateType::LENGTH> CMessageMotionUpdate::UpdateTypeStr = { {
|
||||
"likelySuccess", "likelyFailure", "obstructed", "veryObstructed"
|
||||
} };
|
||||
|
Loading…
Reference in New Issue
Block a user