Fixes nicer fullscreen rendering

Also solves some compiler warnings on linux
This commit is contained in:
Linus Probert 2018-08-30 08:54:21 +02:00
parent 0d1836a8ba
commit a75a0d9331
8 changed files with 54 additions and 30 deletions

View File

@ -1,4 +1,6 @@
-DDEBUG -DDEBUG
-I./steamworks_c_api/src/
-I./src/steam/
-I./build/config.h -I./build/config.h
-I/usr/include/SDL2/ -I/usr/include/SDL2/
-I/usr/include/lua5.2/ -I/usr/include/lua5.2/

View File

@ -254,7 +254,7 @@ static void
initViewports(Uint32 offset) initViewports(Uint32 offset)
{ {
mainViewport = (SDL_Rect) { offset, 0, mainViewport = (SDL_Rect) { offset, 0,
SCREEN_HEIGHT, SCREEN_WIDTH SCREEN_WIDTH, SCREEN_HEIGHT
}; };
gameViewport = (SDL_Rect) { offset, 0, gameViewport = (SDL_Rect) { offset, 0,
@ -547,6 +547,31 @@ init(void)
return true; return true;
} }
static void
toggle_fullscreen(void)
{
bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP;
Settings *settings = settings_get();
if (isFullscreen) {
initViewports(0);
SDL_SetWindowFullscreen(gWindow, 0);
settings->fullscreen_enabled = false;
}
else {
int w, h;
SDL_GetWindowSize(gWindow, &w, &h);
SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_DisplayMode dMode;
SDL_GetWindowDisplayMode(gWindow, &dMode);
double ratio = (double) (dMode.w) / w;
double offset = ((dMode.w - w) / 2);
initViewports((Uint32)((offset)/(ratio*2)));
settings->fullscreen_enabled = true;
}
}
static void static void
handle_main_input(void) handle_main_input(void)
{ {
@ -592,23 +617,7 @@ handle_main_input(void)
} }
if (input_modkey_is_pressed(&input, KEY_CTRL_F)) { if (input_modkey_is_pressed(&input, KEY_CTRL_F)) {
bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP; toggle_fullscreen();
if (isFullscreen) {
initViewports(0);
SDL_SetWindowFullscreen(gWindow, 0);
}
else {
int w, h;
SDL_RenderGetLogicalSize(gRenderer, &w, &h);
SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_DisplayMode dMode;
SDL_GetWindowDisplayMode(gWindow, &dMode);
double ratio = (double) w / (double) dMode.w;
double offset = (double) (dMode.w - w) / 2;
initViewports((Uint32) (offset * ratio));
}
} }
} }
@ -643,9 +652,6 @@ handle_events(void)
static bool static bool
is_player_dead(void) is_player_dead(void)
{ {
#ifdef DEBUG
gPlayer->stats.hp = gPlayer->stats.hp > 0 ? gPlayer->stats.hp : 1;
#endif // DEBUG
if (gPlayer->stats.hp <= 0) { if (gPlayer->stats.hp <= 0) {
return true; return true;
} }
@ -731,9 +737,10 @@ run_game_update(void)
if (skillActivated && settings->tooltips_enabled && playerLevel < 5) { if (skillActivated && settings->tooltips_enabled && playerLevel < 5) {
gGui->activeTooltip = new_skill_tooltip; gGui->activeTooltip = new_skill_tooltip;
} }
if (!artifactTooltipShown && gPlayer->equipment.hasArtifacts && settings->tooltips_enabled) { if (!artifactTooltipShown && gPlayer->equipment.hasArtifacts) {
artifactTooltipShown = true; artifactTooltipShown = true;
gGui->activeTooltip = new_artifact_tooltip; if (settings->tooltips_enabled)
gGui->activeTooltip = new_artifact_tooltip;
} }
if (gGameState == PLAYING && currentTurn == PLAYER) if (gGameState == PLAYING && currentTurn == PLAYER)
@ -839,6 +846,7 @@ run_game_render(void)
render_game(); render_game();
render_gui(); render_gui();
SDL_RenderSetViewport(gRenderer, &mainViewport);
particle_engine_render_global(gCamera); particle_engine_render_global(gCamera);
gui_render_tooltip(gGui, gCamera); gui_render_tooltip(gGui, gCamera);
@ -1090,6 +1098,11 @@ int main(int argc, char *argv[])
if (!init()) if (!init())
return 1; return 1;
if (settings_get()->fullscreen_enabled) {
// Game starts in windowed mode so this will
// change to fullscreen
toggle_fullscreen();
}
run(); run();
close(); close();
PHYSFS_deinit(); PHYSFS_deinit();

View File

@ -31,6 +31,7 @@ static const char *KEY_MUSIC_ENABLED = "music_enabled";
static const char *KEY_SOUND_ENABLED = "sound_enabled"; static const char *KEY_SOUND_ENABLED = "sound_enabled";
static const char *KEY_TOOLTIPS_ENABLED = "tooltips_enabled"; static const char *KEY_TOOLTIPS_ENABLED = "tooltips_enabled";
static const char *KEY_HOW_TO_PLAY_SHOWN = "how_to_play_shown"; static const char *KEY_HOW_TO_PLAY_SHOWN = "how_to_play_shown";
static const char *KEY_FULLSCREEN_ENABLED = "fullscreen_enabled";
static static
DbQuery MIGRATE_COMMANDS[] = { DbQuery MIGRATE_COMMANDS[] = {
@ -53,6 +54,7 @@ set_default_settings(void)
settings.sound_enabled = true; settings.sound_enabled = true;
settings.tooltips_enabled = true; settings.tooltips_enabled = true;
settings.howto_tooltip_shown = false; settings.howto_tooltip_shown = false;
settings.fullscreen_enabled = false;
} }
static void static void
@ -90,6 +92,10 @@ load_settings_cb(void *unused, int count, char **values, char **colNames)
settings.howto_tooltip_shown = (bool)atoi(values[i + 1]); settings.howto_tooltip_shown = (bool)atoi(values[i + 1]);
i += 2; i += 2;
} }
else if (!strcmp(KEY_FULLSCREEN_ENABLED, values[i])) {
settings.fullscreen_enabled = (bool)atoi(values[i + 1]);
i += 2;
}
else if (!strcmp(KEY_TOOLTIPS_ENABLED, values[i])) { else if (!strcmp(KEY_TOOLTIPS_ENABLED, values[i])) {
settings.tooltips_enabled = (bool)atoi(values[i + 1]); settings.tooltips_enabled = (bool)atoi(values[i + 1]);
i += 2; i += 2;
@ -141,6 +147,7 @@ settings_save(void)
save_setting_int(KEY_MUSIC_ENABLED, settings.music_enabled); save_setting_int(KEY_MUSIC_ENABLED, settings.music_enabled);
save_setting_int(KEY_TOOLTIPS_ENABLED, settings.tooltips_enabled); save_setting_int(KEY_TOOLTIPS_ENABLED, settings.tooltips_enabled);
save_setting_int(KEY_HOW_TO_PLAY_SHOWN, settings.howto_tooltip_shown); save_setting_int(KEY_HOW_TO_PLAY_SHOWN, settings.howto_tooltip_shown);
save_setting_int(KEY_FULLSCREEN_ENABLED, settings.fullscreen_enabled);
} }
Settings * Settings *

