diff --git a/basegraph.cpp b/basegraph.cpp index 448926ba..b1a7c32e 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -8,8 +8,6 @@ #include "hyper.h" namespace hr { -EX int fontscale = 100; - #if HDR /** configuration of the current view */ struct display_data { @@ -1035,48 +1033,103 @@ EX void displayColorButton(int x, int y, const string& name, int key, int align, ld textscale() { return vid.fsize / (current_display->radius * cgi.crossf) * (1+pconf.alpha) * 2; } - -EX bool setfsize = true; -EX bool vsync_off; - -EX void do_setfsize() { +EX void compute_fsize() { + println(hlog, "compute_fsize() called"); dual::split_or_do([&] { - vid.fsize = min(vid.yres * fontscale/ 3200, vid.xres * fontscale/ 4800), setfsize = false; + if(vid.relative_font) + vid.fsize = min(vid.yres * vid.fontscale/ 3200, vid.xres * vid.fontscale/ 4800); + else + vid.fsize = vid.abs_fsize; + println(hlog, "set fsize to ", vid.fsize); + if(vid.fsize < 6) vid.fsize = 6; }); } -EX void disable_vsync() { -#if CAP_SDL && CAP_GL && !ISMOBWEB - SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); -#endif +EX bool graphics_on; + +EX bool want_vsync() { + if(vrhr::active()) + return false; + return vid.want_vsync; } + +EX bool need_to_apply_screen_settings() { + if(vid.want_fullscreen != vid.full) + return true; + if(make_pair(vid.xres, vid.yres) != get_requested_resolution()) + return true; + if(vid.want_antialias != vid.antialias) + return true; + if(vid.wantGL != vid.usingGL) + return true; + if(want_vsync() != vid.current_vsync) + return true; + return false; + } + +EX void apply_screen_settings() { + if(!need_to_apply_screen_settings()) return; + if(!graphics_on) return; + +#if ISANDROID + if(vid.full != vid.want_fullscreen) + addMessage(XLAT("Reenter HyperRogue to apply this setting")); +#endif + SDL_QuitSubSystem(SDL_INIT_VIDEO); + graphics_on = false; + android_settings_changed(); + init_graph(); + if(vid.usingGL) { + glhr::be_textured(); glhr::be_nontextured(); + } + } + +EX pair get_requested_resolution() { + if(vid.want_fullscreen && vid.change_fullscr) + return { vid.fullscreen_x, vid.fullscreen_y }; + else if(vid.want_fullscreen) + return { vid.xres = vid.xscr, vid.yres = vid.yscr }; + else if(vid.relative_window_size) + return { vid.xscr * vid.window_rel_x + .5, vid.yscr * vid.window_rel_y + .5 }; + else + return { vid.window_x, vid.window_y }; + } + #if CAP_SDL EX void setvideomode() { DEBBI(DF_INIT | DF_GRAPH, ("setvideomode")); - if(!vid.full) { - if(vid.xres > vid.xscr) vid.xres = vid.xscr * 9/10, setfsize = true; - if(vid.yres > vid.yscr) vid.yres = vid.yscr * 9/10, setfsize = true; - } + vid.full = vid.want_fullscreen; - if(setfsize) do_setfsize(); + tie(vid.xres, vid.yres) = get_requested_resolution(); + + compute_fsize(); int flags = 0; + vid.antialias = vid.want_antialias; + #if CAP_GL + vid.usingGL = vid.wantGL; if(vid.usingGL) { flags = SDL_OPENGL | SDL_HWSURFACE; SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); - if(vsync_off) disable_vsync(); + vid.current_vsync = want_vsync(); + if(vid.current_vsync) + SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 ); + else + SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); if(vid.antialias & AA_MULTI) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (vid.antialias & AA_MULTI16) ? 16 : 4); } } +#else + vid.usingGL = false; #endif int sizeflag = (vid.full ? SDL_FULLSCREEN : SDL_RESIZABLE); @@ -1103,7 +1156,7 @@ EX void setvideomode() { if(vid.full && !s) { vid.xres = vid.xscr; vid.yres = vid.yscr; - do_setfsize(); + vid.fsize = 10; s = s_screen = SDL_SetVideoMode(vid.xres, vid.yres, 32, flags | SDL_FULLSCREEN); } @@ -1138,7 +1191,80 @@ EX void setvideomode() { EX bool noGUI = false; -EX void initgraph() { +#if CAP_SDL +EX bool sdl_on = false; +EX int SDL_Init1(Uint32 flags) { + if(!sdl_on) { + sdl_on = true; + return SDL_Init(flags); + } + else + return SDL_InitSubSystem(flags); + } +#endif + +EX void init_font() { +#if CAP_SDLTTF + if(TTF_Init() != 0) { + printf("Failed to initialize TTF.\n"); + exit(2); + } +#endif + } + +EX void close_font() { +#if CAP_SDLTTF + for(int i=0; i<=max_font_size; i++) if(font[i]) TTF_CloseFont(font[i]); + TTF_Quit(); +#endif +#if CAL_GLFONT + for(int i=0; i<=max_glfont_size; i++) if(glfont[i]) delete glfont[i]; +#endif + } + +EX void init_graph() { +#if CAP_SDL + if (SDL_Init1(SDL_INIT_VIDEO) == -1) + { + printf("Failed to initialize video.\n"); + exit(2); + } + graphics_on = true; + +#if ISWEB + get_canvas_size(); +#else + if(!vid.xscr) { + const SDL_VideoInfo *inf = SDL_GetVideoInfo(); + vid.xscr = vid.xres = inf->current_w; + vid.yscr = vid.yres = inf->current_h; + } +#endif + +#ifdef CUSTOM_CAPTION + SDL_WM_SetCaption(CUSTOM_CAPTION, CUSTOM_CAPTION); +#else + SDL_WM_SetCaption("HyperRogue " VER, "HyperRogue " VER); +#endif +#endif + +#if CAP_SDL + setvideomode(); + if(!s) { + printf("Failed to initialize graphics.\n"); + exit(2); + } + + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableUNICODE(1); +#endif + +#if ISANDROID + vid.full = vid.want_fullscreen; +#endif + } + +EX void initialize_all() { DEBBI(DF_INIT | DF_GRAPH, ("initgraph")); @@ -1157,28 +1283,6 @@ EX void initgraph() { return; } -#if CAP_SDL - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) == -1) - { - printf("Failed to initialize video.\n"); - exit(2); - } - -#if ISWEB - get_canvas_size(); -#else - const SDL_VideoInfo *inf = SDL_GetVideoInfo(); - vid.xscr = vid.xres = inf->current_w; - vid.yscr = vid.yres = inf->current_h; -#endif - -#ifdef CUSTOM_CAPTION - SDL_WM_SetCaption(CUSTOM_CAPTION, CUSTOM_CAPTION); -#else - SDL_WM_SetCaption("HyperRogue " VER, "HyperRogue " VER); -#endif -#endif - preparesort(); #if CAP_CONFIG loadConfig(); @@ -1191,26 +1295,12 @@ EX void initgraph() { #if CAP_COMMANDLINE arg::read(2); #endif + + init_graph(); check_cgi(); cgi.require_basics(); - -#if CAP_SDL - setvideomode(); - if(!s) { - printf("Failed to initialize graphics.\n"); - exit(2); - } - - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - SDL_EnableUNICODE(1); -#endif -#if CAP_SDLTTF - if(TTF_Init() != 0) { - printf("Failed to initialize TTF.\n"); - exit(2); - } -#endif + init_font(); #if CAP_SDLJOY initJoysticks(); @@ -1219,22 +1309,16 @@ EX void initgraph() { #if CAP_SDLAUDIO initAudio(); #endif - } -EX void cleargraph() { +EX void quit_all() { DEBBI(DF_INIT, ("clear graph")); -#if CAP_SDLTTF - for(int i=0; i<256; i++) if(font[i]) TTF_CloseFont(font[i]); -#endif -#if CAL_GLFONT - for(int i=0; i<128; i++) if(glfont[i]) delete glfont[i]; -#endif #if CAP_SDLJOY closeJoysticks(); #endif #if CAP_SDL SDL_Quit(); + sdl_on = false; #endif } diff --git a/config.cpp b/config.cpp index 48566e0f..a9772b09 100644 --- a/config.cpp +++ b/config.cpp @@ -476,11 +476,11 @@ EX videopar vid; #define DEFAULT_WALLMODE (ISMOBILE ? 3 : 5) #define DEFAULT_MONMODE (ISMOBILE ? 2 : 4) -#if ISANDROID -#define ANDROID_SETTINGS settingsChanged = true; -#else -#define ANDROID_SETTINGS ; -#endif +EX void android_settings_changed() { + #if ISANDROID + settingsChanged = true; + #endif + } extern color_t floorcolors[landtypes]; @@ -619,7 +619,19 @@ EX void initConfig() { param_i(vid.msglimit, "message limit", 5); param_i(vid.timeformat, "message log time format", 0); - param_i(fontscale, "fontscale", 100); + + param_b(vid.relative_font, "relative_font", true) + -> editable("set relative font size", 'r') + -> set_reaction(compute_fsize); + param_i(vid.fontscale, "fontscale", 100) + -> editable(25, 400, 10, "font scale", "", 'b') + -> set_reaction(compute_fsize) + -> set_sets([] { dialog::bound_low(0); }); + + param_i(vid.abs_fsize, "fsize", 12) + -> editable(1, 72, 1, "font size", "", 'b') + -> set_reaction(compute_fsize) + -> set_sets([] { dialog::bound_low(0); }); param_i(vid.mobilecompasssize, "mobile compass size", 0); // ISMOBILE || ISPANDORA ? 30 : 0); param_i(vid.radarsize, "radarsize size", 120); @@ -655,8 +667,11 @@ EX void initConfig() { // basic graphics - addsaver(vid.usingGL, "usingGL", true); - addsaver(vid.antialias, "antialias", AA_NOGL | AA_FONT | (ISWEB ? AA_MULTI : AA_LINES) | AA_LINEWIDTH | AA_VERSION); + param_b(vid.wantGL, "usingGL", true) + ->editable("openGL mode", 'o'); + + addsaver(vid.want_antialias, "antialias", AA_NOGL | AA_FONT | (ISWEB ? AA_MULTI : AA_LINES) | AA_VERSION); + addsaver(vid.fineline, "fineline", true); param_f(vid.linewidth, "linewidth", 1); addsaver(precise_width, "precisewidth", .5); addsaver(perfect_linewidth, "perfect_linewidth", 1); @@ -664,7 +679,6 @@ EX void initConfig() { addsaver(fat_edges, "fat-edges"); param_f(vid.sspeed, "sspeed", "scrollingspeed", 0); param_f(vid.mspeed, "mspeed", "movement speed", 1); - addsaver(vid.full, "fullscreen", false); addsaver(vid.aurastr, "aura strength", ISMOBILE ? 0 : 128); addsaver(vid.aurasmoothen, "aura smoothen", 5); param_enum(vid.graphglyph, "graphglyph", "graphical items/kills", 1) @@ -675,9 +689,44 @@ EX void initConfig() { addsaver(vid.particles, "extra effects", 1); param_i(vid.framelimit, "frame limit", 999); - addsaver(vid.xres, "xres"); - addsaver(vid.yres, "yres"); - param_i(vid.fsize, "font size"); + + param_b(vid.want_vsync, "vsync", true) + ->editable("vsync", 'v'); + + param_b(vid.want_fullscreen, "fullscreen", false) + ->editable("fullscreen mode", 'f'); + param_b(vid.change_fullscr, "fullscreen_change", false) + ->editable("use specific fullscreen resolution", 'g'); + param_b(vid.relative_window_size, "window_relative", true) + ->editable("specify relative window size", 'g'); + + param_custom(vid.xres, "xres", [] (char ch) {}, 0); + param_custom(vid.yres, "yres", [] (char ch) {}, 0); + + param_i(vid.fullscreen_x, "fullscreen_x", 1280) + -> editable(640, 3840, 640, "fullscreen resolution to use (X)", "", 'x') + -> set_sets([] { dialog::bound_low(640); }); + + param_i(vid.fullscreen_y, "fullscreen_y", 1024) + -> editable(480, 2160, 480, "fullscreen resolution to use (X)", "", 'x') + -> set_sets([] { dialog::bound_low(480); }); + + param_i(vid.window_x, "window_x", 1280) + -> editable(160, 3840, 160, "window resolution to use (X)", "", 'x') + -> set_sets([] { dialog::bound_low(160); }); + + param_i(vid.window_y, "window_y", 1024) + -> editable(120, 2160, 120, "window resolution to use (Y)", "", 'x') + -> set_sets([] { dialog::bound_low(120); }); + + param_f(vid.window_rel_x, "window_rel_x", .9) + -> editable(.1, 1, .1, "screen size percentage to use (X)", "", 'x') + -> set_sets([] { dialog::bound_low(.1); }); + + param_f(vid.window_rel_y, "window_rel_y", .9) + -> editable(.1, 1, .1, "screen size percentage to use (X)", "", 'x') + -> set_sets([] { dialog::bound_low(.1); }); + param_b(vid.darkhepta, "mark heptagons", false); for(auto& lp: linepatterns::patterns) { @@ -1389,24 +1438,21 @@ EX void show_vector_settings() { vid.usingGL ? "" : XLAT("Line width setting is only taken into account in OpenGL.")); }); - dialog::addSelItem(XLAT("line quality"), its(vid.linequality), 'L'); + dialog::addSelItem(XLAT("line quality"), its(vid.linequality), 'l'); dialog::add_action([] { dialog::editNumber(vid.linequality, -3, 5, 1, 1, XLAT("line quality"), XLAT("Higher numbers make the curved lines smoother, but reduce the performance.")); }); - dialog::addBoolItem("finer lines at the boundary", vid.antialias & AA_LINEWIDTH, 'O'); - dialog::add_action([] () { - vid.antialias ^= AA_LINEWIDTH; - }); - - dialog::addBoolItem("perfect width", perfect_linewidth == 2, 'P'); + dialog::addBoolItem("perfect width", perfect_linewidth == 2, 'p'); if(perfect_linewidth == 1) dialog::lastItem().value = XLAT("shots only"); dialog::add_action([] { perfect_linewidth = (1 + perfect_linewidth) % 3; }); - if(vid.antialias & AA_LINEWIDTH) { - dialog::addSelItem("variable width", fts(precise_width), 'M'); + dialog::addBoolItem_action("finer lines at the boundary", vid.fineline, 'O'); + + if(vid.fineline) { + dialog::addSelItem("variable width", fts(precise_width), 'm'); dialog::add_action([] () { dialog::editNumber(precise_width, 0, 2, 0.1, 0.5, XLAT("variable width"), XLAT("lines longer than this value will be split into shorter lines, with width computed separately for each of them.") @@ -1419,11 +1465,11 @@ EX void show_vector_settings() { dialog::addBreak(100); dialog::addInfo(XLAT("hint: press Alt while testing modes")); dialog::addBreak(100); - dialog::addBoolItem_action(XLAT("disable shadows"), noshadow, 'F'); - dialog::addBoolItem_action(XLAT("bright mode"), bright, 'G'); - dialog::addBoolItem_action(XLAT("colorblind simulation"), cblind, 'H'); + dialog::addBoolItem_action(XLAT("disable shadows"), noshadow, 'f'); + dialog::addBoolItem_action(XLAT("bright mode"), bright, 'g'); + dialog::addBoolItem_action(XLAT("colorblind simulation"), cblind, 'h'); - dialog::addBoolItem_action(XLAT("no fill in neon mode"), neon_nofill, 'N'); + dialog::addBoolItem_action(XLAT("no fill in neon mode"), neon_nofill, 'n'); dialog::addBreak(50); dialog::addBack(); @@ -1436,19 +1482,76 @@ EX void showGraphConfig() { dialog::init(XLAT("graphics configuration")); +#if !ISIOS && !ISWEB + add_edit(vid.want_fullscreen); + + if(vid.want_fullscreen) { + add_edit(vid.change_fullscr); + if(vid.change_fullscr) + add_edit(vid.fullscreen_x), add_edit(vid.fullscreen_y); + else + dialog::addBreak(200); + } + else { + add_edit(vid.relative_window_size); + if(vid.relative_window_size) + add_edit(vid.window_rel_x), add_edit(vid.window_rel_y); + else + add_edit(vid.window_x), add_edit(vid.window_y); + } +#endif + #if CAP_GLORNOT - dialog::addBoolItem(XLAT("openGL mode"), vid.usingGL, 'o'); + add_edit(vid.wantGL); #endif - if(!vid.usingGL) - dialog::addBoolItem(XLAT("anti-aliasing"), vid.antialias & AA_NOGL, 'O'); - - if(vid.usingGL) + if(!vid.usingGL) { + dialog::addBoolItem(XLAT("anti-aliasing"), vid.want_antialias & AA_NOGL, 'O'); + dialog::add_action([] { + if(!vid.usingGL) + vid.want_antialias ^= AA_NOGL | AA_FONT; + }); + } + else { dialog::addSelItem(XLAT("anti-aliasing"), - (vid.antialias & AA_POLY) ? "polygons" : - (vid.antialias & AA_LINES) ? "lines" : - (vid.antialias & AA_MULTI) ? "multisampling" : + (vid.want_antialias & AA_POLY) ? "polygons" : + (vid.want_antialias & AA_LINES) ? "lines" : + (vid.want_antialias & AA_MULTI) ? "multisampling" : "NO", 'O'); + dialog::add_action([] { + if(vid.want_antialias & AA_MULTI) + vid.want_antialias ^= AA_MULTI; + else if(vid.want_antialias & AA_POLY) + vid.want_antialias ^= AA_POLY | AA_LINES | AA_MULTI; + else if(vid.want_antialias & AA_LINES) + vid.want_antialias |= AA_POLY; + else + vid.want_antialias |= AA_LINES; + }); + } + + if(vid.usingGL) { + if(vrhr::active()) + dialog::addInfo(XLAT("(vsync disabled in VR)")); + else + add_edit(vid.want_vsync); + } + else + dialog::addBreak(100); + + if(need_to_apply_screen_settings()) { + dialog::addItem(XLAT("apply changes"), 'A'); + dialog::add_action(apply_screen_settings); + dialog::addBreak(100); + } + else + dialog::addBreak(200); + + add_edit(vid.relative_font); + if(vid.relative_font) + add_edit(vid.fontscale); + else + add_edit(vid.abs_fsize); dialog::addSelItem(XLAT("vector settings"), XLAT("width") + " " + fts(vid.linewidth), 'w'); dialog::add_action_push(show_vector_settings); @@ -1458,11 +1561,7 @@ EX void showGraphConfig() { if(getcstat == 'l') mouseovers = XLAT("Reduce the framerate limit to conserve CPU energy"); #endif - -#if !ISIOS && !ISWEB - dialog::addBoolItem(XLAT("fullscreen mode"), (vid.full), 'f'); -#endif - + dialog::addSelItem(XLAT("scrolling speed"), fts(vid.sspeed), 'a'); dialog::addSelItem(XLAT("camera movement speed"), fts(camera_speed), 'c'); @@ -1489,8 +1588,6 @@ EX void showGraphConfig() { keyhandler = [] (int sym, int uni) { dialog::handleNavigation(sym, uni); - if(uni == 'O') uni = 'o', shiftmul = -1; - char xuni = uni | 96; if((uni >= 32 && uni < 64) || uni == 'L' || uni == 'C') xuni = uni; @@ -1507,30 +1604,6 @@ EX void showGraphConfig() { XLAT("movement animation speed"), XLAT("+5 = move instantly")); - else if(xuni == 'f') switchFullscreen(); - - #if CAP_GLORNOT - else if(xuni == 'o' && shiftmul > 0) switchGL(); - #endif - - else if(xuni == 'o' && shiftmul < 0) { - if(!vid.usingGL) - vid.antialias ^= AA_NOGL | AA_FONT; - else if(vid.antialias & AA_MULTI) - vid.antialias ^= AA_MULTI; - else if(vid.antialias & AA_POLY) - vid.antialias ^= AA_POLY | AA_LINES | AA_MULTI; - else if(vid.antialias & AA_LINES) - vid.antialias |= AA_POLY; - else - vid.antialias |= AA_LINES; -#if CAP_SDL - setvideomode(); -#endif - } - - // if(xuni == 'b') vid.antialias ^= AA_LINEWIDTH; - #if CAP_FRAMELIMIT else if(xuni == 'l') { dialog::editNumber(vid.framelimit, 5, 300, 10, 300, XLAT("framerate limit"), ""); @@ -1545,36 +1618,6 @@ EX void showGraphConfig() { }; } -EX void switchFullscreen() { - vid.full = !vid.full; -#if ISANDROID - addMessage(XLAT("Reenter HyperRogue to apply this setting")); - ANDROID_SETTINGS -#endif -#if CAP_SDL - if(true) { - vid.xres = vid.full ? vid.xscr : 9999; - vid.yres = vid.full ? vid.yscr : 9999; - extern bool setfsize; - setfsize = true; - } - setvideomode(); -#endif - } - -EX void switchGL() { - vid.usingGL = !vid.usingGL; - if(vid.usingGL) addMessage(XLAT("openGL mode enabled")); - if(!vid.usingGL) addMessage(XLAT("openGL mode disabled")); - ANDROID_SETTINGS; -#if CAP_SDL - setvideomode(); - if(vid.usingGL) { - glhr::be_textured(); glhr::be_nontextured(); - } -#endif - } - EX void edit_whatever(char type, int index) { if(type == 'f') { dialog::editNumber(whatever[index], -10, 10, 1, 0, XLAT("whatever"), @@ -1660,14 +1703,6 @@ EX void configureInterface() { add_edit(vid.msgleft); - dialog::addSelItem(XLAT("font scale"), its(fontscale), 'b'); - dialog::add_action([] { - dialog::editNumber(fontscale, 25, 400, 10, 100, XLAT("font scale"), ""); - const int minfontscale = ISMOBILE ? 50 : 25; - dialog::reaction = [] () { setfsize = true; do_setfsize(); }; - dialog::bound_low(minfontscale); - }); - add_edit(glyphsortorder); add_edit(vid.graphglyph); @@ -2576,12 +2611,12 @@ EX void selectLanguageScreen() { if(uni == '0') { vid.language = -1; - ANDROID_SETTINGS; + android_settings_changed(); } else if(uni >= 'a' && uni < 'a'+NUMLAN) { vid.language = uni - 'a'; - ANDROID_SETTINGS; + android_settings_changed(); } else if(doexiton(sym, uni)) @@ -2846,7 +2881,7 @@ EX int read_config_args() { if(argis("-c")) { PHASE(1); shift(); conffile = argcs(); } // change the configuration from the command line - else if(argis("-aa")) { PHASEFROM(2); shift(); vid.antialias = argi(); } + else if(argis("-aa")) { PHASEFROM(2); shift(); vid.want_antialias = argi(); apply_screen_settings(); } else if(argis("-lw")) { PHASEFROM(2); shift_arg_formula(vid.linewidth); } else if(argis("-wm")) { PHASEFROM(2); shift(); vid.wallmode = argi(); } else if(argis("-mm")) { PHASEFROM(2); shift(); vid.monmode = argi(); } @@ -2858,10 +2893,8 @@ EX int read_config_args() { // non-configurable options else if(argis("-vsync_off")) { - #if CAP_SDL && CAP_GL - vsync_off = true; - if(curphase == 3) setvideomode(); - #endif + vid.want_vsync = false; + apply_screen_settings(); } else if(argis("-aura")) { PHASEFROM(2); @@ -2923,7 +2956,7 @@ EX int read_config_args() { sscanf(argcs(), "%dx%dx%d", &clWidth, &clHeight, &clFont); if(clWidth) vid.xres = clWidth; if(clHeight) vid.yres = clHeight; - if(clFont) vid.fsize = clFont; + if(clFont) vid.abs_fsize = clFont, vid.relative_font = true; } else if(argis("-msm")) { PHASEFROM(2); memory_saving_mode = true; @@ -2969,8 +3002,8 @@ EX int read_config_args() { else if(argis("-msens")) { PHASEFROM(2); shift_arg_formula(mouseaim_sensitivity); } - TOGGLE('o', vid.usingGL, switchGL()) - TOGGLE('f', vid.full, switchFullscreen()) + TOGGLE('o', vid.usingGL, apply_screen_settings()) + TOGGLE('f', vid.want_fullscreen, apply_screen_settings()) else if(argis("-noshaders")) { PHASE(1); glhr::noshaders = true; diff --git a/control.cpp b/control.cpp index 8f0e10ce..3a801a75 100644 --- a/control.cpp +++ b/control.cpp @@ -212,6 +212,14 @@ EX SDL_Joystick* sticks[8]; EX int numsticks; EX void initJoysticks() { + + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + { + printf("Failed to initialize joysticks.\n"); + numsticks = 0; + return; + } + DEBB(DF_INIT, ("init joysticks")); numsticks = SDL_NumJoysticks(); if(numsticks > 8) numsticks = 8; @@ -652,12 +660,17 @@ int cframelimit = 1000; EX void resize_screen_to(int x, int y) { dual::split_or_do([&] { - vid.xres = x; - vid.yres = y; vid.killreduction = 0; + if(vid.want_fullscreen) return; + if(vid.relative_window_size) { + vid.window_rel_x = x * 1. / vid.xscr; + vid.window_rel_y = y * 1. / vid.yscr; + } + else { + vid.window_x = x; + vid.window_y = y; + } }); - extern bool setfsize; - setfsize = true; setvideomode(); } @@ -963,7 +976,8 @@ EX void handle_event(SDL_Event& ev) { numlock_on = ev.key.keysym.mod & KMOD_NUM; if(sym == SDLK_RETURN && (ev.key.keysym.mod & (KMOD_LALT | KMOD_RALT))) { sym = 0; uni = 0; - switchFullscreen(); + vid.want_fullscreen = !vid.want_fullscreen; + apply_screen_settings(); } } diff --git a/drawing.cpp b/drawing.cpp index 6f0399b5..7e9d0282 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -790,7 +790,7 @@ EX ld scale_at(const shiftmatrix& T) { EX int perfect_linewidth = 1; EX ld linewidthat(const shiftpoint& h) { - if(!(vid.antialias & AA_LINEWIDTH)) return 1; + if(!vid.fineline) return 1; else if(hyperbolic && pmodel == mdDisk && pconf.alpha == 1 && !ISWEB && !flat_on) { double dz = h[LDIM]; if(dz < 1) return 1; diff --git a/history.cpp b/history.cpp index 0d863b91..eda40bf3 100644 --- a/history.cpp +++ b/history.cpp @@ -89,8 +89,9 @@ namespace spiral { velx=1; vely=1; bool dosave = false; - bool saveGL = vid.usingGL; - if(saveGL) switchGL(); // { vid.usingGL = false; setvideomode(); } + bool saveGL = vid.wantGL; + vid.wantGL = false; + apply_screen_settings(); while(true) { @@ -138,7 +139,8 @@ namespace spiral { breakloop: quickmap.clear(); - if(saveGL) switchGL(); // { vid.usingGL = true; setvideomode(); } + vid.wantGL = saveGL; + apply_screen_settings(); } } diff --git a/hyper.h b/hyper.h index 84735bac..3d609f49 100644 --- a/hyper.h +++ b/hyper.h @@ -300,7 +300,12 @@ struct videopar { int linequality; + bool want_fullscreen; bool full; + bool change_fullscr; + bool relative_window_size; + bool want_vsync; + bool current_vsync; int graphglyph; // graphical glyphs bool darkhepta; @@ -310,10 +315,15 @@ struct videopar { int xscr, yscr; + int fullscreen_x, fullscreen_y; + int window_x, window_y; + ld window_rel_x, window_rel_y; + bool grid; bool particles; - int fsize; + bool relative_font; + int fsize, abs_fsize, fontscale; int flashtime; int wallmode, monmode, axes, highlightmode; @@ -322,13 +332,16 @@ struct videopar { int msgleft, msglimit; + bool wantGL; + int want_antialias; + bool fineline; + bool usingGL; int antialias; #define AA_NOGL 1 #define AA_VERSION 2 #define AA_LINES 4 #define AA_POLY 8 - #define AA_LINEWIDTH 16 #define AA_FONT 32 #define AA_MULTI 64 #define AA_MULTI16 128 // not configurable diff --git a/legacy.cpp b/legacy.cpp index b9f1f005..c65624ff 100644 --- a/legacy.cpp +++ b/legacy.cpp @@ -51,10 +51,10 @@ void loadOldConfig(FILE *f) { if(err == 4) { vid.scale = a; pconf.alpha = c; vid.sspeed = d; } - err=fscanf(f, "%d%d%d%d%d%d%d", &vid.wallmode, &vid.monmode, &vid.axes, &musicvolume, &vid.framelimit, &gl, &vid.antialias); + err=fscanf(f, "%d%d%d%d%d%d%d", &vid.wallmode, &vid.monmode, &vid.axes, &musicvolume, &vid.framelimit, &gl, &vid.want_antialias); vid.usingGL = gl; - if(vid.antialias == 0) vid.antialias = AA_VERSION | AA_LINES | AA_LINEWIDTH; - if(vid.antialias == 1) vid.antialias = AA_NOGL | AA_VERSION | AA_LINES | AA_LINEWIDTH | AA_FONT; + if(vid.want_antialias == 0) vid.want_antialias = AA_VERSION | AA_LINES | AA_LINEWIDTH; + if(vid.want_antialias == 1) vid.want_antialias = AA_NOGL | AA_VERSION | AA_LINES | AA_LINEWIDTH | AA_FONT; double jps = vid.joypanspeed; err=fscanf(f, "%d%d%d%lf%d%d", &vid.joyvalue, &vid.joyvalue2, &vid.joypanthreshold, &jps, &aa, &vid.flashtime); vid.joypanspeed = jps; diff --git a/system.cpp b/system.cpp index 942cc744..02e444d5 100644 --- a/system.cpp +++ b/system.cpp @@ -1575,7 +1575,7 @@ EX void initAll() { firstland0 = firstland; // initlanguage(); - initgraph(); + initialize_all(); #if CAP_SAVE loadsave(); if(IRREGULAR) irr::auto_creator(); @@ -1603,7 +1603,7 @@ EX void finishAll() { #endif clearMemory(); #if !ISMOBILE - cleargraph(); + quit_all(); #endif achievement_close(); diff --git a/vr.cpp b/vr.cpp index 15258e66..3de44faf 100644 --- a/vr.cpp +++ b/vr.cpp @@ -755,6 +755,8 @@ EX void start_vr() { return; } else println(hlog, "VR initialized successfully"); + + apply_screen_settings(); string driver = GetTrackedDeviceString( vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_TrackingSystemName_String ); string display = GetTrackedDeviceString( vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_SerialNumber_String );