]> icculus.org git repositories - divverent/netradiant.git/blob - include/ientity.h
s/GtkRadiant/NetRadiant/
[divverent/netradiant.git] / include / ientity.h
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #if !defined(INCLUDED_IENTITY_H)
23 #define INCLUDED_IENTITY_H
24
25 #include "generic/constant.h"
26
27 #include "string/string.h"
28 #include "scenelib.h"
29
30 class EntityClass;
31
32 typedef Callback1<const char*> KeyObserver;
33
34 class EntityKeyValue
35 {
36 public:
37   virtual const char* c_str() const = 0;
38   virtual void assign(const char* other) = 0;
39   virtual void attach(const KeyObserver& observer) = 0;
40   virtual void detach(const KeyObserver& observer) = 0;
41 };
42
43 class Entity
44 {
45 public:
46   STRING_CONSTANT(Name, "Entity");
47
48   class Observer
49   {
50   public:
51     virtual void insert(const char* key, EntityKeyValue& value) = 0;
52     virtual void erase(const char* key, EntityKeyValue& value) = 0;
53     virtual void clear() { };
54   };
55
56   class Visitor
57   {
58   public:
59     virtual void visit(const char* key, const char* value) = 0;
60   };
61
62   virtual const EntityClass& getEntityClass() const = 0;
63   virtual void forEachKeyValue(Visitor& visitor) const = 0;
64   virtual void setKeyValue(const char* key, const char* value) = 0;
65   virtual const char* getKeyValue(const char* key) const = 0;
66   virtual bool isContainer() const = 0;
67   virtual void attach(Observer& observer) = 0;
68   virtual void detach(Observer& observer) = 0;
69 };
70
71 class EntityCopyingVisitor : public Entity::Visitor
72 {
73   Entity& m_entity;
74 public:
75   EntityCopyingVisitor(Entity& entity)
76     : m_entity(entity)
77   {
78   }
79
80   void visit(const char* key, const char* value)
81   {
82     if(!string_equal(key, "classname"))
83     {
84       m_entity.setKeyValue(key, value);
85     }
86   }
87 };
88
89 inline Entity* Node_getEntity(scene::Node& node)
90 {
91   return NodeTypeCast<Entity>::cast(node);
92 }
93
94
95 template<typename value_type>
96 class Stack;
97 template<typename Contained>
98 class Reference;
99
100 namespace scene
101 {
102   class Node;
103 }
104
105 typedef Reference<scene::Node> NodeReference;
106
107 namespace scene
108 {
109   typedef Stack<NodeReference> Path;
110 }
111
112 class Counter;
113
114 class EntityCreator
115 {
116 public:
117   INTEGER_CONSTANT(Version, 2);
118   STRING_CONSTANT(Name, "entity");
119
120   virtual scene::Node& createEntity(EntityClass* eclass) = 0;
121
122   typedef void (*KeyValueChangedFunc)();
123   virtual void setKeyValueChangedFunc(KeyValueChangedFunc func) = 0;
124
125   virtual void setCounter(Counter* counter) = 0;
126
127   virtual void connectEntities(const scene::Path& e1, const scene::Path& e2) = 0;
128
129   virtual void setLightRadii(bool lightRadii) = 0;
130   virtual bool getLightRadii() = 0;
131   virtual void setShowNames(bool showNames) = 0;
132   virtual bool getShowNames() = 0;
133   virtual void setShowAngles(bool showAngles) = 0;
134   virtual bool getShowAngles() = 0;
135
136   virtual void printStatistics() const = 0;
137 };
138
139 #include "modulesystem.h"
140
141 template<typename Type>
142 class GlobalModule;
143 typedef GlobalModule<EntityCreator> GlobalEntityModule;
144
145 template<typename Type>
146 class GlobalModuleRef;
147 typedef GlobalModuleRef<EntityCreator> GlobalEntityModuleRef;
148
149 inline EntityCreator& GlobalEntityCreator()
150 {
151   return GlobalEntityModule::getTable();
152 }
153
154 #endif