comparison src/zamikongine/engine.nim @ 499:3f1111f3b9f8

did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
author Sam <sam@basx.dev>
date Wed, 18 Jan 2023 09:52:03 +0700
parents 0c18638c7217
children 8025ab67d931
comparison
equal deleted inserted replaced
498:2fa8e418deae 499:3f1111f3b9f8
77 commandPool*: VkCommandPool 77 commandPool*: VkCommandPool
78 commandBuffers*: array[MAX_FRAMES_IN_FLIGHT, VkCommandBuffer] 78 commandBuffers*: array[MAX_FRAMES_IN_FLIGHT, VkCommandBuffer]
79 imageAvailableSemaphores*: array[MAX_FRAMES_IN_FLIGHT, VkSemaphore] 79 imageAvailableSemaphores*: array[MAX_FRAMES_IN_FLIGHT, VkSemaphore]
80 renderFinishedSemaphores*: array[MAX_FRAMES_IN_FLIGHT, VkSemaphore] 80 renderFinishedSemaphores*: array[MAX_FRAMES_IN_FLIGHT, VkSemaphore]
81 inFlightFences*: array[MAX_FRAMES_IN_FLIGHT, VkFence] 81 inFlightFences*: array[MAX_FRAMES_IN_FLIGHT, VkFence]
82 Input* = object
83 keysDown*: set[Key]
84 keysPressed*: set[Key]
85 keysReleased*: set[Key]
86 mouseDown*: set[MouseButton]
87 mousePressed*: set[MouseButton]
88 mouseReleased*: set[MouseButton]
89 mouseX*: int
90 mouseY*: int
82 Engine* = object 91 Engine* = object
83 vulkan*: Vulkan 92 vulkan*: Vulkan
84 window*: NativeWindow 93 window*: NativeWindow
85 currentscenedata*: ref Thing 94 currentscenedata*: ref Thing
95 input*: Input
86 96
87 proc getAllPhysicalDevices(instance: VkInstance, surface: VkSurfaceKHR): seq[PhysicalDevice] = 97 proc getAllPhysicalDevices(instance: VkInstance, surface: VkSurfaceKHR): seq[PhysicalDevice] =
88 for vulkanPhysicalDevice in getVulkanPhysicalDevices(instance): 98 for vulkanPhysicalDevice in getVulkanPhysicalDevices(instance):
89 var device = PhysicalDevice(device: vulkanPhysicalDevice, extensions: getDeviceExtensions(vulkanPhysicalDevice)) 99 var device = PhysicalDevice(device: vulkanPhysicalDevice, extensions: getDeviceExtensions(vulkanPhysicalDevice))
90 vkGetPhysicalDeviceProperties(vulkanPhysicalDevice, addr(device.properties)) 100 vkGetPhysicalDeviceProperties(vulkanPhysicalDevice, addr(device.properties))
516 allmeshes.add(mesh[]) 526 allmeshes.add(mesh[])
517 if allmeshes.len > 0: 527 if allmeshes.len > 0:
518 var ubermesh = createUberMesh(allmeshes) 528 var ubermesh = createUberMesh(allmeshes)
519 result.vertexBuffers.add createVertexBuffers(ubermesh, result.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue) 529 result.vertexBuffers.add createVertexBuffers(ubermesh, result.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue)
520 530
521 # vertex buffers with indexes 531 when not IndexType is void:
522 var allindexedmeshes: seq[IndexedMesh[VertexType, IndexType]] 532 # vertex buffers with indexes
523 for mesh in partsOfType[ref IndexedMesh[VertexType, IndexType]](engine.currentscenedata): 533 var allindexedmeshes: seq[IndexedMesh[VertexType, IndexType]]
524 allindexedmeshes.add(mesh[]) 534 for mesh in partsOfType[ref IndexedMesh[VertexType, IndexType]](engine.currentscenedata):
525 if allindexedmeshes.len > 0: 535 allindexedmeshes.add(mesh[])
526 var indexedubermesh = createUberMesh(allindexedmeshes) 536 if allindexedmeshes.len > 0:
527 result.indexedVertexBuffers.add createIndexedVertexBuffers(indexedubermesh, result.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue) 537 var indexedubermesh = createUberMesh(allindexedmeshes)
538 result.indexedVertexBuffers.add createIndexedVertexBuffers(indexedubermesh, result.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue)
528 539
529 # uniform buffers 540 # uniform buffers
530 result.uniformBuffers = createUniformBuffers[MAX_FRAMES_IN_FLIGHT, UniformType]( 541 result.uniformBuffers = createUniformBuffers[MAX_FRAMES_IN_FLIGHT, UniformType](
531 result.device, 542 result.device,
532 engine.vulkan.device.physicalDevice.device 543 engine.vulkan.device.physicalDevice.device
702 lastUpdate = getTime() 713 lastUpdate = getTime()
703 714
704 while not killed: 715 while not killed:
705 716
706 # process input 717 # process input
718 engine.input.keysPressed = {}
719 engine.input.keysReleased = {}
720 engine.input.mousePressed = {}
721 engine.input.mouseReleased = {}
707 for event in engine.window.pendingEvents(): 722 for event in engine.window.pendingEvents():
708 case event.eventType: 723 case event.eventType:
709 of Quit: 724 of Quit:
710 killed = true 725 killed = true
711 of ResizedWindow: 726 of ResizedWindow:
712 resized = true 727 resized = true
713 of KeyDown: 728 of KeyPressed:
714 echo event 729 engine.input.keysPressed.incl event.key
715 if event.key == Escape: 730 engine.input.keysDown.incl event.key
716 killed = true 731 of KeyReleased:
732 engine.input.keysReleased.incl event.key
733 engine.input.keysDown.excl event.key
734 of MousePressed:
735 engine.input.mousePressed.incl event.button
736 engine.input.mouseDown.incl event.button
737 of MouseReleased:
738 engine.input.mouseReleased.incl event.button
739 engine.input.mouseDown.excl event.button
740 of MouseMoved:
741 engine.input.mouseX = event.x
742 engine.input.mouseY = event.y
717 else: 743 else:
718 discard 744 discard
719 745
720 # game logic update 746 # game logic update
721 let 747 let