Cache PHS for large maps, because the loading time is insane for large maps.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3564 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2010-07-25 15:07:19 +00:00
parent 0f5a25025d
commit fdcdfe2d5a
1 changed files with 29 additions and 3 deletions

View File

@ -445,13 +445,13 @@ void SV_CalcPHS (void)
return;
}
if (developer.value)
Con_TPrintf (STL_BUILDINGPHS);
num = sv.world.worldmodel->numleafs;
rowwords = (num+31)>>5;
rowbytes = rowwords*4;
if (developer.value)
Con_TPrintf (STL_BUILDINGPHS);
sv.pvs = Hunk_AllocName (rowbytes*num, "phs vis");
scan = sv.pvs;
vcount = 0;
@ -471,6 +471,19 @@ void SV_CalcPHS (void)
}
}
/*this routine takes an exponential amount of time, so cache it if its too big*/
if (rowbytes*num >= 0x100000)
{
sv.phs = COM_LoadHunkFile(va("maps/%s.phs", sv.name));
if (sv.phs && com_filesize == rowbytes*num + 8 && ((unsigned*)sv.phs)[0] == *(unsigned*)"QPHS" && ((unsigned*)sv.phs)[1] == *(unsigned*)"\1\0\0\0")
{
sv.phs += 8;
Con_DPrintf("Loaded cached PHS\n");
return;
}
else
Con_DPrintf("Stale cached PHS\n");
}
sv.phs = Hunk_AllocName (rowbytes*num, "phs hear");
count = 0;
@ -506,6 +519,18 @@ void SV_CalcPHS (void)
count++;
}
if (rowbytes*num >= 0x100000)
{
vfsfile_t *f = FS_OpenVFS(va("maps/%s.phs", sv.name), "wb", FS_GAMEONLY);
if (f)
{
VFS_WRITE(f, "QPHS\1\0\0\0", 8);
VFS_WRITE(f, sv.phs, rowbytes*num);
VFS_CLOSE(f);
Con_Printf("Written PHS cache (%u bytes)\n", rowbytes*num);
}
}
if (num)
if (developer.value)
Con_TPrintf (STL_PHSINFO, vcount/num, count/num, num);
@ -762,6 +787,7 @@ void SV_SpawnServer (char *server, char *startspot, qboolean noents, qboolean us
//reset the server time.
sv.time = 0.1; //some progs don't like time starting at 0.
//cos of spawn funcs like self.nextthink = time...
//NQ uses 1, QW uses 0. Awkward.
sv.starttime = Sys_DoubleTime();
COM_FlushTempoaryPacks();