mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 13:43:41 +00:00
Compare commits
2 Commits
fcb79bc2a3
...
63644b4759
| Author | SHA1 | Date | |
|---|---|---|---|
| 63644b4759 | |||
| 75189645d0 |
2
Doxyfile
2
Doxyfile
@ -530,7 +530,7 @@ EXTRACT_ALL = NO
|
|||||||
# be included in the documentation.
|
# be included in the documentation.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
EXTRACT_PRIVATE = YES
|
EXTRACT_PRIVATE = NO
|
||||||
|
|
||||||
# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual
|
# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual
|
||||||
# methods of a class will be included in the documentation.
|
# methods of a class will be included in the documentation.
|
||||||
|
|||||||
@ -16,36 +16,61 @@ using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
|
|||||||
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
||||||
using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
using ComponentArray = std::array<Component*, MAX_COMPONENTS>;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \brief Main class for any object in game, stores associations, labeling and components
|
||||||
|
* \details The entity class is the primary class each object in the game needs to use. Add components to assign functionality.
|
||||||
|
*
|
||||||
|
* \todo More detailed description
|
||||||
|
* \todo Some functions in entity class are only supposed to be called in specific context, which might be valid uses for `friend` keyword. Example: Entity() should only be called from Manager::addEntity(). Verify each functions intended use/scope.
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Entity
|
class Entity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*! TODO */
|
/*!
|
||||||
|
* \brief Used for rendering order (last is highest) or retrieving entities of group
|
||||||
|
* \todo Label used in singular entity shouldn't use plural
|
||||||
|
* \todo HEARTS are rendered above POWERUPS, missleading order
|
||||||
|
* \todo PROJECTILE are rendered above POWERUPS, missleading order
|
||||||
|
* \todo Generalize HEARTS as UI or similar
|
||||||
|
*/
|
||||||
enum class GroupLabel
|
enum class GroupLabel
|
||||||
{
|
{
|
||||||
MAPTILES,
|
MAPTILES, //!< Entity using TileComponent
|
||||||
PLAYERS,
|
PLAYERS, //!< Primary entity in player controll
|
||||||
ENEMIES,
|
ENEMIES, //!< \deprecated All players now grouped as Entity::PLAYERS
|
||||||
COLLIDERS,
|
COLLIDERS, //!< Fixed collider entity, e.g. a wall
|
||||||
PROJECTILE,
|
PROJECTILE, //!< \todo Document
|
||||||
HEARTS,
|
HEARTS, //!< \todo Document
|
||||||
POWERUPS
|
POWERUPS //!< \todo Document
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Allows grouping entities by team association for hits, win conditions, etc.
|
||||||
|
*/
|
||||||
enum class TeamLabel
|
enum class TeamLabel
|
||||||
{
|
{
|
||||||
NONE, //!< No team
|
NONE, //!< No team, should be skipped in any checks
|
||||||
BLUE, //!< Team blue
|
BLUE, //!< Team blue
|
||||||
RED //!< Team red
|
RED //!< Team red
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \todo Document
|
||||||
|
*/
|
||||||
explicit Entity(Manager& mManager) :
|
explicit Entity(Manager& mManager) :
|
||||||
manager(mManager) { };
|
manager(mManager) { };
|
||||||
|
|
||||||
void update() const;
|
void update() const; //!< Call each frame to update all components
|
||||||
|
//! Call after update to render components.
|
||||||
|
//! \sa SpriteComponent::draw()
|
||||||
void draw() const;
|
void draw() const;
|
||||||
|
|
||||||
bool isActive() const { return this->active; }
|
bool isActive() const { return this->active; } //!< \sa destroy()
|
||||||
|
//! Mark for destruction for Manager::refresh() and disables collision
|
||||||
|
//! \sa ColliderComponent
|
||||||
void destroy() {
|
void destroy() {
|
||||||
this->active = false;
|
this->active = false;
|
||||||
if (this->hasComponent<ColliderComponent>()) {
|
if (this->hasComponent<ColliderComponent>()) {
|
||||||
@ -53,22 +78,26 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasGroup(Group mGroup);
|
bool hasGroup(Group mGroup); //!< \sa GroupLabel
|
||||||
void addGroup(Group mGroup);
|
void addGroup(Group mGroup); //!< \sa GroupLabel
|
||||||
void delGroup(Group mGroup);
|
void delGroup(Group mGroup); //!< \sa GroupLabel
|
||||||
|
//! \returns bitset with true on position GroupLabel if the entity belongs to group
|
||||||
|
//! \sa GroupLabel
|
||||||
std::bitset<MAX_GROUPS> getGroupBitSet();
|
std::bitset<MAX_GROUPS> getGroupBitSet();
|
||||||
|
|
||||||
void setTeam(TeamLabel teamLabel);
|
void setTeam(TeamLabel teamLabel); //!< \sa TeamLabel
|
||||||
/*! TODO */
|
TeamLabel getTeam(); //!< \sa TeamLabel
|
||||||
TeamLabel getTeam();
|
|
||||||
|
|
||||||
|
//! \sa Manager
|
||||||
Manager& getManager() { return manager; };
|
Manager& getManager() { return manager; };
|
||||||
|
|
||||||
template <typename T> bool hasComponent() const
|
template <typename T> bool hasComponent() const //! \sa Component
|
||||||
{
|
{
|
||||||
return componentBitSet[getComponentTypeID<T>()];
|
return componentBitSet[getComponentTypeID<T>()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \brief Adds specified type as component and calls Component::init()
|
||||||
|
//! \param mArgs Constructor arguments of component
|
||||||
template <typename T, typename...TArgs> T& addComponent(TArgs&&...mArgs)
|
template <typename T, typename...TArgs> T& addComponent(TArgs&&...mArgs)
|
||||||
{
|
{
|
||||||
T* c(new T(std::forward<TArgs>(mArgs)...));
|
T* c(new T(std::forward<TArgs>(mArgs)...));
|
||||||
@ -83,7 +112,7 @@ public:
|
|||||||
return *c;
|
return *c;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> T& getComponent() const
|
template <typename T> T& getComponent() const //! \returns Component of type T
|
||||||
{
|
{
|
||||||
auto ptr(componentArray[getComponentTypeID<T>()]);
|
auto ptr(componentArray[getComponentTypeID<T>()]);
|
||||||
return *static_cast<T*>(ptr);
|
return *static_cast<T*>(ptr);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user