dxx-rebirth/common/main/piggy.h

189 lines
5.3 KiB
C
Raw Normal View History

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.
*/
/*
*
* Interface to piggy functions.
*
*/
2015-04-19 04:18:52 +00:00
#pragma once
2006-03-20 17:12:09 +00:00
2014-07-20 01:09:55 +00:00
#include <physfs.h>
2006-03-20 17:12:09 +00:00
#include "sounds.h"
#include "inferno.h"
2013-10-26 03:40:50 +00:00
#include "gr.h"
2015-02-14 22:48:30 +00:00
#include "fwd-partial_range.h"
2015-04-02 02:36:52 +00:00
#include "dxxsconf.h"
#include "dsx-ns.h"
2016-01-09 16:38:15 +00:00
#ifdef dsx
2015-12-13 18:00:49 +00:00
namespace dsx {
2013-12-26 04:18:28 +00:00
struct digi_sound;
}
#endif
2013-12-26 04:18:28 +00:00
2006-03-20 17:12:09 +00:00
#define D1_SHARE_BIG_PIGSIZE 5092871 // v1.0 - 1.4 before RLE compression
#define D1_SHARE_10_PIGSIZE 2529454 // v1.0 - 1.2
#define D1_SHARE_PIGSIZE 2509799 // v1.4
#define D1_10_BIG_PIGSIZE 7640220 // v1.0 before RLE compression
#define D1_10_PIGSIZE 4520145 // v1.0
#define D1_PIGSIZE 4920305 // v1.4 - 1.5 (Incl. OEM v1.4a)
#define D1_OEM_PIGSIZE 5039735 // v1.0
#define D1_MAC_PIGSIZE 3975533
#define D1_MAC_SHARE_PIGSIZE 2714487
#if defined(DXX_BUILD_DESCENT_II)
#define D1_PIGFILE "descent.pig"
2006-03-20 17:12:09 +00:00
#define MAX_ALIASES 20
struct alias
{
2006-03-20 17:12:09 +00:00
char alias_name[FILENAME_LEN];
char file_name[FILENAME_LEN];
};
2006-03-20 17:12:09 +00:00
2020-05-02 21:18:42 +00:00
extern std::array<alias, MAX_ALIASES> alias_list;
2015-02-14 22:48:27 +00:00
extern unsigned Num_aliases;
2006-03-20 17:12:09 +00:00
extern int Piggy_hamfile_version;
extern int Pigfile_initialized;
#endif
2006-03-20 17:12:09 +00:00
// an index into the bitmap collection of the piggy file
struct bitmap_index
{
2006-03-20 17:12:09 +00:00
ushort index;
2014-01-12 23:00:43 +00:00
};
2014-09-27 22:46:25 +00:00
#define DEFINE_BITMAP_SERIAL_UDT() DEFINE_SERIAL_UDT_TO_MESSAGE(bitmap_index, b, (b.index))
2006-03-20 17:12:09 +00:00
struct BitmapFile
{
2020-05-02 21:18:42 +00:00
std::array<char, 13> name;
};
2012-11-11 00:14:30 +00:00
#if defined(DXX_BUILD_DESCENT_I)
extern int MacPig;
extern int PCSharePig;
extern grs_bitmap bogus_bitmap;
#endif
2020-05-02 21:18:42 +00:00
extern std::array<uint8_t, 64 * 64> bogus_data;
2016-01-09 16:38:15 +00:00
#ifdef dsx
namespace dsx {
int properties_init();
2006-03-20 17:12:09 +00:00
void piggy_close();
bitmap_index piggy_register_bitmap(grs_bitmap &bmp, const char * name, int in_file);
int piggy_register_sound( digi_sound * snd, const char * name, int in_file );
2014-07-26 23:51:39 +00:00
bitmap_index piggy_find_bitmap(const char *name);
}
2014-07-26 23:51:39 +00:00
int piggy_find_sound(const char *name);
2006-03-20 17:12:09 +00:00
void piggy_read_bitmap_data(grs_bitmap * bmp);
namespace dsx {
2006-03-20 17:12:09 +00:00
void piggy_read_sound_data(digi_sound *snd);
}
2006-03-20 17:12:09 +00:00
void piggy_load_level_data();
#if defined(DXX_BUILD_DESCENT_I)
constexpr std::integral_constant<unsigned, 1800> MAX_BITMAP_FILES{};
#define PIGGY_PC_SHAREWARE 2
#elif defined(DXX_BUILD_DESCENT_II)
2016-07-14 01:59:05 +00:00
// Upped for CD Enhanced
constexpr std::integral_constant<unsigned, 2620> MAX_BITMAP_FILES{};
#endif
2018-10-21 00:24:07 +00:00
#define MAX_SOUND_FILES MAX_SOUNDS
2006-03-20 17:12:09 +00:00
namespace dsx {
extern void piggy_bitmap_page_in( bitmap_index bmp );
void piggy_bitmap_page_out_all();
2006-03-20 17:12:09 +00:00
2020-05-02 21:18:42 +00:00
using GameBitmaps_array = std::array<grs_bitmap, MAX_BITMAP_FILES>;
extern std::array<digi_sound, MAX_SOUND_FILES> GameSounds;
extern GameBitmaps_array GameBitmaps;
2006-03-20 17:12:09 +00:00
# define PIGGY_PAGE_IN(bmp) _piggy_page_in(bmp)
static inline void _piggy_page_in(bitmap_index bmp) {
2017-01-15 00:03:13 +00:00
if (GameBitmaps[bmp.index].get_flag_mask(BM_FLAG_PAGED_OUT))
{
2006-03-20 17:12:09 +00:00
piggy_bitmap_page_in( bmp );
}
}
#if defined(DXX_BUILD_DESCENT_I)
void piggy_read_sounds(int pc_shareware);
#elif defined(DXX_BUILD_DESCENT_II)
void piggy_init_pigfile(const char *filename);
void piggy_read_sounds(void);
2006-03-20 17:12:09 +00:00
//reads in a new pigfile (for new palette)
//returns the size of all the bitmap data
void piggy_new_pigfile(char *pigname);
//loads custom bitmaps for current level
void load_bitmap_replacements(const char *level_name);
2006-03-20 17:12:09 +00:00
//if descent.pig exists, loads descent 1 texture bitmaps
void load_d1_bitmap_replacements();
/*
* Find and load the named bitmap from descent.pig
*/
grs_bitmap *read_extra_bitmap_d1_pig(const char *name, grs_bitmap &out);
int read_hamfile();
void read_sndfile(int required);
#endif
}
namespace dcx {
2006-03-20 17:12:09 +00:00
/*
* reads a bitmap_index structure from a PHYSFS_File
2006-03-20 17:12:09 +00:00
*/
void bitmap_index_read(PHYSFS_File *fp, bitmap_index &bi);
void bitmap_index_read_n(PHYSFS_File *fp, partial_range_t<bitmap_index *> r);
}
2006-03-20 17:12:09 +00:00
extern void remove_char( char * s, char c ); // in piggy.c
#define REMOVE_EOL(s) remove_char((s),'\n')
#define REMOVE_COMMENTS(s) remove_char((s),';')
#define REMOVE_DOTS(s) remove_char((s),'.')
extern unsigned Num_bitmap_files;
2012-11-11 00:14:30 +00:00
extern int Num_sound_files;
extern ubyte bogus_bitmap_initialized;
namespace dsx {
extern digi_sound bogus_sound;
}
#endif
#define space_tab " \t"
#define equal_space " \t="
2012-11-11 00:14:30 +00:00
#if defined(DXX_BUILD_DESCENT_I)
2015-04-19 04:18:52 +00:00
#include "hash.h"
2012-11-11 00:14:30 +00:00
extern hashtable AllBitmapsNames;
extern hashtable AllDigiSndNames;
#elif defined(DXX_BUILD_DESCENT_II)
2020-05-02 21:18:42 +00:00
extern std::array<BitmapFile, MAX_BITMAP_FILES> AllBitmaps;
2012-11-11 00:14:30 +00:00
#endif
2016-11-19 17:24:52 +00:00
void swap_0_255(grs_bitmap &bmp);
enum class pig_bitmap_offset : unsigned
{
None = 0
};