From 3bf10bef02ccedc621dcc7238f0d71c4a1ef99fb Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Thu, 14 Feb 2013 11:08:22 +1030 Subject: [PATCH] qbsp: pass entity pointer into key/value get/set functions Signed-off-by: Kevin Shanahan --- qbsp/brush.c | 12 ++++++------ qbsp/map.c | 20 ++++++++++---------- qbsp/qbsp.c | 10 +++++----- qbsp/qbsp.h | 6 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/qbsp/brush.c b/qbsp/brush.c index 6bc6ac68..ad7b866d 100644 --- a/qbsp/brush.c +++ b/qbsp/brush.c @@ -296,7 +296,7 @@ FindTargetEntity(const char *szTarget) const char *szName; for (iEntity = 0; iEntity < map.cEntities; iEntity++) { - szName = ValueForKey(iEntity, "targetname"); + szName = ValueForKey(&map.rgEntities[iEntity], "targetname"); if (szName && !strcasecmp(szTarget, szName)) return iEntity; } @@ -317,18 +317,18 @@ FixRotateOrigin(int iEntity, vec3_t offset) const char *szSearch; char szOrigin[20]; - szSearch = ValueForKey(iEntity, "target"); + szSearch = ValueForKey(&map.rgEntities[iEntity], "target"); if (!szSearch) { - szSearch = ValueForKey(iEntity, "classname"); + szSearch = ValueForKey(&map.rgEntities[iEntity], "classname"); Message(msgWarning, warnNoRotateTarget, szSearch); } else { iFoundEnt = FindTargetEntity(szSearch); if (iFoundEnt != -1) - GetVectorForKey(iFoundEnt, "origin", offset); + GetVectorForKey(&map.rgEntities[iFoundEnt], "origin", offset); } sprintf(szOrigin, "%d %d %d", (int)offset[0], (int)offset[1], (int)offset[2]); - SetKeyValue(iEntity, "origin", szOrigin); + SetKeyValue(&map.rgEntities[iEntity], "origin", szOrigin); } @@ -357,7 +357,7 @@ CreateBrushFaces(void) max = brush_maxs[0] = brush_maxs[1] = brush_maxs[2] = -VECT_MAX; // Hipnotic rotation - szClassname = ValueForKey(map.iEntities, "classname"); + szClassname = ValueForKey(&map.rgEntities[map.iEntities], "classname"); if (!strncmp(szClassname, "rotate_", 7)) FixRotateOrigin(map.iEntities, offset); diff --git a/qbsp/map.c b/qbsp/map.c index 831f599c..9a1fa21d 100644 --- a/qbsp/map.c +++ b/qbsp/map.c @@ -116,7 +116,7 @@ ParseEpair(void) e->value = copystring(token); if (!strcasecmp(e->key, "origin")) - GetVectorForKey(map.iEntities, e->key, + GetVectorForKey(&map.rgEntities[map.iEntities], e->key, map.rgEntities[map.iEntities].origin); else if (!strcasecmp(e->key, "classname")) { if (!strcasecmp(e->value, "info_player_start")) { @@ -627,11 +627,11 @@ PrintEntity(int iEntity) const char * -ValueForKey(int iEntity, const char *key) +ValueForKey(const mapentity_t *ent, const char *key) { - epair_t *ep; + const epair_t *ep; - for (ep = map.rgEntities[iEntity].epairs; ep; ep = ep->next) + for (ep = ent->epairs; ep; ep = ep->next) if (!strcmp(ep->key, key)) return ep->value; @@ -640,31 +640,31 @@ ValueForKey(int iEntity, const char *key) void -SetKeyValue(int iEntity, const char *key, const char *value) +SetKeyValue(mapentity_t *ent, const char *key, const char *value) { epair_t *ep; - for (ep = map.rgEntities[iEntity].epairs; ep; ep = ep->next) + for (ep = ent->epairs; ep; ep = ep->next) if (!strcmp(ep->key, key)) { free(ep->value); /* FIXME */ ep->value = copystring(value); return; } ep = AllocMem(OTHER, sizeof(epair_t), true); - ep->next = map.rgEntities[iEntity].epairs; - map.rgEntities[iEntity].epairs = ep; + ep->next = ent->epairs; + ent->epairs = ep; ep->key = copystring(key); ep->value = copystring(value); } void -GetVectorForKey(int iEntity, const char *szKey, vec3_t vec) +GetVectorForKey(const mapentity_t *ent, const char *szKey, vec3_t vec) { const char *value; double v1, v2, v3; - value = ValueForKey(iEntity, szKey); + value = ValueForKey(ent, szKey); v1 = v2 = v3 = 0; // scanf into doubles, then assign, so it is vec_t size independent sscanf(value, "%lf %lf %lf", &v1, &v2, &v3); diff --git a/qbsp/qbsp.c b/qbsp/qbsp.c index f3d7ea10..43e5aed2 100644 --- a/qbsp/qbsp.c +++ b/qbsp/qbsp.c @@ -55,7 +55,7 @@ ProcessEntity(mapentity_t *ent) if (hullnum == 0) Message(msgStat, "MODEL: %s", mod); - SetKeyValue(map.iEntities, "model", mod); + SetKeyValue(&map.rgEntities[map.iEntities], "model", mod); } // take the brush_ts and clip off all overlapping and contained faces, // leaving a perfect skin of the model with no hidden faces @@ -150,11 +150,11 @@ UpdateEntLump(void) map.rgEntities[iEntity].iBrushEnd) continue; sprintf(szMod, "*%i", m); - SetKeyValue(iEntity, "model", szMod); + SetKeyValue(&map.rgEntities[iEntity], "model", szMod); m++; // Do extra work for rotating entities if necessary - szClassname = ValueForKey(iEntity, "classname"); + szClassname = ValueForKey(&map.rgEntities[iEntity], "classname"); if (!strncmp(szClassname, "rotate_", 7)) FixRotateOrigin(iEntity, temp); } @@ -247,9 +247,9 @@ ProcessFile(void) return; } - wadstring = ValueForKey(0, "_wad"); + wadstring = ValueForKey(pWorldEnt, "_wad"); if (!wadstring) - wadstring = ValueForKey(0, "wad"); + wadstring = ValueForKey(pWorldEnt, "wad"); if (!wadstring) Message(msgWarning, warnNoWadKey); else diff --git a/qbsp/qbsp.h b/qbsp/qbsp.h index cc147ac4..e75cc857 100644 --- a/qbsp/qbsp.h +++ b/qbsp/qbsp.h @@ -634,9 +634,9 @@ void LoadMapFile(void); int FindMiptex(char *name); void PrintEntity(int iEntity); -const char *ValueForKey(int iEntity, const char *key); -void SetKeyValue(int iEntity, const char *key, const char *value); -void GetVectorForKey(int iEntity, const char *szKey, vec3_t vec); +const char *ValueForKey(const mapentity_t *ent, const char *key); +void SetKeyValue(mapentity_t *ent, const char *key, const char *value); +void GetVectorForKey(const mapentity_t *ent, const char *szKey, vec3_t vec); void WriteEntitiesToString(void);