SCI: storing game super class address now inside SciEngine

svn-id: r52311
This commit is contained in:
Martin Kiewitz 2010-08-23 20:29:13 +00:00
parent edea88cf54
commit 0c5561105c
4 changed files with 25 additions and 20 deletions

View file

@ -275,15 +275,8 @@ SciVersion GameFeatures::detectLofsType() {
return _lofsType;
}
// Find the "Game" object, super class of the actual game-object
const reg_t game = g_sci->getGameObject();
const Object *gameObject = _segMan->getObject(game);
reg_t gameSuperClass = NULL_REG;
if (gameObject) {
gameSuperClass = gameObject->getSuperClassSelector();
}
// Find a function of the game object which invokes lofsa/lofss
// Find a function of the "Game" object (which is the game super class) which invokes lofsa/lofss
reg_t gameSuperClass = g_sci->getGameSuperClassAddress();
bool found = false;
if (!gameSuperClass.isNull()) {
Common::String gameSuperClassName = _segMan->getObjectName(gameSuperClass);

View file

@ -251,7 +251,7 @@ kLanguage SciEngine::getSciLanguage() {
lang = K_LANG_ENGLISH;
if (SELECTOR(printLang) != -1) {
lang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(printLang));
lang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(printLang));
if ((getSciVersion() >= SCI_VERSION_1_1) || (lang == K_LANG_NONE)) {
// If language is set to none, we use the language from the game detector.
@ -292,7 +292,7 @@ kLanguage SciEngine::getSciLanguage() {
void SciEngine::setSciLanguage(kLanguage lang) {
if (SELECTOR(printLang) != -1)
writeSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(printLang), lang);
writeSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(printLang), lang);
}
void SciEngine::setSciLanguage() {
@ -304,7 +304,7 @@ Common::String SciEngine::strSplit(const char *str, const char *sep) {
kLanguage subLang = K_LANG_NONE;
if (SELECTOR(subtitleLang) != -1) {
subLang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(subtitleLang));
subLang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(subtitleLang));
}
kLanguage secondLang;
@ -327,7 +327,7 @@ Common::String SciEngine::strSplit(const char *str, const char *sep) {
void SciEngine::checkVocabularySwitch() {
uint16 parserLanguage = 1;
if (SELECTOR(parseLang) != -1)
parserLanguage = readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(parseLang));
parserLanguage = readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(parseLang));
if (parserLanguage != _vocabularyLanguage) {
delete _vocabulary;

View file

@ -201,7 +201,8 @@ Common::Error SciEngine::run() {
// Add the after market GM patches for the specified game, if they exist
_resMan->addNewGMPatch(_gameId);
_gameObj = _resMan->findGameObject();
_gameObjectAddress = _resMan->findGameObject();
_gameSuperClassAddress = NULL_REG;
SegManager *segMan = new SegManager(_resMan);
@ -212,6 +213,7 @@ Common::Error SciEngine::run() {
// Create debugger console. It requires GFX to be initialized
_console = new Console(this);
_kernel = new Kernel(_resMan, segMan);
_features = new GameFeatures(segMan, _kernel);
// Only SCI0, SCI01 and SCI1 EGA games used a parser
_vocabulary = (getSciVersion() <= SCI_VERSION_1_EGA) ? new Vocabulary(_resMan, false) : NULL;
@ -231,6 +233,14 @@ Common::Error SciEngine::run() {
return Common::kUnknownError;
}
// we try to find the super class address of the game object, we can't do that earlier
const Object *gameObject = segMan->getObject(_gameObjectAddress);
if (!gameObject) {
warning("Could not get game object, aborting...");
return Common::kUnknownError;
}
_gameSuperClassAddress = gameObject->getSuperClassSelector();
script_adjust_opcode_formats();
// Must be called after game_init(), as they use _features
@ -250,9 +260,9 @@ Common::Error SciEngine::run() {
if (selectedLanguage == Common::EN_ANY) {
// and english was selected as language
if (SELECTOR(printLang) != -1) // set text language to english
writeSelectorValue(segMan, _gameObj, SELECTOR(printLang), 1);
writeSelectorValue(segMan, _gameObjectAddress, SELECTOR(printLang), 1);
if (SELECTOR(parseLang) != -1) // and set parser language to english as well
writeSelectorValue(segMan, _gameObj, SELECTOR(parseLang), 1);
writeSelectorValue(segMan, _gameObjectAddress, SELECTOR(parseLang), 1);
}
}
@ -444,8 +454,8 @@ void SciEngine::initStackBaseWithSelector(Selector selector) {
_gamestate->stack_base[1] = NULL_REG;
// Register the first element on the execution stack
if (!send_selector(_gamestate, _gameObj, _gameObj, _gamestate->stack_base, 2, _gamestate->stack_base)) {
_console->printObject(_gameObj);
if (!send_selector(_gamestate, _gameObjectAddress, _gameObjectAddress, _gamestate->stack_base, 2, _gamestate->stack_base)) {
_console->printObject(_gameObjectAddress);
error("initStackBaseWithSelector: error while registering the first selector in the call stack");
}

View file

@ -233,7 +233,8 @@ public:
inline EngineState *getEngineState() const { return _gamestate; }
inline Vocabulary *getVocabulary() const { return _vocabulary; }
inline EventManager *getEventManager() const { return _eventMan; }
inline reg_t getGameObject() const { return _gameObj; }
inline reg_t getGameObject() const { return _gameObjectAddress; }
inline reg_t getGameSuperClassAddress() const { return _gameSuperClassAddress; }
Common::RandomSource &getRNG() { return _rng; }
@ -342,7 +343,8 @@ private:
Vocabulary *_vocabulary;
int16 _vocabularyLanguage;
EventManager *_eventMan;
reg_t _gameObj; /**< Pointer to the game object */
reg_t _gameObjectAddress; /**< Pointer to the game object */
reg_t _gameSuperClassAddress; // Address of the super class of the game object
Console *_console;
Common::RandomSource _rng;
};