]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchmodule.cpp
refactored plugin api; refactored callback library; added signals library
[xonotic/netradiant.git] / radiant / patchmodule.cpp
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 #include "patchmodule.h"
23
24 #include "qerplugin.h"
25 #include "ipatch.h"
26
27 #include "patch.h"
28 #include "patchmanip.h"
29
30 namespace
31 {
32   std::size_t g_patchModuleCount = 0;
33 }
34
35 void Patch_Construct(EPatchType type)
36 {
37   if(++g_patchModuleCount != 1)
38   {
39     return;
40   }
41
42   PatchFilters_construct();
43
44   PatchPreferences_construct();
45
46   Patch_registerPreferencesPage();
47
48   Patch::constructStatic(type);
49   PatchInstance::constructStatic();
50
51   if(type == ePatchTypeDoom3)
52   {
53     MAX_PATCH_WIDTH = MAX_PATCH_HEIGHT = 99;
54   }
55   else
56   {
57     MAX_PATCH_WIDTH = MAX_PATCH_HEIGHT = 15;
58   }
59 }
60
61 void Patch_Destroy()
62 {
63   if(--g_patchModuleCount != 0)
64   {
65     return;
66   }
67
68   Patch::destroyStatic();
69   PatchInstance::destroyStatic();
70 }
71
72 class Quake3PatchCreator : public PatchCreator
73 {
74 public:
75   scene::Node& createPatch()
76   {
77     return (new PatchNodeQuake3())->node();
78   }
79 };
80
81 Quake3PatchCreator g_Quake3PatchCreator;
82
83 PatchCreator& GetQuake3PatchCreator()
84 {
85   return g_Quake3PatchCreator;
86 }
87
88 class Doom3PatchCreator : public PatchCreator
89 {
90 public:
91   scene::Node& createPatch()
92   {
93     return (new PatchNodeDoom3(true))->node();
94   }
95 };
96
97 Doom3PatchCreator g_Doom3PatchCreator;
98
99 PatchCreator& GetDoom3PatchCreator()
100 {
101   return g_Doom3PatchCreator;
102 }
103
104 class Doom3PatchDef2Creator : public PatchCreator
105 {
106 public:
107   scene::Node& createPatch()
108   {
109     return (new PatchNodeDoom3())->node();
110   }
111 };
112
113 Doom3PatchDef2Creator g_Doom3PatchDef2Creator;
114
115 PatchCreator& GetDoom3PatchDef2Creator()
116 {
117   return g_Doom3PatchDef2Creator;
118 }
119
120 #include "modulesystem/singletonmodule.h"
121 #include "modulesystem/moduleregistry.h"
122
123 class PatchDependencies :
124   public GlobalRadiantModuleRef,
125   public GlobalSceneGraphModuleRef,
126   public GlobalShaderCacheModuleRef,
127   public GlobalSelectionModuleRef,
128   public GlobalOpenGLModuleRef,
129   public GlobalUndoModuleRef,
130   public GlobalFilterModuleRef
131 {
132 };
133
134 class PatchQuake3API : public TypeSystemRef
135 {
136   PatchCreator* m_patchquake3;
137 public:
138   typedef PatchCreator Type;
139   STRING_CONSTANT(Name, "quake3");
140
141   PatchQuake3API()
142   {
143     Patch_Construct(ePatchTypeQuake3);
144  
145     m_patchquake3 = &GetQuake3PatchCreator();
146     g_patchCreator = m_patchquake3;
147   }
148   ~PatchQuake3API()
149   {
150     Patch_Destroy();
151   }
152   PatchCreator* getTable()
153   {
154     return m_patchquake3;
155   }
156 };
157
158 typedef SingletonModule<PatchQuake3API, PatchDependencies> PatchQuake3Module;
159 typedef Static<PatchQuake3Module> StaticPatchQuake3Module;
160 StaticRegisterModule staticRegisterPatchQuake3(StaticPatchQuake3Module::instance());
161
162
163
164 class PatchDoom3API : public TypeSystemRef
165 {
166   PatchCreator* m_patchdoom3;
167 public:
168   typedef PatchCreator Type;
169   STRING_CONSTANT(Name, "doom3");
170
171   PatchDoom3API()
172   {
173     Patch_Construct(ePatchTypeDoom3);
174
175     m_patchdoom3 = &GetDoom3PatchCreator();
176   }
177   ~PatchDoom3API()
178   {
179     Patch_Destroy();
180   }
181   PatchCreator* getTable()
182   {
183     return m_patchdoom3;
184   }
185 };
186
187 typedef SingletonModule<PatchDoom3API, PatchDependencies> PatchDoom3Module;
188 typedef Static<PatchDoom3Module> StaticPatchDoom3Module;
189 StaticRegisterModule staticRegisterPatchDoom3(StaticPatchDoom3Module::instance());
190
191
192 class PatchDef2Doom3API : public TypeSystemRef
193 {
194   PatchCreator* m_patchdef2doom3;
195 public:
196   typedef PatchCreator Type;
197   STRING_CONSTANT(Name, "def2doom3");
198
199   PatchDef2Doom3API()
200   {
201     Patch_Construct(ePatchTypeDoom3);
202
203     m_patchdef2doom3 = &GetDoom3PatchDef2Creator();
204     g_patchCreator = m_patchdef2doom3;
205   }
206   ~PatchDef2Doom3API()
207   {
208     Patch_Destroy();
209   }
210   PatchCreator* getTable()
211   {
212     return m_patchdef2doom3;
213   }
214 };
215
216 typedef SingletonModule<PatchDef2Doom3API, PatchDependencies> PatchDef2Doom3Module;
217 typedef Static<PatchDef2Doom3Module> StaticPatchDef2Doom3Module;
218 StaticRegisterModule staticRegisterPatchDef2Doom3(StaticPatchDef2Doom3Module::instance());
219
220
221