Structify animsounds arrays.

git-svn-id: https://svn.eduke32.com/eduke32@6282 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-06-25 11:24:19 +00:00
parent 6b880ccb06
commit 4db07ee9af
3 changed files with 22 additions and 22 deletions

View file

@ -118,12 +118,13 @@ int32_t Anim_Play(const char *fn)
return 0;
}
int32_t framenum = 0, soundidx = 0; // custom anim sounds
uint16_t soundidx = 0; // custom anim sounds
int32_t running = 1, i;
I_ClearAllInput();
#ifdef USE_LIBVPX
uint16_t framenum = 0;
while (getrendermode() >= REND_POLYMOST) // if, really
{
char vpxfn[BMAX_PATH];
@ -193,9 +194,9 @@ int32_t Anim_Play(const char *fn)
// after rendering the frame but before displaying: maybe play sound...
framenum++;
while (soundidx < anim->numsounds && anim->sounds[soundidx << 1] == framenum)
while (soundidx < anim->numsounds && anim->sounds[soundidx].frame == framenum)
{
S_PlaySound(anim->sounds[(soundidx << 1) + 1]);
S_PlaySound(anim->sounds[soundidx].sound);
soundidx++;
}
@ -332,13 +333,13 @@ int32_t Anim_Play(const char *fn)
if (!anim->numsounds && anim->sound_func)
anim->sound_func(i);
framenum = i++;
while (soundidx < anim->numsounds && anim->sounds[soundidx << 1] == framenum)
while (soundidx < anim->numsounds && anim->sounds[soundidx].frame == (uint16_t)i)
{
S_PlaySound(anim->sounds[(soundidx << 1) + 1]);
S_PlaySound(anim->sounds[soundidx].sound);
soundidx++;
}
++i;
} while (i < numframes);
end_anim_restore_gl:

View file

@ -23,12 +23,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef anim_h_
#define anim_h_
typedef struct {
uint16_t frame, sound;
} animsound_t;
typedef struct
{
uint8_t* animbuf;
void (*sound_func)(int32_t);
uint16_t *sounds;
int16_t numsounds;
animsound_t *sounds;
uint16_t numsounds;
uint8_t framedelay;
char animlock;
} dukeanim_t;

View file

@ -5286,11 +5286,13 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
initprintf("Warning: overwriting already defined hi-anim %s's sounds on line %s:%d\n", fileName,
pScript->filename, scriptfile_getlinum(pScript, tokenPtr));
Bfree(animPtr->sounds);
animPtr->numsounds = 0;
}
animPtr->sounds = (uint16_t *) Xcalloc(allocSize, 2 * sizeof(uint16_t));
animPtr->sounds = (animsound_t *)Xmalloc(allocSize * sizeof(animsound_t));
animPtr->numsounds = 0;
}
else
break;
while (pScript->textptr < animSoundsEnd)
{
@ -5310,10 +5312,6 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
defError = 1;
// TODO: look carefully at whether this can be removed.
if (animPtr->sounds == NULL) // Bcalloc check
break;
if (scriptfile_getsymbol(pScript, &soundNum))
break;
@ -5344,18 +5342,15 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
if (numPairs >= allocSize)
{
void *newptr;
allocSize *= 2;
newptr = Xrealloc(animPtr->sounds, allocSize * 2 * sizeof(uint16_t));
animPtr->sounds = (uint16_t *)newptr;
animPtr->sounds = (animsound_t *)Xrealloc(animPtr->sounds, allocSize * sizeof(animsound_t));
}
defError = 0;
animPtr->sounds[2 * numPairs] = frameNum;
animPtr->sounds[2 * numPairs + 1] = soundNum;
animsound_t & sound = animPtr->sounds[numPairs];
sound.frame = frameNum;
sound.sound = soundNum;
++numPairs;
}