diff --git a/source/src/tools.h b/source/src/tools.h index 763d9285..a9791489 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -610,6 +610,28 @@ template 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)); } diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 4f59e960..da77da4c 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -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);