From 7888c13b6bf9a986eb3030a5a9d6f48fbb8a0dc0 Mon Sep 17 00:00:00 2001 From: Kp Date: Tue, 12 Aug 2014 02:55:23 +0000 Subject: [PATCH] Write point_seg carefully --- common/main/aistruct.h | 5 +++-- similar/main/ai.cpp | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/main/aistruct.h b/common/main/aistruct.h index 4cf1c9d84..83a03e951 100644 --- a/common/main/aistruct.h +++ b/common/main/aistruct.h @@ -29,6 +29,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifndef _AISTRUCT_H #define _AISTRUCT_H +#include #include "polyobj.h" #ifdef __cplusplus @@ -308,7 +309,7 @@ struct ai_cloak_info_rw }; #endif -struct point_seg { +struct point_seg : prohibit_void_ptr { int segnum; vms_vector point; }; @@ -318,7 +319,7 @@ struct seg_seg short start, end; }; -#define MAX_POINT_SEGS 2500 +static const unsigned MAX_POINT_SEGS = 2500; // These are the information for a robot describing the location of // the player last time he wasn't cloaked, and the time at which he diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index 5cbf03287..6f7b95c21 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -41,6 +41,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "laser.h" #include "fvi.h" #include "physfsx.h" +#include "physfs-serial.h" #include "polyobj.h" #include "bm.h" #include "weapon.h" @@ -4461,6 +4462,13 @@ static void state_ai_cloak_info_to_ai_cloak_info_rw(ai_cloak_info *aic, ai_cloak aic_rw->last_position.z = aic->last_position.z; } +DEFINE_SERIAL_VMS_VECTOR_TO_MESSAGE(); +DEFINE_SERIAL_UDT_TO_MESSAGE(point_seg, p, (p.segnum, p.point)); +ASSERT_SERIAL_UDT_MESSAGE_SIZE(point_seg, 16); + +DEFINE_SERIAL_MUTABLE_UDT_TO_MESSAGE(point_seg_array_t, p, (static_cast &>(p))); +DEFINE_SERIAL_CONST_UDT_TO_MESSAGE(point_seg_array_t, p, (static_cast &>(p))); + int ai_save_state(PHYSFS_file *fp) { int i = 0; @@ -4475,7 +4483,7 @@ int ai_save_state(PHYSFS_file *fp) state_ai_local_to_ai_local_rw(ailp, &ail_rw); PHYSFS_write(fp, &ail_rw, sizeof(ail_rw), 1); } - PHYSFS_write(fp, Point_segs, sizeof(point_seg), MAX_POINT_SEGS); + PHYSFSX_serialize_write(fp, Point_segs); //PHYSFS_write(fp, Ai_cloak_info, sizeof(ai_cloak_info) * MAX_AI_CLOAK_INFO, 1); for (i = 0; i < MAX_AI_CLOAK_INFO; i++) { @@ -4615,15 +4623,6 @@ static void ai_local_read_swap(ai_local *ail, int swap, PHYSFS_file *fp) } } -static void point_seg_read_swap(point_seg_array_t &psa, int swap, PHYSFS_file *fp) -{ - range_for (auto &ps, psa) - { - ps.segnum = PHYSFSX_readSXE32(fp, swap); - PHYSFSX_readVectorX(fp, &ps.point, swap); - } -} - static void ai_cloak_info_read_n_swap(ai_cloak_info *ci, int n, int swap, PHYSFS_file *fp) { int i; @@ -4648,7 +4647,7 @@ int ai_restore_state(PHYSFS_file *fp, int version, int swap) Overall_agitation = PHYSFSX_readSXE32(fp, swap); range_for (object &obj, Objects) ai_local_read_swap(&obj.ctype.ai_info.ail, swap, fp); - point_seg_read_swap(Point_segs, swap, fp); + PHYSFSX_serialize_read(fp, Point_segs); ai_cloak_info_read_n_swap(Ai_cloak_info, MAX_AI_CLOAK_INFO, swap, fp); tmptime32 = PHYSFSX_readSXE32(fp, swap); Boss_cloak_start_time = (fix64)tmptime32;