From 00b1d972857a11b3695e3804ab5f9cbe6b64d2a2 Mon Sep 17 00:00:00 2001 From: Kearwood Kip Gilbert Date: Sat, 20 Jul 2019 13:55:16 -0700 Subject: [PATCH] Add CMake scripts for collecting assets, switch to Vulkan inspired public api --- CMakeLists.txt | 16 +++++++ kraken/CMakeLists.txt | 2 +- kraken/Context.cpp | 61 ------------------------ kraken/kraken.cpp | 35 ++++++++++++++ kraken/kraken.h | 19 -------- kraken/public/CMakeLists.txt | 1 - kraken/public/kraken.h | 30 ++++++++++++ kraken_standard_assets/CMakeLists.txt | 2 + tools/convert/main.cpp | 67 ++++++++++++++++++--------- 9 files changed, 130 insertions(+), 103 deletions(-) delete mode 100644 kraken/Context.cpp create mode 100644 kraken/kraken.cpp delete mode 100755 kraken/kraken.h create mode 100644 kraken_standard_assets/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index e01db23..e8742d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,21 @@ macro (add_sources) endif() endmacro() +macro (add_standard_asset) + file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + foreach (_src ${ARGN}) + if (_relPath) + list (APPEND KRAKEN_STANDARD_ASSETS "${_relPath}/${_src}") + else() + list (APPEND KRAKEN_STANDARD_ASSETS "${_src}") + endif() + endforeach() + if (_relPath) + # propagate KRAKEN_STANDARD_ASSETS to parent directory + set (KRAKEN_STANDARD_ASSETS ${KRAKEN_STANDARD_ASSETS} PARENT_SCOPE) + endif() +endmacro() + macro (add_public_header) file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") foreach (_src ${ARGN}) @@ -158,5 +173,6 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG) DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/export/lib/win) ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG) +add_subdirectory(kraken_standard_assets) add_subdirectory(tests) add_subdirectory(tools) diff --git a/kraken/CMakeLists.txt b/kraken/CMakeLists.txt index 0babb84..78ba67f 100644 --- a/kraken/CMakeLists.txt +++ b/kraken/CMakeLists.txt @@ -3,7 +3,7 @@ add_subdirectory(public) set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE) # Private Implementation -add_sources(context.cpp) +add_sources(kraken.cpp) add_sources(KRAmbientZone.cpp) add_sources(KRAnimation.cpp) add_sources(KRAnimationAttribute.cpp) diff --git a/kraken/Context.cpp b/kraken/Context.cpp deleted file mode 100644 index 3fa985a..0000000 --- a/kraken/Context.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "public/context.h" - -#include "KRContext.h" - -namespace kraken { - -Context* sContext = nullptr; - -class Context::impl -{ -public: - impl(); - ~impl(); - bool loadResource(const char* szPath); - -private: - KRContext mContext; -}; - -/* static */ -Context* Context::Get() -{ - if (!sContext) { - sContext = new Context(); - } - return sContext; -} - -Context::Context() -{ - mImpl = new impl(); -} - -Context::~Context() -{ - delete mImpl; -} - -bool Context::loadResource(const char* szPath) -{ - return mImpl->loadResource(szPath); -} - -bool Context::impl::loadResource(const char* szPath) -{ - mContext.loadResource(szPath); - // TODO: update KRContext::loadResource to return success/fail boolean - return true; -} - -Context::impl::impl() -{ - -} - -Context::impl::~impl() -{ - -} - -}; // namespace kraken diff --git a/kraken/kraken.cpp b/kraken/kraken.cpp new file mode 100644 index 0000000..268b1c1 --- /dev/null +++ b/kraken/kraken.cpp @@ -0,0 +1,35 @@ +#include "public/kraken.h" + +#include "KRContext.h" + +namespace { + +KRContext* sContext = nullptr; + +}; // anonysmous namespace + +KrResult KrInitialize(const KrInitializeInfo* pInitializeInfo) +{ + if (!sContext) { + sContext = new KRContext(); + } + return KR_SUCCESS; +} + +KrResult KrShutdown() +{ + if (sContext) { + delete sContext; + sContext = nullptr; + } + return KR_SUCCESS; +} + +KrResult KrLoadResource(const KrLoadResourceInfo* pLoadResourceInfo) +{ + if (!sContext) { + return KR_ERROR_NOT_INITIALIZED; + } + sContext->loadResource(pLoadResourceInfo->pResourcePath); + return KR_SUCCESS; +} diff --git a/kraken/kraken.h b/kraken/kraken.h deleted file mode 100755 index e86ff20..0000000 --- a/kraken/kraken.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// kraken.h -// kraken -// -// Created by Kearwood Gilbert on 2015-11-06. -// Copyright © 2015 Kearwood Software. All rights reserved. -// - -#import - -//! Project version number for kraken. -FOUNDATION_EXPORT double krakenVersionNumber; - -//! Project version string for kraken. -FOUNDATION_EXPORT const unsigned char krakenVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/kraken/public/CMakeLists.txt b/kraken/public/CMakeLists.txt index 7084624..ece9c06 100644 --- a/kraken/public/CMakeLists.txt +++ b/kraken/public/CMakeLists.txt @@ -1,3 +1,2 @@ add_public_header(kraken.h) -add_public_header(context.h) set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE) diff --git a/kraken/public/kraken.h b/kraken/public/kraken.h index 105cf16..78aa7d6 100644 --- a/kraken/public/kraken.h +++ b/kraken/public/kraken.h @@ -33,4 +33,34 @@ #include "context.h" +#define KR_NULL_HANDLE 0 + +typedef enum { + KR_SUCCESS = 0, + KR_ERROR_NOT_INITIALIZED = 1, + KR_ERROR_WRONG_THREAD = 2, + KR_RESULT_MAX_ENUM = 0x7FFFFFFF +} KrResult; + +typedef enum { + KR_STRUCTURE_TYPE_INITIALIZE = 0, + KR_STRUCTURE_TYPE_SHUTDOWN = 1, + KR_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF +} KrStructureType; + +typedef struct { + KrStructureType sType; + void* pNext; +} KrInitializeInfo; + +typedef struct { + KrStructureType sType; + void* pNext; + const char* pResourcePath; +} KrLoadResourceInfo; + +KrResult KrInitialize(const KrInitializeInfo* pInitializeInfo); +KrResult KrShutdown(); +KrResult KrLoadResource(const KrLoadResourceInfo* pLoadResourceInfo); + #endif // KRAKEN_H diff --git a/kraken_standard_assets/CMakeLists.txt b/kraken_standard_assets/CMakeLists.txt new file mode 100644 index 0000000..d04e585 --- /dev/null +++ b/kraken_standard_assets/CMakeLists.txt @@ -0,0 +1,2 @@ +set(KRAKEN_STANDARD_ASSETS "${KRAKEN_STANDARD_ASSETS}" PARENT_SCOPE) +add_standard_asset(hrtf_kemar.krbundle) \ No newline at end of file diff --git a/tools/convert/main.cpp b/tools/convert/main.cpp index 21f5600..82525b7 100644 --- a/tools/convert/main.cpp +++ b/tools/convert/main.cpp @@ -1,21 +1,46 @@ -#include "main.h" - -#include -#include "kraken.h" - -using namespace kraken; - -int main( int argc, char *argv[] ) -{ - Context* context = Context::Get(); - - for (int i = 0; i < argc; i++) { - char *arg = argv[i]; - if (arg[0] != '-') { - context->loadResource(arg); - } - } - - printf("Kraken Convert\n"); - return 0; -} +#include "main.h" + +#include +#include "kraken.h" + +using namespace kraken; + +int main( int argc, char *argv[] ) +{ + printf("Kraken Convert\n"); + printf("Initializing Kraken...\n"); + KrInitializeInfo init_info = {}; + init_info.sType = KR_STRUCTURE_TYPE_INITIALIZE; + init_info.pNext = NULL; + KrResult res = KrInitialize(&init_info); + if (res != KR_SUCCESS) { + printf("Failed to initialize Kraken!\n"); + return 1; + } + + KrLoadResourceInfo load_resource_info = {}; + + for (int i = 0; i < argc; i++) { + char *arg = argv[i]; + if (arg[0] != '-') { + load_resource_info.pResourcePath = arg; + res = KrLoadResource(&load_resource_info); + if (res != KR_SUCCESS) { + printf("Failed to load resource: %s\n", arg); + } + } + } + + KrShutdown(); +/* + Context* context = Context::Get(); + + for (int i = 0; i < argc; i++) { + char *arg = argv[i]; + if (arg[0] != '-') { + context->loadResource(arg); + } + } +*/ + return 0; +}