CHEWY: Shifting saving/loading code into engine class

This commit is contained in:
Paul Gilbert 2021-10-23 21:33:15 -07:00
parent 36b4b2c1b7
commit 264835e44a
7 changed files with 96 additions and 149 deletions

View File

@ -84,4 +84,70 @@ Common::Error ChewyEngine::run() {
return Common::kNoError;
}
Common::Error ChewyEngine::loadGameStream(Common::SeekableReadStream *stream) {
exit_room(-1);
Common::Serializer s(stream, nullptr);
if (!spieler.synchronize(s)) {
fcode = READFEHLER;
modul = DATEI;
} else {
flags.LoadGame = true;
split_adsh(stream);
ERROR
if (spieler.inv_cur == true && spieler.AkInvent != -1) {
menu_item = CUR_USE;
}
if (spieler.AkInvent != -1)
spieler.room_m_obj[spieler.AkInvent].RoomNr = -1;
room->load_room(&room_blk, spieler.PersonRoomNr[P_CHEWY], &spieler);
ERROR
load_chewy_taf(spieler.ChewyAni);
fx_blende = 1;
room->calc_invent(&room_blk, &spieler);
if (spieler.AkInvent != -1)
spieler.room_m_obj[spieler.AkInvent].RoomNr = 255;
obj->sort();
set_speed();
for (int i = 0; i < MAX_PERSON; i++) {
set_person_pos(spieler.X[i], spieler.Y[i], i, spieler.Phase[i]);
}
auto_obj = 0;
enter_room(-1);
flags.LoadGame = false;
}
return Common::kNoError;
}
Common::Error ChewyEngine::saveGameStream(Common::WriteStream *stream, bool isAutosave) {
Common::Serializer s(nullptr, stream);
int16 spr_nr;
int16 i;
spr_nr = chewy_ph[spieler_vector[P_CHEWY].Phase * 8 + spieler_vector[P_CHEWY].PhNr];
for (i = 0; i < MAX_PERSON; i++) {
spieler.X[i] = spieler_vector[i].Xypos[0];
spieler.Y[i] = spieler_vector[i].Xypos[1];
spieler.Phase[i] = person_end_phase[i];
}
if (!spieler.synchronize(s)) {
fcode = WRITEFEHLER;
modul = DATEI;
} else {
append_adsh(stream);
ERROR
}
return Common::kNoError;
}
} // End of namespace Chewy

View File

@ -52,9 +52,11 @@ protected:
bool hasFeature(EngineFeature f) const override;
void initialize();
void shutdown();
void shutdown() {}
public:
const ChewyGameDescription *_gameDescription;
Common::RandomSource _rnd;
TempFileArchive _tempFiles;
EventsManager *_events;
Sound *_sound;
@ -63,13 +65,18 @@ public:
ChewyEngine(OSystem *syst, const ChewyGameDescription *gameDesc);
~ChewyEngine() override;
int getGameType() const;
uint32 getFeatures() const;
Common::Language getLanguage() const;
Common::Platform getPlatform() const;
const ChewyGameDescription *_gameDescription;
Common::RandomSource _rnd;
/**
* Load savegame data
*/
Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
/**
* Save savegame data
*/
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave) override;
};
extern ChewyEngine *g_engine;

View File

