18 #include "precompiled.h"
48 #include "tools/atlas/GameInterface/GameLoop.h"
99 "<a:help>Display the unit using the engine's actor system.</a:help>"
101 "<Actor>units/hellenes/infantry_spearman_b.xml</Actor>"
104 "<Actor>structures/hellenes/barracks.xml</Actor>"
105 "<FoundationActor>structures/fndn_4x4.xml</FoundationActor>"
107 "<element name='Actor' a:help='Filename of the actor to be used for this unit'>"
111 "<element name='FoundationActor' a:help='Filename of the actor to be used the foundation while this unit is being constructed'>"
116 "<element name='Foundation' a:help='Used internally; if present, the unit will be rendered as a foundation'>"
121 "<element name='ConstructionPreview' a:help='If present, the unit should have a construction preview'>"
126 "<element name='DisableShadows' a:help='Used internally; if present, shadows will be disabled'>"
130 "<element name='SilhouetteDisplay'>"
131 "<data type='boolean'/>"
133 "<element name='SilhouetteOccluder'>"
134 "<data type='boolean'/>"
137 "<element name='SelectionShape'>"
139 "<element name='Bounds' a:help='Determines the selection box based on the model bounds'>"
142 "<element name='Footprint' a:help='Determines the selection box based on the entity Footprint component'>"
145 "<element name='Box' a:help='Sets the selection shape to a box of specified dimensions'>"
146 "<attribute name='width'>"
147 "<ref name='positiveDecimal' />"
149 "<attribute name='height'>"
150 "<ref name='positiveDecimal' />"
152 "<attribute name='depth'>"
153 "<ref name='positiveDecimal' />"
156 "<element name='Cylinder' a:help='Sets the selection shape to a cylinder of specified dimensions'>"
157 "<attribute name='radius'>"
158 "<ref name='positiveDecimal' />"
160 "<attribute name='height'>"
161 "<ref name='positiveDecimal' />"
167 "<element name='VisibleInAtlasOnly'>"
168 "<data type='boolean'/>"
209 serialize.NumberFixed_Unbounded(
"r",
m_R);
210 serialize.NumberFixed_Unbounded(
"g",
m_G);
211 serialize.NumberFixed_Unbounded(
"b",
m_B);
214 serialize.StringASCII(
"anim name",
m_AnimName, 0, 256);
216 serialize.NumberFixed_Unbounded(
"anim speed",
m_AnimSpeed);
218 serialize.NumberFixed_Unbounded(
"anim desync",
m_AnimDesync);
221 serialize.NumberU32_Unbounded(
"seed",
m_Seed);
394 std::map<std::string, std::string>::const_iterator it =
m_AnimOverride.find(name);
501 void Interpolate(
float frameTime,
float frameOffset);
511 if (GetSimContext().HasUnitManager())
513 std::set<CStr> selections;
514 m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);
522 if (paramNode.GetChild(
"SilhouetteDisplay").ToBool())
525 if (paramNode.GetChild(
"SilhouetteOccluder").ToBool())
535 if (paramNode.GetChild(
"DisableShadows").IsOk())
548 InitSelectionShapeDescriptor(paramNode);
550 m_Unit->SetID(GetEntityId());
561 if (shapeNode.
IsOk())
574 cmpFootprint->
GetShape(fpShape, fpSize0, fpSize1, fpHeight);
576 float size0 = fpSize0.
ToFloat();
577 float size1 = fpSize1.
ToFloat();
592 shapeDescriptor->
m_Size0 = size0;
593 shapeDescriptor->
m_Size1 = size1;
598 LOGERROR(L
"[VisualActor] Cannot apply footprint-based SelectionShape; Footprint component not initialized.");
612 LOGWARNING(L
"[VisualActor] TODO: Cylinder selection shapes are not yet implemented; defaulting to recursive bounding boxes");
617 LOGERROR(L
"[VisualActor] No selection shape specified");
631 std::set<CStr> selections;
677 if (!cmpPosition || !cmpPosition->
IsInWorld())
692 std::map<std::string, std::string>::const_iterator it =
m_AnimOverride.find(name);
716 if (cmpPosition && cmpPosition->
IsInWorld())
754 if (!cmpPosition || !cmpPosition->
IsInWorld())
782 if (floating && cmpTerrain)
784 CVector3D pos = transform.GetTranslation();
786 dy += std::max(0.f, pos.
Y - ground);
An entity initialisation parameter node.
virtual void HandleMessage(const CMessage &msg, bool global)
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
A simple fixed-point number class.
virtual CVector3D GetProjectileLaunchPoint()
Return the exact position where a projectile should be launched from (based on the actor's ammo prop ...
#define REGISTER_COMPONENT_TYPE(cname)
virtual void ResetMoveAnimation(std::string name)
Ensures that the given animation will be used when it normally would be, removing reference to any an...
virtual void Hotload(const VfsPath &name)
Called when an actor file has been modified and reloaded dynamically.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
float m_Size0
Box width if BOX, or radius if CYLINDER.
bool ToBool() const
Parses the content of this node as a boolean ("true" == true, anything else == false) ...
virtual void SetPlayerID(player_id_t id)
std::wstring m_ProjectileModelName
float m_Height
Box height if BOX, cylinder height if CYLINDER.
const std::wstring & ToString() const
Returns the content of this node as a string.
virtual bool IsDebug() const
Returns true if the serializer is being used in debug mode.
static const CBoundingBoxAligned EMPTY
float m_Size1
Box depth if BOX, or radius if CYLINDER.
void DeleteUnit(CUnit *unit)
void SetEntitySelection(const CStr &selection)
void Interpolate(float frameTime, float frameOffset)
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
virtual void SelectAnimation(std::string name, bool once, fixed speed, std::wstring soundgroup)
Start playing the given animation.
Serialization interface; see serialization overview.
std::wstring m_SoundGroup
virtual float GetExactGroundLevel(float x, float z)=0
Add renderable objects to the scene collector.
Sent when terrain (texture or elevation) has been changed.
virtual void SetTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1)=0
Called when terrain has changed in the given inclusive bounds.
virtual const CBoundingBoxOriented & GetSelectionBox()
Returns the world-space selection box of this model.
virtual void SetTransform(const CMatrix3D &transform)
bool IsBoxVisible(const CVector3D &position, const CBoundingBoxAligned &bounds) const
void SetCustomSelectionShape(CustomSelectionShape *descriptor)
Sets a custom selection shape as described by a descriptor.
Provides efficient range-based queries of the game world, and also LOS-based effects (fog of war)...
GameLoopState * g_AtlasGameLoop
virtual bool GetAlwaysVisible()=0
virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating)=0
Get the current interpolated transform matrix, for rendering.
CModelAbstract & GetModel() const
#define MODELFLAG_IGNORE_LOS
virtual bool IsInWorld()=0
Returns true if the entity currently exists at a defined position in the world.
virtual void SubmitRecursive(CModelAbstract *model)
Submit a model that is part of the scene, including attached sub-models.
float deltaSimTime
Elapsed simulation time since previous interpolate, in seconds.
virtual ELosVisibility GetLosVisibility(CEntityHandle ent, player_id_t player, bool forceRetainInFog=false)=0
Returns the visibility status of the given entity, with respect to the given player.
virtual bool HasConstructionPreview()
Returns true if this entity should have a construction preview.
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
This interface accepts renderable objects.
Describes a custom selection shape to be used for a model's selection box instead of the default recu...
virtual void Serialize(ISerializer &serialize)
CEntityHandle GetEntityHandle() const
fixed ToFixed() const
Parses the content of this node as a fixed-point number.
void RenderSubmit(SceneCollector &collector, const CFrustum &frustum, bool culling)
bool m_PreviouslyRendered
Whether the visual actor has been rendered at least once.
virtual void SetShadingColour(fixed r, fixed g, fixed b, fixed a)
Set the shading colour that will be modulated with the model's textures.
entity_id_t GetEntityId() const
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
virtual int GetType() const =0
virtual void ReplaceMoveAnimation(std::string name, std::string replace)
Replaces a specified animation with another.
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
Final update phase, after all other updates.
virtual CUnit * GetUnit()
Returns the underlying unit of this visual actor.
static std::string GetSchema()
virtual void SetUnitEntitySelection(const CStr &selection)
Sets the specified entity selection on the underlying unit.
virtual void SelectMovementAnimation(fixed runThreshold)
Start playing the walk/run animations, scaled to the unit's movement speed.
static const CBoundingBoxOriented EMPTY
float ToFloat() const
Convert to float. May be lossy - float can't represent all values.
virtual std::wstring GetProjectileActor()
Return the filename of the actor to be used for projectiles from this unit, or the empty string if no...
virtual void SetVariable(std::string name, float value)
Set an arbitrarily-named variable that the model may use to alter its appearance (e.g.
void SerializeCommon(S &serialize)
struct CObjectBase::@7 m_Properties
virtual player_id_t GetOwner()=0
float offset
Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns...
static void ClassInit(CComponentManager &componentManager)
void SetAnimationState(const CStr &name, bool once, float speed, float desync, const CStrW &actionSound)
Start playing an animation.
void InitModel(const CParamNode ¶mNode)
Helper function shared by component init and actor reloading.
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
bool m_VisibleInAtlasOnly
const CSimContext & GetSimContext() const
void SubscribeGloballyToMessageType(MessageTypeId mtid)
Subscribe the current component type to all messages of the given message type.
virtual void SetActorSeed(u32 seed)
Set actor seed for random variations and reload model.
CVector3D m_HalfSizes
Half the sizes of the box in each dimension (u,v,w).
A simplified syntax for accessing entity components.
virtual CVector3D GetPosition()
Get the world-space position of the base point of the object's visual representation.
fixed m_AnimSyncRepeatTime
void String(const char *name, const std::wstring &value, uint32_t minlength, uint32_t maxlength)
Serialize a Unicode string.
const CObjectEntry & GetObject() const
virtual player_id_t GetPlayerID() const
virtual void SetEntityVariable(const std::string &name, float value)
Called when the entity tries to set some variable to affect the display of this model and/or its chil...
CEntityHandle GetSystemEntity() const
static CFixed FromInt(int n)
#define MODELFLAG_SILHOUETTE_DISPLAY
void SetAnimationSyncRepeat(float repeatTime)
Adjust the speed of the current animation, so that Update(repeatTime) will do a complete animation lo...
CModelAbstract * FindFirstAmmoProp()
Find the first prop used for ammo, by this model or its own props.
virtual void SetConstructionProgress(fixed progress)
Set construction progress of the model, this affects the rendered position of the model...
void Update(fixed turnLength)
Abstract base class for graphical objects that are used by units, or as props attached to other CMode...
bool IsZero() const
Returns true if the number is precisely 0.
CUnitManager & GetUnitManager() const
SceneCollector & collector
virtual fixed GetCurrentSpeed()=0
Get the current movement speed.
virtual void SetVisibility(bool visible)=0
Enables or disables rendering of an entity's selectable.
virtual CModel * ToCModel()
Dynamic cast.
CUnit * CreateUnit(const CStrW &actorName, uint32_t seed, const std::set< CStr8 > &selections)
const CMatrix3D & GetTransform() const
virtual const CParamNode * LoadLatestTemplate(entity_id_t ent)=0
Returns the template most recently specified for the entity 'ent'.
virtual void SetShadingColor(const CColor &colour)
virtual CColor GetShadingColor() const
CUnitAnimation * GetAnimation()
bool m_ConstructionPreview
void InitSelectionShapeDescriptor(const CParamNode ¶mNode)
Helper method; initializes the model selection shape descriptor from XML. Factored out for readabilit...
virtual std::wstring GetActorShortName()
Return the short name of the actor that's being displayed, or the empty string on error...
Prepare for rendering a new frame (set up model positions etc).
virtual const CBoundingBoxAligned GetWorldBoundsRec()
Returns world space bounds of this object and all child objects.
CVector3D GetTranslation() const
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)
#define MODELFLAG_SILHOUETTE_OCCLUDER
const CBoundingBoxAligned & GetWorldBounds()
Returns the world-space axis-aligned bounds of this object.
EType m_Type
Type of shape.
virtual CBoundingBoxOriented GetSelectionBox()
Get the oriented world-space bounding box of the object's visual representation, clipped at the Y=0 p...
fixed m_ConstructionProgress
void SetAnimationSyncOffset(float actionTime)
Adjust the offset of the current animation, so that Update(actionTime) will advance it to the 'action...
void UpdateModel(float frameTime)
Update the model's animation.
The selection shape is determined by an oriented box of custom, user-specified size.
virtual u32 GetActorSeed()
Get actor seed used for random variations.
virtual CModelDecal * ToCModelDecal()
Dynamic cast.
std::map< std::string, std::string > m_AnimOverride
virtual void SetAnimationSyncRepeat(fixed repeattime)
Adjust the speed of the current animation, so it can match simulation events.
virtual void SetAnimationSyncOffset(fixed actiontime)
Adjust the offset of the current animation, so it can match simulation events.
virtual void Init(const CParamNode ¶mNode)
ICmpRangeManager::ELosVisibility m_Visibility
virtual void ValidatePosition()=0
Ensure that both the transformation and the bone matrices are correct for this model and all its prop...
virtual CBoundingBoxAligned GetBounds()
Get the world-space bounding box of the object's visual representation.
Deserialization interface; see serialization overview.
The visual representation of an entity (typically an actor).
void AddFlagsRec(int flags)