Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int engine_init(engine_init_flags *init_flags) {

int w = setting->video.screen_w;
int h = setting->video.screen_h;
int fs = setting->video.fullscreen;
int window_mode = setting->video.window_mode;
int vsync = setting->video.vsync;
int aspect = setting->video.aspect;
int fb_scale = setting->video.fb_scale;
Expand All @@ -57,7 +57,7 @@ int engine_init(engine_init_flags *init_flags) {
// Initialize everything.
video_scan_renderers();
audio_scan_backends();
if(!video_init(renderer, w, h, fs, vsync, aspect, framerate_limit, fb_scale, scaling_mode)) {
if(!video_init(renderer, w, h, window_mode, vsync, aspect, framerate_limit, fb_scale, scaling_mode)) {
goto exit_0;
}
if(!audio_init(player, frequency, mono, resampler, music_volume, sound_volume)) {
Expand Down Expand Up @@ -181,7 +181,7 @@ void engine_run(engine_init_flags *init_flags) {
int static_wait = 0;
while(run && game_state_is_running(gs)) {
// Handle events
bool check_fs;
int check_wm;
while(SDL_PollEvent(&e)) {
// Handle other events
switch(e.type) {
Expand Down Expand Up @@ -264,8 +264,8 @@ void engine_run(engine_init_flags *init_flags) {
enable_screen_updates = 1;
break;
case SDL_WINDOWEVENT_RESTORED:
video_get_state(NULL, NULL, &check_fs, NULL, NULL, NULL);
if(check_fs) {
video_get_state(NULL, NULL, &check_wm, NULL, NULL, NULL);
if(check_wm != WINDOW_MODE_WINDOWED) {
video_reinit_renderer();
}
log_debug("RESTORED");
Expand Down
14 changes: 9 additions & 5 deletions src/game/scenes/mainmenu/menu_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,17 @@ void menu_video_done(component *c, void *u) {
bool render_plugin_changed = strcmp(v->renderer, local->old_video_settings.renderer) != 0;
if(render_plugin_changed) {
video_close();
video_init(v->renderer, v->screen_w, v->screen_h, v->fullscreen, v->vsync, v->aspect, v->framerate_limit,
video_init(v->renderer, v->screen_w, v->screen_h, v->window_mode, v->vsync, v->aspect, v->framerate_limit,
v->fb_scale, v->scaling_mode);
menu_set_submenu(c->parent, menu_video_confirm_create(s, &local->old_video_settings));
} else if(local->old_video_settings.screen_w != v->screen_w || local->old_video_settings.screen_h != v->screen_h ||
local->old_video_settings.fullscreen != v->fullscreen || local->old_video_settings.vsync != v->vsync ||
local->old_video_settings.window_mode != v->window_mode ||
local->old_video_settings.vsync != v->vsync ||
local->old_video_settings.aspect != v->aspect ||
local->old_video_settings.framerate_limit != v->framerate_limit ||
local->old_video_settings.fb_scale != v->fb_scale ||
local->old_video_settings.scaling_mode != v->scaling_mode) {
video_reinit(v->screen_w, v->screen_h, v->fullscreen, v->vsync, v->aspect, v->framerate_limit, v->fb_scale,
video_reinit(v->screen_w, v->screen_h, v->window_mode, v->vsync, v->aspect, v->framerate_limit, v->fb_scale,
v->scaling_mode);

menu_set_submenu(c->parent, menu_video_confirm_create(s, &local->old_video_settings));
Expand Down Expand Up @@ -303,8 +304,11 @@ component *menu_video_create(scene *s) {
&setting->video.vsync, offon_opts, 2));
menu_attach(menu, textselector_create_bind_opts("ASPECT", "Video aspect ratio. Original game is 4:3.", NULL, NULL,
&setting->video.aspect, aspect_opts, 2));
menu_attach(menu, textselector_create_bind_opts("FULLSCREEN", "Run the game in a fullscreen window.", NULL, NULL,
&setting->video.fullscreen, offon_opts, 2));
const char *window_mode_opts[] = {"OFF", "WINDOWED", "EXCLUSIVE"};
menu_attach(menu,
textselector_create_bind_opts("FS",
"OFF=windowed, WINDOWED=borderless fullscreen, EXCLUSIVE=true fullscreen.",
NULL, NULL, &setting->video.window_mode, window_mode_opts, 3));

// Done button
menu_attach(menu, button_create("DONE", "Return to the main menu.", false, false, menu_video_done, s));
Expand Down
4 changes: 2 additions & 2 deletions src/game/scenes/mainmenu/menu_video_confirm.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ void video_confirm_cancel_clicked(component *c, void *userdata) {
*v = *local->old_video_settings;
if(render_plugin_changed) {
video_close();
video_init(v->renderer, v->screen_w, v->screen_h, v->fullscreen, v->vsync, v->aspect, v->framerate_limit,
video_init(v->renderer, v->screen_w, v->screen_h, v->window_mode, v->vsync, v->aspect, v->framerate_limit,
v->fb_scale, v->scaling_mode);
} else {
video_reinit(v->screen_w, v->screen_h, v->fullscreen, v->vsync, v->aspect, v->framerate_limit, v->fb_scale,
video_reinit(v->screen_w, v->screen_h, v->window_mode, v->vsync, v->aspect, v->framerate_limit, v->fb_scale,
v->scaling_mode);
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/utils/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const field f_video[] = {
F_INT(settings_video, framerate_limit, 0),
F_BOOL(settings_video, vsync, 0),
F_INT(settings_video, aspect, 0),
F_BOOL(settings_video, fullscreen, 0),
F_INT(settings_video, window_mode, WINDOW_MODE_WINDOWED),
F_INT(settings_video, scaling, 0),
F_INT(settings_video, scaling_mode, 0),
F_BOOL(settings_video, instant_console, 0),
Expand Down
9 changes: 8 additions & 1 deletion src/game/utils/settings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifndef SETTINGS_H
#define SETTINGS_H

typedef enum
{
WINDOW_MODE_WINDOWED,
WINDOW_MODE_BORDERLESS,
WINDOW_MODE_FULLSCREEN
} window_mode;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should also be a typedef for this, and that should be used as a function argument type, if possible.


typedef enum
{
FIGHT_MODE_NORMAL,
Expand Down Expand Up @@ -46,7 +53,7 @@ typedef struct {
int framerate_limit;
int vsync;
int aspect;
int fullscreen;
int window_mode;
int scaling;
int scaling_mode;
int instant_console;
Expand Down
10 changes: 5 additions & 5 deletions src/video/renderers/null/null_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ static const char *get_name(void) {
return "NULL";
}

static bool setup_context(void *userdata, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
static bool setup_context(void *userdata, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode) {
log_info("NULL Renderer initialized!");
return true;
}

static void get_context_state(void *userdata, int *window_w, int *window_h, bool *fullscreen, bool *vsync, int *aspect,
static void get_context_state(void *userdata, int *window_w, int *window_h, int *window_mode, bool *vsync, int *aspect,
int *fb_scale) {
if(window_w != NULL) {
*window_w = 0;
}
if(window_h != NULL) {
*window_h = 0;
}
if(fullscreen != NULL) {
*fullscreen = false;
if(window_mode != NULL) {
*window_mode = 0;
}
if(vsync != NULL) {
*vsync = false;
Expand All @@ -43,7 +43,7 @@ static void get_context_state(void *userdata, int *window_w, int *window_h, bool
}
}

static bool reset_context_with(void *userdata, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
static bool reset_context_with(void *userdata, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode) {
log_info("NULL renderer reset.");
return true;
Expand Down
20 changes: 10 additions & 10 deletions src/video/renderers/opengl3/gl3_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct gl3_context {
int screen_w;
int screen_h;
int fb_scale;
bool fullscreen;
int window_mode;
bool vsync;
int aspect;
int scaling_mode;
Expand Down Expand Up @@ -104,12 +104,12 @@ static void reload_scaler_program(const gl3_context *ctx) {
bind_uniform_2f(ctx->scale_prog_id, "texture_size", (GLfloat)fb_w, (GLfloat)fb_h);
}

static bool setup_context(void *userdata, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
static bool setup_context(void *userdata, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode) {
gl3_context *ctx = userdata;
ctx->screen_w = window_w;
ctx->screen_h = window_h;
ctx->fullscreen = fullscreen;
ctx->window_mode = window_mode;
ctx->framerate_limit = framerate_limit;
ctx->fb_scale = fb_scale;
ctx->vsync = vsync;
Expand All @@ -121,7 +121,7 @@ static bool setup_context(void *userdata, int window_w, int window_h, bool fulls
ctx->last_tick = SDL_GetPerformanceCounter();
set_framerate_limit(ctx, framerate_limit);

if(!create_window(&ctx->window, window_w, window_h, fullscreen)) {
if(!create_window(&ctx->window, window_w, window_h, window_mode)) {
goto error_0;
}
if(!create_gl_context(&ctx->gl_context, ctx->window)) {
Expand Down Expand Up @@ -206,7 +206,7 @@ static bool setup_context(void *userdata, int window_w, int window_h, bool fulls
return false;
}

static void get_context_state(void *userdata, int *window_w, int *window_h, bool *fullscreen, bool *vsync, int *aspect,
static void get_context_state(void *userdata, int *window_w, int *window_h, int *window_mode, bool *vsync, int *aspect,
int *fb_scale) {
gl3_context *ctx = userdata;
if(window_w != NULL) {
Expand All @@ -215,8 +215,8 @@ static void get_context_state(void *userdata, int *window_w, int *window_h, bool
if(window_h != NULL) {
*window_h = ctx->screen_h;
}
if(fullscreen != NULL) {
*fullscreen = ctx->fullscreen;
if(window_mode != NULL) {
*window_mode = ctx->window_mode;
}
if(vsync != NULL) {
*vsync = ctx->vsync;
Expand All @@ -229,17 +229,17 @@ static void get_context_state(void *userdata, int *window_w, int *window_h, bool
}
}

static bool reset_context_with(void *userdata, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
static bool reset_context_with(void *userdata, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode) {
gl3_context *ctx = userdata;
ctx->screen_w = window_w;
ctx->screen_h = window_h;
ctx->fullscreen = fullscreen;
ctx->window_mode = window_mode;
ctx->vsync = vsync;
ctx->aspect = aspect;

set_framerate_limit(ctx, framerate_limit);
bool success = resize_window(ctx->window, window_w, window_h, fullscreen);
bool success = resize_window(ctx->window, window_w, window_h, window_mode);
success = set_vsync(ctx->vsync) && success;

const bool fb_scale_changed = ctx->fb_scale != fb_scale;
Expand Down
23 changes: 18 additions & 5 deletions src/video/renderers/opengl3/sdl_window.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "video/renderers/opengl3/sdl_window.h"
#include "game/utils/settings.h"
#include "game/utils/version.h"
#include "utils/log.h"

Expand Down Expand Up @@ -73,7 +74,7 @@ bool has_gl_available(int version_major, int version_minor) {
return ret;
}

bool create_window(SDL_Window **window, int width, int height, bool fullscreen) {
bool create_window(SDL_Window **window, int width, int height, int window_mode) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to use the new type. For example this would be "window_mode window_mode" instead of "int window_mode". Idea is that we declare by type that this variable can only contain the three types defined by the typedef. This goes for all functions where this is used.

char title[32];
snprintf(title, 32, "OpenOMF v%s", get_version_string());

Expand All @@ -95,11 +96,17 @@ bool create_window(SDL_Window **window, int width, int height, bool fullscreen)
return false;
}

if(fullscreen) {
if(window_mode == WINDOW_MODE_FULLSCREEN) {
if(SDL_SetWindowFullscreen(w, SDL_WINDOW_FULLSCREEN) != 0) {
log_error("Could not set fullscreen mode: %s", SDL_GetError());
} else {
log_info("Fullscreen mode enabled!");
log_info("Fullscreen mode enabled (exclusive)!");
}
} else if(window_mode == WINDOW_MODE_BORDERLESS) {
if(SDL_SetWindowFullscreen(w, SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) {
log_error("Could not set fullscreen mode: %s", SDL_GetError());
} else {
log_info("Fullscreen mode enabled (borderless)!");
}
} else {
SDL_SetWindowFullscreen(w, 0);
Expand All @@ -110,9 +117,15 @@ bool create_window(SDL_Window **window, int width, int height, bool fullscreen)
return true;
}

bool resize_window(SDL_Window *window, int width, int height, bool fullscreen) {
bool resize_window(SDL_Window *window, int width, int height, int window_mode) {
SDL_SetWindowSize(window, width, height);
if(SDL_SetWindowFullscreen(window, fullscreen ? SDL_WINDOW_FULLSCREEN : 0) < 0) {
unsigned int fs_flag = 0;
if(window_mode == WINDOW_MODE_FULLSCREEN) {
fs_flag = SDL_WINDOW_FULLSCREEN;
} else if(window_mode == WINDOW_MODE_BORDERLESS) {
fs_flag = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
if(SDL_SetWindowFullscreen(window, fs_flag) < 0) {
log_error("Could not set fullscreen mode: %s", SDL_GetError());
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/video/renderers/opengl3/sdl_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

bool has_gl_available(int major_version, int minor_version);
bool create_gl_context(SDL_GLContext **context, SDL_Window *window);
bool create_window(SDL_Window **window, int width, int height, bool fullscreen);
bool resize_window(SDL_Window *window, int width, int height, bool fullscreen);
bool create_window(SDL_Window **window, int width, int height, int window_mode);
bool resize_window(SDL_Window *window, int width, int height, int window_mode);
bool set_vsync(bool enable);
void ortho2d(float *matrix, float left, float right, float bottom, float top);

Expand Down
6 changes: 3 additions & 3 deletions src/video/renderers/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ typedef void (*init_renderer_fn)(renderer *renderer);
typedef void (*close_renderer_fn)(renderer *renderer);

// Renderer initialization and de-initialization, these must be implemented.
typedef bool (*setup_context_fn)(void *ctx, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
typedef bool (*setup_context_fn)(void *ctx, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode);
typedef void (*get_context_state_fn)(void *ctx, int *window_w, int *window_h, bool *fullscreen, bool *vsync,
typedef void (*get_context_state_fn)(void *ctx, int *window_w, int *window_h, int *window_mode, bool *vsync,
int *aspect, int *fb_scale);
typedef bool (*reset_context_with_fn)(void *ctx, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
typedef bool (*reset_context_with_fn)(void *ctx, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode);
typedef void (*reset_context_fn)(void *ctx);
typedef void (*close_context_fn)(void *ctx);
Expand Down
12 changes: 6 additions & 6 deletions src/video/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ static bool video_find_renderer(const char *try_name) {
return false;
}

bool video_init(const char *try_name, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
bool video_init(const char *try_name, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode) {
if(!video_find_renderer(try_name)) {
goto exit_0;
}
current_renderer.create(&current_renderer);
if(!current_renderer.setup_context(current_renderer.ctx, window_w, window_h, fullscreen, vsync, aspect,
if(!current_renderer.setup_context(current_renderer.ctx, window_w, window_h, window_mode, vsync, aspect,
framerate_limit, fb_scale, scaling_mode)) {
goto exit_1;
}
Expand All @@ -179,9 +179,9 @@ void video_reinit_renderer(void) {
current_renderer.reset_context(current_renderer.ctx);
}

bool video_reinit(int window_w, int window_h, bool fullscreen, bool vsync, int aspect, int framerate_limit,
bool video_reinit(int window_w, int window_h, int window_mode, bool vsync, int aspect, int framerate_limit,
int fb_scale, int scaling_mode) {
return current_renderer.reset_context_with(current_renderer.ctx, window_w, window_h, fullscreen, vsync, aspect,
return current_renderer.reset_context_with(current_renderer.ctx, window_w, window_h, window_mode, vsync, aspect,
framerate_limit, fb_scale, scaling_mode);
}

Expand Down Expand Up @@ -214,8 +214,8 @@ void video_move_target(int x, int y) {
current_renderer.move_target(current_renderer.ctx, x, y);
}

void video_get_state(int *w, int *h, bool *fs, bool *vsync, int *aspect, int *fb_scale) {
current_renderer.get_context_state(current_renderer.ctx, w, h, fs, vsync, aspect, fb_scale);
void video_get_state(int *w, int *h, int *window_mode, bool *vsync, int *aspect, int *fb_scale) {
current_renderer.get_context_state(current_renderer.ctx, w, h, window_mode, vsync, aspect, fb_scale);
}

void video_schedule_screenshot(video_screenshot_signal callback) {
Expand Down
12 changes: 6 additions & 6 deletions src/video/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,30 @@ bool video_get_renderer_info(int index, const char **name, const char **descript
* @param try_name Preferred renderer name (NULL to use the best available)
* @param window_w Window width in pixels
* @param window_h Window height in pixels
* @param fullscreen Enable fullscreen mode
* @param window_mode Window mode (WINDOW_MODE_WINDOWED, WINDOW_MODE_FULLSCREEN, WINDOW_MODE_BORDERLESS)
* @param vsync Enable vertical sync
* @param aspect Aspect ratio mode
* @param framerate_limit Maximum framerate (0 for unlimited)
* @param fb_scale Framebuffer scale factor
* @param scaling_mode Scaling algorithm mode
* @return true on success, false on failure
*/
bool video_init(const char *try_name, int window_w, int window_h, bool fullscreen, bool vsync, int aspect,
bool video_init(const char *try_name, int window_w, int window_h, int window_mode, bool vsync, int aspect,
int framerate_limit, int fb_scale, int scaling_mode);

/**
* @brief Reinitialize video with new settings (keeps current renderer)
* @param window_w Window width in pixels
* @param window_h Window height in pixels
* @param fullscreen Enable fullscreen mode
* @param window_mode Window mode (WINDOW_MODE_WINDOWED, WINDOW_MODE_FULLSCREEN, WINDOW_MODE_BORDERLESS)
* @param vsync Enable vertical sync
* @param aspect Aspect ratio mode
* @param framerate_limit Maximum framerate (0 for unlimited)
* @param fb_scale Framebuffer scale factor
* @param scaling_mode Scaling algorithm mode
* @return true on success, false on failure
*/
bool video_reinit(int window_w, int window_h, bool fullscreen, bool vsync, int aspect, int framerate_limit,
bool video_reinit(int window_w, int window_h, int window_mode, bool vsync, int aspect, int framerate_limit,
int fb_scale, int scaling_mode);

/**
Expand All @@ -82,12 +82,12 @@ void video_reinit_renderer(void);
* @brief Get current video state
* @param w Output for window width (can be NULL)
* @param h Output for window height (can be NULL)
* @param fs Output for fullscreen state (can be NULL)
* @param window_mode Output for window mode (can be NULL)
* @param vsync Output for vsync state (can be NULL)
* @param aspect Output for aspect ratio mode (can be NULL)
* @param fb_scale Output for framebuffer scale (can be NULL)
*/
void video_get_state(int *w, int *h, bool *fs, bool *vsync, int *aspect, int *fb_scale);
void video_get_state(int *w, int *h, int *window_mode, bool *vsync, int *aspect, int *fb_scale);

/**
* @brief Move the rendering target position
Expand Down