Changeset 27673

Timestamp:
Jun 13, 2023, 5:48:03 PM (14 months ago)
Author:
wraitii
Message:

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 reverts rP14754 (original implementation) and rP14768.

Accepted By: Freagarach (concept only)

Differential Revision: https://code.wildfiregames.com/D5009

Location:
ps/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/TerritoryDecay.js

    r25458 r27673  
    132132};
    133133
    134 TerritoryDecay.prototype.OnTerritoryPositionChanged = function(msg)
     134TerritoryDecay.prototype.OnPositionChanged = function(msg)
    135135{
    136136    if (this.territoryOwnership)
  • ps/trunk/source/simulation2/MessageTypes.h

    r26537 r27673  
    1 /* Copyright (C) 2022 Wildfire Games.
     1/* Copyright (C) 202 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    302302};
    303303
    304 /*Sent whenever the territory type (neutral,own,enemy) differs from the former type*/
    305 class CMessageTerritoryPositionChanged final : public CMessage
    306 {
    307 public:
    308     DEFAULT_MESSAGE_IMPL(TerritoryPositionChanged)
    309 
    310     CMessageTerritoryPositionChanged(entity_id_t entity, player_id_t newTerritory) :
    311         entity(entity), newTerritory(newTerritory)
    312     {
    313     }
    314 
    315     entity_id_t entity;
    316     player_id_t newTerritory;
    317 };
    318 
    319304/**
    320305 * Sent by CCmpUnitMotion during Update if an event happened that might interest other components.
  • ps/trunk/source/simulation2/TypeList.h

    r25182 r27673  
    1 /* Copyright (C) 2021 Wildfire Games.
     1/* Copyright (C) 202 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    4545MESSAGE(PositionChanged)
    4646MESSAGE(InterpolatedPositionChanged)
    47 MESSAGE(TerritoryPositionChanged)
    4847MESSAGE(MotionUpdate)
    4948MESSAGE(RangeUpdate)
  • ps/trunk/source/simulation2/components/CCmpPosition.cpp

    r26605 r27673  
    2525
    2626#include "ICmpTerrain.h"
    27 #include "ICmpTerritoryManager.h"
    2827#include "ICmpVisual.h"
    2928#include "ICmpWaterManager.h"
     
    9089    // relative to the parent entity
    9190    entity_angle_t m_RotX, m_RotY, m_RotZ;
    92 
    93     player_id_t m_Territory;
    9491
    9592    entity_id_t m_TurretParent;
     
    162159        m_InterpolatedRotX = m_InterpolatedRotY = m_InterpolatedRotZ = 0.f;
    163160        m_LastInterpolatedRotX = m_LastInterpolatedRotZ = 0.f;
    164         m_Territory = INVALID_PLAYER;
    165161
    166162        m_TurretParent = INVALID_ENTITY;
     
    188184            serialize.NumberFixed_Unbounded("last z", m_LastZ);
    189185        }
    190         serialize.NumberI32_Unbounded("territory", m_Territory);
     186
    191187        serialize.NumberFixed_Unbounded("rot x", m_RotX);
    192188        serialize.NumberFixed_Unbounded("rot y", m_RotY);
     
    247243            deserialize.NumberFixed_Unbounded("last z", m_LastZ);
    248244        }
    249         deserialize.NumberI32_Unbounded("territory", m_Territory);
     245
    250246        deserialize.NumberFixed_Unbounded("rot x", m_RotX);
    251247        deserialize.NumberFixed_Unbounded("rot y", m_RotY);
     
    840836            m_LastYDifference = entity_pos_t::Zero();
    841837
    842 
    843             // warn when a position change also causes a territory change under the entity
    844             if (m_InWorld)
    845             {
    846                 player_id_t newTerritory;
    847                 CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSystemEntity());
    848                 if (cmpTerritoryManager)
    849                     newTerritory = cmpTerritoryManager->GetOwner(m_X, m_Z);
    850                 else
    851                     newTerritory = INVALID_PLAYER;
    852                 if (newTerritory != m_Territory)
    853                 {
    854                     m_Territory = newTerritory;
    855                     CMessageTerritoryPositionChanged posMsg(GetEntityId(), m_Territory);
    856                     GetSimContext().GetComponentManager().PostMessage(GetEntityId(), posMsg);
    857                 }
    858             }
    859             else if (m_Territory != INVALID_PLAYER)
    860             {
    861                 m_Territory = INVALID_PLAYER;
    862                 CMessageTerritoryPositionChanged posMsg(GetEntityId(), m_Territory);
    863                 GetSimContext().GetComponentManager().PostMessage(GetEntityId(), posMsg);
    864             }
    865838            break;
    866839        }
  • ps/trunk/source/simulation2/scripting/MessageTypeConversions.cpp

    r25434 r27673  
    1 /* Copyright (C) 2021 Wildfire Games.
     1/* Copyright (C) 202 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    248248////////////////////////////////
    249249
    250 JS::Value CMessageTerritoryPositionChanged::ToJSVal(const ScriptInterface& scriptInterface) const
    251 {
    252     TOJSVAL_SETUP();
    253     SET_MSG_PROPERTY(entity);
    254     SET_MSG_PROPERTY(newTerritory);
    255     return JS::ObjectValue(*obj);
    256 }
    257 
    258 CMessage* CMessageTerritoryPositionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val)
    259 {
    260     FROMJSVAL_SETUP();
    261     GET_MSG_PROPERTY(entity_id_t, entity);
    262     GET_MSG_PROPERTY(player_id_t, newTerritory);
    263     return new CMessageTerritoryPositionChanged(entity, newTerritory);
    264 }
    265 
    266 ////////////////////////////////
    267 
    268250const std::array<const char*, CMessageMotionUpdate::UpdateType::LENGTH> CMessageMotionUpdate::UpdateTypeStr = { {
    269251    "likelySuccess", "likelyFailure", "obstructed", "veryObstructed"
Note: See TracChangeset for help on using the changeset viewer.