// // ======================================================================================================================= // Map_ImportFile // ======================================================================================================================= // void Map_ImportFile( char *fileName ) { char *buf; idStr temp; Sys_BeginWait(); temp = fileName; temp.BackSlashesToSlashes(); if( LoadFile( temp, ( void ** ) &buf ) != -1 ) { Map_ImportBuffer( buf ); Mem_Free( buf ); Map_BuildBrushData(); } Sys_UpdateWindows( W_ALL ); mapModified = 1; Sys_EndWait(); }
// //================ //Map_ImportFile //================ // void Map_ImportFile (char *filename) { char* buf; char temp[1024]; Sys_BeginWait (); QE_ConvertDOSToUnixName( temp, filename ); if (LoadFile (filename, (void **)&buf) != -1) { Map_ImportBuffer(buf); free(buf); Map_BuildBrushData(); } Sys_UpdateWindows (W_ALL); modified = true; Sys_EndWait(); }
/* ======================================================================================================================= ======================================================================================================================= */ void Map_BuildBrushData( void ) { brush_t *b, *next; if( active_brushes.next == NULL ) { return; } Sys_BeginWait(); // this could take a while int n = 0; for( b = active_brushes.next; b != NULL && b != &active_brushes; b = next ) { next = b->next; Brush_Build( b, true, false, false ); if( !b->brush_faces || ( g_PrefsDlg.m_bCleanTiny && CheckForTinyBrush( b, n++, g_PrefsDlg.m_fTinySize ) ) ) { Brush_Free( b ); common->Printf( "Removed degenerate brush\n" ); } } Sys_EndWait(); }
// //================ //Map_ImportFile //================ // void Map_ImportFile( const char *filename ){ FileStream file; Sys_BeginWait(); Sys_Printf( "Importing map from %s\n",filename ); const char* type = strrchr( filename,'.' ); if ( type != NULL ) { type++; } /*!\todo Resolve "r" problem in scriptlib" */ if ( file.Open( filename, "rb" ) ) { Map_Import( &file, type, true ); } else{ Sys_FPrintf( SYS_ERR, "ERROR: couldn't open %s for read\n", filename ); } file.Close(); Sys_UpdateWindows( W_ALL ); modified = true; Sys_EndWait(); }
/* ============= Undo_Undo ============= */ void Undo_Undo(void) { undo_t *undo, *redo; brush_t *pBrush, *pNextBrush; entity_t *pEntity, *pNextEntity, *pUndoEntity; if (!g_lastundo) { Sys_Status("Nothing left to undo.\n"); return; } if (!g_lastundo->done) { Sys_Status("Undo_Undo: WARNING: last undo not yet finished!\n"); } // get the last undo undo = g_lastundo; if (g_lastundo->prev) g_lastundo->prev->next = NULL; else g_undolist = NULL; g_lastundo = g_lastundo->prev; //allocate a new redo redo = (undo_t *) Mem_ClearedAlloc(sizeof(undo_t), TAG_TOOLS); if (!redo) return; memset(redo, 0, sizeof(undo_t)); redo->brushlist.next = &redo->brushlist; redo->brushlist.prev = &redo->brushlist; redo->entitylist.next = &redo->entitylist; redo->entitylist.prev = &redo->entitylist; if (g_lastredo) g_lastredo->next = redo; else g_redolist = redo; redo->prev = g_lastredo; redo->next = NULL; g_lastredo = redo; redo->time = Sys_DoubleTime(); redo->id = g_redoId++; redo->done = true; redo->operation = undo->operation; //reset the redo IDs of all brushes using the new ID for (pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pBrush->next) { if (pBrush->redoId == redo->id) { pBrush->redoId = 0; } } for (pBrush = selected_brushes.next; pBrush != NULL && pBrush != &selected_brushes; pBrush = pBrush->next) { if (pBrush->redoId == redo->id) { pBrush->redoId = 0; } } //reset the redo IDs of all entities using thew new ID for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next) { if (pEntity->redoId == redo->id) { pEntity->redoId = 0; } } // remove current selection Select_Deselect(); // move "created" brushes to the redo for (pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush=pNextBrush) { pNextBrush = pBrush->next; if (pBrush->undoId == undo->id) { //Brush_Free(pBrush); //move the brush to the redo Brush_RemoveFromList(pBrush); Brush_AddToList(pBrush, &redo->brushlist); //make sure the ID of the owner is stored pBrush->ownerId = pBrush->owner->entityId; //unlink the brush from the owner entity Entity_UnlinkBrush(pBrush); } } // move "created" entities to the redo for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pNextEntity) { pNextEntity = pEntity->next; if (pEntity->undoId == undo->id) { // check if this entity is in the undo for (pUndoEntity = undo->entitylist.next; pUndoEntity != NULL && pUndoEntity != &undo->entitylist; pUndoEntity = pUndoEntity->next) { // move brushes to the undo entity if (pUndoEntity->entityId == pEntity->entityId) { pUndoEntity->brushes.next = pEntity->brushes.next; pUndoEntity->brushes.prev = pEntity->brushes.prev; pEntity->brushes.next = &pEntity->brushes; pEntity->brushes.prev = &pEntity->brushes; } } // //Entity_Free(pEntity); //move the entity to the redo Entity_RemoveFromList(pEntity); Entity_AddToList(pEntity, &redo->entitylist); } } // add the undo entities back into the entity list for (pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = undo->entitylist.next) { g_undoMemorySize -= Entity_MemorySize(pEntity); //if this is the world entity if (pEntity->entityId == world_entity->entityId) { //free the epairs of the world entity Entity_FreeEpairs(world_entity); //set back the original epairs world_entity->epairs = pEntity->epairs; //free the world_entity clone that stored the epairs Entity_Free(pEntity); } else { Entity_RemoveFromList(pEntity); Entity_AddToList(pEntity, &entities); pEntity->redoId = redo->id; } } // add the undo brushes back into the selected brushes for (pBrush = undo->brushlist.next; pBrush != NULL && pBrush != &undo->brushlist; pBrush = undo->brushlist.next) { g_undoMemorySize -= Brush_MemorySize(pBrush); Brush_RemoveFromList(pBrush); Brush_AddToList(pBrush, &active_brushes); for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next) { if (pEntity->entityId == pBrush->ownerId) { Entity_LinkBrush(pEntity, pBrush); break; } } //if the brush is not linked then it should be linked into the world entity if (pEntity == NULL || pEntity == &entities) { Entity_LinkBrush(world_entity, pBrush); } //build the brush //Brush_Build(pBrush); Select_Brush(pBrush); pBrush->redoId = redo->id; } // common->Printf("%s undone.\n", undo->operation); // free the undo g_undoMemorySize -= sizeof(undo_t); Mem_Free(undo); g_undoSize--; g_undoId--; if (g_undoId <= 0) g_undoId = 2 * g_undoMaxSize; // Sys_BeginWait(); brush_t *b, *next; for (b = active_brushes.next ; b != NULL && b != &active_brushes ; b=next) { next = b->next; Brush_Build( b, true, false, false ); } for (b = selected_brushes.next ; b != NULL && b != &selected_brushes ; b=next) { next = b->next; Brush_Build( b, true, false, false ); } Sys_EndWait(); g_bScreenUpdates = true; Sys_UpdateWindows(W_ALL); }
/* ================ Map_LoadFile ================ */ void Map_LoadFile( const char *filename ){ clock_t start, finish; double elapsed_time; start = clock(); Sys_BeginWait(); Select_Deselect(); /*! \todo FIXME TTimo why is this commented out? stability issues maybe? or duplicate feature? forcing to show the console during map load was a good thing IMO */ //SetInspectorMode(W_CONSOLE); Sys_Printf( "Loading map from %s\n", filename ); Map_Free(); //++timo FIXME: maybe even easier to have Group_Init called from Map_Free? Group_Init(); g_qeglobals.d_num_entities = 0; g_qeglobals.d_parsed_brushes = 0; // cancel the map loading process // used when conversion between standard map format and BP format is required and the user cancels the process g_bCancel_Map_LoadFile = false; strcpy( currentmap, filename ); g_bScreenUpdates = false; // leo: avoid redraws while loading the map (see fenris:1952) // prepare to let the map module do the parsing FileStream file; const char* type = strrchr( filename,'.' ); if ( type != NULL ) { type++; } // NOTE TTimo opening has binary doesn't make a lot of sense // but opening as text confuses the scriptlib parser // this may be a problem if we "rb" and use the XML parser, might have an incompatibility if ( file.Open( filename, "rb" ) ) { Map_Import( &file, type ); } else{ Sys_FPrintf( SYS_ERR, "ERROR: failed to open %s for read\n", filename ); } file.Close(); g_bScreenUpdates = true; if ( g_bCancel_Map_LoadFile ) { Sys_Printf( "Map_LoadFile canceled\n" ); Map_New(); Sys_EndWait(); return; } if ( !world_entity ) { Sys_Printf( "No worldspawn in map.\n" ); Map_New(); Sys_EndWait(); return; } finish = clock(); elapsed_time = (double)( finish - start ) / CLOCKS_PER_SEC; Sys_Printf( "--- LoadMapFile ---\n" ); Sys_Printf( "%s\n", filename ); Sys_Printf( "%5i brushes\n", g_qeglobals.d_parsed_brushes ); Sys_Printf( "%5i entities\n", g_qeglobals.d_num_entities ); Sys_Printf( "%5.2f second(s) load time\n", elapsed_time ); Sys_EndWait(); Map_RestoreBetween(); // // move the view to a start position // Map_StartPosition(); Map_RegionOff(); modified = false; Sys_SetTitle( filename ); Texture_ShowInuse(); QERApp_SortActiveShaders(); Sys_UpdateWindows( W_ALL ); }
/* ================== WinMain ================== */ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance ,LPSTR lpCmdLine, int nCmdShow) { MSG msg; double time, oldtime, delta; HACCEL accelerators; g_qeglobals.d_hInstance = hInstance; InitCommonControls (); screen_width = GetSystemMetrics (SM_CXFULLSCREEN); screen_height = GetSystemMetrics (SM_CYFULLSCREEN); // hack for broken NT 4.0 dual screen if (screen_width > 2*screen_height) screen_width /= 2; accelerators = LoadAccelerators (hInstance , MAKEINTRESOURCE(IDR_ACCELERATOR1)); if (!accelerators) Error ("LoadAccelerators failed"); Main_Create (hInstance); WCam_Create (hInstance); WXY_Create (hInstance); WZ_Create (hInstance); CreateEntityWindow(hInstance); // the project file can be specified on the command line, // or implicitly found in the scripts directory if (lpCmdLine && strlen(lpCmdLine)) { ParseCommandLine (lpCmdLine); if (!QE_LoadProject(argv[1])) Error ("Couldn't load %s project file", argv[1]); } else if (!QE_LoadProject("scripts/quake.qe4")) Error ("Couldn't load scripts/quake.qe4 project file"); QE_Init (); Sys_Printf ("Entering message loop\n"); oldtime = Sys_DoubleTime (); while (!have_quit) { Sys_EndWait (); // remove wait cursor if active while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { if (!TranslateAccelerator(g_qeglobals.d_hwndMain, accelerators, &msg) ) { TranslateMessage (&msg); DispatchMessage (&msg); } if (msg.message == WM_QUIT) have_quit = true; } CheckBspProcess (); time = Sys_DoubleTime (); delta = time - oldtime; oldtime = time; if (delta > 0.2) delta = 0.2; // run time dependant behavior Cam_MouseControl (delta); // update any windows now if (update_bits & W_CAMERA) { InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false); UpdateWindow (g_qeglobals.d_hwndCamera); } if (update_bits & (W_Z | W_Z_OVERLAY) ) { InvalidateRect(g_qeglobals.d_hwndZ, NULL, false); UpdateWindow (g_qeglobals.d_hwndZ); } if ( update_bits & W_TEXTURE ) { InvalidateRect(g_qeglobals.d_hwndTexture, NULL, false); UpdateWindow (g_qeglobals.d_hwndEntity); } if (update_bits & (W_XY | W_XY_OVERLAY)) { InvalidateRect(g_qeglobals.d_hwndXY, NULL, false); UpdateWindow (g_qeglobals.d_hwndXY); } update_bits = 0; if (!cambuttonstate && !have_quit) { // if not driving in the camera view, block WaitMessage (); } } /* return success of application */ return TRUE; }
/* ======================================================================================================================= Map_LoadFile ======================================================================================================================= */ void Map_LoadFile(const char *filename) { entity_t *ent; CWaitDlg dlg; idStr fileStr, status; idMapFile mapfile; Sys_BeginWait(); Select_Deselect(); dlg.AllowCancel( true ); idStr( filename ).ExtractFileName( fileStr ); sprintf( status, "Loading %s...", fileStr.c_str() ); dlg.SetWindowText( status ); sprintf( status, "Reading file %s...", fileStr.c_str() ); dlg.SetText( status ); // SetInspectorMode(W_CONSOLE); fileStr = filename; fileStr.BackSlashesToSlashes(); common->Printf( "Map_LoadFile: %s\n", fileStr.c_str() ); Map_Free(); g_qeglobals.d_parsed_brushes = 0; strcpy( currentmap, filename ); if(mapfile.Parse(filename, true, true)) { g_qeglobals.bNeedConvert = false; g_qeglobals.bOldBrushes = false; g_qeglobals.bPrimitBrushes = false; g_qeglobals.mapVersion = 1.0; long lastUpdate = 0; int count = mapfile.GetNumEntities(); for (int i = 0; i < count; i++) { idMapEntity *mapent = mapfile.GetEntity(i); if (mapent) { idStr classname = mapent->epairs.GetString("classname"); // Update 20 times a second if ( (GetTickCount() - lastUpdate) > 50 ) { lastUpdate = GetTickCount(); sprintf(status, "Loading entity %i (%s)...", i, classname.c_str()); dlg.SetText(status); } if ( dlg.CancelPressed() ) { Sys_Status("Map load cancelled.\n"); Map_New(); return; } if (classname == "worldspawn") { world_entity = EntityFromMapEntity(mapent, &dlg); Entity_PostParse(world_entity, &active_brushes); } else { ent = EntityFromMapEntity(mapent, &dlg); Entity_PostParse(ent, &active_brushes); Entity_Name(ent, true); // add the entity to the end of the entity list ent->next = &entities; ent->prev = entities.prev; entities.prev->next = ent; entities.prev = ent; g_qeglobals.d_num_entities++; } } } } if (!world_entity) { Sys_Status("No worldspawn in map.\n"); Map_New(); return; } common->Printf("--- LoadMapFile ---\n"); common->Printf("%s\n", fileStr.c_str()); common->Printf("%5i brushes\n", g_qeglobals.d_parsed_brushes); common->Printf("%5i entities\n", g_qeglobals.d_num_entities); dlg.SetText("Restoring Between"); Map_RestoreBetween(); dlg.SetText("Building Brush Data"); common->Printf("Map_BuildAllDisplayLists\n"); Map_BuildBrushData(); // // reset the "need conversion" flag conversion to the good format done in // Map_BuildBrushData // g_qeglobals.bNeedConvert = false; // move the view to a start position ent = AngledEntity(); g_pParentWnd->GetCamera()->Camera().angles[PITCH] = 0; if (ent) { GetVectorForKey(ent, "origin", g_pParentWnd->GetCamera()->Camera().origin); GetVectorForKey(ent, "origin", g_pParentWnd->GetXYWnd()->GetOrigin()); g_pParentWnd->GetCamera()->Camera().angles[YAW] = FloatForKey(ent, "angle"); } else { g_pParentWnd->GetCamera()->Camera().angles[YAW] = 0; VectorCopy(vec3_origin, g_pParentWnd->GetCamera()->Camera().origin); VectorCopy(vec3_origin, g_pParentWnd->GetXYWnd()->GetOrigin()); } Map_RegionOff(); mapModified = 0; if (GetFileAttributes(filename) & FILE_ATTRIBUTE_READONLY) { fileStr += " (read only) "; } Sys_SetTitle(fileStr); Texture_ShowInuse(); if (g_pParentWnd->GetCamera()->GetRenderMode()) { g_pParentWnd->GetCamera()->BuildRendererState(); } Sys_EndWait(); Sys_UpdateWindows(W_ALL); }
/* ================ Map_LoadFile ================ */ void Map_LoadFile (char *filename) { char *buf; entity_t *ent; char temp[1024]; Sys_BeginWait (); Select_Deselect(); //SetInspectorMode(W_CONSOLE); QE_ConvertDOSToUnixName( temp, filename ); Sys_Printf ("Map_LoadFile: %s\n", temp ); Map_Free (); //++timo FIXME: maybe even easier to have Group_Init called from Map_Free? Group_Init(); g_qeglobals.d_parsed_brushes = 0; strcpy (currentmap, filename); if (LoadFile (filename, (void **)&buf) != -1) { StartTokenParsing (buf); g_qeglobals.d_num_entities = 0; // Timo // will be used in Entity_Parse to detect if a conversion between brush formats is needed g_qeglobals.bNeedConvert = false; g_qeglobals.bOldBrushes = false; g_qeglobals.bPrimitBrushes = false; while (1) { ent = Entity_Parse (false, &active_brushes); if (!ent) break; if (!strcmp(ValueForKey (ent, "classname"), "worldspawn")) { if (world_entity) Sys_Printf ("WARNING: multiple worldspawn\n"); world_entity = ent; } else if (!strcmp(ValueForKey (ent, "classname"), "group_info")) { // it's a group thing! Group_Add(ent); Entity_Free(ent); } else { // add the entity to the end of the entity list ent->next = &entities; ent->prev = entities.prev; entities.prev->next = ent; entities.prev = ent; g_qeglobals.d_num_entities++; } } } free (buf); if (!world_entity) { Sys_Printf ("No worldspawn in map.\n"); Map_New (); return; } Sys_Printf ("--- LoadMapFile ---\n"); Sys_Printf ("%s\n", temp ); Sys_Printf ("%5i brushes\n", g_qeglobals.d_parsed_brushes ); Sys_Printf ("%5i entities\n", g_qeglobals.d_num_entities); Map_RestoreBetween (); Sys_Printf ("Map_BuildAllDisplayLists\n"); Map_BuildBrushData(); // reset the "need conversion" flag // conversion to the good format done in Map_BuildBrushData g_qeglobals.bNeedConvert=false; // // move the view to a start position // ent = AngledEntity(); g_pParentWnd->GetCamera()->Camera().angles[PITCH] = 0; if (ent) { GetVectorForKey (ent, "origin", g_pParentWnd->GetCamera()->Camera().origin); GetVectorForKey (ent, "origin", g_pParentWnd->GetXYWnd()->GetOrigin()); g_pParentWnd->GetCamera()->Camera().angles[YAW] = FloatForKey (ent, "angle"); } else { g_pParentWnd->GetCamera()->Camera().angles[YAW] = 0; VectorCopy (vec3_origin, g_pParentWnd->GetCamera()->Camera().origin); VectorCopy (vec3_origin, g_pParentWnd->GetXYWnd()->GetOrigin()); } Map_RegionOff (); modified = false; Sys_SetTitle (temp); Texture_ShowInuse (); Sys_EndWait(); Sys_UpdateWindows (W_ALL); }