Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CCmpUnitRenderer Class Referencefinal

Efficiently(ish) renders all the units in the world. More...

Inheritance diagram for CCmpUnitRenderer:
Collaboration diagram for CCmpUnitRenderer:

Classes

struct  SUnit
 

Public Member Functions

int GetComponentTypeId () const override
 
void Init (const CParamNode &paramNode) override
 
void Deinit () override
 
void Serialize (ISerializer &serialize) override
 
void Deserialize (const CParamNode &paramNode, IDeserializer &deserialize) override
 
void HandleMessage (const CMessage &msg, bool global) override
 
SUnitLookupUnit (tag_t tag)
 
tag_t AddUnit (CEntityHandle entity, CUnit *actor, const CBoundingSphere &boundsApprox, int flags) override
 
void RemoveUnit (tag_t tag) override
 
void RecomputeSweptBounds (SUnit *unit)
 
void UpdateUnit (tag_t tag, CUnit *actor, const CBoundingSphere &boundsApprox) override
 
void UpdateUnitPos (tag_t tag, bool inWorld, const CVector3D &pos0, const CVector3D &pos1) override
 
void TurnStart ()
 
void Interpolate (float frameTime, float frameOffset)
 
void RenderSubmit (SceneCollector &collector, const CFrustum &frustum, bool culling)
 
void UpdateVisibility (SUnit &unit) const
 
float GetFrameOffset () const override
 Returns the frame offset from the last Interpolate message. More...
 
void SetDebugOverlay (bool enabled) override
 Toggle the rendering of debug info. More...
 
void PickAllEntitiesAtPoint (std::vector< std::pair< CEntityHandle, CVector3D > > &outEntities, const CVector3D &origin, const CVector3D &dir, bool allowEditorSelectables) const override
 Return a list of visual entities along with their center point. More...
 
virtual tag_t AddUnit (CEntityHandle entity, CUnit *unit, const CBoundingSphere &boundsApprox, int flags)=0
 
virtual void RemoveUnit (tag_t tag)=0
 
virtual void UpdateUnit (tag_t tag, CUnit *unit, const CBoundingSphere &boundsApprox)=0
 
virtual void UpdateUnitPos (tag_t tag, bool inWorld, const CVector3D &pos0, const CVector3D &pos1)=0
 
virtual void PickAllEntitiesAtPoint (std::vector< std::pair< CEntityHandle, CVector3D > > &outEntities, const CVector3D &origin, const CVector3D &dir, bool allowEditorSelectables) const =0
 Return a list of visual entities along with their center point. More...
 
virtual float GetFrameOffset () const =0
 Returns the frame offset from the last Interpolate message. More...
 
virtual void SetDebugOverlay (bool enabled)=0
 Toggle the rendering of debug info. More...
 
- Public Member Functions inherited from IComponent
virtual ~IComponent ()
 
virtual void Init (const CParamNode &paramNode)=0
 
virtual void Deinit ()=0
 
virtual void HandleMessage (const CMessage &msg, bool global)
 
CEntityHandle GetEntityHandle () const
 
void SetEntityHandle (CEntityHandle ent)
 
entity_id_t GetEntityId () const
 
CEntityHandle GetSystemEntity () const
 
const CSimContextGetSimContext () const
 
void SetSimContext (const CSimContext &context)
 
virtual void Serialize (ISerializer &serialize)=0
 
virtual void Deserialize (const CParamNode &paramNode, IDeserializer &deserialize)=0
 
virtual bool NewJSObject (const ScriptInterface &scriptInterface, JS::MutableHandleObject out) const
 Returns false by default, indicating that a scripted wrapper of this IComponent is not supported. More...
 
virtual JS::Value GetJSInstance () const
 
virtual int GetComponentTypeId () const =0
 

Static Public Member Functions

static void ClassInit (CComponentManager &componentManager)
 
static IComponentAllocate (const ScriptInterface &, JS::HandleValue)
 
static void Deallocate (IComponent *cmp)
 
static std::string GetSchema ()
 
- Static Public Member Functions inherited from IComponent
static std::string GetSchema ()
 
static void RegisterComponentType (CComponentManager &mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char *name, const std::string &schema)
 
static void RegisterComponentTypeScriptWrapper (CComponentManager &mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char *name, const std::string &schema)
 
static u8 GetSerializationVersion ()
 

Public Attributes

std::vector< SUnitm_Units
 
std::vector< tag_tm_UnitTagsFree
 
int m_FrameNumber
 
float m_FrameOffset
 
bool m_EnableDebugOverlays
 
std::vector< SOverlaySpherem_DebugSpheres
 

Additional Inherited Members

- Public Types inherited from ICmpUnitRenderer
enum  { ACTOR_ONLY = 1 << 0 , VISIBLE_IN_ATLAS_ONLY = 1 << 1 }
 
- Public Types inherited from IComponent
using AllocFunc = IComponent *(*)(const ScriptInterface &scriptInterface, JS::HandleValue ctor)
 
using DeallocFunc = void(*)(IComponent *)
 

Detailed Description

Efficiently(ish) renders all the units in the world.

