From 4b743b40635d96a6188e58c5053cefc719592b02 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 23 Jun 2020 22:51:37 +0200 Subject: [PATCH] - use the original palette loader from RR. --- source/games/duke/src/common_game.h | 10 +-- source/games/duke/src/game_main.cpp | 96 ++++++++++++++++++++++++++++ source/games/duke/src/zz_common.cpp | 92 -------------------------- source/games/duke/src/zz_game.cpp | 2 +- source/games/duke/src/zz_osdcmds.cpp | 48 -------------- 5 files changed, 102 insertions(+), 146 deletions(-) diff --git a/source/games/duke/src/common_game.h b/source/games/duke/src/common_game.h index 11d723e76..23e551fbf 100644 --- a/source/games/duke/src/common_game.h +++ b/source/games/duke/src/common_game.h @@ -34,17 +34,17 @@ enum Games_t { GAMECOUNT }; -typedef enum basepal_ { +enum basepal_t { BASEPAL = 0, WATERPAL, SLIMEPAL, - DREALMSPAL, TITLEPAL, + DREALMSPAL, ENDINGPAL, // 5 - ANIMPAL, + ANIMPAL, // not used anymore DRUGPAL, BASEPALCOUNT -} basepal_t; +}; #include "v_text.h" @@ -58,7 +58,7 @@ extern void G_SetupGlobalPsky(void); ////////// -extern void G_LoadLookups(void); +extern void genspriteremaps(void); ////////// diff --git a/source/games/duke/src/game_main.cpp b/source/games/duke/src/game_main.cpp index bd6033247..9c99d5ed3 100644 --- a/source/games/duke/src/game_main.cpp +++ b/source/games/duke/src/game_main.cpp @@ -67,5 +67,101 @@ void checkcommandline() } } +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void genspriteremaps(void) +{ + int j; + + auto fr = fileSystem.OpenFileReader("lookup.dat"); + if (!fr.isOpen()) + return; + + j = lookups.loadTable(fr); + + if (j < 0) + { + if (j == -1) + Printf("ERROR loading \"lookup.dat\": failed reading enough data.\n"); + + return; + } + + uint8_t paldata[768]; + + for (j=1; j<=5; j++) + { + if (fr.Read(paldata, 768) != 768) + return; + + for (int k = 0; k < 768; k++) // Build uses 6 bit VGA palettes. + paldata[k] = (paldata[k] << 2) | (paldata[k] >> 6); + + paletteSetColorTable(j, paldata, j == DREALMSPAL || j == ENDINGPAL, j < DREALMSPAL); + } + + for (int i = 0; i < 256; i++) + { + // swap red and blue channels. + paldata[i * 3] = GPalette.BaseColors[i].b; + paldata[i * 3+1] = GPalette.BaseColors[i].g; + paldata[i * 3+2] = GPalette.BaseColors[i].r; + } + paletteSetColorTable(DRUGPAL, paldata, false, false); // todo: implement this as a shader effect (swap R and B in postprocessing.) + + if (isRR()) + { + uint8_t table[256]; + for (j = 0; j < 768; j++) + table[j] = j; + for (j = 0; j < 32; j++) + table[j] = j + 32; + + lookups.makeTable(7, table, 0, 0, 0, 0); + + for (j = 0; j < 768; j++) + table[j] = j; + lookups.makeTable(30, table, 0, 0, 0, 0); + lookups.makeTable(31, table, 0, 0, 0, 0); + lookups.makeTable(32, table, 0, 0, 0, 0); + lookups.makeTable(33, table, 0, 0, 0, 0); + if (isRRRA()) + lookups.makeTable(105, table, 0, 0, 0, 0); + + int unk = 63; + for (j = 64; j < 80; j++) + { + unk--; + table[j] = unk; + table[j + 16] = j - 24; + } + table[80] = 80; + table[81] = 81; + for (j = 0; j < 32; j++) + { + table[j] = j + 32; + } + lookups.makeTable(34, table, 0, 0, 0, 0); + for (j = 0; j < 768; j++) + table[j] = j; + for (j = 0; j < 16; j++) + table[j] = j + 129; + for (j = 16; j < 32; j++) + table[j] = j + 192; + lookups.makeTable(35, table, 0, 0, 0, 0); + if (isRRRA()) + { + lookups.makeTable(50, nullptr, 12 * 4, 12 * 4, 12 * 4, 0); + lookups.makeTable(51, nullptr, 12 * 4, 12 * 4, 12 * 4, 0); + lookups.makeTable(54, lookups.getTable(8), 32 * 4, 32 * 4, 32 * 4, 0); + } + } +} + + END_DUKE_NS diff --git a/source/games/duke/src/zz_common.cpp b/source/games/duke/src/zz_common.cpp index bd2d2cecf..ab34597f0 100644 --- a/source/games/duke/src/zz_common.cpp +++ b/source/games/duke/src/zz_common.cpp @@ -99,97 +99,5 @@ void G_SetupGlobalPsky(void) g_pskyidx = skyIdx; } -////////// - -void G_LoadLookups(void) -{ - int32_t j; - - auto fr = fileSystem.OpenFileReader("lookup.dat"); - if (!fr.isOpen()) - return; - - j = lookups.loadTable(fr); - - if (j < 0) - { - if (j == -1) - Printf("ERROR loading \"lookup.dat\": failed reading enough data.\n"); - - return; - } - - uint8_t paldata[768]; - - for (j=1; j<=5; j++) - { - // Account for TILE_TITLE and REALMS swap between basepal number and on-disk order. - int32_t basepalnum = (j == 3 || j == 4) ? 4+3-j : j; - - if (fr.Read(paldata, 768) != 768) - return; - - for (bssize_t k = 0; k < 768; k++) - paldata[k] <<= 2; - - paletteSetColorTable(basepalnum, paldata, basepalnum == DREALMSPAL || basepalnum == ENDINGPAL, basepalnum < DREALMSPAL); - } - - for (int i = 0; i < 256; i++) - { - // swap red and blue channels. - paldata[i * 3] = GPalette.BaseColors[i].b; - paldata[i * 3+1] = GPalette.BaseColors[i].g; - paldata[i * 3+2] = GPalette.BaseColors[i].r; - } - paletteSetColorTable(DRUGPAL, paldata, false, false); // todo: implement this as a shader effect (swap R and B in postprocessing.) - - if (RR) - { - uint8_t table[256]; - for (bssize_t i = 0; i < 256; i++) - table[i] = i; - for (bssize_t i = 0; i < 32; i++) - table[i] = i+32; - - lookups.makeTable(7, table, 0, 0, 0, 0); - - for (bssize_t i = 0; i < 256; i++) - table[i] = i; - lookups.makeTable(30, table, 0, 0, 0, 0); - lookups.makeTable(31, table, 0, 0, 0, 0); - lookups.makeTable(32, table, 0, 0, 0, 0); - lookups.makeTable(33, table, 0, 0, 0, 0); - if (RRRA) - lookups.makeTable(105, table, 0, 0, 0, 0); - - j = 63; - for (bssize_t i = 64; i < 80; i++) - { - j--; - table[i] = j; - table[i+16] = i-24; - } - table[80] = 80; - table[81] = 81; - for (bssize_t i = 0; i < 32; i++) - table[i] = i+32; - lookups.makeTable(34, table, 0, 0, 0, 0); - for (bssize_t i = 0; i < 256; i++) - table[i] = i; - for (bssize_t i = 0; i < 16; i++) - table[i] = i+129; - for (bssize_t i = 16; i < 32; i++) - table[i] = i+192; - lookups.makeTable(35, table, 0, 0, 0, 0); - if (RRRA) - { - lookups.makeTable(50, NULL, 12 * 4, 12 * 4, 12 * 4, 0); - lookups.makeTable(51, NULL, 12 * 4, 12 * 4, 12 * 4, 0); - lookups.makeTable(54, lookups.getTable(8), 32 * 4, 32 * 4, 32 * 4, 0); - } - } -} - END_DUKE_NS diff --git a/source/games/duke/src/zz_game.cpp b/source/games/duke/src/zz_game.cpp index 0ed8b42dd..c8437a187 100644 --- a/source/games/duke/src/zz_game.cpp +++ b/source/games/duke/src/zz_game.cpp @@ -2133,7 +2133,7 @@ static void G_Startup(void) picanm[TILE_LOADSCREEN].sf |= PICANM_NOFULLBRIGHT_BIT; // Printf("Loading palette/lookups...\n"); - G_LoadLookups(); + genspriteremaps(); TileFiles.PostLoadSetup(); screenpeek = myconnectindex; diff --git a/source/games/duke/src/zz_osdcmds.cpp b/source/games/duke/src/zz_osdcmds.cpp index fbe7a9b7e..d6d7211b5 100644 --- a/source/games/duke/src/zz_osdcmds.cpp +++ b/source/games/duke/src/zz_osdcmds.cpp @@ -130,50 +130,6 @@ foundone: } -// demo [] -// -// To profile a demo ("timedemo mode"), can be given in the range 0-8, -// which will start to replay it as fast as possible, rendering frames -// for each gametic. -// -// Notes: -// * The demos should be recorded with demorec_diffs set to 0, so that the -// game state updates are actually computed. -// * Currently, the profiling can only be aborted on SDL 1.2 builds by -// pressing any key. -// * With greater than 1, interpolation should be calculated properly, -// though this has not been verified by looking at the frames. -// * When testing whether a change in the source has an effect on performance, -// the variance of the run times MUST be taken into account (that is, the -// replaying must be performed multiple times for the old and new versions, -// etc.) -static int osdcmd_demo(CCmdFuncPtr parm) -{ - if (numplayers > 1) - { - Printf("Command not allowed in multiplayer\n"); - return OSDCMD_OK; - } - - if (g_player[myconnectindex].ps->gm & MODE_GAME) - { - Printf("demo: Must not be in a game.\n"); - return OSDCMD_OK; - } - - if (parm->numparms != 1 && parm->numparms != 2) - return OSDCMD_SHOWHELP; - - { - int32_t prof = parm->numparms==2 ? Batoi(parm->parms[1]) : -1; - - Demo_SetFirst(parm->parms[0]); - Demo_PlayFirst(clamp(prof, -1, 8)+1, 0); - } - - return OSDCMD_OK; -} - static int osdcmd_activatecheat(CCmdFuncPtr parm) { if (parm->numparms != 1) @@ -377,10 +333,6 @@ int32_t registerosdcommands(void) { C_RegisterFunction("map","map : loads the given map", osdcmd_map); - if (!VOLUMEONE) - { - C_RegisterFunction("demo","demo : starts the given demo", osdcmd_demo); - } C_RegisterFunction("levelwarp","levelwarp : warp to episode 'e' and map 'm'", osdcmd_levelwarp); C_RegisterFunction("give","give : gives requested item", osdcmd_give);