From a844c94af116dec8602d82c4af29b9b93c66ccc2 Mon Sep 17 00:00:00 2001 From: Thilo Schulz Date: Wed, 13 Jul 2011 08:40:30 +0000 Subject: [PATCH] - Add dual protocol support to team arena demo selector - Fix demo selection in team arena menu on case sensitive file systems - Some changes in the way how vanilla q3 demo file lists are compiled in the menu --- code/q3_ui/ui_demo2.c | 71 ++++++++++++++++++++----------------------- code/ui/ui_atoms.c | 28 +++++++++++++++-- code/ui/ui_local.h | 2 +- code/ui/ui_main.c | 52 ++++++++++++++++++++----------- 4 files changed, 94 insertions(+), 59 deletions(-) diff --git a/code/q3_ui/ui_demo2.c b/code/q3_ui/ui_demo2.c index f63bcdf7..a16a762b 100644 --- a/code/q3_ui/ui_demo2.c +++ b/code/q3_ui/ui_demo2.c @@ -72,8 +72,6 @@ typedef struct { int numDemos; char names[NAMEBUFSIZE]; - int numLegacyDemos; - char namesLegacy[NAMEBUFSIZE]; char *demolist[MAX_DEMOS]; } demos_t; @@ -133,7 +131,7 @@ Demos_MenuInit =============== */ static void Demos_MenuInit( void ) { - int i; + int i, j; int len; char *demoname, extension[32]; int protocol, protocolLegacy; @@ -239,51 +237,48 @@ static void Demos_MenuInit( void ) { protocolLegacy = 0; Com_sprintf(extension, sizeof(extension), ".%s%d", DEMOEXT, protocol); - s_demos.numDemos = trap_FS_GetFileList("demos", extension, s_demos.names, NAMEBUFSIZE); + s_demos.numDemos = trap_FS_GetFileList("demos", extension, s_demos.names, ARRAY_LEN(s_demos.names)); - if(s_demos.numDemos > MAX_DEMOS) - s_demos.numDemos = MAX_DEMOS; - - if(protocolLegacy > 0) + demoname = s_demos.names; + i = 0; + + for(j = 0; j < 2; j++) { - Com_sprintf(extension, sizeof(extension), ".%s%d", DEMOEXT, protocolLegacy); - s_demos.numLegacyDemos = trap_FS_GetFileList("demos", extension, s_demos.namesLegacy, NAMEBUFSIZE); + if(s_demos.numDemos > MAX_DEMOS) + s_demos.numDemos = MAX_DEMOS; + + for(; i < s_demos.numDemos; i++) + { + s_demos.list.itemnames[i] = demoname; + + len = strlen(demoname); + + demoname += len + 1; + } + + if(!j) + { + if(protocolLegacy > 0 && s_demos.numDemos < MAX_DEMOS) + { + Com_sprintf(extension, sizeof(extension), ".%s%d", DEMOEXT, protocolLegacy); + s_demos.numDemos += trap_FS_GetFileList("demos", extension, demoname, + ARRAY_LEN(s_demos.names) - (demoname - s_demos.names)); + } + else + break; + } } - else - s_demos.numLegacyDemos = 0; - s_demos.list.numitems = s_demos.numDemos + s_demos.numLegacyDemos; + s_demos.list.numitems = s_demos.numDemos; - - if (!s_demos.list.numitems) { - strcpy( s_demos.names, "No Demos Found." ); + if(!s_demos.numDemos) + { + s_demos.list.itemnames[0] = "No Demos Found."; s_demos.list.numitems = 1; //degenerate case, not selectable s_demos.go.generic.flags |= (QMF_INACTIVE|QMF_HIDDEN); } - else if (s_demos.list.numitems > MAX_DEMOS) - s_demos.list.numitems = MAX_DEMOS; - - demoname = s_demos.names; - for(i = 0; i < s_demos.numDemos; i++) - { - s_demos.list.itemnames[i] = demoname; - - len = strlen(demoname); - - demoname += len + 1; - } - - demoname = s_demos.namesLegacy; - for(; i < s_demos.list.numitems; i++) - { - s_demos.list.itemnames[i] = demoname; - - len = strlen(demoname); - - demoname += len + 1; - } Menu_AddItem( &s_demos.menu, &s_demos.banner ); Menu_AddItem( &s_demos.menu, &s_demos.framel ); diff --git a/code/ui/ui_atoms.c b/code/ui/ui_atoms.c index 9df2e4aa..6faa7931 100644 --- a/code/ui/ui_atoms.c +++ b/code/ui/ui_atoms.c @@ -146,10 +146,13 @@ void UI_SetBestScores(postGameInfo_t *newInfo, qboolean postGame) { } } -void UI_LoadBestScores(const char *map, int game) { +void UI_LoadBestScores(const char *map, int game) +{ char fileName[MAX_QPATH]; fileHandle_t f; postGameInfo_t newInfo; + int protocol, protocolLegacy; + memset(&newInfo, 0, sizeof(postGameInfo_t)); Com_sprintf(fileName, MAX_QPATH, "games/%s_%i.game", map, game); if (trap_FS_FOpenFile(fileName, &f, FS_READ) >= 0) { @@ -162,11 +165,30 @@ void UI_LoadBestScores(const char *map, int game) { } UI_SetBestScores(&newInfo, qfalse); - Com_sprintf(fileName, MAX_QPATH, "demos/%s_%d.%s%d", map, game, DEMOEXT, (int)trap_Cvar_VariableValue("protocol")); uiInfo.demoAvailable = qfalse; - if (trap_FS_FOpenFile(fileName, &f, FS_READ) >= 0) { + + protocolLegacy = trap_Cvar_VariableValue("com_legacyprotocol"); + protocol = trap_Cvar_VariableValue("com_protocol"); + + if(!protocol) + protocol = trap_Cvar_VariableValue("protocol"); + if(protocolLegacy == protocol) + protocolLegacy = 0; + + Com_sprintf(fileName, MAX_QPATH, "demos/%s_%d.%s%d", map, game, DEMOEXT, protocol); + if(trap_FS_FOpenFile(fileName, &f, FS_READ) >= 0) + { uiInfo.demoAvailable = qtrue; trap_FS_FCloseFile(f); + } + else if(protocolLegacy > 0) + { + Com_sprintf(fileName, MAX_QPATH, "demos/%s_%d.%s%d", map, game, DEMOEXT, protocolLegacy); + if (trap_FS_FOpenFile(fileName, &f, FS_READ) >= 0) + { + uiInfo.demoAvailable = qtrue; + trap_FS_FCloseFile(f); + } } } diff --git a/code/ui/ui_local.h b/code/ui/ui_local.h index b43d5d0e..fc6e9af3 100644 --- a/code/ui/ui_local.h +++ b/code/ui/ui_local.h @@ -631,7 +631,7 @@ typedef struct { #define MAPS_PER_TIER 3 #define MAX_TIERS 16 #define MAX_MODS 64 -#define MAX_DEMOS 256 +#define MAX_DEMOS 512 #define MAX_MOVIES 256 #define MAX_PLAYERMODELS 256 diff --git a/code/ui/ui_main.c b/code/ui/ui_main.c index 87c9a2d8..1feda741 100644 --- a/code/ui/ui_main.c +++ b/code/ui/ui_main.c @@ -2863,7 +2863,7 @@ static void UI_LoadMovies( void ) { } - +#define NAMEBUFSIZE (MAX_DEMOS * 32) /* =============== @@ -2871,31 +2871,49 @@ UI_LoadDemos =============== */ static void UI_LoadDemos( void ) { - char demolist[4096]; - char demoExt[32]; + char demolist[NAMEBUFSIZE]; + char demoExt[32]; char *demoname; - int i, len; + int i, j, len; + int protocol, protocolLegacy; - Com_sprintf(demoExt, sizeof(demoExt), "%s%d", DEMOEXT, (int)trap_Cvar_VariableValue("protocol")); + protocolLegacy = trap_Cvar_VariableValue("com_legacyprotocol"); + protocol = trap_Cvar_VariableValue("com_protocol"); - uiInfo.demoCount = trap_FS_GetFileList( "demos", demoExt, demolist, 4096 ); + if(!protocol) + protocol = trap_Cvar_VariableValue("protocol"); + if(protocolLegacy == protocol) + protocolLegacy = 0; - Com_sprintf(demoExt, sizeof(demoExt), ".%s%d", DEMOEXT, (int)trap_Cvar_VariableValue("protocol")); + Com_sprintf(demoExt, sizeof(demoExt), ".%s%d", DEMOEXT, protocol); + uiInfo.demoCount = trap_FS_GetFileList("demos", demoExt, demolist, ARRAY_LEN(demolist)); + + demoname = demolist; + i = 0; - if (uiInfo.demoCount) { - if (uiInfo.demoCount > MAX_DEMOS) { + for(j = 0; j < 2; j++) + { + if(uiInfo.demoCount > MAX_DEMOS) uiInfo.demoCount = MAX_DEMOS; - } - demoname = demolist; - for ( i = 0; i < uiInfo.demoCount; i++ ) { - len = strlen( demoname ); - if (!Q_stricmp(demoname + len - strlen(demoExt), demoExt)) { - demoname[len-strlen(demoExt)] = '\0'; - } - Q_strupr(demoname); + + for(; i < uiInfo.demoCount; i++) + { + len = strlen(demoname); uiInfo.demoList[i] = String_Alloc(demoname); demoname += len + 1; } + + if(!j) + { + if(protocolLegacy > 0 && uiInfo.demoCount < MAX_DEMOS) + { + Com_sprintf(demoExt, sizeof(demoExt), ".%s%d", DEMOEXT, protocolLegacy); + uiInfo.demoCount += trap_FS_GetFileList("demos", demoExt, demolist, ARRAY_LEN(demolist)); + demoname = demolist; + } + else + break; + } } }