Output bytes now track field sizes.

This removes the clumsy local variable pointer stuff.
This commit is contained in:
Michael Martin
2013-10-09 00:34:35 -07:00
parent 876daf0827
commit eca23397c3
3 changed files with 25 additions and 33 deletions
+11 -19
View File
@@ -152,7 +152,6 @@ LoadShipQueue (void *fh, QUEUE *pQueue)
HSHIPFRAG hStarShip;
SHIP_FRAGMENT *FragPtr;
COUNT Index;
BYTE tmpb;
read_16 (fh, &Index);
@@ -184,7 +183,6 @@ LoadRaceQueue (void *fh, QUEUE *pQueue)
HFLEETINFO hStarShip;
FLEET_INFO *FleetPtr;
COUNT Index;
BYTE tmpb;
read_16 (fh, &Index);
@@ -195,10 +193,8 @@ LoadRaceQueue (void *fh, QUEUE *pQueue)
read_16 (fh, &FleetPtr->allied_state);
read_8 (fh, &FleetPtr->days_left);
read_8 (fh, &FleetPtr->growth_fract);
read_8 (fh, &tmpb);
FleetPtr->crew_level = tmpb;
read_8 (fh, &tmpb);
FleetPtr->max_crew = tmpb;
read_16 (fh, &FleetPtr->crew_level);
read_16 (fh, &FleetPtr->max_crew);
read_8 (fh, &FleetPtr->growth);
read_8 (fh, &FleetPtr->max_energy);
read_16s(fh, &FleetPtr->loc.x);
@@ -228,20 +224,17 @@ LoadGroupQueue (void *fh, QUEUE *pQueue)
{
HIPGROUP hGroup;
IP_GROUP *GroupPtr;
BYTE tmpb;
hGroup = BuildGroup (pQueue, 0);
GroupPtr = LockIpGroup (pQueue, hGroup);
read_16 (fh, &GroupPtr->group_counter);
read_8 (fh, &GroupPtr->race_id);
read_8 (fh, &tmpb); /* was var2 */
GroupPtr->sys_loc = LONIBBLE (tmpb);
GroupPtr->task = HINIBBLE (tmpb);
read_8 (fh, &GroupPtr->sys_loc);
read_8 (fh, &GroupPtr->task);
read_8 (fh, &GroupPtr->in_system); /* was crew_level */
read_8 (fh, &tmpb); /* was energy_level */
GroupPtr->dest_loc = LONIBBLE (tmpb);
GroupPtr->orbit_pos = HINIBBLE (tmpb);
read_8 (fh, &GroupPtr->dest_loc);
read_8 (fh, &GroupPtr->orbit_pos);
read_8 (fh, &GroupPtr->group_id); /* was max_energy */
read_16s(fh, &GroupPtr->loc.x);
read_16s(fh, &GroupPtr->loc.y);
@@ -254,7 +247,6 @@ static void
LoadEncounter (ENCOUNTER *EncounterPtr, void *fh)
{
COUNT i;
BYTE tmpb;
EncounterPtr->pred = 0;
EncounterPtr->succ = 0;
@@ -378,11 +370,11 @@ LoadSummary (SUMMARY_DESC *SummPtr, void *fp)
DWORD nameSize = 0;
if (!read_32s (fp, &magic))
return FALSE;
if (magic == SAVE_MAGIC)
if (magic == SAVEFILE_TAG)
{
if (read_32 (fp, &magic) != 1 || magic != SUMMARY_MAGIC)
if (read_32 (fp, &magic) != 1 || magic != SUMMARY_TAG)
return FALSE;
if (read_32 (fp, &magic) != 1 || magic < 161)
if (read_32 (fp, &magic) != 1 || magic < 160)
return FALSE;
nameSize = magic - 160;
}
@@ -475,7 +467,7 @@ LoadGame (COUNT which_game, SUMMARY_DESC *SummPtr)
GlobData.SIS_state = SummPtr->SS;
chunk = 0;
while (chunk != OMNIBUS_MAGIC)
while (chunk != OMNIBUS_TAG)
{
if (read_32(in_fp, &chunk) != 1)
{
@@ -487,7 +479,7 @@ LoadGame (COUNT which_game, SUMMARY_DESC *SummPtr)
res_CloseResFile (in_fp);
return FALSE;
}
if (chunk == OMNIBUS_MAGIC)
if (chunk == OMNIBUS_TAG)
break;
log_add (log_Debug, "Skipping chunk of tag %08X (size %u)", chunk, chunkSize);
+9 -11
View File
@@ -212,8 +212,8 @@ SaveRaceQueue (SAVEBUF *fh, QUEUE *pQueue)
cwrite_16 (fh, FleetPtr->allied_state);
cwrite_8 (fh, FleetPtr->days_left);
cwrite_8 (fh, FleetPtr->growth_fract);
cwrite_8 (fh, FleetPtr->crew_level);
cwrite_8 (fh, FleetPtr->max_crew);
cwrite_16 (fh, FleetPtr->crew_level);
cwrite_16 (fh, FleetPtr->max_crew);
cwrite_8 (fh, FleetPtr->growth);
cwrite_8 (fh, FleetPtr->max_energy);
cwrite_16 (fh, FleetPtr->loc.x);
@@ -250,13 +250,11 @@ SaveGroupQueue (SAVEBUF *fh, QUEUE *pQueue)
cwrite_16 (fh, GroupPtr->group_counter);
cwrite_8 (fh, GroupPtr->race_id);
assert (GroupPtr->sys_loc < 0x10 && GroupPtr->task < 0x10);
cwrite_8 (fh, MAKE_BYTE (GroupPtr->sys_loc, GroupPtr->task));
/* was var2 */
cwrite_8 (fh, GroupPtr->sys_loc);
cwrite_8 (fh, GroupPtr->task);
cwrite_8 (fh, GroupPtr->in_system); /* was crew_level */
assert (GroupPtr->dest_loc < 0x10 && GroupPtr->orbit_pos < 0x10);
cwrite_8 (fh, MAKE_BYTE (GroupPtr->dest_loc, GroupPtr->orbit_pos));
/* was energy_level */
cwrite_8 (fh, GroupPtr->dest_loc);
cwrite_8 (fh, GroupPtr->orbit_pos);
cwrite_8 (fh, GroupPtr->group_id); /* was max_energy */
cwrite_16 (fh, GroupPtr->loc.x);
cwrite_16 (fh, GroupPtr->loc.y);
@@ -385,8 +383,8 @@ static BOOLEAN
SaveSummary (const SUMMARY_DESC *SummPtr, void *fp)
{
if (
write_32 (fp, SAVE_MAGIC) != 1 ||
write_32 (fp, SUMMARY_MAGIC) != 1 ||
write_32 (fp, SAVEFILE_TAG) != 1 ||
write_32 (fp, SUMMARY_TAG) != 1 ||
write_32 (fp, 160 + strlen(SummPtr->SaveName)) != 1
)
return FALSE;
@@ -773,7 +771,7 @@ SaveGame (COUNT which_game, SUMMARY_DESC *SummPtr, const char *name)
success = SaveSummary (SummPtr, out_fp);
// Then write the rest of the data.
if (success && write_32 (out_fp, OMNIBUS_MAGIC) != 1)
if (success && write_32 (out_fp, OMNIBUS_TAG) != 1)
success = FALSE;
if (success && write_32 (out_fp, flen) != 1)
success = FALSE;
+5 -3
View File
@@ -31,11 +31,13 @@ extern "C" {
// is only used for displaying savegame summaries. There is also
// room for only 16 devices on screen.
#define MAX_EXCLUSIVE_DEVICES 16
#define SAVE_MAGIC 0x01534d55 // "UMS\x01": UQM Save version 1
#define SUMMARY_MAGIC 0x6d6d7553 // "Summ": Summary. Must be first!
#define OMNIBUS_MAGIC 0x696e6d4f // "Omni": All data, uncompressed
#define SAVE_NAME_SIZE 64
// The savefile tag numbers.
#define SAVEFILE_TAG 0x01534d55 // "UMS\x01": UQM Save version 1
#define OMNIBUS_TAG 0x696e6d4f // "Omni": All data, uncompressed
#define SUMMARY_TAG 0x6d6d7553 // "Summ": Summary. Must be first!
typedef struct
{
SIS_STATE SS;