Modernize egl-main

This commit is contained in:
Jeffrey Pfau 2014-07-23 22:57:58 -07:00
parent 754d3f50ce
commit 6c9ee4c212
1 changed files with 22 additions and 19 deletions

View File

@ -68,41 +68,46 @@ static void _GBASDLStart(struct GBAThread* context);
static void _GBASDLClean(struct GBAThread* context); static void _GBASDLClean(struct GBAThread* context);
int main(int argc, char** argv) { int main(int argc, char** argv) {
const char* fname = "test.rom"; struct GBAVideoEGLRenderer renderer;
if (argc > 1) {
fname = argv[1]; struct StartupOptions opts;
} if (!parseCommandArgs(&opts, argc, argv, 0)) {
int fd = open(fname, O_RDONLY); usage(argv[0], 0);
if (fd < 0) { freeOptions(&opts);
return 1; return 1;
} }
struct GBAVideoEGLRenderer renderer;
if (!_GBAEGLInit(&renderer)) { if (!_GBAEGLInit(&renderer)) {
return 1; return 1;
} }
GBAVideoSoftwareRendererCreate(&renderer.d); GBAVideoSoftwareRendererCreate(&renderer.d);
struct GBAThread context = { struct GBAThread context = {
.fd = fd,
.fname = fname,
.biosFd = -1,
.useDebugger = 0,
.renderer = &renderer.d.d, .renderer = &renderer.d.d,
.frameskip = 0,
.sync.videoFrameWait = 0, .sync.videoFrameWait = 0,
.sync.audioWait = 0, .sync.audioWait = 1,
.startCallback = _GBASDLStart, .startCallback = _GBASDLStart,
.cleanCallback = _GBASDLClean, .cleanCallback = _GBASDLClean,
.userData = &renderer .userData = &renderer
}; };
context.debugger = createDebugger(&opts);
GBAMapOptionsToContext(&opts, &context);
renderer.audio.samples = context.audioBuffers;
GBASDLInitAudio(&renderer.audio);
renderer.events.bindings = &context.inputMap;
GBASDLInitEvents(&renderer.events);
GBAThreadStart(&context); GBAThreadStart(&context);
_GBAEGLRunloop(&context, &renderer); _GBAEGLRunloop(&context, &renderer);
GBAThreadJoin(&context); GBAThreadJoin(&context);
close(fd); freeOptions(&opts);
free(context.debugger);
_GBAEGLDeinit(&renderer); _GBAEGLDeinit(&renderer);
@ -114,9 +119,6 @@ static int _GBAEGLInit(struct GBAVideoEGLRenderer* renderer) {
return 0; return 0;
} }
GBASDLInitEvents(&renderer->events);
GBASDLInitAudio(&renderer->audio);
bcm_host_init(); bcm_host_init();
renderer->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); renderer->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
int major, minor; int major, minor;
@ -238,7 +240,7 @@ static void _GBAEGLRunloop(struct GBAThread* context, struct GBAVideoEGLRenderer
GBASyncWaitFrameEnd(&context->sync); GBASyncWaitFrameEnd(&context->sync);
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
GBASDLHandleEvent(context, &event); GBASDLHandleEvent(context, &renderer->events, &event);
} }
} }
} }
@ -259,6 +261,7 @@ static void _GBAEGLDeinit(struct GBAVideoEGLRenderer* renderer) {
static void _GBASDLStart(struct GBAThread* threadContext) { static void _GBASDLStart(struct GBAThread* threadContext) {
struct GBAVideoEGLRenderer* renderer = threadContext->userData; struct GBAVideoEGLRenderer* renderer = threadContext->userData;
renderer->audio.audio = &threadContext->gba->audio; renderer->audio.audio = &threadContext->gba->audio;
renderer->audio.thread = threadContext;
} }
static void _GBASDLClean(struct GBAThread* threadContext) { static void _GBASDLClean(struct GBAThread* threadContext) {