From add7b7d22b8a7b0a01a10fba44b9d79b507038b5 Mon Sep 17 00:00:00 2001 From: Alkapivo Date: Thu, 14 Aug 2025 22:42:33 +0200 Subject: [PATCH] Add FPSRender implementation to TestSuite --- test/TestSuite.gml | 80 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/test/TestSuite.gml b/test/TestSuite.gml index 50ba120..50189fd 100644 --- a/test/TestSuite.gml +++ b/test/TestSuite.gml @@ -24,6 +24,9 @@ function TestSuite(json = {}) constructor { ///@type {Boolean} stopAfterFailure = Struct.getDefault(json, "stopAfterFailure", false) + ///@type {FPSMeasure} + measure = new FPSMeasure() + ///@private ///@type {Number} pointer = 0 @@ -35,6 +38,8 @@ function TestSuite(json = {}) constructor { return this } + //this.measure.update() + if (this.pointer >= this.tests.size()) { this.finished = true return this @@ -53,14 +58,83 @@ function TestSuite(json = {}) constructor { var status = this.report.getLast().result.status if (this.stopAfterFailure) { switch (status) { - case PromiseStatus.REJECTED: this.finished = true break - case PromiseStatus.FULLFILLED: this.pointer++ break + case PromiseStatus.REJECTED: this.finished = true + break + case PromiseStatus.FULLFILLED: this.pointer += 1 + break } } else if (status != PromiseStatus.PENDING) { - this.pointer++ + this.pointer += 1 } } return this } } + + +function FPSMeasure() constructor { + ///@type {Array>} + timeline = new Array(Array, [ new Array(Struct) ]) + + ///@type {Number} + time = 0.0 + + ///@type {Number} + startTime = 0.0 + + ///@return {FPSMeasure} + update = function() { + var current = get_timer() + if (this.time == 0.0) { + this.time = current + this.startTime = current + } + + if (current - this.time >= 1000000) { + this.time = current + timeline.add(new Array(Struct)) + } + + timeline.getLast().add({ + "fps": fps, + "fpsReal": fps_real, + }) + + return this + } + + ///@return {Array} + generateReport = function() { + reports = new Array(Struct) + + this.timeline.forEach(function(cell, index, reports) { + var report = { + minFps: null, + maxFps: null, + avgFps: null, + minFpsReal: null, + maxFpsReal: null, + avgFpsReal: null, + } + + cell.forEach(function(entry, index, report) { + report.minFps = report.minFps == null ? entry.fps : min(report.minFps, entry.fps) + report.maxFps = report.maxFps == null ? entry.fps : min(report.maxFps, entry.fps) + report.avgFps = report.avgFps == null ? entry.fps : report.avgFps + entry.fps + report.minFpsReal = report.minFpsReal == null ? entry.fpsReal : min(report.minFpsReal, entry.fpsReal) + report.maxFpsReal = report.maxFpsReal == null ? entry.fpsReal : min(report.maxFpsReal, entry.fpsReal) + report.avgFpsReal = report.avgFpsReal == null ? entry.fpsReal : report.avgFpsReal + entry.fpsReal + }, report) + + report.avgFps = (report.avgFps == null || cell.size() == 0) ? 0.0 : report.avgFps / cell.size() + report.avgFpsReal = (report.avgFpsReal == null || cell.size() == 0) ? 0.0 : report.avgFpsReal / cell.size() + reports.add(report) + }, reports) + + return { + duration: (get_timer() - this.startTime) / 1000000, + data: reports.container, + } + } +} \ No newline at end of file