Skip to content

Commit

Permalink
client: improve autodetect heretic2 map
Browse files Browse the repository at this point in the history
  • Loading branch information
0lvin committed Dec 18, 2024
1 parent f931f9c commit 5a0def6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Note:
with tranparency or some animations flags and properties.
* If you like support some other maps type, create pull request for Mod_Load2QBSP
function and provide a link to demo maps.
* Use `maptype 1` before load any Heretic 2 maps. Look to
[maptype_t](src/common/header/cmodel.h#L42) for more info.
* Use `maptype 1` before load any Heretic 2 maps, or place game data to `heretic2` directory.
Look to [maptype_t](src/common/header/cmodel.h#L42) for more info.

Games:

Expand Down
2 changes: 0 additions & 2 deletions src/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,6 @@ CL_Shutdown(void)

isdown = true;

CM_ModFreeAll();

#ifdef USE_CURL
CL_HTTP_Cleanup(true);
#endif
Expand Down
19 changes: 16 additions & 3 deletions src/common/collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ static cleaf_t *box_leaf;
static cplane_t *box_planes;
static cvar_t *map_noareas;
static cvar_t *r_maptype;
static cvar_t *r_game;
static int box_headnode;
static int checkcount;
static int floodvalid;
Expand Down Expand Up @@ -1736,6 +1737,16 @@ CM_ModFree(model_t *cmod)
memset(cmod, 0, sizeof(model_t));
}

void
CM_ModInit(void)
{
memset(models, 0, sizeof(models));

map_noareas = Cvar_Get("map_noareas", "0", 0);
r_maptype = Cvar_Get("maptype", "0", CVAR_ARCHIVE);
r_game = Cvar_Get("game", "", CVAR_LATCH | CVAR_SERVERINFO);
}

void
CM_ModFreeAll(void)
{
Expand Down Expand Up @@ -1769,6 +1780,11 @@ CM_LoadCachedMap(const char *name, model_t *mod)

/* Can't detect will use provided */
maptype = r_maptype->value;
/* force heretic2 only if game is heretic2 */
if (!strcmp(r_game->string, "heretic2") && maptype == map_quake2rr)
{
maptype = map_heretic2;
}
cmod_base = Mod_Load2QBSP(name, (byte *)filebuf, filelen, &length, &maptype);
header = (dheader_t *)cmod_base;

Expand Down Expand Up @@ -1863,9 +1879,6 @@ CM_LoadMap(const char *name, qboolean clientload, unsigned *checksum)
{
int i, sec_start;

map_noareas = Cvar_Get("map_noareas", "0", 0);
r_maptype = Cvar_Get("maptype", "0", CVAR_ARCHIVE);

if (!name[0])
{
memset(&empty_model, 0, sizeof(empty_model));
Expand Down
2 changes: 2 additions & 0 deletions src/common/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ Qcommon_Init(int argc, char **argv)

// The filesystems needs to be initialized after the cvars.
FS_InitFilesystem();
CM_ModInit();

// Add and execute configuration files.
Qcommon_ExecConfigs(true);
Expand Down Expand Up @@ -830,6 +831,7 @@ Qcommon_Frame(int usec)
void
Qcommon_Shutdown(void)
{
CM_ModFreeAll();
FS_ShutdownFilesystem();
Cvar_Fini();

Expand Down
1 change: 1 addition & 0 deletions src/common/header/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ cmodel_t *CM_InlineModel(const char *name); /* *1, *2, etc */
int CM_MapSurfacesNum(void);
mapsurface_t* CM_MapSurfaces(int surfnum);

void CM_ModInit(void);
void CM_ModFreeAll(void);

int CM_NumClusters(void);
Expand Down

0 comments on commit 5a0def6

Please sign in to comment.