Skip to content

Commit

Permalink
feat: count nodes in get_performance_info (#191)
Browse files Browse the repository at this point in the history
* get_performance_info() - add Nodes count to output

* add option argument for `get_performance_info`

---------

Co-authored-by: fireday2 <[email protected]>
  • Loading branch information
Ark2000 and fireday2 authored Sep 10, 2024
1 parent 06d7aa3 commit d0d2d01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions addons/panku_console/modules/engine_tools/env.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ func set_time_scale(val:float) -> void:
_module.set_time_scale(val)

const _HELP_get_performance_info = "Show performance info"
func get_performance_info() -> String:
return _module.get_performance_info()
func get_performance_info(count_nodes := false) -> String:
return _module.get_performance_info(count_nodes)

const _HELP_take_screenshot = "Take a screenshot of current window"
func take_screenshot() -> void:
Expand Down
24 changes: 22 additions & 2 deletions addons/panku_console/modules/engine_tools/module.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,28 @@ func toggle_fullscreen() -> void:
func set_time_scale(val:float) -> void:
Engine.time_scale = val

func get_performance_info() -> String:
return "FPS: %d | Mem: %.2fMB | Objs: %d" % [Engine.get_frames_per_second(), OS.get_static_memory_usage()/1048576.0, Performance.get_monitor(Performance.OBJECT_COUNT)]
class ClsCountNodesInTree:
func calc_children_count(core: PankuConsole, node_path: String) -> int:
var nd: Node = core.get_tree().current_scene.get_node(node_path)
return count_all_children(nd)
func count_all_children(nd: Node) -> int:
var count: int = nd.get_children().size()
for child: Node in nd.get_children():
count += count_all_children(child)
return count

func get_performance_info(count_nodes:bool) -> String:
var result = "FPS: %d | Mem: %.2fMB | Objs: %d" % [
Engine.get_frames_per_second(),
OS.get_static_memory_usage()/1048576.0,
Performance.get_monitor(Performance.OBJECT_COUNT)
]
if count_nodes:
var cls_count: ClsCountNodesInTree = ClsCountNodesInTree.new()
var root_count: int = cls_count.calc_children_count(core, "/root")
var panku_count: int = cls_count.calc_children_count(core, "/root/Panku")
result += " | Nodes: %d" % [root_count - panku_count]
return result

func take_screenshot() -> void:
var image = core.get_viewport().get_texture().get_image()
Expand Down

0 comments on commit d0d2d01

Please sign in to comment.