1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-27 02:20:36 +00:00

Merge pull request #246 from Quuxplusone/adc

Adc
This commit is contained in:
Zeno Rogue 2021-07-21 10:20:41 +02:00 committed by GitHub
commit 9941d602f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 36 deletions

View File

@ -45,7 +45,23 @@ EX bool hide_player() {
;
}
#define ADC(V,c) IF_KEY_EXISTS(it, current_display->all_drawn_copies, c) for(const shiftmatrix& V: it->second)
template<class T>
class span {
T *begin_ = nullptr;
T *end_ = nullptr;
public:
explicit span() = default;
explicit span(T *p, int n) : begin_(p), end_(p + n) {}
T *begin() const { return begin_; }
T *end() const { return end_; }
};
template<class Map, class Key>
hr::span<const shiftmatrix> span_at(const Map& map, const Key& key) {
auto it = map.find(key);
return (it == map.end()) ? hr::span<const shiftmatrix>() : hr::span<const shiftmatrix>(it->second.data(), it->second.size());
}
EX hookset<bool(int sym, int uni)> hooks_handleKey;
EX hookset<bool(cell *c, const shiftmatrix& V)> hooks_drawcell;
@ -4361,7 +4377,8 @@ EX void queuecircleat1(cell *c, const shiftmatrix& V, double rad, color_t col) {
EX void queuecircleat(cell *c, double rad, color_t col) {
if(!c) return;
ADC(V, c) queuecircleat1(c, V, rad, col);
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, c))
queuecircleat1(c, V, rad, col);
}
#endif
@ -4418,7 +4435,8 @@ EX void drawMarkers() {
ignore(ok);
#if CAP_QUEUE
if(haveMount()) ADC(V, dragon::target) {
if(haveMount())
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, dragon::target)) {
queuestr(V, 1, "X",
gradient(0, iinf[itOrbDomination].color, -1, sintick(dragon::whichturn == turncount ? 75 : 150), 1));
}
@ -4536,15 +4554,19 @@ EX void drawMarkers() {
int adj = 1 - ((sword_angles/cwt.at->type)&1);
if(items[itOrbSword]) ADC(V, cwt.at)
if(items[itOrbSword])
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
queuestr(V * spin(M_PI+(-adj-2*ang)*M_PI/sword_angles) * xpush0(cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword].color);
if(items[itOrbSword2]) ADC(V, cwt.at)
if(items[itOrbSword2])
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
queuestr(V * spin((-adj-2*ang)*M_PI/sword_angles) * xpush0(-cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword2].color);
}
if(SWORDDIM == 3 && !shmup::on) {
if(items[itOrbSword]) ADC(V, cwt.at)
if(items[itOrbSword])
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
queuestr(V * sword::dir[multi::cpid].T * xpush0(cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword].color);
if(items[itOrbSword2]) ADC(V, cwt.at)
if(items[itOrbSword2])
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, cwt.at))
queuestr(V * sword::dir[multi::cpid].T * xpush0(-cgi.sword_size), vid.fsize*2, "+", iinf[itOrbSword2].color);
}
}
@ -4603,11 +4625,18 @@ void drawFlashes() {
bool kill = true;
flashdata& f = flashes[k];
bool copies = false;
ADC(V, f.where) copies = true, draw_flash(f, V, kill);
forCellIdEx(c2, id, f.where) if(!copies) ADC(V, c2) {
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, f.where)) {
copies = true;
draw_flash(f, V, kill);
}
forCellIdEx(c2, id, f.where) {
if(!copies) {
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, c2)) {
draw_flash(f, V * currentmap->iadj(f.where, id), kill);
copies = true;
}
}
}
if(f.t > ticks - 800 && !copies) {
kill = false;
}

12
hyper.h
View File

@ -575,11 +575,6 @@ typedef function<int(struct cell*)> cellfunction;
#define forCellCM(ct, cf) forCellIdCM(ct,forCellCM ## __LINE__,cf)
#define forCellAll(ct, cf) forCellIdCM(ct,forCellAll ## __LINE__,cf)
/* conditions */
/** `IF_KEY_EXISTS(it, map, key) statement` checks whether the map 'map' contain key 'key', and if so, executes statement with it set to the relevant iterator */
#define IF_KEY_EXISTS(it, map, key) for(auto it: {map.find(key)}) if(it != map.end())
// canAttack/moveval flags
#define AF_NORMAL 0 // nothing special about this attack
@ -851,6 +846,13 @@ template<class T> array<T, 4> make_array(T a, T b, T c, T d) { array<T,4> x; x[0
template<class T> array<T, 3> make_array(T a, T b, T c) { array<T,3> x; x[0] = a; x[1] = b; x[2] = c; return x; }
template<class T> array<T, 2> make_array(T a, T b) { array<T,2> x; x[0] = a; x[1] = b; return x; }
// Find in a std::map or std::unordered_map, or return null.
template<class Map, class Key>
const typename Map::mapped_type *at_or_null(const Map& map, const Key& key) {
auto it = map.find(key);
return (it == map.end()) ? nullptr : &it->second;
}
namespace daily {
extern bool on;
extern int daily_id;

View File

@ -207,10 +207,10 @@ cld exp_parser::parse(int prio) {
cld c = rparse(0);
force_eat(")");
IF_KEY_EXISTS(it, extra_params, "angleunit") {
a *= it->second;
b *= it->second;
c *= it->second;
if (auto *angleunit = hr::at_or_null(extra_params, "angleunit")) {
a *= *angleunit;
b *= *angleunit;
c *= *angleunit;
}
return edge_of_triangle_with_angles(real(a), real(b), real(c));
@ -237,14 +237,14 @@ cld exp_parser::parse(int prio) {
test.compute_sum();
test.compute_geometry();
res = test.edgelength;
IF_KEY_EXISTS(it, extra_params, "distunit")
res /= it->second;
if (auto *distunit = hr::at_or_null(extra_params, "distunit"))
res /= *distunit;
}
#endif
else if(eat("regangle(")) {
cld edgelen = parse(0);
IF_KEY_EXISTS(it, extra_params, "distunit") {
edgelen = edgelen * it->second;
if (auto *distunit = hr::at_or_null(extra_params, "distunit")) {
edgelen *= *distunit;
}
force_eat(",");
@ -260,14 +260,14 @@ cld exp_parser::parse(int prio) {
if(arb::legacy) {
res = M_PI - result;
IF_KEY_EXISTS(it, extra_params, "angleofs")
res -= it->second;
if (auto *angleofs = hr::at_or_null(extra_params, "angleofs"))
res -= *angleofs;
}
else
res = result;
IF_KEY_EXISTS(it, extra_params, "angleunit")
res /= it->second;
if (auto *angleunit = hr::at_or_null(extra_params, "angleunit"))
res /= *angleunit;
}
else if(eat("test(")) {
res = parsepar();
@ -318,8 +318,8 @@ cld exp_parser::parse(int prio) {
else if(next() == '(') at++, res = parsepar();
else {
string number = next_token();
IF_KEY_EXISTS(it, extra_params, number) res = it->second;
else IF_KEY_EXISTS(it, params, number) res = it->second->get_cld();
if (auto *p = hr::at_or_null(extra_params, number)) res = *p;
else if (auto *p = hr::at_or_null(params, number)) res = (*p)->get_cld();
else if(number == "e") res = exp(1);
else if(number == "i") res = cld(0, 1);
else if(number == "p" || number == "pi") res = M_PI;