Don't require a game on startup

This commit is contained in:
Simon Gellis 2024-10-31 21:21:05 -04:00
parent 3cb5606382
commit f6ed4d6f27
4 changed files with 21 additions and 9 deletions

9
cli.c
View File

@ -2,10 +2,15 @@
#include <stdio.h> #include <stdio.h>
int parseCLIArgs(int argc, char **argv, CLIArgs *args) { int parseCLIArgs(int argc, char **argv, CLIArgs *args) {
if (argc != 2) { int arg;
args->filename = NULL;
for (arg = 1; arg < argc; ++arg) {
if (args->filename) {
fprintf(stderr, "usage: %s /path/to/rom.vb\n", argv[0]); fprintf(stderr, "usage: %s /path/to/rom.vb\n", argv[0]);
return 1; return 1;
} }
args->filename = argv[1]; args->filename = argv[arg];
}
return 0; return 0;
} }

9
main.c
View File

@ -1,5 +1,6 @@
#include "cli.h" #include "cli.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include "ui.h" #include "ui.h"
@ -7,6 +8,7 @@ int main(int argc, char **argv) {
CLIArgs args; CLIArgs args;
UIContext *ui; UIContext *ui;
int status; int status;
bool running = false;
if (parseCLIArgs(argc, argv, &args)) { if (parseCLIArgs(argc, argv, &args)) {
return 1; return 1;
@ -25,10 +27,13 @@ int main(int argc, char **argv) {
} }
if (args.filename) { if (args.filename) {
uiLoadGame(ui, args.filename); if (uiLoadGame(ui, args.filename)) {
return 1;
}
running = true;
} }
status = uiRun(ui); status = uiRun(ui, running);
uiDestroy(ui); uiDestroy(ui);
SDL_Quit(); SDL_Quit();
return status; return status;

4
ui.c
View File

@ -105,10 +105,10 @@ typedef enum status_t {
status_running status_running
} status_t; } status_t;
int uiRun(UIContext *ui) { int uiRun(UIContext *ui, bool running) {
static uint8_t leftEye[384*224]; static uint8_t leftEye[384*224];
static uint8_t rightEye[384*224]; static uint8_t rightEye[384*224];
status_t status = status_running; status_t status = running ? status_running : status_paused;
while (1) { while (1) {
struct nk_context *ctx; struct nk_context *ctx;

4
ui.h
View File

@ -1,11 +1,13 @@
#ifndef SHROOMS_VB_NATIVE_UI_ #ifndef SHROOMS_VB_NATIVE_UI_
#define SHROOMS_VB_NATIVE_UI_ #define SHROOMS_VB_NATIVE_UI_
#include <stdbool.h>
typedef struct UIContext UIContext; typedef struct UIContext UIContext;
UIContext *uiInit(); UIContext *uiInit();
void uiDestroy(UIContext *ui); void uiDestroy(UIContext *ui);
int uiLoadGame(UIContext *ui, const char *path); int uiLoadGame(UIContext *ui, const char *path);
int uiRun(UIContext *ui); int uiRun(UIContext *ui, bool running);
#endif #endif