mirror of https://github.com/bjornbytes/lovr.git
Custom os implementation for pico;
This commit is contained in:
parent
b0b9e38da6
commit
58ab637465
|
@ -629,7 +629,6 @@ elseif(EMSCRIPTEN)
|
|||
target_sources(lovr PRIVATE src/core/os_web.c)
|
||||
target_compile_definitions(lovr PRIVATE -DLOVR_WEBGL)
|
||||
elseif(ANDROID)
|
||||
target_sources(lovr PRIVATE src/core/os_android.c)
|
||||
target_link_libraries(lovr log EGL GLESv3 android)
|
||||
target_compile_definitions(lovr PRIVATE -DLOVR_GLES)
|
||||
target_include_directories(lovr PRIVATE "${ANDROID_NDK}/sources/android/native_app_glue")
|
||||
|
@ -658,6 +657,7 @@ elseif(ANDROID)
|
|||
# TODO error (probably way earlier) if both USE_VRAPI and USE_PICO aren't defined
|
||||
if(LOVR_USE_VRAPI)
|
||||
set(ANDROID_FLAVOR "vrapi")
|
||||
target_sources(lovr PRIVATE src/core/os_android.c)
|
||||
get_target_property(VRAPI_LIB ${LOVR_VRAPI} IMPORTED_LOCATION)
|
||||
file(COPY ${VRAPI_LIB} DESTINATION lib/${ANDROID_ABI})
|
||||
set(ANDROID_CLASSPATH "${ANDROID_JAR}")
|
||||
|
|
|
@ -1,5 +1,181 @@
|
|||
#include "headset/headset.h"
|
||||
#include "core/os.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include <android/log.h>
|
||||
|
||||
// Platform
|
||||
|
||||
bool lovrPlatformInit() {
|
||||
lovrPlatformOpenConsole();
|
||||
return true;
|
||||
}
|
||||
|
||||
void lovrPlatformDestroy() {
|
||||
//
|
||||
}
|
||||
|
||||
const char* lovrPlatformGetName() {
|
||||
return "Android";
|
||||
}
|
||||
|
||||
static uint64_t epoch;
|
||||
#define NS_PER_SEC 1000000000ULL
|
||||
|
||||
static uint64_t getTime() {
|
||||
struct timespec t;
|
||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
return (uint64_t) t.tv_sec * NS_PER_SEC + (uint64_t) t.tv_nsec;
|
||||
}
|
||||
|
||||
double lovrPlatformGetTime() {
|
||||
return (getTime() - epoch) / (double) NS_PER_SEC;
|
||||
}
|
||||
|
||||
void lovrPlatformSetTime(double time) {
|
||||
epoch = getTime() - (uint64_t) (time * NS_PER_SEC + .5);
|
||||
}
|
||||
|
||||
void lovrPlatformSleep(double seconds) {
|
||||
seconds += .5e-9;
|
||||
struct timespec t;
|
||||
t.tv_sec = seconds;
|
||||
t.tv_nsec = (seconds - t.tv_sec) * NS_PER_SEC;
|
||||
while (nanosleep(&t, &t));
|
||||
}
|
||||
|
||||
void lovrPlatformPollEvents() {
|
||||
//
|
||||
}
|
||||
|
||||
// To make regular printing work, a thread makes a pipe and redirects stdout and stderr to the write
|
||||
// end of the pipe. The read end of the pipe is forwarded to __android_log_write.
|
||||
static struct {
|
||||
int handles[2];
|
||||
pthread_t thread;
|
||||
} logState;
|
||||
|
||||
static void* log_main(void* data) {
|
||||
int* fd = data;
|
||||
pipe(fd);
|
||||
dup2(fd[1], STDOUT_FILENO);
|
||||
dup2(fd[1], STDERR_FILENO);
|
||||
setvbuf(stdout, 0, _IOLBF, 0);
|
||||
setvbuf(stderr, 0, _IONBF, 0);
|
||||
ssize_t length;
|
||||
char buffer[1024];
|
||||
while ((length = read(fd[0], buffer, sizeof(buffer) - 1)) > 0) {
|
||||
buffer[length] = '\0';
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "LOVR", buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lovrPlatformOpenConsole() {
|
||||
pthread_create(&logState.thread, NULL, log_main, logState.handles);
|
||||
pthread_detach(logState.thread);
|
||||
}
|
||||
|
||||
size_t lovrPlatformGetHomeDirectory(char* buffer, size_t size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t lovrPlatformGetDataDirectory(char* buffer, size_t size) {
|
||||
buffer[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t lovrPlatformGetWorkingDirectory(char* buffer, size_t size) {
|
||||
return getcwd(buffer, size) ? strlen(buffer) : 0;
|
||||
}
|
||||
|
||||
size_t lovrPlatformGetExecutablePath(char* buffer, size_t size) {
|
||||
ssize_t length = readlink("/proc/self/exe", buffer, size - 1);
|
||||
if (length >= 0) {
|
||||
buffer[length] = '\0';
|
||||
return length;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static char apkPath[1024];
|
||||
size_t lovrPlatformGetBundlePath(char* buffer, size_t size) {
|
||||
size_t length = strlen(apkPath);
|
||||
if (length >= size) return 0;
|
||||
memcpy(buffer, apkPath, length);
|
||||
buffer[length] = '\0';
|
||||
return length;
|
||||
}
|
||||
|
||||
bool lovrPlatformCreateWindow(WindowFlags* flags) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lovrPlatformHasWindow() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void lovrPlatformGetWindowSize(int* width, int* height) {
|
||||
if (width) *width = 0;
|
||||
if (height) *height = 0;
|
||||
}
|
||||
|
||||
void lovrPlatformGetFramebufferSize(int* width, int* height) {
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
}
|
||||
|
||||
void lovrPlatformSwapBuffers() {
|
||||
//
|
||||
}
|
||||
|
||||
void* lovrPlatformGetProcAddress(const char* function) {
|
||||
return (void*) eglGetProcAddress(function);
|
||||
}
|
||||
|
||||
void lovrPlatformOnQuitRequest(quitCallback callback) {
|
||||
//
|
||||
}
|
||||
|
||||
void lovrPlatformOnWindowFocus(windowFocusCallback callback) {
|
||||
//
|
||||
}
|
||||
|
||||
void lovrPlatformOnWindowResize(windowResizeCallback callback) {
|
||||
//
|
||||
}
|
||||
|
||||
void lovrPlatformOnMouseButton(mouseButtonCallback callback) {
|
||||
//
|
||||
}
|
||||
|
||||
void lovrPlatformOnKeyboardEvent(keyboardCallback callback) {
|
||||
//
|
||||
}
|
||||
|
||||
void lovrPlatformGetMousePosition(double* x, double* y) {
|
||||
*x = *y = 0.;
|
||||
}
|
||||
|
||||
void lovrPlatformSetMouseMode(MouseMode mode) {
|
||||
//
|
||||
}
|
||||
|
||||
bool lovrPlatformIsMouseDown(MouseButton button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool lovrPlatformIsKeyDown(KeyCode key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Headset backend
|
||||
|
||||
static struct {
|
||||
float offset;
|
||||
|
|
Loading…
Reference in New Issue