From 0d2d2a2d4454847400ad4cad94daed367cfa6e69 Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Tue, 18 Mar 2025 18:08:42 +0100 Subject: [PATCH] Add engine.detect_common_issues() and run it after 300 frames. --- src/graphics/render.nim | 4 ++++ src/myou_engine.nim | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/graphics/render.nim b/src/graphics/render.nim index b949d28..8a66132 100644 --- a/src/graphics/render.nim +++ b/src/graphics/render.nim @@ -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 diff --git a/src/myou_engine.nim b/src/myou_engine.nim index caf5e1a..e368af1 100644 --- a/src/myou_engine.nim +++ b/src/myou_engine.nim @@ -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"