Former-commit-id: 1493cf5e743cf96084588a751ff92bfc35732a6d [formerly bc8fceb313fe789262c13eb9714cdc4b5e43bb8b] [formerly 25a7db8fa5e658180231fc8ad7f1b9e15c560771 [formerly d43ffc393e253069feafa3c82d2d12db6c7c48fc]] Former-commit-id: 7368a2e39183cd6611442f786b9c1f124f803e6b [formerly 421f1b00641d63f9c5a069c90b34c377a5a78f46] Former-commit-id: 9aa635cdb8cc8ebafb78c558d263c63fb3f73670
104 lines
2.8 KiB
C++
104 lines
2.8 KiB
C++
// Copyright (C) 2015 Jérôme Leclercq
|
|
// This file is part of the "Nazara Development Kit"
|
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
|
|
#pragma once
|
|
|
|
#ifndef NDK_BASESYSTEM_HPP
|
|
#define NDK_BASESYSTEM_HPP
|
|
|
|
#include <Nazara/Core/Bitset.hpp>
|
|
#include <NDK/Entity.hpp>
|
|
#include <vector>
|
|
|
|
namespace Ndk
|
|
{
|
|
class World;
|
|
|
|
class NDK_API BaseSystem
|
|
{
|
|
friend class Sdk;
|
|
friend Entity;
|
|
friend World;
|
|
|
|
public:
|
|
inline BaseSystem(SystemIndex systemId);
|
|
inline BaseSystem(const BaseSystem&);
|
|
BaseSystem(BaseSystem&&) noexcept = default;
|
|
virtual ~BaseSystem();
|
|
|
|
inline void Enable(bool enable = true);
|
|
|
|
virtual BaseSystem* Clone() const = 0;
|
|
|
|
bool Filters(const Entity* entity) const;
|
|
|
|
inline const std::vector<EntityHandle>& GetEntities() const;
|
|
inline SystemIndex GetIndex() const;
|
|
inline float GetUpdateRate() const;
|
|
inline World& GetWorld() const;
|
|
|
|
inline bool IsEnabled() const;
|
|
|
|
inline bool HasEntity(const Entity* entity) const;
|
|
|
|
inline void SetUpdateRate(float updatePerSecond);
|
|
|
|
inline void Update(float elapsedTime);
|
|
|
|
BaseSystem& operator=(const BaseSystem&) = delete;
|
|
BaseSystem& operator=(BaseSystem&&) noexcept = default;
|
|
|
|
protected:
|
|
template<typename ComponentType> void Excludes();
|
|
template<typename ComponentType1, typename ComponentType2, typename... Rest> void Excludes();
|
|
inline void ExcludesComponent(ComponentIndex index);
|
|
|
|
static SystemIndex GetNextIndex();
|
|
|
|
template<typename ComponentType> void Requires();
|
|
template<typename ComponentType1, typename ComponentType2, typename... Rest> void Requires();
|
|
inline void RequiresComponent(ComponentIndex index);
|
|
|
|
template<typename ComponentType> void RequiresAny();
|
|
template<typename ComponentType1, typename ComponentType2, typename... Rest> void RequiresAny();
|
|
inline void RequiresAnyComponent(ComponentIndex index);
|
|
|
|
virtual void OnUpdate(float elapsedTime) = 0;
|
|
|
|
private:
|
|
inline void AddEntity(Entity* entity);
|
|
|
|
virtual void OnEntityAdded(Entity* entity);
|
|
virtual void OnEntityRemoved(Entity* entity);
|
|
virtual void OnEntityValidation(Entity* entity, bool justAdded);
|
|
|
|
inline void RemoveEntity(Entity* entity);
|
|
|
|
inline void SetWorld(World* world) noexcept;
|
|
|
|
inline void ValidateEntity(Entity* entity, bool justAdded);
|
|
|
|
static inline bool Initialize();
|
|
static inline void Uninitialize();
|
|
|
|
std::vector<EntityHandle> m_entities;
|
|
Nz::Bitset<Nz::UInt64> m_entityBits;
|
|
Nz::Bitset<> m_excludedComponents;
|
|
mutable Nz::Bitset<> m_filterResult;
|
|
Nz::Bitset<> m_requiredAnyComponents;
|
|
Nz::Bitset<> m_requiredComponents;
|
|
SystemIndex m_systemIndex;
|
|
World* m_world;
|
|
bool m_updateEnabled;
|
|
float m_updateCounter;
|
|
float m_updateRate;
|
|
|
|
static SystemIndex s_nextIndex;
|
|
};
|
|
}
|
|
|
|
#include <NDK/BaseSystem.inl>
|
|
|
|
#endif // NDK_BASESYSTEM_HPP
|