[Scummvm-cvs-logs] SF.net SVN: scummvm:[51027] scummvm/trunk/engines/sci

m_kiewitz at users.sourceforge.net m_kiewitz at users.sourceforge.net
Mon Jul 19 15:50:07 CEST 2010


Revision: 51027
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51027&view=rev
Author:   m_kiewitz
Date:     2010-07-19 13:50:06 +0000 (Mon, 19 Jul 2010)

Log Message:
-----------
SCI: implement foreign vocabulary support

not fully working, extended chars do not work currently as input

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kparse.cpp
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/parser/vocabulary.cpp
    scummvm/trunk/engines/sci/parser/vocabulary.h
    scummvm/trunk/engines/sci/sci.cpp
    scummvm/trunk/engines/sci/sci.h

Modified: scummvm/trunk/engines/sci/engine/kparse.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kparse.cpp	2010-07-19 13:05:41 UTC (rev 51026)
+++ scummvm/trunk/engines/sci/engine/kparse.cpp	2010-07-19 13:50:06 UTC (rev 51027)
@@ -93,6 +93,7 @@
 	char *error;
 	ResultWordList words;
 	reg_t event = argv[1];
+	g_sci->checkVocabularySwitch();
 	Vocabulary *voc = g_sci->getVocabulary();
 	voc->parser_event = event;
 	reg_t params[2] = { voc->parser_base, stringpos };

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2010-07-19 13:05:41 UTC (rev 51026)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2010-07-19 13:50:06 UTC (rev 51027)
@@ -324,4 +324,16 @@
 	return retval;
 }
 
+void SciEngine::checkVocabularySwitch() {
+	uint16 parserLanguage = 1;
+	if (SELECTOR(parseLang) != -1)
+		parserLanguage = readSelectorValue(_gamestate->_segMan, _gameObj, SELECTOR(parseLang));
+		
+	if (parserLanguage != _vocabularyLanguage) {
+		delete _vocabulary;
+		_vocabulary = new Vocabulary(_resMan, parserLanguage > 1 ? true : false);
+		_vocabularyLanguage = parserLanguage;
+	}
+}
+
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/parser/vocabulary.cpp
===================================================================
--- scummvm/trunk/engines/sci/parser/vocabulary.cpp	2010-07-19 13:05:41 UTC (rev 51026)
+++ scummvm/trunk/engines/sci/parser/vocabulary.cpp	2010-07-19 13:50:06 UTC (rev 51027)
@@ -33,9 +33,8 @@
 
 namespace Sci {
 
-Vocabulary::Vocabulary(ResourceManager *resMan) : _resMan(resMan) {
+Vocabulary::Vocabulary(ResourceManager *resMan, bool foreign) : _resMan(resMan), _foreign(foreign) {
 	_parserRules = NULL;
-	_vocabVersion = kVocabularySCI0;
 
 	memset(_parserNodes, 0, sizeof(_parserNodes));
 	// Mark parse tree as unused
@@ -45,6 +44,23 @@
 	_synonyms.clear(); // No synonyms
 
 	debug(2, "Initializing vocabulary");
+	if (_resMan->testResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB))) {
+		_vocabVersion = kVocabularySCI0;
+		_resourceIdWords = VOCAB_RESOURCE_SCI0_MAIN_VOCAB;
+		_resourceIdSuffixes = VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB;
+		_resourceIdBranches = VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES;
+	} else {
+		warning("Could not find a main vocabulary, trying SCI01");
+		_vocabVersion = kVocabularySCI1;
+		_resourceIdWords = VOCAB_RESOURCE_SCI1_MAIN_VOCAB;
+		_resourceIdSuffixes = VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB;
+		_resourceIdBranches = VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES;
+		if (_foreign) {
+			_resourceIdWords += 10;
+			_resourceIdSuffixes += 10;
+			_resourceIdBranches += 10;
+		}
+	}
 
 	if (getSciVersion() <= SCI_VERSION_1_EGA && loadParserWords()) {
 		loadSuffixes();
@@ -72,16 +88,10 @@
 	int currentwordpos = 0;
 
 	// First try to load the SCI0 vocab resource.
-	Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB), 0);
+	Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdWords), 0);
 
 	if (!resource) {
-		warning("SCI0: Could not find a main vocabulary, trying SCI01");
-		resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB), 0);
-		_vocabVersion = kVocabularySCI1;
-	}
-
-	if (!resource) {
-		warning("SCI1: Could not find a main vocabulary");
+		warning("Could not find a main vocabulary");
 		return false; // NOT critical: SCI1 games and some demos don't have one!
 	}
 
