From 01f2c4545c79dab1999c8ea0492d4426e870afc8 Mon Sep 17 00:00:00 2001 From: timbergeron Date: Sat, 10 Feb 2024 23:50:10 -0800 Subject: [PATCH] preload map descriptions on a separate thread and reload for new mods --- Quake/common.c | 1 + Quake/host.c | 1 + Quake/host_cmd.c | 65 +++++++++++++++++++++++++++++++++++++----------- Quake/quakedef.h | 3 +++ 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/Quake/common.c b/Quake/common.c index 4dc617a4..b2a972e4 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -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 diff --git a/Quake/host.c b/Quake/host.c index 410988a5..1458d2f4 100644 --- a/Quake/host.c +++ b/Quake/host.c @@ -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 diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index fa310ff9..1e13657c 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -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; } @@ -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"); @@ -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 //============================================================================== diff --git a/Quake/quakedef.h b/Quake/quakedef.h index 643ebf06..c2ac429f 100644 --- a/Quake/quakedef.h +++ b/Quake/quakedef.h @@ -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); @@ -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);