From a423dbd2da4e407e050ab945ad93007406c7c024 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 9 Aug 2019 22:07:03 +0200 Subject: [PATCH] more header cleanup --- barriers.cpp | 6 +- commandline.cpp | 2 +- config.cpp | 2 +- control.cpp | 24 +- debug.cpp | 28 +- floorshapes.cpp | 4 +- game.cpp | 29 ++- geom-exp.cpp | 2 +- geometry.cpp | 2 +- graph.cpp | 58 ++--- hud.cpp | 2 +- hyper.cpp | 8 +- hyper.h | 656 +---------------------------------------------- hypgraph.cpp | 8 +- init.cpp | 2 +- inventory.cpp | 24 +- irregular.cpp | 47 ++-- landgen.cpp | 2 +- landlock.cpp | 50 ++-- language.cpp | 12 + orbgen.cpp | 25 +- orbs.cpp | 2 +- pattern2.cpp | 18 +- patterns.cpp | 8 +- quit.cpp | 2 +- renderbuffer.cpp | 33 +++ savemem.cpp | 2 +- screenshot.cpp | 8 +- shaders.cpp | 101 ++++++-- surface.cpp | 18 +- system.cpp | 20 +- textures.cpp | 134 +++++++++- 32 files changed, 487 insertions(+), 852 deletions(-) diff --git a/barriers.cpp b/barriers.cpp index 9459ea97..8199856e 100644 --- a/barriers.cpp +++ b/barriers.cpp @@ -4,7 +4,7 @@ namespace hr { -EX bool checkBarriersFront(cellwalker bb, int q, bool cross) { +EX bool checkBarriersFront(cellwalker bb, int q IS(5), bool cross IS(false)) { if(!ctof(bb.at)) return false; @@ -36,7 +36,7 @@ EX void preventbarriers(cell *c) { if(c && c->bardir == NODIR) c->bardir = NOBARRIERS; } -EX bool checkBarriersBack(cellwalker bb, int q, bool cross) { +EX bool checkBarriersBack(cellwalker bb, int q IS(5), bool cross IS(false)) { // printf("back, %p, s%d\n", bb.at, bb.spin); // if(mark) { printf("mpdist = %d [%d] bardir = %d spin=%d q=%d cross=%d\n", bb.at->mpdist, BARLEV, bb.at->bardir, bb.spin, q, cross); } @@ -811,7 +811,7 @@ EX bool buildBarrier3D(cell *c, eLand l2, int forced_dir) { } #endif -EX bool buildBarrierNowall(cell *c, eLand l2, int forced_dir) { +EX bool buildBarrierNowall(cell *c, eLand l2, int forced_dir IS(NODIR)) { if(geometry == gBinary4) return false; #if MAXMDIM >= 4 diff --git a/commandline.cpp b/commandline.cpp index b4a1d3f5..0b166d0f 100644 --- a/commandline.cpp +++ b/commandline.cpp @@ -4,7 +4,7 @@ namespace hr { #if CAP_COMMANDLINE -const char *scorefile = "hyperrogue.log"; +EX const char *scorefile = "hyperrogue.log"; namespace arg { eLand readland(const string& ss) { diff --git a/config.cpp b/config.cpp index 7f424da8..9ae0625e 100644 --- a/config.cpp +++ b/config.cpp @@ -24,7 +24,7 @@ EX videopar vid; extern color_t floorcolors[landtypes]; -charstyle& getcs(int id) { +EX charstyle& getcs(int id IS(multi::cpid)) { if(multi::players>1 && id >= 0 && id < multi::players) return multi::scs[id]; else diff --git a/control.cpp b/control.cpp index 5a6c04c7..8da06489 100644 --- a/control.cpp +++ b/control.cpp @@ -19,8 +19,8 @@ EX int getcstat, lgetcstat; ld getcshift; EX bool inslider; -function keyhandler = [] (int sym, int uni) {}; -function joyhandler = [] (SDL_Event &ev) {return false;}; +EX function keyhandler = [] (int sym, int uni) {}; +EX function joyhandler = [] (SDL_Event &ev) {return false;}; // is the player using mouse? (used for auto-cross) @@ -40,12 +40,12 @@ EX ld mouseaim_sensitivity = 0.01; EX int timetowait; #if CAP_SDLJOY -int joyx, joyy, panjoyx, panjoyy; -movedir joydir; +EX int joyx, joyy, panjoyx, panjoyy; +EX movedir joydir; #endif -movedir mousedest; -ld shiftmul = 1; +EX movedir mousedest; +EX ld shiftmul = 1; EX cell *mouseover, *mouseover2, *lmouseover; ld modist, modist2, centdist; @@ -181,8 +181,8 @@ EX void mousemovement() { } #if CAP_SDLJOY -SDL_Joystick* sticks[8]; -int numsticks; +EX SDL_Joystick* sticks[8]; +EX int numsticks; EX void initJoysticks() { DEBB(DF_INIT, ("init joysticks")); @@ -267,7 +267,7 @@ EX bool doexiton(int sym, int uni) { return false; } -bool didsomething; +EX bool didsomething; typedef SDL_Event eventtype; @@ -523,9 +523,13 @@ EX void handlekey(int sym, int uni) { keyhandler(sym, uni); } +EX void resize_screen_to(int x, int y); + #if !CAP_SDL EX void mainloopiter() { printf("(compiled without SDL -- no action)\n"); quitmainloop = true; } -#else +#endif + +#if CAP_SDL // Warning: a very long function! todo: refactor diff --git a/debug.cpp b/debug.cpp index d9834182..d6d7626e 100644 --- a/debug.cpp +++ b/debug.cpp @@ -3,10 +3,22 @@ namespace hr { -int steplimit = 0; -int cstep; +EX int steplimit = 0; +EX int cstep; -vector buggycells; +EX vector buggycells; + +#if HDR +template +void limitgen(T... args) { + if(steplimit) { + cstep++; + printf("%6d ", cstep); + printf(args...); + if(cstep == steplimit) buggyGeneration = true; + } + } +#endif cell *pathTowards(cell *pf, cell *pt) { @@ -302,7 +314,7 @@ template string dnameof2(T x, int p) { return s + " (" + its(x) + "/" + its(p) + ")"; } -vector > drawbugs; +EX vector > drawbugs; bool debugmode = false; @@ -456,14 +468,14 @@ struct debugScreen { } }; -void push_debug_screen() { +EX void push_debug_screen() { debugScreen ds; pushScreen(ds); } // -- cheat menu -- -void showCheatMenu() { +EX void showCheatMenu() { gamescreen(1); dialog::init("cheat menu"); dialog::addItem(XLAT("gain orb powers"), 'F'); @@ -505,7 +517,7 @@ void showCheatMenu() { }; } -void viewall() { +EX void viewall() { celllister cl(cwt.at, 20, 2000, NULL); vector all_monsters; @@ -540,7 +552,7 @@ void viewall() { } } -void modalDebug(cell *c) { +EX void modalDebug(cell *c) { viewctr.at = c->master; if(noGUI) { fprintf(stderr, "fatal: modalDebug called on %p without GUI\n", c); diff --git a/floorshapes.cpp b/floorshapes.cpp index 6a97e593..86587000 100644 --- a/floorshapes.cpp +++ b/floorshapes.cpp @@ -1,8 +1,8 @@ namespace hr { #if CAP_SHAPES -vector floor_texture_vertices; -renderbuffer *floor_textures; +EX vector floor_texture_vertices; +EX renderbuffer *floor_textures; void geometry_information::init_floorshapes() { all_escher_floorshapes.clear(); diff --git a/game.cpp b/game.cpp index 6c37da4d..6e41eddd 100644 --- a/game.cpp +++ b/game.cpp @@ -2924,8 +2924,8 @@ EX bool nogoSlow(cell *to, cell *from) { } // pathdist begin -cell *pd_from; -int pd_range; +EX cell *pd_from; +EX int pd_range; EX void onpath(cell *c, int d) { c->pathdist = d; @@ -3014,6 +3014,27 @@ EX void computePathdist(eMonster param) { } } } + +#if HDR +struct pathdata { + void checklock() { + if(pd_from) pd_from = NULL, clear_pathdata(); + if(pathlock) printf("path error\n"); + pathlock++; + } + ~pathdata() { + pathlock--; + clear_pathdata(); + } + pathdata(eMonster m) { + checklock(); + computePathdist(m); + } + pathdata(int i) { + checklock(); + } + }; +#endif // pathdist end vector > butterflies; @@ -5113,8 +5134,8 @@ EX void movemutant() { } } -__typeof(shpos) shpos; -int cshpos = 0; +EX vector> shpos; +EX int cshpos = 0; EX cell *lastmountpos[MAXPLAYER]; diff --git a/geom-exp.cpp b/geom-exp.cpp index 3ecd117c..ab80df4f 100644 --- a/geom-exp.cpp +++ b/geom-exp.cpp @@ -468,7 +468,7 @@ string current_proj_name() { return XLAT("general perspective"); } -void showEuclideanMenu() { +EX void showEuclideanMenu() { // for(int i=2; iwall == waMineMine) @@ -5017,7 +5017,7 @@ void drawcell_in_radar(cell *c, transmatrix V) { } #endif -void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) { +EX void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) { PROD( if(product::pmap) { product::drawcell_stack(c, V, spinv, mirrored); return; } ) @@ -6824,13 +6824,13 @@ EX void queuecircleat(cell *c, double rad, color_t col) { #define MOBON true #endif -cell *forwardcell() { +EX cell *forwardcell() { movedir md = vectodir(move_destination_vec(6)); cellwalker xc = cwt + md.d + wstep; return xc.at; } -void drawMarkers() { +EX void drawMarkers() { if(!(cmode & sm::NORMAL)) return; @@ -7092,7 +7092,7 @@ void drawFlashes() { #endif } -bool allowIncreasedSight() { +EX bool allowIncreasedSight() { if(cheater || autocheat) return true; if(peace::on) return true; #if CAP_TOUR @@ -7105,7 +7105,7 @@ bool allowIncreasedSight() { return false; } -bool allowChangeRange() { +EX bool allowChangeRange() { if(cheater || peace::on || randomPatternsMode) return true; #if CAP_TOUR if(tour::on) return true; @@ -7117,11 +7117,11 @@ bool allowChangeRange() { return false; } -purehookset hooks_drawmap; +EX purehookset hooks_drawmap; -transmatrix actual_view_transform; +EX transmatrix actual_view_transform; -ld wall_radar(cell *c, transmatrix T, ld max) { +EX ld wall_radar(cell *c, transmatrix T, ld max) { if(pmodel != mdPerspective || !vid.use_wall_radar) return max; ld step = max / 20; ld fixed_yshift = 0; @@ -7139,7 +7139,7 @@ ld wall_radar(cell *c, transmatrix T, ld max) { return fixed_yshift; } -void make_actual_view() { +EX void make_actual_view() { sphereflip = Id; if(sphereflipped()) sphereflip[DIM][DIM] = -1; actual_view_transform = sphereflip; @@ -7160,7 +7160,7 @@ void make_actual_view() { #endif } -transmatrix cview() { +EX transmatrix cview() { make_actual_view(); #if MAXMDIM >= 4 if(GDIM == 3 && WDIM == 2) { @@ -7182,7 +7182,7 @@ transmatrix cview() { return actual_view_transform * View; } -void precise_mouseover() { +EX void precise_mouseover() { if(WDIM == 3) { mouseover2 = mouseover = viewctr.at->c7; ld best = HUGE_VAL; @@ -7686,7 +7686,7 @@ EX void normalscreen() { vector< function > screens = { normalscreen }; -int cmode; +EX int cmode; EX void drawscreen() { @@ -7927,7 +7927,7 @@ EX void animateReplacement(cell *a, cell *b, int layer, int direction_hinta, int animateMovement(&c1, a, layer, direction_hintb); } -void drawBug(const cellwalker& cw, color_t col) { +EX void drawBug(const cellwalker& cw, color_t col) { #if CAP_SHAPES initquickqueue(); transmatrix V = ggmatrix(cw.at); diff --git a/hud.cpp b/hud.cpp index 2f4d6e00..ab1c7c07 100644 --- a/hud.cpp +++ b/hud.cpp @@ -86,7 +86,7 @@ void updatesort() { glyph_lastticks = ticks; } -void preparesort() { +EX void preparesort() { for(int i=0; i *hr::hooks_main; +namespace hr { +EX hookset *hooks_main; -int hyper_main(int argc, char **argv) { +EX int hyper_main(int argc, char **argv) { using namespace hr; #if ISWEB emscripten_get_commandline(); @@ -76,10 +77,11 @@ int hyper_main(int argc, char **argv) { profile_info(); return 0; } +} #ifndef NOMAIN int main(int argc, char **argv) { - return hyper_main(argc, argv); + return hr::hyper_main(argc, argv); } #endif #endif diff --git a/hyper.h b/hyper.h index c743ddb7..00c2ed02 100644 --- a/hyper.h +++ b/hyper.h @@ -1538,17 +1538,12 @@ void useup(cell *c); // useup thumpers/bonfires cell *playerpos(int i); bool makeflame(cell *c, int timeout, bool checkonly); -void bfs(); bool isPlayerInBoatOn(cell *c); bool isPlayerInBoatOn(cell *c, int i); void destroyBoats(cell *c, cell *cf, bool strandedToo); -extern bool showoff; extern int lastexplore; -extern int truelotus; extern int asteroids_generated, asteroid_orbs_generated; extern eLand lastland; -extern time_t timerstart; -extern bool timerstopped; bool againstRose(cell *cfrom, cell *cto); bool withRose(cell *cfrom, cell *cto); @@ -2004,18 +1999,7 @@ color_t darkena(color_t c, int lev, int a); #define SHSIZE 16 - -extern vector> shpos; -extern int cshpos; - -#if CAP_ANIMATIONS -namespace anims { - void animate_parameter(ld &x, string f, const reaction_t& r); - void deanimate(ld &x); - void get_parameter_animation(ld &x, string& f); - extern ld a, b; - } -#endif +namespace anims { void animate_parameter(ld &x, string f, const reaction_t& r); } extern bool timerghost; @@ -2211,35 +2195,9 @@ extern char mousekey; extern char newmousekey; void displaymm(char c, int x, int y, int rad, int size, const string& title, int align); -bool canPushThumperOn(cell *tgt, cell *thumper, cell *player); -void pushThumper(cell *th, cell *cto); - template T pick(T x, U... u) { std::initializer_list i = {x,u...}; return *(i.begin() + hrand(1+sizeof...(u))); } -eLand getNewSealand(eLand old); -bool createOnSea(eLand old); - -namespace inv { - extern bool on; - extern bool usedForbidden; - extern bool activating; - extern array remaining; - extern array usedup; - void compute(); - void applyBox(eItem it); - - extern int incheck; - void check(int delta); - void show(); - } - -bool drawItemType(eItem it, cell *c, const transmatrix& V, color_t icol, int ticks, bool hidden); - int darkenedby(int c, int lev); -extern int mousex, mousey; -#if CAP_MOUSEGRAB -extern ld mouseaim_x, mouseaim_y; -#endif extern ld mouseaim_sensitivity; string generateHelpForItem(eItem it); bool graphglyph(); @@ -2258,9 +2216,6 @@ template int addHook(hookset*& m, int prio, const U& hook) return 0; } -extern purehookset hooks_frame, hooks_stats, clearmemory, hooks_config, hooks_tests, hooks_removecells, hooks_initgame, hooks_calcparam, hooks_mainmenu, hooks_startmenu, hooks_markers; -extern purehookset hooks_swapdim; - template void callhooks(hookset *h, U... args) { if(h) for(auto& p: *h) p.second(args...); } @@ -2273,20 +2228,6 @@ template V callhandlers(V zero, hookset *h, U&. return zero; } -extern hookset *hooks_handleKey; -extern hookset *hooks_drawcell; -extern hookset *hooks_main; -extern hookset *hooks_args; -extern hookset *hooks_mark; -extern hookset *hooks_nextland; -extern hookset *hooks_welcome_message, *hooks_default_help; -extern hookset *hooks_mouseover; -extern hookset *hooks_newmap; - -extern ld shiftmul; -void initcs(charstyle &cs); -charstyle& getcs(int id = multi::cpid); - struct msginfo { int stamp; time_t rtstamp; @@ -2298,11 +2239,6 @@ struct msginfo { string msg; }; -extern vector msgs; -void flashMessages(); - -extern int lightat, safetyat; - int watercolor(int phase); bool doHighlight(); void buildHelpText(); @@ -2312,12 +2248,8 @@ bool quitsaves(); extern const char* COLORBAR; -int textwidth(int siz, const string &str); #define GLERR(call) glError(call, __FILE__, __LINE__) -extern bool gtouched, mousepressed, mousemoved, actonrelease; -extern bool inslider; - struct colortable: vector { color_t& operator [] (int i) { i %= size(); if(i<0) i += size(); return ((vector&)(*this)) [i]; } const color_t& operator [] (int i) const { i %= size(); if(i<0) i += size(); return ((vector&)(*this)) [i]; } @@ -2325,84 +2257,15 @@ struct colortable: vector { colortable() : vector({0}) {} }; -extern bool outoffocus; -extern int frames; -extern transmatrix playerV; -extern bool didsomething; -extern void drawStats(); -extern int calcfps(); -extern colortable distcolors, minecolors; - -extern eItem orbToTarget; -extern eMonster monsterToSummon; - -void panning(hyperpoint hf, hyperpoint ht); -extern transmatrix sphereflip; - -void initConfig(); -void loadConfig(); - -extern bool auraNOGL; - -#if CAP_SDLJOY -extern void initJoysticks(); -extern bool autojoy; -extern int joyx, joyy, panjoyx, panjoyy; -extern movedir joydir; -extern SDL_Joystick* sticks[8]; -extern int numsticks; -void closeJoysticks(); -#endif - -void preparesort(); - #define SHMUPTITLE "shoot'em up mode" -bool dodrawcell(cell *c); -void drawcell(cell *c, transmatrix V, int spinv, bool mirrored); -extern cell* straightDownSeek; -extern hyperpoint straightDownPoint; -extern ld straightDownSpeed; - -extern int frameid; -extern bool leftclick; -void clearMemory(); - -extern function keyhandler; -#if CAP_SDL -extern function joyhandler; -#endif -bool gmodekeys(int sym, int uni); - // check for a plain number key #define NUMBERKEY (interpret_as_direction(sym, uni) ? 0 : uni) #define DKEY (get_direction_key(sym, uni)) #define DIRECTIONKEY (interpret_as_direction(sym, uni) ? uni : 0) -bool interpret_as_direction(int sym, int uni); -int get_direction_key(int sym, int uni); - -void switchGL(); -void switchFullscreen(); -extern int cmode; - namespace scores { void load(); } -void gotoHelp(const string& h); -void showCustomizeChar(); -void showCheatMenu(); -void showGraphQuickKeys(); -void showChangeMode(); -void showEuclideanMenu(); -void show3D(); -void gameoverscreen(); -void showJoyConfig(); - -void gamescreen(int darken); -void showMission(); -void handleKeyQuit(int sym, int uni); -void handlePanning(int sym, int uni); - #if ISMOBILE==1 namespace leader { void showMenu(); void handleKey(int sym, int uni); } #endif @@ -2411,19 +2274,6 @@ namespace mirror { cellwalker reflect(const cellwalker& cw); } -bool inmirror(eLand l); -bool inmirror(cell *c); -bool inmirror(const cellwalker& cw); - -void check_total_victory(); -void applyBoxNum(int& i, string name = ""); -extern int hinttoshow; - -bool isShmupLifeOrb(eItem it); -int orbcharges(eItem it); - -color_t gradient(color_t c0, color_t c1, ld v0, ld v, ld v1); - struct hint { time_t last; function usable; @@ -2434,8 +2284,6 @@ struct hint { extern hint hints[]; int counthints(); -void gainShard(cell *c2, const char *msg); - int textwidth(int siz, const string &str); #if CAP_GL int gl_width(int size, const char *s); @@ -2447,22 +2295,6 @@ extern bool longclick; extern bool useRangedOrb; #endif -void addaura(hyperpoint h, color_t col, int fd); -void addauraspecial(hyperpoint h, color_t col, int dir); -void drawaura(); -void clearaura(); - -void drawBug(const cellwalker& cw, color_t col); - -void mainloop(); -void mainloopiter(); -extern bool showstartmenu; -void selectLanguageScreen(); - -bool inscreenrange(cell *c); -bool allowIncreasedSight(); -bool allowChangeRange(); - static inline bool orbProtection(eItem it) { return false; } // not implemented #if CAP_FIELD @@ -2479,70 +2311,10 @@ namespace windmap { extern int wavephase; -void buildEquidistant(cell *c); -void produceGhost(cell *c, eMonster victim, eMonster who); -void sideAttack(cell *mf, int dir, eMonster who, int bonus, eItem orb); -void sideAttack(cell *mf, int dir, eMonster who, int bonuskill); - -void orboflava(int i); - -void setland(cell *c, eLand l); - -eLand getNewLand(eLand old); - -extern bool randomPatternsMode; - -extern int isRandland(eLand l); - -extern vector buggycells; - -extern bool landUnlocked(eLand l); - -extern void describeCell(cell*); -extern bool rlyehComplete(); - -extern int steplimit, cstep; - -template -void limitgen(T... args) { - if(steplimit) { - cstep++; - printf("%6d ", cstep); - printf(args...); - if(cstep == steplimit) buggyGeneration = true; - } - } - -eLand oppositeElement(eLand l, eLand l2); - -extern int hardness_empty(); -extern eWall getElementalWall(eLand l); - -void gainItem(eItem it); - -void destroyTrapsOn(cell *c); -void destroyTrapsAround(cell *c); - -extern int messagelogpos; - -void showMessageLog(); - int getgametime(); string getgametime_s(int timespent = getgametime()); extern int stampbase; -transmatrix cellrelmatrix(cell *c, int i); - -void terracottaAround(cell *c); - -double cellgfxdist(cell *c, int i); - -int ctof(cell *c); - -void modalDebug(cell *c); -void push_debug_screen(); -int getDistLimit(); - #ifndef GL typedef float GLfloat; #endif @@ -2666,49 +2438,9 @@ extern int emeraldtable[100][7]; const eLand NOWALLSEP = laNone; const eLand NOWALLSEP_USED = laWhirlpool; -bool hasbardir(cell *c); - -bool buildBarrierNowall(cell *c, eLand l2, int forced_dir = NODIR); -bool checkBarriersBack(cellwalker bb, int q=5, bool cross = false); -bool checkBarriersFront(cellwalker bb, int q=5, bool cross = false); - -bool quickfind(eLand l); -void beCIsland(cell *c); -bool isOnCIsland(cell *c); -void generateTreasureIsland(cell *c); -bool openplains(cell *c); -void buildBigStuff(cell *c, cell *from); -void setLandQuotient(cell *c); -void setLandSphere(cell *c); -void setLandWeird(cell *c); -void moreBigStuff(cell *c); -void setLandEuclid(cell *c); -void setLandSol(cell *c); -void setLandNil(cell *c); -bool checkInTree(cell *c, int maxv); -cell *findcompass(cell *c); -int edgeDepth(cell *c); -int compassDist(cell *c); -void buildCamelot(cell *c); - #define HAUNTED_RADIUS getDistLimit() #define UNKNOWN 65535 -#if CAP_COMMANDLINE -extern const char *scorefile; -extern string levelfile; -extern string picfile; -extern const char *conffile; -extern const char *musicfile; -#endif - -extern string s0; -extern int anthraxBonus; -int celldistAlt(cell *c); -int celldist(cell *c); -int masterAlt(cell *c); -int getHemisphere(cell *c, int which); - namespace tactic { extern bool on; extern bool trailer; @@ -2798,16 +2530,6 @@ namespace princess { #define GRAIL_FOUND 0x4000 #define GRAIL_RADIUS_MASK 0x3FFF -int eudist(int sx, int sy); - -bool ishept(cell *c); -int cdist50(cell *c); -bool polarb50(cell *c); - -bool isGravityLand(eLand l); -bool isWarpedType(eLand l); -bool isWarped(cell *c); - struct hrmap { virtual heptagon *getOrigin() { return NULL; } virtual cell *gamestart() { return getOrigin()->c7; } @@ -2862,35 +2584,6 @@ struct hrmap_hyperbolic : hrmap_standard { void verify() override { verifycells(origin); } }; -namespace irr { - #if CAP_IRR - extern ld density; - extern ld quality; - extern int cellcount; - extern int place_attempts; - extern int rearrange_max_attempts; - extern int rearrange_less; - extern int irrid; - void link_to_base(heptagon *h, heptspin base); - void link_start(heptagon *h); - void link_next(heptagon *h, int d); - void may_link_next(heptagon *h, int d); - void link_cell(cell *c, int d); - void clear_links(heptagon *h); - bool pseudohept(cell*); - array get_masters(cell *c); - bool ctof(cell* c); - bool supports(eGeometry g); - void visual_creator(); - unsigned char density_code(); - int celldist(cell *c, bool alts); - extern int bitruncations_requested, bitruncations_performed; - #endif - } - -extern hrmap *currentmap; -extern vector allmaps; - // list all cells in distance at most maxdist, or until when maxcount cells are reached struct manual_celllister { @@ -2959,11 +2652,6 @@ int currfp_get_R(); int currfp_get_X(); #endif -const char *dnameof(eMonster m); -const char *dnameof(eLand l); -const char *dnameof(eWall w); -const char *dnameof(eItem i); - void runGeometryExperiments(); // z to close to this limit => do not draw @@ -3000,9 +2688,7 @@ bool haveMobileCompass(); bool handleCompass(); inline bool sphereflipped() { return sphere && vid.alpha > 1.1 && DIM == 3; } -bool hide_player(); int cellcolor(cell *c); -transmatrix screenpos(ld x, ld y); extern ld backbrightness; void initcells(); @@ -3023,22 +2709,12 @@ extern const char *musicfile; extern const char *loadlevel; #endif -transmatrix spin(ld alpha); -transmatrix xpush(ld alpha); -transmatrix inverse(const transmatrix&); -ld hdist(const hyperpoint& h1, const hyperpoint& h2); - extern bool fixseed; extern eLand firstland0; extern int startseed; // heptspin hsstep(const heptspin &hs, int spin); -extern void fixmatrix(transmatrix&); -transmatrix rgpushxto0(const hyperpoint& H); - -string its(int i); - ld hdist0(const hyperpoint& mh); extern bool fading; @@ -3051,8 +2727,6 @@ extern hookset *hooks_music; extern hookset *hooks_prestats; extern purehookset hooks_fixticks; -ld realradius(); - void sdltogl(SDL_Surface *txt, struct glfont_t& f, int ch); void showStartMenu(); @@ -3072,133 +2746,6 @@ int snake_pair(cell *c); extern colortable nestcolors; -#if CAP_TEXTURE -namespace texture { - enum eTextureState { - tsOff, tsAdjusting, tsActive - }; - - struct texture_data { - GLuint textureid; - - int twidth; - int tx, ty, origdim; - - texture_data() { textureid = 0; twidth = 2048; } - - vector texture_pixels; - - color_t& get_texture_pixel(int x, int y) { - return texture_pixels[(y&(twidth-1))*twidth+(x&(twidth-1))]; - } - - vector> undos; - vector > pixels_to_draw; - - bool loadTextureGL(); - bool whitetexture(); - bool readtexture(string tn); - void saveRawTexture(string tn); - - void undo(); - void undoLock(); - void update(); - }; - - struct texture_config { - string texturename; - string configname; - color_t paint_color; - eTextureState tstate; - eTextureState tstate_max; - - transmatrix itt; - - color_t grid_color; - color_t mesh_color; - color_t master_color; - color_t slave_color; - - int color_alpha; - - int gsplits; - - int recolor(color_t col); - - typedef tuple texture_parameters; - texture_parameters orig_texture_parameters; - - map texture_map, texture_map_orig; - set models; - - basic_textureinfo tinf3; - - bool texture_tuned; - string texture_tuner; - vector tuned_vertices; - - bool apply(cell *c, const transmatrix &V, color_t col); - void mark_triangles(); - - void clear_texture_map(); - void perform_mapping(); - void mapTextureTriangle(textureinfo &mi, const array& v, const array& tv, int splits); - void mapTextureTriangle(textureinfo &mi, const array& v, const array& tv) { mapTextureTriangle(mi, v, tv, gsplits); } - void mapTexture2(textureinfo& mi); - void finish_mapping(); - void true_remap(); - void remap(); - bool correctly_mapped; - hyperpoint texture_coordinates(hyperpoint); - - void drawRawTexture(); - void saveFullTexture(string tn); - - bool save(); - bool load(); - - texture_data data; - - texture_config() { - // argh, no member initialization in some of my compilers - texturename = "textures/hyperrogue-texture.png"; - configname = "textures/hyperrogue.txc"; - itt = Id; - paint_color = 0x000000FF; - grid_color = 0; - mesh_color = 0; - master_color = 0xFFFFFF30; - slave_color = 0xFF000008; - color_alpha = 128; - gsplits = 1; - texture_tuned = false; - } - - }; - - extern texture_config config; - - extern ld penwidth; - extern bool saving; - - void showMenu(); - - void drawPixel(cell *c, hyperpoint h, color_t col); - extern cell *where; - // compute 'c' automatically, based on the hint in 'where' - void drawPixel(hyperpoint h, color_t col); - void drawLine(hyperpoint h1, hyperpoint h2, color_t col, int steps = 10); - - extern bool texturesym; - - extern cpatterntype cgroup; - - extern bool texture_aura; - bool using_aura(); - void start_editor(); - } -#endif - unsigned char& part(color_t& col, int i); transmatrix applyPatterndir(cell *c, const patterns::patterninfo& si); @@ -3251,8 +2798,6 @@ void fullcenter(); void mainloop(); void clearAnimations(); -transmatrix rotmatrix(double rotation, int c0, int c1); - void destroycellcontents(cell *c); extern heptagon *last_cleared; @@ -3265,41 +2810,6 @@ template void eliminate_if(vector& data, U pred) { bool is_cell_removed(cell *c); void set_if_removed(cell*& c, cell *val); -struct renderbuffer { - bool valid; - int x, y; - - #if CAP_GL - int tx, ty; - GLuint FramebufferName; - GLuint renderedTexture; - GLuint depth_stencil_rb; - Uint32 *expanded_data; - void use_as_texture(); - #endif - #if CAP_SDL - SDL_Surface *srf; - void make_surface(); - SDL_Surface *render(); - #endif - - renderbuffer(int x, int y, bool gl); - ~renderbuffer(); - void enable(); - void clear(color_t col); - }; - -extern renderbuffer *floor_textures; - -struct resetbuffer { - GLint drawFboId, readFboId; - SDL_Surface *sreset; - resetbuffer(); - void reset(); - }; - -double randd(); - #if CAP_ORIENTATION transmatrix getOrientation(); #endif @@ -3338,28 +2848,6 @@ template array make_array(T a, T b) { array x; x[0] = a; x[1 extern const hyperpoint Hypc; -#if CAP_SURFACE -namespace surface { - - enum eShape { dsNone, dsTractricoid, dsDini, dsKuen, dsHyperlike, dsHyperboloid, dsHemisphere, dsCrystal }; - extern eShape sh; - void show_surfaces(); - void run_shape(eShape); - extern ld hyper_b, dini_b; - - } -#endif - -struct stringpar { - string v; - stringpar(string s) : v(s) { } - stringpar(const char* s) : v(s) { } - stringpar(eMonster m) { v= minf[m].name; } - stringpar(eLand l) { v= linf[l].name; } - stringpar(eWall w) { v= winf[w].name; } - stringpar(eItem i) { v= iinf[i].name; } - }; - namespace gp { typedef pair loc; @@ -3505,87 +2993,6 @@ template<> struct saver : dsaver { #endif -namespace glhr { - - struct glmatrix { - GLfloat a[4][4]; - GLfloat* operator[] (int i) { return a[i]; } - const GLfloat* operator[] (int i) const { return a[i]; } - GLfloat* as_array() { return a[0]; } - const GLfloat* as_array() const { return a[0]; } - }; - - enum class shader_projection { standard, band, halfplane, standardH3, standardR3, - standardS30, standardS31, standardS32, standardS33, - ball, halfplane3, band3, flatten, standardSolv, standardNil, - MAX - }; - - extern shader_projection new_shader_projection; - - glmatrix tmtogl(const transmatrix& T); - - void set_depthtest(bool b); - glmatrix translate(ld x, ld y, ld z); - void color2(color_t color, ld scale = 1); - void be_nontextured(shader_projection sp = new_shader_projection); - void be_textured(shader_projection sp = new_shader_projection); - void use_projection(shader_projection sp = new_shader_projection); - void set_modelview(const glmatrix& m); - hyperpoint gltopoint(const glvertex& t); - glvertex pointtogl(const hyperpoint& t); - - inline glvertex makevertex(GLfloat x, GLfloat y, GLfloat z) { - #if SHDIM == 3 - return make_array(x, y, z); - #else - return make_array(x, y, z, 1); - #endif - } - - struct colored_vertex { - glvertex coords; - glvec4 color; - colored_vertex(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b) { - coords[0] = x; - coords[1] = y; - coords[2] = current_display->scrdist; - coords[3] = 1; - color[0] = r; - color[1] = g; - color[2] = b; - color[3] = 1; - } - colored_vertex(hyperpoint h, color_t col) { - coords = pointtogl(h); - for(int i=0; i<4; i++) - color[i] = part(col, 3-i) / 255.0; - } - }; - - struct textured_vertex { - glvertex coords; - glvec2 texture; - }; - - struct ct_vertex { - glvertex coords; - glvec4 color; - glvec2 texture; - ct_vertex(const hyperpoint& h, ld x1, ld y1, ld col) { - coords = pointtogl(h); - texture[0] = x1; - texture[1] = y1; - color[0] = color[1] = color[2] = col; - color[3] = 1; - } - }; - - void prepare(vector& v); - void prepare(vector& v); - void prepare(vector& v); - } - #if CAP_SHAPES struct floorshape; @@ -3613,26 +3020,6 @@ struct hpcshape { extern vector shPlainWall3D, shWireframe3D, shWall3D, shMiniWall3D; #endif -cell *newCell(int type, heptagon *master); -extern color_t qpixel_pixel_outside; - -int zebra3(cell *c); -int geosupport_threecolor(); -int geosupport_football(); -bool geosupport_chessboard(); -bool ishex1(cell *c); -namespace fieldpattern { int fieldval_uniq(cell *c); int fieldval_uniq_rand(cell *c, int d); } -bool warptype(cell *c); -bool horo_ok(); -bool deep_ocean_at(cell *c, cell *from); -int wallchance(cell *c, bool deepOcean); - -ld master_to_c7_angle(); - -void resize_screen_to(int x, int y); -extern bool canvas_invisible; -extern cell *pd_from; - namespace daily { extern bool on; extern int daily_id; @@ -3647,27 +3034,6 @@ namespace daily { void uploadscore(bool really_final); } -enum eOrbLandRelation { - olrForbidden, // never appears: forbidden - olrDangerous, // never appears: would be dangerous - olrUseless, // never appears: useless here - olrNoPrizes, // no prizes in this land - olrNoPrizeOrb,// orb not allowed as a prize - olrPrize25, // prize for collecting 25 - olrPrize3, // prize for collecting 3 - olrNative, // native orb in this land - olrNative1, // native orb in this land (1) - olrGuest, // extra orb in this land - olrPNative, // Land of Power: native - olrPBasic, // Land of Power: basic orbs - olrPPrized, // Land of Power: prized orbs - olrPNever, // Land of Power: foreign orbs - olrHub, // hub lands - olrMonster, // available from a monster - olrAlways, // always available - olrBurns // burns - }; - namespace torusconfig { extern int sdx, sdy; @@ -3731,7 +3097,6 @@ namespace fieldpattern { #endif bool incompatible(eLand l1, eLand l2); -eOrbLandRelation getOLR(eItem it, eLand l); struct plainshape; void clear_plainshape(plainshape& gsh); @@ -4127,25 +3492,6 @@ extern void computePathdist(eMonster m); extern void onpath(cell *c, int d); extern void clear_pathdata(); -struct pathdata { - void checklock() { - if(pd_from) pd_from = NULL, clear_pathdata(); - if(pathlock) printf("path error\n"); - pathlock++; - } - ~pathdata() { - pathlock--; - clear_pathdata(); - } - pathdata(eMonster m) { - checklock(); - computePathdist(m); - } - pathdata(int i) { - checklock(); - } - }; - extern int timetowait; #define RING(i) for(double i=0; i<=cgi.S84+1e-6; i+=SD3 * pow(.5, vid.linequality)) diff --git a/hypgraph.cpp b/hypgraph.cpp index f76919c8..900e6668 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -851,11 +851,11 @@ ld spherity(const transmatrix& V) { return spherity(tC0(V)); } -bool confusingGeometry() { +EX bool confusingGeometry() { return quotient; } -ld master_to_c7_angle() { +EX ld master_to_c7_angle() { ld alpha = 0; #if CAP_GP if(cgi.gpdata) alpha = cgi.gpdata->alpha; @@ -863,7 +863,7 @@ ld master_to_c7_angle() { return (!BITRUNCATED && !binarytiling && !archimedean) ? M_PI + alpha : 0; } -transmatrix actualV(const heptspin& hs, const transmatrix& V) { +EX transmatrix actualV(const heptspin& hs, const transmatrix& V) { if(WDIM == 3) return V; #if CAP_IRR if(IRREGULAR) @@ -1406,7 +1406,7 @@ EX void resetview() { } -void panning(hyperpoint hf, hyperpoint ht) { +EX void panning(hyperpoint hf, hyperpoint ht) { View = rgpushxto0(hf) * rgpushxto0(gpushxto0(hf) * ht) * gpushxto0(hf) * View; playermoved = false; diff --git a/init.cpp b/init.cpp index 6a76bc27..e7bae558 100644 --- a/init.cpp +++ b/init.cpp @@ -10,7 +10,7 @@ EX int fontscale = 100; EX int debugflags = DF_INIT | DF_ERROR | DF_WARN | DF_MSG | DF_TIME | DF_LOG; -string s0; +EX string s0; EX bool fixseed = false; EX int startseed = 0; diff --git a/inventory.cpp b/inventory.cpp index 431037ad..fcdf171f 100644 --- a/inventory.cpp +++ b/inventory.cpp @@ -1,18 +1,20 @@ // Hyperbolic Rogue -- Orb Strategy Mode // Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details -namespace hr { namespace inv { +namespace hr { - bool on; - array usedup; - array remaining; +EX namespace inv { + + EX bool on; + EX array usedup; + EX array remaining; array extra_orbs; int rseed; - bool usedForbidden; + EX bool usedForbidden; - void init() { + EX void init() { rseed = hrandpos(); usedForbidden = false; for(int i=0; i= at ? (its(at)+"!") : "10-50"); } - void compute() { + EX void compute() { extra = ""; orbinfoline = ""; @@ -445,9 +447,9 @@ namespace hr { namespace inv { return s; } - bool activating; + EX bool activating; - void show() { + EX void show() { if(remaining[itOrbSword]) items[itOrbSword]++; if(remaining[itOrbSword2]) items[itOrbSword2]++; @@ -652,9 +654,9 @@ namespace hr { namespace inv { } #endif - int incheck; + EX int incheck; - void check(int delta) { + EX void check(int delta) { incheck += delta; for(int i=0; i periodmap; -void link_to_base(heptagon *h, heptspin base) { +EX void link_to_base(heptagon *h, heptspin base) { // printf("linking %p to %p/%d\n", h, base.at, base.spin); auto &hi = periodmap[h]; hi.base = base; @@ -562,7 +565,7 @@ void link_to_base(heptagon *h, heptspin base) { h->c7 = hi.subcells[0]; } -void clear_links(heptagon *h) { +EX void clear_links(heptagon *h) { auto& hi = periodmap[h]; for(cell *c: hi.subcells) { for(int i=0; itype; i++) if(c->move(i)) c->move(i)->move(c->c.spin(i)) = NULL; @@ -573,11 +576,11 @@ void clear_links(heptagon *h) { periodmap.erase(h); } -void link_start(heptagon *h) { +EX void link_start(heptagon *h) { link_to_base(h, heptspin(cells[0].owner->master, 0)); } -void link_next(heptagon *parent, int d) { +EX void link_next(heptagon *parent, int d) { if(!periodmap.count(parent)) link_to_base(parent, heptspin(cells[0].owner->master, 0)); // printf("linking next: %p direction %d [s%d]\n", parent, d, parent->c.spin(d)); @@ -586,13 +589,13 @@ void link_next(heptagon *parent, int d) { link_to_base(h, hs); } -void may_link_next(heptagon *parent, int d) { +EX void may_link_next(heptagon *parent, int d) { if(!periodmap.count(parent->move(d))) link_next(parent, d); } -void link_cell(cell *c, int d) { +EX void link_cell(cell *c, int d) { // printf("linking cell: %p direction %d\n", c, d); int ci = cellindex[c]; auto& sc = cells[ci]; @@ -775,7 +778,7 @@ void compute_horocycle(heptagon *alt) { last_on_horocycle[alt] = *(hs[LOOKUP/2].begin()); } -int celldist(cell *c, bool alts) { +EX int celldist(cell *c, bool alts) { heptagon *master = c->master; auto &hi = periodmap[master]; /* if(alts && master->alt->alt->s != hsOrigin && isize(hi.celldists[alts]) == 0) { @@ -968,7 +971,7 @@ void show_gridmaker() { }; } -void visual_creator() { +EX void visual_creator() { stop_game(); orig_geometry = geometry; switch(geometry) { @@ -1044,7 +1047,7 @@ int readArgs() { } #endif -unsigned char density_code() { +EX unsigned char density_code() { if(isize(cells) < 128) return isize(cells); else { int t = 127, a = isize(cells); @@ -1053,19 +1056,19 @@ unsigned char density_code() { } } -bool pseudohept(cell* c) { +EX bool pseudohept(cell* c) { return cells[cellindex[c]].is_pseudohept; } -bool ctof(cell* c) { +EX bool ctof(cell* c) { return cells[cellindex[c]].patterndir == -1; } -bool supports(eGeometry g) { +EX bool supports(eGeometry g) { return among(g, gNormal, gKleinQuartic, gOctagon, gBolza2, gFieldQuotient, gSphere, gSmallSphere, gTinySphere); } -array get_masters(cell *c) { +EX array get_masters(cell *c) { int d = cells[cellindex[c]].patterndir; heptspin s = periodmap[c->master].base; heptspin s0 = heptspin(c->master, 0) + (d - s.spin); diff --git a/landgen.cpp b/landgen.cpp index 237a8822..81c04ecb 100644 --- a/landgen.cpp +++ b/landgen.cpp @@ -12,7 +12,7 @@ eLand lastland; int lastexplore; -bool randomPatternsMode = false; +EX bool randomPatternsMode = false; EX int randompattern[landtypes]; int genrange_bonus = 0; diff --git a/landlock.cpp b/landlock.cpp index 0c2166e1..2938edde 100644 --- a/landlock.cpp +++ b/landlock.cpp @@ -5,7 +5,7 @@ namespace hr { -bool nodisplay(eMonster m) { +EX bool nodisplay(eMonster m) { return m == moIvyDead || m == moDragonTail || @@ -15,7 +15,7 @@ bool nodisplay(eMonster m) { } // returns: 2 = treasure increaser, 1 = just appears, 0 = does not appear -int isNative(eLand l, eMonster m) { +EX int isNative(eLand l, eMonster m) { switch(l) { #define LAND(a,b,c,d,e,f,g) case c: #define NATIVE(x) return x; @@ -28,13 +28,13 @@ int isNative(eLand l, eMonster m) { EX eItem treasureType(eLand l) { return linf[l].treasure; } -eItem treasureTypeUnlock(eLand l, eItem u) { +EX eItem treasureTypeUnlock(eLand l, eItem u) { if(u != itOrbLove && l == laPrincessQuest) return itPalace; return treasureType(l); } -eLand landof(eItem it) { +EX eLand landof(eItem it) { for(int i=0; i= 10); @@ -84,7 +84,7 @@ int variant_unlock_value() { return inv::on ? 75 : 30; } -bool landUnlocked(eLand l) { +EX bool landUnlocked(eLand l) { if(randomPatternsMode) { return landUnlockedRPM(l); } @@ -116,7 +116,7 @@ bool landUnlocked(eLand l) { return false; } -void countHyperstoneQuest(int& i1, int& i2) { +EX void countHyperstoneQuest(int& i1, int& i2) { i1 = 0; i2 = 0; generateLandList(isLandIngame); for(eLand l: landlist) if(l != laCamelot && l != laPrincessQuest) { @@ -127,7 +127,7 @@ void countHyperstoneQuest(int& i1, int& i2) { } } -bool hyperstonesUnlocked() { +EX bool hyperstonesUnlocked() { int i1, i2; if(tactic::on && isCrossroads(specialland) && !tactic::trailer) return true; countHyperstoneQuest(i1, i2); @@ -135,14 +135,14 @@ bool hyperstonesUnlocked() { } // 2 = always available, 1 = highscore required, 0 = never available -int isRandland(eLand l) { +EX int isRandland(eLand l) { if(l == laIce || l == laDesert || l == laCaves || l == laWildWest || l == laDocks) return 2; for(eLand ll: randlands) if(l == ll) return 1; return 0; } -bool incompatible1(eLand l1, eLand l2) { +EX bool incompatible1(eLand l1, eLand l2) { if(isCrossroads(l1) && isCrossroads(l2)) return true; if(l1 == laJungle && l2 == laMotion) return true; if(l1 == laMirrorOld && l2 == laMotion) return true; @@ -165,18 +165,18 @@ bool incompatible1(eLand l1, eLand l2) { return false; } -eLand randomElementalLand() { +EX eLand randomElementalLand() { int i = hrand(4); eLand t[4] = { laEFire, laEWater, laEAir, laEEarth }; return t[i]; } -int elementalKills() { +EX int elementalKills() { return kills[moAirElemental] + kills[moWaterElemental] + kills[moEarthElemental] + kills[moFireElemental]; } -eLand randomElementalLandWeighted() { +EX eLand randomElementalLandWeighted() { int i = hrand(elementalKills()); i -= kills[moAirElemental]; if(i<0) return laEAir; i -= kills[moWaterElemental]; if(i<0) return laEWater; @@ -186,11 +186,11 @@ eLand randomElementalLandWeighted() { return laElementalWall; } -bool incompatible(eLand nw, eLand old) { +EX bool incompatible(eLand nw, eLand old) { return (nw == old) || incompatible1(nw, old) || incompatible1(old, nw); } -bool rlyehComplete() { +EX bool rlyehComplete() { if(chaosmode) return items[itStatue] >= 1; return items[itStatue] >= 10 || items[itGrimoire] >= 10; } @@ -209,7 +209,7 @@ eLand pickLandRPM(eLand old) { } } -eLand pickluck(eLand l1, eLand l2) { +EX eLand pickluck(eLand l1, eLand l2) { int t1 = items[treasureType(l1)]; int t2 = items[treasureType(l2)]; if(t1 < t2) return l1; @@ -229,7 +229,7 @@ eLand pickluck(eLand l1, eLand l2) { l == laPrairie || l == laHalloween; } */ -eLand getNewSealand(eLand old) { +EX eLand getNewSealand(eLand old) { while(true) { eLand p = pick(laOcean, pick(laCaribbean, laLivefjord, laWarpSea, laKraken, laDocks)); if(p == laKraken && !landUnlocked(p)) continue; @@ -241,7 +241,7 @@ eLand getNewSealand(eLand old) { } } -bool createOnSea(eLand old) { +EX bool createOnSea(eLand old) { return old == laWarpSea || old == laCaribbean || old == laKraken || (old == laLivefjord && hrand(2)) || @@ -249,9 +249,9 @@ bool createOnSea(eLand old) { (old == laOcean && (chaosmode ? hrand(2) : !generatingEquidistant)); } -hookset *hooks_nextland; +EX hookset *hooks_nextland; -eLand getNewLand(eLand old) { +EX eLand getNewLand(eLand old) { if(old == laMirror && !chaosmode && hrand(10) >= ((tactic::on || racing::on) ? 0 : markOrb(itOrbLuck) ? 5 : 2)) return laMirrored; if(old == laTerracotta && !chaosmode && hrand(5) >= ((tactic::on || racing::on) ? 0 : markOrb(itOrbLuck) ? 2 : 1) && !weirdhyperbolic) return laTerracotta; @@ -557,7 +557,7 @@ template void generateLandList(T t) { for(auto l: land_over) if(t(l)) landlist.push_back(l); } -eLand getLandForList(cell *c) { +EX eLand getLandForList(cell *c) { eLand l = c->land; if(isElemental(l)) return laElementalWall; if(l == laWarpSea) return laWarpCoast; @@ -570,7 +570,7 @@ eLand getLandForList(cell *c) { return l; } -bool isLandIngame(eLand l) { +EX bool isLandIngame(eLand l) { if(isElemental(l)) l = laElementalWall; if(dual::state == 2 && !dual::check_side(l)) return false; if((euclid || sol) && isCyclic(l) && l != specialland) return false; @@ -653,7 +653,7 @@ int old_daily_id = 1000000; const int landscapes_when = 1000; // check if the given land should appear in lists -land_validity_t& land_validity(eLand l) { +EX land_validity_t& land_validity(eLand l) { using namespace lv; diff --git a/language.cpp b/language.cpp index 0d26836a..338593f7 100644 --- a/language.cpp +++ b/language.cpp @@ -12,6 +12,18 @@ EX const char *dnameof(eLand l) { return linf[l].name; } EX const char *dnameof(eWall w) { return winf[w].name; } EX const char *dnameof(eItem i) { return iinf[i].name; } +#if HDR +struct stringpar { + string v; + stringpar(string s) : v(s) { } + stringpar(const char* s) : v(s) { } + stringpar(eMonster m) { v= minf[m].name; } + stringpar(eLand l) { v= linf[l].name; } + stringpar(eWall w) { v= winf[w].name; } + stringpar(eItem i) { v= iinf[i].name; } + }; +#endif + /* string dnameofEnum(eItem i) { FILE *f = fopen("classes.cpp", "rt"); diff --git a/orbgen.cpp b/orbgen.cpp index 68c1c87f..34c5bd34 100644 --- a/orbgen.cpp +++ b/orbgen.cpp @@ -4,6 +4,29 @@ namespace hr { // orbgen flags +#if HDR +enum eOrbLandRelation { + olrForbidden, // never appears: forbidden + olrDangerous, // never appears: would be dangerous + olrUseless, // never appears: useless here + olrNoPrizes, // no prizes in this land + olrNoPrizeOrb,// orb not allowed as a prize + olrPrize25, // prize for collecting 25 + olrPrize3, // prize for collecting 3 + olrNative, // native orb in this land + olrNative1, // native orb in this land (1) + olrGuest, // extra orb in this land + olrPNative, // Land of Power: native + olrPBasic, // Land of Power: basic orbs + olrPPrized, // Land of Power: prized orbs + olrPNever, // Land of Power: foreign orbs + olrHub, // hub lands + olrMonster, // available from a monster + olrAlways, // always available + olrBurns // burns + }; +#endif + namespace orbgenflags { // generates in the given land from 10 treasures, in the classic mode static const int LOCAL10 = 1; @@ -171,7 +194,7 @@ string olrDescriptions[] = { "would be destroyed in %the1" }; -eOrbLandRelation getOLR(eItem it, eLand l) { +EX eOrbLandRelation getOLR(eItem it, eLand l) { if(l == laPower) { if(it == itOrbFire) return olrPNative; diff --git a/orbs.cpp b/orbs.cpp index eb1febea..4c4af43c 100644 --- a/orbs.cpp +++ b/orbs.cpp @@ -1458,7 +1458,7 @@ EX void makelava(cell *c, int i) { else if(makeflame(c, i, false)) orbused[itOrbLava] = true; } -void orboflava(int i) { +EX void orboflava(int i) { if(items[itOrbLava]) for(cell *c: dcal) { if(c->cpdist > 5) break; diff --git a/pattern2.cpp b/pattern2.cpp index 8d2a9d8c..fa324427 100644 --- a/pattern2.cpp +++ b/pattern2.cpp @@ -146,7 +146,7 @@ int land50(cell *c) { } } -bool polara50(cell *c) { +EX bool polara50(cell *c) { if(sphere || euclid || S7>7 || S6>6) return false; else if(NONSTDVAR) return polara50(fiftyval(c->master->c7)); else if(ctof(c)) return polara50(fiftyval(c)); @@ -158,7 +158,7 @@ bool polara50(cell *c) { } } -bool polarb50(cell *c) { +EX bool polarb50(cell *c) { if(euclid) return true; if(sphere || euclid || S7>7 || S6>6) return true; else if(NONSTDVAR) return polarb50(fiftyval(c->master->c7)); @@ -175,7 +175,7 @@ int elhextable[28][3] = { {0,1,2}, {1,2,9}, {1,9,-1}, {1,8,-1}, {1,-1,-1} }; -int fiftyval049(heptagon *h) { +EX int fiftyval049(heptagon *h) { int i = h->fiftyval / 32; if(i <= 7) return i; if(quotient) return 0; @@ -191,7 +191,7 @@ int fiftyval049(heptagon *h) { return allcodes[0] + 7; } -int fiftyval049(cell *c) { +EX int fiftyval049(cell *c) { if(euclid) return fiftyval(c) / 32; else if(ctof(c)) return fiftyval049(c->master); else if(sphere) return 0; @@ -228,7 +228,7 @@ int fiftyval049(cell *c) { } } -int fiftyval200(cell *c) { +EX int fiftyval200(cell *c) { int i = fiftyval049(c); i *= 4; if(polara50(c)) i|=1; @@ -324,7 +324,7 @@ EX int zebra40(cell *c) { } } -int zebra3(cell *c) { +EX int zebra3(cell *c) { if(ctof(c)) return (c->master->zebraval/10)/4; else if(euclid || sphere || S7>7 || S6>6) return 0; else { @@ -1120,7 +1120,7 @@ namespace patterns { } -bool geosupport_chessboard() { +EX bool geosupport_chessboard() { return #if CAP_ARCM (archimedean && PURE) ? arcm::current.support_chessboard() : @@ -1130,7 +1130,7 @@ bool geosupport_chessboard() { (VALENCE % 2 == 0); } -int geosupport_threecolor() { +EX int geosupport_threecolor() { if(IRREGULAR) return 0; if(penrose || binarytiling) return 0; #if CAP_ARCM @@ -1149,7 +1149,7 @@ int geosupport_threecolor() { return 0; } -int geosupport_football() { +EX int geosupport_football() { // always works in bitrunc geometries if(BITRUNCATED) return 2; if(binarytiling || penrose) return 0; diff --git a/patterns.cpp b/patterns.cpp index c153985c..4fb3646f 100644 --- a/patterns.cpp +++ b/patterns.cpp @@ -1027,13 +1027,13 @@ int nextfiftyval(int par, int gpar, int d) { exit(1); } -int land50(int x) { return x&7; } +EX int land50(int x) { return x&7; } -bool polara50(int x) { return x&8; } +EX bool polara50(int x) { return x&8; } -bool polarb50(int x) { return x&16; } +EX bool polarb50(int x) { return x&16; } -int cdist50(int x) { +EX int cdist50(int x) { x /= 32; if(x == 0) return 0; if(x < 8) return 2; diff --git a/quit.cpp b/quit.cpp index d3f25e93..77e0c8e3 100644 --- a/quit.cpp +++ b/quit.cpp @@ -274,7 +274,7 @@ hint hints[] = { {-1, []() { return false; }, noaction, noaction} }; -int hinttoshow; +EX int hinttoshow; string contstr() { return XLAT(canmove ? "continue" : "see how it ended"); diff --git a/renderbuffer.cpp b/renderbuffer.cpp index 2847b4af..3feec70e 100644 --- a/renderbuffer.cpp +++ b/renderbuffer.cpp @@ -31,6 +31,39 @@ GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers) #endif #endif +#if HDR +struct renderbuffer { + bool valid; + int x, y; + + #if CAP_GL + int tx, ty; + GLuint FramebufferName; + GLuint renderedTexture; + GLuint depth_stencil_rb; + Uint32 *expanded_data; + void use_as_texture(); + #endif + #if CAP_SDL + SDL_Surface *srf; + void make_surface(); + SDL_Surface *render(); + #endif + + renderbuffer(int x, int y, bool gl); + ~renderbuffer(); + void enable(); + void clear(color_t col); + }; + +struct resetbuffer { + GLint drawFboId, readFboId; + SDL_Surface *sreset; + resetbuffer(); + void reset(); + }; +#endif + renderbuffer::renderbuffer(int x, int y, bool gl) : x(x), y(y) { valid = false; diff --git a/savemem.cpp b/savemem.cpp index fcd20f84..050fe5e5 100644 --- a/savemem.cpp +++ b/savemem.cpp @@ -167,7 +167,7 @@ void save_memory() { removed_cells.clear(); } -purehookset hooks_removecells; +EX purehookset hooks_removecells; bool is_cell_removed(cell *c) { return binary_search(removed_cells.begin(), removed_cells.end(), c); diff --git a/screenshot.cpp b/screenshot.cpp index 2e982b5d..9f002a5d 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -529,19 +529,19 @@ struct animated_parameter { vector aps; -void deanimate(ld &x) { +EX void deanimate(ld &x) { for(int i=0; i(x, y, z, 1); + #endif + } + + struct colored_vertex { + glvertex coords; + glvec4 color; + colored_vertex(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b) { + coords[0] = x; + coords[1] = y; + coords[2] = current_display->scrdist; + coords[3] = 1; + color[0] = r; + color[1] = g; + color[2] = b; + color[3] = 1; + } + colored_vertex(hyperpoint h, color_t col) { + coords = pointtogl(h); + for(int i=0; i<4; i++) + color[i] = part(col, 3-i) / 255.0; + } + }; + + struct textured_vertex { + glvertex coords; + glvec2 texture; + }; + + struct ct_vertex { + glvertex coords; + glvec4 color; + glvec2 texture; + ct_vertex(const hyperpoint& h, ld x1, ld y1, ld col) { + coords = pointtogl(h); + texture[0] = x1; + texture[1] = y1; + color[0] = color[1] = color[2] = col; + color[3] = 1; + } + }; + +#endif #if CAP_SHADER bool noshaders = false; @@ -62,7 +127,7 @@ flagtype flags[gmMAX] = { 0, GF_TEXTURE, GF_VARCOLOR, GF_TEXTURE | GF_LIGHTFOG | eMode mode; -shader_projection current_shader_projection, new_shader_projection; +EX shader_projection current_shader_projection, new_shader_projection; void switch_mode(eMode m, shader_projection sp); @@ -99,7 +164,7 @@ glmatrix scale(ld x, ld y, ld z) { return tmp; } -glmatrix tmtogl(const transmatrix& T) { +EX glmatrix tmtogl(const transmatrix& T) { glmatrix tmp; for(int i=0; i<4; i++) for(int j=0; j<4; j++) @@ -133,7 +198,7 @@ glmatrix frustum(ld x, ld y, ld vnear = 1e-3, ld vfar = 1e9) { return as_glmatrix(frustum); } -glmatrix translate(ld x, ld y, ld z) { +EX glmatrix translate(ld x, ld y, ld z) { glmatrix tmp; for(int i=0; i<4; i++) for(int j=0; j<4; j++) @@ -330,7 +395,7 @@ bool operator != (const glmatrix& m1, const glmatrix& m2) { bool uses_mvp(shader_projection sp) { return among(sp, shader_projection::standard, shader_projection::flatten); } -void set_modelview(const glmatrix& modelview) { +EX void set_modelview(const glmatrix& modelview) { #if CAP_NOSHADER if(noshaders) { glMatrixMode(GL_MODELVIEW); @@ -378,7 +443,7 @@ void id_modelview() { glUniformMatrix4fv(current->uMVP, 1, 0, projection.as_array()); } -void color2(color_t color, ld scale) { +EX void color2(color_t color, ld scale IS(1)) { GLfloat cols[4]; for(int i=0; i<4; i++) cols[i] = part(color, 3-i) / 255.0 * scale; @@ -396,9 +461,9 @@ void colorClear(color_t color) { glClearColor(part(color, 3) / 255.0, part(color, 2) / 255.0, part(color, 1) / 255.0, part(color, 0) / 255.0); } -void be_nontextured(shader_projection sp) { switch_mode(gmColored, sp); } -void be_textured(shader_projection sp) { switch_mode(gmTextured, sp); } -void use_projection(shader_projection sp) { switch_mode(mode, sp); } +EX void be_nontextured(shader_projection sp IS(new_shader_projection)) { switch_mode(gmColored, sp); } +EX void be_textured(shader_projection sp IS(new_shader_projection)) { switch_mode(gmTextured, sp); } +EX void use_projection(shader_projection sp IS(new_shader_projection)) { switch_mode(mode, sp); } void switch_mode(eMode m, shader_projection sp) { if(m == mode && current_shader_projection == sp) return; @@ -713,14 +778,14 @@ void init() { #endif } -hyperpoint gltopoint(const glvertex& t) { +EX hyperpoint gltopoint(const glvertex& t) { hyperpoint h; h[0] = t[0]; h[1] = t[1]; h[2] = t[2]; if(SHDIM == 4 && MAXMDIM == 4) h[3] = t[3]; return h; } -glvertex pointtogl(const hyperpoint& t) { +EX glvertex pointtogl(const hyperpoint& t) { glvertex h; h[0] = t[0]; h[1] = t[1]; h[2] = t[2]; if(SHDIM == 4) h[3] = (DIM == 3) ? t[3] : 1; @@ -780,7 +845,7 @@ void vertices_texture(const vector& v, const vector& t, int #endif } -void prepare(vector& v) { +EX void prepare(vector& v) { #if CAP_VERTEXBUFFER bindbuffer(v); PTR(glhr::aPosition, SHDIM, coords); @@ -798,7 +863,7 @@ void prepare(vector& v) { #endif } -void prepare(vector& v) { +EX void prepare(vector& v) { #if CAP_VERTEXBUFFER bindbuffer(v); PTR(glhr::aPosition, SHDIM, coords); @@ -817,7 +882,7 @@ void prepare(vector& v) { // color2(col); } -void prepare(vector& v) { +EX void prepare(vector& v) { #if CAP_VERTEXBUFFER bindbuffer(v); PTR(glhr::aPosition, SHDIM, coords); @@ -853,7 +918,7 @@ void store_in_buffer(vector& v) { #endif } -void set_depthtest(bool b) { +EX void set_depthtest(bool b) { if(b != current_depthtest) { current_depthtest = b; if(b) glEnable(GL_DEPTH_TEST); @@ -862,7 +927,7 @@ void set_depthtest(bool b) { } -void set_depthwrite(bool b) { +EX void set_depthwrite(bool b) { if(b != current_depthwrite) { // <- this does not work ask intended for some reason... current_depthwrite = b; if(b) glDepthMask(GL_TRUE); @@ -870,14 +935,14 @@ void set_depthwrite(bool b) { } } -void set_linewidth(ld lw) { +EX void set_linewidth(ld lw) { if(lw != current_linewidth) { current_linewidth = lw; glLineWidth(lw); } } -void switch_to_text(const vector& v, const vector& t) { +EX void switch_to_text(const vector& v, const vector& t) { glhr::be_textured(); dynamicval pm(pmodel, mdUnchanged); if(!svg::in) current_display->set_all(0); diff --git a/surface.cpp b/surface.cpp index 353d3176..6d642728 100644 --- a/surface.cpp +++ b/surface.cpp @@ -4,22 +4,28 @@ // See http://webmath2.unito.it/paginepersonali/sergio.console/CurveSuperfici/AG15.pdf for a nice reference #if CAP_SURFACE -namespace hr { namespace surface { +namespace hr { + +EX namespace surface { ld sech(ld d) { return 1 / cosh(d); } +#if HDR +enum eShape { dsNone, dsTractricoid, dsDini, dsKuen, dsHyperlike, dsHyperboloid, dsHemisphere, dsCrystal }; +#endif + string shape_name[] = { "hypersian rug", "tractricoid", "Dini's surface", "Kuen surface", "concave barrel", "hyperboloid", "hemisphere", "crystal" }; -eShape sh; +EX eShape sh; hyperpoint unit_vector[3] = {hpxyz(1,0,0), hpxyz(0,1,0), hpxyz(0,0,1)}; ld last_int_of = 0, last_int = 0; -ld dini_b = .15; +EX ld dini_b = .15; -ld hyper_b = 1; +EX ld hyper_b = 1; ld f(ld x) { return sqrt(1 - pow(hyper_b * sinh(x), 2)); @@ -579,7 +585,7 @@ void run_other() { } } -void run_shape(eShape s) { +EX void run_shape(eShape s) { coverage.clear(); need_mouseh = true; sh = s; @@ -663,7 +669,7 @@ void cancel_shape() { cell *coverage_center; transmatrix coverage_matrix; -void show_surfaces() { +EX void show_surfaces() { cmode = sm::SIDE; gamescreen(0); dialog::init(XLAT("constant curvature surfaces"), iinf[itPalace].color, 150, 0); diff --git a/system.cpp b/system.cpp index aa9b6e52..8aca82a3 100644 --- a/system.cpp +++ b/system.cpp @@ -8,24 +8,24 @@ namespace hr { EX bool game_active; -bool cblind; -bool autocheat; -bool canvas_invisible; +EX bool cblind; +EX bool autocheat; +EX bool canvas_invisible; -int truelotus; -int gamecount; +EX int truelotus; +EX int gamecount; -int asteroids_generated, asteroid_orbs_generated; +EX int asteroids_generated, asteroid_orbs_generated; -time_t timerstart, savetime; -bool timerstopped; +EX time_t timerstart, savetime; +EX bool timerstopped; int savecount; EX bool showoff = false; EX bool doCross = false; bool gamegen_failure; -eLand top_land; +EX eLand top_land; bool verless(string v, string cmp) { if(isdigit(v[0]) && isdigit(v[1])) @@ -367,7 +367,7 @@ void applyBox(int& t) { else boxid++; } -void applyBoxNum(int& i, string name) { +EX void applyBoxNum(int& i, string name IS("")) { fakebox[boxid] = (name == ""); boxname[boxid] = name; monsbox[boxid] = false; diff --git a/textures.cpp b/textures.cpp index d946f7fb..547afff7 100644 --- a/textures.cpp +++ b/textures.cpp @@ -2,9 +2,115 @@ // Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details #if CAP_TEXTURE -namespace hr { namespace texture { +namespace hr { -cpatterntype cgroup; +EX namespace texture { + +#if HDR +enum eTextureState { + tsOff, tsAdjusting, tsActive + }; + +struct texture_data { + GLuint textureid; + + int twidth; + int tx, ty, origdim; + + texture_data() { textureid = 0; twidth = 2048; } + + vector texture_pixels; + + color_t& get_texture_pixel(int x, int y) { + return texture_pixels[(y&(twidth-1))*twidth+(x&(twidth-1))]; + } + + vector> undos; + vector > pixels_to_draw; + + bool loadTextureGL(); + bool whitetexture(); + bool readtexture(string tn); + void saveRawTexture(string tn); + + void undo(); + void undoLock(); + void update(); + }; + +struct texture_config { + string texturename; + string configname; + color_t paint_color; + eTextureState tstate; + eTextureState tstate_max; + + transmatrix itt; + + color_t grid_color; + color_t mesh_color; + color_t master_color; + color_t slave_color; + + int color_alpha; + + int gsplits; + + int recolor(color_t col); + + typedef tuple texture_parameters; + texture_parameters orig_texture_parameters; + + map texture_map, texture_map_orig; + set models; + + basic_textureinfo tinf3; + + bool texture_tuned; + string texture_tuner; + vector tuned_vertices; + + bool apply(cell *c, const transmatrix &V, color_t col); + void mark_triangles(); + + void clear_texture_map(); + void perform_mapping(); + void mapTextureTriangle(textureinfo &mi, const array& v, const array& tv, int splits); + void mapTextureTriangle(textureinfo &mi, const array& v, const array& tv) { mapTextureTriangle(mi, v, tv, gsplits); } + void mapTexture2(textureinfo& mi); + void finish_mapping(); + void true_remap(); + void remap(); + bool correctly_mapped; + hyperpoint texture_coordinates(hyperpoint); + + void drawRawTexture(); + void saveFullTexture(string tn); + + bool save(); + bool load(); + + texture_data data; + + texture_config() { + // argh, no member initialization in some of my compilers + texturename = "textures/hyperrogue-texture.png"; + configname = "textures/hyperrogue.txc"; + itt = Id; + paint_color = 0x000000FF; + grid_color = 0; + mesh_color = 0; + master_color = 0xFFFFFF30; + slave_color = 0xFF000008; + color_alpha = 128; + gsplits = 1; + texture_tuned = false; + } + + }; +#endif + +EX cpatterntype cgroup; #if CAP_PNG SDL_Surface *convertSurface(SDL_Surface* s) { @@ -38,9 +144,9 @@ struct undo { unsigned last; }; -texture_config config; +EX texture_config config; -bool saving = false; +EX bool saving = false; template void scale_colorarray(int origdim, int targetdim, const T& src, const U& dest) { int ox = 0, tx = 0, partials[4]; @@ -323,9 +429,9 @@ int texture_config::recolor(color_t col) { return col; } -bool texture_aura; +EX bool texture_aura; -bool using_aura() { +EX bool using_aura() { return texture_aura && config.tstate == texture::tsActive; } @@ -1081,7 +1187,7 @@ string texturehelp = "Again, tesselations can have their geometry changed.\n\n"; #if CAP_EDIT -void start_editor() { +EX void start_editor() { addMessage("white"); if(config.data.whitetexture() && config.data.loadTextureGL()) { config.tstate = config.tstate_max = tsActive; @@ -1093,7 +1199,7 @@ void start_editor() { } #endif -void showMenu() { +EX void showMenu() { cmode = sm::SIDE | sm::MAYDARK | sm::DIALOG_STRICT_X; gamescreen(0); if(config.tstate == tsAdjusting) { @@ -1319,7 +1425,7 @@ array ptc(const array& h) { return make_array(ptc(h[0]), ptc(h[1]), ptc(h[2])); } -ld penwidth = .02; +EX ld penwidth = .02; int texture_distance(pair p1, pair p2) { return max(abs(p1.first-p2.first), abs(p1.second - p2.second)); @@ -1420,7 +1526,7 @@ void fillcircle(hyperpoint h, color_t col) { } } -bool texturesym = false; +EX bool texturesym = false; void actDrawPixel(cell *c, hyperpoint h, color_t col) { try { @@ -1437,13 +1543,13 @@ void actDrawPixel(cell *c, hyperpoint h, color_t col) { catch(out_of_range&) {} } -void drawPixel(cell *c, hyperpoint h, color_t col) { +EX void drawPixel(cell *c, hyperpoint h, color_t col) { config.data.pixels_to_draw.emplace_back(c, h, col); } -cell *where; +EX cell *where; -void drawPixel(hyperpoint h, color_t col) { +EX void drawPixel(hyperpoint h, color_t col) { try { again: transmatrix g0 = gmatrix[where]; @@ -1465,7 +1571,7 @@ void drawPixel(hyperpoint h, color_t col) { catch(out_of_range&) {} } -void drawLine(hyperpoint h1, hyperpoint h2, color_t col, int steps) { +EX void drawLine(hyperpoint h1, hyperpoint h2, color_t col, int steps IS(10)) { if(steps > 0 && hdist(h1, h2) > penwidth / 3) { hyperpoint h3 = mid(h1, h2); drawLine(h1, h3, col, steps-1);