diff options
author | Max Horn | 2010-02-13 17:42:49 +0000 |
---|---|---|
committer | Max Horn | 2010-02-13 17:42:49 +0000 |
commit | ac4d325e0d61b649026a5f5414f749697b285ccc (patch) | |
tree | c58f62596d050be62e98180c0255e7998a9a62e4 /engines/sci | |
parent | 24fd77eb242c4d90e8c3a3b0bcc5f0c48a4dc77f (diff) | |
download | scummvm-rg350-ac4d325e0d61b649026a5f5414f749697b285ccc.tar.gz scummvm-rg350-ac4d325e0d61b649026a5f5414f749697b285ccc.tar.bz2 scummvm-rg350-ac4d325e0d61b649026a5f5414f749697b285ccc.zip |
SCI: Add global g_sci pointer to the active SciEngine instance
svn-id: r48046
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/console.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/kevent.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/kfile.cpp | 26 | ||||
-rw-r--r-- | engines/sci/engine/kmisc.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/message.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/selector.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/selector.h | 2 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 12 | ||||
-rw-r--r-- | engines/sci/event.cpp | 2 | ||||
-rw-r--r-- | engines/sci/graphics/frameout.cpp | 2 | ||||
-rw-r--r-- | engines/sci/graphics/menu.cpp | 6 | ||||
-rw-r--r-- | engines/sci/graphics/palette.cpp | 4 | ||||
-rw-r--r-- | engines/sci/parser/grammar.cpp | 4 | ||||
-rw-r--r-- | engines/sci/parser/vocabulary.cpp | 8 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 10 | ||||
-rw-r--r-- | engines/sci/sci.h | 9 | ||||
-rw-r--r-- | engines/sci/sound/drivers/mididriver.h | 2 | ||||
-rw-r--r-- | engines/sci/sound/iterator/core.cpp | 2 | ||||
-rw-r--r-- | engines/sci/sound/iterator/iterator.cpp | 2 | ||||
-rw-r--r-- | engines/sci/sound/music.cpp | 6 | ||||
-rw-r--r-- | engines/sci/sound/soundcmd.cpp | 2 |
21 files changed, 64 insertions, 49 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index e1641d473f..424d7ca72b 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -1635,7 +1635,7 @@ bool Console::cmdGCObjects(int argc, const char **argv) { void _print_address(void * _, reg_t addr) { if (addr.segment) - ((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf(" %04x:%04x\n", PRINT_REG(addr)); + g_sci->getSciDebugger()->DebugPrintf(" %04x:%04x\n", PRINT_REG(addr)); } bool Console::cmdGCShowReachable(int argc, const char **argv) { diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index 3099c87ff4..7762417625 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -93,7 +93,7 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { // track left buttton clicks, if requested if (curEvent.type == SCI_EVENT_MOUSE_PRESS && curEvent.data == 1 && g_debug_track_mouse_clicks) { - ((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("Mouse clicked at %d, %d\n", + g_sci->getSciDebugger()->DebugPrintf("Mouse clicked at %d, %d\n", mousePos.x, mousePos.y); } @@ -125,7 +125,7 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { g_debugState.stopOnEvent = false; // A SCI event occured, and we have been asked to stop, so open the debug console - Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); con->DebugPrintf("SCI event occured: "); switch (curEvent.type) { case SCI_EVENT_QUIT: diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 09b03f538f..d6c95bda87 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -105,7 +105,7 @@ void file_open(EngineState *s, const char *filename, int mode) { filename += 2; Common::String englishName = s->getLanguageString(filename, K_LANG_ENGLISH); - const Common::String wrappedName = ((Sci::SciEngine*)g_engine)->wrapFilename(englishName); + const Common::String wrappedName = g_sci->wrapFilename(englishName); Common::SeekableReadStream *inFile = 0; Common::WriteStream *outFile = 0; Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); @@ -257,7 +257,7 @@ void listSavegames(Common::Array<SavegameDesc> &saves) { Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); // Load all saves - Common::StringList saveNames = saveFileMan->listSavefiles(((SciEngine *)g_engine)->getSavegamePattern()); + Common::StringList saveNames = saveFileMan->listSavefiles(g_sci->getSavegamePattern()); for (Common::StringList::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) { Common::String filename = *iter; @@ -294,7 +294,7 @@ bool Console::cmdListSaves(int argc, const char **argv) { Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); for (uint i = 0; i < saves.size(); i++) { - Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(saves[i].id); + Common::String filename = g_sci->getSavegameName(saves[i].id); Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { SavegameMetadata meta; @@ -405,7 +405,7 @@ reg_t kDeviceInfo(EngineState *s, int argc, reg_t *argv) { Common::Array<SavegameDesc> saves; listSavegames(saves); int savedir_nr = saves[savegame_id].id; - Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); + Common::String filename = g_sci->getSavegameName(savedir_nr); Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); saveFileMan->removeSavefile(filename); } @@ -462,7 +462,7 @@ reg_t kCheckSaveGame(EngineState *s, int argc, reg_t *argv) { } Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); - Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); + Common::String filename = g_sci->getSavegameName(savedir_nr); Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { // found a savegame file @@ -496,7 +496,7 @@ reg_t kGetSaveFiles(EngineState *s, int argc, reg_t *argv) { Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); for (uint i = 0; i < saves.size(); i++) { - Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(saves[i].id); + Common::String filename = g_sci->getSavegameName(saves[i].id); Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { // found a savegame file @@ -575,7 +575,7 @@ reg_t kSaveGame(EngineState *s, int argc, reg_t *argv) { return NULL_REG; } - Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_id); + Common::String filename = g_sci->getSavegameName(savedir_id); Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); Common::OutSaveFile *out; if (!(out = saveFileMan->openForSaving(filename))) { @@ -619,7 +619,7 @@ reg_t kRestoreGame(EngineState *s, int argc, reg_t *argv) { if (savedir_nr > -1) { Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); - Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); + Common::String filename = g_sci->getSavegameName(savedir_nr); Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { // found a savegame file @@ -677,7 +677,7 @@ reg_t DirSeeker::firstFile(const Common::String &mask, reg_t buffer, SegManager _outbuffer = buffer; // Prefix the mask - const Common::String wrappedMask = ((Sci::SciEngine*)g_engine)->wrapFilename(mask); + const Common::String wrappedMask = g_sci->wrapFilename(mask); // Obtain a list of all savefiles matching the given mask Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); @@ -696,7 +696,7 @@ reg_t DirSeeker::nextFile(SegManager *segMan) { const Common::String wrappedString = *_iter; // Strip the prefix - Common::String string = ((Sci::SciEngine*)g_engine)->unwrapFilename(wrappedString); + Common::String string = g_sci->unwrapFilename(wrappedString); if (string.size() > 12) string = Common::String(string.c_str(), 12); segMan->strcpy(_outbuffer, string.c_str()); @@ -795,10 +795,10 @@ reg_t kFileIO(EngineState *s, int argc, reg_t *argv) { Common::Array<SavegameDesc> saves; listSavegames(saves); int savedir_nr = saves[slotNum].id; - name = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); + name = g_sci->getSavegameName(savedir_nr); saveFileMan->removeSavefile(name); } else { - const Common::String wrappedName = ((Sci::SciEngine*)g_engine)->wrapFilename(name); + const Common::String wrappedName = g_sci->wrapFilename(name); saveFileMan->removeSavefile(wrappedName); } @@ -878,7 +878,7 @@ reg_t kFileIO(EngineState *s, int argc, reg_t *argv) { // Check for regular file bool exists = Common::File::exists(name); Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); - const Common::String wrappedName = ((Sci::SciEngine*)g_engine)->wrapFilename(name); + const Common::String wrappedName = g_sci->wrapFilename(name); if (!exists) exists = !saveFileMan->listSavefiles(name).empty(); diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index bd1cf587ea..01aa1fe6f8 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -306,7 +306,7 @@ enum kPlatformOps { }; reg_t kPlatform(EngineState *s, int argc, reg_t *argv) { - bool isWindows = ((SciEngine*)g_engine)->getPlatform() == Common::kPlatformWindows; + bool isWindows = g_sci->getPlatform() == Common::kPlatformWindows; if (argc == 0 && getSciVersion() < SCI_VERSION_2) { // This is called in KQ5CD with no parameters, where it seems to do some graphics diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index c55ac0b84f..5d72248939 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -135,7 +135,7 @@ public: }; bool MessageState::getRecord(CursorStack &stack, bool recurse, MessageRecord &record) { - Resource *res = ((SciEngine *)g_engine)->getResourceManager()->findResource(ResourceId(kResourceTypeMessage, stack.getModule()), 0); + Resource *res = g_sci->getResourceManager()->findResource(ResourceId(kResourceTypeMessage, stack.getModule()), 0); if (!res) { warning("Failed to open message resource %d", stack.getModule()); diff --git a/engines/sci/engine/selector.cpp b/engines/sci/engine/selector.cpp index 41e0c435af..8a859b1431 100644 --- a/engines/sci/engine/selector.cpp +++ b/engines/sci/engine/selector.cpp @@ -187,7 +187,7 @@ reg_t read_selector(SegManager *segMan, reg_t object, Selector selector_id) { void write_selector(SegManager *segMan, reg_t object, Selector selector_id, reg_t value) { ObjVarRef address; - if ((selector_id < 0) || (selector_id > (int)((SciEngine*)g_engine)->getKernel()->getSelectorNamesSize())) { + if ((selector_id < 0) || (selector_id > (int)g_sci->getKernel()->getSelectorNamesSize())) { warning("Attempt to write to invalid selector %d of" " object at %04x:%04x.", selector_id, PRINT_REG(object)); return; @@ -195,7 +195,7 @@ void write_selector(SegManager *segMan, reg_t object, Selector selector_id, reg_ if (lookup_selector(segMan, object, selector_id, &address, NULL) != kSelectorVariable) warning("Selector '%s' of object at %04x:%04x could not be" - " written to", ((SciEngine*)g_engine)->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object)); + " written to", g_sci->getKernel()->getSelectorName(selector_id).c_str(), PRINT_REG(object)); else *address.getPointer(segMan) = value; } diff --git a/engines/sci/engine/selector.h b/engines/sci/engine/selector.h index f74ec45213..427af7430a 100644 --- a/engines/sci/engine/selector.h +++ b/engines/sci/engine/selector.h @@ -46,7 +46,7 @@ enum SelectorInvocation { /** * Map a selector name to a selector id. Shortcut for accessing the selector cache. */ -#define SELECTOR(_slc_) (((SciEngine *)g_engine)->getKernel()->_selectorCache._slc_) +#define SELECTOR(_slc_) (g_sci->getKernel()->_selectorCache._slc_) //#define SELECTOR(_slc_) _slc_ /** diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 262773a0ed..aa7163929b 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -285,7 +285,7 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP Common::List<Breakpoint>::const_iterator bp; for (bp = s->_breakpoints.begin(); bp != s->_breakpoints.end(); ++bp) { if (bp->type == BREAK_EXPORT && bp->address == bpaddress) { - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); con->DebugPrintf("Break on script %d, export %d\n", script, pubfunct); g_debugState.debugging = true; breakpointWasHit = true; @@ -368,7 +368,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt cmplen = 256; if (bp->type == BREAK_SELECTOR && !strncmp(bp->name.c_str(), method_name, cmplen)) { - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); con->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj)); print_send_action = 1; breakpointWasHit = true; @@ -379,7 +379,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt } #ifdef VM_DEBUG_SEND - printf("Send to %04x:%04x, selector %04x (%s):", PRINT_REG(send_obj), selector, ((SciEngine *)g_engine)->getKernel()->getSelectorName(selector).c_str()); + printf("Send to %04x:%04x, selector %04x (%s):", PRINT_REG(send_obj), selector, g_sci->getKernel()->getSelectorName(selector).c_str()); #endif // VM_DEBUG_SEND ObjVarRef varp; @@ -816,7 +816,7 @@ void run_vm(EngineState *s, bool restoring) { script_debug(s, breakpointWasHit); breakpointWasHit = false; } - Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); if (con->isAttached()) { con->onFrame(); } @@ -1681,7 +1681,7 @@ static EngineState *_game_run(EngineState *&s) { int game_is_finished = 0; if (Common::isDebugChannelEnabled(kDebugLevelOnStartup)) - ((Sci::SciEngine*)g_engine)->getSciDebugger()->attach(); + g_sci->getSciDebugger()->attach(); do { s->_executionStackPosChanged = false; @@ -1738,7 +1738,7 @@ int game_run(EngineState **_s) { // Now: Register the first element on the execution stack- if (!send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base)) { - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); con->printObject(s->_gameObj); warning("Failed to run the game! Aborting..."); return 1; diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp index 0e6206627e..4f6201824e 100644 --- a/engines/sci/event.cpp +++ b/engines/sci/event.cpp @@ -175,7 +175,7 @@ sciEvent SciEvent::getFromScummVM() { // Debug console if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) { // Open debug console - Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); con->attach(); // Clear keyboard event diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp index 4f4b0a9aea..79cbc6c669 100644 --- a/engines/sci/graphics/frameout.cpp +++ b/engines/sci/graphics/frameout.cpp @@ -239,7 +239,7 @@ void GfxFrameout::kernelFrameout() { // TODO: rewrite this the "SCI2" way (i.e. implement the text buffer to draw inside kCreateTextBitmap) // This doesn't work for SCI2.1 games... if (getSciVersion() == SCI_VERSION_2) { - Kernel *kernel = ((SciEngine *)g_engine)->getKernel(); + Kernel *kernel = g_sci->getKernel(); if (lookup_selector(_segMan, itemEntry->object, kernel->_selectorCache.text, NULL, NULL) == kSelectorVariable) { Common::String text = _segMan->getString(GET_SEL32(_segMan, itemEntry->object, SELECTOR(text))); int16 fontRes = GET_SEL32V(_segMan, itemEntry->object, SELECTOR(font)); diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp index beeed27885..69b38df2e8 100644 --- a/engines/sci/graphics/menu.cpp +++ b/engines/sci/graphics/menu.cpp @@ -190,7 +190,7 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t if (separatorCount == tempPos - beginPos) { itemEntry->separatorLine = true; } else { - EngineState *s = ((SciEngine *)g_engine)->getEngineState(); // HACK: needed for strSplit() + EngineState *s = g_sci->getEngineState(); // HACK: needed for strSplit() itemEntry->text = s->strSplit(Common::String(content.c_str() + beginPos, tempPos - beginPos).c_str()); // LSL6 uses "Ctrl-" prefix string instead of ^ like all the other games do @@ -250,7 +250,7 @@ GuiMenuItemEntry *GfxMenu::findItem(uint16 menuId, uint16 itemId) { } void GfxMenu::kernelSetAttribute(uint16 menuId, uint16 itemId, uint16 attributeId, reg_t value) { - EngineState *s = ((SciEngine *)g_engine)->getEngineState(); // HACK: needed for strSplit() + EngineState *s = g_sci->getEngineState(); // HACK: needed for strSplit() GuiMenuItemEntry *itemEntry = findItem(menuId, itemId); if (!itemEntry) error("Tried to setAttribute() on non-existant menu-item %d:%d", menuId, itemId); @@ -391,7 +391,7 @@ reg_t GfxMenu::kernelSelect(reg_t eventObject) { case SCI_EVENT_SAID: // HACK: should be removed as soon as said() is cleaned up - s = ((SciEngine *)g_engine)->getEngineState(); + s = g_sci->getEngineState(); while (itemIterator != itemEnd) { itemEntry = *itemIterator; diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp index 3652605a44..09b51117e0 100644 --- a/engines/sci/graphics/palette.cpp +++ b/engines/sci/graphics/palette.cpp @@ -442,7 +442,7 @@ void GfxPalette::startPalVary(uint16 paletteId, uint16 ticks) { _palVaryId = paletteId; _palVaryStart = g_system->getMillis(); _palVaryEnd = _palVaryStart + ticks * 1000 / 60; - ((SciEngine*)g_engine)->getTimerManager()->installTimerProc(&palVaryCallback, 1000 / 60, this); + g_sci->getTimerManager()->installTimerProc(&palVaryCallback, 1000 / 60, this); } void GfxPalette::togglePalVary(bool pause) { @@ -453,7 +453,7 @@ void GfxPalette::togglePalVary(bool pause) { } void GfxPalette::stopPalVary() { - ((SciEngine*)g_engine)->getTimerManager()->removeTimerProc(&palVaryCallback); + g_sci->getTimerManager()->removeTimerProc(&palVaryCallback); _palVaryId = -1; // invalidate the target palette // HACK: just set the target palette diff --git a/engines/sci/parser/grammar.cpp b/engines/sci/parser/grammar.cpp index 9ee3b8aeaa..1f35bffbc4 100644 --- a/engines/sci/parser/grammar.cpp +++ b/engines/sci/parser/grammar.cpp @@ -355,7 +355,7 @@ ParseRuleList *Vocabulary::buildGNF(bool verbose) { int ntrules_nr; ParseRuleList *ntlist = NULL; ParseRuleList *tlist, *new_tlist; - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); for (uint i = 1; i < _parserBranches.size(); i++) { // branch rule 0 is treated specially ParseRule *rule = _vbuild_rule(&_parserBranches[i]); @@ -480,7 +480,7 @@ static int _vbpt_write_subexpression(parse_tree_node_t *nodes, int *pos, ParseRu } int Vocabulary::parseGNF(const ResultWordList &words, bool verbose) { - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); // Get the start rules: ParseRuleList *work = _vocab_clone_rule_list_by_id(_parserRules, _parserBranches[0].data[1]); ParseRuleList *results = NULL; diff --git a/engines/sci/parser/vocabulary.cpp b/engines/sci/parser/vocabulary.cpp index 2cf47f00c3..00448f5d51 100644 --- a/engines/sci/parser/vocabulary.cpp +++ b/engines/sci/parser/vocabulary.cpp @@ -448,7 +448,7 @@ bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, ch void Vocabulary::printSuffixes() const { char word_buf[256], alt_buf[256]; - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); int i = 0; for (SuffixList::const_iterator suf = _parserSuffixes.begin(); suf != _parserSuffixes.end(); ++suf) { @@ -463,7 +463,7 @@ void Vocabulary::printSuffixes() const { } void Vocabulary::printParserWords() const { - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); int j = 0; for (WordMap::iterator i = _parserWords.begin(); i != _parserWords.end(); ++i) { @@ -570,7 +570,7 @@ void Vocabulary::synonymizeTokens(ResultWordList &words) { } void Vocabulary::printParserNodes(int num) { - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); for (int i = 0; i < num; i++) { con->DebugPrintf(" Node %03x: ", i); @@ -584,7 +584,7 @@ void Vocabulary::printParserNodes(int num) { int Vocabulary::parseNodes(int *i, int *pos, int type, int nr, int argc, const char **argv) { int nextToken = 0, nextValue = 0, newPos = 0, oldPos = 0; - Console *con = ((SciEngine *)g_engine)->getSciDebugger(); + Console *con = g_sci->getSciDebugger(); if (type == kParseNil) return 0; diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 8b891c3fc8..14af399d65 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -54,12 +54,18 @@ namespace Sci { extern int g_loadFromLauncher; +SciEngine *g_sci = 0; + + class GfxDriver; SciEngine::SciEngine(OSystem *syst, const ADGameDescription *desc) : Engine(syst), _gameDescription(desc), _system(syst) { _console = NULL; + assert(g_sci = 0); + g_sci = this; + // Set up the engine specific debug levels Common::addDebugChannel(kDebugLevelError, "Error", "Script error debugging"); Common::addDebugChannel(kDebugLevelNodes, "Lists", "Lists and nodes debugging"); @@ -111,11 +117,11 @@ SciEngine::~SciEngine() { delete _vocabulary; delete _console; delete _resMan; + + g_sci = 0; } Common::Error SciEngine::run() { - // FIXME/TODO: Move some of the stuff below to init() - // Assign default values to the config manager, in case settings are missing ConfMan.registerDefault("undither", "true"); ConfMan.registerDefault("enable_fb01", "false"); diff --git a/engines/sci/sci.h b/engines/sci/sci.h index 31e8631fa8..c6a251cb7b 100644 --- a/engines/sci/sci.h +++ b/engines/sci/sci.h @@ -154,6 +154,15 @@ private: OSystem *_system; }; + +/** + * Global instance of the SciEngine class, similar to g_engine. + * This is a hackish way to make all central components available + * everywhere. Ideally, we would get rid of this again in the future, + * but for now it's a pragmatic and simple way to achieve the goal. + */ +extern SciEngine *g_sci; + /** * Convenience function to obtain the active SCI version. */ diff --git a/engines/sci/sound/drivers/mididriver.h b/engines/sci/sound/drivers/mididriver.h index ec67f8bb21..22b08e22d6 100644 --- a/engines/sci/sound/drivers/mididriver.h +++ b/engines/sci/sound/drivers/mididriver.h @@ -73,7 +73,7 @@ public: MidiPlayer(SciVersion version) : _reverb(0), _version(version) { } int open() { - ResourceManager *resMan = ((SciEngine *)g_engine)->getResourceManager(); // HACK + ResourceManager *resMan = g_sci->getResourceManager(); // HACK return open(resMan); } virtual int open(ResourceManager *resMan) { return _driver->open(); } diff --git a/engines/sci/sound/iterator/core.cpp b/engines/sci/sound/iterator/core.cpp index c7c9ace028..7e5b690c08 100644 --- a/engines/sci/sound/iterator/core.cpp +++ b/engines/sci/sound/iterator/core.cpp @@ -228,7 +228,7 @@ Common::Error SfxPlayer::init(ResourceManager *resMan, int expected_latency) { switch (musicDriver) { case MD_ADLIB: // FIXME: There's no Amiga sound option, so we hook it up to AdLib - if (((SciEngine *)g_engine)->getPlatform() == Common::kPlatformAmiga) + if (g_sci->getPlatform() == Common::kPlatformAmiga) _mididrv = MidiPlayer_Amiga_create(_soundVersion); else _mididrv = MidiPlayer_AdLib_create(_soundVersion); diff --git a/engines/sci/sound/iterator/iterator.cpp b/engines/sci/sound/iterator/iterator.cpp index d800b80a36..5d9d63e5af 100644 --- a/engines/sci/sound/iterator/iterator.cpp +++ b/engines/sci/sound/iterator/iterator.cpp @@ -144,7 +144,7 @@ void SongIteratorChannel::resetSynthChannels() { byte buf[5]; // FIXME: Evil hack - SfxState &sound = ((SciEngine*)g_engine)->getEngineState()->_sound; + SfxState &sound = g_sci->getEngineState()->_sound; for (int i = 0; i < MIDI_CHANNELS; i++) { if (playmask & (1 << i)) { diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp index ed007d0b8a..7915395e9a 100644 --- a/engines/sci/sound/music.cpp +++ b/engines/sci/sound/music.cpp @@ -67,7 +67,7 @@ void SciMusic::init() { // WORKAROUND: Default to MIDI in Amiga SCI1_EGA+ games as we don't support those patches yet. // We also don't yet support the 7.pat file of SCI1+ Mac games or SCI0 Mac patches, so we // default to MIDI in those games to let them run. - Common::Platform platform = ((SciEngine *)g_engine)->getPlatform(); + Common::Platform platform = g_sci->getPlatform(); if (getSciVersion() >= SCI_VERSION_2 || platform == Common::kPlatformMacintosh || (platform == Common::kPlatformAmiga && getSciVersion() >= SCI_VERSION_1_EGA)) midiType = MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI); @@ -77,7 +77,7 @@ void SciMusic::init() { switch (midiType) { case MD_ADLIB: // FIXME: There's no Amiga sound option, so we hook it up to AdLib - if (((SciEngine *)g_engine)->getPlatform() == Common::kPlatformAmiga) + if (g_sci->getPlatform() == Common::kPlatformAmiga) _pMidiDrv = MidiPlayer_Amiga_create(_soundVersion); else _pMidiDrv = MidiPlayer_AdLib_create(_soundVersion); @@ -199,7 +199,7 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) { delete pSnd->pStreamAud; byte flags = Audio::FLAG_UNSIGNED; // Amiga SCI1 games had signed sound data - if (_soundVersion >= SCI_VERSION_1_EARLY && ((SciEngine *)g_engine)->getPlatform() == Common::kPlatformAmiga) + if (_soundVersion >= SCI_VERSION_1_EARLY && g_sci->getPlatform() == Common::kPlatformAmiga) flags = 0; int endPart = track->digitalSampleEnd > 0 ? (track->digitalSampleSize - track->digitalSampleEnd) : 0; pSnd->pStreamAud = Audio::makeRawStream(channelData + track->digitalSampleStart, diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp index 318adf01c9..70e0ba5b0c 100644 --- a/engines/sci/sound/soundcmd.cpp +++ b/engines/sci/sound/soundcmd.cpp @@ -133,7 +133,7 @@ SoundCommandParser::SoundCommandParser(ResourceManager *resMan, SegManager *segM #ifdef USE_OLD_MUSIC_FUNCTIONS // The following hack is needed to ease the change from old to new sound code (because the new sound code does not use SfxState) - _state = &((SciEngine *)g_engine)->getEngineState()->_sound; // HACK + _state = &g_sci->getEngineState()->_sound; // HACK #endif #ifndef USE_OLD_MUSIC_FUNCTIONS |