- 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
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 true CACHE BOOL "Use std::shared_ptr<T> rather than boost::shared_ptr<T>?")
set(ENTITYX_BUILD_SHARED false CACHE BOOL "Build shared libraries?")
set(ENTITYX_BUILD_PYTHON false CACHE BOOL "Build entityx::python?")
-set(ENTITYX_BOOST_SP_DISABLE_THREADS true CACHE BOOL "Disable multi-threading support in boost::shared_ptr")
include(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
include(CheckCXXSourceCompiles)
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
-
-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)
-endif ()
-
# C++11 feature checks
include(CheckCXX11Features.cmake)
entityx
gtest
gtest_main
- ${Boost_SYSTEM_LIBRARY}
- ${Boost_TIMER_LIBRARY}
- ${Boost_SIGNALS_LIBRARY}
${ARGN}
)
add_test(${TARGET_NAME} ${TARGET_NAME})
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)
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")
# 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)
add_library(entityx STATIC ${sources})
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)
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()
+++ /dev/null
-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()
+++ /dev/null
-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
-)
- 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
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 ..
+cmake -DENTITYX_BUILD_SHARED=0 -DENTITYX_BUILD_TESTING=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 -DENTITYX_USE_CPP11_STDLIB=1 ..
```
### Installing on Ubuntu 12.04
- `-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
#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@"
#cmakedefine ENTITYX_NEED_GET_POINTER_SHARED_PTR_SPECIALIZATION "@ENTITYX_NEED_GET_POINTER_SHARED_PTR_SPECIALIZATION@"
+#define ENTITYX_USE_STD_SHARED_PTR 1
+#define ENTITYX_HAVE_STD_SHARED_PTR 1
+
#include <stdint.h>
#include "entityx/config.h"
void Timer::restart()
{
-
+ _start = std::chrono::system_clock::now();
}
double Timer::elapsed()
{
- return 1.0;
+ return std::chrono::duration<double>(std::chrono::system_clock::now() - _start);
}
} // namespace help
*
* Author: Antony Woods <antony@teamwoods.org>
*/
-
#pragma once
+ #include <chrono>
+
namespace entityx {
namespace help {
void restart();
double elapsed();
+private:
+ std::chrono::time_point<std::chrono::system_clock> _start;
};
} // namespace help
#include <iostream>
#include <sstream>
#include "entityx/python/PythonSystem.h"
-#include "entityx/help/NonCopyableEvent.h"
+#include "entityx/help/NonCopyable.h"
namespace py = boost::python;
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"