Fixes nicer fullscreen rendering
Also solves some compiler warnings on linux
This commit is contained in:
parent
0d1836a8ba
commit
a75a0d9331
|
@ -1,4 +1,6 @@
|
|||
-DDEBUG
|
||||
-I./steamworks_c_api/src/
|
||||
-I./src/steam/
|
||||
-I./build/config.h
|
||||
-I/usr/include/SDL2/
|
||||
-I/usr/include/lua5.2/
|
||||
|
|
59
src/main.c
59
src/main.c
|
@ -254,7 +254,7 @@ static void
|
|||
initViewports(Uint32 offset)
|
||||
{
|
||||
mainViewport = (SDL_Rect) { offset, 0,
|
||||
SCREEN_HEIGHT, SCREEN_WIDTH
|
||||
SCREEN_WIDTH, SCREEN_HEIGHT
|
||||
};
|
||||
|
||||
gameViewport = (SDL_Rect) { offset, 0,
|
||||
|
@ -547,6 +547,31 @@ init(void)
|
|||
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
|
||||
handle_main_input(void)
|
||||
{
|
||||
|
@ -592,23 +617,7 @@ handle_main_input(void)
|
|||
}
|
||||
|
||||
if (input_modkey_is_pressed(&input, KEY_CTRL_F)) {
|
||||
bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
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));
|
||||
}
|
||||
toggle_fullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -643,9 +652,6 @@ handle_events(void)
|
|||
static bool
|
||||
is_player_dead(void)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
gPlayer->stats.hp = gPlayer->stats.hp > 0 ? gPlayer->stats.hp : 1;
|
||||
#endif // DEBUG
|
||||
if (gPlayer->stats.hp <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -731,9 +737,10 @@ run_game_update(void)
|
|||
if (skillActivated && settings->tooltips_enabled && playerLevel < 5) {
|
||||
gGui->activeTooltip = new_skill_tooltip;
|
||||
}
|
||||
if (!artifactTooltipShown && gPlayer->equipment.hasArtifacts && settings->tooltips_enabled) {
|
||||
if (!artifactTooltipShown && gPlayer->equipment.hasArtifacts) {
|
||||
artifactTooltipShown = true;
|
||||
gGui->activeTooltip = new_artifact_tooltip;
|
||||
if (settings->tooltips_enabled)
|
||||
gGui->activeTooltip = new_artifact_tooltip;
|
||||
}
|
||||
|
||||
if (gGameState == PLAYING && currentTurn == PLAYER)
|
||||
|
@ -839,6 +846,7 @@ run_game_render(void)
|
|||
render_game();
|
||||
render_gui();
|
||||
|
||||
SDL_RenderSetViewport(gRenderer, &mainViewport);
|
||||
particle_engine_render_global(gCamera);
|
||||
gui_render_tooltip(gGui, gCamera);
|
||||
|
||||
|
@ -1090,6 +1098,11 @@ int main(int argc, char *argv[])
|
|||
if (!init())
|
||||
return 1;
|
||||
|
||||
if (settings_get()->fullscreen_enabled) {
|
||||
// Game starts in windowed mode so this will
|
||||
// change to fullscreen
|
||||
toggle_fullscreen();
|
||||
}
|
||||
run();
|
||||
close();
|
||||
PHYSFS_deinit();
|
||||
|
|
|
@ -31,6 +31,7 @@ static const char *KEY_MUSIC_ENABLED = "music_enabled";
|
|||
static const char *KEY_SOUND_ENABLED = "sound_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_FULLSCREEN_ENABLED = "fullscreen_enabled";
|
||||
|
||||
static
|
||||
DbQuery MIGRATE_COMMANDS[] = {
|
||||
|
@ -53,6 +54,7 @@ set_default_settings(void)
|
|||
settings.sound_enabled = true;
|
||||
settings.tooltips_enabled = true;
|
||||
settings.howto_tooltip_shown = false;
|
||||
settings.fullscreen_enabled = false;
|
||||
}
|
||||
|
||||
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]);
|
||||
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])) {
|
||||
settings.tooltips_enabled = (bool)atoi(values[i + 1]);
|
||||
i += 2;
|
||||
|
@ -141,6 +147,7 @@ settings_save(void)
|
|||
save_setting_int(KEY_MUSIC_ENABLED, settings.music_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_FULLSCREEN_ENABLED, settings.fullscreen_enabled);
|
||||
}
|
||||
|
||||
Settings *
|
||||
|
|
|
@ -26,6 +26,7 @@ typedef struct Settings {
|
|||
bool sound_enabled;
|
||||
bool tooltips_enabled;
|
||||
bool howto_tooltip_shown;
|
||||
bool fullscreen_enabled;
|
||||
} Settings;
|
||||
|
||||
void
|
||||
|
|
|
@ -19,7 +19,7 @@ static Sint64 m_AppID = 0;
|
|||
static Sint64 m_hLeaderboard = 0;
|
||||
|
||||
static bool
|
||||
steam_request_stats()
|
||||
steam_request_stats(void)
|
||||
{
|
||||
if (m_Initiated)
|
||||
return c_SteamUserStats_RequestCurrentStats();
|
||||
|
|
|
@ -26,6 +26,7 @@ endif ()
|
|||
include_directories(${STEAMWORKS_INCLUDE_DIR})
|
||||
|
||||
add_library(steamworks_c_wrapper
|
||||
SHARED
|
||||
src/steamworks_c_wrapper
|
||||
)
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ static bool m_RecvCB = false;
|
|||
|
||||
static void(*statsReceivedCb)(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()
|
||||
{
|
||||
if (SteamAPI_Init()) {
|
||||
|
@ -26,7 +26,7 @@ c_SteamAPI_Init()
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int64
|
||||
extern "C" int64_t
|
||||
c_SteamAPI_GetAppID()
|
||||
{
|
||||
if (!m_Initiated)
|
||||
|
|
|
@ -15,7 +15,7 @@ void
|
|||
c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void), void(*)(int64_t));
|
||||
|
||||
bool
|
||||
c_SteamUserStats_RequestCurrentStats();
|
||||
c_SteamUserStats_RequestCurrentStats(void);
|
||||
|
||||
bool
|
||||
c_SteamUserStats_SetAchievement(const char *id);
|
||||
|
@ -33,7 +33,7 @@ void
|
|||
c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore);
|
||||
|
||||
void
|
||||
c_SteamAPI_Shutdown();
|
||||
c_SteamAPI_Shutdown(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
class CallbackHandler
|
||||
|
@ -46,4 +46,4 @@ public:
|
|||
|
||||
void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure);
|
||||
};
|
||||
#endif // __cplusplus
|
||||
#endif // __cplusplus
|
||||
|
|
Loading…
Reference in New Issue