From fa6746867c80c2467efe51519ac1e1f683478a0e Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 20 Dec 2013 18:31:35 +0000 Subject: [PATCH] Lunatic: add ceiling-or-floor method set_picnum(). BUILD_LUNATIC. git-svn-id: https://svn.eduke32.com/eduke32@4207 1a8010ca-5511-0410-912e-c29ae57300e0 --- .../eduke32/source/lunatic/defs_common.lua | 32 +++++++++++++------ .../eduke32/source/lunatic/doc/lunatic.txt | 7 +++- .../source/lunatic/test/damagehplane.lua | 9 +----- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index c7e0f75ce..0ee2a3030 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -167,6 +167,16 @@ end bitint_new_struct_type("uint8_t", "UBit8") bitint_new_struct_type("uint16_t", "UBit16") +-- Converts a template struct definition to an internal, unrestricted one. +-- NOTE: "[^ ]*" for const decorations in defs.ilua. +function strip_const(structstr) + return (string.gsub(structstr, "const[^ ]* ", "")); +end + +local function maybe_strip_const(str) + return _LUNATIC_AUX and strip_const(str) or str +end + --== Core engine structs ==-- @@ -182,6 +192,8 @@ local CF_MEMBERS = [[ ffi.cdef("typedef struct { "..CF_MEMBERS:gsub("~","").." } ceiling_or_floor_t;") +local hplane_ptr_ct = ffi.typeof("struct { "..strip_const(CF_MEMBERS:gsub("~","")).." } *") + local SECTOR_STRUCT = [[ struct { const int16_t wallptr, wallnum; @@ -232,16 +244,6 @@ struct { int16_t lotag, hitag, extra; }]] --- Converts a template struct definition to an internal, unrestricted one. --- NOTE: "[^ ]*" for const decorations in defs.ilua. -function strip_const(structstr) - return (string.gsub(structstr, "const[^ ]* ", "")); -end - -local function maybe_strip_const(str) - return _LUNATIC_AUX and strip_const(str) or str -end - -- NOTE for FFI definitions: we're compiling EDuke32 with -funsigned-char, so -- we need to take care to declare chars as unsigned whenever it matters, for -- example if it represents a palette index. (I think it's harmless for stuff @@ -587,6 +589,16 @@ local sectortype_mt = { } ffi.metatype("sectortype", sectortype_mt) +local hplane_mt = { + __index = { + set_picnum = function(hp, picnum) + check_tile_idx(picnum) + ffi.cast(hplane_ptr_ct, hp).picnum = picnum + end + }, +} +ffi.metatype("ceiling_or_floor_t", hplane_mt) + local walltype_ptr_ct = ffi.typeof("$ *", ffi.typeof(strip_const(WALL_STRUCT))) local walltype_mt = { diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index 43ca7e222..dced6aa22 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -656,10 +656,15 @@ _`u8`_ `cf.xpanning`, `cf.ypanning`:: The panning values of the ceiling or floor. One full cycle is covered by values from `0` to `255`. +===== ceiling-or-floor methods + +`cf:set_picnum(tilenum)`:: +Set the tile number of the ceiling-or-floor `cf`. + ===== `sector` methods `sec:set_ceilingpicnum(tilenum)`, {nbsp} `sec:set_floorpicnum(tilenum)`:: -Set the tile number of the ceiling or floor. +Set the tile number of the ceiling or the floor. [[sec_cfz_at]] `sec:ceilingzat(pos)`, {nbsp} `sec:floorzat(pos)`:: Return the z coordinate of sector `sec`'s ceiling or floor at position `pos`, diff --git a/polymer/eduke32/source/lunatic/test/damagehplane.lua b/polymer/eduke32/source/lunatic/test/damagehplane.lua index a30017c33..486d40324 100644 --- a/polymer/eduke32/source/lunatic/test/damagehplane.lua +++ b/polymer/eduke32/source/lunatic/test/damagehplane.lua @@ -41,14 +41,7 @@ gameactor local bunchnum = spr.extra for sectnum, what in sectorsofbunch(bunchnum, gv.BOTH_CF) do local cf = sector[sectnum][what] - - -- TODO: provide cf:set_picnum() - if (what=="ceiling") then - sector[sectnum]:set_ceilingpicnum(D.GLASS2 + cnt) - else - sector[sectnum]:set_floorpicnum(D.GLASS2 + cnt) - end - + cf:set_picnum(D.GLASS2 + cnt) cf.statbits:clear(sector.STAT.BLOCK + sector.STAT.HITSCAN) if (finish) then cf.statbits:clear(sector.STAT.TRANS_BITMASK)