Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/ModelAbstract.h
/* Copyright (C) 2011 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | struct CustomSelectionShape | ||||
float m_Size0; ///< Box width if @ref BOX, or radius if @ref CYLINDER | float m_Size0; ///< Box width if @ref BOX, or radius if @ref CYLINDER | ||||
float m_Size1; ///< Box depth if @ref BOX, or radius if @ref CYLINDER | float m_Size1; ///< Box depth if @ref BOX, or radius if @ref CYLINDER | ||||
float m_Height; ///< Box height if @ref BOX, cylinder height if @ref CYLINDER | float m_Height; ///< Box height if @ref BOX, cylinder height if @ref CYLINDER | ||||
}; | }; | ||||
public: | public: | ||||
CModelAbstract() | CModelAbstract() | ||||
: m_Parent(NULL), m_PositionValid(false), m_ShadingColor(1, 1, 1, 1), m_PlayerID(INVALID_PLAYER), | : m_Parent(nullptr), m_PositionValid(false), m_ShadingColor(1, 1, 1, 1), m_PlayerID(INVALID_PLAYER), | ||||
m_SelectionBoxValid(false), m_CustomSelectionShape(NULL) | m_SelectionBoxValid(false), m_CustomSelectionShape(nullptr) | ||||
{ } | { } | ||||
~CModelAbstract() | ~CModelAbstract() | ||||
{ | { | ||||
delete m_CustomSelectionShape; // allocated and set externally by CCmpVisualActor, but our responsibility to clean up | delete m_CustomSelectionShape; // allocated and set externally by CCmpVisualActor, but our responsibility to clean up | ||||
} | } | ||||
virtual CModelAbstract* Clone() const = 0; | virtual CModelAbstract* Clone() const = 0; | ||||
/// Dynamic cast | /// Dynamic cast | ||||
virtual CModel* ToCModel() { return NULL; } | virtual CModel* ToCModel() { return nullptr; } | ||||
/// Dynamic cast | /// Dynamic cast | ||||
virtual CModelDecal* ToCModelDecal() { return NULL; } | virtual CModelDecal* ToCModelDecal() { return nullptr; } | ||||
/// Dynamic cast | /// Dynamic cast | ||||
virtual CModelParticleEmitter* ToCModelParticleEmitter() { return NULL; } | virtual CModelParticleEmitter* ToCModelParticleEmitter() { return nullptr; } | ||||
// (This dynamic casting is a bit ugly, but we won't have many subclasses | // (This dynamic casting is a bit ugly, but we won't have many subclasses | ||||
// and this seems the easiest way to integrate with other code that wants | // and this seems the easiest way to integrate with other code that wants | ||||
// type-specific processing) | // type-specific processing) | ||||
/// Calls SetDirty on this model and all child objects. | /// Calls SetDirty on this model and all child objects. | ||||
virtual void SetDirtyRec(int dirtyflags) = 0; | virtual void SetDirtyRec(int dirtyflags) = 0; | ||||
Show All 9 Lines | public: | ||||
virtual void InvalidateBounds() | virtual void InvalidateBounds() | ||||
{ | { | ||||
m_BoundsValid = false; | m_BoundsValid = false; | ||||
// a call to this method usually means that the model's transform has changed, i.e. it has moved or rotated, so we'll also | // a call to this method usually means that the model's transform has changed, i.e. it has moved or rotated, so we'll also | ||||
// want to update the selection box accordingly regardless of the shape it is built from. | // want to update the selection box accordingly regardless of the shape it is built from. | ||||
m_SelectionBoxValid = false; | m_SelectionBoxValid = false; | ||||
} | } | ||||
/// Sets a custom selection shape as described by a @p descriptor. Argument may be NULL | /// Sets a custom selection shape as described by a @p descriptor. Argument may be nullptr | ||||
/// if you wish to keep the default behaviour of using the recursively-calculated bounding boxes. | /// if you wish to keep the default behaviour of using the recursively-calculated bounding boxes. | ||||
void SetCustomSelectionShape(CustomSelectionShape* descriptor) | void SetCustomSelectionShape(CustomSelectionShape* descriptor) | ||||
{ | { | ||||
if (m_CustomSelectionShape != descriptor) | if (m_CustomSelectionShape != descriptor) | ||||
{ | { | ||||
m_CustomSelectionShape = descriptor; | m_CustomSelectionShape = descriptor; | ||||
m_SelectionBoxValid = false; // update the selection box when it is next requested | m_SelectionBoxValid = false; // update the selection box when it is next requested | ||||
} | } | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
protected: | protected: | ||||
/// Selection box for this model. | /// Selection box for this model. | ||||
CBoundingBoxOriented m_SelectionBox; | CBoundingBoxOriented m_SelectionBox; | ||||
/// Is the current selection box valid? | /// Is the current selection box valid? | ||||
bool m_SelectionBoxValid; | bool m_SelectionBoxValid; | ||||
/// Pointer to a descriptor for a custom-defined selection box shape. If no custom selection box is required, this is NULL | /// Pointer to a descriptor for a custom-defined selection box shape. If no custom selection box is required, this is nullptr | ||||
/// and the standard recursive-bounding-box-based selection box is used. Otherwise, a custom selection box described by this | /// and the standard recursive-bounding-box-based selection box is used. Otherwise, a custom selection box described by this | ||||
/// field will be used. | /// field will be used. | ||||
/// @see SetCustomSelectionShape | /// @see SetCustomSelectionShape | ||||
CustomSelectionShape* m_CustomSelectionShape; | CustomSelectionShape* m_CustomSelectionShape; | ||||
}; | }; | ||||
#endif // INCLUDED_MODELABSTRACT | #endif // INCLUDED_MODELABSTRACT |
Wildfire Games · Phabricator