godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.41k stars 21.26k forks source link

Monitors tab incorrectly reports integers as floats #99577

Closed clayjohn closed 2 days ago

clayjohn commented 3 days ago

Tested versions

System information

M2 Macbook

Issue description

Values that are always integers are being reported as floats in the editor monitor.

Image

This is technically a regression from https://github.com/godotengine/godot/pull/47502

However, https://github.com/godotengine/godot/pull/47502 just exposed an underlying flaw in the monitor system: get_monitor() always returns a double

https://github.com/godotengine/godot/blob/0c45ace151f25de2ca54fe7a46b6f077be32ba6f/main/performance.cpp#L159

Steps to reproduce

Just look in the monitors tab

Minimal reproduction project (MRP)

N/A - this is native to the Godot editor itself

carsonetb commented 3 days ago

Hi!

I'd be interested in trying to fix this issue. I'm not sure if you've already started working on it, but if you haven't and you don't want to, I'd like to take a crack at it.

clayjohn commented 3 days ago

I don't plan on working on this, so go ahead!

carsonetb commented 3 days ago

I think the simplest way to fix this issue would be to just check if the number ends with a .0 and if so remove it. I just added a few lines to EditorPerformanceProfiler::_create_label which do this:

default: {
    String ret = TS->format_number(rtos(p_value));
    if (ret.ends_with(".0")) {
        ret = ret.pad_decimals(0);
    }
    return ret;
}

This fixes the issue of integers as floats in the Monitor:

Image

By the way, I don't see how it's a flaw that get_monitor() returns a double. In 4.3 it returned a double but we didn't see the trailing ".0". Anyway, I'll probably create a pull request for this in a bit.

AThousandShips commented 2 days ago

This was already reported in:

clayjohn commented 2 days ago

Closing as a duplicate of https://github.com/godotengine/godot/issues/99000