]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - include/ientity.h
Merge commit '48410b113dd2036e69dbf723a39ec9af02fc9b12'
[xonotic/netradiant.git] / include / ientity.h
index 51ca389f28e7a8b308f858b3041f6b19f53e5d69..c74ed7c625de4568dc675ca772fda3195b9f4fa6 100644 (file)
-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-\r
-#ifndef _IENTITY_H_\r
-#define _IENTITY_H_\r
-\r
-//\r
-// API for entity manip stuff\r
-//\r
-\r
-// FIXME TTimo this prolly needs to merge with iepairs.h?\r
-\r
-/*!\r
-SPoG\r
-generic "entity" module... \r
-at first, there will only be one implementation for all entities, \r
-perhaps later there will be one for each entity type? \r
-it would probably make more sense to have a single implementation, \r
-a generic one that is very flexible and can adapt the visualisation of \r
-itself depending on an xml config specified in the entity definitions file\r
-*/\r
-#define ENTITY_MAJOR "entity"\r
-// {A1C9F9FD-75D5-4e4d-9D65-235D6D3F254C}\r
-static const GUID QEREntityTable_GUID = \r
-{ 0xa1c9f9fd, 0x75d5, 0x4e4d, { 0x9d, 0x65, 0x23, 0x5d, 0x6d, 0x3f, 0x25, 0x4c } };\r
-\r
-typedef entity_t* (* PFN_ENTITYALLOC) ();\r
-typedef void (* PFN_ENTITYFREE) (entity_t *e);\r
-typedef entity_t* (* PFN_ENTITYCREATE) (eclass_t *c);\r
-typedef entity_t* (* PFN_ENTITYCLONE) (entity_t *e);\r
-typedef void  (* PFN_ENTITYSETKEYVALUE) (entity_t *ent, const char *key, const char *value);\r
-typedef void  (* PFN_ENTITYDELETEKEY) (entity_t *ent, const char *key);\r
-typedef const char* (* PFN_ENTITYVALUEFORKEY) (entity_t *ent, const char *key);\r
-typedef float (* PFN_ENTITYFLOATFORKEY) (entity_t *ent, const char *key);\r
-typedef int   (* PFN_ENTITYINTFORKEY) (entity_t *ent, const char *key);\r
-typedef void  (* PFN_ENTITYVECTORFORKEY) (entity_t *ent, const char *key, vec3_t vec);\r
-typedef void (* PFN_ENTITYADDTOLIST) (entity_t *e, entity_t *lst);\r
-typedef void (* PFN_ENTITYREMOVEFROMLIST) (entity_t *e);\r
-typedef void (* PFN_ENTITYLINKBRUSH) (entity_t *e, brush_t *b);\r
-typedef void (* PFN_ENTITYUNLINKBRUSH) (brush_t *b);\r
-typedef void (* PFN_ENTITYDRAWLIGHT) (entity_t* e, int nGLState, int pref, int nViewType);\r
-typedef int (* PFN_ENTITYMEMORYSIZE) (entity_t *e);\r
-typedef void (* PFN_ENTITYUPDATEMODEL) (entity_t *e);\r
-typedef epair_t* (* PFN_ALLOCATEEPAIR) (const char *key, const char *value);\r
-typedef epair_t** (* PFN_GETENTITYKEYVALLIST) (entity_t *e);\r
-typedef void (* PFN_SETENTITYKEYVALLIST) (entity_t *e, epair_t* ep);\r
-\r
-\r
-struct _QEREntityTable\r
-{\r
-  int m_nSize;\r
-  PFN_ENTITYALLOC m_pfnEntity_Alloc;\r
-  PFN_ENTITYFREE m_pfnEntity_Free;\r
-  PFN_ENTITYCREATE m_pfnEntity_Create;\r
-  PFN_ENTITYCLONE m_pfnEntity_Clone;\r
-  PFN_ENTITYSETKEYVALUE m_pfnSetKeyValue;\r
-  PFN_ENTITYDELETEKEY m_pfnDeleteKey;\r
-  PFN_ENTITYVALUEFORKEY m_pfnValueForKey;\r
-  PFN_ENTITYFLOATFORKEY m_pfnFloatForKey;\r
-  PFN_ENTITYINTFORKEY m_pfnIntForKey;\r
-  PFN_ENTITYVECTORFORKEY m_pfnGetVectorForKey;\r
-  PFN_ENTITYADDTOLIST m_pfnEntity_AddToList;\r
-  PFN_ENTITYREMOVEFROMLIST m_pfnEntity_RemoveFromList;\r
-  PFN_ENTITYLINKBRUSH m_pfnEntity_LinkBrush;\r
-  PFN_ENTITYUNLINKBRUSH m_pfnEntity_UnlinkBrush;\r
-  PFN_ENTITYDRAWLIGHT m_pfnDrawLight;\r
-  PFN_ENTITYMEMORYSIZE m_pfnEntity_MemorySize;\r
-  PFN_ALLOCATEEPAIR m_pfnAllocateEpair;\r
-  PFN_GETENTITYKEYVALLIST m_pfnGetEntityKeyValList;\r
-  PFN_SETENTITYKEYVALLIST m_pfnSetEntityKeyValList;\r
-};\r
-\r
-#ifdef USE_ENTITYTABLE_DEFINE\r
-#ifndef __ENTITYTABLENAME\r
-#define __ENTITYTABLENAME g_EntityTable\r
-#endif\r
-#define Entity_Alloc __ENTITYTABLENAME.m_pfnEntity_Alloc\r
-#define Entity_Free __ENTITYTABLENAME.m_pfnEntity_Free\r
-#define Entity_Clone __ENTITYTABLENAME.m_pfnEntity_Clone\r
-#define SetKeyValue __ENTITYTABLENAME.m_pfnSetKeyValue\r
-#define DeleteKey __ENTITYTABLENAME.m_pfnDeleteKey\r
-#define ValueForKey __ENTITYTABLENAME.m_pfnValueForKey\r
-#define FloatForKey __ENTITYTABLENAME.m_pfnFloatForKey\r
-#define IntForKey __ENTITYTABLENAME.m_pfnIntForKey\r
-#define GetVectorForKey __ENTITYTABLENAME.m_pfnGetVectorForKey\r
-#define Entity_AddToList __ENTITYTABLENAME.m_pfnEntity_AddToList\r
-#define Entity_RemoveFromList __ENTITYTABLENAME.m_pfnEntity_RemoveFromList\r
-#define Entity_LinkBrush __ENTITYTABLENAME.m_pfnEntity_LinkBrush\r
-#define Entity_UnlinkBrush __ENTITYTABLENAME.m_pfnEntity_UnlinkBrush\r
-#define DrawLight __ENTITYTABLENAME.m_pfnDrawLight\r
-#define Entity_MemorySize __ENTITYTABLENAME.m_pfnEntity_MemorySize\r
-#define Entity_AllocateEpair __ENTITYTABLENAME.m_pfnAllocateEpair\r
-#define Entity_GetKeyValList __ENTITYTABLENAME.m_pfnGetEntityKeyValList\r
-#define Entity_SetKeyValList __ENTITYTABLENAME.m_pfnSetEntityKeyValList\r
-#endif\r
-\r
-#endif\r
-\r
+/*
+Copyright (C) 2001-2006, William Joseph.
+All Rights Reserved.
+
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#if !defined(INCLUDED_IENTITY_H)
+#define INCLUDED_IENTITY_H
+
+#include "generic/constant.h"
+
+#include "string/string.h"
+#include "scenelib.h"
+
+class EntityClass;
+
+typedef Callback1<const char*> KeyObserver;
+
+class EntityKeyValue
+{
+public:
+  virtual const char* c_str() const = 0;
+  virtual void assign(const char* other) = 0;
+  virtual void attach(const KeyObserver& observer) = 0;
+  virtual void detach(const KeyObserver& observer) = 0;
+};
+
+class Entity
+{
+public:
+  STRING_CONSTANT(Name, "Entity");
+
+  class Observer
+  {
+  public:
+    virtual void insert(const char* key, EntityKeyValue& value) = 0;
+    virtual void erase(const char* key, EntityKeyValue& value) = 0;
+    virtual void clear() { };
+  };
+
+  class Visitor
+  {
+  public:
+    virtual void visit(const char* key, const char* value) = 0;
+  };
+
+  virtual const EntityClass& getEntityClass() const = 0;
+  virtual void forEachKeyValue(Visitor& visitor) const = 0;
+  virtual void setKeyValue(const char* key, const char* value) = 0;
+  virtual const char* getKeyValue(const char* key) const = 0;
+  virtual bool isContainer() const = 0;
+  virtual void attach(Observer& observer) = 0;
+  virtual void detach(Observer& observer) = 0;
+};
+
+class EntityCopyingVisitor : public Entity::Visitor
+{
+  Entity& m_entity;
+public:
+  EntityCopyingVisitor(Entity& entity)
+    : m_entity(entity)
+  {
+  }
+
+  void visit(const char* key, const char* value)
+  {
+    if(!string_equal(key, "classname"))
+    {
+      m_entity.setKeyValue(key, value);
+    }
+  }
+};
+
+inline Entity* Node_getEntity(scene::Node& node)
+{
+  return NodeTypeCast<Entity>::cast(node);
+}
+
+
+template<typename value_type>
+class Stack;
+template<typename Contained>
+class Reference;
+
+namespace scene
+{
+  class Node;
+}
+
+typedef Reference<scene::Node> NodeReference;
+
+namespace scene
+{
+  typedef Stack<NodeReference> Path;
+}
+
+class Counter;
+
+class EntityCreator
+{
+public:
+  INTEGER_CONSTANT(Version, 2);
+  STRING_CONSTANT(Name, "entity");
+
+  virtual scene::Node& createEntity(EntityClass* eclass) = 0;
+
+  typedef void (*KeyValueChangedFunc)();
+  virtual void setKeyValueChangedFunc(KeyValueChangedFunc func) = 0;
+
+  virtual void setCounter(Counter* counter) = 0;
+
+  virtual void connectEntities(const scene::Path& e1, const scene::Path& e2, int index) = 0;
+
+  virtual void setLightRadii(bool lightRadii) = 0;
+  virtual bool getLightRadii() = 0;
+  virtual void setShowNames(bool showNames) = 0;
+  virtual bool getShowNames() = 0;
+  virtual void setShowAngles(bool showAngles) = 0;
+  virtual bool getShowAngles() = 0;
+
+  virtual void printStatistics() const = 0;
+};
+
+#include "modulesystem.h"
+
+template<typename Type>
+class GlobalModule;
+typedef GlobalModule<EntityCreator> GlobalEntityModule;
+
+template<typename Type>
+class GlobalModuleRef;
+typedef GlobalModuleRef<EntityCreator> GlobalEntityModuleRef;
+
+inline EntityCreator& GlobalEntityCreator()
+{
+  return GlobalEntityModule::getTable();
+}
+
+#endif