Skip to content

Commit

Permalink
[TD] Updates Save/Load code to use Pipe/Straw system.
Browse files Browse the repository at this point in the history
Adds LCW compression and SHA1 checksum.
Uses CDFileClass to ensure files are saved/loaded to/from user data folder.
Adds prefix for side to save/load menu items similar to RA.
  • Loading branch information
OmniBlade committed Jun 14, 2024
1 parent 6233416 commit ac3ce7d
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 409 deletions.
28 changes: 10 additions & 18 deletions tiberiandawn/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void BaseClass::Write_INI(CCINIClass& ini)
* HISTORY: *
* 03/24/1995 BRR : Created. *
*=============================================================================================*/
bool BaseClass::Load(FileClass& file)
bool BaseClass::Load(Straw& file)
{
int num_struct;
int i;
Expand All @@ -249,7 +249,7 @@ bool BaseClass::Load(FileClass& file)
/*
** Read in & check the size of this class
*/
if (file.Read(&i, sizeof(i)) != sizeof(i)) {
if (file.Get(&i, sizeof(i)) != sizeof(i)) {
return (false);
}

Expand All @@ -260,19 +260,19 @@ bool BaseClass::Load(FileClass& file)
/*
** Read in the House & the number of structures in the base
*/
if (file.Read(&House, sizeof(House)) != sizeof(House)) {
if (file.Get(&House, sizeof(House)) != sizeof(House)) {
return (false);
}

if (file.Read(&num_struct, sizeof(num_struct)) != sizeof(num_struct)) {
if (file.Get(&num_struct, sizeof(num_struct)) != sizeof(num_struct)) {
return (false);
}

/*
** Read each node entry & add it to the list
*/
for (i = 0; i < num_struct; i++) {
if (file.Read(&node, sizeof(node)) != sizeof(node)) {
if (file.Get(&node, sizeof(node)) != sizeof(node)) {
return (false);
}
Nodes.Add(node);
Expand All @@ -296,7 +296,7 @@ bool BaseClass::Load(FileClass& file)
* HISTORY: *
* 03/24/1995 BRR : Created. *
*=============================================================================================*/
bool BaseClass::Save(FileClass& file)
bool BaseClass::Save(Pipe& file) const
{
int num_struct;
int i;
Expand All @@ -306,30 +306,22 @@ bool BaseClass::Save(FileClass& file)
** Write the size of this class
*/
i = sizeof(*this);
if (file.Write(&i, sizeof(i)) != sizeof(i)) {
return (false);
}
file.Put(&i, sizeof(i));

/*
** Write the House & the number of structures in the base
*/
if (file.Write(&House, sizeof(House)) != sizeof(House)) {
return (false);
}
file.Put(&House, sizeof(House));

num_struct = Nodes.Count();
if (file.Write(&num_struct, sizeof(num_struct)) != sizeof(num_struct)) {
return (false);
}
file.Put(&num_struct, sizeof(num_struct));

/*
** Write each node entry
*/
for (i = 0; i < num_struct; i++) {
node = Nodes[i];
if (file.Write(&node, sizeof(node)) != sizeof(node)) {
return (false);
}
file.Put(&node, sizeof(node));
}

return (true);
Expand Down
7 changes: 5 additions & 2 deletions tiberiandawn/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#ifndef BASE_H
#define BASE_H

class Straw;
class Pipe;

/****************************************************************************
** This class defines one "node" in the pre-built base list. Each node
** contains a type of building to build, and the COORD to build it at.
Expand Down Expand Up @@ -82,8 +85,8 @@ class BaseClass
{
return "Base";
}
bool Load(FileClass& file);
bool Save(FileClass& file);
bool Load(Straw& file);
bool Save(Pipe& file) const;
virtual void Code_Pointers(void){};
virtual void Decode_Pointers(void){};

Expand Down
7 changes: 5 additions & 2 deletions tiberiandawn/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#include "template.h"
#include "endianness.h"

class Pipe;
class Straw;

/****************************************************************************
** Each cell on the map is controlled by the following structure.
*/
Expand Down Expand Up @@ -258,8 +261,8 @@ class CellClass
** File I/O.
*/
bool Should_Save(void) const;
bool Save(FileClass& file);
bool Load(FileClass& file);
bool Save(Pipe& file) const;
bool Load(Straw& file);
void Code_Pointers(void);
void Decode_Pointers(void);

Expand Down
Loading

0 comments on commit ac3ce7d

Please sign in to comment.