generate/read collision bits

This commit is contained in:
Andre Leiradella 2015-05-13 13:50:19 -03:00
parent 9f86628ac5
commit 3d754904fe
2 changed files with 19 additions and 9 deletions

View File

@ -579,29 +579,23 @@ local function compile_cmd( args )
end
end
-- collision bits
if coll then
-- collision bits
local bits, bit = 0, 1
for y = 1, map.height do
for x = 1, map.width do
local blocked = false
for i = 1, #coll do
for _, layer in ipairs( map.layers ) do
if layer.name == coll[ i ] then
if layer.tiles[ y ][ x ] then
blocked = true
if layer.tiles[ y ][ x ] ~= 0 then
bits = bits | bit
break
end
end
end
end
if blocked then
bits = bits | bit
end
if bit == 0x80000000 then
out:writeu32( bits )
bits, bit = 0, 1

View File

@ -113,6 +113,22 @@ rl_map_t* rl_map_create( const void* data, size_t size, const rl_tileset_t* tile
}
}
int numqw = ( width * height + 31 ) / 32;
uint32_t* restrict collision = (uint32_t*)rl_malloc( numqw * sizeof( uint32_t ) );
if ( !collision )
{
return destroy( map );
}
map->collision = collision;
const uint32_t* restrict coll_end = collision + numqw;
while ( collision < coll_end )
{
*collision++ = ne32( *ptr.u32++ );
}
return map;
}