From 27a0f433338726dd486c5c8be0ad60ba587aeaa1 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 25 Feb 2017 21:40:29 +0100 Subject: DIRECTOR: Move utility functions to util.cpp --- engines/director/frame.cpp | 5 +- engines/director/lingo/lingo-code.cpp | 9 +-- engines/director/lingo/lingo-codegen.cpp | 21 +++--- engines/director/lingo/lingo.cpp | 42 ------------ engines/director/lingo/lingo.h | 2 - engines/director/module.mk | 1 + engines/director/util.cpp | 108 +++++++++++++++++++++++++++++++ engines/director/util.h | 39 +++++++++++ 8 files changed, 165 insertions(+), 62 deletions(-) create mode 100644 engines/director/util.cpp create mode 100644 engines/director/util.h (limited to 'engines') diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp index d20026cb62..fd0ee9844c 100644 --- a/engines/director/frame.cpp +++ b/engines/director/frame.cpp @@ -35,6 +35,7 @@ #include "director/archive.h" #include "director/score.h" #include "director/sprite.h" +#include "director/util.h" namespace Director { @@ -586,12 +587,12 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { Image::ImageDecoder *img = getImageFrom(_sprites[i]->_castId); if (!img) { - warning("Image with id %d not found", _sprites[i]->_castId); + warning("Image with id %d (%s) not found", _sprites[i]->_castId, numToCastNum(_sprites[i]->_castId)); continue; } if (!img->getSurface()) { - warning("Frame::renderSprites: Could not load image %d", _sprites[i]->_castId); + warning("Frame::renderSprites: Could not load image %d (%s)", _sprites[i]->_castId, numToCastNum(_sprites[i]->_castId)); continue; } diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index b7fc484d91..96f2b72158 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -44,6 +44,7 @@ // THIS SOFTWARE. #include "director/cast.h" +#include "director/util.h" #include "director/lingo/lingo.h" #include "director/lingo/lingo-gr.h" @@ -578,8 +579,8 @@ void Lingo::c_contains() { d1.toString(); d2.toString(); - Common::String *s1 = g_lingo->toLowercaseMac(d1.u.s); - Common::String *s2 = g_lingo->toLowercaseMac(d2.u.s); + Common::String *s1 = toLowercaseMac(d1.u.s); + Common::String *s2 = toLowercaseMac(d2.u.s); int res = s1->contains(*s2) ? 1 : 0; @@ -601,8 +602,8 @@ void Lingo::c_starts() { d1.toString(); d2.toString(); - Common::String *s1 = g_lingo->toLowercaseMac(d1.u.s); - Common::String *s2 = g_lingo->toLowercaseMac(d2.u.s); + Common::String *s1 = toLowercaseMac(d1.u.s); + Common::String *s2 = toLowercaseMac(d2.u.s); int res = s1->hasPrefix(*s2) ? 1 : 0; diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp index d69de85e9a..b16e6b6131 100644 --- a/engines/director/lingo/lingo-codegen.cpp +++ b/engines/director/lingo/lingo-codegen.cpp @@ -48,6 +48,7 @@ #include "audio/decoders/wave.h" #include "director/lingo/lingo-gr.h" +#include "director/util.h" namespace Director { @@ -146,22 +147,18 @@ Symbol *Lingo::lookupVar(const char *name, bool create, bool putInGlobalList) { // Looking for the cast member constants if (_vm->getVersion() < 4) { // TODO: There could be a flag 'Allow Outdated Lingo' in Movie Info in D4 - if (strlen(name) == 3) { - if (tolower(name[0]) >= 'a' && tolower(name[0]) <= 'h' && - name[1] >= '1' && name[1] <= '8' && - name[2] >= '1' && name[2] <= '8') { + int val = castNumToNum(name); - if (!create) - error("Cast reference used in wrong context: %s", name); + if (val != -1) { + if (!create) + error("Cast reference used in wrong context: %s", name); - int val = (tolower(name[0]) - 'a') * 64 + (name[1] - '1') * 8 + (name[2] - '1') + 1; - sym = new Symbol; + sym = new Symbol; - sym->type = CASTREF; - sym->u.i = val; + sym->type = CASTREF; + sym->u.i = val; - return sym; - } + return sym; } } diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index ffbbdab933..5775eb13bc 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -438,48 +438,6 @@ const char *Datum::type2str(bool isk) { } } -// This is table for built-in Macintosh font lowercasing. -// '.' means that the symbol should be not changed, rest -// of the symbols are stripping the diacritics -// The table starts from 0x80 -// -// TODO: Check it for correctness. -static char lowerCaseConvert[] = -"aacenoua" // 80 -"aaaaacee" // 88 -"eeiiiino" // 90 -"oooouuuu" // 98 -"........" // a0 -".......o" // a8 -"........" // b0 -".......o" // b8 -"........" // c0 -".. aao.." // c8 -"--.....y";// d0-d8 - -Common::String *Lingo::toLowercaseMac(Common::String *s) { - Common::String *res = new Common::String; - const unsigned char *p = (const unsigned char *)s->c_str(); - - while (*p) { - if (*p >= 0x80 && *p <= 0xd8) { - if (lowerCaseConvert[*p - 0x80] != '.') - *res += lowerCaseConvert[*p - 0x80]; - else - *res += *p; - } else if (*p < 0x80) { - *res += tolower(*p); - } else { - warning("Unacceptable symbol in toLowercaseMac: %c", *p); - - *res += *p; - } - p++; - } - - return res; -} - void Lingo::parseMenu(const char *code) { warning("STUB: parseMenu"); } diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index 516e91c6ed..1e84344cdb 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -190,8 +190,6 @@ public: void initFuncs(); void initTheEntities(); - Common::String *toLowercaseMac(Common::String *s); - void runTests(); private: diff --git a/engines/director/module.mk b/engines/director/module.mk index e947af4be7..07a7a28c85 100644 --- a/engines/director/module.mk +++ b/engines/director/module.mk @@ -13,6 +13,7 @@ MODULE_OBJS = \ score.o \ sound.o \ sprite.o \ + util.o \ lingo/lingo-gr.o \ lingo/lingo.o \ lingo/lingo-builtins.o \ diff --git a/engines/director/util.cpp b/engines/director/util.cpp new file mode 100644 index 0000000000..ccde2b3127 --- /dev/null +++ b/engines/director/util.cpp @@ -0,0 +1,108 @@ +/* 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. + * + * 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. + * + * 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. + * + */ + +#include "common/str.h" +#include "common/textconsole.h" + +#include "director/util.h" + +namespace Director { + +int castNumToNum(const char *str) { + if (strlen(str) != 3) + return -1; + + if (tolower(str[0]) >= 'a' && tolower(str[0]) <= 'h' && + str[1] >= '1' && str[1] <= '8' && + str[2] >= '1' && str[2] <= '8') { + + return (tolower(str[0]) - 'a') * 64 + (str[1] - '1') * 8 + (str[2] - '1') + 1; + } + + return -1; +} + +char *numToCastNum(int num) { + static char res[4]; + + res[0] = res[1] = res[2] = '?'; + res[3] = '\0'; + num--; + + if (num > 0 && num <= 512) { + int c = num / 64; + res[0] = 'A' + c; + num -= 64 * c; + + c = num / 8; + res[1] = '1' + c; + num -= 8 * c; + + res[2] = '1' + num; + } + + return res; +} + +// This is table for built-in Macintosh font lowercasing. +// '.' means that the symbol should be not changed, rest +// of the symbols are stripping the diacritics +// The table starts from 0x80 +// +// TODO: Check it for correctness. +static char lowerCaseConvert[] = +"aacenoua" // 80 +"aaaaacee" // 88 +"eeiiiino" // 90 +"oooouuuu" // 98 +"........" // a0 +".......o" // a8 +"........" // b0 +".......o" // b8 +"........" // c0 +".. aao.." // c8 +"--.....y";// d0-d8 + +Common::String *toLowercaseMac(Common::String *s) { + Common::String *res = new Common::String; + const unsigned char *p = (const unsigned char *)s->c_str(); + + while (*p) { + if (*p >= 0x80 && *p <= 0xd8) { + if (lowerCaseConvert[*p - 0x80] != '.') + *res += lowerCaseConvert[*p - 0x80]; + else + *res += *p; + } else if (*p < 0x80) { + *res += tolower(*p); + } else { + warning("Unacceptable symbol in toLowercaseMac: %c", *p); + + *res += *p; + } + p++; + } + + return res; +} + +} // End of namespace Director diff --git a/engines/director/util.h b/engines/director/util.h new file mode 100644 index 0000000000..66f8074cfe --- /dev/null +++ b/engines/director/util.h @@ -0,0 +1,39 @@ +/* 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. + * + * 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. + * + * 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. + * + */ + +#ifndef DIRECTOR_UTIL_H +#define DIRECTOR_UTIL_H + +namespace Common { +class String; +} + +namespace Director { + +int castNumToNum(const char *str); +char *numToCastNum(int num); + +Common::String *toLowercaseMac(Common::String *s); + +} // End of namespace Director + +#endif -- cgit v1.2.3