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.getLocalRcPath = &LocalRcPath_get;
134 m_radiantcore.getAppPath = &AppPath_get;
135 m_radiantcore.getGameToolsPath = &GameToolsPath_get;
136 m_radiantcore.getSettingsPath = &SettingsPath_get;
137 m_radiantcore.getMapsPath = &getMapsPath;
139 m_radiantcore.getGameName = &gamename_get;
140 m_radiantcore.getGameMode = &gamemode_get;
142 m_radiantcore.getMapName = &getMapName;
143 m_radiantcore.getMapWorldEntity = getMapWorldEntity;
144 m_radiantcore.getGridSize = GetGridSize;
146 m_radiantcore.getGameDescriptionKeyValue = &GameDescription_getKeyValue;
147 m_radiantcore.getRequiredGameDescriptionKeyValue = &GameDescription_getRequiredKeyValue;
149 m_radiantcore.attachGameToolsPathObserver = Radiant_attachGameToolsPathObserver;
150 m_radiantcore.detachGameToolsPathObserver = Radiant_detachGameToolsPathObserver;
151 m_radiantcore.attachEnginePathObserver = Radiant_attachEnginePathObserver;
152 m_radiantcore.detachEnginePathObserver = Radiant_detachEnginePathObserver;
153 m_radiantcore.attachGameNameObserver = Radiant_attachGameNameObserver;
154 m_radiantcore.detachGameNameObserver = Radiant_detachGameNameObserver;
155 m_radiantcore.attachGameModeObserver = Radiant_attachGameModeObserver;
156 m_radiantcore.detachGameModeObserver = Radiant_detachGameModeObserver;
158 m_radiantcore.XYWindowDestroyed_connect = XYWindowDestroyed_connect;
159 m_radiantcore.XYWindowDestroyed_disconnect = XYWindowDestroyed_disconnect;
160 m_radiantcore.XYWindowMouseDown_connect = XYWindowMouseDown_connect;
161 m_radiantcore.XYWindowMouseDown_disconnect = XYWindowMouseDown_disconnect;
162 m_radiantcore.XYWindow_getViewType = XYWindow_getViewType;
163 m_radiantcore.XYWindow_windowToWorld = XYWindow_windowToWorld;
164 m_radiantcore.TextureBrowser_getSelectedShader = TextureBrowser_getSelectedShader;
166 m_radiantcore.m_pfnMessageBox = >k_MessageBox;
167 m_radiantcore.m_pfnFileDialog = &file_dialog;
168 m_radiantcore.m_pfnColorDialog = &color_dialog;
169 m_radiantcore.m_pfnDirDialog = &dir_dialog;
170 m_radiantcore.m_pfnNewImage = &new_plugin_image;
172 _QERFuncTable_1* getTable()
174 return &m_radiantcore;
178 typedef SingletonModule<RadiantCoreAPI> RadiantCoreModule;
179 typedef Static<RadiantCoreModule> StaticRadiantCoreModule;
180 StaticRegisterModule staticRegisterRadiantCore(StaticRadiantCoreModule::instance());
183 class RadiantDependencies :
184 public GlobalRadiantModuleRef,
185 public GlobalFileSystemModuleRef,
186 public GlobalEntityModuleRef,
187 public GlobalShadersModuleRef,
188 public GlobalBrushModuleRef,
189 public GlobalSceneGraphModuleRef,
190 public GlobalShaderCacheModuleRef,
191 public GlobalFiletypesModuleRef,
192 public GlobalSelectionModuleRef,
193 public GlobalReferenceModuleRef,
194 public GlobalOpenGLModuleRef,
195 public GlobalEntityClassManagerModuleRef,
196 public GlobalUndoModuleRef,
197 public GlobalScripLibModuleRef,
198 public GlobalNamespaceModuleRef
200 ImageModulesRef m_image_modules;
201 MapModulesRef m_map_modules;
202 ToolbarModulesRef m_toolbar_modules;
203 PluginModulesRef m_plugin_modules;
206 RadiantDependencies() :
207 GlobalEntityModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entities")),
208 GlobalShadersModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("shaders")),
209 GlobalBrushModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("brushtypes")),
210 GlobalEntityClassManagerModuleRef(GlobalRadiant().getRequiredGameDescriptionKeyValue("entityclass")),
211 m_image_modules(GlobalRadiant().getRequiredGameDescriptionKeyValue("texturetypes")),
212 m_map_modules(GlobalRadiant().getRequiredGameDescriptionKeyValue("maptypes")),
213 m_toolbar_modules("*"),
214 m_plugin_modules("*")
218 ImageModules& getImageModules()
220 return m_image_modules.get();
222 MapModules& getMapModules()
224 return m_map_modules.get();
226 ToolbarModules& getToolbarModules()
228 return m_toolbar_modules.get();
230 PluginModules& getPluginModules()
232 return m_plugin_modules.get();
236 class Radiant : public TypeSystemRef
243 GlobalFiletypes().addType("sound", "wav", filetype_t("PCM sound files", "*.wav"));
245 Selection_construct();
246 HomePaths_Construct();
249 MultiMon_Construct();
251 Pointfile_Construct();
252 GLWindow_Construct();
253 BuildMenu_Construct();
255 EntityList_Construct();
256 MainFrame_Construct();
257 GroupDialog_Construct();
258 SurfaceInspector_Construct();
259 PatchInspector_Construct();
261 XYWindow_Construct();
262 BuildMonitor_Construct();
263 TextureBrowser_Construct();
265 Autosave_Construct();
266 EntityInspector_construct();
267 FindTextureDialog_Construct();
268 NullModel_construct();
272 EnginePath_Realise();
276 EnginePath_Unrealise();
280 FindTextureDialog_Destroy();
281 EntityInspector_destroy();
284 TextureBrowser_Destroy();
285 BuildMonitor_Destroy();
288 PatchInspector_Destroy();
289 SurfaceInspector_Destroy();
290 GroupDialog_Destroy();
292 EntityList_Destroy();
308 bool g_RadiantInitialised = false;
309 RadiantDependencies* g_RadiantDependencies;
315 bool Radiant_Construct(ModuleServer& server)
317 GlobalModuleServer::instance().set(server);
318 StaticModuleRegistryList().instance().registerModules();
320 g_RadiantDependencies = new RadiantDependencies();
322 g_RadiantInitialised = !server.getError();
324 if(g_RadiantInitialised)
326 g_Radiant = new Radiant;
329 return g_RadiantInitialised;
331 void Radiant_Destroy()
333 if(g_RadiantInitialised)
338 delete g_RadiantDependencies;
341 ImageModules& Radiant_getImageModules()
343 return g_RadiantDependencies->getImageModules();
345 MapModules& Radiant_getMapModules()
347 return g_RadiantDependencies->getMapModules();
349 ToolbarModules& Radiant_getToolbarModules()
351 return g_RadiantDependencies->getToolbarModules();
353 PluginModules& Radiant_getPluginModules()
355 return g_RadiantDependencies->getPluginModules();