29 #include "../../idlib/precompiled.h"
59 DWORD dw = GetTickCount();
104 for (
int i = 0;
i < 3;
i++) {
105 if (b->maxs[
i] - b->mins[
i] < fSize) {
111 common->
Printf(
"Possible problem brush (too small) #%i ", n);
150 for (ent = entities.
next; ent != &entities; ent = ent->
next) {
166 for (ent = entities.
next; ent != &entities; ent = ent->
next) {
169 if (name && name[0]) {
171 if (prefix && *prefix) {
172 buf =
va(
"%s_%s_", prefix, eclass);
174 buf =
va(
"%s_", eclass);
176 int len = strlen(buf);
178 int j = atoi(name + len);
200 for (ent = entities.
next; ent != &entities; ent = ent->
next) {
220 if (
g_pParentWnd->MessageBox(
"Copy selection?",
"", MB_YESNO) == IDYES) {
226 g_qeglobals.rw->InitFromMap(
NULL );
227 g_qeglobals.sw->ClearAllSoundEmitters();
233 g_qeglobals.d_num_entities = 0;
255 while (entities.
next != &entities) {
307 pm->ctrl(
i,
j).st = (*mappatch)[
j * mappatch->
GetWidth() +
i].st;
315 *pm->epairs = mappatch->
epairs;
317 brush_t *
b = AddBrushForPatch(pm,
false);
330 if (!b->brush_faces) {
335 for (scan = b->brush_faces; scan->next; scan = scan->next) {
341 f->originalPlane = f->plane;
347 for (
int j = 0;
j < 3;
j++) {
348 f->planepts[
j].x = w[
j].x + origin.
x;
349 f->planepts[
j].y = w[
j].y + origin.
y;
350 f->planepts[
j].z = w[
j].z + origin.
z;
355 f->brushprimit_texdef.coords[0][0] = mat[0][0];
356 f->brushprimit_texdef.coords[0][1] = mat[0][1];
357 f->brushprimit_texdef.coords[0][2] = mat[0][2];
358 f->brushprimit_texdef.coords[1][0] = mat[1][0];
359 f->brushprimit_texdef.coords[1][1] = mat[1][1];
360 f->brushprimit_texdef.coords[1][2] = mat[1][2];
383 if ( (GetTickCount() - lastUpdate) > 50 ) {
384 lastUpdate = GetTickCount();
386 sprintf(status,
"Reading primitive %i (brush)",
i);
388 sprintf(status,
"Reading primitive %i (patch)",
i);
427 idStr fileStr, status;
436 dlg.SetWindowText( status );
437 sprintf( status,
"Reading file %s...", fileStr.
c_str() );
448 g_qeglobals.d_parsed_brushes = 0;
451 if(mapfile.
Parse(filename,
true,
true)) {
452 g_qeglobals.bNeedConvert =
false;
453 g_qeglobals.bOldBrushes =
false;
454 g_qeglobals.bPrimitBrushes =
false;
455 g_qeglobals.mapVersion = 1.0;
464 if ( (GetTickCount() - lastUpdate) > 50 ) {
465 lastUpdate = GetTickCount();
466 sprintf(status,
"Loading entity %i (%s)...",
i, classname.
c_str());
474 if (classname ==
"worldspawn") {
486 g_qeglobals.d_num_entities++;
501 common->
Printf(
"%5i brushes\n", g_qeglobals.d_parsed_brushes);
502 common->
Printf(
"%5i entities\n", g_qeglobals.d_num_entities);
504 dlg.
SetText(
"Restoring Between");
507 dlg.
SetText(
"Building Brush Data");
515 g_qeglobals.bNeedConvert =
false;
537 if (GetFileAttributes(filename) & FILE_ATTRIBUTE_READONLY) {
538 fileStr +=
" (read only) ";
540 Sys_SetTitle(fileStr);
562 patch->
SetSize( b->pPatch->width, b->pPatch->height );
563 for (
int i = 0;
i < b->pPatch->width;
i++ ) {
564 for (
int j = 0;
j < b->pPatch->height;
j++ ) {
566 (*patch)[
j*patch->
GetWidth()+
i].st = b->pPatch->ctrl(
i,
j).st;
570 if ( b->pPatch->explicitSubdivisions ) {
574 patch->
SetMaterial( b->pPatch->d_texture->GetName() );
575 if ( b->pPatch->epairs ) {
576 patch->
epairs = *b->pPatch->epairs;
582 for ( face_t *
f = b->brush_faces;
f;
f =
f->next ) {
590 plane.
FromPoints(
f->planepts[0],
f->planepts[1],
f->planepts[2],
false );
595 plane =
f->originalPlane;
600 mat[0][0] =
f->brushprimit_texdef.coords[0][0];
601 mat[0][1] =
f->brushprimit_texdef.coords[0][1];
602 mat[0][2] =
f->brushprimit_texdef.coords[0][2];
603 mat[1][0] =
f->brushprimit_texdef.coords[1][0];
604 mat[1][1] =
f->brushprimit_texdef.coords[1][1];
605 mat[1][2] =
f->brushprimit_texdef.coords[1][2];
608 mapbrush->
epairs = b->epairs;
623 if ( e->
eclass->fixedsize && !
b->entityModel ) {
628 if ( GetTickCount() - lastUpdate > 50 ) {
629 lastUpdate = GetTickCount();
631 sprintf( status,
"Adding primitive %i (patch)", count );
634 sprintf( status,
"Adding primitive %i (brush)", count );
653 bool Map_SaveFile(
const char *filename,
bool use_region,
bool autosave) {
660 int len = strlen(filename);
661 WIN32_FIND_DATA FileData;
662 if (FindFirstFile(filename, &FileData) != INVALID_HANDLE_VALUE) {
664 if (len > 0 && GetFileAttributes(filename) & FILE_ATTRIBUTE_READONLY) {
665 g_pParentWnd->MessageBox(
"File is read only",
"Read Only", MB_OK);
670 if (filename ==
NULL || len == 0 || (filename &&
stricmp(filename,
"unnamed.map") == 0)) {
671 CFileDialog dlgSave(
FALSE,
"map",
NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Map Files (*.map)|*.map||",AfxGetMainWnd());
672 if (dlgSave.DoModal() == IDOK) {
673 filename = dlgSave.m_ofn.lpstrFile;
681 MEMORYSTATUSEX statex;
682 statex.dwLength =
sizeof (statex);
683 GlobalMemoryStatusEx (&statex);
684 if ( statex.dwMemoryLoad > 95 ) {
685 g_pParentWnd->MessageBox(
"Physical memory is over 95% utilized. Consider saving and restarting",
"Memory");
699 if ( _unlink(backup) != 0 && errno != 2 ) {
700 g_pParentWnd->MessageBox(
va(
"Unable to delete %s: %s", backup.
c_str(), strerror(errno) ),
"File Error" );
703 if ( rename(filename, backup) != 0 ) {
704 g_pParentWnd->MessageBox(
va(
"Unable to rename %s to %s: %s", filename, backup.
c_str(), strerror(errno) ),
"File Error" );
711 bool localFile = (strstr(filename,
":") !=
NULL);
712 if (autosave || localFile) {
725 dlg.
SetText(
"Saving worldspawn...");
730 sprintf( buf,
"{\n\"classname\" \"info_player_start\"\n\"origin\"\t \"%i %i %i\"\n\"angle\"\t \"%i\"\n}\n",
736 src.LoadMemory( buf, buf.
Length(),
"regionbuf" );
742 for ( e = entities.
next; e != &entities; e = next ) {
765 sprintf(text,
"%i %i %i", (
int)origin[0], (
int)origin[1], (
int)origin[2]);
774 sprintf(status,
"Saving entity %i (%s)...", count, classname.
c_str());
783 idStr mapExt = (use_region) ?
".reg" :
".map";
786 map.
Write(mapFile, mapExt, !(autosave || localFile));
793 if (!strstr(temp,
"autosave")) {
816 SetKeyValue(world_entity,
"classname",
"worldspawn");
830 g_qeglobals.mapVersion = MAP_VERSION;
855 memset(&td, 0,
sizeof(td));
856 td = g_qeglobals.d_texturewin.texdef;
859 td.SetName(
"textures/REGION");
861 const int REGION_WIDTH = 1024;
889 maxs[2] = mins[2] + REGION_WIDTH;
894 mins[2] = maxs[2] - REGION_WIDTH;
897 for (i = 0; i < 6; i++) {
915 for (i = 0; i < 6; i++) {
931 for (i = 0; i < 3; i++) {
954 for (i = 0; i < 3; i++) {
1007 Sys_Status(
"Tried to region with no selection...\n");
1070 if (!QE_SingleBrush()) {
1095 if (!QE_SingleBrush()) {
1120 int targetnum = atoi(tn + 1);
1121 if (targetnum > maxtarg) {
1122 maxtarg = targetnum;
1128 int targetnum = atoi(tn + 1);
1129 if (targetnum > maxtarg) {
1130 maxtarg = targetnum;
1136 sprintf(rStr,
"t%i", maxtarg + 1);
1154 g_qeglobals.d_parsed_brushes = 0;
1156 CMapStringToString mapStr;
1157 StartTokenParsing(buf);
1158 g_qeglobals.d_num_entities = 0;
1164 g_qeglobals.bNeedConvert =
false;
1165 g_qeglobals.bOldBrushes =
false;
1166 g_qeglobals.bPrimitBrushes =
false;
1167 g_qeglobals.mapVersion = 1.0;
1169 if (GetToken(
true)) {
1170 if (
stricmp(token,
"Version") == 0) {
1172 g_qeglobals.mapVersion = atof(token);
1173 common->
Printf(
"Map version: %1.2f\n", g_qeglobals.mapVersion);
1195 for (b = ent->
brushes.onext; b && b != &ent->
brushes; b = b->onext) {
1202 while (b && b != &ent->
brushes) {
1203 brush_t *bNext = b->onext;
1214 CString strTarget(
"");
1215 if (str.GetLength() > 0) {
1216 if (
FindEntity(
"target", str.GetBuffer(0))) {
1217 if (!mapStr.Lookup(str, strKey)) {
1221 mapStr.SetAt(str, strKey);
1225 SetKeyValue(ent,
"target", strTarget.GetBuffer(0));
1238 if (cstrNameOld != cstrNameNew)
1240 RemappedNames.
Set(cstrNameOld, cstrNameNew);
1250 entities.
prev = ent;
1251 g_qeglobals.d_num_entities++;
1264 for (
int iKeyVal=0; iKeyVal < iNumKeyVals; iKeyVal++)
1274 if (pEntOld && pEntNew)
1276 CString cstrTargetNameOld =
ValueForKey(pEntOld,
"target");
1277 if (!cstrTargetNameOld.IsEmpty())
1283 if ( pEntOldTarget )
1285 LPCSTR psNewTargetName = RemappedNames.
GetString( cstrTargetNameOld );
1286 if (psNewTargetName && psNewTargetName[0])
1301 for (
int i = 0;
i < ptrs.GetSize();
i++) {
1302 Brush_Build(reinterpret_cast < brush_t * > (ptrs[
i]),
true,
false);
1303 Select_Brush(reinterpret_cast < brush_t * > (ptrs[i]),
true,
false);
1315 g_qeglobals.bNeedConvert =
false;
1336 if (
LoadFile( temp, (
void **) &buf) != -1) {
1360 f = fopen(temp,
"w");
1368 g_qeglobals.mapVersion = MAP_VERSION;
1369 fprintf( f,
"Version %1.2f\n", MAP_VERSION );
1377 for ( e = entities.
next; e != &entities; e = next ) {
1378 fprintf( f,
"// entity %i\n", count );
1398 g_qeglobals.mapVersion = MAP_VERSION;
1407 for (e = entities.
next; e != &entities; e = next) {
1435 va_start( argPtr,
string );
1441 while ( (*
string >=
'0' && *
string <=
'9') ||
1442 *
string ==
'.' || *
string ==
'-' || *
string ==
'+' || *
string ==
'#') {
1451 f = va_arg( argPtr,
double );
1455 fprintf( fp,
"%s", buf.
c_str() );
1459 i = va_arg( argPtr,
long );
1460 fprintf( fp,
"%d", i );
1463 u = va_arg( argPtr,
unsigned long );
1464 fprintf( fp,
"%u", u );
1467 u = va_arg( argPtr,
unsigned long );
1468 fprintf( fp,
"%o", u );
1471 u = va_arg( argPtr,
unsigned long );
1472 fprintf( fp,
"%x", u );
1475 u = va_arg( argPtr,
unsigned long );
1476 fprintf( fp,
"%X", u );
1479 i = va_arg( argPtr,
long );
1480 fprintf( fp,
"%c", (
char) i );
1483 str = va_arg( argPtr,
char * );
1484 fprintf( fp,
"%s", str );
1487 fprintf( fp,
"%%" );
1490 common->
Error(
"WriteFileString: invalid %%%c", *
string );
1499 fprintf( fp,
"\t" );
1502 fprintf( fp,
"\n" );
1504 common->
Error(
"WriteFileString: unknown escape character \'%c\'", *
string );
1510 fprintf( fp,
"%c", *
string );
1535 char *buff = Buffer;
1537 va_start( argPtr,
string );
1543 while ( (*
string >=
'0' && *
string <=
'9') ||
1544 *
string ==
'.' || *
string ==
'-' || *
string ==
'+' || *
string ==
'#') {
1553 f = va_arg( argPtr,
double );
1561 i = va_arg( argPtr,
long );
1565 u = va_arg( argPtr,
unsigned long );
1569 u = va_arg( argPtr,
unsigned long );
1573 u = va_arg( argPtr,
unsigned long );
1577 u = va_arg( argPtr,
unsigned long );
1581 i = va_arg( argPtr,
long );
1582 sprintf( buff,
"%c", (
char) i );
1585 str = va_arg( argPtr,
char * );
1592 common->
Error(
"MemFile_fprintf: invalid %%%c", *
string );
1606 common->
Error(
"MemFile_fprintf: unknown escape character \'%c\'", *
string );
1612 sprintf( buff,
"%c", *
string );
1617 buff = Buffer + strlen(Buffer);
CMainFrame * g_pParentWnd
int GetNumSides(void) const
const idPlane & GetPlane(void) const
bool Entity_NameIsUnique(const char *name)
void WINAPI Sys_UpdateWindows(int nBits)
idMapEntity * GetEntity(int i) const
face_t * Face_Alloc(void)
idStr & SetFileExtension(const char *extension)
void AddPrimitive(idMapPrimitive *p)
bool FromPoints(const idVec3 &p1, const idVec3 &p2, const idVec3 &p3, bool fixDegenerate=true)
brush_t * Brush_Alloc(void)
idMapBrushSide * GetSide(int i) const
int GetVertSubdivisions(void) const
void Map_BuildBrushData(void)
bool CheckForTinyBrush(brush_t *b, int n, float fSize)
bool WriteFileString(FILE *fp, char *string,...)
void Entity_Free(entity_t *e)
int AddSide(idMapBrushSide *side)
const idStr & GetKey(void) const
void Entity_UnlinkBrush(brush_t *b)
entity_t between_entities
#define VectorSubtract(a, b, c)
void SetExplicitlySubdivided(bool b)
void Undo_EndBrush(brush_t *pBrush)
bool Map_SaveFile(const char *filename, bool use_region, bool autosave)
void StripTrailing(const char c)
void Map_ImportBuffer(char *buf, bool renameEntities)
void AllowCancel(bool enable)
idFileSystem * fileSystem
brush_t * BrushFromMapBrush(idMapBrush *mapbrush, idVec3 origin)
void Map_RegionBrush(void)
void Sys_Status(const char *psz, int part)
int GetHorzSubdivisions(void) const
const char * ValueForKey(entity_t *ent, const char *key)
void Map_ImportFile(char *fileName)
void Brush_Free(brush_t *b, bool bRemoveNode)
void Map_ApplyRegion(void)
entity_t * Map_FindClass(char *cname)
const char * GetMaterial(void) const
brush_t * selected_face_brush
void MemFile_fprintf(CMemFile *pMemFile, const char *string,...)
void Set(const char *key, const char *value)
void Texture_ClearInuse(void)
void UniqueTargetName(idStr &rStr)
void Undo_Start(char *operation)
int Cmpn(const char *text, int n) const
entity_t * Entity_Parse(bool onlypairs, brush_t *pList)
void Brush_Build(brush_t *b, bool bSnap, bool bMarkMap, bool bConvert, bool updateLights)
void Undo_EndEntity(entity_t *entity)
int Icmp(const char *text) const
idStr & BackSlashesToSlashes(void)
void SetKeyValue(entity_t *ent, const char *key, const char *value, bool trackAngles)
int GetHeight(void) const
idVec3 region_maxs(MAX_WORLD_COORD, MAX_WORLD_COORD, MAX_WORLD_COORD)
brush_t * region_sides[6]
void BuildRendererState()
void ExtractFileName(idStr &dest) const
GLuint GLuint GLsizei count
void SetPlane(const idPlane &p)
void SetMaterial(const char *p)
const char * GetString(const char *key, const char *defaultString="") const
GLubyte GLubyte GLubyte GLubyte w
bool EntityHasModel(entity_t *ent)
idStr & StripFileExtension(void)
const idMaterial * Texture_ForName(const char *name)
static idMapEntity * Parse(idLexer &src, bool worldSpawn=false, float version=CURRENT_MAP_VERSION)
void Brush_AddToList(brush_t *b, brush_t *list)
int GetNumEntities(void) const
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
bool Parse(const char *filename, bool ignoreRegion=false, bool osPath=false)
idMapPrimitive * BrushToMapPrimitive(const brush_t *b, const idVec3 &origin)
void SetEditEntity(entity_t *ent)
void Pointfile_Clear(void)
entity_t * EntityFromMapEntity(idMapEntity *mapent, CWaitDlg *dlg)
bool Write(const char *fileName, const char *ext, bool fromBasePath=true)
void GetTextureMatrix(idVec3 &mat1, idVec3 &mat2)
void RemoveRegionBrushes(void)
void SetText(const char *msg, bool append=false)
bool GetExplicitlySubdivided(void) const
const idStr & GetValue(void) const
void SetVertSubdivisions(int n)
void SetMaterial(const char *p)
void Brush_RemoveFromList(brush_t *b)
int Map_GetUniqueEntityID(const char *prefix, const char *eclass)
brush_t * BrushFromMapPatch(idMapPatch *mappatch, idVec3 origin)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
CInspectorDialog * g_Inspectors
idMapEntity * EntityToMapEntity(entity_t *e, bool use_region, CWaitDlg *dlg)
void Map_SaveBetween(void)
void Map_RestoreBetween(void)
void Map_RegionSelectedBrushes(void)
bool GetVectorForKey(entity_t *ent, const char *key, idVec3 &vec)
void Entity_LinkBrush(entity_t *e, brush_t *b)
idMapPrimitive * GetPrimitive(int i) const
void AddRegionBrushes(void)
void Texture_ShowInuse(void)
int LoadFile(const char *filename, void **bufferptr)
entity_t * AngledEntity()
void Map_LoadFile(const char *filename)
entity_t * FindEntity(const char *pszKey, const char *pszValue)
void BaseForPlane(const idVec3 &normal, const float dist)
brush_t * Brush_Create(idVec3 mins, idVec3 maxs, texdef_t *texdef)
void SetTextureMatrix(const idVec3 mat[2])
const char * GetMaterial(void) const
const char * c_str(void) const
idVec3 region_mins(MIN_WORLD_COORD, MIN_WORLD_COORD, MIN_WORLD_COORD)
void Map_RegionTallBrush(void)
void SetHorzSubdivisions(int n)
const idKeyValue * GetKeyVal(int index) const
char * va(const char *fmt,...)
int AddEntity(idMapEntity *mapentity)
virtual const char * OSPathToRelativePath(const char *OSPath)=0
virtual void Error(const char *fmt,...) id_attribute((format(printf
int GetNumPrimitives(void) const
void Map_SaveSelected(char *fileName)
float FloatForKey(entity_t *ent, const char *key)
void Entity_WriteSelected(entity_t *e, FILE *f)
int GetNumKeyVals(void) const
void SetSize(int patchWidth, int patchHeight)
entity_t * Entity_PostParse(entity_t *ent, brush_t *pList)
int sprintf(idStr &string, const char *fmt,...)
void Entity_Name(entity_t *e, bool force)
eclass_t * Eclass_ForName(const char *name, bool has_brushes)
bool Map_IsBrushFiltered(brush_t *b)
void Map_VerifyCurrentMap(const char *map)