aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2013-04-02 19:58:14 -0400
committerAlec Thomas <alec@swapoff.org>2013-04-02 19:58:14 -0400
commit92abeefb2b8314ee348dcaaaeaa6d5c966273a1b (patch)
tree00a41f852ebff779bf700f5f4ce2d22615d7a1b7
parent947d29aa374b9b5f5c581120ce5a4e7a32d0c981 (diff)
Remove Components*, moved to tags/ in a previous change.
-rw-r--r--CMakeLists.txt4
-rw-r--r--entityx/Components.cc11
-rw-r--r--entityx/Components.h66
-rw-r--r--entityx/Components_test.cc55
4 files changed, 2 insertions, 134 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 013c96e..2b6c527 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -127,7 +127,7 @@ set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.48.0 REQUIRED COMPONENTS signals)
-set(sources entityx/Components.cc entityx/System.cc entityx/Event.cc entityx/Entity.cc entityx/Manager.cc)
+set(sources 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(
@@ -148,9 +148,9 @@ if (BUILD_TESTING)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
enable_testing()
create_test(entity_test entityx/Entity_test.cc)
- create_test(component_test entityx/Components_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)
if (RUN_BENCHMARKS)
message("-- Running benchmarks")
create_test(benchmarks_test entityx/Benchmarks_test.cc)
diff --git a/entityx/Components.cc b/entityx/Components.cc
deleted file mode 100644
index 8d6e929..0000000
--- a/entityx/Components.cc
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Copyright (C) 2012 Alec Thomas <alec@swapoff.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: Alec Thomas <alec@swapoff.org>
- */
-
-#include "entityx/Components.h"
diff --git a/entityx/Components.h b/entityx/Components.h
deleted file mode 100644
index 9168cc5..0000000
--- a/entityx/Components.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (C) 2012 Alec Thomas <alec@swapoff.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: Alec Thomas <alec@swapoff.org>
- */
-
-#pragma once
-
-#include <string>
-#include <boost/unordered_set.hpp>
-#include "entityx/Entity.h"
-
-namespace entityx {
-
-/**
- * Allow entities to be tagged with strings.
- */
-class TagsComponent : public Component<TagsComponent> {
- struct TagsPredicate {
- TagsPredicate(const std::string &tag) : tag(tag) {}
-
- bool operator () (EntityManager &manager, Entity::Id id) {
- auto tags = manager.component<TagsComponent>(id);
- return tags != nullptr && tags->tags.find(tag) != tags->tags.end();
- }
-
- std::string tag;
- };
-
- public:
- /**
- * Construct a new TagsComponent with the given tags.
- *
- * eg. TagsComponent tags("a", "b", "c");
- */
- template <typename ... Args>
- TagsComponent(const std::string &tag, const Args & ... tags) {
- set_tags(tag, tags ...);
- }
-
- /**
- * Filter the provided view to only those entities with the given tag.
- */
- static EntityManager::View view(const EntityManager::View &view, const std::string &tag) {
- return EntityManager::View(view, TagsPredicate(tag));
- }
-
- boost::unordered_set<std::string> tags;
-
- private:
- template <typename ... Args>
- void set_tags(const std::string &tag1, const std::string &tag2, const Args & ... tags) {
- this->tags.insert(tag1);
- set_tags(tag2, tags ...);
- }
-
- void set_tags(const std::string &tag) {
- tags.insert(tag);
- }
-};
-
-}
diff --git a/entityx/Components_test.cc b/entityx/Components_test.cc
deleted file mode 100644
index d9a0ecd..0000000
--- a/entityx/Components_test.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (C) 2012 Alec Thomas <alec@swapoff.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: Alec Thomas <alec@swapoff.org>
- */
-
-#include <gtest/gtest.h>
-#include "entityx/Components.h"
-
-using namespace std;
-using namespace boost;
-using namespace entityx;
-
-
-struct Position : public Component<Position> {};
-
-
-template <typename T>
-int size(const T &t) {
- int n = 0;
- for (auto i : t) {
- ++n;
- (void)i; // Unused on purpose, suppress warning
- }
- return n;
-}
-
-
-TEST(TagsComponentTest, TestVariadicConstruction) {
- auto tags = TagsComponent("player", "indestructible");
- unordered_set<string> expected;
- expected.insert("player");
- expected.insert("indestructible");
- ASSERT_TRUE(expected == tags.tags);
-}
-
-TEST(TagsComponentTest, TestEntitiesWithTag) {
- EventManager ev;
- EntityManager en(ev);
- Entity a = en.create();
- a.assign<Position>();
- for (int i = 0; i < 99; ++i) {
- auto e = en.create();
- e.assign<Position>();
- e.assign<TagsComponent>("positionable");
- }
- a.assign<TagsComponent>("player", "indestructible");
- auto entities = en.entities_with_components<Position>();
- ASSERT_EQ(100, size(entities));
- ASSERT_EQ(1, size(TagsComponent::view(entities, "player")));
-}