Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/desktop/backends/glfw2.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static Runner *g_runner;

static bool tryOpenWindow(int reqW, int reqH) {
static bool tryOpenWindow(int reqW, int reqH, bool fullscreen) {
#ifdef GLFW_OPENGL_VERSION_MAJOR
if (gfx == SOFTWARE || gfx == LEGACY_GL) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
Expand All @@ -29,7 +29,7 @@ static bool tryOpenWindow(int reqW, int reqH) {
for (size_t i = 0; i < sizeof(GLCommon_versions)/sizeof(GLCommon_versions[0]); i++) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, GLCommon_versions[i].major);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, GLCommon_versions[i].minor);

if (GLCommon_versions[i].major >= 3) {
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
if (GLCommon_versions[i].major == 3 && GLCommon_versions[i].minor == 2) {
Expand All @@ -52,7 +52,7 @@ static bool tryOpenWindow(int reqW, int reqH) {

return false;
#else
return glfwOpenWindow(reqW, reqH, 8, 8, 8, 8, 24, 8, GLFW_WINDOW) != 0;
return glfwOpenWindow(reqW, reqH, 8, 8, 8, 8, 24, 8, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) != 0;
#endif
}

Expand Down Expand Up @@ -91,10 +91,21 @@ void platformGetMousePos(double *xPos, double *yPos) {
*yPos = (double)my;
}

static bool glfw2Fullscreen = false;

static bool platformGetWindowFocus(void) {
return glfwGetWindowParam(GLFW_ACTIVE);
}

bool platformGetWindowFullscreen(void) {
return glfw2Fullscreen;
}

void platformSetWindowFullscreen(bool fullscreen) {
if (fullscreen == glfw2Fullscreen) return;
glfw2Fullscreen = fullscreen;
}

static int32_t glfwKeyToGml(int glfwKey) {
// Letters and numbers are the same as GML
if (glfwKey >= 'A' && glfwKey <= 'Z') return glfwKey;
Expand Down Expand Up @@ -184,7 +195,7 @@ static void GLFWCALL scrollCallback(int pos) {
if (g_runner) RunnerMouse_onWheel(g_runner->mouse, yoffset);
}

bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) {
bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless, bool fullscreen) {
if (headless) {
fprintf(stderr, "Headless mode is not supported with GLFW 2\n");
return false;
Expand All @@ -196,7 +207,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless)
return false;
}

if (!tryOpenWindow(reqW, reqH)) {
if (!tryOpenWindow(reqW, reqH, fullscreen)) {
fprintf(stderr, "Failed to create GLFW window\n");
glfwTerminate();
return false;
Expand Down
23 changes: 22 additions & 1 deletion src/desktop/backends/glfw3.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ static bool platformGetWindowFocus(void) {
return glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0;
}

static int windowedX, windowedY, windowedW, windowedH;

bool platformGetWindowFullscreen(void) {
return glfwGetWindowMonitor(window) != NULL;
}

void platformSetWindowFullscreen(bool fullscreen) {
if (fullscreen == platformGetWindowFullscreen()) return;
if (fullscreen) {
glfwGetWindowPos(window, &windowedX, &windowedY);
glfwGetWindowSize(window, &windowedW, &windowedH);
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
} else {
glfwSetWindowMonitor(window, NULL, windowedX, windowedY, windowedW, windowedH, 0);
}
}

static void glfwErrorCallback(int code, const char* description) {
fprintf(stderr, "GLFW error 0x%x: %s\n", code, description);
}
Expand Down Expand Up @@ -220,7 +239,7 @@ static void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) {
RunnerMouse_onWheel(g_runner->mouse, yoffset);
}

bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) {
bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless, bool fullscreen) {
// Init GLFW
glfwSetErrorCallback(glfwErrorCallback);
if (!glfwInit()) {
Expand Down Expand Up @@ -269,6 +288,8 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless)
// We set the window size AFTER the window creation so we can use glfwGetWindowContentScale
platformSetWindowSize(reqW, reqH);

platformSetWindowFullscreen(fullscreen);

// Set up keyboard input
glfwSetKeyCallback(window, keyCallback);
glfwSetCharCallback(window, characterCallback);
Expand Down
24 changes: 17 additions & 7 deletions src/desktop/backends/sdl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,16 @@ static bool platformGetWindowFocus(void) {
return SDL_GetAppState() & SDL_APPINPUTFOCUS;
}

bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) {
bool platformGetWindowFullscreen(void) {
return scr ? (scr->flags & SDL_FULLSCREEN) : false;
}

void platformSetWindowFullscreen(bool fullscreen) {
if (fullscreen == platformGetWindowFullscreen()) return;
SDL_WM_ToggleFullScreen(scr);
}

bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless, bool fullscreen) {
if (headless && gfx != SOFTWARE) {
fprintf(stderr, "Headless mode on SDL 1.2 requires the software renderer!\n");
return false;
Expand Down Expand Up @@ -267,7 +276,8 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless)
fbWidth = reqW;
fbHeight = reqH;
if(!headless) {
scr = SDL_SetVideoMode(fbWidth, fbHeight, 0, (gfx == SOFTWARE ? 0 : SDL_OPENGL) | SDL_RESIZABLE);
Uint32 videoFlags = (gfx == SOFTWARE ? 0 : SDL_OPENGL) | SDL_RESIZABLE | (fullscreen ? SDL_FULLSCREEN : 0);
scr = SDL_SetVideoMode(fbWidth, fbHeight, 0, videoFlags);
if (!scr && gfx == SOFTWARE) {
SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
if (modes && modes != (SDL_Rect**) -1 && modes[0]) {
Expand Down Expand Up @@ -416,11 +426,11 @@ static void platformResetJoysticks(void) {
openJoysticks[i] = NULL;
}
}

SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
SDL_JoystickEventState(SDL_IGNORE);

int numJoysticks = SDL_NumJoysticks();
bool needsRemap = false;
for (int i = 0; i < numJoysticks && i < MAX_GAMEPADS; i++) {
Expand All @@ -432,11 +442,11 @@ static void platformResetJoysticks(void) {
needsRemap = true;
}
}

for (int i = numJoysticks; i < MAX_GAMEPADS; i++) {
joystickMappings[i].valid = false;
}

if (needsRemap) {
loadGamepadMappings();
}
Expand Down Expand Up @@ -502,7 +512,7 @@ bool platformHandleEvents(void) {
float norm = val / 32767.0f;
if (map->axis_button_sign[btn] < 0) norm = -norm;
if (norm < 0.0f) norm = 0.0f;

if (norm > slot->buttonValue[btn]) {
slot->buttonValue[btn] = norm;
}
Expand Down
16 changes: 13 additions & 3 deletions src/desktop/backends/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ bool platformGetScaledWindowSize(int32_t* outW, int32_t* outH) {
}

static float platformGetWindowScale(void) {
if (!scale_x || !scale_y) return;
int32_t draw_w, draw_h;
int logical_w, logical_h;
platformGetWindowSize(&draw_w, &draw_h);
if (!platformGetWindowSize(&draw_w, &draw_h)) return 1.0f;
SDL_GetWindowSize(window, &logical_w, &logical_h);
return (logical_h > 0) ? (float)draw_h / logical_h : 1.0f;
}
Expand Down Expand Up @@ -161,7 +160,15 @@ static bool platformGetWindowFocus(void) {
return SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS;
}

bool platformInit(int reqW, int reqH, const char *title, bool headless) {
bool platformGetWindowFullscreen(void) {
return SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP;
}

void platformSetWindowFullscreen(bool fullscreen) {
SDL_SetWindowFullscreen(window, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
}

bool platformInit(int reqW, int reqH, const char *title, bool headless, bool fullscreen) {
// Init SDL
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_GAMECONTROLLER)) {
fprintf(stderr, "Failed to initialize SDL\n");
Expand Down Expand Up @@ -213,6 +220,9 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) {
} else {
scr = SDL_GetWindowSurface(window);
}

platformSetWindowFullscreen(fullscreen);

// If we don't do this, the window will be larger than it should be on HiDPI displays.
platformSetWindowSize(reqW, reqH);

Expand Down
12 changes: 11 additions & 1 deletion src/desktop/backends/sdl3.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ static bool platformGetWindowFocus(void) {
return SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS;
}

bool platformInit(int reqW, int reqH, const char *title, bool headless) {
bool platformGetWindowFullscreen(void) {
return SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN;
}

void platformSetWindowFullscreen(bool fullscreen) {
SDL_SetWindowFullscreen(window, fullscreen);
}

bool platformInit(int reqW, int reqH, const char *title, bool headless, bool fullscreen) {
// Init SDL
if (!SDL_Init(SDL_INIT_VIDEO|SDL_INIT_GAMEPAD)) {
fprintf(stderr, "Failed to initialize SDL\n");
Expand Down Expand Up @@ -190,6 +198,8 @@ bool platformInit(int reqW, int reqH, const char *title, bool headless) {
} else
scr = SDL_GetWindowSurface(window);

platformSetWindowFullscreen(fullscreen);

return true;
}

Expand Down
10 changes: 9 additions & 1 deletion src/desktop/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ typedef struct {
bool alwaysLogUnknownFunctions;
bool alwaysLogStubbedFunctions;
bool headless;
bool fullscreen;
bool traceFrames;
bool printRooms;
bool printObjects;
Expand Down Expand Up @@ -425,6 +426,7 @@ static void printUsage(const char *argv0) {
" --record-inputs <file> - Record all keyboard inputs to a file\n"
" --playback-inputs <file> - Playback input from file\n"
" --renderer <renderer> - Set the rendering API\n"
" --fullscreen - Launch in fullscreen mode\n"
" --lazy-rooms - Lazily load rooms, increases load times but reduces memory usage\n"
" --eager-room <rooms> - When --lazy-rooms is set, keep these rooms always in memory\n"
" --os-type <os> - Set the reported OS type\n"
Expand Down Expand Up @@ -484,6 +486,7 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[])
{"record-inputs", required_argument, nullptr, 'I'},
{"playback-inputs", required_argument, nullptr, 'P'},
{"renderer", required_argument, nullptr, 'g'},
{"fullscreen", no_argument, nullptr, 4101},
{"lazy-rooms", no_argument, nullptr, 'z'},
{"eager-room", required_argument, nullptr, 'G'},
{"os-type", required_argument, nullptr, 'O'},
Expand Down Expand Up @@ -678,6 +681,9 @@ static void parseCommandLineArgs(CommandLineArgs* args, int argc, char* argv[])
case 'g':
args->renderer = optarg;
break;
case 4101:
args->fullscreen = true;
break;
case 'z':
args->lazyRooms = true;
break;
Expand Down Expand Up @@ -1321,7 +1327,7 @@ int main(int argc, char* argv[]) {
resolveWindowSize(&args, gen8->defaultWindowWidth, gen8->defaultWindowHeight, &windowW, &windowH);

if (!platformInitialized) {
if (!platformInit(windowW, windowH, windowTitle, args.headless)) {
if (!platformInit(windowW, windowH, windowTitle, args.headless, args.fullscreen)) {
DataWin_free(dataWin);
freeCommandLineArgs(&args);
return 1;
Expand Down Expand Up @@ -1418,6 +1424,8 @@ int main(int argc, char* argv[]) {
runner->setWindowSize = platformSetWindowSize;
runner->getWindowSize = platformGetWindowSize;
runner->setWindowTitle = platformSetWindowTitle;
runner->getWindowFullscreen = platformGetWindowFullscreen;
runner->setWindowFullscreen = platformSetWindowFullscreen;
Runner_setGameArgs(runner, currentGameArgs, (int32_t) arrlen(currentGameArgs));
platformInitFunctions(runner);

Expand Down
4 changes: 3 additions & 1 deletion src/desktop/platformdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "runner.h"
#include "input_recording.h"

bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless);
bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless, bool fullscreen);
void platformInitFunctions(Runner *);
void platformExit(void);
void platformSwapBuffers(void);
Expand All @@ -18,6 +18,8 @@ bool platformGetWindowSize(int32_t* outW, int32_t* outH);
bool platformGetScaledWindowSize(int32_t* outW, int32_t* outH);
void platformSetWindowSize(int32_t width, int32_t height);
void platformSetWindowTitle(const char* title);
bool platformGetWindowFullscreen(void);
void platformSetWindowFullscreen(bool fullscreen);
void platformSleepUntil(uint64_t time);

enum GraphicsAPI {
Expand Down
2 changes: 1 addition & 1 deletion src/ps2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ int main(int argc, char* argv[]) {
options.eagerlyLoadedRooms = eagerRooms;
options.progressCallback = PS2Overlay_statusScreenCallback;
options.progressCallbackUserData = PS2Overlay_getCallbackData();

DataWin* dataWin = DataWin_parse(dataWinPath, options);
free(dataWinPath);
shfree(eagerRooms);
Expand Down
2 changes: 1 addition & 1 deletion src/ps3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static void sys_callback(uint64_t status, uint64_t param, void* userdata) {
case SYSUTIL_EXIT_GAME:
shouldExit = true;
break;

case SYSUTIL_MENU_OPEN:
case SYSUTIL_MENU_CLOSE:
break;
Expand Down
2 changes: 2 additions & 0 deletions src/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ struct Runner {
bool (*getWindowSize)(int32_t* outW, int32_t* outH);
void (*setWindowSize)(int32_t width, int32_t height);
bool (*windowHasFocus)(void);
bool (*getWindowFullscreen)(void);
void (*setWindowFullscreen)(bool fullscreen);
void (*setCursor)(int32_t cursorType);
int32_t currentCursor; // last value passed to window_set_cursor
TileLayerMapEntry* tileLayerMap; // stb_ds hashmap: depth -> tile layer state
Expand Down
Loading
Loading