mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
C-CON: fix 'resizearray' after r4735: copy over old values, zero-init new ones.
Make lunatic/test/gamearray.con run in C-CON, too. git-svn-id: https://svn.eduke32.com/eduke32@5238 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
d27824ae3c
commit
fe4db15536
3 changed files with 32 additions and 17 deletions
|
@ -4590,11 +4590,9 @@ finish_qsprintf:
|
|||
// elements, resize the array to size zero.
|
||||
if (numelts > 0)
|
||||
{
|
||||
/*OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n",
|
||||
aGameArrays[j].szLabel, aGameArrays[j].size, numelts);*/
|
||||
int32_t numbytes = numelts * sizeof(int32_t);
|
||||
#ifdef BITNESS64
|
||||
int32_t *tmpar = (int32_t *)Xmalloc(numbytes);
|
||||
int32_t *tmpar = (int32_t *)Xcalloc(numelts, sizeof(int32_t));
|
||||
kread(fil, tmpar, numbytes);
|
||||
#endif
|
||||
Baligned_free(aGameArrays[j].plValues);
|
||||
|
@ -4650,14 +4648,23 @@ finish_qsprintf:
|
|||
insptr++;
|
||||
{
|
||||
tw=*insptr++;
|
||||
int32_t asize = Gv_GetVarX(*insptr++);
|
||||
const int32_t newSize = Gv_GetVarX(*insptr++);
|
||||
const int32_t oldSize = aGameArrays[tw].size;
|
||||
|
||||
if (asize > 0)
|
||||
if (newSize > 0 && newSize != oldSize)
|
||||
{
|
||||
/*OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n", aGameArrays[j].szLabel, aGameArrays[j].size, asize);*/
|
||||
// OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n",
|
||||
// aGameArrays[j].szLabel, aGameArrays[j].size, newSize);
|
||||
intptr_t *const tmpar = Xmalloc(GAR_ELTSZ * oldSize);
|
||||
memcpy(tmpar, aGameArrays[tw].plValues, GAR_ELTSZ * oldSize);
|
||||
|
||||
Baligned_free(aGameArrays[tw].plValues);
|
||||
aGameArrays[tw].plValues = (intptr_t *)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, GAR_ELTSZ * asize);
|
||||
aGameArrays[tw].size = asize;
|
||||
aGameArrays[tw].plValues = (intptr_t *)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, GAR_ELTSZ * newSize);
|
||||
aGameArrays[tw].size = newSize;
|
||||
|
||||
memcpy(aGameArrays[tw].plValues, tmpar, GAR_ELTSZ * min(oldSize, newSize));
|
||||
if (newSize > oldSize)
|
||||
memset(&aGameArrays[tw].plValues[oldSize], 0, GAR_ELTSZ * (newSize - oldSize));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
// Test for gamearrays / their persistence.
|
||||
// Doesn't run in C-CON because redefinequote/qsprintf error out when passed a
|
||||
// non-allocated quote as destination.
|
||||
|
||||
define QWESZ 10
|
||||
define ASDSZ 12
|
||||
|
@ -25,8 +23,15 @@ gamevar local 0 0
|
|||
gamevar i 0 0
|
||||
gamevar tmp 0 0
|
||||
|
||||
definequote 400 LTEST_QWE_ARRAY.bin
|
||||
definequote 401 LTEST_ASD_ARRAY.bin
|
||||
define Q_qwe_fn 400
|
||||
define Q_asd_fn 401
|
||||
definequote Q_qwe_fn LTEST_QWE_ARRAY.bin
|
||||
definequote Q_asd_fn LTEST_ASD_ARRAY.bin
|
||||
|
||||
// Wouldn't run in C-CON otherwise; redefinequote/qsprintf errors out when
|
||||
// passed a non-allocated quote as destination.
|
||||
definequote 500 TEMP
|
||||
definequote 501 TEMP
|
||||
|
||||
definequote 505 tile y sizes: 0:%d 1:%d 2:%d 3:%d 4:%d 5:%d 6:%d 7:%d 8:%d
|
||||
definequote 506 1: 0x0a0a0d0d==168430861 ? %d
|
||||
|
@ -80,11 +85,14 @@ onevent EVENT_ENTERLEVEL
|
|||
resizearray qwe NEWQWESZ // shrink
|
||||
resizearray asd NEWASDSZ // grow
|
||||
|
||||
writearraytofile qwe 400
|
||||
writearraytofile asd 401
|
||||
ifvarn qwe[4] 4 state error
|
||||
ifvarn asd[4] 0x0a0a0d0d state error
|
||||
|
||||
readarrayfromfile qwe1 400
|
||||
readarrayfromfile asd1 401
|
||||
writearraytofile qwe Q_qwe_fn
|
||||
writearraytofile asd Q_asd_fn
|
||||
|
||||
readarrayfromfile qwe1 Q_qwe_fn
|
||||
readarrayfromfile asd1 Q_asd_fn
|
||||
|
||||
qsprintf 507 507 asd[4]
|
||||
userquote 507
|
||||
|
|
|
@ -491,7 +491,7 @@ int32_t MUSIC_PlaySong(char *song, int32_t loopflag)
|
|||
else initprintf("%s: fopen: %s\n", __func__, strerror(errno));
|
||||
}
|
||||
else
|
||||
music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem((char *) song, g_musicSize)
|
||||
music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem(song, g_musicSize)
|
||||
#if (SDL_MAJOR_VERSION > 1)
|
||||
, SDL_FALSE
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue