aboutsummaryrefslogtreecommitdiffstats
path: root/entityx/deps
diff options
context:
space:
mode:
authorAndy <drumsetmonkey@gmail.com>2017-01-19 09:21:12 -0500
committerAndy <drumsetmonkey@gmail.com>2017-01-19 09:21:12 -0500
commit213d9ccfbb4752d4c62d6b7e6b3f9172cdf1bccc (patch)
tree7872c6f30c8adf048a7863a33d837299c7fb0771 /entityx/deps
parent19a32074595a4a2797eaeb978f8bd302f736f6a6 (diff)
parent8452b199d28bea53bf2c5e3b3d604064000fc73d (diff)
Limb animation actually works
Diffstat (limited to 'entityx/deps')
-rw-r--r--entityx/deps/Dependencies.h54
1 files changed, 54 insertions, 0 deletions
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 <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 "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<Dependency<Physics, Position, Direction>>();
+ */
+template <typename C, typename ... Deps>
+class Dependency : public System<Dependency<C, Deps...>>, public Receiver<Dependency<C, Deps...>> {
+public:
+ void receive(const ComponentAddedEvent<C> &event) {
+ assign<Deps...>(event.entity);
+ }
+
+ void configure(EventManager &events) override {
+ events.subscribe<ComponentAddedEvent<C>>(*this);
+ }
+
+ void update(EntityManager &entities, EventManager &events, TimeDelta dt) override {}
+
+private:
+ template <typename D>
+ void assign(Entity entity) {
+ if (!entity.component<D>()) entity.assign<D>();
+ }
+
+ template <typename D, typename D1, typename ... Ds>
+ void assign(Entity entity) {
+ assign<D>(entity);
+ assign<D1, Ds...>(entity);
+ }
+};
+
+} // namespace deps
+} // namespace entityx