savegame: Moved spawntemp fields into their own stfields list and removed FFL_SPAWNTEMP

Having fields from 2 structs in the same list is very easy to mess up
This commit is contained in:
BjossiAlfreds 2026-05-21 15:45:43 +00:00
parent fd605824d1
commit b878572086
6 changed files with 78 additions and 41 deletions

View file

@ -428,6 +428,7 @@ set(Game-Header
${GAME_SRC_DIR}/savegame/tables/gamemmove_decs.h
${GAME_SRC_DIR}/savegame/tables/gamemmove_list.h
${GAME_SRC_DIR}/savegame/tables/levelfields.h
${GAME_SRC_DIR}/savegame/tables/stfields.h
)
set(Client-Source

View file

@ -147,19 +147,20 @@ ED_ParseField(const char *key, const char *value, edict_t *ent)
return;
}
f = FindSpawnfield(key);
if (!f)
{
gi.dprintf("'%s' is not a field. Value is '%s'\n", key, value);
return;
}
if (f->flags & FFL_SPAWNTEMP)
f = FindSpawntempField(key);
if (f)
{
b = (byte *)&st + f->ofs;
}
else
{
f = FindSpawnfield(key);
if (!f)
{
gi.dprintf("'%s' is not a field. Value is '%s'\n", key, value);
return;
}
b = (byte *)ent + f->ofs;
}

View file

@ -573,8 +573,7 @@ extern cvar_t *g_swap_speed;
/* fields are needed for spawning from the entity
string and saving / loading games */
#define FFL_SPAWNTEMP 1
#define FFL_NOSPAWN 2
#define FFL_NOSPAWN 1
typedef enum
{
@ -602,6 +601,7 @@ typedef struct
} field_t;
const field_t *FindSpawnfield(const char *key);
const field_t *FindSpawntempField(const char *key);
extern gitem_t itemlist[];
extern const int itemlist_len;

View file

@ -155,6 +155,13 @@ static const mmoveList_t mmoveList[] = {
#include "tables/gamemmove_list.h"
};
/*
* Spawntemp fields for entity spawning
*/
static const field_t stfields[] = {
#include "tables/stfields.h"
};
/*
* Entity fields to be saved
*/
@ -252,6 +259,22 @@ sg_fwrite(const void *src, size_t n, FILE *f)
}
}
const field_t *
FindSpawntempField(const char *key)
{
const field_t *f;
for (f = stfields; f < ARREND(stfields); f++)
{
if (!Q_strcasecmp(f->name, key))
{
return f;
}
}
return NULL;
}
const field_t *
FindSpawnfield(const char *key)
{
@ -555,11 +578,6 @@ WriteField1(FILE *f, const field_t *field, void *base, const fptrList_t *fpl)
size_t len;
int index;
if (field->flags & FFL_SPAWNTEMP)
{
return;
}
p = (byte *)base + field->ofs;
switch (field->type)
@ -679,11 +697,6 @@ WriteField2(FILE *f, const field_t *field, const void *base, const fptrList_t *f
{
const void *p;
if (field->flags & FFL_SPAWNTEMP)
{
return;
}
p = (const byte *)base + field->ofs;
switch (field->type)
@ -852,11 +865,6 @@ ReadField(FILE *f, const field_t *field, void *base, const fptrList_t *fpl)
int len;
int index;
if (field->flags & FFL_SPAWNTEMP)
{
return;
}
p = (byte *)base + field->ofs;
switch (field->type)

View file

@ -89,20 +89,4 @@
{"checkattack", FOFS(monsterinfo.checkattack), F_FUNCTION, FFL_NOSPAWN},
{"currentmove", FOFS(monsterinfo.currentmove), F_MMOVE, FFL_NOSPAWN},
{"endfunc", FOFS(moveinfo.endfunc), F_FUNCTION, FFL_NOSPAWN},
{"lip", STOFS(lip), F_INT, FFL_SPAWNTEMP},
{"distance", STOFS(distance), F_INT, FFL_SPAWNTEMP},
{"height", STOFS(height), F_INT, FFL_SPAWNTEMP},
{"noise", STOFS(noise), F_LSTRING, FFL_SPAWNTEMP},
{"pausetime", STOFS(pausetime), F_FLOAT, FFL_SPAWNTEMP},
{"item", STOFS(item), F_LSTRING, FFL_SPAWNTEMP},
{"item", FOFS(item), F_ITEM},
{"gravity", STOFS(gravity), F_LSTRING, FFL_SPAWNTEMP},
{"sky", STOFS(sky), F_LSTRING, FFL_SPAWNTEMP},
{"skyrotate", STOFS(skyrotate), F_FLOAT, FFL_SPAWNTEMP},
{"skyaxis", STOFS(skyaxis), F_VECTOR, FFL_SPAWNTEMP},
{"minyaw", STOFS(minyaw), F_FLOAT, FFL_SPAWNTEMP},
{"maxyaw", STOFS(maxyaw), F_FLOAT, FFL_SPAWNTEMP},
{"minpitch", STOFS(minpitch), F_FLOAT, FFL_SPAWNTEMP},
{"maxpitch", STOFS(maxpitch), F_FLOAT, FFL_SPAWNTEMP},
{"music", STOFS(music), F_LSTRING, FFL_SPAWNTEMP},
{"nextmap", STOFS(nextmap), F_LSTRING, FFL_SPAWNTEMP},

View file

@ -0,0 +1,43 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2011 Yamagi Burmeister
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Spawntemp fields used for entity spawning.
*
* =======================================================================
*/
{"lip", STOFS(lip), F_INT},
{"distance", STOFS(distance), F_INT},
{"height", STOFS(height), F_INT},
{"noise", STOFS(noise), F_LSTRING},
{"pausetime", STOFS(pausetime), F_FLOAT},
{"item", STOFS(item), F_LSTRING},
{"gravity", STOFS(gravity), F_LSTRING, },
{"sky", STOFS(sky), F_LSTRING, },
{"skyrotate", STOFS(skyrotate), F_FLOAT},
{"skyaxis", STOFS(skyaxis), F_VECTOR},
{"minyaw", STOFS(minyaw), F_FLOAT},
{"maxyaw", STOFS(maxyaw), F_FLOAT},
{"minpitch", STOFS(minpitch), F_FLOAT},
{"maxpitch", STOFS(maxpitch), F_FLOAT},
{"music", STOFS(music), F_LSTRING},
{"nextmap", STOFS(nextmap), F_LSTRING},