debug.gd 928 B

12345678910111213141516171819202122232425262728
  1. extends Label
  2. # Displays some useful debug information in a Label.
  3. @onready var player := $"../Player"
  4. @onready var voxel_world := $"../VoxelWorld"
  5. func _process(_delta: float) -> void:
  6. if Input.is_action_just_pressed(&"debug"):
  7. visible = not visible
  8. text = "Position: %.1v" % player.transform.origin \
  9. + "\nEffective render distance: " + str(voxel_world.effective_render_distance) \
  10. + "\nLooking: " + _cardinal_string_from_radians(player.transform.basis.get_euler().y) \
  11. + "\nMemory: " + "%3.0f" % (OS.get_static_memory_usage() / 1048576.0) + " MiB" \
  12. + "\nFPS: %d" % Engine.get_frames_per_second()
  13. # Expects a rotation where 0 is North, on the range -PI to PI.
  14. func _cardinal_string_from_radians(angle: float) -> String:
  15. if angle > TAU * 3 / 8:
  16. return "South"
  17. if angle < -TAU * 3 / 8:
  18. return "South"
  19. if angle > TAU * 1 / 8:
  20. return "West"
  21. if angle < -TAU * 1 / 8:
  22. return "East"
  23. return "North"