Skip to content

Instantly share code, notes, and snippets.

@chrisforbes
Created December 26, 2017 21:34
Show Gist options
  • Save chrisforbes/2acf0d88d10401bbf174639629cab2cc to your computer and use it in GitHub Desktop.
Save chrisforbes/2acf0d88d10401bbf174639629cab2cc to your computer and use it in GitHub Desktop.
static unsigned get_neighbor_bits(wire_pos w) {
unsigned bits = 0u;
auto bl = ship->get_block(w.pos);
for (auto i = 0u; i < 6u; i++) {
if (i == w.face || i == (w.face ^ 1)) continue;
if (bl->surfs[i]) {
// inside corner
if (bl->has_wire[i]) {
bits |= 1 << i;
}
}
else {
auto np = w.pos + surface_index_to_normal(i);
auto n = ship->get_block(np);
if (n && n->surfs[w.face]) {
// straight along surface
if (n->has_wire[w.face]) {
bits |= 1 << i;
}
}
else {
auto rp = np + surface_index_to_normal(w.face);
auto r = ship->get_block(rp);
if (r && r->surfs[i ^ 1]) {
// outside corner
if (r->has_wire[w.face]) {
bits |= 1 << i;
}
}
}
}
}
return bits;
}
@chrisforbes
Copy link
Author

\o/ this is actually buggy. last has_wire[w.face] should be has_wire[i ^ 1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment