From abcc98d5c1a5be5cbda1e6fdf33e28506b8232b7 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 7 Apr 2013 15:20:28 +0000 Subject: [PATCH] Lunatic: access to show2dsector[], fix some permit-negative bound checks. git-svn-id: https://svn.eduke32.com/eduke32@3650 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/bitar.lua | 29 +++++++++++++++---- polymer/eduke32/source/lunatic/defs.ilua | 12 +++++--- .../eduke32/source/lunatic/defs_common.lua | 8 +++++ polymer/eduke32/source/lunatic/dynsymlist | 2 ++ polymer/eduke32/source/lunatic/dynsymlist_m32 | 2 ++ polymer/eduke32/source/lunatic/test.elua | 11 +++++++ 6 files changed, 55 insertions(+), 9 deletions(-) diff --git a/polymer/eduke32/source/lunatic/bitar.lua b/polymer/eduke32/source/lunatic/bitar.lua index 3ea895d59..5cb4a3d39 100644 --- a/polymer/eduke32/source/lunatic/bitar.lua +++ b/polymer/eduke32/source/lunatic/bitar.lua @@ -16,7 +16,12 @@ local tostring = tostring module(...) -local bitar_ct = ffi.typeof("struct { const double maxbidx, maxidx; const intptr_t arptr; }") +local bitar_ct = ffi.typeof[[ +struct { + const double maxbidx; // last permissible bit index + const double maxidx; // last permissible int32_t index + const intptr_t arptr; // address of the int32_t array +}]] local ptr_to_int = ffi.typeof("int32_t *") local anchor = {} @@ -110,6 +115,8 @@ local mt = { --- Additional operations __index = { + -- TODO: Rename to 'testi', 'seti', 'cleari'; add 'flipi'? + -- Is bit i set? isset = function(s, i) if (not (i >= 0 and i<=s.maxbidx)) then @@ -212,20 +219,31 @@ local mt = { end, } -local bitar = ffi.metatype(bitar_ct, mt) +ffi.metatype(bitar_ct, mt) + -- Create new bit array. function new(maxbidx, initval) if (type(maxbidx) ~= "number" or not (maxbidx >= 0 and maxbidx <= (2^31)-2)) then - error("bad argument #1 to bitar.new (must be a number in [0..(2^31)-2])", 2) + -- NOTE: Uh-oh, we can't write '2^31' because that would be interpreted + -- as color by OSD_Printf. + error("bad argument #1 to bitar.new (must be a number in [0..(2**31)-2])", 2) end if (math.floor(maxbidx) ~= maxbidx) then error("bad argument #1 to bitar.new (must be an integral number)") end - if (type(initval)=="string") then - -- string containing hex digits (a..p) given, for INTERNAL use + if (ffi.istype(ptr_to_int, initval)) then + -- Initialization from an array on the C side. INTERNAL. + -- Cannot be reached by user code since there's no access to the FFI + -- (and thus no way to create pointers). + + return bitar_from_intar(maxbidx, (maxbidx+1)/32-1, initval) + + elseif (type(initval)=="string") then + -- String containing hex digits (a..p) given, for INTERNAL use only. + -- XXX: Can be reached by user code. local lstr = initval @@ -249,6 +267,7 @@ function new(maxbidx, initval) end end + -- NOTE: cannot be extracted from the string, use the passed one. return bitar_from_intar(maxbidx, maxidx, ar) else diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 0c8afe021..d3f107bbe 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -929,7 +929,7 @@ local actor_mt = { end, set_picnum = function(a, picnum) - if (picnum >= 0) then + if (not (picnum < 0)) then check_tile_idx(picnum) end ffi.cast(actor_ptr_ct, a).picnum = picnum @@ -1043,7 +1043,7 @@ local player_mt = { end, set_customexitsound = function(p, soundnum) - if (soundnum >= 0) then + if (not (soundnum < 0)) then check_sound_idx(soundnum) end ffi.cast(player_ptr_ct, p).customexitsound = soundnum @@ -1110,7 +1110,7 @@ ffi.metatype("DukePlayer_t", player_mt) local function GenProjectileSetFunc(Member) return function(self, picnum) - if (picnum >= 0) then + if (not (picnum < 0)) then check_tile_idx(picnum) end ffi.cast(projectile_ptr_ct, self)[Member] = picnum @@ -1900,7 +1900,11 @@ function DBG_.testmembread() membaccode = membaccode[1] end if (membaccode) then - local codestr = "do local _bit,_math=require'bit',require'math'; local tmp=".. + local codestr = [[ +do + local _bit,_math=require'bit',require'math' + local _band,_gv=_bit.band,gv +local tmp=]].. membaccode:gsub("%%s","0").." end" local code = assert(loadstring(codestr)) code() diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index d6e448a26..0b468b85c 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -312,6 +312,8 @@ const int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; const int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; const int16_t tilesizx[MAXTILES], tilesizy[MAXTILES]; +uint8_t show2dsector[(MAXSECTORS+7)>>3]; + const int16_t headsectbunch[2][MAXBUNCHES], nextsectbunch[2][MAXSECTORS]; int16_t yax_getbunch(int16_t i, int16_t cf); @@ -707,6 +709,12 @@ static_members.sprite.CSTAT = conststruct TRANSLUCENT_BOTH_BITS = 512+2, } +local bitar = require("bitar") +-- XXX: bitar uses int32_t arrays, while show2dsector[] is a uint8_t +-- array. Potential unaligned access. Also, only works on little-endian +-- machines. This sucks. +static_members.sector.showbitmap = bitar.new(ffiC.MAXSECTORS-1, ffi.cast("int32_t *", ffiC.show2dsector)) + local sms = static_members.sprite sms._headspritesect = creategtab(ffiC.headspritesect, ffiC.MAXSECTORS, 'headspritesect[]') -- NOTE: don't allow freelist access diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index 199ed9fcb..3843452df 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -43,6 +43,8 @@ nextspritestat; tilesizx; tilesizy; +show2dsector; + headsectbunch; nextsectbunch; diff --git a/polymer/eduke32/source/lunatic/dynsymlist_m32 b/polymer/eduke32/source/lunatic/dynsymlist_m32 index 0e4df0664..3ca7c73e6 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist_m32 +++ b/polymer/eduke32/source/lunatic/dynsymlist_m32 @@ -43,6 +43,8 @@ nextspritestat; tilesizx; tilesizy; +show2dsector; + headsectbunch; nextsectbunch; diff --git a/polymer/eduke32/source/lunatic/test.elua b/polymer/eduke32/source/lunatic/test.elua index 8e51f1d73..f5787c571 100644 --- a/polymer/eduke32/source/lunatic/test.elua +++ b/polymer/eduke32/source/lunatic/test.elua @@ -430,6 +430,17 @@ gameevent("DISPLAYREST", function() -- con._gametext(2822, j, i, 12, 0, 0, 16, 0,0,gv.xdim,gv.ydim,8192) end end + + -- Clear showing every sector with the pavement floor tile. (Unless we're + -- in such a sector or an adjoining one.) + -- XXX: We need a better place to do this, maybe an event in + -- G_DisplayRest() where show2dsector[] is tweaked? + local show2dsector = sector.showbitmap + for i=0,gv.numsectors-1 do + if (sector[i].floorpicnum==815) then + show2dsector:set0(i) + end + end end) -- APLAYER