From 9e4f10f3e12cedeebb18aad4ce1f3a71ea794641 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 12 Dec 2013 19:22:14 +0000 Subject: [PATCH] Lunatic: add "for s, what in sectorsofbunch(bunchnum, gv.BOTH_CF)" iterator. git-svn-id: https://svn.eduke32.com/eduke32@4198 1a8010ca-5511-0410-912e-c29ae57300e0 --- .../eduke32/source/lunatic/defs_common.lua | 38 ++++++++++++++++--- .../eduke32/source/lunatic/doc/lunatic.txt | 17 ++++++++- polymer/eduke32/source/lunatic/test.lua | 10 ++--- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index 99b42af82..00cb8c49e 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -366,8 +366,9 @@ enum { MAXSPRITESONSCREEN = 4096, MAXBUNCHES = 512, - CEILING = 0, - FLOOR = 1, + CEILING = 0, // must be 0 + FLOOR = 1, // must be 1 + BOTH_CF = 2, CLIPMASK0 = (1<<16)+1, // blocking CLIPMASK1 = (256<<16)+64, // hittable @@ -1191,15 +1192,40 @@ local function iter_sectorsofbunch(cf, i) if (i >= 0) then return i end end +local function iter_sectorsofbunch_both(cftab, i) + local cf = cftab[1] + + if (i < 0) then + i = ffiC.headsectbunch[cf][-i-1]; + else + i = ffiC.nextsectbunch[cf][i]; + end + + if (i < 0 and cf==0) then + cftab[1] = 1 + i = ffiC.headsectbunch[1][cftab[2]] + assert(i >= 0, "TROR bunch lists corrupt") + end + + if (i >= 0) then + return i, cftab[1]==0 and "ceiling" or "floor" + end +end + function sectorsofbunch(bunchnum, cf) if (not (bunchnum >= 0 and bunchnum < ffiC.numyaxbunches)) then error("passed invalid bunchnum to sectorsofbunch iterator", 2) end - if (not (cf == 0 or cf == 1)) then - error("passed invalid 'cf' to sectorsofbunch iterator, must be 0 or 1", 2) - end - return iter_sectorsofbunch, cf, -bunchnum-1 + if (cf == ffiC.BOTH_CF) then + return iter_sectorsofbunch_both, { 0, bunchnum }, -bunchnum-1 + else + if (not (cf == 0 or cf == 1)) then + error("passed invalid 'cf' to sectorsofbunch iterator, must be 0 or 1", 2) + end + + return iter_sectorsofbunch, cf, -bunchnum-1 + end end diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index 11c2f657d..27e0ee76b 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -295,11 +295,14 @@ The hard engine limits on the number of sectors, walls, and sprites. These constants *must* be used instead of any literal numeric values because they can change depending on how EDuke32 was configured and built. +`gv.CEILING`, `gv.FLOOR`, `gv.BOTH_CF`:: +Constants permissible to the <> iterator. + ////////// `gv.MAXSTATUS`, `gv.MAXTILES`, `gv.MAXSPRITESONSCREEN`:: TODO -`gv.MAXBUNCHES`, `gv.CEILING`, `gv.FLOOR`:: +`gv.MAXBUNCHES`:: TODO ////////// @@ -1239,6 +1242,18 @@ allowed. Inserting sprites is always allowed. Iterates over the indices of all sprites contained in the sector with index `sectnum` with the same meaning for `maydelete` as with `spritesofstat`. +[[sectorsofbunch_1]] +*for* s *in* sectorsofbunch(bunchnum, cf)+:: + +Iterates over the indices of the sectors whose ceiling's or floor's bunch +equals `bunchnum`, selected by passing `gv.CEILING` or `gv.FLOOR` +(respectively) to `cf`. + +[[sectorsofbunch_2]] +*for* s, what *in* sectorsofbunch(bunchnum, gv.BOTH_CF)+:: +Iterates over the indices of the sectors whose ceiling's and floor's bunch +equals `bunchnum`. On each iteration, `what` is one of the strings `'ceiling'` +or `'floor'`, denoting whether it's the ceiling or floor of sector `s` that has +the given bunch number. + Sector containment functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/polymer/eduke32/source/lunatic/test.lua b/polymer/eduke32/source/lunatic/test.lua index 2fab0db07..266606b44 100644 --- a/polymer/eduke32/source/lunatic/test.lua +++ b/polymer/eduke32/source/lunatic/test.lua @@ -90,16 +90,12 @@ gameevent --actor = {} actor[562].flags = bit.bor(actor[562].flags, 2); -- pal 6 with goggles on front SEENINE end ---[[ - -- TODO: better API for all TROR things? +---[[ if (vol==1 and lev==8) then print('tweaking bunch 1'); -- trueror1.map - for i in sectorsofbunch(1, gv.CEILING) do - sector[i].ceilingz = sector[i].ceilingz - 3*1024; - end - for i in sectorsofbunch(1, gv.FLOOR) do - sector[i].floorz = sector[i].floorz - 3*1024; + for i, what in sectorsofbunch(1, gv.BOTH_CF) do + sector[i][what].z = sector[i][what].z - 3*1024; end end --]]