Read walls carefully
This commit is contained in:
parent
b3dc2a1bc0
commit
78143eb045
|
@ -133,7 +133,7 @@ struct v16_wall
|
|||
sbyte trigger; // Which trigger is associated with the wall.
|
||||
sbyte clip_num; // Which animation associated with the wall.
|
||||
sbyte keys;
|
||||
} __pack__;
|
||||
};
|
||||
|
||||
struct v19_wall
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ struct v19_wall
|
|||
sbyte clip_num; // Which animation associated with the wall.
|
||||
sbyte keys;
|
||||
int linked_wall; // number of linked wall
|
||||
} __pack__;
|
||||
};
|
||||
|
||||
//End old wall structures
|
||||
|
||||
|
@ -169,7 +169,7 @@ struct wall
|
|||
// Note: This gets stuffed at load time in gamemine.c. Don't try to use it in the editor. You will be sorry!
|
||||
sbyte cloak_value; // if this wall is cloaked, the fade value
|
||||
#endif
|
||||
} __pack__;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct active_door
|
||||
|
@ -339,22 +339,17 @@ void wclip_write(PHYSFS_file *, const wclip &);
|
|||
/*
|
||||
* reads a v16_wall structure from a PHYSFS_file
|
||||
*/
|
||||
extern void v16_wall_read(v16_wall *w, PHYSFS_file *fp);
|
||||
void v16_wall_read(PHYSFS_file *fp, v16_wall &w);
|
||||
|
||||
/*
|
||||
* reads a v19_wall structure from a PHYSFS_file
|
||||
*/
|
||||
extern void v19_wall_read(v19_wall *w, PHYSFS_file *fp);
|
||||
void v19_wall_read(PHYSFS_file *fp, v19_wall &w);
|
||||
|
||||
/*
|
||||
* reads a wall structure from a PHYSFS_file
|
||||
*/
|
||||
extern void wall_read(wall *w, PHYSFS_file *fp);
|
||||
|
||||
/*
|
||||
* reads n wall structs from a PHYSFS_file and swaps if specified
|
||||
*/
|
||||
extern void wall_read_n_swap(wall *w, int n, int swap, PHYSFS_file *fp);
|
||||
void wall_read(PHYSFS_file *fp, wall &w);
|
||||
|
||||
/*
|
||||
* reads an active_door structure from a PHYSFS_file
|
||||
|
@ -362,7 +357,7 @@ extern void wall_read_n_swap(wall *w, int n, int swap, PHYSFS_file *fp);
|
|||
void active_door_read(PHYSFS_file *fp, active_door &ad);
|
||||
void active_door_write(PHYSFS_file *fp, const active_door &ad);
|
||||
|
||||
extern void wall_write(wall *w, short version, PHYSFS_file *fp);
|
||||
void wall_write(PHYSFS_file *fp, const wall &w, short version);
|
||||
void wall_close_door_num(int door_num);
|
||||
void init_stuck_objects(void);
|
||||
void clear_stuck_objects(void);
|
||||
|
|
|
@ -899,10 +899,10 @@ static int load_game_data(PHYSFS_file *LoadFile)
|
|||
range_for (auto &nw, partial_range(Walls, Num_walls))
|
||||
{
|
||||
if (game_top_fileinfo_version >= 20)
|
||||
wall_read(&nw, LoadFile); // v20 walls and up.
|
||||
wall_read(LoadFile, nw); // v20 walls and up.
|
||||
else if (game_top_fileinfo_version >= 17) {
|
||||
v19_wall w;
|
||||
v19_wall_read(&w, LoadFile);
|
||||
v19_wall_read(LoadFile, w);
|
||||
nw.segnum = w.segnum;
|
||||
nw.sidenum = w.sidenum;
|
||||
nw.linked_wall = w.linked_wall;
|
||||
|
@ -919,7 +919,7 @@ static int load_game_data(PHYSFS_file *LoadFile)
|
|||
nw.state = WALL_DOOR_CLOSED;
|
||||
} else {
|
||||
v16_wall w;
|
||||
v16_wall_read(&w, LoadFile);
|
||||
v16_wall_read(LoadFile, w);
|
||||
nw.segnum = segment_none;
|
||||
nw.sidenum = nw.linked_wall = -1;
|
||||
nw.type = w.type;
|
||||
|
@ -1596,7 +1596,7 @@ static int save_game_data(PHYSFS_file *SaveFile)
|
|||
|
||||
walls_offset = PHYSFS_tell(SaveFile);
|
||||
range_for (auto &w, partial_range(Walls, Num_walls))
|
||||
wall_write(&w, game_top_fileinfo_version, SaveFile);
|
||||
wall_write(SaveFile, w, game_top_fileinfo_version);
|
||||
|
||||
//==================== SAVE TRIGGER INFO =============================
|
||||
|
||||
|
|
|
@ -1165,7 +1165,7 @@ int state_save_all_sub(const char *filename, const char *desc)
|
|||
i = Num_walls;
|
||||
PHYSFS_write(fp, &i, sizeof(int), 1);
|
||||
range_for (auto &w, partial_range(Walls, Num_walls))
|
||||
PHYSFS_write(fp, &w, sizeof(w), 1);
|
||||
wall_write(fp, w, 0x7fff);
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
//Save exploding wall info
|
||||
|
@ -1638,7 +1638,7 @@ int state_restore_all_sub(const char *filename, int secret_restore)
|
|||
//Restore wall info
|
||||
Num_walls = PHYSFSX_readSXE32(fp, swap);
|
||||
range_for (auto &w, partial_range(Walls, Num_walls))
|
||||
wall_read_n_swap(&w, 1, swap, fp);
|
||||
wall_read(fp, w);
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
//now that we have the walls, check if any sounds are linked to
|
||||
|
|
|
@ -1755,84 +1755,59 @@ void wclip_write(PHYSFS_file *fp, const wclip &wc)
|
|||
PHYSFSX_serialize_write(fp, wc);
|
||||
}
|
||||
|
||||
struct wrap_v16_wall
|
||||
{
|
||||
const wall *w;
|
||||
wrap_v16_wall(const wall &t) : w(&t) {}
|
||||
};
|
||||
|
||||
#define _SERIAL_UDT_WALL_V16_MEMBERS(P) (P type, P flags, P hps, P trigger, P clip_num, P keys)
|
||||
|
||||
DEFINE_SERIAL_UDT_TO_MESSAGE(v16_wall, w, _SERIAL_UDT_WALL_V16_MEMBERS(w.));
|
||||
DEFINE_SERIAL_UDT_TO_MESSAGE(wrap_v16_wall, w, _SERIAL_UDT_WALL_V16_MEMBERS(w.w->));
|
||||
ASSERT_SERIAL_UDT_MESSAGE_SIZE(wrap_v16_wall, 9);
|
||||
|
||||
/*
|
||||
* reads a v16_wall structure from a PHYSFS_file
|
||||
*/
|
||||
void v16_wall_read(v16_wall *w, PHYSFS_file *fp)
|
||||
void v16_wall_read(PHYSFS_file *fp, v16_wall &w)
|
||||
{
|
||||
w->type = PHYSFSX_readByte(fp);
|
||||
w->flags = PHYSFSX_readByte(fp);
|
||||
w->hps = PHYSFSX_readFix(fp);
|
||||
w->trigger = PHYSFSX_readByte(fp);
|
||||
w->clip_num = PHYSFSX_readByte(fp);
|
||||
w->keys = PHYSFSX_readByte(fp);
|
||||
PHYSFSX_serialize_read(fp, w);
|
||||
}
|
||||
|
||||
struct wrap_v19_wall
|
||||
{
|
||||
const wall *w;
|
||||
wrap_v19_wall(const wall &t) : w(&t) {}
|
||||
};
|
||||
|
||||
DEFINE_SERIAL_UDT_TO_MESSAGE(v19_wall, w, (w.segnum, w.sidenum, w.type, w.flags, w.hps, w.trigger, w.clip_num, w.keys, w.linked_wall));
|
||||
DEFINE_SERIAL_UDT_TO_MESSAGE(wrap_v19_wall, w, (w.w->segnum, serial::pad<2>(), w.w->sidenum, w.w->type, w.w->flags, w.w->hps, w.w->trigger, w.w->clip_num, w.w->keys, w.w->linked_wall));
|
||||
ASSERT_SERIAL_UDT_MESSAGE_SIZE(v19_wall, 21);
|
||||
ASSERT_SERIAL_UDT_MESSAGE_SIZE(wrap_v19_wall, 21);
|
||||
|
||||
/*
|
||||
* reads a v19_wall structure from a PHYSFS_file
|
||||
*/
|
||||
void v19_wall_read(v19_wall *w, PHYSFS_file *fp)
|
||||
void v19_wall_read(PHYSFS_file *fp, v19_wall &w)
|
||||
{
|
||||
w->segnum = PHYSFSX_readInt(fp);
|
||||
w->sidenum = PHYSFSX_readInt(fp);
|
||||
w->type = PHYSFSX_readByte(fp);
|
||||
w->flags = PHYSFSX_readByte(fp);
|
||||
w->hps = PHYSFSX_readFix(fp);
|
||||
w->trigger = PHYSFSX_readByte(fp);
|
||||
w->clip_num = PHYSFSX_readByte(fp);
|
||||
w->keys = PHYSFSX_readByte(fp);
|
||||
w->linked_wall = PHYSFSX_readInt(fp);
|
||||
PHYSFSX_serialize_read(fp, w);
|
||||
}
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
#define _SERIAL_UDT_WALL_D2X_MEMBERS serial::pad<2>()
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
#define _SERIAL_UDT_WALL_D2X_MEMBERS w.controlling_trigger, w.cloak_value
|
||||
#endif
|
||||
DEFINE_SERIAL_UDT_TO_MESSAGE(wall, w, (w.segnum, serial::pad<2>(), w.sidenum, w.hps, w.linked_wall, w.type, w.flags, w.state, w.trigger, w.clip_num, w.keys, _SERIAL_UDT_WALL_D2X_MEMBERS));
|
||||
ASSERT_SERIAL_UDT_MESSAGE_SIZE(wall, 24);
|
||||
|
||||
/*
|
||||
* reads a wall structure from a PHYSFS_file
|
||||
*/
|
||||
void wall_read(wall *w, PHYSFS_file *fp)
|
||||
void wall_read(PHYSFS_file *fp, wall &w)
|
||||
{
|
||||
w->segnum = PHYSFSX_readInt(fp);
|
||||
w->sidenum = PHYSFSX_readInt(fp);
|
||||
w->hps = PHYSFSX_readFix(fp);
|
||||
w->linked_wall = PHYSFSX_readInt(fp);
|
||||
w->type = PHYSFSX_readByte(fp);
|
||||
w->flags = PHYSFSX_readByte(fp);
|
||||
w->state = PHYSFSX_readByte(fp);
|
||||
w->trigger = PHYSFSX_readByte(fp);
|
||||
w->clip_num = PHYSFSX_readByte(fp);
|
||||
w->keys = PHYSFSX_readByte(fp);
|
||||
sbyte controlling_trigger = PHYSFSX_readByte(fp);
|
||||
sbyte cloak_value = PHYSFSX_readByte(fp);
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
(void)controlling_trigger;
|
||||
(void)cloak_value;
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
w->controlling_trigger = controlling_trigger;
|
||||
w->cloak_value = cloak_value;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void wall_swap(wall *w, int swap)
|
||||
{
|
||||
if (!swap)
|
||||
return;
|
||||
|
||||
w->segnum = SWAPSHORT(w->segnum);
|
||||
w->sidenum = SWAPINT(w->sidenum);
|
||||
w->hps = SWAPINT(w->hps);
|
||||
w->linked_wall = SWAPINT(w->linked_wall);
|
||||
}
|
||||
|
||||
/*
|
||||
* reads n wall structs from a PHYSFS_file and swaps if specified
|
||||
*/
|
||||
void wall_read_n_swap(wall *w, int n, int swap, PHYSFS_file *fp)
|
||||
{
|
||||
int i;
|
||||
|
||||
PHYSFS_read(fp, w, sizeof(wall), n);
|
||||
|
||||
if (swap)
|
||||
for (i = 0; i < n; i++)
|
||||
wall_swap(&w[i], swap);
|
||||
PHYSFSX_serialize_read(fp, w);
|
||||
}
|
||||
|
||||
DEFINE_SERIAL_UDT_TO_MESSAGE(active_door, d, (d.n_parts, d.front_wallnum, d.back_wallnum, d.time));
|
||||
|
@ -1851,48 +1826,14 @@ void active_door_write(PHYSFS_file *fp, const active_door &ad)
|
|||
PHYSFSX_serialize_write(fp, ad);
|
||||
}
|
||||
|
||||
void wall_write(wall *w, short version, PHYSFS_file *fp)
|
||||
void wall_write(PHYSFS_file *fp, const wall &w, short version)
|
||||
{
|
||||
if (version >= 17)
|
||||
{
|
||||
PHYSFS_writeSLE32(fp, w->segnum);
|
||||
PHYSFS_writeSLE32(fp, w->sidenum);
|
||||
}
|
||||
|
||||
if (version >= 20)
|
||||
{
|
||||
PHYSFSX_writeFix(fp, w->hps);
|
||||
PHYSFS_writeSLE32(fp, w->linked_wall);
|
||||
}
|
||||
|
||||
PHYSFSX_writeU8(fp, w->type);
|
||||
PHYSFSX_writeU8(fp, w->flags);
|
||||
|
||||
if (version < 20)
|
||||
PHYSFSX_writeFix(fp, w->hps);
|
||||
if (version <= 16)
|
||||
PHYSFSX_serialize_write<wrap_v16_wall>(fp, w);
|
||||
else if (version <= 19)
|
||||
PHYSFSX_serialize_write<wrap_v19_wall>(fp, w);
|
||||
else
|
||||
PHYSFSX_writeU8(fp, w->state);
|
||||
|
||||
PHYSFSX_writeU8(fp, w->trigger);
|
||||
PHYSFSX_writeU8(fp, w->clip_num);
|
||||
PHYSFSX_writeU8(fp, w->keys);
|
||||
|
||||
if (version >= 20)
|
||||
{
|
||||
sbyte controlling_trigger;
|
||||
sbyte cloak_value;
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
controlling_trigger = 0;
|
||||
cloak_value = 0;
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
controlling_trigger = w->controlling_trigger;
|
||||
cloak_value = w->cloak_value;
|
||||
#endif
|
||||
PHYSFSX_writeU8(fp, controlling_trigger);
|
||||
PHYSFSX_writeU8(fp, cloak_value);
|
||||
}
|
||||
else if (version >= 17)
|
||||
PHYSFS_writeSLE32(fp, w->linked_wall);
|
||||
PHYSFSX_serialize_write(fp, w);
|
||||
}
|
||||
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
|
|
Loading…
Reference in a new issue