aboutsummaryrefslogtreecommitdiff
path: root/engines/toon
diff options
context:
space:
mode:
authorBLooperZ2019-11-08 00:40:58 +0200
committerEugene Sandulenko2019-11-18 02:02:14 +0100
commit32b9b7226ca35eb2b47ff0a030472f78640101cd (patch)
tree779036d21b2881ddf6a1e2612db292d637d14708 /engines/toon
parente87e18052c517737c7327ada531fb737fafa5ef4 (diff)
downloadscummvm-rg350-32b9b7226ca35eb2b47ff0a030472f78640101cd.tar.gz
scummvm-rg350-32b9b7226ca35eb2b47ff0a030472f78640101cd.tar.bz2
scummvm-rg350-32b9b7226ca35eb2b47ff0a030472f78640101cd.zip
TOON: plaintext format for subtitles
Diffstat (limited to 'engines/toon')
-rw-r--r--engines/toon/subtitles.cpp53
-rw-r--r--engines/toon/subtitles.h21
-rw-r--r--engines/toon/toon.cpp8
-rw-r--r--engines/toon/toon.h2
4 files changed, 52 insertions, 32 deletions
diff --git a/engines/toon/subtitles.cpp b/engines/toon/subtitles.cpp
index 51811808df..f3205ed8f8 100644
--- a/engines/toon/subtitles.cpp
+++ b/engines/toon/subtitles.cpp
@@ -38,7 +38,7 @@ SubtitleRenderer::~SubtitleRenderer() {
void SubtitleRenderer::render(const Graphics::Surface &frame, uint32 frameNumber, byte color) {
- if (!_hasSubtitles || _index > _last) {
+ if (!_hasSubtitles || _tw.empty()) {
return;
}
@@ -48,19 +48,18 @@ void SubtitleRenderer::render(const Graphics::Surface &frame, uint32 frameNumber
// _vm->drawCostumeLine(0, 0, strf, _subSurface);
// _vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w, _subSurface->h);
- if (frameNumber > _tw[_index].fend) {
- _index++;
- if (_index > _last) {
+ if (frameNumber > _tw.front()._endFrame) {
+ _tw.pop_front();
+ if (_tw.empty()) {
return;
}
- _currentLine = (char *)_fileData + _tw[_index].foffset;
}
- if (frameNumber < _tw[_index].fstart) {
+ if (frameNumber < _tw.front()._startFrame) {
return;
}
- _vm->drawCustomText(TOON_SCREEN_WIDTH / 2, TOON_SCREEN_HEIGHT, _currentLine, _subSurface, color);
+ _vm->drawCustomText(TOON_SCREEN_WIDTH / 2, TOON_SCREEN_HEIGHT, _tw.front()._text.c_str(), _subSurface, color);
_vm->_system->copyRectToScreen(_subSurface->getBasePtr(0, 0), _subSurface->pitch, 0, 0, _subSurface->w, _subSurface->h);
}
@@ -68,25 +67,45 @@ bool SubtitleRenderer::load(const Common::String &video) {
// warning(video.c_str());
_hasSubtitles = false;
- _index = 0;
Common::String subfile(video);
Common::String ext("tss");
subfile.replace(subfile.size() - ext.size(), ext.size(), ext);
- uint32 fileSize = 0;
- uint8 *fileData = _vm->resources()->getFileData(subfile, &fileSize);
- if (!fileData) {
+ Common::SeekableReadStream *file;
+ file = _vm->resources()->openFile(subfile);
+ if (!file) {
return false;
}
- uint32 numOflines = *((uint32 *) fileData);
- uint32 idx_size = numOflines * sizeof(TimeWindow);
- memcpy(_tw, sizeof(numOflines) + fileData, idx_size);
- _fileData = sizeof(numOflines) + fileData + idx_size;
- _last = numOflines - 1;
+ Common::String line;
+ int lineNo = 0;
+
+ _tw.clear();
+ while (!file->eos() && !file->err()) {
+ line = file->readLine();
+
+ lineNo++;
+ if (line.empty() || line[0] == '#') {
+ continue;
+ }
+
+ const char *ptr = line.c_str();
+
+ int startFrame = strtoul(ptr, const_cast<char **>(&ptr), 10);
+ int endFrame = strtoul(ptr, const_cast<char **>(&ptr), 10);
+
+ while (*ptr && Common::isSpace(*ptr))
+ ptr++;
+
+ if (startFrame > endFrame) {
+ warning("%s:%d: startFrame (%d) > endFrame (%d)", subfile.c_str(), lineNo, startFrame, endFrame);
+ continue;
+ }
+
+ _tw.push_back(TimeWindow(startFrame, endFrame, ptr));
+ }
- _currentLine = (char *)_fileData + _tw[0].foffset;
_hasSubtitles = true;
return _hasSubtitles;
}
diff --git a/engines/toon/subtitles.h b/engines/toon/subtitles.h
index 41b12638a1..133964c522 100644
--- a/engines/toon/subtitles.h
+++ b/engines/toon/subtitles.h
@@ -28,10 +28,16 @@
namespace Toon {
-struct TimeWindow {
- uint32 fstart;
- uint32 fend;
- uint32 foffset;
+class TimeWindow {
+public:
+ uint16 _startFrame;
+ uint16 _endFrame;
+ Common::String _text;
+ TimeWindow(int startFrame, int endFrame, const Common::String &text) {
+ _startFrame = startFrame;
+ _endFrame = endFrame;
+ _text = text;
+ }
};
class SubtitleRenderer {
@@ -45,12 +51,7 @@ protected:
ToonEngine *_vm;
Graphics::Surface *_subSurface;
bool _hasSubtitles;
- char *_lines[384];
- TimeWindow _tw[384];
- uint8 *_fileData;
- uint16 _index;
- uint16 _last;
- char *_currentLine;
+ Common::List<TimeWindow> _tw;
};
} // End of namespace Toon
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 2407966567..0f03536f66 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -1434,7 +1434,7 @@ void ToonEngine::updateAnimationSceneScripts(int32 timeElapsed) {
do {
if (_sceneAnimationScripts[_lastProcessedSceneScript]._lastTimer <= _system->getMillis() &&
- !_sceneAnimationScripts[_lastProcessedSceneScript]._frozen && !_sceneAnimationScripts[_lastProcessedSceneScript]._frozenForConversation) {
+ !_sceneAnimationScripts[_lastProcessedSceneScript]._frozen && !_sceneAnimationScripts[_lastProcessedSceneScript]._frozenForConversation) {
_animationSceneScriptRunFlag = true;
while (_animationSceneScriptRunFlag && _sceneAnimationScripts[_lastProcessedSceneScript]._lastTimer <= _system->getMillis() && !_shouldQuit) {
@@ -2992,8 +2992,8 @@ int32 ToonEngine::showInventory() {
int32 x = 57 * (i % 7) + 114;
int32 y = ((9 * (i % 7)) & 0xf) + 56 * (i / 7) + 80;
if (_mouseX >= (_gameState->_currentScrollValue + x - 6) &&
- _mouseX <= (_gameState->_currentScrollValue + x + 44 + 7) &&
- _mouseY >= y - 6 && _mouseY <= y + 50) {
+ _mouseX <= (_gameState->_currentScrollValue + x + 44 + 7) &&
+ _mouseY >= y - 6 && _mouseY <= y + 50) {
foundObj = i;
break;
}
@@ -3297,7 +3297,7 @@ void ToonEngine::drawConversationLine() {
}
}
-void ToonEngine::drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, byte color) {
+void ToonEngine::drawCustomText(int16 x, int16 y, const char *line, Graphics::Surface *frame, byte color) {
if (line) {
byte col = color; // 0xce
_fontRenderer->setFontColor(0, col, col);
diff --git a/engines/toon/toon.h b/engines/toon/toon.h
index 1d693873f6..836dfe541a 100644
--- a/engines/toon/toon.h
+++ b/engines/toon/toon.h
@@ -211,7 +211,7 @@ public:
void playRoomMusic();
void waitForScriptStep();
void doMagnifierEffect();
- void drawCustomText(int16 x, int16 y, char *line, Graphics::Surface *frame, byte color);
+ void drawCustomText(int16 x, int16 y, const char *line, Graphics::Surface *frame, byte color);
bool canSaveGameStateCurrently();
bool canLoadGameStateCurrently();
void pauseEngineIntern(bool pause);