From f1768275f4a6b8b272d70ffbad90bd389ede9e3a Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Fri, 23 Aug 2024 00:33:38 +0200 Subject: [PATCH] Remove elvis and replace remaining nimble dependencies by git submodules. --- .gitmodules | 6 ++++++ libs/nglfw | 1 + libs/packages/pixie.nim | 3 --- libs/pixie | 1 - libs/stb_image_nim | 2 +- libs/tinyre | 1 + src/graphics/material.nim | 5 ++--- src/graphics/render.nim | 10 ++++++---- src/objects/gameobject.nim | 20 +------------------- src/objects/mesh.nim | 16 ++++++---------- src/platform/glfw_wrap.nim | 10 +++++----- src/scene.nim | 24 ++++++++++++------------ src/util.nim | 5 ++++- 13 files changed, 45 insertions(+), 59 deletions(-) create mode 160000 libs/nglfw delete mode 100644 libs/packages/pixie.nim delete mode 160000 libs/pixie create mode 160000 libs/tinyre diff --git a/.gitmodules b/.gitmodules index 34896e7..b026840 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,9 @@ [submodule "libs/stb_image_nim"] path = libs/stb_image_nim url = https://gitlab.com/kungfoobar/stb_image-Nim.git +[submodule "libs/tinyre"] + path = libs/tinyre + url = https://github.com/khchen/tinyre +[submodule "libs/nglfw"] + path = libs/nglfw + url = https://github.com/DiThi/nglfw diff --git a/libs/nglfw b/libs/nglfw new file mode 160000 index 0000000..4ffed95 --- /dev/null +++ b/libs/nglfw @@ -0,0 +1 @@ +Subproject commit 4ffed95fde502a86fd694b99e755300984d13ae1 diff --git a/libs/packages/pixie.nim b/libs/packages/pixie.nim deleted file mode 100644 index 139f548..0000000 --- a/libs/packages/pixie.nim +++ /dev/null @@ -1,3 +0,0 @@ -import ../pixie/src/pixie -export pixie - diff --git a/libs/pixie b/libs/pixie deleted file mode 160000 index 8458981..0000000 --- a/libs/pixie +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 84589810078f5b9ca85b510393e0cf1364481e65 diff --git a/libs/stb_image_nim b/libs/stb_image_nim index 11e49d0..57212e9 160000 --- a/libs/stb_image_nim +++ b/libs/stb_image_nim @@ -1 +1 @@ -Subproject commit 11e49d00741d755e5bbc940cea8c98e16713653f +Subproject commit 57212e9dccd0bc4506a34101d69c32565eefa8fc diff --git a/libs/tinyre b/libs/tinyre new file mode 160000 index 0000000..77469f5 --- /dev/null +++ b/libs/tinyre @@ -0,0 +1 @@ +Subproject commit 77469f58916369bc3863194cabb05238577fb257 diff --git a/src/graphics/material.nim b/src/graphics/material.nim index a185d8a..ac3d57f 100644 --- a/src/graphics/material.nim +++ b/src/graphics/material.nim @@ -61,7 +61,6 @@ proc use*(self: Shader): GLuint {.inline,discardable.} proc destroy*(self: Shader) # End forward declarations -import elvis import tinyre import std/sequtils import std/strformat @@ -439,13 +438,13 @@ proc initShader*(self: Shader, engine: MyouEngine, material: Material, glDeleteShader(fragment_shader) if "ERROR: 0:" in gl_log: # Show engine for first error - let line = error_msg.split(":")[2].parseInt ?: 0 + let line = try: error_msg.split(":")[2].parseInt except: 0 # TODO: show only 4 lines of engine but also the previous # line without indent to know which function it is for i in max(1, line - 1000) ..< min(line + 4, lines.len): console_error(&"{i} {lines[i - 1]}") elif gl_log.startsWith "0(": - let line = error_msg.split({'(',')'})[1].parseInt ?: 0 + let line = try: error_msg.split({'(',')'})[1].parseInt except: 0 for i in max(1, line - 1000) ..< min(line + 4, lines.len): console_error(&"{i} {lines[i - 1]}") else: diff --git a/src/graphics/render.nim b/src/graphics/render.nim index fbb0e5e..3198f86 100644 --- a/src/graphics/render.nim +++ b/src/graphics/render.nim @@ -51,7 +51,6 @@ proc draw_cubemap*(self: RenderManager, scene: Scene, cubemap_fb: Framebuffer, c proc get_render_uniform_blocks*(): string # End forward declarations -import elvis import std/algorithm import std/options import std/strformat @@ -266,7 +265,7 @@ proc draw_mesh*(self: RenderManager, mesh: Mesh, mesh2world: Mat4, cam_data: Ren continue var mat = if material_override == nil: - amesh.materials.get_or_default(submesh_idx) ?: self.no_material + amesh.materials.get_or_default(submesh_idx, self.no_material) else: material_override @@ -417,7 +416,10 @@ proc draw_quad*(self: RenderManager, material: Material, scene: Scene, cam_data: proc draw_viewport*(self: RenderManager, viewport: Viewport, rect: (int32,int32,int32,int32), dest_buffer: Framebuffer, passes: seq[int]) = # Configure camera data - let cam = viewport.debug_camera ?: viewport.camera + let cam = if viewport.debug_camera.nonNil: + viewport.debug_camera + else: + viewport.camera let scene = cam.scene if self.was_right_eye != viewport.is_right_eye: self.was_right_eye = viewport.is_right_eye @@ -523,7 +525,7 @@ proc draw_viewport*(self: RenderManager, viewport: Viewport, rect: (int32,int32, idx = idx shr 1 idx = num_meshes - idx - 1 let ob = scene.mesh_passes[1][idx] - # (ob.last_lod[cam_name].?mesh ? ob).sort_faces(cam_pos) + # TODO: LoDs ob.sort_faces(cam_pos) for ob in scene.mesh_passes[1]: if ob.visible: diff --git a/src/objects/gameobject.nim b/src/objects/gameobject.nim index fe51ffa..9d4134e 100644 --- a/src/objects/gameobject.nim +++ b/src/objects/gameobject.nim @@ -110,8 +110,6 @@ method get_armature*(self: GameObject): Armature {.base.} = # End forward declarations and ob type methods import json -import elvis - import std/math import std/tables import ../incomplete @@ -120,22 +118,6 @@ import ../graphics/ubo import ../scene import ./mesh -# Alternative to ob type methods using templates instead -# TODO: use or delete - -# template is_camera*(self: GameObject): bool = ?self and self.otype == TCamera -# template is_light*(self: GameObject): bool = ?self and self.otype == TLight -# template is_mesh*(self: GameObject): bool = ?self and self.otype == TMesh -# template is_armature*(self: GameObject): bool = ?self and self.otype == TArmature -# template get_camera*(self: GameObject): Camera = -# if ?self and self.otype == TCamera: cast[Camera](self) else: nil -# template get_light*(self: GameObject): Light = -# if ?self and self.otype == TLight: cast[Light](self) else: nil -# template get_mesh*(self: GameObject): Mesh = -# if ?self and self.otype == TMesh: cast[Mesh](self) else: nil -# template get_armature*(self: GameObject): Armature = -# if ?self and self.otype == TArmature: cast[Armature](self) else: nil - proc initGameObject*(self: GameObject, engine: MyouEngine, name: string="", scene: Scene=nil): GameObject = # Remember to add any new mutable reference to clone() self.engine = engine @@ -500,7 +482,7 @@ iterator children_recursive*(self: GameObject, include_self: static[bool] = fals break proc remove*(self: GameObject, recursive: bool = true) = - if ?self.scene: + if self.scene.nonNil: self.scene.remove_object(self, recursive) proc destroy*(self: GameObject, recursive: bool = true) = diff --git a/src/objects/mesh.nim b/src/objects/mesh.nim index c7c19c4..46b1071 100644 --- a/src/objects/mesh.nim +++ b/src/objects/mesh.nim @@ -52,8 +52,6 @@ proc ensure_capacity*(self: Mesh, extra_elements: int) proc write_vaos*(self: MeshData) # End forward declarations and ob type methods -import elvis -import ../quat import std/algorithm # import std/sequtils @@ -65,6 +63,7 @@ import ./gameobject import ../scene import ../util import ../attributes +import ../quat export arr_ref export tables @@ -167,7 +166,7 @@ proc gpu_buffers_upload*(self: MeshData) = if not had_indices: self.num_indices.add(num_indices.int32) elif not had_indices: - self.num_indices.add((buffer_size div (self.stride ?: 0)).int32) + self.num_indices.add((buffer_size div self.stride).int32) self.index_buffers.add(ib) if self.use_tf: self.tf_vbos.setLen 2 @@ -405,10 +404,7 @@ proc load_from_va_ia*(self: Mesh, if self.data != nil: self.data.remove(self) - # if @hash and (@data = @engine.mesh_datas[@hash])? - # @data.users.push @ - # @engine.main_loop?.reset_timeout() - # return + # TODO: hash meshes to reuse existing copies automatically var data = newMeshData(self.engine) when defined(myouUseRenderdoc): data.name = self.name @@ -460,14 +456,14 @@ proc load_from_va_ia*(self: Mesh, proc add_modifier*(self: Mesh, modifier: VertexModifier) = self.vertex_modifiers.add(modifier) - if ?modifier.prepare_mesh and ?self.data: + if modifier.prepare_mesh.nonNil and self.data.nonNil: echo &"applying modifiers of {self.name} after it was already loaded" modifier.prepare_mesh(self) # self.update_signature() proc insert_modifier*(self: Mesh, index: int, modifier: VertexModifier) = self.vertex_modifiers.insert(modifier, index) - if ?modifier.prepare_mesh and ?self.data: + if modifier.prepare_mesh.nonNil and self.data.nonNil: echo &"applying modifiers of {self.name} after it was already loaded" modifier.prepare_mesh(self) # self.update_signature() @@ -483,7 +479,7 @@ proc remove_modifier*(self: Mesh, modifier: VertexModifier) = proc clone_impl*(self: Mesh, clone: Mesh): Mesh = clone.last_lod.clear() - if ?clone.data: + if clone.data.nonNil: clone.data.users.add(clone) return clone diff --git a/src/platform/glfw_wrap.nim b/src/platform/glfw_wrap.nim index 1274364..3d89e49 100644 --- a/src/platform/glfw_wrap.nim +++ b/src/platform/glfw_wrap.nim @@ -35,7 +35,7 @@ import ../types import vmath except Quat -import staticglfw as glfw +import nglfw as glfw type Window* = glfw.Window # proc make_window*(width, height: int32, title: string): Window @@ -154,7 +154,7 @@ proc init_graphics*(engine: MyouEngine, width, height: int32, title: string, # TODO!! Option to delay this to simulate the situation in mobile platforms # Init GLFW - if glfw.init() == 0: + if not glfw.init(): raise newException(Exception, "Failed to Initialize GLFW") let major = opengl_version div 100 @@ -209,12 +209,12 @@ var current_screen: Screen proc platform_switch_screen*(screen: Screen): bool {.inline.} = if current_screen != screen: - screen.window.makeContextCurrent() + cast[Window](screen.window).makeContextCurrent() current_screen = screen return true # proc platform_swap_buffers*(screen: Screen) {.inline.} = -# screen.window.swapBuffers() +# cast[Window](screen.window).swapBuffers() proc start_platform_main_loop*(engine: MyouEngine, main_loop: proc(self: MyouEngine)) = while windows.len != 0: @@ -231,4 +231,4 @@ proc start_platform_main_loop*(engine: MyouEngine, main_loop: proc(self: MyouEng glfw.terminate() proc myouAndroidGetActivity*(): pointer = - assert false, "Not using Android" \ No newline at end of file + assert false, "Not using Android" diff --git a/src/scene.nim b/src/scene.nim index 92f0342..663d457 100644 --- a/src/scene.nim +++ b/src/scene.nim @@ -64,7 +64,6 @@ proc render_all_cubemaps*(self: Scene, use_roughness_prefiltering: bool, mipmap_ import vmath except Quat import ./quat -import elvis import std/algorithm import std/math import std/options @@ -163,13 +162,13 @@ proc add_object*(self: Scene, ob: GameObject, ob.parent = p p.children.add(ob) var armature = p.get_armature - if ?armature and ?parent_bone: + if armature.nonNil and parent_bone != "": var bone = armature.bones[parent_bone] - if ?bone: + if bone.nonNil: ob.parent_bone_index = armature.bone_list.find(bone) bone.object_children.add(ob) var mesh = ob.get_mesh - if ?mesh: + if mesh.nonNil: # TODO: not having number of passes hardcoded for p in 0'i32 .. 2: if p in mesh.passes: @@ -196,12 +195,12 @@ proc remove_object*(self: Scene, ob: GameObject, recursive: bool = true) = self.objects.del(ob.name) self.parents.del(ob.original_name) var mesh = ob.get_mesh - if ?mesh: + if mesh.nonNil: self.mesh_passes[0].remove mesh self.mesh_passes[1].remove mesh self.fg_pass.remove mesh self.bg_pass.remove mesh - if ?mesh.data: + if mesh.data.nonNil: mesh.data.remove(mesh) elif ob.is_camera: for screen in self.engine.screens: @@ -217,9 +216,9 @@ proc remove_object*(self: Scene, ob: GameObject, recursive: bool = true) = self.lights.remove light elif ob.is_armature: self.armatures.remove ob.get_armature - if ob.parent_bone_index != -1 and ?ob.parent: + if ob.parent_bone_index != -1 and ob.parent.nonNil: var ar = ob.parent.get_armature - if ?ar and ar.bone_list.len > ob.parent_bone_index: + if ar.nonNil and ar.bone_list.len > ob.parent_bone_index: ar.bone_list[ob.parent_bone_index].object_children.remove ob ob.body.destroy() # TODO: Remove probes if they have no users @@ -235,7 +234,7 @@ proc remove_object*(self: Scene, ob: GameObject, recursive: bool = true) = proc make_parent*(self: Scene, parent: GameObject, child: GameObject, keep_transform: bool = true) = assert parent != nil and child != nil, "Arguments 'parent' and 'child' can't be nil." - if ?child.parent: + if child.parent.nonNil: self.clear_parent(child, keep_transform) # TODO: should we store the index in the objects # to make this check faster? @@ -313,7 +312,7 @@ proc reorder_children*(self: Scene) = reorder(c) for ob in self.children: - if ?ob.parent: + if ob.parent.nonNil: continue reorder(ob) self.children_are_ordered = true @@ -382,9 +381,10 @@ proc new_mesh*(self: Scene, name: string, proc set_active_camera*(self: Scene, camera: Camera) = self.active_camera = camera if camera.scene != self: - self.add_object(camera, camera.name ?: "Camera") + let name = if camera.name != "": camera.name else: "Camera" + self.add_object(camera, name) if self.add_viewport_automatically: - if not ?self.engine.screens[0].viewports: + if self.engine.screens[0].viewports.len == 0: self.engine.screens[0].add_viewport(camera) return diff --git a/src/util.nim b/src/util.nim index e4bfdd1..428da3d 100644 --- a/src/util.nim +++ b/src/util.nim @@ -96,9 +96,10 @@ func align*[T: SomeInteger](n, align: T): T = func bytelen*[T](s: seq[T]): int = s.len * sizeof(T) -func get_or_default*[T](s: seq[T], i: int): T = +func get_or_default*[T](s: seq[T], i: int, default: T = T.default): T = if i >= s.low and i <= s.high: return s[i] + return default when defined(js): @@ -229,3 +230,5 @@ template staticOrDebugRead*(path: string): string = readFile dir & path else: staticRead path + +template nonNil*(x: untyped): bool = x != nil