1
0
forked from mirrors/0ad
Files
0ad/binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js
T
2019-07-15 14:44:53 +00:00

46 lines
1.1 KiB
JavaScript

function RandomMapLogger()
{
this.lastTime = undefined;
this.startTime = Engine.GetMicroseconds();
this.prefix = ""; // seems noisy
this.printDirectly(
this.prefix +
"Generating " + g_MapSettings.Name +
" of size " + g_MapSettings.Size +
" and " + getNumPlayers() + " players.\n");
}
RandomMapLogger.prototype.printDirectly = function(string)
{
log(string);
print(string);
};
RandomMapLogger.prototype.print = function(string)
{
this.printDuration();
this.printDirectly(this.prefix + string + "...");
this.lastTime = Engine.GetMicroseconds();
};
RandomMapLogger.prototype.printDuration = function()
{
if (!this.lastTime)
return;
this.printDurationDirectly("", this.lastTime);
this.lastTime = Engine.GetMicroseconds();
};
RandomMapLogger.prototype.close = function()
{
this.printDuration();
this.printDurationDirectly(this.prefix + "Total map generation time:", this.startTime);
};
RandomMapLogger.prototype.printDurationDirectly = function(text, startTime)
{
this.printDirectly(text + " " + ((Engine.GetMicroseconds() - startTime) / 1000000).toFixed(6) + "s.\n");
};