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