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 "brushmodule.h"
24 #include "qerplugin.h"
26 #include "brushnode.h"
27 #include "brushmanip.h"
29 #include "preferencesystem.h"
34 #include "mainframe.h"
35 #include "preferences.h"
37 LatchedBool g_useAlternativeTextureProjection(false, "Use alternative texture-projection");
38 bool g_showAlternativeTextureProjectionOption = false;
39 bool g_brush_always_caulk;
41 bool getTextureLockEnabled()
43 return g_brush_texturelock_enabled;
46 void Face_importSnapPlanes(bool value)
48 Face::m_quantise = value ? quantiseInteger : quantiseFloating;
50 typedef FreeCaller1<bool, Face_importSnapPlanes> FaceImportSnapPlanesCaller;
52 void Face_exportSnapPlanes(const BoolImportCallback& importer)
54 importer(Face::m_quantise == quantiseInteger);
56 typedef FreeCaller1<const BoolImportCallback&, Face_exportSnapPlanes> FaceExportSnapPlanesCaller;
58 void Brush_constructPreferences(PreferencesPage& page)
61 "", "Snap planes to integer grid",
62 FaceImportSnapPlanesCaller(),
63 FaceExportSnapPlanesCaller()
66 "Default texture scale",
67 g_texdef_default_scale
69 if(g_showAlternativeTextureProjectionOption)
72 "", "Use alternative texture-projection",
73 LatchedBoolImportCaller(g_useAlternativeTextureProjection),
74 BoolExportCaller(g_useAlternativeTextureProjection.m_latched)
78 page.appendCheckBox("",
79 "Always use caulk for new brushes",
83 void Brush_constructPage(PreferenceGroup& group)
85 PreferencesPage page(group.createPage("Brush", "Brush Settings"));
86 Brush_constructPreferences(page);
88 void Brush_registerPreferencesPage()
90 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Brush_constructPage>());
93 void Brush_unlatchPreferences()
95 if(g_showAlternativeTextureProjectionOption)
97 g_useAlternativeTextureProjection.useLatched();
98 globalErrorStream() << "Unlatched g_useAlternativeTextureProjection (" << g_useAlternativeTextureProjection.m_value << ")\n";
99 Brush::destroyStatic();
100 Brush::constructStatic(g_useAlternativeTextureProjection.m_value ? eBrushTypeQuake3BP : eBrushTypeQuake3);
104 void Brush_Construct(EBrushType type)
106 if(type == eBrushTypeQuake3)
108 g_showAlternativeTextureProjectionOption = true;
110 GlobalPreferenceSystem().registerPreference(
111 "AlternativeTextureProjection",
112 BoolImportStringCaller(g_useAlternativeTextureProjection.m_latched),
113 BoolExportStringCaller(g_useAlternativeTextureProjection.m_latched)
115 g_useAlternativeTextureProjection.useLatched();
117 if(g_useAlternativeTextureProjection.m_value)
119 type = eBrushTypeQuake3BP;
123 GlobalPreferenceSystem().registerPreference(
125 BoolImportStringCaller(g_brush_always_caulk),
126 BoolExportStringCaller(g_brush_always_caulk));
129 Brush_registerCommands();
130 Brush_registerPreferencesPage();
132 BrushFilters_construct();
134 BrushClipPlane::constructStatic();
135 BrushInstance::constructStatic();
136 Brush::constructStatic(type);
138 Brush::m_maxWorldCoord = g_MaxWorldCoord;
139 BrushInstance::m_counter = &g_brushCount;
141 g_texdef_default_scale = 0.5f;
142 const char* value = g_pGameDescription->getKeyValue("default_scale");
143 if(!string_empty(value))
145 float scale = static_cast<float>(atof(value));
148 g_texdef_default_scale = scale;
152 globalErrorStream() << "error parsing \"default_scale\" attribute\n";
156 GlobalPreferenceSystem().registerPreference("TextureLock", BoolImportStringCaller(g_brush_texturelock_enabled), BoolExportStringCaller(g_brush_texturelock_enabled));
157 GlobalPreferenceSystem().registerPreference("BrushSnapPlanes", makeBoolStringImportCallback(FaceImportSnapPlanesCaller()), makeBoolStringExportCallback(FaceExportSnapPlanesCaller()));
158 GlobalPreferenceSystem().registerPreference("TexdefDefaultScale", FloatImportStringCaller(g_texdef_default_scale), FloatExportStringCaller(g_texdef_default_scale));
160 GridStatus_getTextureLockEnabled = getTextureLockEnabled;
161 g_texture_lock_status_changed = FreeCaller<GridStatus_onTextureLockEnabledChanged>();
166 Brush::m_maxWorldCoord = 0;
167 BrushInstance::m_counter = 0;
169 Brush::destroyStatic();
170 BrushInstance::destroyStatic();
171 BrushClipPlane::destroyStatic();
174 void Brush_clipperColourChanged()
176 BrushClipPlane::destroyStatic();
177 BrushClipPlane::constructStatic();
180 void BrushFaceData_fromFace(const BrushFaceDataCallback& callback, Face& face)
182 _QERFaceData faceData;
183 faceData.m_p0 = face.getPlane().planePoints()[0];
184 faceData.m_p1 = face.getPlane().planePoints()[1];
185 faceData.m_p2 = face.getPlane().planePoints()[2];
186 faceData.m_shader = face.GetShader();
187 faceData.m_texdef = face.getTexdef().m_projection.m_texdef;
188 faceData.contents = face.getShader().m_flags.m_contentFlags;
189 faceData.flags = face.getShader().m_flags.m_surfaceFlags;
190 faceData.value = face.getShader().m_flags.m_value;
193 typedef ConstReferenceCaller1<BrushFaceDataCallback, Face&, BrushFaceData_fromFace> BrushFaceDataFromFaceCaller;
194 typedef Callback1<Face&> FaceCallback;
196 class Quake3BrushCreator : public BrushCreator
199 scene::Node& createBrush()
201 return (new BrushNode)->node();
203 bool useAlternativeTextureProjection() const
205 return g_useAlternativeTextureProjection.m_value;
207 void Brush_forEachFace(scene::Node& brush, const BrushFaceDataCallback& callback)
209 ::Brush_forEachFace(*Node_getBrush(brush), FaceCallback(BrushFaceDataFromFaceCaller(callback)));
211 bool Brush_addFace(scene::Node& brush, const _QERFaceData& faceData)
213 Node_getBrush(brush)->undoSave();
214 return Node_getBrush(brush)->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_shader, TextureProjection(faceData.m_texdef, brushprimit_texdef_t(), Vector3(0, 0, 0), Vector3(0, 0, 0))) != 0;
218 Quake3BrushCreator g_Quake3BrushCreator;
220 BrushCreator& GetBrushCreator()
222 return g_Quake3BrushCreator;
225 #include "modulesystem/singletonmodule.h"
226 #include "modulesystem/moduleregistry.h"
229 class BrushDependencies :
230 public GlobalRadiantModuleRef,
231 public GlobalSceneGraphModuleRef,
232 public GlobalShaderCacheModuleRef,
233 public GlobalSelectionModuleRef,
234 public GlobalOpenGLModuleRef,
235 public GlobalUndoModuleRef,
236 public GlobalFilterModuleRef
240 class BrushDoom3API : public TypeSystemRef
242 BrushCreator* m_brushdoom3;
244 typedef BrushCreator Type;
245 STRING_CONSTANT(Name, "doom3");
249 Brush_Construct(eBrushTypeDoom3);
251 m_brushdoom3 = &GetBrushCreator();
257 BrushCreator* getTable()
263 typedef SingletonModule<BrushDoom3API, BrushDependencies> BrushDoom3Module;
264 typedef Static<BrushDoom3Module> StaticBrushDoom3Module;
265 StaticRegisterModule staticRegisterBrushDoom3(StaticBrushDoom3Module::instance());
268 class BrushQuake4API : public TypeSystemRef
270 BrushCreator* m_brushquake4;
272 typedef BrushCreator Type;
273 STRING_CONSTANT(Name, "quake4");
277 Brush_Construct(eBrushTypeQuake4);
279 m_brushquake4 = &GetBrushCreator();
285 BrushCreator* getTable()
287 return m_brushquake4;
291 typedef SingletonModule<BrushQuake4API, BrushDependencies> BrushQuake4Module;
292 typedef Static<BrushQuake4Module> StaticBrushQuake4Module;
293 StaticRegisterModule staticRegisterBrushQuake4(StaticBrushQuake4Module::instance());
296 class BrushQuake3API : public TypeSystemRef
298 BrushCreator* m_brushquake3;
300 typedef BrushCreator Type;
301 STRING_CONSTANT(Name, "quake3");
305 Brush_Construct(eBrushTypeQuake3);
307 m_brushquake3 = &GetBrushCreator();
313 BrushCreator* getTable()
315 return m_brushquake3;
319 typedef SingletonModule<BrushQuake3API, BrushDependencies> BrushQuake3Module;
320 typedef Static<BrushQuake3Module> StaticBrushQuake3Module;
321 StaticRegisterModule staticRegisterBrushQuake3(StaticBrushQuake3Module::instance());
324 class BrushQuake2API : public TypeSystemRef
326 BrushCreator* m_brushquake2;
328 typedef BrushCreator Type;
329 STRING_CONSTANT(Name, "quake2");
333 Brush_Construct(eBrushTypeQuake2);
335 m_brushquake2 = &GetBrushCreator();
341 BrushCreator* getTable()
343 return m_brushquake2;
347 typedef SingletonModule<BrushQuake2API, BrushDependencies> BrushQuake2Module;
348 typedef Static<BrushQuake2Module> StaticBrushQuake2Module;
349 StaticRegisterModule staticRegisterBrushQuake2(StaticBrushQuake2Module::instance());
352 class BrushQuake1API : public TypeSystemRef
354 BrushCreator* m_brushquake1;
356 typedef BrushCreator Type;
357 STRING_CONSTANT(Name, "quake");
361 Brush_Construct(eBrushTypeQuake);
363 m_brushquake1 = &GetBrushCreator();
369 BrushCreator* getTable()
371 return m_brushquake1;
375 typedef SingletonModule<BrushQuake1API, BrushDependencies> BrushQuake1Module;
376 typedef Static<BrushQuake1Module> StaticBrushQuake1Module;
377 StaticRegisterModule staticRegisterBrushQuake1(StaticBrushQuake1Module::instance());
380 class BrushHalfLifeAPI : public TypeSystemRef
382 BrushCreator* m_brushhalflife;
384 typedef BrushCreator Type;
385 STRING_CONSTANT(Name, "halflife");
389 Brush_Construct(eBrushTypeHalfLife);
391 m_brushhalflife = &GetBrushCreator();
397 BrushCreator* getTable()
399 return m_brushhalflife;
403 typedef SingletonModule<BrushHalfLifeAPI, BrushDependencies> BrushHalfLifeModule;
404 typedef Static<BrushHalfLifeModule> StaticBrushHalfLifeModule;
405 StaticRegisterModule staticRegisterBrushHalfLife(StaticBrushHalfLifeModule::instance());