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 ){
87 return g_pGameDescription->getKeyValue( key );
90 const char* GameDescription_getRequiredKeyValue( const char* key ){
91 return g_pGameDescription->getRequiredKeyValue( key );
94 const char* getMapName(){
95 return Map_Name( g_map );
98 scene::Node& getMapWorldEntity(){
99 return Map_FindOrInsertWorldspawn( g_map );
102 VIEWTYPE XYWindow_getViewType(){
103 return g_pParentWnd->GetXYWnd()->GetViewType();
106 Vector3 XYWindow_windowToWorld( const WindowVector& position ){
107 Vector3 result( 0, 0, 0 );
108 g_pParentWnd->GetXYWnd()->XY_ToPoint( static_cast<int>( position.x() ), static_cast<int>( position.y() ), result );
112 const char* TextureBrowser_getSelectedShader(){
113 return TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
118 _QERFuncTable_1 m_radiantcore;
120 typedef _QERFuncTable_1 Type;
121 STRING_CONSTANT( Name, "*" );
124 m_radiantcore.getEnginePath = &EnginePath_get;
125 m_radiantcore.getLocalRcPath = &LocalRcPath_get;
126 m_radiantcore.getAppPath = &AppPath_get;
127 m_radiantcore.getGameToolsPath = &GameToolsPath_get;
128 m_radiantcore.getSettingsPath = &SettingsPath_get;
129 m_radiantcore.getMapsPath = &getMapsPath;
131 m_radiantcore.getGameName = &gamename_get;
132 m_radiantcore.getGameMode = &gamemode_get;
134 m_radiantcore.getMapName = &getMapName;
135 m_radiantcore.getMapWorldEntity = getMapWorldEntity;
136 m_radiantcore.getGridSize = GetGridSize;
138 m_radiantcore.getGameDescriptionKeyValue = &GameDescription_getKeyValue;
139 m_radiantcore.getRequiredGameDescriptionKeyValue = &GameDescription_getRequiredKeyValue;
141 m_radiantcore.attachGameToolsPathObserver = Radiant_attachGameToolsPathObserver;
142 m_radiantcore.detachGameToolsPathObserver = Radiant_detachGameToolsPathObserver;
143 m_radiantcore.attachEnginePathObserver = Radiant_attachEnginePathObserver;
144 m_radiantcore.detachEnginePathObserver = Radiant_detachEnginePathObserver;
145 m_radiantcore.attachGameNameObserver = Radiant_attachGameNameObserver;
146 m_radiantcore.detachGameNameObserver = Radiant_detachGameNameObserver;
147 m_radiantcore.attachGameModeObserver = Radiant_attachGameModeObserver;
148 m_radiantcore.detachGameModeObserver = Radiant_detachGameModeObserver;
150 m_radiantcore.XYWindowDestroyed_connect = XYWindowDestroyed_connect;
151 m_radiantcore.XYWindowDestroyed_disconnect = XYWindowDestroyed_disconnect;
152 m_radiantcore.XYWindowMouseDown_connect = XYWindowMouseDown_connect;
153 m_radiantcore.XYWindowMouseDown_disconnect = XYWindowMouseDown_disconnect;
154 m_radiantcore.XYWindow_getViewType = XYWindow_getViewType;
155 m_radiantcore.XYWindow_windowToWorld = XYWindow_windowToWorld;
156 m_radiantcore.TextureBrowser_getSelectedShader = TextureBrowser_getSelectedShader;
158 m_radiantcore.m_pfnMessageBox = >k_MessageBox;
159 m_radiantcore.m_pfnFileDialog = &file_dialog;
160 m_radiantcore.m_pfnColorDialog = &color_dialog;
161 m_radiantcore.m_pfnDirDialog = &dir_dialog;
162 m_radiantcore.m_pfnNewImage = &new_plugin_image;
164 _QERFuncTable_1* getTable(){
165 return &m_radiantcore;
169 typedef SingletonModule<RadiantCoreAPI> RadiantCoreModule;
170 typedef Static<RadiantCoreModule> StaticRadiantCoreModule;
171 StaticRegisterModule staticRegisterRadiantCore( StaticRadiantCoreModule::instance() );
174 class RadiantDependencies :
175 public GlobalRadiantModuleRef,
176 public GlobalFileSystemModuleRef,
177 public GlobalEntityModuleRef,
178 public GlobalShadersModuleRef,
179 public GlobalBrushModuleRef,
180 public GlobalSceneGraphModuleRef,
181 public GlobalShaderCacheModuleRef,
182 public GlobalFiletypesModuleRef,
183 public GlobalSelectionModuleRef,
184 public GlobalReferenceModuleRef,
185 public GlobalOpenGLModuleRef,
186 public GlobalEntityClassManagerModuleRef,
187 public GlobalUndoModuleRef,
188 public GlobalScripLibModuleRef,
189 public GlobalNamespaceModuleRef
191 ImageModulesRef m_image_modules;
192 MapModulesRef m_map_modules;
193 ToolbarModulesRef m_toolbar_modules;
194 PluginModulesRef m_plugin_modules;
197 RadiantDependencies() :
198 GlobalEntityModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entities" ) ),
199 GlobalShadersModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "shaders" ) ),
200 GlobalBrushModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "brushtypes" ) ),
201 GlobalEntityClassManagerModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entityclass" ) ),
202 m_image_modules( GlobalRadiant().getRequiredGameDescriptionKeyValue( "texturetypes" ) ),
203 m_map_modules( GlobalRadiant().getRequiredGameDescriptionKeyValue( "maptypes" ) ),
204 m_toolbar_modules( "*" ),
205 m_plugin_modules( "*" ){
208 ImageModules& getImageModules(){
209 return m_image_modules.get();
211 MapModules& getMapModules(){
212 return m_map_modules.get();
214 ToolbarModules& getToolbarModules(){
215 return m_toolbar_modules.get();
217 PluginModules& getPluginModules(){
218 return m_plugin_modules.get();
222 class Radiant : public TypeSystemRef
228 GlobalFiletypes().addType( "sound", "wav", filetype_t( "PCM sound files", "*.wav" ) );
230 Selection_construct();
231 HomePaths_Construct();
234 MultiMon_Construct();
236 Pointfile_Construct();
237 GLWindow_Construct();
238 BuildMenu_Construct();
240 EntityList_Construct();
241 MainFrame_Construct();
242 GroupDialog_Construct();
243 SurfaceInspector_Construct();
244 PatchInspector_Construct();
246 XYWindow_Construct();
247 BuildMonitor_Construct();
248 TextureBrowser_Construct();
250 Autosave_Construct();
251 EntityInspector_construct();
252 FindTextureDialog_Construct();
253 NullModel_construct();
257 EnginePath_Realise();
260 EnginePath_Unrealise();
264 FindTextureDialog_Destroy();
265 EntityInspector_destroy();
268 TextureBrowser_Destroy();
269 BuildMonitor_Destroy();
272 PatchInspector_Destroy();
273 SurfaceInspector_Destroy();
274 GroupDialog_Destroy();
276 EntityList_Destroy();
292 bool g_RadiantInitialised = false;
293 RadiantDependencies* g_RadiantDependencies;
299 bool Radiant_Construct( ModuleServer& server ){
300 GlobalModuleServer::instance().set( server );
301 StaticModuleRegistryList().instance().registerModules();
303 g_RadiantDependencies = new RadiantDependencies();
305 g_RadiantInitialised = !server.getError();
307 if ( g_RadiantInitialised ) {
308 g_Radiant = new Radiant;
311 return g_RadiantInitialised;
313 void Radiant_Destroy(){
314 if ( g_RadiantInitialised ) {
318 delete g_RadiantDependencies;
321 ImageModules& Radiant_getImageModules(){
322 return g_RadiantDependencies->getImageModules();
324 MapModules& Radiant_getMapModules(){
325 return g_RadiantDependencies->getMapModules();
327 ToolbarModules& Radiant_getToolbarModules(){
328 return g_RadiantDependencies->getToolbarModules();
330 PluginModules& Radiant_getPluginModules(){
331 return g_RadiantDependencies->getPluginModules();