Skip to content

Commit

Permalink
TONY: Work on enabling GMM saving and loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 17, 2012
1 parent 8876266 commit 59942d9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 12 deletions.
36 changes: 33 additions & 3 deletions engines/tony/detection.cpp
Expand Up @@ -25,6 +25,7 @@

#include "engines/advancedDetector.h"
#include "common/system.h"
#include "graphics/surface.h"

#include "tony/tony.h"
#include "tony/game.h"
Expand Down Expand Up @@ -75,18 +76,23 @@ class TonyMetaEngine : public AdvancedMetaEngine {
virtual SaveStateList listSaves(const char *target) const;
virtual int getMaximumSaveSlot() const;
virtual void removeSaveState(const char *target, int slot) const;
SaveStateDescriptor TonyMetaEngine::querySaveMetaInfos(const char *target, int slot) const;
};

bool TonyMetaEngine::hasFeature(MetaEngineFeature f) const {
return
(f == kSupportsListSaves) ||
// (f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave);
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail);
}

bool Tony::TonyEngine::hasFeature(EngineFeature f) const {
return
(f == kSupportsRTL);
(f == kSupportsRTL) ||
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime);
}

bool TonyMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
Expand Down Expand Up @@ -136,6 +142,30 @@ void TonyMetaEngine::removeSaveState(const char *target, int slot) const {
g_system->getSavefileManager()->removeSavefile(filename);
}

SaveStateDescriptor TonyMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
Tony::RMString saveName;
byte difficulty;

Graphics::PixelFormat pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
Graphics::Surface *thumbnail = new Graphics::Surface();
thumbnail->create(160, 120, pixelFormat);

if (Tony::RMOptionScreen::LoadThumbnailFromSaveState(slot, (byte *)thumbnail->pixels, saveName, difficulty)) {
// Create the return descriptor
SaveStateDescriptor desc(slot, (const char *)saveName);
desc.setDeletableFlag(true);
desc.setWriteProtectedFlag(false);
desc.setThumbnail(thumbnail);

return desc;
}

thumbnail->free();
delete thumbnail;
return SaveStateDescriptor();
}


#if PLUGIN_ENABLED_DYNAMIC(TONY)
REGISTER_PLUGIN_DYNAMIC(TONY, PLUGIN_TYPE_ENGINE, TonyMetaEngine);
#else
Expand Down
12 changes: 8 additions & 4 deletions engines/tony/gfxengine.cpp
Expand Up @@ -698,7 +698,7 @@ void LoadMusic(Common::InSaveFile *f);

#define TONY_SAVEGAME_VERSION 8

