Skip to content

Commit

Permalink
allow to set complevel by COMPDB lump (#2125)
Browse files Browse the repository at this point in the history
* allow to set complevel by COMPDB lump

Fixes #2121

* do not apply comp[] options in complevel Vanilla

* check for DV_NONE, do not apply comp options if not MBF21

* minor restructuring

* do not even need old_demover, it will always be MBF21 anyway

* fix blank line in compdb.lmp
  • Loading branch information
fabiangreffrath authored Jan 7, 2025
1 parent bfe338f commit a4b08b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
6 changes: 5 additions & 1 deletion base/all-all/compdb.lmp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
}
]
},
{
"name": "doomsday_of_uac_e1m8",
"md5": "32fc3115a3162b623f0d0f4e7dee6861",
"complevel": "1.9"
},
{
"name": "hell_revealed_map19",
"md5": "811a0c97777a198bc9b2bb558cb46e6a",
Expand All @@ -34,7 +39,6 @@
"md5": "145c4dfcf843f2b92c73036ba0e1d98a",
"options": [ {"name": "comp_vile", "value": 1} ]
},

{
"name": "hell_to_pay_map14",
"md5": "5379c080299eb961792b50ad96821543",
Expand Down
42 changes: 37 additions & 5 deletions src/g_compatibility.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "doomstat.h"
#include "doomtype.h"
#include "g_game.h"
#include "i_printf.h"
#include "m_array.h"
#include "m_misc.h"
Expand Down Expand Up @@ -77,6 +78,7 @@ typedef struct
{
md5_digest_t checksum;
option_t *options;
demo_version_t complevel;
} comp_record_t;

static comp_record_t *comp_database;
Expand Down Expand Up @@ -125,6 +127,18 @@ void G_ParseCompDatabase(void)
I_Printf(VB_ERROR, "COMPDB: wrong key %s", md5);
continue;
}

record.complevel = DV_MBF21;
const char *complevel = JS_GetStringValue(level, "complevel");
if (complevel)
{
demo_version_t new_complevel = G_GetNamedComplevel(complevel);
if (new_complevel != DV_NONE)
{
record.complevel = new_complevel;
}
}

json_t *js_options = JS_GetObject(level, "options");
json_t *js_option = NULL;
JS_ArrayForEach(js_option, js_options)
Expand Down Expand Up @@ -184,19 +198,23 @@ static void GetLevelCheckSum(int lump, md5_checksum_t* cksum)

void G_ApplyLevelCompatibility(int lump)
{
if (demorecording || demoplayback || netgame || !mbf21)
{
return;
}

static boolean restore_comp;
static int old_comp[COMP_TOTAL];

if (restore_comp)
{
if (demo_version != DV_MBF21)
{
demo_version = DV_MBF21;
G_ReloadDefaults(true);
}
memcpy(comp, old_comp, sizeof(*comp));
restore_comp = false;
}
else if (demorecording || demoplayback || netgame || !mbf21)
{
return;
}

md5_checksum_t cksum;

Expand All @@ -212,6 +230,20 @@ void G_ApplyLevelCompatibility(int lump)
memcpy(old_comp, comp, sizeof(*comp));
restore_comp = true;

demo_version_t new_demover = record->complevel;
if (new_demover != DV_MBF21)
{
demo_version = new_demover;
G_ReloadDefaults(true);
I_Printf(VB_INFO, "Automatically setting compatibility level \"%s\"",
G_GetCurrentComplevelName());
}

if (!mbf21)
{
return;
}

option_t *option;
array_foreach(option, record->options)
{
Expand Down

0 comments on commit a4b08b7

Please sign in to comment.