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; return 0;
} }
int32_t framenum = 0, soundidx = 0; // custom anim sounds uint16_t soundidx = 0; // custom anim sounds
int32_t running = 1, i; int32_t running = 1, i;
I_ClearAllInput(); I_ClearAllInput();
#ifdef USE_LIBVPX #ifdef USE_LIBVPX
uint16_t framenum = 0;
while (getrendermode() >= REND_POLYMOST) // if, really while (getrendermode() >= REND_POLYMOST) // if, really
{ {
char vpxfn[BMAX_PATH]; 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... // after rendering the frame but before displaying: maybe play sound...
framenum++; 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++; soundidx++;
} }
@ -332,13 +333,13 @@ int32_t Anim_Play(const char *fn)
if (!anim->numsounds && anim->sound_func) if (!anim->numsounds && anim->sound_func)
anim->sound_func(i); anim->sound_func(i);
framenum = i++; while (soundidx < anim->numsounds && anim->sounds[soundidx].frame == (uint16_t)i)
while (soundidx < anim->numsounds && anim->sounds[soundidx << 1] == framenum)
{ {
S_PlaySound(anim->sounds[(soundidx << 1) + 1]); S_PlaySound(anim->sounds[soundidx].sound);
soundidx++; soundidx++;
} }
++i;
} while (i < numframes); } while (i < numframes);
end_anim_restore_gl: 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_ #ifndef anim_h_
#define anim_h_ #define anim_h_
typedef struct {
uint16_t frame, sound;
} animsound_t;
typedef struct typedef struct
{ {
uint8_t* animbuf; uint8_t* animbuf;
void (*sound_func)(int32_t); void (*sound_func)(int32_t);
uint16_t *sounds; animsound_t *sounds;
int16_t numsounds; uint16_t numsounds;
uint8_t framedelay; uint8_t framedelay;
char animlock; char animlock;
} dukeanim_t; } 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, initprintf("Warning: overwriting already defined hi-anim %s's sounds on line %s:%d\n", fileName,
pScript->filename, scriptfile_getlinum(pScript, tokenPtr)); pScript->filename, scriptfile_getlinum(pScript, tokenPtr));
Bfree(animPtr->sounds); 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) while (pScript->textptr < animSoundsEnd)
{ {
@ -5310,10 +5312,6 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
defError = 1; defError = 1;
// TODO: look carefully at whether this can be removed.
if (animPtr->sounds == NULL) // Bcalloc check
break;
if (scriptfile_getsymbol(pScript, &soundNum)) if (scriptfile_getsymbol(pScript, &soundNum))
break; break;
@ -5344,18 +5342,15 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
if (numPairs >= allocSize) if (numPairs >= allocSize)
{ {
void *newptr;
allocSize *= 2; allocSize *= 2;
newptr = Xrealloc(animPtr->sounds, allocSize * 2 * sizeof(uint16_t)); animPtr->sounds = (animsound_t *)Xrealloc(animPtr->sounds, allocSize * sizeof(animsound_t));
animPtr->sounds = (uint16_t *)newptr;
} }
defError = 0; defError = 0;
animPtr->sounds[2 * numPairs] = frameNum; animsound_t & sound = animPtr->sounds[numPairs];
animPtr->sounds[2 * numPairs + 1] = soundNum; sound.frame = frameNum;
sound.sound = soundNum;
++numPairs; ++numPairs;
} }