From f33887b2f813b9f8fb448cf88e83a886a460571e Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 27 May 2015 08:47:34 +0000 Subject: [PATCH] Convert multi-psky handling to use dynamically-allocated arrays. git-svn-id: https://svn.eduke32.com/eduke32@5255 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 11 ++--- polymer/eduke32/build/src/engine.c | 23 ++++++++++ polymer/eduke32/build/src/engine_priv.h | 8 ++-- polymer/eduke32/source/common.c | 42 +++++------------- polymer/eduke32/source/sw/src/common.c | 33 ++------------ polymer/eduke32/source/testgame/src/common.c | 46 +++++--------------- 6 files changed, 58 insertions(+), 105 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index be69ac2f0..3232d19ea 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -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; diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 0585f1377..8f66c1f6e 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -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; } diff --git a/polymer/eduke32/build/src/engine_priv.h b/polymer/eduke32/build/src/engine_priv.h index a968aa5e4..2bf3dd055 100644 --- a/polymer/eduke32/build/src/engine_priv.h +++ b/polymer/eduke32/build/src/engine_priv.h @@ -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) diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index aaf605a21..5a99e2450 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -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; ilognumtiles = 1; + defaultsky->horizfrac = 8192; } diff --git a/polymer/eduke32/source/testgame/src/common.c b/polymer/eduke32/source/testgame/src/common.c index bfab688e3..349677a79 100644 --- a/polymer/eduke32/source/testgame/src/common.c +++ b/polymer/eduke32/source/testgame/src/common.c @@ -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; ilognumtiles = 3; + nightsky->horizfrac = 65536; }