diff options
author | Alec Thomas <alec@swapoff.org> | 2016-04-13 10:58:33 +1000 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2016-04-13 10:58:33 +1000 |
commit | b6c5fcb1de2aa53d9a8b9f1ece9b77f49f9d3cf8 (patch) | |
tree | 8e49867defe543369a5e0c1c6e91f7177bada290 | |
parent | 4a4d3f4735c2f0fc38078622bc38dfe61e6fda80 (diff) | |
parent | 2dcddf58bd0112d2c8a8c242415d21552c00d563 (diff) |
Merge pull request #142 from roig/master
Fixed shared library compilation and Function to retrieve the entity from ComponentHandle
-rw-r--r-- | CMakeLists.txt | 35 | ||||
-rw-r--r-- | entityx/Entity.h | 11 |
2 files changed, 29 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 993badb..116b137 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,14 +91,14 @@ macro(require FEATURE_NAME MESSAGE_STRING) endif() endmacro(require) -macro(create_test TARGET_NAME SOURCE) +macro(create_test TARGET_NAME SOURCE DEPENDENCIES) add_executable(${TARGET_NAME} ${SOURCE}) + set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "entityx/tests") target_link_libraries( ${TARGET_NAME} - entityx + ${DEPENDENCIES} ${ARGN} ) - set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "entityx/tests") # Special case for benchmark tests if (${TARGET_NAME} MATCHES .*benchmark.*) @@ -129,36 +129,36 @@ message("-- Checking misc features") require(HAVE_STDINT_H "stdint.h") # Things to install -set(install_libs entityx) + set(sources entityx/System.cc entityx/Event.cc entityx/Entity.cc entityx/help/Timer.cc entityx/help/Pool.cc) -add_library(entityx STATIC ${sources}) -set_target_properties(entityx PROPERTIES DEBUG_POSTFIX -d FOLDER entityx) if (ENTITYX_BUILD_SHARED) message("-- Building shared libraries (-DENTITYX_BUILD_SHARED=0 to only build static librarires)") add_library(entityx_shared SHARED ${sources}) - target_link_libraries( - entityx_shared - ) + set_target_properties(entityx_shared PROPERTIES OUTPUT_NAME entityx DEBUG_POSTFIX -d VERSION ${ENTITYX_VERSION} SOVERSION ${ENTITYX_MAJOR_VERSION} FOLDER entityx) - list(APPEND install_libs entityx_shared) + set(install_libs entityx_shared) +else() + add_library(entityx STATIC ${sources}) + set_target_properties(entityx PROPERTIES DEBUG_POSTFIX -d FOLDER entityx) + set(install_libs entityx) endif (ENTITYX_BUILD_SHARED) if (ENTITYX_BUILD_TESTING) enable_testing() - create_test(pool_test entityx/help/Pool_test.cc) - create_test(entity_test entityx/Entity_test.cc) - create_test(event_test entityx/Event_test.cc) - create_test(system_test entityx/System_test.cc) - create_test(tags_component_test entityx/tags/TagsComponent_test.cc) - create_test(dependencies_test entityx/deps/Dependencies_test.cc) - create_test(benchmarks_test entityx/Benchmarks_test.cc) + create_test(pool_test entityx/help/Pool_test.cc ${install_libs}) + create_test(entity_test entityx/Entity_test.cc ${install_libs}) + create_test(event_test entityx/Event_test.cc ${install_libs}) + create_test(system_test entityx/System_test.cc ${install_libs}) + create_test(tags_component_test entityx/tags/TagsComponent_test.cc ${install_libs}) + create_test(dependencies_test entityx/deps/Dependencies_test.cc ${install_libs}) + create_test(benchmarks_test entityx/Benchmarks_test.cc ${install_libs}) if (ENTITYX_RUN_BENCHMARKS) message("-- Running benchmarks") else () @@ -197,4 +197,5 @@ install( TARGETS ${install_libs} LIBRARY DESTINATION "${libdir}" ARCHIVE DESTINATION "${libdir}" + RUNTIME DESTINATION "bin" ) diff --git a/entityx/Entity.h b/entityx/Entity.h index 0f037b4..9fcf676 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -201,6 +201,11 @@ public: */ void remove(); + /** + * Returns the Entity associated with the component + */ + Entity entity(); + bool operator == (const ComponentHandle<C> &other) const { return manager_ == other.manager_ && id_ == other.id_; } @@ -1058,6 +1063,12 @@ inline void ComponentHandle<C, EM>::remove() { manager_->template remove<C>(id_); } +template <typename C, typename EM> +inline Entity ComponentHandle<C, EM>::entity() { + assert(valid()); + return manager_->get(id_); +} + } // namespace entityx |