Add engine.detect_common_issues() and run it after 300 frames.

This commit is contained in:
Alberto Torres 2025-03-18 18:08:42 +01:00
parent c09499dd01
commit 0d2d2a2d44
2 changed files with 33 additions and 0 deletions

View file

@ -249,6 +249,10 @@ proc draw_all*(self: RenderManager) =
glUseProgram(0)
glBindVertexArray(0)
# Detect common issues after an arbitrary amount of time
if self.render_tick == 60 * 5:
self.engine.detect_common_issues()
proc draw_mesh*(self: RenderManager, mesh: Mesh, mesh2world: Mat4, cam_data: RenderCameraData, pass: int = -1, material_override: Material = nil) =
if mesh.sqscale < 0.000001:
mesh.culled_in_last_frame = true

View file

@ -69,6 +69,7 @@ proc newMyouEngine*(
): MyouEngine
proc get_builtin_shader_library*(use_cubemap_prefiltering = true): string
proc get_builtin_shader_textures*(): Table[string, Texture]
proc detect_common_issues*(self: MyouEngine)
# End forward declarations
import std/strutils
@ -220,3 +221,31 @@ proc loadScene*(self: MyouEngine, uri: string, callback: proc(err: string, scene
let loader = loaders[0](self)
loader.openAssetFile(uri)
loader.loadScene(name, nil, callback)
proc detect_common_issues*(self: MyouEngine) =
# TODO: use logging
template check(cond: bool, msg: string) =
if not cond:
echo msg
return
check self.screen.nonNil, "Warning: there is no screen"
check self.screen.enabled, "Warning: main screen is not enabled"
check self.screen.viewports.len != 0, "Warning: main screen has no viewports"
var any_scene_enabled = false
for vp in self.screen.viewports:
if vp.camera.scene.enabled:
any_scene_enabled = true
check any_scene_enabled, "Warning: no visible scene is enabled"
var any_object_visible = false
block ob_vis:
for vp in self.screen.viewports:
if vp.camera.scene.enabled:
for pass in vp.camera.scene.mesh_passes:
for mesh in pass:
if mesh.visible and mesh.materials.len != 0:
# TODO: check culling
# TODO: separate flags to specify why nothing is visible
any_object_visible = true
break ob_vis
check any_object_visible, "Warning: no visible object"