From 3d754904fe112760c96c1885f84a26f4caa3242a Mon Sep 17 00:00:00 2001 From: Andre Leiradella Date: Wed, 13 May 2015 13:50:19 -0300 Subject: [PATCH] generate/read collision bits --- etc/rlmap.lua | 12 +++--------- src/rl_map.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/etc/rlmap.lua b/etc/rlmap.lua index 1b3a01c..1668ffd 100644 --- a/etc/rlmap.lua +++ b/etc/rlmap.lua @@ -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 diff --git a/src/rl_map.c b/src/rl_map.c index bcfec16..dd04cd8 100644 --- a/src/rl_map.c +++ b/src/rl_map.c @@ -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; }