void RMGfxEngine::SaveState(const char *fn, byte *curThumb, const char *name, bool bFastCompress) {
void RMGfxEngine::SaveState(const Common::String &fn, byte *curThumb, const Common::String &name) {
Common::OutSaveFile *f;
byte *state;
uint thumbsize;
Expand Down Expand Up @@ -733,9 +733,9 @@ void RMGfxEngine::SaveState(const char *fn, byte *curThumb, const char *name, bo
i = mpalQueryGlobalVar("VERSIONEFACILE");
f->writeByte(i);

i = strlen(name);
i = strlen(name.c_str());
f->writeByte(i);
f->write(name, i);
f->write(name.c_str(), i);
f->writeUint32LE(m_nCurLoc);
f->writeUint32LE(tp.x);
f->writeUint32LE(tp.y);
Expand Down Expand Up @@ -801,7 +801,7 @@ void RMGfxEngine::SaveState(const char *fn, byte *curThumb, const char *name, bo
delete f;
}

void RMGfxEngine::LoadState(CORO_PARAM, const char *fn) {
void RMGfxEngine::LoadState(CORO_PARAM, const Common::String &fn) {
// PROBLEMA: Bisognerebbe caricare la locazione in un thread a parte per fare la OnEnter ...
CORO_BEGIN_CONTEXT;
Common::InSaveFile *f;
Expand Down Expand Up @@ -986,4 +986,8 @@ void RMGfxEngine::WaitWipeEnd(CORO_PARAM) {
CoroScheduler.waitForSingleObject(coroParam, m_hWipeEvent, CORO_INFINITE);
}

bool RMGfxEngine::CanLoadSave() {
return m_bInput && !m_tony.InAction();
}

} // End of namespace Tony
5 changes: 3 additions & 2 deletions engines/tony/gfxengine.h
Expand Up @@ -133,8 +133,8 @@ class RMGfxEngine {
void Unfreeze(void);

// State management
void SaveState(const char *fn, byte *curThumb, const char *name, bool bFastCompress = false);
void LoadState(CORO_PARAM, const char *fn);
void SaveState(const Common::String &fn, byte *curThumb, const Common::String &name);
void LoadState(CORO_PARAM, const Common::String &fn);

// Selects a location
void SelectLocation(const RMPoint &ptTonyStart = RMPoint(-1, -1), const RMPoint &start = RMPoint(-1, -1));
Expand All @@ -150,6 +150,7 @@ class RMGfxEngine {
void SetPalesati(bool bpal) {
m_inter.SetPalesati(bpal);
}
bool CanLoadSave();
};

} // End of namespace Tony
Expand Down
44 changes: 42 additions & 2 deletions engines/tony/tony.cpp
Expand Up @@ -43,6 +43,14 @@ TonyEngine::TonyEngine(OSystem *syst, const TonyGameDescription *gameDesc) : Eng
DebugMan.addDebugChannel(kTonyDebugActions, "actions", "Actions debugging");
DebugMan.addDebugChannel(kTonyDebugSound, "sound", "Sound debugging");
DebugMan.addDebugChannel(kTonyDebugMusic, "music", "Music debugging");

// Set up load slot number
_loadSlotNumber = -1;
if (ConfMan.hasKey("save_slot")) {
int slotNumber = ConfMan.getInt("save_slot");
if (slotNumber >= 0 && slotNumber <= 99)
_loadSlotNumber = slotNumber;
}
}

TonyEngine::~TonyEngine() {
Expand Down Expand Up @@ -400,7 +408,7 @@ void TonyEngine::AutoSave(CORO_PARAM) {
CORO_INVOKE_0(MainWaitFrame);
MainFreeze();
_ctx->buf = GetSaveStateFileName(0);
_theEngine.SaveState(_ctx->buf.c_str(), (byte *)m_curThumbnail, "Autosave", true);
_theEngine.SaveState(_ctx->buf, (byte *)m_curThumbnail, "Autosave");
MainUnfreeze();

CORO_END_CODE;
Expand Down Expand Up @@ -499,17 +507,26 @@ void TonyEngine::Abort(void) {
*/
void TonyEngine::PlayProcess(CORO_PARAM, const void *param) {
CORO_BEGIN_CONTEXT;
Common::String fn;
CORO_END_CONTEXT(_ctx);


CORO_BEGIN_CODE(_ctx);

// CORO_INFINITE loop. We rely on the outer main process to detect if a shutdown is required,
// Game loop. We rely on the outer main process to detect if a shutdown is required,
// and kill the scheudler and all the processes, including this one
for (;;) {
// Se siamo in pausa, entra nel loop appropriato
if (_vm->m_bPaused)
_vm->PauseLoop();

// If a savegame needs to be loaded, then do so
if (_vm->_loadSlotNumber != -1 && GLOBALS.GfxEngine != NULL) {
_ctx->fn = GetSaveStateFileName(_vm->_loadSlotNumber);
CORO_INVOKE_1(GLOBALS.GfxEngine->LoadState, _ctx->fn);
_vm->_loadSlotNumber = -1;
}

// Wait for the next frame
CORO_INVOKE_1(CoroScheduler.sleep, 50);

Expand Down Expand Up @@ -627,4 +644,27 @@ uint32 TonyEngine::GetTime() {
return g_system->getMillis();
}

bool TonyEngine::canLoadGameStateCurrently() {
return GLOBALS.GfxEngine != NULL && GLOBALS.GfxEngine->CanLoadSave();
}
bool TonyEngine::canSaveGameStateCurrently() {
return GLOBALS.GfxEngine != NULL && GLOBALS.GfxEngine->CanLoadSave();
}

Common::Error TonyEngine::loadGameState(int slot) {
_loadSlotNumber = slot;
return Common::kNoError;
}

Common::Error TonyEngine::saveGameState(int slot, const Common::String &desc) {
if (!GLOBALS.GfxEngine)
return Common::kUnknownError;

RMSnapshot s;
s.GrabScreenshot(*GLOBALS.GfxEngine, 4, m_curThumbnail);

GLOBALS.GfxEngine->SaveState(GetSaveStateFileName(slot), (byte *)m_curThumbnail, desc);
return Common::kNoError;
}

} // End of namespace Tony
8 changes: 7 additions & 1 deletion engines/tony/tony.h
Expand Up @@ -78,8 +78,9 @@ struct VoiceHeader {

class TonyEngine : public Engine {
private:
Common::ErrorCode Init();
int _loadSlotNumber;

Common::ErrorCode Init();
void InitMusic();
void CloseMusic();
bool OpenVoiceDatabase();
Expand Down Expand Up @@ -142,6 +143,11 @@ class TonyEngine : public Engine {
RMGfxEngine *GetEngine() { return &_theEngine; }
void GUIError(const Common::String &msg);

virtual bool canLoadGameStateCurrently();
virtual bool canSaveGameStateCurrently();
Common::Error TonyEngine::loadGameState(int slot);
Common::Error TonyEngine::saveGameState(int slot, const Common::String &desc);

// Avverte che siamo guidati dal GDI
void GDIControl(bool bCon);

Expand Down

0 comments on commit 59942d9

Please sign in to comment.