diff --git a/core/pen/include/os.h b/core/pen/include/os.h index b17b8f4e..42cc15c9 100644 --- a/core/pen/include/os.h +++ b/core/pen/include/os.h @@ -41,6 +41,11 @@ namespace pen void os_show_cursor(bool show); const Str os_path_for_resource(const c8* filename); const user_info& os_get_user_info(); + Str os_get_persistent_data_directory(); + void os_create_directory(const Str& dir); + void os_open_url(const Str& url); + void os_ignore_slient(); + f32 os_get_status_bar_portrait_height(); // music struct music_item diff --git a/core/pen/source/ios/os.mm b/core/pen/source/ios/os.mm index 6860d819..e6afa246 100644 --- a/core/pen/source/ios/os.mm +++ b/core/pen/source/ios/os.mm @@ -384,4 +384,45 @@ void music_close_file(const music_file& item) { pen::memory_free(item.pcm_data); } + + Str os_get_persistent_data_directory() + { + @autoreleasepool { + NSString* dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + return dir.UTF8String; + } + } + + void os_create_directory(const Str& dir) + { + @autoreleasepool { + NSFileManager* manager = [NSFileManager defaultManager]; + NSString* path = [NSString stringWithUTF8String:dir.c_str()]; + NSError* err = nil; + [manager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&err]; + } + } + + void os_open_url(const Str& url) + { + @autoreleasepool { + NSString* path = [NSString stringWithUTF8String:url.c_str()]; + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:path]]; + } + } + + void os_ignore_slient() + { + @autoreleasepool { + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; + [[AVAudioSession sharedInstance] setActive:YES error:nil]; + } + } + + f32 os_get_status_bar_portrait_height() + { + CGFloat h = [[[UIApplication sharedApplication] windows].firstObject windowScene].statusBarManager.statusBarFrame.size.height; + CGFloat s = [[UIScreen mainScreen] scale]; + return (f32)h*s; + } } diff --git a/core/pen/source/osx/os.mm b/core/pen/source/osx/os.mm index a6875f66..5150ae56 100644 --- a/core/pen/source/osx/os.mm +++ b/core/pen/source/osx/os.mm @@ -822,6 +822,37 @@ void window_set_frame(const window_frame& f) { return s_ctx.pen_user_info; } + + Str os_get_persistent_data_directory() + { + @autoreleasepool { + NSString* dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + return dir.UTF8String; + } + } + + void os_create_directory(const Str& dir) + { + @autoreleasepool { + NSFileManager* manager = [NSFileManager defaultManager]; + NSString* path = [NSString stringWithUTF8String:dir.c_str()]; + NSError* err = nil; + [manager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&err]; + } + } + + void os_open_url(const Str& url) + { + @autoreleasepool { + NSString* path = [NSString stringWithUTF8String:url.c_str()]; + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:path]]; + } + } + + void os_ignore_slient() + { + // stub + } } // diff --git a/core/put/source/audio/audio.cpp b/core/put/source/audio/audio.cpp index 70700cc6..0b1f8db0 100644 --- a/core/put/source/audio/audio.cpp +++ b/core/put/source/audio/audio.cpp @@ -151,7 +151,6 @@ namespace put if (!_shutdown.load()) { pen::semaphore_post(_audio_job_thread_info->p_sem_consume, 1); - pen::semaphore_wait(_audio_job_thread_info->p_sem_continue); } } diff --git a/core/put/source/audio/audio_fmod.cpp b/core/put/source/audio/audio_fmod.cpp index 62590856..6d30c2ed 100644 --- a/core/put/source/audio/audio_fmod.cpp +++ b/core/put/source/audio/audio_fmod.cpp @@ -9,6 +9,7 @@ #include "memory.h" #include "os.h" #include "slot_resource.h" +#include "timer.h" #include "fmod.hpp" @@ -259,8 +260,14 @@ namespace put _audio_resources[resource_slot].assigned_flag |= 0xff; _audio_resources[resource_slot].type = AUDIO_RESOURCE_SOUND; + + Str resovled_name = filename; + if(filename[0] != '/') + { + resovled_name = pen::os_path_for_resource(filename); + } - FMOD_RESULT result = _sound_system->createSound(pen::os_path_for_resource(filename).c_str(), FMOD_DEFAULT, NULL, + FMOD_RESULT result = _sound_system->createSound(resovled_name.c_str(), FMOD_DEFAULT, NULL, (FMOD::Sound**)&_audio_resources[resource_slot].resource); PEN_ASSERT(result == FMOD_OK); diff --git a/tools/premake/app_template.lua b/tools/premake/app_template.lua index e2b2c4a4..12826c1a 100644 --- a/tools/premake/app_template.lua +++ b/tools/premake/app_template.lua @@ -6,13 +6,13 @@ local function add_pmtech_links() filter "configurations:Release" links { "put", "pen" } - + filter {} end local function setup_osx() - links - { + links + { "Cocoa.framework", "GameController.framework", "iconv", @@ -23,12 +23,19 @@ local function setup_osx() "OpenGL.framework" } add_pmtech_links() - - files - { - (pmtech_dir .. "core/template/osx/Info.plist") - } - + + if _OPTIONS["plist"] then + files + { + _OPTIONS["plist"] + } + else + files + { + (pmtech_dir .. "core/template/osx/Info.plist") + } + end + if _ACTION == "xcode4" then install_name_tool = "cd ../../bin/osx && install_name_tool -add_rpath @executable_path/../../.. " filter "configurations:Debug" @@ -46,8 +53,8 @@ end local function setup_linux() --linux must be linked in order add_pmtech_links() - links - { + links + { "pthread", "GLEW", "GLU", @@ -86,35 +93,35 @@ local function setup_win32() { pmtech_dir .. "/third_party/glew/lib/win64" } - links - { + links + { "OpenGL32.lib" } else - links - { + links + { "d3d11.lib" } end - + links { "dxguid.lib", - "winmm.lib", - "comctl32.lib", + "winmm.lib", + "comctl32.lib", "fmod64_vc.lib", - "Shlwapi.lib" + "Shlwapi.lib" } add_pmtech_links() - + systemversion(windows_sdk_version()) disablewarnings { "4800", "4305", "4018", "4244", "4267", "4996" } end local function setup_ios() - links - { + links + { "Foundation.framework", "UIKit.framework", "QuartzCore.framework", @@ -125,15 +132,26 @@ local function setup_ios() "MediaPlayer.framework", "fmod_iphoneos" } - - files - { - (pmtech_dir .. "/core/template/ios/**.*"), + + files + { "bin/ios/data" } - excludes - { + if _OPTIONS["plist"] then + files + { + _OPTIONS["plist"] + } + else + files + { + (pmtech_dir .. "/core/template/ios/**.*"), + } + end + + excludes + { ("**.DS_Store") } @@ -141,7 +159,7 @@ local function setup_ios() { "bin/ios/data" } - + xcodebuildsettings { ["IPHONEOS_DEPLOYMENT_TARGET"] = "14.0" @@ -154,7 +172,7 @@ local function setup_android() pmtech_dir .. "/core/template/android/manifest/**.*", pmtech_dir .. "/core/template/android/activity/**.*" } - + androidabis { "armeabi-v7a", "x86" @@ -169,22 +187,22 @@ local function setup_web() linkoptions { file_list } io.close(file) end - + filter "configurations:Debug" - buildoptions { - "-g4", - "-s STACK_OVERFLOW_CHECK=1", - "-s SAFE_HEAP=1", - "-s DETERMINISTIC=1" + buildoptions { + "-g4", + "-s STACK_OVERFLOW_CHECK=1", + "-s SAFE_HEAP=1", + "-s DETERMINISTIC=1" } - linkoptions { - "-g4", + linkoptions { + "-g4", "--source-map-base http://localhost:8000/web/", - "-s STACK_OVERFLOW_CHECK=1", - "-s SAFE_HEAP=1", - "-s DETERMINISTIC=1" + "-s STACK_OVERFLOW_CHECK=1", + "-s SAFE_HEAP=1", + "-s DETERMINISTIC=1" } - + filter {} targetextension (".html") links { "pen", "put" } @@ -197,9 +215,9 @@ local function setup_platform() setup_osx() elseif platform_dir == "ios" then setup_ios() - elseif platform_dir == "linux" then + elseif platform_dir == "linux" then setup_linux() - elseif platform_dir == "android" then + elseif platform_dir == "android" then setup_android() elseif platform_dir == "web" then setup_web() @@ -211,13 +229,13 @@ local function setup_bullet() { (pmtech_dir .. "third_party/bullet/lib/" .. platform_dir) } - + filter "configurations:Debug" links { "bullet_monolithic_d" } - + filter "configurations:Release" links { "bullet_monolithic" } - + filter {} end @@ -243,45 +261,45 @@ function create_dll(project_name, source_directory, root_directory) setup_product( project_name ) kind ( binary_type ) language "C++" - + print(pmtech_dir) includedirs { -- platform pmtech_dir .. "core/pen/include", - pmtech_dir .. "core/pen/include/common", + pmtech_dir .. "core/pen/include/common", pmtech_dir .. "core/pen/include/" .. platform_dir, - - --utility + + --utility pmtech_dir .. "core/put/source/", - - -- third party + + -- third party pmtech_dir .. "third_party/", - + -- local "include/", } - - files - { + + files + { (root_directory .. "code/" .. source_directory .. "/**.cpp"), (root_directory .. "code/" .. source_directory .. "/**.c"), (root_directory .. "code/" .. source_directory .. "/**.h"), (root_directory .. "code/" .. source_directory .. "/**.m"), (root_directory .. "code/" .. source_directory .. "/**.mm") } - + setup_env() location (root_directory .. "/build/" .. platform_dir) targetdir (root_directory .. "/bin/" .. platform_dir) debugdir (root_directory .. "/bin/" .. platform_dir) - + filter "configurations:Release" defines { "NDEBUG" } optimize "Speed" targetname (project_name) - + filter "configurations:Debug" defines { "DEBUG" } symbols "On" @@ -294,37 +312,37 @@ function create_binary(project_name, source_directory, root_directory, binary_ty setup_product( project_name ) kind ( binary_type ) language "C++" - + if binary_type ~= "SharedLib" then dependson { "pen", "put" } end - + includedirs { -- platform pmtech_dir .. "core/pen/include", - pmtech_dir .. "core/pen/include/common", + pmtech_dir .. "core/pen/include/common", pmtech_dir .. "core/pen/include/" .. platform_dir, - - --utility + + --utility pmtech_dir .. "core/put/source/", - - -- third party + + -- third party pmtech_dir .. "third_party/", - + -- local "include/", } - - files - { + + files + { (root_directory .. "code/" .. source_directory .. "/**.cpp"), (root_directory .. "code/" .. source_directory .. "/**.c"), (root_directory .. "code/" .. source_directory .. "/**.h"), (root_directory .. "code/" .. source_directory .. "/**.m"), (root_directory .. "code/" .. source_directory .. "/**.mm") } - + setup_env() setup_platform() setup_platform_defines() @@ -333,26 +351,26 @@ function create_binary(project_name, source_directory, root_directory, binary_ty location (root_directory .. "/build/" .. platform_dir) targetdir (root_directory .. "/bin/" .. platform_dir) debugdir (root_directory .. "/bin/" .. platform_dir) - + filter "configurations:Release" defines { "NDEBUG" } entrypoint "WinMainCRTStartup" optimize "Speed" targetname (project_name) libdirs - { - pmtech_dir .. "core/pen/lib/" .. platform_dir .. "/release", + { + pmtech_dir .. "core/pen/lib/" .. platform_dir .. "/release", pmtech_dir .. "core/put/lib/" .. platform_dir .. "/release", } - + filter "configurations:Debug" defines { "DEBUG" } entrypoint "WinMainCRTStartup" symbols "On" targetname (project_name .. "_d") libdirs - { - pmtech_dir .. "core/pen/lib/" .. platform_dir .. "/debug", + { + pmtech_dir .. "core/pen/lib/" .. platform_dir .. "/debug", pmtech_dir .. "core/put/lib/" .. platform_dir .. "/debug", } end @@ -365,7 +383,7 @@ function create_app_example( project_name, root_directory ) create_app( project_name, project_name, root_directory ) end -function setup_live_lib( project_name ) +function setup_live_lib( project_name ) if platform == "win32" then filter {} libdirs { @@ -396,7 +414,7 @@ function setup_live_lib( project_name ) "-export-dynamic" } end - + project "pmtech_editor" filter "configurations:Debug" if platform == "osx" then @@ -410,7 +428,7 @@ function setup_live_lib( project_name ) elseif platform == "linux" then defines { ('LIVE_LIB="\\\"lib' .. project_name .. '_d.so\\\""') - } + } end filter "configurations:Release" if platform == "osx" then @@ -424,7 +442,7 @@ function setup_live_lib( project_name ) elseif platform == "linux" then defines { ('LIVE_LIB="\\\"lib' .. project_name .. '.so\\\""') - } + } end project ( project_name ) diff --git a/tools/premake/options.lua b/tools/premake/options.lua index 8aa519f6..acf1bc3f 100644 --- a/tools/premake/options.lua +++ b/tools/premake/options.lua @@ -1,10 +1,10 @@ --add extension options -newoption +newoption { trigger = "renderer", value = "API", description = "Choose a renderer", - allowed = + allowed = { { "opengl", "OpenGL (macOS, linux, Android)" }, { "dx11", "DirectX 11 (Windows only)" }, @@ -13,33 +13,33 @@ newoption } } -newoption +newoption { trigger = "sdk_version", value = "version", description = "Specify operating system SDK", } -newoption +newoption { trigger = "platform_dir", value = "dir", description = "specify platform specifc src folder", } -newoption +newoption { trigger = "toolset", value = "value", description = "specify toolset (clang, gcc)", } -newoption +newoption { trigger = "xcode_target", value = "TARGET", description = "Choose an xcode build target", - allowed = + allowed = { { "osx", "OSX" }, { "ios", "iOS" }, @@ -49,13 +49,20 @@ newoption newoption { trigger = "teamid", - value = "id", + value = "id", description = "development team id for apple developers" } -newoption +newoption { trigger = "pmtech_dir", value = "dir", description = "specify location of pmtech in relation to project" } + +newoption +{ + trigger = "plist", + value = "filepath", + description = "specify filepath to plist" +}