diff options
-rwxr-xr-x | CMakeLists.txt | 21 | ||||
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | entityx/3rdparty/simplesignal.h | 4 | ||||
-rw-r--r-- | entityx/Entity.cc | 3 | ||||
-rw-r--r-- | entityx/Entity.h | 8 | ||||
-rw-r--r-- | entityx/Event.cc | 2 | ||||
-rw-r--r-- | entityx/Event.h | 2 | ||||
-rw-r--r-- | entityx/System.cc | 3 | ||||
-rw-r--r-- | entityx/System.h | 8 | ||||
-rw-r--r-- | entityx/config.h.in | 5 | ||||
-rw-r--r-- | entityx/deps/Dependencies.h | 2 | ||||
-rw-r--r-- | examples/example.cc | 14 |
12 files changed, 40 insertions, 41 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d77099..90a0bbd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}) set(ENTITYX_BUILD_TESTING false CACHE BOOL "Enable building of tests.") set(ENTITYX_RUN_BENCHMARKS false CACHE BOOL "Run benchmarks (in conjunction with -DENTITYX_BUILD_TESTING=1).") set(ENTITYX_MAX_COMPONENTS 64 CACHE STRING "Set the maximum number of components.") +set(ENTITYX_DT_TYPE double CACHE STRING "The type used for delta time in EntityX update methods.") set(ENTITYX_BUILD_SHARED true CACHE BOOL "Build shared libraries?") include(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) @@ -35,6 +36,10 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Ox /Zi /FS /DEBUG") endif() +# if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Wno-c++98-compat -Wno-shadow -Wno-padded -Wno-missing-noreturn -Wno-global-constructors") +# endif() + # C++11 feature checks include(CheckCXX11Features.cmake) @@ -100,22 +105,6 @@ require(HAS_CXX11_LONG_LONG "C++11 lambdas") message("-- Checking misc features") require(HAVE_STDINT_H "stdint.h") -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") - set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") -elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - # /Zi - Produces a program database (PDB) that contains type information and symbolic debugging information for use with the debugger. - # /FS - Allows multiple cl.exe processes to write to the same .pdb file - # /DEBUG - Enable debug during linking - # /Od - Disables optimization - set(CMAKE_CXX_FLAGS_DEBUG "/Zi /FS /DEBUG /Od /MDd") - # /Ox - Full optimization - set(CMAKE_CXX_FLAGS_RELEASE "/Ox -DNDEBUG") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Ox /Zi /FS /DEBUG") -endif() - # Things to install set(install_libs entityx) @@ -185,7 +185,7 @@ A basic movement system might be implemented with something like the following: ```c++ struct MovementSystem : public System<MovementSystem> { - void update(entityx::EntityManager &es, entityx::EventManager &events, double dt) override { + void update(entityx::EntityManager &es, entityx::EventManager &events, DeltaTime dt) override { Position::Handle position; Direction::Handle direction; for (Entity entity : es.entities_with_components(position, direction)) { @@ -222,7 +222,7 @@ Next we implement our collision system, which emits ``Collision`` objects via an ```c++ class CollisionSystem : public System<CollisionSystem> { public: - void update(entityx::EntityManager &es, entityx::EventManager &events, double dt) override { + void update(entityx::EntityManager &es, entityx::EventManager &events, DeltaTime dt) override { Position::Handle left_position, right_position; for (Entity left_entity : es.entities_with_components(left_position)) { for (Entity right_entity : es.entities_with_components(right_position)) { @@ -245,7 +245,7 @@ struct DebugSystem : public System<DebugSystem>, Receiver<DebugSystem> { event_manager.subscribe<Collision>(*this); } - void update(entityx::EntityManager &entities, entityx::EventManager &events, double dt) {} + void update(entityx::EntityManager &entities, entityx::EventManager &events, DeltaTime dt) {} void receive(const Collision &collision) { LOG(DEBUG) << "entities collided: " << collision.left << " and " << collision.right << endl; @@ -301,7 +301,7 @@ public: } } - void update(double dt) { + void update(DeltaTime dt) { systems.update<DebugSystem>(dt); systems.update<MovementSystem>(dt); systems.update<CollisionSystem>(dt); @@ -374,6 +374,7 @@ Once these dependencies are installed you should be able to build and install En - `-DENTITYX_MAX_COMPONENTS=64` - Override the maximum number of components that can be assigned to each entity. - `-DENTITYX_BUILD_SHARED=1` - Whether to build shared libraries (defaults to 1). - `-DENTITYX_BUILD_TESTING=1` - Whether to build tests (defaults to 0). Run with "make && make test". +- `-DENTITYX_DT_TYPE=double` - The type used for delta time in EntityX update methods. Once you have selected your flags, build and install with: diff --git a/entityx/3rdparty/simplesignal.h b/entityx/3rdparty/simplesignal.h index c0eb4f0..3c60273 100644 --- a/entityx/3rdparty/simplesignal.h +++ b/entityx/3rdparty/simplesignal.h @@ -200,8 +200,8 @@ class ProtoSignal<R(Args...), Collector> : private CollectorInvocation< return collector.result(); } // Number of connected slots. - int size() { - int size = 0; + std::size_t size() { + std::size_t size = 0; SignalLink *link = callback_ring_; link->incref(); do { diff --git a/entityx/Entity.cc b/entityx/Entity.cc index 463e6b3..5461ca7 100644 --- a/entityx/Entity.cc +++ b/entityx/Entity.cc @@ -50,5 +50,8 @@ void EntityManager::reset() { index_counter_ = 0; } +EntityCreatedEvent::~EntityCreatedEvent() {} +EntityDestroyedEvent::~EntityDestroyedEvent() {} + } // namespace entityx diff --git a/entityx/Entity.h b/entityx/Entity.h index e5c7480..d546189 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -273,6 +273,7 @@ struct Component : public BaseComponent { */ struct EntityCreatedEvent : public Event<EntityCreatedEvent> { explicit EntityCreatedEvent(Entity entity) : entity(entity) {} + virtual ~EntityCreatedEvent(); Entity entity; }; @@ -283,6 +284,7 @@ struct EntityCreatedEvent : public Event<EntityCreatedEvent> { */ struct EntityDestroyedEvent : public Event<EntityDestroyedEvent> { explicit EntityDestroyedEvent(Entity entity) : entity(entity) {} + virtual ~EntityDestroyedEvent(); Entity entity; }; @@ -400,7 +402,7 @@ class EntityManager : entityx::help::NonCopyable { Iterator begin() { return Iterator(manager_, mask_, 0); } - Iterator end() { return Iterator(manager_, mask_, manager_->capacity()); } + Iterator end() { return Iterator(manager_, mask_, uint32_t(manager_->capacity())); } const Iterator begin() const { return Iterator(manager_, mask_, 0); } const Iterator end() const { return Iterator(manager_, mask_, manager_->capacity()); } @@ -525,7 +527,7 @@ class EntityManager : entityx::help::NonCopyable { */ void destroy(Entity::Id entity) { assert_valid(entity); - int index = entity.index(); + uint32_t index = entity.index(); auto mask = entity_component_mask_[entity.index()]; event_manager_.emit<EntityDestroyedEvent>(Entity(this, entity)); for (size_t i = 0; i < component_pools_.size(); i++) { @@ -533,7 +535,7 @@ class EntityManager : entityx::help::NonCopyable { if (pool && mask.test(i)) pool->destroy(index); } - entity_component_mask_[index] = 0; + entity_component_mask_[index].reset(); entity_version_[index]++; free_list_.push_back(index); } diff --git a/entityx/Event.cc b/entityx/Event.cc index 36896a0..505b228 100644 --- a/entityx/Event.cc +++ b/entityx/Event.cc @@ -14,6 +14,8 @@ namespace entityx { BaseEvent::Family BaseEvent::family_counter_ = 0; +BaseEvent::~BaseEvent() { +} EventManager::EventManager() { } diff --git a/entityx/Event.h b/entityx/Event.h index 53afd7d..7763723 100644 --- a/entityx/Event.h +++ b/entityx/Event.h @@ -29,7 +29,7 @@ class BaseEvent { public: typedef std::size_t Family; - virtual ~BaseEvent() {} + virtual ~BaseEvent(); virtual Family my_family() const = 0; diff --git a/entityx/System.cc b/entityx/System.cc index dc83cac..278629e 100644 --- a/entityx/System.cc +++ b/entityx/System.cc @@ -14,6 +14,9 @@ namespace entityx { BaseSystem::Family BaseSystem::family_counter_; +BaseSystem::~BaseSystem() { +} + void SystemManager::configure() { for (auto &pair : systems_) { pair.second->configure(event_manager_); diff --git a/entityx/System.h b/entityx/System.h index 4854b8d..996e442 100644 --- a/entityx/System.h +++ b/entityx/System.h @@ -34,7 +34,7 @@ class BaseSystem : entityx::help::NonCopyable { public: typedef size_t Family; - virtual ~BaseSystem() {} + virtual ~BaseSystem(); /** * Called once all Systems have been added to the SystemManager. @@ -48,7 +48,7 @@ class BaseSystem : entityx::help::NonCopyable { * * Called every game step. */ - virtual void update(EntityManager &entities, EventManager &events, double dt) = 0; + virtual void update(EntityManager &entities, EventManager &events, DeltaTime dt) = 0; static Family family_counter_; @@ -60,7 +60,7 @@ class BaseSystem : entityx::help::NonCopyable { * Use this class when implementing Systems. * * struct MovementSystem : public System<MovementSystem> { - * void update(EntityManager &entities, EventManager &events, double dt) { + * void update(EntityManager &entities, EventManager &events, DeltaTime dt) { * // Do stuff to/with entities... * } * } @@ -136,7 +136,7 @@ class SystemManager : entityx::help::NonCopyable { * Call the System::update() method for a registered system. */ template <typename S> - void update(double dt) { + void update(DeltaTime dt) { assert(initialized_ && "SystemManager::configure() not called"); std::shared_ptr<S> s = system<S>(); s->update(entity_manager_, event_manager_, dt); diff --git a/entityx/config.h.in b/entityx/config.h.in index e76e4df..42e1418 100644 --- a/entityx/config.h.in +++ b/entityx/config.h.in @@ -1,12 +1,11 @@ #pragma once -#cmakedefine ENTITYX_MAX_COMPONENTS @ENTITYX_MAX_COMPONENTS@ - #include <cstdint> #include <cstddef> namespace entityx { -static const size_t MAX_COMPONENTS = ENTITYX_MAX_COMPONENTS; +static const size_t MAX_COMPONENTS = @ENTITYX_MAX_COMPONENTS@; +typedef @ENTITYX_DT_TYPE@ DeltaTime; } // namespace entityx diff --git a/entityx/deps/Dependencies.h b/entityx/deps/Dependencies.h index 83ab4a5..4f9883b 100644 --- a/entityx/deps/Dependencies.h +++ b/entityx/deps/Dependencies.h @@ -35,7 +35,7 @@ public: events.subscribe<ComponentAddedEvent<C>>(*this); } - virtual void update(EntityManager &entities, EventManager &events, double dt) override {} + virtual void update(EntityManager &entities, EventManager &events, DeltaTime dt) override {} private: template <typename D> diff --git a/examples/example.cc b/examples/example.cc index cf00a8b..29ca68a 100644 --- a/examples/example.cc +++ b/examples/example.cc @@ -86,7 +86,7 @@ struct CollisionEvent : public ex::Event<CollisionEvent> { // Updates a body's position and rotation. struct BodySystem : public ex::System<BodySystem> { - void update(ex::EntityManager &es, ex::EventManager &events, double dt) override { + void update(ex::EntityManager &es, ex::EventManager &events, DeltaTime dt) override { Body::Handle body; for (ex::Entity entity : es.entities_with_components(body)) { body->position += body->direction * static_cast<float>(dt); @@ -99,7 +99,7 @@ struct BodySystem : public ex::System<BodySystem> { // Fades out the alpha value of any Renderable and Fadeable entity. Once the // object has completely faded out it is destroyed. struct FadeOutSystem : public ex::System<FadeOutSystem> { - void update(ex::EntityManager &es, ex::EventManager &events, double dt) override { + void update(ex::EntityManager &es, ex::EventManager &events, DeltaTime dt) override { Fadeable::Handle fade; Renderable::Handle renderable; for (ex::Entity entity : es.entities_with_components(fade, renderable)) { @@ -121,7 +121,7 @@ class BounceSystem : public ex::System<BounceSystem> { public: explicit BounceSystem(sf::RenderTarget &target) : size(target.getSize()) {} - void update(ex::EntityManager &es, ex::EventManager &events, double dt) override { + void update(ex::EntityManager &es, ex::EventManager &events, DeltaTime dt) override { Body::Handle body; for (ex::Entity entity : es.entities_with_components(body)) { if (body->position.x + body->direction.x < 0 || @@ -159,7 +159,7 @@ class CollisionSystem : public ex::System<CollisionSystem> { size.y = size.y / PARTITIONS + 1; } - void update(ex::EntityManager &es, ex::EventManager &events, double dt) override { + void update(ex::EntityManager &es, ex::EventManager &events, DeltaTime dt) override { reset(); collect(es); collide(events); @@ -226,7 +226,7 @@ public: events.subscribe<CollisionEvent>(*this); } - void update(ex::EntityManager &es, ex::EventManager &events, double dt) override { + void update(ex::EntityManager &es, ex::EventManager &events, DeltaTime dt) override { for (ex::Entity entity : collided) { emit_particles(es, entity); entity.destroy(); @@ -285,7 +285,7 @@ public: text.setColor(sf::Color::White); } - void update(ex::EntityManager &es, ex::EventManager &events, double dt) override { + void update(ex::EntityManager &es, ex::EventManager &events, DeltaTime dt) override { Body::Handle body; Renderable::Handle renderable; for (ex::Entity entity : es.entities_with_components(body, renderable)) { @@ -341,7 +341,7 @@ public: } } - void update(double dt) { + void update(DeltaTime dt) { systems.update<BodySystem>(dt); systems.update<FadeOutSystem>(dt); systems.update<BounceSystem>(dt); |