refactored celldraw

This commit is contained in:
Zeno Rogue 2019-10-25 12:44:41 +02:00
parent 4d5fb13b32
commit 85a08d205d
18 changed files with 3427 additions and 3304 deletions

View File

@ -620,7 +620,7 @@ struct hrmap_archimedean : hrmap {
if(id < 2*current.N ? !DUAL : !PURE) {
if(!do_draw(h->c7, V)) continue;
drawcell(h->c7, V, 0, false);
drawcell(h->c7, V);
}
for(int i=0; i<S; i++) {

View File

@ -392,7 +392,7 @@ EX namespace binary {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
if(geometry == gBinaryTiling) {
dq::enqueue(h->move(bd_up), V * xpush(-log(2)));

2671
celldrawer.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -572,7 +572,7 @@ struct hrmap_crystal : hrmap_standard {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
if(wallopt && isWall3(c) && isize(dq::drawqueue) > 1000) continue;

View File

@ -693,7 +693,7 @@ EX namespace euclid3 {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
if(wallopt && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int i=0; i<S7; i++)
@ -1244,7 +1244,7 @@ void hrmap_euclid_any::draw() {
}
if(do_draw(cw.at, Mat)) {
drawcell(cw.at, cw.mirrored ? Mat * spin(-2*M_PI*cw.spin / cw.at->type) * Mirror : Mat, cw.spin, cw.mirrored);
drawcell(cw, cw.mirrored ? Mat * spin(-2*M_PI*cw.spin / cw.at->type) * Mirror : Mat);
for(int x=-1; x<=+1; x++)
for(int y=-1; y<=+1; y++) {
euspot p(dx+x, dy+y);

View File

@ -640,8 +640,10 @@ color_t distribute_color(int id) {
return v;
}
EX void do_viewdist(cell *c, const transmatrix& V, color_t& wcol, color_t& fcol) {
void celldrawer::do_viewdist() {
if(behindsphere(V)) return;
cell *c = cw.at;
int cd = (use_color_codes || number_coding == ncDistance || number_coding == ncDebug) ? curr_dist(c) : 0;

3190
graph.cpp

File diff suppressed because it is too large Load Diff

108
hud.cpp
View File

@ -8,23 +8,6 @@
#include "hyper.h"
namespace hr {
#if HDR
struct radarpoint {
hyperpoint h;
char glyph;
color_t color;
color_t line;
};
struct radarline {
hyperpoint h1, h2;
color_t line;
};
#endif
EX vector<radarpoint> radarpoints;
EX vector<radarline> radarlines;
EX purehookset hooks_stats;
EX int monsterclass(eMonster m) {
@ -380,97 +363,6 @@ void drawMobileArrow(int i) {
EX bool nofps = false;
EX void draw_radar(bool cornermode) {
if(dual::split([] { dual::in_subscreen([] { calcparam(); draw_radar(false); }); })) return;
bool d3 = WDIM == 3;
bool hyp = hyperbolic;
bool sph = sphere;
bool scompass = nonisotropic && !hybri;
dynamicval<eGeometry> g(geometry, gEuclid);
dynamicval<eModel> pm(pmodel, mdDisk);
dynamicval<bool> ga(vid.always3, false);
dynamicval<geometryinfo1> gi(ginf[gEuclid].g, giEuclid2);
initquickqueue();
int rad = vid.radarsize;
if(dual::state) rad /= 2;
ld cx = dual::state ? (dual::currently_loaded ? vid.xres/2+rad+2 : vid.xres/2-rad-2) : cornermode ? rad+2 : vid.xres-rad-2;
ld cy = vid.yres-rad-2 - vid.fsize;
for(int i=0; i<360; i++)
curvepoint(atscreenpos(cx-cos(i * degree)*rad, cy-sin(i*degree)*rad, 1) * C0);
queuecurve(0xFFFFFFFF, 0x000000FF, PPR::ZERO);
ld alpha = 15 * degree;
ld co = cos(alpha);
ld si = sin(alpha);
if(sph && !d3) {
for(int i=0; i<360; i++)
curvepoint(atscreenpos(cx-cos(i * degree)*rad, cy-sin(i*degree)*rad*si, 1) * C0);
queuecurve(0, 0x200000FF, PPR::ZERO);
}
if(d3) {
for(int i=0; i<360; i++)
curvepoint(atscreenpos(cx-cos(i * degree)*rad, cy-sin(i*degree)*rad*si, 1) * C0);
queuecurve(0xFF0000FF, 0x200000FF, PPR::ZERO);
curvepoint(atscreenpos(cx-sin(vid.fov*degree/2)*rad, cy-sin(vid.fov*degree/2)*rad*si, 1) * C0);
curvepoint(atscreenpos(cx, cy, 1) * C0);
curvepoint(atscreenpos(cx+sin(vid.fov*degree/2)*rad, cy-sin(vid.fov*degree/2)*rad*si, 1) * C0);
queuecurve(0xFF8000FF, 0, PPR::ZERO);
}
if(d3) for(auto& r: radarpoints) {
queueline(atscreenpos(cx+rad * r.h[0], cy - rad * r.h[2] * si + rad * r.h[1] * co, 0)*C0, atscreenpos(cx+rad*r.h[0], cy - rad*r.h[2] * si, 0)*C0, r.line, -1);
}
if(scompass) {
auto compassdir = [&] (char dirname, hyperpoint h) {
h = nisot::local_perspective * h * .8;
queueline(atscreenpos(cx+rad * h[0], cy - rad * h[2] * si + rad * h[1] * co, 0)*C0, atscreenpos(cx+rad*h[0], cy - rad*h[2] * si, 0)*C0, 0xA0401040, -1);
displaychr(int(cx+rad * h[0]), int(cy - rad * h[2] * si + rad * h[1] * co), 0, 8, dirname, 0xA04010);
};
compassdir('E', point3(+1, 0, 0));
compassdir('N', point3(0, +1, 0));
compassdir('W', point3(-1, 0, 0));
compassdir('S', point3(0, -1, 0));
compassdir('U', point3(0, 0,+1));
compassdir('D', point3(0, 0,-1));
}
auto locate = [&] (hyperpoint h) {
if(sph)
return point3(cx + (rad-10) * h[0], cy + (rad-10) * h[2] * si + (rad-10) * h[1] * co, +h[1] * si > h[2] * co ? 8 : 16);
else if(hyp)
return point3(cx + rad * h[0], cy + rad * h[1], 1/(1+h[3]) * cgi.scalefactor * current_display->radius / (inHighQual ? 10 : 6));
else
return point3(cx + rad * h[0], cy + rad * h[1], rad * cgi.scalefactor / (vid.radarrange + cgi.scalefactor/4) * 0.8);
};
for(auto& r: radarlines) {
hyperpoint h1 = locate(r.h1);
hyperpoint h2 = locate(r.h2);
h1 = tC0(atscreenpos(h1[0], h1[1], 1));
h2 = tC0(atscreenpos(h2[0], h2[1], 1));
queueline(h1, h2, r.line, -1);
}
quickqueue();
glflush();
for(auto& r: radarpoints) {
if(d3) displaychr(int(cx + rad * r.h[0]), int(cy - rad * r.h[2] * si + rad * r.h[1] * co), 0, 8, r.glyph, r.color);
else {
hyperpoint h = locate(r.h);
displaychr(int(h[0]), int(h[1]), 0, int(h[2]), r.glyph, r.color);
}
}
}
EX color_t crosshair_color = 0xFFFFFFC0;
EX ld crosshair_size = 0;

View File

@ -90,9 +90,12 @@
#include "rug.cpp"
#include "control.cpp"
#include "hud.cpp"
#include "radar.cpp"
#include "hypgraph.cpp"
#include "textures.cpp"
#include "graph.cpp"
#include "celldrawer.cpp"
#include "sky.cpp"
#include "blizzard.cpp"
#include "sound.cpp"
#include "achievement.cpp"

View File

@ -1069,7 +1069,7 @@ void drawrec(cell *c, const transmatrix& V) {
if(maindir != li.last_dir) printf("ld %d/%d\n", maindir, li.last_dir); */
draw_li.relative = at;
draw_li.total_dir = fixg6(dir);
drawcell(c, V1, 0, false);
drawcell(c, V1);
res = true;
}
for(int i=0; i<c->type; i++) {
@ -1088,7 +1088,7 @@ void drawrec(cell *c, const transmatrix& V) {
draw_li.last_dir = -1;
bool res = false;
if(do_draw(c, V))
drawcell(c, V, 0, false), res = true;
drawcell(c, V), res = true;
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
if(!c2) continue;
@ -1169,7 +1169,7 @@ void hrmap_standard::draw() {
transmatrix V1 = V0 * irr::cells[vc[i]].pusher;
if(do_draw(c, V1))
draw = true,
drawcell(hi.subcells[i], V0 * irr::cells[vc[i]].pusher, 0, false);
drawcell(hi.subcells[i], V0 * irr::cells[vc[i]].pusher);
}
}
#endif
@ -1177,7 +1177,7 @@ void hrmap_standard::draw() {
else {
if(do_draw(c, V1)) {
transmatrix V2 = actualV(hs, V1);
drawcell(c, V2, 0, hs.mirrored);
drawcell(cellwalker(c, 0, hs.mirrored), V2);
draw = true;
}
@ -1188,7 +1188,7 @@ void hrmap_standard::draw() {
transmatrix V2 = V1 * cgi.hexmove[d];
if(do_draw(c->move(ds), V2))
draw = true,
drawcell(c->move(ds), V2, 0, hs.mirrored ^ c->c.mirror(ds));
drawcell(cellwalker(c->move(ds), 0, hs.mirrored ^ c->c.mirror(ds)), V2);
}
}
}

View File

@ -1110,6 +1110,11 @@ namespace mapeditor {
#endif
EX void drawGhosts(cell *c, const transmatrix& V, int ct) {
if((cmode & sm::MAP) && lmouseover && darken == 0 &&
(GDIM == 3 || !mouseout()) &&
(patterns::whichPattern ? patterns::getpatterninfo0(c).id == patterns::getpatterninfo0(lmouseover).id : c == lmouseover)) {
queuecircleat(c, .78, 0x00FFFFFF);
}
}
hyperpoint ccenter = C0;

View File

@ -386,7 +386,7 @@ EX namespace solnihv {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
if(wallopt && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int i=0; i<S7; i++) {
@ -833,7 +833,7 @@ EX namespace nilv {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
if(wallopt && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
if(0) for(int t=0; t<c->type; t++) {
@ -1123,7 +1123,8 @@ EX namespace product {
EX int cwall_offset, cwall_mask, actual_view_level;
EX void drawcell_stack(cell *c, transmatrix V, int spinv, bool mirrored) {
EX void drawcell_stack(cellwalker cw, transmatrix V) {
cell *c = cw.at;
if(sphere) gmatrix[c] = V; /* some computations need gmatrix0 for underlying geometry */
bool s = sphere;
hybrid::in_actual([&] {
@ -1146,7 +1147,8 @@ EX namespace product {
if(z == 1) cwall_mask ^= (1<<c->type);
cell *c1 = hybrid::get_at(c, actual_view_level+z);
setdist(c1, 7, NULL);
drawcell(c1, V * mscale(Id, cgi.plevel * (z+actual_view_level - hybrid::current_view_level)), spinv, mirrored);
cw.at = c1;
drawcell(cw, V * mscale(Id, cgi.plevel * (z+actual_view_level - hybrid::current_view_level)));
}
});
}
@ -1539,10 +1541,10 @@ EX namespace rots {
if(sl2) {
if(V[3][3] < 0) V = centralsym * V;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
}
else {
drawcell(c, V, 0, false);
drawcell(c, V);
}
if(wallopt && isWall3(c) && isize(dq::drawqueue) > 1000) continue;

View File

@ -352,7 +352,7 @@ struct hrmap_kite : hrmap {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
for(int i=0; i<c->type; i++)
dq::enqueue(c->cmove(i)->master, V * tmatrix(c, i));

185
radar.cpp Normal file
View File

@ -0,0 +1,185 @@
#include "hyper.h"
namespace hr {
#if HDR
struct radarpoint {
hyperpoint h;
char glyph;
color_t color;
color_t line;
};
struct radarline {
hyperpoint h1, h2;
color_t line;
};
#endif
EX vector<radarpoint> radarpoints;
EX vector<radarline> radarlines;
EX transmatrix radar_transform;
pair<bool, hyperpoint> makeradar(hyperpoint h) {
if(GDIM == 3 && WDIM == 2) h = radar_transform * h;
ld d = hdist0(h);
if(sol && nisot::geodesic_movement) {
h = inverse_exp(h, iLazy);
ld r = hypot_d(3, h);
if(r < 1) h = h * (atanh(r) / r);
else return {false, h};
}
if(prod) h = product::inverse_exp(h);
if(nisot::local_perspective_used()) h = nisot::local_perspective * h;
if(WDIM == 3) {
if(d >= vid.radarrange) return {false, h};
if(d) h = h * (d / vid.radarrange / hypot_d(3, h));
}
else if(hyperbolic) {
for(int a=0; a<3; a++) h[a] = h[a] / (1 + h[3]);
}
else if(sphere) {
h[2] = h[3];
}
else {
if(d > vid.radarrange) return {false, h};
if(d) h = h * (d / (vid.radarrange + cgi.scalefactor/4) / hypot_d(3, h));
}
if(invalid_point(h)) return {false, h};
return {true, h};
}
EX void addradar(const transmatrix& V, char ch, color_t col, color_t outline) {
hyperpoint h = tC0(V);
auto hp = makeradar(h);
if(hp.first)
radarpoints.emplace_back(radarpoint{hp.second, ch, col, outline});
}
EX void addradar(const hyperpoint h1, const hyperpoint h2, color_t col) {
auto hp1 = makeradar(h1);
auto hp2 = makeradar(h2);
if(hp1.first && hp2.first)
radarlines.emplace_back(radarline{hp1.second, hp2.second, col});
}
void celldrawer::drawcell_in_radar() {
cell *c = cw.at;
#if CAP_SHMUP
if(shmup::on) {
pair<shmup::mit, shmup::mit> p =
shmup::monstersAt.equal_range(c);
for(shmup::mit it = p.first; it != p.second; it++) {
shmup::monster* m = it->second;
addradar(V*m->at, minf[m->type].glyph, minf[m->type].color, 0xFF0000FF);
}
}
#endif
if(c->monst)
addradar(V, minf[c->monst].glyph, minf[c->monst].color, isFriendly(c->monst) ? 0x00FF00FF : 0xFF0000FF);
else if(c->item && !itemHiddenFromSight(c))
addradar(V, iinf[c->item].glyph, iinf[c->item].color, kind_outline(c->item));
}
void celldrawer::radar_grid() {
cell *c = cw.at;
for(int t=0; t<c->type; t++)
if(c->move(t) && c->move(t) < c)
addradar(V*get_corner_position(c, t%c->type), V*get_corner_position(c, (t+1)%c->type), gridcolor(c, c->move(t)));
}
EX void draw_radar(bool cornermode) {
if(dual::split([] { dual::in_subscreen([] { calcparam(); draw_radar(false); }); })) return;
bool d3 = WDIM == 3;
bool hyp = hyperbolic;
bool sph = sphere;
bool scompass = nonisotropic && !hybri;
dynamicval<eGeometry> g(geometry, gEuclid);
dynamicval<eModel> pm(pmodel, mdDisk);
dynamicval<bool> ga(vid.always3, false);
dynamicval<geometryinfo1> gi(ginf[gEuclid].g, giEuclid2);
initquickqueue();
int rad = vid.radarsize;
if(dual::state) rad /= 2;
ld cx = dual::state ? (dual::currently_loaded ? vid.xres/2+rad+2 : vid.xres/2-rad-2) : cornermode ? rad+2 : vid.xres-rad-2;
ld cy = vid.yres-rad-2 - vid.fsize;
for(int i=0; i<360; i++)
curvepoint(atscreenpos(cx-cos(i * degree)*rad, cy-sin(i*degree)*rad, 1) * C0);
queuecurve(0xFFFFFFFF, 0x000000FF, PPR::ZERO);
ld alpha = 15 * degree;
ld co = cos(alpha);
ld si = sin(alpha);
if(sph && !d3) {
for(int i=0; i<360; i++)
curvepoint(atscreenpos(cx-cos(i * degree)*rad, cy-sin(i*degree)*rad*si, 1) * C0);
queuecurve(0, 0x200000FF, PPR::ZERO);
}
if(d3) {
for(int i=0; i<360; i++)
curvepoint(atscreenpos(cx-cos(i * degree)*rad, cy-sin(i*degree)*rad*si, 1) * C0);
queuecurve(0xFF0000FF, 0x200000FF, PPR::ZERO);
curvepoint(atscreenpos(cx-sin(vid.fov*degree/2)*rad, cy-sin(vid.fov*degree/2)*rad*si, 1) * C0);
curvepoint(atscreenpos(cx, cy, 1) * C0);
curvepoint(atscreenpos(cx+sin(vid.fov*degree/2)*rad, cy-sin(vid.fov*degree/2)*rad*si, 1) * C0);
queuecurve(0xFF8000FF, 0, PPR::ZERO);
}
if(d3) for(auto& r: radarpoints) {
queueline(atscreenpos(cx+rad * r.h[0], cy - rad * r.h[2] * si + rad * r.h[1] * co, 0)*C0, atscreenpos(cx+rad*r.h[0], cy - rad*r.h[2] * si, 0)*C0, r.line, -1);
}
if(scompass) {
auto compassdir = [&] (char dirname, hyperpoint h) {
h = nisot::local_perspective * h * .8;
queueline(atscreenpos(cx+rad * h[0], cy - rad * h[2] * si + rad * h[1] * co, 0)*C0, atscreenpos(cx+rad*h[0], cy - rad*h[2] * si, 0)*C0, 0xA0401040, -1);
displaychr(int(cx+rad * h[0]), int(cy - rad * h[2] * si + rad * h[1] * co), 0, 8, dirname, 0xA04010);
};
compassdir('E', point3(+1, 0, 0));
compassdir('N', point3(0, +1, 0));
compassdir('W', point3(-1, 0, 0));
compassdir('S', point3(0, -1, 0));
compassdir('U', point3(0, 0,+1));
compassdir('D', point3(0, 0,-1));
}
auto locate = [&] (hyperpoint h) {
if(sph)
return point3(cx + (rad-10) * h[0], cy + (rad-10) * h[2] * si + (rad-10) * h[1] * co, +h[1] * si > h[2] * co ? 8 : 16);
else if(hyp)
return point3(cx + rad * h[0], cy + rad * h[1], 1/(1+h[3]) * cgi.scalefactor * current_display->radius / (inHighQual ? 10 : 6));
else
return point3(cx + rad * h[0], cy + rad * h[1], rad * cgi.scalefactor / (vid.radarrange + cgi.scalefactor/4) * 0.8);
};
for(auto& r: radarlines) {
hyperpoint h1 = locate(r.h1);
hyperpoint h2 = locate(r.h2);
h1 = tC0(atscreenpos(h1[0], h1[1], 1));
h2 = tC0(atscreenpos(h2[0], h2[1], 1));
queueline(h1, h2, r.line, -1);
}
quickqueue();
glflush();
for(auto& r: radarpoints) {
if(d3) displaychr(int(cx + rad * r.h[0]), int(cy - rad * r.h[2] * si + rad * r.h[1] * co), 0, 8, r.glyph, r.color);
else {
hyperpoint h = locate(r.h);
displaychr(int(h[0]), int(h[1]), 0, int(h[2]), r.glyph, r.color);
}
}
}
}

View File

@ -470,10 +470,10 @@ EX void do_raycast() {
}
connections[u] = enc(ids[c1] * S7);
if(isWall3(c1)) {
color_t wcol;
color_t fcol;
setcolors(c1, wcol, fcol);
wcol = darkena(wcol, 0, 0xFF);
celldrawer dd;
dd.cw.at = c1;
dd.setcolors();
color_t wcol = darkena(dd.wcol, 0, 0xFF);
wallcolor[u] = glhr::acolor(wcol);
}
else

View File

@ -570,7 +570,7 @@ EX namespace reg3 {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
if(wallopt && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int d=0; d<S7; d++)
@ -864,7 +864,7 @@ EX namespace reg3 {
cell *c = h->c7;
if(!do_draw(c, V)) continue;
drawcell(c, V, 0, false);
drawcell(c, V);
if(wallopt && isWall3(c) && isize(dq::drawqueue) > 1000) continue;
for(int i=0; i<S7; i++) if(h->move(i)) {

218
shmup.cpp
View File

@ -2755,14 +2755,116 @@ EX bool boatAt(cell *c) {
EX hookset<bool(const transmatrix&, cell*, shmup::monster*)> *hooks_draw;
EX bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, transmatrix& Vboat0, const transmatrix *Vdp) {
EX void clearMonsters() {
for(mit it = monstersAt.begin(); it != monstersAt.end(); it++)
delete(it->second);
for(monster *m: active) delete m;
mousetarget = NULL;
lmousetarget = NULL;
monstersAt.clear();
active.clear();
}
EX void clearMemory() {
clearMonsters();
gmatrix.clear();
while(!traplist.empty()) traplist.pop();
curtime = 0;
nextmove = 0;
nextdragon = 0;
visibleAt = 0;
for(int i=0; i<MAXPLAYER; i++) pc[i] = NULL;
}
void gamedata(hr::gamedata* gd) {
if(shmup::on) {
gd->store(pc[0]); // assuming 1 player!
gd->store(nextmove);
gd->store(curtime);
gd->store(nextdragon);
gd->store(visibleAt);
gd->store(traplist);
gd->store(monstersAt);
gd->store(active);
gd->store(mousetarget);
gd->store(lmousetarget);
gd->store(nonvirtual);
gd->store(additional);
if(WDIM == 3) gd->store(swordmatrix[0]); // assuming 1 player!
gd->store(traplist);
gd->store(firetraplist);
}
}
EX cell *playerpos(int i) {
if(!pc[i]) return NULL;
return pc[i]->base;
}
EX bool playerInBoat(int i) {
if(!pc[i]) return false;
return pc[i]->inBoat;
}
EX void destroyBoats(cell *c) {
for(monster *m: active)
if(m->base == c && m->inBoat)
m->inBoat = false;
}
EX void virtualRebase(shmup::monster *m, bool tohex) {
virtualRebase(m->base, m->at, tohex);
}
EX hookset<bool(shmup::monster*, string&)> *hooks_describe;
EX void addShmupHelp(string& out) {
if(shmup::mousetarget && sqdist(mouseh, tC0(shmup::mousetarget->pat)) < .1) {
if(callhandlers(false, hooks_describe, shmup::mousetarget, out)) return;
out += XLAT1(minf[shmup::mousetarget->type].name);
help = generateHelpForMonster(shmup::mousetarget->type);
}
}
auto hooks = addHook(clearmemory, 0, shmup::clearMemory) +
addHook(hooks_gamedata, 0, shmup::gamedata) +
addHook(hooks_removecells, 0, [] () {
for(mit it = monstersAt.begin(); it != monstersAt.end();) {
if(is_cell_removed(it->first)) {
monstersAt.insert(make_pair(nullptr, it->second));
auto it0 = it; it++;
monstersAt.erase(it0);
}
else it++;
}
});
EX void switch_shmup() {
stop_game();
switch_game_mode(rg::shmup);
resetScores();
start_game();
configure();
}
#if MAXMDIM >= 4
auto hooksw = addHook(hooks_swapdim, 100, [] {
for(auto& p: monstersAt) swapmatrix(p.second->at);
});
#endif
}
bool celldrawer::draw_shmup_monster() {
using namespace shmup;
auto& c = cw.at;
#if CAP_SHAPES
pair<mit, mit> p =
monstersAt.equal_range(c);
if(p.first == p.second) return false;
ld zlev = -geom3::factor_to_lev(zlevel(tC0((*Vdp))));
ld zlev = -geom3::factor_to_lev(zlevel(tC0(Vd)));
vector<monster*> monsters;
@ -2781,21 +2883,20 @@ EX bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, tr
if(m->inBoat) {
view = m->pat;
Vboat = &Vboat0;
if(WDIM == 2) Vboat0 = view;
if(WDIM == 3) Vboat0 = view * spin(-M_PI/2);
if(WDIM == 2) Vboat = view;
if(WDIM == 3) Vboat = view * spin(-M_PI/2);
bool magic = m->type == moPlayer && items[itOrbWater];
color_t outcolor = magic ? watercolor(0) : 0xC06000FF;
color_t incolor = magic ? 0x0060C0FF : 0x804000FF;
if(WDIM == 2) {
queuepoly(Vboat0, cgi.shBoatOuter, outcolor);
queuepoly(Vboat0, cgi.shBoatInner, incolor);
queuepoly(Vboat, cgi.shBoatOuter, outcolor);
queuepoly(Vboat, cgi.shBoatInner, incolor);
}
if(WDIM == 3) {
queuepoly(mscale(Vboat0, cgi.scalefactor/2), cgi.shBoatOuter, outcolor);
queuepoly(mscale(Vboat0, cgi.scalefactor/2-0.01), cgi.shBoatInner, incolor);
queuepoly(mscale(Vboat, cgi.scalefactor/2), cgi.shBoatOuter, outcolor);
queuepoly(mscale(Vboat, cgi.scalefactor/2-0.01), cgi.shBoatInner, incolor);
}
}
@ -2934,103 +3035,4 @@ EX bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, tr
return false;
}
EX void clearMonsters() {
for(mit it = monstersAt.begin(); it != monstersAt.end(); it++)
delete(it->second);
for(monster *m: active) delete m;
mousetarget = NULL;
lmousetarget = NULL;
monstersAt.clear();
active.clear();
}
EX void clearMemory() {
clearMonsters();
gmatrix.clear();
while(!traplist.empty()) traplist.pop();
curtime = 0;
nextmove = 0;
nextdragon = 0;
visibleAt = 0;
for(int i=0; i<MAXPLAYER; i++) pc[i] = NULL;
}
void gamedata(hr::gamedata* gd) {
if(shmup::on) {
gd->store(pc[0]); // assuming 1 player!
gd->store(nextmove);
gd->store(curtime);
gd->store(nextdragon);
gd->store(visibleAt);
gd->store(traplist);
gd->store(monstersAt);
gd->store(active);
gd->store(mousetarget);
gd->store(lmousetarget);
gd->store(nonvirtual);
gd->store(additional);
if(WDIM == 3) gd->store(swordmatrix[0]); // assuming 1 player!
gd->store(traplist);
gd->store(firetraplist);
}
}
EX cell *playerpos(int i) {
if(!pc[i]) return NULL;
return pc[i]->base;
}
EX bool playerInBoat(int i) {
if(!pc[i]) return false;
return pc[i]->inBoat;
}
EX void destroyBoats(cell *c) {
for(monster *m: active)
if(m->base == c && m->inBoat)
m->inBoat = false;
}
EX void virtualRebase(shmup::monster *m, bool tohex) {
virtualRebase(m->base, m->at, tohex);
}
EX hookset<bool(shmup::monster*, string&)> *hooks_describe;
EX void addShmupHelp(string& out) {
if(shmup::mousetarget && sqdist(mouseh, tC0(shmup::mousetarget->pat)) < .1) {
if(callhandlers(false, hooks_describe, shmup::mousetarget, out)) return;
out += XLAT1(minf[shmup::mousetarget->type].name);
help = generateHelpForMonster(shmup::mousetarget->type);
}
}
auto hooks = addHook(clearmemory, 0, shmup::clearMemory) +
addHook(hooks_gamedata, 0, shmup::gamedata) +
addHook(hooks_removecells, 0, [] () {
for(mit it = monstersAt.begin(); it != monstersAt.end();) {
if(is_cell_removed(it->first)) {
monstersAt.insert(make_pair(nullptr, it->second));
auto it0 = it; it++;
monstersAt.erase(it0);
}
else it++;
}
});
EX void switch_shmup() {
stop_game();
switch_game_mode(rg::shmup);
resetScores();
start_game();
configure();
}
#if MAXMDIM >= 4
auto hooksw = addHook(hooks_swapdim, 100, [] {
for(auto& p: monstersAt) swapmatrix(p.second->at);
});
#endif
}
}

299
sky.cpp Normal file
View File

@ -0,0 +1,299 @@
#include "hyper.h"
namespace hr {
EX ld camera_level;
EX int get_skybrightness(int mul IS(1)) {
ld s = 1 - mul * (camera_level - cgi.WALL) / -2;
if(s > 1) return 255;
if(s < 0) return 0;
return int(s * 255);
}
struct sky_item {
cell *c;
transmatrix T;
color_t color;
sky_item(cell *_c, const struct transmatrix _T, color_t _color) : c(_c), T(_T), color(_color) {}
};
struct dqi_sky : drawqueueitem {
vector<sky_item> sky;
void draw();
virtual color_t outline_group() { return 3; }
// singleton
dqi_sky() { hr::sky = this; }
~dqi_sky() { hr::sky = NULL; }
};
EX struct dqi_sky *sky;
EX void prepare_sky() {
sky = NULL;
if(euclid) {
if(WDIM == 3 || GDIM == 2) return;
transmatrix T = ggmatrix(currentmap->gamestart());
T = gpushxto0(tC0(T)) * T;
queuepoly(T, cgi.shEuclideanSky, 0x0044e4FF);
queuepolyat(T * zpush(cgi.SKY+0.5) * xpush(cgi.SKY+0.5), cgi.shSun, 0xFFFF00FF, PPR::SKY);
}
else {
sky = &queuea<dqi_sky> (PPR::SKY);
}
}
void dqi_sky::draw() {
if(!vid.usingGL || sky.empty()) return;
vector<glhr::colored_vertex> skyvertices;
int sk = get_skybrightness();
unordered_map<cell*, color_t> colors;
#ifdef USE_UNORDERED_MAP
colors.reserve(isize(sky));
#endif
for(sky_item& si: sky) colors[si.c] = darkena(gradient(0, si.color, 0, sk, 255), 0, 0xFF);
hyperpoint skypoint = cpush0(2, cgi.SKY);
vector<glhr::colored_vertex> this_poly;
// I am not sure why, but extra projection martix introduced in stereo
// causes some vertices to not be drawn. Thus we apply separately
transmatrix Tsh = Id;
if(global_projection)
Tsh = xpush(vid.ipd * global_projection/2);
for(sky_item& si: sky) {
auto c = si.c;
for(int i=0; i<c->type; i++) {
if(1) {
cellwalker cw0(c, i);
cellwalker cw = cw0;
do {
cw += wstep; cw++;
if(cw.at < c || !colors.count(si.c)) goto next;
}
while(cw != cw0);
this_poly.clear();
transmatrix T1 = Tsh * si.T;
do {
this_poly.emplace_back(T1 * skypoint, colors[cw.at]);
T1 = T1 * cellrelmatrix(cw.at, cw.spin);
cw += wstep; cw++;
}
while(cw != cw0);
int k = isize(this_poly);
for(int j=2; j<k; j++) {
skyvertices.push_back(this_poly[0]);
skyvertices.push_back(this_poly[j-1]);
skyvertices.push_back(this_poly[j]);
}
}
next: ;
}
}
for(auto& v: skyvertices) for(int i=0; i<3; i++) v.color[i] *= 2;
for(int ed = current_display->stereo_active() ? -1 : 0; ed<2; ed+=2) {
if(global_projection && global_projection != ed) continue;
current_display->next_shader_flags = GF_VARCOLOR;
current_display->set_all(ed);
if(global_projection)
glhr::projection_multiply(glhr::tmtogl(xpush(-vid.ipd * global_projection/2)));
glapplymatrix(Id);
glhr::prepare(skyvertices);
glhr::set_fogbase(1.0 + 5 / sightranges[geometry]);
glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE);
glhr::set_depthwrite(model_needs_depth() && prio != PPR::TRANSPARENT_SHADOW && prio != PPR::EUCLIDEAN_SKY);
glDrawArrays(GL_TRIANGLES, 0, isize(skyvertices));
}
}
color_t skycolor(cell *c) {
int cd = (euclid || stdhyperbolic) ? getCdata(c, 1) : 0;
int z = (cd * 5) & 127;
if(z >= 64) z = 127 - z;
if(c->land == laHell)
return z < 32 ? gradient(0x400000, 0xFF0000, 0, z, 32) : gradient(0xFF0000, 0xFFFF00, 32, z, 63);
else
return gradient(0x4040FF, 0xFFFFFF, 0, z, 63);
}
void celldrawer::draw_ceiling() {
if(pmodel != mdPerspective || sphere) return;
cell *c = cw.at;
switch(ceiling_category(c)) {
/* ceilingless levels */
case 1: {
if(euclid) return;
if(fieldpattern::fieldval_uniq(c) % 3 == 0) {
queuepolyat(V * zpush(cgi.SKY+1), cgi.shNightStar, 0xFFFFFFFF, PPR::SKY);
}
if(sky) sky->sky.emplace_back(sky_item{c, V, 0x00000F});
if(c->land == laAsteroids) {
if(fieldpattern::fieldval_uniq(c) % 9 < 3) {
queuepolyat(V * zpush(-1-cgi.SKY), cgi.shNightStar, 0xFFFFFFFF, PPR::SKY);
}
int sk = get_skybrightness(-1);
auto sky = draw_shapevec(c, V * MirrorZ, cgi.shFullFloor.levels[SIDE_SKY], 0x000000FF + 0x100 * (sk/17), PPR::SKY);
if(sky) sky->tinf = NULL, sky->flags |= POLY_INTENSE;
}
return;
}
case 2: {
if(euclid) return;
color_t col;
switch(c->land) {
case laWineyard:
col = 0x4040FF;
if(emeraldval(c) / 4 == 11) {
queuepolyat(V * zpush(cgi.SKY+1), cgi.shSun, 0xFFFF00FF, PPR::SKY);
}
break;
case laPower:
col = c->landparam ? 0xFF2010 : 0x000020;
break;
case laDesert:
case laRedRock:
col = 0x4040FF;
break;
case laAlchemist:
col = fcol;
break;
case laVariant: {
int b = getBits(c);
col = 0x404040;
for(int a=0; a<21; a++)
if((b >> a) & 1)
col += variant_features[a].color_change;
col = col & 0x00FF00;
break;
}
case laDragon:
col = c->wall == waChasm ? 0xFFFFFF : 0x4040FF;
break;
default:
col = skycolor(c);
}
if(sky) sky->sky.emplace_back(c, V, col);
return;
}
case 3: {
if(sky) sky->sky.emplace_back(c, V, 0);
if(camera_level <= cgi.WALL) return;
if(c->land == laMercuryRiver) fcol = linf[laTerracotta].color, fd = 1;
if(qfi.fshape) draw_shapevec(c, V, qfi.fshape->levels[SIDE_WALL], darkena(fcol, fd, 0xFF), PPR::WALL);
forCellIdEx(c2, i, c)
if(ceiling_category(c2) != 3) {
color_t wcol2 = gradient(0, wcol, 0, .8, 1);
placeSidewall(c, i, SIDE_HIGH, V, darkena(wcol2, fd, 0xFF));
placeSidewall(c, i, SIDE_HIGH2, V, darkena(wcol2, fd, 0xFF));
placeSidewall(c, i, SIDE_SKY, V, darkena(wcol2, fd, 0xFF));
}
return;
}
case 4: {
if(sky) sky->sky.emplace_back(c, V, 0x00000F);
if(camera_level <= cgi.HIGH2) return;
auto ispal = [&] (cell *c0) { return c0->land == laPalace && among(c0->wall, waPalace, waClosedGate, waOpenGate); };
color_t wcol2 = 0xFFD500;
if(ispal(c)) {
forCellIdEx(c2, i, c) if(!ispal(c2))
placeSidewall(c, i, SIDE_HIGH, V, darkena(wcol2, fd, 0xFF));
}
else {
bool window = false;
forCellIdEx(c2, i, c) if(c2->wall == waPalace && ispal(c->cmodmove(i+1)) && ispal(c->cmodmove(i-1))) window = true;
if(qfi.fshape && !window) draw_shapevec(c, V, qfi.fshape->levels[SIDE_HIGH], darkena(fcol, fd, 0xFF), PPR::WALL);
if(window)
forCellIdEx(c2, i, c)
placeSidewall(c, i, SIDE_HIGH2, V, darkena(wcol2, fd, 0xFF));
}
if(among(c->wall, waClosedGate, waOpenGate) && qfi.fshape) draw_shapevec(c, V, qfi.fshape->levels[SIDE_WALL], 0x202020FF, PPR::WALL);
if(euclid) return;
if(true) {
queuepolyat(V * zpush(cgi.SKY+0.5), cgi.shNightStar, 0xFFFFFFFF, PPR::SKY);
}
break;
}
case 6: {
if(sky) sky->sky.emplace_back(c, V, skycolor(c));
if(camera_level <= cgi.HIGH2) return;
color_t wcol2 = winf[waRuinWall].color;
if(c->landparam == 1)
forCellIdEx(c2, i, c) if(c2->landparam != 1)
placeSidewall(c, i, SIDE_HIGH, V, darkena(wcol2, fd, 0xFF));
if(c->landparam != 2)
forCellIdEx(c2, i, c) if(c2->landparam == 2)
placeSidewall(c, i, SIDE_HIGH2, V, darkena(wcol2, fd, 0xFF));
if(c->landparam == 0)
if(qfi.fshape) draw_shapevec(c, V, qfi.fshape->levels[SIDE_HIGH], darkena(wcol2, fd, 0xFF), PPR::WALL);
if(c->landparam == 1)
if(qfi.fshape) draw_shapevec(c, V, qfi.fshape->levels[SIDE_WALL], darkena(wcol2, fd, 0xFF), PPR::WALL);
break;
}
case 7: {
if(sky) sky->sky.emplace_back(c, V, 0x00000F);
if(fieldpattern::fieldval_uniq(c) % 5 < 2) {
queuepolyat(V * zpush(cgi.SKY+1), cgi.shNightStar, 0xFFFFFFFF, PPR::SKY);
}
if(camera_level <= cgi.HIGH2) return;
color_t wcol2 = winf[waColumn].color;
if(c->landparam == 1)
forCellIdEx(c2, i, c) if(c2->landparam != 1)
placeSidewall(c, i, SIDE_HIGH, V, darkena(wcol2, fd, 0xFF));
if(c->landparam != 2)
forCellIdEx(c2, i, c) if(c2->landparam == 2)
placeSidewall(c, i, SIDE_HIGH2, V, darkena(wcol2, fd, 0xFF));
if(c->landparam == 0)
if(qfi.fshape) draw_shapevec(c, V, qfi.fshape->levels[SIDE_HIGH], darkena(wcol2, fd, 0xFF), PPR::WALL);
if(c->landparam == 1)
if(qfi.fshape) draw_shapevec(c, V, qfi.fshape->levels[SIDE_WALL], darkena(wcol2, fd, 0xFF), PPR::WALL);
break;
}
case 5: {
if(sky) sky->sky.emplace_back(c, V, 0x00000F);
if(camera_level <= cgi.WALL) return;
if(pseudohept(c)) {
forCellIdEx(c2, i, c)
placeSidewall(c, i, SIDE_HIGH, V, darkena(fcol, fd, 0xFF));
}
else if(qfi.fshape)
draw_shapevec(c, V, qfi.fshape->levels[SIDE_WALL], darkena(fcol, fd, 0xFF), PPR::WALL);
if(euclid) return;
if(true) {
queuepolyat(V * zpush(cgi.SKY+0.5), cgi.shNightStar, 0xFFFFFFFF, PPR::SKY);
}
}
}
}
}