diff options
author | Alec Thomas <alec@swapoff.org> | 2013-02-27 13:14:53 -0800 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2013-02-27 13:14:53 -0800 |
commit | 87785361dc273e8ae8ed14cc6d55a81ba9c647af (patch) | |
tree | 057fc0a8cf7d308edbb159c670736f7330d8fdfd | |
parent | 6bb2ed010c3892b3c290e76df0d37583448cc6c7 (diff) | |
parent | bda99099cf02c89977a06251462fecbb6025bf19 (diff) |
Merge pull request #1 from larspensjo/linux-gcc
Enable testing for Linux GCC.
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | README.md | 22 | ||||
-rw-r--r-- | entityx/Entity_test.cc | 16 | ||||
-rw-r--r-- | entityx/System_test.cc | 5 |
4 files changed, 29 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index be77681..c4547c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package(Boost 1.48.0 REQUIRED COMPONENTS signals) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Werror -Wall -Wextra -Wno-unused-parameter -Wno-error=unused-variable -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Werror -Wall -Wextra -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=sign-compare -std=c++11") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") @@ -67,9 +67,11 @@ include_directories( ${GTest_INCLUDE_DIR} ) +set(BUILD_TESTING false CACHE BOOL "Enable building of tests") if (BUILD_TESTING) enable_testing() find_package(GTest REQUIRED) + include_directories(${GTEST_INCLUDE_DIRS}) create_test(entity_test entityx/Entity_test.cc) create_test(component_test entityx/Components_test.cc) create_test(event_test entityx/Event_test.cc) @@ -28,7 +28,7 @@ Entity entity = entities.create(); ### Components (entity data) -Components are typically POD types containing self-contained sets of related data. Implementations are [curiously recurring template pattern](http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern) (CRTP) subclasses of `Component<T>`. +Components are typically [POD types](http://en.wikipedia.org/wiki/Plain_Old_Data_Structures) containing self-contained sets of related data. Implementations are [curiously recurring template pattern](http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern) (CRTP) subclasses of `Component<T>`. #### Creating components @@ -66,7 +66,7 @@ entity.assign(position); #### Querying entities and their components -To query all components with a set of components assigned use ``EntityManager::entities_with_components()``. This method will return only those entities that have *all* of the specified components associated with them, assigning each component pointer to the corresponding component instance: +To query all entities with a set of components assigned, use ``EntityManager::entities_with_components()``. This method will return only those entities that have *all* of the specified components associated with them, assigning each component pointer to the corresponding component instance: ```c++ boost::shared_ptr<Position> position; @@ -117,7 +117,7 @@ First, we define the event type, which for our example is simply the two entitie ```c++ struct Collision : public Event<Collision> { Collision(Entity left, Entity right) : left(left), right(right) {} - + Entity left, right; }; ``` @@ -181,7 +181,7 @@ class GameManager : public Manager { system_manager.add<MovementSystem>(); system_manager.add<CollisionSystem>(); } - + void initialize() { // Create some entities in random locations heading in random directions for (int i = 0; i < 100; ++i) { @@ -190,7 +190,7 @@ class GameManager : public Manager { entity.assign<Direction>((rand() % 10) - 5, (rand() % 10) - 5); } } - + void update(double dt) { system_manager.update<MovementSystem>(dt); system_manager.update<CollisionSystem>(dt); @@ -206,12 +206,16 @@ EntityX has the following build and runtime requirements: - [CMake](http://cmake.org/) - [Boost](http://boost.org) `1.48.0` or higher (links against `boost::signals`). - [Glog](http://code.google.com/p/google-glog/) (tested with `0.3.2`). -- [GTest](http://code.google.com/p/googletest/) +- [GTest](http://code.google.com/p/googletest/) (needed for testing only) -Once these dependencies are installed you should be able to build and install EntityX with: +Once these dependencies are installed you should be able to build and install EntityX as follows. BUILD_TESTING is false by default. ```c++ -mkdir build && cd build && cmake .. && make && make test && make install +mkdir build +cd build +cmake [-DBUILD_TESTING=true] .. +make +make install ``` -EntityX has currently only been tested on Mac OSX (Lion and Mountain Lion). Reports and patches for builds on other platforms are welcome. +EntityX has currently only been tested on Mac OSX (Lion and Mountain Lion), and Linux Debian. Reports and patches for builds on other platforms are welcome. diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index 55da405..67026e8 100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -4,7 +4,7 @@ * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. - * + * * Author: Alec Thomas <alec@swapoff.org> */ @@ -16,10 +16,12 @@ #include <gtest/gtest.h> #include "entityx/Entity.h" -using namespace std; +// using namespace std; // This will give name space conflicts with boost using namespace boost; using namespace entityx; +using std::ostream; +using std::vector; template <typename T> int size(const T &t) { @@ -192,11 +194,13 @@ TEST_F(EntityManagerTest, TestUnpack) { ASSERT_EQ(d, ud); } +// gcc 4.7.2 does not allow this struct to be declared locally inside the TEST_F. +struct NullDeleter {template<typename T> void operator()(T*) {} }; + TEST_F(EntityManagerTest, TestUnpackNullMissing) { Entity::Id e = em.create(); auto p = em.assign<Position>(e); - struct NullDeleter {template<typename T> void operator()(T*) {} }; shared_ptr<Position> up(reinterpret_cast<Position*>(0Xdeadbeef), NullDeleter()); shared_ptr<Direction> ud(reinterpret_cast<Direction*>(0Xdeadbeef), NullDeleter()); em.unpack<Position, Direction>(e, up, ud); @@ -225,7 +229,7 @@ TEST_F(EntityManagerTest, TestEntityCreatedEvent) { em.create(); } ASSERT_EQ(10, receiver.created.size()); -}; +} TEST_F(EntityManagerTest, TestEntityDestroyedEvent) { struct EntityDestroyedEventReceiver : public Receiver<EntityDestroyedEventReceiver> { @@ -249,7 +253,7 @@ TEST_F(EntityManagerTest, TestEntityDestroyedEvent) { em.destroy(e); } ASSERT_TRUE(entities == receiver.destroyed); -}; +} TEST_F(EntityManagerTest, TestComponentAddedEvent) { struct ComponentAddedEventReceiver : public Receiver<ComponentAddedEventReceiver> { @@ -289,4 +293,4 @@ TEST_F(EntityManagerTest, TestComponentAddedEvent) { } ASSERT_EQ(10, receiver.position_events); ASSERT_EQ(10, receiver.direction_events); -}; +} diff --git a/entityx/System_test.cc b/entityx/System_test.cc index 63da01f..c529bd1 100644 --- a/entityx/System_test.cc +++ b/entityx/System_test.cc @@ -4,7 +4,7 @@ * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. - * + * * Author: Alec Thomas <alec@swapoff.org> */ @@ -16,9 +16,10 @@ #include "entityx/System.h" -using namespace std; +// using namespace std; // This will give name space conflicts with boost using namespace boost; using namespace entityx; +using std::string; struct Position : Component<Position> { Position(float x = 0.0f, float y = 0.0f) : x(x), y(y) {} |