]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchmodule.cpp
bumping revision because of file with accidentally wrong rev released
[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 CommonPatchCreator : public PatchCreator
73 {
74 public:
75   void Patch_undoSave(scene::Node& patch) const
76   {
77     Node_getPatch(patch)->undoSave();
78   }
79   void Patch_resize(scene::Node& patch, std::size_t width, std::size_t height) const
80   {
81     Node_getPatch(patch)->setDims(width, height);
82   }
83   PatchControlMatrix Patch_getControlPoints(scene::Node& node) const
84   {
85     Patch& patch = *Node_getPatch(node);
86     return PatchControlMatrix(patch.getHeight(), patch.getWidth(), patch.getControlPoints().data());
87   }
88   void Patch_controlPointsChanged(scene::Node& patch) const
89   {
90     return Node_getPatch(patch)->controlPointsChanged();
91   }
92   const char* Patch_getShader(scene::Node& patch) const
93   {
94     return Node_getPatch(patch)->GetShader();
95   }
96   void Patch_setShader(scene::Node& patch, const char* shader) const
97   {
98     Node_getPatch(patch)->SetShader(shader);
99   }
100 };
101
102 class Quake3PatchCreator : public CommonPatchCreator
103 {
104 public:
105   scene::Node& createPatch()
106   {
107     return (new PatchNodeQuake3())->node();
108   }
109 };
110
111 Quake3PatchCreator g_Quake3PatchCreator;
112
113 PatchCreator& GetQuake3PatchCreator()
114 {
115   return g_Quake3PatchCreator;
116 }
117
118 class Doom3PatchCreator : public CommonPatchCreator
119 {
120 public:
121   scene::Node& createPatch()
122   {
123     return (new PatchNodeDoom3(true))->node();
124   }
125 };
126
127 Doom3PatchCreator g_Doom3PatchCreator;
128
129 PatchCreator& GetDoom3PatchCreator()
130 {
131   return g_Doom3PatchCreator;
132 }
133
134 class Doom3PatchDef2Creator : public CommonPatchCreator
135 {
136 public:
137   scene::Node& createPatch()
138   {
139     return (new PatchNodeDoom3())->node();
140   }
141 };
142
143 Doom3PatchDef2Creator g_Doom3PatchDef2Creator;
144
145 PatchCreator& GetDoom3PatchDef2Creator()
146 {
147   return g_Doom3PatchDef2Creator;
148 }
149
150 #include "modulesystem/singletonmodule.h"
151 #include "modulesystem/moduleregistry.h"
152
153 class PatchDependencies :
154   public GlobalRadiantModuleRef,
155   public GlobalSceneGraphModuleRef,
156   public GlobalShaderCacheModuleRef,
157   public GlobalSelectionModuleRef,
158   public GlobalOpenGLModuleRef,
159   public GlobalUndoModuleRef,
160   public GlobalFilterModuleRef
161 {
162 };
163
164 class PatchQuake3API : public TypeSystemRef
165 {
166   PatchCreator* m_patchquake3;
167 public:
168   typedef PatchCreator Type;
169   STRING_CONSTANT(Name, "quake3");
170
171   PatchQuake3API()
172   {
173     Patch_Construct(ePatchTypeQuake3);
174  
175     m_patchquake3 = &GetQuake3PatchCreator();
176     g_patchCreator = m_patchquake3;
177   }
178   ~PatchQuake3API()
179   {
180     Patch_Destroy();
181   }
182   PatchCreator* getTable()
183   {
184     return m_patchquake3;
185   }
186 };
187
188 typedef SingletonModule<PatchQuake3API, PatchDependencies> PatchQuake3Module;
189 typedef Static<PatchQuake3Module> StaticPatchQuake3Module;
190 StaticRegisterModule staticRegisterPatchQuake3(StaticPatchQuake3Module::instance());
191
192
193
194 class PatchDoom3API : public TypeSystemRef
195 {
196   PatchCreator* m_patchdoom3;
197 public:
198   typedef PatchCreator Type;
199   STRING_CONSTANT(Name, "doom3");
200
201   PatchDoom3API()
202   {
203     Patch_Construct(ePatchTypeDoom3);
204
205     m_patchdoom3 = &GetDoom3PatchCreator();
206   }
207   ~PatchDoom3API()
208   {
209     Patch_Destroy();
210   }
211   PatchCreator* getTable()
212   {
213     return m_patchdoom3;
214   }
215 };
216
217 typedef SingletonModule<PatchDoom3API, PatchDependencies> PatchDoom3Module;
218 typedef Static<PatchDoom3Module> StaticPatchDoom3Module;
219 StaticRegisterModule staticRegisterPatchDoom3(StaticPatchDoom3Module::instance());
220
221
222 class PatchDef2Doom3API : public TypeSystemRef
223 {
224   PatchCreator* m_patchdef2doom3;
225 public:
226   typedef PatchCreator Type;
227   STRING_CONSTANT(Name, "def2doom3");
228
229   PatchDef2Doom3API()
230   {
231     Patch_Construct(ePatchTypeDoom3);
232
233     m_patchdef2doom3 = &GetDoom3PatchDef2Creator();
234     g_patchCreator = m_patchdef2doom3;
235   }
236   ~PatchDef2Doom3API()
237   {
238     Patch_Destroy();
239   }
240   PatchCreator* getTable()
241   {
242     return m_patchdef2doom3;
243   }
244 };
245
246 typedef SingletonModule<PatchDef2Doom3API, PatchDependencies> PatchDef2Doom3Module;
247 typedef Static<PatchDef2Doom3Module> StaticPatchDef2Doom3Module;
248 StaticRegisterModule staticRegisterPatchDef2Doom3(StaticPatchDef2Doom3Module::instance());
249
250
251