diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 24d18d631..5021c592e 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -77,8 +77,10 @@ enum rendmode_t { #define MAXPLAYERS 16 #define MAXBASEPALS 8 #define MAXPALOOKUPS 256 +// Maximum number of defined multi-pskies: #define MAXPSKYMULTIS 8 -#define MAXPSKYTILES 256 +// Maximum number of component tiles in a multi-psky: +#define MAXPSKYTILES 8 #define MAXSPRITESONSCREEN 4096 #define MAXUNIQHUDID 256 //Extra slots so HUD models can store animation state without messing game sprites @@ -740,21 +742,39 @@ EXTERN uint8_t palette[768]; EXTERN int16_t numshades; EXTERN char *palookup[MAXPALOOKUPS]; EXTERN uint8_t **basepaltableptr; -EXTERN char parallaxtype, showinvisibility; -EXTERN int32_t parallaxyoffs, parallaxyscale; +EXTERN char showinvisibility; EXTERN int32_t g_visibility, parallaxvisibility; EXTERN int32_t g_rotatespriteNoWidescreen; EXTERN int32_t windowx1, windowy1, windowx2, windowy2; EXTERN int16_t startumost[MAXXDIM], startdmost[MAXXDIM]; -// original multi-psky handling (only one per map) -EXTERN int16_t pskyoff[MAXPSKYTILES], pskybits; -// new multi-psky -- up to MAXPSKYMULTIS -EXTERN int16_t pskynummultis; -EXTERN int32_t pskymultiyscale[MAXPSKYMULTIS]; -EXTERN int16_t pskymultilist[MAXPSKYMULTIS], pskymultibits[MAXPSKYMULTIS]; -EXTERN int16_t pskymultioff[MAXPSKYMULTIS][MAXPSKYTILES]; +// The maximum tile offset ever used in any tiled parallaxed multi-sky. +#define PSKYOFF_MAX 4 + +typedef struct { + // The proportion at which looking up/down affects the apparent 'horiz' of + // a parallaxed sky, scaled by 65536 (so, a value of 65536 makes it align + // with the drawn surrounding scene): + int32_t horizfrac; + + // The texel index offset in the y direction of a parallaxed sky: + // XXX: currently always 0. + int32_t yoffs; + + int8_t lognumtiles; // 1<>1)+parallaxyoffs), tsizy) + ((uint32_t)globalypanning<<24); + globalzd = divscale32(((tsizy>>1)+g_psky.yoffs), tsizy) + ((uint32_t)globalypanning<<24); } else #endif { globalshiftval = 32-globalshiftval; globalyscale = (8<<(globalshiftval-19)); - globalzd = (((tsizy>>1)+parallaxyoffs)<>1)+g_psky.yoffs)<>1),dapyscale) + (ydimen>>1); @@ -8646,10 +8631,7 @@ int32_t initengine(void) xyaspect = -1; - pskyoff[0] = 0; pskybits = 0; - pskynummultis = 0; - - parallaxtype = 2; parallaxyoffs = 0L; parallaxyscale = 65536; + parallaxtype = 2; g_psky.horizfrac = 65536; showinvisibility = 0; for (i=1; i<1024; i++) diff --git a/polymer/eduke32/build/src/engine_priv.h b/polymer/eduke32/build/src/engine_priv.h index ad2065506..8428cdbc4 100644 --- a/polymer/eduke32/build/src/engine_priv.h +++ b/polymer/eduke32/build/src/engine_priv.h @@ -212,4 +212,30 @@ static inline void bricolor(palette_t *wpptr, int32_t dacol) } } +// Get properties of parallaxed sky to draw. +// Returns: pointer to tile offset array. Sets-by-pointer the other two. +static inline const int8_t *getpsky(int32_t *dapyscale, int32_t *dapskybits) +{ + int32_t j; + static const int8_t zeropskyoff[MAXPSKYTILES] = { 0 }; + + // First, try a multi-sky. + for (j=0; jfloorshade, global_cf_pal = sec->floorpal; global_cf_z = sec->floorz; // REFACT global_cf_xpanning = sec->floorxpanning; global_cf_ypanning = sec->floorypanning, global_cf_heinum = sec->floorheinum; @@ -2414,7 +2400,7 @@ static void polymost_drawalls(int32_t bunch) dd[0] = (float)xdimen*.0000001; //Adjust sky depth based on screen size! t = (double)((1<<(picsiz[globalpicnum]&15))<>1)+parallaxyoffs)) - vv[1]*ghoriz; + vv[0] = dd[0]*((double)((tilesizy[globalpicnum]>>1)+g_psky.yoffs)) - vv[1]*ghoriz; i = (1<<(picsiz[globalpicnum]>>4)); if (i != tilesizy[globalpicnum]) i += i; //Hack to draw black rectangle below sky when looking down... @@ -2649,20 +2635,7 @@ static void polymost_drawalls(int32_t bunch) DO_TILE_ANIM(globalpicnum, sectnum); - // multi-psky stuff - dapskyoff = zeropskyoff; - dapskybits = pskybits; - - for (i=0; iceilingshade, global_cf_pal = sec->ceilingpal; global_cf_z = sec->ceilingz; // REFACT global_cf_xpanning = sec->ceilingxpanning; global_cf_ypanning = sec->ceilingypanning, global_cf_heinum = sec->ceilingheinum; @@ -2695,7 +2668,7 @@ static void polymost_drawalls(int32_t bunch) dd[0] = (float)xdimen*.0000001; //Adjust sky depth based on screen size! t = (double)((1<<(picsiz[globalpicnum]&15))<>1)+parallaxyoffs)) - vv[1]*ghoriz; + vv[0] = dd[0]*((double)((tilesizy[globalpicnum]>>1)+g_psky.yoffs)) - vv[1]*ghoriz; i = (1<<(picsiz[globalpicnum]>>4)); if (i != tilesizy[globalpicnum]) i += i; //Hack to draw black rectangle below sky when looking down... diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index b7226238a..ed6ab2331 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -723,7 +723,7 @@ void ExtSetupMapFilename(const char *mapname) void ExtLoadMap(const char *mapname) { int32_t i; - int32_t sky=0; + int32_t mskyidx=0; getmessageleng = 0; getmessagetimeoff = 0; @@ -732,39 +732,20 @@ void ExtLoadMap(const char *mapname) // old-fashioned multi-psky handling - Bmemset(pskyoff, 0, sizeof(pskyoff)); + Bmemset(g_psky.tileofs, 0, sizeof(g_psky.tileofs)); for (i=0; i= 0) break; - } } - switch (sky) - { - case MOONSKY1 : - // keep in sync with G_MultiPskyInit - // -v- - Bmemcpy(pskyoff, pskymultioff[0], sizeof(pskymultioff[0])); - break; + if (mskyidx >= 0) + Bmemcpy(g_psky.tileofs, multipsky[mskyidx].tileofs, sizeof(g_psky.tileofs)); - case BIGORBIT1 : // orbit - Bmemcpy(pskyoff, pskymultioff[1], sizeof(pskymultioff[0])); - break; - - case LA : // la city - Bmemcpy(pskyoff, pskymultioff[2], sizeof(pskymultioff[0])); - break; - } - - pskybits=3; - parallaxtype=0; + g_psky.lognumtiles = 3; + parallaxtype = 0; ////////// #if M32_UNDO @@ -10489,7 +10470,7 @@ int32_t ExtInit(void) ReadHelpFile("m32help.hlp"); - G_MultiPskyInit(); + G_MultiPskyInit(MOONSKY1, BIGORBIT1, LA); #ifdef LUNATIC if (Em_CreateState(&g_EmState) == 0) diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index e4cb92539..ad4815707 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -152,56 +152,72 @@ const char *G_ConFile(void) ////////// -void G_MultiPskyInit(void) +// Set up new-style multi-psky handling. +// NOTE: When adding more multi-pskies, take a look whether the engine-side +// MAXPSKYMULTIS needs to be increased. +void G_MultiPskyInit(int32_t MOONSKY1__DYN, int32_t BIGORBIT1__DYN, int32_t LA__DYN) { int32_t i; - // new-style multi-psky handling - pskymultilist[0] = MOONSKY1; - pskymultilist[1] = BIGORBIT1; - pskymultilist[2] = LA; + psky_t *moonsky = &multipsky[0]; + psky_t *spacesky = &multipsky[1]; + psky_t *citysky = &multipsky[2]; - pskymultiyscale[0] = 32768; - pskymultiyscale[1] = 32768; - pskymultiyscale[2] = 16384+1024; + static int32_t inited; + if (inited) + return; + inited = 1; - for (i=0; i<3; ++i) - { - pskymultibits[i] = 3; - Bmemset(pskymultioff[i], 0, sizeof(pskymultioff[i])); - } - - // KEEPINSYNC with Polymer MAX OFFSET = 4 - - // MOONSKY1 - // earth mountain mountain sun - pskymultioff[0][6]=1; - pskymultioff[0][1]=2; - pskymultioff[0][4]=2; - pskymultioff[0][2]=3; - - // BIGORBIT1 // orbit - // earth1 2 3 moon/sun - pskymultioff[1][5]=1; - pskymultioff[1][6]=2; - pskymultioff[1][7]=3; - pskymultioff[1][2]=4; - - // LA // la city - // earth1 2 3 moon/sun - pskymultioff[2][0]=1; - pskymultioff[2][1]=2; - pskymultioff[2][2]=1; - pskymultioff[2][3]=3; - pskymultioff[2][4]=4; - pskymultioff[2][5]=0; - pskymultioff[2][6]=2; - pskymultioff[2][7]=3; + multipskytile[0] = MOONSKY1__DYN; + multipskytile[1] = BIGORBIT1__DYN; + multipskytile[2] = LA__DYN; pskynummultis = 3; + // 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.) + + // MOONSKY1 + // earth mountain mountain sun + moonsky->lognumtiles = 3; + moonsky->horizfrac = 32768; + moonsky->tileofs[6] = 1; + moonsky->tileofs[1] = 2; + moonsky->tileofs[4] = 2; + moonsky->tileofs[2] = 3; + + // BIGORBIT1 // orbit + // earth1 2 3 moon/sun + spacesky->lognumtiles = 3; + spacesky->horizfrac = 32768; + spacesky->tileofs[5] = 1; + spacesky->tileofs[6] = 2; + spacesky->tileofs[7] = 3; + spacesky->tileofs[2] = 4; + + // LA // la city + // earth1 2 3 moon/sun + citysky->lognumtiles = 3; + citysky->horizfrac = 16384+1024; + citysky->tileofs[0] = 1; + citysky->tileofs[1] = 2; + citysky->tileofs[2] = 1; + citysky->tileofs[3] = 3; + citysky->tileofs[4] = 4; + citysky->tileofs[5] = 0; + citysky->tileofs[6] = 2; + citysky->tileofs[7] = 3; + + for (i=0; iclouds[0],&clouds[0],sizeof(clouds)); Bmemcpy(&save->cloudx[0],&cloudx[0],sizeof(cloudx)); Bmemcpy(&save->cloudy[0],&cloudy[0],sizeof(cloudy)); - Bmemcpy(&save->pskyoff[0],&pskyoff[0],sizeof(pskyoff)); - Bmemcpy(&save->pskybits,&pskybits,sizeof(pskybits)); + Bmemcpy(&save->pskyoff[0],g_psky.tileofs,sizeof(g_psky.tileofs)); + Bmemcpy(&save->pskybits,&g_psky.lognumtiles,sizeof(g_psky.lognumtiles)); Bmemcpy(&save->animategoal[0],&animategoal[0],sizeof(animategoal)); Bmemcpy(&save->animatevel[0],&animatevel[0],sizeof(animatevel)); Bmemcpy(&save->g_animateCount,&g_animateCount,sizeof(g_animateCount)); @@ -5643,8 +5643,8 @@ void G_RestoreMapState(void) Bmemcpy(&clouds[0],&save->clouds[0],sizeof(clouds)); Bmemcpy(&cloudx[0],&save->cloudx[0],sizeof(cloudx)); Bmemcpy(&cloudy[0],&save->cloudy[0],sizeof(cloudy)); - Bmemcpy(&pskyoff[0],&save->pskyoff[0],sizeof(pskyoff)); - Bmemcpy(&pskybits,&save->pskybits,sizeof(pskybits)); + Bmemcpy(g_psky.tileofs,&save->pskyoff[0],sizeof(g_psky.tileofs)); + Bmemcpy(&g_psky.lognumtiles,&save->pskybits,sizeof(g_psky.lognumtiles)); Bmemcpy(&animategoal[0],&save->animategoal[0],sizeof(animategoal)); Bmemcpy(&animatevel[0],&save->animatevel[0],sizeof(animatevel)); Bmemcpy(&g_animateCount,&save->g_animateCount,sizeof(g_animateCount)); diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 0b9791652..b877151f4 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -966,50 +966,31 @@ static void resetprestat(int32_t snum,int32_t g) static inline void G_SetupBackdrop(int16_t sky) { - static int32_t multiskiesinited=0; + // Get the static value of the base sky tile number. + const int32_t ssky = DYNAMICTILEMAP(sky); - if (!multiskiesinited) + Bmemset(g_psky.tileofs, 0, sizeof(g_psky.tileofs)); + + // XXX: why the condition? + if (g_psky.horizfrac != 65536) + g_psky.horizfrac = 32768; + + if (ssky == CLOUDYOCEAN__STATIC) { - multiskiesinited = 1; - G_MultiPskyInit(); + g_psky.horizfrac = 65536; + } + else + { + int32_t mskyidx = MultiPsky_TileToIdx(ssky); + if (mskyidx >= 0) + { + Bmemcpy(g_psky.tileofs, multipsky[mskyidx].tileofs, sizeof(g_psky.tileofs)); + if (ssky == LA__STATIC) + g_psky.horizfrac = 16384+1024; + } } - Bmemset(pskyoff, 0, sizeof(pskyoff)); - - if (parallaxyscale != 65536) - parallaxyscale = 32768; - - switch (DYNAMICTILEMAP(sky)) - { - case CLOUDYOCEAN__STATIC: - parallaxyscale = 65536L; - break; - case MOONSKY1__STATIC : - pskyoff[6]=1; - pskyoff[1]=2; - pskyoff[4]=2; - pskyoff[2]=3; - break; - case BIGORBIT1__STATIC: // orbit - pskyoff[5]=1; - pskyoff[6]=2; - pskyoff[7]=3; - pskyoff[2]=4; - break; - case LA__STATIC: - parallaxyscale = 16384+1024; - pskyoff[0]=1; - pskyoff[1]=2; - pskyoff[2]=1; - pskyoff[3]=3; - pskyoff[4]=4; - pskyoff[5]=0; - pskyoff[6]=2; - pskyoff[7]=3; - break; - } - - pskybits=3; + g_psky.lognumtiles = 3; } // tweak moving sectors with these SE lotags @@ -1451,7 +1432,7 @@ void G_NewGame(int32_t vn, int32_t ln, int32_t sk) ud.player_skill = sk; ud.secretlevel = 0; ud.from_bonus = 0; - parallaxyscale = 0; + g_psky.horizfrac = 0; ud.last_level = -1; g_lastSaveSlot = -1; diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 75dff9826..d3a0a75a9 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -139,6 +139,8 @@ void ReadSaveGameHeaders(void) savehead_t h; + EDUKE32_STATIC_ASSERT(sizeof(h.savename) == sizeof(ud.savegame[0])); + Bstrcpy(fn, "dukesav0.esv"); for (i=0; i<10; i++) @@ -1026,9 +1028,7 @@ static const dataspec_t svgm_anmisc[] = { 0, &clouds[0], sizeof(clouds), 1 }, { 0, &cloudx[0], sizeof(cloudx), 1 }, { 0, &cloudy[0], sizeof(cloudy), 1 }, - { DS_NOCHK, ¶llaxyscale, sizeof(parallaxyscale), 1 }, - { 0, &pskybits, sizeof(pskybits), 1 }, - { 0, &pskyoff[0], sizeof(pskyoff[0]), MAXPSKYTILES }, + { 0, &g_psky, sizeof(g_psky), 1 }, // DS_NOCHK? { 0, &g_earthquakeTime, sizeof(g_earthquakeTime), 1 }, { DS_SAVEFN|DS_LOADFN|DS_NOCHK, (void *)sv_prequote, 0, 1 }, diff --git a/polymer/eduke32/source/savegame.h b/polymer/eduke32/source/savegame.h index 8f614b80d..5a37a11b5 100644 --- a/polymer/eduke32/source/savegame.h +++ b/polymer/eduke32/source/savegame.h @@ -49,9 +49,11 @@ typedef struct uint8_t numplayers, volnum, levnum, skill; char boardfn[256]; // BMAX_PATH // 282 bytes -} savehead_t; // 310 bytes +} savehead_t; #pragma pack(pop) +EDUKE32_STATIC_ASSERT(sizeof(savehead_t) == 310); + int32_t sv_updatestate(int32_t frominit); int32_t sv_readdiff(int32_t fil); uint32_t sv_writediff(FILE *fil);