Greatly improve replay search perfomance by only reading replay name, and not entire file. Increase default search rate up to 1000
This commit is contained in:
1 parent
52c1a950ba
commit
2e8f06286d
3 files changed
+56
-5
No files matched your search
@@ -7156,6 +7156,58 @@ void G_LoadDemoInfo(menudemo_t *pdemo)
|
||||
Z_Free(infobuffer);
|
||||
}
|
||||
|
||||
void G_LoadDemoTitle(menudemo_t *pdemo)
|
||||
{
|
||||
UINT8 infobuffer[96], *info_p;
|
||||
UINT16 pdemoversion;
|
||||
size_t count;
|
||||
|
||||
FILE *handle = fopen(pdemo->filepath, "rb");
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), pdemo->filepath);
|
||||
sprintf(pdemo->title, "INVALID REPLAY");
|
||||
return;
|
||||
}
|
||||
|
||||
count = fread(infobuffer, 1, 96, handle);
|
||||
fclose(handle);
|
||||
info_p = infobuffer;
|
||||
|
||||
// First check isn't too accurate technically, but well, valid replays should be larger than that anyway
|
||||
if (count < 96 || memcmp(info_p, DEMOHEADER, 12))
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemo->filepath);
|
||||
sprintf(pdemo->title, "INVALID REPLAY");
|
||||
Z_Free(infobuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
info_p += 12; // DEMOHEADER
|
||||
|
||||
READUINT8(info_p);
|
||||
READUINT8(info_p);
|
||||
pdemoversion = READUINT16(info_p);
|
||||
|
||||
switch(pdemoversion)
|
||||
{
|
||||
case DEMOVERSION: // latest always supported
|
||||
// demo title
|
||||
M_Memcpy(pdemo->title, info_p, 64);
|
||||
break;
|
||||
#ifdef DEMO_COMPAT_100
|
||||
case 0x0001:
|
||||
sprintf(pdemo->title, "Legacy Replay");
|
||||
break;
|
||||
#endif
|
||||
// too old, cannot support.
|
||||
default:
|
||||
CONS_Alert(CONS_ERROR, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemo->filepath);
|
||||
sprintf(pdemo->title, "INVALID REPLAY");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// G_PlayDemo
|
||||
//
|
||||
|
||||
@@ -265,6 +265,7 @@ void G_DeferedInitNew(boolean pencoremode, const char *mapname, INT32 pickedchar
|
||||
void G_DoLoadLevel(boolean resetplayer);
|
||||
|
||||
void G_LoadDemoInfo(menudemo_t *pdemo);
|
||||
void G_LoadDemoTitle(menudemo_t *pdemo); // For use in replay search feature
|
||||
void G_DeferedPlayDemo(const char *demo);
|
||||
|
||||
// Can be called by the startup code or M_Responder, calls P_SetupLevel.
|
||||
|
||||
+3
-5
@@ -466,7 +466,7 @@ static void Dummystaff_OnChange(void);
|
||||
// ==========================================================================
|
||||
|
||||
// How much replays are checked per frame when using search
|
||||
consvar_t cv_replaysearchrate = {"replaysearchrate", "50", CV_SAVE, CV_Natural, NULL, 0, NULL, NULL, 0, 0, NULL };
|
||||
consvar_t cv_replaysearchrate = {"replaysearchrate", "1000", CV_SAVE, CV_Natural, NULL, 0, NULL, NULL, 0, 0, NULL };
|
||||
|
||||
consvar_t cv_showfocuslost = {"showfocuslost", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL };
|
||||
|
||||
@@ -6782,10 +6782,8 @@ static void M_HutCheckReplays(size_t maxnum)
|
||||
break;
|
||||
|
||||
case MD_NOTLOADED:
|
||||
G_LoadDemoInfo(&demolist_all[replayquerycheck]);
|
||||
++maxnum; // Gonna check this one next iteration, don't decrease our number of tries yet
|
||||
break;
|
||||
|
||||
G_LoadDemoTitle(&demolist_all[replayquerycheck]);
|
||||
/* FALLTHRU */
|
||||
case MD_OUTDATED:
|
||||
case MD_LOADED:
|
||||
if (strcasestr(demolist_all[replayquerycheck].title, replayqueryinput) != NULL)
|
||||
|
||||
Reference in new issue
Block a user