]> git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/md3model/plugin.cpp
reformat code! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / plugins / md3model / plugin.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 "iscenegraph.h"
23 #include "irender.h"
24 #include "iselection.h"
25 #include "iimage.h"
26 #include "imodel.h"
27 #include "igl.h"
28 #include "ifilesystem.h"
29 #include "iundo.h"
30 #include "ifiletypes.h"
31 #include "iscriplib.h"
32
33 #include "modulesystem/singletonmodule.h"
34 #include "typesystem.h"
35
36 #include "md3.h"
37 #include "mdl.h"
38 #include "md2.h"
39 #include "mdc.h"
40 #include "mdlimage.h"
41 #include "md5.h"
42
43
44 class MD3ModelLoader : public ModelLoader {
45 public:
46     scene::Node &loadModel(ArchiveFile &file)
47     {
48         return loadMD3Model(file);
49     }
50 };
51
52 class ModelDependencies :
53         public GlobalFileSystemModuleRef,
54         public GlobalOpenGLModuleRef,
55         public GlobalUndoModuleRef,
56         public GlobalSceneGraphModuleRef,
57         public GlobalShaderCacheModuleRef,
58         public GlobalSelectionModuleRef,
59         public GlobalFiletypesModuleRef {
60 };
61
62 class ModelMD3API : public TypeSystemRef {
63     MD3ModelLoader m_modelmd3;
64 public:
65     typedef ModelLoader Type;
66
67     STRING_CONSTANT(Name, "md3");
68
69     ModelMD3API()
70     {
71         GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("md3 models", "*.md3"));
72     }
73
74     ModelLoader *getTable()
75     {
76         return &m_modelmd3;
77     }
78 };
79
80 typedef SingletonModule<ModelMD3API, ModelDependencies> ModelMD3Module;
81
82 ModelMD3Module g_ModelMD3Module;
83
84
85 class MD2ModelLoader : public ModelLoader {
86 public:
87     scene::Node &loadModel(ArchiveFile &file)
88     {
89         return loadMD2Model(file);
90     }
91 };
92
93 class ModelMD2API : public TypeSystemRef {
94     MD2ModelLoader m_modelmd2;
95 public:
96     typedef ModelLoader Type;
97
98     STRING_CONSTANT(Name, "md2");
99
100     ModelMD2API()
101     {
102         GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("md2 models", "*.md2"));
103     }
104
105     ModelLoader *getTable()
106     {
107         return &m_modelmd2;
108     }
109 };
110
111 typedef SingletonModule<ModelMD2API, ModelDependencies> ModelMD2Module;
112
113 ModelMD2Module g_ModelMD2Module;
114
115 class MDLModelLoader : public ModelLoader {
116 public:
117     scene::Node &loadModel(ArchiveFile &file)
118     {
119         return loadMDLModel(file);
120     }
121 };
122
123 class ModelMDLAPI : public TypeSystemRef {
124     MDLModelLoader m_modelmdl;
125 public:
126     typedef ModelLoader Type;
127
128     STRING_CONSTANT(Name, "mdl");
129
130     ModelMDLAPI()
131     {
132         GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("mdl models", "*.mdl"));
133     }
134
135     ModelLoader *getTable()
136     {
137         return &m_modelmdl;
138     }
139 };
140
141 typedef SingletonModule<ModelMDLAPI, ModelDependencies> ModelMDLModule;
142
143 ModelMDLModule g_ModelMDLModule;
144
145 class MDCModelLoader : public ModelLoader {
146 public:
147     scene::Node &loadModel(ArchiveFile &file)
148     {
149         return loadMDCModel(file);
150     }
151 };
152
153 class ModelMDCAPI : public TypeSystemRef {
154     MDCModelLoader m_modelmdc;
155 public:
156     typedef ModelLoader Type;
157
158     STRING_CONSTANT(Name, "mdc");
159
160     ModelMDCAPI()
161     {
162         GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("mdc models", "*.mdc"));
163     }
164
165     ModelLoader *getTable()
166     {
167         return &m_modelmdc;
168     }
169 };
170
171 typedef SingletonModule<ModelMDCAPI, ModelDependencies> ModelMDCModule;
172
173 ModelMDCModule g_ModelMDCModule;
174
175
176 class ImageMDLAPI {
177     _QERPlugImageTable m_imagemdl;
178 public:
179     typedef _QERPlugImageTable Type;
180
181     STRING_CONSTANT(Name, "mdl");
182
183     ImageMDLAPI()
184     {
185         m_imagemdl.loadImage = &LoadMDLImage;
186     }
187
188     _QERPlugImageTable *getTable()
189     {
190         return &m_imagemdl;
191     }
192 };
193
194 typedef SingletonModule<ImageMDLAPI, GlobalFileSystemModuleRef> ImageMDLModule;
195
196 ImageMDLModule g_ImageMDLModule;
197
198
199 class MD5ModelLoader : public ModelLoader {
200 public:
201     scene::Node &loadModel(ArchiveFile &file)
202     {
203         return loadMD5Model(file);
204     }
205 };
206
207 class ModelMD5Dependencies : public ModelDependencies, public GlobalScripLibModuleRef {
208 };
209
210 class ModelMD5API : public TypeSystemRef {
211     MD5ModelLoader m_modelmd5;
212 public:
213     typedef ModelLoader Type;
214
215     STRING_CONSTANT(Name, "md5mesh");
216
217     ModelMD5API()
218     {
219         GlobalFiletypesModule::getTable().addType(Type::Name(), Name(), filetype_t("md5 meshes", "*.md5mesh"));
220     }
221
222     ModelLoader *getTable()
223     {
224         return &m_modelmd5;
225     }
226 };
227
228 typedef SingletonModule<ModelMD5API, ModelMD5Dependencies> ModelMD5Module;
229
230 ModelMD5Module g_ModelMD5Module;
231
232
233 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer &server)
234 {
235     initialiseModule(server);
236
237     g_ModelMD3Module.selfRegister();
238     g_ModelMD2Module.selfRegister();
239     g_ModelMDLModule.selfRegister();
240     g_ModelMDCModule.selfRegister();
241     g_ImageMDLModule.selfRegister();
242     g_ModelMD5Module.selfRegister();
243 }