2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
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.
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.
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
22 #include "patchmodule.h"
24 #include "qerplugin.h"
28 #include "patchmanip.h"
31 std::size_t g_patchModuleCount = 0;
34 void Patch_Construct(EPatchType type)
36 if (++g_patchModuleCount != 1) {
40 PatchFilters_construct();
42 PatchPreferences_construct();
44 Patch_registerPreferencesPage();
46 Patch::constructStatic(type);
47 PatchInstance::constructStatic();
49 if (type == ePatchTypeDoom3) {
50 MAX_PATCH_WIDTH = MAX_PATCH_HEIGHT = 99;
52 MAX_PATCH_WIDTH = MAX_PATCH_HEIGHT = 31; // matching q3map2
58 if (--g_patchModuleCount != 0) {
62 Patch::destroyStatic();
63 PatchInstance::destroyStatic();
66 class CommonPatchCreator : public PatchCreator {
68 void Patch_undoSave(scene::Node &patch) const
70 Node_getPatch(patch)->undoSave();
73 void Patch_resize(scene::Node &patch, std::size_t width, std::size_t height) const
75 Node_getPatch(patch)->setDims(width, height);
78 PatchControlMatrix Patch_getControlPoints(scene::Node &node) const
80 Patch &patch = *Node_getPatch(node);
81 return PatchControlMatrix(patch.getHeight(), patch.getWidth(), patch.getControlPoints().data());
84 void Patch_controlPointsChanged(scene::Node &patch) const
86 return Node_getPatch(patch)->controlPointsChanged();
89 const char *Patch_getShader(scene::Node &patch) const
91 return Node_getPatch(patch)->GetShader();
94 void Patch_setShader(scene::Node &patch, const char *shader) const
96 Node_getPatch(patch)->SetShader(shader);
100 class Quake3PatchCreator : public CommonPatchCreator {
102 scene::Node &createPatch()
104 return (new PatchNodeQuake3())->node();
108 Quake3PatchCreator g_Quake3PatchCreator;
110 PatchCreator &GetQuake3PatchCreator()
112 return g_Quake3PatchCreator;
115 class Doom3PatchCreator : public CommonPatchCreator {
117 scene::Node &createPatch()
119 return (new PatchNodeDoom3(true))->node();
123 Doom3PatchCreator g_Doom3PatchCreator;
125 PatchCreator &GetDoom3PatchCreator()
127 return g_Doom3PatchCreator;
130 class Doom3PatchDef2Creator : public CommonPatchCreator {
132 scene::Node &createPatch()
134 return (new PatchNodeDoom3())->node();
138 Doom3PatchDef2Creator g_Doom3PatchDef2Creator;
140 PatchCreator &GetDoom3PatchDef2Creator()
142 return g_Doom3PatchDef2Creator;
145 #include "modulesystem/singletonmodule.h"
146 #include "modulesystem/moduleregistry.h"
148 class PatchDependencies :
149 public GlobalRadiantModuleRef,
150 public GlobalSceneGraphModuleRef,
151 public GlobalShaderCacheModuleRef,
152 public GlobalSelectionModuleRef,
153 public GlobalOpenGLModuleRef,
154 public GlobalUndoModuleRef,
155 public GlobalFilterModuleRef {
158 class PatchQuake3API : public TypeSystemRef {
159 PatchCreator *m_patchquake3;
161 typedef PatchCreator Type;
163 STRING_CONSTANT(Name, "quake3");
167 Patch_Construct(ePatchTypeQuake3);
169 m_patchquake3 = &GetQuake3PatchCreator();
170 g_patchCreator = m_patchquake3;
178 PatchCreator *getTable()
180 return m_patchquake3;
184 typedef SingletonModule<PatchQuake3API, PatchDependencies> PatchQuake3Module;
185 typedef Static<PatchQuake3Module> StaticPatchQuake3Module;
186 StaticRegisterModule staticRegisterPatchQuake3(StaticPatchQuake3Module::instance());
189 class PatchDoom3API : public TypeSystemRef {
190 PatchCreator *m_patchdoom3;
192 typedef PatchCreator Type;
194 STRING_CONSTANT(Name, "doom3");
198 Patch_Construct(ePatchTypeDoom3);
200 m_patchdoom3 = &GetDoom3PatchCreator();
208 PatchCreator *getTable()
214 typedef SingletonModule<PatchDoom3API, PatchDependencies> PatchDoom3Module;
215 typedef Static<PatchDoom3Module> StaticPatchDoom3Module;
216 StaticRegisterModule staticRegisterPatchDoom3(StaticPatchDoom3Module::instance());
219 class PatchDef2Doom3API : public TypeSystemRef {
220 PatchCreator *m_patchdef2doom3;
222 typedef PatchCreator Type;
224 STRING_CONSTANT(Name, "def2doom3");
228 Patch_Construct(ePatchTypeDoom3);
230 m_patchdef2doom3 = &GetDoom3PatchDef2Creator();
231 g_patchCreator = m_patchdef2doom3;
239 PatchCreator *getTable()
241 return m_patchdef2doom3;
245 typedef SingletonModule<PatchDef2Doom3API, PatchDependencies> PatchDef2Doom3Module;
246 typedef Static<PatchDef2Doom3Module> StaticPatchDef2Doom3Module;
247 StaticRegisterModule staticRegisterPatchDef2Doom3(StaticPatchDef2Doom3Module::instance());