CON: add sprite pseudo-member 'isvalid', getting 1 if the sprite is valid.

And 0 otherwise. Before accessing a sprite that is not not known to be
definitely valid (e.g. a loop over all sprites from 0 to MAXSPRITES-1),
one should check for validity before accessing it in any other fashion.

git-svn-id: https://svn.eduke32.com/eduke32@4146 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-11-11 16:48:17 +00:00
parent 92594f09c8
commit 8029aceaa4
5 changed files with 20 additions and 1 deletions

View File

@ -824,6 +824,8 @@ const memberlabel_t ActorLabels[]=
{ "ulotag", ACTOR_ULOTAG, 0, 0 },
{ "uhitag", ACTOR_UHITAG, 0, 0 },
{ "isvalid", ACTOR_ISVALID, 0, 0 },
{ "", -1, 0, 0 } // END OF LIST
};

View File

@ -518,6 +518,7 @@ enum ActorLabel_t
ACTOR_ALPHA,
ACTOR_ULOTAG,
ACTOR_UHITAG,
ACTOR_ISVALID,
ACTOR_END
};

View File

@ -2930,6 +2930,10 @@ static void __fastcall VM_GetSprite(int32_t lVar1, int32_t lLabelID, int32_t lVa
Gv_SetVarX(lVar2, (uint8_t)(spriteext[iActor].alpha * 255.0f));
return;
case ACTOR_ISVALID:
Gv_SetVarX(lVar2, sprite[iActor].statnum != MAXSTATUS);
return;
default:
return;
}
@ -3553,6 +3557,7 @@ static int32_t __fastcall VM_AccessSpriteX(int32_t iActor, int32_t lLabelID, int
case ACTOR_YPANNING: return spriteext[iActor].ypanning;
case ACTOR_HTFLAGS: return actor[iActor].flags;
case ACTOR_ALPHA: return (uint8_t)(spriteext[iActor].alpha*255.0f);
case ACTOR_ISVALID: return (sprite[iActor].statnum != MAXSTATUS);
default: return -1;
}

View File

@ -414,6 +414,8 @@ local ActorLabels = {
-- Read access differs from write, write not available:
alpha = { "_math.floor(spriteext[%s].alpha*255)", "spriteext[%s].alpha=(%%s)/255" },
isvalid = { "_con._isvalid(%s)" },
}
local function spr2tspr(code)

View File

@ -1424,11 +1424,20 @@ function _cansee(aci, ps)
return can
end
function _isvalid(i)
check_sprite_idx(i)
return ffiC.sprite[i].statnum ~= ffiC.MAXSTATUS and 1 or 0
end
function _canseespr(s1, s2)
local spr1, spr2 = sprite[s1], sprite[s2]
check_sprite_idx(s1)
check_sprite_idx(s2)
local spr1, spr2 = ffiC.sprite[s1], ffiC.sprite[s2]
-- Redundant, but points the error messages to the CON code:
check_sector_idx(spr1.sectnum)
check_sector_idx(spr2.sectnum)
return cansee(spr1, spr1.sectnum, spr2, spr2.sectnum) and 1 or 0
end