I copied the built-in Fps class in OpenFL and asked AI, but AI said that the built-in Fps class in OpenFL is not accurate?

I copied the built-in Fps class in OpenFL and asked AI, but AI said that the built-in Fps class in OpenFL is not accurate?

package openfl.display;

import haxe.Timer;
import openfl.events.Event;
import openfl.text.TextField;
import openfl.text.TextFormat;
#if gl_stats
import openfl.display._internal.stats.Context3DStats;
import openfl.display._internal.stats.DrawCallContext;
#end
#if flash
import openfl.Lib;
#end

/**
The FPS class provides an easy-to-use monitor to display
the current frame rate of an OpenFL project
/
#if !openfl_debug
@:fileXml(ā€˜tags=ā€œhaxe,releaseā€ā€™)
@:noDebug
#end
class FPS extends TextField
{
/

The current frame rate, expressed using frames-per-second
**/
public var currentFPS(default, null):Int;

@:noCompletion private var cacheCount:Int;
@:noCompletion private var currentTime:Float;
@:noCompletion private var times:Array<Float>;

public function new(x:Float = 10, y:Float = 10, color:Int = 0x000000)
{
	super();

	this.x = x;
	this.y = y;

	currentFPS = 0;
	selectable = false;
	mouseEnabled = false;
	defaultTextFormat = new TextFormat("_sans", 12, color);
	text = "FPS: ";

	cacheCount = 0;
	currentTime = 0;
	times = [];

	#if flash
	addEventListener(Event.ENTER_FRAME, function(e)
	{
		var time = Lib.getTimer();
		__enterFrame(time - currentTime);
	});
	#end
}

// Event Handlers
@:noCompletion
private #if !flash override #end function __enterFrame(deltaTime:Float):Void
{
	currentTime += deltaTime;
	times.push(currentTime);

	while (times[0] < currentTime - 1000)
	{
		times.shift();
	}

	var currentCount = times.length;
	currentFPS = Math.round((currentCount + cacheCount) / 2);

	if (currentCount != cacheCount /*&& visible*/)
	{
		text = "FPS: " + currentFPS;

		#if (gl_stats && !disable_cffi && (!html5 || !canvas))
		text += "\ntotalDC: " + Context3DStats.totalDrawCalls();
		text += "\nstageDC: " + Context3DStats.contextDrawCalls(DrawCallContext.STAGE);
		text += "\nstage3DDC: " + Context3DStats.contextDrawCalls(DrawCallContext.STAGE3D);
		#end
	}

	cacheCount = currentCount;
}

}

I used to think that only the intensity of the luminescent filter was not supported in HTML5,
But even though I tried Windows, it doesn’t support strength!

HTML5 Windows does not support the intensity of luminescent filters

It is a known issue:

If I follow those threads correctly, migrating to SDL3 is a possible solution, if that’s the direction they choose. Version 3 was only officially released in January and I expect moving to it is no trivial task. There’s some discussion about that here.

1 Like