SLUDGE: Add support for some windows-only games

This commit is contained in:
Simei Yin 2017-08-21 09:07:19 +02:00
parent 2edd59d0b8
commit d9a6791500
10 changed files with 58 additions and 14 deletions

View File

@ -20,6 +20,7 @@
*
*/
#include "common/config-manager.h"
#include "common/savefile.h"
#include "sludge/allfiles.h"
@ -2412,11 +2413,29 @@ builtIn(_rem_launchWith) {
UNUSEDALL
trimStack(fun->stack);
// To support some windows only games
Common::String filename = getTextFromAnyVar(fun->stack->thisVar);
trimStack(fun->stack);
if (filename.hasSuffix(".exe")) {
const Common::FSNode gameDataDir(ConfMan.get("path"));
Common::FSList files;
gameDataDir.getChildren(files, Common::FSNode::kListFilesOnly);
for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file) {
Common::String fileName = file->getName();
fileName.toLowercase();
if (fileName.hasSuffix(".dat") || fileName == "data") {
g_sludge->launchNext = file->getName();
return BR_CONTINUE;
}
}
}
g_sludge->launchNext.clear();
setVariable(fun->reg, SVT_INT, false);
return BR_CONTINUE;
}
builtIn(getFramesPerSecond) {
@ -2577,8 +2596,9 @@ BuiltReturn callBuiltIn(int whichFunc, int numParams, LoadedFunction *fun) {
}
if (builtInFunctionArray[whichFunc].func) {
debugC(1, kSludgeDebugBuiltin, "Run built-in function : %s",
(whichFunc < numBIFNames) ? allBIFNames[whichFunc].c_str() : "Unknown");
debugC(3, kSludgeDebugBuiltin,
"Run built-in function %i : %s",
whichFunc, (whichFunc < numBIFNames) ? allBIFNames[whichFunc].c_str() : "Unknown");
return builtInFunctionArray[whichFunc].func(numParams, fun);
}
}

View File

@ -73,6 +73,7 @@ public:
void restore(FrozenStuffStruct *frozenStuff);
// Quit
void startGame() { _weAreDoneSoQuit = false; }
void quitGame() { _weAreDoneSoQuit = true; /* _reallyWantToQuit = true; */ }
bool quit() { return _weAreDoneSoQuit; }

View File

@ -33,7 +33,7 @@
namespace Sludge {
bool ImgLoader::loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve) {
debugC(3, kSludgeDebugDataLoad, "Loading image at position: %i", stream->pos());
debugC(3, kSludgeDebugGraphics, "Loading image at position: %i", stream->pos());
int32 start_ptr = stream->pos();
if (!loadPNGImage(stream, dest)) {
stream->seek(start_ptr);

View File

@ -34,6 +34,7 @@
#include "sludge/newfatal.h"
#include "sludge/objtypes.h"
#include "sludge/people.h"
#include "sludge/region.h"
#include "sludge/statusba.h"
#include "sludge/sound.h"
#include "sludge/sludge.h"
@ -48,7 +49,7 @@ extern VariableStack *noStack;
int dialogValue = 0;
int main_loop(const char *filename) {
int main_loop(Common::String filename) {
if (!initSludge(filename)) {
return 0;
@ -75,6 +76,7 @@ int main_loop(const char *filename) {
startNewFunctionNum(0, 0, NULL, noStack);
g_sludge->_evtMan->startGame();
g_sludge->_timer.init();
while (!g_sludge->_evtMan->quit()) {
@ -88,8 +90,17 @@ int main_loop(const char *filename) {
g_sludge->_timer.waitFrame();
}
killAllFunctions();
killAllRegions();
g_sludge->_soundMan->killSoundStuff();
// Load next game
if (!g_sludge->launchNext.empty()) {
Common::String name = g_sludge->launchNext;
g_sludge->launchNext.clear();
main_loop(name);
}
return (0);
}

View File

@ -24,7 +24,7 @@
namespace Sludge {
int main_loop(const char *filename);
int main_loop(Common::String filename);
} // End of namespace Sludge

View File

@ -33,8 +33,9 @@
namespace Sludge {
ScreenRegion *allScreenRegions = NULL;
ScreenRegion *overRegion = NULL;
ScreenRegion *allScreenRegions = nullptr;
ScreenRegion *overRegion = nullptr;
ScreenRegion *lastRegion = nullptr;
void showBoxes() {
ScreenRegion*huntRegion = allScreenRegions;
@ -121,7 +122,8 @@ void killAllRegions() {
g_sludge->_objMan->removeObjectType(killRegion->thisType);
delete killRegion;
}
overRegion = NULL;
overRegion = nullptr;
lastRegion = nullptr;
}
bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di,

View File

@ -55,7 +55,8 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
DebugMan.addDebugChannel(kSludgeDebugZBuffer, "ZBuffer", "ZBuffer debug level");
DebugMan.addDebugChannel(kSludgeDebugSound, "Sound", "Sound debug level");
DebugMan.enableDebugChannel("Sound");
DebugMan.enableDebugChannel("Data Load");
DebugMan.enableDebugChannel("Built-in");
// init graphics
_origFormat = new Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);
@ -63,10 +64,10 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
// Init Strings
launchMe = "";
launchNext = "";
loadNow = "";
gamePath = "";
bundleFolder = "";
fatalMessage = "";
fatalInfo = "Initialisation error! Something went wrong before we even got started!";

View File

@ -67,6 +67,7 @@ protected:
public:
// global String variables
Common::String launchMe;
Common::String launchNext;
Common::String loadNow;
Common::String gamePath;
Common::String bundleFolder;

View File

@ -54,7 +54,6 @@
namespace Sludge {
extern int dialogValue;
extern Variable *launchResult;
int numBIFNames = 0;
Common::String *allBIFNames;
@ -74,7 +73,6 @@ extern SpeechStruct *speech;
extern LoadedFunction *saverFunc;
LoadedFunction *allRunningFunctions = NULL;
ScreenRegion *lastRegion = NULL;
VariableStack *noStack = NULL;
Variable *globalVars;
@ -913,6 +911,15 @@ bool runSludge() {
return true;
}
void killAllFunctions() {
LoadedFunction *ptr = allRunningFunctions;
while (ptr) {
LoadedFunction *kill = ptr;
ptr = ptr->next;
abortFunction(kill);
}
}
bool loadFunctionCode(LoadedFunction *newFunc) {
uint numLines, numLinesRead;

View File

@ -66,6 +66,7 @@ int startNewFunctionNum(uint, uint, LoadedFunction *, VariableStack*&, bool = tr
bool handleInput();
void restartFunction(LoadedFunction *fun);
bool loadFunctionCode(LoadedFunction *newFunc);
void killAllFunctions();
void finishFunction(LoadedFunction *fun);
void abortFunction(LoadedFunction *fun);