From d7f846d0b6d42c85b597d1ec38ac99aa5cfcaf19 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 8 Feb 2015 08:03:30 +0000 Subject: [PATCH] Factor out generation of strings for time values in the bonus screen. This involves the creation of ud.playerbest. git-svn-id: https://svn.eduke32.com/eduke32@4968 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 126 ++++++++++++-------- polymer/eduke32/source/game.h | 6 + polymer/eduke32/source/gamedef.c | 1 + polymer/eduke32/source/gamedef.h | 1 + polymer/eduke32/source/gamestructures.c | 1 + polymer/eduke32/source/lunatic/con_lang.lua | 1 + polymer/eduke32/source/lunatic/defs.ilua | 1 + polymer/eduke32/source/premap.c | 2 + 8 files changed, 87 insertions(+), 52 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 670131982..5f28c3bf9 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -3377,6 +3377,11 @@ void G_SetCrosshairColor(int32_t r, int32_t g, int32_t b) invalidatetile(CROSSHAIR, -1, -1); } +static inline size_t G_LastMapInfoIndex(void) +{ + return ud.volume_number*MAXLEVELS + ud.last_level - 1; +} + #define SCORESHEETOFFSET -20 static void G_ShowScores(void) { @@ -3385,7 +3390,7 @@ static void G_ShowScores(void) if (playerswhenstarted > 1 && (GametypeFlags[ud.coop]&GAMETYPE_SCORESHEET)) { gametext(160,SCORESHEETOFFSET+58+2,"Multiplayer Totals",0,2+8+16); - gametext(160,SCORESHEETOFFSET+58+10,MapInfo[(ud.volume_number*MAXLEVELS)+ud.last_level-1].name,0,2+8+16); + gametext(160,SCORESHEETOFFSET+58+10,MapInfo[G_LastMapInfoIndex()].name,0,2+8+16); t = 0; minitext(70,SCORESHEETOFFSET+80,"Name",8,2+8+16+ROTATESPRITE_MAX); @@ -12400,7 +12405,7 @@ static void G_DisplayMPResultsScreen(void) if (PLUTOPAK) // JBF 20030804 rotatesprite_fs((260)<<16,36<<16,65536L,0,PLUTOPAKSPRITE+2,0,0,2+8); gametext(160,58+2,"Multiplayer Totals",0,2+8+16); - gametext(160,58+10,MapInfo[(ud.volume_number*MAXLEVELS)+ud.last_level-1].name,0,2+8+16); + gametext(160,58+10,MapInfo[G_LastMapInfoIndex()].name,0,2+8+16); gametext(160,165,"Press any key or button to continue",quotepulseshade,2+8+16); @@ -12457,13 +12462,63 @@ static void G_DisplayMPResultsScreen(void) minitext(45,96+(8*7),"Deaths",8,2+8+16+128); } +static int32_t G_PrintTime_ClockPad(void) +{ + int32_t clockpad = 2; + int32_t ii, ij; + + for (ii=g_player[myconnectindex].ps->player_par/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; + clockpad = max(clockpad,ij); + if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) + { + for (ii=MapInfo[G_LastMapInfoIndex()].partime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; + clockpad = max(clockpad,ij); + if (!NAM && MapInfo[G_LastMapInfoIndex()].designertime) + { + for (ii=MapInfo[G_LastMapInfoIndex()].designertime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; + clockpad = max(clockpad,ij); + } + } + if (ud.playerbest > 0) for (ii=ud.playerbest/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; + clockpad = max(clockpad,ij); + + return clockpad; +} + +static const char* G_PrintTime2(int32_t time) +{ + Bsprintf(tempbuf, "%0*d:%02d", G_PrintTime_ClockPad(), time/(REALGAMETICSPERSEC*60), (time/REALGAMETICSPERSEC)%60); + return tempbuf; +} +static const char* G_PrintTime3(int32_t time) +{ + Bsprintf(tempbuf, "%0*d:%02d.%02d", G_PrintTime_ClockPad(), time/(REALGAMETICSPERSEC*60), (time/REALGAMETICSPERSEC)%60, ((time%REALGAMETICSPERSEC)*33)/10); + return tempbuf; +} + +const char* G_PrintYourTime(void) +{ + return G_PrintTime3(g_player[myconnectindex].ps->player_par); +} +const char* G_PrintParTime(void) +{ + return G_PrintTime2(MapInfo[G_LastMapInfoIndex()].partime); +} +const char* G_PrintDesignerTime(void) +{ + return G_PrintTime2(MapInfo[G_LastMapInfoIndex()].designertime); +} +const char* G_PrintBestTime(void) +{ + return G_PrintTime3(ud.playerbest); +} + void G_BonusScreen(int32_t bonusonly) { int32_t gfx_offset; int32_t bonuscnt; int32_t clockpad = 2; char *lastmapname; - int32_t playerbest = -1; if (g_networkMode == NET_DEDICATED_SERVER) return; @@ -12478,9 +12533,9 @@ void G_BonusScreen(int32_t bonusonly) } else { - lastmapname = MapInfo[(ud.volume_number*MAXLEVELS)+ud.last_level-1].name; + lastmapname = MapInfo[G_LastMapInfoIndex()].name; if (!lastmapname) // this isn't right but it's better than no name at all - lastmapname = MapInfo[(ud.m_volume_number*MAXLEVELS)+ud.last_level-1].name; + lastmapname = MapInfo[G_LastMapInfoIndex()].name; } @@ -12561,29 +12616,8 @@ void G_BonusScreen(int32_t bonusonly) bonuscnt = 0; totalclock = 0; - playerbest = CONFIG_GetMapBestTime(MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].filename); - - if (g_player[myconnectindex].ps->player_par > 0 && (g_player[myconnectindex].ps->player_par < playerbest || playerbest < 0)) - CONFIG_SetMapBestTime(MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].filename, g_player[myconnectindex].ps->player_par); - - { - int32_t ii, ij; - - for (ii=g_player[myconnectindex].ps->player_par/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; - clockpad = max(clockpad,ij); - if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) - { - for (ii=MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].partime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; - clockpad = max(clockpad,ij); - if (!NAM && MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].designertime) - { - for (ii=MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].designertime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; - clockpad = max(clockpad,ij); - } - } - if (playerbest > 0) for (ii=playerbest/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) ; - clockpad = max(clockpad,ij); - } + if (g_player[myconnectindex].ps->player_par > 0 && (g_player[myconnectindex].ps->player_par < ud.playerbest || ud.playerbest < 0)) + CONFIG_SetMapBestTime(MapInfo[G_LastMapInfoIndex()].filename, g_player[myconnectindex].ps->player_par); do { @@ -12665,21 +12699,21 @@ void G_BonusScreen(int32_t bonusonly) yy+=10; if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) { - if (MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].partime) + if (MapInfo[G_LastMapInfoIndex()].partime) { gametext(10,yy+9,"Par Time:",0,2+8+16); yy+=10; } - if (!NAM && !DUKEBETA && MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].designertime) + if (!NAM && !DUKEBETA && MapInfo[G_LastMapInfoIndex()].designertime) { gametext(10,yy+9,"3D Realms' Time:",0,2+8+16); yy+=10; } } - if (playerbest > 0) + if (ud.playerbest > 0) { - gametext(10,yy+9,(g_player[myconnectindex].ps->player_par > 0 && g_player[myconnectindex].ps->player_par < playerbest)?"Prev Best Time:":"Your Best Time:",0,2+8+16); + gametext(10,yy+9,(g_player[myconnectindex].ps->player_par > 0 && g_player[myconnectindex].ps->player_par < ud.playerbest)?"Prev Best Time:":"Your Best Time:",0,2+8+16); yy += 10; } @@ -12697,13 +12731,9 @@ void G_BonusScreen(int32_t bonusonly) if (g_player[myconnectindex].ps->player_par > 0) { - Bsprintf(tempbuf,"%0*d:%02d.%02d",clockpad, - (g_player[myconnectindex].ps->player_par/(REALGAMETICSPERSEC*60)), - (g_player[myconnectindex].ps->player_par/REALGAMETICSPERSEC)%60, - ((g_player[myconnectindex].ps->player_par%REALGAMETICSPERSEC)*33)/10 - ); + G_PrintYourTime(); gametext((320>>2)+71,yy+9,tempbuf,0,2+8+16); - if (g_player[myconnectindex].ps->player_par < playerbest) + if (g_player[myconnectindex].ps->player_par < ud.playerbest) gametext((320>>2)+89+(clockpad*24),yy+9,"New record!",0,2+8+16); } else @@ -12712,31 +12742,23 @@ void G_BonusScreen(int32_t bonusonly) if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) { - if (MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].partime) + if (MapInfo[G_LastMapInfoIndex()].partime) { - Bsprintf(tempbuf,"%0*d:%02d",clockpad, - (MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].partime/(REALGAMETICSPERSEC*60)), - (MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].partime/REALGAMETICSPERSEC)%60); + G_PrintParTime(); gametext((320>>2)+71,yy+9,tempbuf,0,2+8+16); yy+=10; } - if (!NAM && !DUKEBETA && MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].designertime) + if (!NAM && !DUKEBETA && MapInfo[G_LastMapInfoIndex()].designertime) { - Bsprintf(tempbuf,"%0*d:%02d",clockpad, - (MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].designertime/(REALGAMETICSPERSEC*60)), - (MapInfo[ud.volume_number*MAXLEVELS+ud.last_level-1].designertime/REALGAMETICSPERSEC)%60); + G_PrintDesignerTime(); gametext((320>>2)+71,yy+9,tempbuf,0,2+8+16); yy+=10; } } - if (playerbest > 0) + if (ud.playerbest > 0) { - Bsprintf(tempbuf,"%0*d:%02d.%02d",clockpad, - (playerbest/(REALGAMETICSPERSEC*60)), - (playerbest/REALGAMETICSPERSEC)%60, - ((playerbest%REALGAMETICSPERSEC)*33)/10 - ); + G_PrintBestTime(); gametext((320>>2)+71,yy+9,tempbuf,0,2+8+16); yy+=10; } diff --git a/polymer/eduke32/source/game.h b/polymer/eduke32/source/game.h index 9ed5390ae..316a14e3b 100644 --- a/polymer/eduke32/source/game.h +++ b/polymer/eduke32/source/game.h @@ -167,6 +167,7 @@ typedef struct { int32_t player_skill,level_number,volume_number,m_marker,marker,mouseflip; vec2_t m_origin; + int32_t playerbest; int32_t configversion; #if !defined LUNATIC @@ -335,6 +336,11 @@ void A_SpawnRandomGlass(int32_t i,int32_t wallnum,int32_t n); void A_SpawnWallGlass(int32_t i,int32_t wallnum,int32_t n); void G_AddUserQuote(const char *daquote); void G_BackToMenu(void); + +const char* G_PrintYourTime(void); +const char* G_PrintParTime(void); +const char* G_PrintDesignerTime(void); +const char* G_PrintBestTime(void); void G_BonusScreen(int32_t bonusonly); //void G_CheatGetInv(void); void G_DisplayRest(int32_t smoothratio); diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index d4220654b..bb83b7ade 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -1045,6 +1045,7 @@ const memberlabel_t UserdefsLabels[]= { "last_camsprite", USERDEFS_LAST_CAMSPRITE, 0, 0 }, { "last_level", USERDEFS_LAST_LEVEL, 0, 0 }, { "secretlevel", USERDEFS_SECRETLEVEL, 0, 0 }, + { "playerbest", USERDEFS_PLAYERBEST, 0, 0 }, { "const_visibility", USERDEFS_CONST_VISIBILITY, 0, 0 }, { "uw_framerate", USERDEFS_UW_FRAMERATE, 0, 0 }, diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index 40c412f2e..51d276229 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -425,6 +425,7 @@ enum UserdefsLabel_t USERDEFS_RUNKEY_MODE, USERDEFS_M_ORIGIN_X, USERDEFS_M_ORIGIN_Y, + USERDEFS_PLAYERBEST, USERDEFS_END }; diff --git a/polymer/eduke32/source/gamestructures.c b/polymer/eduke32/source/gamestructures.c index 3990ac284..85f8873c3 100644 --- a/polymer/eduke32/source/gamestructures.c +++ b/polymer/eduke32/source/gamestructures.c @@ -251,6 +251,7 @@ static void __fastcall VM_AccessUserdef(int32_t iSet, int32_t lLabelID, int32_t case USERDEFS_RUNKEY_MODE: lLabelID = ud.runkey_mode; break; case USERDEFS_M_ORIGIN_X: lLabelID = ud.m_origin.x; break; case USERDEFS_M_ORIGIN_Y: lLabelID = ud.m_origin.y; break; + case USERDEFS_PLAYERBEST: lLabelID = ud.playerbest; break; default: lLabelID = -1; break; } Gv_SetVarX(lVar2, lLabelID); diff --git a/polymer/eduke32/source/lunatic/con_lang.lua b/polymer/eduke32/source/lunatic/con_lang.lua index c5995ea67..3c6e19825 100644 --- a/polymer/eduke32/source/lunatic/con_lang.lua +++ b/polymer/eduke32/source/lunatic/con_lang.lua @@ -868,6 +868,7 @@ local UserdefLabels = { mouseaiming = UD".mouseaiming", pause_on = UDRO".pause_on", player_skill = UD".player_skill", + playerbest = UDRO".playerbest", mouseflip = UDRO".mouseflip", multimode = { "1" }, noexits = UDRO".noexits", diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 2daaa0af4..1aa1454a2 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -513,6 +513,7 @@ typedef struct { int32_t player_skill,level_number,volume_number,m_marker,marker,mouseflip; vec2_t m_origin; + int32_t playerbest; int32_t configversion; diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index ce29e22e3..4b7eb2099 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1905,6 +1905,8 @@ int32_t G_EnterLevel(int32_t g) G_AlignWarpElevators(); resetpspritevars(g); + ud.playerbest = CONFIG_GetMapBestTime(MapInfo[mii].filename); + G_FadeLoad(0,0,0, 63,0, -7, 4); G_CacheMapData(); G_FadeLoad(0,0,0, 0,63, 7, 4);