From 92abeefb2b8314ee348dcaaaeaa6d5c966273a1b Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Tue, 2 Apr 2013 19:58:14 -0400 Subject: Remove Components*, moved to tags/ in a previous change. --- CMakeLists.txt | 4 +-- entityx/Components.cc | 11 -------- entityx/Components.h | 66 ---------------------------------------------- entityx/Components_test.cc | 55 -------------------------------------- 4 files changed, 2 insertions(+), 134 deletions(-) delete mode 100644 entityx/Components.cc delete mode 100644 entityx/Components.h delete mode 100644 entityx/Components_test.cc 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 - * 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 - */ - -#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 - * 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 - */ - -#pragma once - -#include -#include -#include "entityx/Entity.h" - -namespace entityx { - -/** - * Allow entities to be tagged with strings. - */ -class TagsComponent : public Component { - struct TagsPredicate { - TagsPredicate(const std::string &tag) : tag(tag) {} - - bool operator () (EntityManager &manager, Entity::Id id) { - auto tags = manager.component(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 - 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 tags; - - private: - template - 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 - * 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 - */ - -#include -#include "entityx/Components.h" - -using namespace std; -using namespace boost; -using namespace entityx; - - -struct Position : public Component {}; - - -template -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 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(); - for (int i = 0; i < 99; ++i) { - auto e = en.create(); - e.assign(); - e.assign("positionable"); - } - a.assign("player", "indestructible"); - auto entities = en.entities_with_components(); - ASSERT_EQ(100, size(entities)); - ASSERT_EQ(1, size(TagsComponent::view(entities, "player"))); -} -- cgit v1.2.3