From f492f6faff3d2e0ccfcaf05698053f1478bd26fa Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Wed, 23 Feb 2022 23:34:55 +0200 Subject: [PATCH 01/16] [android] added build for android, fixed various compile errors related to android platform --- CMakeLists.txt | 46 +- core/CMakeLists.txt | 15 +- core/inc/gfx/types.hpp | 1 + core/inc/systems/input.hpp | 4 +- core/inc/vk/ivk.hpp | 21 +- core/main/CMakeLists.txt | 17 +- .../android_native_app_glue/CMakeLists.txt | 6 + core/main/main.cpp | 416 +----------------- core/src/systems/input_android.cpp | 5 + psl/inc/psl/assertions.hpp | 7 +- psl/inc/psl/details/fixed_astring.hpp | 1 + psl/inc/psl/ecs/details/execution.hpp | 30 ++ psl/inc/psl/ecs/filtering.hpp | 4 +- psl/inc/psl/ecs/pack.hpp | 20 +- psl/inc/psl/ecs/state.hpp | 102 +++-- psl/inc/psl/math/vec.hpp | 10 +- psl/inc/psl/stdafx_psl.hpp | 14 - psl/inc/psl/template_utils.hpp | 2 +- tools/android.py | 106 +++++ .../android/app/build.gradle.template | 39 ++ .../app/src/main/AndroidManifest.xml.template | 33 ++ .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../src/main/res/values/strings.xml.template | 4 + tools/templates/android/build.gradle.template | 21 + .../android/gradle.properties.template | 19 + .../android/settings.gradle.template | 2 + 29 files changed, 421 insertions(+), 524 deletions(-) create mode 100644 core/main/android_native_app_glue/CMakeLists.txt create mode 100644 core/src/systems/input_android.cpp create mode 100644 psl/inc/psl/ecs/details/execution.hpp create mode 100644 tools/android.py create mode 100644 tools/templates/android/app/build.gradle.template create mode 100644 tools/templates/android/app/src/main/AndroidManifest.xml.template create mode 100644 tools/templates/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 tools/templates/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 tools/templates/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 tools/templates/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 tools/templates/android/app/src/main/res/values/strings.xml.template create mode 100644 tools/templates/android/build.gradle.template create mode 100644 tools/templates/android/gradle.properties.template create mode 100644 tools/templates/android/settings.gradle.template diff --git a/CMakeLists.txt b/CMakeLists.txt index bbf92f41..7d5eae33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,6 @@ endif() ############################################################################### ### general options and setup ### ############################################################################### -OPTION(PE_SOURCE_ONLY "set to off to not compile the sub-projects" OFF) OPTION(PE_PROFILER "enables the internal profiler" OFF) OPTION(PE_ANALYZE "enables static analyzers for the given platform" OFF) OPTION(PE_VERBOSE "verbose error checking in the default compile options" OFF) @@ -71,10 +70,13 @@ endif() string(TOUPPER PE_MODE PE_MODE) list(APPEND PE_DEFINES -DPLATFORM_${PE_MODE}) -# experimental early support for not supporting vulkan if(PE_VULKAN) message("enabling VULKAN") list(APPEND PE_DEFINES -DPE_VULKAN) + if(NOT DEFINED VK_VERSION OR VK_VERSION STREQUAL "") + message(FATAL_ERROR ${VK_VERSION}) + message(FATAL_ERROR "requested 'vulkan' backend, but did not set 'VK_VERSION'") + endif() endif() if(PE_MOLTEN) @@ -96,7 +98,7 @@ if(PE_PROFILER) endif() -if(NOT VK_STATIC AND NOT PE_SOURCE_ONLY) +if(NOT VK_STATIC) list(APPEND PE_DEFINES -DVK_NO_PROTOTYPES) elseif(VK_STATIC) list(APPEND PE_DEFINES -DVK_STATIC) @@ -108,6 +110,10 @@ else() list(APPEND PE_DEFINES -DPE_RELEASE) endif() +if(${PE_PLATFORM} STREQUAL ANDROID AND (NOT DEFINED ANDROID_NDK OR ANDROID_NDK STREQUAL "")) + message(FATAL_ERROR "Trying to build 'android' target outside of the gradle context is not supported.") +endif() + ############################################################################### ### validation ### ############################################################################### @@ -252,6 +258,11 @@ endif() set(HAS_WSI FALSE) set(PE_SURFACE "unknown") +if(PE_PLATFORM STREQUAL "ANDROID") + set(HAS_WSI TRUE) + set(PE_SURFACE "ANDROID") + list(APPEND PE_DEFINES -DSURFACE_ANDROID;-DVK_USE_PLATFORM_ANDROID_KHR) +endif() if(NOT HAS_WSI AND PE_WSI_D2D) list(APPEND PE_DEFINES -DSURFACE_D2D) message("using D2D WSI") @@ -283,22 +294,19 @@ string(TOLOWER ${PE_SURFACE} PE_SURFACE_LOWERCASE) add_definitions(${PE_DEFINES}) -if(NOT PE_SOURCE_ONLY) - add_subdirectory(extern) +add_subdirectory(extern) - add_subdirectory(psl) - add_subdirectory(core) - if(PE_TESTS) - add_subdirectory(tests) - endif() - - if(PE_BENCHMARKS) - add_subdirectory(benchmarks) - endif() +add_subdirectory(psl) +add_subdirectory(core) +if(PE_TESTS) + add_subdirectory(tests) +endif() - if(EXISTS "${PROJECT_SOURCE_DIR}/modules.txt") - include(${PROJECT_SOURCE_DIR}/modules.txt) - endif() -else() - message("did not compile the project by request") +if(PE_BENCHMARKS) + add_subdirectory(benchmarks) +endif() + + +if(EXISTS "${PROJECT_SOURCE_DIR}/modules.txt") + include(${PROJECT_SOURCE_DIR}/modules.txt) endif() diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index de099208..4c636666 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -11,14 +11,14 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) SET(Python_ADDITIONAL_VERSIONS 3 3.6 3.5 3.4 3.3 3.2 3.1 3.0) find_package(PythonInterp REQUIRED) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC}) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${GEN}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${GEN}) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc/fwd" PREFIX "fwd" FILES ${FWD}) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC}) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_GLES}) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_GLES}) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_VULKAN}) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_VULKAN}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_GLES}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_GLES}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PREFIX "inc" FILES ${INC_VULKAN}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_VULKAN}) if(VS_USE_NATVIS) file(GLOB_RECURSE NATVIS nvs/*.natvis) @@ -126,6 +126,7 @@ target_include_directories(${LOCAL_PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc ${vulkan_SOURCE_DIR}/include + $,${ANDROID_NDK}/sources/android/native_app_glue,> PRIVATE ${WSI_INC} ) diff --git a/core/inc/gfx/types.hpp b/core/inc/gfx/types.hpp index 1bed0635..8e88c543 100644 --- a/core/inc/gfx/types.hpp +++ b/core/inc/gfx/types.hpp @@ -5,6 +5,7 @@ #include "psl/ustring.hpp" #include #include +#include namespace core::gfx { diff --git a/core/inc/systems/input.hpp b/core/inc/systems/input.hpp index 600b5522..c28080f6 100644 --- a/core/inc/systems/input.hpp +++ b/core/inc/systems/input.hpp @@ -656,8 +656,8 @@ namespace core::systems void handle_event(core::os::surface* const surface, const xcb_generic_event_t* event, xcb_intern_atom_reply_t& delete_wm); -#elif defined(SURFACE_D2D) - +#elif defined(SURFACE_ANDROID) + void tick(); #endif mouse_coordinate m_Cursor; common::event m_OnKeyPressed; diff --git a/core/inc/vk/ivk.hpp b/core/inc/vk/ivk.hpp index 4642326c..5165045f 100644 --- a/core/inc/vk/ivk.hpp +++ b/core/inc/vk/ivk.hpp @@ -4,17 +4,20 @@ #define VULKAN_HPP_NO_EXCEPTIONS -#if defined(SURFACE_XCB) -#ifndef VK_USE_PLATFORM_XCB_KHR -#define VK_USE_PLATFORM_XCB_KHR -#endif -#define VK_SURFACE_EXTENSION_NAME VK_KHR_XCB_SURFACE_EXTENSION_NAME +#if defined(SURFACE_ANDROID) + #if !defined(VK_USE_PLATFORM_ANDROID_KHR) + #define VK_USE_PLATFORM_ANDROID_KHR + #endif + #define VK_SURFACE_EXTENSION_NAME VK_KHR_ANDROID_SURFACE_EXTENSION_NAME +#elif defined(SURFACE_XCB) + #ifndef VK_USE_PLATFORM_XCB_KHR + #define VK_USE_PLATFORM_XCB_KHR + #endif + #define VK_SURFACE_EXTENSION_NAME VK_KHR_XCB_SURFACE_EXTENSION_NAME #elif defined(SURFACE_D2D) -#define VK_SURFACE_EXTENSION_NAME VK_KHR_DISPLAY_EXTENSION_NAME -#elif defined(VK_USE_PLATFORM_ANDROID_KHR) -#define VK_SURFACE_EXTENSION_NAME VK_KHR_ANDROID_SURFACE_EXTENSION_NAME + #define VK_SURFACE_EXTENSION_NAME VK_KHR_DISPLAY_EXTENSION_NAME #elif defined(SURFACE_WIN32) -#define VK_SURFACE_EXTENSION_NAME VK_KHR_WIN32_SURFACE_EXTENSION_NAME + #define VK_SURFACE_EXTENSION_NAME VK_KHR_WIN32_SURFACE_EXTENSION_NAME #endif #define VK_VERSION_LATEST_MAJOR 1 diff --git a/core/main/CMakeLists.txt b/core/main/CMakeLists.txt index f0fe51cc..ec4ff46f 100644 --- a/core/main/CMakeLists.txt +++ b/core/main/CMakeLists.txt @@ -4,10 +4,21 @@ set(LOCAL_PROJECT ${PROJECT_MAIN}) project(${LOCAL_PROJECT} VERSION 1.0.0 LANGUAGES CXX) add_definitions(${PE_DEFINES}) -add_executable(${LOCAL_PROJECT} main.cpp) -target_link_libraries(${LOCAL_PROJECT} PUBLIC - ${PROJECT_PSL} ${PE_DL_LIBS} ${PROJECT_CORE}) +if(PE_PLATFORM STREQUAL "ANDROID") + add_subdirectory(android_native_app_glue) + add_library(${LOCAL_PROJECT} SHARED main.cpp) + + target_link_options(${LOCAL_PROJECT} PRIVATE "-u ANativeActivity_onCreate") + target_include_directories(${LOCAL_PROJECT} PUBLIC ${ANDROID_NDK}/sources/android/native_app_glue) + + target_link_libraries(${LOCAL_PROJECT} PUBLIC ${PROJECT_PSL} ${PROJECT_CORE} ${PE_DL_LIBS} PRIVATE android ${PROJECT_ANDROID_NATIVE_GLUE} EGL GLESv1_CM log) +else() + add_executable(${LOCAL_PROJECT} main.cpp) + + target_link_libraries(${LOCAL_PROJECT} PUBLIC + ${PROJECT_PSL} ${PE_DL_LIBS} ${PROJECT_CORE}) +endif() target_compile_features(${LOCAL_PROJECT} PUBLIC ${PE_COMPILER_FEATURES}) target_compile_options(${LOCAL_PROJECT} PRIVATE ${PE_COMPILE_OPTIONS} ${PE_COMPILE_OPTIONS_EXE}) diff --git a/core/main/android_native_app_glue/CMakeLists.txt b/core/main/android_native_app_glue/CMakeLists.txt new file mode 100644 index 00000000..84dcb799 --- /dev/null +++ b/core/main/android_native_app_glue/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.11) +set(PROJECT_ANDROID_NATIVE_GLUE android_native_glue CACHE INTERNAL "") +set(LOCAL_PROJECT ${PROJECT_ANDROID_NATIVE_GLUE}) +project(${LOCAL_PROJECT} VERSION 1.0.0 LANGUAGES C) + +add_library(${LOCAL_PROJECT} STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) diff --git a/core/main/main.cpp b/core/main/main.cpp index 3b5d6932..da36f30e 100755 --- a/core/main/main.cpp +++ b/core/main/main.cpp @@ -75,6 +75,9 @@ #include "data/framebuffer.hpp" +#if defined(PLATFORM_ANDROID) +#include +#endif using namespace core; using namespace core::resource; using namespace core::gfx; @@ -313,409 +316,6 @@ void setup_loggers() #endif -#if defined(MULTI_CONTEXT_RENDERING) -#include -#include -namespace core::systems -{ - class renderer_view; - - class renderer - { - public: - explicit renderer(cache* cache) : m_Cache(cache), deviceIndex(0) {} - ~renderer(); - renderer(renderer&& other) = delete; - renderer& operator=(renderer&& other) = delete; - renderer(const renderer& other) = delete; - renderer& operator=(const renderer& other) = delete; - - void start() { m_Thread = std::thread(&core::systems::renderer::main, this); } - void lock() { mutex.lock(); } - void unlock() { mutex.unlock(); } - - core::systems::renderer_view& create_view(handle surface); - cache& get_cache() { return *m_Cache; } - - const std::vector& views() { return m_Views; } - - void close(renderer_view* view); - - private: - void main(); - std::shared_mutex mutex; - uint32_t deviceIndex = 0u; - cache* m_Cache; - handle m_Context; - std::thread m_Thread; - std::atomic m_ForceClose {false}; - std::atomic m_Closeable {false}; - std::vector m_Views; - }; - class renderer_view - { - friend class renderer; - - public: - renderer_view(renderer* renderer, handle surface, handle context) : - m_Renderer(renderer), m_Surface(surface), m_Context(context), m_Swapchain(create_swapchain()), - m_Pass(m_Context, m_Swapchain) - {} - ~renderer_view() { m_Surface.unload(true); }; - handle& current_surface() { return m_Surface; } - - private: - handle create_swapchain() - { - auto swapchain_handle = create(m_Renderer->get_cache()); - swapchain_handle.load(m_Surface, m_Context); - return swapchain_handle; - } - void present() - { - if(m_Surface->open()) m_Pass.present(); - } - renderer* m_Renderer; - handle m_Surface; - handle m_Context; - handle m_Swapchain; - pass m_Pass; - }; - - renderer::~renderer() - { - m_ForceClose = true; - while(!m_Closeable) - {} - if(m_Thread.joinable()) - { - m_Thread.join(); - } - for(auto& view : m_Views) delete(view); - m_Context.unload(); - if(m_Cache) delete(m_Cache); - } - void renderer::main() - { - // Utility::OS::RegisterThisThread("RenderThread " + ss.str()); - while(!m_ForceClose) - { - mutex.lock(); - { - for(auto& view : m_Views) - { - auto& surf = view->current_surface(); - if(surf->open()) view->present(); - } - } - mutex.unlock(); - } - - m_Closeable = true; - } - - renderer_view& renderer::create_view(handle surface) - { - mutex.lock(); - m_Context = create(*m_Cache); - if(!m_Context.load(APPLICATION_FULL_NAME, deviceIndex)) - { - throw std::runtime_error("no vulkan context could be created"); - } - - auto& view = *m_Views.emplace_back(new renderer_view(this, surface, m_Context)); - mutex.unlock(); - return view; - } - - void renderer::close(renderer_view* view) - { - auto it = std::find(std::begin(m_Views), std::end(m_Views), view); - if(it == std::end(m_Views)) return; - mutex.lock(); - delete(*it); - m_Views.erase(it); - mutex.unlock(); - } -} // namespace core::systems - -core::systems::renderer* init(size_t views = 1) -{ - psl::string libraryPath {utility::application::path::library + "resources.metalib"}; - - memory::region resource_region {1024u * 1024u * 20u, 4u, new memory::default_allocator()}; - cache cache {psl::meta::library {psl::to_string8_t(libraryPath)}, resource_region.allocator()}; - - auto window_data = create_shared(cache, "cd61ad53-5ac8-41e9-a8a2-1d20b43376d9"_uid); - window_data.load(); - - auto rend = new core::systems::renderer {&cache}; - for(auto i = 0u; i < views; ++i) - { - auto window_handle = create(cache); - if(!window_handle.load(window_data)) - { - // LOG_FATAL << "Could not create a OS surface to draw on."; - throw std::runtime_error("no OS surface could be created"); - } - rend->create_view(window_handle); - } - rend->start(); - return rend; -} - -int main() -{ -#ifdef PLATFORM_WINDOWS - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); -#endif - setup_loggers(); - // Utility::OS::RegisterThisThread("Main"); - - std::vector renderers; - { - renderers.push_back(init(4u)); - } - uint64_t frameCount = 0u; - while(renderers.size() > 0) - { - for(auto i = 0u; i < renderers.size(); i) - { - renderers[i]->lock(); - for(auto& view : renderers[i]->views()) - { - auto& surf = view->current_surface(); - if(surf->open()) - surf->tick(); - else - { - renderers[i]->close(view); - break; - } - } - if(renderers[i]->views().size() == 0) - { - delete(renderers[i]); - renderers.erase(std::begin(renderers) + i); - } - else - { - ++i; - } - renderers[i]->unlock(); - } - ++frameCount; - } - return 0; -} -#elif defined(DEDICATED_GRAPHICS_THREAD) - -static void render_thread(handle context, handle swapchain, handle surface, pass* pass) -{ - try - { - while(surface->open() && swapchain->is_ready()) - { - pass->prepare(); - pass->present(); - } - } - catch(...) - { - core::gfx::log->critical("critical issue happened in rendering thread"); - } -} -int main() -{ - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); - _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); - - setup_loggers(); - - psl::string libraryPath {utility::application::path::library + "resources.metalib"}; - - memory::region resource_region {1024u * 1024u * 20u, 4u, new memory::default_allocator()}; - cache cache {psl::meta::library {psl::to_string8_t(libraryPath)}, resource_region.allocator()}; - - auto window_data = create(cache, "cd61ad53-5ac8-41e9-a8a2-1d20b43376d9"_uid); - window_data.load(); - - auto window_handle = create(cache); - if(!window_handle.load(window_data)) - { - core::log->critical("could not create a OS surface to draw on."); - return -1; - } - - - auto context_handle = create(cache); - if(!context_handle.load(APPLICATION_FULL_NAME)) - { - core::log->critical("could not create graphics API surface to use for drawing."); - return -1; - } - - auto swapchain_handle = create(cache); - swapchain_handle.load(window_handle, context_handle); - window_handle->register_swapchain(swapchain_handle); - pass pass {context_handle, swapchain_handle}; - - std::thread tr {&render_thread, context_handle, swapchain_handle, window_handle, &pass}; - - - uint64_t frameCount = 0u; - while(window_handle->tick()) - { - ++frameCount; - } - - tr.join(); - - return 0; -} -#else - - -#if defined(PLATFORM_ANDROID) -bool focused {true}; -int android_entry() -{ - setup_loggers(); - psl::string libraryPath {utility::application::path::library + "resources.metalib"}; - - memory::region resource_region {1024u * 1024u * 20u, 4u, new memory::default_allocator()}; - cache cache {psl::meta::library {psl::to_string8_t(libraryPath)}, resource_region.allocator()}; - - auto window_data = create(cache, UID::convert("cd61ad53-5ac8-41e9-a8a2-1d20b43376d9")); - window_data.load(); - - auto surface_handle = create(cache); - if(!surface_handle.load(window_data)) - { - core::log->critical("Could not create a OS surface to draw on."); - return -1; - } - - auto context_handle = create(cache); - if(!context_handle.load(APPLICATION_FULL_NAME, 0)) - { - core::log->critical("Could not create graphics API surface to use for drawing."); - return -1; - } - - auto swapchain_handle = create(cache); - swapchain_handle.load(surface_handle, context_handle); - surface_handle->register_swapchain(swapchain_handle); - context_handle->device().waitIdle(); - pass pass {context_handle, swapchain_handle}; - pass.build(); - uint64_t frameCount = 0u; - std::chrono::high_resolution_clock::time_point last_tick = std::chrono::high_resolution_clock::now(); - - int ident; - int events; - struct android_poll_source* source; - bool destroy = false; - focused = true; - - while(true) - { - while((ident = ALooper_pollAll(focused ? 0 : -1, NULL, &events, (void**)&source)) >= 0) - { - if(source != NULL) - { - source->process(platform::specifics::android_application, source); - } - if(platform::specifics::android_application->destroyRequested != 0) - { - destroy = true; - break; - } - } - - if(destroy) - { - ANativeActivity_finish(platform::specifics::android_application->activity); - break; - } - - if(swapchain_handle->is_ready()) - { - pass.prepare(); - pass.present(); - } - auto current_time = std::chrono::high_resolution_clock::now(); - std::chrono::duration elapsed = - std::chrono::duration_cast>(current_time - last_tick); - last_tick = current_time; - ++frameCount; - - if(frameCount % 60 == 0) - { - swapchain_handle->clear_color( - vk::ClearColorValue {std::array {(float)(std::rand() % 255) / 255.0f, - (float)(std::rand() % 255) / 255.0f, - (float)(std::rand() % 255) / 255.0f, - 1.0f}}); - pass.build(); - } - } - - return 0; -} - - -#endif - -#if defined(PLATFORM_ANDROID) -static bool initialized = false; - -// todo deal with this extern -android_app* platform::specifics::android_application; - -void handleAppCommand(android_app* app, int32_t cmd) -{ - switch(cmd) - { - case APP_CMD_INIT_WINDOW: - initialized = true; - break; - } -} - -int32_t handleAppInput(struct android_app* app, AInputEvent* event) {} - -void android_main(android_app* application) -{ - application->onAppCmd = handleAppCommand; - // Screen density - AConfiguration* config = AConfiguration_new(); - AConfiguration_fromAssetManager(config, application->activity->assetManager); - // vks::android::screenDensity = AConfiguration_getDensity(config); - AConfiguration_delete(config); - - while(!initialized) - { - int ident; - int events; - struct android_poll_source* source; - bool destroy = false; - - while((ident = ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) - { - if(source != NULL) - { - source->process(application, source); - } - } - } - - platform::specifics::android_application = application; - android_entry(); -} -#elif defined(PLATFORM_WINDOWS) || defined(PLATFORM_LINUX) - int entry(gfx::graphics_backend backend) { psl::string libraryPath {utility::application::path::library + "resources.metalib"}; @@ -1330,6 +930,14 @@ ECSState.create( return 0; } +#if defined(PLATFORM_ANDROID) + +void android_main(struct android_app* application) +{ + return; +} + +#else int main(int argc, char* argv[]) { #ifdef PLATFORM_WINDOWS @@ -1381,5 +989,3 @@ int main(int argc, char* argv[]) return entry(backend); } #endif - -#endif \ No newline at end of file diff --git a/core/src/systems/input_android.cpp b/core/src/systems/input_android.cpp new file mode 100644 index 00000000..3149d5af --- /dev/null +++ b/core/src/systems/input_android.cpp @@ -0,0 +1,5 @@ +#include "systems/input.hpp" + +void core::systems::input::tick() +{ +} \ No newline at end of file diff --git a/psl/inc/psl/assertions.hpp b/psl/inc/psl/assertions.hpp index b982cb10..0f72f13f 100644 --- a/psl/inc/psl/assertions.hpp +++ b/psl/inc/psl/assertions.hpp @@ -80,12 +80,9 @@ DBG__FUNCTION void debug_break(void) { __asm__ __volatile__("bpt"); } #ifdef assert #undef assert #ifdef PE_DEBUG - -#define assert(expression, ...) ((void)0) - +#define assert(expression, ...) if(!(expression)) { debug_break(); } #else - -#define assert(expression, ...) (void)((!!(expression)) || (debug_break(), 0)) +#define assert(expression, ...) ((void)0) #endif #endif diff --git a/psl/inc/psl/details/fixed_astring.hpp b/psl/inc/psl/details/fixed_astring.hpp index 139d747b..55076599 100644 --- a/psl/inc/psl/details/fixed_astring.hpp +++ b/psl/inc/psl/details/fixed_astring.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include namespace psl diff --git a/psl/inc/psl/ecs/details/execution.hpp b/psl/inc/psl/ecs/details/execution.hpp new file mode 100644 index 00000000..53d7b771 --- /dev/null +++ b/psl/inc/psl/ecs/details/execution.hpp @@ -0,0 +1,30 @@ +#pragma once + +#if !defined(PLATFORM_ANDROID) +#include +namespace psl::ecs::execution { + struct no_exec{}; + using sequenced_policy = std::execution::sequenced_policy; + using parallel_policy = std::execution::parallel_policy; + using parallel_unsequenced_policy = std::execution::parallel_unsequenced_policy; + using unsequenced_policy = std::execution::unsequenced_policy; + + inline constexpr sequenced_policy seq{}; + inline constexpr parallel_policy par{}; + inline constexpr parallel_unsequenced_policy par_unseq{}; + inline constexpr unsequenced_policy unseq{}; +} +#else +namespace psl::ecs::execution { + struct no_exec{}; + struct sequenced_policy{}; + struct parallel_policy{}; + struct parallel_unsequenced_policy{}; + struct unsequenced_policy{}; + + inline constexpr no_exec seq{}; + inline constexpr no_exec par{}; + inline constexpr no_exec par_unseq{}; + inline constexpr no_exec unseq{}; +} +#endif \ No newline at end of file diff --git a/psl/inc/psl/ecs/filtering.hpp b/psl/inc/psl/ecs/filtering.hpp index 516d2b2f..ab63cd64 100644 --- a/psl/inc/psl/ecs/filtering.hpp +++ b/psl/inc/psl/ecs/filtering.hpp @@ -1,10 +1,10 @@ #pragma once #include "details/component_key.hpp" +#include "details/execution.hpp" #include "psl/array.hpp" #include "psl/ecs/pack.hpp" #include "psl/template_utils.hpp" #include "selectors.hpp" -#include namespace psl::ecs { @@ -28,7 +28,7 @@ namespace psl::ecs constexpr void selector(psl::type_pack_t>) noexcept { order_by = [](psl::array::iterator begin, psl::array::iterator end, const auto& state) { - state.template order_by(std::execution::par, begin, end); + state.template order_by(psl::ecs::execution::par, begin, end); }; } diff --git a/psl/inc/psl/ecs/pack.hpp b/psl/inc/psl/ecs/pack.hpp index cb513fc0..90632897 100644 --- a/psl/inc/psl/ecs/pack.hpp +++ b/psl/inc/psl/ecs/pack.hpp @@ -58,16 +58,16 @@ namespace psl::ecs public: static constexpr bool has_entities {std::disjunction...>::value}; - using pack_t = pack_base::pack_t; - using filter_t = pack_base::filter_t; - using combine_t = pack_base::combine_t; - using break_t = pack_base::break_t; - using add_t = pack_base::add_t; - using remove_t = pack_base::remove_t; - using except_t = pack_base::except_t; - using conditional_t = pack_base::conditional_t; - using order_by_t = pack_base::order_by_t; - using policy_t = pack_base::policy_t; + using pack_t = typename pack_base::pack_t; + using filter_t = typename pack_base::filter_t; + using combine_t = typename pack_base::combine_t; + using break_t = typename pack_base::break_t; + using add_t = typename pack_base::add_t; + using remove_t = typename pack_base::remove_t; + using except_t = typename pack_base::except_t; + using conditional_t = typename pack_base::conditional_t; + using order_by_t = typename pack_base::order_by_t; + using policy_t = typename pack_base::policy_t; static_assert(std::tuple_size::value <= 1, "multiple order_by statements make no sense"); diff --git a/psl/inc/psl/ecs/state.hpp b/psl/inc/psl/ecs/state.hpp index 6e08da33..3a36279f 100644 --- a/psl/inc/psl/ecs/state.hpp +++ b/psl/inc/psl/ecs/state.hpp @@ -4,6 +4,7 @@ #include "details/component_info.hpp" #include "details/component_key.hpp" #include "details/entity_info.hpp" +#include "details/execution.hpp" #include "details/system_information.hpp" #include "entity.hpp" #include "filtering.hpp" @@ -20,28 +21,6 @@ #include #include -#if __has_include() -#include -#else -namespace std::execution -{ - class sequenced_policy - {}; - - inline constexpr sequenced_policy seq {}; - - class parallel_policy - {}; - - inline constexpr parallel_policy par {}; - - class parallel_unsequenced_policy - {}; - - inline constexpr parallel_unsequenced_policy par_unseq {}; -} // namespace std::execution -#endif - namespace psl::async { class scheduler; @@ -111,15 +90,27 @@ namespace psl::ecs template void order_by(psl::array::iterator begin, psl::array::iterator end) const noexcept { - order_by(std::execution::seq, begin, end); + order_by(psl::ecs::execution::seq, begin, end); + } + + template + void order_by(psl::ecs::execution::no_exec, + psl::array::iterator begin, + psl::array::iterator end) const noexcept + { + const auto pred = Pred {}; + std::sort(begin, end, [this, &pred](entity lhs, entity rhs) -> bool { + return std::invoke(pred, this->get(lhs), this->get(rhs)); + }); } + template - void order_by(std::execution::sequenced_policy, + void order_by(psl::ecs::execution::sequenced_policy, psl::array::iterator begin, psl::array::iterator end) const noexcept { const auto pred = Pred {}; - std::sort(std::execution::seq, begin, end, [this, &pred](entity lhs, entity rhs) -> bool { + std::sort(psl::ecs::execution::seq, begin, end, [this, &pred](entity lhs, entity rhs) -> bool { return std::invoke(pred, this->get(lhs), this->get(rhs)); }); } @@ -127,7 +118,7 @@ namespace psl::ecs private: template - void order_by(std::execution::parallel_policy, + void order_by(psl::ecs::execution::parallel_policy, psl::array::iterator begin, psl::array::iterator end, size_t max) const noexcept @@ -135,29 +126,38 @@ namespace psl::ecs auto size = std::distance(begin, end); if(size <= static_cast(max)) { - order_by(std::execution::seq, begin, end); + order_by(psl::ecs::execution::seq, begin, end); } else { auto middle = std::next(begin, size / 2); auto future = std::async( - [this, &begin, &middle, &max]() { order_by(std::execution::par, begin, middle, max); }); + [this, &begin, &middle, &max]() { order_by(psl::ecs::execution::par, begin, middle, max); }); - order_by(std::execution::par, middle, end, max); + order_by(psl::ecs::execution::par, middle, end, max); const auto pred = Pred {}; future.wait(); - std::inplace_merge( - std::execution::par_unseq, begin, middle, end, [this, &pred](entity lhs, entity rhs) -> bool { - return std::invoke(pred, this->get(lhs), this->get(rhs)); - }); + if constexpr(std::is_same_v) + { + std::inplace_merge(begin, middle, end, [this, &pred](entity lhs, entity rhs) -> bool { + return std::invoke(pred, this->get(lhs), this->get(rhs)); + }); + } + else + { + std::inplace_merge( + psl::ecs::execution::par_unseq, begin, middle, end, [this, &pred](entity lhs, entity rhs) -> bool { + return std::invoke(pred, this->get(lhs), this->get(rhs)); + }); + } } } public: void clear() noexcept; template - void order_by(std::execution::parallel_policy, + void order_by(psl::ecs::execution::parallel_policy, psl::array::iterator begin, psl::array::iterator end) const noexcept { @@ -167,7 +167,7 @@ namespace psl::ecs size /= thread_size; - order_by(std::execution::par, begin, end, size); + order_by(psl::ecs::execution::par, begin, end, size); } @@ -176,18 +176,36 @@ namespace psl::ecs psl::array::iterator end) const noexcept { auto pred = Pred {}; - return std::remove_if(std::execution::par_unseq, begin, end, [this, &pred](entity lhs) -> bool { - return !pred(this->get(lhs)); - }); + if constexpr(std::is_same_v) + { + return std::remove_if(begin, end, [this, &pred](entity lhs) -> bool { + return !pred(this->get(lhs)); + }); + } + else + { + return std::remove_if(psl::ecs::execution::par_unseq, begin, end, [this, &pred](entity lhs) -> bool { + return !pred(this->get(lhs)); + }); + } } template psl::array::iterator on_condition(psl::array::iterator begin, psl::array::iterator end, Pred&& pred) const noexcept { - return std::remove_if(std::execution::par_unseq, begin, end, [this, &pred](entity lhs) -> bool { - return !pred(this->get(lhs)); - }); + if constexpr(std::is_same_v) + { + return std::remove_if(begin, end, [this, &pred](entity lhs) -> bool { + return !pred(this->get(lhs)); + }); + } + else + { + return std::remove_if(psl::ecs::execution::par_unseq, begin, end, [this, &pred](entity lhs) -> bool { + return !pred(this->get(lhs)); + }); + } } template @@ -885,7 +903,7 @@ namespace psl::ecs static_assert(sizeof...(Ts) == 1, "due to a bug in MSVC we cannot have deeper nested template packs"); orderby = [](psl::array::iterator begin, psl::array::iterator end, const psl::ecs::state_t& state) { - state.order_by(std::execution::par, begin, end); + state.order_by(psl::ecs::execution::par, begin, end); }; } diff --git a/psl/inc/psl/math/vec.hpp b/psl/inc/psl/math/vec.hpp index 06710b7d..3548eb51 100644 --- a/psl/inc/psl/math/vec.hpp +++ b/psl/inc/psl/math/vec.hpp @@ -208,7 +208,7 @@ namespace psl } template - operator tvec() const noexcept requires std::convertible_to + operator tvec() const noexcept requires std::is_convertible_v { tvec res {}; for(auto i = 0; i < dimensions; ++i) res[i] = static_cast(value[i]); @@ -303,7 +303,7 @@ namespace psl } template - operator tvec() const noexcept requires std::convertible_to + operator tvec() const noexcept requires std::is_convertible_v { return {static_cast(value[0])}; } @@ -404,7 +404,7 @@ namespace psl } template - operator tvec() const noexcept requires std::convertible_to + operator tvec() const noexcept requires std::is_convertible_v { return {static_cast(value[0]), static_cast(value[1])}; } @@ -520,7 +520,7 @@ namespace psl } template - operator tvec() const noexcept requires std::convertible_to + operator tvec() const noexcept requires std::is_convertible_v { return {static_cast(value[0]), static_cast(value[1]), static_cast(value[2])}; } @@ -652,7 +652,7 @@ namespace psl } template - operator tvec() const noexcept requires std::convertible_to + operator tvec() const noexcept requires std::is_convertible_v { return { static_cast(value[0]), static_cast(value[1]), static_cast(value[2]), static_cast(value[3])}; diff --git a/psl/inc/psl/stdafx_psl.hpp b/psl/inc/psl/stdafx_psl.hpp index 5793a137..c89308ff 100644 --- a/psl/inc/psl/stdafx_psl.hpp +++ b/psl/inc/psl/stdafx_psl.hpp @@ -10,22 +10,8 @@ #include "psl/platform_def.hpp" #include "psl/ustring.hpp" -#ifdef PLATFORM_ANDROID -#include -#include -#include -#endif - #include "psl/logging.hpp" -namespace platform::specifics -{ -#if defined(PLATFORM_ANDROID) - extern android_app* android_application; -#endif - -} // namespace platform::specifics - #include "psl/assertions.hpp" /*! \namespace memory \brief this namespace contains types and utilities for managing regions of memory diff --git a/psl/inc/psl/template_utils.hpp b/psl/inc/psl/template_utils.hpp index 4cfbb6a1..595d3fdb 100644 --- a/psl/inc/psl/template_utils.hpp +++ b/psl/inc/psl/template_utils.hpp @@ -199,7 +199,7 @@ namespace utility::templates } // namespace template - using container_to_type_pack_t = to_type_pack::type; + using container_to_type_pack_t = typename to_type_pack::type; template using container_has_type = has_type>; diff --git a/tools/android.py b/tools/android.py new file mode 100644 index 00000000..6e142f8e --- /dev/null +++ b/tools/android.py @@ -0,0 +1,106 @@ +from argparse import ArgumentParser +import io +import os +import subprocess + +CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) +ROOT_DIR = os.path.join(CURRENT_DIR, '..') + +def run_command(command=[], directory=None, print_stdout=False, catch_stdout=False): + process = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=directory) + output = [] + if print_stdout: + for line in io.TextIOWrapper(process.stdout, newline=''): + if not line.endswith('\r') and catch_stdout: + output.append(line[:len(line)-1] if line[-1] == os.linesep else line) + elif catch_stdout: + for line in io.TextIOWrapper(process.stdout, newline=os.linesep): + line = line.rsplit('\r', maxsplit=1)[-1] + output.append(line[:len(line)-1]) + process.stdout.close() + process.wait() + if process.returncode != 0: + raise Exception(f"Raised exitcode '{process.returncode}' while trying to run the command '{' '.join(comm for comm in command)}'") + return output + +def generate(directory, project="example"): + os.makedirs(directory, exist_ok=True) + if not os.path.exists(os.path.join(directory, 'settings.gradle')): + run_command(command=[ + 'gradle', 'init', + '--type', 'basic', + '--dsl', 'groovy', + '--project-name', project, + '--incubating' + ], directory=directory, print_stdout=True) + + android_templates = os.path.join(CURRENT_DIR, 'templates', 'android') + + templates = [os.path.join(dp, f) for dp, dn, filenames in os.walk(android_templates) for f in filenames if os.path.splitext(f)[1] == '.template'] + + for template in templates: + os.makedirs(os.path.dirname(os.path.join(directory, os.path.relpath(template, android_templates))), exist_ok=True) + with open(template, 'r') as template_file, open(os.path.join(directory, os.path.relpath(template, android_templates).rsplit('.', maxsplit=1)[0]), 'w') as file: + template = template_file.read() + template = template.replace('{{PROJECT}}', project) + template = template.replace('{{COMPANY}}', "paradigmengine") + file.write(template) + + resources = [os.path.join(dp, f) for dp, dn, filenames in os.walk(android_templates) for f in filenames if os.path.splitext(f)[1] != '.template'] + for resource in resources: + os.makedirs(os.path.dirname(os.path.join(directory, os.path.relpath(resource, android_templates))), exist_ok=True) + with open(resource, 'rb') as resource_file, open(os.path.join(directory, os.path.relpath(resource, android_templates)), 'wb') as file: + file.write(resource_file.read()) + + # create the symlinks to the source code + cpp_dir = os.path.join(directory, 'app', 'src', 'main') + [ os.symlink(os.path.join(ROOT_DIR, dir), os.path.join(cpp_dir, dir)) for dir in ['psl', 'core', 'extern', 'cmake', 'CMakeLists.txt', 'tools'] if not os.path.exists(os.path.join(cpp_dir, dir))] + +def parse_installed_packages(channel=0): + sdkman_output = run_command(["sdkmanager", "--list", f"--channel={str(channel)}"], catch_stdout=True) + + packages = {'installed': {}, 'available': {}} + for line in [package for package in sdkman_output if package.count('|') == 3]: + name, version, _, location = (l.strip() for l in line.split('|')) + if name == "Path" or name.startswith('-'): + continue + packages['installed'][name] = {'version': version, 'location': location} + + for line in [package for package in sdkman_output if package.count('|') == 2]: + name, version, _ = (l.strip() for l in line.split('|')) + if name == "Path" or name.startswith('-'): + continue + packages['available'][name] = {'version': version } + + return packages + +def install_required_packages(): + packages = parse_installed_packages(channel=3) + + def install_required(package, channel=0): + if package in packages["installed"]: + return + print(f"Missing '{package}', trying to install now..") + if package in packages["available"]: + print(f"installing '{package}'") + run_command(command=["sdkmanager", package, f"--channel={str(channel)}"], print_stdout=True, catch_stdout=False) + else: + raise Exception(f"Could not find the required sdk package '{package}'") + + install_required("platforms;android-31") + install_required("cmake;3.22.1", channel=3) + install_required("ndk;25.0.8151533", channel=1) + +def main(): + parser = ArgumentParser() + parser.add_argument("--output", default=os.path.join(ROOT_DIR, "builds", "android")) + parser.add_argument("--sdk", default=None, help="set to override the used android sdk, falls back to path available one") + args = parser.parse_args() + + install_required_packages() + + generate(args.output) + +if __name__ == "__main__": + main() + diff --git a/tools/templates/android/app/build.gradle.template b/tools/templates/android/app/build.gradle.template new file mode 100644 index 00000000..53a9e388 --- /dev/null +++ b/tools/templates/android/app/build.gradle.template @@ -0,0 +1,39 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 31 + ndkVersion '25.0.8151533' + + defaultConfig { + applicationId = 'com.{{COMPANY}}.{{PROJECT}}' + minSdkVersion 21 + targetSdkVersion 31 + externalNativeBuild { + cmake { + arguments '-DANDROID_STL=c++_static', '-DPE_PLATFORM=ANDROID', '-DPE_GLES=OFF', '-DPE_VULKAN=ON', '-DPE_MAKE_EXE=ON', '-DVK_VERSION=1.2.148', '-DPE_TESTS=OFF' + } + } + ndk { + abiFilters 'arm64-v8a', 'x86_64' + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), + 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + version '3.22.1' + path 'src/main/CMakeLists.txt' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' +} \ No newline at end of file diff --git a/tools/templates/android/app/src/main/AndroidManifest.xml.template b/tools/templates/android/app/src/main/AndroidManifest.xml.template new file mode 100644 index 00000000..c2c77527 --- /dev/null +++ b/tools/templates/android/app/src/main/AndroidManifest.xml.template @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/templates/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/tools/templates/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..cde69bcccec65160d92116f20ffce4fce0b5245c GIT binary patch literal 3418 zcmZ{nX*|@A^T0p5j$I+^%FVhdvMbgt%d+mG98ubwNv_tpITppba^GiieBBZGI>I89 zGgm8TA>_)DlEu&W;s3#ZUNiH4&CF{a%siTjzG;eOzQB6{003qKeT?}z_5U*{{kgZ; zdV@U&tqa-&4FGisjMN8o=P}$t-`oTM2oeB5d9mHPgTYJx4jup)+5a;Tke$m708DocFzDL>U$$}s6FGiy_I1?O zHXq`q884|^O4Q*%V#vwxqCz-#8i`Gu)2LeB0{%%VKunOF%9~JcFB9MM>N00M`E~;o zBU%)O5u-D6NF~OQV7TV#JAN;=Lylgxy0kncoQpGq<<_gxw`FC=C-cV#$L|(47Hatl ztq3Jngq00x#}HGW@_tj{&A?lwOwrVX4@d66vLVyj1H@i}VD2YXd)n03?U5?cKtFz4 zW#@+MLeDVP>fY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zkRh)!g~R>!jaR9;K|#82kfE5^;R!~}H4C?q{1AG?O$5kGp)G$f%VML%aPD?{ zG6)*KodSZRXbl8OD=ETxQLJz)KMI7xjArKUNh3@0f|T|75?Yy=pD7056ja0W)O;Td zCEJ=7q?d|$3rZb+8Cvt6mybV-#1B2}Jai^DOjM2<90tpql|M5tmheg){2NyZR}x3w zL6u}F+C-PIzZ56q0x$;mVJXM1V0;F}y9F29ob51f;;+)t&7l30gloMMHPTuod530FC}j^4#qOJV%5!&e!H9#!N&XQvs5{R zD_FOomd-uk@?_JiWP%&nQ_myBlM6so1Ffa1aaL7B`!ZTXPg_S%TUS*>M^8iJRj1*~ e{{%>Z1YfTk|3C04d;8A^0$7;Zm{b|L#{L(;l>}-4 literal 0 HcmV?d00001 diff --git a/tools/templates/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/tools/templates/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..bfa42f0e7b91d006d22352c9ff2f134e504e3c1d GIT binary patch literal 4842 zcmZ{oXE5C1x5t0WvTCfdv7&7fy$d2l*k#q|U5FAbL??P!61}%ovaIM)mL!5G(V|6J zAtDH(OY|Du^}l!K&fFLG%sJ2JIp@rG=9y>Ci)Wq~U2RobsvA@Q0MM$dq4lq5{hy#9 zzgp+B{O(-=?1<7r0l>Q?>N6X%s~lmgrmqD6fjj_!c?AF`S0&6U06Z51fWOuNAe#jM z%pSN#J-Mp}`ICpL=qp~?u~Jj$6(~K_%)9}Bn(;pY0&;M00H9x2N23h=CpR7kr8A9X zU%oh4-E@i!Ac}P+&%vOPQ3warO9l!SCN)ixGW54Jsh!`>*aU)#&Mg7;#O_6xd5%I6 zneGSZL3Kn-4B^>#T7pVaIHs3^PY-N^v1!W=%gzfioIWosZ!BN?_M)OOux&6HCyyMf z3ToZ@_h75A33KyC!T)-zYC-bp`@^1n;w3~N+vQ0#4V7!f|JPMlWWJ@+Tg~8>1$GzLlHGuxS)w&NAF*&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V>`Z3f5yuz^??$#3qR#q6F($w>kmKK`x21VmX=9kb^+cPdBY2l zGkIZSf%C+`2nj^)j zo}g}v;5{nk<>%xj-2OqDbJ3S`7|tQWqdvJdgiL{1=w0!qS9$A`w9Qm7>N0Y*Ma%P_ zr@fR4>5u{mKwgZ33Xs$RD6(tcVH~Mas-87Fd^6M6iuV^_o$~ql+!eBIw$U)lzl`q9 z=L6zVsZzi0IIW=DT&ES9HajKhb5lz4yQxT-NRBLv_=2sn7WFX&Wp6Y!&}P+%`!A;s zrCwXO3}jrdA7mB`h~N~HT64TM{R$lNj*~ekqSP^n9P~z;P zWPlRPz0h6za8-P>!ARb+A1-r>8VF*xhrGa8W6J$p*wy`ULrD$CmYV7Gt^scLydQWbo7XN-o9X1i7;l+J_8Ncu zc=EX&dg`GRo4==cz2d_Rz28oLS`Suf6OCp~f{0-aQ`t5YZ=!CAMc6-RZw#}A%;s44 znf2`6gcgm=0SezTH9h+JzeR3Lcm;8?*@+?FDfguK^9)z(Z`I!RKrSAI?H~4et6GTkz07Qgq4B6%Q*8Y0yPc4x z8(^YwtZjYIeOvVLey#>@$UzIciJ#x0pJLFg=8UaZv%-&?Yzp7gWNIo_x^(d75=x2c zv|LQ`HrKP(8TqFxTiP5gdT2>aTN0S7XW*pilASS$UkJ2*n+==D)0mgTGxv43t61fr z47GkfMnD-zSH@|mZ26r*d3WEtr+l-xH@L}BM)~ThoMvKqGw=Ifc}BdkL$^wC}=(XSf4YpG;sA9#OSJf)V=rs#Wq$?Wj+nTlu$YXn yn3SQon5>kvtkl(BT2@T#Mvca!|08g9w{vm``2PjZHg=b<1c17-HkzPl9sXa)&-Ts$ literal 0 HcmV?d00001 diff --git a/tools/templates/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/tools/templates/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..324e72cdd7480cb983fa1bcc7ce686e51ef87fe7 GIT binary patch literal 7718 zcmZ{JWl)?=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kAnD{zQU=Pb^3f` zT5-g`z5|%qOa!WTBed-8`#AQ~wb9TrUZKU)H*O7!LtNnEd!r8!Oda)u!Gb5P`9(`b z`lMP6CLh4OzvXC#CR|@uo$EcHAyGr=)LB7)>=s3 zvU;aR#cN3<5&CLMFU@keW^R-Tqyf4fdkOnwI(H$x#@I1D6#dkUo@YW#7MU0@=NV-4 zEh2K?O@+2e{qW^7r?B~QTO)j}>hR$q9*n$8M(4+DOZ00WXFonLlk^;os8*zI>YG#? z9oq$CD~byz>;`--_NMy|iJRALZ#+qV8OXn=AmL^GL&|q1Qw-^*#~;WNNNbk(96Tnw zGjjscNyIyM2CYwiJ2l-}u_7mUGcvM+puPF^F89eIBx27&$|p_NG)fOaafGv|_b9G$;1LzZ-1aIE?*R6kHg}dy%~K(Q5S2O6086 z{lN&8;0>!pq^f*Jlh=J%Rmaoed<=uf@$iKl+bieC83IT!09J&IF)9H)C?d!eW1UQ}BQwxaqQY47DpOk@`zZ zo>#SM@oI^|nrWm~Ol7=r`!Bp9lQNbBCeHcfN&X$kjj0R(@?f$OHHt|fWe6jDrYg3(mdEd$8P2Yzjt9*EM zLE|cp-Tzsdyt(dvLhU8}_IX&I?B=|yoZ!&<`9&H5PtApt=VUIB4l0a1NH v0SQqt3DM`an1p};^>=lX|A*k@Y-MNT^ZzF}9G-1G696?OEyXH%^Pv9$0dR%J literal 0 HcmV?d00001 diff --git a/tools/templates/android/app/src/main/res/values/strings.xml.template b/tools/templates/android/app/src/main/res/values/strings.xml.template new file mode 100644 index 00000000..68023d95 --- /dev/null +++ b/tools/templates/android/app/src/main/res/values/strings.xml.template @@ -0,0 +1,4 @@ + + + {{PROJECT}} + \ No newline at end of file diff --git a/tools/templates/android/build.gradle.template b/tools/templates/android/build.gradle.template new file mode 100644 index 00000000..3a3b3f0a --- /dev/null +++ b/tools/templates/android/build.gradle.template @@ -0,0 +1,21 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.2.0' + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} \ No newline at end of file diff --git a/tools/templates/android/gradle.properties.template b/tools/templates/android/gradle.properties.template new file mode 100644 index 00000000..9e6fce10 --- /dev/null +++ b/tools/templates/android/gradle.properties.template @@ -0,0 +1,19 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/tools/templates/android/settings.gradle.template b/tools/templates/android/settings.gradle.template new file mode 100644 index 00000000..6a2abffe --- /dev/null +++ b/tools/templates/android/settings.gradle.template @@ -0,0 +1,2 @@ +include ':app' +rootProject.name = "{{PROJECT}}" From 5050435ed6de39bc218d70ce5ff5733af5ddf97f Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Thu, 24 Feb 2022 23:33:51 +0200 Subject: [PATCH 02/16] FIxed last set of compile issues --- core/inc.txt | 2 +- core/inc/gfx/swapchain.hpp | 2 + core/inc/os/context.hpp | 34 ++++ core/inc/vk/swapchain.hpp | 2 + core/main/CMakeLists.txt | 6 +- core/main/main.cpp | 17 +- core/src.txt | 11 ++ core/src/gfx/swapchain.cpp | 3 +- core/src/os/context.cpp | 1 + core/src/os/context_android.cpp | 152 ++++++++++++++++++ core/src/vk/swapchain.cpp | 9 +- tools/android.py | 2 +- .../app/src/main/AndroidManifest.xml.template | 2 +- 13 files changed, 227 insertions(+), 16 deletions(-) create mode 100644 core/inc/os/context.hpp create mode 100644 core/src/os/context.cpp create mode 100644 core/src/os/context_android.cpp diff --git a/core/inc.txt b/core/inc.txt index dd5347c2..201e6145 100644 --- a/core/inc.txt +++ b/core/inc.txt @@ -44,6 +44,7 @@ meta/shader meta/texture os/surface +os/context systems/input @@ -76,7 +77,6 @@ ecs/components/text utility/geometry ) - list(TRANSFORM INC PREPEND inc/) list(TRANSFORM INC APPEND .hpp) diff --git a/core/inc/gfx/swapchain.hpp b/core/inc/gfx/swapchain.hpp index 85f076f4..a4b3b2b8 100644 --- a/core/inc/gfx/swapchain.hpp +++ b/core/inc/gfx/swapchain.hpp @@ -6,6 +6,7 @@ namespace core::os { class surface; + class context; } namespace core::gfx @@ -27,6 +28,7 @@ namespace core::gfx psl::meta::file* metaFile, core::resource::handle surface, core::resource::handle context, + core::os::context& os_context, bool use_depth = true); ~swapchain() {}; diff --git a/core/inc/os/context.hpp b/core/inc/os/context.hpp new file mode 100644 index 00000000..f0ee49c0 --- /dev/null +++ b/core/inc/os/context.hpp @@ -0,0 +1,34 @@ +#pragma once + +#if defined(PLATFORM_ANDROID) +struct android_app; +struct ASensorManager; +struct ASensor; +struct ASensorEventQueue; + +namespace core::os +{ + class context + { + public: + context(android_app* application); + + auto application() noexcept -> android_app&; + bool tick() noexcept; + private: + android_app* m_Application {nullptr}; + bool m_Paused {false}; + ASensorManager* m_SensorManager {nullptr}; + const ASensor* m_AccelerometerSensor {nullptr}; + ASensorEventQueue* m_SensorEventQueue {nullptr}; + }; +} +#else +namespace core::os +{ + class context + { + bool tick() noexcept { return true; } + }; +} +#endif \ No newline at end of file diff --git a/core/inc/vk/swapchain.hpp b/core/inc/vk/swapchain.hpp index 77eb49ed..6176b423 100644 --- a/core/inc/vk/swapchain.hpp +++ b/core/inc/vk/swapchain.hpp @@ -6,6 +6,7 @@ namespace core::os { class surface; + class context; } namespace core::ivk @@ -38,6 +39,7 @@ namespace core::ivk psl::meta::file* metaFile, core::resource::handle surface, core::resource::handle context, + core::os::context& os_context, bool use_depth = true); ~swapchain(); diff --git a/core/main/CMakeLists.txt b/core/main/CMakeLists.txt index ec4ff46f..f40809d9 100644 --- a/core/main/CMakeLists.txt +++ b/core/main/CMakeLists.txt @@ -8,8 +8,10 @@ add_definitions(${PE_DEFINES}) if(PE_PLATFORM STREQUAL "ANDROID") add_subdirectory(android_native_app_glue) add_library(${LOCAL_PROJECT} SHARED main.cpp) - - target_link_options(${LOCAL_PROJECT} PRIVATE "-u ANativeActivity_onCreate") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") + # todo: for some reason this is ignored? + # target_link_options(${LOCAL_PROJECT} PRIVATE "-u ANativeActivity_onCreate") + target_include_directories(${LOCAL_PROJECT} PUBLIC ${ANDROID_NDK}/sources/android/native_app_glue) target_link_libraries(${LOCAL_PROJECT} PUBLIC ${PROJECT_PSL} ${PROJECT_CORE} ${PE_DL_LIBS} PRIVATE android ${PROJECT_ANDROID_NATIVE_GLUE} EGL GLESv1_CM log) diff --git a/core/main/main.cpp b/core/main/main.cpp index da36f30e..21155e2f 100755 --- a/core/main/main.cpp +++ b/core/main/main.cpp @@ -29,6 +29,7 @@ #include "data/window.hpp" // application data #include "os/surface.hpp" // the OS surface to draw one +#include "os/context.hpp" #include "meta/shader.hpp" #include "meta/texture.hpp" @@ -316,7 +317,7 @@ void setup_loggers() #endif -int entry(gfx::graphics_backend backend) +int entry(gfx::graphics_backend backend, core::os::context& os_context) { psl::string libraryPath {utility::application::path::library + "resources.metalib"}; @@ -346,7 +347,7 @@ int entry(gfx::graphics_backend backend) auto context_handle = cache.create(backend, psl::string8_t {APPLICATION_NAME}); - auto swapchain_handle = cache.create(surface_handle, context_handle); + auto swapchain_handle = cache.create(surface_handle, context_handle, os_context); // get a vertex and fragment shader that can be combined, we only need the meta if(!cache.library().contains("234318ae-3590-f1e2-bac5-f113cac3be9b"_uid) || @@ -828,7 +829,7 @@ ECSState.create( size_t burst = 40000; #endif - while(surface_handle->tick()) + while(os_context.tick() && surface_handle->tick()) { core::log->info("---- FRAME {0} START ----", frame); core::log->info("There are {} renderables alive right now", ECSState.size()); @@ -932,8 +933,12 @@ ECSState.create( #if defined(PLATFORM_ANDROID) -void android_main(struct android_app* application) +void android_main(android_app* application) { + auto os_context = core::os::context{application}; + setup_loggers(); + std::srand(0); + entry(graphics_backend::vulkan, os_context); return; } @@ -985,7 +990,7 @@ int main(int argc, char* argv[]) return graphics_backend::gles; #endif }(argc, argv); - - return entry(backend); + core::os::context context{}; + return entry(backend, context); } #endif diff --git a/core/src.txt b/core/src.txt index 03fce442..94654a4d 100644 --- a/core/src.txt +++ b/core/src.txt @@ -48,6 +48,17 @@ ecs/systems/geometry_instance ecs/systems/debug/grid ) +# plaftorm specific includes +if(PE_PLATFORM STREQUAL "ANDROID") + list(APPEND SRC + os/context_android + ) +else() + list(APPEND SRC + os/context + ) +endif() + list(TRANSFORM SRC PREPEND src/) list(TRANSFORM SRC APPEND .cpp) diff --git a/core/src/gfx/swapchain.cpp b/core/src/gfx/swapchain.cpp index 5c2fd49c..2feadd19 100644 --- a/core/src/gfx/swapchain.cpp +++ b/core/src/gfx/swapchain.cpp @@ -29,6 +29,7 @@ swapchain::swapchain(core::resource::cache_t& cache, psl::meta::file* metaFile, handle surface, handle context, + core::os::context& os_context, bool use_depth) : m_Backend(context->backend()) { @@ -46,7 +47,7 @@ swapchain::swapchain(core::resource::cache_t& cache, #ifdef PE_VULKAN case graphics_backend::vulkan: m_VKHandle = cache.create_using( - metaData.uid, surface, context->resource(), use_depth); + metaData.uid, surface, context->resource(), os_context, use_depth); surface->register_swapchain(m_VKHandle); break; #endif diff --git a/core/src/os/context.cpp b/core/src/os/context.cpp new file mode 100644 index 00000000..cc4f53d5 --- /dev/null +++ b/core/src/os/context.cpp @@ -0,0 +1 @@ +#include "os/context.hpp" diff --git a/core/src/os/context_android.cpp b/core/src/os/context_android.cpp new file mode 100644 index 00000000..cbb8f2f9 --- /dev/null +++ b/core/src/os/context_android.cpp @@ -0,0 +1,152 @@ +#define PLATFORM_ANDROID +#include +#include +#include "os/context.hpp" +#include + +static void engine_handle_cmd(struct android_app* app, int32_t cmd) { + switch (cmd) { + case APP_CMD_SAVE_STATE: + app->savedState = nullptr; + app->savedStateSize = 0; + break; + case APP_CMD_INIT_WINDOW: + if (app->window != nullptr) { + //engine_init_display(engine); + //engine_draw_frame(engine); + } + break; + case APP_CMD_TERM_WINDOW: + // The window is being hidden or closed, clean it up. + //engine_term_display(engine); + break; + case APP_CMD_GAINED_FOCUS: + // When our app gains focus, we start monitoring the accelerometer. + // if (engine->accelerometerSensor != nullptr) { + // ASensorEventQueue_enableSensor(engine->sensorEventQueue, + // engine->accelerometerSensor); + // // We'd like to get 60 events per second (in us). + // ASensorEventQueue_setEventRate(engine->sensorEventQueue, + // engine->accelerometerSensor, + // (1000L/60)*1000); + // } + break; + case APP_CMD_LOST_FOCUS: + // When our app loses focus, we stop monitoring the accelerometer. + // This is to avoid consuming battery while not being used. + // if (engine->accelerometerSensor != nullptr) { + // ASensorEventQueue_disableSensor(engine->sensorEventQueue, + // engine->accelerometerSensor); + // } + // Also stop animating. + //engine->animating = 0; + //engine_draw_frame(engine); + break; + default: + break; + } +} + +/* + * AcquireASensorManagerInstance(void) + * Workaround ASensorManager_getInstance() deprecation false alarm + * for Android-N and before, when compiling with NDK-r15 + */ +#include +ASensorManager* AcquireASensorManagerInstance(android_app* app) { + + if(!app) + return nullptr; + + typedef ASensorManager *(*PF_GETINSTANCEFORPACKAGE)(const char *name); + void* androidHandle = dlopen("libandroid.so", RTLD_NOW); + auto getInstanceForPackageFunc = (PF_GETINSTANCEFORPACKAGE) + dlsym(androidHandle, "ASensorManager_getInstanceForPackage"); + if (getInstanceForPackageFunc) { + JNIEnv* env = nullptr; + app->activity->vm->AttachCurrentThread(&env, nullptr); + + jclass android_content_Context = env->GetObjectClass(app->activity->clazz); + jmethodID midGetPackageName = env->GetMethodID(android_content_Context, + "getPackageName", + "()Ljava/lang/String;"); + auto packageName= (jstring)env->CallObjectMethod(app->activity->clazz, + midGetPackageName); + + const char *nativePackageName = env->GetStringUTFChars(packageName, nullptr); + ASensorManager* mgr = getInstanceForPackageFunc(nativePackageName); + env->ReleaseStringUTFChars(packageName, nativePackageName); + app->activity->vm->DetachCurrentThread(); + if (mgr) { + dlclose(androidHandle); + return mgr; + } + } + + typedef ASensorManager *(*PF_GETINSTANCE)(); + auto getInstanceFunc = (PF_GETINSTANCE) + dlsym(androidHandle, "ASensorManager_getInstance"); + // by all means at this point, ASensorManager_getInstance should be available + assert(getInstanceFunc); + dlclose(androidHandle); + + return getInstanceFunc(); +} + + +core::os::context::context(android_app* application) : m_Application(application) +{ + m_Application->userData = this; + m_Application->onAppCmd = engine_handle_cmd; + + m_SensorManager = AcquireASensorManagerInstance(m_Application); + m_AccelerometerSensor = ASensorManager_getDefaultSensor(m_SensorManager, ASENSOR_TYPE_ACCELEROMETER); + m_SensorEventQueue = ASensorManager_createEventQueue(m_SensorManager, m_Application->looper, LOOPER_ID_USER, nullptr, nullptr); + + if (m_Application->savedState != nullptr) { + // We are starting with a previous saved state; restore from it. + // engine.state = *(struct saved_state*)state->savedState; + } +} + +auto core::os::context::application() noexcept -> android_app& +{ + return *m_Application; +} + + +bool core::os::context::tick() noexcept +{ + int ident; + int events; + android_poll_source* source; + + // If not animating, we will block forever waiting for events. + // If animating, we loop until all events are read, then continue + // to draw the next frame of animation. + while ((ident=ALooper_pollAll(m_Paused ? 0 : -1, nullptr, &events, + (void**)&source)) >= 0) { + + // Process this event. + if (source != nullptr) { + source->process(m_Application, source); + } + + // If a sensor has data, process it now. + if (ident == LOOPER_ID_USER) { + if (m_AccelerometerSensor != nullptr) { + ASensorEvent event; + while (ASensorEventQueue_getEvents(m_SensorEventQueue, + &event, 1) > 0) { + } + } + } + + // Check if we are exiting. + if (m_Application->destroyRequested != 0) { + return false; + } + } + + return true; +} \ No newline at end of file diff --git a/core/src/vk/swapchain.cpp b/core/src/vk/swapchain.cpp index daf39555..671170b8 100644 --- a/core/src/vk/swapchain.cpp +++ b/core/src/vk/swapchain.cpp @@ -1,7 +1,9 @@ -#include "vk/swapchain.hpp" +#include "vk/ivk.hpp" +#include "vk/swapchain.hpp" #include "logging.hpp" #include "meta/texture.hpp" #include "os/surface.hpp" +#include "os/context.hpp" #include "vk/context.hpp" #include "vk/conversion.hpp" #include "vk/texture.hpp" @@ -18,6 +20,7 @@ swapchain::swapchain(core::resource::cache_t& cache, psl::meta::file* metaFile, handle surface, handle context, + core::os::context& os_context, bool use_depth) : m_OSSurface(&surface.value()), m_Context(context), m_Cache(cache), m_DepthTextureHandle(), m_UseDepth(use_depth), m_SurfaceFormat {} @@ -36,9 +39,7 @@ swapchain::swapchain(core::resource::cache_t& cache, #elif defined(PLATFORM_ANDROID) vk::AndroidSurfaceCreateInfoKHR createInfo; core::ivk::log->info("creating android swapchain"); - auto android_app = platform::specifics::android_application; - auto window = android_app->window; - createInfo.window = window; + createInfo.window = os_context.application().window; utility::vulkan::check(m_Context->instance().createAndroidSurfaceKHR(&createInfo, VK_NULL_HANDLE, &m_Surface)); #elif defined(SURFACE_D2D) uint32_t displayPropertyCount; diff --git a/tools/android.py b/tools/android.py index 6e142f8e..30e22e60 100644 --- a/tools/android.py +++ b/tools/android.py @@ -23,7 +23,7 @@ def run_command(command=[], directory=None, print_stdout=False, catch_stdout=Fal raise Exception(f"Raised exitcode '{process.returncode}' while trying to run the command '{' '.join(comm for comm in command)}'") return output -def generate(directory, project="example"): +def generate(directory, project="main"): os.makedirs(directory, exist_ok=True) if not os.path.exists(os.path.join(directory, 'settings.gradle')): run_command(command=[ diff --git a/tools/templates/android/app/src/main/AndroidManifest.xml.template b/tools/templates/android/app/src/main/AndroidManifest.xml.template index c2c77527..2478f3c3 100644 --- a/tools/templates/android/app/src/main/AndroidManifest.xml.template +++ b/tools/templates/android/app/src/main/AndroidManifest.xml.template @@ -21,7 +21,7 @@ android:exported="true"> + android:value="{{PROJECT}}" /> From e779932aaaa7c4168ddd2cf8457024185c836c0d Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Sat, 26 Feb 2022 00:17:33 +0200 Subject: [PATCH 03/16] rewrote assert usage platform utils now supports android loading files context build issue fixed --- .clang-format | 1 + benchmarks/src/ecs.cpp | 2 +- core/inc/data/stream.hpp | 2 +- core/inc/gfx/render_graph.hpp | 2 +- core/inc/gles/conversion.hpp | 61 +++-- core/inc/meta/texture.hpp | 2 +- core/inc/os/context.hpp | 1 + core/inc/resource/handle.hpp | 7 +- core/inc/stdafx.hpp | 9 +- core/inc/utility/geometry.hpp | 8 +- core/inc/vk/conversion.hpp | 19 +- core/inc/vk/ivk.hpp | 21 +- core/main/main.cpp | 22 +- core/src/ecs/systems/text.cpp | 2 +- core/src/gfx/compute.cpp | 2 +- core/src/gles/compute.cpp | 12 +- core/src/gles/framebuffer.cpp | 4 +- core/src/gles/geometry.cpp | 4 +- core/src/gles/material.cpp | 1 - core/src/gles/texture.cpp | 5 +- core/src/os/context_android.cpp | 4 +- core/src/os/surface_win32.cpp | 7 +- core/src/os/surface_xcb.cpp | 4 +- core/src/vk/context.cpp | 8 +- core/src/vk/drawpass.cpp | 2 +- core/src/vk/framebuffer.cpp | 4 +- core/src/vk/geometry.cpp | 4 +- core/src/vk/pipeline.cpp | 2 +- core/src/vk/texture.cpp | 2 +- psl/inc/psl/assertions.hpp | 239 +++++++++++------- psl/inc/psl/async/details/description.hpp | 4 +- psl/inc/psl/collections/ring_array.hpp | 2 +- psl/inc/psl/collections/static_ring_array.hpp | 2 +- psl/inc/psl/delegate.hpp | 1 - psl/inc/psl/ecs/command_buffer.hpp | 2 +- psl/inc/psl/ecs/details/component_info.hpp | 2 +- .../psl/ecs/details/staged_sparse_array.hpp | 26 +- psl/inc/psl/ecs/state.hpp | 4 +- psl/inc/psl/math/math.hpp | 5 +- psl/inc/psl/math/matrix.hpp | 8 +- psl/inc/psl/memory/segment.hpp | 4 +- psl/inc/psl/memory/sparse_array.hpp | 8 +- psl/inc/psl/pack_view.hpp | 2 +- psl/inc/psl/platform_utils.hpp | 81 +----- psl/inc/psl/sparse_array.hpp | 7 +- psl/inc/psl/view_ptr.hpp | 2 +- psl/src/application_utils.cpp | 2 +- psl/src/async/scheduler.cpp | 8 +- psl/src/ecs/command_buffer.cpp | 22 +- psl/src/ecs/state.cpp | 54 ++-- psl/src/library.cpp | 29 ++- psl/src/memory/range.cpp | 2 +- psl/src/platform_utils.cpp | 123 ++++++++- .../app/src/main/AndroidManifest.xml.template | 3 +- 54 files changed, 502 insertions(+), 364 deletions(-) diff --git a/.clang-format b/.clang-format index b2f95ccb..bf3604af 100644 --- a/.clang-format +++ b/.clang-format @@ -66,4 +66,5 @@ CommentPragmas: '.* \\(param|tparam|brief|detail|details|return|returns|note|wa # EmptyLineBeforeAccessModifier: LogicalBlock # IndentRequires: true # BreakBeforeConceptDeclarations: true +IndentPPDirectives: BeforeHash ... diff --git a/benchmarks/src/ecs.cpp b/benchmarks/src/ecs.cpp index e753aeac..f1694b97 100644 --- a/benchmarks/src/ecs.cpp +++ b/benchmarks/src/ecs.cpp @@ -234,7 +234,7 @@ auto get_random_entities(const psl::array& source, size_t count, std::mt template void run_system(benchmark::State& gState, state_t& state, const std::vector& count) { - assert(count.size() == 5); + psl_assert(count.size() == 5, "expected size to be 5"); auto entities = state.create(count[0]); std::random_device rd; std::mt19937 g(rd()); diff --git a/core/inc/data/stream.hpp b/core/inc/data/stream.hpp index 7afd653e..15cadd60 100644 --- a/core/inc/data/stream.hpp +++ b/core/inc/data/stream.hpp @@ -276,7 +276,7 @@ namespace core } break; } - assert(false && "unknown sized stream"); + psl_assert(false, "unknown sized stream"); return 0; } diff --git a/core/inc/gfx/render_graph.hpp b/core/inc/gfx/render_graph.hpp index 7f8016ef..5aa9abaf 100644 --- a/core/inc/gfx/render_graph.hpp +++ b/core/inc/gfx/render_graph.hpp @@ -128,7 +128,7 @@ namespace psl } } - assert(it->first->references == 0); + psl_assert(it->first->references == 0, "Should have 0 references"); for(auto* node : it->second) { diff --git a/core/inc/gles/conversion.hpp b/core/inc/gles/conversion.hpp index 46e79b15..49b959e1 100644 --- a/core/inc/gles/conversion.hpp +++ b/core/inc/gles/conversion.hpp @@ -29,7 +29,7 @@ namespace core::gfx::conversion return GL_TESS_EVALUATION_SHADER; break; } - assert(false); + psl_assert(false, "reached end of core::gfx::conversion::to_gles"); return -1; } @@ -56,7 +56,7 @@ namespace core::gfx::conversion return shader_stage::tesselation_evaluation; break; } - assert(false); + psl_assert(false, "reached end of core::gfx::conversion::to_shader_stage"); return shader_stage {}; } @@ -78,8 +78,7 @@ namespace core::gfx::conversion } else if(static_cast(memory) & static_cast(memory_usage::conditional_rendering)) { - assert(false); - // not implemented + psl::not_implemented(); } else if(static_cast(memory) & static_cast(memory_usage::index_buffer)) { @@ -98,7 +97,7 @@ namespace core::gfx::conversion return GL_UNIFORM_BUFFER; } - assert(false); + psl_assert(false, "reached end of core::gfx::conversion::to_gles"); return -1; } @@ -1023,60 +1022,60 @@ namespace core::gfx::conversion break; } - // case GL_UNSIGNED_BYTE_3_3_2: assert(format == GL_RGB || format == GL_RGB_INTEGER); return - // core::gfx::format_t::undefined; case GL_UNSIGNED_BYTE_2_3_3_REV: assert(format == GL_BGR || format == - // GL_BGR_INTEGER); + // case GL_UNSIGNED_BYTE_3_3_2: psl_assert(format == GL_RGB || format == GL_RGB_INTEGER, "format failed check"); return + // core::gfx::format_t::undefined; case GL_UNSIGNED_BYTE_2_3_3_REV: psl_assert(format == GL_BGR || format == + // GL_BGR_INTEGER, "format failed check"); // return core::gfx::format_t::undefined; case GL_UNSIGNED_SHORT_5_6_5: - assert(format == GL_RGB || format == GL_RGB_INTEGER); + psl_assert(format == GL_RGB || format == GL_RGB_INTEGER, "format failed check"); return core::gfx::format_t::r5g6b5_unorm_pack16; // case GL_UNSIGNED_SHORT_5_6_5_REV: - // assert(format == GL_BGR || format == GL_BGR_INTEGER); + // psl_assert(format == GL_BGR || format == GL_BGR_INTEGER, "format failed check"); // return core::gfx::format_t::b5g6r5_unorm_pack16; case GL_UNSIGNED_SHORT_4_4_4_4: - assert(format == GL_RGB /*|| format == GL_BGRA*/ || - format == GL_RGB_INTEGER /*|| format == GL_BGRA_INTEGER*/); + psl_assert(format == GL_RGB /*|| format == GL_BGRA*/ || + format == GL_RGB_INTEGER /*|| format == GL_BGRA_INTEGER*/, "format failed check"); return core::gfx::format_t::r4g4b4a4_unorm_pack16; // case GL_UNSIGNED_SHORT_4_4_4_4_REV: - // assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER); + // psl_assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER); // return core::gfx::format_t::b4g4r4a4_unorm_pack16; case GL_UNSIGNED_SHORT_5_5_5_1: - assert(format == GL_RGB /*|| format == GL_BGRA*/ || - format == GL_RGB_INTEGER /*|| format == GL_BGRA_INTEGER*/); + psl_assert(format == GL_RGB /*|| format == GL_BGRA*/ || + format == GL_RGB_INTEGER /*|| format == GL_BGRA_INTEGER*/, "format failed check"); return core::gfx::format_t::r5g5b5a1_unorm_pack16; // case GL_UNSIGNED_SHORT_1_5_5_5_REV: - // assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER); + // psl_assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER, "format failed check"); // return core::gfx::format_t::a1r5g5b5_unorm_pack16; // case GL_UNSIGNED_INT_8_8_8_8: - // assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER); + // psl_assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER, "format failed check"); // return (format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER) ? core::gfx::format_t::r8g8b8a8_uint // : core::gfx::format_t::r8g8b8a8_unorm; // case GL_UNSIGNED_INT_8_8_8_8_REV: - // assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER); + // psl_assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER, "format failed check"); // return (format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER) ? core::gfx::format_t::a8b8g8r8_uint_pack32 // : core::gfx::format_t::a8b8g8r8_unorm_pack32; // case GL_UNSIGNED_INT_10_10_10_2: - // assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER); + // psl_assert(format == GL_RGB || format == GL_BGRA || format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER, "format failed check"); // return (format == GL_RGB_INTEGER || format == GL_BGRA_INTEGER) // ? core::gfx::format_t::a2r10g10b10_uint_pack32 // : core::gfx::format_t::a2r10g10b10_unorm_pack32; case GL_UNSIGNED_INT_2_10_10_10_REV: - assert(format == GL_RGB /*|| format == GL_BGRA*/ || - format == GL_RGB_INTEGER /*|| format == GL_BGRA_INTEGER*/); + psl_assert(format == GL_RGB /*|| format == GL_BGRA*/ || + format == GL_RGB_INTEGER /*|| format == GL_BGRA_INTEGER*/, "format failed check"); return (format == GL_RGB_INTEGER /*|| format == GL_BGRA_INTEGER*/) ? core::gfx::format_t::a2b10g10r10_uint_pack32 : core::gfx::format_t::a2b10g10r10_unorm_pack32; case GL_UNSIGNED_INT_10F_11F_11F_REV: - assert(format == GL_RGB /*|| format == GL_BGR*/); + psl_assert(format == GL_RGB /*|| format == GL_BGR*/, "format failed check"); return core::gfx::format_t::b10g11r11_ufloat_pack32; case GL_UNSIGNED_INT_5_9_9_9_REV: - assert(format == GL_RGB /*|| format == GL_BGR*/); + psl_assert(format == GL_RGB /*|| format == GL_BGR*/, "format failed check"); return core::gfx::format_t::e5b9g9r9_ufloat_pack32; case GL_UNSIGNED_INT_24_8: - assert(format == GL_DEPTH_STENCIL); + psl_assert(format == GL_DEPTH_STENCIL, "format failed check"); return core::gfx::format_t::d24_unorm_s8_uint; case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: - assert(format == GL_DEPTH_STENCIL); + psl_assert(format == GL_DEPTH_STENCIL, "format failed check"); return core::gfx::format_t::d32_sfloat_s8_uint; } switch(internalFormat) @@ -1295,7 +1294,7 @@ namespace core::gfx::conversion #endif } - assert(false); + psl_assert(false, "core::gfx::conversion::to_gles"); return GL_REPEAT; } @@ -1347,7 +1346,7 @@ namespace core::gfx::conversion return GL_FRONT_AND_BACK; break; } - assert(false); + psl_assert(false, "core::gfx::conversion::to_gles"); return GL_BACK; } @@ -1380,7 +1379,7 @@ namespace core::gfx::conversion return GL_ALWAYS; break; } - assert(false); + psl_assert(false, "core::gfx::conversion::to_gles"); return GL_NEVER; } @@ -1414,7 +1413,7 @@ namespace core::gfx::conversion break; #endif } - assert(false); + psl_assert(false, "core::gfx::conversion::to_gles"); return GL_LINEAR; } @@ -1438,7 +1437,7 @@ namespace core::gfx::conversion return GL_MAX; break; } - assert(false); + psl_assert(false, "core::gfx::conversion::to_gles"); return GL_FUNC_ADD; } @@ -1492,7 +1491,7 @@ namespace core::gfx::conversion return GL_SRC_ALPHA_SATURATE; break; } - assert(false); + psl_assert(false, "core::gfx::conversion::to_gles"); return GL_FUNC_ADD; } } // namespace core::gfx::conversion \ No newline at end of file diff --git a/core/inc/meta/texture.hpp b/core/inc/meta/texture.hpp index ae5b319e..68c4f549 100644 --- a/core/inc/meta/texture.hpp +++ b/core/inc/meta/texture.hpp @@ -108,7 +108,7 @@ namespace core::meta s << m_Width << m_Height << m_Depth << m_MipLevels << m_LayerCount << m_Format << m_ImageType << m_UsageFlags << m_AspectMask; - assert((uint32_t)m_Format.value <= 97 || (uint32_t)m_Format.value >= 120); + psl_assert((uint32_t)m_Format.value <= 97 || (uint32_t)m_Format.value >= 120, "format should be <= 98 or >= 120, but was {}", m_Format.value); } /// \brief validates this texture bool validate() const noexcept; diff --git a/core/inc/os/context.hpp b/core/inc/os/context.hpp index f0ee49c0..d26a262f 100644 --- a/core/inc/os/context.hpp +++ b/core/inc/os/context.hpp @@ -28,6 +28,7 @@ namespace core::os { class context { + public: bool tick() noexcept { return true; } }; } diff --git a/core/inc/resource/handle.hpp b/core/inc/resource/handle.hpp index 6a8ae785..36c2e1b3 100644 --- a/core/inc/resource/handle.hpp +++ b/core/inc/resource/handle.hpp @@ -45,7 +45,7 @@ namespace core::resource } if(m_MetaData) { - assert_debug_break(m_MetaData->reference_count != 0); + psl_assert(m_MetaData->reference_count != 0, "reference count was {}, but should be != 0", m_MetaData->reference_count); m_MetaData->reference_count -= 1; } }; @@ -112,13 +112,13 @@ namespace core::resource inline value_type& value() noexcept { - assert_debug_break(state() == status::loaded); + psl_assert(state() == status::loaded, "state was expected to be loaded, but was {}", state()); return *m_Resource; } inline const value_type& value() const noexcept { - assert_debug_break(state() == status::loaded); + psl_assert(state() == status::loaded, "state was expected to be loaded, but was {}", state()); return *m_Resource; } @@ -367,7 +367,6 @@ namespace core::resource handle make_shared() const noexcept { - assert_debug_break(*this); return handle((void*)m_Resource, m_Cache, m_MetaData, (psl::meta::file*)m_MetaFile); } diff --git a/core/inc/stdafx.hpp b/core/inc/stdafx.hpp index ca349c33..b309d852 100644 --- a/core/inc/stdafx.hpp +++ b/core/inc/stdafx.hpp @@ -49,6 +49,7 @@ #include "psl/math/math.hpp" #include "psl/meta.hpp" #include "psl/serialization/serializer.hpp" +#include "psl/assertions.hpp" #include "resource/resource.hpp" #include "data/stream.hpp" @@ -66,14 +67,6 @@ #endif -#ifdef RELEASE -#ifdef assert -#undef assert - -#define assert () -#endif -#endif - #define STRINGIZE_HELPER(x) #x #define STRINGIZE(x) STRINGIZE_HELPER(x) #define CMP_ISSUE(number, desc) \ diff --git a/core/inc/utility/geometry.hpp b/core/inc/utility/geometry.hpp index e1e62e1c..d2ed77a5 100644 --- a/core/inc/utility/geometry.hpp +++ b/core/inc/utility/geometry.hpp @@ -1327,7 +1327,7 @@ namespace utility::geometry psl::quat rotation, psl::string_view channel = core::data::geometry_t::constants::POSITION) { - assert(source->vertices(channel).has_value()); + psl_assert(source->vertices(channel).has_value(), "missing vertices channel '{}' in source", channel); source->transform(channel, [rotation](psl::vec3& value) mutable { value = psl::math::rotate(rotation, value); }); return source; @@ -1339,7 +1339,7 @@ namespace utility::geometry T scale, psl::string_view channel = core::data::geometry_t::constants::POSITION) { - assert(source->vertices(channel).has_value()); + psl_assert(source->vertices(channel).has_value(), "missing vertices channel '{}' in source", channel); source->transform(channel, [scale](T& value) mutable { value *= scale; }); return source; } @@ -1350,7 +1350,7 @@ namespace utility::geometry T translation, psl::string_view channel = core::data::geometry_t::constants::POSITION) { - assert(source->vertices(channel).has_value()); + psl_assert(source->vertices(channel).has_value(), "missing vertices channel '{}' in source", channel); source->transform(channel, [translation](T& value) mutable { value += translation; }); return source; } @@ -1359,7 +1359,7 @@ namespace utility::geometry psl::string_view source, psl::string_view destination) { - assert(geom->vertices(source).has_value()); + psl_assert(geom->vertices(source).has_value(), "missing vertices channel '{}' in geom", source); geom->vertices(destination, geom->vertices(source).value()); return geom; } diff --git a/core/inc/vk/conversion.hpp b/core/inc/vk/conversion.hpp index 40409a64..13f1b593 100644 --- a/core/inc/vk/conversion.hpp +++ b/core/inc/vk/conversion.hpp @@ -60,7 +60,7 @@ namespace core::gfx::conversion return vk::VertexInputRate::eInstance; break; } - assert(false); + psl::unreachable(); return vk::VertexInputRate::eVertex; } @@ -75,7 +75,7 @@ namespace core::gfx::conversion return vertex_input_rate::instance; break; } - assert(false); + psl::unreachable(); return vertex_input_rate::vertex; } inline vk::BufferUsageFlags to_vk(memory_usage memory) noexcept @@ -240,7 +240,7 @@ namespace core::gfx::conversion break; } - assert(false); + psl::unreachable(); return vk::ImageViewType::e1D; } @@ -271,7 +271,7 @@ namespace core::gfx::conversion break; } - assert(false); + psl::unreachable(); return image_type::planar_1D; } @@ -302,7 +302,7 @@ namespace core::gfx::conversion break; } - assert(false); + psl::unreachable(); return vk::ImageType::e1D; } inline vk::ImageAspectFlags to_vk(image_aspect value) noexcept @@ -775,9 +775,8 @@ namespace core::gfx::conversion case VK_FORMAT_UNDEFINED: return format_t::undefined; break; - default: - assert(false); } + psl::unreachable(); return format_t::undefined; } inline vk::Format to_vk(format_t value) noexcept @@ -1315,7 +1314,7 @@ namespace core::gfx::conversion return vk::DescriptorType::eInputAttachment; break; } - assert(false); + psl::unreachable(); return vk::DescriptorType {0}; } @@ -1357,7 +1356,7 @@ namespace core::gfx::conversion return binding_type::input_attachment; break; } - assert(false); + psl::unreachable(); return binding_type {0}; } inline vk::BlendOp to_vk(blend_op value) noexcept @@ -1405,7 +1404,7 @@ namespace core::gfx::conversion break; } - assert(false); + psl::unreachable(); return vk::AttachmentStoreOp {0}; } diff --git a/core/inc/vk/ivk.hpp b/core/inc/vk/ivk.hpp index 5165045f..8101ded0 100644 --- a/core/inc/vk/ivk.hpp +++ b/core/inc/vk/ivk.hpp @@ -31,7 +31,7 @@ #include "psl/logging.hpp" #include "psl/ustring.hpp" -#include +#include "psl/assertions.hpp" #include // Set to "true" to use staging buffers for uploading @@ -521,25 +521,14 @@ namespace utility::vulkan { inline bool check(const vk::Result& value) { - if(value != vk::Result::eSuccess) - { - LOG_FATAL("vk::Result is \"", vk::to_string(value), "\" in ", __FILE__, " at line ", __LINE__); - assert(value == vk::Result::eSuccess); - return false; - } - - return true; + psl_assert(value == vk::Result::eSuccess, "vk::Result expected success, but got {}", vk::to_string(value)); + return value == vk::Result::eSuccess; } inline bool check(const VkResult& value) { - if(value != VkResult::VK_SUCCESS) - { - LOG_FATAL("vk::Result is \"", vk::to_string((vk::Result)value), "\" in ", __FILE__, " at line ", __LINE__); - assert(value == VkResult::VK_SUCCESS); - return false; - } - return true; + psl_assert(value == VkResult::VK_SUCCESS, "vk::Result expected success, but got {}", vk::to_string((vk::Result)value)); + return value == VkResult::VK_SUCCESS; } template diff --git a/core/main/main.cpp b/core/main/main.cpp index 21155e2f..961a5107 100755 --- a/core/main/main.cpp +++ b/core/main/main.cpp @@ -7,6 +7,7 @@ //#include //#include "stdafx.h" #include "psl/application_utils.hpp" +#include "psl/platform_utils.hpp" #include "psl/library.hpp" #include "resource/resource.hpp" @@ -112,7 +113,7 @@ void load_texture(resource::cache_t& cache, handle context_h if(!cache.contains(texture)) { auto textureHandle = cache.instantiate(texture, context_handle); - assert(textureHandle); + psl_assert(textureHandle, "invalid textureHandle"); } } @@ -306,12 +307,12 @@ void setup_loggers() #include "spdlog/sinks/android_sink.h" void setup_loggers() { - core::log = spdlog::android_logger_mt("main"); - core::systems::log = spdlog::android_logger_mt("systems"); - core::os::log = spdlog::android_logger_mt("os"); - core::data::log = spdlog::android_logger_mt("data"); - core::gfx::log = spdlog::android_logger_mt("gfx"); - core::ivk::log = spdlog::android_logger_mt("ivk"); + core::log = spdlog::android_logger_mt("main", "paradigm"); + core::systems::log = spdlog::android_logger_mt("systems", "paradigm"); + core::os::log = spdlog::android_logger_mt("os", "paradigm"); + core::data::log = spdlog::android_logger_mt("data", "paradigm"); + core::gfx::log = spdlog::android_logger_mt("gfx", "paradigm"); + core::ivk::log = spdlog::android_logger_mt("ivk", "paradigm"); spdlog::set_pattern("[%8T:%6f] [%=8l] %^%v%$ %@", spdlog::pattern_time_type::utc); } @@ -333,7 +334,9 @@ int entry(gfx::graphics_backend backend, core::os::context& os_context) break; } + core::log->info("creating cache"); cache_t cache {psl::meta::library {psl::to_string8_t(libraryPath), {{environment}}}}; + core::log->info("cache created"); // cache cache{psl::meta::library{psl::to_string8_t(libraryPath), {{environment}}}, resource_region.allocator()}; auto window_data = cache.instantiate("cd61ad53-5ac8-41e9-a8a2-1d20b43376d9"_uid); @@ -933,11 +936,16 @@ ECSState.create( #if defined(PLATFORM_ANDROID) +// todo move to os context +AAssetManager* utility::platform::file::ANDROID_ASSET_MANAGER = nullptr; + void android_main(android_app* application) { auto os_context = core::os::context{application}; + utility::platform::file::ANDROID_ASSET_MANAGER = application->activity->assetManager; setup_loggers(); std::srand(0); + entry(graphics_backend::vulkan, os_context); return; } diff --git a/core/src/ecs/systems/text.cpp b/core/src/ecs/systems/text.cpp index 394a06c3..b48a0ae9 100644 --- a/core/src/ecs/systems/text.cpp +++ b/core/src/ecs/systems/text.cpp @@ -158,7 +158,7 @@ core::resource::handle text::create_text(psl::string_vie const auto max_char = character_data.size() + 32; for(int character : text) { - assert((character >= 32 && character < max_char) || character == '\n' || character == '\t'); + psl_assert((character >= 32 && character < max_char) || character == '\n' || character == '\t', "illegal character '{}' used", (char)character); } } diff --git a/core/src/gfx/compute.cpp b/core/src/gfx/compute.cpp index a3d2f6b3..f9b3571e 100644 --- a/core/src/gfx/compute.cpp +++ b/core/src/gfx/compute.cpp @@ -39,7 +39,7 @@ compute::compute(core::resource::cache_t& cache, break; #endif #ifdef PE_VULKAN - assert(true && "todo implement vulkan backend"); + psl::not_implemented("todo implement vulkan backend"); /*case graphics_backend::vulkan: m_Handle << cache.create_using(metaData.uid, context_handle->resource().get(), diff --git a/core/src/gles/compute.cpp b/core/src/gles/compute.cpp index 0d843d4a..a952a209 100644 --- a/core/src/gles/compute.cpp +++ b/core/src/gles/compute.cpp @@ -25,14 +25,18 @@ compute::compute(cache_t& cache, core::resource::handle program_cache) : m_Meta(metaFile) { - assert(data->stages().size() == 1 && data->stages()[0].shader_stage() == core::gfx::shader_stage::compute); + psl_assert(data->stages().size() == 1 && data->stages()[0].shader_stage() == core::gfx::shader_stage::compute, + "shader stages {} and stage name {} did not match assertion", + data->stages().size(), + utility::to_string(data->stages()[0].shader_stage())); auto& stage = data->stages()[0]; auto shader_handle = cache.find(stage.shader()); if(!shader_handle) { - core::igles::log->warn("igles::material_t [{0}] uses a shader [{1}] that cannot be found in the resource cache.", - utility::to_string(metaData.uid), - utility::to_string(stage.shader())); + core::igles::log->warn( + "igles::material_t [{0}] uses a shader [{1}] that cannot be found in the resource cache.", + utility::to_string(metaData.uid), + utility::to_string(stage.shader())); core::igles::log->info("trying to load shader [{0}].", utility::to_string(stage.shader())); diff --git a/core/src/gles/framebuffer.cpp b/core/src/gles/framebuffer.cpp index 2a9ebcb4..1455b683 100644 --- a/core/src/gles/framebuffer.cpp +++ b/core/src/gles/framebuffer.cpp @@ -26,13 +26,11 @@ framebuffer_t::framebuffer_t(core::resource::cache_t& cache, if(!m_Sampler) { core::ivk::log->error("could not load sampler for framebuffer {0}", metaData.uid); - assert(false); } } else { core::ivk::log->error("could not load sampler for framebuffer {0}", metaData.uid); - assert(false); } glGenFramebuffers(m_Framebuffers.size(), m_Framebuffers.data()); @@ -43,7 +41,7 @@ framebuffer_t::framebuffer_t(core::resource::cache_t& cache, if(texture.state() != core::resource::status::loaded) texture = cache.create_using(attach.texture()); - assert_debug_break(!attach.shared()); + psl_assert(!attach.shared(), "attachment isn't allowed to be shared"); auto count = attach.shared() ? 1u : m_Framebuffers.size(); binding& binding = m_Bindings.emplace_back(); diff --git a/core/src/gles/geometry.cpp b/core/src/gles/geometry.cpp index 46ad9b20..d77d2644 100644 --- a/core/src/gles/geometry.cpp +++ b/core/src/gles/geometry.cpp @@ -81,13 +81,13 @@ void geometry_t::recreate(core::resource::handle data) core::igles::log->critical("ran out of memory, could not allocate enough in the buffer to accomodate"); exit(1); } - assert(data->vertex_streams().size() > 0); + psl_assert(data->vertex_streams().size() > 0, "expected size 0, but got {}", data->vertex_streams().size()); m_Vertices = std::begin(data->vertex_streams())->second.size(); std::vector instructions; auto current_segment = std::begin(segments); for(const auto& stream : data->vertex_streams()) { - assert(m_Vertices == stream.second.size()); + psl_assert(m_Vertices == stream.second.size(), "{} did not match {}", m_Vertices, stream.second.size()); auto& instr = instructions.emplace_back(); instr.size = stream.second.bytesize(); instr.destination_offset = current_segment->first.range().begin + current_segment->second.begin; diff --git a/core/src/gles/material.cpp b/core/src/gles/material.cpp index b1156471..c12ae888 100644 --- a/core/src/gles/material.cpp +++ b/core/src/gles/material.cpp @@ -65,7 +65,6 @@ material_t::material_t(core::resource::cache_t& cache, case core::gfx::binding_type::combined_image_sampler: { auto binding_slot = glGetUniformLocation(m_Program->id(), meta->descriptors()[index].name().data()); - // assert(binding_slot != -1); if(auto sampler_handle = cache.find(binding.sampler()); sampler_handle) { diff --git a/core/src/gles/texture.cpp b/core/src/gles/texture.cpp index edadfc98..0c3895a3 100644 --- a/core/src/gles/texture.cpp +++ b/core/src/gles/texture.cpp @@ -176,14 +176,11 @@ void texture_t::create_2D(void* data) if(data != nullptr) { + psl_assert(type != 0, "type was 0"); if(type != 0) { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_Meta->width(), m_Meta->height(), format, type, data); } - else - { - assert_debug_break(false); - } if(pixel_storage != 4) glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } diff --git a/core/src/os/context_android.cpp b/core/src/os/context_android.cpp index cbb8f2f9..13511bc2 100644 --- a/core/src/os/context_android.cpp +++ b/core/src/os/context_android.cpp @@ -1,8 +1,8 @@ #define PLATFORM_ANDROID #include #include +#include #include "os/context.hpp" -#include static void engine_handle_cmd(struct android_app* app, int32_t cmd) { switch (cmd) { @@ -87,7 +87,7 @@ ASensorManager* AcquireASensorManagerInstance(android_app* app) { auto getInstanceFunc = (PF_GETINSTANCE) dlsym(androidHandle, "ASensorManager_getInstance"); // by all means at this point, ASensorManager_getInstance should be available - assert(getInstanceFunc); + psl_assert(getInstanceFunc, "Could not find ASensorManager_getInstance"); dlclose(androidHandle); return getInstanceFunc(); diff --git a/core/src/os/surface_win32.cpp b/core/src/os/surface_win32.cpp index 48959a30..052dae07 100644 --- a/core/src/os/surface_win32.cpp +++ b/core/src/os/surface_win32.cpp @@ -3,7 +3,6 @@ #include "psl/assertions.hpp" #include "systems/input.hpp" #include -#include using namespace core::os; using namespace core; @@ -13,8 +12,8 @@ uint64_t surface::win32_class_id_counter {0}; bool surface::init_surface() { WNDCLASSEX win_class {}; - assert(m_Data->width() > 0); - assert(m_Data->height() > 0); + psl_assert(m_Data->width() > 0, "attempted to make a surface with width: {}", m_Data->width()); + psl_assert(m_Data->height() > 0, "attempted to make a surface with height: {}", m_Data->height()); int width = m_Data->width(); int height = m_Data->height(); @@ -42,7 +41,7 @@ bool surface::init_surface() if(!RegisterClassEx(&win_class)) { // It didn't work, so try to give a useful error: - assert(0 && "Cannot create a window in which to draw!\n"); + psl::unreachable("Cannot create a window in which to draw!") fflush(stdout); std::exit(-1); } diff --git a/core/src/os/surface_xcb.cpp b/core/src/os/surface_xcb.cpp index 5e43f1c6..a0dfa018 100644 --- a/core/src/os/surface_xcb.cpp +++ b/core/src/os/surface_xcb.cpp @@ -34,8 +34,8 @@ bool surface::init_surface() screen = iter.data; uint32_t value_mask, value_list[32]; - assert(m_Data->width() > 0); - assert(m_Data->height() > 0); + psl_assert(m_Data->width() > 0, "window surface width wasn't larger than 0, it was '{}'", m_Data->width()); + psl_assert(m_Data->height() > 0, "window surface height wasn't larger than 0, it was '{}'", m_Data->height()); _xcb_window = xcb_generate_id(_xcb_connection); diff --git a/core/src/vk/context.cpp b/core/src/vk/context.cpp index cf31b45b..da719359 100644 --- a/core/src/vk/context.cpp +++ b/core/src/vk/context.cpp @@ -157,10 +157,10 @@ context::context(core::resource::cache_t& cache, vk::ApplicationInfo appInfo; appInfo.pApplicationName = name.data(); - appInfo.pEngineName = APPLICATION_NAME.data(); - assert_debug_break(VERSION_MAJOR < std::pow(2, 10)); - assert_debug_break(VERSION_MINOR < std::pow(2, 10)); - assert_debug_break(VERSION_PATCH < std::pow(2, 12)); + appInfo.pEngineName = APPLICATION_NAME.data(); + psl_assert(VERSION_MAJOR < std::pow(2, 10), "VERSION_MAJOR {} was higher than {}", VERSION_MAJOR, std::pow(2, 10)); + psl_assert(VERSION_MINOR < std::pow(2, 10), "VERSION_MINOR {} was higher than {}", VERSION_MINOR, std::pow(2, 10)); + psl_assert(VERSION_PATCH < std::pow(2, 12), "VERSION_PATCH {} was higher than {}", VERSION_PATCH, std::pow(2, 12)); appInfo.engineVersion = (((VERSION_MAJOR) << 22) | ((VERSION_MINOR) << 12) | (VERSION_PATCH)); appInfo.apiVersion = VK_API_VERSION_LATEST; diff --git a/core/src/vk/drawpass.cpp b/core/src/vk/drawpass.cpp index f1de563a..aa0b9433 100644 --- a/core/src/vk/drawpass.cpp +++ b/core/src/vk/drawpass.cpp @@ -321,7 +321,7 @@ void drawpass::present() // Signal ready with offscreen semaphore m_SubmitInfo.pSignalSemaphores = &m_RenderComplete; - assert(m_DrawCommandBuffers[m_CurrentBuffer]); + psl_assert(m_DrawCommandBuffers[m_CurrentBuffer], "m_DrawCommandBuffers[{}] was not valid", m_CurrentBuffer); m_SubmitInfo.pCommandBuffers = &m_DrawCommandBuffers[m_CurrentBuffer]; m_SubmitInfo.commandBufferCount = 1; diff --git a/core/src/vk/framebuffer.cpp b/core/src/vk/framebuffer.cpp index 44ab1c4d..0a622b78 100644 --- a/core/src/vk/framebuffer.cpp +++ b/core/src/vk/framebuffer.cpp @@ -37,7 +37,6 @@ framebuffer_t::framebuffer_t(core::resource::cache_t& cache, if(!m_Sampler) { core::ivk::log->error("could not load sampler {0} for framebuffer {1}", m_Sampler.uid(), metaData.uid); - assert(false); } // now we create the renderpass that describes the framebuffer @@ -60,8 +59,7 @@ framebuffer_t::framebuffer_t(core::resource::cache_t& cache, if(utility::vulkan::has_depth(binding.description.format) || utility::vulkan::has_stencil(binding.description.format)) { - // Only one depth attachment allowed - // assert(!hasDepth); + psl_assert(!hasDepth, "Only one depth attachment allowed"); depthReference.attachment = attachmentIndex; depthReference.layout = vk::ImageLayout::eDepthStencilAttachmentOptimal; hasDepth = true; diff --git a/core/src/vk/geometry.cpp b/core/src/vk/geometry.cpp index 975c7dd6..f79f97a9 100644 --- a/core/src/vk/geometry.cpp +++ b/core/src/vk/geometry.cpp @@ -76,13 +76,13 @@ void geometry_t::recreate(core::resource::handle data) core::ivk::log->critical("ran out of memory, could not allocate enough in the buffer to accomodate"); exit(1); } - assert(data->vertex_streams().size() > 0); + psl_assert(data->vertex_streams().size() > 0, "sizeof vertex streams was not larger than 0, it was '{}'", data->vertex_streams().size()); m_Vertices = std::begin(data->vertex_streams())->second.size(); std::vector instructions; size_t i = 0; for(const auto& stream : data->vertex_streams()) { - assert(m_Vertices == stream.second.size()); + psl_assert(m_Vertices == stream.second.size(), "{} did not match {}", m_Vertices, stream.second.size()); auto& instr = instructions.emplace_back(); instr.size = stream.second.bytesize(); instr.source = (std::uintptr_t)(stream.second.cdata()); diff --git a/core/src/vk/pipeline.cpp b/core/src/vk/pipeline.cpp index 2e238cdc..0ebecb09 100644 --- a/core/src/vk/pipeline.cpp +++ b/core/src/vk/pipeline.cpp @@ -235,7 +235,7 @@ pipeline::pipeline(core::resource::cache_t& cache, if(m_BindPoint == vk::PipelineBindPoint::eCompute) { - assert(shaderStages.size() == 1 && "expecting only a single compute in the shader stages"); + psl_assert(shaderStages.size() == 1, "expecting only a single compute in the shader stages, but got {}", shaderStages.size()); vk::ComputePipelineCreateInfo pipelineCreateInfo {}; pipelineCreateInfo.layout = m_PipelineLayout; diff --git a/core/src/vk/texture.cpp b/core/src/vk/texture.cpp index 7e78cd76..36cc08da 100644 --- a/core/src/vk/texture.cpp +++ b/core/src/vk/texture.cpp @@ -121,7 +121,7 @@ vk::DescriptorImageInfo& texture_t::descriptor(const UID& sampler) } auto samplerHandle = m_Cache.find(sampler); - assert(samplerHandle); + psl_assert(samplerHandle, "invalid samplerHandle"); vk::DescriptorImageInfo* descriptor = new vk::DescriptorImageInfo(); descriptor->sampler = samplerHandle->get(mip_levels()); diff --git a/psl/inc/psl/assertions.hpp b/psl/inc/psl/assertions.hpp index 0f72f13f..37b899ac 100644 --- a/psl/inc/psl/assertions.hpp +++ b/psl/inc/psl/assertions.hpp @@ -1,115 +1,182 @@ #pragma once #include "psl/ustring.hpp" -#include +#include + +#ifdef PLATFORM_ANDROID + #include +#endif // PLATFORM_ANDROID + +namespace psl +{ + enum class level_t + { + verbose, + debug, + info, + warn, + error, + fatal, + }; + template + constexpr void print(level_t level, const char* fmt = "failed assert", Args&&... args) + { +#ifdef PLATFORM_ANDROID + int log_level = ANDROID_LOG_SILENT; + switch(level) + { + case level_t::verbose: + log_level = ANDROID_LOG_VERBOSE; + break; + case level_t::debug: + log_level = ANDROID_LOG_DEBUG; + break; + case level_t::info: + log_level = ANDROID_LOG_INFO; + break; + case level_t::warn: + log_level = ANDROID_LOG_WARN; + break; + case level_t::error: + log_level = ANDROID_LOG_ERROR; + break; + case level_t::fatal: + log_level = ANDROID_LOG_FATAL; + break; + default: + log_level = ANDROID_LOG_SILENT; + } + __android_log_write(log_level, "paradigm", fmt::format(fmt, std::forward(args)...).c_str()); +#else + const char* log_level; + switch(level) + { + case level_t::verbose: + log_level = "[verbose] {}"; + break; + case level_t::debug: + log_level = "[debug] {}"; + break; + case level_t::info: + log_level = "[info] {}"; + break; + case level_t::warn: + log_level = "[warn] {}"; + break; + case level_t::error: + log_level = "[error] {}"; + break; + case level_t::fatal: + log_level = "[fatal] {}"; + break; + default: + log_level = "[info] {}"; + } + fmt::print(fmt::format(log_level, fmt), std::forward(args)...); +#endif + } + + [[noreturn]] constexpr void unreachable(const std::string& reason = "") + { + if(reason.empty()) + print(level_t::fatal, "unreachable code reached."); + else + print(level_t::fatal, "{}", reason); + std::terminate(); + } + + [[noreturn]] constexpr void not_implemented(size_t issue = 0) + { + if(issue != 0) + print(level_t::fatal, + "feature not implemented, follow development at https://github.com/JessyDL/paradigm/issues/{}", + issue); + else + print(level_t::fatal, "feature not implemented"); + std::terminate(); + } + + [[noreturn]] constexpr void not_implemented(const std::string& reason, size_t issue = 0) + { + if(issue != 0) + print(level_t::fatal, + "feature not implemented reason: '{}', follow development at " + "https://github.com/JessyDL/paradigm/issues/{}", + reason, + issue); + else + print(level_t::fatal, "feature not implemented reason: '{}'", reason); + std::terminate(); + } +} // namespace psl #if defined(HEDLEY_ALWAYS_INLINE) -#define DBG__ALWAYS_INLINE HEDLEY_ALWAYS_INLINE + #define DBG__ALWAYS_INLINE HEDLEY_ALWAYS_INLINE #elif defined(__GNUC__) && (__GNUC__ >= 4) -#define DBG__ALWAYS_INLINE inline __attribute__((__always_inline__)) + #define DBG__ALWAYS_INLINE inline __attribute__((__always_inline__)) #elif defined(_MSC_VER) && (_MSC_VER >= 1200) -#define DBG__ALWAYS_INLINE __forceinline + #define DBG__ALWAYS_INLINE __forceinline #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#define DBG__ALWAYS_INLINE inline + #define DBG__ALWAYS_INLINE inline #else -#define DBG__ALWAYS_INLINE + #define DBG__ALWAYS_INLINE #endif #define DBG__FUNCTION static DBG__ALWAYS_INLINE #if defined(PLATFORM_ANDROID) -#define debug_break() + #define debug_break() #else -#if defined(__has_builtin) && !defined(__ibmxl__) -#if __has_builtin(__builtin_debugtrap) -#define debug_break() __builtin_debugtrap() -#elif __has_builtin(__debugbreak) -#define debug_break() __debugbreak() -#endif -#endif -#if !defined(debug_break) -#if defined(_MSC_VER) || defined(__INTEL_COMPILER) -#define debug_break() __debugbreak() -#elif defined(__ARMCC_VERSION) -#define debug_break() __breakpoint(42) -#elif defined(__ibmxl__) || defined(__xlC__) -#include -#define debug_break() __trap(42) -#elif defined(__DMC__) && defined(_M_IX86) + #if defined(__has_builtin) && !defined(__ibmxl__) + #if __has_builtin(__builtin_debugtrap) + #define debug_break() __builtin_debugtrap() + #elif __has_builtin(__debugbreak) + #define debug_break() __debugbreak() + #endif + #endif + #if !defined(debug_break) + #if defined(_MSC_VER) || defined(__INTEL_COMPILER) + #define debug_break() __debugbreak() + #elif defined(__ARMCC_VERSION) + #define debug_break() __breakpoint(42) + #elif defined(__ibmxl__) || defined(__xlC__) + #include + #define debug_break() __trap(42) + #elif defined(__DMC__) && defined(_M_IX86) DBG__FUNCTION void debug_break(void) { __asm int 3h; } -#elif defined(__i386__) || defined(__x86_64__) + #elif defined(__i386__) || defined(__x86_64__) DBG__FUNCTION void debug_break(void) { __asm__ __volatile__("int $03"); } -#elif defined(__thumb__) + #elif defined(__thumb__) DBG__FUNCTION void debug_break(void) { __asm__ __volatile__(".inst 0xde01"); } -#elif defined(__aarch64__) + #elif defined(__aarch64__) DBG__FUNCTION void debug_break(void) { __asm__ __volatile__(".inst 0xd4200000"); } -#elif defined(__arm__) + #elif defined(__arm__) DBG__FUNCTION void debug_break(void) { __asm__ __volatile__(".inst 0xe7f001f0"); } -#elif defined(__alpha__) && !defined(__osf__) + #elif defined(__alpha__) && !defined(__osf__) DBG__FUNCTION void debug_break(void) { __asm__ __volatile__("bpt"); } -#elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__) -#define debug_break() __builtin_trap() -#else -#include -#if defined(SIGTRAP) -#define debug_break() raise(SIGTRAP) -#else -#define debug_break() raise(SIGABRT) -#endif -#endif -#endif + #elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__) + #define debug_break() __builtin_trap() + #else + #include + #if defined(SIGTRAP) + #define debug_break() raise(SIGTRAP) + #else + #define debug_break() raise(SIGABRT) + #endif + #endif + #endif #endif #if defined(HEDLEY_LIKELY) -#define DBG_LIKELY(expr) HEDLEY_LIKELY(expr) + #define DBG_LIKELY(expr) HEDLEY_LIKELY(expr) #elif defined(__GNUC__) && (__GNUC__ >= 3) -#define DBG_LIKELY(expr) __builtin_expect(!!(expr), 1) -#else -#define DBG_LIKELY(expr) (!!(expr)) -#endif - -#if !defined(PE_DEBUG) || (PE_DEBUG == 0) -#define assert_debug_break(condition) \ - if(!(condition)) \ - { \ - debug_break(); \ - } -#else -#define assert_debug_break(condition) -#endif - -#ifdef assert -#undef assert -#ifdef PE_DEBUG -#define assert(expression, ...) if(!(expression)) { debug_break(); } -#else -#define assert(expression, ...) ((void)0) -#endif -#endif - -#ifdef PE_DEBUG -#ifdef PLATFORM_WINDOWS -#define psl_assert(expression, message) \ - (void)((!!(expression)) || \ - (_wassert((wchar_t*)(psl::string8::to_string16_t(psl::string8_t{message} + " in expression:" + #expression)).data(), \ - _CRT_WIDE(__FILE__), \ - (unsigned)(__LINE__)), \ - (debug_break(), 0)) -#else -#define psl_assert(expression, message) assert(expression) -#endif + #define DBG_LIKELY(expr) __builtin_expect(!!(expr), 1) #else -#define psl_assert(expression, message) + #define DBG_LIKELY(expr) (!!(expr)) #endif -#if !defined(PE_DEBUG) || (PE_DEBUG == 0) -#define dbg_assert(expr) \ - do \ - { \ - if(!DBG_LIKELY(expr)) \ - { \ - trap(); \ - } \ - } while(0) +#if defined(PE_DEBUG) +#define psl_assert(expression, ...) \ + (void)((!!(expression)) || (psl::print(psl::level_t::fatal, __VA_ARGS__), 0) || (std::terminate(), 0)) #else -#define dbg_assert(expr) +#define psl_assert(expression, ...) #endif \ No newline at end of file diff --git a/psl/inc/psl/async/details/description.hpp b/psl/inc/psl/async/details/description.hpp index 82b8bbc2..753ab697 100644 --- a/psl/inc/psl/async/details/description.hpp +++ b/psl/inc/psl/async/details/description.hpp @@ -74,7 +74,7 @@ namespace psl::async::details std::end(m_DynamicBarriers), std::back_inserter(m_Barriers), [](std::future& barrier) { - assert_debug_break(barrier.valid()); + psl_assert(barrier.valid(), "barrier was not valid"); return barrier.get(); }); m_DynamicBarriers.clear(); @@ -83,7 +83,7 @@ namespace psl::async::details std::end(m_SharedDynamicBarriers), std::back_inserter(m_Barriers), [](std::shared_future& barrier) { - assert_debug_break(barrier.valid()); + psl_assert(barrier.valid(), "barrier was not valid"); return barrier.get(); }); m_SharedDynamicBarriers.clear(); diff --git a/psl/inc/psl/collections/ring_array.hpp b/psl/inc/psl/collections/ring_array.hpp index 155f87c9..d9122632 100644 --- a/psl/inc/psl/collections/ring_array.hpp +++ b/psl/inc/psl/collections/ring_array.hpp @@ -91,7 +91,7 @@ namespace psl } iterator& operator-=(difference_type n) { - assert(n <= m_Index); + psl_assert(n <= m_Index, "expected index: {} to be larger than {}", m_Index, n); m_Index -= n; return *this; } diff --git a/psl/inc/psl/collections/static_ring_array.hpp b/psl/inc/psl/collections/static_ring_array.hpp index 618d2b31..74549cae 100644 --- a/psl/inc/psl/collections/static_ring_array.hpp +++ b/psl/inc/psl/collections/static_ring_array.hpp @@ -92,7 +92,7 @@ namespace psl } iterator& operator-=(difference_type n) { - assert(n <= m_Index); + psl_assert(n <= m_Index, "expected index: {} to be larger than {}", m_Index, n); m_Index -= n; return *this; } diff --git a/psl/inc/psl/delegate.hpp b/psl/inc/psl/delegate.hpp index 228c5d09..db623f55 100644 --- a/psl/inc/psl/delegate.hpp +++ b/psl/inc/psl/delegate.hpp @@ -7,7 +7,6 @@ #endif -#include #include #include #include diff --git a/psl/inc/psl/ecs/command_buffer.hpp b/psl/inc/psl/ecs/command_buffer.hpp index 149d1f12..3e78221f 100644 --- a/psl/inc/psl/ecs/command_buffer.hpp +++ b/psl/inc/psl/ecs/command_buffer.hpp @@ -317,7 +317,7 @@ namespace psl::ecs template void add_component(psl::array_view entities, psl::array_view data) { - assert(entities.size() == data.size()); + psl_assert(entities.size() == data.size(), "incorrect amount of data input compared to entities, expected {} but got {}", entities.size(), data.size()); create_storage(); static_assert(!std::is_empty_v, "no need to pass an array of tag types through, it's a waste of computing and memory"); diff --git a/psl/inc/psl/ecs/details/component_info.hpp b/psl/inc/psl/ecs/details/component_info.hpp index 7fc1e13c..b05924c8 100644 --- a/psl/inc/psl/ecs/details/component_info.hpp +++ b/psl/inc/psl/ecs/details/component_info.hpp @@ -3,13 +3,13 @@ #include "../entity.hpp" #include "component_key.hpp" #include "psl/array_view.hpp" -#include "psl/assertions.hpp" #include "psl/memory/sparse_array.hpp" #include "psl/sparse_array.hpp" #include "psl/sparse_indice_array.hpp" #include "psl/static_array.hpp" #include #include +#include "psl/assertions.hpp" namespace psl { template diff --git a/psl/inc/psl/ecs/details/staged_sparse_array.hpp b/psl/inc/psl/ecs/details/staged_sparse_array.hpp index 6c7ece73..da180297 100644 --- a/psl/inc/psl/ecs/details/staged_sparse_array.hpp +++ b/psl/inc/psl/ecs/details/staged_sparse_array.hpp @@ -80,7 +80,7 @@ namespace psl::ecs::details { index_t sparse_index, chunk_index; chunk_info_for(index, sparse_index, chunk_index); - assert(has(index)); + psl_assert(has(index), "missing index {} in sparse array", index); return ((T*)m_DenseData.data() + get_chunk_from_index(chunk_index)[sparse_index]); } @@ -88,7 +88,7 @@ namespace psl::ecs::details { index_t sparse_index, chunk_index; chunk_info_for(index, sparse_index, chunk_index); - assert(has(index)); + psl_assert(has(index), "missing index {} in sparse array", index); return ((T*)m_DenseData.data() + get_chunk_from_index(chunk_index)[sparse_index]); } @@ -97,7 +97,7 @@ namespace psl::ecs::details { index_t sparse_index, chunk_index; chunk_info_for(index, sparse_index, chunk_index); - assert(has(index, startIndex, endIndex)); + psl_assert(has(index, startIndex, endIndex), "missing index {} within [{}, {}] in sparse array", index, startIndex, endIndex); return ((T*)m_DenseData.data() + get_chunk_from_index(chunk_index)[sparse_index]); } @@ -105,7 +105,7 @@ namespace psl::ecs::details { index_t sparse_index, chunk_index; chunk_info_for(index, sparse_index, chunk_index); - assert(has(index, startIndex, endIndex)); + psl_assert(has(index, startIndex, endIndex), "missing index {} within [{}, {}] in sparse array", index, startIndex, endIndex); return ((T*)m_DenseData.data() + get_chunk_from_index(chunk_index)[sparse_index]); } @@ -341,14 +341,14 @@ namespace psl::ecs::details template void remap(const psl::sparse_array& mapping, Fn&& predicate) { - assert(m_Reverse.size() >= mapping.size()); + psl_assert(m_Reverse.size() >= mapping.size(), "expected {} >= {}", m_Reverse.size(), mapping.size()); m_Sparse.clear(); m_CachedChunkUserIndex = std::numeric_limits::max(); for(index_t i = 0; i < static_cast(m_Reverse.size()); ++i) { if(std::invoke(predicate, m_Reverse[i])) { - assert(mapping.has(m_Reverse[i])); + psl_assert(mapping.has(m_Reverse[i]), "mapping didnt have the ID {}", m_Reverse[i]); auto new_index = mapping.at(m_Reverse[i]); auto offset = new_index; auto& chunk = chunk_for(offset); @@ -459,7 +459,7 @@ namespace psl::ecs::details auto orig_cap = m_Reverse.capacity(); m_Reverse.emplace(std::next(std::begin(m_Reverse), m_StageStart[2]), user_index); if(orig_cap != m_Reverse.capacity()) grow(); - assert_debug_break((m_Reverse.capacity() + 1) * sizeof(value_t) <= m_DenseData.size()); + psl_assert((m_Reverse.capacity() + 1) * sizeof(value_t) <= m_DenseData.size(), "{} <= {}", (m_Reverse.capacity() + 1) * sizeof(value_t), m_DenseData.size()); m_StageStart[2] += 1; m_StageStart[3] += 1; m_StageSize[1] += 1; @@ -501,7 +501,7 @@ namespace psl::ecs::details // if constexpr(std::is_same()) // assert(orig_value == this->at(user_index,2,2)); - assert(chunk[offset] == reverse_index); + psl_assert(chunk[offset] == reverse_index, "expected {} == {}", chunk[offset], reverse_index); } void grow() @@ -539,8 +539,8 @@ namespace psl::ecs::details m_Reverse.reserve((m_DenseData.size() / sizeof(T)) - 1); - assert_debug_break((m_Reverse.capacity() + 1) * sizeof(value_t) <= m_DenseData.size() && - (m_Reverse.capacity() + 2) * sizeof(value_t) >= m_DenseData.size()); + psl_assert((m_Reverse.capacity() + 1) * sizeof(value_t) <= m_DenseData.size() && + (m_Reverse.capacity() + 2) * sizeof(value_t) >= m_DenseData.size(), "capacity was not in line with density data"); } } @@ -811,14 +811,14 @@ namespace psl::ecs::details template void remap(const psl::sparse_array& mapping, Fn&& predicate) { - assert(m_Reverse.size() >= mapping.size()); + psl_assert(m_Reverse.size() >= mapping.size(), "expected {} >= {}", m_Reverse.size(), mapping.size()); m_Sparse.clear(); m_CachedChunkUserIndex = std::numeric_limits::max(); for(index_t i = 0; i < static_cast(m_Reverse.size()); ++i) { if(std::invoke(predicate, m_Reverse[i])) { - assert(mapping.has(m_Reverse[i])); + psl_assert(mapping.has(m_Reverse[i]), "mapping didnt have the ID {}", m_Reverse[i]); auto new_index = mapping.at(m_Reverse[i]); auto offset = new_index; auto& chunk = chunk_for(offset); @@ -902,7 +902,7 @@ namespace psl::ecs::details // if constexpr(std::is_same()) // assert(orig_value == this->at(user_index,2,2)); - assert(chunk[offset] == reverse_index); + psl_assert(chunk[offset] == reverse_index, "{} == {}", chunk[offset], reverse_index); } inline chunk_t& chunk_for(index_t& index) noexcept diff --git a/psl/inc/psl/ecs/state.hpp b/psl/inc/psl/ecs/state.hpp index 3a36279f..0a96a8e7 100644 --- a/psl/inc/psl/ecs/state.hpp +++ b/psl/inc/psl/ecs/state.hpp @@ -373,7 +373,7 @@ namespace psl::ecs template void set_component(psl::array_view entities, psl::array_view data) noexcept { - assert(entities.size() == data.size()); + psl_assert(entities.size() == data.size(), "incorrect amount of data input compared to entities, expected {} but got {}", entities.size(), data.size()); constexpr auto key = details::key_for(); auto cInfo = get_component_info(key); auto d = std::begin(data); @@ -626,7 +626,7 @@ namespace psl::ecs template void add_component(psl::array_view entities, psl::array_view data) { - assert(entities.size() == data.size()); + psl_assert(entities.size() == data.size(), "incorrect amount of data input compared to entities, expected {} but got {}", entities.size(), data.size()); create_storage(); static_assert(!std::is_empty_v, "no need to pass an array of tag types through, it's a waste of computing and memory"); diff --git a/psl/inc/psl/math/math.hpp b/psl/inc/psl/math/math.hpp index d79f257d..77b4ab27 100644 --- a/psl/inc/psl/math/math.hpp +++ b/psl/inc/psl/math/math.hpp @@ -586,9 +586,8 @@ namespace psl::math (mat[{1, 2}] + mat[{2, 1}]) * mult, biggestVal, (mat[{0, 1}] - mat[{1, 0}]) * mult); - default: // Silence a -Wswitch-default warning in GCC. Should never actually get here. Assert is just for - // sanity. - assert(false); + default: + psl::unreachable(); return tquat(0, 0, 0, 1); } } diff --git a/psl/inc/psl/math/matrix.hpp b/psl/inc/psl/math/matrix.hpp index a7e4f141..b5358b17 100644 --- a/psl/inc/psl/math/matrix.hpp +++ b/psl/inc/psl/math/matrix.hpp @@ -90,7 +90,7 @@ namespace psl constexpr tvec column(size_t index) const noexcept { - assert(index < columns_n && "out of range"); + psl_assert(index < columns_n, "out of range {} < {}", index, columns_n); tvec res {}; std::memcpy(res.value.data(), &value[index_of(0, index)], sizeof(precision_t) * column_length); return res; @@ -105,7 +105,7 @@ namespace psl constexpr void column(size_t index, const tvec& vector) noexcept { - assert(index < columns_n && "out of range"); + psl_assert(index < columns_n, "out of range {} < {}", index, columns_n); std::memcpy(&value[index_of(0, index)], vector.value.data(), sizeof(precision_t) * column_length); } @@ -120,7 +120,7 @@ namespace psl constexpr tvec row(size_t index) const noexcept { - assert(index < rows_n && "out of range"); + psl_assert(index < rows_n, "out of range {} < {}", index, rows_n); tvec res {}; for(size_t i = 0; i < row_length; ++i) res[i] = value[index_of(index, i)]; return res; @@ -135,7 +135,7 @@ namespace psl constexpr void row(size_t index, const tvec& vector) noexcept { - assert(index < rows_n && "out of range"); + psl_assert(index < rows_n, "out of range {} < {}", index, rows_n); for(size_t i = 0; i < row_length; ++i) value[index_of(index, i)] = vector[i]; } diff --git a/psl/inc/psl/memory/segment.hpp b/psl/inc/psl/memory/segment.hpp index 2648448c..99e64455 100644 --- a/psl/inc/psl/memory/segment.hpp +++ b/psl/inc/psl/memory/segment.hpp @@ -40,7 +40,7 @@ namespace memory void set(T&& value) { static_assert(std::is_trivial::value, "T should be a trivial type such as a POD data container."); - assert(sizeof(T) <= m_Range->size()); + psl_assert(sizeof(T) <= m_Range->size(), "{} <= {}", sizeof(T), m_Range->size()); if(!m_IsVirtual && is_valid()) std::memcpy((void*)m_Range->begin, &value, sizeof(T)); } @@ -48,7 +48,7 @@ namespace memory void set(const T& value) { static_assert(std::is_trivial::value, "T should be a trivial type such as a POD data container."); - assert(sizeof(T) <= m_Range->size()); + psl_assert(sizeof(T) <= m_Range->size(), "{} <= {}", sizeof(T), m_Range->size()); if(!m_IsVirtual && is_valid()) std::memcpy((void*)m_Range->begin, &value, sizeof(T)); } diff --git a/psl/inc/psl/memory/sparse_array.hpp b/psl/inc/psl/memory/sparse_array.hpp index ebdb083c..8907f786 100644 --- a/psl/inc/psl/memory/sparse_array.hpp +++ b/psl/inc/psl/memory/sparse_array.hpp @@ -140,7 +140,7 @@ namespace memory m_DenseData = std::move(reg); m_Reverse.reserve(m_DenseData.size() / sizeof(T)); - assert_debug_break(m_Reverse.capacity() * sizeof(T) <= m_DenseData.size()); + psl_assert(m_Reverse.capacity() * sizeof(T) <= m_DenseData.size(), "capacity was less than density"); } } @@ -177,8 +177,8 @@ namespace memory { index_type sparse_index, chunk_index; chunk_info_for(index, sparse_index, chunk_index); - assert_debug_break(m_Sparse.size() > chunk_index && m_Sparse[chunk_index].size() > 0 && - m_Sparse[chunk_index][sparse_index] != std::numeric_limits::max()); + psl_assert(m_Sparse.size() > chunk_index && m_Sparse[chunk_index].size() > 0 && + m_Sparse[chunk_index][sparse_index] != std::numeric_limits::max(), "unknown at location"); return *((T*)m_DenseData.data() + m_Sparse[chunk_index][sparse_index]); } @@ -341,7 +341,7 @@ namespace memory return; } - assert(std::all_of(&first, &last, [this](index_type i) { return has(i); })); + psl_assert(std::all_of(&first, &last, [this](index_type i) { return has(i); }), "expected all indices between {} and {} to be available", first, last); if(last - first == m_Reverse.size()) { diff --git a/psl/inc/psl/pack_view.hpp b/psl/inc/psl/pack_view.hpp index c7fbce33..799b9c1a 100644 --- a/psl/inc/psl/pack_view.hpp +++ b/psl/inc/psl/pack_view.hpp @@ -479,7 +479,7 @@ namespace psl pack_view(psl::array_view... views) : m_Pack(std::make_tuple(std::forward>(views)...)) { #ifdef PE_DEBUG - auto test = [](size_t size1, size_t size2) { assert_debug_break(size1 == size2); }; + auto test = [](size_t size1, size_t size2) { psl_assert(size1 == size2, "expected {} == {}", size1, size2); }; (test(views.size(), size()), ...); #endif } diff --git a/psl/inc/psl/platform_utils.hpp b/psl/inc/psl/platform_utils.hpp index 4b73f57a..ae5ad831 100644 --- a/psl/inc/psl/platform_utils.hpp +++ b/psl/inc/psl/platform_utils.hpp @@ -6,17 +6,7 @@ #include #include #include -#ifndef PLATFORM_ANDROID -#if __has_include() #include -#else -#include -namespace std::filesystem -{ - using namespace experimental::filesystem; -} -#endif -#endif #include #include #include @@ -24,6 +14,9 @@ namespace std::filesystem // https://en.wikipedia.org/wiki/Path_%28computing%29#Representations_of_paths_by_operating_system_and_shell +#if defined(PLATFORM_ANDROID) +struct AAssetManager; +#endif namespace utility { /// \brief contains some debug information, such as trace information, as well as utilities to debug. @@ -228,6 +221,8 @@ namespace utility::platform { #ifdef PLATFORM_WINDOWS return to_windows(path); +#elif defined(PLATFORM_ANDROID) + return psl::string{path}; #else return to_unix(path); #endif @@ -244,11 +239,7 @@ namespace utility::platform /// \todo android platform always returns false. Check if there is a way around this or redesign this. static bool is_directory(psl::string_view path) { -#ifdef PLATFORM_ANDROID - return false; -#else return std::filesystem::is_directory(to_platform(path)); -#endif } /// \brief sanitizes the seperators into the application wide standard one. @@ -264,11 +255,7 @@ namespace utility::platform /// \todo android platform always fails this, is it possible this is not always the case? inline static bool erase(psl::string_view path) { -#ifdef PLATFORM_ANDROID - return false; -#else return std::filesystem::remove(directory::to_platform(path)); -#endif } /// \brief checks if the given path (absolute) points to a directory or not. /// \param[in] absolutePath the path to check. @@ -292,9 +279,6 @@ namespace utility::platform /// generic path format. \todo on android no search is run. static std::vector all_files(psl::string_view target_directory, bool recursive) { -#ifdef PLATFORM_ANDROID - return {}; -#else auto folder = to_platform(target_directory); std::vector names; if(recursive) @@ -330,27 +314,22 @@ namespace utility::platform } } return names; -#endif } }; /// \brief file i/o and manpulations utilities namespace namespace file { + #if defined(PLATFORM_ANDROID) + extern AAssetManager* ANDROID_ASSET_MANAGER; + #endif /// \brief checks if the given path points to a file or not. /// /// checks if the given path points to a file or not. This path can be relative to the current working /// directory, usually the app root is the working directory, or an absolute path. \param[in] filename the path /// to the file to check. \returns true in case the target is indeed a file, otherwise in all scenarios it /// returns false. \todo android lacks an implementation. - inline static bool exists(psl::string_view filename) - { -#ifdef PLATFORM_ANDROID - return false; -#else - return std::filesystem::exists(directory::to_platform(filename)); -#endif - } + bool exists(psl::string_view filename); /// \brief erases the file ath the given path. /// \param[in] filename the path to the file. @@ -358,11 +337,7 @@ namespace utility::platform /// \todo android lacks an implementation. inline static bool erase(psl::string_view filename) { -#ifdef PLATFORM_ANDROID - return false; -#else return std::filesystem::remove(directory::to_platform(filename)); -#endif } /// \brief reads the given filepath's contents into a psl::char_t container. @@ -372,24 +347,9 @@ namespace utility::platform /// \note this function might not work in all scenarios on non-desktop platforms that have sandboxed away the /// interaction with the filesystem. Please verify that your target platform actually supports this function for /// the file you wish to load. - static bool read(psl::string_view filename, + bool read(psl::string_view filename, std::vector& out, - size_t count = std::numeric_limits::max()) - { - psl::string file_name = directory::to_platform(filename); - psl::ifstream file(file_name, std::ios::binary | std::ios::ate); - if(!file.is_open()) - { - psl::fprintf(stderr, "Cannot open file %s!\n", file_name.c_str()); - return false; - } - size_t size = std::min(static_cast(file.tellg()), count); - file.seekg(0u, std::ios::beg); - out.resize(size); - file.read(&out[0], size); - file.close(); - return true; - } + size_t count = std::numeric_limits::max()); /// \brief reads the given filepath's contents into a psl::string container. /// \param[in] filename the path to the file. @@ -398,22 +358,7 @@ namespace utility::platform /// \note this function might not work in all scenarios on non-desktop platforms that have sandboxed away the /// interaction with the filesystem. Please verify that your target platform actually supports this function for /// the file you wish to load. - static bool read(psl::string_view filename, psl::string& out, size_t count = std::numeric_limits::max()) - { - psl::string file_name = directory::to_platform(filename); - std::ifstream file(file_name.c_str(), std::ios::binary | std::ios::ate); - if(!file.is_open()) - { - psl::fprintf(stderr, "Cannot open file %s!\n", file_name.c_str()); - return false; - } - size_t size = std::min(static_cast(file.tellg()), count); - file.seekg(0u, std::ios::beg); - out.resize(size); - file.read(&out[0], size); - file.close(); - return true; - } + bool read(psl::string_view filename, psl::string& out, size_t count = std::numeric_limits::max()); /// \brief reads the given filepath's contents into a psl::string container on success. /// \param[in] filename the path to the file. @@ -474,6 +419,8 @@ namespace utility::platform { #ifdef PLATFORM_WINDOWS return to_windows(path); +#elif defined(PLATFORM_ANDROID) + return psl::string{path}; #else return to_unix(path); #endif diff --git a/psl/inc/psl/sparse_array.hpp b/psl/inc/psl/sparse_array.hpp index 8fcdbe16..aec29979 100644 --- a/psl/inc/psl/sparse_array.hpp +++ b/psl/inc/psl/sparse_array.hpp @@ -160,7 +160,7 @@ namespace psl { index_type sparse_index, chunk_index; chunk_info_for(index, sparse_index, chunk_index); - assert_debug_break(m_Sparse[chunk_index][sparse_index] != std::numeric_limits::max()); + psl_assert(m_Sparse[chunk_index][sparse_index] != std::numeric_limits::max(), "{} != {}", m_Sparse[chunk_index][sparse_index], std::numeric_limits::max()); return m_Dense[m_Sparse[chunk_index][sparse_index]]; } @@ -363,7 +363,10 @@ namespace psl return; } - assert(std::all_of(&first, &last, [this](index_type i) { return has(i); })); + psl_assert(std::all_of(&first, &last, [this](index_type i) { return has(i); }), + "Tried to erase an invalid index from the sparse array when erasing the range [{}, {})", + first, + last); if(last - first == m_Dense.size()) { diff --git a/psl/inc/psl/view_ptr.hpp b/psl/inc/psl/view_ptr.hpp index ddda8639..6ea3bb5c 100644 --- a/psl/inc/psl/view_ptr.hpp +++ b/psl/inc/psl/view_ptr.hpp @@ -50,7 +50,7 @@ namespace psl constexpr reference operator*() const noexcept { - assert_debug_break(m_Value != nullptr); + psl_assert(m_Value != nullptr, "m_Value was null"); return *m_Value; } diff --git a/psl/src/application_utils.cpp b/psl/src/application_utils.cpp index 85a94152..92e7a81d 100644 --- a/psl/src/application_utils.cpp +++ b/psl/src/application_utils.cpp @@ -29,7 +29,7 @@ psl::string utility::application::path::get_path() return psl::string {dirname(result)} + "/"; } return ""; -#elif defined(PLATFORM_ANDROID) // we run in a sandbox where we are root +#elif defined(PLATFORM_ANDROID) // we run in a sandbox where we are "root" return ""; #else #error not supported diff --git a/psl/src/async/scheduler.cpp b/psl/src/async/scheduler.cpp index f030bd5f..d7a71f03 100644 --- a/psl/src/async/scheduler.cpp +++ b/psl/src/async/scheduler.cpp @@ -164,9 +164,9 @@ void scheduler::execute() while(inflight.size() > 0) { - assert_debug_break(std::unique(std::begin(inflight), std::end(inflight), [](const auto& lhs, const auto& rhs) { + psl_assert(std::unique(std::begin(inflight), std::end(inflight), [](const auto& lhs, const auto& rhs) { return *lhs == *rhs; - }) == std::end(inflight)); + }) == std::end(inflight), "unique test failed"); if(auto item = m_Tasks.pop(); item) { auto task = item.value(); @@ -188,7 +188,7 @@ void scheduler::execute() inflight.erase(it, std::end(inflight)); - assert_debug_break(std::unique(std::begin(done), std::end(done)) == std::end(done)); + psl_assert(std::unique(std::begin(done), std::end(done)) == std::end(done), "unique test failed"); // Redo the barriers barriers.clear(); @@ -239,7 +239,7 @@ void scheduler::execute() } for(auto& thread : m_Workerthreads) thread->pause(); - assert_debug_break(m_Invocables.size() == done.size()); // check if all tasks are done + psl_assert(m_Invocables.size() == done.size(), "there were still {} tasks in flight", m_Invocables.size() - done.size()); m_TokenOffset += m_Invocables.size(); m_Invocables.clear(); } diff --git a/psl/src/ecs/command_buffer.cpp b/psl/src/ecs/command_buffer.cpp index 1aefc2f7..a55ec3e9 100644 --- a/psl/src/ecs/command_buffer.cpp +++ b/psl/src/ecs/command_buffer.cpp @@ -33,9 +33,9 @@ void command_buffer_t::add_component_impl(details::component_key_t key, size_t size, std::function invocable) { - assert(size != 0); + psl_assert(size != 0, "size of requested components shouldn't be 0"); auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); auto offset = cInfo->size(); cInfo->add(entities); @@ -50,9 +50,9 @@ void command_buffer_t::add_component_impl(details::component_key_t key, size_t size, void* prototype) { - assert(size != 0); + psl_assert(size != 0, "size of requested components shouldn't be 0"); auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); auto offset = cInfo->size(); cInfo->add(entities); @@ -70,7 +70,7 @@ void command_buffer_t::add_component_impl(details::component_key_t key, void command_buffer_t::add_component_impl(details::component_key_t key, psl::array_view entities, size_t size) { auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); cInfo->add(entities); } @@ -81,9 +81,9 @@ void command_buffer_t::add_component_impl(details::component_key_t key, size_t size, std::function invocable) { - assert(size != 0); + psl_assert(size != 0, "size of requested components shouldn't be 0"); auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); auto offset = cInfo->size(); cInfo->add(entities); @@ -99,9 +99,9 @@ void command_buffer_t::add_component_impl(details::component_key_t key, void* prototype, bool repeat) { - assert(size != 0); + psl_assert(size != 0, "size of requested components shouldn't be 0"); auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); auto offset = cInfo->size(); @@ -129,7 +129,7 @@ void command_buffer_t::remove_component(details::component_key_t key, { auto it = std::find_if( std::begin(m_Components), std::end(m_Components), [key](const auto& cInfo) { return cInfo->id() == key; }); - assert(it != std::end(m_Components)); + psl_assert(it != std::end(m_Components), "component info for key {} was not found", reinterpret_cast(key)); (*it)->add(entities); (*it)->destroy(entities); } @@ -139,7 +139,7 @@ void command_buffer_t::remove_component(details::component_key_t key, psl::array { auto it = std::find_if( std::begin(m_Components), std::end(m_Components), [key](const auto& cInfo) { return cInfo->id() == key; }); - assert(it != std::end(m_Components)); + psl_assert(it != std::end(m_Components), "component info for key {} was not found", reinterpret_cast(key)); (*it)->add(entities); diff --git a/psl/src/ecs/state.cpp b/psl/src/ecs/state.cpp index be468505..4276da46 100644 --- a/psl/src/ecs/state.cpp +++ b/psl/src/ecs/state.cpp @@ -291,7 +291,7 @@ state_t::get_component_info(psl::array_view keys) cons void state_t::add_component_impl(details::component_key_t key, psl::array_view entities) { auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); cInfo->add(entities); for(size_t i = 0; i < entities.size(); ++i) m_ModifiedEntities.try_insert(entities[i]); @@ -303,9 +303,9 @@ void state_t::add_component_impl(details::component_key_t key, std::function invocable) { auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); const auto component_size = cInfo->component_size(); - assert(component_size != 0); + psl_assert(component_size != 0, "component size was 0"); auto offset = cInfo->entities().size(); cInfo->add(entities); @@ -322,9 +322,9 @@ void state_t::add_component_impl(details::component_key_t key, bool repeat) { auto cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); const auto component_size = cInfo->component_size(); - assert(component_size != 0); + psl_assert(component_size != 0, "component size was 0"); auto offset = cInfo->entities().size(); @@ -451,7 +451,7 @@ psl::array state_t::filter(details::dependency_pack& pack, bool seed_wit auto it = std::find_if( std::begin(m_Filters), std::end(m_Filters), [&group](const filter_result& data) { return *data.group == group; }); - assert(it != std::end(m_Filters)); + psl_assert(it != std::end(m_Filters), "could not find filter group for pack, could indicate a sync issue"); auto entities = it->entities; @@ -475,11 +475,15 @@ psl::array state_t::filter(details::dependency_pack& pack, bool seed_wit entities.erase(end, std::end(entities)); - assert_debug_break(std::all_of(std::begin(pack.filters), std::end(pack.filters), [this, &entities](auto filter) { - auto cInfo = get_component_info(filter); - return std::all_of( - std::begin(entities), std::end(entities), [filter, &cInfo](entity e) { return cInfo->has_storage_for(e); }); - })); + psl_assert(std::all_of(std::begin(pack.filters), + std::end(pack.filters), + [this, &entities](auto filter) { + auto cInfo = get_component_info(filter); + return std::all_of(std::begin(entities), std::end(entities), [filter, &cInfo](entity e) { + return cInfo->has_storage_for(e); + }); + }), + "not all components had storage for all entities"); return entities; } @@ -755,23 +759,27 @@ void state_t::filter(filter_result& data, psl::array_view source) const } } } - assert_debug_break(std::unique(std::begin(data.entities), std::end(data.entities)) == std::end(data.entities)); - assert_debug_break( - std::all_of(std::begin(data.group->on_combine), std::end(data.group->on_combine), [this, &data](auto filter) { - auto cInfo = get_component_info(filter); - return std::all_of(std::begin(data.entities), std::end(data.entities), [filter, &cInfo](entity e) { - return cInfo->has_storage_for(e); - }); - })); + psl_assert(std::unique(std::begin(data.entities), std::end(data.entities)) == std::end(data.entities), + "some entities were not unique"); + psl_assert(std::all_of(std::begin(data.group->on_combine), + std::end(data.group->on_combine), + [this, &data](auto filter) { + auto cInfo = get_component_info(filter); + return std::all_of(std::begin(data.entities), + std::end(data.entities), + [filter, &cInfo](entity e) { return cInfo->has_storage_for(e); }); + }), + "some components failed to have storage for the entities"); } size_t state_t::prepare_data(psl::array_view entities, void* cache, component_key_t id) const noexcept { if(entities.size() == 0) return 0; const auto& cInfo = get_component_info(id); - assert_debug_break(cInfo != nullptr); - assert_debug_break( - std::all_of(std::begin(entities), std::end(entities), [&cInfo](auto e) { return cInfo->has_storage_for(e); })); + psl_assert(cInfo != nullptr, "component info was null for the key {}", reinterpret_cast(id)); + psl_assert( + std::all_of(std::begin(entities), std::end(entities), [&cInfo](auto e) { return cInfo->has_storage_for(e); }), + "some components failed to have storage for the entities"); return cInfo->copy_to(entities, cache); } @@ -812,7 +820,7 @@ size_t state_t::set(psl::array_view entities, details::component_key_t k { if(entities.size() == 0) return 0; const auto& cInfo = get_component_info(key); - assert(cInfo != nullptr); + psl_assert(cInfo != nullptr, "component info for key {} was not found", reinterpret_cast(key)); return cInfo->copy_from(entities, data); } diff --git a/psl/src/library.cpp b/psl/src/library.cpp index e474dd2c..292b81d7 100644 --- a/psl/src/library.cpp +++ b/psl/src/library.cpp @@ -1,6 +1,5 @@ #include "psl/library.hpp" #include "psl/platform_utils.hpp" -#include using namespace psl::meta; using namespace psl::serialization; @@ -9,6 +8,7 @@ const uint64_t file::polymorphic_identity {register_polymorphic()}; library::library(psl::string8::view lib, std::vector environment) { + auto library = utility::platform::file::read(lib).value_or(""); m_LibraryLocation = utility::platform::directory::to_platform(lib); auto loc = m_LibraryLocation.rfind(psl::to_string8_t(utility::platform::directory::seperator)); m_LibraryFolder = psl::string8::view(&m_LibraryLocation[0], loc); @@ -18,13 +18,26 @@ library::library(psl::string8::view lib, std::vector environment psl::string8_t root = psl::string8_t(m_LibraryFolder) + psl::to_string8_t(utility::platform::directory::seperator); psl_assert(utility::platform::file::exists(psl::from_string8_t(m_LibraryLocation)), - "could not find library at " + m_LibraryLocation); + "could not find library at '{}'", m_LibraryLocation); // Load library into memory serializer s; - std::ifstream library(m_LibraryLocation, std::ifstream::in | std::ifstream::binary); - for(psl::string8_t line; getline(library, line);) + auto lines = [](const auto& file){ + std::vector lines{}; + lines.reserve(std::count(file.begin(), file.end(), '\n')); + auto index = file.find('\n'); + size_t offset = 0; + while(index != psl::string8_t::npos) + { + lines.emplace_back(file.substr(offset, index)); + offset = index + 1; + index = file.find('\n', offset); + } + return lines; + }(library); + + for(auto line : lines) { size_t start = line.find("UID=") + 4; size_t end = line.find("]", start); @@ -49,7 +62,7 @@ library::library(psl::string8::view lib, std::vector environment continue; } psl_assert(m_MetaData.find(uid) == std::end(m_MetaData), - "duplicate UID {" + uid.to_string() + "} found in library"); + "duplicate UID {} found in library", uid.to_string()); psl::string8_t metapath = line.substr(startPath, endPath - startPath); psl::string8_t filepath = line.substr(startFilePath, endFilePath - startFilePath); @@ -57,12 +70,11 @@ library::library(psl::string8::view lib, std::vector environment file* metaPtr = nullptr; psl_assert(utility::platform::file::exists(root + metapath), - "could not find file associated with UID {" + uid.to_string() + "} at {" + root + metapath + "}"); + "could not find file associated with UID {} at {}",uid.to_string(), root + metapath); s.deserialize(metaPtr, root + metapath); psl_assert(metaPtr->ID() == uid, - psl::string8_t {"UID mismatch between library and metafile library expected {"} + uid.to_string() + - "} but file has {" + metaPtr->ID().to_string() + "}"); + "UID mismatch between library and metafile library expected {} but file has {}", uid.to_string(), metaPtr->ID().to_string()); auto pair = m_MetaData.emplace(metaPtr->ID(), std::move(metaPtr)); @@ -70,7 +82,6 @@ library::library(psl::string8::view lib, std::vector environment pair.first->second.flags[0] = true; pair.first->second.readableName = filepath; } - library.close(); // The Library is CLOSED! #NoRuPauligy } diff --git a/psl/src/memory/range.cpp b/psl/src/memory/range.cpp index 57400cd4..dba65ec4 100644 --- a/psl/src/memory/range.cpp +++ b/psl/src/memory/range.cpp @@ -3,7 +3,7 @@ using namespace memory; -range_t::range_t(std::uintptr_t begin, std::uintptr_t end) : begin(begin), end(end) { assert(begin <= end); }; +range_t::range_t(std::uintptr_t begin, std::uintptr_t end) : begin(begin), end(end) { psl_assert(begin <= end, "range's begin should be lequal to end, but was {} <= {}", begin, end); }; bool range_t::operator==(const range_t& other) const { return (other.begin == begin && other.end == end); } diff --git a/psl/src/platform_utils.cpp b/psl/src/platform_utils.cpp index ee9f2088..57a9e068 100644 --- a/psl/src/platform_utils.cpp +++ b/psl/src/platform_utils.cpp @@ -7,6 +7,10 @@ #include #endif +#if defined(PLATFORM_ANDROID) +#include +#endif + #include "psl/string_utils.hpp" // todo: validate windows directory seperator etc.. @@ -196,7 +200,7 @@ utility::debug::trace(size_t offset, size_t depth, std::optionalAddress; #endif return info; +} + +bool utility::platform::file::exists(psl::string_view filename) +{ + #if defined(PLATFORM_ANDROID) + return AAssetManager_open(ANDROID_ASSET_MANAGER, filename.data(), AASSET_MODE_UNKNOWN) != nullptr; + #else + return std::filesystem::exists(directory::to_platform(filename)); + #endif +} + + +bool utility::platform::file::read(psl::string_view filename, std::vector& out, size_t count) +{ + psl::string file_name = directory::to_platform(filename); + psl::print(psl::level_t::verbose, "checking if '{}' exists", directory::to_platform(filename)); + #if !defined(PLATFORM_ANDROID) + psl::ifstream file(file_name, std::ios::binary | std::ios::ate); + if(!file.is_open()) + { + psl::fprintf(stderr, "Cannot open file %s!\n", file_name.c_str()); + return false; + } + size_t size = std::min(static_cast(file.tellg()), count); + file.seekg(0u, std::ios::beg); + out.resize(size); + file.read(&out[0], size); + file.close(); + #else // PLATFORM_ANDROID + AAssetDir* assetDir = AAssetManager_openDir(ANDROID_ASSET_MANAGER, ""); + AAsset *asset = AAssetManager_open(ANDROID_ASSET_MANAGER, file_name.data(), AASSET_MODE_STREAMING); + //holds size of searched file + off64_t length = AAsset_getLength64(asset); + //keeps track of remaining bytes to read + off64_t remaining = AAsset_getRemainingLength64(asset); + size_t Mb = 1000 *1024; // 1Mb is maximum chunk size for compressed assets + size_t currChunk; + out.reserve(length); + + //while we have still some data to read + while (remaining != 0) + { + //set proper size for our next chunk + if(remaining >= Mb) + { + currChunk = Mb; + } + else + { + currChunk = remaining; + } + char chunk[currChunk]; + + //read data chunk + if(AAsset_read(asset, chunk, currChunk) > 0) // returns less than 0 on error + { + //and append it to our vector + out.insert(out.end(),chunk, chunk + currChunk); + remaining = AAsset_getRemainingLength64(asset); + } + } + AAsset_close(asset); + #endif // !PLATFORM_ANDROID + return true; +} + +bool utility::platform::file::read(psl::string_view filename, psl::string& out, size_t count) +{ + psl::string file_name = directory::to_platform(filename); + #if !defined(PLATFORM_ANDROID) + std::ifstream file(file_name.c_str(), std::ios::binary | std::ios::ate); + if(!file.is_open()) + { + psl::fprintf(stderr, "Cannot open file %s!\n", file_name.c_str()); + return false; + } + size_t size = std::min(static_cast(file.tellg()), count); + file.seekg(0u, std::ios::beg); + out.resize(size); + file.read(&out[0], size); + file.close(); + #else // PLATFORM_ANDROID + AAssetDir* assetDir = AAssetManager_openDir(ANDROID_ASSET_MANAGER, ""); + AAsset *asset = AAssetManager_open(ANDROID_ASSET_MANAGER, file_name.data(), AASSET_MODE_BUFFER); + //holds size of searched file + off64_t length = AAsset_getLength64(asset); + //keeps track of remaining bytes to read + off64_t remaining = AAsset_getRemainingLength64(asset); + size_t Mb = 1000 *1024; // 1Mb is maximum chunk size for compressed assets + size_t currChunk; + out.reserve(length); + + //while we have still some data to read + while (remaining != 0) + { + //set proper size for our next chunk + if(remaining >= Mb) + { + currChunk = Mb; + } + else + { + currChunk = remaining; + } + char chunk[currChunk]; + + //read data chunk + if(AAsset_read(asset, chunk, currChunk) > 0) // returns less than 0 on error + { + //and append it to our vector + out.insert(out.end(),chunk, chunk + currChunk); + remaining = AAsset_getRemainingLength64(asset); + } + } + AAsset_close(asset); + #endif // !PLATFORM_ANDROID + return true; } \ No newline at end of file diff --git a/tools/templates/android/app/src/main/AndroidManifest.xml.template b/tools/templates/android/app/src/main/AndroidManifest.xml.template index 2478f3c3..f018788b 100644 --- a/tools/templates/android/app/src/main/AndroidManifest.xml.template +++ b/tools/templates/android/app/src/main/AndroidManifest.xml.template @@ -4,7 +4,7 @@ package="com.{{COMPANY}}.{{PROJECT}}" android:versionCode="1" android:versionName="1.0"> - + - Date: Sat, 26 Feb 2022 00:21:20 +0200 Subject: [PATCH 04/16] removed constexpr for gcc --- psl/inc/psl/assertions.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/psl/inc/psl/assertions.hpp b/psl/inc/psl/assertions.hpp index 37b899ac..117cdef0 100644 --- a/psl/inc/psl/assertions.hpp +++ b/psl/inc/psl/assertions.hpp @@ -75,7 +75,7 @@ namespace psl #endif } - [[noreturn]] constexpr void unreachable(const std::string& reason = "") + [[noreturn]] inline void unreachable(const std::string& reason = "") { if(reason.empty()) print(level_t::fatal, "unreachable code reached."); @@ -84,7 +84,7 @@ namespace psl std::terminate(); } - [[noreturn]] constexpr void not_implemented(size_t issue = 0) + [[noreturn]] inline void not_implemented(size_t issue = 0) { if(issue != 0) print(level_t::fatal, @@ -95,7 +95,7 @@ namespace psl std::terminate(); } - [[noreturn]] constexpr void not_implemented(const std::string& reason, size_t issue = 0) + [[noreturn]] inline void not_implemented(const std::string& reason, size_t issue = 0) { if(issue != 0) print(level_t::fatal, From 453de2ca7b93e3b723ae1b882e6f4c904ef9aaf4 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Sat, 26 Feb 2022 11:25:53 +0200 Subject: [PATCH 05/16] fixed missing semicolon on win32 --- core/src/os/surface_win32.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/os/surface_win32.cpp b/core/src/os/surface_win32.cpp index 052dae07..dfe76099 100644 --- a/core/src/os/surface_win32.cpp +++ b/core/src/os/surface_win32.cpp @@ -41,7 +41,7 @@ bool surface::init_surface() if(!RegisterClassEx(&win_class)) { // It didn't work, so try to give a useful error: - psl::unreachable("Cannot create a window in which to draw!") + psl::unreachable("Cannot create a window in which to draw!"); fflush(stdout); std::exit(-1); } From a744d6beb6ba7b889cb46054c9ab07032166ded9 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Sat, 26 Feb 2022 23:45:44 +0200 Subject: [PATCH 06/16] fixed validation being enabled on Android/Release builds --- core/inc/vk/ivk.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/inc/vk/ivk.hpp b/core/inc/vk/ivk.hpp index 8101ded0..3f5cf228 100644 --- a/core/inc/vk/ivk.hpp +++ b/core/inc/vk/ivk.hpp @@ -53,10 +53,10 @@ #define SURFACE_COLORSPACE vk::ColorSpaceKHR::eSrgbNonlinear #endif -#ifdef DEBUG +#if defined(DEBUG) && !defined(PLATFORM_ANDROID) #define VULKAN_ENABLE_VALIDATION true #else -#define VULKAN_ENABLE_VALIDATION true +#define VULKAN_ENABLE_VALIDATION false #endif From 06c31fd2a373a469973c7f2bf9564b47f746fa22 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Sat, 26 Feb 2022 23:46:49 +0200 Subject: [PATCH 07/16] fixed surface not ticking --- core/src/os/context_android.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/os/context_android.cpp b/core/src/os/context_android.cpp index 13511bc2..66277052 100644 --- a/core/src/os/context_android.cpp +++ b/core/src/os/context_android.cpp @@ -3,6 +3,7 @@ #include #include #include "os/context.hpp" +#include "logging.hpp" static void engine_handle_cmd(struct android_app* app, int32_t cmd) { switch (cmd) { @@ -124,7 +125,7 @@ bool core::os::context::tick() noexcept // If not animating, we will block forever waiting for events. // If animating, we loop until all events are read, then continue // to draw the next frame of animation. - while ((ident=ALooper_pollAll(m_Paused ? 0 : -1, nullptr, &events, + while ((ident=ALooper_pollAll(m_Paused ? -1 : 0, nullptr, &events, (void**)&source)) >= 0) { // Process this event. @@ -144,9 +145,10 @@ bool core::os::context::tick() noexcept // Check if we are exiting. if (m_Application->destroyRequested != 0) { + core::os::log->info("destroy requested"); return false; } } return true; -} \ No newline at end of file +} From 704b30d15f49ec720847a1f443de0b07d8f39856 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Sat, 26 Feb 2022 23:51:46 +0200 Subject: [PATCH 08/16] fixed smaller issues, asserts now print fileloc android path handling fixed switched to AAB --- core/main/main.cpp | 86 +++++----- core/src/os/surface.cpp | 6 +- core/src/vk/context.cpp | 5 +- core/src/vk/swapchain.cpp | 3 +- psl/inc/psl/assertions.hpp | 149 +++++++++++------- psl/inc/psl/pack_view.hpp | 3 +- psl/inc/psl/platform_utils.hpp | 76 +++++++-- psl/src/library.cpp | 9 +- psl/src/platform_utils.cpp | 7 +- tools/android.py | 36 ++++- .../android/app/build.gradle.template | 4 +- .../templates/android/package_0/build.gradle | 12 ++ .../android/settings.gradle.template | 1 + 13 files changed, 271 insertions(+), 126 deletions(-) create mode 100644 tools/templates/android/package_0/build.gradle diff --git a/core/main/main.cpp b/core/main/main.cpp index 961a5107..4c757bbc 100755 --- a/core/main/main.cpp +++ b/core/main/main.cpp @@ -166,7 +166,7 @@ handle setup_gfx_material(resource::cache_t& cache, handle matBuffer, psl::UID vert, psl::UID frag, - const psl::UID& texture) + const psl::UID& texture = psl::UID::invalid_uid) { auto matData = setup_gfx_material_data(cache, context_handle, vert, frag, texture); auto material = cache.create(context_handle, matData, pipeline_cache, matBuffer); @@ -481,8 +481,8 @@ int entry(gfx::graphics_backend backend, core::os::context& os_context) utility::geometry::create_plane(cache, psl::vec2::one * 128.f, psl::ivec2::one, psl::vec2::one * 8.f)); geometryDataHandles.push_back(utility::geometry::create_icosphere(cache, psl::vec3::one, 4)); - geometryDataHandles.push_back( - cache.instantiate("bf36d6f1-af53-41b9-b7ae-0f0cb16d8734"_uid)); + // geometryDataHandles.push_back( + // cache.instantiate("bf36d6f1-af53-41b9-b7ae-0f0cb16d8734"_uid)); auto water_plane_index = geometryDataHandles.size() - 1; for(auto& handle : geometryDataHandles) { @@ -535,50 +535,50 @@ int entry(gfx::graphics_backend backend, core::os::context& os_context) pipeline_cache, instanceMaterialBuffer, "0f48f21f-f707-06b5-5c66-83ff0d53c5a1"_uid, - "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid, - "9b42f9b6-75f6-a4f1-a219-986033d37d8a"_uid)); - - // grass - materials.emplace_back(setup_gfx_material(cache, - context_handle, - pipeline_cache, - instanceMaterialBuffer, - "0f48f21f-f707-06b5-5c66-83ff0d53c5a1"_uid, - "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid, - "944e7173-ede1-0bed-cffe-d6a5a34449be"_uid)); - - // dirt - materials.emplace_back(setup_gfx_material(cache, - context_handle, - pipeline_cache, - instanceMaterialBuffer, - "0f48f21f-f707-06b5-5c66-83ff0d53c5a1"_uid, - "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid, - "f24fa9d7-966a-e942-851b-5b6fb30dd0b6"_uid)); - - // rock - materials.emplace_back(setup_gfx_material(cache, - context_handle, - pipeline_cache, - instanceMaterialBuffer, - "0f48f21f-f707-06b5-5c66-83ff0d53c5a1"_uid, - "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid, - "eb4e6f57-1d5d-56d3-41ed-27ea6b5f5ea1"_uid)); + "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid/*, + "9b42f9b6-75f6-a4f1-a219-986033d37d8a"_uid*/)); + + // // grass + // materials.emplace_back(setup_gfx_material(cache, + // context_handle, + // pipeline_cache, + // instanceMaterialBuffer, + // "0f48f21f-f707-06b5-5c66-83ff0d53c5a1"_uid, + // "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid, + // "944e7173-ede1-0bed-cffe-d6a5a34449be"_uid)); + + // // dirt + // materials.emplace_back(setup_gfx_material(cache, + // context_handle, + // pipeline_cache, + // instanceMaterialBuffer, + // "0f48f21f-f707-06b5-5c66-83ff0d53c5a1"_uid, + // "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid, + // "f24fa9d7-966a-e942-851b-5b6fb30dd0b6"_uid)); + + // // rock + // materials.emplace_back(setup_gfx_material(cache, + // context_handle, + // pipeline_cache, + // instanceMaterialBuffer, + // "0f48f21f-f707-06b5-5c66-83ff0d53c5a1"_uid, + // "b942da62-2922-c985-9c02-ae3008f7a8bc"_uid, + // "eb4e6f57-1d5d-56d3-41ed-27ea6b5f5ea1"_uid)); psl::array> bundles; bundles.emplace_back(cache.create(instanceBuffer, intanceMaterialBinding)); bundles.back()->set_material(materials[0], 2000); bundles.back()->set_material(depth_material, 1000); - bundles.emplace_back(cache.create(instanceBuffer, intanceMaterialBinding)); - bundles.back()->set_material(materials[1], 2000); - bundles.back()->set_material(depth_material, 1000); + // bundles.emplace_back(cache.create(instanceBuffer, intanceMaterialBinding)); + // bundles.back()->set_material(materials[1], 2000); + // bundles.back()->set_material(depth_material, 1000); - bundles.emplace_back(cache.create(instanceBuffer, intanceMaterialBinding)); - bundles.back()->set_material(materials[2], 2000); + // bundles.emplace_back(cache.create(instanceBuffer, intanceMaterialBinding)); + // bundles.back()->set_material(materials[2], 2000); - bundles.emplace_back(cache.create(instanceBuffer, intanceMaterialBinding)); - bundles.back()->set_material(materials[3], 2000); + // bundles.emplace_back(cache.create(instanceBuffer, intanceMaterialBinding)); + // bundles.back()->set_material(materials[3], 2000); core::gfx::render_graph renderGraph {}; auto frameBufferData = @@ -946,6 +946,14 @@ void android_main(android_app* application) setup_loggers(); std::srand(0); + // go into a holding loop while wait for the window to come online. + while(true) { + os_context.tick(); + __android_log_write(ANDROID_LOG_INFO, "paradigm", (std::string("window ") + std::to_string((size_t)(os_context.application().window))).data()); + if(os_context.application().window != nullptr) + break; + } + __android_log_write(ANDROID_LOG_INFO, "paradigm", (std::string("window is loaded ") + std::to_string((size_t)(os_context.application().window))).data()); entry(graphics_backend::vulkan, os_context); return; } diff --git a/core/src/os/surface.cpp b/core/src/os/surface.cpp index d24e9aa1..04a746dc 100644 --- a/core/src/os/surface.cpp +++ b/core/src/os/surface.cpp @@ -13,9 +13,9 @@ surface::surface(core::resource::cache_t& cache, psl::meta::file* metaFile, core::resource::handle data) : m_Data(data), - m_InputSystem(new core::systems::input()) + m_InputSystem(new core::systems::input()), + m_Open(init_surface()) { - init_surface(); } surface::~surface() @@ -57,4 +57,4 @@ void surface::register_swapchain(core::resource::handle sw const data::window& surface::data() const { return m_Data.value(); } -core::systems::input& surface::input() const noexcept { return *m_InputSystem; } \ No newline at end of file +core::systems::input& surface::input() const noexcept { return *m_InputSystem; } diff --git a/core/src/vk/context.cpp b/core/src/vk/context.cpp index da719359..211f866c 100644 --- a/core/src/vk/context.cpp +++ b/core/src/vk/context.cpp @@ -133,6 +133,7 @@ context::context(core::resource::cache_t& cache, uint32_t extensionCount = 0; auto extensions = vk::enumerateInstanceExtensionProperties(); + core::ivk::log->info("instance extensions: {}", extensions.value.size()); for(const auto& ext : extensions.value) { core::ivk::log->info("instance extension: {}", psl::string(&ext.extensionName[0])); @@ -140,12 +141,14 @@ context::context(core::resource::cache_t& cache, uint32_t instanceCount = 0; auto instances = vk::enumerateInstanceLayerProperties(); + core::ivk::log->info("instance layers: {}", instances.value.size()); for(const auto& inst : instances.value) { core::ivk::log->info("instance layer: {}", psl::string(&inst.layerName[0])); } if(m_Validated) { + core::ivk::log->info("Enabling 'VK_LAYER_KHRONOS_validation'"); m_InstanceLayerList.push_back("VK_LAYER_KHRONOS_validation"); m_InstanceExtensionList.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); } @@ -946,4 +949,4 @@ uint32_t context::graphics_queue_index() const noexcept { return m_GraphicsQueue uint32_t context::transfer_que_index() const noexcept { return m_TransferQueueIndex; } -bool context::acquireNextImage2KHR(optional_ref out_version) const noexcept { return false; } \ No newline at end of file +bool context::acquireNextImage2KHR(optional_ref out_version) const noexcept { return false; } diff --git a/core/src/vk/swapchain.cpp b/core/src/vk/swapchain.cpp index 671170b8..162f3b1a 100644 --- a/core/src/vk/swapchain.cpp +++ b/core/src/vk/swapchain.cpp @@ -40,6 +40,7 @@ swapchain::swapchain(core::resource::cache_t& cache, vk::AndroidSurfaceCreateInfoKHR createInfo; core::ivk::log->info("creating android swapchain"); createInfo.window = os_context.application().window; + psl_assert(createInfo.window != nullptr, "application window was invalid"); utility::vulkan::check(m_Context->instance().createAndroidSurfaceKHR(&createInfo, VK_NULL_HANDLE, &m_Surface)); #elif defined(SURFACE_D2D) uint32_t displayPropertyCount; @@ -614,4 +615,4 @@ const vk::ClearColorValue swapchain::clear_color() const noexcept { return m_Cle const vk::ClearDepthStencilValue swapchain::clear_depth() const noexcept { return m_ClearDepth; } bool swapchain::has_depth() const noexcept { return m_UseDepth; } -void swapchain::clear_color(vk::ClearColorValue color) noexcept { m_ClearColor = color; } \ No newline at end of file +void swapchain::clear_color(vk::ClearColorValue color) noexcept { m_ClearColor = color; } diff --git a/psl/inc/psl/assertions.hpp b/psl/inc/psl/assertions.hpp index 117cdef0..ad4beb00 100644 --- a/psl/inc/psl/assertions.hpp +++ b/psl/inc/psl/assertions.hpp @@ -4,6 +4,8 @@ #ifdef PLATFORM_ANDROID #include +#else + #include #endif // PLATFORM_ANDROID namespace psl @@ -17,94 +19,121 @@ namespace psl error, fatal, }; - template - constexpr void print(level_t level, const char* fmt = "failed assert", Args&&... args) + + namespace details { -#ifdef PLATFORM_ANDROID - int log_level = ANDROID_LOG_SILENT; - switch(level) + /// \todo When Android implements source_location, remove the ifdefs + template + struct print_t { - case level_t::verbose: - log_level = ANDROID_LOG_VERBOSE; - break; - case level_t::debug: - log_level = ANDROID_LOG_DEBUG; - break; - case level_t::info: - log_level = ANDROID_LOG_INFO; - break; - case level_t::warn: - log_level = ANDROID_LOG_WARN; - break; - case level_t::error: - log_level = ANDROID_LOG_ERROR; - break; - case level_t::fatal: - log_level = ANDROID_LOG_FATAL; - break; - default: - log_level = ANDROID_LOG_SILENT; - } - __android_log_write(log_level, "paradigm", fmt::format(fmt, std::forward(args)...).c_str()); + #if defined(PLATFORM_ANDROID) + print_t(level_t level, const char* func, const char* file, int line, const char* format, Args&&... args) + { + int log_level = ANDROID_LOG_SILENT; + switch(level) + { + case level_t::verbose: + log_level = ANDROID_LOG_VERBOSE; + break; + case level_t::debug: + log_level = ANDROID_LOG_DEBUG; + break; + case level_t::info: + log_level = ANDROID_LOG_INFO; + break; + case level_t::warn: + log_level = ANDROID_LOG_WARN; + break; + case level_t::error: + log_level = ANDROID_LOG_ERROR; + break; + case level_t::fatal: + log_level = ANDROID_LOG_FATAL; + break; + default: + log_level = ANDROID_LOG_SILENT; + } + __android_log_write(log_level, "paradigm", fmt::format(format, std::forward(args)...).c_str()); + __android_log_write(log_level, "paradigm", fmt::format("at: {} ({}:{})", func, file, line).c_str()); + } + #else + print_t(level_t level, const char* fmt, Args&&... args, const std::source_location& loc = std::source_location::current()) + { + const char* log_level; + switch(level) + { + case level_t::verbose: + log_level = "[verbose] {}\n at: {} ({}:{}:{})"; + break; + case level_t::debug: + log_level = "[debug] {}\n at: {} ({}:{}:{})"; + break; + case level_t::info: + log_level = "[info] {}\n at: {} ({}:{}:{})"; + break; + case level_t::warn: + log_level = "[warn] {}\n at: {} ({}:{}:{})"; + break; + case level_t::error: + log_level = "[error] {}\n at: {} ({}:{}:{})"; + break; + case level_t::fatal: + log_level = "[fatal] {}\n at: {} ({}:{}:{})"; + break; + default: + log_level = "[info] {}\n at: {} ({}:{}:{})"; + } + fmt::print(fmt::format(log_level, fmt, loc.function_name(), loc.file_name(), loc.line(), loc.column()), std::forward(args)...); + } + #endif + }; +#if defined(PLATFORM_ANDROID) + template + print_t(level_t, const char*, const char*, int, const char*, Ts&&...)->print_t; #else - const char* log_level; - switch(level) - { - case level_t::verbose: - log_level = "[verbose] {}"; - break; - case level_t::debug: - log_level = "[debug] {}"; - break; - case level_t::info: - log_level = "[info] {}"; - break; - case level_t::warn: - log_level = "[warn] {}"; - break; - case level_t::error: - log_level = "[error] {}"; - break; - case level_t::fatal: - log_level = "[fatal] {}"; - break; - default: - log_level = "[info] {}"; - } - fmt::print(fmt::format(log_level, fmt), std::forward(args)...); + template + print_t(level_t, const char*, Ts&&...)->print_t; #endif } +} +#if defined(PLATFORM_ANDROID) + #define psl_print(level, message, ...) psl::details::print_t{level, __PRETTY_FUNCTION__, __FILE__, __LINE__, message, __VA_ARGS__} +#else + #define psl_print(level, message, ...) psl::details::print_t{level, message, __VA_ARGS__} +#endif +namespace psl +{ [[noreturn]] inline void unreachable(const std::string& reason = "") { if(reason.empty()) - print(level_t::fatal, "unreachable code reached."); + psl_print(level_t::fatal, "unreachable code reached."); else - print(level_t::fatal, "{}", reason); + psl_print(level_t::fatal, "{}", reason); std::terminate(); } [[noreturn]] inline void not_implemented(size_t issue = 0) { if(issue != 0) - print(level_t::fatal, + psl_print(level_t::fatal, "feature not implemented, follow development at https://github.com/JessyDL/paradigm/issues/{}", issue); else - print(level_t::fatal, "feature not implemented"); + psl_print(level_t::fatal, "feature not implemented"); std::terminate(); } [[noreturn]] inline void not_implemented(const std::string& reason, size_t issue = 0) { if(issue != 0) - print(level_t::fatal, + psl_print(level_t::fatal, "feature not implemented reason: '{}', follow development at " "https://github.com/JessyDL/paradigm/issues/{}", reason, issue); else - print(level_t::fatal, "feature not implemented reason: '{}'", reason); + psl_print(level_t::fatal, "feature not implemented reason: '{}'", reason); std::terminate(); } } // namespace psl @@ -176,7 +205,7 @@ DBG__FUNCTION void debug_break(void) { __asm__ __volatile__("bpt"); } #if defined(PE_DEBUG) #define psl_assert(expression, ...) \ - (void)((!!(expression)) || (psl::print(psl::level_t::fatal, __VA_ARGS__), 0) || (std::terminate(), 0)) + (void)((!!(expression)) || (psl_print(psl::level_t::fatal, __VA_ARGS__), 0) || (std::terminate(), 0)) #else #define psl_assert(expression, ...) -#endif \ No newline at end of file +#endif diff --git a/psl/inc/psl/pack_view.hpp b/psl/inc/psl/pack_view.hpp index 799b9c1a..e213089d 100644 --- a/psl/inc/psl/pack_view.hpp +++ b/psl/inc/psl/pack_view.hpp @@ -479,7 +479,8 @@ namespace psl pack_view(psl::array_view... views) : m_Pack(std::make_tuple(std::forward>(views)...)) { #ifdef PE_DEBUG - auto test = [](size_t size1, size_t size2) { psl_assert(size1 == size2, "expected {} == {}", size1, size2); }; + // todo this needs further verification, seems tag types are present here, should they be? + auto test = [](size_t size1, size_t size2) { psl_assert(size1 == size2 || size1 == 0, "expected size1 {} == size2 {} or size1 == 0 ", size1, size2); }; (test(views.size(), size()), ...); #endif } diff --git a/psl/inc/psl/platform_utils.hpp b/psl/inc/psl/platform_utils.hpp index ae5ad831..fac6c38e 100644 --- a/psl/inc/psl/platform_utils.hpp +++ b/psl/inc/psl/platform_utils.hpp @@ -5,11 +5,11 @@ #include "psl/ustring.hpp" #include #include -#include #include #include #include #include +#include // https://en.wikipedia.org/wiki/Path_%28computing%29#Representations_of_paths_by_operating_system_and_shell @@ -214,6 +214,61 @@ namespace utility::platform return dir; } + static psl::string to_android(psl::string_view path) + { + psl::string result {}; + auto constituents = [](psl::string_view path) -> std::vector { + std::vector res {}; + size_t offset = 0; + size_t index = path.find('/', offset); + while(index != psl::string_view::npos) + { + res.emplace_back(path.substr(offset, index - offset)); + offset = index + 1; + index = path.find('/', offset); + } + res.emplace_back(path.substr(offset, path.size() - offset)); + return res; + }(path); + + size_t offset = 0; + auto it = std::begin(constituents); + auto next = std::next(it); + while(next != std::end(constituents)) + { + if(*next == psl::string_view{".."}) + { + constituents.erase(it, std::next(next)); + if(offset + 2 >= constituents.size()) break; + it = std::next(std::begin(constituents), offset); + next = std::next(next); + } + else + { + offset += 1; + it = std::next(it); + next = std::next(next); + } + } + if(constituents.empty()) return result; + + + const auto size = std::accumulate(std::begin(constituents), + std::end(constituents), + size_t {0}, + [](size_t sum, psl::string_view value) { return sum + value.size(); }) + + constituents.size() - 1; + result.reserve(size); + + for(auto it = std::begin(constituents), end = std::prev(std::end(constituents)); it != end; it = std::next(it)) + { + result.append(*it); + result.append(seperator); + } + result.append(*std::prev(std::end(constituents))); + return result; + } + /// \brief translated the given path to one that is accepted on the current platform /// \param[in] path the path to translate to one that works on the current platform. /// \returns a string that *should* work on the current platform, and satisfies the requirements. @@ -222,7 +277,7 @@ namespace utility::platform #ifdef PLATFORM_WINDOWS return to_windows(path); #elif defined(PLATFORM_ANDROID) - return psl::string{path}; + return to_android(path); #else return to_unix(path); #endif @@ -237,10 +292,7 @@ namespace utility::platform /// \param[in] path the path to check. /// \returns true in case it is a directory. /// \todo android platform always returns false. Check if there is a way around this or redesign this. - static bool is_directory(psl::string_view path) - { - return std::filesystem::is_directory(to_platform(path)); - } + static bool is_directory(psl::string_view path) { return std::filesystem::is_directory(to_platform(path)); } /// \brief sanitizes the seperators into the application wide standard one. /// \param[in] path the path to sanitize. @@ -320,9 +372,9 @@ namespace utility::platform /// \brief file i/o and manpulations utilities namespace namespace file { - #if defined(PLATFORM_ANDROID) +#if defined(PLATFORM_ANDROID) extern AAssetManager* ANDROID_ASSET_MANAGER; - #endif +#endif /// \brief checks if the given path points to a file or not. /// /// checks if the given path points to a file or not. This path can be relative to the current working @@ -348,8 +400,8 @@ namespace utility::platform /// interaction with the filesystem. Please verify that your target platform actually supports this function for /// the file you wish to load. bool read(psl::string_view filename, - std::vector& out, - size_t count = std::numeric_limits::max()); + std::vector& out, + size_t count = std::numeric_limits::max()); /// \brief reads the given filepath's contents into a psl::string container. /// \param[in] filename the path to the file. @@ -412,6 +464,8 @@ namespace utility::platform /// \returns the transformed path. static psl::string to_windows(psl::string_view path) { return directory::to_windows(path); } + static psl::string to_android(psl::string_view path) { return directory::to_android(path); } + /// \brief transforms the given path to the current platforms format. /// \param[in] path the path to transform. /// \returns the transformed path. @@ -420,7 +474,7 @@ namespace utility::platform #ifdef PLATFORM_WINDOWS return to_windows(path); #elif defined(PLATFORM_ANDROID) - return psl::string{path}; + return to_android(path); #else return to_unix(path); #endif diff --git a/psl/src/library.cpp b/psl/src/library.cpp index 292b81d7..dedf95a2 100644 --- a/psl/src/library.cpp +++ b/psl/src/library.cpp @@ -69,9 +69,10 @@ library::library(psl::string8::view lib, std::vector environment psl::string8_t extension = filepath.substr(filepath.find_last_of('.') + 1); file* metaPtr = nullptr; - psl_assert(utility::platform::file::exists(root + metapath), - "could not find file associated with UID {} at {}",uid.to_string(), root + metapath); - s.deserialize(metaPtr, root + metapath); + auto full_metapath = utility::platform::file::to_platform(root + metapath); + psl_assert(utility::platform::file::exists(full_metapath), + "could not find file associated with UID {} at {}",uid.to_string(), full_metapath); + s.deserialize(metaPtr, full_metapath); psl_assert(metaPtr->ID() == uid, "UID mismatch between library and metafile library expected {} but file has {}", uid.to_string(), metaPtr->ID().to_string()); @@ -259,4 +260,4 @@ void library::replace_content(psl::UID uid, psl::string8_t content) noexcept { it->second.file_data = std::move(content); } -} \ No newline at end of file +} diff --git a/psl/src/platform_utils.cpp b/psl/src/platform_utils.cpp index 57a9e068..e933e6db 100644 --- a/psl/src/platform_utils.cpp +++ b/psl/src/platform_utils.cpp @@ -333,7 +333,7 @@ utility::debug::trace_info utility::debug::demangle(void* target) bool utility::platform::file::exists(psl::string_view filename) { #if defined(PLATFORM_ANDROID) - return AAssetManager_open(ANDROID_ASSET_MANAGER, filename.data(), AASSET_MODE_UNKNOWN) != nullptr; + return AAssetManager_open(ANDROID_ASSET_MANAGER, directory::to_platform(filename).data(), AASSET_MODE_UNKNOWN) != nullptr; #else return std::filesystem::exists(directory::to_platform(filename)); #endif @@ -343,7 +343,7 @@ bool utility::platform::file::exists(psl::string_view filename) bool utility::platform::file::read(psl::string_view filename, std::vector& out, size_t count) { psl::string file_name = directory::to_platform(filename); - psl::print(psl::level_t::verbose, "checking if '{}' exists", directory::to_platform(filename)); + psl_assert(exists(file_name), "Could not find filename {}", file_name); #if !defined(PLATFORM_ANDROID) psl::ifstream file(file_name, std::ios::binary | std::ios::ate); if(!file.is_open()) @@ -397,6 +397,7 @@ bool utility::platform::file::read(psl::string_view filename, std::vector Date: Sun, 27 Feb 2022 16:09:53 +0200 Subject: [PATCH 09/16] Cleaned up android project generation --- CMakeLists.txt | 43 +++- CMakePresets.json | 38 ++- .../main/android/build.gradle | 3 +- .../main/android/gradle.properties | 4 + .../main/android/main/build.gradle | 8 +- .../android/main/src/main/AndroidManifest.xml | 10 +- .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../main/src/main/res/values/strings.xml | 4 + .../main}/android/package_0/build.gradle | 0 core/main/android/settings.gradle | 3 + tools/android.py | 236 +++++++++++------- .../src/main/res/values/strings.xml.template | 4 - .../android/settings.gradle.template | 3 - 16 files changed, 235 insertions(+), 121 deletions(-) rename tools/templates/android/build.gradle.template => core/main/android/build.gradle (75%) rename tools/templates/android/gradle.properties.template => core/main/android/gradle.properties (91%) rename tools/templates/android/app/build.gradle.template => core/main/android/main/build.gradle (72%) rename tools/templates/android/app/src/main/AndroidManifest.xml.template => core/main/android/main/src/main/AndroidManifest.xml (84%) rename {tools/templates/android/app => core/main/android/main}/src/main/res/mipmap-hdpi/ic_launcher.png (100%) rename {tools/templates/android/app => core/main/android/main}/src/main/res/mipmap-mdpi/ic_launcher.png (100%) rename {tools/templates/android/app => core/main/android/main}/src/main/res/mipmap-xhdpi/ic_launcher.png (100%) rename {tools/templates/android/app => core/main/android/main}/src/main/res/mipmap-xxhdpi/ic_launcher.png (100%) create mode 100644 core/main/android/main/src/main/res/values/strings.xml rename {tools/templates => core/main}/android/package_0/build.gradle (100%) create mode 100644 core/main/android/settings.gradle delete mode 100644 tools/templates/android/app/src/main/res/values/strings.xml.template delete mode 100644 tools/templates/android/settings.gradle.template diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d5eae33..b9c0f088 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,15 +49,12 @@ OPTION(PE_BENCHMARKS "Enable the generation of benchmarks" OFF) set(PE_BUILD_DIR "${CMAKE_BINARY_DIR}/builds/" CACHE PATH "target location where to build the project to") set(PE_DEFINES -DUNICODE;-D_UNICODE;-DNOMINMAX CACHE INTERNAL "") OPTION(PE_DEFAULT_COMPILE_OPTIONS "Use the default set of compile options (check 'compile options' section in the CMakelists.txt file)" TRUE) - +set(ANDROID_SDK "" CACHE PATH "override root android sdk location") +set(ANDROID_BUNDLETOOL "" CACHE PATH "override android bundletool location") +set(ANDROID_GRADLE "" CACHE PATH "override gradle location") set_property(GLOBAL PROPERTY USE_FOLDERS ON) -if(PE_GLES) - message("enabling GLES") - list(APPEND PE_DEFINES -DPE_GLES) -endif() - -if(PE_PLATFORM STREQUAL AUTO) +if(PE_PLATFORM STREQUAL "AUTO") if(WIN32) set(PE_PLATFORM WINDOWS) elseif(UNIX) @@ -67,6 +64,38 @@ if(PE_PLATFORM STREQUAL AUTO) endif() endif() +if(PE_PLATFORM STREQUAL "ANDROID" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/AndroidManifest.xml") + SET(Python_ADDITIONAL_VERSIONS 3 3.0) + find_package(PythonInterp REQUIRED) + + string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) + add_custom_target(paradigm_android_generate) + add_custom_command(TARGET paradigm_android_generate + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/android.py + --output ${PE_BUILD_DIR}/android + --sdk "${ANDROID_SDK}" + --gradle "${ANDROID_GRADLE}" + --bundletool "${ANDROID_BUNDLETOOL}" + USES_TERMINAL BYPRODUCTS ${PE_BUILD_DIR}/android/gradle.properties) + + add_custom_target(paradigm_android_build DEPENDS paradigm_android_generate) + add_custom_command(TARGET paradigm_android_build + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/android.py + --output ${PE_BUILD_DIR}/android + --build gles ${PE_GLES} vulkan ${PE_VULKAN} vulkan.version ${VK_VERSION} + --type ${build_type} + --sdk "${ANDROID_SDK}" + --gradle "${ANDROID_GRADLE}" + --bundletool "${ANDROID_BUNDLETOOL}" + USES_TERMINAL) + return() +endif() + +if(PE_GLES) + message("enabling GLES") + list(APPEND PE_DEFINES -DPE_GLES) +endif() + string(TOUPPER PE_MODE PE_MODE) list(APPEND PE_DEFINES -DPLATFORM_${PE_MODE}) diff --git a/CMakePresets.json b/CMakePresets.json index 3b0d9ac7..72be50cb 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -202,6 +202,32 @@ "cacheVariables": { "PE_MODE": "release" } + }, + { + "name": "android-release-vulkan", + "displayName": "Android Vulkan (Release)", + "inherits": [ + "settings-vulkan", + "settings-project" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "PE_MODE": "release", + "PE_PLATFORM": "ANDROID" + } + }, + { + "name": "android-debug-vulkan", + "displayName": "Android Vulkan (Debug)", + "inherits": [ + "settings-vulkan", + "settings-project" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "PE_MODE": "debug", + "PE_PLATFORM": "ANDROID" + } } ], "buildPresets": [ @@ -248,6 +274,16 @@ "name": "gnu-linux-release-vulkan", "displayName": "Release", "configurePreset": "gnu-linux-release-vulkan" + }, + { + "name": "android-release-vulkan", + "displayName": "Release", + "configurePreset": "android-release-vulkan" + }, + { + "name": "android-debug-vulkan", + "displayName": "Debug", + "configurePreset": "android-debug-vulkan" } ] -} \ No newline at end of file +} diff --git a/tools/templates/android/build.gradle.template b/core/main/android/build.gradle similarity index 75% rename from tools/templates/android/build.gradle.template rename to core/main/android/build.gradle index 3a3b3f0a..bfcc6a21 100644 --- a/tools/templates/android/build.gradle.template +++ b/core/main/android/build.gradle @@ -1,4 +1,3 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() @@ -18,4 +17,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} \ No newline at end of file +} diff --git a/tools/templates/android/gradle.properties.template b/core/main/android/gradle.properties similarity index 91% rename from tools/templates/android/gradle.properties.template rename to core/main/android/gradle.properties index 9e6fce10..8568f525 100644 --- a/tools/templates/android/gradle.properties.template +++ b/core/main/android/gradle.properties @@ -17,3 +17,7 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +paradigm.gles=OFF +paradigm.vulkan=ON +paradigm.vulkan.version=1.2.148 diff --git a/tools/templates/android/app/build.gradle.template b/core/main/android/main/build.gradle similarity index 72% rename from tools/templates/android/app/build.gradle.template rename to core/main/android/main/build.gradle index 1171830e..7bb8e634 100644 --- a/tools/templates/android/app/build.gradle.template +++ b/core/main/android/main/build.gradle @@ -5,16 +5,20 @@ android { ndkVersion '25.0.8151533' assetPacks = [":package_0"] defaultConfig { - applicationId = 'com.{{COMPANY}}.{{PROJECT}}' + applicationId = 'com.paradigmengine.main' minSdkVersion 21 targetSdkVersion 31 externalNativeBuild { cmake { - arguments '-DANDROID_STL=c++_static', '-DPE_PLATFORM=ANDROID', '-DPE_GLES=OFF', '-DPE_VULKAN=ON', '-DPE_MAKE_EXE=ON', '-DVK_VERSION=1.2.148', '-DPE_TESTS=OFF' + arguments '-DANDROID_STL=c++_static', '-DPE_PLATFORM=ANDROID', '-DPE_GLES=' + getProperty('paradigm.gles'), '-DPE_VULKAN=' + getProperty('paradigm.vulkan'), '-DPE_MAKE_EXE=ON', '-DVK_VERSION=' + getProperty('paradigm.vulkan.version'), '-DPE_TESTS=OFF' } } ndk { abiFilters 'arm64-v8a', 'x86_64' + debugSymbolLevel 'full' + } + packagingOptions { + doNotStrip '**.so' } } buildTypes { diff --git a/tools/templates/android/app/src/main/AndroidManifest.xml.template b/core/main/android/main/src/main/AndroidManifest.xml similarity index 84% rename from tools/templates/android/app/src/main/AndroidManifest.xml.template rename to core/main/android/main/src/main/AndroidManifest.xml index f018788b..7a62bb88 100644 --- a/tools/templates/android/app/src/main/AndroidManifest.xml.template +++ b/core/main/android/main/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ @@ -10,17 +10,17 @@ android:allowBackup="false" android:fullBackupContent="false" android:icon="@mipmap/ic_launcher" - android:label="@string/app_name" + android:label="@string/application_name" android:hasCode="false"> + android:value="main" /> @@ -29,4 +29,4 @@ - \ No newline at end of file + diff --git a/tools/templates/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/core/main/android/main/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from tools/templates/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to core/main/android/main/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/tools/templates/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/core/main/android/main/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from tools/templates/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to core/main/android/main/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/tools/templates/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/core/main/android/main/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from tools/templates/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to core/main/android/main/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/tools/templates/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/core/main/android/main/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from tools/templates/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to core/main/android/main/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/core/main/android/main/src/main/res/values/strings.xml b/core/main/android/main/src/main/res/values/strings.xml new file mode 100644 index 00000000..a30c6c27 --- /dev/null +++ b/core/main/android/main/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + Paradigm + diff --git a/tools/templates/android/package_0/build.gradle b/core/main/android/package_0/build.gradle similarity index 100% rename from tools/templates/android/package_0/build.gradle rename to core/main/android/package_0/build.gradle diff --git a/core/main/android/settings.gradle b/core/main/android/settings.gradle new file mode 100644 index 00000000..ee7ce775 --- /dev/null +++ b/core/main/android/settings.gradle @@ -0,0 +1,3 @@ +include ':main' +include ':package_0' +rootProject.name = "main" diff --git a/tools/android.py b/tools/android.py index f4134eaa..ad8d3a13 100644 --- a/tools/android.py +++ b/tools/android.py @@ -1,139 +1,181 @@ from argparse import ArgumentParser +from email.mime import application import io import os import shutil import subprocess +from distutils.dir_util import copy_tree CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) ROOT_DIR = os.path.join(CURRENT_DIR, '..') def run_command(command=[], directory=None, print_stdout=False, catch_stdout=False): - process = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=directory) + process = subprocess.Popen(command, stdout=os.sys.stdout if print_stdout and not catch_stdout else subprocess.PIPE, stderr=os.sys.stderr, cwd=directory) output = [] - if print_stdout: - for line in io.TextIOWrapper(process.stdout, newline=''): - if not line.endswith('\r') and catch_stdout: - output.append(line[:len(line)-1] if line[-1] == os.linesep else line) - elif catch_stdout: - for line in io.TextIOWrapper(process.stdout, newline=os.linesep): - line = line.rsplit('\r', maxsplit=1)[-1] - output.append(line[:len(line)-1]) - process.stdout.close() + if catch_stdout: + if print_stdout: + for line in io.TextIOWrapper(process.stdout, newline=''): + if not line.endswith('\r'): + output.append(line[:len(line)-1] if line[-1] == os.linesep else line) + else: + for line in io.TextIOWrapper(process.stdout, newline=os.linesep): + line = line.rsplit('\r', maxsplit=1)[-1] + output.append(line[:len(line)-1]) + process.stdout.close() process.wait() if process.returncode != 0: raise Exception(f"Raised exitcode '{process.returncode}' while trying to run the command '{' '.join(comm for comm in command)}'") return output -def generate(directory, project="main"): - os.makedirs(directory, exist_ok=True) - if not os.path.exists(os.path.join(directory, 'settings.gradle')): - run_command(command=[ - 'gradle', 'init', - '--type', 'basic', - '--dsl', 'groovy', - '--project-name', project, - '--incubating' - ], directory=directory, print_stdout=True) - - android_templates = os.path.join(CURRENT_DIR, 'templates', 'android') - - templates = [os.path.join(dp, f) for dp, dn, filenames in os.walk(android_templates) for f in filenames if os.path.splitext(f)[1] == '.template'] - - for template in templates: - os.makedirs(os.path.dirname(os.path.join(directory, os.path.relpath(template, android_templates))), exist_ok=True) - with open(template, 'r') as template_file, open(os.path.join(directory, os.path.relpath(template, android_templates).rsplit('.', maxsplit=1)[0]), 'w') as file: - template = template_file.read() - template = template.replace('{{PROJECT}}', project) - template = template.replace('{{COMPANY}}', "paradigmengine") - file.write(template) - - resources = [os.path.join(dp, f) for dp, dn, filenames in os.walk(android_templates) for f in filenames if os.path.splitext(f)[1] != '.template'] - for resource in resources: - os.makedirs(os.path.dirname(os.path.join(directory, os.path.relpath(resource, android_templates))), exist_ok=True) - with open(resource, 'rb') as resource_file, open(os.path.join(directory, os.path.relpath(resource, android_templates)), 'wb') as file: - file.write(resource_file.read()) - - # create the symlinks to the source code - cpp_dir = os.path.join(directory, 'app', 'src', 'main') - [ os.symlink(os.path.join(ROOT_DIR, dir), os.path.join(cpp_dir, dir)) for dir in ['psl', 'core', 'extern', 'cmake', 'CMakeLists.txt', 'tools'] if not os.path.exists(os.path.join(cpp_dir, dir))] - -def parse_installed_packages(channel=0): - sdkman_output = run_command(["sdkmanager", "--list", f"--channel={str(channel)}"], catch_stdout=True) - - packages = {'installed': {}, 'available': {}} - for line in [package for package in sdkman_output if package.count('|') == 3]: - name, version, _, location = (l.strip() for l in line.split('|')) - if name == "Path" or name.startswith('-'): - continue - packages['installed'][name] = {'version': version, 'location': location} - - for line in [package for package in sdkman_output if package.count('|') == 2]: - name, version, _ = (l.strip() for l in line.split('|')) - if name == "Path" or name.startswith('-'): - continue - packages['available'][name] = {'version': version } - - return packages - -def install_required_packages(): - packages = parse_installed_packages(channel=3) - - def install_required(package, channel=0): +class Android: + def __init__(self, directory, sdk=None, gradle=None, bundletool=None) -> None: + self._sdk = sdk + if self._sdk != None and self._sdk != "": + os.environ["ANDROID_SDK_ROOT"] = self._sdk + self._gradle = gradle or "" + self._bundletool = bundletool or "" + self._directory = directory + self._generated = os.path.exists(directory) and os.path.exists(os.path.join(directory, 'build.gradle')) + self._regenerate_apks = set() + packages = Android._parse_installed_packages(channel=3, sdk=self._sdk) + for dependency, channel in Android.dependencies(): + Android._install_required(packages, dependency, channel, sdk=self._sdk) + + def _install_required(packages, package, channel=0, sdk=None): if package in packages["installed"]: return print(f"Missing '{package}', trying to install now..") if package in packages["available"]: print(f"installing '{package}'") - run_command(command=["sdkmanager", package, f"--channel={str(channel)}"], print_stdout=True, catch_stdout=False) + application = os.path.join(sdk, 'cmdline-tools', 'latest', 'bin', 'sdkmanager') if sdk != None else 'sdkmanager' + run_command(command=[application, package, f"--channel={str(channel)}"], print_stdout=True, catch_stdout=False) else: raise Exception(f"Could not find the required sdk package '{package}'") + def _parse_installed_packages(channel=0, sdk=None): + application = os.path.join(sdk, 'cmdline-tools', 'latest', 'bin', 'sdkmanager') if sdk != None else 'sdkmanager' + sdkman_output = run_command([application, "--list", f"--channel={str(channel)}"], catch_stdout=True) + + packages = {'installed': {}, 'available': {}} + for line in [package for package in sdkman_output if package.count('|') == 3]: + name, version, _, location = (l.strip() for l in line.split('|')) + if name == "Path" or name.startswith('-'): + continue + packages['installed'][name] = {'version': version, 'location': location} + + for line in [package for package in sdkman_output if package.count('|') == 2]: + name, version, _ = (l.strip() for l in line.split('|')) + if name == "Path" or name.startswith('-'): + continue + packages['available'][name] = {'version': version } + + return packages + + def dependencies() -> list[str]: + return [("platforms;android-31", 0), ("cmake;3.22.1", 3), ("ndk;25.0.8151533", 1)] + + def is_generated(self) -> bool: + return self._generated + + def generate(self, overwrite=False) -> None: + if self._generated: + if not overwrite: return + + shutil.rmtree(self._directory, ignore_errors=True) + self._generated = False + + os.makedirs(self._directory, exist_ok=True) + if not os.path.exists(os.path.join(self._directory, 'settings.gradle')): + application = os.path.join(self._gradle, 'gradle') + run_command(command=[ + application, 'init', + '--type', 'basic', + '--dsl', 'groovy', + '--project-name', "main", + '--incubating' + ], directory=self._directory, print_stdout=True) + + android_build_root = os.path.join(CURRENT_DIR, '..', 'core', 'main', 'android') + copy_tree(android_build_root, self._directory) + + # create the symlinks to the source code + cpp_dir = os.path.join(self._directory, 'main', 'src', 'main') + [ os.symlink(os.path.join(ROOT_DIR, dir), os.path.join(cpp_dir, dir)) for dir in ['psl', 'core', 'extern', 'cmake', 'CMakeLists.txt', 'tools'] if not os.path.exists(os.path.join(cpp_dir, dir))] + self._generated = True + + def build(self, type="debug", arguments=None) -> None: + if not self._generated: + raise Exception("Project has not been generated yet") + print(f"building main-{type}.aab") + commands =[] + if type == 'debug': + commands = [':main:bundleDebug'] + elif type == 'release': + commands = [':main:bundleRelease'] + if arguments is not None: + commands.extend([f'-Pparadigm.{key}={value}' for key, value in zip(*[iter(arguments)]*2)]) + run_command(['./gradlew'] + commands, directory=self._directory, print_stdout=True) + self._regenerate_apks.add(type) + + def build_apks(self, type="debug") -> None: + if not os.path.exists(os.path.join('main', 'build', 'outputs', 'bundle', type, f'main-{type}.aab')): + raise Exception("No AAB generated yet, please run 'build' first") + + print(f"building main-{type}.apks") + application = os.path.join(self._bundletool, 'bundletool') + run_command([ + application, + 'build-apks', + f"--bundle={os.path.join('main', 'build', 'outputs', 'bundle', type, f'main-{type}.aab')}", + f"--output={os.path.join('main', 'build', 'outputs', 'bundle', type, f'main-{type}.apks')}", + "--overwrite", + '--local-testing'], directory=self._directory, print_stdout=True) + if type in self._regenerate_apks: + self._regenerate_apks.remove(type) + + def install(self, type='debug'): + if not os.path.exists(os.path.join('main', 'build', 'outputs', 'bundle', type, f'main-{type}.apks')): + self.build_apks(type) + + if type in self._regenerate_apks: + print("main-{type}.apks out of date, trying to rebuild...") + self.build_apks(type) + + print(f"installing main-{type}.apks") + application = os.path.join(self._bundletool, 'bundletool') + run_command([application, 'install-apks', f"--apks={os.path.join('main', 'build', 'outputs', 'bundle', type, f'main-{type}.apks')}"], directory=self._directory, print_stdout=True) + + def run(self): + output = run_command(['adb' 'shell' 'pm' 'list' 'packages', 'com.paradigmengine.main'], catch_stdout=True) + if(len(output) != 1 or output[0] != 'com.paradigmengine.main'): + raise Exception("App wasn't installed, please install first") + + application = os.path.join(self._sdk, 'platform-tools', 'adb') if self._sdk != None else 'adb' + run_command([application, 'shell', 'am', 'start', '-n', 'com.paradigmengine.main/com.paradigmengine.main.MainActivity'], print_stdout=True) - install_required("platforms;android-31") - install_required("cmake;3.22.1", channel=3) - install_required("ndk;25.0.8151533", channel=1) - -def build(directory, type='debug'): - commands =[] - if type == 'debug': - commands = [':app:bundleDebug'] - elif type == 'release': - commands = [':app:bundleRelease'] - - run_command(['./gradlew'] + commands, directory=directory, print_stdout=True) - -def install(directory, type='debug'): - run_command(['adb', 'install', '-r', os.path.join(directory, 'app', 'build', 'outputs', 'apk', type, f'app-{type}.apk')], print_stdout=True) -def run(): - run_command(['adb', 'shell', 'am', 'start', '-n', 'com.paradigmengine.main/com.paradigmengine.main.MainActivity'], print_stdout=True) - def main(): parser = ArgumentParser() parser.add_argument("--output", default=os.path.join(ROOT_DIR, "builds", "android")) parser.add_argument("--sdk", default=None, help="set to override the used android sdk, falls back to path available one") + parser.add_argument("--gradle", default=None, help="set to override the used gradle, falls back to path available one") + parser.add_argument("--bundletool", default=None, help="set to override the used bundletool, falls back to path available one") parser.add_argument("-f", "--force", action="store_true", help="Forcibly generate the build directory even if it already exists") parser.add_argument("-r", "--run", action="store_true", help="run the intent after installation") parser.add_argument("-i", "--install", action="store_true", help="install the apk") - parser.add_argument("-b", "--build", action="store_true", help="build the apk") + parser.add_argument("-b", "--build", default=False, nargs='*', help="build the apk") parser.add_argument("-t", "--type", default="debug", help="type to generate") parser.add_argument("--purge", action="store_true", help="Delete previous install, and generate from scratch") args = parser.parse_args() - install_required_packages() - if args.purge: - args.force = True - shutil.rmtree(args.output, ignore_errors=True) - - - if not os.path.exists(args.output) or args.force: - generate(args.output) + android = Android(args.output, sdk=args.sdk, gradle=args.gradle, bundletool=args.bundletool) + android.generate(overwrite=args.purge) - if args.build: - build(args.output, args.type) + if isinstance(args.build, list): + android.build(args.type, args.build) if args.install: - install(args.output, args.type) + android.install(args.type) if args.run: - run() + android.run() if __name__ == "__main__": main() diff --git a/tools/templates/android/app/src/main/res/values/strings.xml.template b/tools/templates/android/app/src/main/res/values/strings.xml.template deleted file mode 100644 index 68023d95..00000000 --- a/tools/templates/android/app/src/main/res/values/strings.xml.template +++ /dev/null @@ -1,4 +0,0 @@ - - - {{PROJECT}} - \ No newline at end of file diff --git a/tools/templates/android/settings.gradle.template b/tools/templates/android/settings.gradle.template deleted file mode 100644 index 1d95c246..00000000 --- a/tools/templates/android/settings.gradle.template +++ /dev/null @@ -1,3 +0,0 @@ -include ':app' -include ':package_0' -rootProject.name = "{{PROJECT}}" From 534c8e3188c691035644a370601dbdae6bf5f46b Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Mon, 28 Feb 2022 14:53:40 +0200 Subject: [PATCH 10/16] support android CI building --- .github/workflows/main.yml | 35 ++++++++++++++++++++++++++++++++--- CMakeLists.txt | 24 +++++++++++++++--------- tools/android.py | 17 ++++++++++------- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6d434dd..e67e3050 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,9 +101,9 @@ jobs: container: image: gcc:11.2.0 strategy: - fail-fast: false - matrix: - graphics: [vulkan, all] + fail-fast: false + matrix: + graphics: [vulkan, all] name: ubuntu-benchmark needs: ubuntu runs-on: ubuntu-latest @@ -126,3 +126,32 @@ jobs: name: ubuntu-${{ matrix.graphics }} path: results.json if-no-files-found: error + android: + strategy: + fail-fast: false + matrix: + graphics: [vulkan] + name: android + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v1 + with: + submodules: recursive + - name: setup python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + architecture: 'x64' + - name: setup dependencies + run: | + wget https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1-linux-x86_64.sh -q -O /tmp/cmake-install.sh \ + && chmod u+x /tmp/cmake-install.sh \ + && mkdir /opt/cmake \ + && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake \ + && rm /tmp/cmake-install.sh + ln -s /opt/cmake/bin/* /usr/bin/ + - name: initialize + run: cmake --preset=android-release-${{ matrix.graphics }} + - name: compile + run: cmake --build --preset=android-release-${{ matrix.graphics }} diff --git a/CMakeLists.txt b/CMakeLists.txt index b9c0f088..85472904 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,26 +67,32 @@ endif() if(PE_PLATFORM STREQUAL "ANDROID" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/AndroidManifest.xml") SET(Python_ADDITIONAL_VERSIONS 3 3.0) find_package(PythonInterp REQUIRED) - + set(ANDROID_PY_ARGS) + if(NOT ANDROID_SDK STREQUAL "") + list(APPEND --sdk "${ANDROID_SDK}" ANDROID_PY_ARGS) + endif() + if(NOT ANDROID_GRADLE STREQUAL "") + list(APPEND --gradle "${ANDROID_GRADLE}" ANDROID_PY_ARGS) + endif() + if(NOT ANDROID_BUNDLETOOL STREQUAL "") + list(APPEND --bundletool "${ANDROID_BUNDLETOOL}" ANDROID_PY_ARGS) + endif() + string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) - add_custom_target(paradigm_android_generate) + add_custom_target(paradigm_android_generate ALL) add_custom_command(TARGET paradigm_android_generate COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/android.py --output ${PE_BUILD_DIR}/android - --sdk "${ANDROID_SDK}" - --gradle "${ANDROID_GRADLE}" - --bundletool "${ANDROID_BUNDLETOOL}" + ${ANDROID_PY_ARGS} USES_TERMINAL BYPRODUCTS ${PE_BUILD_DIR}/android/gradle.properties) - add_custom_target(paradigm_android_build DEPENDS paradigm_android_generate) + add_custom_target(paradigm_android_build ALL DEPENDS paradigm_android_generate) add_custom_command(TARGET paradigm_android_build COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/android.py --output ${PE_BUILD_DIR}/android --build gles ${PE_GLES} vulkan ${PE_VULKAN} vulkan.version ${VK_VERSION} --type ${build_type} - --sdk "${ANDROID_SDK}" - --gradle "${ANDROID_GRADLE}" - --bundletool "${ANDROID_BUNDLETOOL}" + ${ANDROID_PY_ARGS} USES_TERMINAL) return() endif() diff --git a/tools/android.py b/tools/android.py index ad8d3a13..25863b9f 100644 --- a/tools/android.py +++ b/tools/android.py @@ -4,7 +4,6 @@ import os import shutil import subprocess -from distutils.dir_util import copy_tree CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) ROOT_DIR = os.path.join(CURRENT_DIR, '..') @@ -28,18 +27,21 @@ def run_command(command=[], directory=None, print_stdout=False, catch_stdout=Fal return output class Android: - def __init__(self, directory, sdk=None, gradle=None, bundletool=None) -> None: + def __init__(self, directory, sdk=None, gradle=None, bundletool=None, skip_setup=False) -> None: self._sdk = sdk if self._sdk != None and self._sdk != "": os.environ["ANDROID_SDK_ROOT"] = self._sdk + elif "ANDROID_SDK_ROOT" in os.environ: + self._sdk = os.environ["ANDROID_SDK_ROOT"] self._gradle = gradle or "" self._bundletool = bundletool or "" self._directory = directory self._generated = os.path.exists(directory) and os.path.exists(os.path.join(directory, 'build.gradle')) self._regenerate_apks = set() - packages = Android._parse_installed_packages(channel=3, sdk=self._sdk) - for dependency, channel in Android.dependencies(): - Android._install_required(packages, dependency, channel, sdk=self._sdk) + if not skip_setup: + packages = Android._parse_installed_packages(channel=3, sdk=self._sdk) + for dependency, channel in Android.dependencies(): + Android._install_required(packages, dependency, channel, sdk=self._sdk) def _install_required(packages, package, channel=0, sdk=None): if package in packages["installed"]: @@ -95,7 +97,7 @@ def generate(self, overwrite=False) -> None: ], directory=self._directory, print_stdout=True) android_build_root = os.path.join(CURRENT_DIR, '..', 'core', 'main', 'android') - copy_tree(android_build_root, self._directory) + shutil.copytree(android_build_root, self._directory, dirs_exist_ok=True) # create the symlinks to the source code cpp_dir = os.path.join(self._directory, 'main', 'src', 'main') @@ -165,9 +167,10 @@ def main(): parser.add_argument("-b", "--build", default=False, nargs='*', help="build the apk") parser.add_argument("-t", "--type", default="debug", help="type to generate") parser.add_argument("--purge", action="store_true", help="Delete previous install, and generate from scratch") + parser.add_argument("--skip-setup", action="store_true", help="Skip the setup phase where the SDK tools are installed") args = parser.parse_args() - android = Android(args.output, sdk=args.sdk, gradle=args.gradle, bundletool=args.bundletool) + android = Android(args.output, sdk=args.sdk, gradle=args.gradle, bundletool=args.bundletool, skip_setup=args.skip_setup) android.generate(overwrite=args.purge) if isinstance(args.build, list): From 1b4cec490ce96a6b8cb685fbf31a41070728916a Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Mon, 28 Feb 2022 15:23:35 +0200 Subject: [PATCH 11/16] remove unneeded deps --- .github/workflows/main.yml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e67e3050..9806ccf5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -127,6 +127,9 @@ jobs: path: results.json if-no-files-found: error android: + env: + CC: gcc + CXX: g++ strategy: fail-fast: false matrix: @@ -138,19 +141,6 @@ jobs: uses: actions/checkout@v1 with: submodules: recursive - - name: setup python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - architecture: 'x64' - - name: setup dependencies - run: | - wget https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1-linux-x86_64.sh -q -O /tmp/cmake-install.sh \ - && chmod u+x /tmp/cmake-install.sh \ - && mkdir /opt/cmake \ - && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake \ - && rm /tmp/cmake-install.sh - ln -s /opt/cmake/bin/* /usr/bin/ - name: initialize run: cmake --preset=android-release-${{ matrix.graphics }} - name: compile From e9581a928c01348b5ce8c2772260c5b8624776c5 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Mon, 28 Feb 2022 15:24:24 +0200 Subject: [PATCH 12/16] removed list annotation --- tools/android.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/android.py b/tools/android.py index 25863b9f..fab53026 100644 --- a/tools/android.py +++ b/tools/android.py @@ -72,7 +72,7 @@ def _parse_installed_packages(channel=0, sdk=None): return packages - def dependencies() -> list[str]: + def dependencies(): return [("platforms;android-31", 0), ("cmake;3.22.1", 3), ("ndk;25.0.8151533", 1)] def is_generated(self) -> bool: From a6022ffdff9135d69102ee9f01f5dcdc927b8e0f Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Mon, 28 Feb 2022 15:28:31 +0200 Subject: [PATCH 13/16] added sdk manager accept all licenses --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9806ccf5..b1e08984 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -141,6 +141,8 @@ jobs: uses: actions/checkout@v1 with: submodules: recursive + - name: dependencies + run: yes | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --licenses - name: initialize run: cmake --preset=android-release-${{ matrix.graphics }} - name: compile From e7b231c9c9eb9a20f13447e604f5890370f033a9 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Mon, 28 Feb 2022 15:35:45 +0200 Subject: [PATCH 14/16] add some extra printinh --- tools/android.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/android.py b/tools/android.py index fab53026..99afac34 100644 --- a/tools/android.py +++ b/tools/android.py @@ -45,6 +45,7 @@ def __init__(self, directory, sdk=None, gradle=None, bundletool=None, skip_setup def _install_required(packages, package, channel=0, sdk=None): if package in packages["installed"]: + print(f"sdk package '{package}' was found") return print(f"Missing '{package}', trying to install now..") if package in packages["available"]: @@ -115,6 +116,8 @@ def build(self, type="debug", arguments=None) -> None: commands = [':main:bundleRelease'] if arguments is not None: commands.extend([f'-Pparadigm.{key}={value}' for key, value in zip(*[iter(arguments)]*2)]) + + commands.append('--stacktrace') run_command(['./gradlew'] + commands, directory=self._directory, print_stdout=True) self._regenerate_apks.add(type) From 5a73449f3099bc12ea57688120374323c8e3ac01 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Mon, 28 Feb 2022 15:43:33 +0200 Subject: [PATCH 15/16] Added readme --- core/main/android/package_0/src/main/assets/readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 core/main/android/package_0/src/main/assets/readme.md diff --git a/core/main/android/package_0/src/main/assets/readme.md b/core/main/android/package_0/src/main/assets/readme.md new file mode 100644 index 00000000..df3a0c88 --- /dev/null +++ b/core/main/android/package_0/src/main/assets/readme.md @@ -0,0 +1 @@ +Place assets here to default include them in the app From 1ecca14a913c1c9287453281487176ad6d40cd36 Mon Sep 17 00:00:00 2001 From: Jessy De Lannoit Date: Mon, 28 Feb 2022 15:51:54 +0200 Subject: [PATCH 16/16] added verification step --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b1e08984..9d265cf9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -147,3 +147,5 @@ jobs: run: cmake --preset=android-release-${{ matrix.graphics }} - name: compile run: cmake --build --preset=android-release-${{ matrix.graphics }} + - name: verify + run: python3 -c "import os;import sys;sys.exit(0) if os.path.exists('builds/android/main/build/outputs/bundle/release/main-release.aab') else sys.exit(1)"