Mercurial > games > semicongine
changeset 1299:6d0162bfe48a
did: finish mentioned refactoring, no API changes still
author | sam <sam@basx.dev> |
---|---|
date | Tue, 06 Aug 2024 22:57:43 +0700 |
parents | 1feaa8a97acf |
children | 76b8455cad5e |
files | semicongine.nim semicongine/contrib/algorithms/collision.nim semicongine/contrib/algorithms/noise.nim semicongine/contrib/algorithms/texture_packing.nim semicongine/contrib/settings.nim semicongine/contrib/steam.nim semicongine/core.nim semicongine/core/matrix.nim semicongine/core/utils.nim semicongine/core/vector.nim semicongine/gltf.nim semicongine/image.nim semicongine/rendering.nim semicongine/rendering/platform/linux.nim semicongine/rendering/renderer.nim semicongine/rendering/vulkan/api.nim semicongine/rendering/vulkan_wrappers.nim semicongine/resources.nim semicongine/storage.nim semicongine/text.nim tests/test_gltf.nim tests/test_rendering.nim |
diffstat | 22 files changed, 85 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/semicongine.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine.nim Tue Aug 06 22:57:43 2024 +0700 @@ -9,8 +9,10 @@ import ./semicongine/events import ./semicongine/rendering +import ./semicongine/rendering/vulkan/api export events export rendering +export api import ./semicongine/storage import ./semicongine/input
--- a/semicongine/contrib/algorithms/collision.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/contrib/algorithms/collision.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,3 +1,7 @@ +import std/options + +import ../../core + const MAX_COLLISON_DETECTION_ITERATIONS = 20 const MAX_COLLISON_POINT_CALCULATION_ITERATIONS = 20 @@ -348,7 +352,7 @@ direction[0] = 0.0001 inc n -func calculateCollider(points: openArray[Vec3f], theType: ColliderType): Collider = +func calculateCollider*(points: openArray[Vec3f], theType: ColliderType): Collider = var minX = high(float32) maxX = low(float32)
--- a/semicongine/contrib/algorithms/noise.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/contrib/algorithms/noise.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,3 +1,8 @@ +import std/math +import std/hashes + +import ../../core + proc randomGradient(pos: Vec2f, seed: int32 = 0): Vec2f = let randomAngle: float32 = TAU * (float32(int(hash((pos.x, pos.y, seed)))) / float32(high(int))) return vec2(cos(randomAngle), sin(randomAngle))
--- a/semicongine/contrib/algorithms/texture_packing.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/contrib/algorithms/texture_packing.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,3 +1,7 @@ +import std/algorithm + +import ../../image + type Rect = tuple i: int
--- a/semicongine/contrib/settings.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/contrib/settings.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,3 +1,11 @@ +import std/os +import std/parsecfg +import std/streams +import std/strformat +import std/strutils +import std/tables +import std/times + const CONFIGHOTRELOAD {.booldefine.}: bool = not defined(release) const CONFIGHOTRELOADINTERVAL {.intdefine.}: int = 1000 const CONFIGROOT {.strdefine.}: string = "."
--- a/semicongine/contrib/steam.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/contrib/steam.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,9 +1,12 @@ +import std/dynlib +import std/logging +import std/strutils + var steam_api: LibHandle steam_is_loaded = false when defined(linux): - proc dlerror(): cstring {.stdcall, importc.} steam_api = "libsteam_api.so".loadLib() elif defined(windows): steam_api = "steam_api".loadLib()
--- a/semicongine/core.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/core.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,3 +1,12 @@ +import std/macros +import std/math +import std/os +import std/paths +import std/strutils +import std/strformat +import std/tables +import std/typetraits + const RESOURCEROOT {.hint[XDeclaredButNotUsed]: off.} = "resources" include ./core/utils
--- a/semicongine/core/matrix.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/core/matrix.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,5 +1,3 @@ -import std/math - type # layout is row-first # having an object instead of directly aliasing the array seems a bit ugly at
--- a/semicongine/core/utils.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/core/utils.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,9 +1,3 @@ -import std/strutils -import std/strformat -import std/paths -import std/os -import std/typetraits - type HorizontalAlignment* = enum Left
--- a/semicongine/core/vector.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/core/vector.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,7 +1,3 @@ -import std/math -import std/tables -import std/macros - type TVec1*[T: SomeNumber] = array[1, T] TVec2*[T: SomeNumber] = array[2, T]
--- a/semicongine/gltf.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/gltf.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,3 +1,16 @@ +import std/json +import std/logging +import std/streams +import std/strutils +import std/tables +import std/typetraits + +import ./core +import ./rendering +import ./rendering/vulkan/api +import ./image +import ./resources + type GltfNode* = object children*: seq[int] @@ -149,8 +162,6 @@ if root["images"][imageIndex].hasKey("uri"): raise newException(Exception, "Unsupported feature: Cannot load images from external files") - let imageType = root["images"][imageIndex]["mimeType"].getStr() - # assert imageType == "image/png", "glTF loader currently only supports PNG, but found '" & imageType & "'" let bufferView = root["bufferViews"][root["images"][imageIndex][ "bufferView"].getInt()]
--- a/semicongine/image.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/image.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,4 +1,6 @@ import std/os +import std/streams +import std/strutils import ./core import ./resources @@ -25,8 +27,8 @@ height*: uint32 minInterpolation*: VkFilter = VK_FILTER_LINEAR magInterpolation*: VkFilter = VK_FILTER_LINEAR - wrapU: VkSamplerAddressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT - wrapV: VkSamplerAddressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT + wrapU*: VkSamplerAddressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT + wrapV*: VkSamplerAddressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT data*: seq[T] vk*: VkImage imageview*: VkImageView
--- a/semicongine/rendering.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/rendering.nim Tue Aug 06 22:57:43 2024 +0700 @@ -139,7 +139,7 @@ data*: T buffer*: Buffer offset: uint64 - GPUData = GPUArray | GPUValue + GPUData* = GPUArray | GPUValue RenderData* = object descriptorPool: VkDescriptorPool
--- a/semicongine/rendering/platform/linux.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/rendering/platform/linux.nim Tue Aug 06 22:57:43 2024 +0700 @@ -5,7 +5,6 @@ import ../../thirdparty/x11/xlib import ../../thirdparty/x11/xutil -import ../../thirdparty/x11/keysym import ../../thirdparty/x11/x as x11 import ../../thirdparty/x11/xkblib
--- a/semicongine/rendering/renderer.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/rendering/renderer.nim Tue Aug 06 22:57:43 2024 +0700 @@ -45,9 +45,6 @@ else: return value + alignment - remainder -template sType(descriptorSet: DescriptorSet): untyped = - get(genericParams(typeof(descriptorSet)), 1) - template bufferType(gpuData: GPUData): untyped = typeof(gpuData).TBuffer func needsMapping(bType: BufferType): bool =
--- a/semicongine/rendering/vulkan/api.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/rendering/vulkan/api.nim Tue Aug 06 22:57:43 2024 +0700 @@ -17,20 +17,6 @@ func VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} = (variant shl 29) or (major shl 22) or (minor shl 12) or patch -template checkVkResult*(call: untyped) = - when defined(release): - discard call - else: - # yes, a bit cheap, but this is only for nice debug output - var callstr = astToStr(call).replace("\n", "") - while callstr.find(" ") >= 0: - callstr = callstr.replace(" ", " ") - debug "Calling vulkan: ", callstr - let value = call - if value != VK_SUCCESS: - error "Vulkan error: ", astToStr(call), " returned ", $value - raise newException(Exception, "Vulkan error: " & astToStr(call) & - " returned " & $value) # custom enum iteration (for enum values > 2^16) macro enumFullRange(a: typed): untyped = newNimNode(nnkBracket).add(a.getType[1][1..^1]) @@ -12012,3 +11998,18 @@ vkCreateInstance = cast[proc(pCreateInfo: ptr VkInstanceCreateInfo, pAllocator: ptr VkAllocationCallbacks, pInstance: ptr VkInstance): VkResult {.stdcall.}](vkGetInstanceProcAddr(instance, "vkCreateInstance")) converter NimBool2VkBool*(a: bool): VkBool32 = VkBool32(a) + +template checkVkResult*(call: untyped) = + when defined(release): + discard call + else: + # yes, a bit cheap, but this is only for nice debug output + var callstr = astToStr(call).replace("\n", "") + while callstr.find(" ") >= 0: + callstr = callstr.replace(" ", " ") + debug "Calling vulkan: ", callstr + let value = call + if value != VK_SUCCESS: + error "Vulkan error: ", astToStr(call), " returned ", $value + raise newException(Exception, "Vulkan error: " & astToStr(call) & + " returned " & $value)
--- a/semicongine/rendering/vulkan_wrappers.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/rendering/vulkan_wrappers.nim Tue Aug 06 22:57:43 2024 +0700 @@ -61,12 +61,6 @@ result = newSeq[VkPresentModeKHR](n_modes) checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(vulkan.physicalDevice, vulkan.surface, addr(n_modes), result.ToCPointer) -proc svkGetPhysicalDeviceSurfaceFormatsKHR(): seq[VkSurfaceFormatKHR] = - var n_formats: uint32 - checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(vulkan.physicalDevice, vulkan.surface, addr(n_formats), nil) - result = newSeq[VkSurfaceFormatKHR](n_formats) - checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(vulkan.physicalDevice, vulkan.surface, addr(n_formats), result.ToCPointer) - proc hasValidationLayer*(): bool = var n_layers: uint32 checkVkResult vkEnumerateInstanceLayerProperties(addr(n_layers), nil)
--- a/semicongine/resources.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/resources.nim Tue Aug 06 22:57:43 2024 +0700 @@ -3,7 +3,6 @@ import std/json import std/parsecfg import std/os -import std/paths import std/sequtils import std/sets import std/streams @@ -121,7 +120,7 @@ let package = packageDir.splitPath.tail result[package] = Table[string, string]() for resourcefile in walkDirRec(packageDir, relative = true): - result[package][resourcefile.string.replace('\\', '/')] = staticRead(packageDir.joinPath(resourcefile)) + result[package][resourcefile.replace('\\', '/')] = staticRead(packageDir.joinPath(resourcefile)) const bundledResources = loadResources() proc loadResource_intern*(path: string, package: string): Stream =
--- a/semicongine/storage.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/storage.nim Tue Aug 06 22:57:43 2024 +0700 @@ -2,7 +2,6 @@ import std/os import std/paths import std/strformat -import std/strutils import std/tables import ./core
--- a/semicongine/text.nim Tue Aug 06 17:31:13 2024 +0700 +++ b/semicongine/text.nim Tue Aug 06 22:57:43 2024 +0700 @@ -1,10 +1,20 @@ +import std/algorithm +import std/logging import std/os +import std/sequtils +import std/streams +import std/strformat +import std/strutils import std/tables import std/unicode + import ./core +import ./resources import ./rendering +import ./rendering/vulkan/api import ./image +import ./contrib/algorithms/texture_packing const NEWLINE = Rune('\n') @@ -44,11 +54,11 @@ fragmentUv {.Pass.}: Vec2f color {.ShaderOutput.}: Vec4f descriptorSets {.DescriptorSets.}: (TextboxDescriptorSet, ) - vertexCode = """void main() { + vertexCode* = """void main() { gl_Position = vec4(position * vec3(1 / textbox.aspectratio, 1, 1) * textbox.scale + textbox.position, 1.0); fragmentUv = uv; } """ - fragmentCode = """void main() { + fragmentCode* = """void main() { float v = texture(fontAtlas, fragmentUv).r; if(v == 0) { discard;