From 19aaaa6698ac71b28d240a46186db18a56a03ccd Mon Sep 17 00:00:00 2001 From: Marcel Kulina Date: Fri, 8 Mar 2024 03:01:54 +0100 Subject: [PATCH] fix engine startup --- core/editor/app/CMakeLists.txt | 66 +++++++++++++++---- core/editor/app/src/app/App.cxx | 16 ++++- scripting/editor/KyaniteEditor.swift | 10 ++- scripting/engine/Engine.swift | 5 +- scripting/engine/Kyanite.swift | 4 +- .../native/rendering/NativeRendering.swift | 4 +- 6 files changed, 78 insertions(+), 27 deletions(-) diff --git a/core/editor/app/CMakeLists.txt b/core/editor/app/CMakeLists.txt index b4675da..0c9e1f0 100644 --- a/core/editor/app/CMakeLists.txt +++ b/core/editor/app/CMakeLists.txt @@ -19,7 +19,7 @@ target_include_directories(EditorApp PRIVATE ${CMAKE_SOURCE_DIR}/core/engine/ren target_link_directories(EditorApp PRIVATE ${CMAKE_SOURCE_DIR}/.build/debug) -target_link_libraries(EditorApp PRIVATE SDL2::SDL2) +target_link_libraries(EditorApp PRIVATE SDL2::SDL2 SDL2::SDL2main) add_custom_command(TARGET EditorApp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy -t $ $ @@ -29,23 +29,65 @@ add_custom_command(TARGET EditorApp POST_BUILD source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SRC} ${HEADERS}) +add_custom_command( + TARGET EditorApp +POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/engine/audio/Debug/Audio.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/Audio.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/engine/ecs/Debug/EntityComponentSystem.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/EntityComponentSystem.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/engine/input/Debug/Input.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/Input.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/engine/rendering/Debug/Rendering.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/Rendering.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/editor/assetpipeline/Debug/AssetPipeline.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/AssetPipeline.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/engine/io/Debug/IO.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/IO.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/engine/imgui/Debug/ImGui.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/ImGui.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/core/engine/logger/Debug/Logger.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/Logger.dll +) + +add_custom_command( + TARGET EditorApp + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy -t $ $ + COMMAND_EXPAND_LISTS +) + add_custom_command( TARGET EditorApp POST_BUILD - COMMAND swift build -Xlinker ${CMAKE_BINARY_DIR}/engine/assetpackages/debug/AssetPackages.lib - -Xlinker ${CMAKE_BINARY_DIR}/engine/audio/debug/Audio.lib - -Xlinker ${CMAKE_BINARY_DIR}/engine/core/debug/Core.lib - -Xlinker ${CMAKE_BINARY_DIR}/engine/ecs/debug/EntityComponentSystem.lib - -Xlinker ${CMAKE_BINARY_DIR}/engine/input/debug/Input.lib - -Xlinker ${CMAKE_BINARY_DIR}/engine/rendering/debug/Rendering.lib - -Xlinker ${CMAKE_BINARY_DIR}/editor/core/debug/EditorCore.lib - -Xlinker ${CMAKE_BINARY_DIR}/editor/assetpipeline/debug/AssetPipeline.lib + COMMAND swift build + -Xlinker ${CMAKE_BINARY_DIR}/core/engine/audio/Debug/Audio.lib + -Xlinker ${CMAKE_BINARY_DIR}/core/engine/ecs/Debug/EntityComponentSystem.lib + -Xlinker ${CMAKE_BINARY_DIR}/core/engine/input/Debug/Input.lib + -Xlinker ${CMAKE_BINARY_DIR}/core/engine/rendering/Debug/Rendering.lib + -Xlinker ${CMAKE_BINARY_DIR}/core/editor/assetpipeline/Debug/AssetPipeline.lib + -Xlinker ${CMAKE_BINARY_DIR}/core/engine/io/Debug/IO.lib + -Xlinker ${CMAKE_BINARY_DIR}/core/engine/imgui/Debug/ImGui.lib --static-swift-stdlib -COMMENT "Running swift build with custom flags..." + COMMENT "Running swift build with custom flags..." COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/.build/debug/KyaniteEditor.dll - $/KyaniteEditor.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/KyaniteEditor.dll COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/.build/debug/KyaniteEngine.dll - $/KyaniteEngine.dll + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/KyaniteEngine.dll +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_SOURCE_DIR}/.build/debug/KyaniteEngine.lib + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/KyaniteEngine.lib +COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_SOURCE_DIR}/.build/debug/KyaniteEditor.lib + ${CMAKE_BINARY_DIR}/core/editor/app/Debug/KyaniteEditor.lib ) \ No newline at end of file diff --git a/core/editor/app/src/app/App.cxx b/core/editor/app/src/app/App.cxx index e7d4e03..6297fb3 100644 --- a/core/editor/app/src/app/App.cxx +++ b/core/editor/app/src/app/App.cxx @@ -1,5 +1,7 @@ #include "app/App.hxx" +#include + #include #include #include @@ -9,8 +11,18 @@ // NOTE: These functions come from the Swift libraries. They are *not* unused extern "C" void kyanitemain(bool); -extern "C" void kyaniteeditormain(); +extern "C" void kyaniteeditormain(void* window); int main(int argc, char** argv) { - kyaniteeditormain(); + auto window = SDL_CreateWindow( + "Kyanite", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 800, + 600, + SDL_WINDOW_OPENGL + ); + kyaniteeditormain(window); + + return 0; } \ No newline at end of file diff --git a/scripting/editor/KyaniteEditor.swift b/scripting/editor/KyaniteEditor.swift index 56b6aed..e528f4b 100644 --- a/scripting/editor/KyaniteEditor.swift +++ b/scripting/editor/KyaniteEditor.swift @@ -3,12 +3,10 @@ import Foundation import KyaniteEngine @_cdecl("kyaniteeditormain") -public func kyaniteeditormain() { - let engineThread = Thread { - let engine = Engine(isDebug: true) - engine.start() - }.start() - +public func kyaniteeditormain(window: UnsafeMutableRawPointer?) { + let engine = Engine(window: window, isDebug: true) + let editor = Editor() editor.start() + engine.start() } diff --git a/scripting/engine/Engine.swift b/scripting/engine/Engine.swift index 3a18418..00923c4 100644 --- a/scripting/engine/Engine.swift +++ b/scripting/engine/Engine.swift @@ -2,10 +2,9 @@ import Foundation import Native public class Engine { - private var window: NativeWindow? = nil var time: Float = 0 - public init(isDebug: Bool = false) { + public init(window: UnsafeMutableRawPointer?, isDebug: Bool = false) { // Initialize all subsystems // Initialize the core var imGui = NativeImGui.shared.createContext() @@ -14,7 +13,7 @@ public class Engine { NativeAudio.shared.start() NativeInput.shared.start(imGui: imGui) NativeECS.shared.start(debug: isDebug) - guard let window = window else { + guard let window else { fatalError("Failed to create window") } NativeRendering.shared.start(window: window, imGui: imGui) diff --git a/scripting/engine/Kyanite.swift b/scripting/engine/Kyanite.swift index cdfdf67..4abc2a0 100644 --- a/scripting/engine/Kyanite.swift +++ b/scripting/engine/Kyanite.swift @@ -3,8 +3,8 @@ import Macros @_cdecl("kyanitemain") -public func kyanitemain(isDebug: Bool = false) { - let engine = Engine(isDebug: isDebug) +public func kyanitemain(window: UnsafeMutableRawPointer, isDebug: Bool = false) { + let engine = Engine(window: window, isDebug: isDebug) engine.start() } diff --git a/scripting/native/rendering/NativeRendering.swift b/scripting/native/rendering/NativeRendering.swift index 2dc07b4..bc70767 100644 --- a/scripting/native/rendering/NativeRendering.swift +++ b/scripting/native/rendering/NativeRendering.swift @@ -9,8 +9,8 @@ public class NativeRendering { Rendering_Shutdown() } - public func start(window: NativeWindow, imGui: UnsafeMutableRawPointer) { - Rendering_Init(window.handle, imGui) + public func start(window: UnsafeMutableRawPointer, imGui: UnsafeMutableRawPointer) { + Rendering_Init(window, imGui) } public func preFrame() {