2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
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
23 The following source code is licensed by Id Software and subject to the terms of
24 its LIMITED USE SOFTWARE LICENSE AGREEMENT, a copy of which is included with
25 GtkRadiant. If you did not receive a LIMITED USE SOFTWARE LICENSE AGREEMENT,
26 please contact Id Software immediately at info@idsoftware.com.
32 // Leonardo Zide (leo@lokigames.com)
37 #include "globaldefs.h"
41 #include "debugging/debugging.h"
43 #include "ifilesystem.h"
48 #include <uilib/uilib.h>
50 #include "stream/textfilestream.h"
52 #include "stream/stringstream.h"
56 #include "gtkutil/messagebox.h"
61 #include "camwindow.h"
62 #include "mainframe.h"
63 #include "preferences.h"
68 QEGlobals_t g_qeglobals;
77 // VFS initialization -----------------------
78 // we will call GlobalFileSystem().initDirectory, giving the directories to look in (for files in pk3's and for standalone files)
79 // we need to call in order, the mod ones first, then the base ones .. they will be searched in this order
80 // *nix systems have a dual filesystem in ~/.q3a, which is searched first .. so we need to add that too
82 const char* gamename = gamename_get();
83 const char* basegame = basegame_get();
84 const char* userRoot = g_qeglobals.m_userEnginePath.c_str();
85 const char* globalRoot = EnginePath_get();
88 StringOutputStream editorGamePath( 256 );
89 editorGamePath << GlobalRadiant().getDataPath() << DEFAULT_EDITORVFS_DIRNAME;
90 GlobalFileSystem().initDirectory( editorGamePath.c_str() );
92 // if we have a mod dir
93 if ( !string_equal( gamename, basegame ) ) {
94 // ~/.<gameprefix>/<fs_game>
95 if ( userRoot && !g_disableHomePath ) {
96 StringOutputStream userGamePath( 256 );
97 userGamePath << userRoot << gamename << '/';
98 GlobalFileSystem().initDirectory( userGamePath.c_str() );
101 // <fs_basepath>/<fs_game>
102 if ( !g_disableEnginePath ) {
103 StringOutputStream globalGamePath( 256 );
104 globalGamePath << globalRoot << gamename << '/';
105 GlobalFileSystem().initDirectory( globalGamePath.c_str() );
109 // ~/.<gameprefix>/<fs_main>
110 if ( userRoot && !g_disableHomePath ) {
111 StringOutputStream userBasePath( 256 );
112 userBasePath << userRoot << basegame << '/';
113 GlobalFileSystem().initDirectory( userBasePath.c_str() );
116 // <fs_basepath>/<fs_main>
117 if ( !g_disableEnginePath ) {
118 StringOutputStream globalBasePath( 256 );
119 globalBasePath << globalRoot << basegame << '/';
120 GlobalFileSystem().initDirectory( globalBasePath.c_str() );
124 for ( int i = 0; i < g_pakPathCount; i++ ) {
125 if (g_strcmp0( g_strPakPath[i].c_str(), "")) {
126 GlobalFileSystem().initDirectory( g_strPakPath[i].c_str() );
131 int g_numbrushes = 0;
132 int g_numentities = 0;
134 void QE_UpdateStatusBar(){
136 sprintf( buffer, "Brushes: %d Entities: %d", g_numbrushes, g_numentities );
137 g_pParentWnd->SetStatusText( g_pParentWnd->m_brushcount_status, buffer );
140 SimpleCounter g_brushCount;
142 void QE_brushCountChanged(){
143 g_numbrushes = int(g_brushCount.get() );
144 QE_UpdateStatusBar();
147 SimpleCounter g_entityCount;
149 void QE_entityCountChanged(){
150 g_numentities = int(g_entityCount.get() );
151 QE_UpdateStatusBar();
154 bool ConfirmModified( const char* title ){
155 if ( !Map_Modified( g_map ) ) {
159 auto result = ui::alert( MainFrame_getWindow(), "The current map has changed since it was last saved.\nDo you want to save the current map before continuing?", title, ui::alert_type::YESNOCANCEL, ui::alert_icon::Question );
160 if ( result == ui::alert_response::CANCEL ) {
163 if ( result == ui::alert_response::YES ) {
164 if ( Map_Unnamed( g_map ) ) {
176 // this is expected to not be used since
177 // ".[ExecutableType]" is replaced by "[ExecutableExt]"
178 const char *exe_ext = GDEF_OS_EXE_EXT;
179 build_set_variable( "ExecutableType", exe_ext[0] == '\0' ? exe_ext : exe_ext + 1 );
181 build_set_variable( "ExecutableExt", GDEF_OS_EXE_EXT );
182 build_set_variable( "RadiantPath", AppPath_get() );
183 build_set_variable( "EnginePath", EnginePath_get() );
184 build_set_variable( "UserEnginePath", g_qeglobals.m_userEnginePath.c_str() );
186 build_set_variable( "MonitorAddress", ( g_WatchBSP_Enabled ) ? "127.0.0.1:39000" : "" );
188 build_set_variable( "GameName", gamename_get() );
190 StringBuffer ExtraQ3map2Args;
192 for ( int i = 0; i < g_pakPathCount; i++ ) {
193 if ( g_strcmp0( g_strPakPath[i].c_str(), "") ) {
194 ExtraQ3map2Args.push_string( " -fs_pakpath \"" );
195 ExtraQ3map2Args.push_string( g_strPakPath[i].c_str() );
196 ExtraQ3map2Args.push_string( "\"" );
201 if ( g_disableEnginePath ) {
202 ExtraQ3map2Args.push_string( " -fs_nobasepath " );
205 if ( g_disableHomePath ) {
206 ExtraQ3map2Args.push_string( " -fs_nohomepath " );
209 build_set_variable( "ExtraQ3map2Args", ExtraQ3map2Args.c_str() );
211 const char* mapname = Map_Name( g_map );
212 StringOutputStream name( 256 );
213 name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".bsp";
215 build_set_variable( "MapFile", mapname );
216 build_set_variable( "BspFile", name.c_str() );
220 build_clear_variables();
223 class ArrayCommandListener : public CommandListener
227 ArrayCommandListener(){
228 m_array = g_ptr_array_new();
231 ~ArrayCommandListener(){
232 g_ptr_array_free( m_array, TRUE );
235 void execute( const char* command ){
236 g_ptr_array_add( m_array, g_strdup( command ) );
239 GPtrArray* array() const {
244 class BatchCommandListener : public CommandListener
246 TextOutputStream& m_file;
247 std::size_t m_commandCount;
248 const char* m_outputRedirect;
250 BatchCommandListener( TextOutputStream& file, const char* outputRedirect ) : m_file( file ), m_commandCount( 0 ), m_outputRedirect( outputRedirect ){
253 void execute( const char* command ){
255 if ( m_commandCount == 0 ) {
262 m_file << "\"" << m_outputRedirect << "\"";
268 bool Region_cameraValid(){
269 Vector3 vOrig( vector3_snapped( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ) ) );
271 for ( int i = 0 ; i < 3 ; i++ )
273 if ( vOrig[i] > region_maxs[i] || vOrig[i] < region_mins[i] ) {
281 void RunBSP( const char* name ){
282 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=503
283 // make sure we don't attempt to region compile a map with the camera outside the region
284 if ( region_active && !Region_cameraValid() ) {
285 globalErrorStream() << "The camera must be in the region to start a region compile.\n";
291 if ( Map_Unnamed( g_map ) ) {
292 globalOutputStream() << "build cancelled\n";
296 if ( g_SnapShots_Enabled && !Map_Unnamed( g_map ) && Map_Modified( g_map ) ) {
300 if ( region_active ) {
301 const char* mapname = Map_Name( g_map );
302 StringOutputStream name( 256 );
303 name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".reg";
304 Map_SaveRegion( name.c_str() );
311 if ( g_WatchBSP_Enabled ) {
312 ArrayCommandListener listener;
313 build_run( name, listener );
314 // grab the file name for engine running
315 const char* fullname = Map_Name( g_map );
316 StringOutputStream bspname( 64 );
317 bspname << StringRange( path_get_filename_start( fullname ), path_get_filename_base_end( fullname ) );
318 BuildMonitor_Run( listener.array(), bspname.c_str() );
322 char junkpath[PATH_MAX];
323 strcpy( junkpath, SettingsPath_get() );
324 strcat( junkpath, "junk.txt" );
326 char batpath[PATH_MAX];
328 strcpy( batpath, SettingsPath_get() );
329 strcat( batpath, "qe3bsp.sh" );
330 #elif GDEF_OS_WINDOWS
331 strcpy( batpath, SettingsPath_get() );
332 strcat( batpath, "qe3bsp.bat" );
334 #error "unsupported platform"
336 bool written = false;
338 TextFileOutputStream batchFile( batpath );
339 if ( !batchFile.failed() ) {
341 batchFile << "#!/bin/sh \n\n";
343 BatchCommandListener listener( batchFile, junkpath );
344 build_run( name, listener );
350 chmod( batpath, 0744 );
352 globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
353 globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n";
354 Q_Exec( batpath, NULL, NULL, true, false );
361 // =============================================================================
364 void Sys_SetTitle( const char *text, bool modified ){
365 StringOutputStream title;
372 gtk_window_set_title(MainFrame_getWindow(), title.c_str() );
375 bool g_bWaitCursor = false;
377 void Sys_BeginWait( void ){
378 ScreenUpdates_Disable( "Processing...", "Please Wait" );
379 GdkCursor *cursor = gdk_cursor_new( GDK_WATCH );
380 gdk_window_set_cursor( gtk_widget_get_window(MainFrame_getWindow()), cursor );
381 gdk_cursor_unref( cursor );
382 g_bWaitCursor = true;
385 void Sys_EndWait( void ){
386 ScreenUpdates_Enable();
387 gdk_window_set_cursor(gtk_widget_get_window(MainFrame_getWindow()), 0 );
388 g_bWaitCursor = false;
391 void Sys_Beep( void ){