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