Pyrogenesis  trunk
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
CCmpUnitRenderer Class Reference

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

Inheritance diagram for CCmpUnitRenderer:
Inheritance graph
[legend]
Collaboration diagram for CCmpUnitRenderer:
Collaboration graph
[legend]

Classes

struct  SUnit
 

Public Member Functions

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

Static Public Member Functions

static void ClassInit (CComponentManager &componentManager)
 
static IComponentAllocate (ScriptInterface &, JS::HandleValue)
 
static void Deallocate (IComponent *cmp)
 
static std::string GetSchema ()
 
- Static Public Member Functions inherited from IComponent
static std::string GetSchema ()
 
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 }
 

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

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

Implements ICmpUnitRenderer.

static IComponent* CCmpUnitRenderer::Allocate ( ScriptInterface ,
JS::HandleValue   
)
inlinestatic
static void CCmpUnitRenderer::ClassInit ( CComponentManager componentManager)
inlinestatic
static void CCmpUnitRenderer::Deallocate ( IComponent cmp)
inlinestatic
virtual void CCmpUnitRenderer::Deinit ( )
inlinevirtual

Implements IComponent.

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

Implements IComponent.

virtual int CCmpUnitRenderer::GetComponentTypeId ( ) const
inlinevirtual

Implements IComponent.

virtual float CCmpUnitRenderer::GetFrameOffset ( ) const
inlinevirtual

Returns the frame offset from the last Interpolate message.

Implements ICmpUnitRenderer.

static std::string CCmpUnitRenderer::GetSchema ( )
inlinestatic
virtual void CCmpUnitRenderer::HandleMessage ( const CMessage msg,
bool  global 
)
inlinevirtual

Reimplemented from IComponent.

virtual void CCmpUnitRenderer::Init ( const CParamNode paramNode)
inlinevirtual

Implements IComponent.

void CCmpUnitRenderer::Interpolate ( float  frameTime,
float  frameOffset 
)
SUnit* CCmpUnitRenderer::LookupUnit ( tag_t  tag)
inline
virtual void CCmpUnitRenderer::PickAllEntitiesAtPoint ( std::vector< std::pair< CEntityHandle, CVector3D > > &  outEntities,
const CVector3D origin,
const CVector3D dir,
bool  allowEditorSelectables 
) const
inlinevirtual

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.

void CCmpUnitRenderer::RecomputeSweptBounds ( SUnit unit)
inline
virtual void CCmpUnitRenderer::RemoveUnit ( tag_t  tag)
inlinevirtual

Implements ICmpUnitRenderer.

void CCmpUnitRenderer::RenderSubmit ( SceneCollector collector,
const CFrustum frustum,
bool  culling 
)
virtual void CCmpUnitRenderer::Serialize ( ISerializer serialize)
inlinevirtual

Implements IComponent.

virtual void CCmpUnitRenderer::SetDebugOverlay ( bool  enabled)
inlinevirtual

Toggle the rendering of debug info.

Implements ICmpUnitRenderer.

void CCmpUnitRenderer::TurnStart ( )
virtual void CCmpUnitRenderer::UpdateUnit ( tag_t  tag,
CUnit actor,
const CBoundingSphere boundsApprox 
)
inlinevirtual

Implements ICmpUnitRenderer.

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

Implements ICmpUnitRenderer.

void CCmpUnitRenderer::UpdateVisibility ( SUnit unit) const

Member Data Documentation

std::vector<SOverlaySphere> CCmpUnitRenderer::m_DebugSpheres
bool CCmpUnitRenderer::m_EnableDebugOverlays
int CCmpUnitRenderer::m_FrameNumber
float CCmpUnitRenderer::m_FrameOffset
std::vector<SUnit> CCmpUnitRenderer::m_Units
std::vector<tag_t> CCmpUnitRenderer::m_UnitTagsFree

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