moved svg and PNG screenshot to a new file screenshots.cpp; moved some commandline arguments from commandline.cpp to their respective modules

This commit is contained in:
Zeno Rogue 2018-07-19 23:46:58 +02:00
parent 8c5a88c513
commit 30cb9158cb
11 changed files with 507 additions and 440 deletions

View File

@ -984,96 +984,6 @@ ld textscale() {
// bool notgl = false;
int pngres = 2000;
int pngformat = 0;
#if CAP_PNG
void IMAGESAVE(SDL_Surface *s, const char *fname) {
SDL_Surface *s2 = SDL_PNGFormatAlpha(s);
SDL_SavePNG(s2, fname);
SDL_FreeSurface(s2);
}
#endif
hookset<void(renderbuffer*)> *hooks_hqshot;
#if CAP_SDL
void saveHighQualityShot(const char *fname, const char *caption, int fade) {
resetbuffer rb;
// int maxrange = getDistLimit() * 3/2;
// dynamicval<int> v3(sightrange, (cheater && sightrange < maxrange) ? maxrange : sightrange);
if(cheater) doOvergenerate();
time_t timer;
timer = time(NULL);
dynamicval<videopar> v(vid, vid);
dynamicval<bool> v2(inHighQual, true);
dynamicval<bool> v6(auraNOGL, fname ? true : false);
vid.xres = vid.yres = pngres;
if(pngformat == 1) vid.xres = vid.yres * 4/3;
if(pngformat == 2) vid.xres = vid.yres * 16/9;
if(pngformat == 3) {
vid.xres = vid.yres * 22/16;
while(vid.xres & 15) vid.xres++;
}
// if(vid.pmodel == 0) vid.scale = 0.99;
calcparam();
renderbuffer glbuf(vid.xres, vid.yres, vid.usingGL);
glbuf.enable();
stereo::set_viewport(0);
// printf("format = %d, %d x %d\n", pngformat, vid.xres, vid.yres);
darken = 0;
int numi = (fname?1:2);
for(int i=0; i<numi; i++) {
glbuf.clear(numi==1 ? backcolor : i ? 0xFFFFFF : 0);
#if CAP_RUG
if(rug::rugged)
rug::drawRugScene();
else
#endif
drawfullmap();
drawStats();
callhooks(hooks_hqshot, &glbuf);
if(fade < 255)
for(int y=0; y<vid.yres; y++)
for(int x=0; x<vid.xres; x++) {
int& p = qpixel(s, x, y);
for(int i=0; i<3; i++) {
part(p,i) = (part(p,i) * fade + 127) / 255;
}
}
if(caption)
displayfr(vid.xres/2, vid.fsize+vid.fsize/4, 3, vid.fsize*2, caption, forecolor, 8);
char buf[128]; strftime(buf, 128, "bigshota-%y%m%d-%H%M%S" IMAGEEXT, localtime(&timer));
buf[7] += i;
if(!fname) fname = buf;
IMAGESAVE(glbuf.render(), fname);
if(i == 0) addMessage(XLAT("Saved the high quality shot to %1", fname));
}
rb.reset();
}
#endif
bool setfsize = true;
bool vsync_off;

View File

@ -6,10 +6,6 @@ namespace hr {
#if CAP_COMMANDLINE
const char *scorefile = "hyperrogue.log";
const char *conffile = "hyperrogue.ini";
string levelfile = "hyperrogue.lev";
string picfile = "hyperrogue.pic";
const char *musicfile = "";
const char *loadlevel = NULL;
bool appears(const string& haystack, const string& needle) {
return haystack.find(needle) != string::npos;
@ -88,25 +84,18 @@ namespace arg {
}
#define CHEAT autocheat = true; cheater++; timerghost = false;
int arg::readCommon() {
// first phase options
if(argis("-c")) { PHASE(1); shift(); conffile = argcs(); }
else if(argis("-s")) { PHASE(1); shift(); scorefile = argcs(); }
else if(argis("-m")) { PHASE(1); shift(); musicfile = argcs(); }
else if(argis("-nogui")) { PHASE(1); noGUI = true; }
#ifndef EMSCRIPTEN
else if(argis("-font")) { PHASE(1); shift(); fontpath = args(); }
#endif
#if CAP_SDLAUDIO
else if(argis("-se")) { PHASE(1); shift(); wheresounds = args(); }
#endif
// change the configuration from the command line
else if(argis("-svol")) { PHASEFROM(2); shift(); effvolume = argi(); }
else if(argis("-back")) {
PHASEFROM(2); shift(); backcolor = arghex();
}
@ -147,7 +136,7 @@ int arg::readCommon() {
dont_face_pc = true;
}
else if(argis("-rch")) {
PHASEFROM(2); CHEAT reptilecheat = true;
PHASEFROM(2); cheat(); reptilecheat = true;
}
// cheats
@ -155,19 +144,19 @@ int arg::readCommon() {
PHASE(3);
shift();
activateSafety(readland(args()));
CHEAT;
cheat();
}
else if(argis("-W2")) {
shift(); cheatdest = readland(args()); CHEAT;
shift(); cheatdest = readland(args()); cheat();
showstartmenu = false;
}
else if(argis("-I")) {
PHASE(3) CHEAT
PHASE(3) cheat();
shift(); eItem i = readItem(args());
shift(); items[i] = argi();
}
else if(argis("-IP")) {
PHASE(3) CHEAT
PHASE(3) cheat();
shift(); eItem i = readItem(args());
shift(); int q = argi();
placeItems(q, i);
@ -178,13 +167,13 @@ int arg::readCommon() {
}
#if CAP_INV
else if(argis("-IU")) {
PHASE(3) CHEAT
PHASE(3) cheat();
shift(); eItem i = readItem(args());
shift(); inv::usedup[i] += argi();
inv::compute();
}
else if(argis("-IX")) {
PHASE(3) CHEAT
PHASE(3) cheat();
shift(); eItem i = readItem(args());
shift(); inv::extra_orbs[i] += argi();
inv::compute();
@ -193,59 +182,32 @@ int arg::readCommon() {
else if(argis("-ambush")) {
// make all ambushes use the given number of dogs
// example: hyper -W Hunt -IP Shield 1 -ambush 60
PHASE(3) CHEAT
PHASE(3) cheat();
shift(); ambushval = argi();
}
else if(argis("-M")) {
PHASE(3) CHEAT
PHASE(3) cheat();
shift(); eMonster m = readMonster(args());
shift(); int q = argi();
printf("m = %s q = %d\n", dnameof(m), q);
restoreGolems(q, m, 7);
}
else if(argis("-MK")) {
PHASE(3) CHEAT
PHASE(3) cheat();
shift(); eMonster m = readMonster(args());
shift(); kills[m] += argi();
}
// mode changes:
#define TOGGLE(x, param, act) \
else if(args()[0] == '-' && args()[1] == x && !args()[2]) { PHASEFROM(2); showstartmenu = false; act; } \
else if(args()[0] == '-' && args()[1] == x && args()[2] == '1') { PHASEFROM(2); showstartmenu = false; if(!param) act; } \
else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2); showstartmenu = false; if(param) act; }
TOGGLE('o', vid.usingGL, switchGL())
TOGGLE('C', chaosmode, stop_game_and_switch_mode(rg::chaos))
TOGGLE('7', nonbitrunc, stop_game_and_switch_mode(rg::bitrunc))
TOGGLE('f', vid.full, switchFullscreen())
TOGGLE('T', tactic::on, stop_game_and_switch_mode(rg::tactic))
TOGGLE('S', shmup::on, stop_game_and_switch_mode(rg::shmup))
TOGGLE('H', hardcore, switchHardcore())
TOGGLE('R', randomPatternsMode, stop_game_and_switch_mode(rg::randpattern))
TOGGLE('i', inv::on, stop_game_and_switch_mode(rg::inv))
else if(argis("-peace")) {
peace::otherpuzzles = true;
stop_game_and_switch_mode(peace::on ? 0 : rg::peace);
}
else if(argis("-pmem")) {
peace::otherpuzzles = false;
stop_game_and_switch_mode(peace::on ? 0 : rg::peace);
}
else if(argis("-geo")) {
shift(); targetgeometry = (eGeometry) argi();
if(targetgeometry != geometry)
stop_game_and_switch_mode(rg::geometry);
}
else if(argis("-gp")) {
PHASEFROM(2);
stop_game_and_switch_mode(rg::nothing);
shift(); gp::param.first = argi();
shift(); gp::param.second = argi();
stop_game_and_switch_mode(rg::gp);
}
// 'do something'
else if(argis("-W")) {
PHASEFROM(2);
@ -283,17 +245,17 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
// non-categorized:
else if(argis("-pal")) {
PHASEFROM(2); CHEAT;
PHASEFROM(2); cheat();
shift(); int id = argi();
shift(); linepatterns::patterns[id].color |= argi();
}
else if(argis("-palrgba")) {
PHASEFROM(2); CHEAT;
PHASEFROM(2); cheat();
shift(); int id = argi();
shift(); linepatterns::patterns[id].color = arghex();
}
else if(argis("-qs")) {
CHEAT;
cheat();
shift(); currfp.qpaths.push_back(args());
}
else if(argis("-fix")) {
@ -309,64 +271,10 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
fixseed = true; autocheat = true;
shift(); steplimit = argi();
}
else if(argis("-qpar")) {
int p;
shift(); sscanf(argcs(), "%d,%d,%d",
&p, &quotientspace::rvadd, &quotientspace::rvdir
);
autocheat = true;
currfp.init(p);
}
else if(argis("-test"))
callhooks(hooks_tests);
else if(argis("-qpar2")) {
stop_game_and_switch_mode(rg::nothing);
int a, b;
shift(); sscanf(argcs(), "%d,%d", &a, &b);
using namespace fieldpattern;
current_extra = a;
auto& gxcur = fgeomextras[current_extra];
while(b >= isize(gxcur.primes)) nextPrime(gxcur);
fgeomextras[current_extra].current_prime_id = b;
enableFieldChange();
if(geometry != gFieldQuotient) {
targetgeometry = gFieldQuotient; stop_game_and_switch_mode(rg::geometry);
}
}
else if(argis("-tpar")) {
torusconfig::torus_mode = torusconfig::tmSingle;
shift(); sscanf(argcs(), "%d,%d,%d",
&torusconfig::qty,
&torusconfig::dx,
&torusconfig::dy
);
}
else if(argis("-tparx")) {
shift();
sscanf(argcs(), "%d,%d,%d",
(int*) &torusconfig::torus_mode,
&torusconfig::sdx,
&torusconfig::sdy
);
if(torusconfig::torus_mode == torusconfig::tmSingle)
torusconfig::qty = torusconfig::sdx,
torusconfig::dy = torusconfig::sdy;
torusconfig::activate();
}
else if(argis("-cs")) {
shift(); CHEAT
fieldpattern::matrix M = currfp.strtomatrix(args());
fieldpattern::subpathid = currfp.matcode[M];
fieldpattern::subpathorder = currfp.order(M);
}
else if(argis("-csp")) {
CHEAT
currfp.findsubpath();
}
else if(argis("-quantum")) {
CHEAT;
cheat();
quantum = true;
}
else if(argis("-P")) {
@ -396,17 +304,13 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
if(itemclass(eItem(i)) == IC_TREASURE)
items[i] = q;
}
else if(argis("-ch")) { autocheat = true; }
else if(argis("-ch")) { cheat(); }
else if(argis("-zoom")) {
PHASEFROM(2); shift(); vid.scale = argf();
}
else if(argis("-alpha")) {
PHASEFROM(2); shift(); vid.alpha = argf();
}
else if(argis("-Y")) {
yendor::on = true;
shift(); yendor::challenge = argi();
}
else if(argis("-r")) {
PHASEFROM(2);
shift();
@ -457,7 +361,7 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
shift(); sightrange_bonus = argi();
}
else if(argis("-srx")) {
PHASEFROM(2); CHEAT;
PHASEFROM(2); cheat();
shift(); sightrange_bonus = genrange_bonus = gamerange_bonus = argi();
}
else if(argis("-els")) {
@ -478,43 +382,7 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
else if(argis("-bright")) {
bright = true;
}
#if CAP_SDL
else if(argis("-pngshot")) {
PHASE(3); shift(); start_game();
printf("saving PNG screenshot to %s\n", argcs());
saveHighQualityShot(argcs());
}
#endif
else if(argis("-svgsize")) {
shift(); sscanf(argcs(), "%d/%d", &svg::svgsize, &svg::divby);
}
else if(argis("-svgfont")) {
shift(); svg::font = args();
// note: use '-svgfont latex' to produce text output as: \myfont{size}{text}
// (this is helpful with Inkscape's PDF+TeX output feature; define \myfont yourself)
}
else if(argis("-pngsize")) {
shift(); pngres = argi();
}
else if(argis("-pngformat")) {
shift(); pngformat = argi();
}
else if(argis("-svggamma")) {
shift(); svg::gamma = argf();
}
else if(argis("-svgshot")) {
PHASE(3); shift(); start_game();
printf("saving SVG screenshot to %s\n", argcs());
svg::render(argcs());
}
// other
#if CAP_EDIT
else if(argis("-lev")) { shift(); levelfile = args(); }
else if(argis("-pic")) { shift(); picfile = args(); }
else if(argis("-load")) { PHASE(3); shift(); mapstream::loadMap(args()); }
else if(argis("-picload")) { PHASE(3); shift(); mapeditor::loadPicFile(args()); }
#endif
// graphical options
else if(argis("-noscr")) {
PHASE(3);
@ -523,7 +391,7 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
}
else if(argis("-W3")) {
shift(); top_land = readland(args()); CHEAT;
shift(); top_land = readland(args()); cheat();
showstartmenu = false;
}
else if(argis("-top")) {
@ -535,10 +403,6 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
printf("HyperRogue version " VER "\n");
exit(0);
}
else if(argis("-fi")) {
fieldpattern::info();
exit(0);
}
else if(argis("-L")) {
printf("Treasures:\n");
for(int i=1; i<ittypes; i++)
@ -613,7 +477,6 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2);
printf("Not all options are documented, see hyper.cpp");
exit(0);
}
else if(ca::readArg()) ;
else return 1;
return 0;
}

View File

@ -62,6 +62,7 @@ namespace hr { namespace inv { bool on, activating; } }
#include "nofont.cpp"
#endif
#include "basegraph.cpp"
#include "screenshot.cpp"
#include "renderbuffer.cpp"
#include "help.cpp"
#include "config.cpp"

View File

@ -2988,6 +2988,8 @@ namespace ca {
}
#endif
auto ah = addHook(hooks_args, 0, readArg);
void simulate() {
if(cwt.c->land != laCA) return;
vector<cell*>& allcells = currentmap->allcells();

View File

@ -510,4 +510,85 @@ void runGeometryExperiments() {
pushScreen(showEuclideanMenu);
}
#if CAP_COMMANDLINE
int read_geom_args() {
using namespace arg;
if(argis("-qpar")) {
int p;
shift(); sscanf(argcs(), "%d,%d,%d",
&p, &quotientspace::rvadd, &quotientspace::rvdir
);
autocheat = true;
currfp.init(p);
}
else if(argis("-qpar2")) {
stop_game_and_switch_mode(rg::nothing);
int a, b;
shift(); sscanf(argcs(), "%d,%d", &a, &b);
using namespace fieldpattern;
current_extra = a;
auto& gxcur = fgeomextras[current_extra];
while(b >= isize(gxcur.primes)) nextPrime(gxcur);
fgeomextras[current_extra].current_prime_id = b;
enableFieldChange();
if(geometry != gFieldQuotient) {
targetgeometry = gFieldQuotient; stop_game_and_switch_mode(rg::geometry);
}
}
else if(argis("-cs")) {
shift(); cheat();
fieldpattern::matrix M = currfp.strtomatrix(args());
fieldpattern::subpathid = currfp.matcode[M];
fieldpattern::subpathorder = currfp.order(M);
}
else if(argis("-csp")) {
cheat();
currfp.findsubpath();
}
else if(argis("-tpar")) {
torusconfig::torus_mode = torusconfig::tmSingle;
shift(); sscanf(argcs(), "%d,%d,%d",
&torusconfig::qty,
&torusconfig::dx,
&torusconfig::dy
);
}
else if(argis("-tparx")) {
shift();
sscanf(argcs(), "%d,%d,%d",
(int*) &torusconfig::torus_mode,
&torusconfig::sdx,
&torusconfig::sdy
);
if(torusconfig::torus_mode == torusconfig::tmSingle)
torusconfig::qty = torusconfig::sdx,
torusconfig::dy = torusconfig::sdy;
torusconfig::activate();
}
TOGGLE('7', nonbitrunc, stop_game_and_switch_mode(rg::bitrunc))
else if(argis("-geo")) {
shift(); targetgeometry = (eGeometry) argi();
if(targetgeometry != geometry)
stop_game_and_switch_mode(rg::geometry);
}
else if(argis("-gp")) {
PHASEFROM(2);
stop_game_and_switch_mode(rg::nothing);
shift(); gp::param.first = argi();
shift(); gp::param.second = argi();
stop_game_and_switch_mode(rg::gp);
}
else if(argis("-fi")) {
fieldpattern::info();
exit(0);
}
else return 1;
return 0;
}
auto ah_geom = addHook(hooks_args, 0, read_geom_args);
#endif
}

View File

@ -1832,6 +1832,14 @@ namespace arg {
// an useful macro
#define PHASE(x) { if(arg::curphase > x) phaseerror(x); else if(arg::curphase < x) return 2; }
#define PHASEFROM(x) { if(arg::curphase < x) return 2; }
void cheat() { autocheat = true; cheater++; timerghost = false; }
#define TOGGLE(x, param, act) \
else if(args()[0] == '-' && args()[1] == x && !args()[2]) { PHASEFROM(2); showstartmenu = false; act; } \
else if(args()[0] == '-' && args()[1] == x && args()[2] == '1') { PHASEFROM(2); showstartmenu = false; if(!param) act; } \
else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { PHASEFROM(2); showstartmenu = false; if(param) act; }
void read(int phase);

View File

@ -1794,4 +1794,23 @@ namespace mapeditor {
}
#if CAP_EDIT
#if CAP_COMMANDLINE
string levelfile = "hyperrogue.lev";
const char *loadlevel = NULL;
string picfile = "hyperrogue.pic";
int read_editor_args() {
using namespace arg;
if(argis("-lev")) { shift(); levelfile = args(); }
else if(argis("-pic")) { shift(); picfile = args(); }
else if(argis("-load")) { PHASE(3); shift(); mapstream::loadMap(args()); }
else if(argis("-picload")) { PHASE(3); shift(); mapeditor::loadPicFile(args()); }
else return 1;
return 0;
}
auto ah_editor = addHook(hooks_args, 0, read_editor_args);
#endif
#endif
}

View File

@ -2399,202 +2399,6 @@ void queuecircle(int x, int y, int size, int color, int prio = PPR_CIRCLE) {
ptd.prio = prio << PSHIFT;
}
#if ISMOBILE==1
namespace svg {
bool in = false;
}
#endif
#if ISMOBILE==0
// svg renderer
namespace svg {
FILE *f;
bool in = false;
ld cta(int col) {
// col >>= 24;
col &= 0xFF;
return col / 255.0;
}
bool invisible(int col) { return (col & 0xFF) == 0; }
ld gamma = .5;
void fixgamma(unsigned int& color) {
unsigned char *c = (unsigned char*) (&color);
for(int i=1; i<4; i++) c[i] = 255 * pow(float(c[i] / 255.0), float(gamma));
}
int svgsize;
int divby = 10;
const char* coord(int val) {
static char buf[10][20];
static int id;
id++; id %= 10;
if(divby == 1) {
sprintf(buf[id], "%d", val); return buf[id];
}
else if(divby <= 10) {
sprintf(buf[id], "%.1f", val*1./divby); return buf[id];
}
else {
sprintf(buf[id], "%.2f", val*1./divby); return buf[id];
}
}
char* stylestr(unsigned int fill, unsigned int stroke, ld width=1) {
fixgamma(fill);
fixgamma(stroke);
static char buf[600];
// printf("fill = %08X stroke = %08x\n", fill, stroke);
if(stroke == 0xFF00FF) {
stroke = 0x000000FF;
if(fill == 0x332a22ff) fill = 0x000000FF;
else if(fill == 0x686868FF) fill = 0x000000FF;
else if(fill == 0xd0d0d0FF) fill = 0x000000FF;
else fill = 0xFFFFFFFF;
}
sprintf(buf, "style=\"stroke:#%06x;stroke-opacity:%.3" PLDF ";stroke-width:%" PLDF "px;fill:#%06x;fill-opacity:%.3" PLDF "\"",
(stroke>>8) & 0xFFFFFF, cta(stroke),
width/divby,
(fill>>8) & 0xFFFFFF, cta(fill)
);
return buf;
}
void circle(int x, int y, int size, int col) {
int ba = (backcolor << 8) + 0xFF;
if(!invisible(col))
fprintf(f, "<circle cx='%s' cy='%s' r='%s' %s/>\n",
coord(x), coord(y), coord(size), stylestr(ba, col));
}
const string *link;
void startstring() {
if(link) fprintf(f, "<a xlink:href=\"%s\" xlink:show=\"replace\">", link->c_str());
}
void stopstring() {
if(link) fprintf(f, "</a>");
}
string font = "Times";
void text(int x, int y, int size, const string& str, bool frame, int col, int align) {
double dfc = (x - vid.xcenter) * (x - vid.xcenter) +
(y - vid.ycenter) * (y - vid.ycenter);
dfc /= vid.radius;
dfc /= vid.radius;
// 0 = center, 1 = edge
dfc = 1 - dfc;
col = 0xFF + (col << 8);
bool uselatex = font == "latex";
if(!invisible(col)) {
startstring();
string str2 = "";
for(int i=0; i<(int) str.size(); i++)
if(str[i] == '&')
str2 += "&amp;";
else if(str[i] == '<')
str2 += "&lt;";
else if(str[i] == '>')
str2 += "&gt;";
else if(uselatex && str[i] == '#')
str2 += "\\#";
else str2 += str[i];
if(uselatex) str2 = string("\\myfont{")+coord(size)+"}{" + str2 + "}";
fprintf(f, "<text x='%s' y='%s' text-anchor='%s' ",
coord(x), coord(y+size*.4),
align == 8 ? "middle" :
align < 8 ? "start" :
"end");
if(!uselatex)
fprintf(f, "font-family='%s' font-size='%s' ", font.c_str(), coord(size));
fprintf(f, "%s>%s</text>",
stylestr(col, frame ? 0x0000000FF : 0, (1<<get_sightrange())*dfc/40), str2.c_str());
stopstring();
fprintf(f, "\n");
}
}
void polygon(int *polyx, int *polyy, int polyi, int col, int outline, double minwidth) {
if(invisible(col) && invisible(outline)) return;
if(polyi < 2) return;
double dfc;
if(!pmodel && hyperbolic) {
int avgx = 0, avgy = 0;
for(int i=0; i<polyi; i++)
avgx += polyx[i],
avgy += polyy[i];
avgx /= polyi;
avgy /= polyi;
dfc = (avgx - vid.xcenter) * (avgx - vid.xcenter) +
(avgy - vid.ycenter) * (avgy - vid.ycenter);
dfc /= vid.radius;
dfc /= vid.radius;
// 0 = center, 1 = edge
dfc = 1 - dfc;
if(dfc < 0) dfc = 1;
dfc = max<double>(dfc, 1) * minwidth;
}
else dfc = .8 * minwidth;
startstring();
for(int i=0; i<polyi; i++) {
if(i == 0)
fprintf(f, "<path d=\"M ");
else
fprintf(f, " L ");
fprintf(f, "%s %s", coord(polyx[i]), coord(polyy[i]));
}
fprintf(f, "\" %s/>", stylestr(col, outline, (hyperbolic ? vid.radius : vid.scrsize) *dfc/256));
stopstring();
fprintf(f, "\n");
}
void render(const char *fname) {
if(cheater) doOvergenerate();
dynamicval<videopar> v(vid, vid);
dynamicval<bool> v2(in, true);
dynamicval<int> v5(ringcolor, 0x808080FF);
vid.usingGL = false;
vid.xres = vid.yres = svgsize ? svgsize : min(1 << (get_sightrange()+7), 16384);
calcparam();
dynamicval<bool> v6(inHighQual, true);
darken = 0;
time_t timer;
timer = time(NULL);
char buf[128]; strftime(buf, 128, "svgshot-%y%m%d-%H%M%S.svg", localtime(&timer));
if(!fname) fname = buf;
f = fopen(fname, "wt");
fprintf(f, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%s\" height=\"%s\">\n", coord(vid.xres), coord(vid.yres));
drawfullmap();
fprintf(f, "</svg>\n");
fclose(f);
addMessage(XLAT("Saved the SVG shot to %1 (sightrange %2)", fname, its(get_sightrange())));
}
}
#endif
void getcoord0(const hyperpoint& h, int& xc, int &yc, int &sc) {
hyperpoint hscr;
applymodel(h, hscr);

338
screenshot.cpp Normal file
View File

@ -0,0 +1,338 @@
// Hyperbolic Rogue -- screenshots in SVG and PNG formats
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
namespace hr {
#if ISMOBILE==1
namespace svg {
bool in = false;
}
#endif
#if ISMOBILE==0
// svg renderer
namespace svg {
FILE *f;
bool in = false;
ld cta(int col) {
// col >>= 24;
col &= 0xFF;
return col / 255.0;
}
bool invisible(int col) { return (col & 0xFF) == 0; }
ld gamma = .5;
void fixgamma(unsigned int& color) {
unsigned char *c = (unsigned char*) (&color);
for(int i=1; i<4; i++) c[i] = 255 * pow(float(c[i] / 255.0), float(gamma));
}
int svgsize;
int divby = 10;
const char* coord(int val) {
static char buf[10][20];
static int id;
id++; id %= 10;
if(divby == 1) {
sprintf(buf[id], "%d", val); return buf[id];
}
else if(divby <= 10) {
sprintf(buf[id], "%.1f", val*1./divby); return buf[id];
}
else {
sprintf(buf[id], "%.2f", val*1./divby); return buf[id];
}
}
char* stylestr(unsigned int fill, unsigned int stroke, ld width=1) {
fixgamma(fill);
fixgamma(stroke);
static char buf[600];
// printf("fill = %08X stroke = %08x\n", fill, stroke);
if(stroke == 0xFF00FF) {
stroke = 0x000000FF;
if(fill == 0x332a22ff) fill = 0x000000FF;
else if(fill == 0x686868FF) fill = 0x000000FF;
else if(fill == 0xd0d0d0FF) fill = 0x000000FF;
else fill = 0xFFFFFFFF;
}
sprintf(buf, "style=\"stroke:#%06x;stroke-opacity:%.3" PLDF ";stroke-width:%" PLDF "px;fill:#%06x;fill-opacity:%.3" PLDF "\"",
(stroke>>8) & 0xFFFFFF, cta(stroke),
width/divby,
(fill>>8) & 0xFFFFFF, cta(fill)
);
return buf;
}
void circle(int x, int y, int size, int col) {
int ba = (backcolor << 8) + 0xFF;
if(!invisible(col))
fprintf(f, "<circle cx='%s' cy='%s' r='%s' %s/>\n",
coord(x), coord(y), coord(size), stylestr(ba, col));
}
const string *link;
void startstring() {
if(link) fprintf(f, "<a xlink:href=\"%s\" xlink:show=\"replace\">", link->c_str());
}
void stopstring() {
if(link) fprintf(f, "</a>");
}
string font = "Times";
void text(int x, int y, int size, const string& str, bool frame, int col, int align) {
double dfc = (x - vid.xcenter) * (x - vid.xcenter) +
(y - vid.ycenter) * (y - vid.ycenter);
dfc /= vid.radius;
dfc /= vid.radius;
// 0 = center, 1 = edge
dfc = 1 - dfc;
col = 0xFF + (col << 8);
bool uselatex = font == "latex";
if(!invisible(col)) {
startstring();
string str2 = "";
for(int i=0; i<(int) str.size(); i++)
if(str[i] == '&')
str2 += "&amp;";
else if(str[i] == '<')
str2 += "&lt;";
else if(str[i] == '>')
str2 += "&gt;";
else if(uselatex && str[i] == '#')
str2 += "\\#";
else str2 += str[i];
if(uselatex) str2 = string("\\myfont{")+coord(size)+"}{" + str2 + "}";
fprintf(f, "<text x='%s' y='%s' text-anchor='%s' ",
coord(x), coord(y+size*.4),
align == 8 ? "middle" :
align < 8 ? "start" :
"end");
if(!uselatex)
fprintf(f, "font-family='%s' font-size='%s' ", font.c_str(), coord(size));
fprintf(f, "%s>%s</text>",
stylestr(col, frame ? 0x0000000FF : 0, (1<<get_sightrange())*dfc/40), str2.c_str());
stopstring();
fprintf(f, "\n");
}
}
void polygon(int *polyx, int *polyy, int polyi, int col, int outline, double minwidth) {
if(invisible(col) && invisible(outline)) return;
if(polyi < 2) return;
double dfc;
if(!pmodel && hyperbolic) {
int avgx = 0, avgy = 0;
for(int i=0; i<polyi; i++)
avgx += polyx[i],
avgy += polyy[i];
avgx /= polyi;
avgy /= polyi;
dfc = (avgx - vid.xcenter) * (avgx - vid.xcenter) +
(avgy - vid.ycenter) * (avgy - vid.ycenter);
dfc /= vid.radius;
dfc /= vid.radius;
// 0 = center, 1 = edge
dfc = 1 - dfc;
if(dfc < 0) dfc = 1;
dfc = max<double>(dfc, 1) * minwidth;
}
else dfc = .8 * minwidth;
startstring();
for(int i=0; i<polyi; i++) {
if(i == 0)
fprintf(f, "<path d=\"M ");
else
fprintf(f, " L ");
fprintf(f, "%s %s", coord(polyx[i]), coord(polyy[i]));
}
fprintf(f, "\" %s/>", stylestr(col, outline, (hyperbolic ? vid.radius : vid.scrsize) *dfc/256));
stopstring();
fprintf(f, "\n");
}
void render(const char *fname) {
if(cheater) doOvergenerate();
dynamicval<videopar> v(vid, vid);
dynamicval<bool> v2(in, true);
dynamicval<int> v5(ringcolor, 0x808080FF);
vid.usingGL = false;
vid.xres = vid.yres = svgsize ? svgsize : min(1 << (get_sightrange()+7), 16384);
calcparam();
dynamicval<bool> v6(inHighQual, true);
darken = 0;
time_t timer;
timer = time(NULL);
char buf[128]; strftime(buf, 128, "svgshot-%y%m%d-%H%M%S.svg", localtime(&timer));
if(!fname) fname = buf;
f = fopen(fname, "wt");
fprintf(f, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%s\" height=\"%s\">\n", coord(vid.xres), coord(vid.yres));
drawfullmap();
fprintf(f, "</svg>\n");
fclose(f);
addMessage(XLAT("Saved the SVG shot to %1 (sightrange %2)", fname, its(get_sightrange())));
}
#if CAP_COMMANDLINE
int read_args() {
using namespace arg;
if(argis("-svgsize")) {
shift(); sscanf(argcs(), "%d/%d", &svg::svgsize, &svg::divby);
}
else if(argis("-svgfont")) {
shift(); svg::font = args();
// note: use '-svgfont latex' to produce text output as: \myfont{size}{text}
// (this is helpful with Inkscape's PDF+TeX output feature; define \myfont yourself)
}
else if(argis("-svggamma")) {
shift(); svg::gamma = argf();
}
else if(argis("-svgshot")) {
PHASE(3); shift(); start_game();
printf("saving SVG screenshot to %s\n", argcs());
svg::render(argcs());
}
else return 1;
return 0;
}
auto ah = addHook(hooks_args, 0, read_args);
#endif
}
#endif
#if CAP_SDL
int pngres = 2000;
int pngformat = 0;
#if CAP_PNG
void IMAGESAVE(SDL_Surface *s, const char *fname) {
SDL_Surface *s2 = SDL_PNGFormatAlpha(s);
SDL_SavePNG(s2, fname);
SDL_FreeSurface(s2);
}
#endif
hookset<void(renderbuffer*)> *hooks_hqshot;
void saveHighQualityShot(const char *fname, const char *caption, int fade) {
resetbuffer rb;
// int maxrange = getDistLimit() * 3/2;
// dynamicval<int> v3(sightrange, (cheater && sightrange < maxrange) ? maxrange : sightrange);
if(cheater) doOvergenerate();
time_t timer;
timer = time(NULL);
dynamicval<videopar> v(vid, vid);
dynamicval<bool> v2(inHighQual, true);
dynamicval<bool> v6(auraNOGL, fname ? true : false);
vid.xres = vid.yres = pngres;
if(pngformat == 1) vid.xres = vid.yres * 4/3;
if(pngformat == 2) vid.xres = vid.yres * 16/9;
if(pngformat == 3) {
vid.xres = vid.yres * 22/16;
while(vid.xres & 15) vid.xres++;
}
// if(vid.pmodel == 0) vid.scale = 0.99;
calcparam();
renderbuffer glbuf(vid.xres, vid.yres, vid.usingGL);
glbuf.enable();
stereo::set_viewport(0);
// printf("format = %d, %d x %d\n", pngformat, vid.xres, vid.yres);
darken = 0;
int numi = (fname?1:2);
for(int i=0; i<numi; i++) {
glbuf.clear(numi==1 ? backcolor : i ? 0xFFFFFF : 0);
#if CAP_RUG
if(rug::rugged)
rug::drawRugScene();
else
#endif
drawfullmap();
drawStats();
callhooks(hooks_hqshot, &glbuf);
if(fade < 255)
for(int y=0; y<vid.yres; y++)
for(int x=0; x<vid.xres; x++) {
int& p = qpixel(s, x, y);
for(int i=0; i<3; i++) {
part(p,i) = (part(p,i) * fade + 127) / 255;
}
}
if(caption)
displayfr(vid.xres/2, vid.fsize+vid.fsize/4, 3, vid.fsize*2, caption, forecolor, 8);
char buf[128]; strftime(buf, 128, "bigshota-%y%m%d-%H%M%S" IMAGEEXT, localtime(&timer));
buf[7] += i;
if(!fname) fname = buf;
IMAGESAVE(glbuf.render(), fname);
if(i == 0) addMessage(XLAT("Saved the high quality shot to %1", fname));
}
rb.reset();
}
#if CAP_COMMANDLINE
int png_read_args() {
using namespace arg;
if(argis("-pngshot")) {
PHASE(3); shift(); start_game();
printf("saving PNG screenshot to %s\n", argcs());
saveHighQualityShot(argcs());
}
else if(argis("-pngsize")) {
shift(); pngres = argi();
}
else if(argis("-pngformat")) {
shift(); pngformat = argi();
}
else return 1;
return 0;
}
auto ah_png = addHook(hooks_args, 0, png_read_args);
#endif
#endif
}

View File

@ -3,6 +3,7 @@
namespace hr {
const char *musicfile = "";
bool audio;
string musiclicense;
string musfname[landtypes];
@ -218,4 +219,20 @@ void playSound(cell *c, const string& fname, int vol) {
void resetmusic() {}
#endif
#if CAP_COMMANDLINE
int read_sound_args() {
using namespace arg;
if(argis("-m")) { PHASE(1); shift(); musicfile = argcs(); }
#if CAP_SDLAUDIO
else if(argis("-se")) { PHASE(1); shift(); wheresounds = args(); }
#endif
else if(argis("-svol")) { PHASEFROM(2); shift(); effvolume = argi(); }
else return 1;
return 0;
}
auto ah_sound = addHook(hooks_args, 0, read_sound_args);
#endif
}

View File

@ -1087,4 +1087,28 @@ namespace peace {
auto aNext = addHook(hooks_nextland, 100, getNext);
};
#if CAP_COMMANDLINE
int read_mode_args() {
using namespace arg;
if(argis("-Y")) {
yendor::on = true;
shift(); yendor::challenge = argi();
}
else if(argis("-peace")) {
peace::otherpuzzles = true;
stop_game_and_switch_mode(peace::on ? 0 : rg::peace);
}
else if(argis("-pmem")) {
peace::otherpuzzles = false;
stop_game_and_switch_mode(peace::on ? 0 : rg::peace);
}
TOGGLE('T', tactic::on, stop_game_and_switch_mode(rg::tactic))
else return 1;
return 0;
}
auto ah = addHook(hooks_args, 0, read_mode_args);
#endif
}