1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-14 01:14:48 +00:00
hyperrogue/rogueviz/cvl.cpp

113 lines
3.1 KiB
C++
Raw Normal View History

2019-02-10 09:43:28 +00:00
// Copyright (C) 2018 Zeno and Tehora Rogue, see 'hyper.cpp' for details
// this is a plugin which generates branched tilings for newconformist
// https://github.com/zenorogue/newconformist (see the option '-cvl')
2020-07-30 08:13:46 +00:00
#include "../hyper.h"
2019-02-10 09:43:28 +00:00
namespace hr {
#if CAP_SHOT
2020-07-30 08:13:46 +00:00
2019-02-10 09:43:28 +00:00
struct location {
transmatrix lView;
2019-11-14 19:26:07 +00:00
cell *lco;
2019-02-10 09:43:28 +00:00
};
struct lineinfo {
vector<location> locs;
int plus_matrices;
int minus_matrices;
};
map<int, lineinfo> lines;
location loc_multiply(location orig, transmatrix T) {
dynamicval<transmatrix> dv(View, orig.lView);
2019-11-14 19:26:07 +00:00
dynamicval<cell*> dc(centerover, orig.lco);
2019-02-10 09:43:28 +00:00
View = inverse(T) * View;
for(int a=0; a<10; a++) optimizeview();
2019-11-14 19:26:07 +00:00
return location{View, centerover};
2019-02-10 09:43:28 +00:00
}
bool show_map = false;
void cvl_marker() {
if(show_map) for(auto& l: lines) {
int id = 0;
for(auto& loc: l.second.locs) {
2019-11-14 19:26:07 +00:00
if(gmatrix.count(loc.lco)) {
2020-07-30 08:13:46 +00:00
shiftmatrix T = gmatrix[loc.lco] * inverse(loc.lView);
2019-05-27 05:18:18 +00:00
queuepoly(T, cgi.shAsymmetric, 0xFF00FFFF);
2019-02-10 09:43:28 +00:00
queuestr(T, 1.0, its(l.first)+"/"+its(id), 0xFFFFFF);
}
id++;
}
}
}
int readArgs() {
using namespace arg;
if(0) ;
else if(argis("-cvlbuild")) {
PHASEFROM(3);
start_game();
shift();
fhstream f(argcs(), "rt");
if(!f.f) { shift(); printf("failed to open file\n"); return 0; }
2019-02-10 09:43:28 +00:00
int id;
lineinfo l0;
scan(f, id, l0.plus_matrices, l0.minus_matrices);
2019-11-14 19:26:07 +00:00
l0.locs.push_back(location{View, centerover});
2019-02-10 09:43:28 +00:00
for(int i=1; i<l0.plus_matrices; i++)
l0.locs.push_back(loc_multiply(l0.locs.back(), xpush(1)));
lines[id] = std::move(l0);
while(true) {
scan(f, id);
2019-02-10 09:43:28 +00:00
println(hlog, "id=", id, ".");
if(id < 0) break;
auto& l1 = lines[id];
int step;
scan(f, id, step);
2019-02-10 09:43:28 +00:00
transmatrix T;
for(int a=0; a<9; a++) scan(f, T[0][a]);
scan(f, l1.plus_matrices, l1.minus_matrices);
2019-02-10 09:43:28 +00:00
auto old = lines[id].locs[step];
2019-11-14 19:26:07 +00:00
println(hlog, "FROM ", old.lView, old.lco, " id=", id, " step=", step);
2019-02-10 09:43:28 +00:00
l1.locs.push_back(loc_multiply(old, T));
2019-11-14 19:26:07 +00:00
println(hlog, "TO ", l1.locs.back().lView, l1.locs.back().lco, "; creating ", l1.plus_matrices);
2019-02-10 09:43:28 +00:00
for(int i=1; i<l1.plus_matrices; i++)
l1.locs.push_back(loc_multiply(l1.locs.back(), xpush(1)));
2019-11-14 19:26:07 +00:00
println(hlog, "LAST ", l1.locs.back().lView, l1.locs.back().lco);
2019-02-10 09:43:28 +00:00
}
}
else if(argis("-cvllist")) {
for(auto& l: lines)
for(auto& loc: l.second.locs) {
2019-11-14 19:26:07 +00:00
println(hlog, l.first, ". ", loc.lco, " (dist=", celldist(loc.lco), "), View = ", loc.lView);
2019-02-10 09:43:28 +00:00
}
}
else if(argis("-cvlmap")) {
show_map = !show_map;
}
else if(argis("-cvldraw")) {
shift(); string s = args();
for(auto& p: lines) {
int i = 0;
for(auto& loc: p.second.locs) {
dynamicval<transmatrix> dv(View, loc.lView);
2019-11-14 19:26:07 +00:00
dynamicval<cell*> dc(centerover, loc.lco);
2019-02-10 09:43:28 +00:00
shot::take(format(s.c_str(), p.first, i++));
}
}
}
else return 1;
return 0;
}
auto magichook = addHook(hooks_args, 100, readArgs) + addHook(hooks_frame, 100, cvl_marker);
#endif
2019-02-10 09:43:28 +00:00
}