View File

@ -26,6 +26,7 @@ typedef struct Settings {
bool sound_enabled; bool sound_enabled;
bool tooltips_enabled; bool tooltips_enabled;
bool howto_tooltip_shown; bool howto_tooltip_shown;
bool fullscreen_enabled;
} Settings; } Settings;
void void

View File

@ -19,7 +19,7 @@ static Sint64 m_AppID = 0;
static Sint64 m_hLeaderboard = 0; static Sint64 m_hLeaderboard = 0;
static bool static bool
steam_request_stats() steam_request_stats(void)
{ {
if (m_Initiated) if (m_Initiated)
return c_SteamUserStats_RequestCurrentStats(); return c_SteamUserStats_RequestCurrentStats();

View File

@ -26,6 +26,7 @@ endif ()
include_directories(${STEAMWORKS_INCLUDE_DIR}) include_directories(${STEAMWORKS_INCLUDE_DIR})
add_library(steamworks_c_wrapper add_library(steamworks_c_wrapper
SHARED
src/steamworks_c_wrapper src/steamworks_c_wrapper
) )

View File

@ -11,10 +11,10 @@ static bool m_RecvCB = false;
static void(*statsReceivedCb)(void) = NULL; static void(*statsReceivedCb)(void) = NULL;
static void(*statsStoredCb)(void) = NULL; static void(*statsStoredCb)(void) = NULL;
static void(*leaderBoardReceived)(int64) = NULL; static void(*leaderBoardReceived)(int64_t) = NULL;
extern "C" int64 extern "C" int64_t
c_SteamAPI_Init() c_SteamAPI_Init()
{ {
if (SteamAPI_Init()) { if (SteamAPI_Init()) {
@ -26,7 +26,7 @@ c_SteamAPI_Init()
return 0; return 0;
} }
extern "C" int64 extern "C" int64_t
c_SteamAPI_GetAppID() c_SteamAPI_GetAppID()
{ {
if (!m_Initiated) if (!m_Initiated)

View File

@ -15,7 +15,7 @@ void
c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void), void(*)(int64_t)); c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void), void(*)(int64_t));
bool bool
c_SteamUserStats_RequestCurrentStats(); c_SteamUserStats_RequestCurrentStats(void);
bool bool
c_SteamUserStats_SetAchievement(const char *id); c_SteamUserStats_SetAchievement(const char *id);
@ -33,7 +33,7 @@ void
c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore); c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore);
void void
c_SteamAPI_Shutdown(); c_SteamAPI_Shutdown(void);
#ifdef __cplusplus #ifdef __cplusplus
class CallbackHandler class CallbackHandler
@ -46,4 +46,4 @@ public:
void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure); void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure);
}; };
#endif // __cplusplus #endif // __cplusplus