Commit 19b2dd3b authored by Jonathan Michalon's avatar Jonathan Michalon
Browse files

Fix tiles matching. Seems to work great!

parent 5019c3f7
...@@ -120,7 +120,7 @@ namespace OVCC ...@@ -120,7 +120,7 @@ namespace OVCC
var tmptile = this.get_tile (tmppos); var tmptile = this.get_tile (tmppos);
/* TODO: check if the sides matches */ /* TODO: check if the sides matches */
valid = (tmptile == null) || tmptile.match (links, tile); valid = (tmptile == null) || tile.match (links, tmptile);
if (tmptile != null) { if (tmptile != null) {
have_neighbour = true; have_neighbour = true;
} }
......
...@@ -96,15 +96,25 @@ namespace OVCC ...@@ -96,15 +96,25 @@ namespace OVCC
o.rotate (wise); o.rotate (wise);
} }
} }
private TileObjectLinks mirror_links (TileObjectLinks links) /* this function reverses the nbits firts bits of an integer */
private uint reverse_bits (uint bits, int nbits)
{ {
var mirror = 0; var mirror = 0;
for (var i = 0; i < 12; i++) { for (var i = 0; i < nbits; i++) {
mirror |= ((links & (1 << i)) >> i) << (12 - 1 - i); mirror |= ((bits & (1 << i)) >> i) << (nbits - 1 - i);
} }
return mirror; return mirror;
} }
/* given the way sides are set, we can do two reversing between
* top / bottom and left / right and compose them.
* & ~ (0x7<<3) removes 3 bits (those from right, between top and bottom) */
private TileObjectLinks mirror_links (TileObjectLinks links)
{
return (TileObjectLinks) reverse_bits (links & ~ (0x7<<3), 9)
| reverse_bits ((links >> 3) & ~ (0x7<<3), 9) << 3;
}
/** /**
* Checks whether the object links of a tile are mirror-compatible with * Checks whether the object links of a tile are mirror-compatible with
...@@ -123,13 +133,11 @@ namespace OVCC ...@@ -123,13 +133,11 @@ namespace OVCC
public bool match (TileObjectLinks links, public bool match (TileObjectLinks links,
Tile other) Tile other)
{ {
var other_links = mirror_links (links);
foreach (var o in this._objects) { foreach (var o in this._objects) {
var mask = o.links & links; var mask = o.links & links;
if (mask == 0) continue; if (mask == 0) continue;
/*mask = ((mask >> 6) | ((mask & ((1 << 6) - 1)) << 6)) & other_links;*/ /*mask = ((mask >> 6) | ((mask & ((1 << 6) - 1)) << 6)) & other_links;*/
mask = mirror_links (mask) & other_links; mask = mirror_links (mask);
if (mask == 0) continue;
foreach (var other_o in other._objects) { foreach (var other_o in other._objects) {
if ((other_o.links & mask) != 0) { if ((other_o.links & mask) != 0) {
if (other_o.otype != o.otype) { if (other_o.otype != o.otype) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment