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
var tmptile = this.get_tile (tmppos);
/* TODO: check if the sides matches */
valid = (tmptile == null) || tmptile.match (links, tile);
valid = (tmptile == null) || tile.match (links, tmptile);
if (tmptile != null) {
have_neighbour = true;
}
......
......@@ -97,15 +97,25 @@ namespace OVCC
}
}
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;
for (var i = 0; i < 12; i++) {
mirror |= ((links & (1 << i)) >> i) << (12 - 1 - i);
for (var i = 0; i < nbits; i++) {
mirror |= ((bits & (1 << i)) >> i) << (nbits - 1 - i);
}
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
* another tile. This is expected to be used to check if two tiles can be
......@@ -123,13 +133,11 @@ namespace OVCC
public bool match (TileObjectLinks links,
Tile other)
{
var other_links = mirror_links (links);
foreach (var o in this._objects) {
var mask = o.links & links;
if (mask == 0) continue;
/*mask = ((mask >> 6) | ((mask & ((1 << 6) - 1)) << 6)) & other_links;*/
mask = mirror_links (mask) & other_links;
if (mask == 0) continue;
mask = mirror_links (mask);
foreach (var other_o in other._objects) {
if ((other_o.links & mask) != 0) {
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