From bb31c435bf6502f4e1f94b3de9f046c054031a98 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 3 Dec 2014 01:43:51 +0200 Subject: ZVISION: Remove more dead code, and move some debugger functions --- engines/zvision/core/console.cpp | 79 ++++++++++------ engines/zvision/core/console.h | 2 - engines/zvision/sound/zork_raw.cpp | 22 +++-- engines/zvision/utility/utility.cpp | 176 ------------------------------------ engines/zvision/utility/utility.h | 66 -------------- 5 files changed, 65 insertions(+), 280 deletions(-) diff --git a/engines/zvision/core/console.cpp b/engines/zvision/core/console.cpp index 201d1c9360..f8e28333f1 100644 --- a/engines/zvision/core/console.cpp +++ b/engines/zvision/core/console.cpp @@ -44,7 +44,6 @@ namespace ZVision { Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { - registerCmd("loadimage", WRAP_METHOD(Console, cmdLoadImage)); registerCmd("loadvideo", WRAP_METHOD(Console, cmdLoadVideo)); registerCmd("loadsound", WRAP_METHOD(Console, cmdLoadSound)); registerCmd("raw2wav", WRAP_METHOD(Console, cmdRawToWav)); @@ -55,18 +54,6 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { registerCmd("changelocation", WRAP_METHOD(Console, cmdChangeLocation)); registerCmd("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); registerCmd("parseallscrfiles", WRAP_METHOD(Console, cmdParseAllScrFiles)); - registerCmd("rendertext", WRAP_METHOD(Console, cmdRenderText)); -} - -bool Console::cmdLoadImage(int argc, const char **argv) { -// if (argc == 4) -// _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); -// else { -// DebugPrintf("Use loadimage to load an image to the screen\n"); -// return true; -// } - - return true; } bool Console::cmdLoadVideo(int argc, const char **argv) { @@ -117,7 +104,42 @@ bool Console::cmdRawToWav(int argc, const char **argv) { return true; } - convertRawToWav(argv[1], _engine, argv[2]); + Common::File file; + if (!file.open(argv[1])) + return true; + + Audio::AudioStream *audioStream = makeRawZorkStream(argv[1], _engine); + + Common::DumpFile output; + output.open(argv[2]); + + output.writeUint32BE(MKTAG('R', 'I', 'F', 'F')); + output.writeUint32LE(file.size() * 2 + 36); + output.writeUint32BE(MKTAG('W', 'A', 'V', 'E')); + output.writeUint32BE(MKTAG('f', 'm', 't', ' ')); + output.writeUint32LE(16); + output.writeUint16LE(1); + uint16 numChannels; + if (audioStream->isStereo()) { + numChannels = 2; + output.writeUint16LE(2); + } else { + numChannels = 1; + output.writeUint16LE(1); + } + output.writeUint32LE(audioStream->getRate()); + output.writeUint32LE(audioStream->getRate() * numChannels * 2); + output.writeUint16LE(numChannels * 2); + output.writeUint16LE(16); + output.writeUint32BE(MKTAG('d', 'a', 't', 'a')); + output.writeUint32LE(file.size() * 2); + int16 *buffer = new int16[file.size()]; + audioStream->readBuffer(buffer, file.size()); + output.write(buffer, file.size() * 2); + + delete[] buffer; + + return true; } @@ -186,7 +208,22 @@ bool Console::cmdDumpFile(int argc, const char **argv) { return true; } - writeFileContentsToFile(argv[1], argv[1]); + Common::File f; + if (!f.open(argv[1])) { + return true; + } + + byte *buffer = new byte[f.size()]; + f.read(buffer, f.size()); + + Common::DumpFile dumpFile; + dumpFile.open(argv[1]); + + dumpFile.write(buffer, f.size()); + dumpFile.flush(); + dumpFile.close(); + + delete[] buffer; return true; } @@ -201,16 +238,4 @@ bool Console::cmdParseAllScrFiles(int argc, const char **argv) { return true; } -bool Console::cmdRenderText(int argc, const char **argv) { - if (argc != 7) { - debugPrintf("Use rendertext <1 or 0: wrap> to render text\n"); - return true; - } - - //StringManager::TextStyle style = _engine->getStringManager()->getTextStyle(atoi(argv[2])); - //_engine->getRenderManager()->renderTextToWorkingWindow(333, Common::String(argv[1]), style.font, atoi(argv[3]), atoi(argv[4]), style.color, atoi(argv[5]), -1, Graphics::kTextAlignLeft, atoi(argv[6]) == 0 ? false : true); - - return true; -} - } // End of namespace ZVision diff --git a/engines/zvision/core/console.h b/engines/zvision/core/console.h index 29523c57ee..994e05ba35 100644 --- a/engines/zvision/core/console.h +++ b/engines/zvision/core/console.h @@ -37,7 +37,6 @@ public: private: ZVision *_engine; - bool cmdLoadImage(int argc, const char **argv); bool cmdLoadVideo(int argc, const char **argv); bool cmdLoadSound(int argc, const char **argv); bool cmdRawToWav(int argc, const char **argv); @@ -48,7 +47,6 @@ private: bool cmdChangeLocation(int argc, const char **argv); bool cmdDumpFile(int argc, const char **argv); bool cmdParseAllScrFiles(int argc, const char **argv); - bool cmdRenderText(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/sound/zork_raw.cpp b/engines/zvision/sound/zork_raw.cpp index 485e0b8a49..c26c33a392 100644 --- a/engines/zvision/sound/zork_raw.cpp +++ b/engines/zvision/sound/zork_raw.cpp @@ -21,23 +21,21 @@ */ #include "common/scummsys.h" - -#include "zvision/sound/zork_raw.h" - -#include "zvision/zvision.h" -#include "zvision/detection.h" -#include "zvision/utility/utility.h" - #include "common/file.h" #include "common/str.h" #include "common/stream.h" #include "common/memstream.h" #include "common/bufferedstream.h" #include "common/util.h" - +#include "common/tokenizer.h" #include "audio/audiostream.h" #include "audio/decoders/raw.h" +#include "zvision/sound/zork_raw.h" +#include "zvision/zvision.h" +#include "zvision/detection.h" +#include "zvision/utility/utility.h" + namespace ZVision { const int16 RawChunkStream::_stepAdjustmentTable[8] = { -1, -1, -1, 1, 4, 7, 10, 12}; @@ -255,7 +253,13 @@ Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, Common::File *file = new Common::File(); assert(engine->getSearchManager()->openFile(*file, filePath)); - Common::String fileName = getFileName(filePath); + // Get the file name + Common::StringTokenizer tokenizer(filePath, "/\\"); + Common::String fileName; + while (!tokenizer.empty()) { + fileName = tokenizer.nextToken(); + } + fileName.toLowercase(); SoundParams soundParams = {}; diff --git a/engines/zvision/utility/utility.cpp b/engines/zvision/utility/utility.cpp index 517c89afbd..2388fe826e 100644 --- a/engines/zvision/utility/utility.cpp +++ b/engines/zvision/utility/utility.cpp @@ -32,25 +32,6 @@ namespace ZVision { -void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile) { - Common::File f; - if (!f.open(sourceFile)) { - return; - } - - byte *buffer = new byte[f.size()]; - f.read(buffer, f.size()); - - Common::DumpFile dumpFile; - dumpFile.open(destFile); - - dumpFile.write(buffer, f.size()); - dumpFile.flush(); - dumpFile.close(); - - delete[] buffer; -} - void trimCommentsAndWhiteSpace(Common::String *string) { for (int i = string->size() - 1; i >= 0; i--) { if ((*string)[i] == '#') { @@ -76,161 +57,4 @@ void tryToDumpLine(const Common::String &key, } } -void dumpEveryResultAction(const Common::String &destFile) { - Common::HashMap count; - Common::HashMap fileAlreadyUsed; - - Common::DumpFile output; - output.open(destFile); - - // Find scr files - Common::ArchiveMemberList list; - SearchMan.listMatchingMembers(list, "*.scr"); - - for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { - Common::SeekableReadStream *stream = (*iter)->createReadStream(); - - Common::String line = stream->readLine(); - trimCommentsAndWhiteSpace(&line); - - while (!stream->eos()) { - if (line.matchString("*:add*", true)) { - tryToDumpLine("add", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:animplay*", true)) { - tryToDumpLine("animplay", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:animpreload*", true)) { - tryToDumpLine("animpreload", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:animunload*", true)) { - tryToDumpLine("animunload", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:attenuate*", true)) { - tryToDumpLine("attenuate", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:assign*", true)) { - tryToDumpLine("assign", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:change_location*", true)) { - tryToDumpLine("change_location", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:crossfade*", true) && !fileAlreadyUsed["add"]) { - tryToDumpLine("crossfade", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:debug*", true)) { - tryToDumpLine("debug", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:delay_render*", true)) { - tryToDumpLine("delay_render", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:disable_control*", true)) { - tryToDumpLine("disable_control", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:disable_venus*", true)) { - tryToDumpLine("disable_venus", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:display_message*", true)) { - tryToDumpLine("display_message", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:dissolve*", true)) { - tryToDumpLine("dissolve", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:distort*", true)) { - tryToDumpLine("distort", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:enable_control*", true)) { - tryToDumpLine("enable_control", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:flush_mouse_events*", true)) { - tryToDumpLine("flush_mouse_events", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:inventory*", true)) { - tryToDumpLine("inventory", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:kill*", true)) { - tryToDumpLine("kill", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:menu_bar_enable*", true)) { - tryToDumpLine("menu_bar_enable", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:music*", true)) { - tryToDumpLine("music", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:pan_track*", true)) { - tryToDumpLine("pan_track", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:playpreload*", true)) { - tryToDumpLine("playpreload", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:preferences*", true)) { - tryToDumpLine("preferences", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:quit*", true)) { - tryToDumpLine("quit", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:random*", true)) { - tryToDumpLine("random", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:region*", true)) { - tryToDumpLine("region", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:restore_game*", true)) { - tryToDumpLine("restore_game", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:rotate_to*", true)) { - tryToDumpLine("rotate_to", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:save_game*", true)) { - tryToDumpLine("save_game", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:set_partial_screen*", true)) { - tryToDumpLine("set_partial_screen", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:set_screen*", true)) { - tryToDumpLine("set_screen", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:set_venus*", true)) { - tryToDumpLine("set_venus", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:stop*", true)) { - tryToDumpLine("stop", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:streamvideo*", true)) { - tryToDumpLine("streamvideo", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:syncsound*", true)) { - tryToDumpLine("syncsound", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:timer*", true)) { - tryToDumpLine("timer", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:ttytext*", true)) { - tryToDumpLine("ttytext", line, &count, &fileAlreadyUsed, output); - } else if (line.matchString("*:universe_music*", true)) { - tryToDumpLine("universe_music", line, &count, &fileAlreadyUsed, output); - } - - line = stream->readLine(); - trimCommentsAndWhiteSpace(&line); - } - - for (Common::HashMap::iterator fileUsedIter = fileAlreadyUsed.begin(); fileUsedIter != fileAlreadyUsed.end(); ++fileUsedIter) { - fileUsedIter->_value = false; - } - } - - output.close(); -} - -Common::String getFileName(const Common::String &fullPath) { - Common::StringTokenizer tokenizer(fullPath, "/\\"); - Common::String token; - while (!tokenizer.empty()) { - token = tokenizer.nextToken(); - } - - return token; -} - -void convertRawToWav(const Common::String &inputFile, ZVision *engine, const Common::String &outputFile) { - Common::File file; - if (!file.open(inputFile)) - return; - - Audio::AudioStream *audioStream = makeRawZorkStream(inputFile, engine); - - Common::DumpFile output; - output.open(outputFile); - - output.writeUint32BE(MKTAG('R', 'I', 'F', 'F')); - output.writeUint32LE(file.size() * 2 + 36); - output.writeUint32BE(MKTAG('W', 'A', 'V', 'E')); - output.writeUint32BE(MKTAG('f', 'm', 't', ' ')); - output.writeUint32LE(16); - output.writeUint16LE(1); - uint16 numChannels; - if (audioStream->isStereo()) { - numChannels = 2; - output.writeUint16LE(2); - } else { - numChannels = 1; - output.writeUint16LE(1); - } - output.writeUint32LE(audioStream->getRate()); - output.writeUint32LE(audioStream->getRate() * numChannels * 2); - output.writeUint16LE(numChannels * 2); - output.writeUint16LE(16); - output.writeUint32BE(MKTAG('d', 'a', 't', 'a')); - output.writeUint32LE(file.size() * 2); - int16 *buffer = new int16[file.size()]; - audioStream->readBuffer(buffer, file.size()); - output.write(buffer, file.size() * 2); - - delete[] buffer; -} - } // End of namespace ZVision diff --git a/engines/zvision/utility/utility.h b/engines/zvision/utility/utility.h index 0741cc044c..0ca26b968d 100644 --- a/engines/zvision/utility/utility.h +++ b/engines/zvision/utility/utility.h @@ -33,15 +33,6 @@ namespace ZVision { class ZVision; -/** - * Opens the sourceFile utilizing Common::File (aka SearchMan) and writes the - * contents to destFile. destFile is created in the working directory - * - * @param sourceFile The 'file' you want the contents of - * @param destFile The name of the file where the content will be written to - */ -void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile); - /** * Removes any line comments using '#' as a sequence start. * Then removes any trailing and leading 'whitespace' using String::trim() @@ -51,63 +42,6 @@ void writeFileContentsToFile(const Common::String &sourceFile, const Common::Str */ void trimCommentsAndWhiteSpace(Common::String *string); -/** - * Searches through all the .scr files and dumps 'numberOfExamplesPerType' examples of each type of ResultAction - * ZVision::initialize() must have been called before this function can be used. - * - * @param destFile Where to write the examples - */ -void dumpEveryResultAction(const Common::String &destFile); - -/** - * Removes all duplicate entries from container. Relative order will be preserved. - * - * @param container The Array to remove duplicate entries from - */ -template -void removeDuplicateEntries(Common::Array &container) { - // Length of modified array - uint newLength = 1; - uint j; - - for (uint i = 1; i < container.size(); i++) { - for (j = 0; j < newLength; j++) { - if (container[i] == container[j]) { - break; - } - } - - // If none of the values in index[0..j] of container are the same as array[i], - // then copy the current value to corresponding new position in array - if (j == newLength) { - container[newLength++] = container[i]; - } - } - - // Actually remove the unneeded space - while (container.size() < newLength) { - container.pop_back(); - } -} - -/** - * Gets the name of the file (including extension). Forward or back slashes - * are interpreted as directory changes - * - * @param fullPath A full or partial path to the file. Ex: folderOne/folderTwo/file.txt - * @return The name of the file without any preceding directories. Ex: file.txt - */ -Common::String getFileName(const Common::String &fullPath); - -/** - * Converts a ZVision .RAW file to a .WAV - * The .WAV will be created in the working directory and will overwrite any existing file - * - * @param inputFile The path to the input .RAW file - * @param outputFile The name of the output .WAV file - */ -void convertRawToWav(const Common::String &inputFile, ZVision *engine, const Common::String &outputFile); - } // End of namespace ZVision #endif -- cgit v1.2.3