diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index a4863883f..6561afb9f 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -77,7 +77,7 @@ enum rendmode_t { #define MAXVOXELS 4096 #define MAXSTATUS 1024 #define MAXPLAYERS 16 -#define MAXBASEPALS 8 +#define MAXBASEPALS 256 #define MAXPALOOKUPS 256 #define MAXBLENDTABS 256 // Maximum number of component tiles in a multi-psky: @@ -699,7 +699,7 @@ EXTERN int16_t sintable[2048]; EXTERN uint8_t palette[768]; EXTERN int16_t numshades; EXTERN char *palookup[MAXPALOOKUPS]; -EXTERN uint8_t **basepaltableptr; +extern uint8_t *basepaltable[MAXBASEPALS]; EXTERN uint8_t paletteloaded; enum { @@ -1045,7 +1045,7 @@ intptr_t allocatepermanenttile(int16_t tilenume, int32_t xsiz, int32_t ysiz); void copytilepiece(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, int32_t ysiz, int32_t tilenume2, int32_t sx2, int32_t sy2); void makepalookup(int32_t palnum, const char *remapbuf, int8_t r, int8_t g, int8_t b, char noFloorPal); //void setvgapalette(void); -void setbasepaltable(uint8_t **basepaltable, uint8_t basepalcount); +void setbasepal(int32_t id, uint8_t const *table); void setbrightness(char dabrightness, uint8_t dapalid, uint8_t flags); void setpalettefade(char r, char g, char b, char offset); void squarerotatetile(int16_t tilenume); diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index 89f82f29d..b08b18012 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -1937,7 +1937,7 @@ static int32_t defsparser(scriptfile *script) scriptfile_getstring(script,&fn); break; } } - if (EDUKE32_PREDICT_FALSE((unsigned)basepal >= ((unsigned)basepalcount))) + if (EDUKE32_PREDICT_FALSE((unsigned)basepal >= MAXBASEPALS)) { initprintf("Error: missing or invalid 'base palette number' for highpalookup definition " "near line %s:%d\n", script->filename, scriptfile_getlinum(script,highpaltokptr)); diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index dc2e6744b..e86a131a0 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -2414,8 +2414,8 @@ static int32_t baktile; char apptitle[256] = "Build Engine"; +uint8_t *basepaltable[MAXBASEPALS] = { palette }; static uint8_t basepalreset=1; -uint8_t basepalcount; uint8_t curbasepal; static uint32_t g_lastpalettesum = 0; @@ -9369,6 +9369,12 @@ void uninitengine(void) Bfree(blendtable[i]); Bmemset(blendtable, 0, sizeof(blendtable)); + for (int i=1; i= MAXBASEPALS) - thebasepalcount = MAXBASEPALS - 1; + if (basepaltable[id] == NULL) + basepaltable[id] = (uint8_t *)Xmalloc(768); - basepaltableptr = thebasepaltable; - basepalcount = thebasepalcount; + Bmemcpy(basepaltable[id], table, 768); } // @@ -15671,7 +15676,7 @@ void setbrightness(char dabrightness, uint8_t dapalid, uint8_t flags) Bassert((flags&4)==0); - if (dapalid >= basepalcount) + if (/*(unsigned)dapalid >= MAXBASEPALS ||*/ basepaltable[dapalid] == NULL) dapalid = 0; #ifdef USE_OPENGL paldidchange = (curbasepal != dapalid || basepalreset); @@ -15679,7 +15684,7 @@ void setbrightness(char dabrightness, uint8_t dapalid, uint8_t flags) curbasepal = dapalid; basepalreset = 0; - dapal = basepaltableptr[curbasepal]; + dapal = basepaltable[curbasepal]; if (!(flags&4)) { diff --git a/polymer/eduke32/build/src/engine_priv.h b/polymer/eduke32/build/src/engine_priv.h index 7f7113eb2..4fc7c147d 100644 --- a/polymer/eduke32/build/src/engine_priv.h +++ b/polymer/eduke32/build/src/engine_priv.h @@ -28,7 +28,6 @@ extern "C" { extern "C" { #endif -extern uint8_t basepalcount; extern uint8_t curbasepal; extern int16_t thesector[MAXWALLSB], thewall[MAXWALLSB]; diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 9f38ef471..3de91dd0c 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -4917,7 +4917,7 @@ static _prbucket* polymer_getbuildmaterial(_prmaterial* material, int16_t tile 0, GL_RGB, GL_UNSIGNED_BYTE, - basepaltableptr[curbasepal]); + basepaltable[curbasepal]); bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP); diff --git a/polymer/eduke32/source/anim.c b/polymer/eduke32/source/anim.c index 8285f82af..d6dca38c0 100644 --- a/polymer/eduke32/source/anim.c +++ b/polymer/eduke32/source/anim.c @@ -241,7 +241,7 @@ int32_t G_PlayAnim(const char *fn) goto end_anim; } - basepaltable[ANIMPAL] = ANIM_GetPalette(); + setbasepal(ANIMPAL, ANIM_GetPalette()); // setpalette(0L,256L,tempbuf); // setbrightness(ud.brightness>>2,tempbuf,2); diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 4e13da346..ddd939bf8 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -9864,11 +9864,6 @@ int32_t ExtInit(void) Bsprintf(apptitle, "Mapster32 %s %s", VERSION, s_buildRev); autosavetimer = totalclock+120*autosave; - // This must run before the following OSD_Exec() as the cfg may - // e.g. contain a vid_gamma setting, resulting in a crash in - // setbrightness() which expects basepaltableptr to be initialized. - setbasepaltable(basepaltable, BASEPALCOUNT); - registerosdcommands(); { diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index 93343b2aa..3164a19fe 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -1001,14 +1001,6 @@ void G_DoAutoload(const char *dirname) uint32_t PaletteIndexFullbrights[8] = { 0, 0, 0, 0, 0, 0, 0, 2147418112 }; -static uint8_t water_pal[768], slime_pal[768], title_pal[768], dre_alms[768], ending_pal[768]; - -uint8_t *basepaltable[BASEPALCOUNT] = { - palette, water_pal, slime_pal, - dre_alms, title_pal, ending_pal, - NULL /*anim_pal*/ -}; - void G_LoadLookups(void) { int32_t fp, j; @@ -1027,13 +1019,17 @@ void G_LoadLookups(void) return kclose(fp); } + uint8_t paldata[768]; + for (j=1; j<=5; j++) { // Account for TITLE and REALMS swap between basepal number and on-disk order. int32_t basepalnum = (j == 3 || j == 4) ? 4+3-j : j; - if (kread_and_test(fp, basepaltable[basepalnum], 768)) + if (kread_and_test(fp, paldata, 768)) return kclose(fp); + + setbasepal(basepalnum, paldata); } kclose(fp); diff --git a/polymer/eduke32/source/common_game.h b/polymer/eduke32/source/common_game.h index 2fdb9f32e..019b5428b 100644 --- a/polymer/eduke32/source/common_game.h +++ b/polymer/eduke32/source/common_game.h @@ -124,8 +124,6 @@ void G_DoAutoload(const char *dirname); ////////// -extern uint8_t *basepaltable[BASEPALCOUNT]; - extern void G_LoadLookups(void); ////////// diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 5951996e0..f437779ec 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -305,10 +305,10 @@ static void G_PatchStatusBar(int32_t x1, int32_t y1, int32_t x2, int32_t y2) rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1+clofx,cly1+clofy,clx2+clofx-1,cly2+clofy-1); } -void P_SetGamePalette(DukePlayer_t *player, uint8_t palid, int32_t set) +void P_SetGamePalette(DukePlayer_t *player, uint32_t palid, int32_t set) { - if (palid >= BASEPALCOUNT) - palid = BASEPAL; + if (palid >= MAXBASEPALS) + palid = 0; player->palette = palid; @@ -10982,9 +10982,12 @@ static inline void G_CheckGametype(void) static void G_PostLoadPalette(void) { // Make color index 255 of default/water/slime palette black. - Bmemset(&basepaltable[BASEPAL][255*3], 0, 3); - Bmemset(&basepaltable[WATERPAL][255*3], 0, 3); - Bmemset(&basepaltable[SLIMEPAL][255*3], 0, 3); + if (basepaltable[BASEPAL] != NULL) + Bmemset(&basepaltable[BASEPAL][255*3], 0, 3); + if (basepaltable[WATERPAL] != NULL) + Bmemset(&basepaltable[WATERPAL][255*3], 0, 3); + if (basepaltable[SLIMEPAL] != NULL) + Bmemset(&basepaltable[SLIMEPAL][255*3], 0, 3); generatefogpals(); @@ -11113,8 +11116,6 @@ static void G_Startup(void) if (initengine()) G_FatalEngineError(); - setbasepaltable(basepaltable, BASEPALCOUNT); - #ifdef LUNATIC El_CreateGameState(); C_InitQuotes(); diff --git a/polymer/eduke32/source/game.h b/polymer/eduke32/source/game.h index 7ba27bb20..f40d6eb02 100644 --- a/polymer/eduke32/source/game.h +++ b/polymer/eduke32/source/game.h @@ -378,7 +378,7 @@ void G_UpdatePlayerFromMenu(void); void M32RunScript(const char *s); void P_DoQuote(int32_t q,DukePlayer_t *p); extern int32_t textsc(int32_t sc); -void P_SetGamePalette(DukePlayer_t *player,uint8_t palid,int32_t set); +void P_SetGamePalette(DukePlayer_t *player, uint32_t palid, int32_t set); extern int32_t G_GetStringLineLength(const char *text, const char *end, const int32_t iter); extern int32_t G_GetStringNumLines(const char *text, const char *end, const int32_t iter); diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index de38520e1..087fc9ca8 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -681,7 +681,7 @@ int32_t G_CheckActivatorMotion(int32_t lotag); int32_t A_Dodge(spritetype *s); int32_t A_MoveSpriteClipdist(int32_t spritenum, const vec3_t *change, uint32_t cliptype, int32_t clipdist); void P_DoQuote(int32_t q, DukePlayer_t *p); -void P_SetGamePalette(DukePlayer_t *player, uint8_t palid, int32_t set); +void P_SetGamePalette(DukePlayer_t *player, uint32_t palid, int32_t set); void G_AddUserQuote(const char *daquote); void G_ClearCameraView(DukePlayer_t *ps); void G_DrawTileGeneric(int32_t x, int32_t y, int32_t zoom, int32_t tilenum, diff --git a/polymer/eduke32/source/testgame/src/bstub.c b/polymer/eduke32/source/testgame/src/bstub.c index a07fc1bd3..34e43020c 100644 --- a/polymer/eduke32/source/testgame/src/bstub.c +++ b/polymer/eduke32/source/testgame/src/bstub.c @@ -145,8 +145,6 @@ int32_t ExtPostStartupWindow(void) return -1; } - setbasepaltable(basepaltable, 1); - Ken_InitMultiPsky(); tiletovox[PLAYER] = nextvoxid++; diff --git a/polymer/eduke32/source/testgame/src/common.c b/polymer/eduke32/source/testgame/src/common.c index a31a6131e..ff4210109 100644 --- a/polymer/eduke32/source/testgame/src/common.c +++ b/polymer/eduke32/source/testgame/src/common.c @@ -26,11 +26,6 @@ const char *G_DefFile(void) return defaultdeffilename; } -uint8_t *basepaltable[1] = -{ - palette -}; - uint32_t PaletteIndexFullbrights[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; void Ken_InitMultiPsky(void) diff --git a/polymer/eduke32/source/testgame/src/common_game.h b/polymer/eduke32/source/testgame/src/common_game.h index dfc853a97..6cd6ef23d 100644 --- a/polymer/eduke32/source/testgame/src/common_game.h +++ b/polymer/eduke32/source/testgame/src/common_game.h @@ -4,6 +4,4 @@ extern const char *G_DefaultGrpFile(void); extern const char *G_GrpFile(void); -extern uint8_t *basepaltable[1]; - extern void Ken_InitMultiPsky(void); diff --git a/polymer/eduke32/source/testgame/src/game.c b/polymer/eduke32/source/testgame/src/game.c index 3394f1190..fff5360f3 100644 --- a/polymer/eduke32/source/testgame/src/game.c +++ b/polymer/eduke32/source/testgame/src/game.c @@ -526,8 +526,6 @@ int32_t app_main(int32_t argc, const char **argv) return -1; } - setbasepaltable(basepaltable, 1); - Ken_InitMultiPsky(); initinput();