Skip to content

Commit 8366c23

Browse files
committed
- fix conflicts
2 parents f52cf61 + 8448d50 commit 8366c23

10 files changed

Lines changed: 401 additions & 45 deletions

File tree

core/pen/include/os.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace pen
4747
bool os_delete_directory(const Str& filename);
4848
void os_open_url(const Str& url);
4949
void os_ignore_slient();
50-
void os_enable_background_audio();
50+
void os_enable_background_audio(bool enabled);
5151
f32 os_get_status_bar_portrait_height();
5252
void os_haptic_selection_feedback();
5353
void os_init_on_screen_keyboard();
@@ -56,6 +56,7 @@ namespace pen
5656
Str os_get_keychain_item(const Str& identifier, const Str& key);
5757
bool os_is_backgrounded();
5858
void os_register_background_callback(void (*callback)(bool));
59+
bool os_require_audio_reinit(bool reset);
5960

6061
// music
6162
struct music_item

core/pen/source/android/os.cpp

Lines changed: 217 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717
#include <EGL/egl.h>
1818
#include <EGL/eglext.h>
1919

20-
// setup diig android build
20+
#undef stdin
21+
#undef stdout
22+
#undef stderr
23+
24+
FILE* stdin = NULL;
25+
FILE* stdout = NULL;
26+
FILE* stderr = NULL;
27+
28+
// generate or create a wrapper for pen_activity + new manifest
2129
// filesystem functions
2230
// openURL etc
31+
// OSK
2332

2433
// BLOG NOTES:
2534
// - gradle version, always changing, sdk etc bs bs bs
@@ -34,6 +43,7 @@
3443
// Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
3544
// DEBUGGER INTERMITTENT HANG AND FAIL
3645
// DEBUG INFO works better with device
46+
// horrors of getting jvm methods, name mangling etc
3747

3848
// DONE:
3949
// call c++ from java
@@ -49,26 +59,16 @@
4959
// orientation changes
5060
// debug info? on device
5161
// sort out fmod version
62+
// setup diig android build
5263

5364
#define PEN_JNIFUNC(ret, actname, funcname) extern "C" JNIEXPORT ret JNICALL Java_cc_pmtech_##actname##_##funcname
5465

5566
// global externs
5667
pen::user_info pen_user_info;
5768
pen::window_creation_params pen_window;
5869

59-
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
60-
{
61-
return JNI_VERSION_1_6;
62-
}
63-
6470
extern void audio_init_fmod_android(JNIEnv* env, jobject thiz, jobject activity);
6571

66-
extern "C" JNIEXPORT void JNICALL
67-
Java_cc_pmtech_pen_1activity_initFMOD(JNIEnv* env, jobject thiz, jobject activity)
68-
{
69-
audio_init_fmod_android(env, thiz, activity);
70-
}
71-
7272
namespace
7373
{
7474
struct egl_context
@@ -86,6 +86,8 @@ namespace
8686
ANativeWindow* m_window = nullptr;
8787
jclass m_surface_wrapper_class;
8888
jobject m_surface_wrapper_object;
89+
jobject m_activity_object;
90+
jclass m_activity_class;
8991
};
9092
android_context s_android_context;
9193

@@ -94,10 +96,41 @@ namespace
9496
pen::window_frame window;
9597
pen::pen_creation_params params;
9698
Str user_dir;
99+
bool keyboard_visible = false;
97100
};
98101
pmtech_context s_pmtech_context;
99102
}
100103

