mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-26 05:55:15 +00:00
do vsync exactly like sm64-port does it
maybe this will finally work better
This commit is contained in:
parent
2dc93701a2
commit
a4b4d6d5e5
4 changed files with 13 additions and 14 deletions
|
@ -255,7 +255,7 @@ static struct Option optsControls[] = {
|
||||||
|
|
||||||
static struct Option optsVideo[] = {
|
static struct Option optsVideo[] = {
|
||||||
DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ),
|
DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ),
|
||||||
DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ),
|
DEF_OPT_TOGGLE( optsVideoStr[5], &configWindow.vsync ),
|
||||||
DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ),
|
DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ),
|
||||||
DEF_OPT_TOGGLE( optsVideoStr[7], &configHUD ),
|
DEF_OPT_TOGGLE( optsVideoStr[7], &configHUD ),
|
||||||
DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ),
|
DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ),
|
||||||
|
|
|
@ -100,7 +100,7 @@ static const struct ConfigOption options[] = {
|
||||||
{.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y},
|
{.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y},
|
||||||
{.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w},
|
{.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w},
|
||||||
{.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h},
|
{.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h},
|
||||||
{.name = "vsync", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.vsync},
|
{.name = "vsync", .type = CONFIG_TYPE_BOOL, .boolValue = &configWindow.vsync},
|
||||||
{.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering},
|
{.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering},
|
||||||
{.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume},
|
{.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume},
|
||||||
{.name = "music_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMusicVolume},
|
{.name = "music_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMusicVolume},
|
||||||
|
@ -268,7 +268,7 @@ void configfile_load(const char *filename) {
|
||||||
case CONFIG_TYPE_BOOL:
|
case CONFIG_TYPE_BOOL:
|
||||||
if (strcmp(tokens[1], "true") == 0)
|
if (strcmp(tokens[1], "true") == 0)
|
||||||
*option->boolValue = true;
|
*option->boolValue = true;
|
||||||
else if (strcmp(tokens[1], "false") == 0)
|
else
|
||||||
*option->boolValue = false;
|
*option->boolValue = false;
|
||||||
break;
|
break;
|
||||||
case CONFIG_TYPE_UINT:
|
case CONFIG_TYPE_UINT:
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int x, y, w, h;
|
unsigned int x, y, w, h;
|
||||||
unsigned int vsync;
|
bool vsync;
|
||||||
bool reset;
|
bool reset;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
bool exiting_fullscreen;
|
bool exiting_fullscreen;
|
||||||
|
|
|
@ -53,8 +53,7 @@ static void (*kb_all_keys_up)(void) = NULL;
|
||||||
// whether to use timer for frame control
|
// whether to use timer for frame control
|
||||||
static bool use_timer = true;
|
static bool use_timer = true;
|
||||||
// time between consequtive game frames
|
// time between consequtive game frames
|
||||||
static const Uint32 frame_time = 1000 / FRAMERATE;
|
static const int frame_time = 1000 / FRAMERATE;
|
||||||
static Uint32 frame_start = 0;
|
|
||||||
|
|
||||||
const SDL_Scancode windows_scancode_table[] = {
|
const SDL_Scancode windows_scancode_table[] = {
|
||||||
/* 0 1 2 3 4 5 6 7 */
|
/* 0 1 2 3 4 5 6 7 */
|
||||||
|
@ -138,8 +137,8 @@ int test_vsync(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void gfx_sdl_set_vsync(int mode) {
|
static inline void gfx_sdl_set_vsync(const bool enabled) {
|
||||||
if (mode > 1) {
|
if (enabled) {
|
||||||
// try to detect refresh rate
|
// try to detect refresh rate
|
||||||
SDL_GL_SetSwapInterval(1);
|
SDL_GL_SetSwapInterval(1);
|
||||||
const int vblanks = test_vsync();
|
const int vblanks = test_vsync();
|
||||||
|
@ -149,13 +148,12 @@ static inline void gfx_sdl_set_vsync(int mode) {
|
||||||
use_timer = false;
|
use_timer = false;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
printf("could not determine swap interval, falling back to one vblank + timer sync\n");
|
printf("could not determine swap interval, falling back to timer sync\n");
|
||||||
mode = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_SetSwapInterval(mode);
|
use_timer = true;
|
||||||
use_timer = (mode <= 1);
|
SDL_GL_SetSwapInterval(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gfx_sdl_set_fullscreen(void) {
|
static void gfx_sdl_set_fullscreen(void) {
|
||||||
|
@ -324,14 +322,15 @@ static void gfx_sdl_set_keyboard_callbacks(kb_callback_t on_key_down, kb_callbac
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool gfx_sdl_start_frame(void) {
|
static bool gfx_sdl_start_frame(void) {
|
||||||
frame_start = SDL_GetTicks();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void sync_framerate_with_timer(void) {
|
static inline void sync_framerate_with_timer(void) {
|
||||||
const Uint32 elapsed = SDL_GetTicks() - frame_start;
|
static Uint32 last_time = 0;
|
||||||
|
const int elapsed = SDL_GetTicks() - last_time;
|
||||||
if (elapsed < frame_time)
|
if (elapsed < frame_time)
|
||||||
SDL_Delay(frame_time - elapsed);
|
SDL_Delay(frame_time - elapsed);
|
||||||
|
last_time += frame_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gfx_sdl_swap_buffers_begin(void) {
|
static void gfx_sdl_swap_buffers_begin(void) {
|
||||||
|
|
Loading…
Reference in a new issue