Skip to content

Commit

Permalink
Some fixes to engien to editor mappings. Still WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
broken-bytes committed Feb 6, 2024
1 parent c65f805 commit fd1b9fe
Show file tree
Hide file tree
Showing 57 changed files with 1,119 additions and 174 deletions.
39 changes: 28 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ let package = Package(
name: "scripting",
platforms: [.macOS(.v13), .iOS(.v17), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
products: [
.executable(
.library(
name: "KyaniteEngine",
type: .dynamic,
targets: ["KyaniteEngine"]
),
.library(
name: "KyaniteEditor",
type: .dynamic,
targets: ["KyaniteEditor"]
)
],
dependencies: [
// Depend on the Swift 5.9 release of SwiftSyntax
Expand All @@ -29,17 +35,28 @@ let package = Package(
],
path: "scripting/macros"
),

// Library that exposes a macro as part of its API, which is used in client programs.
// For now this is an executable target, but it will be a library target in the future.
.executableTarget(

.target(
name: "KyaniteEngine",
dependencies: ["Macros"],
path: "scripting/engine",
swiftSettings: [
.unsafeFlags(["-import-objc-header", "./scripting/Bridging_Header.h"]),
.unsafeFlags(["-I", "./engine/shared/include"]),
]
dependencies: ["Macros", "Native"],
path: "scripting/engine"
),

.target(
name: "KyaniteEditor",
dependencies: ["KyaniteEngine"],
path: "scripting/editor"
),

.target(
name: "Bridge",
path: "scripting/bridge"
),

.target(
name: "Native",
dependencies: ["Bridge"],
path: "scripting/native"
)
]
)
2 changes: 2 additions & 0 deletions editor/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ target_include_directories(EditorApp PRIVATE ${CMAKE_SOURCE_DIR}/engine/shared/i
target_include_directories(EditorApp PRIVATE ${CMAKE_SOURCE_DIR}/engine/core/include)
target_include_directories(EditorApp PRIVATE ${CMAKE_SOURCE_DIR}/engine/rendering/include)

target_link_directories(EditorApp PRIVATE ${CMAKE_SOURCE_DIR}/.build/debug)

target_link_libraries(EditorApp PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Concurrent unofficial::sqlite3::sqlite3 assimp::assimp)

# Link all engine libraries
Expand Down
3 changes: 3 additions & 0 deletions editor/app/src/app/App.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <memory>
#include <sstream>

#pragma comment(lib, "KyaniteEngine.lib")
#pragma comment(lib, "KyaniteEditor.lib")

namespace assetpackages = kyanite::engine::assetpackages;
namespace editor = kyanite::editor;

Expand Down
9 changes: 9 additions & 0 deletions editor/app/src/editor/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include <filesystem>
#include <sstream>

// NOTE: These functions come from the Swift libraries. They are *not* unused
extern "C" void kyanitemain();
extern "C" void kyaniteeditormain();

std::thread engineThread;

namespace kyanite::editor {
Editor::Editor(
std::string projectPath,
Expand Down Expand Up @@ -58,6 +64,9 @@ namespace kyanite::editor {
}

auto Editor::InitializeEngine() -> void {
// Start the engine in a separate thread so it does not interfere with the editor
engineThread = std::thread([&]() { kyanitemain(); });
kyaniteeditormain();
_assetDatabase->Load(_service->CachePath());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C" {
* @param path The path to the asset package
* @return The asset package
*/
EXPORTED NativePointer AssetPackages_LoadAssetPackages(const char* path, size_t* numPackages);
EXPORTED void AssetPackages_LoadAssetPackages(const char* path, NativePointer* buffer, size_t* numPackages);

/**
* @brief Loads a texture
Expand Down
10 changes: 2 additions & 8 deletions engine/assetpackages/src/Bridge_AssetPackages.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ void AssetPackages_Initialize(NativePointer loader) {
assetpackages::Initialize(smartLoader);
}

NativePointer AssetPackages_LoadAssetPackages(const char* path, size_t* numPackages) {
void AssetPackages_LoadAssetPackages(const char* path, NativePointer* buffer, size_t* numPackages) {
auto packages = assetpackages::LoadPackageList(path);
*numPackages = packages.size();

assetpackages::AssetPackage** packagesPtr = new assetpackages::AssetPackage*[*numPackages];

for(size_t x = 0; x < *numPackages; x++) {
packagesPtr[x] = packages[x];
}

return reinterpret_cast<NativePointer>(packagesPtr);
*buffer = reinterpret_cast<NativePointer>(packagesPtr);
}

NativePointer AssetPackages_LoadTexture(NativePointer assetPackage, const char* uuid) {
Expand Down
1 change: 1 addition & 0 deletions scripting/bridge/Bridge.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Bridging_Header.h"
67 changes: 67 additions & 0 deletions scripting/bridge/include/Bridge_AssetPackages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma once

#include <shared/Exported.hxx>
#include <shared/NativePointer.hxx>

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initializes the asset packages
* @param loader The loader to use. Creates the engine's internal one if none provided.
*/
EXPORTED void AssetPackages_Initialize(NativePointer loader);

/**
* @brief Loads an asset package
* @param path The path to the asset package
* @return The asset package
*/
EXPORTED void AssetPackages_LoadAssetPackages(const char* path, NativePointer* buffer, size_t* numPackages);

/**
* @brief Loads a texture
* @param uuid The uuid of the texture
* @return The texture
*/
EXPORTED NativePointer AssetPackages_LoadTexture(NativePointer assetPackage, const char* uuid);

/**
* @brief Loads a mesh
* @param uuid The uuid of the mesh
* @return The mesh
*/
EXPORTED NativePointer AssetPackages_LoadMesh(NativePointer assetPackage, const char* uuid);

/**
* @brief Loads a material
* @param uuid The uuid of the material
* @return The material
*/
EXPORTED NativePointer AssetPackages_LoadMaterial(NativePointer assetPackage, const char* uuid);

/**
* @brief Loads a shader
* @param uuid The uuid of the shader
* @return The shader
*/
EXPORTED NativePointer AssetPackages_LoadShader(NativePointer assetPackage, const char* uuid);

/**
* @brief Loads an audioclip
* @param uuid The uuid of the audioclip
* @return The audioclip
*/
EXPORTED NativePointer AssetPackages_LoadAudioClip(NativePointer assetPackage, const char* uuid);

/**
* @brief Clears an asset
* @param asset The asset to clear
*/
EXPORTED void AssetPackages_DisposeAsset(NativePointer asset);

#ifdef __cplusplus
}
#endif
111 changes: 111 additions & 0 deletions scripting/bridge/include/Bridge_Audio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#pragma once

#include <shared/Exported.hxx>
#include <shared/NativePointer.hxx>

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

EXPORTED void Audio_Init();

/**
* @brief Creates an audio device
*
* @return NativePointer
*/
EXPORTED NativePointer Audio_CreateDevice();

/**
* @brief Destroys an audio device
*
* @param device The device to be destroyed
*/
EXPORTED void Audio_DestroyDevice(NativePointer device);

/**
* @brief Creates a new audiosource.
*
* @param x X position of the source
* @param y Y position of the source
* @param z Z position of the source
* @return uint64_t The id of the source
*/
EXPORTED NativePointer Audio_CreateAudioSource(float x, float y, float z);

/**
* @brief Destroys an audiosource via its id
*
* @param source The id of the source
*/
EXPORTED void Audio_DestroyAudioSource(NativePointer source);

/**
* @brief Creates a new audioclip from a given file
*
* @param path The path of the file
* @return uint64_t The id of the clip
*/
EXPORTED NativePointer Audio_CreateAudioClip(const char* path);

/**
* @brief Gets the sample rate of a given clip
*
* @param clip The clip to query
* @return uint32_t
*/
EXPORTED uint32_t Audio_ClipGetSampleRate(NativePointer clip);

/**
* @brief Gets he bitdepth for a given clip
*
* @param clip The clip to be queried
* @return uint32_t
*/
EXPORTED uint32_t Audio_ClipGetBitDepth(NativePointer clip);

/**
* @brief Gets the number of channels for a given clip
*
* @param clip The clip to be queried
* @return uint8_t
*/
EXPORTED uint8_t Audio_ClipGetChannels(NativePointer clip);

/**
* @brief Plays an audio clip via an audiosource
*
* @param source The source to be used
* @param clip The clip to be played
*/
EXPORTED void Audio_AudioSourceSetAudioClip(NativePointer source, NativePointer clip);

/**
* @brief Starts playback of an audiosource
*
* @param source The source
*/
EXPORTED void Audio_AudioSourceStart(NativePointer source);

/**
* @brief Stops playback of an audiosource
*
* @param source The source
*/
EXPORTED void Audio_AudioSourceStop(NativePointer source);

/**
* @brief Toggles looping for the given source
*
* @param source The source
*/
EXPORTED void Audio_AudioSourceSetLooping(NativePointer source, bool looping);


#ifdef __cplusplus
}
#endif
74 changes: 74 additions & 0 deletions scripting/bridge/include/Bridge_Core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once

#include <shared/Exported.hxx>
#include <shared/NativePointer.hxx>

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Initialies the core module
*
*/
EXPORTED void Core_Init();

/**
* @brief Creates a new window
*
* @param title The title of the Window
* @param posX The position horizontal of the window
* @param posY The vertical position of the window
* @param width The width of the window
* @param height The height of the window
* @param flags Flas the window should use
* @param renderBackend The render backend to use for the window (0 = OpenGL, 1 = Vulkan, 2 = D3D12)
* @return uint64_t* Returns a pointer to the window
*/
EXPORTED NativePointer Core_CreateWindow(
const char* title,
uint32_t* posX,
uint32_t* posY,
uint32_t width,
uint32_t height,
uint32_t flags,
uint8_t renderBackend,
bool silent
);

/**
* @brief Creates a new window
*
* @param title The native window
* @return uint64_t* Returns a pointer to the window
*/
EXPORTED NativePointer Core_CreateWindowFromNative(NativePointer nativeWindow);

/**
* @brief Destroys an audiosource via its pointer
*
* @param window The window
*/
EXPORTED void Core_DestroyWindow(NativePointer window);

/**
* @brief Shows the window
*
* @param window The window to be shown
*/
EXPORTED void Core_ShowWindow(NativePointer window);

/**
* @brief Hides the window
*
* @param window The window to be hidden
*/
EXPORTED void Core_HideWindow(NativePointer window);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit fd1b9fe

Please sign in to comment.