0ad/binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js
phosit a80446eb59
Use the profiler to profile map generation
Instead of writing the duration to the console it uses
`Engine.ProfileStart` and `Engine.ProfileStop` to profile map
generation.

Refs: #5263
2026-07-25 10:47:49 +02:00

38 lines
897 B
JavaScript

function RandomMapLogger()
{
this.taskStarted = false;
this.startTime = Engine.GetMicroseconds ? Engine.GetMicroseconds() : 0;
this.prefix = ""; // seems noisy
// Don't print in test cases
if (g_MapSettings.Name)
this.printDirectly(
this.prefix +
"Generating " + g_MapSettings.Name +
" of size " + g_MapSettings.Size +
" and " + (g_MapSettings.PlayerData.length - 1) + " players.\n");
}
RandomMapLogger.prototype.printDirectly = function(string)
{
log(string);
print(string);
};
RandomMapLogger.prototype.print = function(string)
{
if (this.taskStarted)
Engine.ProfileStop();
const text = this.prefix + string;
this.printDirectly(text + "...\n");
Engine.ProfileStart(text);
this.taskStarted = true;
};
RandomMapLogger.prototype.close = function()
{
if (this.taskStarted)
Engine.ProfileStop();
this.printDirectly(this.prefix + "Map generation finished.\n");
};