Game-state file I/O is now entirely in memory instead of temp files

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1932 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2005-10-31 14:06:48 +00:00
parent 85237d4b05
commit 2884b11542
5 changed files with 294 additions and 94 deletions
+44 -44
View File
@@ -45,7 +45,7 @@ InitGroupInfo (BOOLEAN FirstTime)
{
PVOID fp;
fp = res_OpenResFile (tempDir, RANDGRPINFO_FILE, "wb");
fp = OpenStateFile (RANDGRPINFO_FILE, "wb");
if (fp)
{
GROUP_HEADER GH;
@@ -53,24 +53,24 @@ InitGroupInfo (BOOLEAN FirstTime)
GH.NumGroups = 0;
GH.star_index = (COUNT)~0;
GH.GroupOffset[0] = 0;
WriteResFile (&GH, sizeof (GH), 1, fp);
WriteStateFile (&GH, sizeof (GH), 1, fp);
res_CloseResFile (fp);
CloseStateFile (fp);
}
if (FirstTime && (fp = res_OpenResFile (tempDir, DEFGRPINFO_FILE, "wb")))
if (FirstTime && (fp = OpenStateFile (DEFGRPINFO_FILE, "wb")))
{
PutResFileChar (0, fp);
PutStateFileChar (0, fp);
res_CloseResFile (fp);
CloseStateFile (fp);
}
}
void
UninitGroupInfo (void)
{
unlink (tempFilePath (DEFGRPINFO_FILE));
unlink (tempFilePath (RANDGRPINFO_FILE));
DeleteStateFile (DEFGRPINFO_FILE);
DeleteStateFile (RANDGRPINFO_FILE);
}
void
@@ -249,7 +249,7 @@ FlushGroupInfo (GROUP_HEADER *pGH, DWORD offset, BYTE which_group, PVOID fp)
if (which_group == 0)
{
if (pGH->GroupOffset[0] == 0)
pGH->GroupOffset[0] = LengthResFile (fp);
pGH->GroupOffset[0] = LengthStateFile (fp);
{
QUEUE temp_q;
@@ -291,18 +291,18 @@ FlushGroupInfo (GROUP_HEADER *pGH, DWORD offset, BYTE which_group, PVOID fp)
else if (which_group > pGH->NumGroups)
{
pGH->NumGroups = which_group;
pGH->GroupOffset[which_group] = LengthResFile (fp);
pGH->GroupOffset[which_group] = LengthStateFile (fp);
hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
FragPtr = (SHIP_FRAGMENTPTR)LockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip);
RaceType = GET_RACE_ID (FragPtr);
SeekResFile (fp, pGH->GroupOffset[which_group], SEEK_SET);
WriteResFile ((PBYTE)&RaceType, sizeof (RaceType), 1, fp);
SeekStateFile (fp, pGH->GroupOffset[which_group], SEEK_SET);
WriteStateFile ((PBYTE)&RaceType, sizeof (RaceType), 1, fp);
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
}
SeekResFile (fp, offset, SEEK_SET);
WriteResFile (pGH, sizeof (*pGH), 1, fp);
SeekStateFile (fp, offset, SEEK_SET);
WriteStateFile (pGH, sizeof (*pGH), 1, fp);
#ifdef DEBUG_GROUPS
fprintf (stderr, "1)FlushGroupInfo(%lu): WG = %u(%lu), NG = %u, "
"SI = %u\n", offset, which_group, pGH->GroupOffset[which_group],
@@ -312,15 +312,15 @@ FlushGroupInfo (GROUP_HEADER *pGH, DWORD offset, BYTE which_group, PVOID fp)
NumShips = (BYTE)CountLinks (&GLOBAL (npc_built_ship_q));
if (which_group)
SeekResFile (fp, pGH->GroupOffset[which_group]
SeekStateFile (fp, pGH->GroupOffset[which_group]
+ sizeof (RaceType), SEEK_SET);
else
{
RaceType = (BYTE)cur_player;
SeekResFile (fp, pGH->GroupOffset[0], SEEK_SET);
WriteResFile (&RaceType, sizeof (RaceType), 1, fp);
SeekStateFile (fp, pGH->GroupOffset[0], SEEK_SET);
WriteStateFile (&RaceType, sizeof (RaceType), 1, fp);
}
WriteResFile (&NumShips, sizeof (NumShips), 1, fp);
WriteStateFile (&NumShips, sizeof (NumShips), 1, fp);
hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q));
while (NumShips--)
@@ -334,7 +334,7 @@ FlushGroupInfo (GROUP_HEADER *pGH, DWORD offset, BYTE which_group, PVOID fp)
hNextShip = _GetSuccLink (FragPtr);
RaceType = GET_RACE_ID (FragPtr);
WriteResFile ((PBYTE)&RaceType, sizeof (RaceType), 1, fp);
WriteStateFile ((PBYTE)&RaceType, sizeof (RaceType), 1, fp);
#ifdef DEBUG_GROUPS
if (which_group == 0)
@@ -347,7 +347,7 @@ FlushGroupInfo (GROUP_HEADER *pGH, DWORD offset, BYTE which_group, PVOID fp)
GET_GROUP_DEST (FragPtr));
#endif /* DEBUG_GROUPS */
Ptr = (PBYTE)&FragPtr->RaceDescPtr;
WriteResFile ((PBYTE)Ptr,
WriteStateFile ((PBYTE)Ptr,
((PBYTE)&FragPtr->ShipInfo.race_strings) - Ptr, 1, fp);
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
hStarShip = hNextShip;
@@ -359,7 +359,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
{
PVOID fp;
fp = res_OpenResFile (tempDir,
fp = OpenStateFile (
offset && which_group ? DEFGRPINFO_FILE : RANDGRPINFO_FILE,
"r+b");
if (fp)
@@ -369,8 +369,8 @@ GetGroupInfo (DWORD offset, BYTE which_group)
HSTARSHIP hStarShip;
SHIP_FRAGMENTPTR FragPtr;
SeekResFile (fp, offset, SEEK_SET);
ReadResFile (&GH, sizeof (GH), 1, fp);
SeekStateFile (fp, offset, SEEK_SET);
ReadStateFile (&GH, sizeof (GH), 1, fp);
#ifdef DEBUG_GROUPS
fprintf (stderr, "GetGroupInfo(%lu): %u(%lu) out of %u\n", offset,
which_group, GH.GroupOffset[which_group], GH.NumGroups);
@@ -392,7 +392,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
|| !ValidateEvent (ABSOLUTE_EVENT,
&month_index, &day_index, &year_index)))
{
res_CloseResFile (fp);
CloseStateFile (fp);
#ifdef DEBUG_GROUPS
if (GH.star_index == (COUNT)(CurStarDescPtr - star_array))
@@ -400,11 +400,11 @@ GetGroupInfo (DWORD offset, BYTE which_group)
"date %u/%u/%u!\n", month_index, day_index,
year_index);
#endif /* DEBUG_GROUPS */
fp = res_OpenResFile (tempDir, RANDGRPINFO_FILE, "wb");
fp = OpenStateFile (RANDGRPINFO_FILE, "wb");
GH.NumGroups = 0;
GH.star_index = (COUNT)~0;
GH.GroupOffset[0] = 0;
WriteResFile (&GH, sizeof (GH), 1, fp);
WriteStateFile (&GH, sizeof (GH), 1, fp);
}
else
{
@@ -414,9 +414,9 @@ GetGroupInfo (DWORD offset, BYTE which_group)
if (GH.GroupOffset[which_group] == 0)
continue;
SeekResFile (fp, GH.GroupOffset[which_group], SEEK_SET);
ReadResFile (&RaceType, sizeof (RaceType), 1, fp);
ReadResFile (&NumShips, sizeof (NumShips), 1, fp);
SeekStateFile (fp, GH.GroupOffset[which_group], SEEK_SET);
ReadStateFile (&RaceType, sizeof (RaceType), 1, fp);
ReadStateFile (&NumShips, sizeof (NumShips), 1, fp);
if (NumShips)
{
@@ -502,7 +502,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
else if (ValidateEvent (ABSOLUTE_EVENT, /* still fresh */
&month_index, &day_index, &year_index))
{
res_CloseResFile (fp);
CloseStateFile (fp);
return (TRUE);
}
}
@@ -515,8 +515,8 @@ GetGroupInfo (DWORD offset, BYTE which_group)
ShipsLeft = CountLinks (&GLOBAL (npc_built_ship_q));
if (which_group == 0)
{
SeekResFile (fp, GH.GroupOffset[0], SEEK_SET);
ReadResFile (&BaseGroup, sizeof (BaseGroup), 1, fp);
SeekStateFile (fp, GH.GroupOffset[0], SEEK_SET);
ReadStateFile (&BaseGroup, sizeof (BaseGroup), 1, fp);
if (BaseGroup)
{
@@ -538,15 +538,15 @@ GetGroupInfo (DWORD offset, BYTE which_group)
}
ReinitQueue (&GLOBAL (npc_built_ship_q));
SeekResFile (fp, GH.GroupOffset[which_group]
SeekStateFile (fp, GH.GroupOffset[which_group]
+ sizeof (BaseGroup), SEEK_SET);
ReadResFile (&NumShips, sizeof (NumShips), 1, fp);
ReadStateFile (&NumShips, sizeof (NumShips), 1, fp);
while (NumShips--)
{
PBYTE Ptr;
ReadResFile ((PBYTE)&RaceType, sizeof (RaceType), 1, fp);
ReadStateFile ((PBYTE)&RaceType, sizeof (RaceType), 1, fp);
hStarShip = CloneShipFragment (RaceType,
&GLOBAL (npc_built_ship_q), 0);
@@ -554,7 +554,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
FragPtr = (SHIP_FRAGMENTPTR)LockStarShip (
&GLOBAL (npc_built_ship_q), hStarShip);
Ptr = (PBYTE)&FragPtr->RaceDescPtr;
ReadResFile ((PBYTE)Ptr,
ReadStateFile ((PBYTE)Ptr,
((PBYTE)&FragPtr->ShipInfo.race_strings) - Ptr, 1,
fp);
@@ -606,7 +606,7 @@ GetGroupInfo (DWORD offset, BYTE which_group)
}
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
return (GetHeadLink (&GLOBAL (npc_built_ship_q)) != 0);
@@ -617,7 +617,7 @@ PutGroupInfo (DWORD offset, BYTE which_group)
{
PVOID fp;
fp = res_OpenResFile (tempDir,
fp = OpenStateFile (
offset && which_group ? DEFGRPINFO_FILE : RANDGRPINFO_FILE,
"r+b");
if (fp)
@@ -626,23 +626,23 @@ PutGroupInfo (DWORD offset, BYTE which_group)
if (offset == (DWORD) ~0L)
{
offset = LengthResFile (fp);
offset = LengthStateFile (fp);
GH.NumGroups = 0;
GH.GroupOffset[0] = 0;
SeekResFile (fp, offset, SEEK_SET);
WriteResFile (&GH, sizeof (GH), 1, fp);
SeekStateFile (fp, offset, SEEK_SET);
WriteStateFile (&GH, sizeof (GH), 1, fp);
}
if (which_group)
{
SeekResFile (fp, offset, SEEK_SET);
SeekStateFile (fp, offset, SEEK_SET);
if (which_group == (BYTE)~0)
{
cur_player = 0;
which_group = 0;
}
}
ReadResFile (&GH, sizeof (GH), 1, fp);
ReadStateFile (&GH, sizeof (GH), 1, fp);
#ifdef NEVER
if (GetHeadLink (&GLOBAL (npc_built_ship_q))
@@ -669,7 +669,7 @@ PutGroupInfo (DWORD offset, BYTE which_group)
FlushGroupInfo (&GH, offset, which_group, fp);
res_CloseResFile (fp);
CloseStateFile (fp);
}
return (offset);
+10 -10
View File
@@ -105,7 +105,7 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc)
in_fp = res_OpenResFile (saveDir, file, "rb");
if (in_fp)
{
uio_Stream *fp;
GAME_STATE_FILE *fp;
DECODE_REF fh;
COUNT num_links;
Semaphore clock_sem;
@@ -238,7 +238,7 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc)
}
}
fp = res_OpenResFile (tempDir, STARINFO_FILE, "wb");
fp = OpenStateFile (STARINFO_FILE, "wb");
if (fp)
{
DWORD flen;
@@ -250,14 +250,14 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc)
num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen;
cread ((PBYTE)buf, num_bytes, 1, fh);
WriteResFile (buf, num_bytes, 1, fp);
WriteStateFile (buf, num_bytes, 1, fp);
flen -= num_bytes;
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
fp = res_OpenResFile (tempDir, DEFGRPINFO_FILE, "wb");
fp = OpenStateFile (DEFGRPINFO_FILE, "wb");
if (fp)
{
DWORD flen;
@@ -269,14 +269,14 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc)
num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen;
cread ((PBYTE)buf, num_bytes, 1, fh);
WriteResFile (buf, num_bytes, 1, fp);
WriteStateFile (buf, num_bytes, 1, fp);
flen -= num_bytes;
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
fp = res_OpenResFile (tempDir, RANDGRPINFO_FILE, "wb");
fp = OpenStateFile (RANDGRPINFO_FILE, "wb");
if (fp)
{
DWORD flen;
@@ -288,11 +288,11 @@ LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc)
num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen;
cread ((PBYTE)buf, num_bytes, 1, fh);
WriteResFile (buf, num_bytes, 1, fp);
WriteStateFile (buf, num_bytes, 1, fp);
flen -= num_bytes;
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
cread ((PBYTE)&SD, sizeof (SD), 1, fh);
+13 -13
View File
@@ -273,7 +273,7 @@ RetrySave:
}
else
{
uio_Stream *fp;
GAME_STATE_FILE *fp;
DWORD flen;
COUNT num_links;
FRAME frame;
@@ -354,58 +354,58 @@ RetrySave:
}
}
fp = res_OpenResFile (tempDir, STARINFO_FILE, "rb");
fp = OpenStateFile (STARINFO_FILE, "rb");
if (fp)
{
flen = LengthResFile (fp);
flen = LengthStateFile (fp);
cwrite ((PBYTE)&flen, sizeof (flen), 1, fh);
while (flen)
{
COUNT num_bytes;
num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen;
ReadResFile (buf, num_bytes, 1, fp);
ReadStateFile (buf, num_bytes, 1, fp);
cwrite ((PBYTE)buf, num_bytes, 1, fh);
flen -= num_bytes;
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
fp = res_OpenResFile (tempDir, DEFGRPINFO_FILE, "rb");
fp = OpenStateFile (DEFGRPINFO_FILE, "rb");
if (fp)
{
flen = LengthResFile (fp);
flen = LengthStateFile (fp);
cwrite ((PBYTE)&flen, sizeof (flen), 1, fh);
while (flen)
{
COUNT num_bytes;
num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen;
ReadResFile (buf, num_bytes, 1, fp);
ReadStateFile (buf, num_bytes, 1, fp);
cwrite ((PBYTE)buf, num_bytes, 1, fh);
flen -= num_bytes;
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
fp = res_OpenResFile (tempDir, RANDGRPINFO_FILE, "rb");
fp = OpenStateFile (RANDGRPINFO_FILE, "rb");
if (fp)
{
flen = LengthResFile (fp);
flen = LengthStateFile (fp);
cwrite ((PBYTE)&flen, sizeof (flen), 1, fh);
while (flen)
{
COUNT num_bytes;
num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen;
ReadResFile (buf, num_bytes, 1, fp);
ReadStateFile (buf, num_bytes, 1, fp);
cwrite ((PBYTE)buf, num_bytes, 1, fh);
flen -= num_bytes;
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
cwrite ((PBYTE)&SD, sizeof (SD), 1, fh);
+211 -24
View File
@@ -19,17 +19,204 @@
#include "state.h"
#include "encount.h"
#include "file.h"
#include "libs/misc.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
// in-memory file i/o
struct GAME_STATE_FILE
{
const char* symname;
DWORD size_hint;
int open_count;
BYTE* data;
DWORD used;
DWORD size;
DWORD ptr;
};
#define STATE_FILE_ITRAILER 0, 0, 0, 0, 0
#define NUM_STATE_FILES 3
static GAME_STATE_FILE state_files[NUM_STATE_FILES] =
{
{"STARINFO", STAR_BUFSIZE, STATE_FILE_ITRAILER},
{"RANDGRPINFO", RAND_BUFSIZE, STATE_FILE_ITRAILER},
{"DEFGRPINFO", DEF_BUFSIZE, STATE_FILE_ITRAILER}
};
GAME_STATE_FILE*
OpenStateFile (int stateFile, const char* mode)
{
GAME_STATE_FILE* fp;
if (stateFile < 0 || stateFile >= NUM_STATE_FILES)
return NULL_PTR;
fp = &state_files[stateFile];
fp->open_count++;
if (fp->open_count > 1)
fprintf (stderr, "WARNING: "
"State file %s open count is %d after open()\n",
fp->open_count);
if (!fp->data)
{
fp->data = HMalloc (fp->size_hint);
if (!fp->data)
return NULL_PTR;
fp->size = fp->size_hint;
}
// we allow reading and writing for any open mode
// but the mode determines what happens to the file contents
if (mode[0] == 'w')
{ // blow the file away
fp->used = 0;
#ifdef DEBUG
// paint buffer for tracking writes
memset (fp->data, 0xCC, fp->size);
#endif
}
else if (mode[0] == 'r')
{ // nothing
}
else
{
fprintf (stderr, "WARNING: "
"State file %s opened with unsupported mode '%s'\n",
mode);
}
fp->ptr = 0;
return fp;
}
void
CloseStateFile (GAME_STATE_FILE* fp)
{
fp->ptr = 0;
fp->open_count--;
if (fp->open_count < 0)
fprintf (stderr, "WARNING: "
"State file %s open count is %d after close()\n",
fp->open_count);
// Erm, Ok, it's closed! Honest!
}
void
DeleteStateFile (int stateFile)
{
GAME_STATE_FILE* fp;
if (stateFile < 0 || stateFile >= NUM_STATE_FILES)
return;
fp = &state_files[stateFile];
if (fp->open_count != 0)
fprintf (stderr, "WARNING: "
"State file %s open count is %d during delete()\n",
fp->open_count);
fp->used = 0;
fp->ptr = 0;
}
DWORD
LengthStateFile (GAME_STATE_FILE* fp)
{
return fp->used;
}
int
ReadStateFile (PVOID lpBuf, COUNT size, COUNT count, GAME_STATE_FILE *fp)
{
DWORD bytes = size * count;
if (fp->ptr >= fp->size)
{ // EOF
return 0;
}
else if (fp->ptr + bytes > fp->size)
{ // dont have that much data
bytes = fp->size - fp->ptr;
bytes -= bytes % size;
}
if (bytes > 0)
{
memcpy (lpBuf, fp->data + fp->ptr, bytes);
fp->ptr += bytes;
}
return (bytes / size);
}
int
WriteStateFile (PVOID lpBuf, COUNT size, COUNT count, GAME_STATE_FILE *fp)
{
DWORD bytes = size * count;
if (fp->ptr + bytes > fp->size)
{ // dont have that much space available
DWORD newsize = fp->ptr + bytes;
// grab more space in advance
if (newsize < fp->size * 3 / 2)
newsize = fp->size * 3 / 2;
fp->data = HRealloc (fp->data, newsize);
if (!fp->data)
return 0;
fp->size = newsize;
if (newsize > fp->size_hint)
fp->size_hint = newsize;
}
if (bytes > 0)
{
memcpy (fp->data + fp->ptr, lpBuf, bytes);
fp->ptr += bytes;
if (fp->ptr > fp->used)
fp->used = fp->ptr;
}
return (bytes / size);
}
int
PutStateFileChar (char ch, GAME_STATE_FILE *fp)
{
if (1 == WriteStateFile (&ch, sizeof(ch), 1, fp))
return ch;
else
return EOF;
}
int
SeekStateFile (GAME_STATE_FILE *fp, long offset, int whence)
{
if (whence == SEEK_CUR)
offset += fp->ptr;
else if (whence == SEEK_END)
offset += fp->used;
if (offset < 0)
{
fp->ptr = 0;
return 0;
}
fp->ptr = offset;
return 1;
}
void
InitPlanetInfo (void)
{
PVOID fp;
GAME_STATE_FILE* fp;
fp = res_OpenResFile (tempDir, STARINFO_FILE, "wb");
fp = OpenStateFile (STARINFO_FILE, "wb");
if (fp)
{
DWORD offset;
@@ -39,19 +226,19 @@ InitPlanetInfo (void)
pSD = &star_array[0];
do
{
WriteResFile (&offset, sizeof (offset), 1, fp);
WriteStateFile (&offset, sizeof (offset), 1, fp);
++pSD;
} while (pSD->star_pt.x <= MAX_X_UNIVERSE
&& pSD->star_pt.y <= MAX_Y_UNIVERSE);
res_CloseResFile (fp);
CloseStateFile (fp);
}
}
void
UninitPlanetInfo (void)
{
unlink (tempFilePath (STARINFO_FILE));
DeleteStateFile (STARINFO_FILE);
}
void
@@ -62,7 +249,7 @@ GetPlanetInfo (void)
pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask[BIOLOGICAL_SCAN] =
pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask[MINERAL_SCAN] =
pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask[ENERGY_SCAN] = 0;
fp = res_OpenResFile (tempDir, STARINFO_FILE, "rb");
fp = OpenStateFile (STARINFO_FILE, "rb");
if (fp)
{
COUNT star_index, planet_index, moon_index;
@@ -77,8 +264,8 @@ GetPlanetInfo (void)
moon_index = (COUNT)(pSolarSysState->pOrbitalDesc
- pSolarSysState->MoonDesc + 1);
SeekResFile (fp, star_index * sizeof (offset), SEEK_SET);
ReadResFile (&offset, sizeof (offset), 1, fp);
SeekStateFile (fp, star_index * sizeof (offset), SEEK_SET);
ReadStateFile (&offset, sizeof (offset), 1, fp);
if (offset)
{
@@ -93,14 +280,14 @@ GetPlanetInfo (void)
pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask
) * moon_index;
SeekResFile (fp, offset, SEEK_SET);
ReadResFile (pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask,
SeekStateFile (fp, offset, SEEK_SET);
ReadStateFile (pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask,
sizeof (
pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask
), 1, fp);
}
res_CloseResFile (fp);
CloseStateFile (fp);
}
}
@@ -109,7 +296,7 @@ PutPlanetInfo (void)
{
PVOID fp;
fp = res_OpenResFile (tempDir, STARINFO_FILE, "r+b");
fp = OpenStateFile (STARINFO_FILE, "r+b");
if (fp)
{
COUNT i;
@@ -125,8 +312,8 @@ PutPlanetInfo (void)
moon_index = (COUNT)(pSolarSysState->pOrbitalDesc
- pSolarSysState->MoonDesc + 1);
SeekResFile (fp, star_index * sizeof (offset), SEEK_SET);
ReadResFile (&offset, sizeof (offset), 1, fp);
SeekStateFile (fp, star_index * sizeof (offset), SEEK_SET);
ReadStateFile (&offset, sizeof (offset), 1, fp);
if (offset == 0)
{
@@ -135,19 +322,19 @@ PutPlanetInfo (void)
0, 0, 0,
};
offset = LengthResFile (fp);
offset = LengthStateFile (fp);
SeekResFile (fp, star_index * sizeof (offset), SEEK_SET);
WriteResFile (&offset, sizeof (offset), 1, fp);
SeekStateFile (fp, star_index * sizeof (offset), SEEK_SET);
WriteStateFile (&offset, sizeof (offset), 1, fp);
SeekResFile (fp, offset, SEEK_SET);
SeekStateFile (fp, offset, SEEK_SET);
for (i = 0; i < pSolarSysState->SunDesc[0].NumPlanets; ++i)
{
COUNT j;
WriteResFile (ScanRetrieveMask, sizeof (ScanRetrieveMask), 1, fp);
WriteStateFile (ScanRetrieveMask, sizeof (ScanRetrieveMask), 1, fp);
for (j = 0; j < pSolarSysState->PlanetDesc[i].NumPlanets; ++j)
WriteResFile (ScanRetrieveMask, sizeof (ScanRetrieveMask), 1, fp);
WriteStateFile (ScanRetrieveMask, sizeof (ScanRetrieveMask), 1, fp);
}
}
@@ -160,13 +347,13 @@ PutPlanetInfo (void)
pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask
) * moon_index;
SeekResFile (fp, offset, SEEK_SET);
WriteResFile (pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask,
SeekStateFile (fp, offset, SEEK_SET);
WriteStateFile (pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask,
sizeof (
pSolarSysState->SysInfo.PlanetInfo.ScanRetrieveMask
), 1, fp);
res_CloseResFile (fp);
CloseStateFile (fp);
}
}
+16 -3
View File
@@ -35,12 +35,17 @@ extern void BuildGroups (void);
#define MAX_DESC_CHARS 60
typedef UNICODE GAME_DESC[MAX_DESC_CHARS + 1];
#define STARINFO_FILE "starinfo.dat"
typedef struct GAME_STATE_FILE GAME_STATE_FILE;
#define STARINFO_FILE 0
//"starinfo.dat"
#define STAR_BUFSIZE (NUM_SOLAR_SYSTEMS * sizeof (DWORD) \
+ 3800 * (3 * sizeof (DWORD)))
#define RANDGRPINFO_FILE "randgrp.dat"
#define RANDGRPINFO_FILE 1
//"randgrp.dat"
#define RAND_BUFSIZE (4 * 1024)
#define DEFGRPINFO_FILE "defgrp.dat"
#define DEFGRPINFO_FILE 2
//"defgrp.dat"
#define DEF_BUFSIZE (10 * 1024)
typedef enum
@@ -50,6 +55,14 @@ typedef enum
DEFGRPINFO
} INFO_TYPE;
GAME_STATE_FILE* OpenStateFile (int stateFile, const char* mode);
void CloseStateFile (GAME_STATE_FILE* fp);
void DeleteStateFile (int stateFile);
DWORD LengthStateFile (GAME_STATE_FILE* fp);
int ReadStateFile (PVOID lpBuf, COUNT size, COUNT count, GAME_STATE_FILE *fp);
int WriteStateFile (PVOID lpBuf, COUNT size, COUNT count, GAME_STATE_FILE *fp);
int PutStateFileChar (char ch, GAME_STATE_FILE *fp);
int SeekStateFile (GAME_STATE_FILE *fp, long offset, int whence);
#endif /* _STATE_H */