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
24 #include "debugging/debugging.h"
26 #include "qerplugin.h"
27 #include "ifilesystem.h"
32 #include "iscenegraph.h"
33 #include "iselection.h"
35 #include "iscriplib.h"
38 #include "itextures.h"
39 #include "ireference.h"
40 #include "ifiletypes.h"
41 #include "preferencesystem.h"
48 #include "namespace.h"
50 #include "gtkutil/messagebox.h"
51 #include "gtkutil/filechooser.h"
57 #include "entityinspector.h"
58 #include "entitylist.h"
61 #include "texwindow.h"
62 #include "mainframe.h"
66 #include "surfacedialog.h"
67 #include "groupdialog.h"
68 #include "patchdialog.h"
69 #include "camwindow.h"
74 #include "preferences.h"
76 #include "plugintoolbar.h"
77 #include "findtexturedialog.h"
78 #include "nullmodel.h"
81 #include "modulesystem/modulesmap.h"
82 #include "modulesystem/singletonmodule.h"
84 #include "generic/callback.h"
86 const char* GameDescription_getKeyValue(const char* key)
88 return g_pGameDescription->getKeyValue(key);
91 const char* GameDescription_getRequiredKeyValue(const char* key)
93 return g_pGameDescription->getRequiredKeyValue(key);
96 const char* getMapName()
98 return Map_Name(g_map);
101 scene::Node& getMapWorldEntity()
103 return Map_FindOrInsertWorldspawn(g_map);
106 VIEWTYPE XYWindow_getViewType()
108 return g_pParentWnd->GetXYWnd()->GetViewType();
111 Vector3 XYWindow_windowToWorld(const WindowVector& position)
113 Vector3 result(0, 0, 0);
114 g_pParentWnd->GetXYWnd()->XY_ToPoint(static_cast<int>(position.x()), static_cast<int>(position.y()), result);
118 const char* TextureBrowser_getSelectedShader()
120 return TextureBrowser_GetSelectedShader(GlobalTextureBrowser());
125 _QERFuncTable_1 m_radiantcore;
127 typedef _QERFuncTable_1 Type;
128 STRING_CONSTANT(Name, "*");
132 m_radiantcore.getEnginePath = &EnginePath_get;
133 m_radiantcore.getAppPath = &AppPath_get;
134 m_radiantcore.getGameToolsPath = &GameToolsPath_get;
135 m_radiantcore.getSettingsPath = &SettingsPath_get;
137 m_radiantcore.getGameName = &gamename_get;
138 m_radiantcore.getGameMode = &gamemode_get;
140 m_radiantcore.getMapName = &getMapName;
141 m_radiantcore.getMapWorldEntity = getMapWorldEntity;
142 m_radiantcore.getGridSize = GetGridSize;
144 m_radiantcore.getGameDescriptionKeyValue = &GameDescription_getKeyValue;
145 m_radiantcore.getRequiredGameDescriptionKeyValue = &GameDescription_getRequiredKeyValue;
147 m_radiantcore.attachGameToolsPathObserver = Radiant_attachGameToolsPathObserver;
148 m_radiantcore.detachGameToolsPathObserver = Radiant_detachGameToolsPathObserver;
149 m_radiantcore.attachEnginePathObserver = Radiant_attachEnginePathObserver;
150 m_radiantcore.detachEnginePathObserver = Radiant_detachEnginePathObserver;
151 m_radiantcore.attachGameNameObserver = Radiant_attachGameNameObserver;
152 m_radiantcore.detachGameNameObserver = Radiant_detachGameNameObserver;
153 m_radiantcore.attachGameModeObserver = Radiant_attachGameModeObserver;
154 m_radiantcore.detachGameModeObserver = Radiant_detachGameModeObserver;
156 m_radiantcore.XYWindowMouseDown_connect = XYWindowMouseDown_connect;
157 m_radiantcore.XYWindowMouseDown_disconnect = XYWindowMouseDown_disconnect;
158 m_radiantcore.XYWindow_getViewType = XYWindow_getViewType;
159 m_radiantcore.XYWindow_windowToWorld = XYWindow_windowToWorld;
160 m_radiantcore.TextureBrowser_getSelectedShader = TextureBrowser_getSelectedShader;
162 m_radiantcore.m_pfnMessageBox = >k_MessageBox;
163 m_radiantcore.m_pfnFileDialog = &file_dialog;
164 m_radiantcore.m_pfnColorDialog = &color_dialog;
165 m_radiantcore.m_pfnDirDialog = &dir_dialog;
166 m_radiantcore.m_pfnNewImage = &new_plugin_image;
168 _QERFuncTable_1* getTable()
170 return &m_radiantcore;
174 typedef SingletonModule<RadiantCoreAPI> RadiantCoreModule;
175 typedef Static<RadiantCoreModule> StaticRadiantCoreModule;
176 StaticRegisterModule staticRegisterRadiantCore(StaticRadiantCoreModule::instance());
179 class RadiantDependencies :
180 public GlobalRadiantModuleRef,
181 public GlobalFileSystemModuleRef,
182 public GlobalEntityModuleRef,
183 public GlobalShadersModuleRef,
184 public GlobalBrushModuleRef,
185 public GlobalSceneGraphModuleRef,
186 public GlobalShaderCacheModuleRef,
187 public GlobalFiletypesModuleRef,
188 public GlobalSelectionModuleRef,
189 public GlobalReferenceModuleRef,
190 public GlobalOpenGLModuleRef,
191 public GlobalEntityClassManagerModuleRef,
192 public GlobalUndoModuleRef,
193 public GlobalScripLibModuleRef,
194 public GlobalNamespaceModuleRef
196 ImageModulesRef m_image_modules;
197 MapModulesRef m_map_modules;
198 ToolbarModulesRef m_toolbar_modules;
199 PluginModulesRef m_plugin_modules;
202 RadiantDependencies() :
203 GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
204 GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders")),
205 GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes")),
206 GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass")),
207 m_image_modules(GlobalRadiant().getRequiredGameDescriptionKeyValue("texturetypes")),
208 m_map_modules(GlobalRadiant().getRequiredGameDescriptionKeyValue("maptypes")),
209 m_toolbar_modules("*"),
210 m_plugin_modules("*")
214 ImageModules& getImageModules()
216 return m_image_modules.get();
218 MapModules& getMapModules()
220 return m_map_modules.get();
222 ToolbarModules& getToolbarModules()
224 return m_toolbar_modules.get();
226 PluginModules& getPluginModules()
228 return m_plugin_modules.get();
232 class Radiant : public TypeSystemRef
239 GlobalFiletypes().addType("sound", "wav", filetype_t("PCM sound files", "*.wav"));
241 Selection_construct();
242 HomePaths_Construct();
245 MultiMon_Construct();
247 Pointfile_Construct();
248 GLWindow_Construct();
249 BuildMenu_Construct();
251 EntityList_Construct();
252 MainFrame_Construct();
253 GroupDialog_Construct();
254 SurfaceInspector_Construct();
255 PatchInspector_Construct();
257 XYWindow_Construct();
258 BuildMonitor_Construct();
259 TextureBrowser_Construct();
261 Autosave_Construct();
262 EntityInspector_construct();
263 FindTextureDialog_Construct();
264 NullModel_construct();
268 EnginePath_Realise();
272 EnginePath_Unrealise();
276 FindTextureDialog_Destroy();
277 EntityInspector_destroy();
280 TextureBrowser_Destroy();
281 BuildMonitor_Destroy();
284 PatchInspector_Destroy();
285 SurfaceInspector_Destroy();
286 GroupDialog_Destroy();
288 EntityList_Destroy();
304 bool g_RadiantInitialised = false;
305 RadiantDependencies* g_RadiantDependencies;
311 bool Radiant_Construct(ModuleServer& server)
313 GlobalModuleServer::instance().set(server);
314 StaticModuleRegistryList().instance().registerModules();
316 g_RadiantDependencies = new RadiantDependencies();
318 g_RadiantInitialised = !server.getError();
320 if(g_RadiantInitialised)
322 g_Radiant = new Radiant;
325 return g_RadiantInitialised;
327 void Radiant_Destroy()
329 if(g_RadiantInitialised)
334 delete g_RadiantDependencies;
337 ImageModules& Radiant_getImageModules()
339 return g_RadiantDependencies->getImageModules();
341 MapModules& Radiant_getMapModules()
343 return g_RadiantDependencies->getMapModules();
345 ToolbarModules& Radiant_getToolbarModules()
347 return g_RadiantDependencies->getToolbarModules();
349 PluginModules& Radiant_getPluginModules()
351 return g_RadiantDependencies->getPluginModules();