Lunatic: for gameactor(), deprecate AF.replace_hard, make AF.replace default.

That is, always bitwise-OR the per-tile actor flags with the existing ones.

git-svn-id: https://svn.eduke32.com/eduke32@4374 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-03-15 14:10:50 +00:00
parent c3ff173553
commit 86d985620c
4 changed files with 19 additions and 34 deletions

View file

@ -867,9 +867,9 @@ do
our_SFLAG.rotfixed = con_lang.SFLAG.SFLAG_ROTFIXED our_SFLAG.rotfixed = con_lang.SFLAG.SFLAG_ROTFIXED
-- Callback function chaining control flags. -- Callback function chaining control flags.
our_SFLAG.replace_hard = 0x08000000 -- Replace actor code and flags our_SFLAG.replace = 0x08000000
our_SFLAG.replace_soft = 0x10000000 -- Replace actor code, bitwise OR flags our_SFLAG.replace_soft = 0x08000000 -- compat
our_SFLAG.replace = 0x08000000 -- Should only be used for gameevent our_SFLAG.replace_hard = 0x08000000 -- compat, deprecated
our_SFLAG.chain_beg = 0x20000000 our_SFLAG.chain_beg = 0x20000000
our_SFLAG.chain_end = 0x40000000 our_SFLAG.chain_end = 0x40000000
our_SFLAG._CHAIN_MASK_ACTOR = 0x78000000 our_SFLAG._CHAIN_MASK_ACTOR = 0x78000000
@ -2038,15 +2038,14 @@ local function our_gameactor(args)
local chainflags = band(flags, AF._CHAIN_MASK_ACTOR) local chainflags = band(flags, AF._CHAIN_MASK_ACTOR)
flags = band(flags, BNOT.CHAIN_MASK_ACTOR) flags = band(flags, BNOT.CHAIN_MASK_ACTOR)
-- Default chaining behavior: don't, replace the old actor instead, but
-- unlike CON, also replace its flags. (CON ORs them instead.)
if (chainflags == 0) then if (chainflags == 0) then
chainflags = AF.replace_hard -- Default chaining behavior: don't, replace the old actor instead.
chainflags = AF.replace
elseif (band(chainflags, chainflags-1) ~= 0) then elseif (band(chainflags, chainflags-1) ~= 0) then
error("invalid chaining control flags to gameactor", 2) error("invalid chaining control flags to gameactor", 2)
end end
local replacep = (chainflags==AF.replace_soft or chainflags==AF.replace_hard) local replacep = (chainflags==AF.replace)
if (not replacep and not actor_funcs[tilenum]) then if (not replacep and not actor_funcs[tilenum]) then
error("attempt to chain code to nonexistent actor tile "..tilenum, 2) error("attempt to chain code to nonexistent actor tile "..tilenum, 2)
end end
@ -2107,19 +2106,8 @@ local function our_gameactor(args)
gameevent_internal(96, animate_all_sprites) -- EVENT_ANIMATEALLSPRITES gameevent_internal(96, animate_all_sprites) -- EVENT_ANIMATEALLSPRITES
end end
-- All good, set the tile bits in initial run and register the actor! -- All good, bitwise-OR the tile bits and register the actor!
-- XXX: Need to see if some other state living on the C side is clobbered ffiC.g_tile[tilenum]._flags = bit.bor(ffiC.g_tile[tilenum]._flags, flags)
-- by Lua state recreation.
-- TILE_FLAGS_SET_ONLY_ON_FIRST_RUN
if (g_firstRun) then
-- NOTE: when chaining, this allows passing different flags which are
-- silently ORed. This may or may not be what the user intends, but it
-- allows e.g. adding a stayput bit to an already defined enemy.
-- Modifying existing behavior is the whole point of chaining after all.
-- When soft-replacing, bitwise OR too, emulating CON behavior.
local tile = ffiC.g_tile[tilenum]
tile._flags = (chainflags==AF.replace_hard) and flags or bit.bor(tile._flags, flags)
end
local newfunc = replacep and func local newfunc = replacep and func
or (chainflags==AF.chain_beg) and chain_func3(func, actor_funcs[tilenum]) or (chainflags==AF.chain_beg) and chain_func3(func, actor_funcs[tilenum])

View file

@ -1478,17 +1478,15 @@ one. This has certain implications if control is transferred non-locally, for
example by using <<nlcf,`con.longjmp`>>. example by using <<nlcf,`con.longjmp`>>.
+ +
Several flags in `AF` are provided to control how a `gameactor` invocation Several flags in `AF` are provided to control how a `gameactor` invocation
handles chaining. handles chaining. In all cases, the actor tile flags are bitwise-ORed with the
existing ones.
+ +
* `AF.replace_hard`: Completely replace the actor's callback function and * `AF.replace`: Replace the callback function. This is the way CON's
run-time flags. This is the default. `useractor` behaves and is also the Lunatic default.
* `AF.replace_soft`: Replace the callback function, but bitwise-OR the existing * `AF.replace_soft`: deprecated alias for `AF.replace`
run-time flags with the provided ones. This is the way CON's `useractor` * `AF.replace_hard`: [red]*deprecated*
behaves. * `AF.chain_beg`: Prepend the provided `func` to the existing callback function.
* `AF.chain_beg`: Prepend the provided `func` to the existing callback function, * `AF.chain_end`: Append the provided `func` to the existing callback function.
bitwise-OR in flags.
* `AF.chain_end`: Append the provided `func` to the existing callback function,
bitwise-OR in flags.
+ +
The following members all default to 0 if omitted. The following members all default to 0 if omitted.
+ +

View file

@ -549,8 +549,8 @@ function on.actor_end(pos, usertype, tsamm, codetab)
end end
end end
-- 0x10000000: actor.FLAGS.replace_soft -- 0x08000000: actor.FLAGS.replace
flags = bit.bor(flags, 0x10000000) flags = bit.bor(flags, 0x08000000)
local str = flags.."," local str = flags..","
for i=2,math.min(#tsamm,4) do for i=2,math.min(#tsamm,4) do

View file

@ -526,7 +526,6 @@ gameactor{ D.APLAYER, AF.chain_end,
} }
-- Add NODAMAGEPUSH flag to NEWBEAST. -- Add NODAMAGEPUSH flag to NEWBEAST.
-- XXX: Doesn't work because of defs.lua: TILE_FLAGS_SET_ONLY_ON_FIRST_RUN
gameactor { D.NEWBEAST, AF.chain_end + AF.NODAMAGEPUSH, function() end } gameactor { D.NEWBEAST, AF.chain_end + AF.NODAMAGEPUSH, function() end }
-- Also test actor code chaining: strength is doubled. -- Also test actor code chaining: strength is doubled.
@ -691,7 +690,7 @@ gameactor
gameactor gameactor
{ {
-- Innocent sign, similar to test/weaponvars.con actor 909 (tree trunk) -- Innocent sign, similar to test/weaponvars.con actor 909 (tree trunk)
1211, actor.FLAGS.replace_hard, 1211, actor.FLAGS.replace,
function(aci, pli) function(aci, pli)
local a = actor[aci] local a = actor[aci]