@@ -175,13 +185,7 @@
 
 bool Vocabulary::loadSuffixes() {
 	// Determine if we can find a SCI1 suffix vocabulary first
-	Resource* resource = NULL;
-
-	if (_vocabVersion == kVocabularySCI0)
-		resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 1);
-	else
-		resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 1);
-
+	Resource* resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdSuffixes), 1);
 	if (!resource)
 		return false; // No vocabulary found
 
@@ -214,13 +218,7 @@
 }
 
 void Vocabulary::freeSuffixes() {
-	Resource* resource = NULL;
-
-	if (_vocabVersion == kVocabularySCI0)
-		resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB), 0);
-	else
-		resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB), 0);
-
+	Resource* resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdSuffixes), 0);
 	if (resource)
 		_resMan->unlockResource(resource);
 
@@ -228,13 +226,8 @@
 }
 
 bool Vocabulary::loadBranches() {
-	Resource *resource = NULL;
+	Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdBranches), 0);
 
-	if (_vocabVersion == kVocabularySCI0)
-		resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_PARSE_TREE_BRANCHES), 0);
-	else
-		resource = _resMan->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SCI1_PARSE_TREE_BRANCHES), 0);
-
 	_parserBranches.clear();
 
 	if (!resource)

Modified: scummvm/trunk/engines/sci/parser/vocabulary.h
===================================================================
--- scummvm/trunk/engines/sci/parser/vocabulary.h	2010-07-19 13:05:41 UTC (rev 51026)
+++ scummvm/trunk/engines/sci/parser/vocabulary.h	2010-07-19 13:50:06 UTC (rev 51027)
@@ -169,7 +169,7 @@
 
 class Vocabulary {
 public:
-	Vocabulary(ResourceManager *resMan);
+	Vocabulary(ResourceManager *resMan, bool foreign);
 	~Vocabulary();
 
 	/**
@@ -302,6 +302,11 @@
 	ResourceManager *_resMan;
 	VocabularyVersions _vocabVersion;
 
+	bool _foreign;
+	uint16 _resourceIdWords;
+	uint16 _resourceIdSuffixes;
+	uint16 _resourceIdBranches;
+
 	// Parser-related lists
 	SuffixList _parserSuffixes;
 	ParseRuleList *_parserRules; /**< GNF rules used in the parser algorithm */

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-07-19 13:05:41 UTC (rev 51026)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-07-19 13:50:06 UTC (rev 51027)
@@ -85,6 +85,7 @@
 	_gamestate = 0;
 	_kernel = 0;
 	_vocabulary = 0;
+	_vocabularyLanguage = -1;
 	_eventMan = 0;
 	_console = 0;
 
@@ -202,7 +203,7 @@
 	_kernel = new Kernel(_resMan, segMan);
 	_features = new GameFeatures(segMan, _kernel);
 	// Only SCI0 and SCI01 games used a parser
-	_vocabulary = (getSciVersion() <= SCI_VERSION_1_EGA) ? new Vocabulary(_resMan) : NULL;
+	_vocabulary = (getSciVersion() <= SCI_VERSION_1_EGA) ? new Vocabulary(_resMan, false) : NULL;
 	_audio = new AudioPlayer(_resMan);
 	_gamestate = new EngineState(segMan);
 	_eventMan = new EventManager(_resMan->detectFontExtended());

Modified: scummvm/trunk/engines/sci/sci.h
===================================================================
--- scummvm/trunk/engines/sci/sci.h	2010-07-19 13:05:41 UTC (rev 51026)
+++ scummvm/trunk/engines/sci/sci.h	2010-07-19 13:50:06 UTC (rev 51027)
@@ -267,6 +267,9 @@
 
 	Common::String getSciLanguageString(const char *str, kLanguage lang, kLanguage *lang2 = NULL) const;
 
+	// Check if vocabulary needs to get switched (in multilingual parser games)
+	void checkVocabularySwitch();
+
 	// Initializes ports and paint16 for non-sci32 games, also sets default palette
 	void initGraphics();
 
@@ -332,6 +335,7 @@
 	EngineState *_gamestate;
 	Kernel *_kernel;
 	Vocabulary *_vocabulary;
+	int16 _vocabularyLanguage;
 	EventManager *_eventMan;
 	reg_t _gameObj; /**< Pointer to the game object */
 	Console *_console;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list