don't parse lumpname as identifier, use indexes instead of pointers (#1311)

* remove redundant '.'
This commit is contained in:
Roman Fomin 2023-12-08 21:07:36 +07:00 committed by GitHub
parent ad992b89be
commit 702b6439bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 22 deletions

View File

@ -36,7 +36,8 @@ static const byte nobrightmap[COLORMASK_SIZE] = { 0 };
const byte *dc_brightmap = nobrightmap; const byte *dc_brightmap = nobrightmap;
typedef struct { typedef struct
{
const char *name; const char *name;
byte colormask[COLORMASK_SIZE]; byte colormask[COLORMASK_SIZE];
} brightmap_t; } brightmap_t;
@ -92,7 +93,7 @@ static void AddBrightmap(brightmap_t *brightmap)
typedef struct typedef struct
{ {
brightmap_t *brightmap; int idx;
const char *name; const char *name;
int num; int num;
} elem_t; } elem_t;
@ -123,15 +124,15 @@ static void AddElem(array_t *array, elem_t *elem)
array->num_elems++; array->num_elems++;
} }
static brightmap_t *GetBrightmap(const char *name) static int GetBrightmap(const char *name)
{ {
int i; int i;
for (i = 0; i < num_brightmaps; ++i) for (i = 0; i < num_brightmaps; ++i)
{ {
if (!strcasecmp(brightmaps_array[i].name, name)) if (!strcasecmp(brightmaps_array[i].name, name))
return &brightmaps_array[i]; return i;
} }
return NULL; return -1;
} }
enum enum
@ -144,15 +145,15 @@ enum
static boolean ParseProperty(u_scanner_t *s, elem_t *elem) static boolean ParseProperty(u_scanner_t *s, elem_t *elem)
{ {
char *name; char *name;
brightmap_t *brightmap; int idx;
int game = DOOM1AND2; int game = DOOM1AND2;
U_MustGetToken(s, TK_Identifier); U_GetString(s);
name = M_StringDuplicate(s->string); name = M_StringDuplicate(s->string);
U_MustGetToken(s, TK_Identifier); U_MustGetToken(s, TK_Identifier);
brightmap = GetBrightmap(s->string); idx = GetBrightmap(s->string);
if (!brightmap) if (idx < 0)
{ {
U_Error(s, "brightmap '%s' not found", s->string); U_Error(s, "brightmap '%s' not found", s->string);
free(name); free(name);
@ -186,28 +187,31 @@ static boolean ParseProperty(u_scanner_t *s, elem_t *elem)
} }
elem->name = name; elem->name = name;
elem->brightmap = brightmap; elem->idx = idx;
return true; return true;
} }
void R_InitFlatBrightmaps(void) void R_InitFlatBrightmaps(void)
{ {
int i; int i;
elem_t *elems = flats_bm.elems;
for (i = 0; i < flats_bm.num_elems; ++i) for (i = 0; i < flats_bm.num_elems; ++i)
{ {
flats_bm.elems[i].num = R_FlatNumForName(flats_bm.elems[i].name); elems[i].num = R_FlatNumForName(elems[i].name);
} }
} }
const byte *R_BrightmapForTexName(const char *texname) const byte *R_BrightmapForTexName(const char *texname)
{ {
int i; int i;
const elem_t *elems = textures_bm.elems;
for (i = textures_bm.num_elems - 1; i >= 0; i--) for (i = textures_bm.num_elems - 1; i >= 0; i--)
{ {
if (!strncasecmp(textures_bm.elems[i].name, texname, 8)) if (!strncasecmp(elems[i].name, texname, 8))
{ {
return textures_bm.elems[i].brightmap->colormask; return brightmaps_array[elems[i].idx].colormask;
} }
} }
@ -219,11 +223,13 @@ const byte *R_BrightmapForSprite(const int type)
if (STRICTMODE(brightmaps) || force_brightmaps) if (STRICTMODE(brightmaps) || force_brightmaps)
{ {
int i; int i;
const elem_t *elems = sprites_bm.elems;
for (i = sprites_bm.num_elems - 1; i >= 0 ; i--) for (i = sprites_bm.num_elems - 1; i >= 0 ; i--)
{ {
if (sprites_bm.elems[i].num == type) if (elems[i].num == type)
{ {
return sprites_bm.elems[i].brightmap->colormask; return brightmaps_array[elems[i].idx].colormask;
} }
} }
} }
@ -236,11 +242,13 @@ const byte *R_BrightmapForFlatNum(const int num)
if (STRICTMODE(brightmaps) || force_brightmaps) if (STRICTMODE(brightmaps) || force_brightmaps)
{ {
int i; int i;
const elem_t *elems = flats_bm.elems;
for (i = flats_bm.num_elems - 1; i >= 0; i--) for (i = flats_bm.num_elems - 1; i >= 0; i--)
{ {
if (flats_bm.elems[i].num == num) if (elems[i].num == num)
{ {
return flats_bm.elems[i].brightmap->colormask; return brightmaps_array[elems[i].idx].colormask;
} }
} }
} }
@ -253,11 +261,13 @@ const byte *R_BrightmapForState(const int state)
if (STRICTMODE(brightmaps) || force_brightmaps) if (STRICTMODE(brightmaps) || force_brightmaps)
{ {
int i; int i;
const elem_t *elems = states_bm.elems;
for (i = states_bm.num_elems - 1; i >= 0; i--) for (i = states_bm.num_elems - 1; i >= 0; i--)
{ {
if (states_bm.elems[i].num == state) if (elems[i].num == state)
{ {
return states_bm.elems[i].brightmap->colormask; return brightmaps_array[elems[i].idx].colormask;
} }
} }
} }
@ -342,8 +352,8 @@ void R_ParseBrightmaps(int lumpnum)
U_Error(s, "state '%d' not found", elem.num); U_Error(s, "state '%d' not found", elem.num);
} }
U_MustGetToken(s, TK_Identifier); U_MustGetToken(s, TK_Identifier);
elem.brightmap = GetBrightmap(s->string); elem.idx = GetBrightmap(s->string);
if (elem.brightmap) if (elem.idx >= 0)
{ {
AddElem(&states_bm, &elem); AddElem(&states_bm, &elem);
} }

View File

@ -533,7 +533,7 @@ void PRINTF_ATTR(2, 0) U_Error(u_scanner_t* s, const char *msg, ...)
va_start(ap, msg); va_start(ap, msg);
M_vsnprintf(buffer, 1024, msg, ap); M_vsnprintf(buffer, 1024, msg, ap);
va_end(ap); va_end(ap);
I_Error("%s:%d:%d:%s.", s->name, s->tokenLine, s->tokenLinePosition, buffer); I_Error("%s:%d:%d:%s", s->name, s->tokenLine, s->tokenLinePosition, buffer);
} }
boolean U_MustGetToken(u_scanner_t* s, char token) boolean U_MustGetToken(u_scanner_t* s, char token)