Untangling ship queues, stage pre1: decoupling load/save funcs from the queues

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2776 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2007-06-21 05:21:00 +00:00
parent 454841d93f
commit 84a97dd63f
2 changed files with 107 additions and 64 deletions
+53 -34
View File
@@ -134,13 +134,11 @@ read_a16 (void *fp, UWORD *ar, COUNT count)
} }
static void static void
LoadShipQueue (DECODE_REF fh, QUEUE *pQueue, BOOLEAN MakeQ) LoadShipQueue (DECODE_REF fh, QUEUE *pQueue)
{ {
COUNT num_links; COUNT num_links;
cread_16 (fh, &num_links); cread_16 (fh, &num_links);
if (num_links && MakeQ)
InitQueue (pQueue, num_links, sizeof (SHIP_FRAGMENT));
while (num_links--) while (num_links--)
{ {
@@ -151,20 +149,13 @@ LoadShipQueue (DECODE_REF fh, QUEUE *pQueue, BOOLEAN MakeQ)
cread_16 (fh, &Index); cread_16 (fh, &Index);
if (pQueue == &GLOBAL (avail_race_q)) hStarShip = CloneShipFragment (Index, pQueue, 0);
hStarShip = GetStarShipFromIndex (pQueue, Index);
else
hStarShip = CloneShipFragment (Index, pQueue, 0);
FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip); FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip);
if (pQueue != &GLOBAL (avail_race_q)) // Read SHIP_FRAGMENT elements
{ // queues other than avail_race_q save SHIP_FRAGMENT elements cread_16 (fh, &FragPtr->s.Player);
// Read SHIP_FRAGMENT elements cread_8 (fh, &FragPtr->s.Captain);
cread_16 (fh, &FragPtr->s.Player); cread_8 (fh, NULL); /* padding */
cread_8 (fh, &FragPtr->s.Captain);
cread_8 (fh, NULL); /* padding */
}
// Read SHIP_INFO elements // Read SHIP_INFO elements
cread_16 (fh, &FragPtr->ShipInfo.ship_flags); cread_16 (fh, &FragPtr->ShipInfo.ship_flags);
cread_8 (fh, &FragPtr->ShipInfo.var1); cread_8 (fh, &FragPtr->ShipInfo.var1);
@@ -178,23 +169,51 @@ LoadShipQueue (DECODE_REF fh, QUEUE *pQueue, BOOLEAN MakeQ)
cread_16 (fh, &FragPtr->ShipInfo.loc.x); cread_16 (fh, &FragPtr->ShipInfo.loc.x);
cread_16 (fh, &FragPtr->ShipInfo.loc.y); cread_16 (fh, &FragPtr->ShipInfo.loc.y);
if (pQueue == &GLOBAL (avail_race_q)) UnlockStarShip (pQueue, hStarShip);
{ }
// avail_race_q contains information not about specific ships, }
// but about a race.
EXTENDED_SHIP_FRAGMENT *ExtFragPtr =
(EXTENDED_SHIP_FRAGMENT*) FragPtr;
cread_16 (fh, &ExtFragPtr->ShipInfo.actual_strength); static void
cread_16 (fh, &ExtFragPtr->ShipInfo.known_strength); LoadRaceQueue (DECODE_REF fh, QUEUE *pQueue)
cread_16 (fh, &ExtFragPtr->ShipInfo.known_loc.x); {
cread_16 (fh, &ExtFragPtr->ShipInfo.known_loc.y); COUNT num_links;
cread_8 (fh, &ExtFragPtr->ShipInfo.growth_err_term);
cread_8 (fh, &ExtFragPtr->ShipInfo.func_index); cread_16 (fh, &num_links);
cread_16 (fh, &ExtFragPtr->ShipInfo.dest_loc.x);
cread_16 (fh, &ExtFragPtr->ShipInfo.dest_loc.y); while (num_links--)
cread_16 (fh, NULL); /* alignment padding */ {
} HSTARSHIP hStarShip;
EXTENDED_SHIP_FRAGMENT *ExtFragPtr;
COUNT Index;
BYTE tmpb;
cread_16 (fh, &Index);
hStarShip = GetStarShipFromIndex (pQueue, Index);
ExtFragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (pQueue, hStarShip);
// Read EXTENDED_SHIP_INFO elements
cread_16 (fh, &ExtFragPtr->ShipInfo.ship_flags);
cread_8 (fh, &ExtFragPtr->ShipInfo.days_left);
cread_8 (fh, &ExtFragPtr->ShipInfo.growth_fract);
cread_8 (fh, &tmpb);
ExtFragPtr->ShipInfo.crew_level = tmpb;
cread_8 (fh, &tmpb);
ExtFragPtr->ShipInfo.max_crew = tmpb;
cread_8 (fh, &ExtFragPtr->ShipInfo.energy_level);
cread_8 (fh, &ExtFragPtr->ShipInfo.max_energy);
cread_16 (fh, &ExtFragPtr->ShipInfo.loc.x);
cread_16 (fh, &ExtFragPtr->ShipInfo.loc.y);
cread_16 (fh, &ExtFragPtr->ShipInfo.actual_strength);
cread_16 (fh, &ExtFragPtr->ShipInfo.known_strength);
cread_16 (fh, &ExtFragPtr->ShipInfo.known_loc.x);
cread_16 (fh, &ExtFragPtr->ShipInfo.known_loc.y);
cread_8 (fh, &ExtFragPtr->ShipInfo.growth_err_term);
cread_8 (fh, &ExtFragPtr->ShipInfo.func_index);
cread_16 (fh, &ExtFragPtr->ShipInfo.dest_loc.x);
cread_16 (fh, &ExtFragPtr->ShipInfo.dest_loc.y);
cread_16 (fh, NULL); /* alignment padding */
UnlockStarShip (pQueue, hStarShip); UnlockStarShip (pQueue, hStarShip);
} }
@@ -498,10 +517,10 @@ LoadGame (COUNT which_game, SUMMARY_DESC *SummPtr)
"save, Savegame may be corrupt!\n"); "save, Savegame may be corrupt!\n");
GLOBAL (GameClock.TimeCounter) = 0; GLOBAL (GameClock.TimeCounter) = 0;
LoadShipQueue (fh, &GLOBAL (avail_race_q), FALSE); LoadRaceQueue (fh, &GLOBAL (avail_race_q));
if (!(NextActivity & START_INTERPLANETARY)) if (!(NextActivity & START_INTERPLANETARY))
LoadShipQueue (fh, &GLOBAL (npc_built_ship_q), FALSE); LoadShipQueue (fh, &GLOBAL (npc_built_ship_q));
LoadShipQueue (fh, &GLOBAL (built_ship_q), FALSE); LoadShipQueue (fh, &GLOBAL (built_ship_q));
// Load the game events (compressed) // Load the game events (compressed)
cread_16 (fh, &num_links); cread_16 (fh, &num_links);
+54 -30
View File
@@ -129,23 +129,15 @@ SaveShipQueue (DECODE_REF fh, QUEUE *pQueue)
FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip); FragPtr = (SHIP_FRAGMENT*) LockStarShip (pQueue, hStarShip);
hNextShip = _GetSuccLink (FragPtr); hNextShip = _GetSuccLink (FragPtr);
if (pQueue == &GLOBAL (avail_race_q)) Index = GET_RACE_ID (FragPtr);
Index = GetIndexFromStarShip (pQueue, hStarShip);
// The index is the position in the queue.
else
Index = GET_RACE_ID (FragPtr);
// Write the number identifying this ship type. // Write the number identifying this ship type.
// See races.h; look for the enum containing NUM_AVAILABLE_RACES. // See races.h; look for the enum containing NUM_AVAILABLE_RACES.
cwrite_16 (fh, Index); cwrite_16 (fh, Index);
if (pQueue != &GLOBAL (avail_race_q)) // Write SHIP_FRAGMENT elements
{ // queues other than avail_race_q save SHIP_FRAGMENT elements cwrite_16 (fh, FragPtr->s.Player);
// Write SHIP_FRAGMENT elements cwrite_8 (fh, FragPtr->s.Captain);
cwrite_16 (fh, FragPtr->s.Player); cwrite_8 (fh, 0); /* padding */
cwrite_8 (fh, FragPtr->s.Captain);
cwrite_8 (fh, 0); /* padding */
}
// Write SHIP_INFO elements // Write SHIP_INFO elements
cwrite_16 (fh, FragPtr->ShipInfo.ship_flags); cwrite_16 (fh, FragPtr->ShipInfo.ship_flags);
cwrite_8 (fh, FragPtr->ShipInfo.var1); cwrite_8 (fh, FragPtr->ShipInfo.var1);
@@ -157,23 +149,55 @@ SaveShipQueue (DECODE_REF fh, QUEUE *pQueue)
cwrite_16 (fh, FragPtr->ShipInfo.loc.x); cwrite_16 (fh, FragPtr->ShipInfo.loc.x);
cwrite_16 (fh, FragPtr->ShipInfo.loc.y); cwrite_16 (fh, FragPtr->ShipInfo.loc.y);
if (pQueue == &GLOBAL (avail_race_q)) UnlockStarShip (pQueue, hStarShip);
{ hStarShip = hNextShip;
// avail_race_q contains information not about specific ships, }
// but about a race. }
EXTENDED_SHIP_FRAGMENT *ExtFragPtr =
(EXTENDED_SHIP_FRAGMENT*) FragPtr;
cwrite_16 (fh, ExtFragPtr->ShipInfo.actual_strength); static void
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_strength); SaveRaceQueue (DECODE_REF fh, QUEUE *pQueue)
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_loc.x); {
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_loc.y); COUNT num_links;
cwrite_8 (fh, ExtFragPtr->ShipInfo.growth_err_term); HSTARSHIP hStarShip;
cwrite_8 (fh, ExtFragPtr->ShipInfo.func_index);
cwrite_16 (fh, ExtFragPtr->ShipInfo.dest_loc.x); // Write the number of entries in the queue.
cwrite_16 (fh, ExtFragPtr->ShipInfo.dest_loc.y); num_links = CountLinks (pQueue);
cwrite_16 (fh, 0); /* alignment padding */ cwrite_16 (fh, num_links);
}
hStarShip = GetHeadLink (pQueue);
while (num_links--)
{
HSTARSHIP hNextShip;
EXTENDED_SHIP_FRAGMENT *ExtFragPtr;
COUNT Index;
ExtFragPtr = (EXTENDED_SHIP_FRAGMENT *) LockStarShip (pQueue, hStarShip);
hNextShip = _GetSuccLink (ExtFragPtr);
Index = GetIndexFromStarShip (pQueue, hStarShip);
// The index is the position in the queue.
cwrite_16 (fh, Index);
// Write EXTENDED_SHIP_INFO elements
cwrite_16 (fh, ExtFragPtr->ShipInfo.ship_flags);
cwrite_8 (fh, ExtFragPtr->ShipInfo.days_left);
cwrite_8 (fh, ExtFragPtr->ShipInfo.growth_fract);
cwrite_8 (fh, ExtFragPtr->ShipInfo.crew_level);
cwrite_8 (fh, ExtFragPtr->ShipInfo.max_crew);
cwrite_8 (fh, ExtFragPtr->ShipInfo.energy_level);
cwrite_8 (fh, ExtFragPtr->ShipInfo.max_energy);
cwrite_16 (fh, ExtFragPtr->ShipInfo.loc.x);
cwrite_16 (fh, ExtFragPtr->ShipInfo.loc.y);
cwrite_16 (fh, ExtFragPtr->ShipInfo.actual_strength);
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_strength);
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_loc.x);
cwrite_16 (fh, ExtFragPtr->ShipInfo.known_loc.y);
cwrite_8 (fh, ExtFragPtr->ShipInfo.growth_err_term);
cwrite_8 (fh, ExtFragPtr->ShipInfo.func_index);
cwrite_16 (fh, ExtFragPtr->ShipInfo.dest_loc.x);
cwrite_16 (fh, ExtFragPtr->ShipInfo.dest_loc.y);
cwrite_16 (fh, 0); /* alignment padding */
UnlockStarShip (pQueue, hStarShip); UnlockStarShip (pQueue, hStarShip);
hStarShip = hNextShip; hStarShip = hNextShip;
@@ -605,7 +629,7 @@ RetrySave:
// XXX: Restore: ShipStamp.frame is abused to store DWORD info // XXX: Restore: ShipStamp.frame is abused to store DWORD info
GLOBAL (ShipStamp.frame) = frame; GLOBAL (ShipStamp.frame) = frame;
SaveShipQueue (fh, &GLOBAL (avail_race_q)); SaveRaceQueue (fh, &GLOBAL (avail_race_q));
if (!(GLOBAL (CurrentActivity) & START_INTERPLANETARY)) if (!(GLOBAL (CurrentActivity) & START_INTERPLANETARY))
SaveShipQueue (fh, &GLOBAL (npc_built_ship_q)); SaveShipQueue (fh, &GLOBAL (npc_built_ship_q));
SaveShipQueue (fh, &GLOBAL (built_ship_q)); SaveShipQueue (fh, &GLOBAL (built_ship_q));