fixed hybrid bitruncated ray: works after clear map

This commit is contained in:
Zeno Rogue 2020-05-09 18:32:16 +02:00
parent 306d8c3ace
commit c35705cc5c
3 changed files with 39 additions and 25 deletions

View File

@ -329,7 +329,7 @@ hpcshape
int SD3, SD6, SD7, S12, S14, S21, S28, S42, S36, S84;
vector<int> walloffsets;
vector<pair<int, cell*>> walloffsets;
vector<array<int, 3>> symmetriesAt;

View File

@ -1277,14 +1277,13 @@ EX namespace hybrid {
}
}
EX vector<cell*> samples;
EX int wall_offset(cell *c) {
int id = hybrid::underlying == gArchimedean ? arcm::id_of(c->master) + 20 * arcm::parent_index_of(c->master) : shvid(c);
if(isize(cgi.walloffsets) <= id) cgi.walloffsets.resize(id+1, -1);
int &wo = cgi.walloffsets[id];
if(isize(cgi.walloffsets) <= id) cgi.walloffsets.resize(id+1, {-1, nullptr});
auto &wop = cgi.walloffsets[id];
int &wo = wop.first;
if(!wop.second) wop.second = c;
if(wo == -1) {
samples.push_back(c);
cell *c1 = hybrid::get_where(c).first;
wo = isize(cgi.shWall3D);
int won = wo + c->type;
@ -1335,6 +1334,20 @@ EX namespace hybrid {
return wo;
}
auto clear_samples = addHook(hooks_clearmemory, 40, [] () {
for(auto& c: cgis) for(auto& v: c.second.walloffsets)
v.second = nullptr;
});
EX vector<pair<int, cell*>> gen_sample_list() {
if(!hybri) return {make_pair(0, centerover), make_pair(centerover->type, nullptr)};
vector<pair<int, cell*>> result;
for(auto& v: cgi.walloffsets) if(v.first >= 0) result.push_back(v);
sort(result.begin(), result.end());
result.emplace_back(isize(cgi.wallstart)-1, nullptr);
return result;
}
vector<cell*> to_link;
EX void will_link(cell *c) { if(pmap && ((hrmap_hybrid*) pmap)->twisted) to_link.push_back(c); }

View File

@ -189,10 +189,10 @@ void enable_raycaster() {
}
deg = 0;
if(hybri)
for(auto c: hybrid::samples) deg = max<int>(deg, c->type);
else
deg = centerover->type;
auto samples = hybrid::gen_sample_list();
for(int i=0; i<isize(samples)-1; i++)
deg = max(deg, samples[i+1].first - samples[i].first);
last_geometry = geometry;
if(!our_raycaster) {
@ -1119,19 +1119,20 @@ EX void cast() {
glUniform1i(o->uSides, centerover->type);
}
vector<cell*> sa = {centerover};
if(hybri) sa = hybrid::samples;
auto sa = hybrid::gen_sample_list();
vector<transmatrix> ms;
for(auto c: sa) {
for(int j=0; j<c->type; j++) {
if(hybri)
ms.push_back(hybrid::ray_iadj(c, j));
else
ms.push_back(currentmap->iadj(c, j));
}
vector<transmatrix> ms(sa.back().first, Id);
for(auto& p: sa) {
int id = p.first;
cell *c = p.second;
if(!c) continue;
for(int j=0; j<c->type; j++)
ms[id+j] = hybrid::ray_iadj(c, j);
}
// println(hlog, ms);
if(!sol && !nil && reflect_val) {
if(BITRUNCATED) exit(1);
for(int j=0; j<centerover->type; j++) {
@ -1201,11 +1202,11 @@ EX void cast() {
}
if(prod) {
int id = 0;
for(auto c: sa) {
ms[id+c->type-2] = Id;
ms[id+c->type-1] = Id;
id += c->type;
for(auto p: sa) {
int id =p.first;
if(id == 0) continue;
ms[id-2] = Id;
ms[id-1] = Id;
}
}