2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
37 QEGlobals_t g_qeglobals;
40 =======================================================================================================================
41 =======================================================================================================================
43 void WINAPI QE_CheckOpenGLForErrors(void) {
45 int i = qglGetError();
46 if (i != GL_NO_ERROR) {
47 if (i == GL_OUT_OF_MEMORY) {
49 // strMsg.Format("OpenGL out of memory error %s\nDo you wish to save before
50 // exiting?", gluErrorString((GLenum)i));
52 if (g_pParentWnd->MessageBox(strMsg, EDITOR_WINDOWTEXT " Error", MB_YESNO) == IDYES) {
53 Map_SaveFile(NULL, false);
59 // strMsg.Format("Warning: OpenGL Error %s\n ", gluErrorString((GLenum)i));
60 common->Printf(strMsg.GetBuffer(0));
66 =======================================================================================================================
67 =======================================================================================================================
69 bool DoesFileExist(const char *pBuff, long &lSize) {
71 if (file.Open(pBuff, CFile::modeRead | CFile::shareDenyNone)) {
72 lSize += file.GetLength();
81 =======================================================================================================================
82 =======================================================================================================================
84 bool ExtractPath_and_Filename(const char *pPath, CString &strPath, CString &strFilename) {
85 CString strPathName = pPath;
86 int nSlash = strPathName.ReverseFind('\\');
88 strPath = strPathName.Left(nSlash + 1);
89 strFilename = strPathName.Right(strPathName.GetLength() - nSlash - 1);
99 =======================================================================================================================
100 =======================================================================================================================
102 void Map_Snapshot() {
106 // we need to do the following 1. make sure the snapshot directory exists (create
107 // it if it doesn't) 2. find out what the lastest save is based on number 3. inc
108 // that and save the map
110 CString strOrgPath, strOrgFile;
111 ExtractPath_and_Filename(currentmap, strOrgPath, strOrgFile);
112 AddSlash(strOrgPath);
113 strOrgPath += "snapshots";
117 if (_stat(strOrgPath, &Stat) == -1) {
118 bGo = (_mkdir(strOrgPath) != -1);
121 AddSlash(strOrgPath);
125 CString strNewPath = strOrgPath;
126 strNewPath += strOrgFile;
130 strFile.Format("%s.%i", strNewPath, nCount);
131 bGo = DoesFileExist(strFile, lSize);
135 // strFile has the next available slot
136 Map_SaveFile(strFile.GetBuffer(0), false);
137 Sys_SetTitle(currentmap);
138 if (lSize > 12 * 1024 * 1024) { // total size of saves > 4 mb
141 "The snapshot files in the [%s] directory total more than 4 megabytes. You might consider cleaning the directory up.",
147 strMsg.Format("Snapshot save failed.. unabled to create directory\n%s", strOrgPath);
148 g_pParentWnd->MessageBox(strMsg);
153 =======================================================================================================================
154 QE_CheckAutoSave If five minutes have passed since making a change and the map hasn't been saved, save it out.
155 =======================================================================================================================
157 void QE_CheckAutoSave(void) {
158 static bool inAutoSave = false;
159 static bool autoToggle = false;
161 Sys_Status("Did not autosave due recursive entry into autosave routine\n");
165 if ( !mapModified ) {
171 if ( g_PrefsDlg.m_bAutoSave ) {
172 CString strMsg = g_PrefsDlg.m_bSnapShots ? "Autosaving snapshot..." : "Autosaving...";
173 Sys_Status(strMsg.GetBuffer(0), 0);
175 if (g_PrefsDlg.m_bSnapShots && stricmp(currentmap, "unnamed.map") != 0) {
178 Map_SaveFile(ValueForKey(g_qeglobals.d_project_entity, (autoToggle == 0) ? "autosave1" : "autosave2" ), false, true);
181 Sys_Status("Autosaving...Saved.", 0);
182 mapModified = 0; // DHM - _D3XP
184 common->Printf("Autosave skipped...\n");
185 Sys_Status("Autosave skipped...", 0);
192 =======================================================================================================================
193 =======================================================================================================================
196 const char *g_pPathFixups[] = {
208 const int g_nPathFixupCount = sizeof(g_pPathFixups) / sizeof (const char *);
211 =======================================================================================================================
213 =======================================================================================================================
215 bool QE_LoadProject(char *projectfile) {
219 common->Printf("QE_LoadProject (%s)\n", projectfile);
221 if ( fileSystem->ReadFile( projectfile, reinterpret_cast < void ** > (&data), &time) <= 0 ) {
225 g_strProject = projectfile;
226 g_PrefsDlg.m_strLastProject = projectfile;
227 g_PrefsDlg.SavePrefs();
229 CString strData = data;
231 fileSystem->FreeFile( data );
233 StartTokenParsing(strData.GetBuffer(0));
234 g_qeglobals.d_project_entity = Entity_Parse(true);
235 if (!g_qeglobals.d_project_entity) {
236 Error("Couldn't parse %s", projectfile);
239 // set here some default project settings you need
240 if (strlen(ValueForKey(g_qeglobals.d_project_entity, "brush_primit")) == 0) {
241 SetKeyValue(g_qeglobals.d_project_entity, "brush_primit", "0");
244 g_qeglobals.m_bBrushPrimitMode = IntForKey(g_qeglobals.d_project_entity, "brush_primit");
246 Eclass_InitForSourceDirectory(ValueForKey(g_qeglobals.d_project_entity, "entitypath"));
247 g_Inspectors->FillClassList(); // list in entity window
251 // FillTextureMenu();
258 =======================================================================================================================
260 =======================================================================================================================
262 bool QE_SaveProject(const char *pProjectFile) {
264 idFile *file = fileSystem->OpenFileWrite(pProjectFile);
269 file->Write("{\n", 2);
271 int count = g_qeglobals.d_project_entity->epairs.GetNumKeyVals();
272 for (int i = 0; i < count; i++) {
273 file->WriteFloatString( "\"%s\" \"%s\"\n", g_qeglobals.d_project_entity->epairs.GetKeyVal(i)->GetKey().c_str(), g_qeglobals.d_project_entity->epairs.GetKeyVal(i)->GetValue().c_str());
276 file->Write("}\n", 2);
278 fileSystem->CloseFile( file );
284 #define SPEED_MOVE 32
285 #define SPEED_TURN 22.5
288 =======================================================================================================================
289 ConnectEntities Sets target / name on the two entities selected from the first selected to the secon
290 =======================================================================================================================
292 void ConnectEntities(void) {
298 if (g_qeglobals.d_select_count < 2) {
299 Sys_Status("Must have at least two brushes selected.", 0);
304 e1 = g_qeglobals.d_select_order[0]->owner;
306 for (i = 0; i < g_qeglobals.d_select_count; i++) {
307 if (g_qeglobals.d_select_order[i]->owner == world_entity) {
308 Sys_Status("Can't connect to the world.", 0);
314 for (i = 1; i < g_qeglobals.d_select_count; i++) {
315 if (e1 == g_qeglobals.d_select_order[i]->owner) {
316 Sys_Status("Brushes are from same entity.", 0);
322 target = ValueForKey(e1, "target");
323 if ( target && *target) {
324 for (t = 1; t < 2048; t++) {
325 target = ValueForKey(e1, va("target%i", t));
326 if (target && *target) {
336 for (i = 1; i < g_qeglobals.d_select_count; i++) {
337 target = ValueForKey(g_qeglobals.d_select_order[i]->owner, "name");
338 if (target && *target) {
341 UniqueTargetName(strTarget);
344 SetKeyValue(e1, "target", strTarget);
346 SetKeyValue(e1, va("target%i", t), strTarget);
351 Sys_UpdateWindows(W_XY | W_CAMERA);
354 Select_Brush(g_qeglobals.d_select_order[1]);
358 =======================================================================================================================
359 =======================================================================================================================
361 bool QE_SingleBrush(bool bQuiet, bool entityOK) {
362 if ((selected_brushes.next == &selected_brushes) || (selected_brushes.next->next != &selected_brushes)) {
364 Sys_Status("Error: you must have a single brush selected\n");
370 if (!entityOK && selected_brushes.next->owner->eclass->fixedsize) {
372 Sys_Status("Error: you cannot manipulate fixed size entities\n");
382 =======================================================================================================================
383 =======================================================================================================================
386 /* initialize variables */
387 g_qeglobals.d_gridsize = 8;
388 g_qeglobals.d_showgrid = true;
392 * FIXME: idMaterial Texture_Init (true); Cam_Init (); XY_Init ();
398 int g_numbrushes, g_numentities;
401 =======================================================================================================================
402 =======================================================================================================================
404 void QE_CountBrushesAndUpdateStatusBar(void) {
405 static int s_lastbrushcount, s_lastentitycount;
406 static bool s_didonce;
414 if (active_brushes.next != NULL) {
415 for (b = active_brushes.next; b != NULL && b != &active_brushes; b = next) {
417 if (b->brush_faces) {
418 if (!b->owner->eclass->fixedsize) {
429 * if ( entities.next != NULL ) { for ( e = entities.next ; e != &entities &&
430 * g_numentities != MAX_MAP_ENTITIES ; e = e->next) { g_numentities++; } }
432 if (((g_numbrushes != s_lastbrushcount) || (g_numentities != s_lastentitycount)) || (!s_didonce)) {
433 Sys_UpdateStatusBar();
435 s_lastbrushcount = g_numbrushes;
436 s_lastentitycount = g_numentities;