oops android

This commit is contained in:
zeppi 2022-12-09 15:02:36 -05:00
parent fc445de715
commit f7af92712b
3 changed files with 0 additions and 553 deletions

View file

@ -1,120 +0,0 @@
#include <jni.h>
#include <stdio.h>
#include <android/log.h>
#include <string.h>
#include <stdlib.h>
#include "config.h"
#define aassert(x) { if (!x) { __android_log_print(ANDROID_LOG_ERROR, "android_jni", "Assertion failed. %s:%d", __FILE__, __LINE__); abort(); }}
#define PUSH_FRAME { (*env)->PushLocalFrame(env, 16); }
#define POP_FRAME { (*env)->PopLocalFrame(env, NULL); }
void android_billing_service_start() {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, JNI_NAMESPACE "/PythonActivity");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "billingServiceStart", "()V");
aassert(mid);
}
PUSH_FRAME;
(*env)->CallStaticVoidMethod(env, cls, mid);
POP_FRAME;
}
void android_billing_service_stop() {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, JNI_NAMESPACE "/PythonActivity");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "billingServiceStop", "()V");
aassert(mid);
}
PUSH_FRAME;
(*env)->CallStaticVoidMethod(env, cls, mid);
POP_FRAME;
}
void android_billing_buy(char *sku) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, JNI_NAMESPACE "/PythonActivity");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "billingBuy", "(Ljava/lang/String;)V");
aassert(mid);
}
PUSH_FRAME;
(*env)->CallStaticVoidMethod(
env, cls, mid,
(*env)->NewStringUTF(env, sku)
);
POP_FRAME;
}
char *android_billing_get_purchased_items() {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
jobject jreading;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, JNI_NAMESPACE "/PythonActivity");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "billingGetPurchasedItems", "()Ljava/lang/String;");
aassert(mid);
}
PUSH_FRAME;
jreading = (*env)->CallStaticObjectMethod(env, cls, mid);
const char * reading = (*env)->GetStringUTFChars(env, jreading, 0);
POP_FRAME;
return reading;
}
char *android_billing_get_pending_message() {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
jobject jreading;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, JNI_NAMESPACE "/PythonActivity");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "billingGetPendingMessage", "()Ljava/lang/String;");
aassert(mid);
}
PUSH_FRAME;
jreading = (*env)->CallStaticObjectMethod(env, cls, mid);
const char * reading = (*env)->GetStringUTFChars(env, jreading, 0);
POP_FRAME;
return reading;
}

View file

@ -1,125 +0,0 @@
cdef extern void android_sound_queue(int, char *, char *, long long, long long)
cdef extern void android_sound_play(int, char *, char *, long long, long long)
cdef extern void android_sound_stop(int)
cdef extern void android_sound_seek(int, float)
cdef extern void android_sound_dequeue(int)
cdef extern void android_sound_playing_name(int, char *, int)
cdef extern void android_sound_pause(int)
cdef extern void android_sound_unpause(int)
cdef extern void android_sound_set_volume(int, float)
cdef extern void android_sound_set_secondary_volume(int, float)
cdef extern void android_sound_set_pan(int, float)
cdef extern int android_sound_queue_depth(int)
cdef extern int android_sound_get_pos(int)
cdef extern int android_sound_get_length(int)
channels = set()
volumes = { }
def queue(channel, file, name, fadein=0, tight=False):
channels.add(channel)
real_fn = file.name
base = getattr(file, "base", -1)
length = getattr(file, "length", -1)
android_sound_queue(channel, name, real_fn, base, length)
def play(channel, file, name, paused=False, fadein=0, tight=False):
channels.add(channel)
real_fn = file.name
base = getattr(file, "base", -1)
length = getattr(file, "length", -1)
android_sound_play(channel, name, real_fn, base, length)
def seek(channel, position):
android_sound_seek(channel, position)
def stop(channel):
android_sound_stop(channel)
def dequeue(channel, even_tight=False):
android_sound_dequeue(channel)
def queue_depth(channel):
return android_sound_queue_depth(channel)
def playing_name(channel):
cdef char buf[1024]
android_sound_playing_name(channel, buf, 1024)
rv = buf
if not len(rv):
return None
return rv
def pause(channel):
android_sound_pause(channel)
return
def unpause(channel):
android_sound_unpause(channel)
return
def unpause_all():
for i in channels:
unpause(i)
def pause_all():
for i in channels:
pause(i)
def fadeout(channel, ms):
stop(channel)
def busy(channel):
return playing_name(channel) != None
def get_pos(channel):
return android_sound_get_pos(channel)
def get_length(channel):
return android_sound_get_length(channel)
def set_volume(channel, volume):
android_sound_set_volume(channel, volume)
volumes[channel] = volume
def set_secondary_volume(channel, volume):
android_sound_set_secondary_volume(channel, volume)
def set_pan(channel, pan):
android_sound_set_pan(channel, pan)
def set_end_event(channel, event):
return
def get_volume(channel):
return volumes.get(channel, 1.0)
def init(freq, stereo, samples, status=False):
return
def quit():
for i in channels:
stop(i)
def periodic():
return
def alloc_event(surf):
return
def refresh_event():
return
def check_version(version):
return

