2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Functions for loading palettes
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "vecmat.h"
|
|
|
|
#include "gr.h"
|
|
|
|
#include "3d.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "rle.h"
|
|
|
|
#include "inferno.h"
|
2010-04-04 01:31:48 +00:00
|
|
|
#include "game.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "gamepal.h"
|
|
|
|
#include "mission.h"
|
|
|
|
#include "newmenu.h"
|
|
|
|
#include "texmerge.h"
|
|
|
|
#include "piggy.h"
|
|
|
|
#include "strutil.h"
|
2012-11-11 00:14:30 +00:00
|
|
|
#include "gauges.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dsx {
|
2015-12-13 18:00:48 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
char last_palette_loaded[FILENAME_LEN]="";
|
2023-04-15 19:11:14 +00:00
|
|
|
std::array<char, FILENAME_LEN> last_palette_loaded_pig;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2023-04-15 19:11:14 +00:00
|
|
|
//special hack to tell that palette system about a pig that's been loaded elsewhere
|
|
|
|
void load_palette_for_pig(const std::span<const char> name)
|
|
|
|
{
|
|
|
|
/* Never write to the last byte, so that the array is always null terminated. */
|
2023-04-15 19:11:14 +00:00
|
|
|
std::memcpy(last_palette_loaded_pig.data(), name.data(), std::min(name.size(), last_palette_loaded_pig.size() - 1));
|
2023-04-15 19:11:14 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//load a palette by name. returns 1 if new palette loaded, else 0
|
|
|
|
//if used_for_level is set, load pig, etc.
|
|
|
|
//if no_change_screen is set, the current screen does not get remapped,
|
|
|
|
//and the hardware palette does not get changed
|
2023-04-15 19:11:14 +00:00
|
|
|
int load_palette(const std::span<const char> name, const load_palette_use used_for_level, const load_palette_change_screen change_screen)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
char pigname[FILENAME_LEN];
|
2013-01-06 21:03:57 +00:00
|
|
|
palette_array_t old_pal;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2023-04-15 19:11:14 +00:00
|
|
|
if (used_for_level != load_palette_use::background && strcmp(last_palette_loaded_pig.data(), name.data()) != 0)
|
2022-09-24 17:47:52 +00:00
|
|
|
{
|
|
|
|
const auto path = d_splitpath(name.data());
|
2016-08-19 03:41:41 +00:00
|
|
|
snprintf(pigname, sizeof(pigname), "%.*s.pig", DXX_ptrdiff_cast_int(path.base_end - path.base_start), path.base_start);
|
2006-03-20 17:12:09 +00:00
|
|
|
//if not editor, load pig first so small install message can come
|
|
|
|
//up in old palette. If editor version, we must load the pig after
|
|
|
|
//the palette is loaded so we can remap new textures.
|
2016-09-11 18:49:16 +00:00
|
|
|
#if !DXX_USE_EDITOR
|
2006-03-20 17:12:09 +00:00
|
|
|
piggy_new_pigfile(pigname);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-09-24 17:47:52 +00:00
|
|
|
if (d_stricmp(last_palette_loaded, name.data()) != 0)
|
|
|
|
{
|
2013-01-06 21:11:53 +00:00
|
|
|
old_pal = gr_palette;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2022-09-24 17:47:52 +00:00
|
|
|
std::memcpy(last_palette_loaded, name.data(), std::min(name.size(), sizeof(last_palette_loaded) - 1));
|
|
|
|
gr_use_palette_table(name.data());
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2023-04-15 19:11:14 +00:00
|
|
|
if (change_screen == load_palette_change_screen::immediate)
|
|
|
|
{
|
|
|
|
if (Game_wind)
|
|
|
|
gr_remap_bitmap_good(grd_curscreen->sc_canvas.cv_bitmap, old_pal, -1, -1);
|
2006-03-20 17:12:09 +00:00
|
|
|
gr_palette_load(gr_palette);
|
2023-04-15 19:11:14 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2010-07-31 12:09:38 +00:00
|
|
|
newmenu_free_background(); // palette changed! free menu!
|
2008-04-06 20:23:28 +00:00
|
|
|
gr_remap_color_fonts();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
Color_0_31_0 = -1; //for gauges
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-15 19:11:14 +00:00
|
|
|
if (used_for_level != load_palette_use::background && strcmp(last_palette_loaded_pig.data(), name.data()) != 0)
|
2022-09-24 17:47:52 +00:00
|
|
|
{
|
2023-04-15 19:11:14 +00:00
|
|
|
std::memcpy(last_palette_loaded_pig.data(), name.data(), std::min(name.size(), last_palette_loaded_pig.size() - 1));
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2016-09-11 18:49:16 +00:00
|
|
|
#if DXX_USE_EDITOR
|
2006-03-20 17:12:09 +00:00
|
|
|
piggy_new_pigfile(pigname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
texmerge_flush();
|
|
|
|
rle_cache_flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-13 18:00:48 +00:00
|
|
|
}
|