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 "debugging/debugging.h"
39 #include "ifilesystem.h"
44 #include <gtk/gtktearoffmenuitem.h>
46 #include "stream/textfilestream.h"
48 #include "stream/stringstream.h"
52 #include "gtkutil/messagebox.h"
57 #include "camwindow.h"
58 #include "mainframe.h"
59 #include "preferences.h"
64 QEGlobals_t g_qeglobals;
74 // VFS initialization -----------------------
75 // we will call GlobalFileSystem().initDirectory, giving the directories to look in (for files in pk3's and for standalone files)
76 // we need to call in order, the mod ones first, then the base ones .. they will be searched in this order
77 // *nix systems have a dual filesystem in ~/.q3a, which is searched first .. so we need to add that too
79 const char* gamename = gamename_get();
80 const char* basegame = basegame_get();
82 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))
90 // ~/.<gameprefix>/<fs_game>
92 StringOutputStream userGamePath(256);
93 userGamePath << userRoot << gamename << '/';
94 GlobalFileSystem().initDirectory(userGamePath.c_str());
98 // <fs_basepath>/<fs_game>
100 StringOutputStream globalGamePath(256);
101 globalGamePath << globalRoot << gamename << '/';
102 GlobalFileSystem().initDirectory(globalGamePath.c_str());
107 // ~/.<gameprefix>/<fs_main>
109 StringOutputStream userBasePath(256);
110 userBasePath << userRoot << basegame << '/';
111 GlobalFileSystem().initDirectory(userBasePath.c_str());
115 // <fs_basepath>/<fs_main>
117 StringOutputStream globalBasePath(256);
118 globalBasePath << globalRoot << basegame << '/';
119 GlobalFileSystem().initDirectory(globalBasePath.c_str());
123 int g_numbrushes = 0;
124 int g_numentities = 0;
126 void QE_UpdateStatusBar()
129 sprintf(buffer, "Brushes: %d Entities: %d", g_numbrushes, g_numentities);
130 g_pParentWnd->SetStatusText(g_pParentWnd->m_brushcount_status, buffer);
133 SimpleCounter g_brushCount;
135 void QE_brushCountChanged()
137 g_numbrushes = int(g_brushCount.get());
138 QE_UpdateStatusBar();
141 SimpleCounter g_entityCount;
143 void QE_entityCountChanged()
145 g_numentities = int(g_entityCount.get());
146 QE_UpdateStatusBar();
149 bool ConfirmModified(const char* title)
151 if (!Map_Modified(g_map))
154 EMessageBoxReturn result = gtk_MessageBox(GTK_WIDGET(MainFrame_getWindow()), "The current map has changed since it was last saved.\nDo you want to save the current map before continuing?", title, eMB_YESNOCANCEL, eMB_ICONQUESTION);
155 if(result == eIDCANCEL)
161 if(Map_Unnamed(g_map))
174 const char* const EXECUTABLE_TYPE =
175 #if defined(__linux__) || defined (__FreeBSD__)
177 #elif defined(__APPLE__)
182 #error "unknown platform"
188 build_set_variable("RadiantPath", AppPath_get());
189 build_set_variable("ExecutableType", EXECUTABLE_TYPE);
190 build_set_variable("EnginePath", EnginePath_get());
191 build_set_variable("MonitorAddress", (g_WatchBSP_Enabled) ? "127.0.0.1:39000" : "");
192 build_set_variable("GameName", gamename_get());
194 build_set_variable("MapFile", Map_Name(g_map));
199 build_clear_variables();
202 class ArrayCommandListener : public CommandListener
206 ArrayCommandListener()
208 m_array = g_ptr_array_new();
210 ~ArrayCommandListener()
212 g_ptr_array_free(m_array, TRUE);
215 void execute(const char* command)
217 g_ptr_array_add(m_array, g_strdup(command));
220 GPtrArray* array() const
226 class BatchCommandListener : public CommandListener
228 TextOutputStream& m_file;
229 std::size_t m_commandCount;
230 const char* m_outputRedirect;
232 BatchCommandListener(TextOutputStream& file, const char* outputRedirect) : m_file(file), m_commandCount(0), m_outputRedirect(outputRedirect)
236 void execute(const char* command)
239 if (m_commandCount == 0)
247 m_file << "\"" << m_outputRedirect << "\"";
253 bool Region_cameraValid()
255 Vector3 vOrig(vector3_snapped(Camera_getOrigin(*g_pParentWnd->GetCamWnd())));
257 for (int i=0 ; i<3 ; i++)
259 if (vOrig[i] > region_maxs[i] || vOrig[i] < region_mins[i])
268 void RunBSP(const char* name)
270 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=503
271 // make sure we don't attempt to region compile a map with the camera outside the region
272 if (region_active && !Region_cameraValid())
274 globalErrorStream() << "The camera must be in the region to start a region compile.\n";
280 if(Map_Unnamed(g_map))
282 globalOutputStream() << "build cancelled\n";
286 if (g_SnapShots_Enabled && !Map_Unnamed(g_map) && Map_Modified(g_map))
293 const char* mapname = Map_Name(g_map);
294 StringOutputStream name(256);
295 name << StringRange(mapname, path_get_filename_base_end(mapname)) << ".reg";
296 Map_SaveRegion(name.c_str());
303 if (g_WatchBSP_Enabled)
305 ArrayCommandListener listener;
306 build_run(name, listener);
307 // grab the file name for engine running
308 const char* fullname = Map_Name(g_map);
309 StringOutputStream bspname(64);
310 bspname << StringRange(path_get_filename_start(fullname), path_get_filename_base_end(fullname));
311 BuildMonitor_Run( listener.array(), bspname.c_str() );
315 char junkpath[PATH_MAX];
316 strcpy(junkpath, SettingsPath_get());
317 strcat(junkpath, "junk.txt");
319 char batpath[PATH_MAX];
321 strcpy(batpath, SettingsPath_get());
322 strcat(batpath, "qe3bsp.sh");
324 strcpy(batpath, SettingsPath_get());
325 strcat(batpath, "qe3bsp.bat");
327 #error "unsupported platform"
329 bool written = false;
331 TextFileOutputStream batchFile(batpath);
332 if(!batchFile.failed())
335 batchFile << "#!/bin/sh \n\n";
337 BatchCommandListener listener(batchFile, junkpath);
338 build_run(name, listener);
345 chmod (batpath, 0744);
347 globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
348 globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n";
349 Q_Exec(batpath, NULL, NULL, true);
356 // =============================================================================
359 void Sys_SetTitle(const char *text, bool modified)
361 StringOutputStream title;
362 title << ConvertLocaleToUTF8(text);
369 gtk_window_set_title(MainFrame_getWindow(), title.c_str());
372 bool g_bWaitCursor = false;
374 void Sys_BeginWait (void)
376 ScreenUpdates_Disable("Processing...", "Please Wait");
377 GdkCursor *cursor = gdk_cursor_new (GDK_WATCH);
378 gdk_window_set_cursor(GTK_WIDGET(MainFrame_getWindow())->window, cursor);
379 gdk_cursor_unref (cursor);
380 g_bWaitCursor = true;
383 void Sys_EndWait (void)
385 ScreenUpdates_Enable();
386 gdk_window_set_cursor(GTK_WIDGET(MainFrame_getWindow())->window, 0);
387 g_bWaitCursor = false;