Skip to content

Commit

Permalink
preload map descriptions on a separate thread and reload for new mods
Browse files Browse the repository at this point in the history
  • Loading branch information
timbergeron committed Feb 11, 2024
1 parent aacde85 commit 01f2c45
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
1 change: 1 addition & 0 deletions Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3346,6 +3346,7 @@ static void COM_Game_f (void)
if (!isDedicated)
Draw_ReloadTextures(true);
ExtraMaps_NewGame ();
DescMaps_NewGame (); // woods #mapdescriptions
Host_Resetdemos ();
DemoList_Rebuild ();
ParticleList_Rebuild (); // woods #particlelist
Expand Down
1 change: 1 addition & 0 deletions Quake/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,7 @@ void Host_Init (void)
ServerList_Init(); // woods #serverlist
FolderList_Init(); // woods #folderlist
MusicList_Init (); // woods #musiclist
DescMaps_Init (); // woods #mapdescriptions
VID_Init ();
IN_Init ();
TexMgr_Init (); //johnfitz
Expand Down
65 changes: 50 additions & 15 deletions Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,23 @@ void ExtraMaps_NewGame (void)
ExtraMaps_Init ();
}

filelist_item_t* levelwithdesc; // woods #mapdescriptions
//==============================================================================
// woods -- worldspawn map description support #mapdescriptions
//==============================================================================

/*
==================
Host_Maps_f -- woods add worldspawn map description support #mapdescriptions
==================
*/
static void Host_Maps_f (void)
filelist_item_t* levelwithdesc;

static void Host_Maps_Init_f (void) // add worldspawn map description
{
int i;
filelist_item_t *level;
filelist_item_t *level;

int max_word_length = 0;
int count = 0;

const char* filter = NULL;

if (Cmd_Argc() >= 2)
filter = Cmd_Argv(1);

for (level = extralevels, i = 0; level; level = level->next, i++) // find the max map name length
{
int word_length = strlen(level->name);
if (word_length > max_word_length)
if (word_length > max_word_length)
{
max_word_length = word_length;
}
Expand Down Expand Up @@ -279,6 +272,19 @@ static void Host_Maps_f (void)
}
free(space_str);
}
}

static void Host_Maps_f (void) // prints worldspawn map description
{
int i;
filelist_item_t *level;

int count = 0;

const char* filter = NULL;

if (Cmd_Argc() >= 2)
filter = Cmd_Argv(1);

Con_SafePrintf("\n");

Expand Down Expand Up @@ -319,6 +325,35 @@ static void Host_Maps_f (void)
}
}

static int MapDescriptionThreadFunction (void* data)
{
Host_Maps_Init_f ();
return 0;
}

void DescMaps_Init (void)
{
SDL_Thread* thread = SDL_CreateThread (MapDescriptionThreadFunction, "HostMapsThread", NULL);
if (thread != NULL)
{
int threadReturnValue;
SDL_WaitThread(thread, &threadReturnValue); // Wait for the thread to finish
}
else
Con_DPrintf ("SDL_CreateThread failed: %s\n", SDL_GetError());
}

static void DescMaps_Clear (void)
{
FileList_Clear (&levelwithdesc);
}

void DescMaps_NewGame (void)
{
DescMaps_Clear ();
Host_Maps_Init_f ();
}

//==============================================================================
// woods -- FolderList id1 directories management for open cmd #folderlist
//==============================================================================
Expand Down
3 changes: 3 additions & 0 deletions Quake/quakedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ extern filelist_item_t *particlelist; // woods #particlelist
extern filelist_item_t *serverlist; // woods #serverlist
extern filelist_item_t* folderlist; // woods #folderlist
extern filelist_item_t *musiclist; // woods #musiclist
extern filelist_item_t *levelwithdesc; // woods #mapdescriptions

void Host_ClearMemory (void);
void Host_ServerFrame (void);
Expand Down Expand Up @@ -424,9 +425,11 @@ void ServerList_Init(void); // woods #serverlist
void FolderList_Init (void); // woods #folderlist
void SkyList_Init (void); // woods #folderlist
void MusicList_Init (void); // woods #musiclist
void DescMaps_Init (void); // woods #mapdescriptions


void ExtraMaps_NewGame (void);
void DescMaps_NewGame (void); // woods #mapdescriptions
void DemoList_Rebuild (void);
void ParticleList_Rebuild(void);
void SkyList_Rebuild (void);
Expand Down

0 comments on commit 01f2c45

Please sign in to comment.