Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpSelectable.cpp
Show First 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | virtual void SetVisibility(bool visible) | ||||
UpdateMessageSubscriptions(); | UpdateMessageSubscriptions(); | ||||
} | } | ||||
virtual bool IsEditorOnly() const | virtual bool IsEditorOnly() const | ||||
{ | { | ||||
return m_EditorOnly; | return m_EditorOnly; | ||||
} | } | ||||
void RenderSubmit(SceneCollector& collector); | void RenderSubmit(SceneCollector& collector, const CFrustum& frustum, bool culling); | ||||
/** | /** | ||||
* Draw a textured line overlay. The selection overlays for structures are based solely on footprint shape. | * Draw a textured line overlay. The selection overlays for structures are based solely on footprint shape. | ||||
*/ | */ | ||||
void UpdateTexturedLineOverlay(const SOverlayDescriptor* overlayDescriptor, SOverlayTexturedLine& overlay, float frameOffset); | void UpdateTexturedLineOverlay(const SOverlayDescriptor* overlayDescriptor, SOverlayTexturedLine& overlay, float frameOffset); | ||||
/** | /** | ||||
* Called from the interpolation handler; responsible for ensuring the dynamic overlay (provided we're | * Called from the interpolation handler; responsible for ensuring the dynamic overlay (provided we're | ||||
Show All 19 Lines | public: | ||||
*/ | */ | ||||
virtual void UpdateColor(); | virtual void UpdateColor(); | ||||
private: | private: | ||||
SOverlayDescriptor m_OverlayDescriptor; | SOverlayDescriptor m_OverlayDescriptor; | ||||
SOverlayTexturedLine* m_BuildingOverlay; | SOverlayTexturedLine* m_BuildingOverlay; | ||||
SOverlayQuad* m_UnitOverlay; | SOverlayQuad* m_UnitOverlay; | ||||
CBoundingBoxAligned m_UnitBoundingBox; | |||||
SOverlayLine* m_DebugBoundingBoxOverlay; | SOverlayLine* m_DebugBoundingBoxOverlay; | ||||
SOverlayLine* m_DebugSelectionBoxOverlay; | SOverlayLine* m_DebugSelectionBoxOverlay; | ||||
bool m_EnabledInterpolate; | bool m_EnabledInterpolate; | ||||
bool m_EnabledRenderSubmit; | bool m_EnabledRenderSubmit; | ||||
// Whether the selectable will be rendered. | // Whether the selectable will be rendered. | ||||
bool m_Visible; | bool m_Visible; | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global)) | ||||
case MT_WaterChanged: | case MT_WaterChanged: | ||||
InvalidateStaticOverlay(); | InvalidateStaticOverlay(); | ||||
break; | break; | ||||
case MT_RenderSubmit: | case MT_RenderSubmit: | ||||
{ | { | ||||
PROFILE("Selectable::RenderSubmit"); | PROFILE("Selectable::RenderSubmit"); | ||||
const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg); | const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg); | ||||
RenderSubmit(msgData.collector); | RenderSubmit(msgData.collector, msgData.frustum, msgData.culling); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void CCmpSelectable::UpdateColor() | void CCmpSelectable::UpdateColor() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | void CCmpSelectable::UpdateDynamicOverlay(float frameOffset) | ||||
{ | { | ||||
halfSizeX /= 2.0f; | halfSizeX /= 2.0f; | ||||
halfSizeZ /= 2.0f; | halfSizeZ /= 2.0f; | ||||
} | } | ||||
std::vector<CVector2D> points; | std::vector<CVector2D> points; | ||||
points.push_back(CVector2D(position + unitX *(-halfSizeX) + unitZ * halfSizeZ)); // top left | points.push_back(CVector2D(position + unitX *(-halfSizeX) + unitZ * halfSizeZ)); // top left | ||||
points.push_back(CVector2D(position + unitX *(-halfSizeX) + unitZ *(-halfSizeZ))); // bottom left | points.push_back(CVector2D(position + unitX *(-halfSizeX) + unitZ *(-halfSizeZ))); // bottom left | ||||
points.push_back(CVector2D(position + unitX * halfSizeX + unitZ *(-halfSizeZ))); // bottom right | points.push_back(CVector2D(position + unitX * halfSizeX + unitZ *(-halfSizeZ))); // bottom right | ||||
Stan: Space between operators. | |||||
points.push_back(CVector2D(position + unitX * halfSizeX + unitZ * halfSizeZ)); // top right | points.push_back(CVector2D(position + unitX * halfSizeX + unitZ * halfSizeZ)); // top right | ||||
m_UnitBoundingBox = CBoundingBoxAligned(); | |||||
for (int i=0; i < 4; i++) | for (int i=0; i < 4; i++) | ||||
Not Done Inline Actionsspace between operators ++i maybe 4 could be extracted from somewhere. Stan: space between operators ++i maybe 4 could be extracted from somewhere. | |||||
{ | { | ||||
float quadY = std::max( | float quadY = std::max( | ||||
terrain->GetExactGroundLevel(points[i].X, points[i].Y), | terrain->GetExactGroundLevel(points[i].X, points[i].Y), | ||||
cmpWaterManager->GetExactWaterLevel(points[i].X, points[i].Y) | cmpWaterManager->GetExactWaterLevel(points[i].X, points[i].Y) | ||||
); | ); | ||||
m_UnitOverlay->m_Corners[i] = CVector3D(points[i].X, quadY, points[i].Y); | m_UnitOverlay->m_Corners[i] = CVector3D(points[i].X, quadY, points[i].Y); | ||||
m_UnitBoundingBox += m_UnitOverlay->m_Corners[i]; | |||||
} | } | ||||
} | } | ||||
void CCmpSelectable::RenderSubmit(SceneCollector& collector) | void CCmpSelectable::RenderSubmit(SceneCollector& collector, const CFrustum& frustum, bool culling) | ||||
{ | { | ||||
// don't render selection overlay if it's not gonna be visible | // don't render selection overlay if it's not gonna be visible | ||||
if (!ICmpSelectable::m_OverrideVisible) | if (!ICmpSelectable::m_OverrideVisible) | ||||
return; | return; | ||||
if (m_Visible && m_Color.a > 0) | if (m_Visible && m_Color.a > 0) | ||||
{ | { | ||||
if (!m_Cached) | if (!m_Cached) | ||||
Show All 10 Lines | switch (m_OverlayDescriptor.m_Type) | ||||
{ | { | ||||
// Static overlays are allocated once and not updated until they are explicitly deleted again | // Static overlays are allocated once and not updated until they are explicitly deleted again | ||||
// (see InvalidateStaticOverlay). Since they are expected to change rarely (if ever) during | // (see InvalidateStaticOverlay). Since they are expected to change rarely (if ever) during | ||||
// normal gameplay, this saves us doing all the work below on each frame. | // normal gameplay, this saves us doing all the work below on each frame. | ||||
m_BuildingOverlay = new SOverlayTexturedLine; | m_BuildingOverlay = new SOverlayTexturedLine; | ||||
UpdateTexturedLineOverlay(&m_OverlayDescriptor, *m_BuildingOverlay, 0); | UpdateTexturedLineOverlay(&m_OverlayDescriptor, *m_BuildingOverlay, 0); | ||||
} | } | ||||
m_BuildingOverlay->m_Color = m_Color; // done separately so alpha changes don't require a full update call | m_BuildingOverlay->m_Color = m_Color; // done separately so alpha changes don't require a full update call | ||||
if (culling && !m_BuildingOverlay->IsVisibleInFrustum(frustum)) | |||||
break; | |||||
collector.Submit(m_BuildingOverlay); | collector.Submit(m_BuildingOverlay); | ||||
} | } | ||||
break; | break; | ||||
case DYNAMIC_QUAD: | case DYNAMIC_QUAD: | ||||
{ | { | ||||
if (culling && !frustum.IsBoxVisible(m_UnitBoundingBox)) | |||||
break; | |||||
if (m_UnitOverlay) | if (m_UnitOverlay) | ||||
collector.Submit(m_UnitOverlay); | collector.Submit(m_UnitOverlay); | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
Show All 36 Lines |
Wildfire Games · Phabricator
Space between operators.