mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
AGS: Methods to read/write arrays that have safe save/load methods
This commit is contained in:
@@ -207,8 +207,7 @@ HSaveError WriteGameState(PStream out) {
|
||||
// Game base
|
||||
game.WriteForSavegame(out);
|
||||
// Game palette
|
||||
// TODO: probably no need to save this for hi/true-res game
|
||||
out->WriteArray(palette, sizeof(color), 256);
|
||||
out->SafeWriteArray(palette, PALETTE_COUNT);
|
||||
|
||||
if (loaded_game_file_version <= kGameVersion_272) {
|
||||
// Global variables
|
||||
@@ -297,7 +296,7 @@ HSaveError ReadGameState(PStream in, int32_t cmp_ver, const PreservedParams &pp,
|
||||
// Game base
|
||||
game.ReadFromSavegame(in);
|
||||
// Game palette
|
||||
in->ReadArray(palette, sizeof(color), 256);
|
||||
in->SafeReadArray(palette, PALETTE_COUNT);
|
||||
|
||||
if (loaded_game_file_version <= kGameVersion_272) {
|
||||
// Legacy interaction global variables
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ags/lib/allegro/system.h"
|
||||
#include "ags/lib/allegro/aintern.h"
|
||||
#include "ags/shared/core/types.h"
|
||||
#include "ags/shared/util/stream.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "common/system.h"
|
||||
#include "graphics/palette.h"
|
||||
@@ -49,6 +50,20 @@ int _rgb_a_shift_32 = 0;
|
||||
RGB_MAP *rgb_map;
|
||||
COLOR_MAP *color_map;
|
||||
|
||||
void color::readFromFile(AGS::Shared::Stream *file) {
|
||||
r = file->ReadByte();
|
||||
g = file->ReadByte();
|
||||
b = file->ReadByte();
|
||||
filler = file->ReadByte();
|
||||
}
|
||||
|
||||
void color::writeToFile(AGS::Shared::Stream *file) const {
|
||||
file->WriteByte(r);
|
||||
file->WriteByte(g);
|
||||
file->WriteByte(b);
|
||||
file->WriteByte(filler);
|
||||
}
|
||||
|
||||
|
||||
void set_color(int idx, const RGB *p) {
|
||||
_current_palette[idx] = *p;
|
||||
|
||||
@@ -39,11 +39,20 @@ namespace AGS3 {
|
||||
|
||||
class BITMAP;
|
||||
|
||||
namespace AGS {
|
||||
namespace Shared {
|
||||
class Stream;
|
||||
} // namespace Shared
|
||||
} // namespace AGS
|
||||
|
||||
#include "common/pack-start.h" // START STRUCT PACKING
|
||||
|
||||
struct color {
|
||||
byte r, g, b;
|
||||
byte filler;
|
||||
|
||||
void readFromFile(AGS::Shared::Stream *file);
|
||||
void writeToFile(AGS::Shared::Stream *file) const;
|
||||
} PACKED_STRUCT;
|
||||
|
||||
typedef color RGB;
|
||||
|
||||
@@ -83,6 +83,18 @@ public:
|
||||
|
||||
// Fill the requested number of bytes with particular value
|
||||
size_t WriteByteCount(uint8_t b, size_t count);
|
||||
|
||||
template<class T>
|
||||
inline void SafeReadArray(T *arr, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i, ++arr)
|
||||
arr->readFromFile(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void SafeWriteArray(const T *arr, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i, ++arr)
|
||||
arr->writeToFile(this);
|
||||
}
|
||||
};
|
||||
|
||||
class ScummVMReadStream : public Common::SeekableReadStream {
|
||||
|
||||
Reference in New Issue
Block a user