mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
new cvar: gl_mesh_cache. controls minimum triangle count in a model before
the model is cached or cache checks are done for that model. 0 disables caching entrirely.
This commit is contained in:
parent
b277881832
commit
9f2418d873
2 changed files with 110 additions and 95 deletions
|
@ -39,6 +39,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "QF/console.h"
|
#include "QF/console.h"
|
||||||
|
#include "QF/cvar.h"
|
||||||
#include "QF/mdfour.h"
|
#include "QF/mdfour.h"
|
||||||
#include "QF/model.h"
|
#include "QF/model.h"
|
||||||
#include "QF/sys.h"
|
#include "QF/sys.h"
|
||||||
|
@ -50,6 +51,8 @@
|
||||||
ALIAS MODEL DISPLAY LIST GENERATION
|
ALIAS MODEL DISPLAY LIST GENERATION
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern cvar_t *gl_mesh_cache;
|
||||||
|
|
||||||
model_t *aliasmodel;
|
model_t *aliasmodel;
|
||||||
aliashdr_t *paliashdr;
|
aliashdr_t *paliashdr;
|
||||||
|
|
||||||
|
@ -350,81 +353,87 @@ GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s)
|
||||||
unsigned char model_digest[MDFOUR_DIGEST_BYTES];
|
unsigned char model_digest[MDFOUR_DIGEST_BYTES];
|
||||||
unsigned char mesh_digest[MDFOUR_DIGEST_BYTES];
|
unsigned char mesh_digest[MDFOUR_DIGEST_BYTES];
|
||||||
qboolean remesh = true;
|
qboolean remesh = true;
|
||||||
|
qboolean do_cache = false;
|
||||||
|
|
||||||
aliasmodel = m;
|
aliasmodel = m;
|
||||||
paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m);
|
paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m);
|
||||||
|
|
||||||
mdfour (model_digest, (unsigned char *) _m, _s);
|
if (gl_mesh_cache->int_val
|
||||||
|
&& gl_mesh_cache->int_val <= paliashdr->mdl.numtris) {
|
||||||
|
do_cache = true;
|
||||||
|
|
||||||
// look for a cached version
|
mdfour (model_digest, (unsigned char *) _m, _s);
|
||||||
strcpy (cache, "glquake/");
|
|
||||||
COM_StripExtension (m->name + strlen ("progs/"),
|
|
||||||
cache + strlen ("glquake/"));
|
|
||||||
strncat (cache, ".qfms", sizeof (cache) - strlen (cache));
|
|
||||||
|
|
||||||
COM_FOpenFile (cache, &f);
|
// look for a cached version
|
||||||
if (f) {
|
strcpy (cache, "glquake/");
|
||||||
unsigned char d1[MDFOUR_DIGEST_BYTES];
|
COM_StripExtension (m->name + strlen ("progs/"),
|
||||||
unsigned char d2[MDFOUR_DIGEST_BYTES];
|
cache + strlen ("glquake/"));
|
||||||
struct mdfour md;
|
strncat (cache, ".qfms", sizeof (cache) - strlen (cache));
|
||||||
int *c = 0;
|
|
||||||
int nc = 0;
|
|
||||||
int *vo = 0;
|
|
||||||
int no = 0;
|
|
||||||
int len;
|
|
||||||
int vers;
|
|
||||||
|
|
||||||
memset (d1, 0, sizeof (d1));
|
COM_FOpenFile (cache, &f);
|
||||||
memset (d2, 0, sizeof (d2));
|
if (f) {
|
||||||
|
unsigned char d1[MDFOUR_DIGEST_BYTES];
|
||||||
|
unsigned char d2[MDFOUR_DIGEST_BYTES];
|
||||||
|
struct mdfour md;
|
||||||
|
int *c = 0;
|
||||||
|
int nc = 0;
|
||||||
|
int *vo = 0;
|
||||||
|
int no = 0;
|
||||||
|
int len;
|
||||||
|
int vers;
|
||||||
|
|
||||||
Qread (f, &vers, sizeof (int));
|
memset (d1, 0, sizeof (d1));
|
||||||
Qread (f, &len, sizeof (int));
|
memset (d2, 0, sizeof (d2));
|
||||||
Qread (f, &nc, sizeof (int));
|
|
||||||
Qread (f, &no, sizeof (int));
|
|
||||||
|
|
||||||
if (vers == 1 && (nc + no) == len) {
|
Qread (f, &vers, sizeof (int));
|
||||||
c = malloc (((nc + 1023) & ~1023) * sizeof (c[0]));
|
Qread (f, &len, sizeof (int));
|
||||||
vo = malloc (((no + 1023) & ~1023) * sizeof (vo[0]));
|
Qread (f, &nc, sizeof (int));
|
||||||
if (!c || !vo)
|
Qread (f, &no, sizeof (int));
|
||||||
Sys_Error ("gl_mesh.c: out of memory");
|
|
||||||
Qread (f, c, nc * sizeof (c[0]));
|
|
||||||
Qread (f, vo, no * sizeof (vo[0]));
|
|
||||||
Qread (f, d1, MDFOUR_DIGEST_BYTES);
|
|
||||||
Qread (f, d2, MDFOUR_DIGEST_BYTES);
|
|
||||||
Qclose (f);
|
|
||||||
|
|
||||||
mdfour_begin (&md);
|
if (vers == 1 && (nc + no) == len) {
|
||||||
mdfour_update (&md, (unsigned char *) &vers, sizeof(int));
|
c = malloc (((nc + 1023) & ~1023) * sizeof (c[0]));
|
||||||
mdfour_update (&md, (unsigned char *) &len, sizeof(int));
|
vo = malloc (((no + 1023) & ~1023) * sizeof (vo[0]));
|
||||||
mdfour_update (&md, (unsigned char *) &nc, sizeof(int));
|
if (!c || !vo)
|
||||||
mdfour_update (&md, (unsigned char *) &no, sizeof(int));
|
Sys_Error ("gl_mesh.c: out of memory");
|
||||||
mdfour_update (&md, (unsigned char *) c, nc * sizeof (c[0]));
|
Qread (f, c, nc * sizeof (c[0]));
|
||||||
mdfour_update (&md, (unsigned char *) vo, no * sizeof (vo[0]));
|
Qread (f, vo, no * sizeof (vo[0]));
|
||||||
mdfour_update (&md, d1, MDFOUR_DIGEST_BYTES);
|
Qread (f, d1, MDFOUR_DIGEST_BYTES);
|
||||||
mdfour_result (&md, mesh_digest);
|
Qread (f, d2, MDFOUR_DIGEST_BYTES);
|
||||||
|
Qclose (f);
|
||||||
|
|
||||||
if (memcmp (d2, mesh_digest, MDFOUR_DIGEST_BYTES) == 0
|
mdfour_begin (&md);
|
||||||
&& memcmp (d1, model_digest, MDFOUR_DIGEST_BYTES) == 0) {
|
mdfour_update (&md, (unsigned char *) &vers, sizeof(int));
|
||||||
remesh = false;
|
mdfour_update (&md, (unsigned char *) &len, sizeof(int));
|
||||||
numcommands = nc;
|
mdfour_update (&md, (unsigned char *) &nc, sizeof(int));
|
||||||
numorder = no;
|
mdfour_update (&md, (unsigned char *) &no, sizeof(int));
|
||||||
if (numcommands > commands_size) {
|
mdfour_update (&md, (unsigned char *) c, nc * sizeof (c[0]));
|
||||||
if (commands)
|
mdfour_update (&md, (unsigned char *) vo, no * sizeof (vo[0]));
|
||||||
free (commands);
|
mdfour_update (&md, d1, MDFOUR_DIGEST_BYTES);
|
||||||
commands_size = (numcommands + 1023) & ~1023;
|
mdfour_result (&md, mesh_digest);
|
||||||
commands = c;
|
|
||||||
} else {
|
if (memcmp (d2, mesh_digest, MDFOUR_DIGEST_BYTES) == 0
|
||||||
memcpy (commands, c, numcommands * sizeof (c[0]));
|
&& memcmp (d1, model_digest, MDFOUR_DIGEST_BYTES) == 0) {
|
||||||
free(c);
|
remesh = false;
|
||||||
}
|
numcommands = nc;
|
||||||
if (numorder > vertexorder_size) {
|
numorder = no;
|
||||||
if (vertexorder)
|
if (numcommands > commands_size) {
|
||||||
free (vertexorder);
|
if (commands)
|
||||||
vertexorder_size = (numorder + 1023) & ~1023;
|
free (commands);
|
||||||
vertexorder = vo;
|
commands_size = (numcommands + 1023) & ~1023;
|
||||||
} else {
|
commands = c;
|
||||||
memcpy (vertexorder, vo, numorder * sizeof (vo[0]));
|
} else {
|
||||||
free (vo);
|
memcpy (commands, c, numcommands * sizeof (c[0]));
|
||||||
|
free(c);
|
||||||
|
}
|
||||||
|
if (numorder > vertexorder_size) {
|
||||||
|
if (vertexorder)
|
||||||
|
free (vertexorder);
|
||||||
|
vertexorder_size = (numorder + 1023) & ~1023;
|
||||||
|
vertexorder = vo;
|
||||||
|
} else {
|
||||||
|
memcpy (vertexorder, vo, numorder * sizeof (vo[0]));
|
||||||
|
free (vo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,40 +444,42 @@ GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s)
|
||||||
|
|
||||||
BuildTris (); // trifans or lists
|
BuildTris (); // trifans or lists
|
||||||
|
|
||||||
// save out the cached version
|
if (do_cache) {
|
||||||
snprintf (fullpath, sizeof (fullpath), "%s/%s", com_gamedir, cache);
|
// save out the cached version
|
||||||
f = Qopen (fullpath, "wbz9");
|
snprintf (fullpath, sizeof (fullpath), "%s/%s", com_gamedir, cache);
|
||||||
if (!f) {
|
f = Qopen (fullpath, "wbz9");
|
||||||
COM_CreatePath (fullpath);
|
if (!f) {
|
||||||
f = Qopen (fullpath, "wb");
|
COM_CreatePath (fullpath);
|
||||||
}
|
f = Qopen (fullpath, "wb");
|
||||||
|
}
|
||||||
|
|
||||||
if (f) {
|
if (f) {
|
||||||
struct mdfour md;
|
struct mdfour md;
|
||||||
int vers = 1;
|
int vers = 1;
|
||||||
int len = numcommands + numorder;
|
int len = numcommands + numorder;
|
||||||
|
|
||||||
mdfour_begin (&md);
|
mdfour_begin (&md);
|
||||||
mdfour_update (&md, (unsigned char *) &vers, sizeof (int));
|
mdfour_update (&md, (unsigned char *) &vers, sizeof (int));
|
||||||
mdfour_update (&md, (unsigned char *) &len, sizeof (int));
|
mdfour_update (&md, (unsigned char *) &len, sizeof (int));
|
||||||
mdfour_update (&md, (unsigned char *) &numcommands, sizeof (int));
|
mdfour_update (&md, (unsigned char *) &numcommands, sizeof (int));
|
||||||
mdfour_update (&md, (unsigned char *) &numorder, sizeof (int));
|
mdfour_update (&md, (unsigned char *) &numorder, sizeof (int));
|
||||||
mdfour_update (&md, (unsigned char *) commands,
|
mdfour_update (&md, (unsigned char *) commands,
|
||||||
numcommands * sizeof (commands[0]));
|
numcommands * sizeof (commands[0]));
|
||||||
mdfour_update (&md, (unsigned char *) vertexorder,
|
mdfour_update (&md, (unsigned char *) vertexorder,
|
||||||
numorder * sizeof (vertexorder[0]));
|
numorder * sizeof (vertexorder[0]));
|
||||||
mdfour_update (&md, model_digest, MDFOUR_DIGEST_BYTES);
|
mdfour_update (&md, model_digest, MDFOUR_DIGEST_BYTES);
|
||||||
mdfour_result (&md, mesh_digest);
|
mdfour_result (&md, mesh_digest);
|
||||||
|
|
||||||
Qwrite (f, &vers, sizeof (int));
|
Qwrite (f, &vers, sizeof (int));
|
||||||
Qwrite (f, &len, sizeof (int));
|
Qwrite (f, &len, sizeof (int));
|
||||||
Qwrite (f, &numcommands, sizeof (int));
|
Qwrite (f, &numcommands, sizeof (int));
|
||||||
Qwrite (f, &numorder, sizeof (int));
|
Qwrite (f, &numorder, sizeof (int));
|
||||||
Qwrite (f, commands, numcommands * sizeof (commands[0]));
|
Qwrite (f, commands, numcommands * sizeof (commands[0]));
|
||||||
Qwrite (f, vertexorder, numorder * sizeof (vertexorder[0]));
|
Qwrite (f, vertexorder, numorder * sizeof (vertexorder[0]));
|
||||||
Qwrite (f, model_digest, MDFOUR_DIGEST_BYTES);
|
Qwrite (f, model_digest, MDFOUR_DIGEST_BYTES);
|
||||||
Qwrite (f, mesh_digest, MDFOUR_DIGEST_BYTES);
|
Qwrite (f, mesh_digest, MDFOUR_DIGEST_BYTES);
|
||||||
Qclose (f);
|
Qclose (f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ model_t mod_known[MAX_MOD_KNOWN];
|
||||||
int mod_numknown;
|
int mod_numknown;
|
||||||
|
|
||||||
cvar_t *gl_subdivide_size;
|
cvar_t *gl_subdivide_size;
|
||||||
|
cvar_t *gl_mesh_cache;
|
||||||
|
|
||||||
extern byte mod_novis[MAX_MAP_LEAFS / 8];
|
extern byte mod_novis[MAX_MAP_LEAFS / 8];
|
||||||
|
|
||||||
|
@ -106,6 +107,9 @@ Mod_Init_Cvars (void)
|
||||||
gl_subdivide_size =
|
gl_subdivide_size =
|
||||||
Cvar_Get ("gl_subdivide_size", "128", CVAR_ARCHIVE, NULL,
|
Cvar_Get ("gl_subdivide_size", "128", CVAR_ARCHIVE, NULL,
|
||||||
"Sets the division value for the sky brushes.");
|
"Sets the division value for the sky brushes.");
|
||||||
|
gl_mesh_cache = Cvar_Get ("gl_mesh_cache", "256", CVAR_ARCHIVE, NULL,
|
||||||
|
"minimum triangle count in a model for its mesh"
|
||||||
|
" to be cached. 0 to disable caching");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue