Created
June 15, 2012 13:36
-
-
Save triplefox/2936511 to your computer and use it in GitHub Desktop.
in-progress autotiler
This file contains 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
public inline function rewriteAutoTiling(p : { x:Int, y:Int }, fallback : Int) | |
{ | |
// collect the indices for the tile positions. | |
var idx_tl = result.c21(p.x * 2, p.y * 2); | |
var idx_tr = tl + 1; | |
var idx_bl = result.c21(p.x * 2, p.y * 2 + 1); | |
var idx_br = bl + 1; | |
// build the mask information | |
var m_c = defs[c2tSafe(p.x , p.y , fallback)].mask; | |
var m_tl = (defs[c2tSafe(p.x - 1, p.y - 1, fallback)].mask & m_c)>0; | |
var m_t = (defs[c2tSafe(p.x , p.y - 1, fallback)].mask & m_c)>0; | |
var m_tr = (defs[c2tSafe(p.x + 1, p.y - 1, fallback)].mask & m_c)>0; | |
var m_l = (defs[c2tSafe(p.x - 1, p.y , fallback)].mask & m_c)>0; | |
var m_r = (defs[c2tSafe(p.x + 1, p.y , fallback)].mask & m_c)>0; | |
var m_bl = (defs[c2tSafe(p.x - 1, p.y + 1, fallback)].mask & m_c)>0; | |
var m_b = (defs[c2tSafe(p.x , p.y + 1, fallback)].mask & m_c)>0; | |
var m_br = (defs[c2tSafe(p.x + 1, p.y + 1, fallback)].mask & m_c)>0; | |
// get the indexes for each subtile. | |
var si = defs[source.c2t(p.x , p.y )].indexes; | |
var s0 = si[Autotile.computeMask(m_l, m_t, m_tl, 0)]; | |
var s1 = si[Autotile.computeMask(m_t, m_r, m_tr, 1)]; | |
var s3 = si[Autotile.computeMask(m_r, m_b, m_br, 3)]; | |
var s2 = si[Autotile.computeMask(m_b, m_l, m_bl, 2)]; | |
// TODO: now we can blit. | |
} | |
// given this arrangement of tiles in a single continuous strip 0-20: | |
// /\ -- || \/ ** | |
// \/ -- || /\ ** | |
// rewriteAutoTiling does the boilerplate of creating the booleans from the mask defs. | |
// computeMask will compute the correct tile index from the mask created by edges a, b, ab and the | |
// corner index 0-4, where a is the counterclockwise direction and b is the clockwise direction. | |
// then the end of rewriteAutoTiling converts the directives into updates for TileSheetGrid. | |
public static inline function computeMask(a : Bool, b : Bool, ab : Bool, corner : Int) | |
{ | |
var m = (a ? 1 : 0) + (b ? 2 : 0) + (ab ? 4 : 0); | |
var set = (m & 8) * 2; | |
if (corner > 1) return set + corner + 8; | |
else return set + corner; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment