| 1 |
/* |
| 2 |
* Portions of this file are copyright Rebirth contributors and licensed as |
| 3 |
* described in COPYING.txt. |
| 4 |
* Portions of this file are copyright Parallax Software and licensed |
| 5 |
* according to the Parallax license below. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
|
| 8 |
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 |
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 |
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 |
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 |
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 |
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 |
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 |
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 |
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 |
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* |
| 22 |
* Functions for loading palettes |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <string.h> |
| 27 |
#include <stdlib.h> |
| 28 |
|
| 29 |
#include "maths.h" |
| 30 |
#include "vecmat.h" |
| 31 |
#include "gr.h" |
| 32 |
#include "3d.h" |
| 33 |
#include "palette.h" |
| 34 |
#include "rle.h" |
| 35 |
#include "inferno.h" |
| 36 |
#include "game.h" |
| 37 |
#include "gamepal.h" |
| 38 |
#include "mission.h" |
| 39 |
#include "newmenu.h" |
| 40 |
#include "texmerge.h" |
| 41 |
#include "piggy.h" |
| 42 |
#include "strutil.h" |
| 43 |
#include "gauges.h" |
| 44 |
|
| 45 |
namespace dsx { |
| 46 |
|
| 47 |
char last_palette_loaded[FILENAME_LEN]=""; |
| 48 |
std::array<char, FILENAME_LEN> last_palette_loaded_pig; |
| 49 |
|
| 50 |
//special hack to tell that palette system about a pig that's been loaded elsewhere |
| 51 |
void load_palette_for_pig(const std::span<const char> name) |
| 52 |
{ |
| 53 |
/* Never write to the last byte, so that the array is always null terminated. */ |
| 54 |
std::memcpy(last_palette_loaded_pig.data(), name.data(), std::min(name.size(), last_palette_loaded_pig.size() - 1)); |
| 55 |
} |
| 56 |
|
| 57 |
//load a palette by name. returns 1 if new palette loaded, else 0 |
| 58 |
//if used_for_level is set, load pig, etc. |
| 59 |
//if no_change_screen is set, the current screen does not get remapped, |
| 60 |
//and the hardware palette does not get changed |
| 61 |
int load_palette(const std::span<const char> name, const load_palette_use used_for_level, const load_palette_change_screen change_screen) |
| 62 |
{ |
| 63 |
char pigname[FILENAME_LEN]; |
| 64 |
palette_array_t old_pal; |
| 65 |
|
| 66 |
if (used_for_level != load_palette_use::background && strcmp(last_palette_loaded_pig.data(), name.data()) != 0) |
| 67 |
{ |
| 68 |
const auto path = d_splitpath(name.data()); |
| 69 |
snprintf(pigname, sizeof(pigname), "%.*s.pig", DXX_ptrdiff_cast_int(path.base_end - path.base_start), path.base_start); |
| 70 |
//if not editor, load pig first so small install message can come |
| 71 |
//up in old palette. If editor version, we must load the pig after |
| 72 |
//the palette is loaded so we can remap new textures. |
| 73 |
#if !DXX_USE_EDITOR |
| 74 |
piggy_new_pigfile(pigname); |
| 75 |
#endif |
| 76 |
} |
| 77 |
|
| 78 |
if (d_stricmp(last_palette_loaded, name.data()) != 0) |
| 79 |
{ |
| 80 |
old_pal = gr_palette; |
| 81 |
|
| 82 |
std::memcpy(last_palette_loaded, name.data(), std::min(name.size(), sizeof(last_palette_loaded) - 1)); |
| 83 |
gr_use_palette_table(name.data()); |
| 84 |
|
| 85 |
if (change_screen == load_palette_change_screen::immediate) |
| 86 |
{ |
| 87 |
if (Game_wind) |
| 88 |
gr_remap_bitmap_good(grd_curscreen->sc_canvas.cv_bitmap, old_pal, -1, -1); |
| 89 |
gr_palette_load(gr_palette); |
| 90 |
} |
| 91 |
|
| 92 |
newmenu_free_background(); // palette changed! free menu! |
| 93 |
gr_remap_color_fonts(); |
| 94 |
|
| 95 |
Color_0_31_0 = -1; //for gauges |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
if (used_for_level != load_palette_use::background && strcmp(last_palette_loaded_pig.data(), name.data()) != 0) |
| 100 |
{ |
| 101 |
std::memcpy(last_palette_loaded_pig.data(), name.data(), std::min(name.size(), last_palette_loaded_pig.size() - 1)); |
| 102 |
|
| 103 |
#if DXX_USE_EDITOR |
| 104 |
piggy_new_pigfile(pigname); |
| 105 |
#endif |
| 106 |
|
| 107 |
texmerge_flush(); |
| 108 |
rle_cache_flush(); |
| 109 |
} |
| 110 |
|
| 111 |
return 1; |
| 112 |
} |
| 113 |
|
| 114 |
} |