fastjengine / FastJ

An open-source, Java-based 2D game engine.
https://fastj.tech
MIT License
82 stars 22 forks source link

[Bug]: FastJEngine.getFPSData(FPSValue.Current) returns 0.0 #218

Closed oliverbooth closed 2 years ago

oliverbooth commented 2 years ago

What happened?

Calling FastJEngine.getFPSData(FPSValue.Current) returns 0.0

How to Reproduce the Error

@Override
public void update(FastJCanvas canvas) {
    System.out.println(FastJEngine.getFPSData(FPSValue.Current));
}

FastJ Version

other (please specify below)

Specific FastJ Version

1.6.0

Java Version

No response

Relevant Exceptions/Log Output

0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0

Code of Conduct

lucasstarsz commented 2 years ago

I'll look into the issue as soon as I can. Thank you for posting!

lucasstarsz commented 2 years ago

Heya, I've found the issue.

In the current implementation of FastJEngine, getting the current fps value always returns 0.0 for the first 100 seconds because fpsLogIndex (index accessor for the fps log array I have) is always 1 value ahead of the actual current fps. When the first 100 seconds of FPS have been logged, the value will then always be 100 seconds behind.

In short, there was an off-by-one array accessing issue. 😅 I'll go ahead and make the PR, and you should be able to properly see the fix in the next latest FastJ release 👍🏾