scummvm/engines/director/tests.cpp
2020-08-15 14:50:26 +02:00

301 lines
11 KiB
C++

/* 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/config-manager.h"
#include "common/system.h"
#include "common/zlib.h"
#include "common/memstream.h"
#include "common/macresman.h"
#include "graphics/fonts/macfont.h"
#include "graphics/macgui/macfontmanager.h"
#include "graphics/macgui/macwindowmanager.h"
#include "engines/util.h"
#include "director/director.h"
#include "director/archive.h"
#include "director/movie.h"
#include "director/window.h"
#include "director/lingo/lingo.h"
namespace Director {
//////////////////////
// Graphics tests
//////////////////////
void Window::testFontScaling() {
int x = 10;
int y = 10;
int w = g_system->getWidth();
int h = g_system->getHeight();
_vm->setPalette(-1);
Graphics::ManagedSurface surface;
surface.create(w, h, _wm->_pixelformat);
surface.clear(_wm->_colorWhite);
Graphics::MacFont origFont(Graphics::kMacFontNewYork, 18);
const Graphics::MacFONTFont *font1 = (const Graphics::MacFONTFont *)_wm->_fontMan->getFont(origFont);
Graphics::MacFONTFont::testBlit(font1, &surface, 0, x, y + 200, 500);
Graphics::MacFont bigFont(Graphics::kMacFontNewYork, 15);
font1 = (const Graphics::MacFONTFont *)_wm->_fontMan->getFont(bigFont);
Graphics::MacFONTFont::testBlit(font1, &surface, 0, x, y + 50 + 200, 500);
const char *text = "d";
for (int i = 9; i <= 20; i++) {
Graphics::MacFont macFont(Graphics::kMacFontNewYork, i);
const Graphics::Font *font = _wm->_fontMan->getFont(macFont);
int width = font->getStringWidth(text);
Common::Rect bbox = font->getBoundingBox(text, x, y, w);
surface.frameRect(bbox, 15);
font->drawString(&surface, text, x, y, width, 0);
x += width + 1;
}
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
int y1 = 80 + i * 7;
int x1 = 80 + j * 7;
for (x = x1; x < x1 + 6; x++)
for (y = y1; y < y1 + 6; y++)
if (_wm->_pixelformat.bytesPerPixel == 1)
*((byte *)surface.getBasePtr(x, y)) = _vm->transformColor(i * 16 + j);
else
*((uint32 *)surface.getBasePtr(x, y)) = _vm->transformColor(i * 16 + j);
}
}
g_system->copyRectToScreen(surface.getPixels(), surface.pitch, 0, 0, w, h); // testing fonts
Common::Event event;
while (true) {
if (g_system->getEventManager()->pollEvent(event))
if (event.type == Common::EVENT_QUIT)
break;
g_system->updateScreen();
g_system->delayMillis(10);
}
}
void Window::testFonts() {
Common::String fontName("Helvetica");
Common::MacResManager *fontFile = new Common::MacResManager();
if (!fontFile->open(fontName))
error("testFonts(): Could not open %s as a resource fork", fontName.c_str());
Common::MacResIDArray fonds = fontFile->getResIDArray(MKTAG('F','O','N','D'));
if (fonds.size() > 0) {
for (Common::Array<uint16>::iterator iterator = fonds.begin(); iterator != fonds.end(); ++iterator) {
Common::SeekableReadStream *stream = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), *iterator);
Common::String name = fontFile->getResName(MKTAG('F', 'O', 'N', 'D'), *iterator);
debug("Font: %s", name.c_str());
Graphics::MacFontFamily font;
font.load(*stream);
}
}
delete fontFile;
}
//////////////////////
// Movie iteration
//////////////////////
Common::HashMap<Common::String, Movie *> *Window::scanMovies(const Common::String &folder) {
Common::FSNode directory(folder);
Common::FSList movies;
const char *sharedMMMname;
if (_vm->getPlatform() == Common::kPlatformWindows)
sharedMMMname = "SHARDCST.MMM";
else
sharedMMMname = "Shared Cast";
Common::HashMap<Common::String, Movie *> *nameMap = new Common::HashMap<Common::String, Movie *>();
if (!directory.getChildren(movies, Common::FSNode::kListFilesOnly))
return nameMap;
if (!movies.empty()) {
for (Common::FSList::const_iterator i = movies.begin(); i != movies.end(); ++i) {
debugC(2, kDebugLoading, "File: %s", i->getName().c_str());
if (Common::matchString(i->getName().c_str(), sharedMMMname, true)) {
_vm->_sharedCastFile = i->getName();
debugC(2, kDebugLoading, "Shared cast detected: %s", i->getName().c_str());
continue;
}
Archive *arc = _vm->createArchive();
warning("name: %s", i->getName().c_str());
arc->openFile(i->getName());
Movie *m = new Movie(this);
m->setArchive(arc);
nameMap->setVal(m->getMacName(), m);
debugC(2, kDebugLoading, "Movie name: \"%s\"", m->getMacName().c_str());
}
}
return nameMap;
}
void Window::enqueueAllMovies() {
Common::FSNode dir(ConfMan.get("path"));
Common::FSList files;
if (!dir.getChildren(files, Common::FSNode::kListFilesOnly)) {
warning("DirectorEngine::enqueueAllMovies(): Failed inquiring file list");
return;
}
for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file)
_movieQueue.push_back((*file).getName());
Common::sort(_movieQueue.begin(), _movieQueue.end());
debug(1, "=========> Enqueued %d movies", _movieQueue.size());
}
MovieReference Window::getNextMovieFromQueue() {
MovieReference res;
if (_movieQueue.empty())
return res;
res.movie = _movieQueue.front();
debug(0, "=======================================");
debug(0, "=========> Next movie is %s", res.movie.c_str());
debug(0, "=======================================");
_movieQueue.remove_at(0);
return res;
}
const byte testMovie[] = {
0x1F, 0x8B, 0x08, 0x08, 0x00, 0xD1, 0x10, 0x5F, 0x00, 0x03, 0x74, 0x65,
0x73, 0x74, 0x6D, 0x6F, 0x76, 0x69, 0x65, 0x66, 0x69, 0x78, 0x65, 0x64,
0x33, 0x00, 0xB5, 0x54, 0xCD, 0x6B, 0x53, 0x41, 0x10, 0x9F, 0xF7, 0x91,
0xE6, 0x35, 0x89, 0xE6, 0xD5, 0xC4, 0xD8, 0xDA, 0x22, 0x2F, 0x50, 0x24,
0x14, 0x35, 0x60, 0x2E, 0x2A, 0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, 0x57, 0x7C, 0x8B, 0x8D, 0xD5, 0xF5, 0x2B, 0x70, 0xDC, 0xED, 0x31,
0x9C, 0x98, 0x75, 0x05, 0xA1, 0x8F, 0xD2, 0x45, 0x04, 0x6B, 0x06, 0xFE,
0x25, 0xC8, 0xDF, 0xED, 0xE2, 0x26, 0x85, 0x1E, 0x20, 0xAA, 0x01, 0x2A,
0x01, 0x9B, 0x25, 0xB3, 0x42, 0x6A, 0x17, 0x7F, 0xCE, 0xFC, 0x7C, 0x41,
0x6F, 0xDD, 0x4E, 0xC0, 0x33, 0x8F, 0x51, 0x2C, 0x5B, 0xA9, 0xD5, 0x9A,
0xD6, 0xD3, 0x66, 0xBB, 0x56, 0x8E, 0x8B, 0x6E, 0x6D, 0x62, 0x47, 0x23,
0x59, 0x9F, 0x32, 0xAF, 0xE8, 0x2F, 0xED, 0x2A, 0x34, 0x9B, 0x24, 0x06,
0x00, 0x00
};
void Window::runTests() {
Common::MemoryReadStream *movie = new Common::MemoryReadStream(testMovie, ARRAYSIZE(testMovie));
Common::SeekableReadStream *stream = Common::wrapCompressedReadStream(movie);
initGraphics(640, 480);
_mainArchive = new RIFXArchive();
if (!_mainArchive->openStream(stream, 0)) {
error("DirectorEngine::runTests(): Bad movie data");
}
_currentMovie = new Movie(this);
_currentMovie->setArchive(_mainArchive);
_currentMovie->loadArchive();
if (debugChannelSet(-1, kDebugText)) {
testFontScaling();
testFonts();
}
g_lingo->runTests();
}
} // End of namespace Director