View file

@ -1,308 +0,0 @@
#include <jni.h>
#include <stdio.h>
#include <android/log.h>
#include <string.h>
JNIEnv *SDL_ANDROID_GetJNIEnv();
#define aassert(x) { if (!x) { __android_log_print(ANDROID_LOG_ERROR, "android_sound_jni", "Assertion failed. %s:%d", __FILE__, __LINE__); abort(); }}
#define PUSH_FRAME { (*env)->PushLocalFrame(env, 16); }
#define POP_FRAME { (*env)->PopLocalFrame(env, NULL); }
void android_sound_queue(int channel, char *filename, char *real_fn, long long base, long long length) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "queue", "(ILjava/lang/String;Ljava/lang/String;JJ)V");
aassert(mid);
}
PUSH_FRAME;
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(*env)->NewStringUTF(env, filename),
(*env)->NewStringUTF(env, real_fn),
(jlong) base,
(jlong) length);
POP_FRAME;
}
void android_sound_play(int channel, char *filename, char *real_fn, long long base, long long length) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "play", "(ILjava/lang/String;Ljava/lang/String;JJ)V");
aassert(mid);
}
PUSH_FRAME;
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(*env)->NewStringUTF(env, filename),
(*env)->NewStringUTF(env, real_fn),
(jlong) base,
(jlong) length);
POP_FRAME;
}
void android_sound_seek(int channel, float position){
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "seek", "(IF)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(jfloat) position);
}
void android_sound_stop(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "stop", "(I)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel);
}
void android_sound_dequeue(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "dequeue", "(I)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel);
}
int android_sound_queue_depth(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "queue_depth", "(I)I");
aassert(mid);
}
(*env)->CallStaticIntMethod(
env, cls, mid,
channel);
}
void android_sound_playing_name(int channel, char *buf, int buflen) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
jobject s = NULL;
char *jbuf;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "playing_name", "(I)Ljava/lang/String;");
aassert(mid);
}
PUSH_FRAME;
s = (*env)->CallStaticObjectMethod(
env, cls, mid,
channel);
jbuf = (*env)->GetStringUTFChars(env, s, NULL);
strncpy(buf, jbuf, buflen);
(*env)->ReleaseStringUTFChars(env, s, jbuf);
POP_FRAME;
}
void android_sound_set_volume(int channel, float value) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "set_volume", "(IF)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(jfloat) value);
}
void android_sound_set_secondary_volume(int channel, float value) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "set_secondary_volume", "(IF)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(jfloat) value);
}
void android_sound_set_pan(int channel, float value) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "set_pan", "(IF)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel,
(jfloat) value);
}
void android_sound_pause(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "pause", "(I)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel);
}
void android_sound_unpause(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "unpause", "(I)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
channel);
}
int android_sound_get_pos(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "get_pos", "(I)I");
aassert(mid);
}
return (*env)->CallStaticIntMethod(
env, cls, mid,
channel);
}
int android_sound_get_length(int channel) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/RenPySound");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "get_length", "(I)I");
aassert(mid);
}
return (*env)->CallStaticIntMethod(
env, cls, mid,
channel);
}