Numerous performance fixes.

This commit is contained in:
Justin Marshall
2026-05-21 15:36:02 -07:00
parent 2e4265f5a1
commit a89d43628c
29 changed files with 1632 additions and 636 deletions
+115 -72
View File
@@ -5474,97 +5474,140 @@ bool FilterBrush(brush_t *pb) {
the lines can be visible when neither end is. Called for both camera view and xy view.
=======================================================================================================================
*/
void DrawPathLines(void) {
int i, k;
idVec3 mid, mid1;
entity_t *se, *te;
brush_t *sb, *tb;
const char *psz;
idVec3 dir, s1, s2;
float len, f;
int arrows;
int num_entities;
const char *ent_target[MAX_MAP_ENTITIES];
entity_t *ent_entity[MAX_MAP_ENTITIES];
struct pathLineNamedEntity_t {
const char* name;
entity_t* entity;
brush_t* brush;
};
static bool DrawPathLines_IsTargetKey(const char* key) {
if (key == NULL) {
return false;
}
if (idStr::Cmp(key, "target") == 0) {
return true;
}
if (idStr::Cmpn(key, "target", 6) != 0 || key[6] == '\0') {
return false;
}
for (const char* c = key + 6; *c != '\0'; c++) {
if (*c < '0' || *c > '9') {
return false;
}
}
return true;
}
static brush_t* DrawPathLines_FirstBrush(entity_t* ent) {
if (ent == NULL) {
return NULL;
}
brush_t* brush = ent->brushes.onext;
return (brush != &ent->brushes) ? brush : NULL;
}
static void DrawPathLines_AppendNamedEntity(idList<pathLineNamedEntity_t>& namedEntities, idHashIndex& nameHash, entity_t* ent) {
const char* name = ValueForKey(ent, "name");
if (name == NULL || name[0] == '\0') {
return;
}
brush_t* brush = DrawPathLines_FirstBrush(ent);
if (brush == NULL) {
return;
}
pathLineNamedEntity_t named;
named.name = name;
named.entity = ent;
named.brush = brush;
const int index = namedEntities.Append(named);
nameHash.Add(nameHash.GenerateKey(name, true), index);
}
static void DrawPathLines_DrawConnection(const pathLineNamedEntity_t& namedTarget, entity_t* source, brush_t* sourceBrush) {
if (namedTarget.entity == NULL || namedTarget.entity->eclass == NULL || source == NULL || sourceBrush == NULL) {
return;
}
idVec3 mid = namedTarget.brush->owner->origin;
idVec3 mid1 = sourceBrush->owner->origin;
idVec3 dir, s1, s2;
VectorSubtract(mid1, mid, dir);
const float len = dir.Normalize();
s1[0] = -dir[1] * 8 + dir[0] * 8;
s2[0] = dir[1] * 8 + dir[0] * 8;
s1[1] = dir[0] * 8 + dir[1] * 8;
s2[1] = -dir[0] * 8 + dir[1] * 8;
glColor3f(namedTarget.entity->eclass->color[0], namedTarget.entity->eclass->color[1], namedTarget.entity->eclass->color[2]);
glBegin(GL_LINES);
glVertex3fv(mid.ToFloatPtr());
glVertex3fv(mid1.ToFloatPtr());
const int arrows = (int)(len / 256) + 1;
for (int i = 0; i < arrows; i++) {
const float f = len * (i + 0.5f) / arrows;
mid1 = mid + (f * dir);
glVertex3fv(mid1.ToFloatPtr());
glVertex3f(mid1[0] + s1[0], mid1[1] + s1[1], mid1[2]);
glVertex3fv(mid1.ToFloatPtr());
glVertex3f(mid1[0] + s2[0], mid1[1] + s2[1], mid1[2]);
}
glEnd();
}
void DrawPathLines(void) {
if (g_qeglobals.d_savedinfo.exclude & EXCLUDE_PATHS) {
return;
}
num_entities = 0;
for (te = entities.next; te != &entities && num_entities != MAX_MAP_ENTITIES; te = te->next) {
for (int i = 0; i < 2048; i++) {
if (i == 0) {
ent_target[num_entities] = ValueForKey(te, "target");
} else {
ent_target[num_entities] = ValueForKey(te, va("target%i", i));
}
if (ent_target[num_entities][0]) {
ent_entity[num_entities] = te;
num_entities++;
} else if (i > 16) {
break;
}
}
idList<pathLineNamedEntity_t> namedEntities;
idHashIndex nameHash(1024, 1024);
namedEntities.SetGranularity(256);
for (entity_t* ent = entities.next; ent != &entities; ent = ent->next) {
DrawPathLines_AppendNamedEntity(namedEntities, nameHash, ent);
}
for (se = entities.next; se != &entities; se = se->next) {
psz = ValueForKey(se, "name");
if (psz == NULL || psz[0] == '\0') {
for (entity_t* source = entities.next; source != &entities; source = source->next) {
brush_t* sourceBrush = DrawPathLines_FirstBrush(source);
if (sourceBrush == NULL) {
continue;
}
sb = se->brushes.onext;
if (sb == &se->brushes) {
continue;
}
for (k = 0; k < num_entities; k++) {
if (strcmp(ent_target[k], psz)) {
const int numKeys = source->epairs.GetNumKeyVals();
for (int keyIndex = 0; keyIndex < numKeys; keyIndex++) {
const idKeyValue* kv = source->epairs.GetKeyVal(keyIndex);
if (kv == NULL || !DrawPathLines_IsTargetKey(kv->GetKey().c_str())) {
continue;
}
te = ent_entity[k];
tb = te->brushes.onext;
if (tb == &te->brushes) {
const char* targetName = kv->GetValue().c_str();
if (targetName == NULL || targetName[0] == '\0') {
continue;
}
mid = sb->owner->origin;
mid1 = tb->owner->origin;
VectorSubtract(mid1, mid, dir);
len = dir.Normalize();
s1[0] = -dir[1] * 8 + dir[0] * 8;
s2[0] = dir[1] * 8 + dir[0] * 8;
s1[1] = dir[0] * 8 + dir[1] * 8;
s2[1] = -dir[0] * 8 + dir[1] * 8;
glColor3f(se->eclass->color[0], se->eclass->color[1], se->eclass->color[2]);
glBegin(GL_LINES);
glVertex3fv(mid.ToFloatPtr());
glVertex3fv(mid1.ToFloatPtr());
arrows = (int)(len / 256) + 1;
for (i = 0; i < arrows; i++) {
f = len * (i + 0.5) / arrows;
mid1 = mid + (f * dir);
glVertex3fv(mid1.ToFloatPtr());
glVertex3f(mid1[0] + s1[0], mid1[1] + s1[1], mid1[2]);
glVertex3fv(mid1.ToFloatPtr());
glVertex3f(mid1[0] + s2[0], mid1[1] + s2[1], mid1[2]);
const int hashKey = nameHash.GenerateKey(targetName, true);
for (int index = nameHash.First(hashKey); index != -1; index = nameHash.Next(index)) {
const pathLineNamedEntity_t& namedTarget = namedEntities[index];
if (strcmp(namedTarget.name, targetName) == 0) {
DrawPathLines_DrawConnection(namedTarget, source, sourceBrush);
}
}
glEnd();
}
}
return;
}
//