2009-02-27 02:23:40 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2009-02-27 02:23:40 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2009-02-27 02:23:40 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
2010-02-23 22:44:46 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
|
2009-10-28 13:20:30 +00:00
|
|
|
#include "sci/sci.h" // for INCLUDE_OLDGFX
|
2010-02-23 22:44:46 +00:00
|
|
|
#include "sci/debug.h" // for g_debug_sleeptime_factor
|
2012-06-13 11:00:58 +03:00
|
|
|
#include "sci/engine/file.h"
|
SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.
1. Fixes audio volumes syncing erroneously to ScummVM in games
that modify the audio volume without user action (e.g. SCI1.1
talkies that reduce music volume during speech playback). Now,
volumes will only be synchronised when the user interacts with
the game's audio settings. This mechanism works by looking for
a known volume control object in the stack, and only syncing
when the control object is present. (Ports and planes were
researched and found unreliable.)
2. Fixes audio syncing in SCI32 games that do not set game
volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
GK2, Phant1, and Torin.
3. Fixes speech/subtitles syncing in SCI32 games that do not use
global 90, like LSL6hires.
4. Fixes in-game volume controls in SCI32 games reflecting
outdated audio volumes when a change is made during the game
from the ScummVM launcher.
5. Fixes SCI32 games that would restore volumes from save games
or reset volumes on startup, which caused game volumes to be
out-of-sync with ScummVM when started.
6. ScummVM integration code for audio sync has been abstracted
into a new GuestAdditions class. This keeps the ScummVM-
specific code all in one place, with only small hooks into the
engine code. ScummVM integrated save/load code should probably
also go here in the future.
Fixes Trac#9700.
2017-01-26 13:18:41 -06:00
|
|
|
#include "sci/engine/guest_additions.h"
|
2010-06-23 15:23:37 +00:00
|
|
|
#include "sci/engine/kernel.h"
|
2009-02-27 02:23:40 +00:00
|
|
|
#include "sci/engine/state.h"
|
2010-01-29 11:03:54 +00:00
|
|
|
#include "sci/engine/selector.h"
|
2009-08-17 15:49:22 +00:00
|
|
|
#include "sci/engine/vm.h"
|
2009-08-30 14:53:58 +00:00
|
|
|
#include "sci/engine/script.h"
|
2009-10-10 02:16:23 +00:00
|
|
|
#include "sci/engine/message.h"
|
2009-02-27 02:23:40 +00:00
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2010-04-19 00:13:01 +00:00
|
|
|
// Maps half-width single-byte SJIS to full-width double-byte SJIS
|
|
|
|
// Note: SSCI maps 0x5C (the Yen symbol) to 0x005C, which terminates
|
|
|
|
// the string with the leading 0x00 byte. We map Yen to 0x818F.
|
|
|
|
static const uint16 s_halfWidthSJISMap[256] = {
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x81A8, 0x81A9, 0x81AA, 0x81AB,
|
|
|
|
0x8140, 0x8149, 0x818D, 0x8194, 0x8190, 0x8193, 0x8195, 0x818C,
|
|
|
|
0x8169, 0x816A, 0x8196, 0x817B, 0x8143, 0x817C, 0x8144, 0x815E,
|
|
|
|
0x824F, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256,
|
|
|
|
0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181, 0x8184, 0x8148,
|
|
|
|
0x8197, 0x8260, 0x8261, 0x8262, 0x8263, 0x8264, 0x8265, 0x8266,
|
|
|
|
0x8267, 0x8268, 0x8269, 0x826A, 0x826B, 0x826C, 0x826D, 0x826E,
|
|
|
|
0x826F, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276,
|
|
|
|
0x8277, 0x8278, 0x8279, 0x816D, 0x818F /* 0x005C */, 0x816E, 0x814F, 0x8151,
|
|
|
|
0x8280, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287,
|
|
|
|
0x8288, 0x8289, 0x828A, 0x828B, 0x828C, 0x828D, 0x828E, 0x828F,
|
|
|
|
0x8290, 0x8291, 0x8292, 0x8293, 0x8294, 0x8295, 0x8296, 0x8297,
|
|
|
|
0x8298, 0x8299, 0x829A, 0x816F, 0x8162, 0x8170, 0x8160, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0x8140, 0x8142, 0x8175, 0x8176, 0x8141, 0x8145, 0x8392, 0x8340,
|
|
|
|
0x8342, 0x8344, 0x8346, 0x8348, 0x8383, 0x8385, 0x8387, 0x8362,
|
|
|
|
0x815C, 0x8341, 0x8343, 0x8345, 0x8347, 0x8349, 0x834A, 0x834C,
|
|
|
|
0x834E, 0x8350, 0x8352, 0x8354, 0x8356, 0x8358, 0x835A, 0x835C,
|
|
|
|
0x835E, 0x8360, 0x8363, 0x8365, 0x8367, 0x8369, 0x836A, 0x836B,
|
|
|
|
0x836C, 0x836D, 0x836E, 0x8371, 0x8374, 0x8377, 0x837A, 0x837D,
|
|
|
|
0x837E, 0x8380, 0x8381, 0x8382, 0x8384, 0x8386, 0x8388, 0x8389,
|
|
|
|
0x838A, 0x838B, 0x838C, 0x838D, 0x838F, 0x8393, 0x814A, 0x814B,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
};
|
|
|
|
|
2010-06-01 15:11:20 +00:00
|
|
|
EngineState::EngineState(SegManager *segMan)
|
2012-06-13 11:00:58 +03:00
|
|
|
: _segMan(segMan),
|
|
|
|
_dirseeker() {
|
2009-02-27 02:23:40 +00:00
|
|
|
|
2010-06-01 15:48:17 +00:00
|
|
|
reset(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
EngineState::~EngineState() {
|
|
|
|
delete _msgState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EngineState::reset(bool isRestoring) {
|
|
|
|
if (!isRestoring) {
|
|
|
|
_memorySegmentSize = 0;
|
|
|
|
_fileHandles.resize(5);
|
2010-06-08 21:05:46 +00:00
|
|
|
abortScriptProcessing = kAbortNone;
|
SCI: Improve audio volume & settings sync code
This patch includes enhancements to the ScummVM integration with
SCI engine, with particular focus on SCI32 support.
1. Fixes audio volumes syncing erroneously to ScummVM in games
that modify the audio volume without user action (e.g. SCI1.1
talkies that reduce music volume during speech playback). Now,
volumes will only be synchronised when the user interacts with
the game's audio settings. This mechanism works by looking for
a known volume control object in the stack, and only syncing
when the control object is present. (Ports and planes were
researched and found unreliable.)
2. Fixes audio syncing in SCI32 games that do not set game
volumes through kDoSoundMasterVolume/kDoAudioVolume, like GK1,
GK2, Phant1, and Torin.
3. Fixes speech/subtitles syncing in SCI32 games that do not use
global 90, like LSL6hires.
4. Fixes in-game volume controls in SCI32 games reflecting
outdated audio volumes when a change is made during the game
from the ScummVM launcher.
5. Fixes SCI32 games that would restore volumes from save games
or reset volumes on startup, which caused game volumes to be
out-of-sync with ScummVM when started.
6. ScummVM integration code for audio sync has been abstracted
into a new GuestAdditions class. This keeps the ScummVM-
specific code all in one place, with only small hooks into the
engine code. ScummVM integrated save/load code should probably
also go here in the future.
Fixes Trac#9700.
2017-01-26 13:18:41 -06:00
|
|
|
} else {
|
|
|
|
g_sci->_guestAdditions->reset();
|
2010-06-01 15:48:17 +00:00
|
|
|
}
|
2009-02-27 02:23:40 +00:00
|
|
|
|
2017-02-04 12:09:31 -06:00
|
|
|
_delayedRestoreGameId = -1;
|
2015-04-26 09:08:46 +02:00
|
|
|
|
2010-06-10 11:18:10 +00:00
|
|
|
executionStackBase = 0;
|
2010-06-08 21:21:19 +00:00
|
|
|
_executionStackPosChanged = false;
|
2010-06-15 09:11:26 +00:00
|
|
|
stack_base = 0;
|
|
|
|
stack_top = 0;
|
2010-06-08 21:21:19 +00:00
|
|
|
|
|
|
|
r_acc = NULL_REG;
|
|
|
|
r_prev = NULL_REG;
|
2011-03-27 18:13:42 +03:00
|
|
|
r_rest = 0;
|
2010-06-08 21:21:19 +00:00
|
|
|
|
2010-06-10 11:18:10 +00:00
|
|
|
lastWaitTime = 0;
|
2009-02-27 02:23:40 +00:00
|
|
|
|
2010-06-10 11:43:20 +00:00
|
|
|
gcCountDown = 0;
|
2009-02-27 02:23:40 +00:00
|
|
|
|
2017-05-06 21:23:23 -05:00
|
|
|
#ifdef ENABLE_SCI32
|
SCI32: Detect and handle tight loops around kGetEvent
In SSCI, mouse events are received through a hardware interrupt
and the cursor is drawn directly to the graphics card by the
interrupt handler. This allows game scripts to omit calls to
kFrameOut without stopping the mouse cursor from being redrawn
in response to mouse movement.
ScummVM, in contrast, needs to poll for events and submit screen
updates explicitly from the main thread. Submitting screen updates
may block on vsync, which means that this call should really only
be made once per frame, just after the game has finished updating
its back buffer. The closest signal in SCI32 for having completed
drawing a frame is the kFrameOut call, so this is where the
update is submitted (by calling OSystem::updateScreen).
The problem with the approach in ScummVM is that, even though the
mouse position is being updated (by calls to kGetEvent) and drawn
to the backend's back buffer (by GfxCursor32::drawToHardware),
OSystem::updateScreen is never called during game loops that omit
calls to kFrameOut.
This commit introduces a workaround that looks at the number of
times kGetEvent is called between calls to kFrameOut. If the
number of kGetEvent calls is higher than usual (where "usual"
seems to be 0 or 1), we assume that the game is running one of
these tight event loops, and kGetEvent starts calling
OSystem::updateScreen until the next kFrameOut call. We also
then start throttling the calls to kGetEvent to keep CPU usage
down. This fixes at least two such known loops:
1. When interacting with the menu bar at the top of the screen
in LSL6hires;
2. When restoring a game in Phant2 and sitting on the "click mouse"
screen.
A similar workaround may also be needed for kGetTime, though loops
around kGetTime should preferably be replaced using a script patch
to call kWait instead.
2017-05-06 16:37:11 -05:00
|
|
|
_eventCounter = 0;
|
2017-05-06 21:23:23 -05:00
|
|
|
#endif
|
2010-01-17 18:41:28 +00:00
|
|
|
_throttleLastTime = 0;
|
|
|
|
_throttleTrigger = false;
|
2010-12-26 15:28:02 +00:00
|
|
|
_gameIsBenchmarking = false;
|
2009-08-17 15:49:22 +00:00
|
|
|
|
2010-07-12 22:26:48 +00:00
|
|
|
_lastSaveVirtualId = SAVEGAMEID_OFFICIALRANGE_START;
|
|
|
|
_lastSaveNewId = 0;
|
|
|
|
|
2010-08-29 15:13:25 +00:00
|
|
|
_chosenQfGImportItem = 0;
|
|
|
|
|
2010-08-31 15:50:46 +00:00
|
|
|
_cursorWorkaroundActive = false;
|
|
|
|
|
2010-06-10 11:18:10 +00:00
|
|
|
scriptStepCounter = 0;
|
|
|
|
scriptGCInterval = GC_INTERVAL;
|
2010-12-22 13:51:35 +00:00
|
|
|
|
|
|
|
_videoState.reset();
|
2009-03-15 20:31:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-10 22:27:28 +00:00
|
|
|
void EngineState::speedThrottler(uint32 neededSleep) {
|
|
|
|
if (_throttleTrigger) {
|
|
|
|
uint32 curTime = g_system->getMillis();
|
|
|
|
uint32 duration = curTime - _throttleLastTime;
|
|
|
|
|
|
|
|
if (duration < neededSleep) {
|
|
|
|
g_sci->sleep(neededSleep - duration);
|
|
|
|
_throttleLastTime = g_system->getMillis();
|
|
|
|
} else {
|
|
|
|
_throttleLastTime = curTime;
|
|
|
|
}
|
|
|
|
_throttleTrigger = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-23 22:44:46 +00:00
|
|
|
void EngineState::wait(int16 ticks) {
|
2010-06-09 07:59:42 +00:00
|
|
|
uint32 time = g_system->getMillis();
|
2010-06-10 11:18:10 +00:00
|
|
|
r_acc = make_reg(0, ((long)time - (long)lastWaitTime) * 60 / 1000);
|
|
|
|
lastWaitTime = time;
|
2010-02-23 22:44:46 +00:00
|
|
|
|
|
|
|
ticks *= g_debug_sleeptime_factor;
|
2010-06-17 23:10:37 +00:00
|
|
|
g_sci->sleep(ticks * 1000 / 60);
|
2010-02-23 22:44:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 09:17:48 +00:00
|
|
|
void EngineState::initGlobals() {
|
|
|
|
Script *script_000 = _segMan->getScript(1);
|
2011-06-20 00:59:48 +02:00
|
|
|
|
2011-11-05 02:53:08 +02:00
|
|
|
if (script_000->getLocalsCount() == 0)
|
2010-06-09 09:17:48 +00:00
|
|
|
error("Script 0 has no locals block");
|
|
|
|
|
2011-11-05 02:53:08 +02:00
|
|
|
variablesSegment[VAR_GLOBAL] = script_000->getLocalsSegment();
|
|
|
|
variablesBase[VAR_GLOBAL] = variables[VAR_GLOBAL] = script_000->getLocalsBegin();
|
|
|
|
variablesMax[VAR_GLOBAL] = script_000->getLocalsCount();
|
2010-06-09 09:17:48 +00:00
|
|
|
}
|
|
|
|
|
2009-06-04 20:50:51 +00:00
|
|
|
uint16 EngineState::currentRoomNumber() const {
|
2016-09-26 19:28:51 -05:00
|
|
|
return variables[VAR_GLOBAL][kGlobalVarNewRoomNo].toUint16();
|
2009-06-04 20:50:51 +00:00
|
|
|
}
|
2009-03-15 20:31:29 +00:00
|
|
|
|
2010-01-03 15:08:26 +00:00
|
|
|
void EngineState::setRoomNumber(uint16 roomNumber) {
|
2016-09-26 19:28:51 -05:00
|
|
|
variables[VAR_GLOBAL][kGlobalVarNewRoomNo] = make_reg(0, roomNumber);
|
2010-01-03 15:08:26 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 16:44:36 +00:00
|
|
|
void EngineState::shrinkStackToBase() {
|
2010-06-27 23:20:08 +00:00
|
|
|
if (_executionStack.size() > 0) {
|
|
|
|
uint size = executionStackBase + 1;
|
|
|
|
assert(_executionStack.size() >= size);
|
|
|
|
Common::List<ExecStack>::iterator iter = _executionStack.begin();
|
|
|
|
for (uint i = 0; i < size; ++i)
|
|
|
|
++iter;
|
|
|
|
_executionStack.erase(iter, _executionStack.end());
|
|
|
|
}
|
2010-05-23 16:44:36 +00:00
|
|
|
}
|
|
|
|
|
2010-02-13 17:46:44 +00:00
|
|
|
static kLanguage charToLanguage(const char c) {
|
2009-06-24 19:12:45 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'F':
|
|
|
|
return K_LANG_FRENCH;
|
|
|
|
case 'S':
|
|
|
|
return K_LANG_SPANISH;
|
|
|
|
case 'I':
|
|
|
|
return K_LANG_ITALIAN;
|
|
|
|
case 'G':
|
|
|
|
return K_LANG_GERMAN;
|
|
|
|
case 'J':
|
|
|
|
case 'j':
|
|
|
|
return K_LANG_JAPANESE;
|
|
|
|
case 'P':
|
|
|
|
return K_LANG_PORTUGUESE;
|
|
|
|
default:
|
|
|
|
return K_LANG_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
Common::String SciEngine::getSciLanguageString(const Common::String &str, kLanguage requestedLanguage, kLanguage *secondaryLanguage, uint16 *languageSplitter) const {
|
|
|
|
kLanguage foundLanguage = K_LANG_NONE;
|
2014-12-27 11:10:14 +01:00
|
|
|
const byte *textPtr = (const byte *)str.c_str();
|
2014-11-04 22:01:21 +01:00
|
|
|
byte curChar = 0;
|
|
|
|
byte curChar2 = 0;
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
while (1) {
|
|
|
|
curChar = *textPtr;
|
|
|
|
if (!curChar)
|
|
|
|
break;
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
if ((curChar == '%') || (curChar == '#')) {
|
|
|
|
curChar2 = *(textPtr + 1);
|
|
|
|
foundLanguage = charToLanguage(curChar2);
|
|
|
|
|
|
|
|
if (foundLanguage != K_LANG_NONE) {
|
|
|
|
// Return language splitter
|
|
|
|
if (languageSplitter)
|
|
|
|
*languageSplitter = curChar | ( curChar2 << 8 );
|
|
|
|
// Return the secondary language found in the string
|
|
|
|
if (secondaryLanguage)
|
|
|
|
*secondaryLanguage = foundLanguage;
|
2009-06-24 19:12:45 +00:00
|
|
|
break;
|
2014-11-04 22:01:21 +01:00
|
|
|
}
|
2009-06-24 19:12:45 +00:00
|
|
|
}
|
2014-11-04 22:01:21 +01:00
|
|
|
textPtr++;
|
2009-06-24 19:12:45 +00:00
|
|
|
}
|
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
if (foundLanguage == requestedLanguage) {
|
|
|
|
if (curChar2 == 'J') {
|
2010-04-19 00:13:01 +00:00
|
|
|
// Japanese including Kanji, displayed with system font
|
|
|
|
// Convert half-width characters to full-width equivalents
|
|
|
|
Common::String fullWidth;
|
2014-11-02 15:44:22 +01:00
|
|
|
uint16 mappedChar;
|
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
textPtr += 2; // skip over language splitter
|
2014-11-02 15:44:22 +01:00
|
|
|
|
|
|
|
while (1) {
|
2014-11-04 22:01:21 +01:00
|
|
|
curChar = *textPtr;
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2014-11-02 15:44:22 +01:00
|
|
|
switch (curChar) {
|
|
|
|
case 0: // Terminator NUL
|
|
|
|
return fullWidth;
|
|
|
|
case '\\':
|
|
|
|
// "\n", "\N", "\r" and "\R" were overwritten with SPACE + 0x0D in PC-9801 SSCI
|
|
|
|
// inside GetLongest() (text16). We do it here, because it's much cleaner and
|
|
|
|
// we have to process the text here anyway.
|
|
|
|
// Occurs for example in Police Quest 2 intro
|
2014-11-04 22:01:21 +01:00
|
|
|
curChar2 = *(textPtr + 1);
|
2014-11-02 15:44:22 +01:00
|
|
|
switch (curChar2) {
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
|
|
|
fullWidth += ' ';
|
|
|
|
fullWidth += 0x0D; // CR
|
2014-11-04 22:01:21 +01:00
|
|
|
textPtr += 2;
|
2014-11-02 15:44:22 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-10-09 14:59:58 +02:00
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
textPtr++;
|
2010-04-19 00:13:01 +00:00
|
|
|
|
2014-11-02 15:44:22 +01:00
|
|
|
mappedChar = s_halfWidthSJISMap[curChar];
|
2010-04-19 00:13:01 +00:00
|
|
|
if (mappedChar) {
|
|
|
|
fullWidth += mappedChar >> 8;
|
|
|
|
fullWidth += mappedChar & 0xFF;
|
|
|
|
} else {
|
|
|
|
// Copy double-byte character
|
2014-11-04 22:01:21 +01:00
|
|
|
curChar2 = *(textPtr++);
|
2014-11-02 15:44:22 +01:00
|
|
|
if (!curChar) {
|
|
|
|
error("SJIS character %02X is missing second byte", curChar);
|
2010-04-19 00:13:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-02 15:44:22 +01:00
|
|
|
fullWidth += curChar;
|
|
|
|
fullWidth += curChar2;
|
2010-04-19 00:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2014-11-04 22:01:21 +01:00
|
|
|
return Common::String((const char *)(textPtr + 2));
|
2010-04-19 00:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-24 19:12:45 +00:00
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
if (curChar)
|
|
|
|
return Common::String(str.c_str(), (const char *)textPtr - str.c_str());
|
|
|
|
|
|
|
|
return str;
|
2009-06-24 19:12:45 +00:00
|
|
|
}
|
|
|
|
|
2010-02-13 17:46:44 +00:00
|
|
|
kLanguage SciEngine::getSciLanguage() {
|
|
|
|
kLanguage lang = (kLanguage)_resMan->getAudioLanguage();
|
2010-01-31 22:14:35 +00:00
|
|
|
if (lang != K_LANG_NONE)
|
|
|
|
return lang;
|
|
|
|
|
|
|
|
lang = K_LANG_ENGLISH;
|
2009-08-10 18:37:47 +00:00
|
|
|
|
2010-06-10 09:18:57 +00:00
|
|
|
if (SELECTOR(printLang) != -1) {
|
2010-08-23 20:29:13 +00:00
|
|
|
lang = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(printLang));
|
2009-08-10 18:37:47 +00:00
|
|
|
|
2010-02-01 13:27:20 +00:00
|
|
|
if ((getSciVersion() >= SCI_VERSION_1_1) || (lang == K_LANG_NONE)) {
|
2009-08-10 18:37:47 +00:00
|
|
|
// If language is set to none, we use the language from the game detector.
|
|
|
|
// SSCI reads this from resource.cfg (early games do not have a language
|
|
|
|
// setting in resource.cfg, but instead have the secondary language number
|
|
|
|
// hardcoded in the game script).
|
|
|
|
// SCI1.1 games always use the language setting from the config file
|
|
|
|
// (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.
|
2010-02-13 17:46:44 +00:00
|
|
|
switch (getLanguage()) {
|
2009-08-10 18:37:47 +00:00
|
|
|
case Common::FR_FRA:
|
|
|
|
lang = K_LANG_FRENCH;
|
|
|
|
break;
|
|
|
|
case Common::ES_ESP:
|
|
|
|
lang = K_LANG_SPANISH;
|
|
|
|
break;
|
|
|
|
case Common::IT_ITA:
|
|
|
|
lang = K_LANG_ITALIAN;
|
|
|
|
break;
|
|
|
|
case Common::DE_DEU:
|
|
|
|
lang = K_LANG_GERMAN;
|
|
|
|
break;
|
|
|
|
case Common::JA_JPN:
|
|
|
|
lang = K_LANG_JAPANESE;
|
|
|
|
break;
|
|
|
|
case Common::PT_BRA:
|
|
|
|
lang = K_LANG_PORTUGUESE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lang = K_LANG_ENGLISH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:18:10 +00:00
|
|
|
void SciEngine::setSciLanguage(kLanguage lang) {
|
2010-06-10 14:02:20 +00:00
|
|
|
if (SELECTOR(printLang) != -1)
|
2010-08-23 20:29:13 +00:00
|
|
|
writeSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(printLang), lang);
|
2010-06-10 11:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SciEngine::setSciLanguage() {
|
|
|
|
setSciLanguage(getSciLanguage());
|
|
|
|
}
|
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
Common::String SciEngine::strSplitLanguage(const char *str, uint16 *languageSplitter, const char *sep) {
|
|
|
|
kLanguage activeLanguage = getSciLanguage();
|
|
|
|
kLanguage subtitleLanguage = K_LANG_NONE;
|
2009-06-24 19:12:45 +00:00
|
|
|
|
2010-11-17 14:03:14 +00:00
|
|
|
if (SELECTOR(subtitleLang) != -1)
|
2014-11-04 22:01:21 +01:00
|
|
|
subtitleLanguage = (kLanguage)readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(subtitleLang));
|
2009-06-24 19:26:06 +00:00
|
|
|
|
2014-11-04 22:01:21 +01:00
|
|
|
kLanguage foundLanguage;
|
|
|
|
Common::String retval = getSciLanguageString(str, activeLanguage, &foundLanguage, languageSplitter);
|
2009-06-24 19:12:45 +00:00
|
|
|
|
2010-04-18 00:56:04 +00:00
|
|
|
// Don't add subtitle when separator is not set, subtitle language is not set, or
|
|
|
|
// string contains only one language
|
2014-11-04 22:01:21 +01:00
|
|
|
if ((sep == NULL) || (subtitleLanguage == K_LANG_NONE) || (foundLanguage == K_LANG_NONE))
|
2010-04-18 00:56:04 +00:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
// Add subtitle, unless the subtitle language doesn't match the languages in the string
|
2014-11-04 22:01:21 +01:00
|
|
|
if ((subtitleLanguage == K_LANG_ENGLISH) || (subtitleLanguage == foundLanguage)) {
|
2009-06-24 19:12:45 +00:00
|
|
|
retval += sep;
|
2014-11-04 22:01:21 +01:00
|
|
|
retval += getSciLanguageString(str, subtitleLanguage);
|
2009-06-24 19:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-07-19 13:50:06 +00:00
|
|
|
void SciEngine::checkVocabularySwitch() {
|
|
|
|
uint16 parserLanguage = 1;
|
|
|
|
if (SELECTOR(parseLang) != -1)
|
2010-08-23 20:29:13 +00:00
|
|
|
parserLanguage = readSelectorValue(_gamestate->_segMan, _gameObjectAddress, SELECTOR(parseLang));
|
2011-06-20 00:59:48 +02:00
|
|
|
|
2010-07-19 13:50:06 +00:00
|
|
|
if (parserLanguage != _vocabularyLanguage) {
|
|
|
|
delete _vocabulary;
|
|
|
|
_vocabulary = new Vocabulary(_resMan, parserLanguage > 1 ? true : false);
|
2010-07-19 15:30:27 +00:00
|
|
|
_vocabulary->reset();
|
2010-07-19 13:50:06 +00:00
|
|
|
_vocabularyLanguage = parserLanguage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-28 16:20:37 -05:00
|
|
|
SciCallOrigin EngineState::getCurrentCallOrigin() const {
|
|
|
|
// IMPORTANT: This method must always return values that match *exactly* the
|
|
|
|
// values in the workaround tables in workarounds.cpp, or workarounds will
|
|
|
|
// be broken
|
|
|
|
|
|
|
|
Common::String curObjectName = _segMan->getObjectName(xs->sendp);
|
|
|
|
Common::String curMethodName;
|
|
|
|
const Script *localScript = _segMan->getScriptIfLoaded(xs->local_segment);
|
|
|
|
int curScriptNr = localScript->getScriptNumber();
|
|
|
|
|
2017-02-03 09:58:57 -06:00
|
|
|
Selector debugSelector = xs->debugSelector;
|
|
|
|
int debugExportId = xs->debugExportId;
|
|
|
|
|
2016-08-28 16:20:37 -05:00
|
|
|
if (xs->debugLocalCallOffset != -1) {
|
|
|
|
// if lastcall was actually a local call search back for a real call
|
|
|
|
Common::List<ExecStack>::const_iterator callIterator = _executionStack.end();
|
|
|
|
while (callIterator != _executionStack.begin()) {
|
|
|
|
callIterator--;
|
|
|
|
const ExecStack &loopCall = *callIterator;
|
2017-02-03 09:58:57 -06:00
|
|
|
if (loopCall.debugSelector != -1 || loopCall.debugExportId != -1) {
|
|
|
|
debugSelector = loopCall.debugSelector;
|
|
|
|
debugExportId = loopCall.debugExportId;
|
2016-08-28 16:20:37 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xs->type == EXEC_STACK_TYPE_CALL) {
|
2017-02-03 09:58:57 -06:00
|
|
|
if (debugSelector != -1) {
|
|
|
|
curMethodName = g_sci->getKernel()->getSelectorName(debugSelector);
|
|
|
|
} else if (debugExportId != -1) {
|
2016-08-28 16:20:37 -05:00
|
|
|
curObjectName = "";
|
2017-02-03 09:58:57 -06:00
|
|
|
curMethodName = Common::String::format("export %d", debugExportId);
|
2016-08-28 16:20:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SciCallOrigin reply;
|
|
|
|
reply.objectName = curObjectName;
|
|
|
|
reply.methodName = curMethodName;
|
|
|
|
reply.scriptNr = curScriptNr;
|
|
|
|
reply.localCallOffset = xs->debugLocalCallOffset;
|
|
|
|
reply.roomNr = currentRoomNumber();
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2009-02-27 02:23:40 +00:00
|
|
|
} // End of namespace Sci
|