The class maintains a list of all units that currently exist, and the data needed for frustum-culling them. To minimise the amount of work done per frame (despite a unit's interpolated position changing every frame), the culling data is only updated once per turn: we store the position at the start of the turn, and the position at the end of the turn, and assume the unit might be anywhere between those two points (linearly).

(Note this is a slightly invalid assumption: units don't always move linearly, since their interpolated position depends on terrain and water. But over a single turn it's probably going to be a good enough approximation, and will only break for units that both start and end the turn off-screen.)

We want to ignore rotation entirely, since it's a complex function of interpolated position and terrain. So we store a bounding sphere, which is rotation-independent, instead of a bounding box.

Member Function Documentation

◆ AddUnit()

tag_t CCmpUnitRenderer::AddUnit ( CEntityHandle  entity,
CUnit actor,
const CBoundingSphere boundsApprox,
int  flags 
)
inlineoverridevirtual

Implements ICmpUnitRenderer.

◆ Allocate()

static IComponent * CCmpUnitRenderer::Allocate ( const ScriptInterface ,
JS::HandleValue   
)
inlinestatic

◆ ClassInit()

static void CCmpUnitRenderer::ClassInit ( CComponentManager componentManager)
inlinestatic

◆ Deallocate()

static void CCmpUnitRenderer::Deallocate ( IComponent cmp)
inlinestatic

◆ Deinit()

void CCmpUnitRenderer::Deinit ( )
inlineoverridevirtual

Implements IComponent.

◆ Deserialize()

void CCmpUnitRenderer::Deserialize ( const CParamNode paramNode,
IDeserializer deserialize 
)
inlineoverridevirtual

Implements IComponent.

◆ GetComponentTypeId()

int CCmpUnitRenderer::GetComponentTypeId ( ) const
inlineoverridevirtual

Implements IComponent.

◆ GetFrameOffset()

float CCmpUnitRenderer::GetFrameOffset ( ) const
inlineoverridevirtual

Returns the frame offset from the last Interpolate message.

Implements ICmpUnitRenderer.

◆ GetSchema()

static std::string CCmpUnitRenderer::GetSchema ( )
inlinestatic

◆ HandleMessage()

void CCmpUnitRenderer::HandleMessage ( const CMessage msg,
bool  global 
)
inlineoverridevirtual

Reimplemented from IComponent.

◆ Init()

void CCmpUnitRenderer::Init ( const CParamNode paramNode)
inlineoverridevirtual

Implements IComponent.

◆ Interpolate()

void CCmpUnitRenderer::Interpolate ( float  frameTime,
float  frameOffset 
)

◆ LookupUnit()

SUnit * CCmpUnitRenderer::LookupUnit ( tag_t  tag)
inline

◆ PickAllEntitiesAtPoint()

void CCmpUnitRenderer::PickAllEntitiesAtPoint ( std::vector< std::pair< CEntityHandle, CVector3D > > &  outEntities,
const CVector3D origin,
const CVector3D dir,
bool  allowEditorSelectables 
) const
inlineoverridevirtual

Return a list of visual entities along with their center point.

Visual means they have an associated actor and a visual component, but they could still be hiden in the fog of war for a specific player, for example. NOTE: It's generally faster to do a lot of ray intersection tests than querying a lot of entities for component interfaces and doing these types of tests first.

Implements ICmpUnitRenderer.

◆ RecomputeSweptBounds()

void CCmpUnitRenderer::RecomputeSweptBounds ( SUnit unit)
inline

◆ RemoveUnit()

void CCmpUnitRenderer::RemoveUnit ( tag_t  tag)
inlineoverridevirtual

Implements ICmpUnitRenderer.

◆ RenderSubmit()

void CCmpUnitRenderer::RenderSubmit ( SceneCollector collector,
const CFrustum frustum,
bool  culling 
)

◆ Serialize()

void CCmpUnitRenderer::Serialize ( ISerializer serialize)
inlineoverridevirtual

Implements IComponent.

◆ SetDebugOverlay()

void CCmpUnitRenderer::SetDebugOverlay ( bool  enabled)
inlineoverridevirtual

Toggle the rendering of debug info.

Implements ICmpUnitRenderer.

◆ TurnStart()

void CCmpUnitRenderer::TurnStart ( )

◆ UpdateUnit()

void CCmpUnitRenderer::UpdateUnit ( tag_t  tag,
CUnit actor,
const CBoundingSphere boundsApprox 
)
inlineoverridevirtual

Implements ICmpUnitRenderer.

◆ UpdateUnitPos()

void CCmpUnitRenderer::UpdateUnitPos ( tag_t  tag,
bool  inWorld,
const CVector3D pos0,
const CVector3D pos1 
)
inlineoverridevirtual

Implements ICmpUnitRenderer.

◆ UpdateVisibility()

void CCmpUnitRenderer::UpdateVisibility ( SUnit unit) const

Member Data Documentation

◆ m_DebugSpheres

std::vector<SOverlaySphere> CCmpUnitRenderer::m_DebugSpheres

◆ m_EnableDebugOverlays

bool CCmpUnitRenderer::m_EnableDebugOverlays

◆ m_FrameNumber

int CCmpUnitRenderer::m_FrameNumber

◆ m_FrameOffset

float CCmpUnitRenderer::m_FrameOffset

◆ m_Units

std::vector<SUnit> CCmpUnitRenderer::m_Units

◆ m_UnitTagsFree

std::vector<tag_t> CCmpUnitRenderer::m_UnitTagsFree

The documentation for this class was generated from the following file: