Created
December 26, 2017 21:34
-
-
Save chrisforbes/2acf0d88d10401bbf174639629cab2cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
\o/ this is actually buggy. last
has_wire[w.face]
should behas_wire[i ^ 1]