From 0173c0908aac58f00d238e6e9b34520a835b0407 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 15 Mar 2013 16:56:03 +0000 Subject: [PATCH] Lunatic: spritesof{stat,sect} iterators that allow deletion inside the loop. Also, - an optimization for sprite[]:setpos(). Calls to get_sprite_index() seem to be pretty slow (at least when they're not compiled). - add getzrange to the dynsymlists git-svn-id: https://svn.eduke32.com/eduke32@3560 1a8010ca-5511-0410-912e-c29ae57300e0 --- .../eduke32/source/lunatic/defs_common.lua | 49 +++++++++++++++++-- polymer/eduke32/source/lunatic/dynsymlist | 1 + polymer/eduke32/source/lunatic/dynsymlist_m32 | 1 + 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index 56d1525e7..2ddbe502f 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -542,7 +542,9 @@ function spritetype_mt.__index.setpos(spr, pos) -- setsprite() clone return -1 end - ffiC.changespritesect(get_sprite_idx(spr), newsect) + if (spr.sectnum ~= newsect) then + ffiC.changespritesect(get_sprite_idx(spr), newsect) + end return newsect end @@ -757,9 +759,28 @@ local function iter_spritesofsect(sect, i) if (i >= 0) then return i end end -function spritesofsect(sect) +-- sprites of sectnum iterator that allows deleting the iterated sprite +local function iter_spritesofsect_safe(tab, i) + if (i < 0) then + i = ffiC.headspritesect[-i] + else + i = tab[1] + end + + if (i >= 0) then + tab[1] = ffiC.nextspritesect[i] + return i + end +end + +function spritesofsect(sect, maydelete) check_sector_idx(sect) - return iter_spritesofsect, sect, -1 + + if (maydelete) then + return iter_spritesofsect_safe, { -1 }, -sect + else + return iter_spritesofsect, sect, -1 + end end local function iter_spritesofstat(stat, i) @@ -772,12 +793,30 @@ local function iter_spritesofstat(stat, i) if (i >= 0) then return i end end -function spritesofstat(stat) +-- sprites of statnum iterator that allows deleting the iterated sprite +local function iter_spritesofstat_safe(tab, i) + if (i < 0) then + i = ffiC.headspritestat[-i] + else + i = tab[1] + end + + if (i >= 0) then + tab[1] = ffiC.nextspritestat[i] + return i + end +end + +function spritesofstat(stat, maydelete) if (stat >= ffiC.MAXSTATUS+0ULL) then error("passed invalid statnum to spritesofstat iterator", 2) end - return iter_spritesofstat, stat, -1 + if (maydelete) then + return iter_spritesofstat_safe, { -1 }, -stat + else + return iter_spritesofstat, stat, -1 + end end --== TROR iterators ==-- diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index 5b747fea5..e315292e7 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -51,6 +51,7 @@ getangle; cansee; hitscan; neartag; +getzrange; rotatesprite; dist; diff --git a/polymer/eduke32/source/lunatic/dynsymlist_m32 b/polymer/eduke32/source/lunatic/dynsymlist_m32 index f72a7ad1e..f184078a5 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist_m32 +++ b/polymer/eduke32/source/lunatic/dynsymlist_m32 @@ -51,6 +51,7 @@ getangle; cansee; hitscan; neartag; +getzrange; rotatesprite; dist;