aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2010-02-13 17:46:44 +0000
committerMax Horn2010-02-13 17:46:44 +0000
commitb9a11ddb0b69910418d0ccc8cf303a2e2a181f3a (patch)
tree277ec4eb1546916c8695f47e9bafb357916247bb
parent06021f79acfb32677e68b8697d5ba63059a6893d (diff)
downloadscummvm-rg350-b9a11ddb0b69910418d0ccc8cf303a2e2a181f3a.tar.gz
scummvm-rg350-b9a11ddb0b69910418d0ccc8cf303a2e2a181f3a.tar.bz2
scummvm-rg350-b9a11ddb0b69910418d0ccc8cf303a2e2a181f3a.zip
SCI: Move language related code from EngineState to SciEngine
svn-id: r48052
-rw-r--r--engines/sci/engine/game.cpp4
-rw-r--r--engines/sci/engine/kfile.cpp2
-rw-r--r--engines/sci/engine/kgraphics.cpp14
-rw-r--r--engines/sci/engine/kmenu.cpp4
-rw-r--r--engines/sci/engine/ksound.cpp2
-rw-r--r--engines/sci/engine/kstring.cpp2
-rw-r--r--engines/sci/engine/state.cpp28
-rw-r--r--engines/sci/engine/state.h32
-rw-r--r--engines/sci/graphics/menu.cpp6
-rw-r--r--engines/sci/sci.h31
10 files changed, 60 insertions, 65 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 52fc47c4d6..950041873e 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -285,7 +285,9 @@ int game_init(EngineState *s) {
#endif
// Load game language into printLang property of game object
- s->getLanguage();
+ // FIXME: It's evil to achieve this as a side effect of a getter.
+ // Much better to have an explicit init method for this.
+ g_sci->getSciLanguage();
return 0;
}
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index d6c95bda87..e54aaee051 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -104,7 +104,7 @@ void file_open(EngineState *s, const char *filename, int mode) {
if (filename[0] == '/' && filename[1] == '\\')
filename += 2;
- Common::String englishName = s->getLanguageString(filename, K_LANG_ENGLISH);
+ Common::String englishName = g_sci->getSciLanguageString(filename, K_LANG_ENGLISH);
const Common::String wrappedName = g_sci->wrapFilename(englishName);
Common::SeekableReadStream *inFile = 0;
Common::WriteStream *outFile = 0;
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 592d1d4fd0..67b03138ee 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -338,10 +338,10 @@ reg_t kTextSize(EngineState *s, int argc, reg_t *argv) {
#ifdef ENABLE_SCI32
if (g_sci->_gui32)
- g_sci->_gui32->textSize(s->strSplit(text.c_str(), sep).c_str(), font_nr, maxwidth, &textWidth, &textHeight);
+ g_sci->_gui32->textSize(g_sci->strSplit(text.c_str(), sep).c_str(), font_nr, maxwidth, &textWidth, &textHeight);
else
#endif
- g_sci->_gui->textSize(s->strSplit(text.c_str(), sep).c_str(), font_nr, maxwidth, &textWidth, &textHeight);
+ g_sci->_gui->textSize(g_sci->strSplit(text.c_str(), sep).c_str(), font_nr, maxwidth, &textWidth, &textHeight);
debugC(2, kDebugLevelStrings, "GetTextSize '%s' -> %dx%d", text.c_str(), textWidth, textHeight);
dest[2] = make_reg(0, textHeight);
@@ -782,13 +782,13 @@ void _k_GenericDrawControl(EngineState *s, reg_t controlObject, bool hilite) {
switch (type) {
case SCI_CONTROLS_TYPE_BUTTON:
debugC(2, kDebugLevelGraphics, "drawing button %04x:%04x to %d,%d", PRINT_REG(controlObject), x, y);
- g_sci->_gfxControls->kernelDrawButton(rect, controlObject, s->strSplit(text.c_str(), NULL).c_str(), fontId, style, hilite);
+ g_sci->_gfxControls->kernelDrawButton(rect, controlObject, g_sci->strSplit(text.c_str(), NULL).c_str(), fontId, style, hilite);
return;
case SCI_CONTROLS_TYPE_TEXT:
alignment = GET_SEL32V(s->_segMan, controlObject, SELECTOR(mode));
debugC(2, kDebugLevelGraphics, "drawing text %04x:%04x ('%s') to %d,%d, mode=%d", PRINT_REG(controlObject), text.c_str(), x, y, alignment);
- g_sci->_gfxControls->kernelDrawText(rect, controlObject, s->strSplit(text.c_str()).c_str(), fontId, alignment, style, hilite);
+ g_sci->_gfxControls->kernelDrawText(rect, controlObject, g_sci->strSplit(text.c_str()).c_str(), fontId, alignment, style, hilite);
return;
case SCI_CONTROLS_TYPE_TEXTEDIT:
@@ -796,7 +796,7 @@ void _k_GenericDrawControl(EngineState *s, reg_t controlObject, bool hilite) {
maxChars = GET_SEL32V(s->_segMan, controlObject, SELECTOR(max));
cursorPos = GET_SEL32V(s->_segMan, controlObject, SELECTOR(cursor));
debugC(2, kDebugLevelGraphics, "drawing edit control %04x:%04x (text %04x:%04x, '%s') to %d,%d", PRINT_REG(controlObject), PRINT_REG(textReference), text.c_str(), x, y);
- g_sci->_gfxControls->kernelDrawTextEdit(rect, controlObject, s->strSplit(text.c_str(), NULL).c_str(), fontId, mode, style, cursorPos, maxChars, hilite);
+ g_sci->_gfxControls->kernelDrawTextEdit(rect, controlObject, g_sci->strSplit(text.c_str(), NULL).c_str(), fontId, mode, style, cursorPos, maxChars, hilite);
return;
case SCI_CONTROLS_TYPE_ICON:
@@ -1044,7 +1044,7 @@ reg_t kNewWindow(EngineState *s, int argc, reg_t *argv) {
Common::String title;
if (argv[4 + argextra].segment) {
title = s->_segMan->getString(argv[4 + argextra]);
- title = s->strSplit(title.c_str(), NULL);
+ title = g_sci->strSplit(title.c_str(), NULL);
}
return g_sci->_gfxPorts->kernelNewWindow(rect1, rect2, style, priority, colorPen, colorBack, title.c_str());
@@ -1085,7 +1085,7 @@ reg_t kDisplay(EngineState *s, int argc, reg_t *argv) {
text = kernel_lookup_text(s, textp, index);
}
- return g_sci->_gfxPaint16->kernelDisplay(s->strSplit(text.c_str()).c_str(), argc, argv);
+ return g_sci->_gfxPaint16->kernelDisplay(g_sci->strSplit(text.c_str()).c_str(), argc, argv);
}
reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) {
diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp
index 631deffe3a..32d0bc1839 100644
--- a/engines/sci/engine/kmenu.cpp
+++ b/engines/sci/engine/kmenu.cpp
@@ -34,7 +34,7 @@
namespace Sci {
reg_t kAddMenu(EngineState *s, int argc, reg_t *argv) {
- Common::String title = s->strSplit(s->_segMan->getString(argv[0]).c_str());
+ Common::String title = g_sci->strSplit(s->_segMan->getString(argv[0]).c_str());
Common::String content = s->_segMan->getString(argv[1]);
g_sci->_gfxMenu->kernelAddEntry(title, content, argv[1]);
@@ -77,7 +77,7 @@ reg_t kDrawStatus(EngineState *s, int argc, reg_t *argv) {
// Sometimes this is called without giving text, if thats the case dont process it
text = s->_segMan->getString(textReference);
- g_sci->_gfxMenu->kernelDrawStatus(s->strSplit(text.c_str(), NULL).c_str(), colorPen, colorBack);
+ g_sci->_gfxMenu->kernelDrawStatus(g_sci->strSplit(text.c_str(), NULL).c_str(), colorPen, colorBack);
}
return s->r_acc;
}
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index c3d572c174..c5de72fc5a 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -150,7 +150,7 @@ reg_t kDoAudio(EngineState *s, int argc, reg_t *argv) {
if (language != -1)
g_sci->getResMan()->setAudioLanguage(language);
- return make_reg(0, s->getLanguage());
+ return make_reg(0, g_sci->getSciLanguage());
}
break;
case kSciAudioCD:
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 14b5ab6742..ad1811ece5 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -575,7 +575,7 @@ reg_t kStrSplit(EngineState *s, int argc, reg_t *argv) {
sep_str = s->_segMan->getString(argv[2]);
sep = sep_str.c_str();
}
- Common::String str = s->strSplit(format.c_str(), sep);
+ Common::String str = g_sci->strSplit(format.c_str(), sep);
// Make sure target buffer is large enough
SegmentRef buf_r = s->_segMan->dereference(argv[0]);
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index 4559ebd763..e78f7bce1d 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -89,7 +89,7 @@ void EngineState::setRoomNumber(uint16 roomNumber) {
script_000->_localsBlock->_locals[13] = make_reg(0, roomNumber);
}
-kLanguage EngineState::charToLanguage(const char c) const {
+static kLanguage charToLanguage(const char c) {
switch (c) {
case 'F':
return K_LANG_FRENCH;
@@ -109,7 +109,7 @@ kLanguage EngineState::charToLanguage(const char c) const {
}
}
-Common::String EngineState::getLanguageString(const char *str, kLanguage lang) const {
+Common::String SciEngine::getSciLanguageString(const char *str, kLanguage lang) const {
kLanguage secondLang = K_LANG_NONE;
const char *seeker = str;
@@ -138,15 +138,15 @@ Common::String EngineState::getLanguageString(const char *str, kLanguage lang) c
return Common::String(str);
}
-kLanguage EngineState::getLanguage() {
- kLanguage lang = (kLanguage)g_sci->getResMan()->getAudioLanguage();
+kLanguage SciEngine::getSciLanguage() {
+ kLanguage lang = (kLanguage)_resMan->getAudioLanguage();
if (lang != K_LANG_NONE)
return lang;
lang = K_LANG_ENGLISH;
- if (g_sci->getKernel()->_selectorCache.printLang != -1) {
- lang = (kLanguage)GET_SEL32V(_segMan, _gameObj, SELECTOR(printLang));
+ if (_kernel->_selectorCache.printLang != -1) {
+ lang = (kLanguage)GET_SEL32V(_gamestate->_segMan, _gamestate->_gameObj, 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.
@@ -157,7 +157,7 @@ kLanguage EngineState::getLanguage() {
// (essentially disabling runtime language switching).
// Note: only a limited number of multilanguage games have been tested
// so far, so this information may not be 100% accurate.
- switch (((Sci::SciEngine*)g_engine)->getLanguage()) {
+ switch (getLanguage()) {
case Common::FR_FRA:
lang = K_LANG_FRENCH;
break;
@@ -181,26 +181,26 @@ kLanguage EngineState::getLanguage() {
}
// Store language in printLang selector
- PUT_SEL32V(_segMan, _gameObj, SELECTOR(printLang), lang);
+ PUT_SEL32V(_gamestate->_segMan, _gamestate->_gameObj, SELECTOR(printLang), lang);
}
}
return lang;
}
-Common::String EngineState::strSplit(const char *str, const char *sep) {
- kLanguage lang = getLanguage();
+Common::String SciEngine::strSplit(const char *str, const char *sep) {
+ kLanguage lang = getSciLanguage();
kLanguage subLang = K_LANG_NONE;
- if (g_sci->getKernel()->_selectorCache.subtitleLang != -1) {
- subLang = (kLanguage)GET_SEL32V(_segMan, _gameObj, SELECTOR(subtitleLang));
+ if (_kernel->_selectorCache.subtitleLang != -1) {
+ subLang = (kLanguage)GET_SEL32V(_gamestate->_segMan, _gamestate->_gameObj, SELECTOR(subtitleLang));
}
- Common::String retval = getLanguageString(str, lang);
+ Common::String retval = getSciLanguageString(str, lang);
if ((subLang != K_LANG_NONE) && (sep != NULL)) {
retval += sep;
- retval += getLanguageString(str, subLang);
+ retval += getSciLanguageString(str, subLang);
}
return retval;
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index f7011a1a2c..fc80b91c2c 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -80,18 +80,6 @@ enum {
SCI_GAME_WAS_RESTARTED_AT_LEAST_ONCE = 4
};
-/** Supported languages */
-enum kLanguage {
- K_LANG_NONE = 0,
- K_LANG_ENGLISH = 1,
- K_LANG_FRENCH = 33,
- K_LANG_SPANISH = 34,
- K_LANG_ITALIAN = 39,
- K_LANG_GERMAN = 49,
- K_LANG_JAPANESE = 81,
- K_LANG_PORTUGUESE = 351
-};
-
class FileHandle {
public:
Common::String _name;
@@ -192,26 +180,6 @@ public:
byte _memorySegment[kMemorySegmentMax];
EngineState *successor; /**< Successor of this state: Used for restoring */
-
-
-public:
-
- /**
- * Processes a multilanguage string based on the current language settings and
- * returns a string that is ready to be displayed.
- * @param str the multilanguage string
- * @param sep optional seperator between main language and subtitle language,
- * if NULL is passed no subtitle will be added to the returned string
- * @return processed string
- */
- Common::String strSplit(const char *str, const char *sep = "\r----------\r");
-
- kLanguage getLanguage();
-
- Common::String getLanguageString(const char *str, kLanguage lang) const;
-
-private:
- kLanguage charToLanguage(const char c) const;
};
} // End of namespace Sci
diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp
index 69b38df2e8..581c9f6a44 100644
--- a/engines/sci/graphics/menu.cpp
+++ b/engines/sci/graphics/menu.cpp
@@ -190,8 +190,7 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
if (separatorCount == tempPos - beginPos) {
itemEntry->separatorLine = true;
} else {
- EngineState *s = g_sci->getEngineState(); // HACK: needed for strSplit()
- itemEntry->text = s->strSplit(Common::String(content.c_str() + beginPos, tempPos - beginPos).c_str());
+ itemEntry->text = g_sci->strSplit(Common::String(content.c_str() + beginPos, tempPos - beginPos).c_str());
// LSL6 uses "Ctrl-" prefix string instead of ^ like all the other games do
tempPtr = itemEntry->text.c_str();
@@ -250,7 +249,6 @@ GuiMenuItemEntry *GfxMenu::findItem(uint16 menuId, uint16 itemId) {
}
void GfxMenu::kernelSetAttribute(uint16 menuId, uint16 itemId, uint16 attributeId, reg_t value) {
- 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);
@@ -262,7 +260,7 @@ void GfxMenu::kernelSetAttribute(uint16 menuId, uint16 itemId, uint16 attributeI
itemEntry->saidVmPtr = value;
break;
case SCI_MENU_ATTRIBUTE_TEXT:
- itemEntry->text = s->strSplit(_segMan->getString(value).c_str());
+ itemEntry->text = g_sci->strSplit(_segMan->getString(value).c_str());
itemEntry->textVmPtr = value;
// We assume here that no script ever creates a separatorLine dynamically
break;
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index 2138b131cd..088b4312bf 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -100,8 +100,6 @@ enum kDebugLevels {
kDebugLevelOnStartup = 1 << 23
};
-extern const char *versionNames[];
-
/** SCI versions */
enum SciVersion {
SCI_VERSION_NONE,
@@ -124,6 +122,19 @@ enum MoveCountType {
kIncrementMoveCount
};
+/** Supported languages */
+enum kLanguage {
+ K_LANG_NONE = 0,
+ K_LANG_ENGLISH = 1,
+ K_LANG_FRENCH = 33,
+ K_LANG_SPANISH = 34,
+ K_LANG_ITALIAN = 39,
+ K_LANG_GERMAN = 49,
+ K_LANG_JAPANESE = 81,
+ K_LANG_PORTUGUESE = 351
+};
+
+
class SciEngine : public Engine {
friend class Console;
public:
@@ -166,6 +177,22 @@ public:
Common::String unwrapFilename(const Common::String &name) const;
public:
+
+ /**
+ * Processes a multilanguage string based on the current language settings and
+ * returns a string that is ready to be displayed.
+ * @param str the multilanguage string
+ * @param sep optional seperator between main language and subtitle language,
+ * if NULL is passed no subtitle will be added to the returned string
+ * @return processed string
+ */
+ Common::String strSplit(const char *str, const char *sep = "\r----------\r");
+
+ kLanguage getSciLanguage();
+
+ Common::String getSciLanguageString(const char *str, kLanguage lang) const;
+
+public:
GfxAnimate *_gfxAnimate; // Animate for 16-bit gfx
GfxCache *_gfxCache;
GfxCompare *_gfxCompare;