From d935febf090a667b03fd2d9481ed262bfcf63300 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 17 Nov 2018 19:24:02 +0100 Subject: [PATCH] refactored some global and stereo:: variables into display_data structure --- basegraph.cpp | 104 +++++++++++++++++++++++-------------- config.cpp | 48 ++++++++--------- conformal.cpp | 18 +++---- control.cpp | 35 ++++++------- debug.cpp | 2 +- dialogs.cpp | 10 ++-- graph.cpp | 96 +++++++++++++++++----------------- hud.cpp | 8 +-- hyper.h | 83 ++++++++++++++++++----------- hypgraph.cpp | 69 ++++++++++++------------- init.cpp | 8 +-- inventory.cpp | 4 +- mapeditor.cpp | 8 +-- menus.cpp | 57 +++++++++++--------- polygons.cpp | 106 +++++++++++++++++++------------------- quit.cpp | 4 +- rogueviz-banachtarski.cpp | 4 +- rogueviz-graph.cpp | 4 +- rogueviz-pentagonal.cpp | 10 ++-- rogueviz-staircase.cpp | 6 +-- rogueviz-video.cpp | 10 ++-- rogueviz.cpp | 18 ++++--- rug.cpp | 60 ++++++++++----------- screenshot.cpp | 12 ++--- shmup.cpp | 8 +-- system.cpp | 12 ++--- textures.cpp | 28 +++++----- util.cpp | 2 +- 28 files changed, 445 insertions(+), 389 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index e3fb935a..6ee0b4e7 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -3,6 +3,9 @@ namespace hr { +display_data default_display; +display_data *current_display = &default_display; + unsigned backcolor = 0; unsigned bordcolor = 0; unsigned forecolor = 0xFFFFFF; @@ -27,15 +30,15 @@ namespace stereo { GLfloat scrdist, scrdist_text; } -bool stereo::in_anaglyph() { return stereo::mode == stereo::sAnaglyph; } -bool stereo::active() { return stereo::mode != sOFF; } +bool display_data::in_anaglyph() { return vid.stereo_mode == sAnaglyph; } +bool display_data::stereo_active() { return vid.stereo_mode != sOFF; } -ld stereo::eyewidth() { - switch(stereo::mode) { - case stereo::sAnaglyph: - return stereo::anaglyph_eyewidth; - case stereo::sLR: - return stereo::lr_eyewidth; +ld display_data::eyewidth() { + switch(vid.stereo_mode) { + case sAnaglyph: + return vid.anaglyph_eyewidth; + case sLR: + return vid.lr_eyewidth; default: return 0; } @@ -176,24 +179,31 @@ void setcameraangle(bool b) { bool shaderside_projection; +int subscreen; + void start_projection(int ed, bool perspective) { glhr::new_projection(); shaderside_projection = perspective; - if(ed && stereo::mode == stereo::sLR) { + auto cd = current_display; + + if(subscreen) + glhr::projection_multiply(glhr::scale(1/(cd->xmax-cd->ymin), 1/(cd->ymax-cd->ymin), 1)); + + if(ed && vid.stereo_mode == sLR) { glhr::projection_multiply(glhr::translate(ed, 0, 0)); glhr::projection_multiply(glhr::scale(2, 1, 1)); } - glhr::projection_multiply(glhr::translate((vid.xcenter*2.)/vid.xres - 1, 1 - (vid.ycenter*2.)/vid.yres, 0)); + glhr::projection_multiply(glhr::translate((current_display->xcenter*2.)/vid.xres - 1, 1 - (current_display->ycenter*2.)/vid.yres, 0)); } void eyewidth_translate(int ed) { - if(ed) glhr::projection_multiply(glhr::translate(-ed * stereo::eyewidth(), 0, 0)); + if(ed) glhr::projection_multiply(glhr::translate(-ed * current_display->eyewidth(), 0, 0)); } -void stereo::set_projection(int ed, bool apply_models) { - DEBB(DF_GRAPH, (debugfile,"stereo::set_projection\n")); +void display_data::set_projection(int ed, bool apply_models) { + DEBB(DF_GRAPH, (debugfile,"current_display->set_projection\n")); shaderside_projection = false; glhr::new_shader_projection = glhr::shader_projection::standard; @@ -205,7 +215,7 @@ void stereo::set_projection(int ed, bool apply_models) { start_projection(ed, shaderside_projection); if(!shaderside_projection) { - glhr::projection_multiply(glhr::ortho(vid.xres/2, -vid.yres/2, abs(stereo::scrdist) + 30000)); + glhr::projection_multiply(glhr::ortho(vid.xres/2, -vid.yres/2, abs(current_display->scrdist) + 30000)); if(ed) { glhr::glmatrix m = glhr::id; m[2][0] -= ed; @@ -228,20 +238,28 @@ void stereo::set_projection(int ed, bool apply_models) { glhr::projection_multiply(glhr::frustum(vid.xres * 1. / vid.yres, 1)); - GLfloat sc = vid.radius / (vid.yres/2.); + GLfloat sc = current_display->radius / (vid.yres/2.); glhr::projection_multiply(glhr::scale(sc, -sc, -1)); - if(ed) glhr::projection_multiply(glhr::translate(stereo::ipd * ed/2, 0, 0)); + if(ed) glhr::projection_multiply(glhr::translate(vid.ipd * ed/2, 0, 0)); - stereo::scrdist_text = vid.yres * sc / 2; + current_display->scrdist_text = vid.yres * sc / 2; + + if(glhr::new_shader_projection == glhr::shader_projection::band) { + glhr::projection_multiply(glhr::scale(2 / M_PI, 2 / M_PI,1)); + glhr::glmatrix s = glhr::id; + for(int a=0; a<2; a++) + conformal::apply_orientation(s[a][1], s[a][0]); + glhr::projection_multiply(s); + } } cameraangle_on = false; } -void stereo::set_mask(int ed) { - if(ed == 0 || stereo::mode != stereo::sAnaglyph) { +void display_data::set_mask(int ed) { + if(ed == 0 || vid.stereo_mode != sAnaglyph) { glColorMask( GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE ); } else if(ed == 1) { @@ -252,14 +270,20 @@ void stereo::set_mask(int ed) { } } -void stereo::set_viewport(int ed) { - if(ed == 0 || stereo::mode != stereo::sLR) - glViewport(0, 0, vid.xres, vid.yres); - else if(ed == 1) - glViewport(0, 0, vid.xres/2, vid.yres); - else if(ed == -1) - glViewport(vid.xres/2, 0, vid.xres/2, vid.yres); - } +void display_data::set_viewport(int ed) { + ld xmin = vid.xres * current_display->xmin; + ld xmax = vid.xres * current_display->xmax; + ld ymin = vid.yres * current_display->ymin; + ld ymax = vid.yres * current_display->ymax; + + ld xsize = xmax - xmin, ysize = ymax - ymin; + + if(ed == 0 || vid.stereo_mode != sLR) ; + else if(ed == 1) xsize /= 2; + else if(ed == -1) xsize /= 2, xmin += xsize; + + glViewport(xmin, ymin, xsize, ysize); + } bool model_needs_depth() { return pmodel == mdBall; @@ -315,7 +339,7 @@ void setGLProjection(color_t col) { GLERR("setGLProjection"); - stereo::set_projection(0, true); + current_display->set_projection(0, true); GLERR("after set_projection"); } @@ -822,7 +846,7 @@ color_t colormix(color_t a, color_t b, color_t c) { int rhypot(int a, int b) { return (int) sqrt(a*a - b*b); } ld realradius() { - ld vradius = vid.radius; + ld vradius = current_display->radius; if(sphere) { if(sphereflipped()) vradius /= sqrt(vid.alpha*vid.alpha - 1); @@ -830,7 +854,7 @@ ld realradius() { vradius = 1e12; // use the following } if(euclid) - vradius = vid.radius * get_sightrange() / (1 + vid.alpha) / 2.5; + vradius = current_display->radius * get_sightrange() / (1 + vid.alpha) / 2.5; vradius = min(vradius, min(vid.xres, vid.yres) / 2); return vradius; } @@ -838,14 +862,14 @@ ld realradius() { void drawmessage(const string& s, int& y, color_t col) { int rrad = (int) realradius(); int space; - if(y > vid.ycenter + rrad * vid.stretch) + if(y > current_display->ycenter + rrad * vid.stretch) space = vid.xres; - else if(y > vid.ycenter) - space = vid.xcenter - rhypot(rrad, (y-vid.ycenter) / vid.stretch); - else if(y > vid.ycenter - vid.fsize) - space = vid.xcenter - rrad; - else if(y > vid.ycenter - vid.fsize - rrad * vid.stretch) - space = vid.xcenter - rhypot(rrad, (vid.ycenter-vid.fsize-y) / vid.stretch); + else if(y > current_display->ycenter) + space = current_display->xcenter - rhypot(rrad, (y-current_display->ycenter) / vid.stretch); + else if(y > current_display->ycenter - vid.fsize) + space = current_display->xcenter - rrad; + else if(y > current_display->ycenter - vid.fsize - rrad * vid.stretch) + space = current_display->xcenter - rhypot(rrad, (current_display->ycenter-vid.fsize-y) / vid.stretch); else space = vid.xres; @@ -923,13 +947,13 @@ void drawCircle(int x, int y, int size, color_t color, color_t fillcolor) { glhr::be_nontextured(); glhr::id_modelview(); glcoords.clear(); - x -= vid.xcenter; y -= vid.ycenter; + x -= current_display->xcenter; y -= current_display->ycenter; int pts = size * 4; if(pts > 1500) pts = 1500; if(ISMOBILE && pts > 72) pts = 72; for(int r=0; r(x + size * sin(rr), y + size * vid.stretch * cos(rr), stereo::scrdist)); + glcoords.push_back(make_array(x + size * sin(rr), y + size * vid.stretch * cos(rr), current_display->scrdist)); } glhr::vertices(glcoords); glhr::set_depthtest(false); @@ -997,7 +1021,7 @@ void displayColorButton(int x, int y, const string& name, int key, int align, in } ld textscale() { - return vid.fsize / (vid.radius * crossf) * (1+vid.alpha) * 2; + return vid.fsize / (current_display->radius * crossf) * (1+vid.alpha) * 2; } // bool notgl = false; diff --git a/config.cpp b/config.cpp index 4e2037b1..b66a08d0 100644 --- a/config.cpp +++ b/config.cpp @@ -278,11 +278,11 @@ void initConfig() { addsaver(viewdists, "expansion mode"); addsaver(backbrightness, "brightness behind sphere"); - addsaver(stereo::ipd, "interpupilar-distance", 0.05); - addsaver(stereo::lr_eyewidth, "eyewidth-lr", 0.5); - addsaver(stereo::anaglyph_eyewidth, "eyewidth-anaglyph", 0.1); - addsaver(stereo::fov, "field-of-vision", 90); - addsaverenum(stereo::mode, "stereo-mode"); + addsaver(vid.ipd, "interpupilar-distance", 0.05); + addsaver(vid.lr_eyewidth, "eyewidth-lr", 0.5); + addsaver(vid.anaglyph_eyewidth, "eyewidth-anaglyph", 0.1); + addsaver(vid.fov, "field-of-vision", 90); + addsaverenum(vid.stereo_mode, "stereo-mode"); addsaver(vid.euclid_to_sphere, "euclid to sphere projection", 1.5); addsaver(vid.twopoint_param, "twopoint parameter", 1); addsaver(vid.stretch, "stretch", 1); @@ -1181,22 +1181,22 @@ void showStereo() { string modenames[4] = { "OFF", "anaglyph", "side-by-side", "ODS" }; - dialog::addSelItem(XLAT("stereo mode"), XLAT(modenames[stereo::mode]), 'm'); - dialog::addSelItem(XLAT("pupillary distance"), fts3(stereo::ipd), 'e'); + dialog::addSelItem(XLAT("stereo mode"), XLAT(modenames[vid.stereo_mode]), 'm'); + dialog::addSelItem(XLAT("pupillary distance"), fts3(vid.ipd), 'e'); - switch(stereo::mode) { - case stereo::sAnaglyph: - dialog::addSelItem(XLAT("distance between images"), fts(stereo::anaglyph_eyewidth), 'd'); + switch(vid.stereo_mode) { + case sAnaglyph: + dialog::addSelItem(XLAT("distance between images"), fts(vid.anaglyph_eyewidth), 'd'); break; - case stereo::sLR: - dialog::addSelItem(XLAT("distance between images"), fts(stereo::lr_eyewidth), 'd'); + case sLR: + dialog::addSelItem(XLAT("distance between images"), fts(vid.lr_eyewidth), 'd'); break; default: dialog::addBreak(100); break; } - dialog::addSelItem(XLAT("field of view"), fts(stereo::fov) + "°", 'f'); + dialog::addSelItem(XLAT("field of view"), fts(vid.fov) + "°", 'f'); dialog::addBack(); dialog::display(); @@ -1216,26 +1216,26 @@ void showStereo() { ) + "\n\n"; if(uni == 'm') - { stereo::mode = stereo::eStereo((1 + stereo::mode) % (CAP_ODS ? 4 : 3)); return; } + { vid.stereo_mode = eStereo((1 + vid.stereo_mode) % (CAP_ODS ? 4 : 3)); return; } else if(uni == 'e') - dialog::editNumber(stereo::ipd, -10, 10, 0.01, 0, XLAT("pupillary distance"), + dialog::editNumber(vid.ipd, -10, 10, 0.01, 0, XLAT("pupillary distance"), help3 + XLAT("The distance between your eyes in the represented 3D object. This is given in absolute units.") ); - else if(uni == 'd' && stereo::mode == stereo::sAnaglyph) - dialog::editNumber(stereo::anaglyph_eyewidth, -1, 1, 0.01, 0, XLAT("distance between images"), + else if(uni == 'd' && vid.stereo_mode == sAnaglyph) + dialog::editNumber(vid.anaglyph_eyewidth, -1, 1, 0.01, 0, XLAT("distance between images"), help3 + XLAT("The distance between your eyes. 1 is the width of the screen.")); - else if(uni == 'd' && stereo::mode == stereo::sLR) - dialog::editNumber(stereo::lr_eyewidth, -1, 1, 0.01, 0, XLAT("distance between images"), + else if(uni == 'd' && vid.stereo_mode == sLR) + dialog::editNumber(vid.lr_eyewidth, -1, 1, 0.01, 0, XLAT("distance between images"), help3 + XLAT("The distance between your eyes. 1 is the width of the screen.")); else if(uni == 'f') - dialog::editNumber(stereo::fov, 1, 170, 1, 45, "field of view", + dialog::editNumber(vid.fov, 1, 170, 1, 45, "field of view", help3 + XLAT( "Horizontal field of view, in angles. " "This affects the Hypersian Rug mode (even when stereo is OFF) " @@ -1823,10 +1823,10 @@ unordered_map params = { {"mtrans", conformal::model_transition}, {"hp", conformal::halfplane_scale}, {"back", backbrightness}, - {"ipd", stereo::ipd}, - {"lr", stereo::lr_eyewidth}, - {"anaglyph", stereo::anaglyph_eyewidth}, - {"fov", stereo::fov}, + {"ipd", vid.ipd}, + {"lr", vid.lr_eyewidth}, + {"anaglyph", vid.anaglyph_eyewidth}, + {"fov", vid.fov}, {"ets", vid.euclid_to_sphere}, {"stretch", vid.stretch}, {"twopoint", vid.twopoint_param}, diff --git a/conformal.cpp b/conformal.cpp index 823bcf33..56805637 100644 --- a/conformal.cpp +++ b/conformal.cpp @@ -471,9 +471,9 @@ namespace conformal { renderbuffer glbuf(bandfull, bandfull, vid.usingGL); vid.xres = vid.yres = bandfull; - glbuf.enable(); vid.radius = bandhalf; + glbuf.enable(); current_display->radius = bandhalf; calcparam(); - stereo::set_viewport(0); + current_display->set_viewport(0); ld xpos = 0; @@ -505,7 +505,7 @@ namespace conformal { progress(s0 + buf + " ("+its(j+bonus)+"/"+its(siz+bonus+bonus-1)+")"); */ - // calcparam(); vid.radius = bandhalf; + // calcparam(); current_display->radius = bandhalf; phase = j; movetophase(); glbuf.clear(backcolor); @@ -515,7 +515,7 @@ namespace conformal { hyperpoint last = ggmatrix(last_base) * last_relative; hyperpoint hscr; applymodel(last, hscr); - ld bwidth = -vid.radius * hscr[0]; + ld bwidth = -current_display->radius * hscr[0]; printf("bwidth = %lf/%lf\n", bwidth, len); drawsegment: @@ -563,7 +563,7 @@ namespace conformal { } rbuf.reset(); - stereo::set_viewport(0); + current_display->set_viewport(0); if(includeHistory) restoreBack(); @@ -641,11 +641,11 @@ namespace conformal { initquickqueue(); queuereset(mdUnchanged, PPR::LINE); for(int a=-1; a<=1; a++) { - curvepoint(hpxyz(-M_PI/2 * vid.radius, a*vid.radius, 0)); - curvepoint(hpxyz(+M_PI/2 * vid.radius, a*vid.radius, 0)); + curvepoint(hpxyz(-M_PI/2 * current_display->radius, a*current_display->radius, 0)); + curvepoint(hpxyz(+M_PI/2 * current_display->radius, a*current_display->radius, 0)); queuecurve(forecolor, 0, PPR::LINE); - curvepoint(hpxyz(a*vid.radius, -M_PI/2*vid.radius, 0)); - curvepoint(hpxyz(a*vid.radius, +M_PI/2*vid.radius, 0)); + curvepoint(hpxyz(a*current_display->radius, -M_PI/2*current_display->radius, 0)); + curvepoint(hpxyz(a*current_display->radius, +M_PI/2*current_display->radius, 0)); queuecurve(forecolor, 0, PPR::LINE); } queuereset(pmodel, PPR::LINE); diff --git a/control.cpp b/control.cpp index d2d4812f..c2d8af44 100644 --- a/control.cpp +++ b/control.cpp @@ -38,7 +38,6 @@ movedir mousedest; ld shiftmul = 1; cell *mouseover, *mouseover2, *lmouseover; -cellwalker centerover; ld modist, modist2, centdist; int lastt; @@ -278,8 +277,8 @@ void handlePanning(int sym, int uni) { if(isGravityLand(cwt.at->land)) playermoved = false; if(sym == PSEUDOKEY_WHEELUP) { - ld jx = (mousex - vid.xcenter - .0) / vid.radius / 10; - ld jy = (mousey - vid.ycenter - .0) / vid.radius / 10; + ld jx = (mousex - current_display->xcenter - .0) / current_display->radius / 10; + ld jy = (mousey - current_display->ycenter - .0) / current_display->radius / 10; playermoved = false; View = gpushxto0(hpxy(jx, jy)) * View; sym = 1; @@ -392,7 +391,7 @@ void handleKeyNormal(int sym, int uni) { else quitmainloop = true; } - if(uni == 'o' && DEFAULTNOR(sym)) setAppropriateOverview(); + if(uni == 'o' && DEFAULTNOR(sym)) get_o_key().second(); #if CAP_INV if(uni == 'i' && DEFAULTNOR(sym) && inv::on) pushScreen(inv::show); @@ -766,8 +765,8 @@ void handle_event(SDL_Event& ev) { if((rightclick || (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_MMASK)) && !mouseout2()) { fix_mouseh(); if(anyctrl) { - vid.xposition += (mousex - lmousex) * 1. / vid.scrsize, - vid.yposition += (mousey - lmousey) * 1. / vid.scrsize; + vid.xposition += (mousex - lmousex) * 1. / current_display->scrsize, + vid.yposition += (mousey - lmousey) * 1. / current_display->scrsize; } else if(mouseh[2] < 50 && mouseoh[2] < 50) { panning(mouseoh, mouseh); @@ -777,8 +776,8 @@ void handle_event(SDL_Event& ev) { #ifdef SIMULATE_JOYSTICK // pretend that both joysticks are present stick = panstick = (SDL_Joystick*) (&vid); - panjoyx = 20 * (mousex - vid.xcenter); - panjoyy = 20 * (mousey - vid.ycenter); + panjoyx = 20 * (mousex - current_display->xcenter); + panjoyy = 20 * (mousey - current_display->ycenter); checkjoy(); #endif @@ -831,18 +830,18 @@ void displayabutton(int px, int py, string s, int col) { // TMP int siz = vid.yres > vid.xres ? vid.fsize*2 : vid.fsize * 3/2; int rad = (int) realradius(); - if(stereo::mode == stereo::sLR) rad = 99999; + if(vid.stereo_mode == sLR) rad = 99999; int vrx = min(rad, vid.xres/2 - 40); - int vry = min(rad, min(vid.ycenter, vid.yres - vid.ycenter) - 20); - int x = vid.xcenter + px * vrx; - int y = vid.ycenter + py * (vry - siz/2); + int vry = min(rad, min(current_display->ycenter, vid.yres - current_display->ycenter) - 20); + int x = current_display->xcenter + px * vrx; + int y = current_display->ycenter + py * (vry - siz/2); int vrr = int(hypot(vrx, vry) * sqrt(2.)); if(gtouched && !mouseover - && abs(mousex - vid.xcenter) < vrr - && abs(mousey - vid.ycenter) < vrr - && hypot(mousex-vid.xcenter, mousey-vid.ycenter) > vrr - && px == (mousex > vid.xcenter ? 1 : -1) - && py == (mousey > vid.ycenter ? 1 : -1) + && abs(mousex - current_display->xcenter) < vrr + && abs(mousey - current_display->ycenter) < vrr + && hypot(mousex-current_display->xcenter, mousey-current_display->ycenter) > vrr + && px == (mousex > current_display->xcenter ? 1 : -1) + && py == (mousey > current_display->ycenter ? 1 : -1) ) col = 0xFF0000; if(displayfr(x, y, 0, siz, s, col, 8+8*px)) buttonclicked = true; @@ -969,7 +968,7 @@ void show() { if(!sphere) set_geometry(gSphere); mode = 0; fullcenter(); mode = 2; sensitivity = 1; - stereo::mode = stereo::sLR; stereo::ipd = 0.2; + vid.stereo_mode = sLR; vid.ipd = 0.2; vid.alpha = 0; vid.scale = 1; }); diff --git a/debug.cpp b/debug.cpp index 8997817b..644e0e56 100644 --- a/debug.cpp +++ b/debug.cpp @@ -477,7 +477,7 @@ int read_cheat_args() { } else if(argis("-SM")) { PHASEFROM(2); - shift(); stereo::mode = stereo::eStereo(argi()); + shift(); vid.stereo_mode = eStereo(argi()); } #if CAP_INV else if(argis("-IU")) { diff --git a/dialogs.cpp b/dialogs.cpp index 0dab42a5..dd5cfe8b 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -245,7 +245,7 @@ namespace dialog { int lastspace = 0; int xs, xo; - if(sidescreen) + if(current_display->sidescreen) xs = dwidth - vid.fsize*2, xo = vid.yres + vid.fsize; else xs = vid.xres * 618/1000, xo = vid.xres * 186/1000; @@ -314,7 +314,7 @@ namespace dialog { dcenter = vid.xres/2; dwidth = vid.xres; - if(sidescreen) { + if(current_display->sidescreen) { dwidth = vid.xres - vid.yres; dcenter = vid.xres - dwidth / 2; } @@ -382,7 +382,7 @@ namespace dialog { else if(I.type == diSlider) { bool xthis = (mousey >= top && mousey < tothei); int sl, sr; - if(sidescreen) + if(current_display->sidescreen) sl = vid.yres + vid.fsize*2, sr = vid.xres - vid.fsize*2; else sl = vid.xres/4, sr = vid.xres*3/4; @@ -523,7 +523,7 @@ namespace dialog { dcenter = vid.xres/2; dwidth = vid.xres; - if(sidescreen) { + if(current_display->sidescreen) { dwidth = vid.xres - vid.yres; dcenter = vid.xres - dwidth / 2; } @@ -710,7 +710,7 @@ namespace dialog { } else if(uni == 500) { int sl, sr; - if(sidescreen) + if(current_display->sidescreen) sl = vid.yres + vid.fsize*2, sr = vid.xres - vid.fsize*2; else sl = vid.xres/4, sr = vid.xres*3/4; diff --git a/graph.cpp b/graph.cpp index f7236ffa..314f6395 100644 --- a/graph.cpp +++ b/graph.cpp @@ -2288,8 +2288,8 @@ vector auravertices; void drawaura() { if(!haveaura()) return; - if(stereo::mode) return; - double rad = vid.radius; + if(vid.stereo_mode) return; + double rad = current_display->radius; if(sphere && !mdAzimuthalEqui()) rad /= sqrt(vid.alpha*vid.alpha - 1); for(int v=0; v<4; v++) sumaura(v); @@ -2312,8 +2312,8 @@ void drawaura() { for(int y=0; yxcenter) / rad; + ld hy = (y * 1. - current_display->ycenter) / rad / vid.stretch; if(vid.camera_angle) camrotate(hx, hy); @@ -5004,7 +5004,7 @@ void fallingMonsterAnimation(cell *c, eMonster m, int id) { void queuecircleat(cell *c, double rad, color_t col) { if(!c) return; if(!gmatrix.count(c)) return; - if(stereo::mode || sphere) { + if(vid.stereo_mode || sphere) { dynamicval p(poly_outline, col); queuepolyat(gmatrix[c] * spintick(100), shGem[1], 0, PPR::LINE); return; @@ -5044,7 +5044,7 @@ void drawMarkers() { if(!inHighQual) { - bool ok = !ISPANDORA || mousepressed; + bool ok = !ISPANDORA || mousepressed; if(G(dragon::target) && haveMount()) { queuechr(Gm0(dragon::target), 2*vid.fsize, 'X', @@ -5054,30 +5054,30 @@ void drawMarkers() { /* for(int i=0; i<12; i++) if(c->type == 5 && c->master == &dodecahedron[i]) queuechr(xc, yc, sc, 4*vid.fsize, 'A'+i, iinf[itOrbDomination].color); */ - { - using namespace yendor; - if(yii < isize(yi) && !yi[yii].found) { - cell *keycell = NULL; - int i; - for(i=0; icpdist <= get_sightrange_ambush()) { - keycell = yi[yii].path[i]; - break; + if(1) { + using namespace yendor; + if(yii < isize(yi) && !yi[yii].found) { + cell *keycell = NULL; + int i; + for(i=0; icpdist <= get_sightrange_ambush()) { + keycell = yi[yii].path[i]; + break; + } + if(keycell) { + for(; icpdist > 1 ? 0x00FFFF : 0xFF0000, 0, 0xFF)); } @@ -5480,20 +5480,23 @@ bool dronemode; purehookset hooks_calcparam; void calcparam() { + + auto cd = current_display; + DEBB(DF_GRAPH, (debugfile,"calc param\n")); - vid.xcenter = vid.xres / 2; - vid.ycenter = vid.yres / 2; + cd->xcenter = vid.xres * (cd->xmax + cd->xmin) / 2; + cd->ycenter = vid.yres * (cd->ymax + cd->ymin) / 2; if(vid.scale > -1e-2 && vid.scale < 1e-2) vid.scale = 1; - ld realradius = min(vid.xcenter, vid.ycenter); + ld realradius = min(vid.xres * (cd->xmax - cd->xmin) / 2, vid.yres * (cd->ymax - cd->ymin) / 2); - vid.scrsize = realradius - (inHighQual ? 0 : ISANDROID ? 2 : ISIOS ? 40 : 40); + cd->scrsize = realradius - (inHighQual ? 0 : ISANDROID ? 2 : ISIOS ? 40 : 40); sidescreen = false; if(vid.xres < vid.yres - 2 * vid.fsize && !inHighQual) { - vid.ycenter = vid.yres - vid.scrsize - vid.fsize; + cd->ycenter = vid.yres - cd->scrsize - vid.fsize; } else { if(vid.xres >= vid.yres * 5/4-16 && (cmode & sm::SIDE)) @@ -5503,24 +5506,24 @@ void calcparam() { sidescreen = true; #endif - if(sidescreen) vid.xcenter = vid.yres/2; + if(sidescreen) cd->xcenter = vid.yres/2; } - vid.radius = vid.scale * vid.scrsize; - realradius = min(realradius, vid.radius); + cd->radius = vid.scale * cd->scrsize; + realradius = min(realradius, cd->radius); - if(dronemode) { vid.ycenter -= vid.radius; vid.ycenter += vid.fsize/2; vid.ycenter += vid.fsize/2; vid.radius *= 2; } + if(dronemode) { cd->ycenter -= cd->radius; cd->ycenter += vid.fsize/2; cd->ycenter += vid.fsize/2; cd->radius *= 2; } - vid.xcenter += vid.scrsize * vid.xposition; - vid.ycenter += vid.scrsize * vid.yposition; + cd->xcenter += cd->scrsize * vid.xposition; + cd->ycenter += cd->scrsize * vid.yposition; - stereo::tanfov = tan(stereo::fov * degree / 2); + cd->tanfov = tan(vid.fov * degree / 2); if(pmodel) - stereo::scrdist = vid.xres / 2 / stereo::tanfov; + cd->scrdist = vid.xres / 2 / cd->tanfov; else - stereo::scrdist = vid.radius; - stereo::scrdist_text = stereo::scrdist; + cd->scrdist = cd->radius; + cd->scrdist_text = cd->scrdist; callhooks(hooks_calcparam); } @@ -5615,7 +5618,7 @@ void gamescreen(int _darken) { buttonclicked = false; - if((cmode & sm::NORMAL) && stereo::mode != stereo::sLR) { + if((cmode & sm::NORMAL) && vid.stereo_mode != sLR) { if(andmode == 0 && shmup::on) { using namespace shmupballs; calc(); @@ -5668,7 +5671,7 @@ void normalscreen() { keyhandler = handleKeyNormal; if(!playerfound && !anims::any_on()) - displayButton(vid.xcenter, vid.ycenter, XLAT(mousing ? "find the player" : "press SPACE to find the player"), ' ', 8); + displayButton(current_display->xcenter, current_display->ycenter, XLAT(mousing ? "find the player" : "press SPACE to find the player"), ' ', 8); describeMouseover(); } @@ -5754,12 +5757,12 @@ void drawscreen() { for(int p=0; pycenter - current_display->radius * 3/4, 2, vid.fsize, XLAT(minetexts[mines[p]]), minecolors[mines[p]], 8); if(minefieldNearby && !shmup::on && cwt.at->land != laMinefield && cwt.peek()->land != laMinefield) { - displayfr(vid.xres/2, vid.ycenter - vid.radius * 3/4 - vid.fsize*3/2, 2, + displayfr(vid.xres/2, current_display->ycenter - current_display->radius * 3/4 - vid.fsize*3/2, 2, vid.fsize, XLAT("WARNING: you are entering a minefield!"), col, 8); @@ -5822,7 +5825,6 @@ void resetGeometry() { //=== animation map animations[ANIMLAYERS]; -unordered_map gmatrix, gmatrix0; int revhint(cell *c, int hint) { if(hint >= 0 && hint < c->type) return c->c.spin(hint); diff --git a/hud.cpp b/hud.cpp index 4f19b411..236e2a31 100644 --- a/hud.cpp +++ b/hud.cpp @@ -344,18 +344,18 @@ void drawMobileArrow(int i) { bool nofps = false; void drawStats() { - if(nohud || stereo::mode == stereo::sLR) return; + if(nohud || vid.stereo_mode == sLR) return; if(callhandlers(false, hooks_prestats)) return; if(viewdists && show_distance_lists) expansion.view_distances_dialog(); - if(sidescreen) return; + if(current_display->sidescreen) return; { dynamicval pm(pmodel, mdDisk); dynamicval v(vid, vid); vid.alpha = vid.scale = 1; calcparam(); - stereo::set_projection(0, false); + current_display->set_projection(0, false); if(haveMobileCompass()) { initquickqueue(); @@ -476,7 +476,7 @@ void drawStats() { } } } - calcparam(); stereo::set_projection(0, false); + calcparam(); current_display->set_projection(0, false); string s0; if(!peace::on) { diff --git a/hyper.h b/hyper.h index 01e8a34c..ed1bb25f 100644 --- a/hyper.h +++ b/hyper.h @@ -950,7 +950,7 @@ void drawCircle(int x, int y, int size, color_t color, color_t fillcolor = 0); void fixcolor(int& col); ld displayspin(cell *c, int d); hyperpoint gethyper(ld x, ld y); -void resetview(); extern heptspin viewctr; extern cellwalker centerover; +void resetview(); void drawthemap(); void drawfullmap(); extern function wrap_drawfullmap; @@ -985,6 +985,8 @@ extern reaction_t help_delegate; #define HELPFUN(x) (help_delegate = x, "HELPFUN") +enum eStereo { sOFF, sAnaglyph, sLR, sODS }; + struct videopar { ld scale, alpha, sspeed, mspeed, yshift, camera_angle; ld ballangle, ballproj, euclid_to_sphere, twopoint_param, stretch, binary_width; @@ -1005,11 +1007,6 @@ struct videopar { ld xposition, yposition; - // paramaters calculated from the above - int xcenter, ycenter; - ld radius; - int scrsize; - bool grid; int particles; @@ -1058,6 +1055,11 @@ struct videopar { int cells_drawn_limit; ld skiprope; + + eStereo stereo_mode; + ld ipd; + ld lr_eyewidth, anaglyph_eyewidth; + ld fov; }; extern videopar vid; @@ -1068,8 +1070,43 @@ template void pushScreen(const T& x) { screens.push_back(x); } inline void popScreen() { screens.pop_back(); } inline void popScreenAll() { while(isize(screens)>1) popScreen(); } -extern transmatrix View; // current rotation, relative to viewctr -extern transmatrix cwtV; // player-relative view +struct display_data { + transmatrix view_matrix; // current rotation, relative to viewctr + transmatrix player_matrix; // player-relative view + heptspin view_center; + cellwalker precise_center; + unordered_map cellmatrices, old_cellmatrices; + ld xmin, ymin, xmax, ymax; + display_data() { xmin = ymin = 0; xmax = ymax = 1; } + + // paramaters calculated from the above + int xcenter, ycenter; + ld radius; + int scrsize; + bool sidescreen; + + ld tanfov; + + GLfloat scrdist, scrdist_text; + + ld eyewidth(); + bool stereo_active(); + bool in_anaglyph(); + + void set_viewport(int ed); + void set_projection(int ed, bool apply_models); + void set_mask(int ed); + }; + +extern display_data default_display; +extern display_data *current_display; + +#define View (current_display->view_matrix) +#define cwtV (current_display->player_matrix) +#define viewctr (current_display->view_center) +#define centerover (current_display->precise_center) +#define gmatrix (current_display->cellmatrices) +#define gmatrix0 (current_display->old_cellmatrices) extern cell *mouseover, *mouseover2, *lmouseover; extern string mouseovers; @@ -1866,7 +1903,6 @@ struct animation { #define LAYER_BOAT 2 // mark that a boat has moved extern map animations[ANIMLAYERS]; -extern unordered_map gmatrix, gmatrix0; void animateAttack(cell *src, cell *tgt, int layer, int direction_hint); @@ -2375,7 +2411,6 @@ void buildHelpText(); void buildCredits(); void setAppropriateOverview(); bool quitsaves(); -extern bool sidescreen; extern const char* COLORBAR; @@ -3292,25 +3327,6 @@ struct resetbuffer { void reset(); }; -namespace stereo { - enum eStereo { sOFF, sAnaglyph, sLR, sODS }; - - extern eStereo mode; - extern ld ipd; - extern ld lr_eyewidth, anaglyph_eyewidth; - extern ld fov, tanfov; - - extern GLfloat scrdist, scrdist_text; - - ld eyewidth(); - bool active(); - bool in_anaglyph(); - - void set_viewport(int ed); - void set_projection(int ed, bool apply_models); - void set_mask(int ed); - } - double randd(); #if CAP_ORIENTATION @@ -3649,7 +3665,7 @@ namespace glhr { colored_vertex(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b) { coords[0] = x; coords[1] = y; - coords[2] = stereo::scrdist; + coords[2] = current_display->scrdist; color[0] = r; color[1] = g; color[2] = b; @@ -4372,6 +4388,13 @@ namespace dq { void enqueue(heptagon *h, const transmatrix& T); } +typedef pair named_functionality; +inline named_functionality named_dialog(string x, reaction_t dialog) { return named_functionality(x, [dialog] () { pushScreen(dialog); }); } + +extern hookset *hooks_o_key; + +named_functionality get_o_key(); + bool do_draw(cell *c, const transmatrix& T); } diff --git a/hypgraph.cpp b/hypgraph.cpp index 917f02e7..290135aa 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -69,8 +69,8 @@ hyperpoint space_to_perspective(hyperpoint z, ld alpha) { hyperpoint gethyper(ld x, ld y) { - ld hx = (x - vid.xcenter) / vid.radius; - ld hy = (y - vid.ycenter) / vid.radius / vid.stretch; + ld hx = (x - current_display->xcenter) / current_display->radius; + ld hy = (y - current_display->ycenter) / current_display->radius / vid.stretch; if(pmodel) { ghx = hx, ghy = hy; @@ -101,11 +101,11 @@ void apply_depth(hyperpoint &f, ld z) { if(vid.usingGL) f[2] = z; else { - z = z * vid.radius; - ld mul = stereo::scrdist / (stereo::scrdist + z); + z = z * current_display->radius; + ld mul = current_display->scrdist / (current_display->scrdist + z); f[0] = f[0] * mul; f[1] = f[1] * mul; - f[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius + stereo::ipd * mul / 2; + f[2] = vid.xres * current_display->eyewidth() / 2 / current_display->radius + vid.ipd * mul / 2; } } @@ -175,7 +175,7 @@ template void makeband(hyperpoint H, hyperpoint& ret, const T& f) { ld yzf = y * zf; y *= yf; conformal::apply_orientation(y, x); ret = hpxyz(x / M_PI, y / M_PI, 0); - if(zlev != 1 && stereo::active()) + if(zlev != 1 && current_display->stereo_active()) apply_depth(ret, yzf / M_PI); return; } @@ -231,7 +231,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { switch(pmodel) { case mdUnchanged: - ret = H / vid.radius; + ret = H / current_display->radius; return; case mdBall: { @@ -248,7 +248,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { if(!vid.camera_angle) { ret[0] = H[0] / tz; ret[1] = H[1] / tz; - ret[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius - stereo::ipd / tz / 2; + ret[2] = vid.xres * current_display->eyewidth() / 2 / current_display->radius - vid.ipd / tz / 2; } else { ld tx = H[0]; @@ -259,7 +259,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { ld ux = tx, uy = ty * cc - ss * tz, uz = tz * cc + ss * ty; ret[0] = ux / uz; ret[1] = uy / uz; - ret[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius - stereo::ipd / uz / 2; + ret[2] = vid.xres * current_display->eyewidth() / 2 / current_display->radius - vid.ipd / uz / 2; } return; } @@ -292,7 +292,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { } ret[1] = conformal::ocos + H[1]; ret[2] = 0; - if(zlev != 1 && stereo::active()) + if(zlev != 1 && current_display->stereo_active()) apply_depth(ret, -H[1] * geom3::factor_to_lev(zlev)); break; } @@ -510,7 +510,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { ret = H * (d * df / rad / M_PI); ret[2] = 0; - if(zlev != 1 && stereo::active()) + if(zlev != 1 && current_display->stereo_active()) apply_depth(ret, d * zf / M_PI); break; @@ -577,10 +577,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { // game-related graphics -transmatrix View; // current rotation, relative to viewctr -transmatrix cwtV = Id; // player-relative view transmatrix sphereflip; // on the sphere, flip -heptspin viewctr; // heptagon and rotation where the view is centered at bool playerfound; // has player been found in the last drawing? #define eurad crossf @@ -695,19 +692,19 @@ bool in_smart_range(const transmatrix& T) { applymodel(tC0(T), h1); if(std::isnan(h1[0]) || std::isnan(h1[1])) return false; if(std::isinf(h1[0]) || std::isinf(h1[1])) return false; - ld x = vid.xcenter + vid.radius * h1[0]; - ld y = vid.ycenter + vid.radius * h1[1] * vid.stretch; + ld x = current_display->xcenter + current_display->radius * h1[0]; + ld y = current_display->ycenter + current_display->radius * h1[1] * vid.stretch; if(x > vid.xres * 2) return false; if(x < -vid.xres) return false; if(y > vid.yres * 2) return false; if(y < -vid.yres) return false; ld epsilon = 0.01; applymodel(T * xpush0(epsilon), h2); - ld x1 = vid.radius * abs(h2[0] - h1[0]) / epsilon; - ld y1 = vid.radius * abs(h2[1] - h1[1]) * vid.stretch / epsilon; + ld x1 = current_display->radius * abs(h2[0] - h1[0]) / epsilon; + ld y1 = current_display->radius * abs(h2[1] - h1[1]) * vid.stretch / epsilon; applymodel(T * ypush(epsilon) * C0, h3); - ld x2 = vid.radius * abs(h3[0] - h1[0]) / epsilon; - ld y2 = vid.radius * abs(h3[1] - h1[1]) * vid.stretch / epsilon; + ld x2 = current_display->radius * abs(h3[0] - h1[0]) / epsilon; + ld y2 = current_display->radius * abs(h3[1] - h1[1]) * vid.stretch / epsilon; ld scale = sqrt(hypot(x1, y1) * hypot(x2, y2)) * scalefactor * hcrossf7; if(svg::in) scale /= svg::divby; return @@ -1036,7 +1033,7 @@ void optimizeview() { void addball(ld a, ld b, ld c) { hyperpoint h; ballmodel(h, a, b, c); - for(int i=0; i<3; i++) h[i] *= vid.radius; + for(int i=0; i<3; i++) h[i] *= current_display->radius; curvepoint(h); } @@ -1093,19 +1090,19 @@ void fullcenter() { transmatrix screenpos(ld x, ld y) { transmatrix V = Id; - V[0][2] += (x - vid.xcenter) / vid.radius * (1+vid.alpha); - V[1][2] += (y - vid.ycenter) / vid.radius * (1+vid.alpha); + V[0][2] += (x - current_display->xcenter) / current_display->radius * (1+vid.alpha); + V[1][2] += (y - current_display->ycenter) / current_display->radius * (1+vid.alpha); return V; } transmatrix atscreenpos(ld x, ld y, ld size) { transmatrix V = Id; - V[0][2] += (x - vid.xcenter); - V[1][2] += (y - vid.ycenter); + V[0][2] += (x - current_display->xcenter); + V[1][2] += (y - current_display->ycenter); V[0][0] = size * 2 * hcrossf / crossf; V[1][1] = size * 2 * hcrossf / crossf; - V[2][2] = stereo::scrdist; + V[2][2] = current_display->scrdist; return V; } @@ -1115,7 +1112,7 @@ void circle_around_center(ld radius, color_t linecol, color_t fillcol, PPR prio) hyperpoint ret; applymodel(xpush0(radius), ret); ld r = hypot2(ret); - queuecircle(vid.xcenter, vid.ycenter, r * vid.radius, linecol, prio, fillcol); + queuecircle(current_display->xcenter, current_display->ycenter, r * current_display->radius, linecol, prio, fillcol); return; } for(int i=0; i<=360; i++) curvepoint(xspinpush0(i * degree, 10)); @@ -1143,7 +1140,7 @@ void draw_model_elements() { } case mdBall: { - queuecircle(vid.xcenter, vid.ycenter, vid.radius, ringcolor, PPR::OUTCIRCLE, modelcolor); + queuecircle(current_display->xcenter, current_display->ycenter, current_display->radius, ringcolor, PPR::OUTCIRCLE, modelcolor); ballgeometry(); return; } @@ -1200,7 +1197,7 @@ void queuestraight(hyperpoint X, int style, color_t lc, color_t fc, PPR p) { using namespace hyperpoint_vec; hyperpoint H; applymodel(X, H); - H *= vid.radius; + H *= current_display->radius; ld mul = hypot(vid.xres, vid.yres) / hypot2(H); ld m = style == 1 ? -mul : -1; @@ -1242,7 +1239,7 @@ void draw_boundary(int w) { switch(pmodel) { case mdTwoPoint: { - if(twopoint_do_flips || stereo::active() || !sphere) return; + if(twopoint_do_flips || current_display->stereo_active() || !sphere) return; queuereset(vid.usingGL ? mdDisk : mdUnchanged, p); for(int b=-1; b<=1; b+=2) @@ -1303,7 +1300,7 @@ void draw_boundary(int w) { queuereset(mdUnchanged, p); for(int i=0; i<=360; i++) { ld s = sin(i * degree); - curvepoint(hpxyz(vid.radius * cos(i * degree), vid.radius * s * (conformal::cos_ball * s >= 0 - 1e-6 ? 1 : abs(conformal::sin_ball)), 0)); + curvepoint(hpxyz(current_display->radius * cos(i * degree), current_display->radius * s * (conformal::cos_ball * s >= 0 - 1e-6 ? 1 : abs(conformal::sin_ball)), 0)); } queuecurve(lc, fc, p); queuereset(pmodel, p); @@ -1312,7 +1309,7 @@ void draw_boundary(int w) { for(int i=0; i<=360; i++) { ld s = sin(i * degree); - curvepoint(hpxyz(vid.radius * cos(i * degree), vid.radius * s * conformal::sin_ball, 0)); + curvepoint(hpxyz(current_display->radius * cos(i * degree), current_display->radius * s * conformal::sin_ball, 0)); } queuecurve(lc, fc, p); queuereset(pmodel, p); @@ -1320,7 +1317,7 @@ void draw_boundary(int w) { if(euclid || sphere) { queuereset(mdUnchanged, p); for(int i=0; i<=360; i++) { - curvepoint(hpxyz(vid.radius * cos(i * degree), vid.radius * sin(i * degree), 0)); + curvepoint(hpxyz(current_display->radius * cos(i * degree), current_display->radius * sin(i * degree), 0)); } queuecurve(lc, fc, p); queuereset(pmodel, p); @@ -1392,7 +1389,7 @@ void draw_boundary(int w) { cld z = exp(cld(a, a * imag(sm) / real(sm) + M_PI)); hyperpoint ret = hpxyz(real(z), imag(z), 0); ret = mobius(ret, vid.skiprope, 1); - ret *= vid.radius; + ret *= current_display->radius; curvepoint(ret); } queuecurve(ringcolor, 0, p).flags |= POLY_ALWAYS_IN; @@ -1405,8 +1402,8 @@ void draw_boundary(int w) { } if(sphere && pmodel == mdDisk && vid.alpha > 1) { - double rad = vid.radius / sqrt(vid.alpha*vid.alpha - 1); - queuecircle(vid.xcenter, vid.ycenter, rad, lc, p, fc); + double rad = current_display->radius / sqrt(vid.alpha*vid.alpha - 1); + queuecircle(current_display->xcenter, current_display->ycenter, rad, lc, p, fc); return; } diff --git a/init.cpp b/init.cpp index 7a441d91..95da3256 100644 --- a/init.cpp +++ b/init.cpp @@ -158,8 +158,8 @@ void handleclick(MOBPAR_FORMAL) { } else if(getcstat != SDLK_F1 && getcstat != 'i' && getcstat != 't') { - int px = mousex < vid.xcenter ? 0 : 1; - int py = mousey < vid.ycenter ? 0 : 1; + int px = mousex < current_display->xcenter ? 0 : 1; + int py = mousey < current_display->ycenter ? 0 : 1; if(isize(screens) == 1) { if(px == 0 && py == 1) { @@ -296,7 +296,7 @@ void mobile_draw(MOBPAR_FORMAL) { inmenu = isize(screens) > 1; - if(!inmenu && stereo::mode == stereo::sLR && ors::mode) + if(!inmenu && vid.stereo_mode == sLR && ors::mode) mousex = vid.xres/2, mousey = vid.yres/2, mouseh = sphereflip * C0; // if(debfile) fprintf(debfile, "d1\n"), fflush(debfile); @@ -341,7 +341,7 @@ void mobile_draw(MOBPAR_FORMAL) { bool normal_reaction = !inmenu; - if(normal_reaction && stereo::mode == stereo::sLR) { + if(normal_reaction && vid.stereo_mode == sLR) { normal_reaction = false; if(lclicked && !clicked) { if(rug::rugged) diff --git a/inventory.cpp b/inventory.cpp index 171032b0..1ad1cd9b 100644 --- a/inventory.cpp +++ b/inventory.cpp @@ -475,8 +475,8 @@ namespace hr { namespace inv { dialog::addSelItem(XLAT1(iinf[o].name), its(remaining[i]), c); else { auto pos = orbcoord[oc++]; - ld px = vid.xcenter + 2*rad*pos.first + rad*pos.second; - ld py = vid.ycenter + pos.second * rad3; + ld px = current_display->xcenter + 2*rad*pos.first + rad*pos.second; + ld py = current_display->ycenter + pos.second * rad3; int icol = iinf[o].color; if(!remaining[i]) icol = gradient(icol, 0, 0, .5, 1); bool gg = graphglyph(); diff --git a/mapeditor.cpp b/mapeditor.cpp index 5f86407e..70e5e201 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -23,12 +23,12 @@ namespace mapeditor { // mx = xb + ssiz*xpos + mrx * scale // mx = xb + ssiz*xpos' + mrx * scale' - ld mrx = (.0 + mousex - vid.xcenter) / vid.scale; - ld mry = (.0 + mousey - vid.ycenter) / vid.scale; + ld mrx = (.0 + mousex - current_display->xcenter) / vid.scale; + ld mry = (.0 + mousey - current_display->ycenter) / vid.scale; if(vid.xres > vid.yres) { - vid.xposition += (vid.scale - vid.scale*z) * mrx / vid.scrsize; - vid.yposition += (vid.scale - vid.scale*z) * mry / vid.scrsize; + vid.xposition += (vid.scale - vid.scale*z) * mrx / current_display->scrsize; + vid.yposition += (vid.scale - vid.scale*z) * mry / current_display->scrsize; } vid.scale *= z; diff --git a/menus.cpp b/menus.cpp index 7e9f63f1..c8d96f01 100644 --- a/menus.cpp +++ b/menus.cpp @@ -222,7 +222,7 @@ void showMainMenu() { else q = "game over screen"; dialog::addItem(XLAT(q), SDLK_ESCAPE); - dialog::addItem(XLAT("world overview"), 'o'); + dialog::addItem(get_o_key().first, 'o'); if(inv::on) dialog::addItem(XLAT("inventory"), 'i'); @@ -272,7 +272,7 @@ void showMainMenu() { } else if(sym == 'o') { clearMessages(); - setAppropriateOverview(); + get_o_key().second(); } #if CAP_INV else if(sym == 'i') { @@ -813,29 +813,40 @@ void showStartMenu() { // -- overview -- -void setAppropriateOverview() { - clearMessages(); - if(daily::on) { +hookset *hooks_o_key; + +named_functionality get_o_key() { + + if(hooks_o_key) for(auto& h: *hooks_o_key) { + auto res = h.second(); + if(res.first != "") return res; + } + #if CAP_DAILY - achievement_final(false); - pushScreen(daily::showMenu); + if(daily::on) + return named_functionality(XLAT("Strange Challenge"), [] () { + achievement_final(false); + pushScreen(daily::showMenu); + }); #endif - } - else if(viewdists) - runGeometryExperiments(); - else if(tactic::on) - pushScreen(tactic::showMenu); - else if(yendor::on) - pushScreen(yendor::showMenu); - else if(peace::on) - pushScreen(peace::showMenu); - else if((geometry != gNormal || NONSTDVAR) && !chaosmode && !(geometry == gEuclid && isCrossroads(specialland)) && !(weirdhyperbolic && specialland == laCrossroads4)) { - runGeometryExperiments(); - } - else { - dialog::infix = ""; - pushScreen(showOverview); - } + + if(viewdists) + return named_functionality(XLAT("geometry experiments"), runGeometryExperiments); + + if(tactic::on) + return named_dialog(XLAT("Pure Tactics mode"), tactic::showMenu); + + if(yendor::on) + return named_dialog(XLAT("Yendor Challenge"), yendor::showMenu); + + if(peace::on) + return named_dialog(XLAT("peaceful mode"), peace::showMenu); + + if((geometry != gNormal || NONSTDVAR) && !chaosmode && !(geometry == gEuclid && isCrossroads(specialland)) && !(weirdhyperbolic && specialland == laCrossroads4)) + return named_functionality(XLAT("geometry experiments"), runGeometryExperiments); + + dialog::infix = ""; + return named_dialog(XLAT("world overview"), showOverview); } int messagelogpos; diff --git a/polygons.cpp b/polygons.cpp index 05fbc7af..1d054267 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -238,12 +238,12 @@ void fixpoint(array& hscr, hyperpoint H) { } hyperpoint Hscr; applymodel(good, Hscr); - hscr = make_array(Hscr[0]*vid.radius, Hscr[1]*vid.radius*vid.stretch, Hscr[2]*vid.radius); + hscr = make_array(Hscr[0]*current_display->radius, Hscr[1]*current_display->radius*vid.stretch, Hscr[2]*current_display->radius); } void addpoint(const hyperpoint& H) { if(true) { - ld z = vid.radius; + ld z = current_display->radius; // if(vid.alpha + H[2] <= BEHIND_LIMIT && pmodel == mdDisk) poly_flags |= POLY_BEHIND; if(spherespecial) { @@ -284,11 +284,11 @@ void coords_to_poly() { polyi = isize(glcoords); for(int i=0; istereo_active()) glcoords[i][2] = 0; - polyx[i] = vid.xcenter + glcoords[i][0] - glcoords[i][2]; - polyxr[i] = vid.xcenter + glcoords[i][0] + glcoords[i][2]; - polyy[i] = vid.ycenter + glcoords[i][1]; + polyx[i] = current_display->xcenter + glcoords[i][0] - glcoords[i][2]; + polyxr[i] = current_display->xcenter + glcoords[i][0] + glcoords[i][2]; + polyy[i] = current_display->ycenter + glcoords[i][1]; } } @@ -335,11 +335,11 @@ void addpoly(const transmatrix& V, const vector &tab, int ofs, int cnt /* hyperpoint Hscr; applymodel(goodpoint, Hscr); - glcoords.push_back(make_array(Hscr[0]*vid.radius+10, Hscr[1]*vid.radius*vid.stretch, Hscr[2]*vid.radius)); - glcoords.push_back(make_array(Hscr[0]*vid.radius, Hscr[1]*vid.radius*vid.stretch+10, Hscr[2]*vid.radius)); - glcoords.push_back(make_array(Hscr[0]*vid.radius-10, Hscr[1]*vid.radius*vid.stretch, Hscr[2]*vid.radius)); - glcoords.push_back(make_array(Hscr[0]*vid.radius, Hscr[1]*vid.radius*vid.stretch-10, Hscr[2]*vid.radius)); - glcoords.push_back(make_array(Hscr[0]*vid.radius+10, Hscr[1]*vid.radius*vid.stretch, Hscr[2]*vid.radius)); */ + glcoords.push_back(make_array(Hscr[0]*current_display->radius+10, Hscr[1]*current_display->radius*vid.stretch, Hscr[2]*vid.radius)); + glcoords.push_back(make_array(Hscr[0]*current_display->radius, Hscr[1]*current_display->radius*vid.stretch+10, Hscr[2]*vid.radius)); + glcoords.push_back(make_array(Hscr[0]*current_display->radius-10, Hscr[1]*current_display->radius*vid.stretch, Hscr[2]*vid.radius)); + glcoords.push_back(make_array(Hscr[0]*current_display->radius, Hscr[1]*current_display->radius*vid.stretch-10, Hscr[2]*vid.radius)); + glcoords.push_back(make_array(Hscr[0]*current_display->radius+10, Hscr[1]*current_display->radius*vid.stretch, Hscr[2]*vid.radius)); */ } } @@ -439,17 +439,17 @@ void glflush() { if(isize(text_vertices)) { // printf("%08X | %d texts, %d vertices\n", text_color, texts_merged, isize(text_vertices)); - stereo::set_projection(0, false); + current_display->set_projection(0, false); glhr::be_textured(); glBindTexture(GL_TEXTURE_2D, text_texture); glhr::color2(text_color); glhr::set_depthtest(false); - for(int ed = (stereo::active() && text_shift)?-1:0; ed<2; ed+=2) { + for(int ed = (current_display->stereo_active() && text_shift)?-1:0; ed<2; ed+=2) { if(vid.scale < 0) - glhr::set_modelview(glhr::translate(-ed*text_shift-vid.xcenter,-vid.ycenter, stereo::scrdist_text) * glhr::scale(-1,-1,-1)); + glhr::set_modelview(glhr::translate(-ed*text_shift-current_display->xcenter,-current_display->ycenter, current_display->scrdist_text) * glhr::scale(-1,-1,-1)); else - glhr::set_modelview(glhr::translate(-ed*text_shift-vid.xcenter,-vid.ycenter, stereo::scrdist_text)); - stereo::set_mask(ed); + glhr::set_modelview(glhr::translate(-ed*text_shift-current_display->xcenter,-current_display->ycenter, current_display->scrdist_text)); + current_display->set_mask(ed); glhr::current_vertices = NULL; glhr::prepare(text_vertices); @@ -458,7 +458,7 @@ void glflush() { GLERR("print"); } - if(stereo::active() && text_shift) stereo::set_mask(0); + if(current_display->stereo_active() && text_shift) current_display->set_mask(0); texts_merged = 0; text_vertices.clear(); @@ -491,7 +491,7 @@ void dqi_poly::gldraw() { auto& v = *tab; #if MINIMIZE_GL_CALLS - if(stereo::active() == 0 && !tinf && (color == 0 || ((flags & (POLY_VCONVEX | POLY_CCONVEX)) && !(flags & (POLY_INVERSE | POLY_FORCE_INVERTED))))) { + if(current_display->stereo_active() == 0 && !tinf && (color == 0 || ((flags & (POLY_VCONVEX | POLY_CCONVEX)) && !(flags & (POLY_INVERSE | POLY_FORCE_INVERTED))))) { if(color != triangle_color || outline != line_color || texts_merged) { glflush(); triangle_color = color; @@ -539,8 +539,8 @@ void dqi_poly::gldraw() { #endif } - for(int ed = stereo::active() ? -1 : 0; ed<2; ed+=2) { - if(ed) stereo::set_projection(ed, true), stereo::set_viewport(ed); + for(int ed = current_display->stereo_active() ? -1 : 0; ed<2; ed+=2) { + if(ed) current_display->set_projection(ed, true), current_display->set_viewport(ed); bool draw = color; if(shaderside_projection) { @@ -559,7 +559,7 @@ void dqi_poly::gldraw() { glhr::color2(0xFFFFFFFF); glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, offset, cnt); - stereo::set_mask(ed); + current_display->set_mask(ed); glhr::color2(color); glhr::set_depthtest(model_needs_depth()); @@ -568,7 +568,7 @@ void dqi_poly::gldraw() { glStencilFunc( GL_NOTEQUAL, 1, 1); GLfloat xx = vid.xres; GLfloat yy = vid.yres; - GLfloat dist = shaderside_projection ? stereo::scrdist : 0; + GLfloat dist = shaderside_projection ? current_display->scrdist : 0; vector scr = { make_array(-xx, -yy, dist), make_array(+xx, -yy, dist), @@ -603,7 +603,7 @@ void dqi_poly::gldraw() { } } - if(stereo::active()) stereo::set_projection(0, true), stereo::set_viewport(0), stereo::set_mask(0); + if(current_display->stereo_active()) current_display->set_projection(0, true), current_display->set_viewport(0), current_display->set_mask(0); } #endif @@ -620,7 +620,7 @@ double linewidthat(const hyperpoint& h) { if(!(vid.antialias & AA_LINEWIDTH)) return 1; else if(hyperbolic && pmodel == mdDisk && vid.alpha == 1) { double dz = h[2]; - if(dz < 1 || abs(dz-stereo::scrdist) < 1e-6) return 1; + if(dz < 1 || abs(dz-current_display->scrdist) < 1e-6) return 1; else { double dx = sqrt(dz * dz - 1); double dfc = dx/(dz+1); @@ -646,9 +646,9 @@ ld mercator_period; void fixMercator(bool tinf) { if(pmodel == mdBand) - mercator_period = 4 * vid.radius; + mercator_period = 4 * current_display->radius; else - mercator_period = 2 * vid.radius; + mercator_period = 2 * current_display->radius; if(!conformal::model_straight) for(auto& g: glcoords) @@ -656,7 +656,7 @@ void fixMercator(bool tinf) { if(pmodel == mdSinusoidal) for(int i = 0; iradius / vid.stretch * M_PI); ld hperiod = mercator_period / 2; @@ -664,18 +664,18 @@ void fixMercator(bool tinf) { auto dist = [] (ld a, ld b) { return max(b, a-b); }; - ld chypot = hypot(dist(vid.xres, vid.xcenter), dist(vid.yres, vid.ycenter)); + ld chypot = hypot(dist(vid.xres, current_display->xcenter), dist(vid.yres, current_display->ycenter)); ld cmin = -chypot/2, cmax = chypot/2, dmin = -chypot, dmax = chypot; if(mercator_coord) swap(cmin, dmin), swap(cmax, dmax); if(pmodel == mdSinusoidal) - dmin = -vid.stretch * vid.radius / 2, dmax = vid.stretch * vid.radius / 2; + dmin = -vid.stretch * current_display->radius / 2, dmax = vid.stretch * current_display->radius / 2; if(pmodel == mdBandEquidistant) - dmin = -vid.stretch * vid.radius / 2, dmax = vid.stretch * vid.radius / 2; + dmin = -vid.stretch * current_display->radius / 2, dmax = vid.stretch * current_display->radius / 2; if(pmodel == mdBandEquiarea) - dmin = -vid.stretch * vid.radius / M_PI, dmax = vid.stretch * vid.radius / M_PI; + dmin = -vid.stretch * current_display->radius / M_PI, dmax = vid.stretch * current_display->radius / M_PI; for(int i = 0; iradius / vid.stretch * M_PI); if(!conformal::model_straight) for(auto& g: glcoords) conformal::apply_orientation(g[1], g[0]); @@ -743,7 +743,7 @@ void fixMercator(bool tinf) { } if(pmodel == mdSinusoidal) for(int i = 0; iradius / vid.stretch * M_PI); glcoords.push_back(glcoords.back()); glcoords.push_back(glcoords[0]); for(int u=1; u<=2; u++) { @@ -783,7 +783,7 @@ void compute_side_by_centerin(dqi_poly *p, bool& nofill) { else nofill = true; } - applymodel(h1, hscr); hscr[0] *= vid.radius; hscr[1] *= vid.radius * vid.stretch; + applymodel(h1, hscr); hscr[0] *= current_display->radius; hscr[1] *= current_display->radius * vid.stretch; for(int i=0; iradius); h[1] *= vid.stretch; if(i == 0) phases[j].push_back(h); else { @@ -907,7 +907,7 @@ void dqi_poly::draw() { hyperpoint h1 = V * glhr::gltopoint((*tab)[offset+i]); hyperpoint mh1; applymodel(h1, mh1); mh1[1] *= vid.stretch; - phases[cpha].push_back(glhr::pointtogl(mh1 * vid.radius)); + phases[cpha].push_back(glhr::pointtogl(mh1 * current_display->radius)); // check if the i-th edge intersects the boundary of the ellipse // (which corresponds to the segment between the antipodes of foci) @@ -1056,7 +1056,7 @@ void dqi_poly::draw() { if(pmodel == mdSinusoidal) { ld y = glcoords[i][1], x = glcoords[i][0]; conformal::apply_orientation(x, y); - mercator_period = 2 * vid.radius * cos(y / vid.radius / vid.stretch * M_PI); + mercator_period = 2 * current_display->radius * cos(y / current_display->radius / vid.stretch * M_PI); } glcoords[i][mercator_coord] += conformal::ocos * mercator_period * (l - lastl); glcoords[i][1-mercator_coord] += conformal::osin * mercator_period * (l - lastl); @@ -1070,7 +1070,7 @@ void dqi_poly::draw() { ld h = atan2(glcoords[0][0], glcoords[0][1]); for(int i=0; i<=360; i++) { ld a = i * degree + h; - glcoords.push_back(make_array(vid.radius * sin(a), vid.radius * vid.stretch * cos(a), stereo::scrdist)); + glcoords.push_back(make_array(current_display->radius * sin(a), current_display->radius * vid.stretch * cos(a), current_display->scrdist)); } poly_flags ^= POLY_INVERSE; } @@ -1084,7 +1084,7 @@ void dqi_poly::draw() { #if CAP_GL if(vid.usingGL) { poly_flags &= ~(POLY_VCONVEX | POLY_CCONVEX); - // if(pmodel == 0) for(int i=0; iscrdist; if(tinf && (poly_flags & POLY_INVERSE)) { return; } @@ -1149,10 +1149,10 @@ void dqi_poly::draw() { else filledPolygonColorI(s, polyx, polyy, polyi, color); - if(stereo::active()) filledPolygonColorI(aux, polyxr, polyy, polyi, color); + if(current_display->stereo_active()) filledPolygonColorI(aux, polyxr, polyy, polyi, color); ((vid.antialias & AA_NOGL) ?aapolylineColor:polylineColor)(s, polyx, polyy, polyi, outline); - if(stereo::active()) aapolylineColor(aux, polyxr, polyy, polyi, outline); + if(current_display->stereo_active()) aapolylineColor(aux, polyxr, polyy, polyi, outline); if(vid.xres >= 2000 || fatborder) { int xmi = 3000, xma = -3000; @@ -1227,7 +1227,7 @@ int curvestart = 0; bool keep_curvedata = false; void queuereset(eModel m, PPR prio) { - queueaction(prio, [m] () { pmodel = m; stereo::set_projection(0, true); }); + queueaction(prio, [m] () { pmodel = m; current_display->set_projection(0, true); }); } void dqi_line::draw() { @@ -1274,7 +1274,7 @@ void sortquickqueue() { } void quickqueue() { - spherespecial = 0; stereo::set_projection(0, true); + spherespecial = 0; current_display->set_projection(0, true); int siz = isize(ptds); setcameraangle(false); for(int i=0; idraw(); @@ -1392,7 +1392,7 @@ void drawqueue() { profile_stop(3); #if CAP_SDL - if(stereo::active() && !vid.usingGL) { + if(current_display->stereo_active() && !vid.usingGL) { if(aux && (aux->w != s->w || aux->h != s->h)) SDL_FreeSurface(aux); @@ -1410,7 +1410,7 @@ void drawqueue() { spherespecial = 0; spherephase = 0; - stereo::set_projection(0, true); + current_display->set_projection(0, true); for(auto& ptd: ptds) if(ptd->prio == PPR::OUTCIRCLE) ptd->draw(); @@ -1426,7 +1426,7 @@ void drawqueue() { } spherespecial = sphereflipped() ? 1 : -1; - stereo::set_projection(0, true); + current_display->set_projection(0, true); reverse_side_priorities(); for(int i=ptds.size()-1; i>=0; i--) @@ -1437,7 +1437,7 @@ void drawqueue() { reverse_side_priorities(); spherespecial *= -1; spherephase = 1; - stereo::set_projection(0, true); + current_display->set_projection(0, true); } for(auto& ptd: ptds) if(ptd->prio != PPR::OUTCIRCLE) { @@ -1448,11 +1448,11 @@ void drawqueue() { #if CAP_GL if(vid.usingGL) - stereo::set_projection(0, true), stereo::set_mask(0), stereo::set_viewport(0); + current_display->set_projection(0, true), current_display->set_mask(0), current_display->set_viewport(0); #endif #if CAP_SDL - if(stereo::mode == stereo::sAnaglyph && !vid.usingGL) { + if(vid.stereo_mode == sAnaglyph && !vid.usingGL) { int qty = s->w * s->h; int *a = (int*) s->pixels; int *b = (int*) aux->pixels; @@ -1464,7 +1464,7 @@ void drawqueue() { SDL_UnlockSurface(aux); } - if(stereo::mode == stereo::sLR && !vid.usingGL) { + if(vid.stereo_mode == sLR && !vid.usingGL) { SDL_LockSurface(aux); for(int y=0; yxcenter + current_display->radius * hscr[0]; + yc = current_display->ycenter + current_display->radius * vid.stretch * hscr[1]; sc = 0; - // EYETODO sc = vid.eye * vid.radius * hscr[2]; + // EYETODO sc = vid.eye * current_display->radius * hscr[2]; } void queuechr(const hyperpoint& h, int size, char chr, color_t col, int frame) { diff --git a/quit.cpp b/quit.cpp index 0c6e3434..fc7104be 100644 --- a/quit.cpp +++ b/quit.cpp @@ -114,7 +114,7 @@ hint hints[] = { dialog::addItem(XLAT("world overview"), 'z'); }, []() { - setAppropriateOverview(); + pushScreen(showOverview); }}, { 0, @@ -468,7 +468,7 @@ void handleKeyQuit(int sym, int uni) { else if(uni == 'z') hints[hinttoshow].action(); else if(sym == SDLK_F3 || (sym == ' ' || sym == SDLK_HOME)) fullcenter(); - else if(uni == 'o') setAppropriateOverview(); + else if(uni == 'o') get_o_key().second(); #if CAP_INV else if(uni == 'i' && inv::on) pushScreen(inv::show); diff --git a/rogueviz-banachtarski.cpp b/rogueviz-banachtarski.cpp index 98f49307..eb0e3fc3 100644 --- a/rogueviz-banachtarski.cpp +++ b/rogueviz-banachtarski.cpp @@ -301,7 +301,7 @@ void bantar_frame() { cci.second.c->wparam = cci.second.gid; calcparam(); - stereo::set_projection(0, true); + current_display->set_projection(0, true); vector> subscr[4]; @@ -407,7 +407,7 @@ void bantar_frame() { vid.xposition = (!(i&2)) ? xdst : -xdst; vid.yposition = (!(i&1)) ? ydst : -ydst; calcparam(); - stereo::set_projection(0, true); + current_display->set_projection(0, true); drawqueue(); } diff --git a/rogueviz-graph.cpp b/rogueviz-graph.cpp index efd80125..e5d3c332 100644 --- a/rogueviz-graph.cpp +++ b/rogueviz-graph.cpp @@ -206,8 +206,8 @@ void create_model() { int v = global_v; rug::clear_model(); - ld x = (mousex - vid.xcenter + .0) / vid.xres; - ld y = (mousey - vid.ycenter + .0) / vid.yres; + ld x = (mousex - current_display->xcenter + .0) / vid.xres; + ld y = (mousey - current_display->ycenter + .0) / vid.yres; ld alpha = atan2(y, x); ld h = hypot(x, y); diff --git a/rogueviz-pentagonal.cpp b/rogueviz-pentagonal.cpp index 3affa128..f4dbece6 100644 --- a/rogueviz-pentagonal.cpp +++ b/rogueviz-pentagonal.cpp @@ -200,8 +200,8 @@ void create_model() { int v = global_v; rug::clear_model(); - ld x = (mousex - vid.xcenter + .0) / vid.xres; - ld y = (mousey - vid.ycenter + .0) / vid.yres; + ld x = (mousex - current_display->xcenter + .0) / vid.xres; + ld y = (mousey - current_display->ycenter + .0) / vid.yres; ld alpha = atan2(y, x); ld h = hypot(x, y); @@ -299,7 +299,7 @@ bool frame() { if(snubon && rug::rugged) { create_model(); nomenukey = true; - displaychr(vid.xcenter, vid.ycenter, 0, 10, 'X', 0xFFFFFF); + displaychr(current_display->xcenter, current_display->ycenter, 0, 10, 'X', 0xFFFFFF); clearMessages(); nohelp = true; playerfound = true; @@ -325,8 +325,8 @@ bool handleKey(int sym, int uni) { return true; } if(uni == 's' && rug::rugged) { - stereo::fov += 30; - if(stereo::fov >= 180) stereo::fov = 60; + vid.fov += 30; + if(vid.fov >= 180) vid.fov = 60; } if(uni == 'i' && rug::rugged) { rug::invert_depth = !rug::invert_depth; diff --git a/rogueviz-staircase.cpp b/rogueviz-staircase.cpp index 132d6137..4eb1b726 100644 --- a/rogueviz-staircase.cpp +++ b/rogueviz-staircase.cpp @@ -117,8 +117,8 @@ bool on; void make_staircase() { - // stereo::mode = stereo::sODS; - // stereo::set_viewport(0); + // vid.stereo_mode = current_display->sODS; + // current_display->set_viewport(0); rug::no_fog = true; printf("scurvature = %lf progress = %lf strafe=%lf,%lf\n", scurvature, progress, strafex, strafey); @@ -137,7 +137,7 @@ void make_staircase() { acurvature = scurvature; } rug::ruggospeed = acurvature; - stereo::ipd = 0.15 * acurvature; + vid.ipd = 0.15 * acurvature; if(!rug::rugged || !staircase::on) { staircase::on = true; rug::reopen(); diff --git a/rogueviz-video.cpp b/rogueviz-video.cpp index df1bcb65..30696abc 100644 --- a/rogueviz-video.cpp +++ b/rogueviz-video.cpp @@ -175,7 +175,7 @@ string its05(int i) { char buf[64]; sprintf(buf, "%05d", i); return buf; } void staircase_video(int from, int num, int step) { resetbuffer rb; renderbuffer rbuf(TSIZE, TSIZE, true); - stereo::mode = stereo::sODS; + vid.stereo_mode = sODS; for(int i=from; i vx(vid.xres, TSIZE); dynamicval vy(vid.yres, TSIZE); - dynamicval vxc(vid.xcenter, TSIZE/2); - dynamicval vyc(vid.ycenter, TSIZE/2); - stereo::set_viewport(0); + dynamicval vxc(current_display->xcenter, TSIZE/2); + dynamicval vyc(current_display->ycenter, TSIZE/2); + current_display->set_viewport(0); printf("draw scene\n"); rug::drawRugScene(); @@ -223,7 +223,7 @@ void bantar_record() { rbuf.enable(); vid.xres = vid.yres = TSIZE; - stereo::set_viewport(0); + current_display->set_viewport(0); banachtarski::bantar_frame(); IMAGESAVE(rbuf.render(), ("bantar/" + its05(fr) + IMAGEEXT).c_str()); diff --git a/rogueviz.cpp b/rogueviz.cpp index c25c45d5..5502b6ad 100644 --- a/rogueviz.cpp +++ b/rogueviz.cpp @@ -1393,16 +1393,16 @@ bool rogueviz_hud() { initquickqueue(); - int rad = vid.radius/10; + int rad = current_display->radius/10; ld x = vid.xres - rad; for(int i=0; iradius * (i+.5)) / legit * 2 - current_display->radius + vid.yres/2; - transmatrix V = atscreenpos(x, y, vid.radius/4); + transmatrix V = atscreenpos(x, y, current_display->radius/4); poly_outline = OUTLINE_NONE; queuedisk(V, vd.cp, true, NULL); @@ -1413,9 +1413,9 @@ bool rogueviz_hud() { for(int i=0; iradius * (i+isize(legend)+.5)) / legit * 2 - current_display->radius + vid.yres/2; - transmatrix V = atscreenpos(x, y, vid.radius/8); + transmatrix V = atscreenpos(x, y, current_display->radius/8); poly_outline = t->color | 0xFF; queuepolyat(V, shTriangle, 0, PPR::MONSTER_HEAD); @@ -1594,7 +1594,7 @@ void fixparam() { if(!legend.empty() && !nohud) { if((svg::in || inHighQual) && pngformat == 0) vid.xres = vid.xres * 22/16; - vid.xcenter = vid.ycenter; + current_display->xcenter = current_display->ycenter; } } @@ -2242,6 +2242,11 @@ bool default_help() { return true; } +named_functionality o_key() { + if(rogueviz::on) return named_dialog(XLAT("rogueviz menu"), rogueviz::showMenu); + return named_functionality(); + } + auto hooks = addHook(hooks_frame, 0, drawExtra) + #if CAP_COMMANDLINE @@ -2257,6 +2262,7 @@ auto hooks = addHook(shmup::hooks_describe, 100, describe_monster) + addHook(shmup::hooks_turn, 100, turn) + addHook(shmup::hooks_kill, 100, activate) + + addHook(hooks_o_key, 100, o_key) + addHook(hooks_mainmenu, 100, [] () { dialog::addItem(XLAT("rogueviz menu"), 'u'); dialog::add_action([] () { pushScreen(rogueviz::showMenu); }); diff --git a/rug.cpp b/rug.cpp index 552cf7da..fad5b5b8 100644 --- a/rug.cpp +++ b/rug.cpp @@ -339,8 +339,8 @@ void calcLengths() { void setVidParam() { vid.xres = vid.yres = TEXTURESIZE; - vid.scrsize = HTEXTURESIZE; - vid.radius = vid.scrsize * vid.scale; vid.xcenter = HTEXTURESIZE; vid.ycenter = HTEXTURESIZE; + current_display->scrsize = HTEXTURESIZE; + current_display->radius = current_display->scrsize * vid.scale; current_display->xcenter = HTEXTURESIZE; current_display->ycenter = HTEXTURESIZE; // vid.alpha = 1; } @@ -452,7 +452,7 @@ void buildTorusRug() { applymodel(tC0(eumove(x, y)), onscreen); // take point (1,0) // apply eumove(1,0) - // multiply by vid.radius (= HTEXTURESIZE * rugzoom) + // multiply by current_display->radius (= HTEXTURESIZE * rugzoom) // add 1, divide by texturesize r->x1 = onscreen[0]; r->y1 = onscreen[1]; @@ -523,13 +523,13 @@ void buildTorusRug() { for(auto p: points) maxz = max(maxz, max(abs(p->x1), abs(p->y1))); - // maxz * rugzoom * vid.radius == vid.radius + // maxz * rugzoom * current_display->radius == current_display->radius vid.scale = 1 / maxz; for(auto p: points) - p->x1 = (vid.xcenter + vid.radius * vid.scale * p->x1)/ vid.xres, - p->y1 = (vid.ycenter - vid.radius * vid.scale * p->y1)/ vid.yres; + p->x1 = (current_display->xcenter + current_display->radius * vid.scale * p->x1)/ vid.xres, + p->y1 = (current_display->ycenter - current_display->radius * vid.scale * p->y1)/ vid.yres; qvalid = 0; for(auto p: points) if(!p->glue) qvalid++; @@ -1085,7 +1085,7 @@ ld raddif(ld a, ld b) { bool project_ods(hyperpoint azeq, hyperpoint& h1, hyperpoint& h2, bool eye) { USING_NATIVE_GEOMETRY; - ld tanalpha = tan_auto(stereo::ipd/2); + ld tanalpha = tan_auto(vid.ipd/2); if(eye) tanalpha = -tanalpha; if(!sphere) tanalpha = -tanalpha; @@ -1114,7 +1114,7 @@ bool project_ods(hyperpoint azeq, hyperpoint& h1, hyperpoint& h2, bool eye) { ld phi = atan2(y, x) - atan2(y0, x0) + M_PI; - ld delta = euclid ? hypot(y0,z) : atan2_auto(z / sin(theta), t / cos_auto(stereo::ipd/2)); + ld delta = euclid ? hypot(y0,z) : atan2_auto(z / sin(theta), t / cos_auto(vid.ipd/2)); if(euclid || hyperbolic) phi -= M_PI; if(hyperbolic) delta = -delta; @@ -1143,7 +1143,7 @@ void drawTriangle(triangle& t) { dt++; #if CAP_ODS - if(stereo::mode == stereo::sODS) { + if(vid.stereo_mode == current_display->sODS) { hyperpoint pts[3]; for(int i=0; i<3; i++) pts[i] = t.m[i]->getglue()->flat; @@ -1231,12 +1231,12 @@ void prepareTexture() { videopar svid = vid; setVidParam(); - dynamicval d(stereo::mode, stereo::sOFF); + dynamicval d(vid.stereo_mode, sOFF); glbuf->enable(); - stereo::set_viewport(0); - stereo::set_projection(0, true); - stereo::set_mask(0); + current_display->set_viewport(0); + current_display->set_projection(0, true); + current_display->set_mask(0); glbuf->clear(0); ptds.clear(); @@ -1287,23 +1287,23 @@ void drawRugScene() { glhr::set_depthtest(true); glDepthFunc(invert_depth ? GL_GREATER : GL_LESS); - for(int ed=stereo::active() && stereo::mode != stereo::sODS ? -1 : 0; ed < 2; ed += 2) { + for(int ed=current_display->stereo_active() && vid.stereo_mode != sODS ? -1 : 0; ed < 2; ed += 2) { use_precompute = false; ct_array.clear(); - stereo::set_mask(ed), stereo::set_viewport(ed); - if(ed == 1 && stereo::mode == stereo::sAnaglyph) + current_display->set_mask(ed), current_display->set_viewport(ed); + if(ed == 1 && vid.stereo_mode == sAnaglyph) glClear(GL_DEPTH_BUFFER_BIT); start_projection(ed, true); eyewidth_translate(ed); - if(stereo::mode == stereo::sODS) { + if(vid.stereo_mode == sODS) { glhr::projection_multiply(glhr::ortho(M_PI, M_PI, 100)); // 2*M_PI)); } - else if(rug_perspective || stereo::active()) { + else if(rug_perspective || current_display->stereo_active()) { - xview = stereo::tanfov; - yview = stereo::tanfov * vid.yres / vid.xres; + xview = current_display->tanfov; + yview = current_display->tanfov * vid.yres / vid.xres; glhr::projection_multiply(glhr::frustum(xview, yview, lowrug, hirug)); xview = -xview; yview = -yview; @@ -1312,19 +1312,19 @@ void drawRugScene() { glhr::projection_multiply(glhr::translate(0, 0, -model_distance)); if(ed) { if(gwhere == gEuclid) - glhr::projection_multiply(glhr::translate(stereo::ipd*ed/2, 0, 0)); + glhr::projection_multiply(glhr::translate(vid.ipd*ed/2, 0, 0)); else { use_precompute = true; for(auto p: points) { p->precompute = p->flat; - push_point(p->precompute, 0, stereo::ipd*ed/2); + push_point(p->precompute, 0, vid.ipd*ed/2); } } } } else { - xview = stereo::tanfov * model_distance; - yview = stereo::tanfov * model_distance * vid.yres / vid.xres; + xview = current_display->tanfov * model_distance; + yview = current_display->tanfov * model_distance * vid.yres / vid.xres; // glOrtho(-xview, xview, yview, -yview, -1000, 1000); glhr::projection_multiply(glhr::ortho(xview, yview, -1000)); @@ -1345,13 +1345,13 @@ void drawRugScene() { glhr::prepare(ct_array); glDrawArrays(GL_TRIANGLES, 0, isize(ct_array)); - stereo::set_mask(0); + current_display->set_mask(0); } glEnable(GL_BLEND); - stereo::set_mask(0), stereo::set_viewport(0); - stereo::set_projection(0, true); + current_display->set_mask(0), current_display->set_viewport(0); + current_display->set_projection(0, true); if(rug_failure) { rug::close(); @@ -1516,7 +1516,7 @@ void actDraw() { } // do not display button else playerfound = true; - stereo::set_viewport(0); + current_display->set_viewport(0); physics(); drawRugScene(); @@ -1637,8 +1637,8 @@ static const ld RADAR_INF = 1e12; ld radar_distance = RADAR_INF; hyperpoint gethyper(ld x, ld y) { - double mx = (x - vid.xcenter)/vid.xres * 2 * xview; - double my = (vid.ycenter - y)/vid.yres * 2 * yview; + double mx = (x - current_display->xcenter)/vid.xres * 2 * xview; + double my = (current_display->ycenter - y)/vid.yres * 2 * yview; radar_distance = RADAR_INF; double rx1=0, ry1=0; diff --git a/screenshot.cpp b/screenshot.cpp index f4dce875..abeb01ad 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -96,10 +96,10 @@ namespace svg { void text(int x, int y, int size, const string& str, bool frame, color_t col, int align) { - double dfc = (x - vid.xcenter) * (x - vid.xcenter) + - (y - vid.ycenter) * (y - vid.ycenter); - dfc /= vid.radius; - dfc /= vid.radius; + double dfc = (x - current_display->xcenter) * (x - current_display->xcenter) + + (y - current_display->ycenter) * (y - current_display->ycenter); + dfc /= current_display->radius; + dfc /= current_display->radius; // 0 = center, 1 = edge dfc = 1 - dfc; @@ -149,7 +149,7 @@ namespace svg { fprintf(f, "%s %s", coord(polyx[i]), coord(polyy[i])); } - fprintf(f, "\" %s/>", stylestr(col, outline, (hyperbolic ? vid.radius : vid.scrsize) * linewidth/256)); + fprintf(f, "\" %s/>", stylestr(col, outline, (hyperbolic ? current_display->radius : current_display->scrsize) * linewidth/256)); stopstring(); fprintf(f, "\n"); } @@ -252,7 +252,7 @@ void saveHighQualityShot(const char *fname, const char *caption, int fade) { renderbuffer glbuf(vid.xres, vid.yres, vid.usingGL); glbuf.enable(); - stereo::set_viewport(0); + current_display->set_viewport(0); // printf("format = %d, %d x %d\n", pngformat, vid.xres, vid.yres); diff --git a/shmup.cpp b/shmup.cpp index 2e67465d..3c55d780 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -16,9 +16,9 @@ namespace shmupballs { void calc() { int rr = int(realradius()); rad = int(rr * (vid.mobilecompasssize ? vid.mobilecompasssize : 14) / 100); - xmove = max(vid.xcenter - rr - rad, rad); - xfire = min(vid.xcenter + rr + rad, vid.xres - rad); - yb = vid.ycenter + rr - rad; + xmove = max(current_display->xcenter - rr - rad, rad); + xfire = min(current_display->xcenter + rr + rad, vid.xres - rad); + yb = current_display->ycenter + rr - rad; } } @@ -675,7 +675,7 @@ void handleInput(int delta) { if(actionspressed[54]) { centerplayer = -1, playermoved = true; centerpc(100); } if(actionspressed[55] && !lactionpressed[55]) - setAppropriateOverview(); + get_o_key().second(); if(actionspressed[56] && !lactionpressed[56]) showMissionScreen(); diff --git a/system.cpp b/system.cpp index 4ce64ce3..17aa1e7d 100644 --- a/system.cpp +++ b/system.cpp @@ -1034,9 +1034,7 @@ namespace gamestack { struct gamedata { hrmap *hmap; cellwalker cwt; - cellwalker ctover; - heptspin viewctr; - transmatrix View; + display_data d; eGeometry geometry; eVariation variation; bool shmup; @@ -1054,12 +1052,10 @@ namespace gamestack { gamedata gdn; gdn.hmap = currentmap; gdn.cwt = cwt; - gdn.viewctr = viewctr; - gdn.View = View; gdn.geometry = geometry; gdn.shmup = shmup::on; gdn.variation = variation; - gdn.ctover = centerover; + gdn.d = *current_display; gd.push_back(gdn); } @@ -1067,15 +1063,13 @@ namespace gamestack { gamedata& gdn = gd[isize(gd)-1]; currentmap = gdn.hmap; cwt = gdn.cwt; - viewctr = gdn.viewctr; - View = gdn.View; geometry = gdn.geometry; variation = gdn.variation; if(shmup::on) shmup::clearMonsters(); shmup::on = gdn.shmup; resetGeometry(); gd.pop_back(); - centerover = gdn.ctover; + *current_display = gdn.d; bfs(); } diff --git a/textures.cpp b/textures.cpp index 4925dbb0..4c1286b4 100644 --- a/textures.cpp +++ b/textures.cpp @@ -224,8 +224,8 @@ void texture_data::saveRawTexture(string tn) { hyperpoint texture_config::texture_coordinates(hyperpoint h) { hyperpoint inmodel; applymodel(h, inmodel); - inmodel[0] *= vid.radius * 1. / vid.scrsize; - inmodel[1] *= vid.radius * vid.stretch / vid.scrsize; + inmodel[0] *= current_display->radius * 1. / current_display->scrsize; + inmodel[1] *= current_display->radius * vid.stretch / current_display->scrsize; inmodel[2] = 1; inmodel = itt * inmodel; inmodel[0] = (inmodel[0] + 1) / 2; @@ -488,7 +488,7 @@ void texture_config::saveFullTexture(string tn) { drawscreen(); if(data.readtexture(tn) && data.loadTextureGL()) { - itt = Id; // xyscale(Id, vid.scrsize * 1. / vid.radius); + itt = Id; // xyscale(Id, current_display->scrsize * 1. / current_display->radius); perform_mapping(); finish_mapping(); } @@ -511,10 +511,10 @@ void texture_config::drawRawTexture() { inmodel = itt * inmodel; rtver[i].texture[0] = (inmodel[0]+1)/2; rtver[i].texture[1] = (inmodel[1]+1)/2; - rtver[i].coords[0] = x * vid.scrsize; - rtver[i].coords[1] = y * vid.scrsize; + rtver[i].coords[0] = x * current_display->scrsize; + rtver[i].coords[1] = y * current_display->scrsize; } - glhr::set_modelview(glhr::translate(0, 0, stereo::scrdist)); + glhr::set_modelview(glhr::translate(0, 0, current_display->scrdist)); glhr::prepare(rtver); glhr::set_depthtest(false); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -617,8 +617,8 @@ ld magic_quality() { for(auto& p: amp) { hyperpoint inmodel; applymodel(ggmatrix(p.c) * p.cell_relative, inmodel); - inmodel[0] *= vid.radius * 1. / vid.scrsize; - inmodel[1] *= vid.radius * 1. / vid.scrsize; + inmodel[0] *= current_display->radius * 1. / current_display->scrsize; + inmodel[1] *= current_display->radius * 1. / current_display->scrsize; q += intvalxy(inmodel, p.texture_coords); } return q; @@ -657,7 +657,7 @@ eTexturePanstate panstate; void mousemovement() { static hyperpoint lastmouse; - hyperpoint mouseeu = hpxyz((mousex - vid.xcenter + .0) / vid.scrsize, (mousey - vid.ycenter + .0) / vid.scrsize, 1); + hyperpoint mouseeu = hpxyz((mousex - current_display->xcenter + .0) / current_display->scrsize, (mousey - current_display->ycenter + .0) / current_display->scrsize, 1); bool nonzero = mouseeu[0] || mouseeu[1]; switch(panstate) { @@ -986,7 +986,7 @@ void showMagicMenu() { dialog::display(); if(holdmouse) { - hyperpoint mouseeu = hpxyz((mousex - vid.xcenter + .0) / vid.scrsize, (mousey - vid.ycenter + .0) / vid.scrsize, 1); + hyperpoint mouseeu = hpxyz((mousex - current_display->xcenter + .0) / current_display->scrsize, (mousey - current_display->ycenter + .0) / current_display->scrsize, 1); if(newmove) { magicmapper_point newpoint; newpoint.c = mouseover; @@ -1007,13 +1007,13 @@ void showMagicMenu() { /* hyperpoint inmodel; applymodel(h, inmodel); - inmodel[0] *= vid.radius * 1. / vid.scrsize; - inmodel[1] *= vid.radius * 1. / vid.scrsize; + inmodel[0] *= current_display->radius * 1. / current_display->scrsize; + inmodel[1] *= current_display->radius * 1. / current_display->scrsize; */ queuechr( - vid.xcenter + vid.scrsize * am.texture_coords[0], - vid.ycenter + vid.scrsize * am.texture_coords[1], + current_display->xcenter + current_display->scrsize * am.texture_coords[0], + current_display->ycenter + current_display->scrsize * am.texture_coords[1], 0, vid.fsize, letter, 0x00C000, 1); letter++; diff --git a/util.cpp b/util.cpp index d92fef27..2328d98f 100644 --- a/util.cpp +++ b/util.cpp @@ -208,7 +208,7 @@ cld exp_parser::parse(int prio) { else if(number == "ms") res = ticks; else if(number == "mousex") res = mousex; else if(number == "mousey") res = mousey; - else if(number == "mousez") res = cld(mousex - vid.xcenter, mousey - vid.ycenter) / cld(vid.radius, 0); + else if(number == "mousez") res = cld(mousex - current_display->xcenter, mousey - current_display->ycenter) / cld(current_display->radius, 0); else if(extra_params.count(number)) res = extra_params[number]; else if(params.count(number)) res = params.at(number); else if(number[0] >= 'a' && number[0] <= 'z') at = -1;