Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //EntityManager.h
- #pragma once
- #include "ServiceLocator.h"
- #include <type_traits>
- #include "EntitySystemTypes.h"
- #include "ComponentContainer.h"
- class EntityManager
- {
- public:
- EntityManager() {};
- ~EntityManager() {};
- template<typename... Args>
- constexpr std::size_t length(Args...)
- {
- std::cout << sizeof...(Args) << '\n';
- return sizeof...(Args);
- }
- template <typename FirstComponent, typename... Components>
- EntityTypeId CreateEntityType() {
- typedef ComponentContainer<FirstComponent, Components...> Container;
- EntityTypeId id = std::numeric_limits<EntityTypeId>::max();
- if (ServiceLocator<Container>::GetService() == nullptr) {
- id = numberOfEntityTypes;
- Container* container = new Container();
- ServiceLocator<Container>::SetService(container);
- numberOfEntityTypes++;
- }
- else {
- std::cout << "Type already exists when CreatingEntityType " << '\n';
- }
- return id;
- }
- template <typename FirstComponent, typename... Components>
- EntityId CreateEntityOfType() {
- typedef ComponentContainer<FirstComponent, Components...> Container;
- Container* container = ServiceLocator<Container>::GetService();
- if (container == nullptr) {
- return std::numeric_limits<EntityId>::max();
- }
- container->AddElements();
- EntityId entityId = std::numeric_limits<EntityTypeId>::max();
- entityId = container->get<0>().size() - 1;
- return entityId;
- }
- template <typename Component, typename FirstComponent, typename... Components>
- Component& GetComponent(EntityId p_entityId) {
- typedef ComponentContainer<FirstComponent, Components...> Container;
- Container* container = ServiceLocator<Container>::GetService();
- return container->GetComponent<Component>(p_entityId);
- }
- private:
- EntityTypeId numberOfEntityTypes;
- EntityId numberOfEntities;
- };
Advertisement
Add Comment
Please, Sign In to add comment