From 2771be2a5788c1bdbf53a9f13c11da8d79ad30e7 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 18 Feb 2022 15:13:16 -0500 Subject: [PATCH] Fix tvOS build, move common UIKit stuff into it's own folder --- CMakeLists.txt | 4 +- cmake/BuildShaders.cmake | 4 +- platforms/ios/CMakeLists.txt | 4 +- platforms/tvos/CMakeLists.txt | 129 ++++----- platforms/tvos/ViewController.mm.in | 259 ------------------ platforms/tvos/file.mm | 30 -- platforms/{ios => uikit}/ViewController.mm.in | 0 platforms/{ios => uikit}/file.mm | 0 8 files changed, 64 insertions(+), 366 deletions(-) delete mode 100644 platforms/tvos/ViewController.mm.in delete mode 100755 platforms/tvos/file.mm rename platforms/{ios => uikit}/ViewController.mm.in (100%) rename platforms/{ios => uikit}/file.mm (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4b28a..d40c7f4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ endif() if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS") message("iOS build detected!") - set(ENABLE_VULKAN TRUE) + #set(ENABLE_VULKAN TRUE) set(ENABLE_DARWIN TRUE) set(ENABLE_IOS TRUE) set(ENABLE_METAL TRUE) @@ -44,7 +44,7 @@ endif() if(${CMAKE_SYSTEM_NAME} STREQUAL "tvOS") message("tvOS build detected!") - set(ENABLE_VULKAN TRUE) + #set(ENABLE_VULKAN TRUE) set(ENABLE_DARWIN TRUE) set(ENABLE_TVOS TRUE) set(ENABLE_METAL TRUE) diff --git a/cmake/BuildShaders.cmake b/cmake/BuildShaders.cmake index 77b0957..fb5ba15 100755 --- a/cmake/BuildShaders.cmake +++ b/cmake/BuildShaders.cmake @@ -8,7 +8,7 @@ function(add_shader_command) set(EXTRA_PLATFORM_ARG "0") # if targeting ios, we want to use the host's shader compiler - if(ENABLE_IOS) + if(ENABLE_IOS OR ENABLE_TVOS) set(SHADER_COMPILER_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../build/bin/Debug/ShaderCompilerTool") set(EXTRA_PLATFORM_ARG "1") endif() @@ -35,7 +35,7 @@ endfunction() # add shaders to target function(add_shaders) - if(NOT ENABLE_IOS) + if(NOT ENABLE_IOS AND NOT ENABLE_TVOS) cmake_parse_arguments(ARGS "" "TARGET" "SHADERS" ${ARGN}) foreach(SHADER_FILENAME ${ARGS_SHADERS}) diff --git a/platforms/ios/CMakeLists.txt b/platforms/ios/CMakeLists.txt index 53e33fd..8cca590 100644 --- a/platforms/ios/CMakeLists.txt +++ b/platforms/ios/CMakeLists.txt @@ -32,13 +32,13 @@ find_library(CORE_GRAPHICS CoreGraphics) add_platform( MAIN_FILE - ViewController.mm.in + ../uikit/ViewController.mm.in SRC MACOSX_BUNDLE ${APP_HEADER_FILES} ${APP_SOURCE_FILES} ${RESOURCES} - ${CMAKE_CURRENT_SOURCE_DIR}/file.mm + ${CMAKE_CURRENT_SOURCE_DIR}/../uikit/file.mm EXECUTABLE_PROPERTIES MACOSX_BUNDLE ON LINK_LIBRARIES diff --git a/platforms/tvos/CMakeLists.txt b/platforms/tvos/CMakeLists.txt index e2cd2de..0f3f972 100644 --- a/platforms/tvos/CMakeLists.txt +++ b/platforms/tvos/CMakeLists.txt @@ -3,24 +3,23 @@ cmake_minimum_required (VERSION 3.7) include(BundleUtilities) set(APP_HEADER_FILES - ${PROJECT_SOURCE_DIR}/platforms/tvos/AppDelegate.h + ${PROJECT_SOURCE_DIR}/platforms/tvos/AppDelegate.h ) set(APP_SOURCE_FILES - ${PROJECT_SOURCE_DIR}/platforms/tvos/AppDelegate.m - ${PROJECT_SOURCE_DIR}/platforms/tvos/main.m + ${PROJECT_SOURCE_DIR}/platforms/tvos/AppDelegate.m + ${PROJECT_SOURCE_DIR}/platforms/tvos/main.m ) set(RESOURCES - ${PROJECT_SOURCE_DIR}/platforms/tvos/Main.storyboard - ${PROJECT_SOURCE_DIR}/platforms/tvos/LaunchScreen.storyboard - ${CMAKE_SOURCE_DIR}/data - ${CMAKE_BINARY_DIR}/shaders + ${PROJECT_SOURCE_DIR}/platforms/tvos/Main.storyboard + ${PROJECT_SOURCE_DIR}/platforms/tvos/LaunchScreen.storyboard + ${CMAKE_SOURCE_DIR}/data + ${CMAKE_BINARY_DIR}/shaders ) include(../../cmake/AddPlatformExecutable.cmake) -# Locate system libraries on iOS find_library(UIKIT UIKit) find_library(FOUNDATION Foundation) find_library(MOBILECORESERVICES MobileCoreServices) @@ -28,88 +27,76 @@ find_library(CFNETWORK CFNetwork) find_library(SYSTEMCONFIGURATION SystemConfiguration) find_library(GAMECONTROLLER GameController) find_library(QUARTZ QuartzCore) - -# link the frameworks located above - +find_library(METAL Metal) add_platform( MAIN_FILE - ViewController.mm.in + ../uikit/ViewController.mm.in SRC MACOSX_BUNDLE ${APP_HEADER_FILES} ${APP_SOURCE_FILES} ${RESOURCES} - ${CMAKE_CURRENT_SOURCE_DIR}/file.mm + ${CMAKE_CURRENT_SOURCE_DIR}/../uikit/file.mm EXECUTABLE_PROPERTIES MACOSX_BUNDLE ON LINK_LIBRARIES Core GFXMetal -${UIKIT} - ${FOUNDATION} - ${MOBILECORESERVICES} -${CFNETWORK} - ${SYSTEMCONFIGURATION} -${GAMECONTROLLER} -${QUARTZ} - GFXMetal + ${UIKIT} + ${FOUNDATION} + ${MOBILECORESERVICES} + ${CFNETWORK} + ${SYSTEMCONFIGURATION} + ${GAMECONTROLLER} + ${QUARTZ} + ${METAL} + GFXMetal COMPILE_OPTIONS ) function(add_platform_commands APP_NAME) -set(APP_BUNDLE_IDENTIFIER "com.test.app.fantasy") # <== Set to your app's bundle identifier + # set in cmake optionss + #set(APP_BUNDLE_IDENTIFIER "com.test.app") + #set(CODE_SIGN_IDENTITY "iPhone Developer") + #set(DEVELOPMENT_TEAM_ID "aaaa") -set(CODE_SIGN_IDENTITY "iPhone Developer") # <== Set to your team ID from Apple -set(DEVELOPMENT_TEAM_ID "JM5LKVKH48") # <== Set to your preferred code sign identity, to see list: - # /usr/bin/env xcrun security # <== Set to "1" to target iPhone, set to "2" to target iPad, set to "1,2" to target both -set(RESOURCES - ${PROJECT_SOURCE_DIR}/engine/platforms/tvos/Main.storyboard - ${PROJECT_SOURCE_DIR}/engine/platforms/tvos/LaunchScreen.storyboard - ${CMAKE_SOURCE_DIR}/data - ${CMAKE_BINARY_DIR}/shaders -) + set(RESOURCES + ${PROJECT_SOURCE_DIR}/platforms/tvos/Main.storyboard + ${PROJECT_SOURCE_DIR}/platforms/tvos/LaunchScreen.storyboard + ${CMAKE_SOURCE_DIR}/data + ${CMAKE_BINARY_DIR}/shaders + ) -set(PRODUCT_NAME ${APP_NAME}) -set(EXECUTABLE_NAME ${APP_NAME}) -set(MACOSX_BUNDLE_EXECUTABLE_NAME ${APP_NAME}) -set(MACOSX_BUNDLE_INFO_STRING ${APP_BUNDLE_IDENTIFIER}) -set(MACOSX_BUNDLE_GUI_IDENTIFIER ${APP_BUNDLE_IDENTIFIER}) -set(MACOSX_BUNDLE_BUNDLE_NAME ${APP_BUNDLE_IDENTIFIER}) -set(MACOSX_BUNDLE_ICON_FILE "") -set(MACOSX_BUNDLE_LONG_VERSION_STRING "1.0") -set(MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0") -set(MACOSX_BUNDLE_BUNDLE_VERSION "1.0") -set(MACOSX_BUNDLE_COPYRIGHT "Copyright YOU") -set(MACOSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}) + set(PRODUCT_NAME ${APP_NAME}) + set(EXECUTABLE_NAME ${APP_NAME}) + set(MACOSX_BUNDLE_EXECUTABLE_NAME ${APP_NAME}) + set(MACOSX_BUNDLE_INFO_STRING ${APP_BUNDLE_IDENTIFIER}) + set(MACOSX_BUNDLE_GUI_IDENTIFIER ${APP_BUNDLE_IDENTIFIER}) + set(MACOSX_BUNDLE_BUNDLE_NAME ${APP_BUNDLE_IDENTIFIER}) + set(MACOSX_BUNDLE_ICON_FILE "") + set(MACOSX_BUNDLE_LONG_VERSION_STRING "1.0") + set(MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0") + set(MACOSX_BUNDLE_BUNDLE_VERSION "1.0") + set(MACOSX_BUNDLE_COPYRIGHT "Copyright YOU") + set(MACOSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc") - -configure_file(${PROJECT_SOURCE_DIR}/engine/platforms/tvos/plist.in ${CMAKE_BINARY_DIR}/${add_platform_executable_TARGET}Info.plist) - -set_target_properties(${APP_NAME} PROPERTIES - XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym" - RESOURCE "${RESOURCES}" - XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES" - XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} - XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENTITY} - XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEVELOPMENT_TEAM_ID} - XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY} - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_INFO_PLIST "${CMAKE_BINARY_DIR}/${APP_NAME}Info.plist" - XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES - XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES NO - XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)" - XCODE_ATTRIBUTE_ENABLE_TESTABILITY YES - XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES -) - -# Set the app's linker search path to the default location on iOS -set_target_properties( - ${APP_NAME} - PROPERTIES - XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS - "@executable_path/Frameworks" -) + configure_file(${PROJECT_SOURCE_DIR}/platforms/tvos/plist.in ${CMAKE_BINARY_DIR}/${add_platform_executable_TARGET}Info.plist) + set_target_properties(${APP_NAME} PROPERTIES + XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym" + RESOURCE "${RESOURCES}" + XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES" + XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENTITY} + XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEVELOPMENT_TEAM_ID} + XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY} + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_BINARY_DIR}/${APP_NAME}Info.plist" + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES + XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES NO + XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)" + XCODE_ATTRIBUTE_ENABLE_TESTABILITY YES + XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES + ) endfunction() diff --git a/platforms/tvos/ViewController.mm.in b/platforms/tvos/ViewController.mm.in deleted file mode 100644 index 89ef7d7..0000000 --- a/platforms/tvos/ViewController.mm.in +++ /dev/null @@ -1,259 +0,0 @@ -#include -#include -#include - -#import - -#include - -#include <@APP_INCLUDE@> - -@APP_CLASS@* app = nullptr; - -int maxFPS = 60; - -std::array inputKeys; - -float rightX = 0.0f, rightY = 0.0f; -float leftX = 0.0f, leftY = 0.0f; - -@interface GameView : UIView -@end - -@implementation GameView - -+ (Class) layerClass { - return [CAMetalLayer class]; -} - -- (void)draw { - engine->update(1.0f / (float)maxFPS); - engine->begin_frame(1.0f / (float)maxFPS); - engine->render(0); -} - -- (void) controllerConnected { - GCController* controller = [GCController controllers][0]; - [[controller extendedGamepad] setValueChangedHandler:^(GCExtendedGamepad * _Nonnull gamepad, GCControllerElement * _Nonnull element) { - const auto& handle_element = [element](int index, GCControllerElement* e) { - if(element == e) - inputKeys[index] = [(GCControllerButtonInput*)e value] == 1.0f; - }; - - handle_element(0, [[controller extendedGamepad] buttonA]); - handle_element(1, [[controller extendedGamepad] buttonB]); - handle_element(2, [[controller extendedGamepad] buttonX]); - handle_element(3, [[controller extendedGamepad] buttonY]); - - if(element == [[controller extendedGamepad] dpad]) { - inputKeys[4] = [[[[controller extendedGamepad] dpad] up] value] == 1.0f; - inputKeys[5] = [[[[controller extendedGamepad] dpad] down] value] == 1.0f; - inputKeys[6] = [[[[controller extendedGamepad] dpad] left] value] == 1.0f; - inputKeys[7] = [[[[controller extendedGamepad] dpad] right] value] == 1.0f; - } - - if(element == [[controller extendedGamepad] leftThumbstick]) { - leftX = [[[[controller extendedGamepad] leftThumbstick] xAxis] value]; - leftY = [[[[controller extendedGamepad] leftThumbstick] yAxis] value]; - } - - if(element == [[controller extendedGamepad] rightThumbstick]) { - rightX = [[[[controller extendedGamepad] rightThumbstick] xAxis] value]; - rightY = [[[[controller extendedGamepad] rightThumbstick] yAxis] value]; - } - }]; -} - -@end - -@interface GameViewController : UIViewController - -@end - -float mouse_x = 0.0f, mouse_y = 0.0f; -bool mouse_down = false; - -@interface GameViewController () -{ - GameView* view; -} -@end - -@implementation GameViewController - -int width, height; -int drawable_width, drawable_height; - -- (void)viewDidLoad { - [super viewDidLoad]; - view = (GameView*)self.view; - view.userInteractionEnabled = true; - - CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:view selector:@selector(draw)]; - [displayLink addToRunLoop:NSRunLoop.mainRunLoop forMode:NSDefaultRunLoopMode]; - - width = [view frame].size.width; - height = [view frame].size.height; - - drawable_width = [view frame].size.width * [view contentScaleFactor]; - drawable_height = [view frame].size.height * [view contentScaleFactor]; - - engine = new prism::Engine(0, nullptr); - - app = new @APP_CLASS@(); - engine->set_app(app); - - GFXCreateInfo createInfo = {}; - createInfo.api_validation_enabled = true; - - GFXMetal* gfx = new GFXMetal(); - gfx->initialize(createInfo); - engine->set_gfx(gfx); - - app_main(engine); - - engine->add_window((void*)CFBridgingRetain([view layer]), 0, {static_cast(width), static_cast(height)}); - - app->initialize_render(); - - NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:view - selector:@selector(controllerConnected) - name:GCControllerDidConnectNotification - object:nil]; -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - --(bool)prefersStatusBarHidden { - return YES; -} - -@end - -void platform::capture_mouse(const bool capture) { - -} - -const char* platform::get_name() { - return "tvOS"; -} - -Offset platform::get_cursor_position() { - return {static_cast(mouse_x), static_cast(mouse_y)}; -} - -std::tuple platform::get_right_stick_position() { - return {rightX, rightY}; -} - -std::tuple platform::get_left_stick_position() { - return {leftX, leftY}; -} - -bool platform::get_key_down(InputButton key) { - if(key == InputButton::ButtonA) - return inputKeys[0]; - - if(key == InputButton::ButtonB) - return inputKeys[1]; - - if(key == InputButton::ButtonX) - return inputKeys[2]; - - if(key == InputButton::ButtonY) - return inputKeys[3]; - - if(key == InputButton::DPadUp) - return inputKeys[4]; - - if(key == InputButton::DPadDown) - return inputKeys[5]; - - if(key == InputButton::DPadLeft) - return inputKeys[6]; - - if(key == InputButton::DPadRight) - return inputKeys[7]; - - return false; -} - -int platform::open_window(const std::string_view title, const Rectangle rect, const WindowFlags flags) { - return 0; -} - -void platform::set_window_title(const int index, const std::string_view title) { - -} - -bool platform::is_window_focused(const int index) { - -} - -void platform::set_window_focused(const int index) { - -} - -Extent platform::get_window_size(const int index) { - return {static_cast(width), static_cast(height)}; -} - -Extent platform::get_window_drawable_size(const int index) { - return {static_cast(drawable_width), static_cast(drawable_height)}; -} - -Offset platform::get_window_position(const int index) { - -} - -void platform::set_window_size(const int index, const Extent extent) { - -} - -void platform::set_window_position(const int index, const Offset offset) { - -} - -void platform::close_window(const int index) { - -} - -char* platform::translate_keycode(const unsigned int keycode) { - return nullptr; -} - -int platform::get_keycode(const InputButton button) { - -} - -Rectangle platform::get_monitor_resolution() { - -} - -Rectangle platform::get_monitor_work_area() { - -} - -Offset platform::get_screen_cursor_position() { - -} - -float platform::get_window_dpi(const int index) { - return 2.0f; -} - -bool platform::get_mouse_button_down(const int index) { - return mouse_down; -} - -float platform::get_monitor_dpi() { - return 2.0f; -} - -std::tuple platform::get_wheel_delta() { - -} diff --git a/platforms/tvos/file.mm b/platforms/tvos/file.mm deleted file mode 100755 index a409b3f..0000000 --- a/platforms/tvos/file.mm +++ /dev/null @@ -1,30 +0,0 @@ -#include "file.hpp" - -#import -#include - -#import - -#include "string_utils.hpp" - -#include "log.hpp" - -void file::initialize_domain(const FileDomain domain, const AccessMode mode, const std::string_view path) { - NSBundle* bundle = [NSBundle mainBundle]; - NSString* resourceFolderPath = [bundle resourcePath]; - - std::string s = std::string(path); - s = replace_substring(s, "{resource_dir}", std::string([resourceFolderPath cStringUsingEncoding:NSUTF8StringEncoding])); - - domain_data[(int)domain] = s; -} - -std::string file::get_writeable_path(const std::string_view path) { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - - NSString* resourceFolderPath = paths[0]; - - std::string s = std::string([resourceFolderPath cStringUsingEncoding:NSUTF8StringEncoding]) + "/" + std::string(path); - - return s; -} diff --git a/platforms/ios/ViewController.mm.in b/platforms/uikit/ViewController.mm.in similarity index 100% rename from platforms/ios/ViewController.mm.in rename to platforms/uikit/ViewController.mm.in diff --git a/platforms/ios/file.mm b/platforms/uikit/file.mm similarity index 100% rename from platforms/ios/file.mm rename to platforms/uikit/file.mm