Convert multi-psky handling to use dynamically-allocated arrays.

git-svn-id: https://svn.eduke32.com/eduke32@5255 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-05-27 08:47:34 +00:00
parent 410406158a
commit f33887b2f8
6 changed files with 58 additions and 105 deletions

View file

@ -80,8 +80,6 @@ enum rendmode_t {
#define MAXBASEPALS 8
#define MAXPALOOKUPS 256
#define MAXBLENDTABS 256
// Maximum number of defined multi-pskies:
#define MAXPSKYMULTIS 8
// Maximum number of component tiles in a multi-psky:
#define MAXPSKYTILES 8
#define MAXSPRITESONSCREEN 4096
@ -714,6 +712,7 @@ EXTERN int16_t *startumost, *startdmost;
// The maximum tile offset ever used in any tiled parallaxed multi-sky.
#define PSKYOFF_MAX 4
#define DEFAULTPSKY -1
typedef struct {
// The proportion at which looking up/down affects the apparent 'horiz' of
@ -731,11 +730,11 @@ typedef struct {
// Index of map-global (legacy) multi-sky:
EXTERN int32_t g_pskyidx;
// New multi-psky -- up to MAXPSKYMULTIS (effectively constant after initialization):
// New multi-psky
EXTERN int32_t pskynummultis;
EXTERN psky_t multipsky[MAXPSKYMULTIS];
EXTERN psky_t * multipsky;
// Mapping of multi-sky index to base sky tile number:
EXTERN int32_t multipskytile[MAXPSKYMULTIS];
EXTERN int32_t * multipskytile;
FORCE_INLINE int32_t getpskyidx(int32_t picnum)
{
@ -748,6 +747,8 @@ FORCE_INLINE int32_t getpskyidx(int32_t picnum)
return j;
}
EXTERN psky_t * E_DefinePsky(int32_t tilenum);
EXTERN char parallaxtype;
EXTERN int32_t parallaxyoffs_override, parallaxyscale_override;
extern int16_t pskybits_override;

View file

@ -9016,7 +9016,26 @@ static inline int32_t raytrace(int32_t x3, int32_t y3, int32_t *x4, int32_t *y4)
return hitwall;
}
//
// multi-pskies
//
psky_t * E_DefinePsky(int32_t const tilenum)
{
for (int i = 0; i < pskynummultis; i++)
if (multipskytile[i] == tilenum)
return &multipsky[i];
int32_t const newPskyID = pskynummultis++;
multipsky = (psky_t *)Xrealloc(multipsky, pskynummultis * sizeof(psky_t));
multipskytile = (int32_t *)Xrealloc(multipskytile, pskynummultis * sizeof(int32_t));
psky_t * const newPsky = &multipsky[newPskyID];
Bmemset(newPsky, 0, sizeof(psky_t));
multipskytile[newPskyID] = tilenum;
return newPsky;
}
//
// Exported Engine Functions
@ -9287,6 +9306,10 @@ void uninitengine(void)
Bfree(usermaphacks[i].title);
}
Bfree(usermaphacks);
DO_FREE_AND_NULL(multipsky);
DO_FREE_AND_NULL(multipskytile);
pskynummultis = 0;
}

View file

@ -221,14 +221,14 @@ static inline void bricolor(palette_t *wpptr, int32_t dacol)
// Returns: pointer to tile offset array. Sets-by-pointer the other two.
static inline const int8_t *getpsky(int32_t picnum, int32_t *dapyscale, int32_t *dapskybits)
{
int32_t j = getpskyidx(picnum);
psky_t const * const psky = &multipsky[getpskyidx(picnum)];
if (dapskybits)
*dapskybits = (pskybits_override == -1 ? multipsky[j].lognumtiles : pskybits_override);
*dapskybits = (pskybits_override == -1 ? psky->lognumtiles : pskybits_override);
if (dapyscale)
*dapyscale = (parallaxyscale_override == 0 ? multipsky[j].horizfrac : parallaxyscale_override);
*dapyscale = (parallaxyscale_override == 0 ? psky->horizfrac : parallaxyscale_override);
return multipsky[j].tileofs;
return psky->tileofs;
}
FORCE_INLINE void set_globalpos(int32_t const x, int32_t const y, int32_t const z)

View file

