| 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 "plugin.h" |
| 23 | |
| 24 | #include "debugging/debugging.h" |
| 25 | |
| 26 | #include "qerplugin.h" |
| 27 | #include "ifilesystem.h" |
| 28 | #include "ishaders.h" |
| 29 | #include "ientity.h" |
| 30 | #include "ieclass.h" |
| 31 | #include "irender.h" |
| 32 | #include "iscenegraph.h" |
| 33 | #include "iselection.h" |
| 34 | #include "ifilter.h" |
| 35 | #include "iscriplib.h" |
| 36 | #include "igl.h" |
| 37 | #include "iundo.h" |
| 38 | #include "itextures.h" |
| 39 | #include "ireference.h" |
| 40 | #include "ifiletypes.h" |
| 41 | #include "preferencesystem.h" |
| 42 | #include "ibrush.h" |
| 43 | #include "ipatch.h" |
| 44 | #include "iimage.h" |
| 45 | #include "itoolbar.h" |
| 46 | #include "iplugin.h" |
| 47 | #include "imap.h" |
| 48 | #include "namespace.h" |
| 49 | |
| 50 | #include "gtkutil/messagebox.h" |
| 51 | #include "gtkutil/filechooser.h" |
| 52 | #include "maplib.h" |
| 53 | |
| 54 | #include "error.h" |
| 55 | #include "map.h" |
| 56 | #include "qe3.h" |
| 57 | #include "entityinspector.h" |
| 58 | #include "entitylist.h" |
| 59 | #include "points.h" |
| 60 | #include "gtkmisc.h" |
| 61 | #include "texwindow.h" |
| 62 | #include "mainframe.h" |
| 63 | #include "build.h" |
| 64 | #include "mru.h" |
| 65 | #include "multimon.h" |
| 66 | #include "surfacedialog.h" |
| 67 | #include "groupdialog.h" |
| 68 | #include "patchdialog.h" |
| 69 | #include "camwindow.h" |
| 70 | #include "watchbsp.h" |
| 71 | #include "xywindow.h" |
| 72 | #include "entity.h" |
| 73 | #include "select.h" |
| 74 | #include "preferences.h" |
| 75 | #include "autosave.h" |
| 76 | #include "plugintoolbar.h" |
| 77 | #include "findtexturedialog.h" |
| 78 | #include "nullmodel.h" |
| 79 | #include "grid.h" |
| 80 | |
| 81 | #include "modulesystem/modulesmap.h" |
| 82 | #include "modulesystem/singletonmodule.h" |
| 83 | |
| 84 | #include "generic/callback.h" |
| 85 | |
| 86 | const char* GameDescription_getKeyValue( const char* key ){ |
| 87 | return g_pGameDescription->getKeyValue( key ); |
| 88 | } |
| 89 | |
| 90 | const char* GameDescription_getRequiredKeyValue( const char* key ){ |
| 91 | return g_pGameDescription->getRequiredKeyValue( key ); |
| 92 | } |
| 93 | |
| 94 | const char* getMapName(){ |
| 95 | return Map_Name( g_map ); |
| 96 | } |
| 97 | |
| 98 | scene::Node& getMapWorldEntity(){ |
| 99 | return Map_FindOrInsertWorldspawn( g_map ); |
| 100 | } |
| 101 | |
| 102 | VIEWTYPE XYWindow_getViewType(){ |
| 103 | return g_pParentWnd->GetXYWnd()->GetViewType(); |
| 104 | } |
| 105 | |
| 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 ); |
| 109 | return result; |
| 110 | } |
| 111 | |
| 112 | const char* TextureBrowser_getSelectedShader(){ |
| 113 | return TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ); |
| 114 | } |
| 115 | |
| 116 | const char* getGameFile(){ |
| 117 | return g_GamesDialog.m_sGameFile.c_str(); |
| 118 | } |
| 119 | |
| 120 | class RadiantCoreAPI |
| 121 | { |
| 122 | _QERFuncTable_1 m_radiantcore; |
| 123 | public: |
| 124 | typedef _QERFuncTable_1 Type; |
| 125 | STRING_CONSTANT( Name, "*" ); |
| 126 | |
| 127 | RadiantCoreAPI(){ |
| 128 | m_radiantcore.getEnginePath = &EnginePath_get; |
| 129 | m_radiantcore.getLocalRcPath = &LocalRcPath_get; |
| 130 | m_radiantcore.getAppPath = &AppPath_get; |
| 131 | m_radiantcore.getDataPath = &DataPath_get; |
| 132 | m_radiantcore.getGameToolsPath = &GameToolsPath_get; |
| 133 | m_radiantcore.getSettingsPath = &SettingsPath_get; |
| 134 | m_radiantcore.getMapsPath = &getMapsPath; |
| 135 | |
| 136 | m_radiantcore.getGameFile = &getGameFile; |
| 137 | m_radiantcore.getGameName = &gamename_get; |
| 138 | m_radiantcore.getGameMode = &gamemode_get; |
| 139 | |
| 140 | m_radiantcore.getMapName = &getMapName; |
| 141 | m_radiantcore.getMapWorldEntity = getMapWorldEntity; |
| 142 | m_radiantcore.getGridSize = GetGridSize; |
| 143 | |
| 144 | m_radiantcore.getGameDescriptionKeyValue = &GameDescription_getKeyValue; |
| 145 | m_radiantcore.getRequiredGameDescriptionKeyValue = &GameDescription_getRequiredKeyValue; |
| 146 | |
| 147 | m_radiantcore.XYWindowDestroyed_connect = XYWindowDestroyed_connect; |
| 148 | m_radiantcore.XYWindowDestroyed_disconnect = XYWindowDestroyed_disconnect; |
| 149 | m_radiantcore.XYWindowMouseDown_connect = XYWindowMouseDown_connect; |
| 150 | m_radiantcore.XYWindowMouseDown_disconnect = XYWindowMouseDown_disconnect; |
| 151 | m_radiantcore.XYWindow_getViewType = XYWindow_getViewType; |
| 152 | m_radiantcore.XYWindow_windowToWorld = XYWindow_windowToWorld; |
| 153 | m_radiantcore.TextureBrowser_getSelectedShader = TextureBrowser_getSelectedShader; |
| 154 | |
| 155 | m_radiantcore.m_pfnMessageBox = >k_MessageBox; |
| 156 | m_radiantcore.m_pfnFileDialog = &file_dialog; |
| 157 | m_radiantcore.m_pfnColorDialog = &color_dialog; |
| 158 | m_radiantcore.m_pfnDirDialog = &dir_dialog; |
| 159 | m_radiantcore.m_pfnNewImage = &new_plugin_image; |
| 160 | } |
| 161 | _QERFuncTable_1* getTable(){ |
| 162 | return &m_radiantcore; |
| 163 | } |
| 164 | }; |
| 165 | |
| 166 | typedef SingletonModule<RadiantCoreAPI> RadiantCoreModule; |
| 167 | typedef Static<RadiantCoreModule> StaticRadiantCoreModule; |
| 168 | StaticRegisterModule staticRegisterRadiantCore( StaticRadiantCoreModule::instance() ); |
| 169 | |
| 170 | |
| 171 | class RadiantDependencies : |
| 172 | public GlobalRadiantModuleRef, |
| 173 | public GlobalFileSystemModuleRef, |
| 174 | public GlobalEntityModuleRef, |
| 175 | public GlobalShadersModuleRef, |
| 176 | public GlobalBrushModuleRef, |
| 177 | public GlobalSceneGraphModuleRef, |
| 178 | public GlobalShaderCacheModuleRef, |
| 179 | public GlobalFiletypesModuleRef, |
| 180 | public GlobalSelectionModuleRef, |
| 181 | public GlobalReferenceModuleRef, |
| 182 | public GlobalOpenGLModuleRef, |
| 183 | public GlobalEntityClassManagerModuleRef, |
| 184 | public GlobalUndoModuleRef, |
| 185 | public GlobalScripLibModuleRef, |
| 186 | public GlobalNamespaceModuleRef |
| 187 | { |
| 188 | ImageModulesRef m_image_modules; |
| 189 | MapModulesRef m_map_modules; |
| 190 | ToolbarModulesRef m_toolbar_modules; |
| 191 | PluginModulesRef m_plugin_modules; |
| 192 | |
| 193 | public: |
| 194 | RadiantDependencies() : |
| 195 | GlobalEntityModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entities" ) ), |
| 196 | GlobalShadersModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "shaders" ) ), |
| 197 | GlobalBrushModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "brushtypes" ) ), |
| 198 | GlobalEntityClassManagerModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entityclass" ) ), |
| 199 | m_image_modules( GlobalRadiant().getRequiredGameDescriptionKeyValue( "texturetypes" ) ), |
| 200 | m_map_modules( GlobalRadiant().getRequiredGameDescriptionKeyValue( "maptypes" ) ), |
| 201 | m_toolbar_modules( "*" ), |
| 202 | m_plugin_modules( "*" ){ |
| 203 | } |
| 204 | |
| 205 | ImageModules& getImageModules(){ |
| 206 | return m_image_modules.get(); |
| 207 | } |
| 208 | MapModules& getMapModules(){ |
| 209 | return m_map_modules.get(); |
| 210 | } |
| 211 | ToolbarModules& getToolbarModules(){ |
| 212 | return m_toolbar_modules.get(); |
| 213 | } |
| 214 | PluginModules& getPluginModules(){ |
| 215 | return m_plugin_modules.get(); |
| 216 | } |
| 217 | }; |
| 218 | |
| 219 | class Radiant : public TypeSystemRef |
| 220 | { |
| 221 | public: |
| 222 | Radiant(){ |
| 223 | Preferences_Init(); |
| 224 | |
| 225 | GlobalFiletypes().addType( "sound", "wav", filetype_t( "PCM sound files", "*.wav" ) ); |
| 226 | |
| 227 | Selection_construct(); |
| 228 | HomePaths_Construct(); |
| 229 | VFS_Construct(); |
| 230 | Grid_construct(); |
| 231 | MultiMon_Construct(); |
| 232 | MRU_Construct(); |
| 233 | Pointfile_Construct(); |
| 234 | GLWindow_Construct(); |
| 235 | BuildMenu_Construct(); |
| 236 | Map_Construct(); |
| 237 | EntityList_Construct(); |
| 238 | MainFrame_Construct(); |
| 239 | GroupDialog_Construct(); |
| 240 | SurfaceInspector_Construct(); |
| 241 | PatchInspector_Construct(); |
| 242 | CamWnd_Construct(); |
| 243 | XYWindow_Construct(); |
| 244 | BuildMonitor_Construct(); |
| 245 | TextureBrowser_Construct(); |
| 246 | Entity_Construct(); |
| 247 | Autosave_Construct(); |
| 248 | EntityInspector_construct(); |
| 249 | FindTextureDialog_Construct(); |
| 250 | NullModel_construct(); |
| 251 | MapRoot_construct(); |
| 252 | |
| 253 | EnginePath_verify(); |
| 254 | EnginePath_Realise(); |
| 255 | } |
| 256 | ~Radiant(){ |
| 257 | EnginePath_Unrealise(); |
| 258 | |
| 259 | MapRoot_destroy(); |
| 260 | NullModel_destroy(); |
| 261 | FindTextureDialog_Destroy(); |
| 262 | EntityInspector_destroy(); |
| 263 | Autosave_Destroy(); |
| 264 | Entity_Destroy(); |
| 265 | TextureBrowser_Destroy(); |
| 266 | BuildMonitor_Destroy(); |
| 267 | XYWindow_Destroy(); |
| 268 | CamWnd_Destroy(); |
| 269 | PatchInspector_Destroy(); |
| 270 | SurfaceInspector_Destroy(); |
| 271 | GroupDialog_Destroy(); |
| 272 | MainFrame_Destroy(); |
| 273 | EntityList_Destroy(); |
| 274 | Map_Destroy(); |
| 275 | BuildMenu_Destroy(); |
| 276 | GLWindow_Destroy(); |
| 277 | Pointfile_Destroy(); |
| 278 | MRU_Destroy(); |
| 279 | MultiMon_Destroy(); |
| 280 | Grid_destroy(); |
| 281 | VFS_Destroy(); |
| 282 | HomePaths_Destroy(); |
| 283 | Selection_destroy(); |
| 284 | } |
| 285 | }; |
| 286 | |
| 287 | namespace |
| 288 | { |
| 289 | bool g_RadiantInitialised = false; |
| 290 | RadiantDependencies* g_RadiantDependencies; |
| 291 | Radiant* g_Radiant; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | |
| 296 | bool Radiant_Construct( ModuleServer& server ){ |
| 297 | GlobalModuleServer::instance().set( server ); |
| 298 | StaticModuleRegistryList().instance().registerModules(); |
| 299 | |
| 300 | g_RadiantDependencies = new RadiantDependencies(); |
| 301 | |
| 302 | g_RadiantInitialised = !server.getError(); |
| 303 | |
| 304 | if ( g_RadiantInitialised ) { |
| 305 | g_Radiant = new Radiant; |
| 306 | } |
| 307 | |
| 308 | return g_RadiantInitialised; |
| 309 | } |
| 310 | void Radiant_Destroy(){ |
| 311 | if ( g_RadiantInitialised ) { |
| 312 | delete g_Radiant; |
| 313 | } |
| 314 | |
| 315 | delete g_RadiantDependencies; |
| 316 | } |
| 317 | |
| 318 | ImageModules& Radiant_getImageModules(){ |
| 319 | return g_RadiantDependencies->getImageModules(); |
| 320 | } |
| 321 | MapModules& Radiant_getMapModules(){ |
| 322 | return g_RadiantDependencies->getMapModules(); |
| 323 | } |
| 324 | ToolbarModules& Radiant_getToolbarModules(){ |
| 325 | return g_RadiantDependencies->getToolbarModules(); |
| 326 | } |
| 327 | PluginModules& Radiant_getPluginModules(){ |
| 328 | return g_RadiantDependencies->getPluginModules(); |
| 329 | } |