Skip to content

Commit

Permalink
* Model cache commands
Browse files Browse the repository at this point in the history
  • Loading branch information
WALL OF JUSTICE committed Oct 28, 2017
1 parent ec76d92 commit 74227f0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,16 +812,19 @@ void generatePolyModels(int start, int end)
if ( generateAll )
{
polymodels = (polymodel_t*) malloc(sizeof(polymodel_t) * nummodels);
model_cache = openUserFile("models.cache", "rb");
if (model_cache) {
for (size_t model_index = 0; model_index < nummodels; model_index++) {
polymodel_t *cur = &polymodels[model_index];
fread(&cur->numfaces, sizeof(cur->numfaces), 1, model_cache);
cur->faces = (polytriangle_t *) calloc(sizeof(polytriangle_t), cur->numfaces);
fread(polymodels[model_index].faces, sizeof(polytriangle_t), cur->numfaces, model_cache);
if ( useModelCache )
{
model_cache = openDataFile("models.cache", "rb");
if (model_cache) {
for (size_t model_index = 0; model_index < nummodels; model_index++) {
polymodel_t *cur = &polymodels[model_index];
fread(&cur->numfaces, sizeof(cur->numfaces), 1, model_cache);
cur->faces = (polytriangle_t *) calloc(sizeof(polytriangle_t), cur->numfaces);
fread(polymodels[model_index].faces, sizeof(polytriangle_t), cur->numfaces, model_cache);
}
fclose(model_cache);
return generateVBOs(start, end);
}
fclose(model_cache);
return generateVBOs(start, end);
}
}

Expand Down Expand Up @@ -1751,7 +1754,7 @@ void generatePolyModels(int start, int end)
// free up quads for the next model
list_FreeAll(&quads);
}
if (generateAll && (model_cache = openUserFile("models.cache", "wb"))) {
if (generateAll && useModelCache && (model_cache = openDataFile("models.cache", "wb"))) {
for (size_t model_index = 0; model_index < nummodels; model_index++) {
polymodel_t *cur = &polymodels[model_index];
fwrite(&cur->numfaces, sizeof(cur->numfaces), 1, model_cache);
Expand Down
8 changes: 8 additions & 0 deletions src/interface/consolecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ void consoleCommand(char* command_str)
pingtime = SDL_GetTicks();
}
}
else if ( !strncmp(command_str, "/usemodelcache", 14) )
{
useModelCache = true;
}
else if ( !strncmp(command_str, "/disablemodelcache", 14) )
{
useModelCache = false;
}
else if (!strncmp(command_str, "/fov", 4))
{
fov = atoi(&command_str[5]);
Expand Down
4 changes: 4 additions & 0 deletions src/interface/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,10 @@ int saveConfig(char* filename)
{
fprintf(fp, "/splitscreen\n");
}
if ( useModelCache )
{
fprintf(fp, "/usemodelcache\n");
}
fprintf(fp, "/gamepad_deadzone %d\n", gamepad_deadzone);
fprintf(fp, "/gamepad_trigger_deadzone %d\n", gamepad_trigger_deadzone);
fprintf(fp, "/gamepad_leftx_sensitivity %d\n", gamepad_leftx_sensitivity);
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ int* palette;

// video definitions
polymodel_t* polymodels = NULL;
bool useModelCache = false;
list_t ttfTextHash[HASH_SIZE];
TTF_Font* ttf8 = NULL;
TTF_Font* ttf12 = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ extern SDL_Surface** sprites;
extern SDL_Surface** tiles;
extern voxel_t** models;
extern polymodel_t* polymodels;
extern bool useModelCache;
extern Uint32 imgref, vboref;
extern GLuint* texid;
extern bool disablevbos;
Expand Down

0 comments on commit 74227f0

Please sign in to comment.