Skip to content

Commit

Permalink
- os api additions for macos and ios, fixed an issue with audio threa…
Browse files Browse the repository at this point in the history
…d locking causing main thread stall (remove 2 way semaphore) added option to supply cistom plist from premake
  • Loading branch information
polymonster committed Dec 2, 2023
1 parent c201896 commit b4949f6
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 93 deletions.
5 changes: 5 additions & 0 deletions core/pen/include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions core/pen/source/ios/os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
31 changes: 31 additions & 0 deletions core/pen/source/osx/os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

//
Expand Down
1 change: 0 additions & 1 deletion core/put/source/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
9 changes: 8 additions & 1 deletion core/put/source/audio/audio_fmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "memory.h"
#include "os.h"
#include "slot_resource.h"
#include "timer.h"

#include "fmod.hpp"

Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit b4949f6

Please sign in to comment.