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))
175 build_set_variable("RadiantPath", AppPath_get());
176 build_set_variable("ExecutableType", RADIANT_EXECUTABLE);
177 build_set_variable("EnginePath", EnginePath_get());
178 build_set_variable("MonitorAddress", (g_WatchBSP_Enabled) ? "127.0.0.1:39000" : "");
179 build_set_variable("GameName", gamename_get());
181 build_set_variable("MapFile", Map_Name(g_map));
186 build_clear_variables();
189 class ArrayCommandListener : public CommandListener
193 ArrayCommandListener()
195 m_array = g_ptr_array_new();
197 ~ArrayCommandListener()
199 g_ptr_array_free(m_array, TRUE);
202 void execute(const char* command)
204 g_ptr_array_add(m_array, g_strdup(command));
207 GPtrArray* array() const
213 class BatchCommandListener : public CommandListener
215 TextOutputStream& m_file;
216 std::size_t m_commandCount;
217 const char* m_outputRedirect;
219 BatchCommandListener(TextOutputStream& file, const char* outputRedirect) : m_file(file), m_commandCount(0), m_outputRedirect(outputRedirect)
223 void execute(const char* command)
226 if (m_commandCount == 0)
234 m_file << "\"" << m_outputRedirect << "\"";
240 bool Region_cameraValid()
242 Vector3 vOrig(vector3_snapped(Camera_getOrigin(*g_pParentWnd->GetCamWnd())));
244 for (int i=0 ; i<3 ; i++)
246 if (vOrig[i] > region_maxs[i] || vOrig[i] < region_mins[i])
255 void RunBSP(const char* name)
257 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=503
258 // make sure we don't attempt to region compile a map with the camera outside the region
259 if (region_active && !Region_cameraValid())
261 globalErrorStream() << "The camera must be in the region to start a region compile.\n";
267 if(Map_Unnamed(g_map))
269 globalOutputStream() << "build cancelled\n";
273 if (g_SnapShots_Enabled && !Map_Unnamed(g_map) && Map_Modified(g_map))
280 const char* mapname = Map_Name(g_map);
281 StringOutputStream name(256);
282 name << StringRange(mapname, path_get_filename_base_end(mapname)) << ".reg";
283 Map_SaveRegion(name.c_str());
290 if (g_WatchBSP_Enabled)
292 ArrayCommandListener listener;
293 build_run(name, listener);
294 // grab the file name for engine running
295 const char* fullname = Map_Name(g_map);
296 StringOutputStream bspname(64);
297 bspname << StringRange(path_get_filename_start(fullname), path_get_filename_base_end(fullname));
298 BuildMonitor_Run( listener.array(), bspname.c_str() );
302 char junkpath[PATH_MAX];
303 strcpy(junkpath, SettingsPath_get());
304 strcat(junkpath, "junk.txt");
306 char batpath[PATH_MAX];
308 strcpy(batpath, SettingsPath_get());
309 strcat(batpath, "qe3bsp.sh");
311 strcpy(batpath, SettingsPath_get());
312 strcat(batpath, "qe3bsp.bat");
314 #error "unsupported platform"
316 bool written = false;
318 TextFileOutputStream batchFile(batpath);
319 if(!batchFile.failed())
322 batchFile << "#!/bin/sh \n\n";
324 BatchCommandListener listener(batchFile, junkpath);
325 build_run(name, listener);
332 chmod (batpath, 0744);
334 globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
335 globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n";
336 Q_Exec(batpath, NULL, NULL, true);
343 // =============================================================================
346 void Sys_SetTitle(const char *text, bool modified)
348 StringOutputStream title;
349 title << ConvertLocaleToUTF8(text);
356 gtk_window_set_title(MainFrame_getWindow(), title.c_str());
359 bool g_bWaitCursor = false;
361 void Sys_BeginWait (void)
363 ScreenUpdates_Disable("Processing...", "Please Wait");
364 GdkCursor *cursor = gdk_cursor_new (GDK_WATCH);
365 gdk_window_set_cursor(GTK_WIDGET(MainFrame_getWindow())->window, cursor);
366 gdk_cursor_unref (cursor);
367 g_bWaitCursor = true;
370 void Sys_EndWait (void)
372 ScreenUpdates_Enable();
373 gdk_window_set_cursor(GTK_WIDGET(MainFrame_getWindow())->window, 0);
374 g_bWaitCursor = false;