]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/pluginmanager.h
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / radiant / pluginmanager.h
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 #ifndef _PLUGINMANAGER_H_\r
23 #define _PLUGINMANAGER_H_\r
24 \r
25 #include "plugin.h"\r
26 \r
27 // global interfaces we are using\r
28 extern _QERShadersTable g_ShadersTable;\r
29 \r
30 // NOTE: it's actually a module manager, the name should change to ModuleManager..\r
31 class CPlugInManager  \r
32 {\r
33 private:\r
34   GSList* m_PlugIns;\r
35   CPtrArray m_BrushHandles;\r
36   CPtrArray m_SelectedBrushHandles;\r
37   CPtrArray m_ActiveBrushHandles;\r
38 \r
39   // v1.70\r
40   //! brushes of the current entity ( see m_SelectedBrushHandles and m_ActiveBrushHandles )\r
41   CPtrArray m_EntityBrushHandles;\r
42   //! allocated entities, not commited yet ( see m_BrushHandles )\r
43   CPtrArray m_EntityHandles;\r
44 \r
45   //! tells in which array to look when given a patch index\r
46   enum EPatchesMode { EActivePatches, ESelectedPatches, EAllocatedPatches } PatchesMode;\r
47   //! patches handles (brush_t*)\r
48   CPtrArray m_PatchesHandles;\r
49   //! plugin-allocated patches, not commited yet (patchMesh_t*)\r
50   CPtrArray m_PluginPatches;\r
51 \r
52   void InitForDir(const Str &dir); ///< init for plguins/modules below this directory\r
53 \r
54 public:\r
55   CPtrArray& GetActiveHandles() {return m_ActiveBrushHandles; };\r
56   CPtrArray& GetSelectedHandles() {return m_SelectedBrushHandles; };\r
57   CPtrArray& GetPluginPatches() {return m_PluginPatches; };\r
58   brush_t* FindBrushHandle(void *vp);\r
59   patchMesh_t* FindPatchHandle(int index);\r
60   int CreatePatchHandle();\r
61   int AllocateActivePatchHandles();\r
62   int AllocateSelectedPatchHandles();\r
63   void CommitPatchHandleToMap(int index, patchMesh_t *pMesh, char *texName);\r
64   void CommitPatchHandleToEntity(int index, patchMesh_t *pMesh, char *texName, void *vpEntity);\r
65   void ReleasePatchesHandles() { m_PatchesHandles.RemoveAll(); m_PluginPatches.RemoveAll(); }\r
66   void AddFaceToBrushHandle(void *vp, vec3_t v1, vec3_t v2, vec3_t v3);\r
67   void CommitBrushHandleToMap(void *vp);\r
68   void DeleteBrushHandle(void* vp);\r
69   void* CreateBrushHandle();\r
70   void Dispatch(int n, const char *p);\r
71   void Cleanup(); ///< cleanup of data structures allocated for plugins, not a plugin reload\r
72   void Init(); ///< go through the path where we will find modules and plugins\r
73   void LoadImage (const char *name, unsigned char **pic, int *width, int *height);\r
74   void ImportMap (IDataStream *in, CPtrArray *ents, const char *type);\r
75   void ExportMap (CPtrArray *ents, IDataStream *out, const char *type);\r
76   void Shutdown(); ///< shutdown all the plugins/module subsystem\r
77   CPlugInManager();\r
78   virtual ~CPlugInManager();\r
79 \r
80   /*! \r
81   the texture manager front ends the single load\r
82   addins (texture, model, map formats.. etc.)\r
83   */\r
84   _QERTextureInfo* GetTextureInfo();\r
85   void LoadTexture(const char *pFilename);\r
86         \r
87 void* GetSurfaceFlags();\r
88         \r
89   // v1.70\r
90   CPtrArray& GetEntityBrushHandles() {return m_EntityBrushHandles; };\r
91   CPtrArray& GetEntityHandles() {return m_EntityHandles; };\r
92   //! the vpBrush needs to be in m_BrushHandles\r
93   void CommitBrushHandleToEntity(void* vpBrush, void* vpEntity );\r
94   //! the vpEntity needs to be in m_EntityHandles\r
95   void CommitEntityHandleToMap( void* vpEntity );\r
96 \r
97 protected:\r
98   //! read the interfaces this plugin implements\r
99   void LoadFromPath(const char *path); ///< load all modules/plugins in specified path\r
100   void RegisterInterfaces();\r
101 };\r
102 \r
103 class CPluginSlot : public IPlugIn\r
104 {\r
105   APIDescriptor_t *mpAPI;\r
106   _QERPluginTable *mpTable;\r
107   /*!\r
108   is false until Init() happened\r
109   */\r
110   bool m_bReady;\r
111   /*!\r
112   below is valid only if m_bReady = true\r
113   */\r
114   GSList *m_CommandStrings;\r
115   GSList *m_CommandIDs;\r
116   \r
117 public:\r
118   /*!\r
119   build directly from a SYN_PROVIDE interface\r
120   */\r
121   CPluginSlot(APIDescriptor_t *pAPI);\r
122   virtual ~CPluginSlot();\r
123   \r
124   APIDescriptor_t* GetDescriptor() { return mpAPI; }\r
125   /*!\r
126   initialize some management data after the synapse interfaces have been hooked up\r
127   */\r
128   void Init();\r
129   /*!\r
130   dispatching a command by name to the plugin\r
131   */\r
132   void Dispatch(const char *p);\r
133   \r
134   // IPlugIn ------------------------------------------------------------\r
135   const char* getMenuName();\r
136   int getCommandCount();\r
137   const char* getCommand(int n);  \r
138   void addMenuID(int n);\r
139   bool ownsCommandID(int n);\r
140   \r
141 };\r
142 \r
143 class CRadiantPluginManager : public CSynapseAPIManager\r
144 {\r
145   list<CPluginSlot *> mSlots;\r
146 public:\r
147   CRadiantPluginManager() {}\r
148   virtual ~CRadiantPluginManager();\r
149   \r
150   // CSynapseAPIManager interface -------------------\r
151   APIDescriptor_t *BuildRequireAPI(APIDescriptor_t *pAPI);\r
152   \r
153   // CRadiantPluginManager --------------------------\r
154   void PopulateMenu();\r
155   bool Dispatch(int n, const char* p);\r
156 };\r
157 \r
158 class CImageTableSlot\r
159 {\r
160   /*!\r
161   \todo this is a duplicate from the APIDescriptor_t* list that privately stored inside CSynapseAPIManager\r
162   this is probably useless to us in here?\r
163   */\r
164   APIDescriptor_t *mpAPI;\r
165   /*!\r
166   shortcut to mpAPI->mpTable, with correct typing\r
167   this is what we allocate and should free locally\r
168   */\r
169   _QERPlugImageTable *mpTable;\r
170 public:\r
171   CImageTableSlot() { }\r
172   virtual ~CImageTableSlot() { } ///\ \todo need to correctly free and release still..\r
173   \r
174   APIDescriptor_t* GetDescriptor() { return mpAPI; }\r
175   _QERPlugImageTable* GetTable() { return mpTable; }\r
176   \r
177   /*!\r
178   don't go through PrepareRequireAPI for init, just get this API and add the table info\r
179   */\r
180   void InitForFillAPITable(APIDescriptor_t *pAPI);\r
181 };\r
182 \r
183 class CRadiantImageManager : public CSynapseAPIManager\r
184 {\r
185   list<CImageTableSlot *> mSlots;\r
186   \r
187   list<CImageTableSlot *>::iterator mExtScanSlot;\r
188 public:\r
189   CRadiantImageManager() {}\r
190   virtual ~CRadiantImageManager();\r
191   \r
192   // CSynapseAPIManager interface --------------------\r
193   void FillAPITable(APIDescriptor_t *pAPI);\r
194 \r
195   // CRadiantImageManager ----------------------------\r
196   /*!\r
197   extract the extension, go through the list of image interfaces, and load\r
198   */\r
199   void LoadImage(const char *name, byte **pic, int *width, int *height);\r
200     \r
201   /*!\r
202   we often need to walk through the extensions\r
203   this used to be hardcoded in texwindow.cpp\r
204   the two functions are related, they use a static to go through the list\r
205   */\r
206   void BeginExtensionsScan();\r
207   const char* GetNextExtension(); ///< \return NULL when the list has been completely scanned\r
208 };\r
209 \r
210 extern CRadiantImageManager g_ImageManager;\r
211 \r
212 #endif // _PLUGINMANAGER_H_\r