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)
36 #include "globaldefs.h"
40 #include "debugging/debugging.h"
42 #include "ifilesystem.h"
47 #include <uilib/uilib.h>
49 #include "stream/textfilestream.h"
51 #include "stream/stringstream.h"
55 #include "gtkutil/messagebox.h"
60 #include "camwindow.h"
61 #include "mainframe.h"
62 #include "preferences.h"
67 QEGlobals_t g_qeglobals;
76 // VFS initialization -----------------------
77 // we will call GlobalFileSystem().initDirectory, giving the directories to look in (for files in pk3's and for standalone files)
78 // we need to call in order, the mod ones first, then the base ones .. they will be searched in this order
79 // *nix systems have a dual filesystem in ~/.q3a, which is searched first .. so we need to add that too
81 const char* gamename = gamename_get();
82 const char* basegame = basegame_get();
83 const char* userRoot = g_qeglobals.m_userEnginePath.c_str();
84 const char* globalRoot = EnginePath_get();
86 // if we have a mod dir
87 if ( !string_equal( gamename, basegame ) ) {
88 // ~/.<gameprefix>/<fs_game>
90 StringOutputStream userGamePath( 256 );
91 userGamePath << userRoot << gamename << '/';
92 GlobalFileSystem().initDirectory( userGamePath.c_str() );
95 // <fs_basepath>/<fs_game>
97 StringOutputStream globalGamePath( 256 );
98 globalGamePath << globalRoot << gamename << '/';
99 GlobalFileSystem().initDirectory( globalGamePath.c_str() );
103 // ~/.<gameprefix>/<fs_main>
105 StringOutputStream userBasePath( 256 );
106 userBasePath << userRoot << basegame << '/';
107 GlobalFileSystem().initDirectory( userBasePath.c_str() );
110 // <fs_basepath>/<fs_main>
112 StringOutputStream globalBasePath( 256 );
113 globalBasePath << globalRoot << basegame << '/';
114 GlobalFileSystem().initDirectory( globalBasePath.c_str() );
118 int g_numbrushes = 0;
119 int g_numentities = 0;
121 void QE_UpdateStatusBar(){
123 sprintf( buffer, "Brushes: %d Entities: %d", g_numbrushes, g_numentities );
124 g_pParentWnd->SetStatusText( g_pParentWnd->m_brushcount_status, buffer );
127 SimpleCounter g_brushCount;
129 void QE_brushCountChanged(){
130 g_numbrushes = int(g_brushCount.get() );
131 QE_UpdateStatusBar();
134 SimpleCounter g_entityCount;
136 void QE_entityCountChanged(){
137 g_numentities = int(g_entityCount.get() );
138 QE_UpdateStatusBar();
141 bool ConfirmModified( const char* title ){
142 if ( !Map_Modified( g_map ) ) {
146 auto result = MainFrame_getWindow().alert( "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 );
147 if ( result == ui::alert_response::CANCEL ) {
150 if ( result == ui::alert_response::YES ) {
151 if ( Map_Unnamed( g_map ) ) {
163 build_set_variable( "RadiantPath", AppPath_get() );
164 build_set_variable( "ExecutableType", RADIANT_EXECUTABLE );
165 build_set_variable( "EnginePath", EnginePath_get() );
166 build_set_variable( "UserEnginePath", g_qeglobals.m_userEnginePath.c_str() );
167 build_set_variable( "MonitorAddress", ( g_WatchBSP_Enabled ) ? "127.0.0.1:39000" : "" );
168 build_set_variable( "GameName", gamename_get() );
170 const char* mapname = Map_Name( g_map );
171 StringOutputStream name( 256 );
172 name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".bsp";
174 build_set_variable( "MapFile", mapname );
175 build_set_variable( "BspFile", name.c_str() );
179 build_clear_variables();
182 class ArrayCommandListener : public CommandListener
186 ArrayCommandListener(){
187 m_array = g_ptr_array_new();
189 ~ArrayCommandListener(){
190 g_ptr_array_free( m_array, TRUE );
193 void execute( const char* command ){
194 g_ptr_array_add( m_array, g_strdup( command ) );
197 GPtrArray* array() const {
202 class BatchCommandListener : public CommandListener
204 TextOutputStream& m_file;
205 std::size_t m_commandCount;
206 const char* m_outputRedirect;
208 BatchCommandListener( TextOutputStream& file, const char* outputRedirect ) : m_file( file ), m_commandCount( 0 ), m_outputRedirect( outputRedirect ){
211 void execute( const char* command ){
213 if ( m_commandCount == 0 ) {
220 m_file << "\"" << m_outputRedirect << "\"";
226 bool Region_cameraValid(){
227 Vector3 vOrig( vector3_snapped( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ) ) );
229 for ( int i = 0 ; i < 3 ; i++ )
231 if ( vOrig[i] > region_maxs[i] || vOrig[i] < region_mins[i] ) {
239 void RunBSP( const char* name ){
240 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=503
241 // make sure we don't attempt to region compile a map with the camera outside the region
242 if ( region_active && !Region_cameraValid() ) {
243 globalErrorStream() << "The camera must be in the region to start a region compile.\n";
249 if ( Map_Unnamed( g_map ) ) {
250 globalOutputStream() << "build cancelled\n";
254 if ( g_SnapShots_Enabled && !Map_Unnamed( g_map ) && Map_Modified( g_map ) ) {
258 if ( region_active ) {
259 const char* mapname = Map_Name( g_map );
260 StringOutputStream name( 256 );
261 name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".reg";
262 Map_SaveRegion( name.c_str() );
269 if ( g_WatchBSP_Enabled ) {
270 ArrayCommandListener listener;
271 build_run( name, listener );
272 // grab the file name for engine running
273 const char* fullname = Map_Name( g_map );
274 StringOutputStream bspname( 64 );
275 bspname << StringRange( path_get_filename_start( fullname ), path_get_filename_base_end( fullname ) );
276 BuildMonitor_Run( listener.array(), bspname.c_str() );
280 char junkpath[PATH_MAX];
281 strcpy( junkpath, SettingsPath_get() );
282 strcat( junkpath, "junk.txt" );
284 char batpath[PATH_MAX];
286 strcpy( batpath, SettingsPath_get() );
287 strcat( batpath, "qe3bsp.sh" );
288 #elif GDEF_OS_WINDOWS
289 strcpy( batpath, SettingsPath_get() );
290 strcat( batpath, "qe3bsp.bat" );
292 #error "unsupported platform"
294 bool written = false;
296 TextFileOutputStream batchFile( batpath );
297 if ( !batchFile.failed() ) {
299 batchFile << "#!/bin/sh \n\n";
301 BatchCommandListener listener( batchFile, junkpath );
302 build_run( name, listener );
308 chmod( batpath, 0744 );
310 globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
311 globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n";
312 Q_Exec( batpath, NULL, NULL, true, false );
319 // =============================================================================
322 void Sys_SetTitle( const char *text, bool modified ){
323 StringOutputStream title;
330 gtk_window_set_title(MainFrame_getWindow(), title.c_str() );
333 bool g_bWaitCursor = false;
335 void Sys_BeginWait( void ){
336 ScreenUpdates_Disable( "Processing...", "Please Wait" );
337 GdkCursor *cursor = gdk_cursor_new( GDK_WATCH );
338 gdk_window_set_cursor( gtk_widget_get_window(MainFrame_getWindow()), cursor );
339 gdk_cursor_unref( cursor );
340 g_bWaitCursor = true;
343 void Sys_EndWait( void ){
344 ScreenUpdates_Enable();
345 gdk_window_set_cursor(gtk_widget_get_window(MainFrame_getWindow()), 0 );
346 g_bWaitCursor = false;
349 void Sys_Beep( void ){