@ -151,49 +151,27 @@ const char *G_ConFile(void)
//////////
#define NUMPSKYMULTIS 5
EDUKE32_STATIC_ASSERT(NUMPSKYMULTIS <= MAXPSKYMULTIS);
EDUKE32_STATIC_ASSERT(PSKYOFF_MAX <= MAXPSKYTILES);
// Set up new-style multi-psky handling.
void G_InitMultiPsky(int32_t CLOUDYOCEAN__DYN, int32_t MOONSKY1__DYN, int32_t BIGORBIT1__DYN, int32_t LA__DYN)
void G_InitMultiPsky(int32_t const CLOUDYOCEAN__DYN, int32_t const MOONSKY1__DYN, int32_t const BIGORBIT1__DYN, int32_t const LA__DYN)
{
int32_t i;
psky_t *defaultsky = &multipsky[0];
psky_t *oceansky = &multipsky[1];
psky_t *moonsky = &multipsky[2];
psky_t *spacesky = &multipsky[3];
psky_t *citysky = &multipsky[4];
static int32_t inited;
if (inited)
return;
inited = 1;
multipskytile[0] = -1;
multipskytile[1] = CLOUDYOCEAN__DYN;
multipskytile[2] = MOONSKY1__DYN;
multipskytile[3] = BIGORBIT1__DYN;
multipskytile[4] = LA__DYN;
pskynummultis = NUMPSKYMULTIS;
// When adding other multi-skies, take care that the tileofs[] values are
// <= PSKYOFF_MAX. (It can be increased up to MAXPSKYTILES, but should be
// set as tight as possible.)
// The default sky properties (all others are implicitly zero):
psky_t * const defaultsky = E_DefinePsky(DEFAULTPSKY);
defaultsky->lognumtiles = 3;
defaultsky->horizfrac = 32768;
// CLOUDYOCEAN
// Aligns with the drawn scene horizon because it has one itself.
psky_t * const oceansky = E_DefinePsky(CLOUDYOCEAN__DYN);
oceansky->lognumtiles = 3;
oceansky->horizfrac = 65536;
// MOONSKY1
// earth mountain mountain sun
psky_t * const moonsky = E_DefinePsky(MOONSKY1__DYN);
moonsky->lognumtiles = 3;
moonsky->horizfrac = 32768;
moonsky->tileofs[6] = 1;
@ -203,6 +181,7 @@ void G_InitMultiPsky(int32_t CLOUDYOCEAN__DYN, int32_t MOONSKY1__DYN, int32_t BI
// BIGORBIT1 // orbit
// earth1 2 3 moon/sun
psky_t * const spacesky = E_DefinePsky(BIGORBIT1__DYN);
spacesky->lognumtiles = 3;
spacesky->horizfrac = 32768;
spacesky->tileofs[5] = 1;
@ -212,6 +191,7 @@ void G_InitMultiPsky(int32_t CLOUDYOCEAN__DYN, int32_t MOONSKY1__DYN, int32_t BI
// LA // la city
// earth1 2 3 moon/sun
psky_t * const citysky = E_DefinePsky(LA__DYN);
citysky->lognumtiles = 3;
citysky->horizfrac = 16384+1024;
citysky->tileofs[0] = 1;
@ -223,12 +203,12 @@ void G_InitMultiPsky(int32_t CLOUDYOCEAN__DYN, int32_t MOONSKY1__DYN, int32_t BI
citysky->tileofs[6] = 2;
citysky->tileofs[7] = 3;
for (i=0; i<pskynummultis; ++i)
{
int32_t j;
for (j=0; j<(1<<multipsky[i].lognumtiles); ++j)
#if 0
// This assertion should hold. See note above.
for (int i=0; i<pskynummultis; ++i)
for (int j=0; j<(1<<multipsky[i].lognumtiles); ++j)
Bassert(multipsky[i].tileofs[j] <= PSKYOFF_MAX);
}
#endif
}
void G_SetupGlobalPsky(void)

View file

@ -40,36 +40,11 @@ const char *G_DefFile(void)
return g_defNamePtr;
}
#define NUMPSKYMULTIS 1
EDUKE32_STATIC_ASSERT(NUMPSKYMULTIS <= MAXPSKYMULTIS);
EDUKE32_STATIC_ASSERT(PSKYOFF_MAX <= MAXPSKYTILES);
// Set up new-style multi-psky handling.
void SW_InitMultiPsky(void)
{
int32_t i;
static int32_t inited;
if (inited)
return;
inited = 1;
multipskytile[0] = -1;
pskynummultis = NUMPSKYMULTIS;
// When adding other multi-skies, take care that the tileofs[] values are
// <= PSKYOFF_MAX. (It can be increased up to MAXPSKYTILES, but should be
// set as tight as possible.)
// The default sky properties (all others are implicitly zero):
multipsky[0].lognumtiles = 1;
multipsky[0].horizfrac = 8192;
for (i=0; i<pskynummultis; ++i)
{
int32_t j;
for (j=0; j<(1<<multipsky[i].lognumtiles); ++j)
Bassert(multipsky[i].tileofs[j] <= PSKYOFF_MAX);
}
// default
psky * const defaultsky = E_DefinePsky(DEFAULTPSKY);
defaultsky->lognumtiles = 1;
defaultsky->horizfrac = 8192;
}

View file

@ -32,46 +32,20 @@ uint8_t *basepaltable[1] = {
uint32_t PaletteIndexFullbrights[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
#define NUMPSKYMULTIS 3
EDUKE32_STATIC_ASSERT(NUMPSKYMULTIS <= MAXPSKYMULTIS);
EDUKE32_STATIC_ASSERT(PSKYOFF_MAX <= MAXPSKYTILES);
// Set up new-style multi-psky handling.
void Ken_InitMultiPsky(void)
{
int32_t i;
static int32_t inited;
if (inited)
return;
inited = 1;
multipskytile[0] = -1;
multipskytile[1] = DAYSKY;
multipskytile[2] = NIGHTSKY;
pskynummultis = NUMPSKYMULTIS;
// When adding other multi-skies, take care that the tileofs[] values are
// <= PSKYOFF_MAX. (It can be increased up to MAXPSKYTILES, but should be
// set as tight as possible.)
// The default sky properties (all others are implicitly zero):
multipsky[0].lognumtiles = 1;
multipsky[0].horizfrac = 65536;
// default
psky * const defaultsky = E_DefinePsky(DEFAULTPSKY);
defaultsky->lognumtiles = 1;
defaultsky->horizfrac = 65536;
// DAYSKY
multipsky[1].lognumtiles = 1;
multipsky[1].horizfrac = 65536;
psky * const daysky = E_DefinePsky(DAYSKY);
daysky->lognumtiles = 1;
daysky->horizfrac = 65536;
// NIGHTSKY
multipsky[2].lognumtiles = 3;
multipsky[2].horizfrac = 65536;
for (i=0; i<pskynummultis; ++i)
{
int32_t j;
for (j=0; j<(1<<multipsky[i].lognumtiles); ++j)
Bassert(multipsky[i].tileofs[j] <= PSKYOFF_MAX);
}
psky * const nightsky = E_DefinePsky(NIGHTSKY);
nightsky->lognumtiles = 3;
nightsky->horizfrac = 65536;
}