104+
extern "C" JNIEXPORT void JNICALL
105+
Java_cc_pmtech_pen_1activity_init(JNIEnv* env, jobject thiz, jobject activity)
106+
{
107+
s_android_context.m_activity_object = env->NewGlobalRef((jobject)activity);
108+
s_android_context.m_activity_class = (jclass)env->NewGlobalRef(env->GetObjectClass(s_android_context.m_activity_object));
109+
110+
audio_init_fmod_android(env, thiz, activity);
111+
}
112+
113+
PEN_JNIFUNC(void, pen_1activity, native_1on_1key_1down)(JNIEnv* env, jclass thiz,int key_code, int unicode_char)
114+
{
115+
int a = 0;
116+
}
117+
118+
PEN_JNIFUNC(void, pen_1activity, native_1on_1key_1up)(JNIEnv* env, jclass thiz, int key_code)
119+
{
120+
int a = 0;
121+
}
122+
123+
PEN_JNIFUNC(void, pen_1activity, native_1back_1button_1pressed)(JNIEnv* env, jclass thiz)
124+
{
125+
int a = 0;
126+
}
127+
128+
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
129+
{
130+
s_android_context.m_java_vm = vm;
131+
return JNI_VERSION_1_6;
132+
}
133+
101134
void pen_make_gl_context_current()
102135
{
103136

@@ -227,6 +260,39 @@ PEN_JNIFUNC(void, SurfaceWrapper, on_1touch_1cancelled)(JNIEnv* env, jclass thiz
227260

228261
namespace pen
229262
{
263+
JNIEnv* get_jni_env()
264+
{
265+
if (!s_android_context.m_java_vm)
266+
return nullptr;
267+
268+
JNIEnv* env;
269+
int status = s_android_context.m_java_vm->GetEnv((void**)&env, JNI_VERSION_1_4);
270+
if (status == JNI_EDETACHED)
271+
{
272+
if (s_android_context.m_java_vm->AttachCurrentThread(&env, nullptr) != 0)
273+
return nullptr;
274+
}
275+
else if (status != JNI_OK)
276+
{
277+
return nullptr;
278+
}
279+
return env;
280+
}
281+
282+
void get_jni_data(void*& vm, void*& env, void*& instance)
283+
{
284+
/*
285+
JNIEnv* env = get_jni_env();
286+
if(env)
287+
{
288+
jmethodID idGetInstance = env->GetStaticMethodID(s_context.m_device.m_activityClass, "getInstance", "()Landroid/app/Activity;");
289+
instance = env->CallStaticObjectMethod(s_context.m_device.m_activityClass, idGetInstance);
290+
vm = getJavaVM();
291+
env = (void*)env;
292+
}
293+
*/
294+
}
295+
230296
u32 window_init(void* params)
231297
{
232298
return 0;
@@ -294,7 +360,7 @@ namespace pen
294360

295361
void os_set_cursor_pos(u32 client_x, u32 client_y)
296362
{
297-
363+
298364
}
299365

300366
const user_info& os_get_user_info()
@@ -312,6 +378,144 @@ namespace pen
312378
return false;
313379
}
314380

381+
Str os_get_persistent_data_directory()
382+
{
383+
return "";
384+
}
385+
386+
Str os_get_cache_data_directory()
387+
{
388+
return "";
389+
}
390+
391+
void os_create_directory(const Str& dir)
392+
{
393+
394+
}
395+
396+
bool os_delete_directory(const Str& filename)
397+
{
398+
399+
}
400+
401+
void os_open_url(const Str& url)
402+
{
403+
404+
}
405+
406+
void os_ignore_slient()
407+
{
408+
409+
}
410+
411+
void os_enable_background_audio(bool enabled)
412+
{
413+
414+
}
415+
416+
f32 os_get_status_bar_portrait_height()
417+
{
418+
auto env= get_jni_env();
419+
420+
if(env)
421+
{
422+
jmethodID method = env->GetMethodID(s_android_context.m_activity_class, "getStatusBarHeight", "()I");
423+
int res = env->CallIntMethod(s_android_context.m_activity_object, method);
424+
return (f32)res;
425+
}
426+
427+
return 0.0f;
428+
}
429+
430+
void os_haptic_selection_feedback()
431+
{
432+
433+
}
434+
435+
void os_init_on_screen_keyboard()
436+
{
437+
// ??
438+
}
439+
440+
void os_show_on_screen_keyboard(bool show)
441+
{
442+
if(s_pmtech_context.keyboard_visible == show)
443+
return;
444+
445+
auto env = get_jni_env();
446+
if(env)
447+
{
448+
jmethodID method = env->GetStaticMethodID(s_android_context.m_activity_class, "showKeyboard", "(Z)V");
449+
env->CallStaticVoidMethod(s_android_context.m_activity_class, method, show);
450+
451+
s_pmtech_context.keyboard_visible = show;
452+
}
453+
}
454+
455+
bool os_set_keychain_item(const Str& identifier, const Str& key, const Str& value)
456+
{
457+
return false;
458+
}
459+
460+
Str os_get_keychain_item(const Str& identifier, const Str& key)
461+
{
462+
return "";
463+
}
464+
465+
bool os_is_backgrounded()
466+
{
467+
return false;
468+
}
469+
470+
void os_register_background_callback(void (*callback)(bool))
471+
{
472+
473+
}
474+
475+
bool os_require_audio_reinit(bool reset)
476+
{
477+
return false;
478+
}
479+
480+
// music
481+
482+
const music_item* music_get_items()
483+
{
484+
return nullptr;
485+
}
486+
487+
music_file music_open_file(const music_item& item)
488+
{
489+
return {};
490+
}
491+
492+
void music_close_file(const music_file& file)
493+
{
494+
495+
}
496+
497+
void music_enable_remote_control(const music_player_remote& fns)
498+
{
499+
500+
}
501+
502+
void music_set_now_playing(const Str& artist, const Str& album, const Str& track)
503+
{
504+
505+
}
506+
507+
void music_set_now_playing_artwork(void* data, u32 w, u32 h, u32 bpp, u32 row_pitch)
508+
{
509+
510+
}
511+
512+
void music_set_now_playing_time_info(u32 position_ms, u32 duration_ms)
513+
{
514+
515+
}
516+
517+
// filesystem
518+
315519
const c8* filesystem_get_user_directory()
316520
{
317521
return s_pmtech_context.user_dir.c_str();

core/pen/source/ios/os.mm

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ -(MPRemoteCommandHandlerStatus)like;
8484
bool show_on_screen_keyboard = false;
8585
pen::music_player_remote music_remote;
8686
void (*background_callback)(bool) = nullptr;
87+
bool background_audio = true;
88+
bool require_audio_reinit = false;
8789
};
8890
os_context s_context;
8991

@@ -178,16 +180,32 @@ - (void)applicationWillResignActive:(UIApplication *)app
178180
// pairs with applicationDidBecomeActive
179181
if(s_context.background_callback)
180182
{
183+
if(!s_context.background_audio)
184+
{
185+
AVAudioSession *session = [AVAudioSession sharedInstance];
186+
[session setActive:NO error:nil];
187+
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
188+
}
189+
181190
s_context.background_callback(true);
182191
}
183192
}
184193

185194
- (void)applicationDidBecomeActive:(UIApplication *)app
186195
{
196+
if([[AVAudioSession sharedInstance] isOtherAudioPlaying] == 1)
197+
{
198+
s_context.require_audio_reinit = true;
199+
}
200+
201+
AVAudioSession *session = [AVAudioSession sharedInstance];
202+
[session setActive:YES error:nil];
203+
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
204+
187205
// pairs with applicationWillResignActive
188206
if(s_context.background_callback)
189207
{
190-
s_context.background_callback(true);
208+
s_context.background_callback(false);
191209
}
192210
}
193211

@@ -611,8 +629,10 @@ void os_ignore_slient()
611629
}
612630
}
613631

614-
void os_enable_background_audio()
632+
void os_enable_background_audio(bool enable)
615633
{
634+
s_context.background_audio = enable;
635+
616636
AVAudioSession *session = [AVAudioSession sharedInstance];
617637
double rate = 24000.0; // This should match System::setSoftwareFormat 'samplerate' which defaults to 24000
618638
s32 blockSize = 512; // This should match System::setDSPBufferSize 'bufferlength' which defaults to 512
@@ -827,4 +847,16 @@ void os_register_background_callback(void (*callback)(bool))
827847
{
828848
s_context.background_callback = callback;
829849
}
850+
851+
bool os_require_audio_reinit(bool reset)
852+
{
853+
bool res = s_context.require_audio_reinit;
854+
855+
if(reset)
856+
{
857+
s_context.require_audio_reinit = false;
858+
}
859+
860+
return res;
861+
}
830862
}

0 commit comments

Comments
 (0)