From 7c82c3e5a30b37b53c2f038298792bbf9570e19e Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 13 Aug 2017 20:49:38 +0200 Subject: [PATCH] fixes to make the Emscripten web version compile correctly --- basegraph.cpp | 12 +- config.cpp | 52 +++++--- control.cpp | 8 +- hyperweb.cpp | 96 +++++++++++++-- init.cpp | 27 ++++- langen.cpp | 3 +- language.cpp | 8 +- menus.cpp | 83 ------------- nofont.cpp | 330 ++++++++++++++++---------------------------------- shmup.cpp | 16 ++- 10 files changed, 287 insertions(+), 348 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index e836c6a5..d9986a7f 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -362,7 +362,11 @@ void init_glfont(int size) { #endif // glListBase(0); - + +#if CAP_TABFONT + resetTabFont(); +#endif + for(int ch=1;ch<128+NUMEXTRA;ch++) { if(ch<32) continue; @@ -388,6 +392,12 @@ void init_glfont(int size) { #endif } +#if CAP_CREATEFONT + printf("#define NUMEXTRA %d\n", NUMEXTRA); +#define DEMACRO(x) #x + printf("#define NATCHARS " DEMACRO(NATCHARS) "\n"); +#endif + //printf("init size=%d ok\n", size); GLERR("initfont"); } diff --git a/config.cpp b/config.cpp index 380064dd..7cbc9888 100644 --- a/config.cpp +++ b/config.cpp @@ -1,3 +1,7 @@ +// Hyperbolic Rogue -- configuration + +// Copyright (C) 2017- Zeno Rogue, see 'hyper.cpp' for details + videopar vid; #if ISANDROID @@ -45,12 +49,9 @@ int lang() { return default_language; } -// Hyperbolic Rogue -- configuration - -// Copyright (C) 2017- Zeno Rogue, see 'hyper.cpp' for details - bool autojoy = true; +#if CAP_CONFIG struct supersaver { string name; virtual string save() = 0; @@ -128,6 +129,16 @@ template<> struct saver : dsaver { string save() { return ftssmart(val); } void load(const string& s) { val = atof(s.c_str()); } }; +#endif + +#if !CAP_CONFIG +template void addsaver(T& i, U name, V dft) { + i = dft; + } + +template void addsaver(T& i, U name) {} +template void addsaverenum(T& i, U name) {} +#endif void addsaver(charstyle& cs, string s) { addsaver(cs.charid, s + ".charid"); @@ -160,17 +171,6 @@ void initcs(charstyle &cs) { } #if CAP_CONFIG -void savecs(FILE *f, charstyle& cs, int xvernum) { - int gflags = cs.charid; - if(vid.samegender) gflags |= 16; - - fprintf(f, "%d %d %08x %08x %08x %08x", - gflags, vid.language, cs.skincolor, cs.haircolor, cs.swordcolor, cs.dresscolor); - if(cs.charid == 3) fprintf(f, " %08x", cs.dresscolor2); - if(xvernum >= 8990) fprintf(f, " %x", cs.uicolor); - fprintf(f, "\n"); - } - void loadcs(FILE *f, charstyle& cs, int xvernum) { int gflags, err = fscanf(f, "%d%d%x%x%x%x", &gflags, &vid.language, &cs.skincolor, &cs.haircolor, &cs.swordcolor, &cs.dresscolor); @@ -182,6 +182,7 @@ void loadcs(FILE *f, charstyle& cs, int xvernum) { if(xvernum >= 8990) if(fscanf(f, "%x", &cs.uicolor)) ; } +#endif void initConfig() { @@ -300,8 +301,10 @@ void initConfig() { addsaverenum(specialland, "land for special modes"); addsaver(viewdists, "expansion mode"); - - shmup::initConfig(); + +#if CAP_SHMUP + shmup::initConfig(); +#endif } void resetModes() { @@ -311,13 +314,16 @@ void resetModes() { if(chaosmode) restartGame('C'); if(purehepta) restartGame('7'); if(peace::on) restartGame('P'); +#if CAP_TOUR if(tour::on) restartGame('T'); +#endif if(yendor::on) restartGame('y'); if(tactic::on) restartGame('t'); if(randomPatternsMode) restartGame('r'); if(geometry != gNormal) { targetgeometry = gNormal; restartGame('g'); } } - + +#if CAP_CONFIG void resetConfig() { dynamicval rx(vid.xres, 0); dynamicval ry(vid.yres, 0); @@ -327,7 +333,9 @@ void resetConfig() { if(s->name.substr(0,5) != "mode-") s->reset(); } +#endif +#if CAP_CONFIG void saveConfig() { DEBB(DF_INIT, (debugfile,"save config\n")); FILE *f = fopen(conffile, "wt"); @@ -762,7 +770,9 @@ void showBasicConfig() { if(CAP_SHMUP && !ISMOBILE) dialog::addSelItem(XLAT("configure keys/joysticks"), "", 'p'); +#if CAP_CONFIG dialog::addItem(XLAT("reset all configuration"), 'R'); +#endif showAllConfig(); dialog::display(); @@ -800,7 +810,9 @@ void showBasicConfig() { if(uni == 'r') vid.revcontrol = !vid.revcontrol; if(xuni == 'd') vid.drawmousecircle = !vid.drawmousecircle; +#if CAP_CONFIG if(uni == 'R') pushScreen(resetConfigMenu); +#endif #if ISSTEAM if(xuni == 'l') vid.steamscore = vid.steamscore^1; @@ -1129,6 +1141,7 @@ void showCustomizeChar() { }; } +#if CAP_CONFIG void resetConfigMenu() { dialog::init(XLAT("reset all configuration")); dialog::addInfo("Are you sure?"); @@ -1158,7 +1171,9 @@ void resetConfigMenu() { }; } +#endif +#if CAP_TRANS void selectLanguageScreen() { gamescreen(4); dialog::init("select language"); // intentionally not translated @@ -1216,4 +1231,5 @@ void selectLanguageScreen() { popScreen(); }; } +#endif \ No newline at end of file diff --git a/control.cpp b/control.cpp index 5e2e5eb3..ece9fff0 100644 --- a/control.cpp +++ b/control.cpp @@ -33,10 +33,6 @@ ld modist, modist2, centdist; int lastt; -#if ISWEB -Uint8 *SDL_GetKeyState(void *v) { static Uint8 tab[1024]; return tab; } -#endif - bool mouseout() { if((getcstat != '-' && getcstat) || (lgetcstat && lgetcstat != '-')) return true; return outofmap(mouseh); @@ -521,7 +517,8 @@ void mainloopiter() { if(ev.type == SDL_VIDEOEXPOSE) { drawscreen(); } - + +#if CAP_JOY if(ev.type == SDL_JOYAXISMOTION && normal && DEFAULTCONTROL) { if(ev.jaxis.which == 0) { if(ev.jaxis.axis == 0) @@ -584,6 +581,7 @@ void mainloopiter() { else if(ev.type == SDL_JOYBUTTONDOWN && !normal) { sym = uni = SDLK_RETURN; } +#endif if(ev.type == SDL_KEYDOWN) { flashMessages(); diff --git a/hyperweb.cpp b/hyperweb.cpp index 85336e10..c893d15e 100644 --- a/hyperweb.cpp +++ b/hyperweb.cpp @@ -1,11 +1,11 @@ #define ISWEB 1 -#define MINI -#define NOAUDIO -#define NOGFX -#define NOPNG -#define DEMO -#define TOUR +#define ISMINI 1 +#define CAP_AUDIO 0 +#define CAP_SDLGFX 0 +#define CAP_PNG 0 +#define CAP_TOUR 1 #define CAP_SDLTTF 0 +#define CAP_SHMUP 0 #ifdef FAKEWEB void mainloopiter(); @@ -22,10 +22,90 @@ const char *wheresounds; #include "hyper.cpp" -void playSound(cell *c, const string& fname, int vol) { } +// -- demo -- + +bool demoanim; + +void toggleanim(bool v) { + demoanim = v; + if(v) { + sightrange = 4; + vid.wallmode = 5; + vid.particles = true; + vid.sspeed = -1; + vid.mspeed = -1; + geom3::highdetail = geom3::middetail = 5; + } + else { + sightrange = 7; + vid.sspeed = 5; + vid.mspeed = 5; + vid.particles = false; + vid.wallmode = 3; + geom3::highdetail = geom3::middetail = -1; + } + } + +void showDemo() { + gamescreen(2); + + getcstat = ' '; + + dialog::init(XLAT("HyperRogue %1: online demo", VER), 0xC00000, 200, 100); + dialog::addBreak(50); + + dialog::addItem(XLAT("play"), 'f'); + dialog::addItem(XLAT("tutorial"), 'T'); + dialog::addItem(XLAT("help"), 'h'); dialog::lastItem().keycaption += " / F1"; + dialog::addItem(XLAT("toggle high detail"), 'a'); + dialog::addBreak(100); + + dialog::addTitle("highlights", 0xC00000, 120); + dialog::addItem(XLAT("Temple of Cthulhu"), 't'); + dialog::addItem(XLAT("Land of Storms"), 'l'); + dialog::addItem(XLAT("Burial Grounds"), 'b'); + + dialog::display(); + + keyhandler = [] (int sym, int uni) { + dialog::handleNavigation(sym, uni); + if(sym == SDLK_F1 || sym == 'h') gotoHelp(help); + else if(sym == 'a') { + toggleanim(!demoanim); + popScreen(); + } + else if(sym == 'f') { + firstland = laIce; + if(tactic::on) restartGame('t'); + else restartGame(); + } +#if CAP_TOUR + else if(sym == 'T') { + firstland = laIce; + if(!tour::on) tour::start(); + } +#endif + else if(sym == 't') { + firstland = laTemple; + if(!tactic::on) restartGame('t'); + else restartGame(); + } + else if(sym == 'l') { + firstland = laStorms; + if(!tactic::on) restartGame('t'); + else restartGame(); + } + else if(sym == 'b') { + firstland = laBurial; + if(!tactic::on) restartGame('t'); + else restartGame(); + items[itOrbSword] = 60; + } + }; + } void initweb() { toggleanim(false); - cmode = emMenu; + // pushScreen(showDemo); } diff --git a/init.cpp b/init.cpp index 3c0a3069..751c806c 100644 --- a/init.cpp +++ b/init.cpp @@ -1,6 +1,6 @@ -#define VER "10.0g" -#define VERNUM 10007 -#define VERNUM_HEX 0xA007 +#define VER "10.0h" +#define VERNUM 10008 +#define VERNUM_HEX 0xA008 #define GEN_M 0 #define GEN_F 1 @@ -145,7 +145,9 @@ #define CAP_SDLJOY (CAP_SDL && !ISWEB) #endif +#ifndef CAP_SDLTTF #define CAP_SDLTTF (CAP_SDL && !ISMOBILE && !ISWEB) +#endif #define CAP_GLFONT (CAP_GL && !ISMOBILE) @@ -153,14 +155,26 @@ #define CAP_TABFONT (ISWEB) #endif +#ifndef CAP_CREATEFONT +#define CAP_CREATEFONT 0 +#endif + #ifndef CAP_FIXEDSIZE -#define CAP_FIXEDSIZE (CAP_CREATEFONT || CAP_TABLEFONT ? 36 : 0) +#define CAP_FIXEDSIZE (CAP_CREATEFONT || CAP_TABFONT ? 36 : 0) #endif #ifndef CAP_SHMUP #define CAP_SHMUP 1 #endif +#ifdef ISSTEAM +#define CAP_ACHIEVE 1 +#endif + +#ifndef CAP_ACHIEVE +#define CAP_ACHIEVE 0 +#endif + #ifndef CAP_SHMUP_GOOD #define CAP_SHMUP_GOOD (!ISMOBWEB) #endif @@ -239,6 +253,10 @@ void gdpush(int t); typedef int SDL_Event; #endif +#if ISWEB +inline Uint8 *SDL_GetKeyState(void *v) { static Uint8 tab[1024]; return tab; } +#endif + #ifndef CAP_GLEW #define CAP_GLEW (CAP_GL && !ISMOBILE && !ISMAC && !ISLINUX) #endif @@ -737,3 +755,4 @@ void mobile_draw(MOBPAR_FORMAL) { #if !CAP_AUDIO void playSound(cell*, const string &s, int vol) { printf("play sound: %s vol %d\n", s.c_str(), vol); } #endif + diff --git a/langen.cpp b/langen.cpp index 781f6cc0..a386d067 100644 --- a/langen.cpp +++ b/langen.cpp @@ -299,9 +299,10 @@ int main() { } printf("\n"); printf("#define NUMEXTRA %d\n", c); - printf("const char* natchars[NUMEXTRA] = {"); + printf("#define NATCHARS {"); for(int i=0; i 2) dialog::addItem(XLAT("configure player 3") + dsc(2), '3'); +#if CAP_JOY else if(vid.scfg.players == 1 && !shmupcfg && !shmupcfg && !multi::alwaysuse) dialog::addItem(XLAT("old style joystick configuration"), 'b'); +#endif else dialog::addBreak(100); if(vid.scfg.players > 3) dialog::addItem(XLAT("configure player 4") + dsc(3), '4'); @@ -274,11 +280,13 @@ void showShmupConfig() { dialog::addItem(XLAT("configure panning and general keys"), 'p'); else dialog::addBreak(100); +#if CAP_JOY if(numsticks > 0) { if(shmupcfg || multi::alwaysuse || vid.scfg.players > 1) dialog::addItem(XLAT("configure joystick axes"), 'j'); else dialog::addBreak(100); } +#endif if(multi::players > 1) dialog::addItem(XLAT("reset per-player statistics"), 'r'); @@ -343,9 +351,13 @@ void handleConfig(int sym, int uni) { else if(uni == '5') vid.scfg.subconfig = 6; else if(uni == '6') vid.scfg.subconfig = 7; else if(uni == '7') vid.scfg.subconfig = 8; +#if CAP_JOY else if(uni == 'j') vid.scfg.subconfig = SCJOY; +#endif else if(uni == 'a') multi::alwaysuse = !multi::alwaysuse; +#if CAP_JOY else if(uni == 'b') pushScreen(showJoyConfig); +#endif else if(uni == 'r') for(int i=0; i