@ -110,68 +110,6 @@ int16 call_fileio(int16 palette, int16 mode) {
return (ret);
}
void save(Common::WriteStream *ws) {
Common::Serializer s(nullptr, ws);
int16 spr_nr;
int16 i;
spr_nr = chewy_ph[spieler_vector[P_CHEWY].Phase * 8 + spieler_vector[P_CHEWY].PhNr];
for (i = 0; i < MAX_PERSON; i++) {
spieler.X[i] = spieler_vector[i].Xypos[0];
spieler.Y[i] = spieler_vector[i].Xypos[1];
spieler.Phase[i] = person_end_phase[i];
}
if (!spieler.synchronize(s)) {
fcode = WRITEFEHLER;
modul = DATEI;
} else {
append_adsh(ws);
ERROR
}
}
void load(Common::SeekableReadStream *rs) {
exit_room(-1);
Common::Serializer s(rs, nullptr);
if (!spieler.synchronize(s)) {
fcode = READFEHLER;
modul = DATEI;
} else {
flags.LoadGame = true;
split_adsh(rs);
ERROR
if (spieler.inv_cur == true && spieler.AkInvent != -1) {
menu_item = CUR_USE;
}
if (spieler.AkInvent != -1)
spieler.room_m_obj[spieler.AkInvent].RoomNr = -1;
room->load_room(&room_blk, spieler.PersonRoomNr[P_CHEWY], &spieler);
ERROR
load_chewy_taf(spieler.ChewyAni);
fx_blende = 1;
room->calc_invent(&room_blk, &spieler);
if (spieler.AkInvent != -1)
spieler.room_m_obj[spieler.AkInvent].RoomNr = 255;
obj->sort();
set_speed();
for (int i = 0; i < MAX_PERSON; i++) {
set_person_pos(spieler.X[i], spieler.Y[i], i, spieler.Phase[i]);
}
auto_obj = 0;
enter_room(-1);
flags.LoadGame = false;
}
}
void append_adsh(void *sh) {
Stream *shandle = (Stream *)sh;
atds->close_handle(ADH_DATEI);

View File

@ -331,9 +331,6 @@ void init_room();
int16 call_fileio(int16 palette, int16 mode);
void save(Common::WriteStream *ws);
void load(Common::SeekableReadStream *in);
// FIXME: was FILE*
void append_adsh(void *shandle);

View File

@ -83,8 +83,6 @@ void standard_init() {
iog = new io_game(out, in, cur);
strcpy(ioptr.id, "CHE\0");
strcpy(ioptr.save_path, SAVEDIR);
ioptr.save_funktion = &save;
ioptr.load_funktion = &load;
ioptr.delay = 8;
alloc_buffers();
pal [765] = 63;

View File

@ -21,6 +21,7 @@
*/
#include "common/system.h"
#include "chewy/chewy.h"
#include "chewy/events.h"
#include "chewy/file.h"
#include "chewy/io_game.h"
@ -606,79 +607,39 @@ int16 io_game::get_files(char *fname) {
return 0;
}
void io_game::save(int16 y, int16 nr, char *fname) {
char str[4];
char path[80];
int16 abfrage = 0;
int16 j;
Stream *handle;
if (nr + 1 < 10)
j = 2;
else
j = 1;
strcpy(str, "000");
itoa(nr + 1, str + j, 10);
strcpy(path, fname);
strcat(path, str);
void io_game::save(int16 y, int16 slotNum, char *fname) {
cur->wait_taste_los(true);
in->alter_kb_handler();
cur->hide_cur();
out->pop_box
(io->popx + 8, y, io->popx + 131, y + 10, io->m_col[1], io->m_col[0], io->m_col[4]);
// Eintrag löschen
out->printxy(io->popx + 10, y + 2, io->m_col[0], 300, scr_width, "%d.\0", nr + 1);
if (file_find_g[nr][0] == 0) {
abfrage = out->scanxy(io->popx + 28, y + 2, io->m_col[0], io->m_col[4], io->m_col[2], scr_width, "%36s15", &file_find_g[nr][1]);
out->printxy(io->popx + 10, y + 2, io->m_col[0], 300, scr_width, "%d.\0", slotNum + 1);
if (file_find_g[slotNum][0] == 0) {
out->scanxy(io->popx + 28, y + 2, io->m_col[0], io->m_col[4], io->m_col[2], scr_width, "%36s15", &file_find_g[slotNum][1]);
} else {
handle = chewy_fopen(path, "rb");
//handle = chewy_fopen(path, "rb");
out->printxy(io->popx + 167, io->popy + 85, io->m_col[1], 300, scr_width, FSTRING7);
chewy_fclose(handle);
abfrage = out->scanxy(io->popx + 28, y + 2, io->m_col[0], io->m_col[4], io->m_col[2], scr_width, "%36s15", &file_find_g[nr][1]);
//chewy_fclose(handle);
out->scanxy(io->popx + 28, y + 2, io->m_col[0], io->m_col[4], io->m_col[2], scr_width, "%36s15", &file_find_g[slotNum][1]);
}
in->neuer_kb_handler(kbinfo);
mark_eintrag(y, nr);
mark_eintrag(y, slotNum);
out->box_fill(io->popx + 167, io->popy + 70, io->popx + 244, io->popy + 100, io->m_col[5]);
cur->show_cur();
abfrage = 13;
if (abfrage == 13) {
handle = chewy_fopen(path, "wb+");
if (handle) {
chewy_fwrite(io->id, sizeof(io->id), 1, handle);
chewy_fwrite(&file_find_g[nr][1], USER_NAME + 2, 1, handle);
(*io->save_funktion)(dynamic_cast<Common::WriteStream *>(handle));
chewy_fclose(handle);
}
}
Common::String desc(&file_find_g[slotNum][1]);
(void)g_engine->saveGameState(slotNum, desc);
}
void io_game::load(int16 nr, char *fname) {
Stream *handle;
char str[4];
char path[80];
int16 j;
void io_game::load(int16 slotNum, char *fname) {
get_files(io->save_path);
cur->hide_cur();
if (file_find_g[nr][0] == 1) {
if (nr + 1 < 10)
j = 2;
else
j = 1;
strcpy(str, "000\0");
itoa(nr + 1, str + j, 10);
strcpy(path, fname);
strcat(path, str);
handle = chewy_fopen(path, "rb");
if (handle) {
chewy_fseek(handle, sizeof(io->id) + USER_NAME + 2, 0);
(*io->load_funktion)(dynamic_cast<Common::SeekableReadStream *>(handle));
chewy_fclose(handle);
}
if (file_find_g[slotNum][0] == 1) {
(void)g_engine->loadGameState(slotNum);
}
}
@ -699,27 +660,9 @@ char *io_game::io_init(iog_init *iostruc) {
return (&file_find_g[0][0]);
}
void io_game::save_entry(int16 nr, char *fname) {
char str[4];
char path[80];
int16 j;
Stream *handle;
if (nr + 1 < 10)
j = 2;
else
j = 1;
strcpy(str, "000");
itoa(nr + 1, str + j, 10);
strcpy(path, fname);
strcat(path, str);
handle = chewy_fopen(path, "wb+");
if (handle) {
chewy_fwrite(io->id, sizeof(io->id), 1, handle);
chewy_fwrite(&file_find_g[nr][1], USER_NAME + 2, 1, handle);
(*io->save_funktion)(dynamic_cast<Common::WriteStream *>(handle));
chewy_fclose(handle);
}
void io_game::save_entry(int16 slotNum, char *fname) {
Common::String desc(&file_find_g[slotNum][1]);
g_engine->saveGameState(slotNum, desc);
}
} // namespace Chewy

View File

@ -390,8 +390,6 @@ struct iog_init {
uint8 f3 = 0;
uint8 f4 = 0;
uint8 key_nr = 0;
void (*save_funktion)(Common::WriteStream *handle) = nullptr;
void (*load_funktion)(Common::SeekableReadStream *handle) = nullptr;
int16 delay = 0;
};