From 4780912b40b2eddca29a1dfac6b5786deafc2470 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 1 Jun 2014 20:50:14 +0000 Subject: [PATCH] lunatic/util/build.lua: in readdefs(), add option of requesting picnum->name mapping. That is, the reverse of what is returned with the first outarg. Use that in lunatic/util/foreachmap.lua. DONT_BUILD. git-svn-id: https://svn.eduke32.com/eduke32@4499 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/util/build.lua | 14 +++++++++++--- polymer/eduke32/source/lunatic/util/foreachmap.lua | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/polymer/eduke32/source/lunatic/util/build.lua b/polymer/eduke32/source/lunatic/util/build.lua index 1fe60b084..62a4b4919 100644 --- a/polymer/eduke32/source/lunatic/util/build.lua +++ b/polymer/eduke32/source/lunatic/util/build.lua @@ -607,14 +607,15 @@ function loadarts(filenames) return tile end -function readdefs(fn) +-- defs [, rdefs] = readdefs(fn [, alsoreverse]) +function readdefs(fn, alsoreverse) local fh, errmsg = io.open(fn) if (fh==nil) then return nil, errmsg end - local defs = {} + local defs, rdefs = {}, nil for line in fh:lines() do local defname, numstr = string.match(line, "#?%s*define%s+([%a_][%w_]+)%s+([0-9]+)") @@ -623,6 +624,13 @@ function readdefs(fn) end end + if (alsoreverse) then + rdefs = {} + for defname, num in pairs(defs) do + rdefs[num] = defname + end + end + fh:close() - return defs + return defs, rdefs end diff --git a/polymer/eduke32/source/lunatic/util/foreachmap.lua b/polymer/eduke32/source/lunatic/util/foreachmap.lua index 35f35d7e9..a58251b9b 100755 --- a/polymer/eduke32/source/lunatic/util/foreachmap.lua +++ b/polymer/eduke32/source/lunatic/util/foreachmap.lua @@ -22,6 +22,8 @@ -- $ ./findmaps.sh ~/.eduke32/ "sprite: .picnum>=d.CRACK1 and .picnum<=d.CRACK4" -- (Now: no space between "d." and "CRACK" is necessary ".xxx" is translated to -- "sprite[].xxx" only if it's the name of a sprite member.) +-- The local 'rdefs' provides the reverse mapping: from picnums to tile names +-- (or nil). -- Print all V9 maps along with their number of bunches and max(ceilings of a bunch) -- $ prog='if (map.version==9) then print(map.numbunches.." ".. math.max(unpack(map.sectsperbunch[0],0)) .." "..fn) end' @@ -119,7 +121,8 @@ if (modname:sub(1,2) == "-e") then if (x==tab[i]) then return true end end end - local d=require('build').readdefs('../../names.h') or error('Need ../../names.h') -- XXX + local d,rdefs = require('build').readdefs('../../names.h',true) + if (not d) then error('Need ../../names.h') end -- XXX local numsectors, numwalls, numsprites, sector, wall, sprite return function (map, fn) numsectors, numwalls, numsprites = map.numsectors, map.numwalls, map.numsprites