From f800dbc034e7a70a613bab8cd9d147be4f6e88b6 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 10 Jan 2017 21:26:13 -0500 Subject: windows build --- entityx/deps/Dependencies.h | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 entityx/deps/Dependencies.h (limited to 'entityx/deps') diff --git a/entityx/deps/Dependencies.h b/entityx/deps/Dependencies.h new file mode 100644 index 0000000..88c9f79 --- /dev/null +++ b/entityx/deps/Dependencies.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2013 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 "entityx/System.h" +#include "entityx/Event.h" +#include "entityx/Entity.h" + +namespace entityx { +namespace deps { + +/** + * An entityx::System for declaring component dependencies. + * + * eg. To declare that a `Physics` component must always be paired with `Position` + * and `Direction` components: + * + * system_manager->add>(); + */ +template +class Dependency : public System>, public Receiver> { +public: + void receive(const ComponentAddedEvent &event) { + assign(event.entity); + } + + void configure(EventManager &events) override { + events.subscribe>(*this); + } + + void update(EntityManager &entities, EventManager &events, TimeDelta dt) override {} + +private: + template + void assign(Entity entity) { + if (!entity.component()) entity.assign(); + } + + template + void assign(Entity entity) { + assign(entity); + assign(entity); + } +}; + +} // namespace deps +} // namespace entityx -- cgit v1.2.3