Skip to content

Commit

Permalink
fix engine startup
Browse files Browse the repository at this point in the history
  • Loading branch information
broken-bytes committed Mar 8, 2024
1 parent b2f6a58 commit 19aaaa6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 27 deletions.
66 changes: 54 additions & 12 deletions core/editor/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE_DIR:EditorApp> $<TARGET_RUNTIME_DLLS:EditorApp>
Expand All @@ -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 $<TARGET_FILE_DIR:Audio> $<TARGET_RUNTIME_DLLS:EditorApp>
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
$<TARGET_RUNTIME_DLLS:EditorApp>/KyaniteEditor.dll
${CMAKE_BINARY_DIR}/core/editor/app/Debug/KyaniteEditor.dll
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/.build/debug/KyaniteEngine.dll
$<TARGET_RUNTIME_DLLS:EditorApp>/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
)
16 changes: 14 additions & 2 deletions core/editor/app/src/app/App.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "app/App.hxx"

#include <SDL2/SDL.h>

#include <filesystem>
#include <memory>
#include <sstream>
Expand All @@ -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;
}
10 changes: 4 additions & 6 deletions scripting/editor/KyaniteEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
5 changes: 2 additions & 3 deletions scripting/engine/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions scripting/engine/Kyanite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions scripting/native/rendering/NativeRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 19aaaa6

Please sign in to comment.