2014-06-01 17:55:23 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2014-06-01 17:55:23 +00:00
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Segment Loading Stuff
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "segment.h"
|
2014-07-20 01:09:55 +00:00
|
|
|
#include "physfsx.h"
|
2014-10-04 17:33:25 +00:00
|
|
|
#include "physfs-serial.h"
|
2021-11-01 03:37:19 +00:00
|
|
|
#include "d_underlying_value.h"
|
2014-10-04 17:33:25 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-13 18:00:48 +00:00
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct composite_side
|
|
|
|
{
|
|
|
|
const shared_side &sside;
|
|
|
|
const unique_side &uside;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_SERIAL_UDT_TO_MESSAGE(composite_side, s, (s.sside.wall_num, s.uside.tmap_num, s.uside.tmap_num2));
|
|
|
|
ASSERT_SERIAL_UDT_MESSAGE_SIZE(composite_side, 6);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:48:09 +00:00
|
|
|
std::optional<sidenum_t> build_sidenum_from_untrusted(const uint8_t untrusted)
|
|
|
|
{
|
|
|
|
switch (untrusted)
|
|
|
|
{
|
|
|
|
case static_cast<uint8_t>(sidenum_t::WLEFT):
|
|
|
|
case static_cast<uint8_t>(sidenum_t::WTOP):
|
|
|
|
case static_cast<uint8_t>(sidenum_t::WRIGHT):
|
|
|
|
case static_cast<uint8_t>(sidenum_t::WBOTTOM):
|
|
|
|
case static_cast<uint8_t>(sidenum_t::WBACK):
|
|
|
|
case static_cast<uint8_t>(sidenum_t::WFRONT):
|
|
|
|
return sidenum_t{untrusted};
|
|
|
|
default:
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
void segment_side_wall_tmap_write(PHYSFS_File *fp, const shared_side &sside, const unique_side &uside)
|
2014-10-04 17:33:25 +00:00
|
|
|
{
|
2018-06-24 05:06:15 +00:00
|
|
|
PHYSFSX_serialize_write(fp, composite_side{sside, uside});
|
2014-10-04 17:33:25 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-13 18:00:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-04 17:53:09 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dsx {
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
/*
|
2016-01-09 16:38:14 +00:00
|
|
|
* reads a delta_light structure from a PHYSFS_File
|
2006-03-20 17:12:09 +00:00
|
|
|
*/
|
2016-01-09 16:38:14 +00:00
|
|
|
void delta_light_read(delta_light *dl, PHYSFS_File *fp)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-06-01 07:59:55 +00:00
|
|
|
dl->segnum = PHYSFSX_readShort(fp);
|
2022-01-15 20:39:10 +00:00
|
|
|
dl->sidenum = build_sidenum_from_untrusted(PHYSFSX_readByte(fp)).value_or(sidenum_t::WLEFT);
|
2015-02-28 19:36:01 +00:00
|
|
|
PHYSFSX_readByte(fp);
|
2022-01-15 20:39:10 +00:00
|
|
|
dl->vert_light[side_relative_vertnum::_0] = PHYSFSX_readByte(fp);
|
|
|
|
dl->vert_light[side_relative_vertnum::_1] = PHYSFSX_readByte(fp);
|
|
|
|
dl->vert_light[side_relative_vertnum::_2] = PHYSFSX_readByte(fp);
|
|
|
|
dl->vert_light[side_relative_vertnum::_3] = PHYSFSX_readByte(fp);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2016-01-09 16:38:14 +00:00
|
|
|
* reads a dl_index structure from a PHYSFS_File
|
2006-03-20 17:12:09 +00:00
|
|
|
*/
|
2016-01-09 16:38:14 +00:00
|
|
|
void dl_index_read(dl_index *di, PHYSFS_File *fp)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-06-01 07:59:55 +00:00
|
|
|
di->segnum = PHYSFSX_readShort(fp);
|
|
|
|
di->sidenum = PHYSFSX_readByte(fp);
|
|
|
|
di->count = PHYSFSX_readByte(fp);
|
|
|
|
di->index = PHYSFSX_readShort(fp);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 05:34:08 +00:00
|
|
|
void segment2_write(const cscusegment s2, PHYSFS_File *fp)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2021-11-01 03:37:19 +00:00
|
|
|
PHYSFSX_writeU8(fp, underlying_value(s2.s.special));
|
2021-11-01 03:37:20 +00:00
|
|
|
PHYSFSX_writeU8(fp, underlying_value(s2.s.matcen_num));
|
2021-11-01 03:37:20 +00:00
|
|
|
PHYSFSX_writeU8(fp, underlying_value(s2.s.station_idx));
|
2019-12-22 05:34:08 +00:00
|
|
|
PHYSFSX_writeU8(fp, s2.s.s2_flags);
|
|
|
|
PHYSFSX_writeFix(fp, s2.u.static_light);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 04:02:28 +00:00
|
|
|
void delta_light_write(const delta_light *dl, PHYSFS_File *fp)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
PHYSFS_writeSLE16(fp, dl->segnum);
|
|
|
|
PHYSFSX_writeU8(fp, dl->sidenum);
|
2015-02-28 19:36:01 +00:00
|
|
|
PHYSFSX_writeU8(fp, 0);
|
2022-01-15 20:39:10 +00:00
|
|
|
PHYSFSX_writeU8(fp, dl->vert_light[side_relative_vertnum::_0]);
|
|
|
|
PHYSFSX_writeU8(fp, dl->vert_light[side_relative_vertnum::_1]);
|
|
|
|
PHYSFSX_writeU8(fp, dl->vert_light[side_relative_vertnum::_2]);
|
|
|
|
PHYSFSX_writeU8(fp, dl->vert_light[side_relative_vertnum::_3]);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 04:02:28 +00:00
|
|
|
void dl_index_write(const dl_index *di, PHYSFS_File *fp)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
PHYSFS_writeSLE16(fp, di->segnum);
|
|
|
|
PHYSFSX_writeU8(fp, di->sidenum);
|
|
|
|
PHYSFSX_writeU8(fp, di->count);
|
|
|
|
PHYSFS_writeSLE16(fp, di->index);
|
|
|
|
}
|
2015-12-13 18:00:48 +00:00
|
|
|
|
|
|
|
}
|
2014-10-04 17:53:09 +00:00
|
|
|
#endif
|