entity_t and brush_t now converted to idEditorEntity and idEditorBrush

This commit is contained in:
Justin Marshall
2026-05-24 11:33:16 -07:00
parent d6d01e1faf
commit 3242531044
41 changed files with 1598 additions and 1540 deletions
+98 -100
View File
@@ -36,17 +36,17 @@ int mapModified; // for quit confirmation (0 = clean, 1 = unsaved,
// 2 = autosaved, but not regular saved)
char currentmap[1024];
brush_t active_brushes; // brushes currently being displayed
brush_t selected_brushes; // highlighted
idEditorBrush active_brushes; // brushes currently being displayed
idEditorBrush selected_brushes; // highlighted
face_t *selected_face;
brush_t *selected_face_brush;
idEditorBrush *selected_face_brush;
brush_t filtered_brushes; // brushes that have been filtered or regioned
idEditorBrush filtered_brushes; // brushes that have been filtered or regioned
entity_t entities; // head/tail of doubly linked list
idEditorEntity entities; // head/tail of doubly linked list
entity_t *world_entity = NULL; // "classname" "worldspawn" !
idEditorEntity *world_entity = NULL; // "classname" "worldspawn" !
void AddRegionBrushes(void);
void RemoveRegionBrushes(void);
@@ -63,8 +63,8 @@ void DupLists() {
* Cross map selection saving this could mess this up if you have only part of a
* complex entity selected...
*/
brush_t between_brushes;
entity_t between_entities;
idEditorBrush between_brushes;
idEditorEntity between_entities;
bool g_bRestoreBetween = false;
@@ -393,7 +393,7 @@ void Map_RestoreBetween(void) {
=======================================================================================================================
=======================================================================================================================
*/
bool CheckForTinyBrush(brush_t *b, int n, float fSize) {
bool CheckForTinyBrush(idEditorBrush *b, int n, float fSize) {
bool bTiny = false;
for (int i = 0; i < 3; i++) {
if (b->maxs[i] - b->mins[i] < fSize) {
@@ -413,7 +413,7 @@ bool CheckForTinyBrush(brush_t *b, int n, float fSize) {
=======================================================================================================================
*/
void Map_BuildBrushData(void) {
brush_t *b, *next;
idEditorBrush *b, *next;
if (active_brushes.next == NULL) {
return;
@@ -424,7 +424,7 @@ void Map_BuildBrushData(void) {
int n = 0;
for (b = active_brushes.next; b != NULL && b != &active_brushes; b = next) {
next = b->next;
Brush_Build(b, true, false, false);
b->Brush_Build(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");
@@ -438,11 +438,11 @@ void Map_BuildBrushData(void) {
=======================================================================================================================
=======================================================================================================================
*/
entity_t *Map_FindClass(char *cname) {
entity_t *ent;
idEditorEntity *Map_FindClass(char *cname) {
idEditorEntity *ent;
for (ent = entities.next; ent != &entities; ent = ent->next) {
if (!strcmp(cname, ValueForKey(ent, "classname"))) {
if (!strcmp(cname, ent->ValueForKey("classname"))) {
return ent;
}
}
@@ -455,11 +455,11 @@ entity_t *Map_FindClass(char *cname) {
=======================================================================================================================
*/
int Map_GetUniqueEntityID(const char *prefix, const char *eclass) {
entity_t *ent;
idEditorEntity *ent;
int id = 0;
for (ent = entities.next; ent != &entities; ent = ent->next) {
if (!strcmp(eclass, ValueForKey(ent, "classname"))) {
const char *name = ValueForKey(ent, "name");
if (!strcmp(eclass, ent->ValueForKey("classname"))) {
const char *name = ent->ValueForKey("name");
if (name && name[0]) {
const char *buf;
if (prefix && *prefix) {
@@ -486,13 +486,13 @@ int Map_GetUniqueEntityID(const char *prefix, const char *eclass) {
=======================================================================================================================
*/
bool Entity_NameIsUnique(const char *name) {
entity_t *ent;
idEditorEntity *ent;
if (name == NULL) {
return false;
}
for (ent = entities.next; ent != &entities; ent = ent->next) {
const char *testName = ValueForKey(ent, "name");
const char *testName = ent->ValueForKey("name");
if (testName) {
if ( idStr::Icmp(name, testName) == 0 ) {
return false;
@@ -549,12 +549,12 @@ void Map_Free(void) {
}
while (entities.next != &entities) {
Entity_Free(entities.next);
idEditorEntity::Entity_Free(entities.next);
}
}
if (world_entity) {
Entity_Free(world_entity);
idEditorEntity::Entity_Free(world_entity);
}
world_entity = NULL;
@@ -564,8 +564,8 @@ void Map_Free(void) {
=======================================================================================================================
=======================================================================================================================
*/
entity_t *AngledEntity() {
entity_t *ent = Map_FindClass("info_player_start");
idEditorEntity *AngledEntity() {
idEditorEntity *ent = Map_FindClass("info_player_start");
if (!ent) {
ent = Map_FindClass("info_player_deathmatch");
}
@@ -594,7 +594,7 @@ entity_t *AngledEntity() {
}
brush_t *BrushFromMapPatch(idMapPatch *mappatch, idVec3 origin) {
idEditorBrush *BrushFromMapPatch(idMapPatch *mappatch, idVec3 origin) {
patchMesh_t *pm = MakeNewPatch(mappatch->GetWidth(), mappatch->GetHeight());
pm->d_texture = Texture_ForName(mappatch->GetMaterial());
for (int i = 0; i < mappatch->GetWidth(); i++) {
@@ -610,12 +610,12 @@ brush_t *BrushFromMapPatch(idMapPatch *mappatch, idVec3 origin) {
pm->epairs = new idDict;
*pm->epairs = mappatch->epairs;
}
brush_t *b = AddBrushForPatch(pm, false);
idEditorBrush *b = AddBrushForPatch(pm, false);
return b;
}
brush_t *BrushFromMapBrush(idMapBrush *mapbrush, idVec3 origin) {
brush_t *b = NULL;
idEditorBrush *BrushFromMapBrush(idMapBrush *mapbrush, idVec3 origin) {
idEditorBrush *b = NULL;
if (mapbrush) {
b = Brush_Alloc();
int count = mapbrush->GetNumSides();
@@ -661,14 +661,14 @@ brush_t *BrushFromMapBrush(idMapBrush *mapbrush, idVec3 origin) {
return b;
}
entity_t *EntityFromMapEntity(idMapEntity *mapent, CWaitDlg *dlg) {
entity_t *ent = NULL;
idEditorEntity *EntityFromMapEntity(idMapEntity *mapent, CWaitDlg *dlg) {
idEditorEntity *ent = NULL;
if (mapent) {
ent = Entity_New();
ent = idEditorEntity::Entity_New();
ent->brushes.onext = ent->brushes.oprev = &ent->brushes;
ent->origin.Zero();
ent->epairs = mapent->epairs;
GetVectorForKey(ent, "origin", ent->origin);
ent->GetVectorForKey("origin", ent->origin);
int count = mapent->GetNumPrimitives();
long lastUpdate = 0;
idStr status;
@@ -689,7 +689,7 @@ entity_t *EntityFromMapEntity(idMapEntity *mapent, CWaitDlg *dlg) {
return ent;
}
brush_t *b = NULL;
idEditorBrush *b = NULL;
if (prim->GetType() == idMapPrimitive::TYPE_BRUSH) {
idMapBrush *mapbrush = reinterpret_cast<idMapBrush*>(prim);
b = BrushFromMapBrush(mapbrush, ent->origin);
@@ -711,14 +711,13 @@ entity_t *EntityFromMapEntity(idMapEntity *mapent, CWaitDlg *dlg) {
return ent;
}
extern entity_t *Entity_PostParse(entity_t *ent, brush_t *pList);
/*
=======================================================================================================================
Map_LoadFile
=======================================================================================================================
*/
void Map_LoadFile(const char *filename) {
entity_t *ent;
idEditorEntity *ent;
CWaitDlg dlg;
idStr fileStr, status;
idMapFile mapfile;
@@ -769,11 +768,11 @@ void Map_LoadFile(const char *filename) {
}
if (classname == "worldspawn") {
world_entity = EntityFromMapEntity(mapent, &dlg);
Entity_PostParse(world_entity, &active_brushes);
world_entity->Entity_PostParse(&active_brushes);
} else {
ent = EntityFromMapEntity(mapent, &dlg);
Entity_PostParse(ent, &active_brushes);
Entity_Name(ent, true);
ent->Entity_PostParse(&active_brushes);
ent->Entity_Name(true);
// add the entity to the end of the entity list
ent->next = &entities;
ent->prev = entities.prev;
@@ -816,9 +815,9 @@ void Map_LoadFile(const char *filename) {
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");
ent->GetVectorForKey("origin", g_pParentWnd->GetCamera()->Camera().origin);
ent->GetVectorForKey("origin", g_pParentWnd->GetXYWnd()->GetOrigin());
g_pParentWnd->GetCamera()->Camera().angles[YAW] = ent->FloatForKey("angle");
}
else {
g_pParentWnd->GetCamera()->Camera().angles[YAW] = 0;
@@ -853,7 +852,7 @@ void Map_VerifyCurrentMap(const char *map) {
}
}
idMapPrimitive *BrushToMapPrimitive( const brush_t *b, const idVec3 &origin ) {
idMapPrimitive *BrushToMapPrimitive( const idEditorBrush *b, const idVec3 &origin ) {
if ( b->pPatch ) {
idMapPatch *patch = new idMapPatch( b->pPatch->width * 6, b->pPatch->height * 6 );
patch->SetSize( b->pPatch->width, b->pPatch->height );
@@ -908,14 +907,14 @@ idMapPrimitive *BrushToMapPrimitive( const brush_t *b, const idVec3 &origin ) {
}
}
idMapEntity *EntityToMapEntity(entity_t *e, bool use_region, CWaitDlg *dlg) {
idMapEntity *EntityToMapEntity(idEditorEntity *e, bool use_region, CWaitDlg *dlg) {
idMapEntity *mapent = new idMapEntity;
mapent->epairs = e->epairs;
idStr status;
int count = 0;
long lastUpdate = 0;
if ( !EntityHasModel( e ) ) {
for ( brush_t *b = e->brushes.onext; b != &e->brushes; b = b->onext ) {
if ( !e->EntityHasModel() ) {
for ( idEditorBrush *b = e->brushes.onext; b != &e->brushes; b = b->onext ) {
count++;
if ( e->eclass->fixedsize && !b->entityModel ) {
continue;
@@ -948,10 +947,10 @@ idMapEntity *EntityToMapEntity(entity_t *e, bool use_region, CWaitDlg *dlg) {
=======================================================================================================================
*/
bool Map_SaveFile(const char *filename, bool use_region, bool autosave) {
entity_t *e, *next;
idEditorEntity *e, *next;
idStr temp;
int count;
brush_t *b;
idEditorBrush *b;
idStr status;
int len = strlen(filename);
@@ -1044,7 +1043,7 @@ bool Map_SaveFile(const char *filename, bool use_region, bool autosave) {
count++;
next = e->next;
if (e->brushes.onext == &e->brushes) {
Entity_Free(e); // no brushes left, so remove it
idEditorEntity::Entity_Free(e); // no brushes left, so remove it
}
else {
if (use_region) {
@@ -1060,14 +1059,14 @@ bool Map_SaveFile(const char *filename, bool use_region, bool autosave) {
}
idVec3 origin;
if (!GetVectorForKey(e, "origin", origin)) {
if (!e->GetVectorForKey("origin", origin)) {
idStr text;
VectorSubtract(e->brushes.onext->mins, e->eclass->mins, origin);
sprintf(text, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
SetKeyValue(e, "origin", text);
e->SetKeyValue("origin", text);
}
if (use_region && !idStr::Icmp(ValueForKey(e, "classname"), "info_player_start")) {
if (use_region && !idStr::Icmp(e->ValueForKey("classname"), "info_player_start")) {
continue;
}
@@ -1115,9 +1114,9 @@ void Map_New(void) {
Patch_Cleanup();
g_Inspectors->entityDlg.SetEditEntity ( NULL );
world_entity = Entity_New();
world_entity = idEditorEntity::Entity_New();
world_entity->brushes.onext = world_entity->brushes.oprev = &world_entity->brushes;
SetKeyValue(world_entity, "classname", "worldspawn");
world_entity->SetKeyValue("classname", "worldspawn");
world_entity->eclass = Eclass_ForName("worldspawn", true);
if (g_qeglobals.rw) {
g_qeglobals.rw->ClearWorldDecals();
@@ -1143,7 +1142,7 @@ bool region_active;
idVec3 region_mins(MIN_WORLD_COORD, MIN_WORLD_COORD, MIN_WORLD_COORD);
idVec3 region_maxs(MAX_WORLD_COORD, MAX_WORLD_COORD, MAX_WORLD_COORD);
brush_t *region_sides[6];
idEditorBrush *region_sides[6];
/*
=======================================================================================================================
@@ -1202,9 +1201,9 @@ const int REGION_WIDTH = 1024;
region_sides[5] = Brush_Create(mins, maxs, &td);
for (i = 0; i < 6; i++) {
Brush_AddToList(region_sides[i], &selected_brushes);
Entity_LinkBrush(world_entity, region_sides[i]);
Brush_Build(region_sides[i]);
region_sides[i]->Brush_AddToList(&selected_brushes);
world_entity->Entity_LinkBrush(region_sides[i]);
region_sides[i]->Brush_Build();
}
}
@@ -1228,7 +1227,7 @@ void RemoveRegionBrushes(void) {
=======================================================================================================================
=======================================================================================================================
*/
bool Map_IsBrushFiltered(brush_t *b) {
bool Map_IsBrushFiltered(idEditorBrush *b) {
int i;
if (!region_active) {
@@ -1254,7 +1253,7 @@ bool Map_IsBrushFiltered(brush_t *b) {
=======================================================================================================================
*/
void Map_RegionOff(void) {
brush_t *b, *next;
idEditorBrush *b, *next;
int i;
region_active = false;
@@ -1269,13 +1268,13 @@ void Map_RegionOff(void) {
continue; // still filtered
}
Brush_RemoveFromList(b);
b->Brush_RemoveFromList();
if (active_brushes.next == NULL || active_brushes.prev == NULL) {
active_brushes.next = &active_brushes;
active_brushes.prev = &active_brushes;
}
Brush_AddToList(b, &active_brushes);
b->Brush_AddToList(&active_brushes);
}
Sys_UpdateWindows(W_ALL);
@@ -1286,7 +1285,7 @@ void Map_RegionOff(void) {
=======================================================================================================================
*/
void Map_ApplyRegion(void) {
brush_t *b, *next;
idEditorBrush *b, *next;
region_active = true;
for (b = active_brushes.next; b != &active_brushes; b = next) {
@@ -1295,8 +1294,8 @@ void Map_ApplyRegion(void) {
continue; // still filtered
}
Brush_RemoveFromList(b);
Brush_AddToList(b, &filtered_brushes);
b->Brush_RemoveFromList();
b->Brush_AddToList(&filtered_brushes);
}
Sys_UpdateWindows(W_ALL);
@@ -1372,7 +1371,7 @@ void Map_RegionXY(void) {
=======================================================================================================================
*/
void Map_RegionTallBrush(void) {
brush_t *b;
idEditorBrush *b;
if (!QE_SingleBrush()) {
return;
@@ -1397,7 +1396,7 @@ void Map_RegionTallBrush(void) {
=======================================================================================================================
*/
void Map_RegionBrush(void) {
brush_t *b;
idEditorBrush *b;
if (!QE_SingleBrush()) {
return;
@@ -1421,8 +1420,8 @@ void Map_RegionBrush(void) {
void UniqueTargetName(idStr &rStr) {
// make a unique target value
int maxtarg = 0;
for (entity_t * e = entities.next; e != &entities; e = e->next) {
const char *tn = ValueForKey(e, "name");
for (idEditorEntity * e = entities.next; e != &entities; e = e->next) {
const char *tn = e->ValueForKey("name");
if (tn && tn[0]) {
int targetnum = atoi(tn + 1);
if (targetnum > maxtarg) {
@@ -1430,7 +1429,7 @@ void UniqueTargetName(idStr &rStr) {
}
}
else {
tn = ValueForKey(e, "target");
tn = e->ValueForKey("target");
if (tn && tn[0]) {
int targetnum = atoi(tn + 1);
if (targetnum > maxtarg) {
@@ -1450,8 +1449,8 @@ void UniqueTargetName(idStr &rStr) {
// =======================================================================================================================
//
void Map_ImportBuffer(char *buf, bool renameEntities) {
entity_t *ent;
brush_t *b = NULL;
idEditorEntity *ent;
idEditorBrush *b = NULL;
CPtrArray ptrs;
Select_Deselect();
@@ -1487,10 +1486,10 @@ void Map_ImportBuffer(char *buf, bool renameEntities) {
while (1) {
//
// use the selected brushes list as it's handy ent = Entity_Parse (false,
// use the selected brushes list as it's handy ent = idEditorEntity::Entity_Parse(false,
// &selected_brushes);
//
ent = Entity_Parse(false, &active_brushes);
ent = idEditorEntity::Entity_Parse(false, &active_brushes);
if (!ent) {
break;
}
@@ -1503,24 +1502,24 @@ void Map_ImportBuffer(char *buf, bool renameEntities) {
Undo_EndBrush(b);
}
if (!strcmp(ValueForKey(ent, "classname"), "worldspawn")) {
if (!strcmp(ent->ValueForKey("classname"), "worldspawn")) {
// world brushes need to be added to the current world entity
b = ent->brushes.onext;
while (b && b != &ent->brushes) {
brush_t *bNext = b->onext;
Entity_UnlinkBrush(b);
Entity_LinkBrush(world_entity, b);
idEditorBrush *bNext = b->onext;
idEditorEntity::Entity_UnlinkBrush(b);
world_entity->Entity_LinkBrush(b);
ptrs.Add(b);
b = bNext;
}
}
else {
// the following bit remaps conflicting target/targetname key/value pairs
CString str = ValueForKey(ent, "target");
CString str = ent->ValueForKey("target");
CString strKey;
CString strTarget("");
if (str.GetLength() > 0) {
if (FindEntity("target", str.GetBuffer(0))) {
if (idEditorEntity::FindEntity("target", str.GetBuffer(0))) {
if (!mapStr.Lookup(str, strKey)) {
idStr key;
UniqueTargetName(key);
@@ -1529,25 +1528,24 @@ void Map_ImportBuffer(char *buf, bool renameEntities) {
}
strTarget = strKey;
SetKeyValue(ent, "target", strTarget.GetBuffer(0));
ent->SetKeyValue("target", strTarget.GetBuffer(0));
}
}
/*
* str = ValueForKey(ent, "name"); if (str.GetLength() > 0) { if
* (FindEntity("name", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) {
* UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } Entity_SetName(ent,
* strKey.GetBuffer(0)); } }
* str = ent->ValueForKey("name"); if (str.GetLength() > 0) { if
* (idEditorEntity::FindEntity("name", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) {
* UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } ent->Entity_SetName(* strKey.GetBuffer(0)); } }
*/
CString cstrNameOld = ValueForKey(ent, "name");
Entity_Name(ent, renameEntities);
CString cstrNameNew = ValueForKey(ent, "name");
CString cstrNameOld = ent->ValueForKey("name");
ent->Entity_Name(renameEntities);
CString cstrNameNew = ent->ValueForKey("name");
if (cstrNameOld != cstrNameNew)
{
RemappedNames.Set(cstrNameOld, cstrNameNew);
}
//
// if (strTarget.GetLength() > 0) SetKeyValue(ent, "target",
// if (strTarget.GetLength() > 0) ent->SetKeyValue("target",
// strTarget.GetBuffer(0));
// add the entity to the end of the entity list
//
@@ -1575,24 +1573,24 @@ void Map_ImportBuffer(char *buf, bool renameEntities) {
LPCSTR psOldName = pKeyVal->GetKey().c_str();
LPCSTR psNewName = pKeyVal->GetValue().c_str();
entity_t *pEntOld = FindEntity("name", psOldName); // original ent we cloned from
entity_t *pEntNew = FindEntity("name", psNewName); // cloned ent
idEditorEntity *pEntOld = idEditorEntity::FindEntity("name", psOldName); // original ent we cloned from
idEditorEntity *pEntNew = idEditorEntity::FindEntity("name", psNewName); // cloned ent
if (pEntOld && pEntNew)
{
CString cstrTargetNameOld = ValueForKey(pEntOld, "target");
CString cstrTargetNameOld = pEntOld->ValueForKey("target");
if (!cstrTargetNameOld.IsEmpty())
{
// ok, this ent was targeted at another ent, so it's clone needs updating to point to
// the clone of that target, so...
//
entity_t *pEntOldTarget = FindEntity("name", cstrTargetNameOld);
idEditorEntity *pEntOldTarget = idEditorEntity::FindEntity("name", cstrTargetNameOld);
if ( pEntOldTarget )
{
LPCSTR psNewTargetName = RemappedNames.GetString( cstrTargetNameOld );
if (psNewTargetName && psNewTargetName[0])
{
SetKeyValue(pEntNew, "target", psNewTargetName);
pEntNew->SetKeyValue("target", psNewTargetName);
}
}
}
@@ -1606,8 +1604,8 @@ void Map_ImportBuffer(char *buf, bool renameEntities) {
//
g_bScreenUpdates = false;
for (int i = 0; i < ptrs.GetSize(); i++) {
Brush_Build(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
Select_Brush(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
reinterpret_cast < idEditorBrush * > (ptrs[i])->Brush_Build(true, false);
Select_Brush(reinterpret_cast < idEditorBrush * > (ptrs[i]), true, false);
}
// ::LockWindowUpdate(NULL);
@@ -1657,7 +1655,7 @@ void Map_ImportFile(char *fileName) {
// =======================================================================================================================
//
void Map_SaveSelected(char *fileName) {
entity_t *e, *next;
idEditorEntity *e, *next;
FILE *f;
idStr temp;
int count;
@@ -1677,14 +1675,14 @@ void Map_SaveSelected(char *fileName) {
// write world entity second
world_entity->origin.Zero();
Entity_WriteSelected( world_entity, f );
world_entity->Entity_WriteSelected(f );
// then write all other ents
count = 1;
for ( e = entities.next; e != &entities; e = next ) {
fprintf( f, "// entity %i\n", count );
count++;
Entity_WriteSelected( e, f );
e->Entity_WriteSelected(f );
next = e->next;
}
@@ -1697,7 +1695,7 @@ void Map_SaveSelected(char *fileName) {
// =======================================================================================================================
//
void Map_SaveSelected(CMemFile *pMemFile, CMemFile *pPatchFile) {
entity_t *e, *next;
idEditorEntity *e, *next;
int count;
CString strTemp;
@@ -1707,14 +1705,14 @@ void Map_SaveSelected(CMemFile *pMemFile, CMemFile *pPatchFile) {
// write world entity first
world_entity->origin.Zero();
Entity_WriteSelected(world_entity, pMemFile);
world_entity->Entity_WriteSelected(pMemFile);
// then write all other ents
count = 1;
for (e = entities.next; e != &entities; e = next) {
MemFile_fprintf(pMemFile, "// entity %i\n", count);
count++;
Entity_WriteSelected(e, pMemFile);
e->Entity_WriteSelected(pMemFile);
next = e->next;
}