- made all fields of in_anim_t script-safe (except for the texture pointer which will have to be replaced by a Texture ID.

This commit is contained in:
Christoph Oelckers 2017-02-23 00:16:14 +01:00
parent 47ff6ec33f
commit d295186378

View file

@ -198,23 +198,29 @@ public:
// (which is why I have renamed this one!) // (which is why I have renamed this one!)
// //
static const int MAX_ANIMATION_FRAMES = 20;
struct in_anim_t struct in_anim_t
{ {
int type; // Made an int so I can use '|' int type; // Made an int so I can use '|'
int period; // period in tics between animations int period; // period in tics between animations
int nanims; // number of animation frames
yahpt_t loc; // location of animation yahpt_t loc; // location of animation
int data; // ALWAYS: n/a, RANDOM: period deviation (<256) int data; // ALWAYS: n/a, RANDOM: period deviation (<256)
FTexture * p[MAX_ANIMATION_FRAMES]; // actual graphics for frames of animations TArray<FTexture*> frames; // actual graphics for frames of animations
// following must be initialized to zero before use! // following must be initialized to zero before use!
int nexttic; // next value of bcnt (used in conjunction with period) int nexttic; // next value of bcnt (used in conjunction with period)
int ctr; // next frame number to animate int ctr; // next frame number to animate
int state; // used by RANDOM and LEVEL when animating int state; // used by RANDOM and LEVEL when animating
char levelname[9]; FString LevelName;
char levelname2[9]; FString LevelName2;
void Reset()
{
type = period = loc.x = loc.y = data = nexttic = ctr = state = 0;
LevelName = "";
LevelName2 = "";
frames.Clear();
}
}; };
TArray<lnode_t> lnodes; TArray<lnode_t> lnodes;
@ -414,7 +420,7 @@ public:
FScanner sc(lumpnum); FScanner sc(lumpnum);
while (sc.GetString()) while (sc.GetString())
{ {
memset(&an,0,sizeof(an)); an.Reset();
int caseval = sc.MustMatchString(WI_Cmd); int caseval = sc.MustMatchString(WI_Cmd);
switch(caseval) switch(caseval)
{ {
@ -479,15 +485,13 @@ public:
case 10: // IfTravelling case 10: // IfTravelling
an.type = ANIM_IFTRAVELLING; an.type = ANIM_IFTRAVELLING;
sc.MustGetString(); sc.MustGetString();
strncpy(an.levelname2, sc.String, 8); an.LevelName2 = sc.String;
an.levelname2[8] = 0;
goto readanimation; goto readanimation;
case 11: // IfNotTravelling case 11: // IfNotTravelling
an.type = ANIM_IFTRAVELLING; an.type = ANIM_IFTRAVELLING;
sc.MustGetString(); sc.MustGetString();
strncpy(an.levelname2, sc.String, 8); an.LevelName2 = sc.String;
an.levelname2[8] = 0;
goto readanimation; goto readanimation;
case 14: // NoAutostartMap case 14: // NoAutostartMap
@ -496,8 +500,7 @@ public:
readanimation: readanimation:
sc.MustGetString(); sc.MustGetString();
strncpy(an.levelname, sc.String, 8); an.LevelName = sc.String;
an.levelname[8] = 0;
sc.MustGetString(); sc.MustGetString();
caseval=sc.MustMatchString(WI_Cmd); caseval=sc.MustMatchString(WI_Cmd);
@ -527,15 +530,14 @@ public:
if (!sc.CheckString("{")) if (!sc.CheckString("{"))
{ {
sc.MustGetString(); sc.MustGetString();
an.p[an.nanims++] = TexMan[sc.String]; an.frames.Push(TexMan[sc.String]);
} }
else else
{ {
while (!sc.CheckString("}")) while (!sc.CheckString("}"))
{ {
sc.MustGetString(); sc.MustGetString();
if (an.nanims<MAX_ANIMATION_FRAMES) an.frames.Push(TexMan[sc.String]);
an.p[an.nanims++] = TexMan[sc.String];
} }
} }
an.ctr = -1; an.ctr = -1;
@ -549,7 +551,8 @@ public:
sc.MustGetNumber(); sc.MustGetNumber();
an.loc.y = sc.Number; an.loc.y = sc.Number;
sc.MustGetString(); sc.MustGetString();
an.p[0] = TexMan[sc.String]; an.frames.Reserve(1); // allocate exactly one element
an.frames[0] = TexMan[sc.String];
anims.Push(an); anims.Push(an);
break; break;
@ -587,7 +590,7 @@ public:
case ANIM_ALWAYS: case ANIM_ALWAYS:
if (bcnt >= a->nexttic) if (bcnt >= a->nexttic)
{ {
if (++a->ctr >= a->nanims) if (++a->ctr >= (int)a->frames.Size())
{ {
if (a->data==0) a->ctr = 0; if (a->data==0) a->ctr = 0;
else a->ctr--; else a->ctr--;
@ -647,42 +650,42 @@ public:
switch (a->type & ANIM_CONDITION) switch (a->type & ANIM_CONDITION)
{ {
case ANIM_IFVISITED: case ANIM_IFVISITED:
li = FindLevelInfo(a->levelname); li = FindLevelInfo(a->LevelName);
if (li == NULL || !(li->flags & LEVEL_VISITED)) continue; if (li == NULL || !(li->flags & LEVEL_VISITED)) continue;
break; break;
case ANIM_IFNOTVISITED: case ANIM_IFNOTVISITED:
li = FindLevelInfo(a->levelname); li = FindLevelInfo(a->LevelName);
if (li == NULL || (li->flags & LEVEL_VISITED)) continue; if (li == NULL || (li->flags & LEVEL_VISITED)) continue;
break; break;
// StatCount means 'leaving' - everything else means 'entering'! // StatCount means 'leaving' - everything else means 'entering'!
case ANIM_IFENTERING: case ANIM_IFENTERING:
if (state == StatCount || strnicmp(a->levelname, wbs->next, 8)) continue; if (state == StatCount || strnicmp(a->LevelName, wbs->next, 8)) continue;
break; break;
case ANIM_IFNOTENTERING: case ANIM_IFNOTENTERING:
if (state != StatCount && !strnicmp(a->levelname, wbs->next, 8)) continue; if (state != StatCount && !strnicmp(a->LevelName, wbs->next, 8)) continue;
break; break;
case ANIM_IFLEAVING: case ANIM_IFLEAVING:
if (state != StatCount || strnicmp(a->levelname, wbs->current, 8)) continue; if (state != StatCount || strnicmp(a->LevelName, wbs->current, 8)) continue;
break; break;
case ANIM_IFNOTLEAVING: case ANIM_IFNOTLEAVING:
if (state == StatCount && !strnicmp(a->levelname, wbs->current, 8)) continue; if (state == StatCount && !strnicmp(a->LevelName, wbs->current, 8)) continue;
break; break;
case ANIM_IFTRAVELLING: case ANIM_IFTRAVELLING:
if (strnicmp(a->levelname2, wbs->current, 8) || strnicmp(a->levelname, wbs->next, 8)) continue; if (strnicmp(a->LevelName2, wbs->current, 8) || strnicmp(a->LevelName, wbs->next, 8)) continue;
break; break;
case ANIM_IFNOTTRAVELLING: case ANIM_IFNOTTRAVELLING:
if (!strnicmp(a->levelname2, wbs->current, 8) && !strnicmp(a->levelname, wbs->next, 8)) continue; if (!strnicmp(a->LevelName2, wbs->current, 8) && !strnicmp(a->LevelName, wbs->next, 8)) continue;
break; break;
} }
if (a->ctr >= 0) if (a->ctr >= 0)
screen->DrawTexture(a->p[a->ctr], a->loc.x, a->loc.y, screen->DrawTexture(a->frames[a->ctr], a->loc.x, a->loc.y,
DTA_VirtualWidthF, animwidth, DTA_VirtualHeightF, animheight, TAG_DONE); DTA_VirtualWidthF, animwidth, DTA_VirtualHeightF, animheight, TAG_DONE);
} }
} }