diff options
author | Alec Thomas <alec@swapoff.org> | 2013-11-29 12:47:51 -0500 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2013-11-29 12:47:51 -0500 |
commit | d6579543c099c974b9557249aee72306c5aea99d (patch) | |
tree | c15af8586d5b88941603a91ab50aa5bdb6be2ef7 | |
parent | 92714459511725e9b638c7f2435d7f18f97600b1 (diff) | |
parent | b92144502f6d7e779aa7f1e7b657aee2314abf57 (diff) |
Merge no-boost into master.
This eradicates boost as a dependency for everything except the Python
integration, which may or may not work for now.
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | CHANGES.md | 4 | ||||
-rw-r--r-- | CMakeLists.txt | 51 | ||||
-rw-r--r-- | CheckCXX11SharedPtr.cmake | 54 | ||||
-rw-r--r-- | CheckNeedGetPointer.cmake | 18 | ||||
-rw-r--r-- | README.md | 20 | ||||
-rw-r--r-- | entityx/3rdparty/simplesignal.h | 17 | ||||
-rw-r--r-- | entityx/Benchmarks_test.cc | 24 | ||||
-rw-r--r-- | entityx/Entity.h | 5 | ||||
-rw-r--r-- | entityx/Entity_test.cc | 3 | ||||
-rw-r--r-- | entityx/Event.h | 16 | ||||
-rw-r--r-- | entityx/Manager.h | 4 | ||||
-rw-r--r-- | entityx/System.h | 10 | ||||
-rw-r--r-- | entityx/System_test.cc | 3 | ||||
-rw-r--r-- | entityx/config.h.in | 34 | ||||
-rw-r--r-- | entityx/help/NonCopyable.h | 20 | ||||
-rw-r--r-- | entityx/help/Timer.cc | 33 | ||||
-rw-r--r-- | entityx/help/Timer.h | 29 | ||||
-rw-r--r-- | entityx/python/PythonSystem.cc | 7 | ||||
-rw-r--r-- | entityx/tags/TagsComponent.h | 4 | ||||
-rw-r--r-- | entityx/tags/TagsComponent_test.cc | 1 | ||||
-rwxr-xr-x | scripts/travis.sh | 2 |
22 files changed, 166 insertions, 194 deletions
diff --git a/.travis.yml b/.travis.yml index 5b5024f..611553a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ before_install: - sudo apt-add-repository -y ppa:jkeiren/ppa - if test $CC = gcc; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi - sudo apt-get update -qq - - sudo apt-get install -y boost1.48 python-dev - if test $CC = gcc; then sudo apt-get install gcc-4.7 g++-4.7; fi - if test $CC = gcc; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20; fi - if test $CC = gcc; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20; fi @@ -1,5 +1,9 @@ # Change Log +## 2013-10-29 [no-boost branch] - Removed boost dependency for everything except python integration. + +This branch requires C++11 support and has removed all the non-boost::python dependecies, reducing the overhead of running entityx. + ## 2013-08-22 - Remove `boost::signal` and switch to `Simple::Signal`. According to the [benchmarks](http://timj.testbit.eu/2013/cpp11-signal-system-performance/) Simple::Signal is an order of magnitude faster than `boost::signal`. Additionally, `boost::signal` is now deprecated in favor of `boost::signal2`, which is not supported on versions of Boost on a number of platforms. diff --git a/CMakeLists.txt b/CMakeLists.txt index ba530fa..104efb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,12 +11,9 @@ 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_USE_CPP11_STDLIB false CACHE BOOL "For Clang, specify whether to use libc++ (-stdlib=libc++).") -# Check for which shared_ptr implementation to use. -set(ENTITYX_USE_STD_SHARED_PTR false CACHE BOOL "Use std::shared_ptr<T> rather than boost::shared_ptr<T>?") -set(ENTITYX_BUILD_SHARED true CACHE BOOL "Build shared libraries?") -set(ENTITYX_BUILD_PYTHON true CACHE BOOL "Build entityx::python?") -set(ENTITYX_BOOST_SP_DISABLE_THREADS false CACHE BOOL "Disable multi-threading support in boost::shared_ptr") +set(ENTITYX_USE_CPP11_STDLIB true CACHE BOOL "For Clang, specify whether to use libc++ (-stdlib=libc++).") +set(ENTITYX_BUILD_SHARED false CACHE BOOL "Build shared libraries?") +set(ENTITYX_BUILD_PYTHON false CACHE BOOL "Build entityx::python?") include(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) include(CheckCXXSourceCompiles) @@ -28,14 +25,30 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") +# C++11 feature checks +include(CheckCXX11Features.cmake) + +add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1) +set(OLD_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") +check_cxx_source_compiles( +" +#include <memory> + +int main() { + std::shared_ptr<int>(); +} +" +ENTITYX_HAVE_CXX11_STDLIB +) -if (ENTITYX_BOOST_SP_DISABLE_THREADS) - message("-- Disabled multi-threading support in Boost (see http://www.boost.org/doc/libs/1_54_0/libs/smart_ptr/shared_ptr.htm)") - add_definitions(-DBOOST_SP_DISABLE_THREADS=1) +if (NOT ENTITYX_HAVE_CXX11_STDLIB) + message("-- Not using -stdlib=libc++ (test failed to build)") + set(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS}") +else () + message("-- Using -stdlib=libc++") endif () -# C++11 feature checks -include(CheckCXX11Features.cmake) # Misc features check_include_file("stdint.h" HAVE_STDINT_H) @@ -55,9 +68,6 @@ macro(create_test TARGET_NAME SOURCE) entityx gtest gtest_main - ${Boost_SYSTEM_LIBRARY} - ${Boost_TIMER_LIBRARY} - ${Boost_SIGNALS_LIBRARY} ${ARGN} ) add_test(${TARGET_NAME} ${TARGET_NAME}) @@ -81,9 +91,6 @@ require(HAS_CXX11_LONG_LONG "C++11 lambdas") message("-- Checking misc features") require(HAVE_STDINT_H "stdint.h") -set(Boost_USE_STATIC_LIBS OFF) -set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_RUNTIME OFF) if (ENTITYX_BUILD_PYTHON) message("-- Building with Python support (-DENTITYX_BUILD_PYTHON=0 to disable)") find_package(Boost 1.48.0 COMPONENTS python) @@ -91,7 +98,6 @@ else (ENTITYX_BUILD_PYTHON) message("-- Python support disabled") endif (ENTITYX_BUILD_PYTHON) -include_directories(${Boost_INCLUDE_DIR}) set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") @@ -100,9 +106,7 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") # Things to install set(install_libs entityx) -include(CheckCXX11SharedPtr.cmake) - -set(sources entityx/tags/TagsComponent.cc entityx/deps/Dependencies.cc entityx/System.cc entityx/Event.cc entityx/Entity.cc entityx/Manager.cc) +set(sources entityx/tags/TagsComponent.cc entityx/deps/Dependencies.cc entityx/System.cc entityx/Event.cc entityx/Entity.cc entityx/Manager.cc entityx/help/Timer.cc) add_library(entityx STATIC ${sources}) if (ENTITYX_BUILD_SHARED) @@ -110,14 +114,11 @@ if (ENTITYX_BUILD_SHARED) add_library(entityx_shared SHARED ${sources}) target_link_libraries( entityx_shared - ${Boost_SIGNALS_LIBRARY} ) set_target_properties(entityx_shared PROPERTIES OUTPUT_NAME entityx) list(APPEND install_libs entityx_shared) endif (ENTITYX_BUILD_SHARED) -include_directories(${Boost_INCLUDE_DIR}) - if (ENTITYX_BUILD_PYTHON AND Boost_PYTHON_LIBRARY) message("-- Found boost::python, building entityx/python") find_package(PythonLibs REQUIRED) @@ -149,7 +150,7 @@ if (ENTITYX_BUILD_PYTHON AND Boost_PYTHON_LIBRARY) endif (ENTITYX_BUILD_PYTHON AND Boost_PYTHON_LIBRARY) if (ENTITYX_BUILD_TESTING) - find_package(Boost 1.48.0 REQUIRED COMPONENTS timer system) + #find_package(Boost 1.48.0 REQUIRED COMPONENTS timer system) add_subdirectory(gtest-1.6.0) include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) enable_testing() diff --git a/CheckCXX11SharedPtr.cmake b/CheckCXX11SharedPtr.cmake deleted file mode 100644 index 0dc3281..0000000 --- a/CheckCXX11SharedPtr.cmake +++ /dev/null @@ -1,54 +0,0 @@ -cmake_minimum_required(VERSION 2.8.3) - -if (ENTITYX_USE_CPP11_STDLIB) - add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1) - set(OLD_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") - check_cxx_source_compiles( - " - #include <memory> - - int main() { - std::shared_ptr<int>(); - } - " - ENTITYX_HAVE_CXX11_STDLIB - ) - - if (NOT ENTITYX_HAVE_CXX11_STDLIB) - message("-- Not using -stdlib=libc++ (test failed to build)") - set(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS}") - else () - message("-- Using -stdlib=libc++") - endif () -else () - message("-- Using default stdlib (try -DENTITYX_USE_CPP11_STDLIB=1 to use -stdlib=libc++)") -endif () - -check_cxx_source_compiles( -" -#include <memory> - -int main() { std::shared_ptr<int>(); } -" -ENTITYX_HAVE_STD_SHARED_PTR -) - -check_cxx_source_compiles( -" -#include <boost/shared_ptr.hpp> - -int main() { boost::shared_ptr<int>(); } -" -ENTITYX_HAVE_BOOST_SHARED_PTR -) - -if (ENTITYX_HAVE_STD_SHARED_PTR AND ENTITYX_USE_STD_SHARED_PTR) - message("-- Using std::shared_ptr<T>") -else() - if (ENTITYX_USE_STD_SHARED_PTR) - message("-- Using boost::shared_ptr<T> (std::shared_ptr<T> could not be used)") - else() - message("-- Using boost::shared_ptr<T> (try -DENTITYX_USE_STD_SHARED_PTR=1 to use std::shared_ptr<T>)") - endif() -endif() diff --git a/CheckNeedGetPointer.cmake b/CheckNeedGetPointer.cmake deleted file mode 100644 index 2e53ac3..0000000 --- a/CheckNeedGetPointer.cmake +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 2.8.3) - -check_cxx_source_compiles( -" -#include <boost/get_pointer.hpp> - -namespace boost { -template <class T> inline T * get_pointer(const std::shared_ptr<T> &p) { - return p.get(); -} -} - -int main() { - return 0; -} -" -ENTITYX_NEED_GET_POINTER_SHARED_PTR_SPECIALIZATION -) @@ -1,4 +1,4 @@ -# EntityX - A fast, type-safe C++ Entity Component System +# EntityX - A fast, type-safe C++ Entity Component System [](https://travis-ci.org/alecthomas/entityx) @@ -15,6 +15,7 @@ You can also contact me directly via [email](mailto:alec@swapoff.org) or [Twitte ## Recent Notable Changes +- 2013-10-29 - Boost has been removed as a primary dependency for builds not using python. - 2013-08-21 - Remove dependency on `boost::signal` and switch to embedded [Simple::Signal](http://timj.testbit.eu/2013/cpp11-signal-system-performance/). - 2013-08-18 - Destroying an entity invalidates all other references - 2013-08-17 - Python scripting, and a more robust build system @@ -281,7 +282,6 @@ EntityX has the following build and runtime requirements: - A C++ compiler that supports a basic set of C++11 features (ie. Clang >= 3.1, GCC >= 4.7, and maybe (untested) VC++ with the [Nov 2012 CTP](http://www.microsoft.com/en-us/download/details.aspx?id=35515)). - [CMake](http://cmake.org/) -- [Boost](http://boost.org) `1.48.0` (headers only unless using boost::python). ### C++11 compiler and library support @@ -291,22 +291,12 @@ C++11 support is quite...raw. To make life more interesting, C++ support really On OSX you must use Clang as the GCC version is practically prehistoric. -EntityX can build against libstdc++ (GCC with no C++11 library support) or libc++ (Clang with C++11 library support), though you will need to ensure that Boost is built with the same standard library. - I use Homebrew, and the following works for me: For libstdc++: ```bash -brew install boost -cmake -DENTITYX_BUILD_SHARED=0 -DENTITYX_BUILD_TESTING=1 -DENTITYX_USE_STD_SHARED_PTR=1 -DENTITYX_USE_CPP11_STDLIB=0 .. -``` - -For libc++ (with C++11 support): - -```bash -brew install boost --with-c++11 -cmake -DENTITYX_BUILD_SHARED=0 -DENTITYX_BUILD_TESTING=1 -DENTITYX_USE_STD_SHARED_PTR=1 -DENTITYX_USE_CPP11_STDLIB=1 .. +cmake -DENTITYX_BUILD_SHARED=0 -DENTITYX_BUILD_TESTING=1 .. ``` ### Installing on Ubuntu 12.04 @@ -338,14 +328,10 @@ Once these dependencies are installed you should be able to build and install En - `-DENTITYX_BUILD_PYTHON=1` - Build Python scripting integration. - `-DENTITYX_BUILD_TESTING=1` - Build tests (run with `make test`). - `-DENTITYX_RUN_BENCHMARKS=1` - In conjunction with `-DENTITYX_BUILD_TESTING=1`, also build benchmarks. -- `-DENTITYX_USE_CPP11_STDLIB=1` - For Clang, specify whether to use `-stdlib=libc++`. -- `-DENTITYX_USE_STD_SHARED_PTR=1` - Use `std::shared_ptr<T>` (and friends) rather than the Boost equivalents. This does not eliminate the need for Boost, but is useful if the rest of your application uses `std::shared_ptr<T>`. - `-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=0` - Whether to build tests (defaults to 0). Run with "make && make test". -For a production build, you'll typically only need the `-DENTITYX_USE_STD_SHARED_PTR=1` flag, if any. - Once you have selected your flags, build and install with: ```sh diff --git a/entityx/3rdparty/simplesignal.h b/entityx/3rdparty/simplesignal.h index eaca148..0af2644 100644 --- a/entityx/3rdparty/simplesignal.h +++ b/entityx/3rdparty/simplesignal.h @@ -6,7 +6,6 @@ #include <assert.h> #include <stdint.h> #include <vector> -#include <boost/function.hpp> namespace Simple { @@ -46,7 +45,7 @@ struct CollectorDefault<void> { template<class Collector, class R, class... Args> struct CollectorInvocation<Collector, R (Args...)> { inline bool - invoke (Collector &collector, const boost::function<R (Args...)> &cbf, Args... args) + invoke (Collector &collector, const std::function<R (Args...)> &cbf, Args... args) { return collector (cbf (args...)); } @@ -56,7 +55,7 @@ struct CollectorInvocation<Collector, R (Args...)> { template<class Collector, class... Args> struct CollectorInvocation<Collector, void (Args...)> { inline bool - invoke (Collector &collector, const boost::function<void (Args...)> &cbf, Args... args) + invoke (Collector &collector, const std::function<void (Args...)> &cbf, Args... args) { cbf (args...); return collector(); } @@ -66,7 +65,7 @@ struct CollectorInvocation<Collector, void (Args...)> { template<class Collector, class R, class... Args> class ProtoSignal<R (Args...), Collector> : private CollectorInvocation<Collector, R (Args...)> { protected: - typedef boost::function<R (Args...)> CbFunction; + typedef std::function<R (Args...)> CbFunction; typedef typename CbFunction::result_type Result; typedef typename Collector::CollectorResult CollectorResult; private: @@ -237,7 +236,7 @@ public: * The overhead of an unused signal is intentionally kept very low, around the size of a single pointer. * Note that the Signal template types is non-copyable. */ -template <typename SignalSignature, class Collector = Lib::CollectorDefault<typename boost::function<SignalSignature>::result_type> > +template <typename SignalSignature, class Collector = Lib::CollectorDefault<typename std::function<SignalSignature>::result_type> > struct Signal /*final*/ : Lib::ProtoSignal<SignalSignature, Collector> { @@ -247,15 +246,15 @@ struct Signal /*final*/ : Signal (const CbFunction &method = CbFunction()) : ProtoSignal (method) {} }; -/// This function creates a boost::function by binding @a object to the member function pointer @a method. -template<class Instance, class Class, class R, class... Args> boost::function<R (Args...)> +/// This function creates a std::function by binding @a object to the member function pointer @a method. +template<class Instance, class Class, class R, class... Args> std::function<R (Args...)> slot (Instance &object, R (Class::*method) (Args...)) { return [&object, method] (Args... args) { return (object .* method) (args...); }; } -/// This function creates a boost::function by binding @a object to the member function pointer @a method. -template<class Class, class R, class... Args> boost::function<R (Args...)> +/// This function creates a std::function by binding @a object to the member function pointer @a method. +template<class Class, class R, class... Args> std::function<R (Args...)> slot (Class *object, R (Class::*method) (Args...)) { return [object, method] (Args... args) { return (object ->* method) (args...); }; diff --git a/entityx/Benchmarks_test.cc b/entityx/Benchmarks_test.cc index f469c37..100defd 100644 --- a/entityx/Benchmarks_test.cc +++ b/entityx/Benchmarks_test.cc @@ -1,12 +1,22 @@ #include <iostream> #include <vector> -#include <gtest/gtest.h> -#include <boost/timer/timer.hpp> +#include "gtest/gtest.h" +#include "entityx/help/Timer.h" #include "entityx/Entity.h" using namespace std; using namespace entityx; + +struct AutoTimer { + ~AutoTimer() { + cout << timer_.elapsed() << " seconds elapsed" << endl; + } + +private: + entityx::help::Timer timer_; +}; + class BenchmarksTest : public ::testing::Test { protected: BenchmarksTest() : ev(EventManager::make()), em(EntityManager::make(ev)) {} @@ -17,7 +27,7 @@ protected: TEST_F(BenchmarksTest, TestCreateEntities) { - boost::timer::auto_cpu_timer t; + AutoTimer t; uint64_t count = 10000000L; cout << "creating " << count << " entities" << endl; @@ -35,7 +45,7 @@ TEST_F(BenchmarksTest, TestDestroyEntities) { entities.push_back(em->create()); } - boost::timer::auto_cpu_timer t; + AutoTimer t; cout << "destroying " << count << " entities" << endl; for (auto e : entities) { @@ -54,7 +64,7 @@ TEST_F(BenchmarksTest, TestCreateEntitiesWithListener) { uint64_t count = 10000000L; - boost::timer::auto_cpu_timer t; + AutoTimer t; cout << "creating " << count << " entities while notifying a single EntityCreatedEvent listener" << endl; vector<Entity> entities; @@ -73,7 +83,7 @@ TEST_F(BenchmarksTest, TestDestroyEntitiesWithListener) { entities.push_back(em->create()); } - boost::timer::auto_cpu_timer t; + AutoTimer t; cout << "destroying " << count << " entities" << endl; for (auto &e : entities) { @@ -93,7 +103,7 @@ TEST_F(BenchmarksTest, TestEntityIteration) { entities.push_back(e); } - boost::timer::auto_cpu_timer t; + AutoTimer t; cout << "iterating over " << count << " entities with a component 10 times" << endl; for (int i = 0; i < 10; ++i) { diff --git a/entityx/Entity.h b/entityx/Entity.h index 17e3be0..6b37ed2 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -25,6 +25,7 @@ #include "entityx/config.h" #include "entityx/Event.h" +#include "entityx/help/NonCopyable.h" namespace entityx { @@ -239,7 +240,7 @@ struct ComponentRemovedEvent : public Event<ComponentRemovedEvent<T>> { /** * Manages Entity::Id creation and component assignment. */ -class EntityManager : boost::noncopyable, public enable_shared_from_this<EntityManager> { +class EntityManager : entityx::help::NonCopyable, public enable_shared_from_this<EntityManager> { public: typedef std::bitset<entityx::MAX_COMPONENTS> ComponentMask; @@ -252,7 +253,7 @@ class EntityManager : boost::noncopyable, public enable_shared_from_this<EntityM class View { public: - typedef boost::function<bool (const ptr<EntityManager> &, const Entity::Id &)> Predicate; + typedef std::function<bool (const ptr<EntityManager> &, const Entity::Id &)> Predicate; /// A predicate that matches valid entities with the given component mask. class ComponentMaskPredicate { diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index 1fea6cc..685a736 100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -16,8 +16,7 @@ #include <gtest/gtest.h> #include "entityx/Entity.h" -// using namespace std; // This will give name space conflicts with boost -using namespace boost; +// using namespace std; using namespace entityx; using std::ostream; diff --git a/entityx/Event.h b/entityx/Event.h index c375aa1..e60e7d7 100644 --- a/entityx/Event.h +++ b/entityx/Event.h @@ -11,14 +11,12 @@ #pragma once #include <stdint.h> -#include <boost/bind.hpp> -#include <boost/function.hpp> -#include <boost/noncopyable.hpp> -#include <boost/unordered_map.hpp> #include <list> #include <utility> +#include <unordered_map> #include "entityx/config.h" #include "entityx/3rdparty/simplesignal.h" +#include "entityx/help/NonCopyable.h" namespace entityx { @@ -104,7 +102,7 @@ class Receiver : public BaseReceiver { * * Subscriptions are automatically removed when receivers are destroyed.. */ -class EventManager : boost::noncopyable { +class EventManager : entityx::help::NonCopyable { public: EventManager(); virtual ~EventManager(); @@ -132,7 +130,7 @@ class EventManager : boost::noncopyable { void subscribe(Receiver &receiver) { //NOLINT void (Receiver::*receive)(const E &) = &Receiver::receive; auto sig = signal_for(E::family()); - auto wrapper = EventCallbackWrapper<E>(boost::bind(receive, &receiver, _1)); + auto wrapper = EventCallbackWrapper<E>(std::bind(receive, &receiver, std::placeholders::_1)); auto connection = sig->connect(wrapper); static_cast<BaseReceiver&>(receiver).connections_.push_back( std::make_pair(EventSignalWeakPtr(sig), connection)); @@ -189,12 +187,12 @@ class EventManager : boost::noncopyable { // Functor used as an event signal callback that casts to E. template <typename E> struct EventCallbackWrapper { - EventCallbackWrapper(boost::function<void(const E &)> callback) : callback(callback) {} + EventCallbackWrapper(std::function<void(const E &)> callback) : callback(callback) {} void operator()(const BaseEvent* event) { callback(*(static_cast<const E*>(event))); } - boost::function<void(const E &)> callback; + std::function<void(const E &)> callback; }; - boost::unordered_map<int, EventSignalPtr> handlers_; + std::unordered_map<int, EventSignalPtr> handlers_; }; } // namespace entityx diff --git a/entityx/Manager.h b/entityx/Manager.h index 5151df5..3a7e99a 100644 --- a/entityx/Manager.h +++ b/entityx/Manager.h @@ -10,10 +10,10 @@ #pragma once -#include <boost/timer.hpp> #include "entityx/Entity.h" #include "entityx/Event.h" #include "entityx/System.h" +#include "entityx/help/Timer.h" namespace entityx { @@ -58,7 +58,7 @@ class Manager { ptr<SystemManager> system_manager; private: - boost::timer timer_; + help::Timer timer_; bool running_ = false; }; diff --git a/entityx/System.h b/entityx/System.h index e4dcfec..132b8b9 100644 --- a/entityx/System.h +++ b/entityx/System.h @@ -11,13 +11,13 @@ #pragma once -#include <boost/noncopyable.hpp> -#include <boost/unordered_map.hpp> +#include <unordered_map> #include <stdint.h> #include <cassert> #include "entityx/config.h" #include "entityx/Entity.h" #include "entityx/Event.h" +#include "entityx/help/NonCopyable.h" namespace entityx { @@ -25,7 +25,7 @@ namespace entityx { /** * Base System class. Generally should not be directly used, instead see System<Derived>. */ -class BaseSystem : boost::noncopyable { +class BaseSystem : entityx::help::NonCopyable { public: typedef uint64_t Family; @@ -72,7 +72,7 @@ class System : public BaseSystem { }; -class SystemManager : boost::noncopyable, public enable_shared_from_this<SystemManager> { +class SystemManager : entityx::help::NonCopyable, public enable_shared_from_this<SystemManager> { public: SystemManager(ptr<EntityManager> entity_manager, ptr<EventManager> event_manager) : @@ -150,7 +150,7 @@ class SystemManager : boost::noncopyable, public enable_shared_from_this<SystemM bool initialized_ = false; ptr<EntityManager> entity_manager_; ptr<EventManager> event_manager_; - boost::unordered_map<BaseSystem::Family, ptr<BaseSystem>> systems_; + std::unordered_map<BaseSystem::Family, ptr<BaseSystem>> systems_; }; } // namespace entityx diff --git a/entityx/System_test.cc b/entityx/System_test.cc index 0d82df5..b08416e 100644 --- a/entityx/System_test.cc +++ b/entityx/System_test.cc @@ -15,8 +15,7 @@ #include "entityx/System.h" -// using namespace std; // This will give name space conflicts with boost -using namespace boost; +// using namespace std; using namespace entityx; using std::string; diff --git a/entityx/config.h.in b/entityx/config.h.in index de43e83..2e6f000 100644 --- a/entityx/config.h.in +++ b/entityx/config.h.in @@ -1,8 +1,5 @@ #pragma once -#cmakedefine ENTITYX_HAVE_BOOST_SHARED_PTR 1 -#cmakedefine ENTITYX_HAVE_STD_SHARED_PTR 1 -#cmakedefine ENTITYX_USE_STD_SHARED_PTR 1 #cmakedefine ENTITYX_MAX_COMPONENTS @ENTITYX_MAX_COMPONENTS@ #cmakedefine ENTITYX_HAVE_BOOST_PYTHON 1 #cmakedefine ENTITYX_INSTALLED_PYTHON_PACKAGE_DIR "@ENTITYX_INSTALLED_PYTHON_PACKAGE_DIR@" @@ -19,8 +16,6 @@ static const uint64_t MAX_COMPONENTS = ENTITYX_MAX_COMPONENTS; // Which shared_ptr implementation should we use? -#if (ENTITYX_HAVE_STD_SHARED_PTR && ENTITYX_USE_STD_SHARED_PTR) - #include <memory> namespace entityx { @@ -38,35 +33,6 @@ using enable_shared_from_this = std::enable_shared_from_this<T>; } // namespace entityx -#elif ENTITYX_HAVE_BOOST_SHARED_PTR - -#include <boost/shared_ptr.hpp> -#include <boost/weak_ptr.hpp> -#include <boost/enable_shared_from_this.hpp> - - -namespace entityx { - -template <typename T> -using ptr = boost::shared_ptr<T>; -template <typename T> -using weak_ptr = boost::weak_ptr<T>; -template <typename T, typename U> -ptr<U> static_pointer_cast(const ptr<T> &ptr) { - return boost::static_pointer_cast<U>(ptr); -} -template <typename T> -using enable_shared_from_this = boost::enable_shared_from_this<T>; - -} // namespace entityx - -#else - -#warning "Don't have a boost or std shared_ptr implementation to use" - -#endif - - namespace entityx { template <typename T> diff --git a/entityx/help/NonCopyable.h b/entityx/help/NonCopyable.h new file mode 100644 index 0000000..19c0ed1 --- /dev/null +++ b/entityx/help/NonCopyable.h @@ -0,0 +1,20 @@ +// Inspired heavily by boost::noncopyable + +#pragma once + +namespace entityx { +namespace help { + +class NonCopyable { +protected: + NonCopyable() = default; + ~NonCopyable() = default; + + + NonCopyable(const NonCopyable&) = delete; + NonCopyable& operator = (const NonCopyable &) = delete; +}; + + +} // namespace help +} // namespace entityx diff --git a/entityx/help/Timer.cc b/entityx/help/Timer.cc new file mode 100644 index 0000000..5f70ee0 --- /dev/null +++ b/entityx/help/Timer.cc @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2013 Antony Woods <antony@teamwoods.org> + * All rights reserved. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. + * + * Author: Antony Woods <antony@teamwoods.org> + */ + +#include "entityx/help/Timer.h" + +namespace entityx { +namespace help { + +Timer::Timer() { + _start = std::chrono::system_clock::now(); +} + +Timer::~Timer() { +} + +void Timer::restart() { + _start = std::chrono::system_clock::now(); +} + +double Timer::elapsed() { + auto duration = std::chrono::system_clock::now() - _start; + return static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()) / 1000.0; +} + +} // namespace help +} // namespace entityx diff --git a/entityx/help/Timer.h b/entityx/help/Timer.h new file mode 100644 index 0000000..4d22b08 --- /dev/null +++ b/entityx/help/Timer.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2013 Antony Woods <antony@teamwoods.org> + * All rights reserved. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. + * + * Author: Antony Woods <antony@teamwoods.org> + */ +#pragma once + +#include <chrono> + +namespace entityx { +namespace help { + +class Timer { +public: + Timer(); + ~Timer(); + + void restart(); + double elapsed(); +private: + std::chrono::time_point<std::chrono::system_clock> _start; +}; + +} // namespace help +} // namespace entityx diff --git a/entityx/python/PythonSystem.cc b/entityx/python/PythonSystem.cc index bb59e7d..220003b 100644 --- a/entityx/python/PythonSystem.cc +++ b/entityx/python/PythonSystem.cc @@ -15,6 +15,7 @@ #include <iostream> #include <sstream> #include "entityx/python/PythonSystem.h" +#include "entityx/help/NonCopyable.h" namespace py = boost::python; @@ -103,7 +104,7 @@ BOOST_PYTHON_MODULE(_entityx) { py::class_<PythonEntityXLogger>("Logger", py::no_init) .def("write", &PythonEntityXLogger::write); - py::class_<BaseEvent, ptr<BaseEvent>, boost::noncopyable>("BaseEvent", py::no_init); + py::class_<BaseEvent, ptr<BaseEvent>, entityx::help::NonCopyable>("BaseEvent", py::no_init); py::class_<PythonEntity>("Entity", py::init<Entity>()) .def_readonly("_entity", &PythonEntity::_entity) @@ -121,12 +122,12 @@ BOOST_PYTHON_MODULE(_entityx) { .def("get_component", &get_component<PythonComponent>) .staticmethod("get_component"); - py::class_<EntityManager, ptr<EntityManager>, boost::noncopyable>("EntityManager", py::no_init) + py::class_<EntityManager, ptr<EntityManager>, entityx::help::NonCopyable>("EntityManager", py::no_init) .def("create", &EntityManager::create); void (EventManager::*emit)(const BaseEvent &) = &EventManager::emit; - py::class_<EventManager, ptr<EventManager>, boost::noncopyable>("EventManager", py::no_init) + py::class_<EventManager, ptr<EventManager>, entityx::help::NonCopyable>("EventManager", py::no_init) .def("emit", emit); py::implicitly_convertible<PythonEntity, Entity>(); diff --git a/entityx/tags/TagsComponent.h b/entityx/tags/TagsComponent.h index b208c63..6fcb937 100644 --- a/entityx/tags/TagsComponent.h +++ b/entityx/tags/TagsComponent.h @@ -10,8 +10,8 @@ #pragma once -#include <boost/unordered_set.hpp> #include <string> +#include <unordered_set> #include "entityx/Entity.h" namespace entityx { @@ -50,7 +50,7 @@ class TagsComponent : public Component<TagsComponent> { return EntityManager::View(view, TagsPredicate(tag)); } - boost::unordered_set<std::string> tags; + std::unordered_set<std::string> tags; private: template <typename ... Args> diff --git a/entityx/tags/TagsComponent_test.cc b/entityx/tags/TagsComponent_test.cc index a323e78..34651b3 100644 --- a/entityx/tags/TagsComponent_test.cc +++ b/entityx/tags/TagsComponent_test.cc @@ -12,7 +12,6 @@ #include "entityx/tags/TagsComponent.h" using namespace std; -using namespace boost; using namespace entityx; using namespace entityx::tags; diff --git a/scripts/travis.sh b/scripts/travis.sh index dadc478..b6b7975 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -3,7 +3,7 @@ CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug -DENTITYX_BUILD_TESTING=1" if [ "$USE_STD_SHARED_PTR" = "1" ]; then - CMAKE_ARGS="${CMAKE_ARGS} -DENTITYX_USE_STD_SHARED_PTR=1" + CMAKE_ARGS="${CMAKE_ARGS}" # This fails on OSX if [ "$CXX" = "clang++" ]; then CMAKE_ARGS="${CMAKE_ARGS} -DENTITYX_USE_CPP11_STDLIB=1" |