More conversion
This commit is contained in:
+84
-77
@@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
// sv_edict.c -- entity dictionary
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "quakedef.hpp"
|
||||
|
||||
dprograms_t *progs;
|
||||
@@ -72,17 +74,17 @@ static gefv_cache gefvCache[GEFV_CACHESIZE] =
|
||||
{ NULL, "" }
|
||||
};
|
||||
|
||||
cvar_t nomonsters = {"nomonsters", "0", CVAR_NONE};
|
||||
cvar_t gamecfg = {"gamecfg", "0", CVAR_NONE};
|
||||
cvar_t scratch1 = {"scratch1", "0", CVAR_NONE};
|
||||
cvar_t scratch2 = {"scratch2", "0", CVAR_NONE};
|
||||
cvar_t scratch3 = {"scratch3", "0", CVAR_NONE};
|
||||
cvar_t scratch4 = {"scratch4", "0", CVAR_NONE};
|
||||
cvar_t savedgamecfg = {"savedgamecfg", "0", CVAR_ARCHIVE};
|
||||
cvar_t saved1 = {"saved1", "0", CVAR_ARCHIVE};
|
||||
cvar_t saved2 = {"saved2", "0", CVAR_ARCHIVE};
|
||||
cvar_t saved3 = {"saved3", "0", CVAR_ARCHIVE};
|
||||
cvar_t saved4 = {"saved4", "0", CVAR_ARCHIVE};
|
||||
convar nomonsters{"nomonsters", "0"};
|
||||
convar gamecfg{"gamecfg", "0"};
|
||||
convar scratch1{"scratch1", "0"};
|
||||
convar scratch2{"scratch2", "0"};
|
||||
convar scratch3{"scratch3", "0"};
|
||||
convar scratch4{"scratch4", "0"};
|
||||
convar savedgamecfg{"savedgamecfg", "0", {.archive = true}};
|
||||
convar saved1{"saved1", "0", {.archive = true}};
|
||||
convar saved2{"saved2", "0", {.archive = true}};
|
||||
convar saved3{"saved3", "0", {.archive = true}};
|
||||
convar saved4{"saved4", "0", {.archive = true}};
|
||||
|
||||
/*
|
||||
=================
|
||||
@@ -619,7 +621,7 @@ static void ED_PrintEdict_f (void)
|
||||
if (!sv.active)
|
||||
return;
|
||||
|
||||
i = Q_atoi (Cmd_Argv(1));
|
||||
i = Q_atoi (command::argv(1).value_or("").c_str());
|
||||
if (i < 0 || i >= sv.num_edicts)
|
||||
{
|
||||
Con_Printf("Bad edict number\n");
|
||||
@@ -711,41 +713,43 @@ void ED_WriteGlobals (FILE *f)
|
||||
ED_ParseGlobals
|
||||
=============
|
||||
*/
|
||||
const char *ED_ParseGlobals (const char *data)
|
||||
void ED_ParseGlobals (std::istringstream &ss)
|
||||
{
|
||||
char keyname[64];
|
||||
ddef_t *key;
|
||||
|
||||
while (1)
|
||||
std::string keyname;
|
||||
|
||||
while (true)
|
||||
{
|
||||
// parse key
|
||||
data = COM_Parse (data);
|
||||
if (com_token[0] == '}')
|
||||
auto token = common::parse_token(ss);
|
||||
if (token.has_value() && token->front() == '}') {
|
||||
break;
|
||||
if (!data)
|
||||
}
|
||||
if (ss.eof()) {
|
||||
Host_Error ("ED_ParseEntity: EOF without closing brace");
|
||||
}
|
||||
|
||||
q_strlcpy (keyname, com_token, sizeof(keyname));
|
||||
keyname = token.value();
|
||||
|
||||
// parse value
|
||||
data = COM_Parse (data);
|
||||
if (!data)
|
||||
token = common::parse_token(ss);
|
||||
if (ss.eof())
|
||||
Host_Error ("ED_ParseEntity: EOF without closing brace");
|
||||
|
||||
if (com_token[0] == '}')
|
||||
if (token->front() == '}')
|
||||
Host_Error ("ED_ParseEntity: closing brace without data");
|
||||
|
||||
key = ED_FindGlobal (keyname);
|
||||
key = ED_FindGlobal (keyname.c_str());
|
||||
if (!key)
|
||||
{
|
||||
Con_Printf ("'%s' is not a global\n", keyname);
|
||||
Con_Printf ("'%s' is not a global\n", keyname.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ED_ParseEpair ((void *)pr_globals, key, com_token))
|
||||
if (!ED_ParseEpair ((void *)pr_globals, key, token->c_str()))
|
||||
Host_Error ("ED_ParseGlobals: parse error");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@@ -879,13 +883,14 @@ ed should be a properly initialized empty edict.
|
||||
Used for initial level load and for savegames.
|
||||
====================
|
||||
*/
|
||||
const char *ED_ParseEdict (const char *data, edict_t *ent)
|
||||
void ED_ParseEdict(std::istringstream &ss, edict_t *ent)
|
||||
{
|
||||
ddef_t *key;
|
||||
char keyname[256];
|
||||
qboolean anglehack, init;
|
||||
int n;
|
||||
|
||||
std::string keyname{};
|
||||
|
||||
init = false;
|
||||
|
||||
// clear it
|
||||
@@ -896,83 +901,82 @@ const char *ED_ParseEdict (const char *data, edict_t *ent)
|
||||
while (1)
|
||||
{
|
||||
// parse key
|
||||
data = COM_Parse (data);
|
||||
if (com_token[0] == '}')
|
||||
auto token = common::parse_token(ss);
|
||||
if (token.has_value() && token->front() == '}') {
|
||||
break;
|
||||
if (!data)
|
||||
}
|
||||
if (ss.eof()) {
|
||||
Host_Error ("ED_ParseEntity: EOF without closing brace");
|
||||
}
|
||||
|
||||
// anglehack is to allow QuakeEd to write single scalar angles
|
||||
// and allow them to be turned into vectors. (FIXME...)
|
||||
if (!strcmp(com_token, "angle"))
|
||||
if (token == "angle")
|
||||
{
|
||||
strcpy (com_token, "angles");
|
||||
token = "angles";
|
||||
anglehack = true;
|
||||
}
|
||||
else
|
||||
anglehack = false;
|
||||
|
||||
// FIXME: change light to _light to get rid of this hack
|
||||
if (!strcmp(com_token, "light"))
|
||||
strcpy (com_token, "light_lev"); // hack for single light def
|
||||
if (token == "light") {
|
||||
token = "light_lev";
|
||||
}
|
||||
|
||||
q_strlcpy (keyname, com_token, sizeof(keyname));
|
||||
keyname = *token;
|
||||
|
||||
// another hack to fix keynames with trailing spaces
|
||||
n = strlen(keyname);
|
||||
while (n && keyname[n-1] == ' ')
|
||||
{
|
||||
keyname[n-1] = 0;
|
||||
n--;
|
||||
while (!keyname.empty() && keyname.back() == ' ') {
|
||||
keyname.pop_back();
|
||||
}
|
||||
|
||||
// parse value
|
||||
// HACK: we allow truncation when reading the wad field,
|
||||
// otherwise maps using lots of wads with absolute paths
|
||||
// could cause a parse error
|
||||
data = COM_ParseEx (data, !strcmp (keyname, "wad") ? CPE_ALLOWTRUNC : CPE_NOTRUNC);
|
||||
if (!data)
|
||||
token = common::parse_token(ss);
|
||||
if (ss.eof()) {
|
||||
Host_Error ("ED_ParseEntity: EOF without closing brace");
|
||||
}
|
||||
|
||||
if (com_token[0] == '}')
|
||||
if (token->front() == '}') {
|
||||
Host_Error ("ED_ParseEntity: closing brace without data");
|
||||
}
|
||||
|
||||
init = true;
|
||||
|
||||
// keynames with a leading underscore are used for utility comments,
|
||||
// and are immediately discarded by quake
|
||||
if (keyname[0] == '_')
|
||||
if (keyname[0] == '_') {
|
||||
continue;
|
||||
}
|
||||
|
||||
//johnfitz -- hack to support .alpha even when progs.dat doesn't know about it
|
||||
if (!strcmp(keyname, "alpha"))
|
||||
ent->alpha = ENTALPHA_ENCODE(Q_atof(com_token));
|
||||
if (keyname == "alpha")
|
||||
ent->alpha = ENTALPHA_ENCODE(Q_atof(token->c_str()));
|
||||
//johnfitz
|
||||
|
||||
key = ED_FindField (keyname);
|
||||
key = ED_FindField (keyname.c_str());
|
||||
if (!key)
|
||||
{
|
||||
//johnfitz -- HACK -- suppress error becuase fog/sky/alpha fields might not be mentioned in defs.qc
|
||||
if (strncmp(keyname, "sky", 3) && strcmp(keyname, "fog") && strcmp(keyname, "alpha"))
|
||||
Con_DPrintf ("\"%s\" is not a field\n", keyname); //johnfitz -- was Con_Printf
|
||||
if (keyname != "sky" && keyname != "fog" && keyname != "alpha")
|
||||
Con_DPrintf ("\"%s\" is not a field\n", keyname.c_str()); //johnfitz -- was Con_Printf
|
||||
continue;
|
||||
}
|
||||
|
||||
if (anglehack)
|
||||
{
|
||||
char temp[32];
|
||||
strcpy (temp, com_token);
|
||||
sprintf (com_token, "0 %s 0", temp);
|
||||
token = std::format("0 {} 0", *token);
|
||||
}
|
||||
|
||||
if (!ED_ParseEpair ((void *)&ent->v, key, com_token))
|
||||
if (!ED_ParseEpair ((void *)&ent->v, key, token->c_str()))
|
||||
Host_Error ("ED_ParseEdict: parse error");
|
||||
}
|
||||
|
||||
if (!init)
|
||||
ent->free = true;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -999,21 +1003,24 @@ void ED_LoadFromFile (const char *data)
|
||||
|
||||
pr_global_struct->time = sv.time;
|
||||
|
||||
std::istringstream ss{data};
|
||||
|
||||
|
||||
// parse ents
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
// parse the opening brace
|
||||
data = COM_Parse (data);
|
||||
if (!data)
|
||||
auto token = common::parse_token(ss);
|
||||
if (ss.eof())
|
||||
break;
|
||||
if (com_token[0] != '{')
|
||||
Host_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
|
||||
if (token->front() != '{')
|
||||
Host_Error ("ED_LoadFromFile: found %s when expecting {", token->c_str());
|
||||
|
||||
if (!ent)
|
||||
ent = EDICT_NUM(0);
|
||||
else
|
||||
ent = ED_Alloc ();
|
||||
data = ED_ParseEdict (data, ent);
|
||||
ED_ParseEdict (ss, ent);
|
||||
|
||||
// remove things from different skill levels or deathmatch
|
||||
if (deathmatch.value)
|
||||
@@ -1270,21 +1277,21 @@ PR_Init
|
||||
*/
|
||||
void PR_Init (void)
|
||||
{
|
||||
Cmd_AddCommand ("edict", ED_PrintEdict_f);
|
||||
Cmd_AddCommand ("edicts", ED_PrintEdicts);
|
||||
Cmd_AddCommand ("edictcount", ED_Count);
|
||||
Cmd_AddCommand ("profile", PR_Profile_f);
|
||||
Cvar_RegisterVariable (&nomonsters);
|
||||
Cvar_RegisterVariable (&gamecfg);
|
||||
Cvar_RegisterVariable (&scratch1);
|
||||
Cvar_RegisterVariable (&scratch2);
|
||||
Cvar_RegisterVariable (&scratch3);
|
||||
Cvar_RegisterVariable (&scratch4);
|
||||
Cvar_RegisterVariable (&savedgamecfg);
|
||||
Cvar_RegisterVariable (&saved1);
|
||||
Cvar_RegisterVariable (&saved2);
|
||||
Cvar_RegisterVariable (&saved3);
|
||||
Cvar_RegisterVariable (&saved4);
|
||||
command::add("edict", ED_PrintEdict_f);
|
||||
command::add("edicts", ED_PrintEdicts);
|
||||
command::add("edictcount", ED_Count);
|
||||
command::add("profile", PR_Profile_f);
|
||||
nomonsters.inscribe();
|
||||
gamecfg.inscribe();
|
||||
scratch1.inscribe();
|
||||
scratch2.inscribe();
|
||||
scratch3.inscribe();
|
||||
scratch4.inscribe();
|
||||
savedgamecfg.inscribe();
|
||||
saved1.inscribe();
|
||||
saved2.inscribe();
|
||||
saved3.inscribe();
|
||||
saved4.inscribe();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user