From bf81d4e427a695c0766605252f01ecdb1ea40240 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Wed, 1 May 2024 14:23:49 +0300 Subject: [PATCH] maps: cache QBSP in collision map list --- src/client/refresh/gl1/gl1_main.c | 2 -- src/client/refresh/gl1/gl1_model.c | 17 +++-------------- src/client/refresh/gl1/header/local.h | 1 - src/client/refresh/gl3/gl3_main.c | 2 -- src/client/refresh/gl3/gl3_model.c | 17 +++-------------- src/client/refresh/gl3/header/local.h | 1 - src/client/refresh/gl4/gl4_main.c | 2 -- src/client/refresh/gl4/gl4_model.c | 17 +++-------------- src/client/refresh/gl4/header/local.h | 1 - src/client/refresh/soft/header/local.h | 1 - src/client/refresh/soft/sw_main.c | 2 -- src/client/refresh/soft/sw_model.c | 17 +++-------------- src/client/refresh/vk/header/local.h | 1 - src/client/refresh/vk/vk_main.c | 2 -- src/client/refresh/vk/vk_model.c | 17 +++-------------- src/common/collision.c | 26 +++++++++++++++++++++++++- 16 files changed, 40 insertions(+), 86 deletions(-) diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index c1726a31..78e07d34 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -103,7 +103,6 @@ cvar_t *r_customwidth; cvar_t *r_customheight; cvar_t *r_retexturing; -cvar_t *r_maptype; cvar_t *r_scale8bittextures; cvar_t *r_nolerp_list; @@ -1242,7 +1241,6 @@ R_Register(void) r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); r_validation = ri.Cvar_Get("r_validation", "0", CVAR_ARCHIVE); r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); - r_maptype = ri.Cvar_Get("maptype", "0", CVAR_ARCHIVE); /* don't bilerp characters and crosshairs */ r_nolerp_list = ri.Cvar_Get("r_nolerp_list", DEFAULT_NOLERP_LIST, CVAR_ARCHIVE); diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index eba8b9cf..96bea71e 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -295,12 +295,10 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, } static void -Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) +Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen) { int lightgridsize = 0, hunkSize; const bspx_header_t *bspx_header; - size_t modfilelen; - maptype_t maptype; dheader_t *header; byte *mod_base; @@ -309,10 +307,7 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) Com_Error(ERR_DROP, "%s: Loaded a brush model after the world", __func__); } - /* Can't detect will use provided */ - maptype = r_maptype->value; - - mod_base = Mod_Load2QBSP(mod->name, (byte *)buffer, filelen, &modfilelen, &maptype); + mod_base = (byte *)buffer; header = (dheader_t *)mod_base; /* check for BSPX extensions */ @@ -373,9 +368,6 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) &header->lumps[LUMP_NODES], header->ident); Mod_LoadSubmodels(mod, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ - - /* Free QBSP temporary info */ - free(mod_base); } /* @@ -494,10 +486,7 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash) }; break; - case IDBSPHEADER: - /* fall through */ - case RBSPHEADER: - /* fall through */ + /* should have only preloaded formats for maps */ case QBSPHEADER: Mod_LoadBrushModel(mod, buf, modfilelen); break; diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index 50e62272..1fc20114 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -175,7 +175,6 @@ extern cvar_t *r_customwidth; extern cvar_t *r_customheight; extern cvar_t *r_retexturing; -extern cvar_t *r_maptype; extern cvar_t *r_scale8bittextures; extern cvar_t *r_validation; diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index 8331ecd2..e1bac34b 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -83,7 +83,6 @@ cvar_t *gl_msaa_samples; cvar_t *gl_version_override; cvar_t *r_vsync; cvar_t *r_retexturing; -cvar_t *r_maptype; cvar_t *r_scale8bittextures; cvar_t *vid_fullscreen; cvar_t *r_mode; @@ -212,7 +211,6 @@ GL3_Register(void) gl_msaa_samples = ri.Cvar_Get ( "r_msaa_samples", "0", CVAR_ARCHIVE ); gl_version_override = ri.Cvar_Get ( "gl_version_override", "0", CVAR_ARCHIVE ); r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); - r_maptype = ri.Cvar_Get("maptype", "0", CVAR_ARCHIVE); r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); gl3_debugcontext = ri.Cvar_Get("gl3_debugcontext", "0", 0); r_mode = ri.Cvar_Get("r_mode", "4", CVAR_ARCHIVE); diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 4942db78..def4276d 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -296,12 +296,10 @@ Mod_LoadQFaces(gl3model_t *loadmodel, const byte *mod_base, const lump_t *l, } static void -Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int filelen) +Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int modfilelen) { int lightgridsize = 0, hunkSize; const bspx_header_t *bspx_header; - size_t modfilelen; - maptype_t maptype; dheader_t *header; byte *mod_base; @@ -310,10 +308,7 @@ Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int filelen) Com_Error(ERR_DROP, "%s: Loaded a brush model after the world", __func__); } - /* Can't detect will use provided */ - maptype = r_maptype->value; - - mod_base = Mod_Load2QBSP(mod->name, (byte *)buffer, filelen, &modfilelen, &maptype); + mod_base = (byte *)buffer; header = (dheader_t *)mod_base; /* check for BSPX extensions */ @@ -374,9 +369,6 @@ Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int filelen) &header->lumps[LUMP_NODES], header->ident); Mod_LoadSubmodels(mod, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ - - /* Free QBSP temporary info */ - free(mod_base); } /* @@ -495,10 +487,7 @@ Mod_ForName(const char *name, gl3model_t *parent_model, qboolean crash) }; break; - case IDBSPHEADER: - /* fall through */ - case RBSPHEADER: - /* fall through */ + /* should have only preloaded formats for maps */ case QBSPHEADER: Mod_LoadBrushModel(mod, buf, modfilelen); break; diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index f76c6142..92905826 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -509,7 +509,6 @@ extern cvar_t *gl_msaa_samples; extern cvar_t *gl_version_override; extern cvar_t *r_vsync; extern cvar_t *r_retexturing; -extern cvar_t *r_maptype; extern cvar_t *r_scale8bittextures; extern cvar_t *vid_fullscreen; extern cvar_t *r_mode; diff --git a/src/client/refresh/gl4/gl4_main.c b/src/client/refresh/gl4/gl4_main.c index 2ed0bf5d..763f24dd 100644 --- a/src/client/refresh/gl4/gl4_main.c +++ b/src/client/refresh/gl4/gl4_main.c @@ -79,7 +79,6 @@ cvar_t *gl_msaa_samples; cvar_t *gl_version_override; cvar_t *r_vsync; cvar_t *r_retexturing; -cvar_t *r_maptype; cvar_t *r_scale8bittextures; cvar_t *vid_fullscreen; cvar_t *r_mode; @@ -208,7 +207,6 @@ GL4_Register(void) gl_msaa_samples = ri.Cvar_Get ( "r_msaa_samples", "0", CVAR_ARCHIVE ); gl_version_override = ri.Cvar_Get ( "gl_version_override", "0", CVAR_ARCHIVE ); r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); - r_maptype = ri.Cvar_Get("maptype", "0", CVAR_ARCHIVE); r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); gl4_debugcontext = ri.Cvar_Get("gl4_debugcontext", "0", 0); r_mode = ri.Cvar_Get("r_mode", "4", CVAR_ARCHIVE); diff --git a/src/client/refresh/gl4/gl4_model.c b/src/client/refresh/gl4/gl4_model.c index b03e13c9..12b48b7a 100644 --- a/src/client/refresh/gl4/gl4_model.c +++ b/src/client/refresh/gl4/gl4_model.c @@ -296,12 +296,10 @@ Mod_LoadQFaces(gl4model_t *loadmodel, const byte *mod_base, const lump_t *l, } static void -Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int filelen) +Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int modfilelen) { int lightgridsize = 0, hunkSize; const bspx_header_t *bspx_header; - size_t modfilelen; - maptype_t maptype; dheader_t *header; byte *mod_base; @@ -310,10 +308,7 @@ Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int filelen) Com_Error(ERR_DROP, "%s: Loaded a brush model after the world", __func__); } - /* Can't detect will use provided */ - maptype = r_maptype->value; - - mod_base = Mod_Load2QBSP(mod->name, (byte *)buffer, filelen, &modfilelen, &maptype); + mod_base = (byte *)buffer; header = (dheader_t *)mod_base; /* check for BSPX extensions */ @@ -374,9 +369,6 @@ Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int filelen) &header->lumps[LUMP_NODES], header->ident); Mod_LoadSubmodels(mod, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ - - /* Free QBSP temporary info */ - free(mod_base); } /* @@ -495,10 +487,7 @@ Mod_ForName(const char *name, gl4model_t *parent_model, qboolean crash) }; break; - case IDBSPHEADER: - /* fall through */ - case RBSPHEADER: - /* fall through */ + /* should have only preloaded formats for maps */ case QBSPHEADER: Mod_LoadBrushModel(mod, buf, modfilelen); break; diff --git a/src/client/refresh/gl4/header/local.h b/src/client/refresh/gl4/header/local.h index a027c1a9..bf4d45a7 100644 --- a/src/client/refresh/gl4/header/local.h +++ b/src/client/refresh/gl4/header/local.h @@ -499,7 +499,6 @@ extern cvar_t *gl_msaa_samples; extern cvar_t *gl_version_override; extern cvar_t *r_vsync; extern cvar_t *r_retexturing; -extern cvar_t *r_maptype; extern cvar_t *r_scale8bittextures; extern cvar_t *vid_fullscreen; extern cvar_t *r_mode; diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index af4575e0..38764fac 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -398,7 +398,6 @@ extern cvar_t *sw_waterwarp; extern cvar_t *sw_gunzposition; extern cvar_t *r_validation; extern cvar_t *r_retexturing; -extern cvar_t *r_maptype; extern cvar_t *r_scale8bittextures; extern cvar_t *r_palettedtexture; diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 384a4fe4..38914d9e 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -152,7 +152,6 @@ cvar_t *sw_custom_particles; static cvar_t *sw_anisotropic; cvar_t *sw_texture_filtering; cvar_t *r_retexturing; -cvar_t *r_maptype; cvar_t *r_scale8bittextures; cvar_t *sw_gunzposition; cvar_t *r_validation; @@ -387,7 +386,6 @@ R_RegisterVariables (void) sw_texture_filtering = ri.Cvar_Get("sw_texture_filtering", "0", CVAR_ARCHIVE); sw_anisotropic = ri.Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE); r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); - r_maptype = ri.Cvar_Get("maptype", "0", CVAR_ARCHIVE); r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); sw_gunzposition = ri.Cvar_Get("sw_gunzposition", "8", CVAR_ARCHIVE); r_validation = ri.Cvar_Get("r_validation", "0", CVAR_ARCHIVE); diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 44cddc6b..3c06d26a 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -303,12 +303,10 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, } static void -Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) +Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen) { int lightgridsize = 0, hunkSize; const bspx_header_t *bspx_header; - size_t modfilelen; - maptype_t maptype; dheader_t *header; byte *mod_base; @@ -317,10 +315,7 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) Com_Error(ERR_DROP, "%s: Loaded a brush model after the world", __func__); } - /* Can't detect will use provided */ - maptype = r_maptype->value; - - mod_base = Mod_Load2QBSP(mod->name, (byte *)buffer, filelen, &modfilelen, &maptype); + mod_base = (byte *)buffer; header = (dheader_t *)mod_base; /* check for BSPX extensions */ @@ -381,9 +376,6 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) mod->numframes = 2; /* regular and alternate animation */ R_InitSkyBox(mod); - - /* Free QBSP temporary info */ - free(mod_base); } /* @@ -502,10 +494,7 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash) }; break; - case IDBSPHEADER: - /* fall through */ - case RBSPHEADER: - /* fall through */ + /* should have only preloaded formats for maps */ case QBSPHEADER: Mod_LoadBrushModel(mod, buf, modfilelen); break; diff --git a/src/client/refresh/vk/header/local.h b/src/client/refresh/vk/header/local.h index f231c3af..a61695ac 100644 --- a/src/client/refresh/vk/header/local.h +++ b/src/client/refresh/vk/header/local.h @@ -142,7 +142,6 @@ extern cvar_t *vk_molten_fastmath; extern cvar_t *vk_molten_metalbuffers; #endif extern cvar_t *r_retexturing; -extern cvar_t *r_maptype; extern cvar_t *r_scale8bittextures; extern cvar_t *r_nolerp_list; extern cvar_t *r_lerp_list; diff --git a/src/client/refresh/vk/vk_main.c b/src/client/refresh/vk/vk_main.c index 498660f8..930e8609 100644 --- a/src/client/refresh/vk/vk_main.c +++ b/src/client/refresh/vk/vk_main.c @@ -132,7 +132,6 @@ cvar_t *vk_mip_nearfilter; cvar_t *vk_sampleshading; cvar_t *vk_device_idx; cvar_t *r_retexturing; -cvar_t *r_maptype; cvar_t *r_scale8bittextures; static cvar_t *vk_underwater; cvar_t *r_nolerp_list; @@ -1178,7 +1177,6 @@ R_Register(void) vk_molten_metalbuffers = ri.Cvar_Get("vk_molten_metalbuffer", "0", CVAR_ARCHIVE); #endif r_retexturing = ri.Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE); - r_maptype = ri.Cvar_Get("maptype", "0", CVAR_ARCHIVE); r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); vk_underwater = ri.Cvar_Get("vk_underwater", "1", CVAR_ARCHIVE); /* don't bilerp characters and crosshairs */ diff --git a/src/client/refresh/vk/vk_model.c b/src/client/refresh/vk/vk_model.c index 2eeb6614..6a4cee84 100644 --- a/src/client/refresh/vk/vk_model.c +++ b/src/client/refresh/vk/vk_model.c @@ -270,12 +270,10 @@ Mod_LoadQFaces(model_t *loadmodel, const byte *mod_base, const lump_t *l, } static void -Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) +Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen) { int lightgridsize = 0, hunkSize; const bspx_header_t *bspx_header; - size_t modfilelen; - maptype_t maptype; dheader_t *header; byte *mod_base; @@ -284,10 +282,7 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) Com_Error(ERR_DROP, "%s: Loaded a brush model after the world", __func__); } - /* Can't detect will use provided */ - maptype = r_maptype->value; - - mod_base = Mod_Load2QBSP(mod->name, (byte *)buffer, filelen, &modfilelen, &maptype); + mod_base = (byte *)buffer; header = (dheader_t *)mod_base; /* check for BSPX extensions */ @@ -348,9 +343,6 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int filelen) &header->lumps[LUMP_NODES], header->ident); Mod_LoadSubmodels(mod, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ - - /* Free QBSP temporary info */ - free(mod_base); } /* @@ -478,10 +470,7 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash) }; break; - case IDBSPHEADER: - /* fall through */ - case RBSPHEADER: - /* fall through */ + /* should have only preloaded formats for maps */ case QBSPHEADER: Mod_LoadBrushModel(mod, buf, modfilelen); break; diff --git a/src/common/collision.c b/src/common/collision.c index 316d6afa..ed80b959 100644 --- a/src/common/collision.c +++ b/src/common/collision.c @@ -71,6 +71,8 @@ typedef struct { char name[MAX_QPATH]; unsigned checksum; + char *cache; /* raw converted map */ + int cache_size; cleaf_t *map_leafs; int emptyleaf; @@ -1743,7 +1745,7 @@ CM_ModFreeAll(void) static void CM_LoadCachedMap(const char *name, model_t *mod) { - int filelen, hunkSize = 0; + int filelen, hunkSize; byte *cmod_base, *filebuf; maptype_t maptype; dheader_t *header; @@ -1767,6 +1769,7 @@ CM_LoadCachedMap(const char *name, model_t *mod) /* load into heap */ strcpy(mod->name, name); + hunkSize = length; /* allocate memory for future maps cache */ hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_TEXINFO], sizeof(xtexinfo_t), sizeof(mapsurface_t), EXTRA_LUMP_TEXINFO); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], @@ -1794,6 +1797,10 @@ CM_LoadCachedMap(const char *name, model_t *mod) mod->extradata = Hunk_Begin(hunkSize); + mod->cache = Hunk_Alloc(length); + memcpy(mod->cache, cmod_base, length); + mod->cache_size = length; + CMod_LoadSurfaces(mod->name, &mod->map_surfaces, &mod->numtexinfo, cmod_base, &header->lumps[LUMP_TEXINFO]); CMod_LoadLeafs(mod->name, &mod->map_leafs, &mod->numleafs, &mod->emptyleaf, @@ -2120,5 +2127,22 @@ CM_ClusterPHS(int cluster) int CM_LoadFile(const char *path, void **buffer) { + int i; + + for (i = 0; i < MAX_MOD_KNOWN; i++) + { + /* we have already cached */ + if (!strcmp(path, models[i].name) && + models[i].cache && + models[i].extradatasize) + { + *buffer = Z_Malloc(models[i].cache_size); + memcpy(*buffer, models[i].cache, models[i].cache_size); + return models[i].cache_size; + } + } + + Com_Printf("%s: render asked about '%s' but have loaded it yet?\n", + __func__, path); return -1; }