Skip to content
Merged
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
29 changes: 23 additions & 6 deletions Descent3/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ std::vector<tVideoResolution> Video_res_list = {{512, 384},
int Default_resolution_id = 7; // 1280x720 in the default list
int Current_video_resolution_id = Default_resolution_id;
float Render_FOV_setting = 72.0f;
bool Game_fullscreen = true;
int Display_id = 0;

void ConfigureDisplayResolutions() {
Expand Down Expand Up @@ -424,10 +425,18 @@ void ConfigureDisplayResolutions() {
if (current_res_id != Video_res_list.end()) {
Default_resolution_id = static_cast<int>(current_res_id - Video_res_list.begin());
} else {
Default_resolution_id = 0; // default to the highest supported resolution
Default_resolution_id = Video_res_list.size() - 1; // default to the highest supported resolution
}

Current_video_resolution_id = Default_resolution_id;
int tmp;
if (!Database->read_int("RS_resolution", &tmp)) {
// Only override resolution id if the value was not found in the settings
Current_video_resolution_id = Default_resolution_id;
}

LOG_DEBUG << "Resolution configured to w=" << Video_res_list[Current_video_resolution_id].width
<< "h=" << Video_res_list[Current_video_resolution_id].height << " (id " << Current_video_resolution_id
<< ")";
}

tDetailSettings Detail_settings;
Expand Down Expand Up @@ -758,10 +767,12 @@ struct video_menu {

// settings
bool *filtering = nullptr;
bool *fullscreen = nullptr;
bool *mipmapping = nullptr;
bool *vsync = nullptr;
char *resolution_string = nullptr;
short *fov = nullptr;
bool resolution_changed = false;

int *bitdepth = nullptr; // bitdepths

Expand All @@ -777,6 +788,8 @@ struct video_menu {
snprintf(resolution_string, res.size() + 1, res.c_str());
sheet->AddLongButton("Change", IDV_CHANGE_RES_WINDOW);

fullscreen = sheet->AddLongCheckBox("Fullscreen", Game_fullscreen);

// FOV setting 72deg -> 90deg
tSliderSettings settings = {};
settings.min_val.f = D3_DEFAULT_FOV;
Expand Down Expand Up @@ -834,11 +847,14 @@ struct video_menu {
if (bitdepth)
Render_preferred_bitdepth = (*bitdepth) == 1 ? 32 : 16;
#endif
if (GetScreenMode() == SM_GAME) {
Render_preferred_state.bit_depth = Render_preferred_bitdepth;
rend_SetPreferredState(&Render_preferred_state);

if (*fullscreen != Game_fullscreen || Render_preferred_state.bit_depth != Render_preferred_bitdepth ||
resolution_changed) {
resolution_changed = false;
Game_fullscreen = *fullscreen;
SetScreenMode(GetScreenMode(), true);
Render_preferred_state.bit_depth = Render_preferred_bitdepth;
rend_SetPreferredState(&Render_preferred_state, true);

int temp_w = Video_res_list[Current_video_resolution_id].width;
int temp_h = Video_res_list[Current_video_resolution_id].height;
Expand Down Expand Up @@ -885,7 +901,8 @@ struct video_menu {

if (res == UID_OK) {
int newindex = resolution_list->GetCurrentIndex();
if (static_cast<size_t>(newindex) < Video_res_list.size()) {
if (static_cast<size_t>(newindex) < Video_res_list.size() && Current_video_resolution_id != newindex) {
resolution_changed = true;
Current_video_resolution_id = newindex;
std::string res = Video_res_list[Current_video_resolution_id].getName();
snprintf(resolution_string, res.size() + 1, res.c_str());
Expand Down
2 changes: 2 additions & 0 deletions Descent3/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ extern std::vector<tVideoResolution> Video_res_list;
extern int Default_resolution_id;
extern int Current_video_resolution_id;
extern int Display_id;
extern bool Game_fullscreen;


/**
* List all unique resolutions for the detected displays,
Expand Down
5 changes: 4 additions & 1 deletion Descent3/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ void SetScreenMode(int sm, bool force_res_change) {
Render_preferred_state.width = scr_width;
Render_preferred_state.height = scr_height;
Render_preferred_state.bit_depth = scr_bitdepth;
Render_preferred_state.fullscreen = Game_fullscreen;

rend_initted = rend_Init(PreferredRenderer, Descent, &Render_preferred_state);
rend_width = rend_height = 0;
Expand Down Expand Up @@ -987,10 +988,12 @@ void SetScreenMode(int sm, bool force_res_change) {
scr_height = 480;
}

if (rend_width != scr_width || rend_height != scr_height) {
if (rend_width != scr_width || rend_height != scr_height ||
Game_fullscreen != Render_preferred_state.fullscreen) {
Render_preferred_state.width = scr_width;
Render_preferred_state.height = scr_height;
Render_preferred_state.bit_depth = scr_bitdepth;
Render_preferred_state.fullscreen = Game_fullscreen;

LOG_INFO.printf("Setting rend_width=%d height=%d", scr_width, scr_height);
int retval = rend_SetPreferredState(&Render_preferred_state);
Expand Down
4 changes: 2 additions & 2 deletions Descent3/gamesequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ bool GameSequencer() {
SetFunctionMode(MENU_MODE);
} else {
SetGameState(GAMESTATE_LVLPLAYING);
SetScreenMode(SM_GAME);
SetScreenMode(SM_GAME, true);
SetHUDMode(GetHUDMode());
}
ResumeGame();
Expand Down Expand Up @@ -1513,7 +1513,7 @@ void StartLevel() {
#endif

// Set screen mode
SetScreenMode(SM_GAME);
SetScreenMode(SM_GAME, true);

// Init HUD and cockpit
int ship_index;
Expand Down
18 changes: 13 additions & 5 deletions Descent3/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ void SaveGameSettings() {

Database->write("RS_resolution", Current_video_resolution_id);
Database->write("RS_fov", static_cast<int>(Render_FOV_setting));
Database->write("RS_fullscreen", static_cast<int>(Game_fullscreen));

Database->write("RS_bitdepth", Render_preferred_bitdepth);
Database->write("RS_bilear", Render_preferred_state.filtering);
Expand Down Expand Up @@ -1291,13 +1292,16 @@ void LoadGameSettings() {
Database->read("Specmapping", &Detail_settings.Specular_lighting);
Database->read("RS_bitdepth", &Render_preferred_bitdepth, sizeof(Render_preferred_bitdepth));
Database->read_int("RS_resolution", &Current_video_resolution_id);
int tempfov = 0;
Database->read_int("RS_fov", &tempfov);
tempfov = std::clamp(tempfov, static_cast<int>(D3_DEFAULT_FOV), 90);
Render_FOV_setting = static_cast<float>(tempfov);

int tempval = 0;
Database->read_int("RS_fov", &tempval);
tempval = std::clamp(tempval, static_cast<int>(D3_DEFAULT_FOV), 90);
Render_FOV_setting = static_cast<float>(tempval);
Render_FOV = Render_FOV_setting;

Database->read_int("RS_fullscreen", &tempval);
Game_fullscreen = tempval != 0;

Database->read_int("RS_bilear", &Render_preferred_state.filtering);
Database->read_int("RS_mipping", &Render_preferred_state.mipping);
Database->read_int("RS_color_model", &Render_state.cur_color_model);
Expand Down Expand Up @@ -1575,6 +1579,9 @@ void InitGraphics(bool editor) {
if (!InitTextures())
Error("Failed to initialize texture system.");

// Init fullscreen/windowed mode from CLI arguments
rend_InitWindowMode();

#ifdef EDITOR
char *driver = "GDIX";

Expand Down Expand Up @@ -1719,6 +1726,7 @@ void InitMessage(const char *c, float progress) {
}

EndFrame();
Descent->defer();
rend_Flip();
}

Expand Down
2 changes: 1 addition & 1 deletion Descent3/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ int MainMenu() {
}

// setup screen
SetScreenMode(SM_MENU);
SetScreenMode(SM_MENU, true);
// create interface
main_menu.Create();
main_menu.AddItem(IDV_NEWGAME, KEY_N, TXT_MENUNEWGAME, MM_STARTMENU_TYPE);
Expand Down
9 changes: 1 addition & 8 deletions Descent3/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "dedicated_server.h"
#include "init.h"
#include "log.h"
#include "config.h"

#ifdef WIN32
#include "debug.h"
Expand Down Expand Up @@ -253,14 +254,6 @@ int main(int argc, char *argv[]) {
SDL_SetEventFilter(d3SDLEventFilter, nullptr);
install_signal_handlers();

int winArg = FindArgChar("-windowed", 'w');
int fsArg = FindArgChar("-fullscreen", 'f');

if ((fsArg) && (winArg)) {
LOG_FATAL.printf("ERROR: %s AND %s specified!", GameArgs[winArg], GameArgs[fsArg]);
return (0);
}

// Initialize our OS Object. This could be a game dependant OS object, or a default OS object.
// Once we create it, if successful, we can start the game.
int flags = 0;
Expand Down
12 changes: 4 additions & 8 deletions ddio/lnxkey_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@

#include "ddio.h"
#include "pserror.h"
#include "renderer.h"
#include "config.h"

extern volatile struct tLnxKeys {
union {
Expand Down Expand Up @@ -362,14 +364,8 @@ bool sdlKeyFilter(const SDL_Event *event) {

else if (event->key.mod & SDL_KMOD_ALT) {
if ((kc == KEY_ENTER) || (kc == KEY_PADENTER)) {
extern SDL_Window *GSDLWindow;
Uint32 flags = SDL_GetWindowFlags(GSDLWindow);
if (flags & SDL_WINDOW_FULLSCREEN) {
flags &= ~SDL_WINDOW_FULLSCREEN;
} else {
flags |= SDL_WINDOW_FULLSCREEN;
}
SDL_SetWindowFullscreen(GSDLWindow, flags);
Game_fullscreen = !Game_fullscreen;
rend_SetFullScreen(Game_fullscreen);
return false;
} // if
} // else if
Expand Down
95 changes: 0 additions & 95 deletions lib/lnxscreenmode.h

This file was deleted.

9 changes: 8 additions & 1 deletion lib/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ struct renderer_preferred_state {
uint8_t bit_depth;
int width, height;
uint8_t vsync_on;
bool fullscreen = false;
};

struct renderer_lfb {
Expand Down Expand Up @@ -583,11 +584,17 @@ void rend_DrawSpecialLine(g3Point *p0, g3Point *p1);

// Sets some global preferences for the renderer
// Returns -1 if it had to use the default resolution/bitdepth
int rend_SetPreferredState(renderer_preferred_state *pref_state);
int rend_SetPreferredState(renderer_preferred_state *pref_state, bool reinit = false);

// Sets the gamma value
void rend_SetGammaValue(float val);

// Enable or disable fullscreen
void rend_SetFullScreen(bool fullscreen);

// Init window mode from CLI flags -w/-f
bool rend_InitWindowMode();

// Fills in the passed in pointer with the current rendering state
void rend_GetRenderState(rendering_state *rstate);

Expand Down
1 change: 0 additions & 1 deletion renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(CPPS
HardwarePoints.cpp
HardwareSetup.cpp
HardwareTransforms.cpp
lnxscreenmode.cpp
)

add_library(renderer STATIC ${HEADERS} ${CPPS})
Expand Down
Loading
Loading