stopwatch cleanup

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4626 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2009-08-11 19:52:47 +00:00
parent 75f8fae310
commit 4521b61491
2 changed files with 32 additions and 2 deletions
+22
View File
@@ -610,6 +610,28 @@ template <class T, int SIZE> struct ringbuf
#define enumeratek(ht,k,e,b) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc;) { k &e = (ht).enumc->key; (ht).enumc = (ht).enumc->next; b; }
#define enumerate(ht,t,e,b) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc;) { t &e = (ht).enumc->data; (ht).enumc = (ht).enumc->next; b; }
// ease time measurement
struct stopwatch
{
int millis;
stopwatch() : millis(-1) {}
void start()
{
millis = SDL_GetTicks();
}
// returns elapsed time
int stop()
{
ASSERT(millis >= 0);
int time = SDL_GetTicks() - millis;
millis = -1;
return time;
}
};
inline char *newstring(size_t l) { return new char[l+1]; }
inline char *newstring(const char *s, size_t l) { return s_strncpy(newstring(l), s, l+1); }
inline char *newstring(const char *s) { return newstring(s, strlen(s)); }
+10 -2
View File
@@ -280,7 +280,9 @@ VAR(curmaprevision, 1, 0, 0);
bool load_world(char *mname) // still supports all map formats that have existed since the earliest cube betas!
{
int loadmillis = SDL_GetTicks();
stopwatch watch;
watch.start();
advancemaprevision = 1;
setnames(mname);
maploaded = getfilesize(ocgzname);
@@ -425,7 +427,7 @@ bool load_world(char *mname) // still supports all map formats that have
if(f) gzclose(f);
c2skeepalive();
calclight();
conoutf("read map %s rev %d (%d milliseconds)", cgzname, hdr.maprevision, SDL_GetTicks()-loadmillis);
conoutf("read map %s rev %d (%d milliseconds)", cgzname, hdr.maprevision, watch.stop());
conoutf("%s", hdr.maptitle);
pushscontext(IEXC_MAPCFG); // untrusted altogether
@@ -439,11 +441,17 @@ bool load_world(char *mname) // still supports all map formats that have
popscontext();
c2skeepalive();
watch.start();
loopi(256) if(texuse[i]) lookupworldtexture(i);
printf("loaded textures (%d milliseconds)\n", watch.stop());
c2skeepalive();
watch.start();
preload_mapmodels();
printf("loaded mapmodels (%d milliseconds)\n", watch.stop());
c2skeepalive();
watch.start();
audiomgr.preloadmapsounds();
printf("loaded mapsounds (%d milliseconds)\n", watch.stop());
c2skeepalive();
startmap(mname);