18 #include "precompiled.h"
86 "<a:help>Allows this entity to be selected by the player.</a:help>"
89 "<element name='EditorOnly' a:help='If this element is present, the entity is only selectable in Atlas'>"
93 "<element name='Overlay' a:help='Specifies the type of overlay to be displayed when this entity is selected'>"
95 "<element name='AlwaysVisible' a:help='If this element is present, the selection overlay will always be visible (with transparency and desaturation)'>"
100 "<element name='Texture' a:help='Displays a texture underneath the entity.'>"
101 "<element name='MainTexture' a:help='Texture to display underneath the entity. Filepath relative to art/textures/selection/.'><text/></element>"
102 "<element name='MainTextureMask' a:help='Mask texture that controls where to apply player color. Filepath relative to art/textures/selection/.'><text/></element>"
104 "<element name='Outline' a:help='Traces the outline of the entity with a line texture.'>"
105 "<element name='LineTexture' a:help='Texture to apply to the line. Filepath relative to art/textures/selection/.'><text/></element>"
106 "<element name='LineTextureMask' a:help='Texture that controls where to apply player color. Filepath relative to art/textures/selection/.'><text/></element>"
107 "<element name='LineThickness' a:help='Thickness of the line, in world units.'><ref name='positiveDecimal'/></element>"
130 const char* textureBasePath =
"art/textures/selection/";
134 if (textureNode.
IsOk())
141 else if (outlineNode.
IsOk())
285 m_FadeDeltaAlpha = 0.f;
310 if (!cmpPlayerManager)
319 CColor color = cmpPlayer->GetColour();
357 if (!cmpFootprint || !cmpPosition || !cmpPosition->
IsInWorld())
369 entity_pos_t fpSize0_fixed, fpSize1_fixed, fpHeight_fixed;
370 cmpFootprint->
GetShape(fpShape, fpSize0_fixed, fpSize1_fixed, fpHeight_fixed);
373 texturePropsBase.
SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
374 texturePropsBase.SetMaxAnisotropy(4.f);
377 texturePropsMask.
SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
378 texturePropsMask.SetMaxAnisotropy(4.f);
396 float s = sinf(-rotation.
Y.
ToFloat());
397 float c = cosf(-rotation.
Y.
ToFloat());
405 std::vector<CVector2D> points;
406 points.push_back(
CVector2D(origin + unitX * halfSizeX + unitZ *(-halfSizeZ)));
407 points.push_back(
CVector2D(origin + unitX *(-halfSizeX) + unitZ *(-halfSizeZ)));
408 points.push_back(
CVector2D(origin + unitX *(-halfSizeX) + unitZ * halfSizeZ));
409 points.push_back(
CVector2D(origin + unitX * halfSizeX + unitZ * halfSizeZ));
424 for (
unsigned i = 0; i < numSteps; i++)
426 float angle = i * stepAngle;
427 float px = origin.X + radius * sinf(angle);
428 float pz = origin.Y + radius * cosf(angle);
454 if (!cmpFootprint || !cmpPosition || !cmpPosition->
IsInWorld())
463 ENSURE(cmpWaterManager && cmpTerrain);
469 entity_pos_t fpSize0_fixed, fpSize1_fixed, fpHeight_fixed;
470 cmpFootprint->
GetShape(fpShape, fpSize0_fixed, fpSize1_fixed, fpHeight_fixed);
480 texturePropsBase.
SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
481 texturePropsBase.SetMaxAnisotropy(4.f);
484 texturePropsMask.
SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE);
485 texturePropsMask.SetMaxAnisotropy(4.f);
496 float s = sinf(-rotY);
497 float c = cosf(-rotY);
501 float halfSizeX = fpSize0_fixed.
ToFloat();
502 float halfSizeZ = fpSize1_fixed.
ToFloat();
509 std::vector<CVector2D> points;
510 points.push_back(
CVector2D(position + unitX *(-halfSizeX) + unitZ * halfSizeZ));
511 points.push_back(
CVector2D(position + unitX *(-halfSizeX) + unitZ *(-halfSizeZ)));
512 points.push_back(
CVector2D(position + unitX * halfSizeX + unitZ *(-halfSizeZ)));
513 points.push_back(
CVector2D(position + unitX * halfSizeX + unitZ * halfSizeZ));
515 for (
int i=0; i < 4; i++)
517 float quadY = std::max(
544 if (!cmpPlayerManager)
551 color = cmpPlayer->GetColour();
An entity initialisation parameter node.
static void ClassInit(CComponentManager &componentManager)
virtual void SetSelectionHighlightAlpha(float alpha)
Set the alpha of the selection highlight.
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
static const double FADE_DURATION
Total duration of a single fade, in seconds.
A simple fixed-point number class.
static std::string GetSchema()
#define REGISTER_COMPONENT_TYPE(cname)
CTexturePtr m_TextureBase
A single textured quad overlay, intended for entities that move around much, like units (e...
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
virtual void Serialize(ISerializer &serialize)
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
static bool ms_EnableDebugOverlays
const std::string ToUTF8() const
Returns the content of this node as an 8-bit string.
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
Serialization interface; see serialization overview.
Represents the filename and GL parameters of a texture, for passing to CTextureManager::CreateTexture...
Add renderable objects to the scene collector.
void PushCoords(const float x, const float z)
virtual CFixedVector3D GetRotation()=0
Returns the current rotation (relative to the upwards axis), as Euler angles with X=pitch...
bool m_AlwaysVisible
Should this line be rendered fully visible at all times, even under the SoD?
float GetExactGroundLevel(float x, float z) const
void UpdateDynamicOverlay(float frameOffset)
Called from the interpolation handler; responsible for ensuring the dynamic overlay (provided we're u...
virtual bool IsEditorOnly()
Returns true if the entity is only selectable in Atlas editor, e.g.
void RenderSubmit(SceneCollector &collector)
virtual void SetSelectionHighlight(CColor color, bool selected)
Set the selection highlight state.
bool m_Selected
Whether the parent entity is selected (caches GUI's selection state).
virtual CBoundingBoxOriented GetSelectionBox()=0
Get the oriented world-space bounding box of the object's visual representation, clipped at the Y=0 p...
virtual bool IsInWorld()=0
Returns true if the entity currently exists at a defined position in the world.
SOverlayQuad * m_UnitOverlay
static float QuartOut(float t, const float b, const float c, const float d)
void UpdateStaticOverlay()
Called from RenderSubmit if using a static outline; responsible for ensuring that the static overlay ...
bool m_Cached
Whether the selectable's player colour has been cached for rendering.
float m_FadeProgress
Linear time progress of the fade, between 0 and m_FadeDuration.
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
float deltaRealTime
Elapsed real time since previous interpolate, in seconds.
This interface accepts renderable objects.
CEntityHandle GetEntityHandle() const
void InvalidateStaticOverlay()
Explicitly invalidates the static overlay.
const char * c_str() const
Returns null-terminated string.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
virtual int GetType() const =0
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...
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain...
bool m_Closed
Should this line be treated as a closed loop? If set, any end cap settings are ignored.
float ToFloat() const
Parses the content of this node as a floating-point number.
void SubdividePoints(std::vector< CVector2D > &points, float maxSegmentLength, bool closed)
Subdivides a list of points into segments of maximum length maxSegmentLength that are of equal size b...
void AngularStepFromChordLen(const float maxChordLength, const float radius, float &out_stepAngle, unsigned &out_numSteps)
Computes angular step parameters out_stepAngle and out_numSteps, given a maxChordLength on a circle o...
virtual entity_id_t GetPlayerByID(int32_t id)=0
float ToFloat() const
Convert to float. May be lossy - float can't represent all values.
virtual CFixedVector2D GetPosition2D()=0
Returns the current x,z position (no interpolation).
#define SAFE_DELETE(p)
delete memory ensuing from new and set the pointer to zero (thus making double-frees safe / a no-op) ...
virtual player_id_t GetOwner()=0
CColor m_Color
Color to apply to the line texture, where indicated by the mask.
float offset
Range [0, 1] (inclusive); fractional time of current frame between previous/next simulation turns...
virtual float GetExactWaterLevel(float x, float z)=0
Get the current water level at the given point.
static const float RGB_DESATURATION
SOverlayLine * m_DebugSelectionBoxOverlay
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
static const float MIN_ALPHA_ALWAYS_VISIBLE
const CSimContext & GetSimContext() const
static bool IsInitialised()
CTexturePtr m_TextureMask
virtual void Init(const CParamNode ¶mNode)
A simplified syntax for accessing entity components.
virtual void GetInterpolatedPosition2D(float frameOffset, float &x, float &z, float &rotY)=0
Get the current interpolated 2D position and orientation, for rendering.
virtual CTerrain * GetCTerrain()=0
CEntityHandle GetSystemEntity() const
CStrIntern m_QuadTextureMask
Helper functions related to rendering.
A more complex textured line overlay, composed of several textured line segments. ...
Rectangular single-quad terrain overlay, in world space coordinates.
CColor m_Color
Current selection overlay color. Alpha component is subject to fading.
virtual void SetVisibility(bool visible)
Enables or disables rendering of an entity's selectable.
float m_AlphaMin
Minimum value for current selection overlay alpha.
SceneCollector & collector
CStrIntern m_LineTextureMask
virtual CBoundingBoxAligned GetBounds()=0
Get the world-space bounding box of the object's visual representation.
SOverlayDescriptor m_OverlayDescriptor
virtual void HandleMessage(const CMessage &msg, bool global)
SOverlayLine * m_DebugBoundingBoxOverlay
const CSimContext * m_SimContext
Simulation context applicable for this overlay line; used to obtain terrain information during automa...
Prepare for rendering a new frame (set up model positions etc).
float m_FadeBaselineAlpha
Baseline alpha value to start fading from. Constant during a single fade.
float m_Thickness
Half-width of the line, in world-space units.
void ConstructBoxOutline(const CBoundingBoxOriented &box, SOverlayLine &overlayLine)
Constructs a solid outline of an arbitrarily-aligned bounding box.
float m_FadeDeltaAlpha
Delta between target and baseline alpha. Constant during a single fade. Can be positive or negative...
static const float MIN_ALPHA_UNSELECTED
void SetWrap(GLint wrap)
Set wrapping mode (typically GL_REPEAT, GL_CLAMP_TO_EDGE, etc).
virtual void Submit(CPatch *patch)=0
Submit a terrain patch that is part of the scene.
static const player_id_t INVALID_PLAYER
SOverlayTexturedLine * m_BuildingOverlay
Deserialization interface; see serialization overview.
CTexturePtr m_TextureMask