From d0b341e6ca7010641c362bb36ebfc3d225955056 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 4 Jun 2013 14:17:19 -0500 Subject: ZVISION: Create zvision bare structure Add zvision base engine to engines/zvision as well as modify the necessary engine files (configure.engines, etc.) in order for it to be recognized. --- engines/zvision/detection.cpp | 249 +++++++++++++++++++++++++++++++++++ engines/zvision/module.mk | 18 +++ engines/zvision/zork_avi_decoder.cpp | 136 +++++++++++++++++++ engines/zvision/zork_avi_decoder.h | 59 +++++++++ engines/zvision/zork_raw.cpp | 186 ++++++++++++++++++++++++++ engines/zvision/zork_raw.h | 67 ++++++++++ engines/zvision/zvision.cpp | 217 ++++++++++++++++++++++++++++++ engines/zvision/zvision.h | 70 ++++++++++ 8 files changed, 1002 insertions(+) create mode 100644 engines/zvision/detection.cpp create mode 100644 engines/zvision/module.mk create mode 100644 engines/zvision/zork_avi_decoder.cpp create mode 100644 engines/zvision/zork_avi_decoder.h create mode 100644 engines/zvision/zork_raw.cpp create mode 100644 engines/zvision/zork_raw.h create mode 100644 engines/zvision/zvision.cpp create mode 100644 engines/zvision/zvision.h (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp new file mode 100644 index 0000000000..345138b724 --- /dev/null +++ b/engines/zvision/detection.cpp @@ -0,0 +1,249 @@ +/* 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 "base/plugins.h" + +#include "engines/advancedDetector.h" + +#include "common/translation.h" +#include "common/savefile.h" +#include "common/str-array.h" +#include "common/system.h" + +#include "zvision/zvision.h" + + +namespace ZVision { + +struct ZVisionGameDescription { + ADGameDescription desc; +}; + +uint32 ZVision::getFeatures() const { + return _gameDescription->desc.flags; +} + +Common::Language ZVision::getLanguage() const { + return _gameDescription->desc.language; +} + +} + +static const PlainGameDescriptor zVisionGames[] = { + {"zvision", "ZVision Game"}, + {"znemesis", "Zork Nemesis: The Forbidden Lands"}, + {"zgi", "Zork: Grand Inquisitor"}, + {0, 0} +}; + + +namespace ZVision { + +static const ZVisionGameDescription gameDescriptions[] = { + + { + // Zork Nemesis English version + { + "znemesis", + 0, + AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), + Common::EN_ANY, + Common::kPlatformWindows, + ADGF_NO_FLAGS, + GUIO1(GUIO_NONE) + }, + }, + + { AD_TABLE_END_MARKER } +}; + +} // End of namespace ZVision + +static const ExtraGuiOption ZVisionExtraGuiOption = { + _s("Use original save/load screens"), + _s("Use the original save/load screens, instead of the ScummVM ones"), + "originalsaveload", + false +}; + +class ZVisionMetaEngine : public AdvancedMetaEngine { +public: + ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { + _singleid = "zvision"; + } + + virtual const char *getName() const { + return "ZVision"; + } + + virtual const char *getOriginalCopyright() const { + return "ZVision Activision (C) 1996"; + } + + virtual bool hasFeature(MetaEngineFeature f) const; + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; + SaveStateList listSaves(const char *target) const; + virtual int getMaximumSaveSlot() const; + void removeSaveState(const char *target, int slot) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; +}; + +bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { + return false; + /* + (f == kSupportsListSaves) || + (f == kSupportsLoadingDuringStartup) || + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail) || + (f == kSavesSupportCreationDate) || + (f == kSavesSupportPlayTime); + */ +} + +/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); +}*/ + +bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; + if (gd) { + *engine = new ZVision::ZVision(syst, gd); + } + return gd != 0; +} + +const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String &target) const { + ExtraGuiOptions options; + options.push_back(ZVisionExtraGuiOption); + return options; +} + +SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { + //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + /*ZVision::ZVision::SaveHeader header; + Common::String pattern = target; + pattern += ".???"; + + Common::StringArray filenames; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ + + SaveStateList saveList; +/* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { + saveList.push_back(SaveStateDescriptor(slotNum, header.description)); + } + delete in; + } + } + }*/ + + return saveList; +} + +int ZVisionMetaEngine::getMaximumSaveSlot() const { + return 999; +} + +void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { + /* + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + + saveFileMan->removeSavefile(filename.c_str()); + + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".???"; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + // Rename every slot greater than the deleted slot, + if (slotNum > slot) { + saveFileMan->renameSavefile(file->c_str(), filename.c_str()); + filename = ZVision::ZVision::getSavegameFilename(target, ++slot); + } + } + */ +} + +SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { + /* + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); + + if (in) { + ZVision::ZVision::SaveHeader header; + ZVision::ZVision::kReadSaveHeaderError error; + + error = ZVision::ZVision::readSaveHeader(in, true, header); + delete in; + + if (error == ZVision::ZVision::kRSHENoError) { + SaveStateDescriptor desc(slot, header.description); + + desc.setThumbnail(header.thumbnail); + + if (header.version > 0) { + int day = (header.saveDate >> 24) & 0xFF; + int month = (header.saveDate >> 16) & 0xFF; + int year = header.saveDate & 0xFFFF; + + desc.setSaveDate(year, month, day); + + int hour = (header.saveTime >> 16) & 0xFF; + int minutes = (header.saveTime >> 8) & 0xFF; + + desc.setSaveTime(hour, minutes); + + desc.setPlayTime(header.playTime * 1000); + } + + return desc; + } + } + */ + + return SaveStateDescriptor(); +} + +#if PLUGIN_ENABLED_DYNAMIC(ZVISION) + REGISTER_PLUGIN_DYNAMIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#else + REGISTER_PLUGIN_STATIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#endif diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk new file mode 100644 index 0000000000..854ee0307c --- /dev/null +++ b/engines/zvision/module.mk @@ -0,0 +1,18 @@ +MODULE := engines/zvision + +MODULE_OBJS := \ + detection.o \ + zvision.o \ + zork_avi_decoder.o \ + zork_raw.o + +MODULE_DIRS += \ + engines/zvision + +# This module can be built as a plugin +ifeq ($(ENABLE_ZVISION), DYNAMIC_PLUGIN) +PLUGIN := 1 +endif + +# Include common rules +include $(srcdir)/rules.mk \ No newline at end of file diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp new file mode 100644 index 0000000000..9bcc163721 --- /dev/null +++ b/engines/zvision/zork_avi_decoder.cpp @@ -0,0 +1,136 @@ +/* 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/stream.h" +#include "audio/audiostream.h" + +#include "engines/zvision/zork_avi_decoder.h" +#include "engines/zvision/zork_raw.h" + +namespace ZVision { + +// Redefinitions from avi_decoder.cpp +#define ID_VIDS MKTAG('v','i','d','s') +#define ID_TXTS MKTAG('t','x','t','s') +#define ID_STRF MKTAG('s','t','r','f') +#define ID_AUDS MKTAG('a','u','d','s') +#define ID_MIDS MKTAG('m','i','d','s') + +// Copied off AVIDecoder::handleStreamHeader() +void ZorkAVIDecoder::handleStreamHeader() { + AVIStreamHeader sHeader; + sHeader.size = _fileStream->readUint32LE(); + sHeader.streamType = _fileStream->readUint32BE(); + + if (sHeader.streamType == ID_MIDS || sHeader.streamType == ID_TXTS) + error("Unhandled MIDI/Text stream"); + + sHeader.streamHandler = _fileStream->readUint32BE(); + sHeader.flags = _fileStream->readUint32LE(); + sHeader.priority = _fileStream->readUint16LE(); + sHeader.language = _fileStream->readUint16LE(); + sHeader.initialFrames = _fileStream->readUint32LE(); + sHeader.scale = _fileStream->readUint32LE(); + sHeader.rate = _fileStream->readUint32LE(); + sHeader.start = _fileStream->readUint32LE(); + sHeader.length = _fileStream->readUint32LE(); + sHeader.bufferSize = _fileStream->readUint32LE(); + sHeader.quality = _fileStream->readUint32LE(); + sHeader.sampleSize = _fileStream->readUint32LE(); + + _fileStream->skip(sHeader.size - 48); // Skip over the remainder of the chunk (frame) + + if (_fileStream->readUint32BE() != ID_STRF) + error("Could not find STRF tag"); + + uint32 strfSize = _fileStream->readUint32LE(); + uint32 startPos = _fileStream->pos(); + + if (sHeader.streamType == ID_VIDS) { + BitmapInfoHeader bmInfo; + bmInfo.size = _fileStream->readUint32LE(); + bmInfo.width = _fileStream->readUint32LE(); + bmInfo.height = _fileStream->readUint32LE(); + bmInfo.planes = _fileStream->readUint16LE(); + bmInfo.bitCount = _fileStream->readUint16LE(); + bmInfo.compression = _fileStream->readUint32BE(); + bmInfo.sizeImage = _fileStream->readUint32LE(); + bmInfo.xPelsPerMeter = _fileStream->readUint32LE(); + bmInfo.yPelsPerMeter = _fileStream->readUint32LE(); + bmInfo.clrUsed = _fileStream->readUint32LE(); + bmInfo.clrImportant = _fileStream->readUint32LE(); + + if (bmInfo.clrUsed == 0) + bmInfo.clrUsed = 256; + + if (sHeader.streamHandler == 0) + sHeader.streamHandler = bmInfo.compression; + + AVIVideoTrack *track = new AVIVideoTrack(_header.totalFrames, sHeader, bmInfo); + + if (bmInfo.bitCount == 8) { + byte *palette = const_cast(track->getPalette()); + for (uint32 i = 0; i < bmInfo.clrUsed; i++) { + palette[i * 3 + 2] = _fileStream->readByte(); + palette[i * 3 + 1] = _fileStream->readByte(); + palette[i * 3] = _fileStream->readByte(); + _fileStream->readByte(); + } + + track->markPaletteDirty(); + } + + addTrack(track); + } else if (sHeader.streamType == ID_AUDS) { + PCMWaveFormat wvInfo; + wvInfo.tag = _fileStream->readUint16LE(); + wvInfo.channels = _fileStream->readUint16LE(); + wvInfo.samplesPerSec = _fileStream->readUint32LE(); + wvInfo.avgBytesPerSec = _fileStream->readUint32LE(); + wvInfo.blockAlign = _fileStream->readUint16LE(); + wvInfo.size = _fileStream->readUint16LE(); + + // AVI seems to treat the sampleSize as including the second + // channel as well, so divide for our sake. + if (wvInfo.channels == 2) + sHeader.sampleSize /= 2; + + addTrack(new ZorkAVIAudioTrack(sHeader, wvInfo, _soundType)); + } + + // Ensure that we're at the end of the chunk + _fileStream->seek(startPos + strfSize); +} + +void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { + if (_audStream) { + if (_wvInfo.tag == kWaveFormatZorkPCM) { + assert(_wvInfo.size == 8); + _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, DisposeAfterUse::YES), DisposeAfterUse::YES); + } + } else { + delete stream; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/zork_avi_decoder.h b/engines/zvision/zork_avi_decoder.h new file mode 100644 index 0000000000..f6b2ca7977 --- /dev/null +++ b/engines/zvision/zork_avi_decoder.h @@ -0,0 +1,59 @@ +/* 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 ZORK_AVI_DECODER_H +#define ZORK_AVI_DECODER_H + +#include "video/avi_decoder.h" + +namespace ZVision { + +class ZorkAVIDecoder : public Video::AVIDecoder { +public: + ZorkAVIDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType) : + Video::AVIDecoder(soundType) {} + + virtual ~ZorkAVIDecoder() {} + +private: + class ZorkAVIAudioTrack : public Video::AVIDecoder::AVIAudioTrack { + public: + ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) : + Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType) {} + virtual ~ZorkAVIAudioTrack() {} + + void queueSound(Common::SeekableReadStream *stream); + }; + + void handleStreamHeader(); + + private: + // Audio Codecs + enum { + kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM) + }; +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp new file mode 100644 index 0000000000..9332aeb52e --- /dev/null +++ b/engines/zvision/zork_raw.cpp @@ -0,0 +1,186 @@ +/* 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/endian.h" +#include "common/memstream.h" +#include "common/textconsole.h" +#include "common/util.h" + +#include "audio/audiostream.h" + +#include "engines/zvision/zork_raw.h" + +namespace ZVision { + +#pragma mark - +#pragma mark --- RawZorkStream --- +#pragma mark - + +/** + * This is a stream, which allows for playing raw PCM data from a stream. + */ +class RawZorkStream : public Audio::SeekableAudioStream { +public: + RawZorkStream(int rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) + : _rate(rate), _playtime(0, rate), _stream(stream, disposeStream), _endOfData(false), _buffer(0) { + // Setup our buffer for readBuffer + _buffer = new byte[kSampleBufferLength]; + assert(_buffer); + + // Calculate the total playtime of the stream + _playtime = Audio::Timestamp(0, _stream->size() / 2 / 1, rate); + } + + ~RawZorkStream() { + delete[] _buffer; + } + + int readBuffer(int16 *buffer, const int numSamples); + + bool isStereo() const { return true; } + bool endOfData() const { return _endOfData; } + + int getRate() const { return _rate; } + Audio::Timestamp getLength() const { return _playtime; } + + bool seek(const Audio::Timestamp &where); +private: + const int _rate; ///< Sample rate of stream + Audio::Timestamp _playtime; ///< Calculated total play time + Common::DisposablePtr _stream; ///< Stream to read data from + bool _endOfData; ///< Whether the stream end has been reached + + byte *_buffer; ///< Buffer used in readBuffer + enum { + /** + * How many samples we can buffer at once. + * + * TODO: Check whether this size suffices + * for systems with slow disk I/O. + */ + kSampleBufferLength = 2048 + }; + + /** + * Fill the temporary sample buffer used in readBuffer. + * + * @param maxSamples Maximum samples to read. + * @return actual count of samples read. + */ + int fillBuffer(int maxSamples); +}; + +int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { + int samplesLeft = numSamples; + + while (samplesLeft > 0) { + // Try to read up to "samplesLeft" samples. + int len = fillBuffer(samplesLeft); + + // In case we were not able to read any samples + // we will stop reading here. + if (!len) + break; + + // Adjust the samples left to read. + samplesLeft -= len; + + // Copy the data to the caller's buffer. + const byte *src = _buffer; + while (len-- > 0) { + if (*src < 128) + *buffer++ = ((128 - *src) << 8) ^ 0x8000; + else + *buffer++ = (*src << 8) ^ 0x8000; + src++; + } + } + + return numSamples - samplesLeft; +} + +int RawZorkStream::fillBuffer(int maxSamples) { + int bufferedSamples = 0; + byte *dst = _buffer; + + // We can only read up to "kSampleBufferLength" samples + // so we take this into consideration, when trying to + // read up to maxSamples. + maxSamples = MIN(kSampleBufferLength, maxSamples); + + // We will only read up to maxSamples + while (maxSamples > 0 && !endOfData()) { + // Try to read all the sample data and update the + // destination pointer. + const int bytesRead = _stream->read(dst, maxSamples); + dst += bytesRead; + + // Calculate how many samples we actually read. + const int samplesRead = bytesRead; + + // Update all status variables + bufferedSamples += samplesRead; + maxSamples -= samplesRead; + + // We stop stream playback, when we reached the end of the data stream. + // We also stop playback when an error occures. + if (_stream->pos() == _stream->size() || _stream->err() || _stream->eos()) + _endOfData = true; + } + + return bufferedSamples; +} + +bool RawZorkStream::seek(const Audio::Timestamp &where) { + _endOfData = true; + + if (where > _playtime) + return false; + + const uint32 seekSample = convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames(); + _stream->seek(seekSample, SEEK_SET); + + // In case of an error we will not continue stream playback. + if (!_stream->err() && !_stream->eos() && _stream->pos() != _stream->size()) + _endOfData = false; + + return true; +} + +#pragma mark - +#pragma mark --- Raw stream factories --- +#pragma mark - + +Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, + int rate, + DisposeAfterUse::Flag disposeAfterUse) { + assert(stream->size() % 2 == 0); + return new RawZorkStream(rate, disposeAfterUse, stream); +} + +Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, + int rate, + DisposeAfterUse::Flag disposeAfterUse) { + return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, DisposeAfterUse::YES); +} + +} // End of namespace Audio diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h new file mode 100644 index 0000000000..a8f8ce037f --- /dev/null +++ b/engines/zvision/zork_raw.h @@ -0,0 +1,67 @@ +/* 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 ZVISION_ZORK_RAW_H +#define ZVISION_ZORK_RAW_H + +#include "common/scummsys.h" +#include "common/types.h" + +#include "common/list.h" + + +namespace Common { +class SeekableReadStream; +} + +namespace ZVision { + +class SeekableAudioStream; + +/** + * Creates an audio stream, which plays from the given buffer. + * + * @param buffer Buffer to play from. + * @param size Size of the buffer in bytes. + * @param rate Rate of the sound data. + * @param disposeAfterUse Whether to free the buffer after use (with free!). + * @return The new SeekableAudioStream (or 0 on failure). + */ +Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, + int rate, + DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + +/** + * Creates an audio stream, which plays from the given stream. + * + * @param stream Stream object to play from. + * @param rate Rate of the sound data. + * @param disposeAfterUse Whether to delete the stream after use. + * @return The new SeekableAudioStream (or 0 on failure). + */ +Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, + int rate, + DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + +} // End of namespace Audio + +#endif diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp new file mode 100644 index 0000000000..0e553e6287 --- /dev/null +++ b/engines/zvision/zvision.cpp @@ -0,0 +1,217 @@ +#include "common/scummsys.h" + +#include "common/config-manager.h" +#include "common/debug.h" +#include "common/debug-channels.h" +#include "common/error.h" +#include "common/EventRecorder.h" +#include "common/file.h" +#include "common/fs.h" + +#include "audio/audiostream.h" +#include "audio/mixer.h" + +#include "graphics/palette.h" +#include "graphics/surface.h" +#include "graphics/decoders/tga.h" + +#include "video/video_decoder.h" +#include "video/avi_decoder.h" + +#include "engines/util.h" + +#include "zvision/zvision.h" +#include "zvision/zork_avi_decoder.h" +#include "zvision/zork_raw.h" + +namespace ZVision { + +ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { + // Put your engine in a sane state, but do nothing big yet; + // in particular, do not load data from files; rather, if you + // need to do such things, do them from run(). + + // Do not initialize graphics here + + // However this is the place to specify all default directories + const Common::FSNode gameDataDir(ConfMan.get("path")); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/asylum"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/castle"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/conserv"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/endgame"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global/venus"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global2"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global3"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/monast"); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/temple"); + + // Here is the right place to set up the engine specific debug channels + //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); + //DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example"); + + // Don't forget to register your random source + _rnd = new Common::RandomSource("zvision"); + + debug("ZVision::ZVision"); +} + +ZVision::~ZVision() { + debug("ZVision::~ZVision"); + + // Dispose your resources here + delete _rnd; + + // Remove all of our debug levels here + DebugMan.clearAllDebugChannels(); +} + +void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { + if (!videoDecoder) + return; + + videoDecoder->start(); + + byte *scaleBuffer = 0; + byte bytesPerPixel = videoDecoder->getPixelFormat().bytesPerPixel; + uint16 width = videoDecoder->getWidth(); + uint16 height = videoDecoder->getHeight(); + uint16 pitch = videoDecoder->getWidth() * bytesPerPixel; + uint16 screenWidth = 640;//g_sci->_gfxScreen->getDisplayWidth(); + uint16 screenHeight = 480;//g_sci->_gfxScreen->getDisplayHeight(); + + //videoState.fileName.toLowercase(); + + /*if (screenWidth == 640 && width <= 320 && height <= 240 && ((videoState.flags & kDoubled))) { + width *= 2; + height *= 2; + pitch *= 2; + scaleBuffer = new byte[width * height * bytesPerPixel]; + }*/ + + uint16 x, y; + + // Sanity check... + /*if (videoState.x > 0 && videoState.y > 0 && isVMD) { + x = videoState.x; + y = videoState.y; + + if (x + width > screenWidth || y + height > screenHeight) { + // Happens in the Lighthouse demo + warning("VMD video won't fit on screen, centering it instead"); + x = (screenWidth - width) / 2; + y = (screenHeight - height) / 2; + } + } else {*/ + x = (screenWidth - width) / 2; + y = (screenHeight - height) / 2; + //} + + bool skipVideo = false; + + while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) { + if (videoDecoder->needsUpdate()) { + const Graphics::Surface *frame = videoDecoder->decodeNextFrame(); + + if (frame) { + if (scaleBuffer) { + // TODO: Perhaps reuse the relevant function from SCI? + //g_sci->_gfxScreen->scale2x((byte *)frame->pixels, scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight(), bytesPerPixel); + g_system->copyRectToScreen(scaleBuffer, pitch, x, y, width, height); + } else { + g_system->copyRectToScreen(frame->pixels, frame->pitch, x, y, width, height); + } + + g_system->updateScreen(); + } + } + + Common::Event event; + while (g_system->getEventManager()->pollEvent(event)) { + if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) + skipVideo = true; + } + + g_system->delayMillis(10); + } + + delete[] scaleBuffer; + delete videoDecoder; +} + +Common::Error ZVision::run() { + //Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); // ARGB8888 + Graphics::PixelFormat format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); // RGB555 + initGraphics(640, 480, true, &format); + + // Create debugger console. It requires GFX to be initialized + _console = new Console(this); + + // Additional setup. + debug("ZVision::init"); + + // Your main even loop should be (invoked from) here. + debug("ZVision::go: Hello, World!"); + + // This test will show up if -d1 and --debugflags=example are specified on the commandline + //debugC(1, kZVisionDebugExample, "Example debug call"); + + // This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline + //debugC(3, kZVisionDebugExample | kZVisionDebugExample2, "Example debug call two"); + +#if 1 + // Video test + Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); + if (videoDecoder && videoDecoder->loadFile(/*"TD9EAZ1C.AVI"*/"T000A11C.AVI")) { + Common::List formats; + formats.push_back(videoDecoder->getPixelFormat()); + initGraphics(640, 480, true, formats); + + playVideo(videoDecoder); + } +#endif + + Common::File f; + +#if 1 + // Image test + f.open("CB8EB11C.TGA"); + + Graphics::TGADecoder tga; + if (!tga.loadStream(f)) + error("Error while reading TGA image"); + f.close(); + + const Graphics::Surface *tgaSurface = tga.getSurface(); + + Graphics::Surface *screen = g_system->lockScreen(); + for (uint16 y = 0; y < tgaSurface->h; y++) + memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); + g_system->unlockScreen(); + + tga.destroy(); +#endif + +#if 1 + // Sound test + f.open("C000H9TC.RAW"); + Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); + Audio::SoundHandle handle; + g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); +#endif + + // Main loop + Common::EventManager *eventMan = g_system->getEventManager(); + Common::Event event; + + while (!shouldQuit()) { + eventMan->pollEvent(event); // eat events + g_system->updateScreen(); + g_system->delayMillis(10); + } + + return Common::kNoError; +} + +} // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h new file mode 100644 index 0000000000..c2a42f1e21 --- /dev/null +++ b/engines/zvision/zvision.h @@ -0,0 +1,70 @@ +/* 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 ZVISION_H +#define ZVISION_H + +#include "common/random.h" +#include "engines/engine.h" +#include "gui/debugger.h" + +namespace ZVision { + +struct ZVisionGameDescription; +class Console; + +// our engine debug channels +enum { + kZDebugExample = 1 << 0, + kZDebugExample2 = 1 << 1 + // next new channel must be 1 << 2 (4) + // the current limitation is 32 debug channels (1 << 31 is the last one) +}; + +class ZVision : public Engine { +public: + ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc); + ~ZVision(); + + uint32 getFeatures() const; + Common::Language getLanguage() const; + virtual Common::Error run(); + +private: + Console *_console; + const ZVisionGameDescription *_gameDescription; + + // We need random numbers + Common::RandomSource *_rnd; +}; + +// Example console class +class Console : public GUI::Debugger { +public: + Console(ZVision *vm) {} + virtual ~Console(void) {} +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 0303850bf7089637b34ae487855bca866d57b580 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 6 Jun 2013 13:03:09 -0500 Subject: ZVISION: Allow detection to go off inner directory Game detection needs to be off an actual resource, but all the resources are in subdirectories. This updates the code to search for the specific subdirectory. --- engines/zvision/detection.cpp | 9 ++++++- engines/zvision/zvision.cpp | 60 ++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 28 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 345138b724..f8ed6a749b 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -68,7 +68,7 @@ static const ZVisionGameDescription gameDescriptions[] = { 0, AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), Common::EN_ANY, - Common::kPlatformWindows, + Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GUIO_NONE) }, @@ -79,6 +79,11 @@ static const ZVisionGameDescription gameDescriptions[] = { } // End of namespace ZVision +static const char *directoryGlobs[] = { + "znemscr", + 0 +}; + static const ExtraGuiOption ZVisionExtraGuiOption = { _s("Use original save/load screens"), _s("Use the original save/load screens, instead of the ScummVM ones"), @@ -89,6 +94,8 @@ static const ExtraGuiOption ZVisionExtraGuiOption = { class ZVisionMetaEngine : public AdvancedMetaEngine { public: ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { + _maxScanDepth = 2; + _directoryGlobs = directoryGlobs; _singleid = "zvision"; } diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 0e553e6287..d291cabc70 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -35,17 +35,11 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine // However this is the place to specify all default directories const Common::FSNode gameDataDir(ConfMan.get("path")); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/asylum"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/castle"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/conserv"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/endgame"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global/venus"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global2"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/global3"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/monast"); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets/temple"); + SearchMan.addSubDirectoryMatching(gameDataDir, "data1"); + SearchMan.addSubDirectoryMatching(gameDataDir, "data2"); + SearchMan.addSubDirectoryMatching(gameDataDir, "data3"); + SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx"); + SearchMan.addSubDirectoryMatching(gameDataDir, "znemscr"); // Here is the right place to set up the engine specific debug channels //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); @@ -160,10 +154,18 @@ Common::Error ZVision::run() { // This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline //debugC(3, kZVisionDebugExample | kZVisionDebugExample2, "Example debug call two"); + Common::File file; + + if (file.open("ADLIB.MDI")) { + file.close(); + } + + + #if 1 // Video test Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); - if (videoDecoder && videoDecoder->loadFile(/*"TD9EAZ1C.AVI"*/"T000A11C.AVI")) { + if (videoDecoder && videoDecoder->loadFile("ZASSETS/TEMPLE/T000A11C.AVI")) { Common::List formats; formats.push_back(videoDecoder->getPixelFormat()); initGraphics(640, 480, true, formats); @@ -176,29 +178,33 @@ Common::Error ZVision::run() { #if 1 // Image test - f.open("CB8EB11C.TGA"); + if (f.open("zassets/castle/CB8EB11C.TGA")) { + Graphics::TGADecoder tga; + if (!tga.loadStream(f)) + error("Error while reading TGA image"); + f.close(); - Graphics::TGADecoder tga; - if (!tga.loadStream(f)) - error("Error while reading TGA image"); - f.close(); + const Graphics::Surface *tgaSurface = tga.getSurface(); - const Graphics::Surface *tgaSurface = tga.getSurface(); + Graphics::Surface *screen = g_system->lockScreen(); + for (uint16 y = 0; y < tgaSurface->h; y++) + memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); + g_system->unlockScreen(); - Graphics::Surface *screen = g_system->lockScreen(); - for (uint16 y = 0; y < tgaSurface->h; y++) - memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); - g_system->unlockScreen(); + tga.destroy(); + } - tga.destroy(); + #endif #if 1 // Sound test - f.open("C000H9TC.RAW"); - Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); - Audio::SoundHandle handle; - g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); + if (f.open("zassets/castle/C000H9TC.RAW")) { + Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); + Audio::SoundHandle handle; + g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); + } + #endif // Main loop -- cgit v1.2.3 From 5d64107ff3c22324080e2a151a88c49e1ee6cb9d Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 6 Jun 2013 14:51:46 -0500 Subject: ZVISION: normalized file endings --- engines/zvision/detection.cpp | 506 +++++++++++++++++++++--------------------- 1 file changed, 253 insertions(+), 253 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index f8ed6a749b..5488ae5be4 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -1,256 +1,256 @@ -/* 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 "base/plugins.h" - -#include "engines/advancedDetector.h" - -#include "common/translation.h" -#include "common/savefile.h" -#include "common/str-array.h" -#include "common/system.h" - -#include "zvision/zvision.h" - - -namespace ZVision { - -struct ZVisionGameDescription { - ADGameDescription desc; -}; - -uint32 ZVision::getFeatures() const { - return _gameDescription->desc.flags; -} - -Common::Language ZVision::getLanguage() const { - return _gameDescription->desc.language; -} - -} - -static const PlainGameDescriptor zVisionGames[] = { - {"zvision", "ZVision Game"}, - {"znemesis", "Zork Nemesis: The Forbidden Lands"}, - {"zgi", "Zork: Grand Inquisitor"}, - {0, 0} -}; - - -namespace ZVision { - -static const ZVisionGameDescription gameDescriptions[] = { - - { - // Zork Nemesis English version - { - "znemesis", - 0, - AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), - Common::EN_ANY, - Common::kPlatformDOS, - ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) - }, - }, - - { AD_TABLE_END_MARKER } -}; - -} // End of namespace ZVision - +/* 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 "base/plugins.h" + +#include "engines/advancedDetector.h" + +#include "common/translation.h" +#include "common/savefile.h" +#include "common/str-array.h" +#include "common/system.h" + +#include "zvision/zvision.h" + + +namespace ZVision { + +struct ZVisionGameDescription { + ADGameDescription desc; +}; + +uint32 ZVision::getFeatures() const { + return _gameDescription->desc.flags; +} + +Common::Language ZVision::getLanguage() const { + return _gameDescription->desc.language; +} + +} + +static const PlainGameDescriptor zVisionGames[] = { + {"zvision", "ZVision Game"}, + {"znemesis", "Zork Nemesis: The Forbidden Lands"}, + {"zgi", "Zork: Grand Inquisitor"}, + {0, 0} +}; + + +namespace ZVision { + +static const ZVisionGameDescription gameDescriptions[] = { + + { + // Zork Nemesis English version + { + "znemesis", + 0, + AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), + Common::EN_ANY, + Common::kPlatformDOS, + ADGF_NO_FLAGS, + GUIO1(GUIO_NONE) + }, + }, + + { AD_TABLE_END_MARKER } +}; + +} // End of namespace ZVision + static const char *directoryGlobs[] = { "znemscr", 0 -}; - -static const ExtraGuiOption ZVisionExtraGuiOption = { - _s("Use original save/load screens"), - _s("Use the original save/load screens, instead of the ScummVM ones"), - "originalsaveload", - false -}; - -class ZVisionMetaEngine : public AdvancedMetaEngine { -public: - ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { - _maxScanDepth = 2; - _directoryGlobs = directoryGlobs; - _singleid = "zvision"; - } - - virtual const char *getName() const { - return "ZVision"; - } - - virtual const char *getOriginalCopyright() const { - return "ZVision Activision (C) 1996"; - } - - virtual bool hasFeature(MetaEngineFeature f) const; - virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; - virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; - SaveStateList listSaves(const char *target) const; - virtual int getMaximumSaveSlot() const; - void removeSaveState(const char *target, int slot) const; - SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; -}; - -bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { - return false; - /* - (f == kSupportsListSaves) || - (f == kSupportsLoadingDuringStartup) || - (f == kSupportsDeleteSave) || - (f == kSavesSupportMetaInfo) || - (f == kSavesSupportThumbnail) || - (f == kSavesSupportCreationDate) || - (f == kSavesSupportPlayTime); - */ -} - -/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { - return - (f == kSupportsRTL) || - (f == kSupportsLoadingDuringRuntime) || - (f == kSupportsSavingDuringRuntime); -}*/ - -bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { - const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; - if (gd) { - *engine = new ZVision::ZVision(syst, gd); - } - return gd != 0; -} - -const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String &target) const { - ExtraGuiOptions options; - options.push_back(ZVisionExtraGuiOption); - return options; -} - -SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { - //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - /*ZVision::ZVision::SaveHeader header; - Common::String pattern = target; - pattern += ".???"; - - Common::StringArray filenames; - filenames = saveFileMan->listSavefiles(pattern.c_str()); - Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ - - SaveStateList saveList; -/* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { - // Obtain the last 3 digits of the filename, since they correspond to the save slot - int slotNum = atoi(file->c_str() + file->size() - 3); - - if (slotNum >= 0 && slotNum <= 999) { - Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); - if (in) { - if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { - saveList.push_back(SaveStateDescriptor(slotNum, header.description)); - } - delete in; - } - } - }*/ - - return saveList; -} - -int ZVisionMetaEngine::getMaximumSaveSlot() const { - return 999; -} - -void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { - /* - Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); - - saveFileMan->removeSavefile(filename.c_str()); - - Common::StringArray filenames; - Common::String pattern = target; - pattern += ".???"; - filenames = saveFileMan->listSavefiles(pattern.c_str()); - Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) - - for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { - // Obtain the last 3 digits of the filename, since they correspond to the save slot - int slotNum = atoi(file->c_str() + file->size() - 3); - - // Rename every slot greater than the deleted slot, - if (slotNum > slot) { - saveFileMan->renameSavefile(file->c_str(), filename.c_str()); - filename = ZVision::ZVision::getSavegameFilename(target, ++slot); - } - } - */ -} - -SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { - /* - Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); - Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); - - if (in) { - ZVision::ZVision::SaveHeader header; - ZVision::ZVision::kReadSaveHeaderError error; - - error = ZVision::ZVision::readSaveHeader(in, true, header); - delete in; - - if (error == ZVision::ZVision::kRSHENoError) { - SaveStateDescriptor desc(slot, header.description); - - desc.setThumbnail(header.thumbnail); - - if (header.version > 0) { - int day = (header.saveDate >> 24) & 0xFF; - int month = (header.saveDate >> 16) & 0xFF; - int year = header.saveDate & 0xFFFF; - - desc.setSaveDate(year, month, day); - - int hour = (header.saveTime >> 16) & 0xFF; - int minutes = (header.saveTime >> 8) & 0xFF; - - desc.setSaveTime(hour, minutes); - - desc.setPlayTime(header.playTime * 1000); - } - - return desc; - } - } - */ - - return SaveStateDescriptor(); -} - -#if PLUGIN_ENABLED_DYNAMIC(ZVISION) - REGISTER_PLUGIN_DYNAMIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); -#else - REGISTER_PLUGIN_STATIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); -#endif +}; + +static const ExtraGuiOption ZVisionExtraGuiOption = { + _s("Use original save/load screens"), + _s("Use the original save/load screens, instead of the ScummVM ones"), + "originalsaveload", + false +}; + +class ZVisionMetaEngine : public AdvancedMetaEngine { +public: + ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { + _maxScanDepth = 2; + _directoryGlobs = directoryGlobs; + _singleid = "zvision"; + } + + virtual const char *getName() const { + return "ZVision"; + } + + virtual const char *getOriginalCopyright() const { + return "ZVision Activision (C) 1996"; + } + + virtual bool hasFeature(MetaEngineFeature f) const; + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; + SaveStateList listSaves(const char *target) const; + virtual int getMaximumSaveSlot() const; + void removeSaveState(const char *target, int slot) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; +}; + +bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { + return false; + /* + (f == kSupportsListSaves) || + (f == kSupportsLoadingDuringStartup) || + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail) || + (f == kSavesSupportCreationDate) || + (f == kSavesSupportPlayTime); + */ +} + +/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); +}*/ + +bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; + if (gd) { + *engine = new ZVision::ZVision(syst, gd); + } + return gd != 0; +} + +const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String &target) const { + ExtraGuiOptions options; + options.push_back(ZVisionExtraGuiOption); + return options; +} + +SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { + //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + /*ZVision::ZVision::SaveHeader header; + Common::String pattern = target; + pattern += ".???"; + + Common::StringArray filenames; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ + + SaveStateList saveList; +/* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { + saveList.push_back(SaveStateDescriptor(slotNum, header.description)); + } + delete in; + } + } + }*/ + + return saveList; +} + +int ZVisionMetaEngine::getMaximumSaveSlot() const { + return 999; +} + +void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { + /* + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + + saveFileMan->removeSavefile(filename.c_str()); + + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".???"; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + // Rename every slot greater than the deleted slot, + if (slotNum > slot) { + saveFileMan->renameSavefile(file->c_str(), filename.c_str()); + filename = ZVision::ZVision::getSavegameFilename(target, ++slot); + } + } + */ +} + +SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { + /* + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); + + if (in) { + ZVision::ZVision::SaveHeader header; + ZVision::ZVision::kReadSaveHeaderError error; + + error = ZVision::ZVision::readSaveHeader(in, true, header); + delete in; + + if (error == ZVision::ZVision::kRSHENoError) { + SaveStateDescriptor desc(slot, header.description); + + desc.setThumbnail(header.thumbnail); + + if (header.version > 0) { + int day = (header.saveDate >> 24) & 0xFF; + int month = (header.saveDate >> 16) & 0xFF; + int year = header.saveDate & 0xFFFF; + + desc.setSaveDate(year, month, day); + + int hour = (header.saveTime >> 16) & 0xFF; + int minutes = (header.saveTime >> 8) & 0xFF; + + desc.setSaveTime(hour, minutes); + + desc.setPlayTime(header.playTime * 1000); + } + + return desc; + } + } + */ + + return SaveStateDescriptor(); +} + +#if PLUGIN_ENABLED_DYNAMIC(ZVISION) + REGISTER_PLUGIN_DYNAMIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#else + REGISTER_PLUGIN_STATIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#endif -- cgit v1.2.3 From 8ae85892d60d502c582b43b5b6b77af2baccc739 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 8 Jun 2013 10:32:22 -0500 Subject: ZVISION: Alter video handling to follow the new video audio track wrapper. Commit 7a49802c01b0c39be4e86335689db8f3359fde68 created an audio track hook that allows video decoding to use a differnt audio track encoding method Also, re-normalize line endings --- engines/zvision/detection.cpp | 512 +++++++++++++++++------------------ engines/zvision/zork_avi_decoder.cpp | 94 +------ engines/zvision/zork_avi_decoder.h | 2 +- engines/zvision/zvision.cpp | 68 +++-- 4 files changed, 308 insertions(+), 368 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 5488ae5be4..62d834ac3f 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -1,256 +1,256 @@ -/* 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 "base/plugins.h" - -#include "engines/advancedDetector.h" - -#include "common/translation.h" -#include "common/savefile.h" -#include "common/str-array.h" -#include "common/system.h" - -#include "zvision/zvision.h" - - -namespace ZVision { - -struct ZVisionGameDescription { - ADGameDescription desc; -}; - -uint32 ZVision::getFeatures() const { - return _gameDescription->desc.flags; -} - -Common::Language ZVision::getLanguage() const { - return _gameDescription->desc.language; -} - -} - -static const PlainGameDescriptor zVisionGames[] = { - {"zvision", "ZVision Game"}, - {"znemesis", "Zork Nemesis: The Forbidden Lands"}, - {"zgi", "Zork: Grand Inquisitor"}, - {0, 0} -}; - - -namespace ZVision { - -static const ZVisionGameDescription gameDescriptions[] = { - - { - // Zork Nemesis English version - { - "znemesis", - 0, - AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), - Common::EN_ANY, - Common::kPlatformDOS, - ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) - }, - }, - - { AD_TABLE_END_MARKER } -}; - -} // End of namespace ZVision - -static const char *directoryGlobs[] = { - "znemscr", - 0 -}; - -static const ExtraGuiOption ZVisionExtraGuiOption = { - _s("Use original save/load screens"), - _s("Use the original save/load screens, instead of the ScummVM ones"), - "originalsaveload", - false -}; - -class ZVisionMetaEngine : public AdvancedMetaEngine { -public: - ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { - _maxScanDepth = 2; - _directoryGlobs = directoryGlobs; - _singleid = "zvision"; - } - - virtual const char *getName() const { - return "ZVision"; - } - - virtual const char *getOriginalCopyright() const { - return "ZVision Activision (C) 1996"; - } - - virtual bool hasFeature(MetaEngineFeature f) const; - virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; - virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; - SaveStateList listSaves(const char *target) const; - virtual int getMaximumSaveSlot() const; - void removeSaveState(const char *target, int slot) const; - SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; -}; - -bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { - return false; - /* - (f == kSupportsListSaves) || - (f == kSupportsLoadingDuringStartup) || - (f == kSupportsDeleteSave) || - (f == kSavesSupportMetaInfo) || - (f == kSavesSupportThumbnail) || - (f == kSavesSupportCreationDate) || - (f == kSavesSupportPlayTime); - */ -} - -/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { - return - (f == kSupportsRTL) || - (f == kSupportsLoadingDuringRuntime) || - (f == kSupportsSavingDuringRuntime); -}*/ - -bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { - const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; - if (gd) { - *engine = new ZVision::ZVision(syst, gd); - } - return gd != 0; -} - -const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String &target) const { - ExtraGuiOptions options; - options.push_back(ZVisionExtraGuiOption); - return options; -} - -SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { - //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - /*ZVision::ZVision::SaveHeader header; - Common::String pattern = target; - pattern += ".???"; - - Common::StringArray filenames; - filenames = saveFileMan->listSavefiles(pattern.c_str()); - Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ - - SaveStateList saveList; -/* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { - // Obtain the last 3 digits of the filename, since they correspond to the save slot - int slotNum = atoi(file->c_str() + file->size() - 3); - - if (slotNum >= 0 && slotNum <= 999) { - Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); - if (in) { - if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { - saveList.push_back(SaveStateDescriptor(slotNum, header.description)); - } - delete in; - } - } - }*/ - - return saveList; -} - -int ZVisionMetaEngine::getMaximumSaveSlot() const { - return 999; -} - -void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { - /* - Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); - - saveFileMan->removeSavefile(filename.c_str()); - - Common::StringArray filenames; - Common::String pattern = target; - pattern += ".???"; - filenames = saveFileMan->listSavefiles(pattern.c_str()); - Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) - - for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { - // Obtain the last 3 digits of the filename, since they correspond to the save slot - int slotNum = atoi(file->c_str() + file->size() - 3); - - // Rename every slot greater than the deleted slot, - if (slotNum > slot) { - saveFileMan->renameSavefile(file->c_str(), filename.c_str()); - filename = ZVision::ZVision::getSavegameFilename(target, ++slot); - } - } - */ -} - -SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { - /* - Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); - Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); - - if (in) { - ZVision::ZVision::SaveHeader header; - ZVision::ZVision::kReadSaveHeaderError error; - - error = ZVision::ZVision::readSaveHeader(in, true, header); - delete in; - - if (error == ZVision::ZVision::kRSHENoError) { - SaveStateDescriptor desc(slot, header.description); - - desc.setThumbnail(header.thumbnail); - - if (header.version > 0) { - int day = (header.saveDate >> 24) & 0xFF; - int month = (header.saveDate >> 16) & 0xFF; - int year = header.saveDate & 0xFFFF; - - desc.setSaveDate(year, month, day); - - int hour = (header.saveTime >> 16) & 0xFF; - int minutes = (header.saveTime >> 8) & 0xFF; - - desc.setSaveTime(hour, minutes); - - desc.setPlayTime(header.playTime * 1000); - } - - return desc; - } - } - */ - - return SaveStateDescriptor(); -} - -#if PLUGIN_ENABLED_DYNAMIC(ZVISION) - REGISTER_PLUGIN_DYNAMIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); -#else - REGISTER_PLUGIN_STATIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); -#endif +/* 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 "base/plugins.h" + +#include "engines/advancedDetector.h" + +#include "common/translation.h" +#include "common/savefile.h" +#include "common/str-array.h" +#include "common/system.h" + +#include "zvision/zvision.h" + + +namespace ZVision { + +struct ZVisionGameDescription { + ADGameDescription desc; +}; + +uint32 ZVision::getFeatures() const { + return _gameDescription->desc.flags; +} + +Common::Language ZVision::getLanguage() const { + return _gameDescription->desc.language; +} + +} + +static const PlainGameDescriptor zVisionGames[] = { + {"zvision", "ZVision Game"}, + {"znemesis", "Zork Nemesis: The Forbidden Lands"}, + {"zgi", "Zork: Grand Inquisitor"}, + {0, 0} +}; + + +namespace ZVision { + +static const ZVisionGameDescription gameDescriptions[] = { + + { + // Zork Nemesis English version + { + "znemesis", + 0, + AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), + Common::EN_ANY, + Common::kPlatformDOS, + ADGF_NO_FLAGS, + GUIO1(GUIO_NONE) + }, + }, + + { AD_TABLE_END_MARKER } +}; + +} // End of namespace ZVision + +static const char *directoryGlobs[] = { + "znemscr", + 0 +}; + +static const ExtraGuiOption ZVisionExtraGuiOption = { + _s("Use original save/load screens"), + _s("Use the original save/load screens, instead of the ScummVM ones"), + "originalsaveload", + false +}; + +class ZVisionMetaEngine : public AdvancedMetaEngine { +public: + ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { + _maxScanDepth = 2; + _directoryGlobs = directoryGlobs; + _singleid = "zvision"; + } + + virtual const char *getName() const { + return "ZVision"; + } + + virtual const char *getOriginalCopyright() const { + return "ZVision Activision (C) 1996"; + } + + virtual bool hasFeature(MetaEngineFeature f) const; + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; + SaveStateList listSaves(const char *target) const; + virtual int getMaximumSaveSlot() const; + void removeSaveState(const char *target, int slot) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; +}; + +bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { + return false; + /* + (f == kSupportsListSaves) || + (f == kSupportsLoadingDuringStartup) || + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail) || + (f == kSavesSupportCreationDate) || + (f == kSavesSupportPlayTime); + */ +} + +/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); +}*/ + +bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; + if (gd) { + *engine = new ZVision::ZVision(syst, gd); + } + return gd != 0; +} + +const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String &target) const { + ExtraGuiOptions options; + options.push_back(ZVisionExtraGuiOption); + return options; +} + +SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { + //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + /*ZVision::ZVision::SaveHeader header; + Common::String pattern = target; + pattern += ".???"; + + Common::StringArray filenames; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ + + SaveStateList saveList; +/* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { + saveList.push_back(SaveStateDescriptor(slotNum, header.description)); + } + delete in; + } + } + }*/ + + return saveList; +} + +int ZVisionMetaEngine::getMaximumSaveSlot() const { + return 999; +} + +void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { + /* + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + + saveFileMan->removeSavefile(filename.c_str()); + + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".???"; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + // Rename every slot greater than the deleted slot, + if (slotNum > slot) { + saveFileMan->renameSavefile(file->c_str(), filename.c_str()); + filename = ZVision::ZVision::getSavegameFilename(target, ++slot); + } + } + */ +} + +SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { + /* + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); + + if (in) { + ZVision::ZVision::SaveHeader header; + ZVision::ZVision::kReadSaveHeaderError error; + + error = ZVision::ZVision::readSaveHeader(in, true, header); + delete in; + + if (error == ZVision::ZVision::kRSHENoError) { + SaveStateDescriptor desc(slot, header.description); + + desc.setThumbnail(header.thumbnail); + + if (header.version > 0) { + int day = (header.saveDate >> 24) & 0xFF; + int month = (header.saveDate >> 16) & 0xFF; + int year = header.saveDate & 0xFFFF; + + desc.setSaveDate(year, month, day); + + int hour = (header.saveTime >> 16) & 0xFF; + int minutes = (header.saveTime >> 8) & 0xFF; + + desc.setSaveTime(hour, minutes); + + desc.setPlayTime(header.playTime * 1000); + } + + return desc; + } + } + */ + + return SaveStateDescriptor(); +} + +#if PLUGIN_ENABLED_DYNAMIC(ZVISION) + REGISTER_PLUGIN_DYNAMIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#else + REGISTER_PLUGIN_STATIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#endif diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp index 9bcc163721..b0524c7d2f 100644 --- a/engines/zvision/zork_avi_decoder.cpp +++ b/engines/zvision/zork_avi_decoder.cpp @@ -29,97 +29,9 @@ namespace ZVision { -// Redefinitions from avi_decoder.cpp -#define ID_VIDS MKTAG('v','i','d','s') -#define ID_TXTS MKTAG('t','x','t','s') -#define ID_STRF MKTAG('s','t','r','f') -#define ID_AUDS MKTAG('a','u','d','s') -#define ID_MIDS MKTAG('m','i','d','s') - -// Copied off AVIDecoder::handleStreamHeader() -void ZorkAVIDecoder::handleStreamHeader() { - AVIStreamHeader sHeader; - sHeader.size = _fileStream->readUint32LE(); - sHeader.streamType = _fileStream->readUint32BE(); - - if (sHeader.streamType == ID_MIDS || sHeader.streamType == ID_TXTS) - error("Unhandled MIDI/Text stream"); - - sHeader.streamHandler = _fileStream->readUint32BE(); - sHeader.flags = _fileStream->readUint32LE(); - sHeader.priority = _fileStream->readUint16LE(); - sHeader.language = _fileStream->readUint16LE(); - sHeader.initialFrames = _fileStream->readUint32LE(); - sHeader.scale = _fileStream->readUint32LE(); - sHeader.rate = _fileStream->readUint32LE(); - sHeader.start = _fileStream->readUint32LE(); - sHeader.length = _fileStream->readUint32LE(); - sHeader.bufferSize = _fileStream->readUint32LE(); - sHeader.quality = _fileStream->readUint32LE(); - sHeader.sampleSize = _fileStream->readUint32LE(); - - _fileStream->skip(sHeader.size - 48); // Skip over the remainder of the chunk (frame) - - if (_fileStream->readUint32BE() != ID_STRF) - error("Could not find STRF tag"); - - uint32 strfSize = _fileStream->readUint32LE(); - uint32 startPos = _fileStream->pos(); - - if (sHeader.streamType == ID_VIDS) { - BitmapInfoHeader bmInfo; - bmInfo.size = _fileStream->readUint32LE(); - bmInfo.width = _fileStream->readUint32LE(); - bmInfo.height = _fileStream->readUint32LE(); - bmInfo.planes = _fileStream->readUint16LE(); - bmInfo.bitCount = _fileStream->readUint16LE(); - bmInfo.compression = _fileStream->readUint32BE(); - bmInfo.sizeImage = _fileStream->readUint32LE(); - bmInfo.xPelsPerMeter = _fileStream->readUint32LE(); - bmInfo.yPelsPerMeter = _fileStream->readUint32LE(); - bmInfo.clrUsed = _fileStream->readUint32LE(); - bmInfo.clrImportant = _fileStream->readUint32LE(); - - if (bmInfo.clrUsed == 0) - bmInfo.clrUsed = 256; - - if (sHeader.streamHandler == 0) - sHeader.streamHandler = bmInfo.compression; - - AVIVideoTrack *track = new AVIVideoTrack(_header.totalFrames, sHeader, bmInfo); - - if (bmInfo.bitCount == 8) { - byte *palette = const_cast(track->getPalette()); - for (uint32 i = 0; i < bmInfo.clrUsed; i++) { - palette[i * 3 + 2] = _fileStream->readByte(); - palette[i * 3 + 1] = _fileStream->readByte(); - palette[i * 3] = _fileStream->readByte(); - _fileStream->readByte(); - } - - track->markPaletteDirty(); - } - - addTrack(track); - } else if (sHeader.streamType == ID_AUDS) { - PCMWaveFormat wvInfo; - wvInfo.tag = _fileStream->readUint16LE(); - wvInfo.channels = _fileStream->readUint16LE(); - wvInfo.samplesPerSec = _fileStream->readUint32LE(); - wvInfo.avgBytesPerSec = _fileStream->readUint32LE(); - wvInfo.blockAlign = _fileStream->readUint16LE(); - wvInfo.size = _fileStream->readUint16LE(); - - // AVI seems to treat the sampleSize as including the second - // channel as well, so divide for our sake. - if (wvInfo.channels == 2) - sHeader.sampleSize /= 2; - - addTrack(new ZorkAVIAudioTrack(sHeader, wvInfo, _soundType)); - } - - // Ensure that we're at the end of the chunk - _fileStream->seek(startPos + strfSize); +Video::AVIDecoder::AVIAudioTrack *ZVision::ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) { + ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType); + return (Video::AVIDecoder::AVIAudioTrack *)audioTrack; } void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { diff --git a/engines/zvision/zork_avi_decoder.h b/engines/zvision/zork_avi_decoder.h index f6b2ca7977..5530d92ce4 100644 --- a/engines/zvision/zork_avi_decoder.h +++ b/engines/zvision/zork_avi_decoder.h @@ -45,7 +45,7 @@ private: void queueSound(Common::SeekableReadStream *stream); }; - void handleStreamHeader(); + Video::AVIDecoder::AVIAudioTrack *createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo); private: // Audio Codecs diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index d291cabc70..1a72ea0e8c 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -61,6 +61,45 @@ ZVision::~ZVision() { DebugMan.clearAllDebugChannels(); } +// Taken from SCI +void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte bytesPerPixel) { + assert(bytesPerPixel == 1 || bytesPerPixel == 2); + const int newWidth = srcWidth * 2; + const int pitch = newWidth * bytesPerPixel; + const byte *srcPtr = src; + + if (bytesPerPixel == 1) { + for (int y = 0; y < srcHeight; y++) { + for (int x = 0; x < srcWidth; x++) { + const byte color = *srcPtr++; + dst[0] = color; + dst[1] = color; + dst[newWidth] = color; + dst[newWidth + 1] = color; + dst += 2; + } + dst += newWidth; + } + } else if (bytesPerPixel == 2) { + for (int y = 0; y < srcHeight; y++) { + for (int x = 0; x < srcWidth; x++) { + const byte color = *srcPtr++; + const byte color2 = *srcPtr++; + dst[0] = color; + dst[1] = color2; + dst[2] = color; + dst[3] = color2; + dst[pitch] = color; + dst[pitch + 1] = color2; + dst[pitch + 2] = color; + dst[pitch + 3] = color2; + dst += 4; + } + dst += pitch; + } + } +} + void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { if (!videoDecoder) return; @@ -75,32 +114,19 @@ void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { uint16 screenWidth = 640;//g_sci->_gfxScreen->getDisplayWidth(); uint16 screenHeight = 480;//g_sci->_gfxScreen->getDisplayHeight(); - //videoState.fileName.toLowercase(); + bool zoom2x = true; - /*if (screenWidth == 640 && width <= 320 && height <= 240 && ((videoState.flags & kDoubled))) { + if (zoom2x) { width *= 2; height *= 2; pitch *= 2; scaleBuffer = new byte[width * height * bytesPerPixel]; - }*/ + } uint16 x, y; - // Sanity check... - /*if (videoState.x > 0 && videoState.y > 0 && isVMD) { - x = videoState.x; - y = videoState.y; - - if (x + width > screenWidth || y + height > screenHeight) { - // Happens in the Lighthouse demo - warning("VMD video won't fit on screen, centering it instead"); - x = (screenWidth - width) / 2; - y = (screenHeight - height) / 2; - } - } else {*/ - x = (screenWidth - width) / 2; - y = (screenHeight - height) / 2; - //} + x = (screenWidth - width) / 2; + y = (screenHeight - height) / 2; bool skipVideo = false; @@ -110,8 +136,7 @@ void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { if (frame) { if (scaleBuffer) { - // TODO: Perhaps reuse the relevant function from SCI? - //g_sci->_gfxScreen->scale2x((byte *)frame->pixels, scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight(), bytesPerPixel); + scale2x((byte *)frame->pixels, scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight(), bytesPerPixel); g_system->copyRectToScreen(scaleBuffer, pitch, x, y, width, height); } else { g_system->copyRectToScreen(frame->pixels, frame->pitch, x, y, width, height); @@ -178,6 +203,9 @@ Common::Error ZVision::run() { #if 1 // Image test + + initGraphics(640, 480, true, &format); + if (f.open("zassets/castle/CB8EB11C.TGA")) { Graphics::TGADecoder tga; if (!tga.loadStream(f)) -- cgit v1.2.3 From 179f5de49897a723b2605a0fed18980ce144f68c Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 12 Jun 2013 15:11:21 -0500 Subject: ZVISION: Add support for ZFS archive files ZfsArchive implements Common::Archive. --- engines/zvision/zfsArchive.cpp | 144 +++++++++++++++++++++++++++++++++++++++++ engines/zvision/zfsArchive.h | 96 +++++++++++++++++++++++++++ engines/zvision/zvision.cpp | 12 ++++ 3 files changed, 252 insertions(+) create mode 100644 engines/zvision/zfsArchive.cpp create mode 100644 engines/zvision/zfsArchive.h (limited to 'engines/zvision') diff --git a/engines/zvision/zfsArchive.cpp b/engines/zvision/zfsArchive.cpp new file mode 100644 index 0000000000..a3111d7705 --- /dev/null +++ b/engines/zvision/zfsArchive.cpp @@ -0,0 +1,144 @@ +/* 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 "zfsArchive.h" +#include "common/hashmap.h" +#include "common/memstream.h" +#include "common/debug.h" + +namespace ZVision { + +ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { + Common::File zfsFile; + + if (!zfsFile.open(_fileName)) { + warning("ZFSArchive::ZFSArchive(): Could not find the archive file"); + return; + } + + readHeaders(&zfsFile); + + debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); +} + +ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) { + readHeaders(stream); + + debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); +} + +ZfsArchive::~ZfsArchive() { + debug(0, "ZfsArchive Destructor Called"); + ZfsEntryHeaderMap::iterator it = _entryHeaders.begin(); + for ( ; it != _entryHeaders.end(); ++it) { + delete it->_value; + } +} + +void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { + ZfsHeader header; + + // Don't do a straight struct cast since we can't guarantee endianness + header.magic = stream->readUint32LE(); + header.unknown1 = stream->readUint32LE(); + header.unknown2 = stream->readUint32LE(); + header.filesPerBlock = stream->readUint32LE(); + header.fileCount = stream->readUint32LE(); + header.xorKey = stream->readUint32LE(); + header.fileSectionOffset = stream->readUint32LE(); + + uint32 nextOffset; + + do { + // Read the offset to the next block + nextOffset = stream->readUint32LE(); + + // Read in each entry header + for (int i = 0; i < header.filesPerBlock; i++) { + ZfsEntryHeader entryHeader; + + entryHeader.name = readEntryName(stream); + entryHeader.offset = stream->readUint32LE(); + entryHeader.id = stream->readUint32LE(); + entryHeader.size = stream->readUint32LE(); + entryHeader.time = stream->readUint32LE(); + entryHeader.unknown = stream->readUint32LE(); + + if (entryHeader.size != 0) + _entryHeaders[entryHeader.name] = new ZfsEntryHeader(entryHeader); + } + + // Seek to the next block of headers + stream->seek(nextOffset); + } while (nextOffset != 0); +} + +Common::String ZfsArchive::readEntryName(Common::SeekableReadStream *stream) const { + // Entry Names are at most 16 bytes and are null padded + char buffer[16]; + stream->read(buffer, 16); + + return Common::String(buffer); +} + +bool ZfsArchive::hasFile(const Common::String &name) const { + return _entryHeaders.contains(name); +} + +int ZfsArchive::listMembers(Common::ArchiveMemberList &list) const { + int matches = 0; + + for (ZfsEntryHeaderMap::const_iterator it = _entryHeaders.begin(); it != _entryHeaders.end(); ++it) { + list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->name, this))); + matches++; + } + + return matches; +} + +const Common::ArchiveMemberPtr ZfsArchive::getMember(const Common::String &name) const { + if (!_entryHeaders.contains(name)) + return Common::ArchiveMemberPtr(); + + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); +} + +Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::String &name) const { + if (!_entryHeaders.contains(name)) { + return 0; + } + + ZfsEntryHeader *entryHeader = _entryHeaders[name]; + + Common::File zfsArchive; + zfsArchive.open(_fileName); + zfsArchive.seek(entryHeader->offset); + + byte* buffer = new byte[entryHeader->size]; + zfsArchive.read(buffer, entryHeader->size); + + return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES); +} + +} // End namespace ZVision + + diff --git a/engines/zvision/zfsArchive.h b/engines/zvision/zfsArchive.h new file mode 100644 index 0000000000..96c002f815 --- /dev/null +++ b/engines/zvision/zfsArchive.h @@ -0,0 +1,96 @@ +/* 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 ZVISION_ZFS_ARCHIVE_H +#define ZVISION_ZFS_ARCHIVE_H + +#include "common/archive.h" +#include "common/file.h" +#include "common/fs.h" + +namespace ZVision { + +struct ZfsHeader { + uint32 magic; + uint32 unknown1; + uint32 unknown2; + uint32 filesPerBlock; + uint32 fileCount; + uint32 xorKey; + uint32 fileSectionOffset; +}; + +struct ZfsEntryHeader { + Common::String name; + uint32 offset; + uint32 id; + uint32 size; + uint32 time; + uint32 unknown; +}; + +typedef Common::HashMap ZfsEntryHeaderMap; + +class ZfsArchive : public Common::Archive { +public: + ZfsArchive(const Common::String &fileName); + ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream); + ~ZfsArchive(); + + /** + * Check if a member with the given name is present in the Archive. + * Patterns are not allowed, as this is meant to be a quick File::exists() + * replacement. + */ + bool hasFile(const Common::String &fileName) const; + + /** + * Add all members of the Archive to list. + * Must only append to list, and not remove elements from it. + * + * @return the number of names added to list + */ + int listMembers(Common::ArchiveMemberList &list) const; + + /** + * Returns a ArchiveMember representation of the given file. + */ + const Common::ArchiveMemberPtr getMember(const Common::String &name) const; + + /** + * Create a stream bound to a member with the specified name in the + * archive. If no member with this name exists, 0 is returned. + * @return the newly created input stream + */ + Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; + +private: + const Common::String _fileName; + ZfsEntryHeaderMap _entryHeaders; + + void readHeaders(Common::SeekableReadStream *stream); + Common::String readEntryName(Common::SeekableReadStream *stream) const; +}; + +} // End of namespace Common + +#endif diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 1a72ea0e8c..b347782f59 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -21,6 +21,7 @@ #include "engines/util.h" #include "zvision/zvision.h" +#include "zvision/zfsArchive.h" #include "zvision/zork_avi_decoder.h" #include "zvision/zork_raw.h" @@ -160,6 +161,17 @@ void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { } Common::Error ZVision::run() { + // Register the files within the zfs archive files with the SearchMan + Common::ArchiveMemberList list; + SearchMan.listMatchingMembers(list, "*.zfs"); + + for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { + Common::String name = (*iter)->getName(); + ZfsArchive *archive = new ZfsArchive(name, (*iter)->createReadStream()); + + SearchMan.add(name, archive); + } + //Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); // ARGB8888 Graphics::PixelFormat format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); // RGB555 initGraphics(640, 480, true, &format); -- cgit v1.2.3 From ef37f14d539d417a1a4506c5c09df1409700aa30 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 12 Jun 2013 22:06:05 -0500 Subject: ZVISION: Add xor encryption handling to ZfsArchive class --- engines/zvision/zfsArchive.cpp | 29 +++++++++++++++++++---------- engines/zvision/zfsArchive.h | 28 ++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 12 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zfsArchive.cpp b/engines/zvision/zfsArchive.cpp index a3111d7705..59e65f1713 100644 --- a/engines/zvision/zfsArchive.cpp +++ b/engines/zvision/zfsArchive.cpp @@ -55,16 +55,17 @@ ZfsArchive::~ZfsArchive() { } void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { - ZfsHeader header; - // Don't do a straight struct cast since we can't guarantee endianness - header.magic = stream->readUint32LE(); - header.unknown1 = stream->readUint32LE(); - header.unknown2 = stream->readUint32LE(); - header.filesPerBlock = stream->readUint32LE(); - header.fileCount = stream->readUint32LE(); - header.xorKey = stream->readUint32LE(); - header.fileSectionOffset = stream->readUint32LE(); + _header.magic = stream->readUint32LE(); + _header.unknown1 = stream->readUint32LE(); + _header.maxNameLength = stream->readUint32LE(); + _header.filesPerBlock = stream->readUint32LE(); + _header.fileCount = stream->readUint32LE(); + _header.xorKey[0] = stream->readByte(); + _header.xorKey[1] = stream->readByte(); + _header.xorKey[2] = stream->readByte(); + _header.xorKey[3] = stream->readByte(); + _header.fileSectionOffset = stream->readUint32LE(); uint32 nextOffset; @@ -73,7 +74,7 @@ void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { nextOffset = stream->readUint32LE(); // Read in each entry header - for (int i = 0; i < header.filesPerBlock; i++) { + for (int i = 0; i < _header.filesPerBlock; i++) { ZfsEntryHeader entryHeader; entryHeader.name = readEntryName(stream); @@ -135,10 +136,18 @@ Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common:: byte* buffer = new byte[entryHeader->size]; zfsArchive.read(buffer, entryHeader->size); + // Decrypt the data in place + if (_header.xorKey != 0) + unXor(buffer, entryHeader->size, _header.xorKey); return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES); } +void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const { + for (uint32 i = 0; i < length; i++) + buffer[i] ^= xorKey[i % 4]; +} + } // End namespace ZVision diff --git a/engines/zvision/zfsArchive.h b/engines/zvision/zfsArchive.h index 96c002f815..718b26c836 100644 --- a/engines/zvision/zfsArchive.h +++ b/engines/zvision/zfsArchive.h @@ -32,10 +32,10 @@ namespace ZVision { struct ZfsHeader { uint32 magic; uint32 unknown1; - uint32 unknown2; + uint32 maxNameLength; uint32 filesPerBlock; uint32 fileCount; - uint32 xorKey; + byte xorKey[4]; uint32 fileSectionOffset; }; @@ -85,10 +85,34 @@ public: private: const Common::String _fileName; + ZfsHeader _header; ZfsEntryHeaderMap _entryHeaders; + /** + * Parses the zfs file into file entry headers that can be used later + * to get the entry data. + * + * @param stream The contents of the zfs file + */ void readHeaders(Common::SeekableReadStream *stream); + + /** + * Entry names are contained within a 16 byte block. This reads the block + * and converts it the name to a Common::String + * + * @param stream The zfs file stream + * @return The entry file name + */ Common::String readEntryName(Common::SeekableReadStream *stream) const; + + /** + * ZFS file entries can be encrypted using XOR encoding. This method + * decodes the buffer in place using the supplied xorKey. + * + * @param buffer The data to decode + * @param length Length of buffer + */ + void unXor(byte *buffer, int length, const byte *xorKey) const; }; } // End of namespace Common -- cgit v1.2.3 From b65fd98441cadecc44b6e8e06aa2558a282d33c7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 19 Jun 2013 13:59:25 -0500 Subject: ZVISION: Clean up includes --- engines/zvision/zfsArchive.cpp | 4 +++- engines/zvision/zork_avi_decoder.cpp | 2 ++ engines/zvision/zork_raw.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zfsArchive.cpp b/engines/zvision/zfsArchive.cpp index 59e65f1713..93a026e5b9 100644 --- a/engines/zvision/zfsArchive.cpp +++ b/engines/zvision/zfsArchive.cpp @@ -20,7 +20,9 @@ * */ -#include "zfsArchive.h" +#include "common/scummsys.h" + +#include "zvision/zfsArchive.h" #include "common/hashmap.h" #include "common/memstream.h" #include "common/debug.h" diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp index b0524c7d2f..2da524655b 100644 --- a/engines/zvision/zork_avi_decoder.cpp +++ b/engines/zvision/zork_avi_decoder.cpp @@ -21,6 +21,8 @@ * */ +#include "common/scummsys.h" + #include "common/stream.h" #include "audio/audiostream.h" diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 9332aeb52e..3c37f929b3 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -20,6 +20,8 @@ * */ +#include "common/scummsys.h" + #include "common/endian.h" #include "common/memstream.h" #include "common/textconsole.h" -- cgit v1.2.3 From 160d6256f2f391f37bd02c5c060f5db33db2a2f0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 19 Jun 2013 14:12:03 -0500 Subject: ZVISION: Create skeleton engine and move code away from Engine::Run The goal is to have Engine::Run as clean as possible. Aka mostly method calls. --- engines/zvision/events.cpp | 88 +++++++++++++++ engines/zvision/graphics.cpp | 37 ++++++ engines/zvision/scriptManager.h | 42 +++++++ engines/zvision/scripts.cpp | 31 +++++ engines/zvision/video.cpp | 185 ++++++++++++++++++++++++++++++ engines/zvision/zvision.cpp | 245 +++++++++------------------------------- engines/zvision/zvision.h | 30 ++++- 7 files changed, 461 insertions(+), 197 deletions(-) create mode 100644 engines/zvision/events.cpp create mode 100644 engines/zvision/graphics.cpp create mode 100644 engines/zvision/scriptManager.h create mode 100644 engines/zvision/scripts.cpp create mode 100644 engines/zvision/video.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp new file mode 100644 index 0000000000..8d10485ddf --- /dev/null +++ b/engines/zvision/events.cpp @@ -0,0 +1,88 @@ +/* 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/scummsys.h" + +#include "zvision.h" +#include "common/EventRecorder.h" + + +namespace ZVision { + +void ZVision::processEvents() { + while (_eventMan->pollEvent(_event)) { + switch (_event.type) { + case Common::EVENT_LBUTTONDOWN: + onMouseDown(_event.mouse); + break; + + case Common::EVENT_LBUTTONUP: + break; + + case Common::EVENT_RBUTTONDOWN: + break; + + case Common::EVENT_MOUSEMOVE: + onMouseMove(_event.mouse); + break; + + case Common::EVENT_KEYDOWN: + switch (_event.kbd.keycode) { + case Common::KEYCODE_d: + if (_event.kbd.hasFlags(Common::KBD_CTRL)) { + // Start the debugger + getDebugger()->attach(); + getDebugger()->onFrame(); + } + break; + + case Common::KEYCODE_q: + if (_event.kbd.hasFlags(Common::KBD_CTRL)) + quitGame(); + break; + + default: + break; + } + + onKeyDown(_event.kbd.keycode); + break; + + default: + break; + } + } +} + +void ZVision::onMouseDown(const Common::Point &pos) { + +} + +void ZVision::onMouseMove(const Common::Point &pos) { + +} + +void ZVision::onKeyDown(uint16 keyCode) { + +} + +} // End of namespace ZVision diff --git a/engines/zvision/graphics.cpp b/engines/zvision/graphics.cpp new file mode 100644 index 0000000000..17e7a4f06b --- /dev/null +++ b/engines/zvision/graphics.cpp @@ -0,0 +1,37 @@ +/* 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/scummsys.h" + +#include "zvision/zvision.h" + +namespace ZVision { + +void ZVision::updateScripts() { + +} + +void ZVision::updateAnimations(uint32 detaTimeMillis) { + +} + +} // End namespace ZVision diff --git a/engines/zvision/scriptManager.h b/engines/zvision/scriptManager.h new file mode 100644 index 0000000000..a6c9f2b57c --- /dev/null +++ b/engines/zvision/scriptManager.h @@ -0,0 +1,42 @@ +/* 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 ZVISION_SCRIPT_MANAGER_H +#define ZVISION_SCRIPT_MANAGER_H + +#include "common/hashmap.h" + +namespace ZVision { + +class ScriptManager { +public: + ScriptManager(); + ~ScriptManager(); + +private: + Common::HashMap _globalState; +}; + + +} // End namespace ZVision + +#endif diff --git a/engines/zvision/scripts.cpp b/engines/zvision/scripts.cpp new file mode 100644 index 0000000000..40bad8f3a1 --- /dev/null +++ b/engines/zvision/scripts.cpp @@ -0,0 +1,31 @@ +/* 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/scummsys.h" + +#include "zvision/zvision.h" + +namespace ZVision { + + + +} // End namespace ZVision diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp new file mode 100644 index 0000000000..ce686839e8 --- /dev/null +++ b/engines/zvision/video.cpp @@ -0,0 +1,185 @@ +/* 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/scummsys.h" +#include "common/system.h" + +#include "engines/engine.h" +#include "graphics/decoders/tga.h" + +#include "zvision/zork_avi_decoder.h" +#include "zvision/zork_raw.h" + +#include "common/EventRecorder.h" +#include "common/file.h" + +namespace ZVision { + +// Taken from SCI +void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte bytesPerPixel) { + assert(bytesPerPixel == 1 || bytesPerPixel == 2); + const int newWidth = srcWidth * 2; + const int pitch = newWidth * bytesPerPixel; + const byte *srcPtr = src; + + if (bytesPerPixel == 1) { + for (int y = 0; y < srcHeight; y++) { + for (int x = 0; x < srcWidth; x++) { + const byte color = *srcPtr++; + dst[0] = color; + dst[1] = color; + dst[newWidth] = color; + dst[newWidth + 1] = color; + dst += 2; + } + dst += newWidth; + } + } else if (bytesPerPixel == 2) { + for (int y = 0; y < srcHeight; y++) { + for (int x = 0; x < srcWidth; x++) { + const byte color = *srcPtr++; + const byte color2 = *srcPtr++; + dst[0] = color; + dst[1] = color2; + dst[2] = color; + dst[3] = color2; + dst[pitch] = color; + dst[pitch + 1] = color2; + dst[pitch + 2] = color; + dst[pitch + 3] = color2; + dst += 4; + } + dst += pitch; + } + } +} + +void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { + if (!videoDecoder) + return; + + videoDecoder->start(); + + byte *scaleBuffer = 0; + byte bytesPerPixel = videoDecoder->getPixelFormat().bytesPerPixel; + uint16 width = videoDecoder->getWidth(); + uint16 height = videoDecoder->getHeight(); + uint16 pitch = videoDecoder->getWidth() * bytesPerPixel; + uint16 screenWidth = 640;//g_sci->_gfxScreen->getDisplayWidth(); + uint16 screenHeight = 480;//g_sci->_gfxScreen->getDisplayHeight(); + + bool zoom2x = true; + + if (zoom2x) { + width *= 2; + height *= 2; + pitch *= 2; + scaleBuffer = new byte[width * height * bytesPerPixel]; + } + + uint16 x, y; + + x = (screenWidth - width) / 2; + y = (screenHeight - height) / 2; + + bool skipVideo = false; + + while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) { + if (videoDecoder->needsUpdate()) { + const Graphics::Surface *frame = videoDecoder->decodeNextFrame(); + + if (frame) { + if (scaleBuffer) { + scale2x((byte *)frame->pixels, scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight(), bytesPerPixel); + g_system->copyRectToScreen(scaleBuffer, pitch, x, y, width, height); + } else { + g_system->copyRectToScreen(frame->pixels, frame->pitch, x, y, width, height); + } + + g_system->updateScreen(); + } + } + + Common::Event event; + while (g_system->getEventManager()->pollEvent(event)) { + if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) + skipVideo = true; + } + + g_system->delayMillis(10); + } + + delete[] scaleBuffer; + delete videoDecoder; +} + +void tests() { +#if 0 + // Video test + Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); + if (videoDecoder && videoDecoder->loadFile("zassets/temple/t000a11c.avi")) { + Common::List formats; + formats.push_back(videoDecoder->getPixelFormat()); + //initGraphics(640, 480, true, formats); + + playVideo(videoDecoder); + } +#endif + + Common::File f; + +#if 0 + // Image test + + //initGraphics(640, 480, true, &format); + + if (f.open("zassets/castle/cb8eb11c.tga")) { + Graphics::TGADecoder tga; + if (!tga.loadStream(f)) + error("Error while reading TGA image"); + f.close(); + + const Graphics::Surface *tgaSurface = tga.getSurface(); + + Graphics::Surface *screen = g_system->lockScreen(); + for (uint16 y = 0; y < tgaSurface->h; y++) + memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); + g_system->unlockScreen(); + + tga.destroy(); + } + + +#endif + +#if 0 + // Sound test + if (f.open("zassets/castle/c000h9tc.raw")) { + Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); + Audio::SoundHandle handle; + g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); + } + +#endif +} + +} // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index b347782f59..2cc0b47113 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -1,29 +1,40 @@ +/* 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/scummsys.h" - + #include "common/config-manager.h" #include "common/debug.h" #include "common/debug-channels.h" #include "common/error.h" -#include "common/EventRecorder.h" +#include "common/system.h" #include "common/file.h" -#include "common/fs.h" - -#include "audio/audiostream.h" -#include "audio/mixer.h" - -#include "graphics/palette.h" -#include "graphics/surface.h" -#include "graphics/decoders/tga.h" - -#include "video/video_decoder.h" -#include "video/avi_decoder.h" #include "engines/util.h" #include "zvision/zvision.h" #include "zvision/zfsArchive.h" -#include "zvision/zork_avi_decoder.h" -#include "zvision/zork_raw.h" + +#include "graphics/decoders/tga.h" namespace ZVision { @@ -36,9 +47,9 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine // However this is the place to specify all default directories const Common::FSNode gameDataDir(ConfMan.get("path")); - SearchMan.addSubDirectoryMatching(gameDataDir, "data1"); - SearchMan.addSubDirectoryMatching(gameDataDir, "data2"); - SearchMan.addSubDirectoryMatching(gameDataDir, "data3"); + SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4); + SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4); + SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4); SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx"); SearchMan.addSubDirectoryMatching(gameDataDir, "znemscr"); @@ -62,109 +73,12 @@ ZVision::~ZVision() { DebugMan.clearAllDebugChannels(); } -// Taken from SCI -void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte bytesPerPixel) { - assert(bytesPerPixel == 1 || bytesPerPixel == 2); - const int newWidth = srcWidth * 2; - const int pitch = newWidth * bytesPerPixel; - const byte *srcPtr = src; - - if (bytesPerPixel == 1) { - for (int y = 0; y < srcHeight; y++) { - for (int x = 0; x < srcWidth; x++) { - const byte color = *srcPtr++; - dst[0] = color; - dst[1] = color; - dst[newWidth] = color; - dst[newWidth + 1] = color; - dst += 2; - } - dst += newWidth; - } - } else if (bytesPerPixel == 2) { - for (int y = 0; y < srcHeight; y++) { - for (int x = 0; x < srcWidth; x++) { - const byte color = *srcPtr++; - const byte color2 = *srcPtr++; - dst[0] = color; - dst[1] = color2; - dst[2] = color; - dst[3] = color2; - dst[pitch] = color; - dst[pitch + 1] = color2; - dst[pitch + 2] = color; - dst[pitch + 3] = color2; - dst += 4; - } - dst += pitch; - } - } -} - -void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { - if (!videoDecoder) - return; - - videoDecoder->start(); - - byte *scaleBuffer = 0; - byte bytesPerPixel = videoDecoder->getPixelFormat().bytesPerPixel; - uint16 width = videoDecoder->getWidth(); - uint16 height = videoDecoder->getHeight(); - uint16 pitch = videoDecoder->getWidth() * bytesPerPixel; - uint16 screenWidth = 640;//g_sci->_gfxScreen->getDisplayWidth(); - uint16 screenHeight = 480;//g_sci->_gfxScreen->getDisplayHeight(); - - bool zoom2x = true; - - if (zoom2x) { - width *= 2; - height *= 2; - pitch *= 2; - scaleBuffer = new byte[width * height * bytesPerPixel]; - } - - uint16 x, y; - - x = (screenWidth - width) / 2; - y = (screenHeight - height) / 2; - - bool skipVideo = false; - - while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) { - if (videoDecoder->needsUpdate()) { - const Graphics::Surface *frame = videoDecoder->decodeNextFrame(); - - if (frame) { - if (scaleBuffer) { - scale2x((byte *)frame->pixels, scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight(), bytesPerPixel); - g_system->copyRectToScreen(scaleBuffer, pitch, x, y, width, height); - } else { - g_system->copyRectToScreen(frame->pixels, frame->pitch, x, y, width, height); - } - - g_system->updateScreen(); - } - } - - Common::Event event; - while (g_system->getEventManager()->pollEvent(event)) { - if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) - skipVideo = true; - } - - g_system->delayMillis(10); - } - - delete[] scaleBuffer; - delete videoDecoder; -} - Common::Error ZVision::run() { - // Register the files within the zfs archive files with the SearchMan + // Find zfs archive files Common::ArchiveMemberList list; SearchMan.listMatchingMembers(list, "*.zfs"); + // Register the file entries within the zfs archives with the SearchMan for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { Common::String name = (*iter)->getName(); ZfsArchive *archive = new ZfsArchive(name, (*iter)->createReadStream()); @@ -178,86 +92,35 @@ Common::Error ZVision::run() { // Create debugger console. It requires GFX to be initialized _console = new Console(this); - - // Additional setup. - debug("ZVision::init"); - - // Your main even loop should be (invoked from) here. - debug("ZVision::go: Hello, World!"); - - // This test will show up if -d1 and --debugflags=example are specified on the commandline - //debugC(1, kZVisionDebugExample, "Example debug call"); - - // This test will show up if --debugflags=example or --debugflags=example2 or both of them and -d3 are specified on the commandline - //debugC(3, kZVisionDebugExample | kZVisionDebugExample2, "Example debug call two"); - - Common::File file; - - if (file.open("ADLIB.MDI")) { - file.close(); - } - - - -#if 1 - // Video test - Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); - if (videoDecoder && videoDecoder->loadFile("ZASSETS/TEMPLE/T000A11C.AVI")) { - Common::List formats; - formats.push_back(videoDecoder->getPixelFormat()); - initGraphics(640, 480, true, formats); - - playVideo(videoDecoder); - } -#endif - - Common::File f; - -#if 1 - // Image test - - initGraphics(640, 480, true, &format); - - if (f.open("zassets/castle/CB8EB11C.TGA")) { - Graphics::TGADecoder tga; - if (!tga.loadStream(f)) - error("Error while reading TGA image"); - f.close(); - - const Graphics::Surface *tgaSurface = tga.getSurface(); - - Graphics::Surface *screen = g_system->lockScreen(); - for (uint16 y = 0; y < tgaSurface->h; y++) - memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); - g_system->unlockScreen(); - - tga.destroy(); - } - - -#endif - -#if 1 - // Sound test - if (f.open("zassets/castle/C000H9TC.RAW")) { - Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); - Audio::SoundHandle handle; - g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); - } - -#endif // Main loop - Common::EventManager *eventMan = g_system->getEventManager(); - Common::Event event; + uint32 currentTime = _system->getMillis(); + uint32 lastTime = currentTime; + const uint32 desiredFrameTime = 33; // ~30 fps while (!shouldQuit()) { - eventMan->pollEvent(event); // eat events - g_system->updateScreen(); - g_system->delayMillis(10); + processEvents(); + + currentTime = _system->getMillis(); + uint32 deltaTime = currentTime - lastTime; + lastTime = currentTime; + + updateScripts(); + updateAnimations(deltaTime); + + if (_needsScreenUpdate) + { + _system->updateScreen(); + } + + // Calculate the frame delay based off a desired frame rate + int delay = desiredFrameTime - (currentTime - _system->getMillis()); + // Ensure non-negative + delay = delay < 0 ? 0 : delay; + _system->delayMillis(delay); } return Common::kNoError; } - + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index c2a42f1e21..b4664d0e29 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -23,9 +23,12 @@ #ifndef ZVISION_H #define ZVISION_H - + #include "common/random.h" +#include "common/events.h" + #include "engines/engine.h" + #include "gui/debugger.h" namespace ZVision { @@ -45,17 +48,32 @@ class ZVision : public Engine { public: ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc); ~ZVision(); - - uint32 getFeatures() const; - Common::Language getLanguage() const; - virtual Common::Error run(); - + private: Console *_console; const ZVisionGameDescription *_gameDescription; // We need random numbers Common::RandomSource *_rnd; + + // To prevent allocation every time we process events + Common::Event _event; + + bool _needsScreenUpdate; + +public: + uint32 getFeatures() const; + Common::Language getLanguage() const; + virtual Common::Error run(); + +private: + void processEvents(); + void onMouseDown(const Common::Point &pos); + void onMouseMove(const Common::Point &pos); + void onKeyDown(uint16 keyCode); + + void updateScripts(); + void updateAnimations(uint32 detaTimeMillis); }; // Example console class -- cgit v1.2.3 From a8980a4f771ae0ca926c9f38ee4d2e031c29318d Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 19 Jun 2013 15:45:48 -0500 Subject: ZVISION: Create utility function that writes File contents to another File scr files are stored and encrypted in archive files. This is an easy way to dump them for debugging purposes. --- engines/zvision/utility.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 engines/zvision/utility.h (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h new file mode 100644 index 0000000000..15f9490a4b --- /dev/null +++ b/engines/zvision/utility.h @@ -0,0 +1,50 @@ +/* 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 ZVISION_UTILITY_H +#define ZVISION_UTILITY_H + +#include "common/str.h" +#include "common/file.h" + +namespace ZVision { + +void WriteFileContentsToFile(Common::String sourceFile, Common::String destFile) { + Common::File f; + f.open(sourceFile); + byte* buffer = new byte[f.size()]; + f.read(buffer, f.size()); + + Common::DumpFile dumpFile; + dumpFile.open(destFile); + + uint32 writtenBytes = dumpFile.write(buffer, f.size()); + dumpFile.flush(); + dumpFile.close(); + + delete[] buffer; +} + +} // End namespace ZVision + +#endif -- cgit v1.2.3 From f444a1fd38329e77624ecd10c753d6b5ce6edf94 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 00:31:14 -0500 Subject: ZVISION: Create Object class. --- engines/zvision/object.cpp | 371 +++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/object.h | 121 +++++++++++++++ 2 files changed, 492 insertions(+) create mode 100644 engines/zvision/object.cpp create mode 100644 engines/zvision/object.h (limited to 'engines/zvision') diff --git a/engines/zvision/object.cpp b/engines/zvision/object.cpp new file mode 100644 index 0000000000..253eaf7ace --- /dev/null +++ b/engines/zvision/object.cpp @@ -0,0 +1,371 @@ +/* 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/scummsys.h" +#include "common/textconsole.h" + +#include "zvision/object.h" + +namespace ZVision { + +Object::Object(ObjectType type) { + _objectType = type; + + switch (type) { + case BOOL: + _value.boolVal = new bool; + break; + case BYTE: + _value.byteVal = new byte; + break; + case INT16: + _value.int16Val = new int16; + break; + case UINT16: + _value.uint16Val = new uint16; + break; + case INT32: + _value.int32Val = new int32; + break; + case UINT32: + _value.uint32Val = new uint32; + break; + case FLOAT: + _value.floatVal = new float; + break; + case DOUBLE: + _value.doubleVal = new double; + break; + case STRING: + _value.stringVal = new Common::String; + break; + } +} + +Object::Object(bool value) : _objectType(BOOL) { + _value.boolVal = new bool(value); +} + +Object::Object(byte value) : _objectType(BYTE) { + _value.byteVal = new byte(value); +} + +Object::Object(int16 value) : _objectType(INT16) { + _value.int16Val = new int16(value); +} + +Object::Object(uint16 value) : _objectType(UINT16) { + _value.uint16Val = new uint16(value); +} + +Object::Object(int32 value) : _objectType(INT32) { + _value.int32Val = new int32(value); +} + +Object::Object(uint32 value) : _objectType(UINT32) { + _value.uint32Val = new uint32(value); +} + +Object::Object(float value) : _objectType(FLOAT) { + _value.floatVal = new float(value); +} + +Object::Object(double value) : _objectType(DOUBLE) { + _value.doubleVal = new double(value); +} + +Object::Object(Common::String value) : _objectType(BYTE) { + _value.stringVal = new Common::String(value); +} + +Object::Object(const Object& other) { + _objectType = other._objectType; + + switch (_objectType) { + case BOOL: + _value.boolVal = new bool(*other._value.boolVal); + break; + case BYTE: + _value.byteVal = new byte(*other._value.byteVal); + break; + case INT16: + _value.int16Val = new int16(*other._value.int16Val); + break; + case UINT16: + _value.uint16Val = new uint16(*other._value.uint16Val); + break; + case INT32: + _value.int32Val = new int32(*other._value.int32Val); + break; + case UINT32: + _value.uint32Val = new uint32(*other._value.uint32Val); + break; + case FLOAT: + _value.floatVal = new float(*other._value.floatVal); + break; + case DOUBLE: + _value.doubleVal = new double(*other._value.doubleVal); + break; + case STRING: + _value.stringVal = new Common::String(*other._value.stringVal); + break; + } +} + +Object::~Object() { + deleteValue(); +} + +void Object::deleteValue() { + // Call delete on the correct part of the union. + // Even though they all point to the same memory and will all be cast + // to a void *, compiler optimizations could cause undefined behavior. + switch (_objectType) { + case BOOL: + delete _value.boolVal; + break; + case BYTE: + delete _value.byteVal; + break; + case INT16: + delete _value.int16Val; + break; + case UINT16: + delete _value.uint16Val; + break; + case INT32: + delete _value.int32Val; + break; + case UINT32: + delete _value.uint32Val; + break; + case FLOAT: + delete _value.floatVal; + break; + case DOUBLE: + delete _value.doubleVal; + break; + case STRING: + delete _value.stringVal; + break; + } +} + + +Object& Object::operator=(const bool& rhs) { + if (_objectType == BOOL) + *_value.boolVal = rhs; + else { + deleteValue(); + _objectType = BOOL; + _value.boolVal = new bool(rhs); + } + + return *this; +} + +Object& Object::operator=(const byte& rhs) { + if (_objectType == BYTE) + *_value.byteVal = rhs; + else { + deleteValue(); + _objectType = BYTE; + _value.byteVal = new byte(rhs); + } + + return *this; +} + +Object& Object::operator=(const int16& rhs) { + if (_objectType == INT16) + *_value.int16Val = rhs; + else { + deleteValue(); + _objectType = INT16; + _value.int16Val = new int16(rhs); + } + + return *this; +} + +Object& Object::operator=(const uint16& rhs) { + if (_objectType == UINT16) + *_value.uint16Val = rhs; + else { + deleteValue(); + _objectType = UINT16; + _value.uint16Val = new uint16(rhs); + } + + return *this; +} + +Object& Object::operator=(const int32& rhs) { + if (_objectType == INT32) + *_value.int32Val = rhs; + else { + deleteValue(); + _objectType = INT32; + _value.int32Val = new int32(rhs); + } + + return *this; +} + +Object& Object::operator=(const uint32& rhs) { + if (_objectType == UINT32) + *_value.uint32Val = rhs; + else { + deleteValue(); + _objectType = UINT32; + _value.uint32Val = new uint32(rhs); + } + + return *this; +} + +Object& Object::operator=(const float& rhs) { + if (_objectType == FLOAT) + *_value.floatVal = rhs; + else { + deleteValue(); + _objectType = FLOAT; + _value.floatVal = new float(rhs); + } + + return *this; +} + +Object& Object::operator=(const double& rhs) { + if (_objectType == DOUBLE) + *_value.doubleVal = rhs; + else { + deleteValue(); + _objectType = DOUBLE; + _value.doubleVal = new double(rhs); + } + + return *this; +} + +Object& Object::operator=(const Common::String& rhs) { + if (_objectType == STRING) + *_value.stringVal = rhs; + else { + deleteValue(); + _objectType = STRING; + _value.stringVal = new Common::String(rhs); + } + + return *this; +} + +Object& Object::operator=(const Object& rhs) { + switch (_objectType) { + case BOOL: + return operator=(*rhs._value.boolVal); + case BYTE: + return operator=(*rhs._value.byteVal); + case INT16: + return operator=(*rhs._value.int16Val); + case UINT16: + return operator=(*rhs._value.uint16Val); + case INT32: + return operator=(*rhs._value.int32Val); + case UINT32: + return operator=(*rhs._value.uint32Val); + case FLOAT: + return operator=(*rhs._value.floatVal); + case DOUBLE: + return operator=(*rhs._value.doubleVal); + case STRING: + return operator=(*rhs._value.stringVal); + } + + return *this; +} + + +Object::operator bool() { + if (_objectType != BOOL) + warning("'Object' not of type bool. Bad cast"); + + return *_value.boolVal; +} + +Object::operator byte() { + if (_objectType != BYTE) + warning("'Object' not of type byte. Bad cast"); + + return *_value.byteVal; +} + +Object::operator int16() { + if (_objectType != INT16) + warning("'Object' not of type int16. Bad cast"); + + return *_value.int16Val; +} + +Object::operator uint16() { + if (_objectType != UINT16) + warning("'Object' not of type uint16. Bad cast"); + + return *_value.uint16Val; +} + +Object::operator int32() { + if (_objectType != INT32) + warning("'Object' not of type int32. Bad cast"); + + return *_value.int32Val; +} + +Object::operator uint32() { + if (_objectType != UINT32) + warning("'Object' not of type uint32. Bad cast"); + + return *_value.uint32Val; +} + +Object::operator float() { + if (_objectType != FLOAT) + warning("'Object' not of type float. Bad cast"); + + return *_value.floatVal; +} + +Object::operator double() { + if (_objectType != DOUBLE) + warning("'Object' not of type double. Bad cast"); + + return *_value.doubleVal; +} + +Object::operator Common::String() { + if (_objectType != STRING) + warning("'Object' not of type Common::String. Bad cast"); + + return *_value.stringVal; +} + +} // End namespace ZVision diff --git a/engines/zvision/object.h b/engines/zvision/object.h new file mode 100644 index 0000000000..02ca962239 --- /dev/null +++ b/engines/zvision/object.h @@ -0,0 +1,121 @@ +/* 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 ZVISION_OBJECT_H +#define ZVISION_OBJECT_H + +#include "common/str.h" + +namespace ZVision { + + +enum ObjectType { + BOOL, + BYTE, + INT16, + UINT16, + INT32, + UINT32, + FLOAT, + DOUBLE, + STRING, +}; + +/** + * A generic single value storage class. It is useful for storing different + * value types in a single List, Hashmap, etc. + * + * Mimics C#'s Object class + * + * Caution: The actual value is stored on the heap, so be careful creating + * many objects of this class. Also, when re-using 'Object', try to assign + * a value of the same type as before, as this will prevent an extra memory allocation. + */ +class Object { +public: + // Constructors + Object(ObjectType type); + Object(bool value); + Object(byte value); + Object(int16 value); + Object(uint16 value); + Object(int32 value); + Object(uint32 value); + Object(float value); + Object(double value); + Object(Common::String value); + + // Copy constructor + Object(const Object& other); + + // Destructor + ~Object(); + +private: + ObjectType _objectType; + + union { + bool *boolVal; + byte *byteVal; + int16 *int16Val; + uint16 *uint16Val; + int32 *int32Val; + uint32 *uint32Val; + float *floatVal; + double *doubleVal; + Common::String *stringVal; + } _value; + +public: + Object& operator=(const bool& rhs); + Object& operator=(const byte& rhs); + Object& operator=(const int16& rhs); + Object& operator=(const uint16& rhs); + Object& operator=(const int32& rhs); + Object& operator=(const uint32& rhs); + Object& operator=(const float& rhs); + Object& operator=(const double& rhs); + Object& operator=(const Common::String& rhs); + + Object& operator=(const Object& rhs); + + operator bool(); + operator byte(); + operator int16(); + operator uint16(); + operator int32(); + operator uint32(); + operator float(); + operator double(); + operator Common::String(); + +private: + /** + * Helper method for destruction and assignment. Calls delete on + * the currently used data pointer + */ + void deleteValue(); +}; + +} // End namespace ZVision + +#endif -- cgit v1.2.3 From 2ada5a8dd7d953d35ddb8ad56a6827cc95daa1cb Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 00:43:57 -0500 Subject: ZVISION: Split puzzleControl into two files. Add ResultAction enum After further investigation, puzzles and controls don't really share any structs. So it makes more sense to keep them seperate. --- engines/zvision/control.h | 37 ++++++++++++++ engines/zvision/puzzle.h | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 engines/zvision/control.h create mode 100644 engines/zvision/puzzle.h (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h new file mode 100644 index 0000000000..46a7211702 --- /dev/null +++ b/engines/zvision/control.h @@ -0,0 +1,37 @@ +/* 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 ZVISION_CONTROL_H +#define ZVISION_CONTROL_H + +#include "common/scummsys.h" + +namespace ZVision { + +struct Control { + uint16 id; + +}; + +} // End namespace ZVision + +#endif diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h new file mode 100644 index 0000000000..cb44a440e1 --- /dev/null +++ b/engines/zvision/puzzle.h @@ -0,0 +1,119 @@ +/* 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 ZVISION_PUZZLE_H +#define ZVISION_PUZZLE_H + +#include "common/list.h" + +#include "zvision/object.h" + +namespace ZVision { + +/** How criteria should be decided */ +enum CriteriaOperator { + EQUAL_TO, + NOT_EQUAL_TO, + GREATER_THAN, + LESS_THAN +}; + +/** Criteria for a Puzzle result to be fired */ +struct Criteria { + /** The id of a global state */ + uint32 id; + /** + * What we're comparing the value of the global state against + * This can either be a pure value or it can be the id of another global state + */ + uint32 argument; + /** How to do the comparison */ + CriteriaOperator criteriaOperator; + /** Is 'argument' the id of a global state or a pure value */ + bool argumentIsAnId; +}; + +/** What happens when Puzzle criteria are met */ +enum ResultAction { + ADD, + ANIM_PLAY, + ANIM_PRELOAD, + ANIM_UNLOAD, + ATTENUATE, + ASSIGN, + CHANGE_LOCATION, + CROSSFADE, + DEBUG, + DELAY_RENDER, + DISABLE_CONTROL, + DISABLE_VENUS, + DISPLAY_MESSAGE, + DISSOLVE, + DISTORT, + ENABLE_CONTROL, + FLUSH_MOUSE_EVENTS, + INVENTORY, + KILL, + MENU_BAR_ENABLE, + MUSIC, + PAN_TRACK, + PLAY_PRELOAD, + PREFERENCES, + QUIT, + RANDOM, + REGION, + RESTORE_GAME, + ROTATE_TO, + SAVE_GAME, + SET_PARTIAL_SCREEN, + SET_SCREEN, + SET_VENUS, + STOP, + STREAM_VIDEO, + SYNC_SOUND, + TIMER, + TTY_TEXT, + UNIVERSE_MUSIC, +}; + +/** What happens when Puzzle criteria are met */ +struct Result { + ResultAction action; + Common::List arguments; +}; + +enum StateFlags : byte { + ONCE_PER_INST = 0x01, + DO_ME_NOW = 0x02, + DISABLED = 0x04 +}; + +struct Puzzle { + uint32 id; + Common::List criteriaList; + Common::List resultList; + byte flags; +}; + +} + +#endif -- cgit v1.2.3 From 8243263b33fe7aaf4e1144104f1189cd03636ff0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 00:46:27 -0500 Subject: ZVISION: Add documentation to utility functions and add a glorified trim function --- engines/zvision/utility.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 15f9490a4b..0777ba9ebc 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -29,7 +29,14 @@ namespace ZVision { -void WriteFileContentsToFile(Common::String sourceFile, Common::String destFile) { +/** + * 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(Common::String sourceFile, Common::String destFile) { Common::File f; f.open(sourceFile); byte* buffer = new byte[f.size()]; @@ -45,6 +52,23 @@ void WriteFileContentsToFile(Common::String sourceFile, Common::String destFile) delete[] buffer; } +/** + * Removes any line comments using '#' as a sequence start. + * Then removes any trailing and leading 'whitespace'. + * Uses isspace() to determine what is whitespace and what is not. + * + * @param string The string to modify. It is modified in place + */ +void trimCommentsAndWhiteSpace(Common::String &string) { + for (int i = string.size(); i >= 0; --i) { + if (string[i] == '#') { + string.erase(i); + } + } + + string.trim(); +} + } // End namespace ZVision #endif -- cgit v1.2.3 From 75e513c46ca086a7047e906af7d4e9bd5d52c5c7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 00:57:07 -0500 Subject: ZVISION: Create base puzzle parsing. --- engines/zvision/scrFileHandling.cpp | 325 ++++++++++++++++++++++++++++++++++++ engines/zvision/scriptManager.h | 62 +++++++ 2 files changed, 387 insertions(+) create mode 100644 engines/zvision/scrFileHandling.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/scrFileHandling.cpp b/engines/zvision/scrFileHandling.cpp new file mode 100644 index 0000000000..f4b5bab6fb --- /dev/null +++ b/engines/zvision/scrFileHandling.cpp @@ -0,0 +1,325 @@ +/* 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/scummsys.h" + +#include + +#include "zvision/scriptManager.h" +#include "zvision/utility.h" + +#include "common/textconsole.h" +#include "common/file.h" +#include "common/tokenizer.h" + +namespace ZVision { + + +void ScriptManager::parseScrFile(Common::String fileName) { + Common::File file; + if (!file.open(fileName)) + return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another + + char buffer[1024]; + while(!file.eos()) { + Common::String line = file.readLine(); + if (file.err()) { + warning("Error parsing scr file: %s", fileName); + return; + } + + trimCommentsAndWhiteSpace(line); + if (line.empty()) + continue; + + if (line.matchString("puzzle:*", true)) { + Puzzle *puzzle = new Puzzle(); + sscanf(line.c_str(),"puzzle:%u",&(puzzle->id)); + + parsePuzzle(puzzle, file); + } else if (line.matchString("control:*", true)) { + Control *control = new Control(); + sscanf(line.c_str(),"control:%u",&(control->id)); + + parseControl(control, file); + } + } +} + +void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream) { + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + if (line.matchString("criteria {", true)) + puzzle->criteriaList.push_back(parseCriteria(stream)); + else if (line.matchString("results {", true)) + puzzle->resultList.push_back(parseResult(stream)); + else if (line.matchString("flags {", true)) + puzzle->flags = parseFlags(stream); + } + +} + +Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const { + Criteria criteria; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + // Split the string into tokens using ' ' as a delimiter + Common::StringTokenizer tokenizer(line); + Common::String token; + + // Parse the id out of the first token + token = tokenizer.nextToken(); + sscanf(token.c_str(), "[%u]", &(criteria.id)); + + // Parse the operator out of the second token + token = tokenizer.nextToken(); + if (token.c_str()[0] == '=') + criteria.criteriaOperator = EQUAL_TO; + else if (token.c_str()[0] == '!') + criteria.criteriaOperator = NOT_EQUAL_TO; + else if (token.c_str()[0] == '>') + criteria.criteriaOperator = GREATER_THAN; + else if (token.c_str()[0] == '<') + criteria.criteriaOperator = LESS_THAN; + + // First determine if the last token is an id or a value + // Then parse it into 'argument' + token = tokenizer.nextToken(); + if (token.contains('[')) { + sscanf(token.c_str(), "[%u]", &(criteria.argument)); + criteria.argumentIsAnId = true; + } else { + sscanf(token.c_str(), "%u", &(criteria.argument)); + criteria.argumentIsAnId = false; + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + } + + return criteria; +} + +Result ScriptManager::parseResult(Common::SeekableReadStream &stream) const { + Result result; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + Common::StringTokenizer tokenizer(line, " :(),"); + // We don't care about the first token + tokenizer.nextToken(); + Common::String token = tokenizer.nextToken(); + + // The second token defines the action + // Use it to set the action enum and then to parse the arguments + if (token.matchString("add", true)) { + result.action = ADD; + ObjectType argTypes[] = { UINT32, UINT32 }; + parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); + } else if (token.matchString("animplay", true)) { + result.action = ANIM_PLAY; + + } else if (token.matchString("animpreload", true)) { + result.action = ANIM_PRELOAD; + + } else if (token.matchString("animunload", true)) { + result.action = ANIM_UNLOAD; + + } else if (token.matchString("attenuate", true)) { + result.action = ATTENUATE; + + } else if (token.matchString("assign", true)) { + result.action = ASSIGN; + ObjectType argTypes[] = { UINT32, UINT32 }; + parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); + } else if (token.matchString("change_location", true)) { + result.action = CHANGE_LOCATION; + ObjectType argTypes[] = { STRING, STRING, STRING, UINT32 }; + parseResultArguments(result, argTypes, 4, tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken()); + } else if (token.matchString("crossfade", true)) { + result.action = CROSSFADE; + + } else if (token.matchString("debug", true)) { + result.action = DEBUG; + + } else if (token.matchString("delay_render", true)) { + result.action = DELAY_RENDER; + + } else if (token.matchString("disable_control", true)) { + result.action = DISABLE_CONTROL; + + } else if (token.matchString("disable_venus", true)) { + result.action = DISABLE_VENUS; + + } else if (token.matchString("display_message", true)) { + result.action = DISPLAY_MESSAGE; + + } else if (token.matchString("dissolve", true)) { + result.action = DISSOLVE; + } else if (token.matchString("distort", true)) { + result.action = DISTORT; + + } else if (token.matchString("enable_control", true)) { + result.action = ENABLE_CONTROL; + + } else if (token.matchString("flush_mouse_events", true)) { + result.action = FLUSH_MOUSE_EVENTS; + + } else if (token.matchString("inventory", true)) { + result.action = INVENTORY; + + } else if (token.matchString("kill", true)) { + result.action = KILL; + + } else if (token.matchString("menu_bar_enable", true)) { + result.action = MENU_BAR_ENABLE; + + } else if (token.matchString("music", true)) { + result.action = MUSIC; + ObjectType argTypes[] = { UINT32, UINT32, STRING, UINT32, UINT32 }; + parseResultArguments(result, argTypes, 5, + tokenizer.nextToken(), tokenizer.nextToken(), + tokenizer.nextToken(), tokenizer.nextToken(), + tokenizer.nextToken()); + } else if (token.matchString("pan_track", true)) { + result.action = PAN_TRACK; + + } else if (token.matchString("playpreload", true)) { + result.action = PLAY_PRELOAD; + + } else if (token.matchString("preferences", true)) { + result.action = PREFERENCES; + + } else if (token.matchString("quit", true)) { + result.action = QUIT; + + } else if (token.matchString("random", true)) { + result.action = RANDOM; + ObjectType argTypes[] = { UINT32, UINT32 }; + parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); + } else if (token.matchString("region", true)) { + result.action = REGION; + + } else if (token.matchString("restore_game", true)) { + result.action = RESTORE_GAME; + + } else if (token.matchString("rotate_to", true)) { + result.action = ROTATE_TO; + + } else if (token.matchString("save_game", true)) { + result.action = SAVE_GAME; + + } else if (token.matchString("set_partial_screen", true)) { + result.action = SET_PARTIAL_SCREEN; + + } else if (token.matchString("set_screen", true)) { + result.action = SET_SCREEN; + + } else if (token.matchString("set_venus", true)) { + result.action = SET_VENUS; + + } else if (token.matchString("stop", true)) { + result.action = STOP; + ObjectType argTypes[] = { UINT32 }; + parseResultArguments(result, argTypes, 1, tokenizer.nextToken()); + } else if (token.matchString("streamvideo", true)) { + result.action = STREAM_VIDEO; + + } else if (token.matchString("syncsound", true)) { + result.action = SYNC_SOUND; + + } else if (token.matchString("timer", true)) { + result.action = TIMER; + ObjectType argTypes[] = { UINT32, UINT32 }; + parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); + } else if (token.matchString("ttytext", true)) { + result.action = TTY_TEXT; + + } else if (token.matchString("universe_music", true)) { + result.action = UNIVERSE_MUSIC; + + } else { + warning("Unhandled result action type: ", token); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + } + + return result; +} + +void ScriptManager::parseResultArguments(Result &result, const ObjectType *types, int numberOfArgs, ...) const { + va_list argptr; + va_start(argptr, numberOfArgs); + + for (int i = 0; i < numberOfArgs; i++) { + if (types[i] == UINT32) { + Common::String arg = va_arg(argptr, Common::String); + Object argObject(UINT32); + sscanf(arg.c_str(), "%u", &argObject); + result.arguments.push_back(argObject); + break; + } else { + Common::String arg = va_arg(argptr, Common::String); + result.arguments.push_back(Object(arg)); + break; + } + } + + va_end(argptr); +} + +byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { + byte flags; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + if (line.matchString("ONCE_PER_INST", true)) { + flags |= ONCE_PER_INST; + } else if (line.matchString("DO_ME_NOW", true)) { + flags |= DO_ME_NOW; + } else if (line.matchString("DISABLED", true)) { + flags |= DISABLED; + } + } + + return flags; +} + +void ScriptManager::parseControl(Control *control, Common::SeekableReadStream &stream) { + +} + +} // End namespace ZVision diff --git a/engines/zvision/scriptManager.h b/engines/zvision/scriptManager.h index a6c9f2b57c..7f6cc2547a 100644 --- a/engines/zvision/scriptManager.h +++ b/engines/zvision/scriptManager.h @@ -23,8 +23,13 @@ #ifndef ZVISION_SCRIPT_MANAGER_H #define ZVISION_SCRIPT_MANAGER_H +#include "common/str.h" +#include "common/stream.h" #include "common/hashmap.h" +#include "zvision/puzzle.h" +#include "zvision/control.h" + namespace ZVision { class ScriptManager { @@ -34,6 +39,63 @@ public: private: Common::HashMap _globalState; + + /** + * Parses a script file into triggers and events + * + * @param fileName Name of the .scr file + */ + void parseScrFile(Common::String fileName); + + /** + * Helper method for parseScrFile. Parses the stream into a Puzzle object + * + * @param puzzle The object to store what is parsed + * @param stream Scr file stream + */ + void parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream); + + /** + * Helper method for parsePuzzle. Parses the stream into a Criteria object + * + * @param stream Scr file stream + * @return Created Criteria object + */ + Criteria parseCriteria(Common::SeekableReadStream &stream) const; + + /** + * Helper method for parsePuzzle. Parses the stream into a Results object + * + * @param stream Scr file stream + * @return Created Results object + */ + Result parseResult(Common::SeekableReadStream &stream) const; + + /** + * Helper method for parseResults. Parses a number of strings into Object types. + * + * @param result Results object to store the arguments in + * @param types The type of the each of the arguments. IE. BOOL, UINT32, etc. + * @param numberOfArgs The number of arguments. This has to equal the length of 'types' AND the number of optional arguments passed. + * @param String arguments wanting to be parsed + */ + void parseResultArguments(Result &result, const ObjectType *types, int numberOfArgs, ...) const; + + /** + * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum + * + * @param stream Scr file stream + * @return Bitwise or of all the flags set within the puzzle + */ + byte parseFlags(Common::SeekableReadStream &stream) const; + + /** + * Helper method for parseScrFile. Parses the stream into a Control object + * + * @param control The object to store what is parsed + * @param stream Scr file stream + */ + void parseControl(Control *control, Common::SeekableReadStream &stream); }; -- cgit v1.2.3 From cf7c04a001d99081d73e4340acb8065ad593030a Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 13:38:40 -0500 Subject: ZVISION: Fix code formatting to follow the convention --- engines/zvision/control.h | 2 +- engines/zvision/graphics.cpp | 2 +- engines/zvision/object.cpp | 26 ++++++++++---------- engines/zvision/object.h | 49 ++++++++++++++++++------------------- engines/zvision/puzzle.h | 2 +- engines/zvision/scrFileHandling.cpp | 2 +- engines/zvision/scriptManager.h | 2 +- engines/zvision/scripts.cpp | 2 +- engines/zvision/utility.h | 2 +- engines/zvision/zfsArchive.cpp | 2 +- engines/zvision/zfsArchive.h | 2 +- engines/zvision/zork_raw.cpp | 2 +- engines/zvision/zork_raw.h | 2 +- 13 files changed, 48 insertions(+), 49 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 46a7211702..df01544bfc 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -32,6 +32,6 @@ struct Control { }; -} // End namespace ZVision +} // End of namespace ZVision #endif diff --git a/engines/zvision/graphics.cpp b/engines/zvision/graphics.cpp index 17e7a4f06b..7d1201c4f9 100644 --- a/engines/zvision/graphics.cpp +++ b/engines/zvision/graphics.cpp @@ -34,4 +34,4 @@ void ZVision::updateAnimations(uint32 detaTimeMillis) { } -} // End namespace ZVision +} // End of namespace ZVision diff --git a/engines/zvision/object.cpp b/engines/zvision/object.cpp index 253eaf7ace..6bc8c0f648 100644 --- a/engines/zvision/object.cpp +++ b/engines/zvision/object.cpp @@ -97,7 +97,7 @@ Object::Object(Common::String value) : _objectType(BYTE) { _value.stringVal = new Common::String(value); } -Object::Object(const Object& other) { +Object::Object(const Object &other) { _objectType = other._objectType; switch (_objectType) { @@ -138,7 +138,7 @@ Object::~Object() { void Object::deleteValue() { // Call delete on the correct part of the union. // Even though they all point to the same memory and will all be cast - // to a void *, compiler optimizations could cause undefined behavior. + // to a void *, this can still cause undefined behavior. switch (_objectType) { case BOOL: delete _value.boolVal; @@ -171,7 +171,7 @@ void Object::deleteValue() { } -Object& Object::operator=(const bool& rhs) { +Object &Object::operator=(const bool &rhs) { if (_objectType == BOOL) *_value.boolVal = rhs; else { @@ -183,7 +183,7 @@ Object& Object::operator=(const bool& rhs) { return *this; } -Object& Object::operator=(const byte& rhs) { +Object &Object::operator=(const byte &rhs) { if (_objectType == BYTE) *_value.byteVal = rhs; else { @@ -195,7 +195,7 @@ Object& Object::operator=(const byte& rhs) { return *this; } -Object& Object::operator=(const int16& rhs) { +Object &Object::operator=(const int16 &rhs) { if (_objectType == INT16) *_value.int16Val = rhs; else { @@ -207,7 +207,7 @@ Object& Object::operator=(const int16& rhs) { return *this; } -Object& Object::operator=(const uint16& rhs) { +Object &Object::operator=(const uint16 &rhs) { if (_objectType == UINT16) *_value.uint16Val = rhs; else { @@ -219,7 +219,7 @@ Object& Object::operator=(const uint16& rhs) { return *this; } -Object& Object::operator=(const int32& rhs) { +Object &Object::operator=(const int32 &rhs) { if (_objectType == INT32) *_value.int32Val = rhs; else { @@ -231,7 +231,7 @@ Object& Object::operator=(const int32& rhs) { return *this; } -Object& Object::operator=(const uint32& rhs) { +Object &Object::operator=(const uint32 &rhs) { if (_objectType == UINT32) *_value.uint32Val = rhs; else { @@ -243,7 +243,7 @@ Object& Object::operator=(const uint32& rhs) { return *this; } -Object& Object::operator=(const float& rhs) { +Object &Object::operator=(const float &rhs) { if (_objectType == FLOAT) *_value.floatVal = rhs; else { @@ -255,7 +255,7 @@ Object& Object::operator=(const float& rhs) { return *this; } -Object& Object::operator=(const double& rhs) { +Object &Object::operator=(const double &rhs) { if (_objectType == DOUBLE) *_value.doubleVal = rhs; else { @@ -267,7 +267,7 @@ Object& Object::operator=(const double& rhs) { return *this; } -Object& Object::operator=(const Common::String& rhs) { +Object &Object::operator=(const Common::String &rhs) { if (_objectType == STRING) *_value.stringVal = rhs; else { @@ -279,7 +279,7 @@ Object& Object::operator=(const Common::String& rhs) { return *this; } -Object& Object::operator=(const Object& rhs) { +Object &Object::operator=(const Object &rhs) { switch (_objectType) { case BOOL: return operator=(*rhs._value.boolVal); @@ -368,4 +368,4 @@ Object::operator Common::String() { return *_value.stringVal; } -} // End namespace ZVision +} // End of namespace ZVision diff --git a/engines/zvision/object.h b/engines/zvision/object.h index 02ca962239..b98b3812cd 100644 --- a/engines/zvision/object.h +++ b/engines/zvision/object.h @@ -27,19 +27,6 @@ namespace ZVision { - -enum ObjectType { - BOOL, - BYTE, - INT16, - UINT16, - INT32, - UINT32, - FLOAT, - DOUBLE, - STRING, -}; - /** * A generic single value storage class. It is useful for storing different * value types in a single List, Hashmap, etc. @@ -52,6 +39,18 @@ enum ObjectType { */ class Object { public: + enum ObjectType { + BOOL, + BYTE, + INT16, + UINT16, + INT32, + UINT32, + FLOAT, + DOUBLE, + STRING, + }; + // Constructors Object(ObjectType type); Object(bool value); @@ -86,17 +85,17 @@ private: } _value; public: - Object& operator=(const bool& rhs); - Object& operator=(const byte& rhs); - Object& operator=(const int16& rhs); - Object& operator=(const uint16& rhs); - Object& operator=(const int32& rhs); - Object& operator=(const uint32& rhs); - Object& operator=(const float& rhs); - Object& operator=(const double& rhs); - Object& operator=(const Common::String& rhs); - - Object& operator=(const Object& rhs); + Object &operator=(const bool &rhs); + Object &operator=(const byte &rhs); + Object &operator=(const int16 &rhs); + Object &operator=(const uint16 &rhs); + Object &operator=(const int32 &rhs); + Object &operator=(const uint32 &rhs); + Object &operator=(const float &rhs); + Object &operator=(const double &rhs); + Object &operator=(const Common::String &rhs); + + Object& operator=(const Object &rhs); operator bool(); operator byte(); @@ -116,6 +115,6 @@ private: void deleteValue(); }; -} // End namespace ZVision +} // End of namespace ZVision #endif diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index cb44a440e1..6961fde45a 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -114,6 +114,6 @@ struct Puzzle { byte flags; }; -} +} // End of namespace ZVision #endif diff --git a/engines/zvision/scrFileHandling.cpp b/engines/zvision/scrFileHandling.cpp index f4b5bab6fb..a0d4cebf9a 100644 --- a/engines/zvision/scrFileHandling.cpp +++ b/engines/zvision/scrFileHandling.cpp @@ -322,4 +322,4 @@ void ScriptManager::parseControl(Control *control, Common::SeekableReadStream &s } -} // End namespace ZVision +} // End of namespace ZVision diff --git a/engines/zvision/scriptManager.h b/engines/zvision/scriptManager.h index 7f6cc2547a..0bae91945d 100644 --- a/engines/zvision/scriptManager.h +++ b/engines/zvision/scriptManager.h @@ -99,6 +99,6 @@ private: }; -} // End namespace ZVision +} // End of namespace ZVision #endif diff --git a/engines/zvision/scripts.cpp b/engines/zvision/scripts.cpp index 40bad8f3a1..b6deb1b510 100644 --- a/engines/zvision/scripts.cpp +++ b/engines/zvision/scripts.cpp @@ -28,4 +28,4 @@ namespace ZVision { -} // End namespace ZVision +} // End of namespace ZVision diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 0777ba9ebc..f9f99166fc 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -69,6 +69,6 @@ void trimCommentsAndWhiteSpace(Common::String &string) { string.trim(); } -} // End namespace ZVision +} // End of namespace ZVision #endif diff --git a/engines/zvision/zfsArchive.cpp b/engines/zvision/zfsArchive.cpp index 93a026e5b9..e65d0df14e 100644 --- a/engines/zvision/zfsArchive.cpp +++ b/engines/zvision/zfsArchive.cpp @@ -150,6 +150,6 @@ void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const { buffer[i] ^= xorKey[i % 4]; } -} // End namespace ZVision +} // End of namespace ZVision diff --git a/engines/zvision/zfsArchive.h b/engines/zvision/zfsArchive.h index 718b26c836..60292f865e 100644 --- a/engines/zvision/zfsArchive.h +++ b/engines/zvision/zfsArchive.h @@ -115,6 +115,6 @@ private: void unXor(byte *buffer, int length, const byte *xorKey) const; }; -} // End of namespace Common +} // End of namespace ZVision #endif diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 3c37f929b3..e008741e16 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -185,4 +185,4 @@ Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, DisposeAfterUse::YES); } -} // End of namespace Audio +} // End of namespace ZVision diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index a8f8ce037f..3a938026d9 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -62,6 +62,6 @@ Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream int rate, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); -} // End of namespace Audio +} // End of namespace ZVision #endif -- cgit v1.2.3 From 8cc678e2eeda0df0b80fd19b03712a626b0b7bd2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 14:45:51 -0500 Subject: ZVISION: Convert 'Object' implicit conversion operators to accessors Implicit conversion, while simple can cause problems and doesn't show exactly how to get the value. --- engines/zvision/object.cpp | 67 +++++++++++++++++++++++++++------------------- engines/zvision/object.h | 18 ++++++------- 2 files changed, 48 insertions(+), 37 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/object.cpp b/engines/zvision/object.cpp index 6bc8c0f648..322d7f2ea6 100644 --- a/engines/zvision/object.cpp +++ b/engines/zvision/object.cpp @@ -305,67 +305,78 @@ Object &Object::operator=(const Object &rhs) { } -Object::operator bool() { - if (_objectType != BOOL) - warning("'Object' not of type bool. Bad cast"); +bool Object::getBoolValue(bool *returnValue) const { + if (_objectType != BOOL) { + warning("'Object' not of type bool."); + return false; + } - return *_value.boolVal; + *returnValue = *_value.boolVal; + return true; } -Object::operator byte() { +bool Object::getByteValue(byte *returnValue) const { if (_objectType != BYTE) - warning("'Object' not of type byte. Bad cast"); + warning("'Object' not of type byte."); - return *_value.byteVal; + *returnValue = *_value.byteVal; + return true; } -Object::operator int16() { +bool Object::getInt16Value(int16 *returnValue) const { if (_objectType != INT16) - warning("'Object' not of type int16. Bad cast"); + warning("'Object' not of type int16."); - return *_value.int16Val; + *returnValue = *_value.int16Val; + return true; } -Object::operator uint16() { +bool Object::getUInt16Value(uint16 *returnValue) const { if (_objectType != UINT16) - warning("'Object' not of type uint16. Bad cast"); + warning("'Object' not of type uint16."); - return *_value.uint16Val; + *returnValue = *_value.uint16Val; + return true; } -Object::operator int32() { +bool Object::getInt32Value(int32 *returnValue) const { if (_objectType != INT32) - warning("'Object' not of type int32. Bad cast"); + warning("'Object' not of type int32."); - return *_value.int32Val; + *returnValue = *_value.int32Val; + return true; } -Object::operator uint32() { +bool Object::getUInt32Value(uint32 *returnValue) const { if (_objectType != UINT32) - warning("'Object' not of type uint32. Bad cast"); + warning("'Object' not of type uint32."); - return *_value.uint32Val; + *returnValue = *_value.uint32Val; + return true; } -Object::operator float() { +bool Object::getFloatValue(float *returnValue) const { if (_objectType != FLOAT) - warning("'Object' not of type float. Bad cast"); + warning("'Object' not of type float."); - return *_value.floatVal; + *returnValue = *_value.floatVal; + return true; } -Object::operator double() { +bool Object::getDoubleValue(double *returnValue) const { if (_objectType != DOUBLE) - warning("'Object' not of type double. Bad cast"); + warning("'Object' not of type double."); - return *_value.doubleVal; + *returnValue = *_value.doubleVal; + return true; } -Object::operator Common::String() { +bool Object::getStringValue(Common::String *returnValue) const { if (_objectType != STRING) - warning("'Object' not of type Common::String. Bad cast"); + warning("'Object' not of type Common::String."); - return *_value.stringVal; + *returnValue = *_value.stringVal; + return true; } } // End of namespace ZVision diff --git a/engines/zvision/object.h b/engines/zvision/object.h index b98b3812cd..4df572c2b1 100644 --- a/engines/zvision/object.h +++ b/engines/zvision/object.h @@ -97,15 +97,15 @@ public: Object& operator=(const Object &rhs); - operator bool(); - operator byte(); - operator int16(); - operator uint16(); - operator int32(); - operator uint32(); - operator float(); - operator double(); - operator Common::String(); + bool getBoolValue(bool *returnValue) const; + bool getByteValue(byte *returnValue) const; + bool getInt16Value(int16 *returnValue) const; + bool getUInt16Value(uint16 *returnValue) const; + bool getInt32Value(int32 *returnValue) const; + bool getUInt32Value(uint32 *returnValue) const; + bool getFloatValue(float *returnValue) const; + bool getDoubleValue(double *returnValue) const; + bool getStringValue(Common::String *returnValue) const; private: /** -- cgit v1.2.3 From 7803c9fddf5fecd7d9adb6741f08e37fb92c0224 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 24 Jun 2013 14:46:58 -0500 Subject: ZVISION: Force 'Object' constructors to be explicit. --- engines/zvision/object.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/object.h b/engines/zvision/object.h index 4df572c2b1..6e4b98a814 100644 --- a/engines/zvision/object.h +++ b/engines/zvision/object.h @@ -52,19 +52,19 @@ public: }; // Constructors - Object(ObjectType type); - Object(bool value); - Object(byte value); - Object(int16 value); - Object(uint16 value); - Object(int32 value); - Object(uint32 value); - Object(float value); - Object(double value); - Object(Common::String value); + explicit Object(ObjectType type); + explicit Object(bool value); + explicit Object(byte value); + explicit Object(int16 value); + explicit Object(uint16 value); + explicit Object(int32 value); + explicit Object(uint32 value); + explicit Object(float value); + explicit Object(double value); + explicit Object(Common::String value); // Copy constructor - Object(const Object& other); + explicit Object(const Object& other); // Destructor ~Object(); -- cgit v1.2.3 From 3283176f6d000cbb66208a0b5d4b3337004461fd Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 27 Jun 2013 13:40:24 -0500 Subject: ZVISION: Move initialization code from run() and into its own method --- engines/zvision/zvision.cpp | 8 +++++++- engines/zvision/zvision.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 2cc0b47113..452ed00daf 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -73,7 +73,7 @@ ZVision::~ZVision() { DebugMan.clearAllDebugChannels(); } -Common::Error ZVision::run() { +void ZVision::initialize() { // Find zfs archive files Common::ArchiveMemberList list; SearchMan.listMatchingMembers(list, "*.zfs"); @@ -92,6 +92,12 @@ Common::Error ZVision::run() { // Create debugger console. It requires GFX to be initialized _console = new Console(this); +} + +Common::Error ZVision::run() { + initialize(); + + tests(); // Main loop uint32 currentTime = _system->getMillis(); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index b4664d0e29..c5ddb8ab4a 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -67,6 +67,8 @@ public: virtual Common::Error run(); private: + void initialize(); + void processEvents(); void onMouseDown(const Common::Point &pos); void onMouseMove(const Common::Point &pos); -- cgit v1.2.3 From d5fa6612ed8f48ce33dd9f3576c450fe80a7526d Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 27 Jun 2013 13:41:24 -0500 Subject: ZVISION: Modify utility and puzzle comments to make them more clear --- engines/zvision/puzzle.h | 4 ++-- engines/zvision/utility.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 6961fde45a..1133adac47 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -48,8 +48,8 @@ struct Criteria { uint32 argument; /** How to do the comparison */ CriteriaOperator criteriaOperator; - /** Is 'argument' the id of a global state or a pure value */ - bool argumentIsAnId; + /** Whether 'argument' is the id of a global state (true) or a pure value (false) */ + bool isArgumentAnId; }; /** What happens when Puzzle criteria are met */ diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index f9f99166fc..9fade107f5 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -54,8 +54,8 @@ void writeFileContentsToFile(Common::String sourceFile, Common::String destFile) /** * Removes any line comments using '#' as a sequence start. - * Then removes any trailing and leading 'whitespace'. - * Uses isspace() to determine what is whitespace and what is not. + * Then removes any trailing and leading 'whitespace' using String::trim() + * Note: String::trim uses isspace() to determine what is whitespace and what is not. * * @param string The string to modify. It is modified in place */ -- cgit v1.2.3 From 5fef80994101046801500f3350f85ca368d50aa6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 27 Jun 2013 15:17:57 -0500 Subject: ZVISION: Convert union of pointers to union of values except for String. Instead of storing everything on the heap, only store Strings on the heap. For Strings, store a char array pointer instead of an actual String object since String objects are fairly large. --- engines/zvision/object.cpp | 293 ++++++++++++++++++++------------------------- engines/zvision/object.h | 18 +-- 2 files changed, 137 insertions(+), 174 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/object.cpp b/engines/zvision/object.cpp index 322d7f2ea6..b272320988 100644 --- a/engines/zvision/object.cpp +++ b/engines/zvision/object.cpp @@ -27,74 +27,43 @@ namespace ZVision { -Object::Object(ObjectType type) { - _objectType = type; - - switch (type) { - case BOOL: - _value.boolVal = new bool; - break; - case BYTE: - _value.byteVal = new byte; - break; - case INT16: - _value.int16Val = new int16; - break; - case UINT16: - _value.uint16Val = new uint16; - break; - case INT32: - _value.int32Val = new int32; - break; - case UINT32: - _value.uint32Val = new uint32; - break; - case FLOAT: - _value.floatVal = new float; - break; - case DOUBLE: - _value.doubleVal = new double; - break; - case STRING: - _value.stringVal = new Common::String; - break; - } -} +Object::Object(ObjectType type) : _objectType(type) { } Object::Object(bool value) : _objectType(BOOL) { - _value.boolVal = new bool(value); + _value.boolVal = value; } Object::Object(byte value) : _objectType(BYTE) { - _value.byteVal = new byte(value); + _value.byteVal = value; } Object::Object(int16 value) : _objectType(INT16) { - _value.int16Val = new int16(value); + _value.int16Val = value; } Object::Object(uint16 value) : _objectType(UINT16) { - _value.uint16Val = new uint16(value); + _value.uint16Val = value; } Object::Object(int32 value) : _objectType(INT32) { - _value.int32Val = new int32(value); + _value.int32Val = value; } Object::Object(uint32 value) : _objectType(UINT32) { - _value.uint32Val = new uint32(value); + _value.uint32Val = value; } Object::Object(float value) : _objectType(FLOAT) { - _value.floatVal = new float(value); + _value.floatVal = value; } Object::Object(double value) : _objectType(DOUBLE) { - _value.doubleVal = new double(value); + _value.doubleVal = value; } Object::Object(Common::String value) : _objectType(BYTE) { - _value.stringVal = new Common::String(value); + _value.stringVal = new char[value.size() + 1]; + memcpy(_value.stringVal, value.c_str(), value.size() + 1); } Object::Object(const Object &other) { @@ -102,178 +71,167 @@ Object::Object(const Object &other) { switch (_objectType) { case BOOL: - _value.boolVal = new bool(*other._value.boolVal); + _value.boolVal = other._value.boolVal; break; case BYTE: - _value.byteVal = new byte(*other._value.byteVal); + _value.byteVal = other._value.byteVal; break; case INT16: - _value.int16Val = new int16(*other._value.int16Val); + _value.int16Val = other._value.int16Val; break; case UINT16: - _value.uint16Val = new uint16(*other._value.uint16Val); + _value.uint16Val = other._value.uint16Val; break; case INT32: - _value.int32Val = new int32(*other._value.int32Val); + _value.int32Val = other._value.int32Val; break; case UINT32: - _value.uint32Val = new uint32(*other._value.uint32Val); + _value.uint32Val = other._value.uint32Val; break; case FLOAT: - _value.floatVal = new float(*other._value.floatVal); + _value.floatVal = other._value.floatVal; break; case DOUBLE: - _value.doubleVal = new double(*other._value.doubleVal); + _value.doubleVal = other._value.doubleVal; break; case STRING: - _value.stringVal = new Common::String(*other._value.stringVal); + uint32 length = strlen(other._value.stringVal); + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, other._value.stringVal, length + 1); break; } } Object::~Object() { - deleteValue(); + deleteCharPointer(); } -void Object::deleteValue() { - // Call delete on the correct part of the union. - // Even though they all point to the same memory and will all be cast - // to a void *, this can still cause undefined behavior. - switch (_objectType) { - case BOOL: - delete _value.boolVal; - break; - case BYTE: - delete _value.byteVal; - break; - case INT16: - delete _value.int16Val; - break; - case UINT16: - delete _value.uint16Val; - break; - case INT32: - delete _value.int32Val; - break; - case UINT32: - delete _value.uint32Val; - break; - case FLOAT: - delete _value.floatVal; - break; - case DOUBLE: - delete _value.doubleVal; - break; - case STRING: - delete _value.stringVal; - break; - } +void Object::deleteCharPointer() { + if (_objectType == STRING) + delete[] _value.stringVal; } Object &Object::operator=(const bool &rhs) { - if (_objectType == BOOL) - *_value.boolVal = rhs; - else { - deleteValue(); - _objectType = BOOL; - _value.boolVal = new bool(rhs); + if (_objectType == BOOL) { + _value.boolVal = rhs; + return *this; } + deleteCharPointer(); + _objectType = BOOL; + _value.boolVal = rhs; + return *this; } Object &Object::operator=(const byte &rhs) { - if (_objectType == BYTE) - *_value.byteVal = rhs; - else { - deleteValue(); - _objectType = BYTE; - _value.byteVal = new byte(rhs); + if (_objectType == BYTE) { + _value.byteVal = rhs; + return *this; } + deleteCharPointer(); + _objectType = BYTE; + _value.byteVal = rhs; + return *this; } Object &Object::operator=(const int16 &rhs) { - if (_objectType == INT16) - *_value.int16Val = rhs; - else { - deleteValue(); - _objectType = INT16; - _value.int16Val = new int16(rhs); + if (_objectType == INT16) { + _value.int16Val = rhs; + return *this; } + deleteCharPointer(); + _objectType = INT16; + _value.int16Val = rhs; + return *this; } Object &Object::operator=(const uint16 &rhs) { - if (_objectType == UINT16) - *_value.uint16Val = rhs; - else { - deleteValue(); - _objectType = UINT16; - _value.uint16Val = new uint16(rhs); + if (_objectType == UINT16) { + _value.uint16Val = rhs; + return *this; } + deleteCharPointer(); + _objectType = UINT16; + _value.uint16Val = rhs; + return *this; } Object &Object::operator=(const int32 &rhs) { - if (_objectType == INT32) - *_value.int32Val = rhs; - else { - deleteValue(); - _objectType = INT32; - _value.int32Val = new int32(rhs); + if (_objectType == INT32) { + _value.int32Val = rhs; + return *this; } + deleteCharPointer(); + _objectType = INT32; + _value.int32Val = rhs; + return *this; } Object &Object::operator=(const uint32 &rhs) { - if (_objectType == UINT32) - *_value.uint32Val = rhs; - else { - deleteValue(); - _objectType = UINT32; - _value.uint32Val = new uint32(rhs); + if (_objectType == UINT32) { + _value.uint32Val = rhs; + return *this; } + deleteCharPointer(); + _objectType = UINT32; + _value.uint32Val = rhs; + return *this; } Object &Object::operator=(const float &rhs) { - if (_objectType == FLOAT) - *_value.floatVal = rhs; - else { - deleteValue(); - _objectType = FLOAT; - _value.floatVal = new float(rhs); + if (_objectType == FLOAT) { + _value.floatVal = rhs; + return *this; } + deleteCharPointer(); + _objectType = FLOAT; + _value.floatVal = rhs; + return *this; } Object &Object::operator=(const double &rhs) { - if (_objectType == DOUBLE) - *_value.doubleVal = rhs; - else { - deleteValue(); - _objectType = DOUBLE; - _value.doubleVal = new double(rhs); + if (_objectType == DOUBLE) { + _value.doubleVal = rhs; + return *this; } + deleteCharPointer(); + _objectType = DOUBLE; + _value.doubleVal = rhs; + return *this; } Object &Object::operator=(const Common::String &rhs) { - if (_objectType == STRING) - *_value.stringVal = rhs; - else { - deleteValue(); + if (_objectType != STRING) { _objectType = STRING; - _value.stringVal = new Common::String(rhs); + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + + return *this; + } + + uint32 length = strlen(_value.stringVal); + if (length <= rhs.size() + 1) { + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + } else { + delete[] _value.stringVal; + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); } return *this; @@ -282,23 +240,28 @@ Object &Object::operator=(const Common::String &rhs) { Object &Object::operator=(const Object &rhs) { switch (_objectType) { case BOOL: - return operator=(*rhs._value.boolVal); + return operator=(rhs._value.boolVal); case BYTE: - return operator=(*rhs._value.byteVal); + return operator=(rhs._value.byteVal); case INT16: - return operator=(*rhs._value.int16Val); + return operator=(rhs._value.int16Val); case UINT16: - return operator=(*rhs._value.uint16Val); + return operator=(rhs._value.uint16Val); case INT32: - return operator=(*rhs._value.int32Val); + return operator=(rhs._value.int32Val); case UINT32: - return operator=(*rhs._value.uint32Val); + return operator=(rhs._value.uint32Val); case FLOAT: - return operator=(*rhs._value.floatVal); + return operator=(rhs._value.floatVal); case DOUBLE: - return operator=(*rhs._value.doubleVal); + return operator=(rhs._value.doubleVal); case STRING: - return operator=(*rhs._value.stringVal); + uint32 length = strlen(rhs._value.stringVal); + + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, rhs._value.stringVal, length + 1); + + return *this; } return *this; @@ -307,75 +270,75 @@ Object &Object::operator=(const Object &rhs) { bool Object::getBoolValue(bool *returnValue) const { if (_objectType != BOOL) { - warning("'Object' not of type bool."); + warning("'Object' is not storing a bool."); return false; } - *returnValue = *_value.boolVal; + *returnValue = _value.boolVal; return true; } bool Object::getByteValue(byte *returnValue) const { if (_objectType != BYTE) - warning("'Object' not of type byte."); + warning("'Object' is not storing a byte."); - *returnValue = *_value.byteVal; + *returnValue = _value.byteVal; return true; } bool Object::getInt16Value(int16 *returnValue) const { if (_objectType != INT16) - warning("'Object' not of type int16."); + warning("'Object' is not storing an int16."); - *returnValue = *_value.int16Val; + *returnValue = _value.int16Val; return true; } bool Object::getUInt16Value(uint16 *returnValue) const { if (_objectType != UINT16) - warning("'Object' not of type uint16."); + warning("'Object' is not storing a uint16."); - *returnValue = *_value.uint16Val; + *returnValue = _value.uint16Val; return true; } bool Object::getInt32Value(int32 *returnValue) const { if (_objectType != INT32) - warning("'Object' not of type int32."); + warning("'Object' is not storing an int32."); - *returnValue = *_value.int32Val; + *returnValue = _value.int32Val; return true; } bool Object::getUInt32Value(uint32 *returnValue) const { if (_objectType != UINT32) - warning("'Object' not of type uint32."); + warning("'Object' is not storing a uint32."); - *returnValue = *_value.uint32Val; + *returnValue = _value.uint32Val; return true; } bool Object::getFloatValue(float *returnValue) const { if (_objectType != FLOAT) - warning("'Object' not of type float."); + warning("'Object' is not storing a float."); - *returnValue = *_value.floatVal; + *returnValue = _value.floatVal; return true; } bool Object::getDoubleValue(double *returnValue) const { if (_objectType != DOUBLE) - warning("'Object' not of type double."); + warning("'Object' is not storing a double."); - *returnValue = *_value.doubleVal; + *returnValue = _value.doubleVal; return true; } bool Object::getStringValue(Common::String *returnValue) const { if (_objectType != STRING) - warning("'Object' not of type Common::String."); + warning("'Object' is not storing a Common::String."); - *returnValue = *_value.stringVal; + *returnValue = _value.stringVal; return true; } diff --git a/engines/zvision/object.h b/engines/zvision/object.h index 6e4b98a814..dc5905b052 100644 --- a/engines/zvision/object.h +++ b/engines/zvision/object.h @@ -73,15 +73,15 @@ private: ObjectType _objectType; union { - bool *boolVal; - byte *byteVal; - int16 *int16Val; - uint16 *uint16Val; - int32 *int32Val; - uint32 *uint32Val; - float *floatVal; - double *doubleVal; - Common::String *stringVal; + bool boolVal; + byte byteVal; + int16 int16Val; + uint16 uint16Val; + int32 int32Val; + uint32 uint32Val; + float floatVal; + double doubleVal; + char *stringVal; } _value; public: -- cgit v1.2.3 From 30208f7f2b0e47b5684d7d1860541f4dd56f43ce Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 27 Jun 2013 15:18:23 -0500 Subject: ZVISION: Add documentation to 'Object' accessors --- engines/zvision/object.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/object.h b/engines/zvision/object.h index dc5905b052..f7e08c46d3 100644 --- a/engines/zvision/object.h +++ b/engines/zvision/object.h @@ -97,22 +97,89 @@ public: Object& operator=(const Object &rhs); + /** + * Retrieve a bool from the container. If the container is not storing a + * bool, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getBoolValue(bool *returnValue) const; + /** + * Retrieve a byte from the container. If the container is not storing a + * byte, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getByteValue(byte *returnValue) const; + /** + * Retrieve an int16 from the container. If the container is not storing an + * int16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getInt16Value(int16 *returnValue) const; + /** + * Retrieve a uint16 from the container. If the container is not storing a + * uint16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getUInt16Value(uint16 *returnValue) const; + /** + * Retrieve an int32 from the container. If the container is not storing an + * int32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getInt32Value(int32 *returnValue) const; + /** + * Retrieve a uint32 from the container. If the container is not storing a + * uint32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getUInt32Value(uint32 *returnValue) const; + /** + * Retrieve a float from the container. If the container is not storing a + * float, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getFloatValue(float *returnValue) const; + /** + * Retrieve a double from the container. If the container is not storing a + * double, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getDoubleValue(double *returnValue) const; + /** + * Retrieve a String from the container. If the container is not storing a + * string, this will return false and display a warning(). + * + * Caution: Strings are internally stored as char[]. getStringValue uses + * Common::String::operator=(char *) to do the assigment, which uses both + * strlen() AND memmove(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ bool getStringValue(Common::String *returnValue) const; private: /** - * Helper method for destruction and assignment. Calls delete on - * the currently used data pointer + * Helper method for destruction and assignment. It checks to see + * if the char pointer is being used, and if so calls delete on it */ - void deleteValue(); + void deleteCharPointer(); }; } // End of namespace ZVision -- cgit v1.2.3 From c3c75669628e93c66d08a175142ad72b8f9b00a7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 27 Jun 2013 15:22:35 -0500 Subject: ZVISION: Rename 'Object' class to 'SingleValueContainer' --- engines/zvision/object.cpp | 64 +++++++++++++++++++++++----------------------- engines/zvision/object.h | 58 +++++++++++++++++++---------------------- 2 files changed, 58 insertions(+), 64 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/object.cpp b/engines/zvision/object.cpp index b272320988..6a3d4e047d 100644 --- a/engines/zvision/object.cpp +++ b/engines/zvision/object.cpp @@ -27,46 +27,46 @@ namespace ZVision { -Object::Object(ObjectType type) : _objectType(type) { } +SingleValueContainer::SingleValueContainer(ValueType type) : _objectType(type) { } -Object::Object(bool value) : _objectType(BOOL) { +SingleValueContainer::SingleValueContainer(bool value) : _objectType(BOOL) { _value.boolVal = value; } -Object::Object(byte value) : _objectType(BYTE) { +SingleValueContainer::SingleValueContainer(byte value) : _objectType(BYTE) { _value.byteVal = value; } -Object::Object(int16 value) : _objectType(INT16) { +SingleValueContainer::SingleValueContainer(int16 value) : _objectType(INT16) { _value.int16Val = value; } -Object::Object(uint16 value) : _objectType(UINT16) { +SingleValueContainer::SingleValueContainer(uint16 value) : _objectType(UINT16) { _value.uint16Val = value; } -Object::Object(int32 value) : _objectType(INT32) { +SingleValueContainer::SingleValueContainer(int32 value) : _objectType(INT32) { _value.int32Val = value; } -Object::Object(uint32 value) : _objectType(UINT32) { +SingleValueContainer::SingleValueContainer(uint32 value) : _objectType(UINT32) { _value.uint32Val = value; } -Object::Object(float value) : _objectType(FLOAT) { +SingleValueContainer::SingleValueContainer(float value) : _objectType(FLOAT) { _value.floatVal = value; } -Object::Object(double value) : _objectType(DOUBLE) { +SingleValueContainer::SingleValueContainer(double value) : _objectType(DOUBLE) { _value.doubleVal = value; } -Object::Object(Common::String value) : _objectType(BYTE) { +SingleValueContainer::SingleValueContainer(Common::String value) : _objectType(BYTE) { _value.stringVal = new char[value.size() + 1]; memcpy(_value.stringVal, value.c_str(), value.size() + 1); } -Object::Object(const Object &other) { +SingleValueContainer::SingleValueContainer(const SingleValueContainer &other) { _objectType = other._objectType; switch (_objectType) { @@ -102,17 +102,17 @@ Object::Object(const Object &other) { } } -Object::~Object() { +SingleValueContainer::~SingleValueContainer() { deleteCharPointer(); } -void Object::deleteCharPointer() { +void SingleValueContainer::deleteCharPointer() { if (_objectType == STRING) delete[] _value.stringVal; } -Object &Object::operator=(const bool &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const bool &rhs) { if (_objectType == BOOL) { _value.boolVal = rhs; return *this; @@ -125,7 +125,7 @@ Object &Object::operator=(const bool &rhs) { return *this; } -Object &Object::operator=(const byte &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const byte &rhs) { if (_objectType == BYTE) { _value.byteVal = rhs; return *this; @@ -138,7 +138,7 @@ Object &Object::operator=(const byte &rhs) { return *this; } -Object &Object::operator=(const int16 &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const int16 &rhs) { if (_objectType == INT16) { _value.int16Val = rhs; return *this; @@ -151,7 +151,7 @@ Object &Object::operator=(const int16 &rhs) { return *this; } -Object &Object::operator=(const uint16 &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const uint16 &rhs) { if (_objectType == UINT16) { _value.uint16Val = rhs; return *this; @@ -164,7 +164,7 @@ Object &Object::operator=(const uint16 &rhs) { return *this; } -Object &Object::operator=(const int32 &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const int32 &rhs) { if (_objectType == INT32) { _value.int32Val = rhs; return *this; @@ -177,7 +177,7 @@ Object &Object::operator=(const int32 &rhs) { return *this; } -Object &Object::operator=(const uint32 &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const uint32 &rhs) { if (_objectType == UINT32) { _value.uint32Val = rhs; return *this; @@ -190,7 +190,7 @@ Object &Object::operator=(const uint32 &rhs) { return *this; } -Object &Object::operator=(const float &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const float &rhs) { if (_objectType == FLOAT) { _value.floatVal = rhs; return *this; @@ -203,7 +203,7 @@ Object &Object::operator=(const float &rhs) { return *this; } -Object &Object::operator=(const double &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const double &rhs) { if (_objectType == DOUBLE) { _value.doubleVal = rhs; return *this; @@ -216,7 +216,7 @@ Object &Object::operator=(const double &rhs) { return *this; } -Object &Object::operator=(const Common::String &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const Common::String &rhs) { if (_objectType != STRING) { _objectType = STRING; _value.stringVal = new char[rhs.size() + 1]; @@ -237,7 +237,7 @@ Object &Object::operator=(const Common::String &rhs) { return *this; } -Object &Object::operator=(const Object &rhs) { +SingleValueContainer &SingleValueContainer::operator=(const SingleValueContainer &rhs) { switch (_objectType) { case BOOL: return operator=(rhs._value.boolVal); @@ -268,7 +268,7 @@ Object &Object::operator=(const Object &rhs) { } -bool Object::getBoolValue(bool *returnValue) const { +bool SingleValueContainer::getBoolValue(bool *returnValue) const { if (_objectType != BOOL) { warning("'Object' is not storing a bool."); return false; @@ -278,7 +278,7 @@ bool Object::getBoolValue(bool *returnValue) const { return true; } -bool Object::getByteValue(byte *returnValue) const { +bool SingleValueContainer::getByteValue(byte *returnValue) const { if (_objectType != BYTE) warning("'Object' is not storing a byte."); @@ -286,7 +286,7 @@ bool Object::getByteValue(byte *returnValue) const { return true; } -bool Object::getInt16Value(int16 *returnValue) const { +bool SingleValueContainer::getInt16Value(int16 *returnValue) const { if (_objectType != INT16) warning("'Object' is not storing an int16."); @@ -294,7 +294,7 @@ bool Object::getInt16Value(int16 *returnValue) const { return true; } -bool Object::getUInt16Value(uint16 *returnValue) const { +bool SingleValueContainer::getUInt16Value(uint16 *returnValue) const { if (_objectType != UINT16) warning("'Object' is not storing a uint16."); @@ -302,7 +302,7 @@ bool Object::getUInt16Value(uint16 *returnValue) const { return true; } -bool Object::getInt32Value(int32 *returnValue) const { +bool SingleValueContainer::getInt32Value(int32 *returnValue) const { if (_objectType != INT32) warning("'Object' is not storing an int32."); @@ -310,7 +310,7 @@ bool Object::getInt32Value(int32 *returnValue) const { return true; } -bool Object::getUInt32Value(uint32 *returnValue) const { +bool SingleValueContainer::getUInt32Value(uint32 *returnValue) const { if (_objectType != UINT32) warning("'Object' is not storing a uint32."); @@ -318,7 +318,7 @@ bool Object::getUInt32Value(uint32 *returnValue) const { return true; } -bool Object::getFloatValue(float *returnValue) const { +bool SingleValueContainer::getFloatValue(float *returnValue) const { if (_objectType != FLOAT) warning("'Object' is not storing a float."); @@ -326,7 +326,7 @@ bool Object::getFloatValue(float *returnValue) const { return true; } -bool Object::getDoubleValue(double *returnValue) const { +bool SingleValueContainer::getDoubleValue(double *returnValue) const { if (_objectType != DOUBLE) warning("'Object' is not storing a double."); @@ -334,7 +334,7 @@ bool Object::getDoubleValue(double *returnValue) const { return true; } -bool Object::getStringValue(Common::String *returnValue) const { +bool SingleValueContainer::getStringValue(Common::String *returnValue) const { if (_objectType != STRING) warning("'Object' is not storing a Common::String."); diff --git a/engines/zvision/object.h b/engines/zvision/object.h index f7e08c46d3..3c24cc07f0 100644 --- a/engines/zvision/object.h +++ b/engines/zvision/object.h @@ -30,16 +30,10 @@ namespace ZVision { /** * A generic single value storage class. It is useful for storing different * value types in a single List, Hashmap, etc. - * - * Mimics C#'s Object class - * - * Caution: The actual value is stored on the heap, so be careful creating - * many objects of this class. Also, when re-using 'Object', try to assign - * a value of the same type as before, as this will prevent an extra memory allocation. */ -class Object { +class SingleValueContainer { public: - enum ObjectType { + enum ValueType { BOOL, BYTE, INT16, @@ -52,25 +46,25 @@ public: }; // Constructors - explicit Object(ObjectType type); - explicit Object(bool value); - explicit Object(byte value); - explicit Object(int16 value); - explicit Object(uint16 value); - explicit Object(int32 value); - explicit Object(uint32 value); - explicit Object(float value); - explicit Object(double value); - explicit Object(Common::String value); + explicit SingleValueContainer(ValueType type); + explicit SingleValueContainer(bool value); + explicit SingleValueContainer(byte value); + explicit SingleValueContainer(int16 value); + explicit SingleValueContainer(uint16 value); + explicit SingleValueContainer(int32 value); + explicit SingleValueContainer(uint32 value); + explicit SingleValueContainer(float value); + explicit SingleValueContainer(double value); + explicit SingleValueContainer(Common::String value); // Copy constructor - explicit Object(const Object& other); + explicit SingleValueContainer(const SingleValueContainer& other); // Destructor - ~Object(); + ~SingleValueContainer(); private: - ObjectType _objectType; + ValueType _objectType; union { bool boolVal; @@ -85,17 +79,17 @@ private: } _value; public: - Object &operator=(const bool &rhs); - Object &operator=(const byte &rhs); - Object &operator=(const int16 &rhs); - Object &operator=(const uint16 &rhs); - Object &operator=(const int32 &rhs); - Object &operator=(const uint32 &rhs); - Object &operator=(const float &rhs); - Object &operator=(const double &rhs); - Object &operator=(const Common::String &rhs); - - Object& operator=(const Object &rhs); + SingleValueContainer &operator=(const bool &rhs); + SingleValueContainer &operator=(const byte &rhs); + SingleValueContainer &operator=(const int16 &rhs); + SingleValueContainer &operator=(const uint16 &rhs); + SingleValueContainer &operator=(const int32 &rhs); + SingleValueContainer &operator=(const uint32 &rhs); + SingleValueContainer &operator=(const float &rhs); + SingleValueContainer &operator=(const double &rhs); + SingleValueContainer &operator=(const Common::String &rhs); + + SingleValueContainer& operator=(const SingleValueContainer &rhs); /** * Retrieve a bool from the container. If the container is not storing a -- cgit v1.2.3 From 063d6c34008cf61a19ce8ae135b44091371ac728 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 27 Jun 2013 15:25:10 -0500 Subject: ZVISION: Rename object.h and object.cpp to fit the new class name --- engines/zvision/object.cpp | 345 ------------------------------- engines/zvision/object.h | 181 ---------------- engines/zvision/singleValueContainer.cpp | 345 +++++++++++++++++++++++++++++++ engines/zvision/singleValueContainer.h | 181 ++++++++++++++++ 4 files changed, 526 insertions(+), 526 deletions(-) delete mode 100644 engines/zvision/object.cpp delete mode 100644 engines/zvision/object.h create mode 100644 engines/zvision/singleValueContainer.cpp create mode 100644 engines/zvision/singleValueContainer.h (limited to 'engines/zvision') diff --git a/engines/zvision/object.cpp b/engines/zvision/object.cpp deleted file mode 100644 index 6a3d4e047d..0000000000 --- a/engines/zvision/object.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* 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/scummsys.h" -#include "common/textconsole.h" - -#include "zvision/object.h" - -namespace ZVision { - -SingleValueContainer::SingleValueContainer(ValueType type) : _objectType(type) { } - -SingleValueContainer::SingleValueContainer(bool value) : _objectType(BOOL) { - _value.boolVal = value; -} - -SingleValueContainer::SingleValueContainer(byte value) : _objectType(BYTE) { - _value.byteVal = value; -} - -SingleValueContainer::SingleValueContainer(int16 value) : _objectType(INT16) { - _value.int16Val = value; -} - -SingleValueContainer::SingleValueContainer(uint16 value) : _objectType(UINT16) { - _value.uint16Val = value; -} - -SingleValueContainer::SingleValueContainer(int32 value) : _objectType(INT32) { - _value.int32Val = value; -} - -SingleValueContainer::SingleValueContainer(uint32 value) : _objectType(UINT32) { - _value.uint32Val = value; -} - -SingleValueContainer::SingleValueContainer(float value) : _objectType(FLOAT) { - _value.floatVal = value; -} - -SingleValueContainer::SingleValueContainer(double value) : _objectType(DOUBLE) { - _value.doubleVal = value; -} - -SingleValueContainer::SingleValueContainer(Common::String value) : _objectType(BYTE) { - _value.stringVal = new char[value.size() + 1]; - memcpy(_value.stringVal, value.c_str(), value.size() + 1); -} - -SingleValueContainer::SingleValueContainer(const SingleValueContainer &other) { - _objectType = other._objectType; - - switch (_objectType) { - case BOOL: - _value.boolVal = other._value.boolVal; - break; - case BYTE: - _value.byteVal = other._value.byteVal; - break; - case INT16: - _value.int16Val = other._value.int16Val; - break; - case UINT16: - _value.uint16Val = other._value.uint16Val; - break; - case INT32: - _value.int32Val = other._value.int32Val; - break; - case UINT32: - _value.uint32Val = other._value.uint32Val; - break; - case FLOAT: - _value.floatVal = other._value.floatVal; - break; - case DOUBLE: - _value.doubleVal = other._value.doubleVal; - break; - case STRING: - uint32 length = strlen(other._value.stringVal); - _value.stringVal = new char[length + 1]; - memcpy(_value.stringVal, other._value.stringVal, length + 1); - break; - } -} - -SingleValueContainer::~SingleValueContainer() { - deleteCharPointer(); -} - -void SingleValueContainer::deleteCharPointer() { - if (_objectType == STRING) - delete[] _value.stringVal; -} - - -SingleValueContainer &SingleValueContainer::operator=(const bool &rhs) { - if (_objectType == BOOL) { - _value.boolVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = BOOL; - _value.boolVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const byte &rhs) { - if (_objectType == BYTE) { - _value.byteVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = BYTE; - _value.byteVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const int16 &rhs) { - if (_objectType == INT16) { - _value.int16Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = INT16; - _value.int16Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const uint16 &rhs) { - if (_objectType == UINT16) { - _value.uint16Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = UINT16; - _value.uint16Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const int32 &rhs) { - if (_objectType == INT32) { - _value.int32Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = INT32; - _value.int32Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const uint32 &rhs) { - if (_objectType == UINT32) { - _value.uint32Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = UINT32; - _value.uint32Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const float &rhs) { - if (_objectType == FLOAT) { - _value.floatVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = FLOAT; - _value.floatVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const double &rhs) { - if (_objectType == DOUBLE) { - _value.doubleVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = DOUBLE; - _value.doubleVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const Common::String &rhs) { - if (_objectType != STRING) { - _objectType = STRING; - _value.stringVal = new char[rhs.size() + 1]; - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - - return *this; - } - - uint32 length = strlen(_value.stringVal); - if (length <= rhs.size() + 1) { - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - } else { - delete[] _value.stringVal; - _value.stringVal = new char[rhs.size() + 1]; - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - } - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const SingleValueContainer &rhs) { - switch (_objectType) { - case BOOL: - return operator=(rhs._value.boolVal); - case BYTE: - return operator=(rhs._value.byteVal); - case INT16: - return operator=(rhs._value.int16Val); - case UINT16: - return operator=(rhs._value.uint16Val); - case INT32: - return operator=(rhs._value.int32Val); - case UINT32: - return operator=(rhs._value.uint32Val); - case FLOAT: - return operator=(rhs._value.floatVal); - case DOUBLE: - return operator=(rhs._value.doubleVal); - case STRING: - uint32 length = strlen(rhs._value.stringVal); - - _value.stringVal = new char[length + 1]; - memcpy(_value.stringVal, rhs._value.stringVal, length + 1); - - return *this; - } - - return *this; -} - - -bool SingleValueContainer::getBoolValue(bool *returnValue) const { - if (_objectType != BOOL) { - warning("'Object' is not storing a bool."); - return false; - } - - *returnValue = _value.boolVal; - return true; -} - -bool SingleValueContainer::getByteValue(byte *returnValue) const { - if (_objectType != BYTE) - warning("'Object' is not storing a byte."); - - *returnValue = _value.byteVal; - return true; -} - -bool SingleValueContainer::getInt16Value(int16 *returnValue) const { - if (_objectType != INT16) - warning("'Object' is not storing an int16."); - - *returnValue = _value.int16Val; - return true; -} - -bool SingleValueContainer::getUInt16Value(uint16 *returnValue) const { - if (_objectType != UINT16) - warning("'Object' is not storing a uint16."); - - *returnValue = _value.uint16Val; - return true; -} - -bool SingleValueContainer::getInt32Value(int32 *returnValue) const { - if (_objectType != INT32) - warning("'Object' is not storing an int32."); - - *returnValue = _value.int32Val; - return true; -} - -bool SingleValueContainer::getUInt32Value(uint32 *returnValue) const { - if (_objectType != UINT32) - warning("'Object' is not storing a uint32."); - - *returnValue = _value.uint32Val; - return true; -} - -bool SingleValueContainer::getFloatValue(float *returnValue) const { - if (_objectType != FLOAT) - warning("'Object' is not storing a float."); - - *returnValue = _value.floatVal; - return true; -} - -bool SingleValueContainer::getDoubleValue(double *returnValue) const { - if (_objectType != DOUBLE) - warning("'Object' is not storing a double."); - - *returnValue = _value.doubleVal; - return true; -} - -bool SingleValueContainer::getStringValue(Common::String *returnValue) const { - if (_objectType != STRING) - warning("'Object' is not storing a Common::String."); - - *returnValue = _value.stringVal; - return true; -} - -} // End of namespace ZVision diff --git a/engines/zvision/object.h b/engines/zvision/object.h deleted file mode 100644 index 3c24cc07f0..0000000000 --- a/engines/zvision/object.h +++ /dev/null @@ -1,181 +0,0 @@ -/* 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 ZVISION_OBJECT_H -#define ZVISION_OBJECT_H - -#include "common/str.h" - -namespace ZVision { - -/** - * A generic single value storage class. It is useful for storing different - * value types in a single List, Hashmap, etc. - */ -class SingleValueContainer { -public: - enum ValueType { - BOOL, - BYTE, - INT16, - UINT16, - INT32, - UINT32, - FLOAT, - DOUBLE, - STRING, - }; - - // Constructors - explicit SingleValueContainer(ValueType type); - explicit SingleValueContainer(bool value); - explicit SingleValueContainer(byte value); - explicit SingleValueContainer(int16 value); - explicit SingleValueContainer(uint16 value); - explicit SingleValueContainer(int32 value); - explicit SingleValueContainer(uint32 value); - explicit SingleValueContainer(float value); - explicit SingleValueContainer(double value); - explicit SingleValueContainer(Common::String value); - - // Copy constructor - explicit SingleValueContainer(const SingleValueContainer& other); - - // Destructor - ~SingleValueContainer(); - -private: - ValueType _objectType; - - union { - bool boolVal; - byte byteVal; - int16 int16Val; - uint16 uint16Val; - int32 int32Val; - uint32 uint32Val; - float floatVal; - double doubleVal; - char *stringVal; - } _value; - -public: - SingleValueContainer &operator=(const bool &rhs); - SingleValueContainer &operator=(const byte &rhs); - SingleValueContainer &operator=(const int16 &rhs); - SingleValueContainer &operator=(const uint16 &rhs); - SingleValueContainer &operator=(const int32 &rhs); - SingleValueContainer &operator=(const uint32 &rhs); - SingleValueContainer &operator=(const float &rhs); - SingleValueContainer &operator=(const double &rhs); - SingleValueContainer &operator=(const Common::String &rhs); - - SingleValueContainer& operator=(const SingleValueContainer &rhs); - - /** - * Retrieve a bool from the container. If the container is not storing a - * bool, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getBoolValue(bool *returnValue) const; - /** - * Retrieve a byte from the container. If the container is not storing a - * byte, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getByteValue(byte *returnValue) const; - /** - * Retrieve an int16 from the container. If the container is not storing an - * int16, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getInt16Value(int16 *returnValue) const; - /** - * Retrieve a uint16 from the container. If the container is not storing a - * uint16, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getUInt16Value(uint16 *returnValue) const; - /** - * Retrieve an int32 from the container. If the container is not storing an - * int32, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getInt32Value(int32 *returnValue) const; - /** - * Retrieve a uint32 from the container. If the container is not storing a - * uint32, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getUInt32Value(uint32 *returnValue) const; - /** - * Retrieve a float from the container. If the container is not storing a - * float, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getFloatValue(float *returnValue) const; - /** - * Retrieve a double from the container. If the container is not storing a - * double, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getDoubleValue(double *returnValue) const; - /** - * Retrieve a String from the container. If the container is not storing a - * string, this will return false and display a warning(). - * - * Caution: Strings are internally stored as char[]. getStringValue uses - * Common::String::operator=(char *) to do the assigment, which uses both - * strlen() AND memmove(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getStringValue(Common::String *returnValue) const; - -private: - /** - * Helper method for destruction and assignment. It checks to see - * if the char pointer is being used, and if so calls delete on it - */ - void deleteCharPointer(); -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/singleValueContainer.cpp b/engines/zvision/singleValueContainer.cpp new file mode 100644 index 0000000000..6a3d4e047d --- /dev/null +++ b/engines/zvision/singleValueContainer.cpp @@ -0,0 +1,345 @@ +/* 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/scummsys.h" +#include "common/textconsole.h" + +#include "zvision/object.h" + +namespace ZVision { + +SingleValueContainer::SingleValueContainer(ValueType type) : _objectType(type) { } + +SingleValueContainer::SingleValueContainer(bool value) : _objectType(BOOL) { + _value.boolVal = value; +} + +SingleValueContainer::SingleValueContainer(byte value) : _objectType(BYTE) { + _value.byteVal = value; +} + +SingleValueContainer::SingleValueContainer(int16 value) : _objectType(INT16) { + _value.int16Val = value; +} + +SingleValueContainer::SingleValueContainer(uint16 value) : _objectType(UINT16) { + _value.uint16Val = value; +} + +SingleValueContainer::SingleValueContainer(int32 value) : _objectType(INT32) { + _value.int32Val = value; +} + +SingleValueContainer::SingleValueContainer(uint32 value) : _objectType(UINT32) { + _value.uint32Val = value; +} + +SingleValueContainer::SingleValueContainer(float value) : _objectType(FLOAT) { + _value.floatVal = value; +} + +SingleValueContainer::SingleValueContainer(double value) : _objectType(DOUBLE) { + _value.doubleVal = value; +} + +SingleValueContainer::SingleValueContainer(Common::String value) : _objectType(BYTE) { + _value.stringVal = new char[value.size() + 1]; + memcpy(_value.stringVal, value.c_str(), value.size() + 1); +} + +SingleValueContainer::SingleValueContainer(const SingleValueContainer &other) { + _objectType = other._objectType; + + switch (_objectType) { + case BOOL: + _value.boolVal = other._value.boolVal; + break; + case BYTE: + _value.byteVal = other._value.byteVal; + break; + case INT16: + _value.int16Val = other._value.int16Val; + break; + case UINT16: + _value.uint16Val = other._value.uint16Val; + break; + case INT32: + _value.int32Val = other._value.int32Val; + break; + case UINT32: + _value.uint32Val = other._value.uint32Val; + break; + case FLOAT: + _value.floatVal = other._value.floatVal; + break; + case DOUBLE: + _value.doubleVal = other._value.doubleVal; + break; + case STRING: + uint32 length = strlen(other._value.stringVal); + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, other._value.stringVal, length + 1); + break; + } +} + +SingleValueContainer::~SingleValueContainer() { + deleteCharPointer(); +} + +void SingleValueContainer::deleteCharPointer() { + if (_objectType == STRING) + delete[] _value.stringVal; +} + + +SingleValueContainer &SingleValueContainer::operator=(const bool &rhs) { + if (_objectType == BOOL) { + _value.boolVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = BOOL; + _value.boolVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const byte &rhs) { + if (_objectType == BYTE) { + _value.byteVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = BYTE; + _value.byteVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const int16 &rhs) { + if (_objectType == INT16) { + _value.int16Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = INT16; + _value.int16Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const uint16 &rhs) { + if (_objectType == UINT16) { + _value.uint16Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = UINT16; + _value.uint16Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const int32 &rhs) { + if (_objectType == INT32) { + _value.int32Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = INT32; + _value.int32Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const uint32 &rhs) { + if (_objectType == UINT32) { + _value.uint32Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = UINT32; + _value.uint32Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const float &rhs) { + if (_objectType == FLOAT) { + _value.floatVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = FLOAT; + _value.floatVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const double &rhs) { + if (_objectType == DOUBLE) { + _value.doubleVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = DOUBLE; + _value.doubleVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const Common::String &rhs) { + if (_objectType != STRING) { + _objectType = STRING; + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + + return *this; + } + + uint32 length = strlen(_value.stringVal); + if (length <= rhs.size() + 1) { + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + } else { + delete[] _value.stringVal; + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + } + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const SingleValueContainer &rhs) { + switch (_objectType) { + case BOOL: + return operator=(rhs._value.boolVal); + case BYTE: + return operator=(rhs._value.byteVal); + case INT16: + return operator=(rhs._value.int16Val); + case UINT16: + return operator=(rhs._value.uint16Val); + case INT32: + return operator=(rhs._value.int32Val); + case UINT32: + return operator=(rhs._value.uint32Val); + case FLOAT: + return operator=(rhs._value.floatVal); + case DOUBLE: + return operator=(rhs._value.doubleVal); + case STRING: + uint32 length = strlen(rhs._value.stringVal); + + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, rhs._value.stringVal, length + 1); + + return *this; + } + + return *this; +} + + +bool SingleValueContainer::getBoolValue(bool *returnValue) const { + if (_objectType != BOOL) { + warning("'Object' is not storing a bool."); + return false; + } + + *returnValue = _value.boolVal; + return true; +} + +bool SingleValueContainer::getByteValue(byte *returnValue) const { + if (_objectType != BYTE) + warning("'Object' is not storing a byte."); + + *returnValue = _value.byteVal; + return true; +} + +bool SingleValueContainer::getInt16Value(int16 *returnValue) const { + if (_objectType != INT16) + warning("'Object' is not storing an int16."); + + *returnValue = _value.int16Val; + return true; +} + +bool SingleValueContainer::getUInt16Value(uint16 *returnValue) const { + if (_objectType != UINT16) + warning("'Object' is not storing a uint16."); + + *returnValue = _value.uint16Val; + return true; +} + +bool SingleValueContainer::getInt32Value(int32 *returnValue) const { + if (_objectType != INT32) + warning("'Object' is not storing an int32."); + + *returnValue = _value.int32Val; + return true; +} + +bool SingleValueContainer::getUInt32Value(uint32 *returnValue) const { + if (_objectType != UINT32) + warning("'Object' is not storing a uint32."); + + *returnValue = _value.uint32Val; + return true; +} + +bool SingleValueContainer::getFloatValue(float *returnValue) const { + if (_objectType != FLOAT) + warning("'Object' is not storing a float."); + + *returnValue = _value.floatVal; + return true; +} + +bool SingleValueContainer::getDoubleValue(double *returnValue) const { + if (_objectType != DOUBLE) + warning("'Object' is not storing a double."); + + *returnValue = _value.doubleVal; + return true; +} + +bool SingleValueContainer::getStringValue(Common::String *returnValue) const { + if (_objectType != STRING) + warning("'Object' is not storing a Common::String."); + + *returnValue = _value.stringVal; + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/singleValueContainer.h b/engines/zvision/singleValueContainer.h new file mode 100644 index 0000000000..3c24cc07f0 --- /dev/null +++ b/engines/zvision/singleValueContainer.h @@ -0,0 +1,181 @@ +/* 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 ZVISION_OBJECT_H +#define ZVISION_OBJECT_H + +#include "common/str.h" + +namespace ZVision { + +/** + * A generic single value storage class. It is useful for storing different + * value types in a single List, Hashmap, etc. + */ +class SingleValueContainer { +public: + enum ValueType { + BOOL, + BYTE, + INT16, + UINT16, + INT32, + UINT32, + FLOAT, + DOUBLE, + STRING, + }; + + // Constructors + explicit SingleValueContainer(ValueType type); + explicit SingleValueContainer(bool value); + explicit SingleValueContainer(byte value); + explicit SingleValueContainer(int16 value); + explicit SingleValueContainer(uint16 value); + explicit SingleValueContainer(int32 value); + explicit SingleValueContainer(uint32 value); + explicit SingleValueContainer(float value); + explicit SingleValueContainer(double value); + explicit SingleValueContainer(Common::String value); + + // Copy constructor + explicit SingleValueContainer(const SingleValueContainer& other); + + // Destructor + ~SingleValueContainer(); + +private: + ValueType _objectType; + + union { + bool boolVal; + byte byteVal; + int16 int16Val; + uint16 uint16Val; + int32 int32Val; + uint32 uint32Val; + float floatVal; + double doubleVal; + char *stringVal; + } _value; + +public: + SingleValueContainer &operator=(const bool &rhs); + SingleValueContainer &operator=(const byte &rhs); + SingleValueContainer &operator=(const int16 &rhs); + SingleValueContainer &operator=(const uint16 &rhs); + SingleValueContainer &operator=(const int32 &rhs); + SingleValueContainer &operator=(const uint32 &rhs); + SingleValueContainer &operator=(const float &rhs); + SingleValueContainer &operator=(const double &rhs); + SingleValueContainer &operator=(const Common::String &rhs); + + SingleValueContainer& operator=(const SingleValueContainer &rhs); + + /** + * Retrieve a bool from the container. If the container is not storing a + * bool, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getBoolValue(bool *returnValue) const; + /** + * Retrieve a byte from the container. If the container is not storing a + * byte, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getByteValue(byte *returnValue) const; + /** + * Retrieve an int16 from the container. If the container is not storing an + * int16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getInt16Value(int16 *returnValue) const; + /** + * Retrieve a uint16 from the container. If the container is not storing a + * uint16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getUInt16Value(uint16 *returnValue) const; + /** + * Retrieve an int32 from the container. If the container is not storing an + * int32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getInt32Value(int32 *returnValue) const; + /** + * Retrieve a uint32 from the container. If the container is not storing a + * uint32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getUInt32Value(uint32 *returnValue) const; + /** + * Retrieve a float from the container. If the container is not storing a + * float, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getFloatValue(float *returnValue) const; + /** + * Retrieve a double from the container. If the container is not storing a + * double, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getDoubleValue(double *returnValue) const; + /** + * Retrieve a String from the container. If the container is not storing a + * string, this will return false and display a warning(). + * + * Caution: Strings are internally stored as char[]. getStringValue uses + * Common::String::operator=(char *) to do the assigment, which uses both + * strlen() AND memmove(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getStringValue(Common::String *returnValue) const; + +private: + /** + * Helper method for destruction and assignment. It checks to see + * if the char pointer is being used, and if so calls delete on it + */ + void deleteCharPointer(); +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 526c1dc4650948125334cedc32c9fdfb70219dce Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 27 Jun 2013 17:26:26 -0500 Subject: ZVISION: Use spaces in doxygen comments for alignement instead of tabs --- engines/zvision/singleValueContainer.h | 36 +++++++++++++++++----------------- engines/zvision/utility.h | 6 +++--- engines/zvision/zfsArchive.h | 15 +++++++------- 3 files changed, 29 insertions(+), 28 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/singleValueContainer.h b/engines/zvision/singleValueContainer.h index 3c24cc07f0..49c7267f77 100644 --- a/engines/zvision/singleValueContainer.h +++ b/engines/zvision/singleValueContainer.h @@ -95,64 +95,64 @@ public: * Retrieve a bool from the container. If the container is not storing a * bool, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getBoolValue(bool *returnValue) const; /** * Retrieve a byte from the container. If the container is not storing a * byte, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getByteValue(byte *returnValue) const; /** * Retrieve an int16 from the container. If the container is not storing an * int16, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getInt16Value(int16 *returnValue) const; /** * Retrieve a uint16 from the container. If the container is not storing a * uint16, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getUInt16Value(uint16 *returnValue) const; /** * Retrieve an int32 from the container. If the container is not storing an * int32, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getInt32Value(int32 *returnValue) const; /** * Retrieve a uint32 from the container. If the container is not storing a * uint32, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getUInt32Value(uint32 *returnValue) const; /** * Retrieve a float from the container. If the container is not storing a * float, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getFloatValue(float *returnValue) const; /** * Retrieve a double from the container. If the container is not storing a * double, this will return false and display a warning(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getDoubleValue(double *returnValue) const; /** @@ -163,8 +163,8 @@ public: * Common::String::operator=(char *) to do the assigment, which uses both * strlen() AND memmove(). * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful */ bool getStringValue(Common::String *returnValue) const; diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 9fade107f5..4d124509ba 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -33,8 +33,8 @@ namespace 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 + * @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(Common::String sourceFile, Common::String destFile) { Common::File f; @@ -57,7 +57,7 @@ void writeFileContentsToFile(Common::String sourceFile, Common::String destFile) * Then removes any trailing and leading 'whitespace' using String::trim() * Note: String::trim uses isspace() to determine what is whitespace and what is not. * - * @param string The string to modify. It is modified in place + * @param string The string to modify. It is modified in place */ void trimCommentsAndWhiteSpace(Common::String &string) { for (int i = string.size(); i >= 0; --i) { diff --git a/engines/zvision/zfsArchive.h b/engines/zvision/zfsArchive.h index 60292f865e..ccdf192571 100644 --- a/engines/zvision/zfsArchive.h +++ b/engines/zvision/zfsArchive.h @@ -67,7 +67,7 @@ public: * Add all members of the Archive to list. * Must only append to list, and not remove elements from it. * - * @return the number of names added to list + * @return The number of names added to list */ int listMembers(Common::ArchiveMemberList &list) const; @@ -79,7 +79,8 @@ public: /** * Create a stream bound to a member with the specified name in the * archive. If no member with this name exists, 0 is returned. - * @return the newly created input stream + * + * @return The newly created input stream */ Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; @@ -92,7 +93,7 @@ private: * Parses the zfs file into file entry headers that can be used later * to get the entry data. * - * @param stream The contents of the zfs file + * @param stream The contents of the zfs file */ void readHeaders(Common::SeekableReadStream *stream); @@ -100,8 +101,8 @@ private: * Entry names are contained within a 16 byte block. This reads the block * and converts it the name to a Common::String * - * @param stream The zfs file stream - * @return The entry file name + * @param stream The zfs file stream + * @return The entry file name */ Common::String readEntryName(Common::SeekableReadStream *stream) const; @@ -109,8 +110,8 @@ private: * ZFS file entries can be encrypted using XOR encoding. This method * decodes the buffer in place using the supplied xorKey. * - * @param buffer The data to decode - * @param length Length of buffer + * @param buffer The data to decode + * @param length Length of buffer */ void unXor(byte *buffer, int length, const byte *xorKey) const; }; -- cgit v1.2.3 From ac96b943fa90270e1b5c1536f3b0d49bb6c3b161 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 12:19:11 -0500 Subject: ZVISION: Create an instance of ScriptManager inside ZVision --- engines/zvision/zvision.cpp | 7 ++++++- engines/zvision/zvision.h | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 452ed00daf..2009ccde44 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -32,10 +32,13 @@ #include "engines/util.h" #include "zvision/zvision.h" +#include "zvision/scriptManager.h" #include "zvision/zfsArchive.h" #include "graphics/decoders/tga.h" +#include "zvision/tests.h" + namespace ZVision { ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { @@ -59,7 +62,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine // Don't forget to register your random source _rnd = new Common::RandomSource("zvision"); - + debug("ZVision::ZVision"); } @@ -90,6 +93,8 @@ void ZVision::initialize() { Graphics::PixelFormat format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); // RGB555 initGraphics(640, 480, true, &format); + _scriptManager.initialize(); + // Create debugger console. It requires GFX to be initialized _console = new Console(this); } diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index c5ddb8ab4a..b57ce20e25 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -29,6 +29,8 @@ #include "engines/engine.h" +#include "zvision/scriptManager.h" + #include "gui/debugger.h" namespace ZVision { @@ -56,6 +58,8 @@ private: // We need random numbers Common::RandomSource *_rnd; + ScriptManager _scriptManager; + // To prevent allocation every time we process events Common::Event _event; -- cgit v1.2.3 From b3b7bd29b1fe2dcb2e2c13bbd68c907dc4990552 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 17:13:02 -0500 Subject: ZVISION: Create ResultAction base class and ActionAdd child class --- engines/zvision/resultAction.cpp | 38 +++++++++++++++++ engines/zvision/resultAction.h | 92 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 engines/zvision/resultAction.cpp create mode 100644 engines/zvision/resultAction.h (limited to 'engines/zvision') diff --git a/engines/zvision/resultAction.cpp b/engines/zvision/resultAction.cpp new file mode 100644 index 0000000000..d14438d190 --- /dev/null +++ b/engines/zvision/resultAction.cpp @@ -0,0 +1,38 @@ +/* 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/scummsys.h" + +#include "zvision/resultAction.h" + +namespace ZVision { + +ActionAdd::ActionAdd(Common::String line) { + sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); +} + +bool ActionAdd::execute(ZVision *zVision) { + zVision->getScriptManager()->addToStateValue(_key, _value); + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/resultAction.h b/engines/zvision/resultAction.h new file mode 100644 index 0000000000..4fd589d7cc --- /dev/null +++ b/engines/zvision/resultAction.h @@ -0,0 +1,92 @@ +/* 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 ZVISION_RESULT_ACTION_H +#define ZVISION_RESULT_ACTION_H + +#include "common/scummsys.h" + +#include "zvision/zvision.h" + +namespace ZVision { + +class ResultAction { +public: + virtual ~ResultAction() {} + virtual bool execute(ZVision *zVision) = 0; +}; + + +// The different types of actions +// ADD, +// ANIM_PLAY, +// ANIM_PRELOAD, +// ANIM_UNLOAD, +// ATTENUATE, +// ASSIGN, +// CHANGE_LOCATION, +// CROSSFADE, +// DEBUG, +// DELAY_RENDER, +// DISABLE_CONTROL, +// DISABLE_VENUS, +// DISPLAY_MESSAGE, +// DISSOLVE, +// DISTORT, +// ENABLE_CONTROL, +// FLUSH_MOUSE_EVENTS, +// INVENTORY, +// KILL, +// MENU_BAR_ENABLE, +// MUSIC, +// PAN_TRACK, +// PLAY_PRELOAD, +// PREFERENCES, +// QUIT, +// RANDOM, +// REGION, +// RESTORE_GAME, +// ROTATE_TO, +// SAVE_GAME, +// SET_PARTIAL_SCREEN, +// SET_SCREEN, +// SET_VENUS, +// STOP, +// STREAM_VIDEO, +// SYNC_SOUND, +// TIMER, +// TTY_TEXT, +// UNIVERSE_MUSIC, + +class ActionAdd : public ResultAction { +public: + ActionAdd(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + byte _value; +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 464cc44a8204134681aadbe68645fd4efe6d04d4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 17:16:32 -0500 Subject: ZVISION: Convert ScriptManager methods to use ResultAction classes logic --- engines/zvision/puzzle.h | 61 +------- engines/zvision/scrFileHandling.cpp | 284 ++++++++++++++++-------------------- 2 files changed, 129 insertions(+), 216 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 1133adac47..1a456ef6e2 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -25,7 +25,7 @@ #include "common/list.h" -#include "zvision/object.h" +#include "zvision/resultAction.h" namespace ZVision { @@ -39,11 +39,11 @@ enum CriteriaOperator { /** Criteria for a Puzzle result to be fired */ struct Criteria { - /** The id of a global state */ - uint32 id; + /** The key of a global state */ + uint32 key; /** * What we're comparing the value of the global state against - * This can either be a pure value or it can be the id of another global state + * This can either be a pure value or it can be the key of another global state */ uint32 argument; /** How to do the comparison */ @@ -52,55 +52,6 @@ struct Criteria { bool isArgumentAnId; }; -/** What happens when Puzzle criteria are met */ -enum ResultAction { - ADD, - ANIM_PLAY, - ANIM_PRELOAD, - ANIM_UNLOAD, - ATTENUATE, - ASSIGN, - CHANGE_LOCATION, - CROSSFADE, - DEBUG, - DELAY_RENDER, - DISABLE_CONTROL, - DISABLE_VENUS, - DISPLAY_MESSAGE, - DISSOLVE, - DISTORT, - ENABLE_CONTROL, - FLUSH_MOUSE_EVENTS, - INVENTORY, - KILL, - MENU_BAR_ENABLE, - MUSIC, - PAN_TRACK, - PLAY_PRELOAD, - PREFERENCES, - QUIT, - RANDOM, - REGION, - RESTORE_GAME, - ROTATE_TO, - SAVE_GAME, - SET_PARTIAL_SCREEN, - SET_SCREEN, - SET_VENUS, - STOP, - STREAM_VIDEO, - SYNC_SOUND, - TIMER, - TTY_TEXT, - UNIVERSE_MUSIC, -}; - -/** What happens when Puzzle criteria are met */ -struct Result { - ResultAction action; - Common::List arguments; -}; - enum StateFlags : byte { ONCE_PER_INST = 0x01, DO_ME_NOW = 0x02, @@ -108,9 +59,9 @@ enum StateFlags : byte { }; struct Puzzle { - uint32 id; + uint32 key; Common::List criteriaList; - Common::List resultList; + Common::List resultActions; byte flags; }; diff --git a/engines/zvision/scrFileHandling.cpp b/engines/zvision/scrFileHandling.cpp index a0d4cebf9a..c511a2e641 100644 --- a/engines/zvision/scrFileHandling.cpp +++ b/engines/zvision/scrFileHandling.cpp @@ -26,6 +26,7 @@ #include "zvision/scriptManager.h" #include "zvision/utility.h" +#include "zvision/puzzle.h" #include "common/textconsole.h" #include "common/file.h" @@ -33,13 +34,11 @@ namespace ZVision { - void ScriptManager::parseScrFile(Common::String fileName) { Common::File file; if (!file.open(fileName)) return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another - char buffer[1024]; while(!file.eos()) { Common::String line = file.readLine(); if (file.err()) { @@ -52,32 +51,34 @@ void ScriptManager::parseScrFile(Common::String fileName) { continue; if (line.matchString("puzzle:*", true)) { - Puzzle *puzzle = new Puzzle(); - sscanf(line.c_str(),"puzzle:%u",&(puzzle->id)); + Puzzle puzzle; + sscanf(line.c_str(),"puzzle:%u",&(puzzle.id)); parsePuzzle(puzzle, file); + _puzzles.push_back(puzzle); } else if (line.matchString("control:*", true)) { - Control *control = new Control(); - sscanf(line.c_str(),"control:%u",&(control->id)); + Control control; + char controlType[20]; + sscanf(line.c_str(),"control:%u %s",&(control.id), controlType); parseControl(control, file); + _controls.push_back(control); } } } -void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream) { +void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(line); while (!line.contains('}')) { if (line.matchString("criteria {", true)) - puzzle->criteriaList.push_back(parseCriteria(stream)); + puzzle.criteriaList.push_back(parseCriteria(stream)); else if (line.matchString("results {", true)) - puzzle->resultList.push_back(parseResult(stream)); + parseResult(stream, puzzle.resultActions); else if (line.matchString("flags {", true)) - puzzle->flags = parseFlags(stream); + puzzle.flags = parseFlags(stream); } - } Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const { @@ -125,177 +126,138 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const return criteria; } -Result ScriptManager::parseResult(Common::SeekableReadStream &stream) const { - Result result; - +void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(line); while (!line.contains('}')) { - Common::StringTokenizer tokenizer(line, " :(),"); - // We don't care about the first token - tokenizer.nextToken(); - Common::String token = tokenizer.nextToken(); - - // The second token defines the action - // Use it to set the action enum and then to parse the arguments - if (token.matchString("add", true)) { - result.action = ADD; - ObjectType argTypes[] = { UINT32, UINT32 }; - parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); - } else if (token.matchString("animplay", true)) { - result.action = ANIM_PLAY; + // Parse for the action type + if (line.matchString("*:add*", true)) { + actionList.push_back(ActionAdd(line)); + } else if (line.matchString("*:animplay*", true)) { + - } else if (token.matchString("animpreload", true)) { - result.action = ANIM_PRELOAD; - - } else if (token.matchString("animunload", true)) { - result.action = ANIM_UNLOAD; - - } else if (token.matchString("attenuate", true)) { - result.action = ATTENUATE; + } else if (line.matchString("*:animpreload*", true)) { + - } else if (token.matchString("assign", true)) { - result.action = ASSIGN; - ObjectType argTypes[] = { UINT32, UINT32 }; - parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); - } else if (token.matchString("change_location", true)) { - result.action = CHANGE_LOCATION; - ObjectType argTypes[] = { STRING, STRING, STRING, UINT32 }; - parseResultArguments(result, argTypes, 4, tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken()); - } else if (token.matchString("crossfade", true)) { - result.action = CROSSFADE; - - } else if (token.matchString("debug", true)) { - result.action = DEBUG; - - } else if (token.matchString("delay_render", true)) { - result.action = DELAY_RENDER; - - } else if (token.matchString("disable_control", true)) { - result.action = DISABLE_CONTROL; - - } else if (token.matchString("disable_venus", true)) { - result.action = DISABLE_VENUS; - - } else if (token.matchString("display_message", true)) { - result.action = DISPLAY_MESSAGE; - - } else if (token.matchString("dissolve", true)) { - result.action = DISSOLVE; - } else if (token.matchString("distort", true)) { - result.action = DISTORT; - - } else if (token.matchString("enable_control", true)) { - result.action = ENABLE_CONTROL; - - } else if (token.matchString("flush_mouse_events", true)) { - result.action = FLUSH_MOUSE_EVENTS; - - } else if (token.matchString("inventory", true)) { - result.action = INVENTORY; - - } else if (token.matchString("kill", true)) { - result.action = KILL; - - } else if (token.matchString("menu_bar_enable", true)) { - result.action = MENU_BAR_ENABLE; - - } else if (token.matchString("music", true)) { - result.action = MUSIC; - ObjectType argTypes[] = { UINT32, UINT32, STRING, UINT32, UINT32 }; - parseResultArguments(result, argTypes, 5, - tokenizer.nextToken(), tokenizer.nextToken(), - tokenizer.nextToken(), tokenizer.nextToken(), - tokenizer.nextToken()); - } else if (token.matchString("pan_track", true)) { - result.action = PAN_TRACK; - - } else if (token.matchString("playpreload", true)) { - result.action = PLAY_PRELOAD; - - } else if (token.matchString("preferences", true)) { - result.action = PREFERENCES; - - } else if (token.matchString("quit", true)) { - result.action = QUIT; - - } else if (token.matchString("random", true)) { - result.action = RANDOM; - ObjectType argTypes[] = { UINT32, UINT32 }; - parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); - } else if (token.matchString("region", true)) { - result.action = REGION; - - } else if (token.matchString("restore_game", true)) { - result.action = RESTORE_GAME; - - } else if (token.matchString("rotate_to", true)) { - result.action = ROTATE_TO; - - } else if (token.matchString("save_game", true)) { - result.action = SAVE_GAME; + } else if (line.matchString("*:animunload*", true)) { + - } else if (token.matchString("set_partial_screen", true)) { - result.action = SET_PARTIAL_SCREEN; + } else if (line.matchString("*:attenuate*", true)) { + - } else if (token.matchString("set_screen", true)) { - result.action = SET_SCREEN; + } else if (line.matchString("*:assign*", true)) { + - } else if (token.matchString("set_venus", true)) { - result.action = SET_VENUS; + } else if (line.matchString("*:change_location*", true)) { + - } else if (token.matchString("stop", true)) { - result.action = STOP; - ObjectType argTypes[] = { UINT32 }; - parseResultArguments(result, argTypes, 1, tokenizer.nextToken()); - } else if (token.matchString("streamvideo", true)) { - result.action = STREAM_VIDEO; + } else if (line.matchString("*:crossfade*", true)) { + - } else if (token.matchString("syncsound", true)) { - result.action = SYNC_SOUND; + } else if (line.matchString("*:debug*", true)) { + - } else if (token.matchString("timer", true)) { - result.action = TIMER; - ObjectType argTypes[] = { UINT32, UINT32 }; - parseResultArguments(result, argTypes, 2, tokenizer.nextToken(), tokenizer.nextToken()); - } else if (token.matchString("ttytext", true)) { - result.action = TTY_TEXT; + } else if (line.matchString("*:delay_render*", true)) { + - } else if (token.matchString("universe_music", true)) { - result.action = UNIVERSE_MUSIC; + } else if (line.matchString("*:disable_control*", true)) { + - } else { - warning("Unhandled result action type: ", token); - } + } else if (line.matchString("*:disable_venus*", true)) { + - line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - } + } else if (line.matchString("*:display_message*", true)) { + - return result; -} + } else if (line.matchString("*:dissolve*", true)) { + + + } else if (line.matchString("*:distort*", true)) { + + + } else if (line.matchString("*:enable_control*", true)) { + + + } else if (line.matchString("*:flush_mouse_events*", true)) { + + + } else if (line.matchString("*:inventory*", true)) { + + + } else if (line.matchString("*:kill*", true)) { + + + } else if (line.matchString("*:menu_bar_enable*", true)) { + + + } else if (line.matchString("*:music*", true)) { + + + } else if (line.matchString("*:pan_track*", true)) { + + + } else if (line.matchString("*:playpreload*", true)) { + + + } else if (line.matchString("*:preferences*", true)) { + + + } else if (line.matchString("*:quit*", true)) { + + + } else if (line.matchString("*:random*", true)) { + + + } else if (line.matchString("*:region*", true)) { + + + } else if (line.matchString("*:restore_game*", true)) { + + + } else if (line.matchString("*:rotate_to*", true)) { + + + } else if (line.matchString("*:save_game*", true)) { + + + } else if (line.matchString("*:set_partial_screen*", true)) { + + + } else if (line.matchString("*:set_screen*", true)) { + + + } else if (line.matchString("*:set_venus*", true)) { + + + } else if (line.matchString("*:stop*", true)) { + + + } else if (line.matchString("*:streamvideo*", true)) { + + + } else if (line.matchString("*:syncsound*", true)) { + + + } else if (line.matchString("*:timer*", true)) { + + + } else if (line.matchString("*:ttytext*", true)) { + + + } else if (line.matchString("*:universe_music*", true)) { + -void ScriptManager::parseResultArguments(Result &result, const ObjectType *types, int numberOfArgs, ...) const { - va_list argptr; - va_start(argptr, numberOfArgs); - - for (int i = 0; i < numberOfArgs; i++) { - if (types[i] == UINT32) { - Common::String arg = va_arg(argptr, Common::String); - Object argObject(UINT32); - sscanf(arg.c_str(), "%u", &argObject); - result.arguments.push_back(argObject); - break; } else { - Common::String arg = va_arg(argptr, Common::String); - result.arguments.push_back(Object(arg)); - break; + warning("Unhandled result action type: ", line); } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(line); } - va_end(argptr); + return; } byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { @@ -318,7 +280,7 @@ byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { return flags; } -void ScriptManager::parseControl(Control *control, Common::SeekableReadStream &stream) { +void ScriptManager::parseControl(Control &control, Common::SeekableReadStream &stream) { } -- cgit v1.2.3 From b70f85b9a0775212f47c25f5218e63b117d0c696 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 17:18:21 -0500 Subject: ZVISION: Comment clarification for ScriptManager methods and helper structs --- engines/zvision/scrFileHandling.cpp | 4 +-- engines/zvision/scriptManager.h | 63 +++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 32 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scrFileHandling.cpp b/engines/zvision/scrFileHandling.cpp index c511a2e641..61feb12b7e 100644 --- a/engines/zvision/scrFileHandling.cpp +++ b/engines/zvision/scrFileHandling.cpp @@ -113,10 +113,10 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const token = tokenizer.nextToken(); if (token.contains('[')) { sscanf(token.c_str(), "[%u]", &(criteria.argument)); - criteria.argumentIsAnId = true; + criteria.isArgumentAnId = true; } else { sscanf(token.c_str(), "%u", &(criteria.argument)); - criteria.argumentIsAnId = false; + criteria.isArgumentAnId = false; } line = stream.readLine(); diff --git a/engines/zvision/scriptManager.h b/engines/zvision/scriptManager.h index 0bae91945d..563a010de5 100644 --- a/engines/zvision/scriptManager.h +++ b/engines/zvision/scriptManager.h @@ -29,17 +29,27 @@ #include "zvision/puzzle.h" #include "zvision/control.h" +#include "zvision/singleValueContainer.h" namespace ZVision { class ScriptManager { -public: - ScriptManager(); - ~ScriptManager(); - private: + /** Holds the global state variables. Optimize for fast random access */ Common::HashMap _globalState; + /** Holds the currently active puzzles. Optimize for fast iteration */ + Common::List _puzzles; + /** Holds the currently active controls. Optimize for fast iteration */ + Common::List _controls; +public: + + void initialize(); + byte getStateValue(uint32 key); + void setStateValue(uint32 key, byte value); + void addToStateValue(uint32 key, byte valueToAdd); + +private: /** * Parses a script file into triggers and events * @@ -48,54 +58,47 @@ private: void parseScrFile(Common::String fileName); /** - * Helper method for parseScrFile. Parses the stream into a Puzzle object + * Parses the stream into a Puzzle object + * Helper method for parseScrFile. * - * @param puzzle The object to store what is parsed - * @param stream Scr file stream + * @param puzzle The object to store what is parsed + * @param stream Scr file stream */ - void parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream); + void parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream); /** - * Helper method for parsePuzzle. Parses the stream into a Criteria object + * Parses the stream into a Criteria object + * Helper method for parsePuzzle. * - * @param stream Scr file stream - * @return Created Criteria object + * @param stream Scr file stream + * @return Created Criteria object */ Criteria parseCriteria(Common::SeekableReadStream &stream) const; /** - * Helper method for parsePuzzle. Parses the stream into a Results object - * - * @param stream Scr file stream - * @return Created Results object - */ - Result parseResult(Common::SeekableReadStream &stream) const; - - /** - * Helper method for parseResults. Parses a number of strings into Object types. + * Parses the stream into a Results object + * Helper method for parsePuzzle. * - * @param result Results object to store the arguments in - * @param types The type of the each of the arguments. IE. BOOL, UINT32, etc. - * @param numberOfArgs The number of arguments. This has to equal the length of 'types' AND the number of optional arguments passed. - * @param String arguments wanting to be parsed + * @param stream Scr file stream + * @return Created Results object */ - void parseResultArguments(Result &result, const ObjectType *types, int numberOfArgs, ...) const; + void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; /** * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum * - * @param stream Scr file stream - * @return Bitwise or of all the flags set within the puzzle + * @param stream Scr file stream + * @return Bitwise or of all the flags set within the puzzle */ byte parseFlags(Common::SeekableReadStream &stream) const; /** * Helper method for parseScrFile. Parses the stream into a Control object * - * @param control The object to store what is parsed - * @param stream Scr file stream + * @param control The object to store what is parsed + * @param stream Scr file stream */ - void parseControl(Control *control, Common::SeekableReadStream &stream); + void parseControl(Control &control, Common::SeekableReadStream &stream); }; -- cgit v1.2.3 From dec34c174bd34f1fd1354985e7c70336270dd9e6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 17:19:09 -0500 Subject: ZVISION: Create global state accessor/mutator methods for ScriptManager --- engines/zvision/scriptManager.cpp | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 engines/zvision/scriptManager.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/scriptManager.cpp b/engines/zvision/scriptManager.cpp new file mode 100644 index 0000000000..5317bf60f1 --- /dev/null +++ b/engines/zvision/scriptManager.cpp @@ -0,0 +1,46 @@ +/* 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/scummsys.h" + +#include "zvision/scriptManager.h" + +namespace ZVision { + +// TODO: Actually do something in the initialize or remove it +void ScriptManager::initialize() { + +} + +byte ScriptManager::getStateValue(uint32 key) { + return _globalState[key]; +} + +void ScriptManager::setStateValue(uint32 key, byte value) { + _globalState[key] = value; +} + +void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) { + _globalState[key] += valueToAdd; +} + +} // End of namespace ZVision -- cgit v1.2.3 From 8d9f90bf12c758ac4845f19ae8584c0c5ee264c8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 17:23:57 -0500 Subject: ZVISION: Create ScriptManager accessor for ZVision Having the ScriptManager as a member variable forced it to be const, which prevented any non cont methods to be used. Thus, ScriptManager is created on the heap and disposed after use. --- engines/zvision/zvision.cpp | 16 ++++++++++++---- engines/zvision/zvision.h | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 2009ccde44..33b2a80bd4 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -60,19 +60,23 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); //DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example"); - // Don't forget to register your random source + // Register random source _rnd = new Common::RandomSource("zvision"); + // Create managers + _scriptManager = new ScriptManager(); + debug("ZVision::ZVision"); } ZVision::~ZVision() { debug("ZVision::~ZVision"); - // Dispose your resources here + // Dispose of resources + delete _scriptManager; delete _rnd; - // Remove all of our debug levels here + // Remove all of our debug levels DebugMan.clearAllDebugChannels(); } @@ -93,7 +97,7 @@ void ZVision::initialize() { Graphics::PixelFormat format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); // RGB555 initGraphics(640, 480, true, &format); - _scriptManager.initialize(); + _scriptManager->initialize(); // Create debugger console. It requires GFX to be initialized _console = new Console(this); @@ -134,4 +138,8 @@ Common::Error ZVision::run() { return Common::kNoError; } +ScriptManager *ZVision::getScriptManager() const { + return _scriptManager; +} + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index b57ce20e25..b0cd1aec5a 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -58,7 +58,7 @@ private: // We need random numbers Common::RandomSource *_rnd; - ScriptManager _scriptManager; + ScriptManager *_scriptManager; // To prevent allocation every time we process events Common::Event _event; @@ -69,7 +69,8 @@ public: uint32 getFeatures() const; Common::Language getLanguage() const; virtual Common::Error run(); - + ScriptManager *getScriptManager() const; + private: void initialize(); -- cgit v1.2.3 From 7bc0097ddef3bbbb38bf854a2ed8685c92fd3312 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 17:24:20 -0500 Subject: ZVISION: Fix include for singleValueContainer.cpp --- engines/zvision/singleValueContainer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/singleValueContainer.cpp b/engines/zvision/singleValueContainer.cpp index 6a3d4e047d..bd91c44daf 100644 --- a/engines/zvision/singleValueContainer.cpp +++ b/engines/zvision/singleValueContainer.cpp @@ -23,7 +23,7 @@ #include "common/scummsys.h" #include "common/textconsole.h" -#include "zvision/object.h" +#include "zvision/singleValueContainer.h" namespace ZVision { -- cgit v1.2.3 From daa2c4b67060ba8c86b11f60a59f1b59fec5037f Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 1 Jul 2013 17:26:12 -0500 Subject: ZVISION: Move test functions out of video.cpp and into their own file The file only exist to hold the code. The actual tests will be moved to an appropriate location later. --- engines/zvision/tests.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/video.cpp | 50 ------------------------------------------- 2 files changed, 54 insertions(+), 50 deletions(-) create mode 100644 engines/zvision/tests.h (limited to 'engines/zvision') diff --git a/engines/zvision/tests.h b/engines/zvision/tests.h new file mode 100644 index 0000000000..14f80ed83b --- /dev/null +++ b/engines/zvision/tests.h @@ -0,0 +1,54 @@ + +namespace ZVision { + +void tests() { +#if 0 + // Video test + Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); + if (videoDecoder && videoDecoder->loadFile("zassets/temple/t000a11c.avi")) { + Common::List formats; + formats.push_back(videoDecoder->getPixelFormat()); + //initGraphics(640, 480, true, formats); + + playVideo(videoDecoder); + } +#endif + + Common::File f; + +#if 1 + // Image test + + //initGraphics(640, 480, true, &format); + + if (f.open(" zassets/global/GJDEB11C.TGA")) { + Graphics::TGADecoder tga; + if (!tga.loadStream(f)) + error("Error while reading TGA image"); + f.close(); + + const Graphics::Surface *tgaSurface = tga.getSurface(); + + Graphics::Surface *screen = g_system->lockScreen(); + for (uint16 y = 0; y < tgaSurface->h; y++) + memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); + g_system->unlockScreen(); + + tga.destroy(); + } + + +#endif + +#if 0 + // Sound test + if (f.open("zassets/castle/c000h9tc.raw")) { + Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); + Audio::SoundHandle handle; + g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); + } + +#endif +} + +} // End of namespace ZVision diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index ce686839e8..4e5fe82f97 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -132,54 +132,4 @@ void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { delete videoDecoder; } -void tests() { -#if 0 - // Video test - Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); - if (videoDecoder && videoDecoder->loadFile("zassets/temple/t000a11c.avi")) { - Common::List formats; - formats.push_back(videoDecoder->getPixelFormat()); - //initGraphics(640, 480, true, formats); - - playVideo(videoDecoder); - } -#endif - - Common::File f; - -#if 0 - // Image test - - //initGraphics(640, 480, true, &format); - - if (f.open("zassets/castle/cb8eb11c.tga")) { - Graphics::TGADecoder tga; - if (!tga.loadStream(f)) - error("Error while reading TGA image"); - f.close(); - - const Graphics::Surface *tgaSurface = tga.getSurface(); - - Graphics::Surface *screen = g_system->lockScreen(); - for (uint16 y = 0; y < tgaSurface->h; y++) - memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); - g_system->unlockScreen(); - - tga.destroy(); - } - - -#endif - -#if 0 - // Sound test - if (f.open("zassets/castle/c000h9tc.raw")) { - Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); - Audio::SoundHandle handle; - g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); - } - -#endif -} - } // End of namespace ZVision -- cgit v1.2.3 From f99d613dcb1022a6c30b0c299ffada11fb7eba6b Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 15:12:24 -0500 Subject: ZVISION: Rename files to use underscores instead of camelCase --- engines/zvision/resultAction.cpp | 38 ---- engines/zvision/resultAction.h | 92 -------- engines/zvision/result_action.cpp | 38 ++++ engines/zvision/result_action.h | 92 ++++++++ engines/zvision/scrFileHandling.cpp | 287 ------------------------ engines/zvision/scr_file_handling.cpp | 287 ++++++++++++++++++++++++ engines/zvision/scriptManager.cpp | 46 ---- engines/zvision/scriptManager.h | 107 --------- engines/zvision/script_manager.cpp | 46 ++++ engines/zvision/script_manager.h | 107 +++++++++ engines/zvision/singleValueContainer.cpp | 345 ----------------------------- engines/zvision/singleValueContainer.h | 181 --------------- engines/zvision/single_value_container.cpp | 345 +++++++++++++++++++++++++++++ engines/zvision/single_value_container.h | 181 +++++++++++++++ engines/zvision/zfsArchive.cpp | 155 ------------- engines/zvision/zfsArchive.h | 121 ---------- engines/zvision/zfs_archive.cpp | 155 +++++++++++++ engines/zvision/zfs_archive.h | 121 ++++++++++ 18 files changed, 1372 insertions(+), 1372 deletions(-) delete mode 100644 engines/zvision/resultAction.cpp delete mode 100644 engines/zvision/resultAction.h create mode 100644 engines/zvision/result_action.cpp create mode 100644 engines/zvision/result_action.h delete mode 100644 engines/zvision/scrFileHandling.cpp create mode 100644 engines/zvision/scr_file_handling.cpp delete mode 100644 engines/zvision/scriptManager.cpp delete mode 100644 engines/zvision/scriptManager.h create mode 100644 engines/zvision/script_manager.cpp create mode 100644 engines/zvision/script_manager.h delete mode 100644 engines/zvision/singleValueContainer.cpp delete mode 100644 engines/zvision/singleValueContainer.h create mode 100644 engines/zvision/single_value_container.cpp create mode 100644 engines/zvision/single_value_container.h delete mode 100644 engines/zvision/zfsArchive.cpp delete mode 100644 engines/zvision/zfsArchive.h create mode 100644 engines/zvision/zfs_archive.cpp create mode 100644 engines/zvision/zfs_archive.h (limited to 'engines/zvision') diff --git a/engines/zvision/resultAction.cpp b/engines/zvision/resultAction.cpp deleted file mode 100644 index d14438d190..0000000000 --- a/engines/zvision/resultAction.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/resultAction.h" - -namespace ZVision { - -ActionAdd::ActionAdd(Common::String line) { - sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); -} - -bool ActionAdd::execute(ZVision *zVision) { - zVision->getScriptManager()->addToStateValue(_key, _value); - return true; -} - -} // End of namespace ZVision diff --git a/engines/zvision/resultAction.h b/engines/zvision/resultAction.h deleted file mode 100644 index 4fd589d7cc..0000000000 --- a/engines/zvision/resultAction.h +++ /dev/null @@ -1,92 +0,0 @@ -/* 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 ZVISION_RESULT_ACTION_H -#define ZVISION_RESULT_ACTION_H - -#include "common/scummsys.h" - -#include "zvision/zvision.h" - -namespace ZVision { - -class ResultAction { -public: - virtual ~ResultAction() {} - virtual bool execute(ZVision *zVision) = 0; -}; - - -// The different types of actions -// ADD, -// ANIM_PLAY, -// ANIM_PRELOAD, -// ANIM_UNLOAD, -// ATTENUATE, -// ASSIGN, -// CHANGE_LOCATION, -// CROSSFADE, -// DEBUG, -// DELAY_RENDER, -// DISABLE_CONTROL, -// DISABLE_VENUS, -// DISPLAY_MESSAGE, -// DISSOLVE, -// DISTORT, -// ENABLE_CONTROL, -// FLUSH_MOUSE_EVENTS, -// INVENTORY, -// KILL, -// MENU_BAR_ENABLE, -// MUSIC, -// PAN_TRACK, -// PLAY_PRELOAD, -// PREFERENCES, -// QUIT, -// RANDOM, -// REGION, -// RESTORE_GAME, -// ROTATE_TO, -// SAVE_GAME, -// SET_PARTIAL_SCREEN, -// SET_SCREEN, -// SET_VENUS, -// STOP, -// STREAM_VIDEO, -// SYNC_SOUND, -// TIMER, -// TTY_TEXT, -// UNIVERSE_MUSIC, - -class ActionAdd : public ResultAction { -public: - ActionAdd(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - byte _value; -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/result_action.cpp b/engines/zvision/result_action.cpp new file mode 100644 index 0000000000..d14438d190 --- /dev/null +++ b/engines/zvision/result_action.cpp @@ -0,0 +1,38 @@ +/* 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/scummsys.h" + +#include "zvision/resultAction.h" + +namespace ZVision { + +ActionAdd::ActionAdd(Common::String line) { + sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); +} + +bool ActionAdd::execute(ZVision *zVision) { + zVision->getScriptManager()->addToStateValue(_key, _value); + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/result_action.h b/engines/zvision/result_action.h new file mode 100644 index 0000000000..4fd589d7cc --- /dev/null +++ b/engines/zvision/result_action.h @@ -0,0 +1,92 @@ +/* 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 ZVISION_RESULT_ACTION_H +#define ZVISION_RESULT_ACTION_H + +#include "common/scummsys.h" + +#include "zvision/zvision.h" + +namespace ZVision { + +class ResultAction { +public: + virtual ~ResultAction() {} + virtual bool execute(ZVision *zVision) = 0; +}; + + +// The different types of actions +// ADD, +// ANIM_PLAY, +// ANIM_PRELOAD, +// ANIM_UNLOAD, +// ATTENUATE, +// ASSIGN, +// CHANGE_LOCATION, +// CROSSFADE, +// DEBUG, +// DELAY_RENDER, +// DISABLE_CONTROL, +// DISABLE_VENUS, +// DISPLAY_MESSAGE, +// DISSOLVE, +// DISTORT, +// ENABLE_CONTROL, +// FLUSH_MOUSE_EVENTS, +// INVENTORY, +// KILL, +// MENU_BAR_ENABLE, +// MUSIC, +// PAN_TRACK, +// PLAY_PRELOAD, +// PREFERENCES, +// QUIT, +// RANDOM, +// REGION, +// RESTORE_GAME, +// ROTATE_TO, +// SAVE_GAME, +// SET_PARTIAL_SCREEN, +// SET_SCREEN, +// SET_VENUS, +// STOP, +// STREAM_VIDEO, +// SYNC_SOUND, +// TIMER, +// TTY_TEXT, +// UNIVERSE_MUSIC, + +class ActionAdd : public ResultAction { +public: + ActionAdd(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + byte _value; +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/scrFileHandling.cpp b/engines/zvision/scrFileHandling.cpp deleted file mode 100644 index 61feb12b7e..0000000000 --- a/engines/zvision/scrFileHandling.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* 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/scummsys.h" - -#include - -#include "zvision/scriptManager.h" -#include "zvision/utility.h" -#include "zvision/puzzle.h" - -#include "common/textconsole.h" -#include "common/file.h" -#include "common/tokenizer.h" - -namespace ZVision { - -void ScriptManager::parseScrFile(Common::String fileName) { - Common::File file; - if (!file.open(fileName)) - return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another - - while(!file.eos()) { - Common::String line = file.readLine(); - if (file.err()) { - warning("Error parsing scr file: %s", fileName); - return; - } - - trimCommentsAndWhiteSpace(line); - if (line.empty()) - continue; - - if (line.matchString("puzzle:*", true)) { - Puzzle puzzle; - sscanf(line.c_str(),"puzzle:%u",&(puzzle.id)); - - parsePuzzle(puzzle, file); - _puzzles.push_back(puzzle); - } else if (line.matchString("control:*", true)) { - Control control; - char controlType[20]; - sscanf(line.c_str(),"control:%u %s",&(control.id), controlType); - - parseControl(control, file); - _controls.push_back(control); - } - } -} - -void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - if (line.matchString("criteria {", true)) - puzzle.criteriaList.push_back(parseCriteria(stream)); - else if (line.matchString("results {", true)) - parseResult(stream, puzzle.resultActions); - else if (line.matchString("flags {", true)) - puzzle.flags = parseFlags(stream); - } -} - -Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const { - Criteria criteria; - - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - // Split the string into tokens using ' ' as a delimiter - Common::StringTokenizer tokenizer(line); - Common::String token; - - // Parse the id out of the first token - token = tokenizer.nextToken(); - sscanf(token.c_str(), "[%u]", &(criteria.id)); - - // Parse the operator out of the second token - token = tokenizer.nextToken(); - if (token.c_str()[0] == '=') - criteria.criteriaOperator = EQUAL_TO; - else if (token.c_str()[0] == '!') - criteria.criteriaOperator = NOT_EQUAL_TO; - else if (token.c_str()[0] == '>') - criteria.criteriaOperator = GREATER_THAN; - else if (token.c_str()[0] == '<') - criteria.criteriaOperator = LESS_THAN; - - // First determine if the last token is an id or a value - // Then parse it into 'argument' - token = tokenizer.nextToken(); - if (token.contains('[')) { - sscanf(token.c_str(), "[%u]", &(criteria.argument)); - criteria.isArgumentAnId = true; - } else { - sscanf(token.c_str(), "%u", &(criteria.argument)); - criteria.isArgumentAnId = false; - } - - line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - } - - return criteria; -} - -void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - // Parse for the action type - if (line.matchString("*:add*", true)) { - actionList.push_back(ActionAdd(line)); - } else if (line.matchString("*:animplay*", true)) { - - - } else if (line.matchString("*:animpreload*", true)) { - - - } else if (line.matchString("*:animunload*", true)) { - - - } else if (line.matchString("*:attenuate*", true)) { - - - } else if (line.matchString("*:assign*", true)) { - - - } else if (line.matchString("*:change_location*", true)) { - - - } else if (line.matchString("*:crossfade*", true)) { - - - } else if (line.matchString("*:debug*", true)) { - - - } else if (line.matchString("*:delay_render*", true)) { - - - } else if (line.matchString("*:disable_control*", true)) { - - - } else if (line.matchString("*:disable_venus*", true)) { - - - } else if (line.matchString("*:display_message*", true)) { - - - } else if (line.matchString("*:dissolve*", true)) { - - - } else if (line.matchString("*:distort*", true)) { - - - } else if (line.matchString("*:enable_control*", true)) { - - - } else if (line.matchString("*:flush_mouse_events*", true)) { - - - } else if (line.matchString("*:inventory*", true)) { - - - } else if (line.matchString("*:kill*", true)) { - - - } else if (line.matchString("*:menu_bar_enable*", true)) { - - - } else if (line.matchString("*:music*", true)) { - - - } else if (line.matchString("*:pan_track*", true)) { - - - } else if (line.matchString("*:playpreload*", true)) { - - - } else if (line.matchString("*:preferences*", true)) { - - - } else if (line.matchString("*:quit*", true)) { - - - } else if (line.matchString("*:random*", true)) { - - - } else if (line.matchString("*:region*", true)) { - - - } else if (line.matchString("*:restore_game*", true)) { - - - } else if (line.matchString("*:rotate_to*", true)) { - - - } else if (line.matchString("*:save_game*", true)) { - - - } else if (line.matchString("*:set_partial_screen*", true)) { - - - } else if (line.matchString("*:set_screen*", true)) { - - - } else if (line.matchString("*:set_venus*", true)) { - - - } else if (line.matchString("*:stop*", true)) { - - - } else if (line.matchString("*:streamvideo*", true)) { - - - } else if (line.matchString("*:syncsound*", true)) { - - - } else if (line.matchString("*:timer*", true)) { - - - } else if (line.matchString("*:ttytext*", true)) { - - - } else if (line.matchString("*:universe_music*", true)) { - - - } else { - warning("Unhandled result action type: ", line); - } - - line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - } - - return; -} - -byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { - byte flags; - - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); - - while (!line.contains('}')) { - if (line.matchString("ONCE_PER_INST", true)) { - flags |= ONCE_PER_INST; - } else if (line.matchString("DO_ME_NOW", true)) { - flags |= DO_ME_NOW; - } else if (line.matchString("DISABLED", true)) { - flags |= DISABLED; - } - } - - return flags; -} - -void ScriptManager::parseControl(Control &control, Common::SeekableReadStream &stream) { - -} - -} // End of namespace ZVision diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp new file mode 100644 index 0000000000..61feb12b7e --- /dev/null +++ b/engines/zvision/scr_file_handling.cpp @@ -0,0 +1,287 @@ +/* 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/scummsys.h" + +#include + +#include "zvision/scriptManager.h" +#include "zvision/utility.h" +#include "zvision/puzzle.h" + +#include "common/textconsole.h" +#include "common/file.h" +#include "common/tokenizer.h" + +namespace ZVision { + +void ScriptManager::parseScrFile(Common::String fileName) { + Common::File file; + if (!file.open(fileName)) + return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another + + while(!file.eos()) { + Common::String line = file.readLine(); + if (file.err()) { + warning("Error parsing scr file: %s", fileName); + return; + } + + trimCommentsAndWhiteSpace(line); + if (line.empty()) + continue; + + if (line.matchString("puzzle:*", true)) { + Puzzle puzzle; + sscanf(line.c_str(),"puzzle:%u",&(puzzle.id)); + + parsePuzzle(puzzle, file); + _puzzles.push_back(puzzle); + } else if (line.matchString("control:*", true)) { + Control control; + char controlType[20]; + sscanf(line.c_str(),"control:%u %s",&(control.id), controlType); + + parseControl(control, file); + _controls.push_back(control); + } + } +} + +void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + if (line.matchString("criteria {", true)) + puzzle.criteriaList.push_back(parseCriteria(stream)); + else if (line.matchString("results {", true)) + parseResult(stream, puzzle.resultActions); + else if (line.matchString("flags {", true)) + puzzle.flags = parseFlags(stream); + } +} + +Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const { + Criteria criteria; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + // Split the string into tokens using ' ' as a delimiter + Common::StringTokenizer tokenizer(line); + Common::String token; + + // Parse the id out of the first token + token = tokenizer.nextToken(); + sscanf(token.c_str(), "[%u]", &(criteria.id)); + + // Parse the operator out of the second token + token = tokenizer.nextToken(); + if (token.c_str()[0] == '=') + criteria.criteriaOperator = EQUAL_TO; + else if (token.c_str()[0] == '!') + criteria.criteriaOperator = NOT_EQUAL_TO; + else if (token.c_str()[0] == '>') + criteria.criteriaOperator = GREATER_THAN; + else if (token.c_str()[0] == '<') + criteria.criteriaOperator = LESS_THAN; + + // First determine if the last token is an id or a value + // Then parse it into 'argument' + token = tokenizer.nextToken(); + if (token.contains('[')) { + sscanf(token.c_str(), "[%u]", &(criteria.argument)); + criteria.isArgumentAnId = true; + } else { + sscanf(token.c_str(), "%u", &(criteria.argument)); + criteria.isArgumentAnId = false; + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + } + + return criteria; +} + +void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + // Parse for the action type + if (line.matchString("*:add*", true)) { + actionList.push_back(ActionAdd(line)); + } else if (line.matchString("*:animplay*", true)) { + + + } else if (line.matchString("*:animpreload*", true)) { + + + } else if (line.matchString("*:animunload*", true)) { + + + } else if (line.matchString("*:attenuate*", true)) { + + + } else if (line.matchString("*:assign*", true)) { + + + } else if (line.matchString("*:change_location*", true)) { + + + } else if (line.matchString("*:crossfade*", true)) { + + + } else if (line.matchString("*:debug*", true)) { + + + } else if (line.matchString("*:delay_render*", true)) { + + + } else if (line.matchString("*:disable_control*", true)) { + + + } else if (line.matchString("*:disable_venus*", true)) { + + + } else if (line.matchString("*:display_message*", true)) { + + + } else if (line.matchString("*:dissolve*", true)) { + + + } else if (line.matchString("*:distort*", true)) { + + + } else if (line.matchString("*:enable_control*", true)) { + + + } else if (line.matchString("*:flush_mouse_events*", true)) { + + + } else if (line.matchString("*:inventory*", true)) { + + + } else if (line.matchString("*:kill*", true)) { + + + } else if (line.matchString("*:menu_bar_enable*", true)) { + + + } else if (line.matchString("*:music*", true)) { + + + } else if (line.matchString("*:pan_track*", true)) { + + + } else if (line.matchString("*:playpreload*", true)) { + + + } else if (line.matchString("*:preferences*", true)) { + + + } else if (line.matchString("*:quit*", true)) { + + + } else if (line.matchString("*:random*", true)) { + + + } else if (line.matchString("*:region*", true)) { + + + } else if (line.matchString("*:restore_game*", true)) { + + + } else if (line.matchString("*:rotate_to*", true)) { + + + } else if (line.matchString("*:save_game*", true)) { + + + } else if (line.matchString("*:set_partial_screen*", true)) { + + + } else if (line.matchString("*:set_screen*", true)) { + + + } else if (line.matchString("*:set_venus*", true)) { + + + } else if (line.matchString("*:stop*", true)) { + + + } else if (line.matchString("*:streamvideo*", true)) { + + + } else if (line.matchString("*:syncsound*", true)) { + + + } else if (line.matchString("*:timer*", true)) { + + + } else if (line.matchString("*:ttytext*", true)) { + + + } else if (line.matchString("*:universe_music*", true)) { + + + } else { + warning("Unhandled result action type: ", line); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + } + + return; +} + +byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { + byte flags; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(line); + + while (!line.contains('}')) { + if (line.matchString("ONCE_PER_INST", true)) { + flags |= ONCE_PER_INST; + } else if (line.matchString("DO_ME_NOW", true)) { + flags |= DO_ME_NOW; + } else if (line.matchString("DISABLED", true)) { + flags |= DISABLED; + } + } + + return flags; +} + +void ScriptManager::parseControl(Control &control, Common::SeekableReadStream &stream) { + +} + +} // End of namespace ZVision diff --git a/engines/zvision/scriptManager.cpp b/engines/zvision/scriptManager.cpp deleted file mode 100644 index 5317bf60f1..0000000000 --- a/engines/zvision/scriptManager.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/scriptManager.h" - -namespace ZVision { - -// TODO: Actually do something in the initialize or remove it -void ScriptManager::initialize() { - -} - -byte ScriptManager::getStateValue(uint32 key) { - return _globalState[key]; -} - -void ScriptManager::setStateValue(uint32 key, byte value) { - _globalState[key] = value; -} - -void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) { - _globalState[key] += valueToAdd; -} - -} // End of namespace ZVision diff --git a/engines/zvision/scriptManager.h b/engines/zvision/scriptManager.h deleted file mode 100644 index 563a010de5..0000000000 --- a/engines/zvision/scriptManager.h +++ /dev/null @@ -1,107 +0,0 @@ -/* 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 ZVISION_SCRIPT_MANAGER_H -#define ZVISION_SCRIPT_MANAGER_H - -#include "common/str.h" -#include "common/stream.h" -#include "common/hashmap.h" - -#include "zvision/puzzle.h" -#include "zvision/control.h" -#include "zvision/singleValueContainer.h" - -namespace ZVision { - -class ScriptManager { -private: - /** Holds the global state variables. Optimize for fast random access */ - Common::HashMap _globalState; - /** Holds the currently active puzzles. Optimize for fast iteration */ - Common::List _puzzles; - /** Holds the currently active controls. Optimize for fast iteration */ - Common::List _controls; - -public: - - void initialize(); - byte getStateValue(uint32 key); - void setStateValue(uint32 key, byte value); - void addToStateValue(uint32 key, byte valueToAdd); - -private: - /** - * Parses a script file into triggers and events - * - * @param fileName Name of the .scr file - */ - void parseScrFile(Common::String fileName); - - /** - * Parses the stream into a Puzzle object - * Helper method for parseScrFile. - * - * @param puzzle The object to store what is parsed - * @param stream Scr file stream - */ - void parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream); - - /** - * Parses the stream into a Criteria object - * Helper method for parsePuzzle. - * - * @param stream Scr file stream - * @return Created Criteria object - */ - Criteria parseCriteria(Common::SeekableReadStream &stream) const; - - /** - * Parses the stream into a Results object - * Helper method for parsePuzzle. - * - * @param stream Scr file stream - * @return Created Results object - */ - void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; - - /** - * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum - * - * @param stream Scr file stream - * @return Bitwise or of all the flags set within the puzzle - */ - byte parseFlags(Common::SeekableReadStream &stream) const; - - /** - * Helper method for parseScrFile. Parses the stream into a Control object - * - * @param control The object to store what is parsed - * @param stream Scr file stream - */ - void parseControl(Control &control, Common::SeekableReadStream &stream); -}; - - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp new file mode 100644 index 0000000000..5317bf60f1 --- /dev/null +++ b/engines/zvision/script_manager.cpp @@ -0,0 +1,46 @@ +/* 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/scummsys.h" + +#include "zvision/scriptManager.h" + +namespace ZVision { + +// TODO: Actually do something in the initialize or remove it +void ScriptManager::initialize() { + +} + +byte ScriptManager::getStateValue(uint32 key) { + return _globalState[key]; +} + +void ScriptManager::setStateValue(uint32 key, byte value) { + _globalState[key] = value; +} + +void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) { + _globalState[key] += valueToAdd; +} + +} // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h new file mode 100644 index 0000000000..563a010de5 --- /dev/null +++ b/engines/zvision/script_manager.h @@ -0,0 +1,107 @@ +/* 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 ZVISION_SCRIPT_MANAGER_H +#define ZVISION_SCRIPT_MANAGER_H + +#include "common/str.h" +#include "common/stream.h" +#include "common/hashmap.h" + +#include "zvision/puzzle.h" +#include "zvision/control.h" +#include "zvision/singleValueContainer.h" + +namespace ZVision { + +class ScriptManager { +private: + /** Holds the global state variables. Optimize for fast random access */ + Common::HashMap _globalState; + /** Holds the currently active puzzles. Optimize for fast iteration */ + Common::List _puzzles; + /** Holds the currently active controls. Optimize for fast iteration */ + Common::List _controls; + +public: + + void initialize(); + byte getStateValue(uint32 key); + void setStateValue(uint32 key, byte value); + void addToStateValue(uint32 key, byte valueToAdd); + +private: + /** + * Parses a script file into triggers and events + * + * @param fileName Name of the .scr file + */ + void parseScrFile(Common::String fileName); + + /** + * Parses the stream into a Puzzle object + * Helper method for parseScrFile. + * + * @param puzzle The object to store what is parsed + * @param stream Scr file stream + */ + void parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream); + + /** + * Parses the stream into a Criteria object + * Helper method for parsePuzzle. + * + * @param stream Scr file stream + * @return Created Criteria object + */ + Criteria parseCriteria(Common::SeekableReadStream &stream) const; + + /** + * Parses the stream into a Results object + * Helper method for parsePuzzle. + * + * @param stream Scr file stream + * @return Created Results object + */ + void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; + + /** + * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum + * + * @param stream Scr file stream + * @return Bitwise or of all the flags set within the puzzle + */ + byte parseFlags(Common::SeekableReadStream &stream) const; + + /** + * Helper method for parseScrFile. Parses the stream into a Control object + * + * @param control The object to store what is parsed + * @param stream Scr file stream + */ + void parseControl(Control &control, Common::SeekableReadStream &stream); +}; + + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/singleValueContainer.cpp b/engines/zvision/singleValueContainer.cpp deleted file mode 100644 index bd91c44daf..0000000000 --- a/engines/zvision/singleValueContainer.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* 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/scummsys.h" -#include "common/textconsole.h" - -#include "zvision/singleValueContainer.h" - -namespace ZVision { - -SingleValueContainer::SingleValueContainer(ValueType type) : _objectType(type) { } - -SingleValueContainer::SingleValueContainer(bool value) : _objectType(BOOL) { - _value.boolVal = value; -} - -SingleValueContainer::SingleValueContainer(byte value) : _objectType(BYTE) { - _value.byteVal = value; -} - -SingleValueContainer::SingleValueContainer(int16 value) : _objectType(INT16) { - _value.int16Val = value; -} - -SingleValueContainer::SingleValueContainer(uint16 value) : _objectType(UINT16) { - _value.uint16Val = value; -} - -SingleValueContainer::SingleValueContainer(int32 value) : _objectType(INT32) { - _value.int32Val = value; -} - -SingleValueContainer::SingleValueContainer(uint32 value) : _objectType(UINT32) { - _value.uint32Val = value; -} - -SingleValueContainer::SingleValueContainer(float value) : _objectType(FLOAT) { - _value.floatVal = value; -} - -SingleValueContainer::SingleValueContainer(double value) : _objectType(DOUBLE) { - _value.doubleVal = value; -} - -SingleValueContainer::SingleValueContainer(Common::String value) : _objectType(BYTE) { - _value.stringVal = new char[value.size() + 1]; - memcpy(_value.stringVal, value.c_str(), value.size() + 1); -} - -SingleValueContainer::SingleValueContainer(const SingleValueContainer &other) { - _objectType = other._objectType; - - switch (_objectType) { - case BOOL: - _value.boolVal = other._value.boolVal; - break; - case BYTE: - _value.byteVal = other._value.byteVal; - break; - case INT16: - _value.int16Val = other._value.int16Val; - break; - case UINT16: - _value.uint16Val = other._value.uint16Val; - break; - case INT32: - _value.int32Val = other._value.int32Val; - break; - case UINT32: - _value.uint32Val = other._value.uint32Val; - break; - case FLOAT: - _value.floatVal = other._value.floatVal; - break; - case DOUBLE: - _value.doubleVal = other._value.doubleVal; - break; - case STRING: - uint32 length = strlen(other._value.stringVal); - _value.stringVal = new char[length + 1]; - memcpy(_value.stringVal, other._value.stringVal, length + 1); - break; - } -} - -SingleValueContainer::~SingleValueContainer() { - deleteCharPointer(); -} - -void SingleValueContainer::deleteCharPointer() { - if (_objectType == STRING) - delete[] _value.stringVal; -} - - -SingleValueContainer &SingleValueContainer::operator=(const bool &rhs) { - if (_objectType == BOOL) { - _value.boolVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = BOOL; - _value.boolVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const byte &rhs) { - if (_objectType == BYTE) { - _value.byteVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = BYTE; - _value.byteVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const int16 &rhs) { - if (_objectType == INT16) { - _value.int16Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = INT16; - _value.int16Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const uint16 &rhs) { - if (_objectType == UINT16) { - _value.uint16Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = UINT16; - _value.uint16Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const int32 &rhs) { - if (_objectType == INT32) { - _value.int32Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = INT32; - _value.int32Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const uint32 &rhs) { - if (_objectType == UINT32) { - _value.uint32Val = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = UINT32; - _value.uint32Val = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const float &rhs) { - if (_objectType == FLOAT) { - _value.floatVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = FLOAT; - _value.floatVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const double &rhs) { - if (_objectType == DOUBLE) { - _value.doubleVal = rhs; - return *this; - } - - deleteCharPointer(); - _objectType = DOUBLE; - _value.doubleVal = rhs; - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const Common::String &rhs) { - if (_objectType != STRING) { - _objectType = STRING; - _value.stringVal = new char[rhs.size() + 1]; - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - - return *this; - } - - uint32 length = strlen(_value.stringVal); - if (length <= rhs.size() + 1) { - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - } else { - delete[] _value.stringVal; - _value.stringVal = new char[rhs.size() + 1]; - memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); - } - - return *this; -} - -SingleValueContainer &SingleValueContainer::operator=(const SingleValueContainer &rhs) { - switch (_objectType) { - case BOOL: - return operator=(rhs._value.boolVal); - case BYTE: - return operator=(rhs._value.byteVal); - case INT16: - return operator=(rhs._value.int16Val); - case UINT16: - return operator=(rhs._value.uint16Val); - case INT32: - return operator=(rhs._value.int32Val); - case UINT32: - return operator=(rhs._value.uint32Val); - case FLOAT: - return operator=(rhs._value.floatVal); - case DOUBLE: - return operator=(rhs._value.doubleVal); - case STRING: - uint32 length = strlen(rhs._value.stringVal); - - _value.stringVal = new char[length + 1]; - memcpy(_value.stringVal, rhs._value.stringVal, length + 1); - - return *this; - } - - return *this; -} - - -bool SingleValueContainer::getBoolValue(bool *returnValue) const { - if (_objectType != BOOL) { - warning("'Object' is not storing a bool."); - return false; - } - - *returnValue = _value.boolVal; - return true; -} - -bool SingleValueContainer::getByteValue(byte *returnValue) const { - if (_objectType != BYTE) - warning("'Object' is not storing a byte."); - - *returnValue = _value.byteVal; - return true; -} - -bool SingleValueContainer::getInt16Value(int16 *returnValue) const { - if (_objectType != INT16) - warning("'Object' is not storing an int16."); - - *returnValue = _value.int16Val; - return true; -} - -bool SingleValueContainer::getUInt16Value(uint16 *returnValue) const { - if (_objectType != UINT16) - warning("'Object' is not storing a uint16."); - - *returnValue = _value.uint16Val; - return true; -} - -bool SingleValueContainer::getInt32Value(int32 *returnValue) const { - if (_objectType != INT32) - warning("'Object' is not storing an int32."); - - *returnValue = _value.int32Val; - return true; -} - -bool SingleValueContainer::getUInt32Value(uint32 *returnValue) const { - if (_objectType != UINT32) - warning("'Object' is not storing a uint32."); - - *returnValue = _value.uint32Val; - return true; -} - -bool SingleValueContainer::getFloatValue(float *returnValue) const { - if (_objectType != FLOAT) - warning("'Object' is not storing a float."); - - *returnValue = _value.floatVal; - return true; -} - -bool SingleValueContainer::getDoubleValue(double *returnValue) const { - if (_objectType != DOUBLE) - warning("'Object' is not storing a double."); - - *returnValue = _value.doubleVal; - return true; -} - -bool SingleValueContainer::getStringValue(Common::String *returnValue) const { - if (_objectType != STRING) - warning("'Object' is not storing a Common::String."); - - *returnValue = _value.stringVal; - return true; -} - -} // End of namespace ZVision diff --git a/engines/zvision/singleValueContainer.h b/engines/zvision/singleValueContainer.h deleted file mode 100644 index 49c7267f77..0000000000 --- a/engines/zvision/singleValueContainer.h +++ /dev/null @@ -1,181 +0,0 @@ -/* 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 ZVISION_OBJECT_H -#define ZVISION_OBJECT_H - -#include "common/str.h" - -namespace ZVision { - -/** - * A generic single value storage class. It is useful for storing different - * value types in a single List, Hashmap, etc. - */ -class SingleValueContainer { -public: - enum ValueType { - BOOL, - BYTE, - INT16, - UINT16, - INT32, - UINT32, - FLOAT, - DOUBLE, - STRING, - }; - - // Constructors - explicit SingleValueContainer(ValueType type); - explicit SingleValueContainer(bool value); - explicit SingleValueContainer(byte value); - explicit SingleValueContainer(int16 value); - explicit SingleValueContainer(uint16 value); - explicit SingleValueContainer(int32 value); - explicit SingleValueContainer(uint32 value); - explicit SingleValueContainer(float value); - explicit SingleValueContainer(double value); - explicit SingleValueContainer(Common::String value); - - // Copy constructor - explicit SingleValueContainer(const SingleValueContainer& other); - - // Destructor - ~SingleValueContainer(); - -private: - ValueType _objectType; - - union { - bool boolVal; - byte byteVal; - int16 int16Val; - uint16 uint16Val; - int32 int32Val; - uint32 uint32Val; - float floatVal; - double doubleVal; - char *stringVal; - } _value; - -public: - SingleValueContainer &operator=(const bool &rhs); - SingleValueContainer &operator=(const byte &rhs); - SingleValueContainer &operator=(const int16 &rhs); - SingleValueContainer &operator=(const uint16 &rhs); - SingleValueContainer &operator=(const int32 &rhs); - SingleValueContainer &operator=(const uint32 &rhs); - SingleValueContainer &operator=(const float &rhs); - SingleValueContainer &operator=(const double &rhs); - SingleValueContainer &operator=(const Common::String &rhs); - - SingleValueContainer& operator=(const SingleValueContainer &rhs); - - /** - * Retrieve a bool from the container. If the container is not storing a - * bool, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getBoolValue(bool *returnValue) const; - /** - * Retrieve a byte from the container. If the container is not storing a - * byte, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getByteValue(byte *returnValue) const; - /** - * Retrieve an int16 from the container. If the container is not storing an - * int16, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getInt16Value(int16 *returnValue) const; - /** - * Retrieve a uint16 from the container. If the container is not storing a - * uint16, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getUInt16Value(uint16 *returnValue) const; - /** - * Retrieve an int32 from the container. If the container is not storing an - * int32, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getInt32Value(int32 *returnValue) const; - /** - * Retrieve a uint32 from the container. If the container is not storing a - * uint32, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getUInt32Value(uint32 *returnValue) const; - /** - * Retrieve a float from the container. If the container is not storing a - * float, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getFloatValue(float *returnValue) const; - /** - * Retrieve a double from the container. If the container is not storing a - * double, this will return false and display a warning(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getDoubleValue(double *returnValue) const; - /** - * Retrieve a String from the container. If the container is not storing a - * string, this will return false and display a warning(). - * - * Caution: Strings are internally stored as char[]. getStringValue uses - * Common::String::operator=(char *) to do the assigment, which uses both - * strlen() AND memmove(). - * - * @param returnValue Pointer to where you want the value stored - * @return Value indicating whether the value assignment was successful - */ - bool getStringValue(Common::String *returnValue) const; - -private: - /** - * Helper method for destruction and assignment. It checks to see - * if the char pointer is being used, and if so calls delete on it - */ - void deleteCharPointer(); -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/single_value_container.cpp b/engines/zvision/single_value_container.cpp new file mode 100644 index 0000000000..bd91c44daf --- /dev/null +++ b/engines/zvision/single_value_container.cpp @@ -0,0 +1,345 @@ +/* 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/scummsys.h" +#include "common/textconsole.h" + +#include "zvision/singleValueContainer.h" + +namespace ZVision { + +SingleValueContainer::SingleValueContainer(ValueType type) : _objectType(type) { } + +SingleValueContainer::SingleValueContainer(bool value) : _objectType(BOOL) { + _value.boolVal = value; +} + +SingleValueContainer::SingleValueContainer(byte value) : _objectType(BYTE) { + _value.byteVal = value; +} + +SingleValueContainer::SingleValueContainer(int16 value) : _objectType(INT16) { + _value.int16Val = value; +} + +SingleValueContainer::SingleValueContainer(uint16 value) : _objectType(UINT16) { + _value.uint16Val = value; +} + +SingleValueContainer::SingleValueContainer(int32 value) : _objectType(INT32) { + _value.int32Val = value; +} + +SingleValueContainer::SingleValueContainer(uint32 value) : _objectType(UINT32) { + _value.uint32Val = value; +} + +SingleValueContainer::SingleValueContainer(float value) : _objectType(FLOAT) { + _value.floatVal = value; +} + +SingleValueContainer::SingleValueContainer(double value) : _objectType(DOUBLE) { + _value.doubleVal = value; +} + +SingleValueContainer::SingleValueContainer(Common::String value) : _objectType(BYTE) { + _value.stringVal = new char[value.size() + 1]; + memcpy(_value.stringVal, value.c_str(), value.size() + 1); +} + +SingleValueContainer::SingleValueContainer(const SingleValueContainer &other) { + _objectType = other._objectType; + + switch (_objectType) { + case BOOL: + _value.boolVal = other._value.boolVal; + break; + case BYTE: + _value.byteVal = other._value.byteVal; + break; + case INT16: + _value.int16Val = other._value.int16Val; + break; + case UINT16: + _value.uint16Val = other._value.uint16Val; + break; + case INT32: + _value.int32Val = other._value.int32Val; + break; + case UINT32: + _value.uint32Val = other._value.uint32Val; + break; + case FLOAT: + _value.floatVal = other._value.floatVal; + break; + case DOUBLE: + _value.doubleVal = other._value.doubleVal; + break; + case STRING: + uint32 length = strlen(other._value.stringVal); + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, other._value.stringVal, length + 1); + break; + } +} + +SingleValueContainer::~SingleValueContainer() { + deleteCharPointer(); +} + +void SingleValueContainer::deleteCharPointer() { + if (_objectType == STRING) + delete[] _value.stringVal; +} + + +SingleValueContainer &SingleValueContainer::operator=(const bool &rhs) { + if (_objectType == BOOL) { + _value.boolVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = BOOL; + _value.boolVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const byte &rhs) { + if (_objectType == BYTE) { + _value.byteVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = BYTE; + _value.byteVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const int16 &rhs) { + if (_objectType == INT16) { + _value.int16Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = INT16; + _value.int16Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const uint16 &rhs) { + if (_objectType == UINT16) { + _value.uint16Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = UINT16; + _value.uint16Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const int32 &rhs) { + if (_objectType == INT32) { + _value.int32Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = INT32; + _value.int32Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const uint32 &rhs) { + if (_objectType == UINT32) { + _value.uint32Val = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = UINT32; + _value.uint32Val = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const float &rhs) { + if (_objectType == FLOAT) { + _value.floatVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = FLOAT; + _value.floatVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const double &rhs) { + if (_objectType == DOUBLE) { + _value.doubleVal = rhs; + return *this; + } + + deleteCharPointer(); + _objectType = DOUBLE; + _value.doubleVal = rhs; + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const Common::String &rhs) { + if (_objectType != STRING) { + _objectType = STRING; + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + + return *this; + } + + uint32 length = strlen(_value.stringVal); + if (length <= rhs.size() + 1) { + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + } else { + delete[] _value.stringVal; + _value.stringVal = new char[rhs.size() + 1]; + memcpy(_value.stringVal, rhs.c_str(), rhs.size() + 1); + } + + return *this; +} + +SingleValueContainer &SingleValueContainer::operator=(const SingleValueContainer &rhs) { + switch (_objectType) { + case BOOL: + return operator=(rhs._value.boolVal); + case BYTE: + return operator=(rhs._value.byteVal); + case INT16: + return operator=(rhs._value.int16Val); + case UINT16: + return operator=(rhs._value.uint16Val); + case INT32: + return operator=(rhs._value.int32Val); + case UINT32: + return operator=(rhs._value.uint32Val); + case FLOAT: + return operator=(rhs._value.floatVal); + case DOUBLE: + return operator=(rhs._value.doubleVal); + case STRING: + uint32 length = strlen(rhs._value.stringVal); + + _value.stringVal = new char[length + 1]; + memcpy(_value.stringVal, rhs._value.stringVal, length + 1); + + return *this; + } + + return *this; +} + + +bool SingleValueContainer::getBoolValue(bool *returnValue) const { + if (_objectType != BOOL) { + warning("'Object' is not storing a bool."); + return false; + } + + *returnValue = _value.boolVal; + return true; +} + +bool SingleValueContainer::getByteValue(byte *returnValue) const { + if (_objectType != BYTE) + warning("'Object' is not storing a byte."); + + *returnValue = _value.byteVal; + return true; +} + +bool SingleValueContainer::getInt16Value(int16 *returnValue) const { + if (_objectType != INT16) + warning("'Object' is not storing an int16."); + + *returnValue = _value.int16Val; + return true; +} + +bool SingleValueContainer::getUInt16Value(uint16 *returnValue) const { + if (_objectType != UINT16) + warning("'Object' is not storing a uint16."); + + *returnValue = _value.uint16Val; + return true; +} + +bool SingleValueContainer::getInt32Value(int32 *returnValue) const { + if (_objectType != INT32) + warning("'Object' is not storing an int32."); + + *returnValue = _value.int32Val; + return true; +} + +bool SingleValueContainer::getUInt32Value(uint32 *returnValue) const { + if (_objectType != UINT32) + warning("'Object' is not storing a uint32."); + + *returnValue = _value.uint32Val; + return true; +} + +bool SingleValueContainer::getFloatValue(float *returnValue) const { + if (_objectType != FLOAT) + warning("'Object' is not storing a float."); + + *returnValue = _value.floatVal; + return true; +} + +bool SingleValueContainer::getDoubleValue(double *returnValue) const { + if (_objectType != DOUBLE) + warning("'Object' is not storing a double."); + + *returnValue = _value.doubleVal; + return true; +} + +bool SingleValueContainer::getStringValue(Common::String *returnValue) const { + if (_objectType != STRING) + warning("'Object' is not storing a Common::String."); + + *returnValue = _value.stringVal; + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/single_value_container.h b/engines/zvision/single_value_container.h new file mode 100644 index 0000000000..49c7267f77 --- /dev/null +++ b/engines/zvision/single_value_container.h @@ -0,0 +1,181 @@ +/* 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 ZVISION_OBJECT_H +#define ZVISION_OBJECT_H + +#include "common/str.h" + +namespace ZVision { + +/** + * A generic single value storage class. It is useful for storing different + * value types in a single List, Hashmap, etc. + */ +class SingleValueContainer { +public: + enum ValueType { + BOOL, + BYTE, + INT16, + UINT16, + INT32, + UINT32, + FLOAT, + DOUBLE, + STRING, + }; + + // Constructors + explicit SingleValueContainer(ValueType type); + explicit SingleValueContainer(bool value); + explicit SingleValueContainer(byte value); + explicit SingleValueContainer(int16 value); + explicit SingleValueContainer(uint16 value); + explicit SingleValueContainer(int32 value); + explicit SingleValueContainer(uint32 value); + explicit SingleValueContainer(float value); + explicit SingleValueContainer(double value); + explicit SingleValueContainer(Common::String value); + + // Copy constructor + explicit SingleValueContainer(const SingleValueContainer& other); + + // Destructor + ~SingleValueContainer(); + +private: + ValueType _objectType; + + union { + bool boolVal; + byte byteVal; + int16 int16Val; + uint16 uint16Val; + int32 int32Val; + uint32 uint32Val; + float floatVal; + double doubleVal; + char *stringVal; + } _value; + +public: + SingleValueContainer &operator=(const bool &rhs); + SingleValueContainer &operator=(const byte &rhs); + SingleValueContainer &operator=(const int16 &rhs); + SingleValueContainer &operator=(const uint16 &rhs); + SingleValueContainer &operator=(const int32 &rhs); + SingleValueContainer &operator=(const uint32 &rhs); + SingleValueContainer &operator=(const float &rhs); + SingleValueContainer &operator=(const double &rhs); + SingleValueContainer &operator=(const Common::String &rhs); + + SingleValueContainer& operator=(const SingleValueContainer &rhs); + + /** + * Retrieve a bool from the container. If the container is not storing a + * bool, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getBoolValue(bool *returnValue) const; + /** + * Retrieve a byte from the container. If the container is not storing a + * byte, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getByteValue(byte *returnValue) const; + /** + * Retrieve an int16 from the container. If the container is not storing an + * int16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getInt16Value(int16 *returnValue) const; + /** + * Retrieve a uint16 from the container. If the container is not storing a + * uint16, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getUInt16Value(uint16 *returnValue) const; + /** + * Retrieve an int32 from the container. If the container is not storing an + * int32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getInt32Value(int32 *returnValue) const; + /** + * Retrieve a uint32 from the container. If the container is not storing a + * uint32, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getUInt32Value(uint32 *returnValue) const; + /** + * Retrieve a float from the container. If the container is not storing a + * float, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getFloatValue(float *returnValue) const; + /** + * Retrieve a double from the container. If the container is not storing a + * double, this will return false and display a warning(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getDoubleValue(double *returnValue) const; + /** + * Retrieve a String from the container. If the container is not storing a + * string, this will return false and display a warning(). + * + * Caution: Strings are internally stored as char[]. getStringValue uses + * Common::String::operator=(char *) to do the assigment, which uses both + * strlen() AND memmove(). + * + * @param returnValue Pointer to where you want the value stored + * @return Value indicating whether the value assignment was successful + */ + bool getStringValue(Common::String *returnValue) const; + +private: + /** + * Helper method for destruction and assignment. It checks to see + * if the char pointer is being used, and if so calls delete on it + */ + void deleteCharPointer(); +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/zfsArchive.cpp b/engines/zvision/zfsArchive.cpp deleted file mode 100644 index e65d0df14e..0000000000 --- a/engines/zvision/zfsArchive.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/zfsArchive.h" -#include "common/hashmap.h" -#include "common/memstream.h" -#include "common/debug.h" - -namespace ZVision { - -ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { - Common::File zfsFile; - - if (!zfsFile.open(_fileName)) { - warning("ZFSArchive::ZFSArchive(): Could not find the archive file"); - return; - } - - readHeaders(&zfsFile); - - debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); -} - -ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) { - readHeaders(stream); - - debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); -} - -ZfsArchive::~ZfsArchive() { - debug(0, "ZfsArchive Destructor Called"); - ZfsEntryHeaderMap::iterator it = _entryHeaders.begin(); - for ( ; it != _entryHeaders.end(); ++it) { - delete it->_value; - } -} - -void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { - // Don't do a straight struct cast since we can't guarantee endianness - _header.magic = stream->readUint32LE(); - _header.unknown1 = stream->readUint32LE(); - _header.maxNameLength = stream->readUint32LE(); - _header.filesPerBlock = stream->readUint32LE(); - _header.fileCount = stream->readUint32LE(); - _header.xorKey[0] = stream->readByte(); - _header.xorKey[1] = stream->readByte(); - _header.xorKey[2] = stream->readByte(); - _header.xorKey[3] = stream->readByte(); - _header.fileSectionOffset = stream->readUint32LE(); - - uint32 nextOffset; - - do { - // Read the offset to the next block - nextOffset = stream->readUint32LE(); - - // Read in each entry header - for (int i = 0; i < _header.filesPerBlock; i++) { - ZfsEntryHeader entryHeader; - - entryHeader.name = readEntryName(stream); - entryHeader.offset = stream->readUint32LE(); - entryHeader.id = stream->readUint32LE(); - entryHeader.size = stream->readUint32LE(); - entryHeader.time = stream->readUint32LE(); - entryHeader.unknown = stream->readUint32LE(); - - if (entryHeader.size != 0) - _entryHeaders[entryHeader.name] = new ZfsEntryHeader(entryHeader); - } - - // Seek to the next block of headers - stream->seek(nextOffset); - } while (nextOffset != 0); -} - -Common::String ZfsArchive::readEntryName(Common::SeekableReadStream *stream) const { - // Entry Names are at most 16 bytes and are null padded - char buffer[16]; - stream->read(buffer, 16); - - return Common::String(buffer); -} - -bool ZfsArchive::hasFile(const Common::String &name) const { - return _entryHeaders.contains(name); -} - -int ZfsArchive::listMembers(Common::ArchiveMemberList &list) const { - int matches = 0; - - for (ZfsEntryHeaderMap::const_iterator it = _entryHeaders.begin(); it != _entryHeaders.end(); ++it) { - list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->name, this))); - matches++; - } - - return matches; -} - -const Common::ArchiveMemberPtr ZfsArchive::getMember(const Common::String &name) const { - if (!_entryHeaders.contains(name)) - return Common::ArchiveMemberPtr(); - - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); -} - -Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::String &name) const { - if (!_entryHeaders.contains(name)) { - return 0; - } - - ZfsEntryHeader *entryHeader = _entryHeaders[name]; - - Common::File zfsArchive; - zfsArchive.open(_fileName); - zfsArchive.seek(entryHeader->offset); - - byte* buffer = new byte[entryHeader->size]; - zfsArchive.read(buffer, entryHeader->size); - // Decrypt the data in place - if (_header.xorKey != 0) - unXor(buffer, entryHeader->size, _header.xorKey); - - return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES); -} - -void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const { - for (uint32 i = 0; i < length; i++) - buffer[i] ^= xorKey[i % 4]; -} - -} // End of namespace ZVision - - diff --git a/engines/zvision/zfsArchive.h b/engines/zvision/zfsArchive.h deleted file mode 100644 index ccdf192571..0000000000 --- a/engines/zvision/zfsArchive.h +++ /dev/null @@ -1,121 +0,0 @@ -/* 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 ZVISION_ZFS_ARCHIVE_H -#define ZVISION_ZFS_ARCHIVE_H - -#include "common/archive.h" -#include "common/file.h" -#include "common/fs.h" - -namespace ZVision { - -struct ZfsHeader { - uint32 magic; - uint32 unknown1; - uint32 maxNameLength; - uint32 filesPerBlock; - uint32 fileCount; - byte xorKey[4]; - uint32 fileSectionOffset; -}; - -struct ZfsEntryHeader { - Common::String name; - uint32 offset; - uint32 id; - uint32 size; - uint32 time; - uint32 unknown; -}; - -typedef Common::HashMap ZfsEntryHeaderMap; - -class ZfsArchive : public Common::Archive { -public: - ZfsArchive(const Common::String &fileName); - ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream); - ~ZfsArchive(); - - /** - * Check if a member with the given name is present in the Archive. - * Patterns are not allowed, as this is meant to be a quick File::exists() - * replacement. - */ - bool hasFile(const Common::String &fileName) const; - - /** - * Add all members of the Archive to list. - * Must only append to list, and not remove elements from it. - * - * @return The number of names added to list - */ - int listMembers(Common::ArchiveMemberList &list) const; - - /** - * Returns a ArchiveMember representation of the given file. - */ - const Common::ArchiveMemberPtr getMember(const Common::String &name) const; - - /** - * Create a stream bound to a member with the specified name in the - * archive. If no member with this name exists, 0 is returned. - * - * @return The newly created input stream - */ - Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; - -private: - const Common::String _fileName; - ZfsHeader _header; - ZfsEntryHeaderMap _entryHeaders; - - /** - * Parses the zfs file into file entry headers that can be used later - * to get the entry data. - * - * @param stream The contents of the zfs file - */ - void readHeaders(Common::SeekableReadStream *stream); - - /** - * Entry names are contained within a 16 byte block. This reads the block - * and converts it the name to a Common::String - * - * @param stream The zfs file stream - * @return The entry file name - */ - Common::String readEntryName(Common::SeekableReadStream *stream) const; - - /** - * ZFS file entries can be encrypted using XOR encoding. This method - * decodes the buffer in place using the supplied xorKey. - * - * @param buffer The data to decode - * @param length Length of buffer - */ - void unXor(byte *buffer, int length, const byte *xorKey) const; -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp new file mode 100644 index 0000000000..e65d0df14e --- /dev/null +++ b/engines/zvision/zfs_archive.cpp @@ -0,0 +1,155 @@ +/* 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/scummsys.h" + +#include "zvision/zfsArchive.h" +#include "common/hashmap.h" +#include "common/memstream.h" +#include "common/debug.h" + +namespace ZVision { + +ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { + Common::File zfsFile; + + if (!zfsFile.open(_fileName)) { + warning("ZFSArchive::ZFSArchive(): Could not find the archive file"); + return; + } + + readHeaders(&zfsFile); + + debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); +} + +ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) { + readHeaders(stream); + + debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); +} + +ZfsArchive::~ZfsArchive() { + debug(0, "ZfsArchive Destructor Called"); + ZfsEntryHeaderMap::iterator it = _entryHeaders.begin(); + for ( ; it != _entryHeaders.end(); ++it) { + delete it->_value; + } +} + +void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { + // Don't do a straight struct cast since we can't guarantee endianness + _header.magic = stream->readUint32LE(); + _header.unknown1 = stream->readUint32LE(); + _header.maxNameLength = stream->readUint32LE(); + _header.filesPerBlock = stream->readUint32LE(); + _header.fileCount = stream->readUint32LE(); + _header.xorKey[0] = stream->readByte(); + _header.xorKey[1] = stream->readByte(); + _header.xorKey[2] = stream->readByte(); + _header.xorKey[3] = stream->readByte(); + _header.fileSectionOffset = stream->readUint32LE(); + + uint32 nextOffset; + + do { + // Read the offset to the next block + nextOffset = stream->readUint32LE(); + + // Read in each entry header + for (int i = 0; i < _header.filesPerBlock; i++) { + ZfsEntryHeader entryHeader; + + entryHeader.name = readEntryName(stream); + entryHeader.offset = stream->readUint32LE(); + entryHeader.id = stream->readUint32LE(); + entryHeader.size = stream->readUint32LE(); + entryHeader.time = stream->readUint32LE(); + entryHeader.unknown = stream->readUint32LE(); + + if (entryHeader.size != 0) + _entryHeaders[entryHeader.name] = new ZfsEntryHeader(entryHeader); + } + + // Seek to the next block of headers + stream->seek(nextOffset); + } while (nextOffset != 0); +} + +Common::String ZfsArchive::readEntryName(Common::SeekableReadStream *stream) const { + // Entry Names are at most 16 bytes and are null padded + char buffer[16]; + stream->read(buffer, 16); + + return Common::String(buffer); +} + +bool ZfsArchive::hasFile(const Common::String &name) const { + return _entryHeaders.contains(name); +} + +int ZfsArchive::listMembers(Common::ArchiveMemberList &list) const { + int matches = 0; + + for (ZfsEntryHeaderMap::const_iterator it = _entryHeaders.begin(); it != _entryHeaders.end(); ++it) { + list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(it->_value->name, this))); + matches++; + } + + return matches; +} + +const Common::ArchiveMemberPtr ZfsArchive::getMember(const Common::String &name) const { + if (!_entryHeaders.contains(name)) + return Common::ArchiveMemberPtr(); + + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); +} + +Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common::String &name) const { + if (!_entryHeaders.contains(name)) { + return 0; + } + + ZfsEntryHeader *entryHeader = _entryHeaders[name]; + + Common::File zfsArchive; + zfsArchive.open(_fileName); + zfsArchive.seek(entryHeader->offset); + + byte* buffer = new byte[entryHeader->size]; + zfsArchive.read(buffer, entryHeader->size); + // Decrypt the data in place + if (_header.xorKey != 0) + unXor(buffer, entryHeader->size, _header.xorKey); + + return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES); +} + +void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const { + for (uint32 i = 0; i < length; i++) + buffer[i] ^= xorKey[i % 4]; +} + +} // End of namespace ZVision + + diff --git a/engines/zvision/zfs_archive.h b/engines/zvision/zfs_archive.h new file mode 100644 index 0000000000..ccdf192571 --- /dev/null +++ b/engines/zvision/zfs_archive.h @@ -0,0 +1,121 @@ +/* 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 ZVISION_ZFS_ARCHIVE_H +#define ZVISION_ZFS_ARCHIVE_H + +#include "common/archive.h" +#include "common/file.h" +#include "common/fs.h" + +namespace ZVision { + +struct ZfsHeader { + uint32 magic; + uint32 unknown1; + uint32 maxNameLength; + uint32 filesPerBlock; + uint32 fileCount; + byte xorKey[4]; + uint32 fileSectionOffset; +}; + +struct ZfsEntryHeader { + Common::String name; + uint32 offset; + uint32 id; + uint32 size; + uint32 time; + uint32 unknown; +}; + +typedef Common::HashMap ZfsEntryHeaderMap; + +class ZfsArchive : public Common::Archive { +public: + ZfsArchive(const Common::String &fileName); + ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream); + ~ZfsArchive(); + + /** + * Check if a member with the given name is present in the Archive. + * Patterns are not allowed, as this is meant to be a quick File::exists() + * replacement. + */ + bool hasFile(const Common::String &fileName) const; + + /** + * Add all members of the Archive to list. + * Must only append to list, and not remove elements from it. + * + * @return The number of names added to list + */ + int listMembers(Common::ArchiveMemberList &list) const; + + /** + * Returns a ArchiveMember representation of the given file. + */ + const Common::ArchiveMemberPtr getMember(const Common::String &name) const; + + /** + * Create a stream bound to a member with the specified name in the + * archive. If no member with this name exists, 0 is returned. + * + * @return The newly created input stream + */ + Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; + +private: + const Common::String _fileName; + ZfsHeader _header; + ZfsEntryHeaderMap _entryHeaders; + + /** + * Parses the zfs file into file entry headers that can be used later + * to get the entry data. + * + * @param stream The contents of the zfs file + */ + void readHeaders(Common::SeekableReadStream *stream); + + /** + * Entry names are contained within a 16 byte block. This reads the block + * and converts it the name to a Common::String + * + * @param stream The zfs file stream + * @return The entry file name + */ + Common::String readEntryName(Common::SeekableReadStream *stream) const; + + /** + * ZFS file entries can be encrypted using XOR encoding. This method + * decodes the buffer in place using the supplied xorKey. + * + * @param buffer The data to decode + * @param length Length of buffer + */ + void unXor(byte *buffer, int length, const byte *xorKey) const; +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 1710468121648d494a393f7176c81027fec573c4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 15:45:46 -0500 Subject: ZVISION: Fix includes to use new underscore names --- engines/zvision/puzzle.h | 2 +- engines/zvision/result_action.cpp | 2 +- engines/zvision/scr_file_handling.cpp | 2 +- engines/zvision/script_manager.cpp | 2 +- engines/zvision/script_manager.h | 2 +- engines/zvision/zfs_archive.cpp | 2 +- engines/zvision/zvision.cpp | 4 ++-- engines/zvision/zvision.h | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 1a456ef6e2..75d3dc0826 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -25,7 +25,7 @@ #include "common/list.h" -#include "zvision/resultAction.h" +#include "zvision/result_action.h" namespace ZVision { diff --git a/engines/zvision/result_action.cpp b/engines/zvision/result_action.cpp index d14438d190..375dcd2f59 100644 --- a/engines/zvision/result_action.cpp +++ b/engines/zvision/result_action.cpp @@ -22,7 +22,7 @@ #include "common/scummsys.h" -#include "zvision/resultAction.h" +#include "zvision/result_action.h" namespace ZVision { diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 61feb12b7e..d18e042815 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -24,7 +24,7 @@ #include -#include "zvision/scriptManager.h" +#include "zvision/script_manager.h" #include "zvision/utility.h" #include "zvision/puzzle.h" diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 5317bf60f1..13438d4fa6 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -22,7 +22,7 @@ #include "common/scummsys.h" -#include "zvision/scriptManager.h" +#include "zvision/script_manager.h" namespace ZVision { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 563a010de5..7f46bd51fe 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -29,7 +29,7 @@ #include "zvision/puzzle.h" #include "zvision/control.h" -#include "zvision/singleValueContainer.h" +#include "zvision/result_action.h" namespace ZVision { diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index e65d0df14e..85933b3240 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -22,7 +22,7 @@ #include "common/scummsys.h" -#include "zvision/zfsArchive.h" +#include "zvision/zfs_archive.h" #include "common/hashmap.h" #include "common/memstream.h" #include "common/debug.h" diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 33b2a80bd4..5af1cbb1a2 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -32,8 +32,8 @@ #include "engines/util.h" #include "zvision/zvision.h" -#include "zvision/scriptManager.h" -#include "zvision/zfsArchive.h" +#include "zvision/script_manager.h" +#include "zvision/zfs_archive.h" #include "graphics/decoders/tga.h" diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index b0cd1aec5a..166d3c023f 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -29,7 +29,7 @@ #include "engines/engine.h" -#include "zvision/scriptManager.h" +#include "zvision/script_manager.h" #include "gui/debugger.h" -- cgit v1.2.3 From 0b9dce40a08020499aab20d8c9d967f53f7d84ea Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 15:46:36 -0500 Subject: ZVISION: Fix usage of Puzzle struct to use 'key' instead of 'id' --- engines/zvision/scr_file_handling.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index d18e042815..073d0eaaa4 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -52,7 +52,7 @@ void ScriptManager::parseScrFile(Common::String fileName) { if (line.matchString("puzzle:*", true)) { Puzzle puzzle; - sscanf(line.c_str(),"puzzle:%u",&(puzzle.id)); + sscanf(line.c_str(),"puzzle:%u",&(puzzle.key)); parsePuzzle(puzzle, file); _puzzles.push_back(puzzle); @@ -95,7 +95,7 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const // Parse the id out of the first token token = tokenizer.nextToken(); - sscanf(token.c_str(), "[%u]", &(criteria.id)); + sscanf(token.c_str(), "[%u]", &(criteria.key)); // Parse the operator out of the second token token = tokenizer.nextToken(); -- cgit v1.2.3 From c0c4ee65339285652b7966afa66a48d012d6ea27 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 17:19:54 -0500 Subject: ZVISION: Fix single_value_container.h include to use the new file name --- engines/zvision/single_value_container.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/single_value_container.cpp b/engines/zvision/single_value_container.cpp index bd91c44daf..7e27098377 100644 --- a/engines/zvision/single_value_container.cpp +++ b/engines/zvision/single_value_container.cpp @@ -23,7 +23,7 @@ #include "common/scummsys.h" #include "common/textconsole.h" -#include "zvision/singleValueContainer.h" +#include "zvision/single_value_container.h" namespace ZVision { -- cgit v1.2.3 From 187c119e934fd5887fb26e2dada5e1a4c856e056 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 17:21:21 -0500 Subject: ZVISION: Create ResultAction 's for Add and Random. Create class templates for PlayAnimation, PreloadAnimation, and Attenuate --- engines/zvision/result_action.cpp | 30 +++++++++++++++++++++++++++ engines/zvision/result_action.h | 38 +++++++++++++++++++++++++++++++++++ engines/zvision/scr_file_handling.cpp | 7 +++---- engines/zvision/zvision.cpp | 4 ++++ engines/zvision/zvision.h | 3 ++- 5 files changed, 77 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/result_action.cpp b/engines/zvision/result_action.cpp index 375dcd2f59..de439db1b9 100644 --- a/engines/zvision/result_action.cpp +++ b/engines/zvision/result_action.cpp @@ -26,6 +26,9 @@ namespace ZVision { +// ActionAdd +////////////////////////////////////////////////////////////////////////////// + ActionAdd::ActionAdd(Common::String line) { sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); } @@ -35,4 +38,31 @@ bool ActionAdd::execute(ZVision *zVision) { return true; } + +// ActionAssign +////////////////////////////////////////////////////////////////////////////// + +ActionAssign::ActionAssign(Common::String line) { + sscanf(line.c_str(), ":assign(%u, %hhu)", &_key, &_value); +} + +bool ActionAssign::execute(ZVision *zVision) { + zVision->getScriptManager()->setStateValue(_key, _value); + return true; +} + + +// ActionRandom +////////////////////////////////////////////////////////////////////////////// + +ActionRandom::ActionRandom(Common::String line) { + sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); +} + +bool ActionRandom::execute(ZVision *zVision) { + uint32 randNumber = zVision->getRandomSource()->getRandomNumber(_max); + zVision->getScriptManager()->setStateValue(_key, randNumber); + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/result_action.h b/engines/zvision/result_action.h index 4fd589d7cc..7ab896d510 100644 --- a/engines/zvision/result_action.h +++ b/engines/zvision/result_action.h @@ -87,6 +87,44 @@ private: byte _value; }; +class ActionPlayAnimation : public ResultAction { +public: + ActionPlayAnimation(Common::String line); + bool execute(ZVision *zVision); +}; + +class ActionPreloadAnimation : public ResultAction { +public: + ActionPreloadAnimation(Common::String line); + bool execute(ZVision *zVision); +}; + +class ActionAttenuate : public ResultAction { +public: + ActionAttenuate(Common::String line); + bool execute(ZVision *zVision); +}; + +class ActionAssign : public ResultAction { +public: + ActionAssign(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + byte _value; +}; + +class ActionRandom : public ResultAction { +public: + ActionRandom(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + uint32 _max; +}; + } // End of namespace ZVision #endif diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 073d0eaaa4..3171492717 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -131,16 +131,15 @@ void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(line); + // TODO: Re-order the if-then statements in order of highest occurrence while (!line.contains('}')) { // Parse for the action type if (line.matchString("*:add*", true)) { actionList.push_back(ActionAdd(line)); } else if (line.matchString("*:animplay*", true)) { - - + actionList.push_back(ActionPlayAnimation(line)); } else if (line.matchString("*:animpreload*", true)) { - - + actionList.push_back(ActionPreloadAnimation(line)); } else if (line.matchString("*:animunload*", true)) { diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 5af1cbb1a2..479bf2379a 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -142,4 +142,8 @@ ScriptManager *ZVision::getScriptManager() const { return _scriptManager; } +Common::RandomSource *ZVision::getRandomSource() const { + return _rnd; +} + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 166d3c023f..ac5796ad91 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -70,6 +70,7 @@ public: Common::Language getLanguage() const; virtual Common::Error run(); ScriptManager *getScriptManager() const; + Common::RandomSource *getRandomSource() const; private: void initialize(); @@ -89,7 +90,7 @@ public: Console(ZVision *vm) {} virtual ~Console(void) {} }; - + } // End of namespace ZVision #endif -- cgit v1.2.3 From 16cc970c9e1c7ccc06088de732abcd6ac51fa26a Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 17:50:40 -0500 Subject: ZVISION: Normalize remaining CRLF to LF for the remote --- engines/zvision/detection.cpp | 512 +++++++++++++++++------------------ engines/zvision/module.mk | 34 +-- engines/zvision/zork_avi_decoder.cpp | 100 +++---- engines/zvision/zork_avi_decoder.h | 118 ++++---- engines/zvision/zork_raw.cpp | 376 ++++++++++++------------- engines/zvision/zork_raw.h | 134 ++++----- engines/zvision/zvision.cpp | 298 ++++++++++---------- engines/zvision/zvision.h | 188 ++++++------- 8 files changed, 880 insertions(+), 880 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 62d834ac3f..5488ae5be4 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -1,256 +1,256 @@ -/* 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 "base/plugins.h" - -#include "engines/advancedDetector.h" - -#include "common/translation.h" -#include "common/savefile.h" -#include "common/str-array.h" -#include "common/system.h" - -#include "zvision/zvision.h" - - -namespace ZVision { - -struct ZVisionGameDescription { - ADGameDescription desc; -}; - -uint32 ZVision::getFeatures() const { - return _gameDescription->desc.flags; -} - -Common::Language ZVision::getLanguage() const { - return _gameDescription->desc.language; -} - -} - -static const PlainGameDescriptor zVisionGames[] = { - {"zvision", "ZVision Game"}, - {"znemesis", "Zork Nemesis: The Forbidden Lands"}, - {"zgi", "Zork: Grand Inquisitor"}, - {0, 0} -}; - - -namespace ZVision { - -static const ZVisionGameDescription gameDescriptions[] = { - - { - // Zork Nemesis English version - { - "znemesis", - 0, - AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), - Common::EN_ANY, - Common::kPlatformDOS, - ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) - }, - }, - - { AD_TABLE_END_MARKER } -}; - -} // End of namespace ZVision - -static const char *directoryGlobs[] = { - "znemscr", - 0 -}; - -static const ExtraGuiOption ZVisionExtraGuiOption = { - _s("Use original save/load screens"), - _s("Use the original save/load screens, instead of the ScummVM ones"), - "originalsaveload", - false -}; - -class ZVisionMetaEngine : public AdvancedMetaEngine { -public: - ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { - _maxScanDepth = 2; - _directoryGlobs = directoryGlobs; - _singleid = "zvision"; - } - - virtual const char *getName() const { - return "ZVision"; - } - - virtual const char *getOriginalCopyright() const { - return "ZVision Activision (C) 1996"; - } - - virtual bool hasFeature(MetaEngineFeature f) const; - virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; - virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; - SaveStateList listSaves(const char *target) const; - virtual int getMaximumSaveSlot() const; - void removeSaveState(const char *target, int slot) const; - SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; -}; - -bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { - return false; - /* - (f == kSupportsListSaves) || - (f == kSupportsLoadingDuringStartup) || - (f == kSupportsDeleteSave) || - (f == kSavesSupportMetaInfo) || - (f == kSavesSupportThumbnail) || - (f == kSavesSupportCreationDate) || - (f == kSavesSupportPlayTime); - */ -} - -/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { - return - (f == kSupportsRTL) || - (f == kSupportsLoadingDuringRuntime) || - (f == kSupportsSavingDuringRuntime); -}*/ - -bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { - const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; - if (gd) { - *engine = new ZVision::ZVision(syst, gd); - } - return gd != 0; -} - -const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String &target) const { - ExtraGuiOptions options; - options.push_back(ZVisionExtraGuiOption); - return options; -} - -SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { - //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - /*ZVision::ZVision::SaveHeader header; - Common::String pattern = target; - pattern += ".???"; - - Common::StringArray filenames; - filenames = saveFileMan->listSavefiles(pattern.c_str()); - Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ - - SaveStateList saveList; -/* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { - // Obtain the last 3 digits of the filename, since they correspond to the save slot - int slotNum = atoi(file->c_str() + file->size() - 3); - - if (slotNum >= 0 && slotNum <= 999) { - Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); - if (in) { - if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { - saveList.push_back(SaveStateDescriptor(slotNum, header.description)); - } - delete in; - } - } - }*/ - - return saveList; -} - -int ZVisionMetaEngine::getMaximumSaveSlot() const { - return 999; -} - -void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { - /* - Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); - - saveFileMan->removeSavefile(filename.c_str()); - - Common::StringArray filenames; - Common::String pattern = target; - pattern += ".???"; - filenames = saveFileMan->listSavefiles(pattern.c_str()); - Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) - - for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { - // Obtain the last 3 digits of the filename, since they correspond to the save slot - int slotNum = atoi(file->c_str() + file->size() - 3); - - // Rename every slot greater than the deleted slot, - if (slotNum > slot) { - saveFileMan->renameSavefile(file->c_str(), filename.c_str()); - filename = ZVision::ZVision::getSavegameFilename(target, ++slot); - } - } - */ -} - -SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { - /* - Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); - Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); - - if (in) { - ZVision::ZVision::SaveHeader header; - ZVision::ZVision::kReadSaveHeaderError error; - - error = ZVision::ZVision::readSaveHeader(in, true, header); - delete in; - - if (error == ZVision::ZVision::kRSHENoError) { - SaveStateDescriptor desc(slot, header.description); - - desc.setThumbnail(header.thumbnail); - - if (header.version > 0) { - int day = (header.saveDate >> 24) & 0xFF; - int month = (header.saveDate >> 16) & 0xFF; - int year = header.saveDate & 0xFFFF; - - desc.setSaveDate(year, month, day); - - int hour = (header.saveTime >> 16) & 0xFF; - int minutes = (header.saveTime >> 8) & 0xFF; - - desc.setSaveTime(hour, minutes); - - desc.setPlayTime(header.playTime * 1000); - } - - return desc; - } - } - */ - - return SaveStateDescriptor(); -} - -#if PLUGIN_ENABLED_DYNAMIC(ZVISION) - REGISTER_PLUGIN_DYNAMIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); -#else - REGISTER_PLUGIN_STATIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); -#endif +/* 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 "base/plugins.h" + +#include "engines/advancedDetector.h" + +#include "common/translation.h" +#include "common/savefile.h" +#include "common/str-array.h" +#include "common/system.h" + +#include "zvision/zvision.h" + + +namespace ZVision { + +struct ZVisionGameDescription { + ADGameDescription desc; +}; + +uint32 ZVision::getFeatures() const { + return _gameDescription->desc.flags; +} + +Common::Language ZVision::getLanguage() const { + return _gameDescription->desc.language; +} + +} + +static const PlainGameDescriptor zVisionGames[] = { + {"zvision", "ZVision Game"}, + {"znemesis", "Zork Nemesis: The Forbidden Lands"}, + {"zgi", "Zork: Grand Inquisitor"}, + {0, 0} +}; + + +namespace ZVision { + +static const ZVisionGameDescription gameDescriptions[] = { + + { + // Zork Nemesis English version + { + "znemesis", + 0, + AD_ENTRY1s("CSCR.ZFS", "88226e51a205d2e50c67a5237f3bd5f2", 2397741), + Common::EN_ANY, + Common::kPlatformDOS, + ADGF_NO_FLAGS, + GUIO1(GUIO_NONE) + }, + }, + + { AD_TABLE_END_MARKER } +}; + +} // End of namespace ZVision + +static const char *directoryGlobs[] = { + "znemscr", + 0 +}; + +static const ExtraGuiOption ZVisionExtraGuiOption = { + _s("Use original save/load screens"), + _s("Use the original save/load screens, instead of the ScummVM ones"), + "originalsaveload", + false +}; + +class ZVisionMetaEngine : public AdvancedMetaEngine { +public: + ZVisionMetaEngine() : AdvancedMetaEngine(ZVision::gameDescriptions, sizeof(ZVision::ZVisionGameDescription), zVisionGames) { + _maxScanDepth = 2; + _directoryGlobs = directoryGlobs; + _singleid = "zvision"; + } + + virtual const char *getName() const { + return "ZVision"; + } + + virtual const char *getOriginalCopyright() const { + return "ZVision Activision (C) 1996"; + } + + virtual bool hasFeature(MetaEngineFeature f) const; + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const; + SaveStateList listSaves(const char *target) const; + virtual int getMaximumSaveSlot() const; + void removeSaveState(const char *target, int slot) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; +}; + +bool ZVisionMetaEngine::hasFeature(MetaEngineFeature f) const { + return false; + /* + (f == kSupportsListSaves) || + (f == kSupportsLoadingDuringStartup) || + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail) || + (f == kSavesSupportCreationDate) || + (f == kSavesSupportPlayTime); + */ +} + +/*bool ZVision::ZVision::hasFeature(EngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); +}*/ + +bool ZVisionMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + const ZVision::ZVisionGameDescription *gd = (const ZVision::ZVisionGameDescription *)desc; + if (gd) { + *engine = new ZVision::ZVision(syst, gd); + } + return gd != 0; +} + +const ExtraGuiOptions ZVisionMetaEngine::getExtraGuiOptions(const Common::String &target) const { + ExtraGuiOptions options; + options.push_back(ZVisionExtraGuiOption); + return options; +} + +SaveStateList ZVisionMetaEngine::listSaves(const char *target) const { + //Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + /*ZVision::ZVision::SaveHeader header; + Common::String pattern = target; + pattern += ".???"; + + Common::StringArray filenames; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ + + SaveStateList saveList; +/* for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + if (ZVision::ZVision::readSaveHeader(in, false, header) == ZVision::ZVision::kRSHENoError) { + saveList.push_back(SaveStateDescriptor(slotNum, header.description)); + } + delete in; + } + } + }*/ + + return saveList; +} + +int ZVisionMetaEngine::getMaximumSaveSlot() const { + return 999; +} + +void ZVisionMetaEngine::removeSaveState(const char *target, int slot) const { + /* + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + + saveFileMan->removeSavefile(filename.c_str()); + + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".???"; + filenames = saveFileMan->listSavefiles(pattern.c_str()); + Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + // Rename every slot greater than the deleted slot, + if (slotNum > slot) { + saveFileMan->renameSavefile(file->c_str(), filename.c_str()); + filename = ZVision::ZVision::getSavegameFilename(target, ++slot); + } + } + */ +} + +SaveStateDescriptor ZVisionMetaEngine::querySaveMetaInfos(const char *target, int slot) const { + /* + Common::String filename = ZVision::ZVision::getSavegameFilename(target, slot); + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str()); + + if (in) { + ZVision::ZVision::SaveHeader header; + ZVision::ZVision::kReadSaveHeaderError error; + + error = ZVision::ZVision::readSaveHeader(in, true, header); + delete in; + + if (error == ZVision::ZVision::kRSHENoError) { + SaveStateDescriptor desc(slot, header.description); + + desc.setThumbnail(header.thumbnail); + + if (header.version > 0) { + int day = (header.saveDate >> 24) & 0xFF; + int month = (header.saveDate >> 16) & 0xFF; + int year = header.saveDate & 0xFFFF; + + desc.setSaveDate(year, month, day); + + int hour = (header.saveTime >> 16) & 0xFF; + int minutes = (header.saveTime >> 8) & 0xFF; + + desc.setSaveTime(hour, minutes); + + desc.setPlayTime(header.playTime * 1000); + } + + return desc; + } + } + */ + + return SaveStateDescriptor(); +} + +#if PLUGIN_ENABLED_DYNAMIC(ZVISION) + REGISTER_PLUGIN_DYNAMIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#else + REGISTER_PLUGIN_STATIC(ZVISION, PLUGIN_TYPE_ENGINE, ZVisionMetaEngine); +#endif diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 854ee0307c..3dd17a2f99 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -1,18 +1,18 @@ -MODULE := engines/zvision - -MODULE_OBJS := \ - detection.o \ - zvision.o \ - zork_avi_decoder.o \ - zork_raw.o - -MODULE_DIRS += \ - engines/zvision - -# This module can be built as a plugin -ifeq ($(ENABLE_ZVISION), DYNAMIC_PLUGIN) -PLUGIN := 1 -endif - -# Include common rules +MODULE := engines/zvision + +MODULE_OBJS := \ + detection.o \ + zvision.o \ + zork_avi_decoder.o \ + zork_raw.o + +MODULE_DIRS += \ + engines/zvision + +# This module can be built as a plugin +ifeq ($(ENABLE_ZVISION), DYNAMIC_PLUGIN) +PLUGIN := 1 +endif + +# Include common rules include $(srcdir)/rules.mk \ No newline at end of file diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp index 2da524655b..4ceff48891 100644 --- a/engines/zvision/zork_avi_decoder.cpp +++ b/engines/zvision/zork_avi_decoder.cpp @@ -1,50 +1,50 @@ -/* 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/scummsys.h" - -#include "common/stream.h" -#include "audio/audiostream.h" - -#include "engines/zvision/zork_avi_decoder.h" -#include "engines/zvision/zork_raw.h" - -namespace ZVision { - -Video::AVIDecoder::AVIAudioTrack *ZVision::ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) { - ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType); - return (Video::AVIDecoder::AVIAudioTrack *)audioTrack; -} - -void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { - if (_audStream) { - if (_wvInfo.tag == kWaveFormatZorkPCM) { - assert(_wvInfo.size == 8); - _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, DisposeAfterUse::YES), DisposeAfterUse::YES); - } - } else { - delete stream; - } -} - -} // End of namespace ZVision +/* 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/scummsys.h" + +#include "common/stream.h" +#include "audio/audiostream.h" + +#include "engines/zvision/zork_avi_decoder.h" +#include "engines/zvision/zork_raw.h" + +namespace ZVision { + +Video::AVIDecoder::AVIAudioTrack *ZVision::ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) { + ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType); + return (Video::AVIDecoder::AVIAudioTrack *)audioTrack; +} + +void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { + if (_audStream) { + if (_wvInfo.tag == kWaveFormatZorkPCM) { + assert(_wvInfo.size == 8); + _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, DisposeAfterUse::YES), DisposeAfterUse::YES); + } + } else { + delete stream; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/zork_avi_decoder.h b/engines/zvision/zork_avi_decoder.h index 5530d92ce4..1dff304894 100644 --- a/engines/zvision/zork_avi_decoder.h +++ b/engines/zvision/zork_avi_decoder.h @@ -1,59 +1,59 @@ -/* 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 ZORK_AVI_DECODER_H -#define ZORK_AVI_DECODER_H - -#include "video/avi_decoder.h" - -namespace ZVision { - -class ZorkAVIDecoder : public Video::AVIDecoder { -public: - ZorkAVIDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType) : - Video::AVIDecoder(soundType) {} - - virtual ~ZorkAVIDecoder() {} - -private: - class ZorkAVIAudioTrack : public Video::AVIDecoder::AVIAudioTrack { - public: - ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) : - Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType) {} - virtual ~ZorkAVIAudioTrack() {} - - void queueSound(Common::SeekableReadStream *stream); - }; - - Video::AVIDecoder::AVIAudioTrack *createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo); - - private: - // Audio Codecs - enum { - kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM) - }; -}; - -} // End of namespace ZVision - -#endif +/* 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 ZORK_AVI_DECODER_H +#define ZORK_AVI_DECODER_H + +#include "video/avi_decoder.h" + +namespace ZVision { + +class ZorkAVIDecoder : public Video::AVIDecoder { +public: + ZorkAVIDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType) : + Video::AVIDecoder(soundType) {} + + virtual ~ZorkAVIDecoder() {} + +private: + class ZorkAVIAudioTrack : public Video::AVIDecoder::AVIAudioTrack { + public: + ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) : + Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType) {} + virtual ~ZorkAVIAudioTrack() {} + + void queueSound(Common::SeekableReadStream *stream); + }; + + Video::AVIDecoder::AVIAudioTrack *createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo); + + private: + // Audio Codecs + enum { + kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM) + }; +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index e008741e16..d920550bc7 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -1,188 +1,188 @@ -/* 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/scummsys.h" - -#include "common/endian.h" -#include "common/memstream.h" -#include "common/textconsole.h" -#include "common/util.h" - -#include "audio/audiostream.h" - -#include "engines/zvision/zork_raw.h" - -namespace ZVision { - -#pragma mark - -#pragma mark --- RawZorkStream --- -#pragma mark - - -/** - * This is a stream, which allows for playing raw PCM data from a stream. - */ -class RawZorkStream : public Audio::SeekableAudioStream { -public: - RawZorkStream(int rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) - : _rate(rate), _playtime(0, rate), _stream(stream, disposeStream), _endOfData(false), _buffer(0) { - // Setup our buffer for readBuffer - _buffer = new byte[kSampleBufferLength]; - assert(_buffer); - - // Calculate the total playtime of the stream - _playtime = Audio::Timestamp(0, _stream->size() / 2 / 1, rate); - } - - ~RawZorkStream() { - delete[] _buffer; - } - - int readBuffer(int16 *buffer, const int numSamples); - - bool isStereo() const { return true; } - bool endOfData() const { return _endOfData; } - - int getRate() const { return _rate; } - Audio::Timestamp getLength() const { return _playtime; } - - bool seek(const Audio::Timestamp &where); -private: - const int _rate; ///< Sample rate of stream - Audio::Timestamp _playtime; ///< Calculated total play time - Common::DisposablePtr _stream; ///< Stream to read data from - bool _endOfData; ///< Whether the stream end has been reached - - byte *_buffer; ///< Buffer used in readBuffer - enum { - /** - * How many samples we can buffer at once. - * - * TODO: Check whether this size suffices - * for systems with slow disk I/O. - */ - kSampleBufferLength = 2048 - }; - - /** - * Fill the temporary sample buffer used in readBuffer. - * - * @param maxSamples Maximum samples to read. - * @return actual count of samples read. - */ - int fillBuffer(int maxSamples); -}; - -int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { - int samplesLeft = numSamples; - - while (samplesLeft > 0) { - // Try to read up to "samplesLeft" samples. - int len = fillBuffer(samplesLeft); - - // In case we were not able to read any samples - // we will stop reading here. - if (!len) - break; - - // Adjust the samples left to read. - samplesLeft -= len; - - // Copy the data to the caller's buffer. - const byte *src = _buffer; - while (len-- > 0) { - if (*src < 128) - *buffer++ = ((128 - *src) << 8) ^ 0x8000; - else - *buffer++ = (*src << 8) ^ 0x8000; - src++; - } - } - - return numSamples - samplesLeft; -} - -int RawZorkStream::fillBuffer(int maxSamples) { - int bufferedSamples = 0; - byte *dst = _buffer; - - // We can only read up to "kSampleBufferLength" samples - // so we take this into consideration, when trying to - // read up to maxSamples. - maxSamples = MIN(kSampleBufferLength, maxSamples); - - // We will only read up to maxSamples - while (maxSamples > 0 && !endOfData()) { - // Try to read all the sample data and update the - // destination pointer. - const int bytesRead = _stream->read(dst, maxSamples); - dst += bytesRead; - - // Calculate how many samples we actually read. - const int samplesRead = bytesRead; - - // Update all status variables - bufferedSamples += samplesRead; - maxSamples -= samplesRead; - - // We stop stream playback, when we reached the end of the data stream. - // We also stop playback when an error occures. - if (_stream->pos() == _stream->size() || _stream->err() || _stream->eos()) - _endOfData = true; - } - - return bufferedSamples; -} - -bool RawZorkStream::seek(const Audio::Timestamp &where) { - _endOfData = true; - - if (where > _playtime) - return false; - - const uint32 seekSample = convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames(); - _stream->seek(seekSample, SEEK_SET); - - // In case of an error we will not continue stream playback. - if (!_stream->err() && !_stream->eos() && _stream->pos() != _stream->size()) - _endOfData = false; - - return true; -} - -#pragma mark - -#pragma mark --- Raw stream factories --- -#pragma mark - - -Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, - int rate, - DisposeAfterUse::Flag disposeAfterUse) { - assert(stream->size() % 2 == 0); - return new RawZorkStream(rate, disposeAfterUse, stream); -} - -Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, - int rate, - DisposeAfterUse::Flag disposeAfterUse) { - return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, DisposeAfterUse::YES); -} - -} // End of namespace ZVision +/* 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/scummsys.h" + +#include "common/endian.h" +#include "common/memstream.h" +#include "common/textconsole.h" +#include "common/util.h" + +#include "audio/audiostream.h" + +#include "engines/zvision/zork_raw.h" + +namespace ZVision { + +#pragma mark - +#pragma mark --- RawZorkStream --- +#pragma mark - + +/** + * This is a stream, which allows for playing raw PCM data from a stream. + */ +class RawZorkStream : public Audio::SeekableAudioStream { +public: + RawZorkStream(int rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) + : _rate(rate), _playtime(0, rate), _stream(stream, disposeStream), _endOfData(false), _buffer(0) { + // Setup our buffer for readBuffer + _buffer = new byte[kSampleBufferLength]; + assert(_buffer); + + // Calculate the total playtime of the stream + _playtime = Audio::Timestamp(0, _stream->size() / 2 / 1, rate); + } + + ~RawZorkStream() { + delete[] _buffer; + } + + int readBuffer(int16 *buffer, const int numSamples); + + bool isStereo() const { return true; } + bool endOfData() const { return _endOfData; } + + int getRate() const { return _rate; } + Audio::Timestamp getLength() const { return _playtime; } + + bool seek(const Audio::Timestamp &where); +private: + const int _rate; ///< Sample rate of stream + Audio::Timestamp _playtime; ///< Calculated total play time + Common::DisposablePtr _stream; ///< Stream to read data from + bool _endOfData; ///< Whether the stream end has been reached + + byte *_buffer; ///< Buffer used in readBuffer + enum { + /** + * How many samples we can buffer at once. + * + * TODO: Check whether this size suffices + * for systems with slow disk I/O. + */ + kSampleBufferLength = 2048 + }; + + /** + * Fill the temporary sample buffer used in readBuffer. + * + * @param maxSamples Maximum samples to read. + * @return actual count of samples read. + */ + int fillBuffer(int maxSamples); +}; + +int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { + int samplesLeft = numSamples; + + while (samplesLeft > 0) { + // Try to read up to "samplesLeft" samples. + int len = fillBuffer(samplesLeft); + + // In case we were not able to read any samples + // we will stop reading here. + if (!len) + break; + + // Adjust the samples left to read. + samplesLeft -= len; + + // Copy the data to the caller's buffer. + const byte *src = _buffer; + while (len-- > 0) { + if (*src < 128) + *buffer++ = ((128 - *src) << 8) ^ 0x8000; + else + *buffer++ = (*src << 8) ^ 0x8000; + src++; + } + } + + return numSamples - samplesLeft; +} + +int RawZorkStream::fillBuffer(int maxSamples) { + int bufferedSamples = 0; + byte *dst = _buffer; + + // We can only read up to "kSampleBufferLength" samples + // so we take this into consideration, when trying to + // read up to maxSamples. + maxSamples = MIN(kSampleBufferLength, maxSamples); + + // We will only read up to maxSamples + while (maxSamples > 0 && !endOfData()) { + // Try to read all the sample data and update the + // destination pointer. + const int bytesRead = _stream->read(dst, maxSamples); + dst += bytesRead; + + // Calculate how many samples we actually read. + const int samplesRead = bytesRead; + + // Update all status variables + bufferedSamples += samplesRead; + maxSamples -= samplesRead; + + // We stop stream playback, when we reached the end of the data stream. + // We also stop playback when an error occures. + if (_stream->pos() == _stream->size() || _stream->err() || _stream->eos()) + _endOfData = true; + } + + return bufferedSamples; +} + +bool RawZorkStream::seek(const Audio::Timestamp &where) { + _endOfData = true; + + if (where > _playtime) + return false; + + const uint32 seekSample = convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames(); + _stream->seek(seekSample, SEEK_SET); + + // In case of an error we will not continue stream playback. + if (!_stream->err() && !_stream->eos() && _stream->pos() != _stream->size()) + _endOfData = false; + + return true; +} + +#pragma mark - +#pragma mark --- Raw stream factories --- +#pragma mark - + +Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, + int rate, + DisposeAfterUse::Flag disposeAfterUse) { + assert(stream->size() % 2 == 0); + return new RawZorkStream(rate, disposeAfterUse, stream); +} + +Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, + int rate, + DisposeAfterUse::Flag disposeAfterUse) { + return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, DisposeAfterUse::YES); +} + +} // End of namespace ZVision diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 3a938026d9..1de3b575ba 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -1,67 +1,67 @@ -/* 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 ZVISION_ZORK_RAW_H -#define ZVISION_ZORK_RAW_H - -#include "common/scummsys.h" -#include "common/types.h" - -#include "common/list.h" - - -namespace Common { -class SeekableReadStream; -} - -namespace ZVision { - -class SeekableAudioStream; - -/** - * Creates an audio stream, which plays from the given buffer. - * - * @param buffer Buffer to play from. - * @param size Size of the buffer in bytes. - * @param rate Rate of the sound data. - * @param disposeAfterUse Whether to free the buffer after use (with free!). - * @return The new SeekableAudioStream (or 0 on failure). - */ -Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, - int rate, - DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); - -/** - * Creates an audio stream, which plays from the given stream. - * - * @param stream Stream object to play from. - * @param rate Rate of the sound data. - * @param disposeAfterUse Whether to delete the stream after use. - * @return The new SeekableAudioStream (or 0 on failure). - */ -Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, - int rate, - DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); - -} // End of namespace ZVision - -#endif +/* 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 ZVISION_ZORK_RAW_H +#define ZVISION_ZORK_RAW_H + +#include "common/scummsys.h" +#include "common/types.h" + +#include "common/list.h" + + +namespace Common { +class SeekableReadStream; +} + +namespace ZVision { + +class SeekableAudioStream; + +/** + * Creates an audio stream, which plays from the given buffer. + * + * @param buffer Buffer to play from. + * @param size Size of the buffer in bytes. + * @param rate Rate of the sound data. + * @param disposeAfterUse Whether to free the buffer after use (with free!). + * @return The new SeekableAudioStream (or 0 on failure). + */ +Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, + int rate, + DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + +/** + * Creates an audio stream, which plays from the given stream. + * + * @param stream Stream object to play from. + * @param rate Rate of the sound data. + * @param disposeAfterUse Whether to delete the stream after use. + * @return The new SeekableAudioStream (or 0 on failure). + */ +Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, + int rate, + DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 479bf2379a..5e83c47721 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -1,149 +1,149 @@ -/* 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/scummsys.h" - -#include "common/config-manager.h" -#include "common/debug.h" -#include "common/debug-channels.h" -#include "common/error.h" -#include "common/system.h" -#include "common/file.h" - -#include "engines/util.h" - -#include "zvision/zvision.h" -#include "zvision/script_manager.h" -#include "zvision/zfs_archive.h" - -#include "graphics/decoders/tga.h" - -#include "zvision/tests.h" - -namespace ZVision { - -ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { - // Put your engine in a sane state, but do nothing big yet; - // in particular, do not load data from files; rather, if you - // need to do such things, do them from run(). - - // Do not initialize graphics here - - // However this is the place to specify all default directories - const Common::FSNode gameDataDir(ConfMan.get("path")); - SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4); - SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4); - SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4); - SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx"); - SearchMan.addSubDirectoryMatching(gameDataDir, "znemscr"); - - // Here is the right place to set up the engine specific debug channels - //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); - //DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example"); - - // Register random source - _rnd = new Common::RandomSource("zvision"); - - // Create managers - _scriptManager = new ScriptManager(); - - debug("ZVision::ZVision"); -} - -ZVision::~ZVision() { - debug("ZVision::~ZVision"); - - // Dispose of resources - delete _scriptManager; - delete _rnd; - - // Remove all of our debug levels - DebugMan.clearAllDebugChannels(); -} - -void ZVision::initialize() { - // Find zfs archive files - Common::ArchiveMemberList list; - SearchMan.listMatchingMembers(list, "*.zfs"); - - // Register the file entries within the zfs archives with the SearchMan - for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { - Common::String name = (*iter)->getName(); - ZfsArchive *archive = new ZfsArchive(name, (*iter)->createReadStream()); - - SearchMan.add(name, archive); - } - - //Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); // ARGB8888 - Graphics::PixelFormat format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); // RGB555 - initGraphics(640, 480, true, &format); - - _scriptManager->initialize(); - - // Create debugger console. It requires GFX to be initialized - _console = new Console(this); -} - -Common::Error ZVision::run() { - initialize(); - - tests(); - - // Main loop - uint32 currentTime = _system->getMillis(); - uint32 lastTime = currentTime; - const uint32 desiredFrameTime = 33; // ~30 fps - - while (!shouldQuit()) { - processEvents(); - - currentTime = _system->getMillis(); - uint32 deltaTime = currentTime - lastTime; - lastTime = currentTime; - - updateScripts(); - updateAnimations(deltaTime); - - if (_needsScreenUpdate) - { - _system->updateScreen(); - } - - // Calculate the frame delay based off a desired frame rate - int delay = desiredFrameTime - (currentTime - _system->getMillis()); - // Ensure non-negative - delay = delay < 0 ? 0 : delay; - _system->delayMillis(delay); - } - - return Common::kNoError; -} - -ScriptManager *ZVision::getScriptManager() const { - return _scriptManager; -} - -Common::RandomSource *ZVision::getRandomSource() const { - return _rnd; -} - -} // End of namespace ZVision +/* 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/scummsys.h" + +#include "common/config-manager.h" +#include "common/debug.h" +#include "common/debug-channels.h" +#include "common/error.h" +#include "common/system.h" +#include "common/file.h" + +#include "engines/util.h" + +#include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/zfs_archive.h" + +#include "graphics/decoders/tga.h" + +#include "zvision/tests.h" + +namespace ZVision { + +ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { + // Put your engine in a sane state, but do nothing big yet; + // in particular, do not load data from files; rather, if you + // need to do such things, do them from run(). + + // Do not initialize graphics here + + // However this is the place to specify all default directories + const Common::FSNode gameDataDir(ConfMan.get("path")); + SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4); + SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4); + SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4); + SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx"); + SearchMan.addSubDirectoryMatching(gameDataDir, "znemscr"); + + // Here is the right place to set up the engine specific debug channels + //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); + //DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example"); + + // Register random source + _rnd = new Common::RandomSource("zvision"); + + // Create managers + _scriptManager = new ScriptManager(); + + debug("ZVision::ZVision"); +} + +ZVision::~ZVision() { + debug("ZVision::~ZVision"); + + // Dispose of resources + delete _scriptManager; + delete _rnd; + + // Remove all of our debug levels + DebugMan.clearAllDebugChannels(); +} + +void ZVision::initialize() { + // Find zfs archive files + Common::ArchiveMemberList list; + SearchMan.listMatchingMembers(list, "*.zfs"); + + // Register the file entries within the zfs archives with the SearchMan + for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { + Common::String name = (*iter)->getName(); + ZfsArchive *archive = new ZfsArchive(name, (*iter)->createReadStream()); + + SearchMan.add(name, archive); + } + + //Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); // ARGB8888 + Graphics::PixelFormat format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); // RGB555 + initGraphics(640, 480, true, &format); + + _scriptManager->initialize(); + + // Create debugger console. It requires GFX to be initialized + _console = new Console(this); +} + +Common::Error ZVision::run() { + initialize(); + + tests(); + + // Main loop + uint32 currentTime = _system->getMillis(); + uint32 lastTime = currentTime; + const uint32 desiredFrameTime = 33; // ~30 fps + + while (!shouldQuit()) { + processEvents(); + + currentTime = _system->getMillis(); + uint32 deltaTime = currentTime - lastTime; + lastTime = currentTime; + + updateScripts(); + updateAnimations(deltaTime); + + if (_needsScreenUpdate) + { + _system->updateScreen(); + } + + // Calculate the frame delay based off a desired frame rate + int delay = desiredFrameTime - (currentTime - _system->getMillis()); + // Ensure non-negative + delay = delay < 0 ? 0 : delay; + _system->delayMillis(delay); + } + + return Common::kNoError; +} + +ScriptManager *ZVision::getScriptManager() const { + return _scriptManager; +} + +Common::RandomSource *ZVision::getRandomSource() const { + return _rnd; +} + +} // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index ac5796ad91..0053fe5a9e 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -1,96 +1,96 @@ -/* 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 ZVISION_H -#define ZVISION_H - -#include "common/random.h" -#include "common/events.h" - -#include "engines/engine.h" - -#include "zvision/script_manager.h" - -#include "gui/debugger.h" - -namespace ZVision { - -struct ZVisionGameDescription; -class Console; - -// our engine debug channels -enum { - kZDebugExample = 1 << 0, - kZDebugExample2 = 1 << 1 - // next new channel must be 1 << 2 (4) - // the current limitation is 32 debug channels (1 << 31 is the last one) -}; - -class ZVision : public Engine { -public: - ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc); - ~ZVision(); - -private: - Console *_console; - const ZVisionGameDescription *_gameDescription; - - // We need random numbers - Common::RandomSource *_rnd; - - ScriptManager *_scriptManager; - - // To prevent allocation every time we process events - Common::Event _event; - - bool _needsScreenUpdate; - -public: - uint32 getFeatures() const; - Common::Language getLanguage() const; - virtual Common::Error run(); - ScriptManager *getScriptManager() const; - Common::RandomSource *getRandomSource() const; - -private: - void initialize(); - - void processEvents(); +/* 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 ZVISION_H +#define ZVISION_H + +#include "common/random.h" +#include "common/events.h" + +#include "engines/engine.h" + +#include "zvision/script_manager.h" + +#include "gui/debugger.h" + +namespace ZVision { + +struct ZVisionGameDescription; +class Console; + +// our engine debug channels +enum { + kZDebugExample = 1 << 0, + kZDebugExample2 = 1 << 1 + // next new channel must be 1 << 2 (4) + // the current limitation is 32 debug channels (1 << 31 is the last one) +}; + +class ZVision : public Engine { +public: + ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc); + ~ZVision(); + +private: + Console *_console; + const ZVisionGameDescription *_gameDescription; + + // We need random numbers + Common::RandomSource *_rnd; + + ScriptManager *_scriptManager; + + // To prevent allocation every time we process events + Common::Event _event; + + bool _needsScreenUpdate; + +public: + uint32 getFeatures() const; + Common::Language getLanguage() const; + virtual Common::Error run(); + ScriptManager *getScriptManager() const; + Common::RandomSource *getRandomSource() const; + +private: + void initialize(); + + void processEvents(); void onMouseDown(const Common::Point &pos); void onMouseMove(const Common::Point &pos); - void onKeyDown(uint16 keyCode); - - void updateScripts(); - void updateAnimations(uint32 detaTimeMillis); -}; - -// Example console class -class Console : public GUI::Debugger { -public: - Console(ZVision *vm) {} - virtual ~Console(void) {} -}; - -} // End of namespace ZVision - -#endif + void onKeyDown(uint16 keyCode); + + void updateScripts(); + void updateAnimations(uint32 detaTimeMillis); +}; + +// Example console class +class Console : public GUI::Debugger { +public: + Console(ZVision *vm) {} + virtual ~Console(void) {} +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 0ba9ca8fa0614287bf4b7e666a07126fa8e1faad Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 18:21:25 -0500 Subject: ZVISION: Forward declare ZVision in result_action.h result_action.h is #included before ZVision is declared, causing not declared compiler errors --- engines/zvision/result_action.cpp | 1 + engines/zvision/result_action.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/result_action.cpp b/engines/zvision/result_action.cpp index de439db1b9..4721c5bd61 100644 --- a/engines/zvision/result_action.cpp +++ b/engines/zvision/result_action.cpp @@ -23,6 +23,7 @@ #include "common/scummsys.h" #include "zvision/result_action.h" +#include "zvision/zvision.h" namespace ZVision { diff --git a/engines/zvision/result_action.h b/engines/zvision/result_action.h index 7ab896d510..fbf8e7f019 100644 --- a/engines/zvision/result_action.h +++ b/engines/zvision/result_action.h @@ -25,10 +25,13 @@ #include "common/scummsys.h" -#include "zvision/zvision.h" +#include "common/str.h" namespace ZVision { +// Forward declaration of ZVision. This file is included before ZVision is declared +class ZVision; + class ResultAction { public: virtual ~ResultAction() {} -- cgit v1.2.3 From 3822de2aec0d41df7c2beeb5a1269577e9c3df84 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 3 Jul 2013 18:24:06 -0500 Subject: ZVISION: Change Puzzle::resultActions to a List of pointers instead of ResultAction objects ResultAction is abstract, therefore, it can't be directly stored in the list --- engines/zvision/puzzle.h | 3 ++- engines/zvision/scr_file_handling.cpp | 8 ++++---- engines/zvision/script_manager.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 75d3dc0826..fd9c61e8bc 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -61,7 +61,8 @@ enum StateFlags : byte { struct Puzzle { uint32 key; Common::List criteriaList; - Common::List resultActions; + // This has to be list of pointers because ResultAction is abstract + Common::List resultActions; byte flags; }; diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 3171492717..eb867fa0a2 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -126,7 +126,7 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const return criteria; } -void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { +void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(line); @@ -135,11 +135,11 @@ void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List while (!line.contains('}')) { // Parse for the action type if (line.matchString("*:add*", true)) { - actionList.push_back(ActionAdd(line)); + actionList.push_back(new ActionAdd(line)); } else if (line.matchString("*:animplay*", true)) { - actionList.push_back(ActionPlayAnimation(line)); + actionList.push_back(new ActionPlayAnimation(line)); } else if (line.matchString("*:animpreload*", true)) { - actionList.push_back(ActionPreloadAnimation(line)); + actionList.push_back(new ActionPreloadAnimation(line)); } else if (line.matchString("*:animunload*", true)) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 7f46bd51fe..173705edf5 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -82,7 +82,7 @@ private: * @param stream Scr file stream * @return Created Results object */ - void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; + void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; /** * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum -- cgit v1.2.3 From 3f93f7d27fe58690a4b94c22247bb00a9af2c92e Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 5 Jul 2013 20:14:50 -0500 Subject: ZVISION: Change trimCommentsAndWhiteSpace to use a pointer instead of a reference. --- engines/zvision/scr_file_handling.cpp | 14 +++++++------- engines/zvision/utility.h | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index eb867fa0a2..285e635c61 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -46,7 +46,7 @@ void ScriptManager::parseScrFile(Common::String fileName) { return; } - trimCommentsAndWhiteSpace(line); + trimCommentsAndWhiteSpace(&line); if (line.empty()) continue; @@ -69,7 +69,7 @@ void ScriptManager::parseScrFile(Common::String fileName) { void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); + trimCommentsAndWhiteSpace(&line); while (!line.contains('}')) { if (line.matchString("criteria {", true)) @@ -86,7 +86,7 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const // Loop until we find the closing brace Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); + trimCommentsAndWhiteSpace(&line); while (!line.contains('}')) { // Split the string into tokens using ' ' as a delimiter @@ -120,7 +120,7 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const } line = stream.readLine(); - trimCommentsAndWhiteSpace(line); + trimCommentsAndWhiteSpace(&line); } return criteria; @@ -129,7 +129,7 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); + trimCommentsAndWhiteSpace(&line); // TODO: Re-order the if-then statements in order of highest occurrence while (!line.contains('}')) { @@ -253,7 +253,7 @@ void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List } line = stream.readLine(); - trimCommentsAndWhiteSpace(line); + trimCommentsAndWhiteSpace(&line); } return; @@ -264,7 +264,7 @@ byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { // Loop until we find the closing brace Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(line); + trimCommentsAndWhiteSpace(&line); while (!line.contains('}')) { if (line.matchString("ONCE_PER_INST", true)) { diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 4d124509ba..511b3c12f2 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -59,14 +59,15 @@ void writeFileContentsToFile(Common::String sourceFile, Common::String destFile) * * @param string The string to modify. It is modified in place */ -void trimCommentsAndWhiteSpace(Common::String &string) { - for (int i = string.size(); i >= 0; --i) { - if (string[i] == '#') { - string.erase(i); +void trimCommentsAndWhiteSpace(Common::String *string) { + for (int i = string->size() - 1; i >= 0; i--) { + if ((*string)[i] == '#') { + string->erase(i); } } - string.trim(); + string->trim(); +} } } // End of namespace ZVision -- cgit v1.2.3 From ebb546c46850475485753346594376cf62465765 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 6 Jul 2013 00:26:01 -0500 Subject: ZVISION: Create utility method to dump result action signatures from various .scr files --- engines/zvision/utility.h | 134 +++++++++++++++++++++++++++++++++++++++++++- engines/zvision/zvision.cpp | 5 +- 2 files changed, 136 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 511b3c12f2..0b2ef2b8cd 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -36,7 +36,7 @@ namespace ZVision { * @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(Common::String sourceFile, Common::String destFile) { +void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile) { Common::File f; f.open(sourceFile); byte* buffer = new byte[f.size()]; @@ -68,6 +68,138 @@ void trimCommentsAndWhiteSpace(Common::String *string) { string->trim(); } + +void tryToDumpLine(const Common::String &key, + Common::String &line, + Common::HashMap *count, + Common::HashMap *fileAlreadyUsed, + Common::DumpFile &output) { + const byte numberOfExamplesPerType = 8; + + if ((*count)[key] < numberOfExamplesPerType && !(*fileAlreadyUsed)[key]) { + output.writeString(line); + output.writeByte('\n'); + (*count)[key]++; + (*fileAlreadyUsed)[key] = true; + } +} + +/** + * 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) { + + + 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 iter = fileAlreadyUsed.begin(); iter != fileAlreadyUsed.end(); ++iter) { + (*iter)._value = false; + } + } + + output.close(); } } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 5e83c47721..6fb94f8725 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -37,7 +37,7 @@ #include "graphics/decoders/tga.h" -#include "zvision/tests.h" +#include "zvision/utility.h" namespace ZVision { @@ -106,7 +106,8 @@ void ZVision::initialize() { Common::Error ZVision::run() { initialize(); - tests(); + dumpEveryResultAction("resultActions.txt"); + debug("dump finished"); // Main loop uint32 currentTime = _system->getMillis(); -- cgit v1.2.3 From a77ae2163b460c081f969d764bcdb6ad001396a5 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 6 Jul 2013 00:29:15 -0500 Subject: ZVISION: Add definitions for more ResultActions --- engines/zvision/result_action.cpp | 93 +++++++++++++++++++++++++++++++++++++++ engines/zvision/result_action.h | 93 ++++++++++++++++++++++++++++++++------- 2 files changed, 169 insertions(+), 17 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/result_action.cpp b/engines/zvision/result_action.cpp index 4721c5bd61..c61fcca398 100644 --- a/engines/zvision/result_action.cpp +++ b/engines/zvision/result_action.cpp @@ -27,6 +27,7 @@ namespace ZVision { +////////////////////////////////////////////////////////////////////////////// // ActionAdd ////////////////////////////////////////////////////////////////////////////// @@ -40,6 +41,7 @@ bool ActionAdd::execute(ZVision *zVision) { } +////////////////////////////////////////////////////////////////////////////// // ActionAssign ////////////////////////////////////////////////////////////////////////////// @@ -53,6 +55,83 @@ bool ActionAssign::execute(ZVision *zVision) { } +////////////////////////////////////////////////////////////////////////////// +// ActionAttenuate +////////////////////////////////////////////////////////////////////////////// + +ActionAttenuate::ActionAttenuate(Common::String line) { + sscanf(line.c_str(), ":assign(%u, %hd)", &_key, &_attenuation); +} + +bool ActionAttenuate::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionChangeLocation +////////////////////////////////////////////////////////////////////////////// + +ActionChangeLocation::ActionChangeLocation(Common::String line) { + sscanf(line.c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); +} + +bool ActionChangeLocation::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionCrossfade +////////////////////////////////////////////////////////////////////////////// + +ActionCrossfade::ActionCrossfade(Common::String line) { + sscanf(line.c_str(), + ":crossfade(%u %u %hhu %hhu %hhu %hhu %hu)", + &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); +} + +bool ActionCrossfade::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionPreloadAnimation +////////////////////////////////////////////////////////////////////////////// + +ActionPreloadAnimation::ActionPreloadAnimation(Common::String line) { + // The two %*hhu are always 0 and dont seem to have a use + sscanf(line.c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); +} + +bool ActionPreloadAnimation::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionPlayAnimation +////////////////////////////////////////////////////////////////////////////// + +ActionPlayAnimation::ActionPlayAnimation(Common::String line) { + // The two %*hhu are always 0 and dont seem to have a use + sscanf(line.c_str(), + ":animplay:%u(%s %u %u %u %u %u %u %hhu %*hhu %*hhu %u %hhu)", + &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); +} + +bool ActionPlayAnimation::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// // ActionRandom ////////////////////////////////////////////////////////////////////////////// @@ -66,4 +145,18 @@ bool ActionRandom::execute(ZVision *zVision) { return true; } + +////////////////////////////////////////////////////////////////////////////// +// ActionTimer +////////////////////////////////////////////////////////////////////////////// + +ActionTimer::ActionTimer(Common::String line) { + sscanf(line.c_str(), ":timer:%u(%hu)", &_key, &_time); +} + +bool ActionTimer::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/result_action.h b/engines/zvision/result_action.h index fbf8e7f019..a58ef68e34 100644 --- a/engines/zvision/result_action.h +++ b/engines/zvision/result_action.h @@ -40,13 +40,6 @@ public: // The different types of actions -// ADD, -// ANIM_PLAY, -// ANIM_PRELOAD, -// ANIM_UNLOAD, -// ATTENUATE, -// ASSIGN, -// CHANGE_LOCATION, // CROSSFADE, // DEBUG, // DELAY_RENDER, @@ -76,7 +69,6 @@ public: // STOP, // STREAM_VIDEO, // SYNC_SOUND, -// TIMER, // TTY_TEXT, // UNIVERSE_MUSIC, @@ -90,34 +82,91 @@ private: byte _value; }; -class ActionPlayAnimation : public ResultAction { +class ActionAssign : public ResultAction { public: - ActionPlayAnimation(Common::String line); + ActionAssign(Common::String line); bool execute(ZVision *zVision); + +private: + uint32 _key; + byte _value; }; -class ActionPreloadAnimation : public ResultAction { +class ActionAttenuate : public ResultAction { public: - ActionPreloadAnimation(Common::String line); + ActionAttenuate(Common::String line); bool execute(ZVision *zVision); + +private: + uint32 _key; + int16 _attenuation; }; -class ActionAttenuate : public ResultAction { +class ActionChangeLocation : public ResultAction { public: - ActionAttenuate(Common::String line); + ActionChangeLocation(Common::String line); bool execute(ZVision *zVision); + +private: + char _world; + char _room; + char _nodeview[2]; + int16 _x; }; -class ActionAssign : public ResultAction { +class ActionCrossfade : public ResultAction { public: - ActionAssign(Common::String line); + ActionCrossfade(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _keyOne; + uint32 _keyTwo; + byte _oneStartVolume; + byte _twoStartVolume; + byte _oneEndVolume; + byte _twoEndVolume; + uint16 _timeInMillis; +}; + +class ActionPlayAnimation : public ResultAction { +public: + ActionPlayAnimation(Common::String line); bool execute(ZVision *zVision); private: uint32 _key; - byte _value; + Common::String _fileName; + uint32 _x; + uint32 _y; + uint32 _width; + uint32 _height; + uint32 _start; + uint32 _end; + uint32 _mask; + byte _framerate; + bool _loop; }; +class ActionPreloadAnimation : public ResultAction { +public: + ActionPreloadAnimation(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + Common::String _fileName; + uint32 _mask; + byte _framerate; +}; + +// TODO: See if this exists in ZGI. It doesn't in ZNem +//class ActionUnloadAnimation : public ResultAction { +//public: +// ActionUnloadAnimation(Common::String line); +// bool execute(ZVision *zVision); +//}; + class ActionRandom : public ResultAction { public: ActionRandom(Common::String line); @@ -128,6 +177,16 @@ private: uint32 _max; }; +class ActionTimer : public ResultAction { +public: + ActionTimer(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + uint32 _time; +}; + } // End of namespace ZVision #endif -- cgit v1.2.3 From 42092369948af8499b980b320b09911b53c10b3d Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 6 Jul 2013 01:52:45 -0500 Subject: ZVISION: Create debug console and apply console logic to main loop --- engines/zvision/console.cpp | 35 +++++++++++++++++++++++++++++++++++ engines/zvision/console.h | 42 ++++++++++++++++++++++++++++++++++++++++++ engines/zvision/events.cpp | 7 ++++--- engines/zvision/zvision.cpp | 11 +++++++---- engines/zvision/zvision.h | 7 ------- 5 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 engines/zvision/console.cpp create mode 100644 engines/zvision/console.h (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp new file mode 100644 index 0000000000..a26dba9d6d --- /dev/null +++ b/engines/zvision/console.cpp @@ -0,0 +1,35 @@ +/* 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/scummsys.h" + +#include "gui/debugger.h" + +#include "zvision/console.h" +#include "zvision/zvision.h" + +namespace ZVision { + + Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { + } + +} // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h new file mode 100644 index 0000000000..c91b362451 --- /dev/null +++ b/engines/zvision/console.h @@ -0,0 +1,42 @@ +/* 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 ZVISION_CONSOLE_H +#define ZVISION_CONSOLE_H + +#include "gui/debugger.h" + +namespace ZVision { + + class ZVision; + + class Console : public GUI::Debugger { + public: + Console(ZVision *engine); + virtual ~Console() {} + + private: + ZVision *_engine; + }; + +} // End of namespace ZVision +#endif diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 8d10485ddf..cb1ef53248 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -22,7 +22,8 @@ #include "common/scummsys.h" -#include "zvision.h" +#include "zvision/zvision.h" +#include "zvision/console.h" #include "common/EventRecorder.h" @@ -50,8 +51,8 @@ void ZVision::processEvents() { case Common::KEYCODE_d: if (_event.kbd.hasFlags(Common::KBD_CTRL)) { // Start the debugger - getDebugger()->attach(); - getDebugger()->onFrame(); + _console->attach(); + _console->onFrame(); } break; diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 6fb94f8725..7a07b59b71 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -25,6 +25,7 @@ #include "common/config-manager.h" #include "common/debug.h" #include "common/debug-channels.h" +#include "common/textconsole.h" #include "common/error.h" #include "common/system.h" #include "common/file.h" @@ -32,11 +33,10 @@ #include "engines/util.h" #include "zvision/zvision.h" +#include "zvision/console.h" #include "zvision/script_manager.h" #include "zvision/zfs_archive.h" -#include "graphics/decoders/tga.h" - #include "zvision/utility.h" namespace ZVision { @@ -73,6 +73,7 @@ ZVision::~ZVision() { debug("ZVision::~ZVision"); // Dispose of resources + delete _console; delete _scriptManager; delete _rnd; @@ -124,9 +125,11 @@ Common::Error ZVision::run() { updateScripts(); updateAnimations(deltaTime); - if (_needsScreenUpdate) - { + + + if (_needsScreenUpdate || _console->isActive()) { _system->updateScreen(); + _needsScreenUpdate = false; } // Calculate the frame delay based off a desired frame rate diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 0053fe5a9e..9dd36662f7 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -83,13 +83,6 @@ private: void updateScripts(); void updateAnimations(uint32 detaTimeMillis); }; - -// Example console class -class Console : public GUI::Debugger { -public: - Console(ZVision *vm) {} - virtual ~Console(void) {} -}; } // End of namespace ZVision -- cgit v1.2.3 From 46865dc39414a6e8123c41faa287c03270d7a6da Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 6 Jul 2013 01:54:05 -0500 Subject: ZVISION: Create renderImageToScreen method and add a console command for it --- engines/zvision/console.cpp | 11 ++++++++++ engines/zvision/console.h | 2 ++ engines/zvision/image.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/zvision.h | 1 + 4 files changed, 67 insertions(+) create mode 100644 engines/zvision/image.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index a26dba9d6d..d9d4182646 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -30,6 +30,17 @@ namespace ZVision { Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { + DCmd_Register("loadimage", WRAP_METHOD(Console, cmdLoadImage)); + } + + bool Console::cmdLoadImage(int argc, const char **argv) { + if (argc != 6) { + DebugPrintf("Use loadimage to load an image to the screen"); + return false; + } + _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5])); + + return true; } } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index c91b362451..c341b8d226 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -36,6 +36,8 @@ namespace ZVision { private: ZVision *_engine; + + bool cmdLoadImage(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp new file mode 100644 index 0000000000..95fed0c73c --- /dev/null +++ b/engines/zvision/image.cpp @@ -0,0 +1,53 @@ +/* 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/scummsys.h" + +#include "common/file.h" +#include "common/system.h" + +#include "graphics/decoders/tga.h" + +#include "zvision/zvision.h" + +namespace ZVision { + +void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y, uint32 width, uint32 height) { + Common::File file; + + if (file.open(fileName)) { + Graphics::TGADecoder tga; + if (!tga.loadStream(file)) + error("Error while reading TGA image"); + file.close(); + + const Graphics::Surface *tgaSurface = tga.getSurface(); + + _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, width, height); + + tga.destroy(); + + _needsScreenUpdate = true; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 9dd36662f7..7ff03ca719 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -71,6 +71,7 @@ public: virtual Common::Error run(); ScriptManager *getScriptManager() const; Common::RandomSource *getRandomSource() const; + void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y, uint32 width, uint32 height); private: void initialize(); -- cgit v1.2.3 From 540dde67db3dcf00f336ea772c0c51701675ece8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 6 Jul 2013 01:55:31 -0500 Subject: ZVISION: Cleanup dump method from run() --- engines/zvision/zvision.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 7a07b59b71..4653b30346 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -107,9 +107,6 @@ void ZVision::initialize() { Common::Error ZVision::run() { initialize(); - dumpEveryResultAction("resultActions.txt"); - debug("dump finished"); - // Main loop uint32 currentTime = _system->getMillis(); uint32 lastTime = currentTime; @@ -125,8 +122,6 @@ Common::Error ZVision::run() { updateScripts(); updateAnimations(deltaTime); - - if (_needsScreenUpdate || _console->isActive()) { _system->updateScreen(); _needsScreenUpdate = false; -- cgit v1.2.3 From c882f796950c4ada93b5ea85c69b62f2613b0aea Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 7 Jul 2013 16:29:47 +0300 Subject: ZVISION: Remove direct inclusion of stdio.h --- engines/zvision/scr_file_handling.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 285e635c61..a0ecf6bb4c 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -22,8 +22,6 @@ #include "common/scummsys.h" -#include - #include "zvision/script_manager.h" #include "zvision/utility.h" #include "zvision/puzzle.h" -- cgit v1.2.3 From 258ecb0aebc21d84c2e81b9b82e9c49a24e6d41b Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 7 Jul 2013 16:32:38 +0300 Subject: ZVISION: Remove nonstandard C type declaration from the StateFlags enum --- engines/zvision/puzzle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index fd9c61e8bc..d3b7536e8d 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -52,7 +52,7 @@ struct Criteria { bool isArgumentAnId; }; -enum StateFlags : byte { +enum StateFlags { ONCE_PER_INST = 0x01, DO_ME_NOW = 0x02, DISABLED = 0x04 -- cgit v1.2.3 From a8e5e1e2dbd8a3fcf438966383172866a90b835e Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 6 Jul 2013 12:30:54 -0500 Subject: ZVISION: Rename result_action.h/.cpp files to actions.h/.cpp --- engines/zvision/actions.cpp | 162 ++++++++++++++++++++++++++++++++ engines/zvision/actions.h | 192 ++++++++++++++++++++++++++++++++++++++ engines/zvision/puzzle.h | 2 +- engines/zvision/result_action.cpp | 162 -------------------------------- engines/zvision/result_action.h | 192 -------------------------------------- engines/zvision/script_manager.h | 2 +- 6 files changed, 356 insertions(+), 356 deletions(-) create mode 100644 engines/zvision/actions.cpp create mode 100644 engines/zvision/actions.h delete mode 100644 engines/zvision/result_action.cpp delete mode 100644 engines/zvision/result_action.h (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp new file mode 100644 index 0000000000..23f7f166c8 --- /dev/null +++ b/engines/zvision/actions.cpp @@ -0,0 +1,162 @@ +/* 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/scummsys.h" + +#include "zvision/actions.h" +#include "zvision/zvision.h" + +namespace ZVision { + +////////////////////////////////////////////////////////////////////////////// +// ActionAdd +////////////////////////////////////////////////////////////////////////////// + +ActionAdd::ActionAdd(Common::String line) { + sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); +} + +bool ActionAdd::execute(ZVision *zVision) { + zVision->getScriptManager()->addToStateValue(_key, _value); + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionAssign +////////////////////////////////////////////////////////////////////////////// + +ActionAssign::ActionAssign(Common::String line) { + sscanf(line.c_str(), ":assign(%u, %hhu)", &_key, &_value); +} + +bool ActionAssign::execute(ZVision *zVision) { + zVision->getScriptManager()->setStateValue(_key, _value); + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionAttenuate +////////////////////////////////////////////////////////////////////////////// + +ActionAttenuate::ActionAttenuate(Common::String line) { + sscanf(line.c_str(), ":assign(%u, %hd)", &_key, &_attenuation); +} + +bool ActionAttenuate::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionChangeLocation +////////////////////////////////////////////////////////////////////////////// + +ActionChangeLocation::ActionChangeLocation(Common::String line) { + sscanf(line.c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); +} + +bool ActionChangeLocation::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionCrossfade +////////////////////////////////////////////////////////////////////////////// + +ActionCrossfade::ActionCrossfade(Common::String line) { + sscanf(line.c_str(), + ":crossfade(%u %u %hhu %hhu %hhu %hhu %hu)", + &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); +} + +bool ActionCrossfade::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionPreloadAnimation +////////////////////////////////////////////////////////////////////////////// + +ActionPreloadAnimation::ActionPreloadAnimation(Common::String line) { + // The two %*hhu are always 0 and dont seem to have a use + sscanf(line.c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); +} + +bool ActionPreloadAnimation::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionPlayAnimation +////////////////////////////////////////////////////////////////////////////// + +ActionPlayAnimation::ActionPlayAnimation(Common::String line) { + // The two %*hhu are always 0 and dont seem to have a use + sscanf(line.c_str(), + ":animplay:%u(%s %u %u %u %u %u %u %hhu %*hhu %*hhu %u %hhu)", + &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); +} + +bool ActionPlayAnimation::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionRandom +////////////////////////////////////////////////////////////////////////////// + +ActionRandom::ActionRandom(Common::String line) { + sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); +} + +bool ActionRandom::execute(ZVision *zVision) { + uint32 randNumber = zVision->getRandomSource()->getRandomNumber(_max); + zVision->getScriptManager()->setStateValue(_key, randNumber); + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionTimer +////////////////////////////////////////////////////////////////////////////// + +ActionTimer::ActionTimer(Common::String line) { + sscanf(line.c_str(), ":timer:%u(%hu)", &_key, &_time); +} + +bool ActionTimer::execute(ZVision *zVision) { + // TODO: Implement + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h new file mode 100644 index 0000000000..a58ef68e34 --- /dev/null +++ b/engines/zvision/actions.h @@ -0,0 +1,192 @@ +/* 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 ZVISION_RESULT_ACTION_H +#define ZVISION_RESULT_ACTION_H + +#include "common/scummsys.h" + +#include "common/str.h" + +namespace ZVision { + +// Forward declaration of ZVision. This file is included before ZVision is declared +class ZVision; + +class ResultAction { +public: + virtual ~ResultAction() {} + virtual bool execute(ZVision *zVision) = 0; +}; + + +// The different types of actions +// CROSSFADE, +// DEBUG, +// DELAY_RENDER, +// DISABLE_CONTROL, +// DISABLE_VENUS, +// DISPLAY_MESSAGE, +// DISSOLVE, +// DISTORT, +// ENABLE_CONTROL, +// FLUSH_MOUSE_EVENTS, +// INVENTORY, +// KILL, +// MENU_BAR_ENABLE, +// MUSIC, +// PAN_TRACK, +// PLAY_PRELOAD, +// PREFERENCES, +// QUIT, +// RANDOM, +// REGION, +// RESTORE_GAME, +// ROTATE_TO, +// SAVE_GAME, +// SET_PARTIAL_SCREEN, +// SET_SCREEN, +// SET_VENUS, +// STOP, +// STREAM_VIDEO, +// SYNC_SOUND, +// TTY_TEXT, +// UNIVERSE_MUSIC, + +class ActionAdd : public ResultAction { +public: + ActionAdd(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + byte _value; +}; + +class ActionAssign : public ResultAction { +public: + ActionAssign(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + byte _value; +}; + +class ActionAttenuate : public ResultAction { +public: + ActionAttenuate(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + int16 _attenuation; +}; + +class ActionChangeLocation : public ResultAction { +public: + ActionChangeLocation(Common::String line); + bool execute(ZVision *zVision); + +private: + char _world; + char _room; + char _nodeview[2]; + int16 _x; +}; + +class ActionCrossfade : public ResultAction { +public: + ActionCrossfade(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _keyOne; + uint32 _keyTwo; + byte _oneStartVolume; + byte _twoStartVolume; + byte _oneEndVolume; + byte _twoEndVolume; + uint16 _timeInMillis; +}; + +class ActionPlayAnimation : public ResultAction { +public: + ActionPlayAnimation(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + Common::String _fileName; + uint32 _x; + uint32 _y; + uint32 _width; + uint32 _height; + uint32 _start; + uint32 _end; + uint32 _mask; + byte _framerate; + bool _loop; +}; + +class ActionPreloadAnimation : public ResultAction { +public: + ActionPreloadAnimation(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + Common::String _fileName; + uint32 _mask; + byte _framerate; +}; + +// TODO: See if this exists in ZGI. It doesn't in ZNem +//class ActionUnloadAnimation : public ResultAction { +//public: +// ActionUnloadAnimation(Common::String line); +// bool execute(ZVision *zVision); +//}; + +class ActionRandom : public ResultAction { +public: + ActionRandom(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + uint32 _max; +}; + +class ActionTimer : public ResultAction { +public: + ActionTimer(Common::String line); + bool execute(ZVision *zVision); + +private: + uint32 _key; + uint32 _time; +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index d3b7536e8d..9dab606f54 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -25,7 +25,7 @@ #include "common/list.h" -#include "zvision/result_action.h" +#include "zvision/actions.h" namespace ZVision { diff --git a/engines/zvision/result_action.cpp b/engines/zvision/result_action.cpp deleted file mode 100644 index c61fcca398..0000000000 --- a/engines/zvision/result_action.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/result_action.h" -#include "zvision/zvision.h" - -namespace ZVision { - -////////////////////////////////////////////////////////////////////////////// -// ActionAdd -////////////////////////////////////////////////////////////////////////////// - -ActionAdd::ActionAdd(Common::String line) { - sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); -} - -bool ActionAdd::execute(ZVision *zVision) { - zVision->getScriptManager()->addToStateValue(_key, _value); - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionAssign -////////////////////////////////////////////////////////////////////////////// - -ActionAssign::ActionAssign(Common::String line) { - sscanf(line.c_str(), ":assign(%u, %hhu)", &_key, &_value); -} - -bool ActionAssign::execute(ZVision *zVision) { - zVision->getScriptManager()->setStateValue(_key, _value); - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionAttenuate -////////////////////////////////////////////////////////////////////////////// - -ActionAttenuate::ActionAttenuate(Common::String line) { - sscanf(line.c_str(), ":assign(%u, %hd)", &_key, &_attenuation); -} - -bool ActionAttenuate::execute(ZVision *zVision) { - // TODO: Implement - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionChangeLocation -////////////////////////////////////////////////////////////////////////////// - -ActionChangeLocation::ActionChangeLocation(Common::String line) { - sscanf(line.c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); -} - -bool ActionChangeLocation::execute(ZVision *zVision) { - // TODO: Implement - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionCrossfade -////////////////////////////////////////////////////////////////////////////// - -ActionCrossfade::ActionCrossfade(Common::String line) { - sscanf(line.c_str(), - ":crossfade(%u %u %hhu %hhu %hhu %hhu %hu)", - &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); -} - -bool ActionCrossfade::execute(ZVision *zVision) { - // TODO: Implement - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionPreloadAnimation -////////////////////////////////////////////////////////////////////////////// - -ActionPreloadAnimation::ActionPreloadAnimation(Common::String line) { - // The two %*hhu are always 0 and dont seem to have a use - sscanf(line.c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); -} - -bool ActionPreloadAnimation::execute(ZVision *zVision) { - // TODO: Implement - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionPlayAnimation -////////////////////////////////////////////////////////////////////////////// - -ActionPlayAnimation::ActionPlayAnimation(Common::String line) { - // The two %*hhu are always 0 and dont seem to have a use - sscanf(line.c_str(), - ":animplay:%u(%s %u %u %u %u %u %u %hhu %*hhu %*hhu %u %hhu)", - &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); -} - -bool ActionPlayAnimation::execute(ZVision *zVision) { - // TODO: Implement - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionRandom -////////////////////////////////////////////////////////////////////////////// - -ActionRandom::ActionRandom(Common::String line) { - sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); -} - -bool ActionRandom::execute(ZVision *zVision) { - uint32 randNumber = zVision->getRandomSource()->getRandomNumber(_max); - zVision->getScriptManager()->setStateValue(_key, randNumber); - return true; -} - - -////////////////////////////////////////////////////////////////////////////// -// ActionTimer -////////////////////////////////////////////////////////////////////////////// - -ActionTimer::ActionTimer(Common::String line) { - sscanf(line.c_str(), ":timer:%u(%hu)", &_key, &_time); -} - -bool ActionTimer::execute(ZVision *zVision) { - // TODO: Implement - return true; -} - -} // End of namespace ZVision diff --git a/engines/zvision/result_action.h b/engines/zvision/result_action.h deleted file mode 100644 index a58ef68e34..0000000000 --- a/engines/zvision/result_action.h +++ /dev/null @@ -1,192 +0,0 @@ -/* 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 ZVISION_RESULT_ACTION_H -#define ZVISION_RESULT_ACTION_H - -#include "common/scummsys.h" - -#include "common/str.h" - -namespace ZVision { - -// Forward declaration of ZVision. This file is included before ZVision is declared -class ZVision; - -class ResultAction { -public: - virtual ~ResultAction() {} - virtual bool execute(ZVision *zVision) = 0; -}; - - -// The different types of actions -// CROSSFADE, -// DEBUG, -// DELAY_RENDER, -// DISABLE_CONTROL, -// DISABLE_VENUS, -// DISPLAY_MESSAGE, -// DISSOLVE, -// DISTORT, -// ENABLE_CONTROL, -// FLUSH_MOUSE_EVENTS, -// INVENTORY, -// KILL, -// MENU_BAR_ENABLE, -// MUSIC, -// PAN_TRACK, -// PLAY_PRELOAD, -// PREFERENCES, -// QUIT, -// RANDOM, -// REGION, -// RESTORE_GAME, -// ROTATE_TO, -// SAVE_GAME, -// SET_PARTIAL_SCREEN, -// SET_SCREEN, -// SET_VENUS, -// STOP, -// STREAM_VIDEO, -// SYNC_SOUND, -// TTY_TEXT, -// UNIVERSE_MUSIC, - -class ActionAdd : public ResultAction { -public: - ActionAdd(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - byte _value; -}; - -class ActionAssign : public ResultAction { -public: - ActionAssign(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - byte _value; -}; - -class ActionAttenuate : public ResultAction { -public: - ActionAttenuate(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - int16 _attenuation; -}; - -class ActionChangeLocation : public ResultAction { -public: - ActionChangeLocation(Common::String line); - bool execute(ZVision *zVision); - -private: - char _world; - char _room; - char _nodeview[2]; - int16 _x; -}; - -class ActionCrossfade : public ResultAction { -public: - ActionCrossfade(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _keyOne; - uint32 _keyTwo; - byte _oneStartVolume; - byte _twoStartVolume; - byte _oneEndVolume; - byte _twoEndVolume; - uint16 _timeInMillis; -}; - -class ActionPlayAnimation : public ResultAction { -public: - ActionPlayAnimation(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - Common::String _fileName; - uint32 _x; - uint32 _y; - uint32 _width; - uint32 _height; - uint32 _start; - uint32 _end; - uint32 _mask; - byte _framerate; - bool _loop; -}; - -class ActionPreloadAnimation : public ResultAction { -public: - ActionPreloadAnimation(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - Common::String _fileName; - uint32 _mask; - byte _framerate; -}; - -// TODO: See if this exists in ZGI. It doesn't in ZNem -//class ActionUnloadAnimation : public ResultAction { -//public: -// ActionUnloadAnimation(Common::String line); -// bool execute(ZVision *zVision); -//}; - -class ActionRandom : public ResultAction { -public: - ActionRandom(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - uint32 _max; -}; - -class ActionTimer : public ResultAction { -public: - ActionTimer(Common::String line); - bool execute(ZVision *zVision); - -private: - uint32 _key; - uint32 _time; -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 173705edf5..f02073b4c6 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -29,7 +29,7 @@ #include "zvision/puzzle.h" #include "zvision/control.h" -#include "zvision/result_action.h" +#include "zvision/actions.h" namespace ZVision { -- cgit v1.2.3 From fa365dffce5036a6f82e8a4df212a9a424f522bd Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 6 Jul 2013 16:15:10 -0500 Subject: ZVISION: Change #include scummsys.h to types.h --- engines/zvision/control.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index df01544bfc..1f59478b4c 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -23,7 +23,7 @@ #ifndef ZVISION_CONTROL_H #define ZVISION_CONTROL_H -#include "common/scummsys.h" +#include "common/types.h" namespace ZVision { -- cgit v1.2.3 From 89693d4074091bfb998fc6fbdbfe585f53a6ad13 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 7 Jul 2013 10:35:00 -0500 Subject: ZVISION: Create class for decompressing and reading LZSS --- engines/zvision/lzss_read_stream.cpp | 134 +++++++++++++++++++++++++++++++++++ engines/zvision/lzss_read_stream.h | 75 ++++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 engines/zvision/lzss_read_stream.cpp create mode 100644 engines/zvision/lzss_read_stream.h (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp new file mode 100644 index 0000000000..69b49c596c --- /dev/null +++ b/engines/zvision/lzss_read_stream.cpp @@ -0,0 +1,134 @@ +/* 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/scummsys.h" + +#include "zvision/lzss_read_stream.h" + +namespace ZVision { + +LzssReadStream::LzssReadStream(Common::SeekableReadStream *source, bool stream, uint32 decompressedSize) + : _source(source), + // It's convention to set the starting cursor position to blockSize - 16 + _windowCursor(0x0FEE), + _readCursor(0) { + // Clear the window to null + memset(_window, 0, blockSize); + + // Reserve space in the destination buffer + // TODO: Make a better guess + if (decompressedSize == npos) { + decompressedSize = source->size(); + } + _destination.reserve(decompressedSize); + + if (stream) + decompressBytes(blockSize); + else + decompressAll(); +} + +void LzssReadStream::decompressBytes(uint32 numberOfBytes) { + uint32 bytesRead = 0; + + while (!_source->eos() && bytesRead <= numberOfBytes) { + byte flagbyte = _source->readByte(); + byte mask = 1; + + for (uint32 i = 0; i < 8; i++) { + if (!_source->eos()) { + if ((flagbyte & mask) == mask) + { + byte data = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + _window[_windowCursor] = data; + _destination.push_back(data); + + // Increment and wrap the window cursor + _windowCursor = (_windowCursor + 1) & 0xFFF; + } + else + { + byte low = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + byte high = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + uint16 length = (high & 0xF) + 2; + uint16 offset = low | ((high & 0xF0)<<4); + + for(byte j = 0; j <= length; j++) + { + byte temp = _window[(offset + j) & 0xFFF]; + _window[_windowCursor] = temp; + _destination.push_back(temp); + _windowCursor = (_windowCursor + 1) & 0xFFF; + } + }; + + mask = mask << 1; + } + } + } +} + +void LzssReadStream::decompressAll() { + decompressBytes(_source->size()); +} + +bool LzssReadStream::eos() const { + // Make sure that we've read all of the source + return _readCursor >= _destination.size() && _source->eos(); +} + +uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) { + // Check if there are enough bytes available + // If not, keep decompressing until we have enough bytes or until we reach EOS + while (dataSize > _destination.size() - _readCursor) { + // Check if we can read any more data from source + if (_source->eos()) { + dataSize = _destination.size() - _readCursor; + break; + } + + decompressBytes(blockSize); + } + + memcpy(dataPtr, _destination.begin() + _readCursor, dataSize); + _readCursor += dataSize; + + return dataSize; +} + +uint32 LzssReadStream::currentSize() const { + return _destination.size(); +} + +} // End of namespace ZVision diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h new file mode 100644 index 0000000000..7e6511a5a9 --- /dev/null +++ b/engines/zvision/lzss_read_stream.h @@ -0,0 +1,75 @@ +/* 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 ZVISION_LZSS_STREAM_H +#define ZVISION_LZSS_STREAM_H + +#include "common/types.h" +#include "common/stream.h" +#include "common/memstream.h" +#include "common/array.h" + +namespace ZVision { + +class LzssReadStream : public Common::ReadStream { +public: + /** + * A class that decompresses LZSS data and implements ReadStream for easy access + * to the decompiled data. It can either decompress all the data in the beginning + * or decompress as needed by read(). + * + * @param source The source data + * @param stream Decompress the data as needed (true) or all at once (false) + * @param decompressedSize The size of the decompressed data. If npos, the class will choose a size and grow as needed + */ + LzssReadStream(Common::SeekableReadStream *source, bool stream = true, uint32 decompressedSize = npos); + +public: + static const uint32 npos = 0xFFFFFFFFu; + static const uint16 blockSize = 0x1000u; + +private: + Common::SeekableReadStream *_source; + Common::Array _destination; + char _window[blockSize]; + uint16 _windowCursor; + uint32 _readCursor; + +public: + bool eos() const; + uint32 read(void *dataPtr, uint32 dataSize); + uint32 currentSize() const; + +private: + /** + * Decompress the next from the source stream. Or until EOS + * + * @param numberOfBytes How many bytes to decompress. This is a count of source bytes, not destination bytes + */ + void decompressBytes(uint32 numberOfBytes); + /** Decompress all of the source stream. */ + void decompressAll(); +}; + +} + +#endif -- cgit v1.2.3 From 399e512be232746f956b6be52b8387b52114d35b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 7 Jul 2013 10:35:56 -0500 Subject: ZVISION: Update renderImageToScreen to handle TGZ image files --- engines/zvision/console.cpp | 6 +++--- engines/zvision/image.cpp | 46 +++++++++++++++++++++++++++++++++++++-------- engines/zvision/zvision.h | 2 +- 3 files changed, 42 insertions(+), 12 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index d9d4182646..3af67408cb 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -34,11 +34,11 @@ namespace ZVision { } bool Console::cmdLoadImage(int argc, const char **argv) { - if (argc != 6) { - DebugPrintf("Use loadimage to load an image to the screen"); + if (argc != 4) { + DebugPrintf("Use loadimage to load an image to the screen"); return false; } - _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5])); + _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); return true; } diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp index 95fed0c73c..1463401e0f 100644 --- a/engines/zvision/image.cpp +++ b/engines/zvision/image.cpp @@ -28,25 +28,55 @@ #include "graphics/decoders/tga.h" #include "zvision/zvision.h" +#include "zvision/lzss_read_stream.h" namespace ZVision { -void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y, uint32 width, uint32 height) { +void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { Common::File file; if (file.open(fileName)) { - Graphics::TGADecoder tga; - if (!tga.loadStream(file)) - error("Error while reading TGA image"); - file.close(); + // Read the magic number + // Some files are true TGA, while others are TGZ + char fileType[4]; + file.read(fileType, 4); - const Graphics::Surface *tgaSurface = tga.getSurface(); + // Check for true TGA files + if (fileType[0] == 'T' && fileType[1] == 'G' && fileType[2] == 'A' && fileType[3] == '\0') { + // Reset the cursor + file.seek(0); - _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, width, height); + // Decode + Graphics::TGADecoder tga; + if (!tga.loadStream(file)) + error("Error while reading TGA image"); + file.close(); - tga.destroy(); + const Graphics::Surface *tgaSurface = tga.getSurface(); + + _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); + + tga.destroy(); + } else { + // TGZ files have a header and then Bitmap data that is compressed with LZSS + uint32 decompressedSize = file.readSint32LE(); + uint32 width = file.readSint32LE(); + uint32 height = file.readSint32LE(); + + LzssReadStream stream(&file, false, decompressedSize); + byte *buffer = new byte[stream.currentSize()]; + stream.read(buffer, stream.currentSize()); + + //Graphics::PixelFormat format(16, 5, 6, 5, 0, 11, 5, 0, 0); + // Graphics::PixelFormat format(16, 5, 5, 5, 1, 11, 6, 1, 0); + + _system->copyRectToScreen(buffer, width * 2, x, y, width, height); + } + _needsScreenUpdate = true; + } else { + error("Could not open file %s", fileName.c_str()); } } diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 7ff03ca719..31c65a82af 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -71,7 +71,7 @@ public: virtual Common::Error run(); ScriptManager *getScriptManager() const; Common::RandomSource *getRandomSource() const; - void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y, uint32 width, uint32 height); + void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); private: void initialize(); -- cgit v1.2.3 From ca89f7679881aeb2ce056592f5d38531db2465fd Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 7 Jul 2013 11:31:05 -0500 Subject: ZVISION: Move early break out above the for loop. LzssReadStream::decompressBytes() The other code would go through each of the for loops and do nothing due to EOS. --- engines/zvision/lzss_read_stream.cpp | 74 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 69b49c596c..61b5b16393 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -52,49 +52,49 @@ void LzssReadStream::decompressBytes(uint32 numberOfBytes) { while (!_source->eos() && bytesRead <= numberOfBytes) { byte flagbyte = _source->readByte(); + if (_source->eos()) + break; byte mask = 1; for (uint32 i = 0; i < 8; i++) { - if (!_source->eos()) { - if ((flagbyte & mask) == mask) + if ((flagbyte & mask) == mask) + { + byte data = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + _window[_windowCursor] = data; + _destination.push_back(data); + + // Increment and wrap the window cursor + _windowCursor = (_windowCursor + 1) & 0xFFF; + } + else + { + byte low = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + byte high = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + uint16 length = (high & 0xF) + 2; + uint16 offset = low | ((high & 0xF0)<<4); + + for(byte j = 0; j <= length; j++) { - byte data = _source->readByte(); - bytesRead++; - if (_source->eos()) - break; - - _window[_windowCursor] = data; - _destination.push_back(data); - - // Increment and wrap the window cursor + byte temp = _window[(offset + j) & 0xFFF]; + _window[_windowCursor] = temp; + _destination.push_back(temp); _windowCursor = (_windowCursor + 1) & 0xFFF; } - else - { - byte low = _source->readByte(); - bytesRead++; - if (_source->eos()) - break; - - byte high = _source->readByte(); - bytesRead++; - if (_source->eos()) - break; - - uint16 length = (high & 0xF) + 2; - uint16 offset = low | ((high & 0xF0)<<4); - - for(byte j = 0; j <= length; j++) - { - byte temp = _window[(offset + j) & 0xFFF]; - _window[_windowCursor] = temp; - _destination.push_back(temp); - _windowCursor = (_windowCursor + 1) & 0xFFF; - } - }; - - mask = mask << 1; - } + }; + + mask = mask << 1; } } } -- cgit v1.2.3 From 00c028476513c5f41d5ac9941a7315163eeae307 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 7 Jul 2013 11:45:10 -0500 Subject: ZVISION: Conform to new eventRecorder code --- engines/zvision/events.cpp | 2 +- engines/zvision/video.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index cb1ef53248..984d59e2ba 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -24,7 +24,7 @@ #include "zvision/zvision.h" #include "zvision/console.h" -#include "common/EventRecorder.h" +#include "common/events.h" namespace ZVision { diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 4e5fe82f97..8f77554619 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -29,7 +29,7 @@ #include "zvision/zork_avi_decoder.h" #include "zvision/zork_raw.h" -#include "common/EventRecorder.h" +#include "common/events.h" #include "common/file.h" namespace ZVision { -- cgit v1.2.3 From ec7915bcb9d507979fa51d76de736f10b8060255 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 7 Jul 2013 11:45:59 -0500 Subject: ZVISION: Fix eos checking in LzssReadStream --- engines/zvision/lzss_read_stream.cpp | 14 +++++++++----- engines/zvision/lzss_read_stream.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 61b5b16393..a7cdcd9d88 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -30,7 +30,8 @@ LzssReadStream::LzssReadStream(Common::SeekableReadStream *source, bool stream, : _source(source), // It's convention to set the starting cursor position to blockSize - 16 _windowCursor(0x0FEE), - _readCursor(0) { + _readCursor(0), + _eosFlag(false) { // Clear the window to null memset(_window, 0, blockSize); @@ -104,8 +105,7 @@ void LzssReadStream::decompressAll() { } bool LzssReadStream::eos() const { - // Make sure that we've read all of the source - return _readCursor >= _destination.size() && _source->eos(); + return _eosFlag; } uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) { @@ -114,15 +114,19 @@ uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) { while (dataSize > _destination.size() - _readCursor) { // Check if we can read any more data from source if (_source->eos()) { + // Shorten the dataSize to what we have left and flag that we're at EOS dataSize = _destination.size() - _readCursor; + _eosFlag = true; break; } decompressBytes(blockSize); } - memcpy(dataPtr, _destination.begin() + _readCursor, dataSize); - _readCursor += dataSize; + if (dataSize > 0) { + memcpy(dataPtr, _destination.begin() + _readCursor, dataSize); + _readCursor += dataSize; + } return dataSize; } diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 7e6511a5a9..9ef1d6da37 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -53,6 +53,7 @@ private: char _window[blockSize]; uint16 _windowCursor; uint32 _readCursor; + bool _eosFlag; public: bool eos() const; -- cgit v1.2.3 From 811ea394862a35faacd2e87c68ef57a501f67f3c Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 7 Jul 2013 12:23:12 -0500 Subject: ZVISION: Update module.mk with current objs --- engines/zvision/module.mk | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 3dd17a2f99..3d672d96bc 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -1,8 +1,20 @@ MODULE := engines/zvision MODULE_OBJS := \ + actions.o \ + console.o \ detection.o \ + events.o \ + graphics.o \ + image.o \ + lzss_read_stream.o \ + scr_file_handling.o \ + script_manager.o \ + scripts.o \ + single_value_container.o \ + video.o \ zvision.o \ + zfs_archive.o \ zork_avi_decoder.o \ zork_raw.o -- cgit v1.2.3 From 4c7db7f5de574833b360653e423d8240d7af8fa9 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 8 Jul 2013 14:03:37 -0500 Subject: ZVISION: renderImageToScreen: Check for TGZ first instead of TGA TGA's aren't required to have a magic number in the header, but TGZ are. Therefore it's easier to identify TGZ files. --- engines/zvision/image.cpp | 82 +++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp index 1463401e0f..35ec9b3e2f 100644 --- a/engines/zvision/image.cpp +++ b/engines/zvision/image.cpp @@ -35,49 +35,49 @@ namespace ZVision { void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { Common::File file; - if (file.open(fileName)) { - // Read the magic number - // Some files are true TGA, while others are TGZ - char fileType[4]; - file.read(fileType, 4); - - // Check for true TGA files - if (fileType[0] == 'T' && fileType[1] == 'G' && fileType[2] == 'A' && fileType[3] == '\0') { - // Reset the cursor - file.seek(0); - - // Decode - Graphics::TGADecoder tga; - if (!tga.loadStream(file)) - error("Error while reading TGA image"); - file.close(); - - const Graphics::Surface *tgaSurface = tga.getSurface(); - - _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); - - tga.destroy(); - } else { - // TGZ files have a header and then Bitmap data that is compressed with LZSS - uint32 decompressedSize = file.readSint32LE(); - uint32 width = file.readSint32LE(); - uint32 height = file.readSint32LE(); - - LzssReadStream stream(&file, false, decompressedSize); - byte *buffer = new byte[stream.currentSize()]; - stream.read(buffer, stream.currentSize()); - - //Graphics::PixelFormat format(16, 5, 6, 5, 0, 11, 5, 0, 0); - // Graphics::PixelFormat format(16, 5, 5, 5, 1, 11, 6, 1, 0); - - _system->copyRectToScreen(buffer, width * 2, x, y, width, height); - } - - - _needsScreenUpdate = true; - } else { + if (!file.open(fileName)) { error("Could not open file %s", fileName.c_str()); + return; } + + // Read the magic number + // Some files are true TGA, while others are TGZ + char fileType[4]; + file.read(fileType, 4); + + // Check for TGZ files + if (fileType[0] == 'T' && fileType[1] == 'G' && fileType[2] == 'Z' && fileType[3] == '\0') { + // TGZ files have a header and then Bitmap data that is compressed with LZSS + uint32 decompressedSize = file.readSint32LE(); + uint32 width = file.readSint32LE(); + uint32 height = file.readSint32LE(); + + LzssReadStream stream(&file, false, decompressedSize); + byte *buffer = new byte[stream.currentSize()]; + stream.read(buffer, stream.currentSize()); + + //Graphics::PixelFormat format(16, 5, 6, 5, 0, 11, 5, 0, 0); + // Graphics::PixelFormat format(16, 5, 5, 5, 1, 11, 6, 1, 0); + + _system->copyRectToScreen(buffer, width * 2, x, y, width, height); + } else { + // Reset the cursor + file.seek(0); + + // Decode + Graphics::TGADecoder tga; + if (!tga.loadStream(file)) + error("Error while reading TGA image"); + file.close(); + + const Graphics::Surface *tgaSurface = tga.getSurface(); + + _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); + + tga.destroy(); + } + + _needsScreenUpdate = true; } } // End of namespace ZVision -- cgit v1.2.3 From afbcca2187c7a07e6e0853bd0befdc1e9a67dce2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 8 Jul 2013 16:04:18 -0500 Subject: ZVISION: Move engine width, height, and pixelFormat to const member variables --- engines/zvision/image.cpp | 4 ---- engines/zvision/zvision.cpp | 12 ++++++++---- engines/zvision/zvision.h | 6 ++++-- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp index 35ec9b3e2f..981308fa31 100644 --- a/engines/zvision/image.cpp +++ b/engines/zvision/image.cpp @@ -56,9 +56,6 @@ void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint byte *buffer = new byte[stream.currentSize()]; stream.read(buffer, stream.currentSize()); - //Graphics::PixelFormat format(16, 5, 6, 5, 0, 11, 5, 0, 0); - // Graphics::PixelFormat format(16, 5, 5, 5, 1, 11, 6, 1, 0); - _system->copyRectToScreen(buffer, width * 2, x, y, width, height); } else { // Reset the cursor @@ -71,7 +68,6 @@ void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint file.close(); const Graphics::Surface *tgaSurface = tga.getSurface(); - _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); tga.destroy(); diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 4653b30346..ac810d8d07 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -41,7 +41,13 @@ namespace ZVision { -ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) { +ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) + : Engine(syst), + _gameDescription(gameDesc), + _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 + _currentVideo(0), + _width(640), + _height(480) { // Put your engine in a sane state, but do nothing big yet; // in particular, do not load data from files; rather, if you // need to do such things, do them from run(). @@ -94,9 +100,7 @@ void ZVision::initialize() { SearchMan.add(name, archive); } - //Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); // ARGB8888 - Graphics::PixelFormat format = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); // RGB555 - initGraphics(640, 480, true, &format); + initGraphics(_width, _height, true, &_pixelFormat); _scriptManager->initialize(); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 31c65a82af..d18319a056 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -54,12 +54,14 @@ public: private: Console *_console; const ZVisionGameDescription *_gameDescription; + const Graphics::PixelFormat _pixelFormat; + const int _width; + const int _height; // We need random numbers Common::RandomSource *_rnd; - + // Managers ScriptManager *_scriptManager; - // To prevent allocation every time we process events Common::Event _event; -- cgit v1.2.3 From 76b2aa33ca129b1c7a626f1a043e5d828e72af57 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 8 Jul 2013 16:08:16 -0500 Subject: ZVISION: Create/refactor methods for playing video. The pixel format for videos is not the same as for the rest of the game. (Game: RGB 555, Video: RGB 565) --- engines/zvision/video.cpp | 79 ++++++++++++++++++--------------------------- engines/zvision/zvision.cpp | 10 ++++-- engines/zvision/zvision.h | 5 +++ 3 files changed, 44 insertions(+), 50 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 8f77554619..5e27e3ada1 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -21,16 +21,14 @@ */ #include "common/scummsys.h" + #include "common/system.h" +#include "engines/util.h" -#include "engines/engine.h" -#include "graphics/decoders/tga.h" +#include "graphics/surface.h" -#include "zvision/zork_avi_decoder.h" -#include "zvision/zork_raw.h" +#include "zvision/zvision.h" -#include "common/events.h" -#include "common/file.h" namespace ZVision { @@ -73,63 +71,50 @@ void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte b } } -void playVideo(Video::VideoDecoder *videoDecoder /*, VideoState videoState*/) { +void ZVision::startVideo(Video::VideoDecoder *videoDecoder) { if (!videoDecoder) return; - videoDecoder->start(); + _currentVideo = videoDecoder; - byte *scaleBuffer = 0; - byte bytesPerPixel = videoDecoder->getPixelFormat().bytesPerPixel; - uint16 width = videoDecoder->getWidth(); - uint16 height = videoDecoder->getHeight(); - uint16 pitch = videoDecoder->getWidth() * bytesPerPixel; - uint16 screenWidth = 640;//g_sci->_gfxScreen->getDisplayWidth(); - uint16 screenHeight = 480;//g_sci->_gfxScreen->getDisplayHeight(); + Common::List formats; + formats.push_back(videoDecoder->getPixelFormat()); + initGraphics(640, 480, true, formats); + _currentVideo->start(); - bool zoom2x = true; + continueVideo(); +} - if (zoom2x) { - width *= 2; - height *= 2; - pitch *= 2; - scaleBuffer = new byte[width * height * bytesPerPixel]; +void ZVision::continueVideo() { + if (_currentVideo == 0) { + warning("No video loaded. Nothing to continue"); + return; } - uint16 x, y; - - x = (screenWidth - width) / 2; - y = (screenHeight - height) / 2; + byte bytesPerPixel = _currentVideo->getPixelFormat().bytesPerPixel; + uint16 width = _currentVideo->getWidth(); + uint16 height = _currentVideo->getHeight(); + uint16 pitch = _currentVideo->getWidth() * bytesPerPixel; - bool skipVideo = false; + uint16 x = (_system->getWidth() - width) / 2; + uint16 y = (_system->getWidth() - height) / 2; - while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) { - if (videoDecoder->needsUpdate()) { - const Graphics::Surface *frame = videoDecoder->decodeNextFrame(); + if (!_currentVideo->endOfVideo()) { + if (_currentVideo->needsUpdate()) { + const Graphics::Surface *frame = _currentVideo->decodeNextFrame(); if (frame) { - if (scaleBuffer) { - scale2x((byte *)frame->pixels, scaleBuffer, videoDecoder->getWidth(), videoDecoder->getHeight(), bytesPerPixel); - g_system->copyRectToScreen(scaleBuffer, pitch, x, y, width, height); - } else { - g_system->copyRectToScreen(frame->pixels, frame->pitch, x, y, width, height); - } - - g_system->updateScreen(); - } - } + _system->copyRectToScreen(frame->pixels, pitch, x, y, width, height); - Common::Event event; - while (g_system->getEventManager()->pollEvent(event)) { - if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) - skipVideo = true; + _needsScreenUpdate = true; + } } - - g_system->delayMillis(10); + } else { + initGraphics(_width, _height, true, &_pixelFormat); + delete _currentVideo; + _currentVideo = 0; } - delete[] scaleBuffer; - delete videoDecoder; } } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index ac810d8d07..de1730f354 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -122,9 +122,13 @@ Common::Error ZVision::run() { currentTime = _system->getMillis(); uint32 deltaTime = currentTime - lastTime; lastTime = currentTime; - - updateScripts(); - updateAnimations(deltaTime); + + if (_currentVideo != 0) + continueVideo(); + else { + updateScripts(); + updateAnimations(deltaTime); + } if (_needsScreenUpdate || _console->isActive()) { _system->updateScreen(); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index d18319a056..ffda12ac1a 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -27,6 +27,8 @@ #include "common/random.h" #include "common/events.h" +#include "video/video_decoder.h" + #include "engines/engine.h" #include "zvision/script_manager.h" @@ -67,6 +69,7 @@ private: bool _needsScreenUpdate; + Video::VideoDecoder *_currentVideo; public: uint32 getFeatures() const; Common::Language getLanguage() const; @@ -74,6 +77,8 @@ public: ScriptManager *getScriptManager() const; Common::RandomSource *getRandomSource() const; void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); + void startVideo(Video::VideoDecoder *videoDecoder); + void continueVideo(); private: void initialize(); -- cgit v1.2.3 From 4398c04a7b20c5ccb5033d04430479c795f9dff8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 8 Jul 2013 16:14:02 -0500 Subject: ZVISION: Create console command for loading a video --- engines/zvision/console.cpp | 34 +++++++++++++++++++++++++--------- engines/zvision/console.h | 1 + engines/zvision/video.cpp | 1 + 3 files changed, 27 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 3af67408cb..3721c94f42 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -26,21 +26,37 @@ #include "zvision/console.h" #include "zvision/zvision.h" +#include "zvision/zork_avi_decoder.h" namespace ZVision { - Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { - DCmd_Register("loadimage", WRAP_METHOD(Console, cmdLoadImage)); +Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { + DCmd_Register("loadimage", WRAP_METHOD(Console, cmdLoadImage)); + DCmd_Register("loadvideo", WRAP_METHOD(Console, cmdLoadVideo)); +} + +bool Console::cmdLoadImage(int argc, const char **argv) { + if (argc != 4) { + DebugPrintf("Use loadimage to load an image to the screen"); + return false; } + _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); + + return true; +} - bool Console::cmdLoadImage(int argc, const char **argv) { - if (argc != 4) { - DebugPrintf("Use loadimage to load an image to the screen"); - return false; - } - _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); +bool Console::cmdLoadVideo(int argc, const char **argv) { + if (argc != 2) { + DebugPrintf("Use loadvideo to load a video to the screen"); + return false; + } - return true; + Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); + if (videoDecoder && videoDecoder->loadFile(argv[1])) { + _engine->startVideo(videoDecoder); } + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index c341b8d226..66037983ae 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -38,6 +38,7 @@ namespace ZVision { ZVision *_engine; bool cmdLoadImage(int argc, const char **argv); + bool cmdLoadVideo(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 5e27e3ada1..b5e9fa098c 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -82,6 +82,7 @@ void ZVision::startVideo(Video::VideoDecoder *videoDecoder) { initGraphics(640, 480, true, formats); _currentVideo->start(); + // Load the first frame continueVideo(); } -- cgit v1.2.3 From 0451503ecc415a7f871652040fc23e221d3e4d63 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 10 Jul 2013 18:06:10 -0500 Subject: ZVISION: Remove implicit cast between integer types --- engines/zvision/zfs_archive.cpp | 4 ++-- engines/zvision/zfs_archive.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index 85933b3240..fbfe3d3dc4 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -76,7 +76,7 @@ void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { nextOffset = stream->readUint32LE(); // Read in each entry header - for (int i = 0; i < _header.filesPerBlock; i++) { + for (uint32 i = 0; i < _header.filesPerBlock; i++) { ZfsEntryHeader entryHeader; entryHeader.name = readEntryName(stream); @@ -145,7 +145,7 @@ Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common:: return new Common::MemoryReadStream(buffer, entryHeader->size, DisposeAfterUse::YES); } -void ZfsArchive::unXor(byte *buffer, int length, const byte *xorKey) const { +void ZfsArchive::unXor(byte *buffer, uint32 length, const byte *xorKey) const { for (uint32 i = 0; i < length; i++) buffer[i] ^= xorKey[i % 4]; } diff --git a/engines/zvision/zfs_archive.h b/engines/zvision/zfs_archive.h index ccdf192571..cb371f2c87 100644 --- a/engines/zvision/zfs_archive.h +++ b/engines/zvision/zfs_archive.h @@ -113,7 +113,7 @@ private: * @param buffer The data to decode * @param length Length of buffer */ - void unXor(byte *buffer, int length, const byte *xorKey) const; + void unXor(byte *buffer, uint32 length, const byte *xorKey) const; }; } // End of namespace ZVision -- cgit v1.2.3 From 61a2fffafd708828dd6cef4dff4dc971e8541654 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 10 Jul 2013 23:13:50 -0500 Subject: ZVISION: Standardize naming conventions to fit the rest of the code base --- engines/zvision/actions.cpp | 26 +++++++++++++------------- engines/zvision/actions.h | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 23f7f166c8..9bdc6aa981 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -35,8 +35,8 @@ ActionAdd::ActionAdd(Common::String line) { sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); } -bool ActionAdd::execute(ZVision *zVision) { - zVision->getScriptManager()->addToStateValue(_key, _value); +bool ActionAdd::execute(ZVision *engine) { + engine->getScriptManager()->addToStateValue(_key, _value); return true; } @@ -49,8 +49,8 @@ ActionAssign::ActionAssign(Common::String line) { sscanf(line.c_str(), ":assign(%u, %hhu)", &_key, &_value); } -bool ActionAssign::execute(ZVision *zVision) { - zVision->getScriptManager()->setStateValue(_key, _value); +bool ActionAssign::execute(ZVision *engine) { + engine->getScriptManager()->setStateValue(_key, _value); return true; } @@ -63,7 +63,7 @@ ActionAttenuate::ActionAttenuate(Common::String line) { sscanf(line.c_str(), ":assign(%u, %hd)", &_key, &_attenuation); } -bool ActionAttenuate::execute(ZVision *zVision) { +bool ActionAttenuate::execute(ZVision *engine) { // TODO: Implement return true; } @@ -77,7 +77,7 @@ ActionChangeLocation::ActionChangeLocation(Common::String line) { sscanf(line.c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); } -bool ActionChangeLocation::execute(ZVision *zVision) { +bool ActionChangeLocation::execute(ZVision *engine) { // TODO: Implement return true; } @@ -93,7 +93,7 @@ ActionCrossfade::ActionCrossfade(Common::String line) { &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } -bool ActionCrossfade::execute(ZVision *zVision) { +bool ActionCrossfade::execute(ZVision *engine) { // TODO: Implement return true; } @@ -108,7 +108,7 @@ ActionPreloadAnimation::ActionPreloadAnimation(Common::String line) { sscanf(line.c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); } -bool ActionPreloadAnimation::execute(ZVision *zVision) { +bool ActionPreloadAnimation::execute(ZVision *engine) { // TODO: Implement return true; } @@ -125,7 +125,7 @@ ActionPlayAnimation::ActionPlayAnimation(Common::String line) { &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); } -bool ActionPlayAnimation::execute(ZVision *zVision) { +bool ActionPlayAnimation::execute(ZVision *engine) { // TODO: Implement return true; } @@ -139,9 +139,9 @@ ActionRandom::ActionRandom(Common::String line) { sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); } -bool ActionRandom::execute(ZVision *zVision) { - uint32 randNumber = zVision->getRandomSource()->getRandomNumber(_max); - zVision->getScriptManager()->setStateValue(_key, randNumber); +bool ActionRandom::execute(ZVision *engine) { + uint32 randNumber = engine->getRandomSource()->getRandomNumber(_max); + engine->getScriptManager()->setStateValue(_key, randNumber); return true; } @@ -154,8 +154,8 @@ ActionTimer::ActionTimer(Common::String line) { sscanf(line.c_str(), ":timer:%u(%hu)", &_key, &_time); } -bool ActionTimer::execute(ZVision *zVision) { // TODO: Implement +bool ActionTimer::execute(ZVision *engine) { return true; } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index a58ef68e34..aed8483ee7 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -35,7 +35,7 @@ class ZVision; class ResultAction { public: virtual ~ResultAction() {} - virtual bool execute(ZVision *zVision) = 0; + virtual bool execute(ZVision *engine) = 0; }; @@ -75,7 +75,7 @@ public: class ActionAdd : public ResultAction { public: ActionAdd(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _key; @@ -85,7 +85,7 @@ private: class ActionAssign : public ResultAction { public: ActionAssign(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _key; @@ -95,7 +95,7 @@ private: class ActionAttenuate : public ResultAction { public: ActionAttenuate(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _key; @@ -105,7 +105,7 @@ private: class ActionChangeLocation : public ResultAction { public: ActionChangeLocation(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: char _world; @@ -117,7 +117,7 @@ private: class ActionCrossfade : public ResultAction { public: ActionCrossfade(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _keyOne; @@ -132,7 +132,7 @@ private: class ActionPlayAnimation : public ResultAction { public: ActionPlayAnimation(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _key; @@ -151,7 +151,7 @@ private: class ActionPreloadAnimation : public ResultAction { public: ActionPreloadAnimation(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _key; @@ -164,13 +164,13 @@ private: //class ActionUnloadAnimation : public ResultAction { //public: // ActionUnloadAnimation(Common::String line); -// bool execute(ZVision *zVision); +// bool execute(ZVision *engine); //}; class ActionRandom : public ResultAction { public: ActionRandom(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _key; @@ -180,7 +180,7 @@ private: class ActionTimer : public ResultAction { public: ActionTimer(Common::String line); - bool execute(ZVision *zVision); + bool execute(ZVision *engine); private: uint32 _key; -- cgit v1.2.3 From 4e55d7ba9476cd47a3118ecdeb0d0618e6d32211 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:08:00 -0500 Subject: ZVISION: Clean up includes --- engines/zvision/puzzle.h | 8 ++++---- engines/zvision/scr_file_handling.cpp | 4 ++-- engines/zvision/zvision.h | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 9dab606f54..7a2755fd69 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -25,10 +25,10 @@ #include "common/list.h" -#include "zvision/actions.h" - namespace ZVision { +class ResultAction; + /** How criteria should be decided */ enum CriteriaOperator { EQUAL_TO, @@ -48,8 +48,8 @@ struct Criteria { uint32 argument; /** How to do the comparison */ CriteriaOperator criteriaOperator; - /** Whether 'argument' is the id of a global state (true) or a pure value (false) */ - bool isArgumentAnId; + /** Whether 'argument' is the key of a global state (true) or a pure value (false) */ + bool argumentIsAKey; }; enum StateFlags { diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index a0ecf6bb4c..6bf73733e5 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -111,10 +111,10 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const token = tokenizer.nextToken(); if (token.contains('[')) { sscanf(token.c_str(), "[%u]", &(criteria.argument)); - criteria.isArgumentAnId = true; + criteria.argumentIsAKey = true; } else { sscanf(token.c_str(), "%u", &(criteria.argument)); - criteria.isArgumentAnId = false; + criteria.argumentIsAKey = false; } line = stream.readLine(); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index ffda12ac1a..bec8827583 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -31,14 +31,13 @@ #include "engines/engine.h" -#include "zvision/script_manager.h" - #include "gui/debugger.h" namespace ZVision { struct ZVisionGameDescription; class Console; +class ScriptManager; // our engine debug channels enum { -- cgit v1.2.3 From 9d478206f85769e5cbe7f1eda0ec8b9ac390dbc0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:10:50 -0500 Subject: ZVISION: Move utility functions to a cpp file with declarations in a header file --- engines/zvision/utility.cpp | 180 ++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/utility.h | 149 +----------------------------------- 2 files changed, 184 insertions(+), 145 deletions(-) create mode 100644 engines/zvision/utility.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp new file mode 100644 index 0000000000..41b589d0c0 --- /dev/null +++ b/engines/zvision/utility.cpp @@ -0,0 +1,180 @@ +/* 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/scummsys.h" + +#include "zvision/utility.h" + +namespace ZVision { + +void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile) { + Common::File f; + f.open(sourceFile); + 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] == '#') { + string->erase(i); + } + } + + string->trim(); +} + +void tryToDumpLine(const Common::String &key, + Common::String &line, + Common::HashMap *count, + Common::HashMap *fileAlreadyUsed, + Common::DumpFile &output) { + const byte numberOfExamplesPerType = 8; + + if ((*count)[key] < numberOfExamplesPerType && !(*fileAlreadyUsed)[key]) { + output.writeString(line); + output.writeByte('\n'); + (*count)[key]++; + (*fileAlreadyUsed)[key] = true; + } +} + +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 iter = fileAlreadyUsed.begin(); iter != fileAlreadyUsed.end(); ++iter) { + iter->_value = false; + } + } + + output.close(); +} + +} // End of namespace ZVision diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 0b2ef2b8cd..43d28df6c9 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -26,6 +26,7 @@ #include "common/str.h" #include "common/file.h" +#include "common/array.h" namespace ZVision { @@ -36,21 +37,7 @@ namespace ZVision { * @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) { - Common::File f; - f.open(sourceFile); - byte* buffer = new byte[f.size()]; - f.read(buffer, f.size()); - - Common::DumpFile dumpFile; - dumpFile.open(destFile); - - uint32 writtenBytes = dumpFile.write(buffer, f.size()); - dumpFile.flush(); - dumpFile.close(); - - delete[] buffer; -} +void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile); /** * Removes any line comments using '#' as a sequence start. @@ -59,30 +46,7 @@ void writeFileContentsToFile(const Common::String &sourceFile, const Common::Str * * @param string The string to modify. It is modified in place */ -void trimCommentsAndWhiteSpace(Common::String *string) { - for (int i = string->size() - 1; i >= 0; i--) { - if ((*string)[i] == '#') { - string->erase(i); - } - } - - string->trim(); -} - -void tryToDumpLine(const Common::String &key, - Common::String &line, - Common::HashMap *count, - Common::HashMap *fileAlreadyUsed, - Common::DumpFile &output) { - const byte numberOfExamplesPerType = 8; - - if ((*count)[key] < numberOfExamplesPerType && !(*fileAlreadyUsed)[key]) { - output.writeString(line); - output.writeByte('\n'); - (*count)[key]++; - (*fileAlreadyUsed)[key] = true; - } -} +void trimCommentsAndWhiteSpace(Common::String *string); /** * Searches through all the .scr files and dumps 'numberOfExamplesPerType' examples of each type of ResultAction @@ -90,116 +54,11 @@ void tryToDumpLine(const Common::String &key, * * @param destFile Where to write the examples */ -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"); +void dumpEveryResultAction(const Common::String &destFile); - 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 iter = fileAlreadyUsed.begin(); iter != fileAlreadyUsed.end(); ++iter) { - (*iter)._value = false; } } - - output.close(); } } // End of namespace ZVision -- cgit v1.2.3 From d672c2c44093269ce1c0bd8107346d05f4c1b225 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:11:21 -0500 Subject: ZVISION: Remove unused methods from ZVision class --- engines/zvision/graphics.cpp | 8 -------- engines/zvision/zvision.h | 3 --- 2 files changed, 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/graphics.cpp b/engines/zvision/graphics.cpp index 7d1201c4f9..610960dd72 100644 --- a/engines/zvision/graphics.cpp +++ b/engines/zvision/graphics.cpp @@ -26,12 +26,4 @@ namespace ZVision { -void ZVision::updateScripts() { - -} - -void ZVision::updateAnimations(uint32 detaTimeMillis) { - -} - } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index bec8827583..7f5b8e3a86 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -86,9 +86,6 @@ private: void onMouseDown(const Common::Point &pos); void onMouseMove(const Common::Point &pos); void onKeyDown(uint16 keyCode); - - void updateScripts(); - void updateAnimations(uint32 detaTimeMillis); }; } // End of namespace ZVision -- cgit v1.2.3 From 3397edb4f55d2e3f0973f4ffea6668d8f5b4dbb4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:17:32 -0500 Subject: ZVISION: Add ActionNode class This class encases actions that happen over time (timer, animations, etc) Each frame, the engine calls process() on each active ActionNode --- engines/zvision/action_node.cpp | 45 ++++++++++++++++++++++++++++++++ engines/zvision/action_node.h | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 engines/zvision/action_node.cpp create mode 100644 engines/zvision/action_node.h (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.cpp b/engines/zvision/action_node.cpp new file mode 100644 index 0000000000..dec52d9615 --- /dev/null +++ b/engines/zvision/action_node.cpp @@ -0,0 +1,45 @@ +/* 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/scummsys.h" + +#include "zvision/action_node.h" +#include "zvision/zvision.h" +#include "zvision/script_manager.h" + +namespace ZVision { + +NodeTimer::NodeTimer(uint32 key, uint32 timeInSeconds) + : _key(key), _timeLeft(timeInSeconds * 1000) {} + +bool NodeTimer::process(ZVision *engine, uint32 deltaTimeInMillis) { + _timeLeft -= deltaTimeInMillis; + + if (_timeLeft <= 0) { + engine->getScriptManager()->setStateValue(_key, 0); + return true; + } + + return false; +} + +} // End of namespace ZVision diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h new file mode 100644 index 0000000000..cd5c9f3b27 --- /dev/null +++ b/engines/zvision/action_node.h @@ -0,0 +1,58 @@ +/* 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 ZVISION_ACTION_NODE_H +#define ZVISION_ACTION_NODE_H + +#include "common/types.h" + +namespace ZVision { + +class ZVision; + +class ActionNode { +public: + virtual ~ActionNode() {} + virtual bool process(ZVision *engine, uint32 deltaTimeInMillis); +}; + +class NodeTimer : public ActionNode { +public: + NodeTimer(uint32 key, uint32 timeInSeconds); + /** + * Decrement the timer by the delta time. If the timer is finished, set the status + * in _globalState and let this node be deleted + * + * @param engine Pointer to the ZVision instance + * @param deltaTimeInMillis Amount of time that has passed since the last frame + * @return Node should be deleted after this (true) or kept (false) + */ + bool process(ZVision *engine, uint32 deltaTimeInMillis); + +private: + uint32 _key; + uint32 _timeLeft; +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From ba22c838613912238196d8488a9f781f07416c77 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:18:23 -0500 Subject: ZVISION: Implement ActionTimer::execute() --- engines/zvision/actions.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 9bdc6aa981..a5b1e951aa 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -24,6 +24,8 @@ #include "zvision/actions.h" #include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/action_node.h" namespace ZVision { @@ -154,8 +156,8 @@ ActionTimer::ActionTimer(Common::String line) { sscanf(line.c_str(), ":timer:%u(%hu)", &_key, &_time); } - // TODO: Implement bool ActionTimer::execute(ZVision *engine) { + engine->getScriptManager()->addActionNode(new NodeTimer(_key, _time)); return true; } -- cgit v1.2.3 From 78daaeb583a371edddd67b5399cbc14201fe7ee1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:23:36 -0500 Subject: ZVISION: Create main containers in ScriptManager --- engines/zvision/scr_file_handling.cpp | 6 ++++-- engines/zvision/script_manager.h | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 6bf73733e5..2371c350f7 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -25,6 +25,7 @@ #include "zvision/script_manager.h" #include "zvision/utility.h" #include "zvision/puzzle.h" +#include "zvision/actions.h" #include "common/textconsole.h" #include "common/file.h" @@ -53,14 +54,15 @@ void ScriptManager::parseScrFile(Common::String fileName) { sscanf(line.c_str(),"puzzle:%u",&(puzzle.key)); parsePuzzle(puzzle, file); - _puzzles.push_back(puzzle); + _activePuzzles.push_back(puzzle); } else if (line.matchString("control:*", true)) { Control control; char controlType[20]; sscanf(line.c_str(),"control:%u %s",&(control.id), controlType); parseControl(control, file); - _controls.push_back(control); + /** Holds the currently active puzzles */ + _activeControls.push_back(control); } } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index f02073b4c6..5be4c171e0 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -26,21 +26,33 @@ #include "common/str.h" #include "common/stream.h" #include "common/hashmap.h" +#include "common/stack.h" #include "zvision/puzzle.h" #include "zvision/control.h" -#include "zvision/actions.h" namespace ZVision { +class ActionNode; + class ScriptManager { private: - /** Holds the global state variables. Optimize for fast random access */ + /** + * Holds the global state variable. Do NOT directly modify this. Use the accessors and + * mutators getStateValue() and setStateValue(). This ensures that Puzzles that reference a + * particular state key are checked after the key is modified. + */ Common::HashMap _globalState; - /** Holds the currently active puzzles. Optimize for fast iteration */ - Common::List _puzzles; - /** Holds the currently active controls. Optimize for fast iteration */ - Common::List _controls; + /** Holds the currently active ActionNodes */ + Common::List _activeNodes; + /** References _globalState keys to Puzzles */ + Common::HashMap> _referenceTable; + /** Holds the Puzzles that should be checked this frame */ + Common::Stack _puzzlesToCheck; + /** Holds the currently active puzzles */ + Common::List _activePuzzles; + /** Holds the currently active controls */ + Common::List _activeControls; public: -- cgit v1.2.3 From 9c7203c4b922845d63b00236a78e48e4f55bd633 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:25:09 -0500 Subject: ZVISION: Create utility method to remove duplicate entries from a Common::Array --- engines/zvision/utility.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 43d28df6c9..e5713fc7f4 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -56,7 +56,19 @@ void trimCommentsAndWhiteSpace(Common::String *string); */ void dumpEveryResultAction(const Common::String &destFile); +/** + * Removes all duplicate entries from container. + * + * @param container + * @return + */ +template +void removeDuplicateEntries(Common::Array *container) { + Common::sort(container->front(), container->back()); + for (int i = 0; i < container->size(); i++) { + while (container[i] == container[i +1]) { + container->remove_at(i + 1); } } } -- cgit v1.2.3 From 24dc3e1793749269daa30350a5923f51d7892efd Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:26:32 -0500 Subject: ZVISION: Create ScriptManager state handling logic --- engines/zvision/script_manager.cpp | 88 ++++++++++++++++++++++++++++++++++++++ engines/zvision/script_manager.h | 12 ++++++ engines/zvision/zvision.cpp | 6 +-- 3 files changed, 103 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 13438d4fa6..b4ad1cc003 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -22,19 +22,103 @@ #include "common/scummsys.h" +#include "common/algorithm.h" +#include "common/hashmap.h" + #include "zvision/script_manager.h" +#include "zvision/actions.h" +#include "zvision/action_node.h" +#include "zvision/utility.h" namespace ZVision { +ScriptManager::ScriptManager(ZVision *engine) : _engine(engine) {} + // TODO: Actually do something in the initialize or remove it void ScriptManager::initialize() { } +void ScriptManager::createReferenceTable() { + // Iterate through each Puzzle + for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { + Puzzle *puzzlePtr = &(*activePuzzleIter); + + // Iterate through each Criteria and add a reference from the criteria key to the Puzzle + for (Common::List::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { + _referenceTable[criteriaIter->key].push_back(puzzlePtr); + + // If the argument is a key, add a reference to it as well + if (criteriaIter->argument) + _referenceTable[criteriaIter->argument].push_back(puzzlePtr); + } + } + + // Remove duplicate entries + for (Common::HashMap>::iterator referenceTableIter; referenceTableIter != _referenceTable.end(); referenceTableIter++) { + removeDuplicateEntries(&(referenceTableIter->_value)); + } +} + +void ScriptManager::updateNodes(uint32 deltaTimeMillis) { + // If process() returns true, it means the node can be deleted + for (Common::List::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) { + if ((*iter)->process(_engine, deltaTimeMillis)) { + // Remove the node from _activeNodes, then delete it + ActionNode *node = *iter; + iter = _activeNodes.erase(iter); + delete node; + } else { + iter++; + } + } +} + +void ScriptManager::checkPuzzleCriteria() { + while (!_puzzlesToCheck.empty()) { + Puzzle *puzzle = _puzzlesToCheck.pop(); + // Check each Criteria + for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { + bool criteriaMet = false; + + // Get the value to compare against + byte argumentValue; + if ((*iter).argument) + argumentValue = getStateValue(iter->argument); + else + argumentValue = iter->argument; + + // Do the comparison + switch ((*iter).criteriaOperator) { + case EQUAL_TO: + criteriaMet = getStateValue(iter->key) == argumentValue; + break; + case NOT_EQUAL_TO: + criteriaMet = getStateValue(iter->key) != argumentValue; + break; + case GREATER_THAN: + criteriaMet = getStateValue(iter->key) > argumentValue; + break; + case LESS_THAN: + criteriaMet = getStateValue(iter->key) < argumentValue; + break; + } + + // TODO: Add logic for the different Flags (aka, ONCE_PER_INST) + if (criteriaMet) { + for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { + (*resultIter)->execute(_engine); + } + } + } + } +} + byte ScriptManager::getStateValue(uint32 key) { return _globalState[key]; } +// TODO: Add logic to check _referenceTable and add to _puzzlesToCheck if necessary void ScriptManager::setStateValue(uint32 key, byte value) { _globalState[key] = value; } @@ -43,4 +127,8 @@ void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) { _globalState[key] += valueToAdd; } +void ScriptManager::addActionNode(ActionNode *node) { + _activeNodes.push_back(node); +} + } // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 5be4c171e0..42f4bba602 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -33,10 +33,15 @@ namespace ZVision { +class ZVision; class ActionNode; class ScriptManager { +public: + ScriptManager(ZVision *engine); + private: + ZVision *_engine; /** * Holds the global state variable. Do NOT directly modify this. Use the accessors and * mutators getStateValue() and setStateValue(). This ensures that Puzzles that reference a @@ -57,11 +62,18 @@ private: public: void initialize(); + void updateNodes(uint32 deltaTimeMillis); + void checkPuzzleCriteria(); + byte getStateValue(uint32 key); void setStateValue(uint32 key, byte value); void addToStateValue(uint32 key, byte valueToAdd); + void addActionNode(ActionNode *node); + private: + void createReferenceTable(); + /** * Parses a script file into triggers and events * diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index de1730f354..c126a9ad7c 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -70,7 +70,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _rnd = new Common::RandomSource("zvision"); // Create managers - _scriptManager = new ScriptManager(); + _scriptManager = new ScriptManager(this); debug("ZVision::ZVision"); } @@ -126,8 +126,8 @@ Common::Error ZVision::run() { if (_currentVideo != 0) continueVideo(); else { - updateScripts(); - updateAnimations(deltaTime); + _scriptManager->updateNodes(deltaTime); + _scriptManager->checkPuzzleCriteria(); } if (_needsScreenUpdate || _console->isActive()) { -- cgit v1.2.3 From 29061acd4ebeef2686b2ee2ff9c97d6ee4f11e91 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 00:44:23 -0500 Subject: ZVISION: Add operator< to the Puzzle struct ScriptManager does a unique-fication of a container of Puzzles using a sort with some other logic. The sort uses operator< --- engines/zvision/puzzle.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 7a2755fd69..b3831d4665 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -64,6 +64,13 @@ struct Puzzle { // This has to be list of pointers because ResultAction is abstract Common::List resultActions; byte flags; + + // Used by the ScriptManager to allow unique-ification of _referenceTable + // The unique-ification is done by sorting, then iterating and removing duplicates + // The sort uses operator< + const bool operator<(const Puzzle &other) const { + return key < other.key; + } }; } // End of namespace ZVision -- cgit v1.2.3 From ae84e9508e846e7cfd39652f74c0816b399409e7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 11 Jul 2013 17:02:14 -0500 Subject: ZVISION: Add 2x scaling to videos --- engines/zvision/video.cpp | 18 ++++++++++++------ engines/zvision/zvision.cpp | 1 + engines/zvision/zvision.h | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index b5e9fa098c..0cca486af6 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -79,7 +79,10 @@ void ZVision::startVideo(Video::VideoDecoder *videoDecoder) { Common::List formats; formats.push_back(videoDecoder->getPixelFormat()); - initGraphics(640, 480, true, formats); + initGraphics(_width, _height, true, formats); + + _scaledVideoFrameBuffer = new byte[_currentVideo->getWidth() * _currentVideo->getHeight() * _currentVideo->getPixelFormat().bytesPerPixel * 4]; + _currentVideo->start(); // Load the first frame @@ -95,17 +98,18 @@ void ZVision::continueVideo() { byte bytesPerPixel = _currentVideo->getPixelFormat().bytesPerPixel; uint16 width = _currentVideo->getWidth(); uint16 height = _currentVideo->getHeight(); - uint16 pitch = _currentVideo->getWidth() * bytesPerPixel; + uint16 pitch = width * bytesPerPixel; - uint16 x = (_system->getWidth() - width) / 2; - uint16 y = (_system->getWidth() - height) / 2; + uint16 x = (_system->getWidth() - (width * 2)) / 2; + uint16 y = (_system->getHeight() - (height * 2)) / 2; if (!_currentVideo->endOfVideo()) { if (_currentVideo->needsUpdate()) { const Graphics::Surface *frame = _currentVideo->decodeNextFrame(); - if (frame) { - _system->copyRectToScreen(frame->pixels, pitch, x, y, width, height); + if (frame) { + scale2x(static_cast(frame->pixels), _scaledVideoFrameBuffer, width, height, bytesPerPixel); + _system->copyRectToScreen(_scaledVideoFrameBuffer, pitch * 2, x, y, width * 2, height * 2); _needsScreenUpdate = true; } @@ -114,6 +118,8 @@ void ZVision::continueVideo() { initGraphics(_width, _height, true, &_pixelFormat); delete _currentVideo; _currentVideo = 0; + delete _scaledVideoFrameBuffer; + _scaledVideoFrameBuffer = 0; } } diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index c126a9ad7c..475a453c08 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -46,6 +46,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _gameDescription(gameDesc), _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 _currentVideo(0), + _scaledVideoFrameBuffer(0), _width(640), _height(480) { // Put your engine in a sane state, but do nothing big yet; diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 7f5b8e3a86..50394a6070 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -69,6 +69,7 @@ private: bool _needsScreenUpdate; Video::VideoDecoder *_currentVideo; + byte *_scaledVideoFrameBuffer; public: uint32 getFeatures() const; Common::Language getLanguage() const; -- cgit v1.2.3 From 09358141de42a2ecb4ad487145dc52345814f8a1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 12 Jul 2013 00:44:05 -0500 Subject: ZVISION: Allow the console to stay open when errors occur --- engines/zvision/console.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 3721c94f42..f038af1232 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -38,7 +38,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { bool Console::cmdLoadImage(int argc, const char **argv) { if (argc != 4) { DebugPrintf("Use loadimage to load an image to the screen"); - return false; + return true; } _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); @@ -48,7 +48,7 @@ bool Console::cmdLoadImage(int argc, const char **argv) { bool Console::cmdLoadVideo(int argc, const char **argv) { if (argc != 2) { DebugPrintf("Use loadvideo to load a video to the screen"); - return false; + return true; } Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); -- cgit v1.2.3 From 8d2bef2936f555cbc675248838079dfe06ff562a Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 13 Jul 2013 11:34:28 -0500 Subject: ZVISION: Create console command for loading sounds --- engines/zvision/console.cpp | 24 ++++++++++++++++++++++++ engines/zvision/console.h | 1 + engines/zvision/zvision.cpp | 4 ++++ engines/zvision/zvision.h | 2 ++ 4 files changed, 31 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index f038af1232..c3be4ba0f5 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -23,16 +23,21 @@ #include "common/scummsys.h" #include "gui/debugger.h" +#include "common/file.h" +#include "common/bufferedstream.h" +#include "audio/mixer.h" #include "zvision/console.h" #include "zvision/zvision.h" #include "zvision/zork_avi_decoder.h" +#include "zvision/zork_raw.h" namespace ZVision { Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("loadimage", WRAP_METHOD(Console, cmdLoadImage)); DCmd_Register("loadvideo", WRAP_METHOD(Console, cmdLoadVideo)); + DCmd_Register("loadsound", WRAP_METHOD(Console, cmdLoadSound)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -59,4 +64,23 @@ bool Console::cmdLoadVideo(int argc, const char **argv) { return true; } +bool Console::cmdLoadSound(int argc, const char **argv) { + if (argc != 3) { + DebugPrintf("Use loadsound to load a video to the screen"); + return true; + } + + Common::File *file = new Common::File(); + if (!file->open(argv[1])) { + DebugPrintf("File does not exist"); + return true; + } + + Audio::AudioStream *soundStream = makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), atoi(argv[2]), DisposeAfterUse::YES); + Audio::SoundHandle handle; + _engine->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 66037983ae..354051d2b0 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -39,6 +39,7 @@ namespace ZVision { bool cmdLoadImage(int argc, const char **argv); bool cmdLoadVideo(int argc, const char **argv); + bool cmdLoadSound(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 475a453c08..ba08122ba5 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -154,4 +154,8 @@ Common::RandomSource *ZVision::getRandomSource() const { return _rnd; } +Audio::Mixer *ZVision::getMixer() const { + return _mixer; +} + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 50394a6070..11773a33ad 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -76,6 +76,8 @@ public: virtual Common::Error run(); ScriptManager *getScriptManager() const; Common::RandomSource *getRandomSource() const; + Audio::Mixer *getMixer() const; + void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); void startVideo(Video::VideoDecoder *videoDecoder); void continueVideo(); -- cgit v1.2.3 From 535d6a2a405118ee1e94198f8231532ec2b08bad Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 13 Jul 2013 11:35:19 -0500 Subject: ZVISION: Modify RawZorkStream to use a modified ADPCM codec --- engines/zvision/zork_raw.cpp | 209 ++++++++++++++++--------------------------- engines/zvision/zork_raw.h | 59 ++++++++++-- 2 files changed, 131 insertions(+), 137 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index d920550bc7..69d8edd8df 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -22,164 +22,113 @@ #include "common/scummsys.h" -#include "common/endian.h" +#include "common/stream.h" #include "common/memstream.h" -#include "common/textconsole.h" #include "common/util.h" - #include "audio/audiostream.h" #include "engines/zvision/zork_raw.h" namespace ZVision { -#pragma mark - -#pragma mark --- RawZorkStream --- -#pragma mark - - -/** - * This is a stream, which allows for playing raw PCM data from a stream. - */ -class RawZorkStream : public Audio::SeekableAudioStream { -public: - RawZorkStream(int rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) - : _rate(rate), _playtime(0, rate), _stream(stream, disposeStream), _endOfData(false), _buffer(0) { - // Setup our buffer for readBuffer - _buffer = new byte[kSampleBufferLength]; - assert(_buffer); - - // Calculate the total playtime of the stream - _playtime = Audio::Timestamp(0, _stream->size() / 2 / 1, rate); - } - - ~RawZorkStream() { - delete[] _buffer; - } - - int readBuffer(int16 *buffer, const int numSamples); - - bool isStereo() const { return true; } - bool endOfData() const { return _endOfData; } - - int getRate() const { return _rate; } - Audio::Timestamp getLength() const { return _playtime; } - - bool seek(const Audio::Timestamp &where); -private: - const int _rate; ///< Sample rate of stream - Audio::Timestamp _playtime; ///< Calculated total play time - Common::DisposablePtr _stream; ///< Stream to read data from - bool _endOfData; ///< Whether the stream end has been reached - - byte *_buffer; ///< Buffer used in readBuffer - enum { - /** - * How many samples we can buffer at once. - * - * TODO: Check whether this size suffices - * for systems with slow disk I/O. - */ - kSampleBufferLength = 2048 - }; - - /** - * Fill the temporary sample buffer used in readBuffer. - * - * @param maxSamples Maximum samples to read. - * @return actual count of samples read. - */ - int fillBuffer(int maxSamples); -}; - -int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { - int samplesLeft = numSamples; - - while (samplesLeft > 0) { - // Try to read up to "samplesLeft" samples. - int len = fillBuffer(samplesLeft); - - // In case we were not able to read any samples - // we will stop reading here. - if (!len) - break; - - // Adjust the samples left to read. - samplesLeft -= len; - - // Copy the data to the caller's buffer. - const byte *src = _buffer; - while (len-- > 0) { - if (*src < 128) - *buffer++ = ((128 - *src) << 8) ^ 0x8000; - else - *buffer++ = (*src << 8) ^ 0x8000; - src++; - } - } - - return numSamples - samplesLeft; +const int16 RawZorkStream::stepAdjustmentTable[8] = {-1, -1, -1, 1, 4, 7, 10, 12}; + +const int32 RawZorkStream::amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, + 0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001C, 0x001F, + 0x0022, 0x0025, 0x0029, 0x002D, 0x0032, 0x0037, 0x003C, 0x0042, + 0x0049, 0x0050, 0x0058, 0x0061, 0x006B, 0x0076, 0x0082, 0x008F, + 0x009D, 0x00AD, 0x00BE, 0x00D1, 0x00E6, 0x00FD, 0x0117, 0x0133, + 0x0151, 0x0173, 0x0198, 0x01C1, 0x01EE, 0x0220, 0x0256, 0x0292, + 0x02D4, 0x031C, 0x036C, 0x03C3, 0x0424, 0x048E, 0x0502, 0x0583, + 0x0610, 0x06AB, 0x0756, 0x0812, 0x08E0, 0x09C3, 0x0ABD, 0x0BD0, + 0x0CFF, 0x0E4C, 0x0FBA, 0x114C, 0x1307, 0x14EE, 0x1706, 0x1954, + 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B, + 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF}; + +RawZorkStream::RawZorkStream(uint32 rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) + : _rate(rate), + _stream(stream, disposeStream), + _endOfData(false) { + _lastSample[0] = {0, 0}; + _lastSample[1] = {0, 0}; + + // Calculate the total playtime of the stream + _playtime = Audio::Timestamp(0, _stream->size() / 2, rate); } -int RawZorkStream::fillBuffer(int maxSamples) { - int bufferedSamples = 0; - byte *dst = _buffer; - - // We can only read up to "kSampleBufferLength" samples - // so we take this into consideration, when trying to - // read up to maxSamples. - maxSamples = MIN(kSampleBufferLength, maxSamples); - - // We will only read up to maxSamples - while (maxSamples > 0 && !endOfData()) { - // Try to read all the sample data and update the - // destination pointer. - const int bytesRead = _stream->read(dst, maxSamples); - dst += bytesRead; +int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { + uint16 bytesRead = 0; - // Calculate how many samples we actually read. - const int samplesRead = bytesRead; + // 0: Left, 1: Right + byte channel = 0; - // Update all status variables - bufferedSamples += samplesRead; - maxSamples -= samplesRead; + while (bytesRead < numSamples) { + byte encodedSample = _stream->readByte(); + bytesRead++; - // We stop stream playback, when we reached the end of the data stream. - // We also stop playback when an error occures. - if (_stream->pos() == _stream->size() || _stream->err() || _stream->eos()) + if (_stream->eos()) { _endOfData = true; + return bytesRead; + } + + uint16 index = _lastSample[channel].index; + uint32 lookUpSample = amplitudeLookupTable[index]; + + int32 sample = 0; + + if (encodedSample & 0x40) + sample += lookUpSample; + if (encodedSample & 0x20) + sample += lookUpSample >> 1; + if (encodedSample & 0x10) + sample += lookUpSample >> 2; + if (encodedSample & 8) + sample += lookUpSample >> 3; + if (encodedSample & 4) + sample += lookUpSample >> 4; + if (encodedSample & 2) + sample += lookUpSample >> 5; + if (encodedSample & 1) + sample += lookUpSample >> 6; + if (encodedSample & 0x80) + sample = -sample; + + sample += _lastSample[channel].sample; + sample = CLIP(sample, -32768, 32767); + + buffer[bytesRead - 1] = (int16)sample; + + index += stepAdjustmentTable[(encodedSample >> 4) & 7]; + index = CLIP(index, 0, 88); + + _lastSample[channel].sample = sample; + _lastSample[channel].index = index; + + // Increment and wrap the channel + channel = (channel + 1) & 1; } - return bufferedSamples; + return bytesRead; } -bool RawZorkStream::seek(const Audio::Timestamp &where) { - _endOfData = true; - - if (where > _playtime) - return false; - - const uint32 seekSample = convertTimeToStreamPos(where, getRate(), isStereo()).totalNumberOfFrames(); - _stream->seek(seekSample, SEEK_SET); - - // In case of an error we will not continue stream playback. - if (!_stream->err() && !_stream->eos() && _stream->pos() != _stream->size()) - _endOfData = false; +bool RawZorkStream::rewind() { + _stream->seek(0, 0); + _stream->clearErr(); + _endOfData = false; + _lastSample[0] = {0, 0}; + _lastSample[1] = {0, 0}; return true; } -#pragma mark - -#pragma mark --- Raw stream factories --- -#pragma mark - - -Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, +Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, int rate, DisposeAfterUse::Flag disposeAfterUse) { assert(stream->size() % 2 == 0); return new RawZorkStream(rate, disposeAfterUse, stream); } -Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, +Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, int rate, DisposeAfterUse::Flag disposeAfterUse) { return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, DisposeAfterUse::YES); diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 1de3b575ba..43cf4d83d0 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -23,19 +23,64 @@ #ifndef ZVISION_ZORK_RAW_H #define ZVISION_ZORK_RAW_H -#include "common/scummsys.h" #include "common/types.h" - -#include "common/list.h" - +#include "audio/audiostream.h" namespace Common { class SeekableReadStream; } namespace ZVision { +/** + * This is a stream, which allows for playing raw ADPCM data from a stream. + */ +class RawZorkStream : public Audio::RewindableAudioStream { +public: + RawZorkStream(uint32 rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream); + + ~RawZorkStream() { + } + +private: + const int _rate; // Sample rate of stream + Audio::Timestamp _playtime; // Calculated total play time + Common::DisposablePtr _stream; // Stream to read data from + bool _endOfData; // Whether the stream end has been reached + + /** + * Holds the frequency and index from the last sample + * 0 holds the left channel, 1 holds the right channel + */ + struct { + int32 sample; + int16 index; + } _lastSample[2]; + + static const int16 stepAdjustmentTable[8]; + + static const int32 amplitudeLookupTable[89]; + +public: + int readBuffer(int16 *buffer, const int numSamples); + + bool isStereo() const { return true; } + bool endOfData() const { return _endOfData; } + + int getRate() const { return _rate; } + Audio::Timestamp getLength() const { return _playtime; } + + bool rewind(); -class SeekableAudioStream; +private: + /** + * Fill the temporary sample buffer used in readBuffer. + * + * @param maxSamples Maximum samples to read. + * @return actual count of samples read. + */ + int fillBuffer(int maxSamples); + uint32 processBlock(); +}; /** * Creates an audio stream, which plays from the given buffer. @@ -46,7 +91,7 @@ class SeekableAudioStream; * @param disposeAfterUse Whether to free the buffer after use (with free!). * @return The new SeekableAudioStream (or 0 on failure). */ -Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, +Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, int rate, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); @@ -58,7 +103,7 @@ Audio::SeekableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, * @param disposeAfterUse Whether to delete the stream after use. * @return The new SeekableAudioStream (or 0 on failure). */ -Audio::SeekableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, +Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, int rate, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); -- cgit v1.2.3 From f88127104b6b59a336761966e9652412083402b7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 15 Jul 2013 10:32:56 -0500 Subject: ZVISION: Fix implicit conversion for scanf-type functions --- engines/zvision/scr_file_handling.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 2371c350f7..6a2e8cf701 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -41,7 +41,7 @@ void ScriptManager::parseScrFile(Common::String fileName) { while(!file.eos()) { Common::String line = file.readLine(); if (file.err()) { - warning("Error parsing scr file: %s", fileName); + warning("Error parsing scr file: %s", fileName.c_str()); return; } @@ -249,7 +249,7 @@ void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List } else { - warning("Unhandled result action type: ", line); + warning("Unhandled result action type: %s", line.c_str()); } line = stream.readLine(); -- cgit v1.2.3 From c45a13cdd716da04c9b64ba50560d7d89facfccb Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 15 Jul 2013 10:33:49 -0500 Subject: ZVISION: Conform to GCC spacing for template inside template --- engines/zvision/script_manager.cpp | 2 +- engines/zvision/script_manager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index b4ad1cc003..7fcf2f67a3 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -55,7 +55,7 @@ void ScriptManager::createReferenceTable() { } // Remove duplicate entries - for (Common::HashMap>::iterator referenceTableIter; referenceTableIter != _referenceTable.end(); referenceTableIter++) { + for (Common::HashMap >::iterator referenceTableIter; referenceTableIter != _referenceTable.end(); referenceTableIter++) { removeDuplicateEntries(&(referenceTableIter->_value)); } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 42f4bba602..7924eee4c0 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -51,7 +51,7 @@ private: /** Holds the currently active ActionNodes */ Common::List _activeNodes; /** References _globalState keys to Puzzles */ - Common::HashMap> _referenceTable; + Common::HashMap > _referenceTable; /** Holds the Puzzles that should be checked this frame */ Common::Stack _puzzlesToCheck; /** Holds the currently active puzzles */ -- cgit v1.2.3 From 644313e8f20fa777325c748a450ca698141c0d97 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 15 Jul 2013 10:35:23 -0500 Subject: ZVISION: Add stereo/mono handling for Zork sound --- engines/zvision/console.cpp | 6 +++--- engines/zvision/zork_raw.cpp | 24 +++++++++++++----------- engines/zvision/zork_raw.h | 13 ++++++++----- 3 files changed, 24 insertions(+), 19 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index c3be4ba0f5..e0ca37c1d2 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -65,8 +65,8 @@ bool Console::cmdLoadVideo(int argc, const char **argv) { } bool Console::cmdLoadSound(int argc, const char **argv) { - if (argc != 3) { - DebugPrintf("Use loadsound to load a video to the screen"); + if (argc != 4) { + DebugPrintf("Use loadsound to load a video to the screen"); return true; } @@ -76,7 +76,7 @@ bool Console::cmdLoadSound(int argc, const char **argv) { return true; } - Audio::AudioStream *soundStream = makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), atoi(argv[2]), DisposeAfterUse::YES); + Audio::AudioStream *soundStream = makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), atoi(argv[2]), atoi(argv[3]), DisposeAfterUse::YES); Audio::SoundHandle handle; _engine->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 69d8edd8df..c4b76d91fe 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -45,8 +45,9 @@ const int32 RawZorkStream::amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B, 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF}; -RawZorkStream::RawZorkStream(uint32 rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) +RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) : _rate(rate), + _stereo(stereo), _stream(stream, disposeStream), _endOfData(false) { _lastSample[0] = {0, 0}; @@ -64,14 +65,13 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { while (bytesRead < numSamples) { byte encodedSample = _stream->readByte(); - bytesRead++; - if (_stream->eos()) { _endOfData = true; return bytesRead; } + bytesRead++; - uint16 index = _lastSample[channel].index; + int16 index = _lastSample[channel].index; uint32 lookUpSample = amplitudeLookupTable[index]; int32 sample = 0; @@ -105,7 +105,7 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { _lastSample[channel].index = index; // Increment and wrap the channel - channel = (channel + 1) & 1; + channel = (channel + 1) & _stereo; } return bytesRead; @@ -122,16 +122,18 @@ bool RawZorkStream::rewind() { } Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, - int rate, - DisposeAfterUse::Flag disposeAfterUse) { + int rate, + bool stereo, + DisposeAfterUse::Flag disposeAfterUse) { assert(stream->size() % 2 == 0); - return new RawZorkStream(rate, disposeAfterUse, stream); + return new RawZorkStream(rate, stereo, disposeAfterUse, stream); } Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, - int rate, - DisposeAfterUse::Flag disposeAfterUse) { - return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, DisposeAfterUse::YES); + int rate, + bool stereo, + DisposeAfterUse::Flag disposeAfterUse) { + return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, DisposeAfterUse::YES); } } // End of namespace ZVision diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 43cf4d83d0..7386c87f86 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -36,7 +36,7 @@ namespace ZVision { */ class RawZorkStream : public Audio::RewindableAudioStream { public: - RawZorkStream(uint32 rate, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream); + RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream); ~RawZorkStream() { } @@ -46,6 +46,7 @@ private: Audio::Timestamp _playtime; // Calculated total play time Common::DisposablePtr _stream; // Stream to read data from bool _endOfData; // Whether the stream end has been reached + bool _stereo; /** * Holds the frequency and index from the last sample @@ -92,8 +93,9 @@ private: * @return The new SeekableAudioStream (or 0 on failure). */ Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, - int rate, - DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + int rate, + bool stereo, + DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); /** * Creates an audio stream, which plays from the given stream. @@ -104,8 +106,9 @@ Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, * @return The new SeekableAudioStream (or 0 on failure). */ Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, - int rate, - DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + int rate, + bool stereo, + DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); } // End of namespace ZVision -- cgit v1.2.3 From 8de12fcbd2dbfddd45bd7916e1e90b5b3e4466bc Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 15 Jul 2013 10:36:24 -0500 Subject: ZVISION: Add underscore prefix to public static variable names --- engines/zvision/lzss_read_stream.cpp | 8 ++++---- engines/zvision/lzss_read_stream.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index a7cdcd9d88..2d7acdb8ce 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -33,17 +33,17 @@ LzssReadStream::LzssReadStream(Common::SeekableReadStream *source, bool stream, _readCursor(0), _eosFlag(false) { // Clear the window to null - memset(_window, 0, blockSize); + memset(_window, 0, _blockSize); // Reserve space in the destination buffer // TODO: Make a better guess - if (decompressedSize == npos) { + if (decompressedSize == _npos) { decompressedSize = source->size(); } _destination.reserve(decompressedSize); if (stream) - decompressBytes(blockSize); + decompressBytes(_blockSize); else decompressAll(); } @@ -120,7 +120,7 @@ uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) { break; } - decompressBytes(blockSize); + decompressBytes(_blockSize); } if (dataSize > 0) { diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 9ef1d6da37..142bf9e1a2 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -41,16 +41,16 @@ public: * @param stream Decompress the data as needed (true) or all at once (false) * @param decompressedSize The size of the decompressed data. If npos, the class will choose a size and grow as needed */ - LzssReadStream(Common::SeekableReadStream *source, bool stream = true, uint32 decompressedSize = npos); + LzssReadStream(Common::SeekableReadStream *source, bool stream = true, uint32 decompressedSize = _npos); public: - static const uint32 npos = 0xFFFFFFFFu; - static const uint16 blockSize = 0x1000u; + static const uint32 _npos = 0xFFFFFFFFu; + static const uint16 _blockSize = 0x1000u; private: Common::SeekableReadStream *_source; Common::Array _destination; - char _window[blockSize]; + char _window[_blockSize]; uint16 _windowCursor; uint32 _readCursor; bool _eosFlag; -- cgit v1.2.3 From a30f49b556ef27644d752368c11590cc48c0fccf Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 16 Jul 2013 16:52:46 -0500 Subject: ZVISION: Add a game type enum to detection This is needed for sound file differentiation --- engines/zvision/detection.cpp | 11 ++++------- engines/zvision/detection.h | 42 ++++++++++++++++++++++++++++++++++++++++++ engines/zvision/zvision.cpp | 5 +++-- engines/zvision/zvision.h | 4 +++- 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 engines/zvision/detection.h (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 5488ae5be4..8c87c90203 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -23,22 +23,17 @@ #include "base/plugins.h" -#include "engines/advancedDetector.h" - #include "common/translation.h" #include "common/savefile.h" #include "common/str-array.h" #include "common/system.h" #include "zvision/zvision.h" +#include "zvision/detection.h" namespace ZVision { -struct ZVisionGameDescription { - ADGameDescription desc; -}; - uint32 ZVision::getFeatures() const { return _gameDescription->desc.flags; } @@ -47,7 +42,8 @@ Common::Language ZVision::getLanguage() const { return _gameDescription->desc.language; } -} +} // End of namespace ZVision + static const PlainGameDescriptor zVisionGames[] = { {"zvision", "ZVision Game"}, @@ -72,6 +68,7 @@ static const ZVisionGameDescription gameDescriptions[] = { ADGF_NO_FLAGS, GUIO1(GUIO_NONE) }, + ZorkNemesis }, { AD_TABLE_END_MARKER } diff --git a/engines/zvision/detection.h b/engines/zvision/detection.h new file mode 100644 index 0000000000..b1e5dcbe01 --- /dev/null +++ b/engines/zvision/detection.h @@ -0,0 +1,42 @@ +/* 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 ZVISION_DETECTION_H +#define ZVISION_DETECTION_H + +#include "engines/advancedDetector.h" + +namespace ZVision { + +enum ZVisionGameId { + ZorkNemesis, + ZorkGrandInquisitor +}; + +struct ZVisionGameDescription { + ADGameDescription desc; + ZVisionGameId gameId; +}; + +} + +#endif diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index ba08122ba5..4ce775db86 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -36,6 +36,7 @@ #include "zvision/console.h" #include "zvision/script_manager.h" #include "zvision/zfs_archive.h" +#include "zvision/detection.h" #include "zvision/utility.h" @@ -154,8 +155,8 @@ Common::RandomSource *ZVision::getRandomSource() const { return _rnd; } -Audio::Mixer *ZVision::getMixer() const { - return _mixer; +ZVisionGameId ZVision::getGameId() const { + return _gameDescription->gameId; } } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 11773a33ad..17a7c026f1 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -31,6 +31,8 @@ #include "engines/engine.h" +#include "zvision/detection.h" + #include "gui/debugger.h" namespace ZVision { @@ -76,7 +78,7 @@ public: virtual Common::Error run(); ScriptManager *getScriptManager() const; Common::RandomSource *getRandomSource() const; - Audio::Mixer *getMixer() const; + ZVisionGameId getGameId() const; void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); void startVideo(Video::VideoDecoder *videoDecoder); -- cgit v1.2.3 From 9f7ff84fe4b9362a80ccf6b0f40602e01fb991d1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 16 Jul 2013 16:55:18 -0500 Subject: ZVISION: Create utility function to parse fileName from a full/partial path --- engines/zvision/utility.cpp | 19 +++++++++++++++++++ engines/zvision/utility.h | 2 ++ 2 files changed, 21 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index 41b589d0c0..5f69fd7433 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -22,6 +22,8 @@ #include "common/scummsys.h" +#include "common/tokenizer.h" + #include "zvision/utility.h" namespace ZVision { @@ -177,4 +179,21 @@ void dumpEveryResultAction(const Common::String &destFile) { output.close(); } +/** + * 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) { + Common::StringTokenizer tokenizer(fullPath, "/\\"); + Common::String token; + while (!tokenizer.empty()) { + token = tokenizer.nextToken(); + } + + return token; +} + } // End of namespace ZVision diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index e5713fc7f4..dba765b65c 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -73,6 +73,8 @@ void removeDuplicateEntries(Common::Array *container) { } } +Common::String getFileName(const Common::String &fullPath); + } // End of namespace ZVision #endif -- cgit v1.2.3 From 76f4d2b3d898710f5fefba47aafafc889037968b Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 16 Jul 2013 16:56:15 -0500 Subject: ZVISION: Create logic to decode sound rate and isStereo from fileName --- engines/zvision/zork_avi_decoder.cpp | 10 +++--- engines/zvision/zork_raw.cpp | 62 +++++++++++++++++++++++++++++++----- engines/zvision/zork_raw.h | 49 +++++++++++++++++++++------- 3 files changed, 96 insertions(+), 25 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp index 4ceff48891..d9b9511175 100644 --- a/engines/zvision/zork_avi_decoder.cpp +++ b/engines/zvision/zork_avi_decoder.cpp @@ -26,13 +26,13 @@ #include "common/stream.h" #include "audio/audiostream.h" -#include "engines/zvision/zork_avi_decoder.h" -#include "engines/zvision/zork_raw.h" +#include "zvision/zork_avi_decoder.h" +#include "zvision/zork_raw.h" namespace ZVision { -Video::AVIDecoder::AVIAudioTrack *ZVision::ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) { - ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType); +Video::AVIDecoder::AVIAudioTrack *ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) { + ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType); return (Video::AVIDecoder::AVIAudioTrack *)audioTrack; } @@ -40,7 +40,7 @@ void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *s if (_audStream) { if (_wvInfo.tag == kWaveFormatZorkPCM) { assert(_wvInfo.size == 8); - _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, DisposeAfterUse::YES), DisposeAfterUse::YES); + _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, _audStream->isStereo(), DisposeAfterUse::YES), DisposeAfterUse::YES); } } else { delete stream; diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index c4b76d91fe..9f71b7602c 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -22,18 +22,24 @@ #include "common/scummsys.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 "audio/audiostream.h" -#include "engines/zvision/zork_raw.h" +#include "zvision/zork_raw.h" +#include "zvision/zvision.h" +#include "zvision/detection.h" +#include "zvision/utility.h" namespace ZVision { -const int16 RawZorkStream::stepAdjustmentTable[8] = {-1, -1, -1, 1, 4, 7, 10, 12}; +const int16 RawZorkStream::_stepAdjustmentTable[8] = {-1, -1, -1, 1, 4, 7, 10, 12}; -const int32 RawZorkStream::amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, +const int32 RawZorkStream::_amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001C, 0x001F, 0x0022, 0x0025, 0x0029, 0x002D, 0x0032, 0x0037, 0x003C, 0x0042, 0x0049, 0x0050, 0x0058, 0x0061, 0x006B, 0x0076, 0x0082, 0x008F, @@ -45,9 +51,10 @@ const int32 RawZorkStream::amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B, 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF}; -RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) +RawZorkStream::RawZorkStream(uint32 rate, bool stereo, bool packed, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) : _rate(rate), _stereo(stereo), + _packed(packed), _stream(stream, disposeStream), _endOfData(false) { _lastSample[0] = {0, 0}; @@ -58,6 +65,18 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag dis } int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { + if (_packed) + return decodeADPCM(buffer, numSamples); + else { + uint32 bytesRead = _stream->read(buffer, numSamples); + if (_stream->eos()) + _endOfData = true; + + return bytesRead; + } +} + +int RawZorkStream::decodeADPCM(int16 *buffer, const int numSamples) { uint16 bytesRead = 0; // 0: Left, 1: Right @@ -72,7 +91,7 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { bytesRead++; int16 index = _lastSample[channel].index; - uint32 lookUpSample = amplitudeLookupTable[index]; + uint32 lookUpSample = _amplitudeLookupTable[index]; int32 sample = 0; @@ -98,7 +117,7 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { buffer[bytesRead - 1] = (int16)sample; - index += stepAdjustmentTable[(encodedSample >> 4) & 7]; + index += _stepAdjustmentTable[(encodedSample >> 4) & 7]; index = CLIP(index, 0, 88); _lastSample[channel].sample = sample; @@ -124,16 +143,43 @@ bool RawZorkStream::rewind() { Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, int rate, bool stereo, + bool packed, DisposeAfterUse::Flag disposeAfterUse) { assert(stream->size() % 2 == 0); - return new RawZorkStream(rate, stereo, disposeAfterUse, stream); + return new RawZorkStream(rate, stereo, packed, disposeAfterUse, stream); } Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, int rate, bool stereo, + bool packed, DisposeAfterUse::Flag disposeAfterUse) { - return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, DisposeAfterUse::YES); + return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, packed, DisposeAfterUse::YES); +} + +Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) { + Common::File *file = new Common::File(); + assert(file->open(filePath)); + + Common::String fileName = getFileName(filePath); + fileName.toLowercase(); + + SoundParams soundParams; + + if (engine->getGameId() == ZorkNemesis) { + for (int i = 0; i < 6; i++) { + if (zNemSoundParamLookupTable[i].identifier == (fileName[6])) + soundParams = zNemSoundParamLookupTable[i]; + } + } + else if (engine->getGameId() == ZorkGrandInquisitor) { + for (int i = 0; i < 6; i++) { + if (zgiSoundParamLookupTable[i].identifier == (fileName[7])) + soundParams = zgiSoundParamLookupTable[i]; + } + } + + return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams.rate, soundParams.stereo, soundParams.packed, DisposeAfterUse::YES); } } // End of namespace ZVision diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 7386c87f86..5efa27a1e3 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -31,22 +31,51 @@ class SeekableReadStream; } namespace ZVision { + +class ZVision; + +struct SoundParams { + char identifier; + uint16 rate; + bool stereo; + bool packed; +}; + +const SoundParams zNemSoundParamLookupTable[6] = {{'6', 0x2B11, false, false}, + {'a', 0x5622, false, true}, + {'b', 0x5622, true, true}, + {'n', 0x2B11, false, true}, + {'s', 0x5622, false, true}, + {'t', 0x5622, true, true} +}; + +const SoundParams zgiSoundParamLookupTable[5] = {{'a',0x5622, false, false}, + {'k',0x2B11, true, true}, + {'p',0x5622, false, true}, + {'q',0x5622, true, true}, + {'u',0xAC44, true, true} +}; + /** * This is a stream, which allows for playing raw ADPCM data from a stream. */ class RawZorkStream : public Audio::RewindableAudioStream { public: - RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream); + RawZorkStream(uint32 rate, bool stereo, bool packed, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream); + RawZorkStream(const Common::String &filePath, ZVision *engine); ~RawZorkStream() { } +public: + private: const int _rate; // Sample rate of stream Audio::Timestamp _playtime; // Calculated total play time Common::DisposablePtr _stream; // Stream to read data from bool _endOfData; // Whether the stream end has been reached bool _stereo; + bool _packed; /** * Holds the frequency and index from the last sample @@ -57,9 +86,8 @@ private: int16 index; } _lastSample[2]; - static const int16 stepAdjustmentTable[8]; - - static const int32 amplitudeLookupTable[89]; + static const int16 _stepAdjustmentTable[8]; + static const int32 _amplitudeLookupTable[89]; public: int readBuffer(int16 *buffer, const int numSamples); @@ -73,14 +101,7 @@ public: bool rewind(); private: - /** - * Fill the temporary sample buffer used in readBuffer. - * - * @param maxSamples Maximum samples to read. - * @return actual count of samples read. - */ - int fillBuffer(int maxSamples); - uint32 processBlock(); + int decodeADPCM(int16 *buffer, const int numSamples); }; /** @@ -95,6 +116,7 @@ private: Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, int rate, bool stereo, + bool packed, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); /** @@ -108,8 +130,11 @@ Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, int rate, bool stereo, + bool packed, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); +Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine); + } // End of namespace ZVision #endif -- cgit v1.2.3 From 92f3de72de273cc4ae3767e5991ff1f7cd85c8ed Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 16 Jul 2013 16:57:12 -0500 Subject: ZVISION: Convert console sound handling to use new fileName decoding --- engines/zvision/console.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index e0ca37c1d2..a18da8605a 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -42,7 +42,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { bool Console::cmdLoadImage(int argc, const char **argv) { if (argc != 4) { - DebugPrintf("Use loadimage to load an image to the screen"); + DebugPrintf("Use loadimage to load an image to the screen\n"); return true; } _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); @@ -52,7 +52,7 @@ bool Console::cmdLoadImage(int argc, const char **argv) { bool Console::cmdLoadVideo(int argc, const char **argv) { if (argc != 2) { - DebugPrintf("Use loadvideo to load a video to the screen"); + DebugPrintf("Use loadvideo to load a video to the screen\n"); return true; } @@ -65,20 +65,19 @@ bool Console::cmdLoadVideo(int argc, const char **argv) { } bool Console::cmdLoadSound(int argc, const char **argv) { - if (argc != 4) { - DebugPrintf("Use loadsound to load a video to the screen"); + if (argc != 2) { + DebugPrintf("Use loadsound to load a sound\n"); return true; } - Common::File *file = new Common::File(); - if (!file->open(argv[1])) { - DebugPrintf("File does not exist"); + if (!Common::File::exists(argv[1])) { + DebugPrintf("File does not exist\n"); return true; } - Audio::AudioStream *soundStream = makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), atoi(argv[2]), atoi(argv[3]), DisposeAfterUse::YES); + Audio::AudioStream *soundStream = makeRawZorkStream(argv[1], _engine); Audio::SoundHandle handle; - _engine->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); + _engine->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); return true; } -- cgit v1.2.3 From 071d9f2241d608753372a027b489ae3027d73480 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 16 Jul 2013 16:59:11 -0500 Subject: ZVISION: Add logic to allow the user to break out of videos --- engines/zvision/events.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 984d59e2ba..a3d6b6b670 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -25,6 +25,7 @@ #include "zvision/zvision.h" #include "zvision/console.h" #include "common/events.h" +#include "engines/util.h" namespace ZVision { @@ -55,12 +56,19 @@ void ZVision::processEvents() { _console->onFrame(); } break; - case Common::KEYCODE_q: if (_event.kbd.hasFlags(Common::KBD_CTRL)) quitGame(); break; - + case Common::KEYCODE_ESCAPE: + if (_currentVideo != 0) { + initGraphics(_width, _height, true, &_pixelFormat); + delete _currentVideo; + _currentVideo = 0; + delete _scaledVideoFrameBuffer; + _scaledVideoFrameBuffer = 0; + } + break; default: break; } -- cgit v1.2.3 From c7ce580bbde99c1634a1160a18350ccd51badb39 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 12:11:04 -0500 Subject: ZVISION: Removed 'packed' audio handling from RawZorkStream. Moved it to the factory method for creating Audio Streams --- engines/zvision/zork_raw.cpp | 57 +++++++++++++++++++------------------------- engines/zvision/zork_raw.h | 11 ++------- 2 files changed, 27 insertions(+), 41 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 9f71b7602c..78913a7262 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -29,6 +29,7 @@ #include "common/bufferedstream.h" #include "common/util.h" #include "audio/audiostream.h" +#include "audio/decoders/raw.h" #include "zvision/zork_raw.h" #include "zvision/zvision.h" @@ -40,21 +41,20 @@ namespace ZVision { const int16 RawZorkStream::_stepAdjustmentTable[8] = {-1, -1, -1, 1, 4, 7, 10, 12}; const int32 RawZorkStream::_amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, - 0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001C, 0x001F, - 0x0022, 0x0025, 0x0029, 0x002D, 0x0032, 0x0037, 0x003C, 0x0042, - 0x0049, 0x0050, 0x0058, 0x0061, 0x006B, 0x0076, 0x0082, 0x008F, - 0x009D, 0x00AD, 0x00BE, 0x00D1, 0x00E6, 0x00FD, 0x0117, 0x0133, - 0x0151, 0x0173, 0x0198, 0x01C1, 0x01EE, 0x0220, 0x0256, 0x0292, - 0x02D4, 0x031C, 0x036C, 0x03C3, 0x0424, 0x048E, 0x0502, 0x0583, - 0x0610, 0x06AB, 0x0756, 0x0812, 0x08E0, 0x09C3, 0x0ABD, 0x0BD0, - 0x0CFF, 0x0E4C, 0x0FBA, 0x114C, 0x1307, 0x14EE, 0x1706, 0x1954, - 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B, - 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF}; - -RawZorkStream::RawZorkStream(uint32 rate, bool stereo, bool packed, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) + 0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001C, 0x001F, + 0x0022, 0x0025, 0x0029, 0x002D, 0x0032, 0x0037, 0x003C, 0x0042, + 0x0049, 0x0050, 0x0058, 0x0061, 0x006B, 0x0076, 0x0082, 0x008F, + 0x009D, 0x00AD, 0x00BE, 0x00D1, 0x00E6, 0x00FD, 0x0117, 0x0133, + 0x0151, 0x0173, 0x0198, 0x01C1, 0x01EE, 0x0220, 0x0256, 0x0292, + 0x02D4, 0x031C, 0x036C, 0x03C3, 0x0424, 0x048E, 0x0502, 0x0583, + 0x0610, 0x06AB, 0x0756, 0x0812, 0x08E0, 0x09C3, 0x0ABD, 0x0BD0, + 0x0CFF, 0x0E4C, 0x0FBA, 0x114C, 0x1307, 0x14EE, 0x1706, 0x1954, + 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B, + 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF}; + +RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) : _rate(rate), _stereo(stereo), - _packed(packed), _stream(stream, disposeStream), _endOfData(false) { _lastSample[0] = {0, 0}; @@ -65,18 +65,6 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, bool packed, DisposeAfter } int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { - if (_packed) - return decodeADPCM(buffer, numSamples); - else { - uint32 bytesRead = _stream->read(buffer, numSamples); - if (_stream->eos()) - _endOfData = true; - - return bytesRead; - } -} - -int RawZorkStream::decodeADPCM(int16 *buffer, const int numSamples) { uint16 bytesRead = 0; // 0: Left, 1: Right @@ -143,21 +131,19 @@ bool RawZorkStream::rewind() { Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, int rate, bool stereo, - bool packed, DisposeAfterUse::Flag disposeAfterUse) { assert(stream->size() % 2 == 0); - return new RawZorkStream(rate, stereo, packed, disposeAfterUse, stream); + return new RawZorkStream(rate, stereo, disposeAfterUse, stream); } Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, int rate, bool stereo, - bool packed, DisposeAfterUse::Flag disposeAfterUse) { - return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, packed, DisposeAfterUse::YES); + return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, DisposeAfterUse::YES); } -Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) { +Audio::AudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) { Common::File *file = new Common::File(); assert(file->open(filePath)); @@ -178,8 +164,15 @@ Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, soundParams = zgiSoundParamLookupTable[i]; } } - - return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams.rate, soundParams.stereo, soundParams.packed, DisposeAfterUse::YES); + + if (soundParams.packed) { + byte flags = 0; + if (soundParams.stereo) + flags |= Audio::FLAG_STEREO; + return Audio::makeRawStream(file, soundParams.rate, flags, DisposeAfterUse::YES); + } + else + return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams.rate, soundParams.stereo, DisposeAfterUse::YES); } } // End of namespace ZVision diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 5efa27a1e3..8d4670e26c 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -61,8 +61,7 @@ const SoundParams zgiSoundParamLookupTable[5] = {{'a',0x5622, false, false}, */ class RawZorkStream : public Audio::RewindableAudioStream { public: - RawZorkStream(uint32 rate, bool stereo, bool packed, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream); - RawZorkStream(const Common::String &filePath, ZVision *engine); + RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream); ~RawZorkStream() { } @@ -75,7 +74,6 @@ private: Common::DisposablePtr _stream; // Stream to read data from bool _endOfData; // Whether the stream end has been reached bool _stereo; - bool _packed; /** * Holds the frequency and index from the last sample @@ -99,9 +97,6 @@ public: Audio::Timestamp getLength() const { return _playtime; } bool rewind(); - -private: - int decodeADPCM(int16 *buffer, const int numSamples); }; /** @@ -116,7 +111,6 @@ private: Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, int rate, bool stereo, - bool packed, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); /** @@ -130,10 +124,9 @@ Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, int rate, bool stereo, - bool packed, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); -Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine); +Audio::AudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine); } // End of namespace ZVision -- cgit v1.2.3 From d771b615e050ecd13e9da73111230ec16158beb2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 12:11:36 -0500 Subject: ZVISION: Use individual initialization instead of inline. --- engines/zvision/zork_raw.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 78913a7262..140e6a532b 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -57,8 +57,10 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag dis _stereo(stereo), _stream(stream, disposeStream), _endOfData(false) { - _lastSample[0] = {0, 0}; - _lastSample[1] = {0, 0}; + _lastSample[0].index = 0; + _lastSample[0].sample = 0; + _lastSample[1].index = 0; + _lastSample[1].sample = 0; // Calculate the total playtime of the stream _playtime = Audio::Timestamp(0, _stream->size() / 2, rate); @@ -122,8 +124,10 @@ bool RawZorkStream::rewind() { _stream->seek(0, 0); _stream->clearErr(); _endOfData = false; - _lastSample[0] = {0, 0}; - _lastSample[1] = {0, 0}; + _lastSample[0].index = 0; + _lastSample[0].sample = 0; + _lastSample[1].index = 0; + _lastSample[1].sample = 0; return true; } -- cgit v1.2.3 From 03c871ff3025457067bb504af0799c901498253e Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 17:16:19 -0500 Subject: ZVISION: Convert _stereo to a byte since it is used for a bitwise and --- engines/zvision/zork_raw.cpp | 5 ++++- engines/zvision/zork_raw.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 140e6a532b..68bb25dd48 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -54,9 +54,12 @@ const int32 RawZorkStream::_amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) : _rate(rate), - _stereo(stereo), + _stereo(0), _stream(stream, disposeStream), _endOfData(false) { + if (stereo) + _stereo = 1; + _lastSample[0].index = 0; _lastSample[0].sample = 0; _lastSample[1].index = 0; diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 8d4670e26c..6d25d197ee 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -73,7 +73,7 @@ private: Audio::Timestamp _playtime; // Calculated total play time Common::DisposablePtr _stream; // Stream to read data from bool _endOfData; // Whether the stream end has been reached - bool _stereo; + byte _stereo; /** * Holds the frequency and index from the last sample -- cgit v1.2.3 From 134f8fda173731d744bd814d68850ce14fa4fd94 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 17:16:52 -0500 Subject: ZVISION: Fix incorrect assumptions about a file being stereo --- engines/zvision/zork_raw.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 68bb25dd48..cb031d6214 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -66,7 +66,10 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag dis _lastSample[1].sample = 0; // Calculate the total playtime of the stream - _playtime = Audio::Timestamp(0, _stream->size() / 2, rate); + if (stereo) + _playtime = Audio::Timestamp(0, _stream->size() / 2, rate); + else + _playtime = Audio::Timestamp(0, _stream->size(), rate); } int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { @@ -139,7 +142,9 @@ Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stre int rate, bool stereo, DisposeAfterUse::Flag disposeAfterUse) { - assert(stream->size() % 2 == 0); + if (stereo) + assert(stream->size() % 2 == 0); + return new RawZorkStream(rate, stereo, disposeAfterUse, stream); } -- cgit v1.2.3 From e897a1bb2ae444cf812f2c11060585ccd2b48e4c Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 17:19:59 -0500 Subject: ZVISION: Fix logic concerning whether a stream is packed or not It was accidentally returning a raw stream for a ZorkStream and a ZorkStream for a raw --- engines/zvision/zork_raw.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index cb031d6214..2ffe8eb3a6 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -178,13 +178,14 @@ Audio::AudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *e } if (soundParams.packed) { + return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams.rate, soundParams.stereo, DisposeAfterUse::YES); + } else { byte flags = 0; if (soundParams.stereo) flags |= Audio::FLAG_STEREO; + return Audio::makeRawStream(file, soundParams.rate, flags, DisposeAfterUse::YES); } - else - return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams.rate, soundParams.stereo, DisposeAfterUse::YES); } } // End of namespace ZVision -- cgit v1.2.3 From 7644e00bf3e55c1b6b2ea0d74db89d8539cb9f31 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 19:24:39 -0500 Subject: ZVISION: Convert ResultActions to take a String pointer in their constructors There's no point in copying the String since it's just being parsed --- engines/zvision/actions.cpp | 36 +++++++++++++++++------------------ engines/zvision/actions.h | 20 +++++++++---------- engines/zvision/scr_file_handling.cpp | 6 +++--- 3 files changed, 31 insertions(+), 31 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index a5b1e951aa..791eda11e0 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -33,8 +33,8 @@ namespace ZVision { // ActionAdd ////////////////////////////////////////////////////////////////////////////// -ActionAdd::ActionAdd(Common::String line) { - sscanf(line.c_str(), ":add(%u,%hhu)", &_key, &_value); +ActionAdd::ActionAdd(Common::String *line) { + sscanf(line->c_str(), ":add(%u,%hhu)", &_key, &_value); } bool ActionAdd::execute(ZVision *engine) { @@ -47,8 +47,8 @@ bool ActionAdd::execute(ZVision *engine) { // ActionAssign ////////////////////////////////////////////////////////////////////////////// -ActionAssign::ActionAssign(Common::String line) { - sscanf(line.c_str(), ":assign(%u, %hhu)", &_key, &_value); +ActionAssign::ActionAssign(Common::String *line) { + sscanf(line->c_str(), ":assign(%u, %hhu)", &_key, &_value); } bool ActionAssign::execute(ZVision *engine) { @@ -61,8 +61,8 @@ bool ActionAssign::execute(ZVision *engine) { // ActionAttenuate ////////////////////////////////////////////////////////////////////////////// -ActionAttenuate::ActionAttenuate(Common::String line) { - sscanf(line.c_str(), ":assign(%u, %hd)", &_key, &_attenuation); +ActionAttenuate::ActionAttenuate(Common::String *line) { + sscanf(line->c_str(), ":assign(%u, %hd)", &_key, &_attenuation); } bool ActionAttenuate::execute(ZVision *engine) { @@ -75,8 +75,8 @@ bool ActionAttenuate::execute(ZVision *engine) { // ActionChangeLocation ////////////////////////////////////////////////////////////////////////////// -ActionChangeLocation::ActionChangeLocation(Common::String line) { - sscanf(line.c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); +ActionChangeLocation::ActionChangeLocation(Common::String *line) { + sscanf(line->c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); } bool ActionChangeLocation::execute(ZVision *engine) { @@ -89,8 +89,8 @@ bool ActionChangeLocation::execute(ZVision *engine) { // ActionCrossfade ////////////////////////////////////////////////////////////////////////////// -ActionCrossfade::ActionCrossfade(Common::String line) { - sscanf(line.c_str(), +ActionCrossfade::ActionCrossfade(Common::String *line) { + sscanf(line->c_str(), ":crossfade(%u %u %hhu %hhu %hhu %hhu %hu)", &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } @@ -105,9 +105,9 @@ bool ActionCrossfade::execute(ZVision *engine) { // ActionPreloadAnimation ////////////////////////////////////////////////////////////////////////////// -ActionPreloadAnimation::ActionPreloadAnimation(Common::String line) { +ActionPreloadAnimation::ActionPreloadAnimation(Common::String *line) { // The two %*hhu are always 0 and dont seem to have a use - sscanf(line.c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); + sscanf(line->c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); } bool ActionPreloadAnimation::execute(ZVision *engine) { @@ -120,9 +120,9 @@ bool ActionPreloadAnimation::execute(ZVision *engine) { // ActionPlayAnimation ////////////////////////////////////////////////////////////////////////////// -ActionPlayAnimation::ActionPlayAnimation(Common::String line) { +ActionPlayAnimation::ActionPlayAnimation(Common::String *line) { // The two %*hhu are always 0 and dont seem to have a use - sscanf(line.c_str(), + sscanf(line->c_str(), ":animplay:%u(%s %u %u %u %u %u %u %hhu %*hhu %*hhu %u %hhu)", &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); } @@ -137,8 +137,8 @@ bool ActionPlayAnimation::execute(ZVision *engine) { // ActionRandom ////////////////////////////////////////////////////////////////////////////// -ActionRandom::ActionRandom(Common::String line) { - sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); +ActionRandom::ActionRandom(Common::String *line) { + sscanf(line->c_str(), ":random:%u, %u)", &_key, &_max); } bool ActionRandom::execute(ZVision *engine) { @@ -152,8 +152,8 @@ bool ActionRandom::execute(ZVision *engine) { // ActionTimer ////////////////////////////////////////////////////////////////////////////// -ActionTimer::ActionTimer(Common::String line) { - sscanf(line.c_str(), ":timer:%u(%hu)", &_key, &_time); +ActionTimer::ActionTimer(Common::String *line) { + sscanf(line->c_str(), ":timer:%u(%hu)", &_key, &_time); } bool ActionTimer::execute(ZVision *engine) { diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index aed8483ee7..9b2267df82 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -74,7 +74,7 @@ public: class ActionAdd : public ResultAction { public: - ActionAdd(Common::String line); + ActionAdd(Common::String *line); bool execute(ZVision *engine); private: @@ -84,7 +84,7 @@ private: class ActionAssign : public ResultAction { public: - ActionAssign(Common::String line); + ActionAssign(Common::String *line); bool execute(ZVision *engine); private: @@ -94,7 +94,7 @@ private: class ActionAttenuate : public ResultAction { public: - ActionAttenuate(Common::String line); + ActionAttenuate(Common::String *line); bool execute(ZVision *engine); private: @@ -104,7 +104,7 @@ private: class ActionChangeLocation : public ResultAction { public: - ActionChangeLocation(Common::String line); + ActionChangeLocation(Common::String *line); bool execute(ZVision *engine); private: @@ -116,7 +116,7 @@ private: class ActionCrossfade : public ResultAction { public: - ActionCrossfade(Common::String line); + ActionCrossfade(Common::String *line); bool execute(ZVision *engine); private: @@ -131,7 +131,7 @@ private: class ActionPlayAnimation : public ResultAction { public: - ActionPlayAnimation(Common::String line); + ActionPlayAnimation(Common::String *line); bool execute(ZVision *engine); private: @@ -150,7 +150,7 @@ private: class ActionPreloadAnimation : public ResultAction { public: - ActionPreloadAnimation(Common::String line); + ActionPreloadAnimation(Common::String *line); bool execute(ZVision *engine); private: @@ -163,13 +163,13 @@ private: // TODO: See if this exists in ZGI. It doesn't in ZNem //class ActionUnloadAnimation : public ResultAction { //public: -// ActionUnloadAnimation(Common::String line); +// ActionUnloadAnimation(Common::String *line); // bool execute(ZVision *engine); //}; class ActionRandom : public ResultAction { public: - ActionRandom(Common::String line); + ActionRandom(Common::String *line); bool execute(ZVision *engine); private: @@ -179,7 +179,7 @@ private: class ActionTimer : public ResultAction { public: - ActionTimer(Common::String line); + ActionTimer(Common::String *line); bool execute(ZVision *engine); private: diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 6a2e8cf701..168a6d830a 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -135,11 +135,11 @@ void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List while (!line.contains('}')) { // Parse for the action type if (line.matchString("*:add*", true)) { - actionList.push_back(new ActionAdd(line)); + actionList.push_back(new ActionAdd(&line)); } else if (line.matchString("*:animplay*", true)) { - actionList.push_back(new ActionPlayAnimation(line)); + actionList.push_back(new ActionPlayAnimation(&line)); } else if (line.matchString("*:animpreload*", true)) { - actionList.push_back(new ActionPreloadAnimation(line)); + actionList.push_back(new ActionPreloadAnimation(&line)); } else if (line.matchString("*:animunload*", true)) { -- cgit v1.2.3 From 32f88486058c0553ae2c0cd1808ef06fcd09b143 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 18 Jul 2013 14:38:57 -0500 Subject: ZVISION: Create utility function to convert .RAW to .WAV --- engines/zvision/utility.cpp | 44 +++++++++++++++++++++++++++++++++++++------- engines/zvision/utility.h | 18 ++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index 5f69fd7433..42fadc78c4 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -25,6 +25,8 @@ #include "common/tokenizer.h" #include "zvision/utility.h" +#include "zvision/zvision.h" +#include "zvision/zork_raw.h" namespace ZVision { @@ -179,13 +181,6 @@ void dumpEveryResultAction(const Common::String &destFile) { output.close(); } -/** - * 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) { Common::StringTokenizer tokenizer(fullPath, "/\\"); Common::String token; @@ -196,4 +191,39 @@ Common::String getFileName(const Common::String &fullPath) { 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()]; + int readBytes = audioStream->readBuffer(buffer, file.size()); + output.write(buffer, file.size() * 2); +} + } // End of namespace ZVision diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index dba765b65c..46f81efb33 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -30,6 +30,8 @@ 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 @@ -73,8 +75,24 @@ void removeDuplicateEntries(Common::Array *container) { } } +/** + * 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 From 8f32592ab9556c57d459be116863d3bb7ac88c72 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 18 Jul 2013 14:40:02 -0500 Subject: ZVISION: Create console command to use the raw2wav function --- engines/zvision/console.cpp | 11 +++++++++++ engines/zvision/console.h | 1 + 2 files changed, 12 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index a18da8605a..ed244c1f58 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -31,6 +31,7 @@ #include "zvision/zvision.h" #include "zvision/zork_avi_decoder.h" #include "zvision/zork_raw.h" +#include "zvision/utility.h" namespace ZVision { @@ -38,6 +39,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("loadimage", WRAP_METHOD(Console, cmdLoadImage)); DCmd_Register("loadvideo", WRAP_METHOD(Console, cmdLoadVideo)); DCmd_Register("loadsound", WRAP_METHOD(Console, cmdLoadSound)); + DCmd_Register("raw2wav", WRAP_METHOD(Console, cmdRawToWav)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -82,4 +84,13 @@ bool Console::cmdLoadSound(int argc, const char **argv) { return true; } +bool Console::cmdRawToWav(int argc, const char **argv) { + if (argc != 3) { + DebugPrintf("Use raw2wav to dump a .RAW file to .WAV\n"); + return true; + } + + convertRawToWav(argv[1], _engine, argv[2]); +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 354051d2b0..cf22c42e35 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -40,6 +40,7 @@ namespace ZVision { 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); }; } // End of namespace ZVision -- cgit v1.2.3 From 1c44fe7afba706400dd8d3c2132f47da4e07ac1e Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 18 Jul 2013 14:40:45 -0500 Subject: ZVISION: Fix the error causing distortions in the sound --- engines/zvision/zork_raw.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 2ffe8eb3a6..03a35e09ab 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -73,7 +73,7 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag dis } int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { - uint16 bytesRead = 0; + uint32 bytesRead = 0; // 0: Left, 1: Right byte channel = 0; @@ -114,7 +114,7 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { buffer[bytesRead - 1] = (int16)sample; index += _stepAdjustmentTable[(encodedSample >> 4) & 7]; - index = CLIP(index, 0, 88); + index = CLIP(index, 0, 88); _lastSample[channel].sample = sample; _lastSample[channel].index = index; -- cgit v1.2.3 From 125a061a9650297d81a76cc8e77033ca099191b0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 18 Jul 2013 14:43:16 -0500 Subject: ZVISION: Convert to using MKTAG() instead of checking each char individually --- engines/zvision/image.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp index 981308fa31..6e6b802739 100644 --- a/engines/zvision/image.cpp +++ b/engines/zvision/image.cpp @@ -42,11 +42,11 @@ void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint // Read the magic number // Some files are true TGA, while others are TGZ - char fileType[4]; - file.read(fileType, 4); + uint32 fileType; + fileType = file.readUint32BE(); // Check for TGZ files - if (fileType[0] == 'T' && fileType[1] == 'G' && fileType[2] == 'Z' && fileType[3] == '\0') { + if (fileType == MKTAG('T', 'G', 'Z', '\0')) { // TGZ files have a header and then Bitmap data that is compressed with LZSS uint32 decompressedSize = file.readSint32LE(); uint32 width = file.readSint32LE(); -- cgit v1.2.3 From 47161ef30d8d7350a92fe28a031437abb338732c Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 15:37:46 -0500 Subject: ZVISION: LZSSReadStream - Decompress directly to the destination buffer instead of an intermediate buffer --- engines/zvision/image.cpp | 6 ++-- engines/zvision/lzss_read_stream.cpp | 62 ++++++++---------------------------- engines/zvision/lzss_read_stream.h | 13 ++------ 3 files changed, 20 insertions(+), 61 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp index 6e6b802739..cacfec302c 100644 --- a/engines/zvision/image.cpp +++ b/engines/zvision/image.cpp @@ -52,9 +52,9 @@ void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint uint32 width = file.readSint32LE(); uint32 height = file.readSint32LE(); - LzssReadStream stream(&file, false, decompressedSize); - byte *buffer = new byte[stream.currentSize()]; - stream.read(buffer, stream.currentSize()); + LzssReadStream stream(&file); + byte *buffer = new byte[decompressedSize]; + stream.read(buffer, decompressedSize); _system->copyRectToScreen(buffer, width * 2, x, y, width, height); } else { diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 2d7acdb8ce..35c708a6c7 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -26,7 +26,7 @@ namespace ZVision { -LzssReadStream::LzssReadStream(Common::SeekableReadStream *source, bool stream, uint32 decompressedSize) +LzssReadStream::LzssReadStream(Common::SeekableReadStream *source) : _source(source), // It's convention to set the starting cursor position to blockSize - 16 _windowCursor(0x0FEE), @@ -34,24 +34,12 @@ LzssReadStream::LzssReadStream(Common::SeekableReadStream *source, bool stream, _eosFlag(false) { // Clear the window to null memset(_window, 0, _blockSize); - - // Reserve space in the destination buffer - // TODO: Make a better guess - if (decompressedSize == _npos) { - decompressedSize = source->size(); - } - _destination.reserve(decompressedSize); - - if (stream) - decompressBytes(_blockSize); - else - decompressAll(); } -void LzssReadStream::decompressBytes(uint32 numberOfBytes) { - uint32 bytesRead = 0; +uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) { + uint32 destinationCursor = 0; - while (!_source->eos() && bytesRead <= numberOfBytes) { + while (destinationCursor < numberOfBytes) { byte flagbyte = _source->readByte(); if (_source->eos()) break; @@ -61,12 +49,11 @@ void LzssReadStream::decompressBytes(uint32 numberOfBytes) { if ((flagbyte & mask) == mask) { byte data = _source->readByte(); - bytesRead++; if (_source->eos()) - break; + return destinationCursor; _window[_windowCursor] = data; - _destination.push_back(data); + destination[destinationCursor++] = data; // Increment and wrap the window cursor _windowCursor = (_windowCursor + 1) & 0xFFF; @@ -74,14 +61,12 @@ void LzssReadStream::decompressBytes(uint32 numberOfBytes) { else { byte low = _source->readByte(); - bytesRead++; if (_source->eos()) - break; + return destinationCursor; byte high = _source->readByte(); - bytesRead++; if (_source->eos()) - break; + return destinationCursor; uint16 length = (high & 0xF) + 2; uint16 offset = low | ((high & 0xF0)<<4); @@ -90,7 +75,7 @@ void LzssReadStream::decompressBytes(uint32 numberOfBytes) { { byte temp = _window[(offset + j) & 0xFFF]; _window[_windowCursor] = temp; - _destination.push_back(temp); + destination[destinationCursor++] = temp; _windowCursor = (_windowCursor + 1) & 0xFFF; } }; @@ -98,10 +83,8 @@ void LzssReadStream::decompressBytes(uint32 numberOfBytes) { mask = mask << 1; } } -} -void LzssReadStream::decompressAll() { - decompressBytes(_source->size()); + return destinationCursor; } bool LzssReadStream::eos() const { @@ -109,30 +92,13 @@ bool LzssReadStream::eos() const { } uint32 LzssReadStream::read(void *dataPtr, uint32 dataSize) { - // Check if there are enough bytes available - // If not, keep decompressing until we have enough bytes or until we reach EOS - while (dataSize > _destination.size() - _readCursor) { - // Check if we can read any more data from source - if (_source->eos()) { - // Shorten the dataSize to what we have left and flag that we're at EOS - dataSize = _destination.size() - _readCursor; - _eosFlag = true; - break; - } - - decompressBytes(_blockSize); - } - - if (dataSize > 0) { - memcpy(dataPtr, _destination.begin() + _readCursor, dataSize); - _readCursor += dataSize; + uint32 bytesRead = decompressBytes(static_cast(dataPtr), dataSize); + if (bytesRead < dataSize) { + // Flag that we're at EOS + _eosFlag = true; } return dataSize; } -uint32 LzssReadStream::currentSize() const { - return _destination.size(); -} - } // End of namespace ZVision diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 142bf9e1a2..0dea25b325 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -34,14 +34,11 @@ class LzssReadStream : public Common::ReadStream { public: /** * A class that decompresses LZSS data and implements ReadStream for easy access - * to the decompiled data. It can either decompress all the data in the beginning - * or decompress as needed by read(). + * to the decompiled data. * * @param source The source data - * @param stream Decompress the data as needed (true) or all at once (false) - * @param decompressedSize The size of the decompressed data. If npos, the class will choose a size and grow as needed */ - LzssReadStream(Common::SeekableReadStream *source, bool stream = true, uint32 decompressedSize = _npos); + LzssReadStream(Common::SeekableReadStream *source); public: static const uint32 _npos = 0xFFFFFFFFu; @@ -49,7 +46,6 @@ public: private: Common::SeekableReadStream *_source; - Common::Array _destination; char _window[_blockSize]; uint16 _windowCursor; uint32 _readCursor; @@ -58,7 +54,6 @@ private: public: bool eos() const; uint32 read(void *dataPtr, uint32 dataSize); - uint32 currentSize() const; private: /** @@ -66,9 +61,7 @@ private: * * @param numberOfBytes How many bytes to decompress. This is a count of source bytes, not destination bytes */ - void decompressBytes(uint32 numberOfBytes); - /** Decompress all of the source stream. */ - void decompressAll(); + uint32 decompressBytes(byte* destination, uint32 numberOfBytes); }; } -- cgit v1.2.3 From b316df9e821a7cb27290e8ebed49eb78c2ee5884 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 17 Jul 2013 15:45:09 -0500 Subject: ZVISION: Add a return statement for when image load fails --- engines/zvision/image.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp index cacfec302c..c4823813dc 100644 --- a/engines/zvision/image.cpp +++ b/engines/zvision/image.cpp @@ -63,9 +63,10 @@ void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint // Decode Graphics::TGADecoder tga; - if (!tga.loadStream(file)) + if (!tga.loadStream(file)) { error("Error while reading TGA image"); - file.close(); + return; + } const Graphics::Surface *tgaSurface = tga.getSurface(); _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); -- cgit v1.2.3 From d546e11cf12d90eb246513ccc0be867172f0af96 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 19 Jul 2013 10:23:29 -0500 Subject: ZVISION: Fix namespace indentation --- engines/zvision/console.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.h b/engines/zvision/console.h index cf22c42e35..3110d8ad37 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -27,21 +27,20 @@ namespace ZVision { - class ZVision; +class ZVision; - class Console : public GUI::Debugger { - public: - Console(ZVision *engine); - virtual ~Console() {} +class Console : public GUI::Debugger { +public: + Console(ZVision *engine); + virtual ~Console() {} - private: - ZVision *_engine; +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); - }; + bool cmdLoadImage(int argc, const char **argv); + bool cmdLoadVideo(int argc, const char **argv); + bool cmdLoadSound(int argc, const char **argv); +}; } // End of namespace ZVision #endif -- cgit v1.2.3 From 471364077953509ae7528d3097ca746fe5588f7c Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 19 Jul 2013 10:24:02 -0500 Subject: ZVISION: Remove extraneous member variable --- engines/zvision/lzss_read_stream.cpp | 1 - engines/zvision/lzss_read_stream.h | 1 - 2 files changed, 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 35c708a6c7..d169620a25 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -30,7 +30,6 @@ LzssReadStream::LzssReadStream(Common::SeekableReadStream *source) : _source(source), // It's convention to set the starting cursor position to blockSize - 16 _windowCursor(0x0FEE), - _readCursor(0), _eosFlag(false) { // Clear the window to null memset(_window, 0, _blockSize); diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 0dea25b325..b2d6085a29 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -48,7 +48,6 @@ private: Common::SeekableReadStream *_source; char _window[_blockSize]; uint16 _windowCursor; - uint32 _readCursor; bool _eosFlag; public: -- cgit v1.2.3 From 94000e07811831f1ffdb2575b0cc3513c34a1d36 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 19 Jul 2013 10:25:02 -0500 Subject: ZVISION: Replace includes with forward declarations --- engines/zvision/lzss_read_stream.h | 5 ++++- engines/zvision/script_manager.h | 7 +++++-- engines/zvision/single_value_container.cpp | 2 ++ engines/zvision/single_value_container.h | 4 +++- engines/zvision/utility.cpp | 1 + engines/zvision/utility.h | 6 ++++-- engines/zvision/zfs_archive.cpp | 4 +++- engines/zvision/zfs_archive.h | 10 +++++++--- 8 files changed, 29 insertions(+), 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index b2d6085a29..0814220728 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -25,9 +25,12 @@ #include "common/types.h" #include "common/stream.h" -#include "common/memstream.h" #include "common/array.h" +namespace Common { +class SeekableReadStream; +} + namespace ZVision { class LzssReadStream : public Common::ReadStream { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 7924eee4c0..2d9bcc3fd5 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -23,14 +23,17 @@ #ifndef ZVISION_SCRIPT_MANAGER_H #define ZVISION_SCRIPT_MANAGER_H -#include "common/str.h" -#include "common/stream.h" #include "common/hashmap.h" #include "common/stack.h" #include "zvision/puzzle.h" #include "zvision/control.h" +namespace Common { +class String; +class SeekableReadStream; +} + namespace ZVision { class ZVision; diff --git a/engines/zvision/single_value_container.cpp b/engines/zvision/single_value_container.cpp index 7e27098377..0fd758a85e 100644 --- a/engines/zvision/single_value_container.cpp +++ b/engines/zvision/single_value_container.cpp @@ -21,7 +21,9 @@ */ #include "common/scummsys.h" + #include "common/textconsole.h" +#include "common/str.h" #include "zvision/single_value_container.h" diff --git a/engines/zvision/single_value_container.h b/engines/zvision/single_value_container.h index 49c7267f77..593f11c737 100644 --- a/engines/zvision/single_value_container.h +++ b/engines/zvision/single_value_container.h @@ -23,7 +23,9 @@ #ifndef ZVISION_OBJECT_H #define ZVISION_OBJECT_H -#include "common/str.h" +namespace Common { +class String; +} namespace ZVision { diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index 42fadc78c4..bf8e5c91d6 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -23,6 +23,7 @@ #include "common/scummsys.h" #include "common/tokenizer.h" +#include "common/file.h" #include "zvision/utility.h" #include "zvision/zvision.h" diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 46f81efb33..e68d0de449 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -24,10 +24,12 @@ #ifndef ZVISION_UTILITY_H #define ZVISION_UTILITY_H -#include "common/str.h" -#include "common/file.h" #include "common/array.h" +namespace Common { +class String; +} + namespace ZVision { class ZVision; diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index fbfe3d3dc4..f815d9ccd3 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -22,10 +22,12 @@ #include "common/scummsys.h" -#include "zvision/zfs_archive.h" #include "common/hashmap.h" #include "common/memstream.h" #include "common/debug.h" +#include "common/file.h" + +#include "zvision/zfs_archive.h" namespace ZVision { diff --git a/engines/zvision/zfs_archive.h b/engines/zvision/zfs_archive.h index cb371f2c87..e683ac1b53 100644 --- a/engines/zvision/zfs_archive.h +++ b/engines/zvision/zfs_archive.h @@ -24,8 +24,12 @@ #define ZVISION_ZFS_ARCHIVE_H #include "common/archive.h" -#include "common/file.h" -#include "common/fs.h" +#include "common/hashmap.h" + + +namespace Common { +class String; +} namespace ZVision { @@ -48,7 +52,7 @@ struct ZfsEntryHeader { uint32 unknown; }; -typedef Common::HashMap ZfsEntryHeaderMap; +typedef Common::HashMap ZfsEntryHeaderMap; class ZfsArchive : public Common::Archive { public: -- cgit v1.2.3 From 6d7541a43040ee6791bf0099ddff9645753ac24b Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 19 Jul 2013 11:07:05 -0500 Subject: ZVISION: Create RenderManager class and move code from image.cpp --- engines/zvision/image.cpp | 80 ------------------------------------- engines/zvision/render_manager.cpp | 81 ++++++++++++++++++++++++++++++++++++++ engines/zvision/render_manager.h | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 80 deletions(-) delete mode 100644 engines/zvision/image.cpp create mode 100644 engines/zvision/render_manager.cpp create mode 100644 engines/zvision/render_manager.h (limited to 'engines/zvision') diff --git a/engines/zvision/image.cpp b/engines/zvision/image.cpp deleted file mode 100644 index c4823813dc..0000000000 --- a/engines/zvision/image.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* 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/scummsys.h" - -#include "common/file.h" -#include "common/system.h" - -#include "graphics/decoders/tga.h" - -#include "zvision/zvision.h" -#include "zvision/lzss_read_stream.h" - -namespace ZVision { - -void ZVision::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { - Common::File file; - - if (!file.open(fileName)) { - error("Could not open file %s", fileName.c_str()); - return; - } - - // Read the magic number - // Some files are true TGA, while others are TGZ - uint32 fileType; - fileType = file.readUint32BE(); - - // Check for TGZ files - if (fileType == MKTAG('T', 'G', 'Z', '\0')) { - // TGZ files have a header and then Bitmap data that is compressed with LZSS - uint32 decompressedSize = file.readSint32LE(); - uint32 width = file.readSint32LE(); - uint32 height = file.readSint32LE(); - - LzssReadStream stream(&file); - byte *buffer = new byte[decompressedSize]; - stream.read(buffer, decompressedSize); - - _system->copyRectToScreen(buffer, width * 2, x, y, width, height); - } else { - // Reset the cursor - file.seek(0); - - // Decode - Graphics::TGADecoder tga; - if (!tga.loadStream(file)) { - error("Error while reading TGA image"); - return; - } - - const Graphics::Surface *tgaSurface = tga.getSurface(); - _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); - - tga.destroy(); - } - - _needsScreenUpdate = true; -} - -} // End of namespace ZVision diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp new file mode 100644 index 0000000000..671e7c0136 --- /dev/null +++ b/engines/zvision/render_manager.cpp @@ -0,0 +1,81 @@ +/* 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/scummsys.h" + +#include "common/file.h" +#include "common/system.h" + +#include "graphics/decoders/tga.h" + +#include "zvision/render_manager.h" +#include "zvision/lzss_read_stream.h" + +namespace ZVision { + +RenderManager::RenderManager(OSystem *system) : _system(system) {} + +void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { + Common::File file; + + if (!file.open(fileName)) { + error("Could not open file %s", fileName.c_str()); + return; + } + + // Read the magic number + // Some files are true TGA, while others are TGZ + uint32 fileType; + fileType = file.readUint32BE(); + + // Check for TGZ files + if (fileType == MKTAG('T', 'G', 'Z', '\0')) { + // TGZ files have a header and then Bitmap data that is compressed with LZSS + uint32 decompressedSize = file.readSint32LE(); + uint32 width = file.readSint32LE(); + uint32 height = file.readSint32LE(); + + LzssReadStream stream(&file); + byte *buffer = new byte[decompressedSize]; + stream.read(buffer, decompressedSize); + + _system->copyRectToScreen(buffer, width * 2, x, y, width, height); + } else { + // Reset the cursor + file.seek(0); + + // Decode + Graphics::TGADecoder tga; + if (!tga.loadStream(file)) + error("Error while reading TGA image"); + file.close(); + + const Graphics::Surface *tgaSurface = tga.getSurface(); + _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); + + tga.destroy(); + } + + _needsScreenUpdate = true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h new file mode 100644 index 0000000000..137ec51d5a --- /dev/null +++ b/engines/zvision/render_manager.h @@ -0,0 +1,70 @@ +/* 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 ZVISION_RENDER_MANAGER_H +#define ZVISION_RENDER_MANAGER_H + +#include "common/types.h" + +class OSystem; + +namespace Common { +class String; +} + +namespace ZVision { + +class RenderManager { +public: + RenderManager(OSystem *system); + +public: + enum RenderState { + PANORAMA, + TILT, + FLAT + }; + +private: + OSystem *_system; + RenderState _renderState; + + struct { + uint16 fieldOfView; + uint16 linearScale; + } _panoramaOptions; + + // TODO: See if tilt and panorama need to have separate options + struct { + uint16 fieldOfView; + uint16 linearScale; + } _tiltOptions; + + bool _needsScreenUpdate; + +public: + void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 4bd95987d2119027fa175e08f22d0171f53358c0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 19 Jul 2013 11:07:58 -0500 Subject: ZVISION: Convert old code to use RenderManager --- engines/zvision/console.cpp | 3 ++- engines/zvision/console.h | 1 + engines/zvision/zvision.cpp | 6 ++++++ engines/zvision/zvision.h | 5 ++++- 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index ed244c1f58..2b45ed24b9 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -29,6 +29,7 @@ #include "zvision/console.h" #include "zvision/zvision.h" +#include "zvision/render_manager.h" #include "zvision/zork_avi_decoder.h" #include "zvision/zork_raw.h" #include "zvision/utility.h" @@ -47,7 +48,7 @@ bool Console::cmdLoadImage(int argc, const char **argv) { DebugPrintf("Use loadimage to load an image to the screen\n"); return true; } - _engine->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); + _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); return true; } diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 3110d8ad37..05b8f1247f 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -40,6 +40,7 @@ private: 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); }; } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 4ce775db86..0e2e02788f 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -35,6 +35,7 @@ #include "zvision/zvision.h" #include "zvision/console.h" #include "zvision/script_manager.h" +#include "zvision/render_manager.h" #include "zvision/zfs_archive.h" #include "zvision/detection.h" @@ -73,6 +74,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); + _renderManager = new RenderManager(_system); debug("ZVision::ZVision"); } @@ -151,6 +153,10 @@ ScriptManager *ZVision::getScriptManager() const { return _scriptManager; } +RenderManager *ZVision::getRenderManager() const { + return _renderManager; +} + Common::RandomSource *ZVision::getRandomSource() const { return _rnd; } diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 17a7c026f1..7740dba6dc 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -40,6 +40,7 @@ namespace ZVision { struct ZVisionGameDescription; class Console; class ScriptManager; +class RenderManager; // our engine debug channels enum { @@ -65,6 +66,8 @@ private: Common::RandomSource *_rnd; // Managers ScriptManager *_scriptManager; + RenderManager *_renderManager; + // To prevent allocation every time we process events Common::Event _event; @@ -77,10 +80,10 @@ public: Common::Language getLanguage() const; virtual Common::Error run(); ScriptManager *getScriptManager() const; + RenderManager *getRenderManager() const; Common::RandomSource *getRandomSource() const; ZVisionGameId getGameId() const; - void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); void startVideo(Video::VideoDecoder *videoDecoder); void continueVideo(); -- cgit v1.2.3 From 2bfefd969128b0a33afc8beccf52a4e9f6e4840f Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 19 Jul 2013 11:08:37 -0500 Subject: ZVISION: Remove extraneous file --- engines/zvision/graphics.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 engines/zvision/graphics.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/graphics.cpp b/engines/zvision/graphics.cpp deleted file mode 100644 index 610960dd72..0000000000 --- a/engines/zvision/graphics.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/zvision.h" - -namespace ZVision { - -} // End of namespace ZVision -- cgit v1.2.3 From b3eb48996af2236baf89dd5afd6cfeef1b5e86bd Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 19 Jul 2013 12:17:14 -0500 Subject: ZVISION: Fix memory leaks --- engines/zvision/events.cpp | 2 +- engines/zvision/render_manager.cpp | 2 ++ engines/zvision/utility.cpp | 2 ++ engines/zvision/video.cpp | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index a3d6b6b670..afa2d95207 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -65,7 +65,7 @@ void ZVision::processEvents() { initGraphics(_width, _height, true, &_pixelFormat); delete _currentVideo; _currentVideo = 0; - delete _scaledVideoFrameBuffer; + delete[] _scaledVideoFrameBuffer; _scaledVideoFrameBuffer = 0; } break; diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 671e7c0136..6d3f7c6fc1 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -59,6 +59,8 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x stream.read(buffer, decompressedSize); _system->copyRectToScreen(buffer, width * 2, x, y, width, height); + + delete[] buffer; } else { // Reset the cursor file.seek(0); diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index bf8e5c91d6..fa29fe660f 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -225,6 +225,8 @@ void convertRawToWav(const Common::String &inputFile, ZVision *engine, const Com int16 *buffer = new int16[file.size()]; int readBytes = audioStream->readBuffer(buffer, file.size()); output.write(buffer, file.size() * 2); + + delete[] buffer; } } // End of namespace ZVision diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 0cca486af6..0428090003 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -118,7 +118,7 @@ void ZVision::continueVideo() { initGraphics(_width, _height, true, &_pixelFormat); delete _currentVideo; _currentVideo = 0; - delete _scaledVideoFrameBuffer; + delete[] _scaledVideoFrameBuffer; _scaledVideoFrameBuffer = 0; } -- cgit v1.2.3 From 9e6b2dfc12706f4b367fedf951759c8be0ab5e90 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 20 Jul 2013 12:14:32 -0500 Subject: ZVISION: Create member function for creating a panorama look up table --- engines/zvision/render_manager.cpp | 44 +++++++++++++++++++++++++++++++++++++- engines/zvision/render_manager.h | 10 ++++++++- engines/zvision/zvision.cpp | 2 +- 3 files changed, 53 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 6d3f7c6fc1..2a8ed1274e 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -24,6 +24,7 @@ #include "common/file.h" #include "common/system.h" +#include "common/rect.h" #include "graphics/decoders/tga.h" @@ -32,7 +33,12 @@ namespace ZVision { -RenderManager::RenderManager(OSystem *system) : _system(system) {} +RenderManager::RenderManager(OSystem *system, const int width, const int height) + : _system(system), + _width(width), + _height(height), + _renderTable(width, height) { +} void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { Common::File file; @@ -80,4 +86,40 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x _needsScreenUpdate = true; } +void RenderManager::generatePanoramaLookupTable() { + float fieldOfView = _panoramaOptions.fieldOfView; + float scale = _panoramaOptions.linearScale; + _renderTable.clear(); + + double halfWidth = (double)_width / 2.0; + double halfHeight = (double)_height / 2.0; + + double fovRadians = (fieldOfView * 3.14159265 / 180.0); + double halfHeightOverTan = halfHeight / tan(fovRadians); + double tanOverHalfHeight = tan(fovRadians) / halfHeight; + + for (int32 x = 0; x < _width; x++) { + // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) + double xPos = (double)x - halfWidth + 0.01; + + double tempX = atan(xPos*tanOverHalfHeight); + double scaledX = scale * halfHeightOverTan * tempX; + double nn = cos(tempX); + double newHalfWidth = halfHeight * nn * halfHeightOverTan * tanOverHalfHeight*2.0; + + int32 newX = floor(scaledX);// + half_w); + + double yScale = newHalfWidth / (double)_height; + double et2 = ((double)_height - newHalfWidth) / 2.0; + + for (int32 y = 0; y < _height; y++) { + double et1 = (double)y*yScale; + + _renderTable(x, y).x = newX; //pixel index + + int32 newY = floor(et2 + et1); + _renderTable(x, y).y = newY; //pixel index + } + } +} } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 137ec51d5a..e481c26666 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -25,17 +25,20 @@ #include "common/types.h" +#include "zvision/dense_2d_array.h" + class OSystem; namespace Common { class String; +class Point; } namespace ZVision { class RenderManager { public: - RenderManager(OSystem *system); + RenderManager(OSystem *system, const int width, const int height); public: enum RenderState { @@ -46,6 +49,8 @@ public: private: OSystem *_system; + const int _width; + const int _height; RenderState _renderState; struct { @@ -59,10 +64,13 @@ private: uint16 linearScale; } _tiltOptions; + Dense2DArray _renderTable; + bool _needsScreenUpdate; public: void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); + void generatePanoramaLookupTable(); }; } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 0e2e02788f..57c9dea211 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -74,7 +74,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); - _renderManager = new RenderManager(_system); + _renderManager = new RenderManager(_system, _width, _height); debug("ZVision::ZVision"); } -- cgit v1.2.3 From cd51b646f39fb826f5d618c6d61c996844f628dd Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:13:57 -0500 Subject: ZVISION: Create a class for handling all render table logic Aka, creating the lookup tables, storing the current render state, and eventually doing the image mutations. --- engines/zvision/render_table.cpp | 95 ++++++++++++++++++++++++++++++++++++++++ engines/zvision/render_table.h | 69 +++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 engines/zvision/render_table.cpp create mode 100644 engines/zvision/render_table.h (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp new file mode 100644 index 0000000000..1baf9514a3 --- /dev/null +++ b/engines/zvision/render_table.cpp @@ -0,0 +1,95 @@ +/* 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/scummsys.h" + +#include "zvision/render_table.h" + + +namespace ZVision { + +RenderTable::RenderTable(uint32 numRows, uint32 numColumns) + : _numRows(numRows), + _numColumns(numColumns) { + assert(numRows != 0 && numColumns != 0); + + _internalBuffer = new Common::Point[numRows * numColumns]; +} + +RenderTable::~RenderTable() { + delete[] _internalBuffer; +} + +void RenderTable::setRenderState(RenderState newState) { + _renderState = newState; + + switch (newState) { + case PANORAMA: + _panoramaOptions.fieldOfView = 60; + _panoramaOptions.linearScale = 1; + generatePanoramaLookupTable(); + break; + case TILT: + generateTiltLookupTable(); + break; + case FLAT: + // Intentionally left empty + break; + } +} + +void RenderTable::generatePanoramaLookupTable() { + float fieldOfView = _panoramaOptions.fieldOfView; + float scale = _panoramaOptions.linearScale; + + memset(_internalBuffer, 0, _numRows * _numColumns * sizeof(uint16)); + + float halfWidth = (float)_numColumns / 2.0f; + float halfHeight = (float)_numRows / 2.0f; + + float fovRadians = (fieldOfView * M_PI / 180.0f); + float halfHeightOverTan = halfHeight / tan(fovRadians); + float tanOverHalfHeight = tan(fovRadians) / halfHeight; + + for (uint32 x = 0; x < _numRows; x++) { + // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) + float xPos = (float)x - halfWidth + 0.01; + float tempX = atan(xPos*tanOverHalfHeight); + + int32 newX = floor(scale * halfHeightOverTan * tempX);// + half_w); + float cosX = cos(tempX); + + for (uint32 y = 0; y < _numColumns; y++) { + int32 newY = floor(halfHeight + (y - halfHeight) * cosX); + + uint32 index = x * _numColumns + y; + _internalBuffer[index].x = newX; //pixel index + _internalBuffer[index].y = newY; //pixel index + } + } +} + +void RenderTable::generateTiltLookupTable() { + +} + +} // End of namespace ZVision diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h new file mode 100644 index 0000000000..9d54551c3b --- /dev/null +++ b/engines/zvision/render_table.h @@ -0,0 +1,69 @@ +/* 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 ZVISION_RENDER_TABLE_H +#define ZVISION_RENDER_TABLE_H + +#include "common/types.h" +#include "common/rect.h" + +namespace ZVision { + +class RenderTable { +public: + RenderTable(uint32 numRows, uint32 numColumns); + ~RenderTable(); + +public: + enum RenderState { + PANORAMA, + TILT, + FLAT + }; + +private: + uint32 _numColumns, _numRows; + Common::Point *_internalBuffer; + RenderState _renderState; + + struct { + uint16 fieldOfView; + uint16 linearScale; + } _panoramaOptions; + + // TODO: See if tilt and panorama need to have separate options + struct { + uint16 fieldOfView; + uint16 linearScale; + } _tiltOptions; + +public: + void setRenderState(RenderState newState); + +private: + void generatePanoramaLookupTable(); + void generateTiltLookupTable(); +}; + +} // End of namesapce ZVision + +#endif -- cgit v1.2.3 From ed4490730902780923bf1e91ed3617d56efb7c24 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:33:58 -0500 Subject: ZVISION: Move rendering logic from ZVision class to RenderManager class --- engines/zvision/events.cpp | 11 ++---- engines/zvision/render_manager.cpp | 60 ++++++++++++----------------- engines/zvision/render_manager.h | 77 ++++++++++++++++++++++++++------------ engines/zvision/video.cpp | 26 ++++++------- engines/zvision/zvision.cpp | 23 ++++-------- engines/zvision/zvision.h | 10 ----- 6 files changed, 101 insertions(+), 106 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index afa2d95207..a01ea74cd0 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -27,6 +27,7 @@ #include "common/events.h" #include "engines/util.h" +#include "zvision/render_manager.h" namespace ZVision { @@ -61,13 +62,9 @@ void ZVision::processEvents() { quitGame(); break; case Common::KEYCODE_ESCAPE: - if (_currentVideo != 0) { - initGraphics(_width, _height, true, &_pixelFormat); - delete _currentVideo; - _currentVideo = 0; - delete[] _scaledVideoFrameBuffer; - _scaledVideoFrameBuffer = 0; - } + if (_renderManager->isVideoPlaying()) + _renderManager->cancelVideo(); + break; default: break; diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 2a8ed1274e..8c3d37a160 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -24,8 +24,8 @@ #include "common/file.h" #include "common/system.h" -#include "common/rect.h" +#include "engines/util.h" #include "graphics/decoders/tga.h" #include "zvision/render_manager.h" @@ -37,9 +37,29 @@ RenderManager::RenderManager(OSystem *system, const int width, const int height) : _system(system), _width(width), _height(height), + _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 + _currentVideo(0), + _scaledVideoFrameBuffer(0), _renderTable(width, height) { } +/** + * Initialize graphics + */ +void RenderManager::initialize() { + initGraphics(_width, _height, true, &_pixelFormat); +} + +void RenderManager::updateScreen(bool isConsoleActive) { + if (_currentVideo != 0) + continueVideo(); + + if (_needsScreenUpdate || isConsoleActive) { + _system->updateScreen(); + _needsScreenUpdate = false; + } +} + void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { Common::File file; @@ -86,40 +106,8 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x _needsScreenUpdate = true; } -void RenderManager::generatePanoramaLookupTable() { - float fieldOfView = _panoramaOptions.fieldOfView; - float scale = _panoramaOptions.linearScale; - _renderTable.clear(); - - double halfWidth = (double)_width / 2.0; - double halfHeight = (double)_height / 2.0; - - double fovRadians = (fieldOfView * 3.14159265 / 180.0); - double halfHeightOverTan = halfHeight / tan(fovRadians); - double tanOverHalfHeight = tan(fovRadians) / halfHeight; - - for (int32 x = 0; x < _width; x++) { - // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) - double xPos = (double)x - halfWidth + 0.01; - - double tempX = atan(xPos*tanOverHalfHeight); - double scaledX = scale * halfHeightOverTan * tempX; - double nn = cos(tempX); - double newHalfWidth = halfHeight * nn * halfHeightOverTan * tanOverHalfHeight*2.0; - - int32 newX = floor(scaledX);// + half_w); - - double yScale = newHalfWidth / (double)_height; - double et2 = ((double)_height - newHalfWidth) / 2.0; - - for (int32 y = 0; y < _height; y++) { - double et1 = (double)y*yScale; - - _renderTable(x, y).x = newX; //pixel index - - int32 newY = floor(et2 + et1); - _renderTable(x, y).y = newY; //pixel index - } - } +void RenderManager::setRenderState(RenderTable::RenderState state) { + _renderTable.setRenderState(state); } + } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index e481c26666..f2f1dd72e4 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -24,14 +24,20 @@ #define ZVISION_RENDER_MANAGER_H #include "common/types.h" +#include "common/rect.h" -#include "zvision/dense_2d_array.h" +#include "graphics/pixelformat.h" + +#include "zvision/render_table.h" class OSystem; namespace Common { class String; -class Point; +} + +namespace Video { +class VideoDecoder; } namespace ZVision { @@ -40,37 +46,62 @@ class RenderManager { public: RenderManager(OSystem *system, const int width, const int height); -public: - enum RenderState { - PANORAMA, - TILT, - FLAT - }; - private: OSystem *_system; const int _width; const int _height; - RenderState _renderState; - - struct { - uint16 fieldOfView; - uint16 linearScale; - } _panoramaOptions; + const Graphics::PixelFormat _pixelFormat; + RenderTable _renderTable; - // TODO: See if tilt and panorama need to have separate options - struct { - uint16 fieldOfView; - uint16 linearScale; - } _tiltOptions; - - Dense2DArray _renderTable; + Video::VideoDecoder *_currentVideo; + byte *_scaledVideoFrameBuffer; bool _needsScreenUpdate; public: + void initialize(); + void updateScreen(bool isConsoleActive); + + /** + * Start a video playing. It will also load the first frame of the video. + * + * @param videoDecoder The video to play + */ + void startVideo(Video::VideoDecoder *videoDecoder); + /** + * @return Is a video currently being played + */ + bool isVideoPlaying() { return _currentVideo == 0; } + /** + * Cancels a video prematurely. Any sound remaining in the queue will continue to play. + * The last frame of the video will remain on the screen until something else overwrites it + */ + void cancelVideo(); + + /** + * Blits the image to the screen. Actual screen updates won't happen until the end of the frame. + * The image will be clipped to fit inside the window. + * + * @param fileName Name of the image file + * @param x X position where the image should be put + * @param y Y position where the image should be put + */ void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); - void generatePanoramaLookupTable(); + + /** + * Set how the frame should be rendered + * + * @param state One of the RenderStates + */ + void setRenderState(RenderTable::RenderState state); + + bool needsScreenUpdate() { return _needsScreenUpdate; }; + +private: + /** + * Checks the time since the last video frame, and blits the next frame to the screen + */ + void continueVideo(); }; } // End of namespace ZVision diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 0428090003..c0b575b23b 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -23,11 +23,11 @@ #include "common/scummsys.h" #include "common/system.h" +#include "video/video_decoder.h" #include "engines/util.h" - #include "graphics/surface.h" -#include "zvision/zvision.h" +#include "zvision/render_manager.h" namespace ZVision { @@ -71,7 +71,7 @@ void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte b } } -void ZVision::startVideo(Video::VideoDecoder *videoDecoder) { +void RenderManager::startVideo(Video::VideoDecoder *videoDecoder) { if (!videoDecoder) return; @@ -89,12 +89,7 @@ void ZVision::startVideo(Video::VideoDecoder *videoDecoder) { continueVideo(); } -void ZVision::continueVideo() { - if (_currentVideo == 0) { - warning("No video loaded. Nothing to continue"); - return; - } - +void RenderManager::continueVideo() { byte bytesPerPixel = _currentVideo->getPixelFormat().bytesPerPixel; uint16 width = _currentVideo->getWidth(); uint16 height = _currentVideo->getHeight(); @@ -115,13 +110,16 @@ void ZVision::continueVideo() { } } } else { - initGraphics(_width, _height, true, &_pixelFormat); - delete _currentVideo; - _currentVideo = 0; - delete[] _scaledVideoFrameBuffer; - _scaledVideoFrameBuffer = 0; + cancelVideo(); } +} +void RenderManager::cancelVideo() { + initGraphics(_width, _height, true, &_pixelFormat); + delete _currentVideo; + _currentVideo = 0; + delete[] _scaledVideoFrameBuffer; + _scaledVideoFrameBuffer = 0; } } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 57c9dea211..8cd7343368 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -46,9 +46,6 @@ namespace ZVision { ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), - _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 - _currentVideo(0), - _scaledVideoFrameBuffer(0), _width(640), _height(480) { // Put your engine in a sane state, but do nothing big yet; @@ -104,7 +101,7 @@ void ZVision::initialize() { SearchMan.add(name, archive); } - initGraphics(_width, _height, true, &_pixelFormat); + _renderManager->initialize(); _scriptManager->initialize(); @@ -127,19 +124,13 @@ Common::Error ZVision::run() { uint32 deltaTime = currentTime - lastTime; lastTime = currentTime; - if (_currentVideo != 0) - continueVideo(); - else { - _scriptManager->updateNodes(deltaTime); - _scriptManager->checkPuzzleCriteria(); - } - - if (_needsScreenUpdate || _console->isActive()) { - _system->updateScreen(); - _needsScreenUpdate = false; - } + _scriptManager->updateNodes(deltaTime); + _scriptManager->checkPuzzleCriteria(); + + // Render a frame + _renderManager->updateScreen(_console->isActive()); - // Calculate the frame delay based off a desired frame rate + // Calculate the frame delay based off a desired frame time int delay = desiredFrameTime - (currentTime - _system->getMillis()); // Ensure non-negative delay = delay < 0 ? 0 : delay; diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 7740dba6dc..2e6ec11a53 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -27,8 +27,6 @@ #include "common/random.h" #include "common/events.h" -#include "video/video_decoder.h" - #include "engines/engine.h" #include "zvision/detection.h" @@ -58,7 +56,6 @@ public: private: Console *_console; const ZVisionGameDescription *_gameDescription; - const Graphics::PixelFormat _pixelFormat; const int _width; const int _height; @@ -71,10 +68,6 @@ private: // To prevent allocation every time we process events Common::Event _event; - bool _needsScreenUpdate; - - Video::VideoDecoder *_currentVideo; - byte *_scaledVideoFrameBuffer; public: uint32 getFeatures() const; Common::Language getLanguage() const; @@ -84,9 +77,6 @@ public: Common::RandomSource *getRandomSource() const; ZVisionGameId getGameId() const; - void startVideo(Video::VideoDecoder *videoDecoder); - void continueVideo(); - private: void initialize(); -- cgit v1.2.3 From de2e7fd144622436429da2af79e155724af49d46 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:34:52 -0500 Subject: ZVISION: Convert error() to warning() I did not realize the intended behavior of error() is to close the application --- engines/zvision/render_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 8c3d37a160..b2c9e29b94 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -64,7 +64,7 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x Common::File file; if (!file.open(fileName)) { - error("Could not open file %s", fileName.c_str()); + warning("Could not open file %s", fileName.c_str()); return; } @@ -94,7 +94,7 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x // Decode Graphics::TGADecoder tga; if (!tga.loadStream(file)) - error("Error while reading TGA image"); + warning("Error while reading TGA image"); file.close(); const Graphics::Surface *tgaSurface = tga.getSurface(); -- cgit v1.2.3 From 88934cd5d01c20c4add55c81277923f481674176 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:36:11 -0500 Subject: ZVISION: Convert console code to use RenderManager and add method for setRenderState --- engines/zvision/console.cpp | 24 +++++++++++++++++++++++- engines/zvision/console.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 2b45ed24b9..687be8f086 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -41,6 +41,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("loadvideo", WRAP_METHOD(Console, cmdLoadVideo)); DCmd_Register("loadsound", WRAP_METHOD(Console, cmdLoadSound)); DCmd_Register("raw2wav", WRAP_METHOD(Console, cmdRawToWav)); + DCmd_Register("setrenderstate", WRAP_METHOD(Console, cmdSetRenderState)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -61,7 +62,7 @@ bool Console::cmdLoadVideo(int argc, const char **argv) { Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); if (videoDecoder && videoDecoder->loadFile(argv[1])) { - _engine->startVideo(videoDecoder); + _engine->getRenderManager()->startVideo(videoDecoder); } return true; @@ -92,6 +93,27 @@ bool Console::cmdRawToWav(int argc, const char **argv) { } convertRawToWav(argv[1], _engine, argv[2]); + return true; +} + +bool Console::cmdSetRenderState(int argc, const char **argv) { + if (argc != 2) { + DebugPrintf("Use setrenderstate to change the current render state\n"); + return true; + } + + Common::String renderState(argv[1]); + + if (renderState.matchString("panorama", true)) + _engine->getRenderManager()->setRenderState(RenderTable::PANORAMA); + else if (renderState.matchString("tilt", true)) + _engine->getRenderManager()->setRenderState(RenderTable::TILT); + else if (renderState.matchString("flat", true)) + _engine->getRenderManager()->setRenderState(RenderTable::FLAT); + else + DebugPrintf("Use setrenderstate to change the current render state\n"); + + return true; } } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 05b8f1247f..e2937030eb 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -41,6 +41,7 @@ private: bool cmdLoadVideo(int argc, const char **argv); bool cmdLoadSound(int argc, const char **argv); bool cmdRawToWav(int argc, const char **argv); + bool cmdSetRenderState(int argc, const char **argv); }; } // End of namespace ZVision -- cgit v1.2.3 From 73f02759f914327732bac2f1a750f3a95efe17ce Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:36:53 -0500 Subject: ZVISION: Remove supurflouous 'const' and add 'inline' --- engines/zvision/puzzle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index b3831d4665..06c228d367 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -68,7 +68,7 @@ struct Puzzle { // Used by the ScriptManager to allow unique-ification of _referenceTable // The unique-ification is done by sorting, then iterating and removing duplicates // The sort uses operator< - const bool operator<(const Puzzle &other) const { + inline bool operator<(const Puzzle &other) const { return key < other.key; } }; -- cgit v1.2.3 From df2e78e6f85c4c519e61985febcc3d70085202f0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:37:45 -0500 Subject: ZVISION: Remove variable used for debugging purposes --- engines/zvision/utility.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index fa29fe660f..2942a35c81 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -223,7 +223,7 @@ void convertRawToWav(const Common::String &inputFile, ZVision *engine, const Com output.writeUint32BE(MKTAG('d', 'a', 't', 'a')); output.writeUint32LE(file.size() * 2); int16 *buffer = new int16[file.size()]; - int readBytes = audioStream->readBuffer(buffer, file.size()); + audioStream->readBuffer(buffer, file.size()); output.write(buffer, file.size() * 2); delete[] buffer; -- cgit v1.2.3 From 65a08c71c6912ec0bcf20987652f7bd5d50a7791 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:38:17 -0500 Subject: ZVISION: Fix unsigned/signed compiler warning --- engines/zvision/utility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index e68d0de449..58a7ec3ab7 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -70,7 +70,7 @@ template void removeDuplicateEntries(Common::Array *container) { Common::sort(container->front(), container->back()); - for (int i = 0; i < container->size(); i++) { + for (uint32 i = 0; i < container->size(); i++) { while (container[i] == container[i +1]) { container->remove_at(i + 1); } -- cgit v1.2.3 From 364e9d659cf62566611921c3b2abceb2d97e2632 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 24 Jul 2013 11:39:54 -0500 Subject: ZVISION: Force all files to be registered with SearchMan as 'flat' There are 10 file name conflicts as a result, but the conflicts are byte identical. --- engines/zvision/zvision.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 8cd7343368..b79ecb4993 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -56,11 +56,11 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // However this is the place to specify all default directories const Common::FSNode gameDataDir(ConfMan.get("path")); - SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4); - SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4); - SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4); - SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx"); - SearchMan.addSubDirectoryMatching(gameDataDir, "znemscr"); + // TODO: There are 10 file clashes when we flatten the directories. From a quick look, the files are exactly the same, so it shouldn't matter. But I'm noting it here just in-case it does become a problem. + SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx", 0, 1, true); // Here is the right place to set up the engine specific debug channels //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); -- cgit v1.2.3 From 2349fcfd3170e84d9ec2dd95bd7180fcaa0752e7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 26 Jul 2013 12:25:07 -0500 Subject: ZVISION: Modify renderImageToScreen to take into account the current RenderState --- engines/zvision/render_manager.cpp | 54 +++++++++++++++++++++++++++++++++----- engines/zvision/render_manager.h | 13 +++++---- 2 files changed, 55 insertions(+), 12 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b2c9e29b94..183f823c56 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -60,7 +60,45 @@ void RenderManager::updateScreen(bool isConsoleActive) { } } -void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { +void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle) { + // Panoramas are transposed + // The actual data is transposed in the RenderTable lookup + if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { + uint32 temp = imageHeight; + imageHeight = imageWidth; + imageWidth = temp; + } + + // Check if we truly want a subRect of the image + if (subRectangle.isEmpty()) + subRectangle = Common::Rect(imageWidth, imageHeight); + + // Clip to image bounds + subRectangle.clip(imageWidth, imageHeight); + // Clip destRect to screen bounds + Common::Rect destRect(destinationX, destinationY, destinationX + subRectangle.width(), destinationY + subRectangle.height()); + destRect.clip(_width, _height); + // Clip subRect to screen bounds + subRectangle.translate(destRect.left - destinationX, destRect.top - destinationY); + subRectangle.setWidth(destRect.width()); + subRectangle.setHeight(destRect.height()); + + // Check for validity + if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty()) + return; + + if (_renderTable.getRenderState() == RenderTable::FLAT) { + _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left, destRect.top, destRect.width(), destRect.height()); + } else { + uint16 *destBuffer = new uint16[destRect.width() * destRect.height()]; + _renderTable.mutateImage((uint16 *)buffer, destBuffer, horizontalPitch, subRectangle); + + _system->copyRectToScreen(destBuffer, subRectangle.width() * sizeof(uint16), destRect.left, destRect.top, destRect.width(), destRect.height()); + delete[] destBuffer; + } +} + +void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle) { Common::File file; if (!file.open(fileName)) { @@ -77,15 +115,16 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x if (fileType == MKTAG('T', 'G', 'Z', '\0')) { // TGZ files have a header and then Bitmap data that is compressed with LZSS uint32 decompressedSize = file.readSint32LE(); - uint32 width = file.readSint32LE(); - uint32 height = file.readSint32LE(); + uint32 imageWidth = file.readSint32LE(); + uint32 imageHeight = file.readSint32LE(); LzssReadStream stream(&file); byte *buffer = new byte[decompressedSize]; stream.read(buffer, decompressedSize); - _system->copyRectToScreen(buffer, width * 2, x, y, width, height); + uint32 horizontalPitch = imageWidth * sizeof(uint16); + renderSubRectToScreen((uint16 *)buffer, imageWidth, imageHeight, horizontalPitch, destinationX, destinationY, subRectangle); delete[] buffer; } else { // Reset the cursor @@ -93,12 +132,13 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x // Decode Graphics::TGADecoder tga; - if (!tga.loadStream(file)) + if (!tga.loadStream(file)) { warning("Error while reading TGA image"); - file.close(); + return; + } const Graphics::Surface *tgaSurface = tga.getSurface(); - _system->copyRectToScreen(tgaSurface->pixels, tgaSurface->pitch, x, y, tgaSurface->w, tgaSurface->h); + renderSubRectToScreen((uint16 *)tgaSurface->pixels, tgaSurface->w, tgaSurface->h, tgaSurface->pitch, destinationX, destinationY, subRectangle); tga.destroy(); } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index f2f1dd72e4..db0088811f 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -79,14 +79,15 @@ public: void cancelVideo(); /** - * Blits the image to the screen. Actual screen updates won't happen until the end of the frame. + * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. * The image will be clipped to fit inside the window. * - * @param fileName Name of the image file - * @param x X position where the image should be put - * @param y Y position where the image should be put + * @param fileName Name of the image file + * @param destinationX X position where the image should be put + * @param destinationY Y position where the image should be put + * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. */ - void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); + void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0)); /** * Set how the frame should be rendered @@ -102,6 +103,8 @@ private: * Checks the time since the last video frame, and blits the next frame to the screen */ void continueVideo(); + + void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle); }; } // End of namespace ZVision -- cgit v1.2.3 From 3d223e2123672e00ccc38c2fd3d33dbe814d7156 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 26 Jul 2013 12:26:30 -0500 Subject: ZVISION: Modify the RenderTable panorama math to account for panoramas being transposed --- engines/zvision/render_table.cpp | 39 +++++++++++++++++++++++++++++---------- engines/zvision/render_table.h | 4 +++- 2 files changed, 32 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 1baf9514a3..3743c42d27 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -29,7 +29,8 @@ namespace ZVision { RenderTable::RenderTable(uint32 numRows, uint32 numColumns) : _numRows(numRows), - _numColumns(numColumns) { + _numColumns(numColumns), + _renderState(RenderState::FLAT) { assert(numRows != 0 && numColumns != 0); _internalBuffer = new Common::Point[numRows * numColumns]; @@ -57,6 +58,21 @@ void RenderTable::setRenderState(RenderState newState) { } } +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 horizontalPitch, Common::Rect subRectangle) { + uint32 imageWidth = horizontalPitch / 2; + + for (int y = subRectangle.top; y < subRectangle.bottom; y++) { + uint32 normalizedY = y - subRectangle.top; + for (int x = subRectangle.left; x < subRectangle.right; x++) { + uint32 normalizedX = x - subRectangle.left; + + uint32 index = y * _numColumns + x; + uint32 sourceIndex = _internalBuffer[index].y * imageWidth + _internalBuffer[index].x; + destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceIndex]; + } + } +} + void RenderTable::generatePanoramaLookupTable() { float fieldOfView = _panoramaOptions.fieldOfView; float scale = _panoramaOptions.linearScale; @@ -70,20 +86,23 @@ void RenderTable::generatePanoramaLookupTable() { float halfHeightOverTan = halfHeight / tan(fovRadians); float tanOverHalfHeight = tan(fovRadians) / halfHeight; - for (uint32 x = 0; x < _numRows; x++) { + // TODO: Change the algorithm to write a whole row at a time instead of a whole column at a time. AKA: for(y) { for(x) {}} instead of for(x) { for(y) {}} + for (uint32 x = 0; x < _numColumns; x++) { // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) - float xPos = (float)x - halfWidth + 0.01; - float tempX = atan(xPos*tanOverHalfHeight); + float temp = atan(tanOverHalfHeight * ((float)x - halfWidth + 0.01f)); - int32 newX = floor(scale * halfHeightOverTan * tempX);// + half_w); - float cosX = cos(tempX); + int32 newX = floor((halfHeightOverTan * scale * temp) + halfWidth); + float cosX = cos(temp); - for (uint32 y = 0; y < _numColumns; y++) { + for (uint32 y = 0; y < _numRows; y++) { int32 newY = floor(halfHeight + (y - halfHeight) * cosX); - uint32 index = x * _numColumns + y; - _internalBuffer[index].x = newX; //pixel index - _internalBuffer[index].y = newY; //pixel index + // Panorama images are transposed. Rather than trying to transpose the source, we know + // they will be mutated by this table. Therefore we can swap the axes here + uint32 index = y * _numColumns + x; + + _internalBuffer[index].x = newY; //pixel index + _internalBuffer[index].y = newX; //pixel index } } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 9d54551c3b..fca76818e5 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -57,13 +57,15 @@ private: } _tiltOptions; public: + RenderState getRenderState() { return _renderState; } void setRenderState(RenderState newState); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 horizontalPitch, Common::Rect subRectangle); private: void generatePanoramaLookupTable(); void generateTiltLookupTable(); }; -} // End of namesapce ZVision +} // End of namespace ZVision #endif -- cgit v1.2.3 From c8359ad56ca4bf84ac1110ef1ceccbc9d4dc97dd Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 26 Jul 2013 12:27:04 -0500 Subject: ZVISION: Modify loadImage console command to account for new render options --- engines/zvision/console.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 687be8f086..bfe2609777 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -45,11 +45,14 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { } bool Console::cmdLoadImage(int argc, const char **argv) { - if (argc != 4) { - DebugPrintf("Use loadimage to load an image to the screen\n"); + if (argc == 4) + _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); + else if (argc == 8) + _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3]), Common::Rect(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]))); + else { + DebugPrintf("Use loadimage [ ] to load an image to the screen\n"); return true; } - _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); return true; } -- cgit v1.2.3 From 34b3a788981a94830023946dcc45bc6a1e028805 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 26 Jul 2013 14:28:08 -0500 Subject: ZVISION: Fix error causing image discontinutities The width and height were swapped when passed to the class constructor. --- engines/zvision/render_table.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 3743c42d27..388dc85bcb 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -27,7 +27,7 @@ namespace ZVision { -RenderTable::RenderTable(uint32 numRows, uint32 numColumns) +RenderTable::RenderTable(uint32 numColumns, uint32 numRows) : _numRows(numRows), _numColumns(numColumns), _renderState(RenderState::FLAT) { @@ -97,10 +97,10 @@ void RenderTable::generatePanoramaLookupTable() { for (uint32 y = 0; y < _numRows; y++) { int32 newY = floor(halfHeight + (y - halfHeight) * cosX); - // Panorama images are transposed. Rather than trying to transpose the source, we know - // they will be mutated by this table. Therefore we can swap the axes here uint32 index = y * _numColumns + x; + // Panorama images are transposed. Rather than trying to transpose the source, we know + // they will be mutated by this table. Therefore we can swap the axes here _internalBuffer[index].x = newY; //pixel index _internalBuffer[index].y = newX; //pixel index } -- cgit v1.2.3 From 611ff31a56055b1ec05445597087cb042de2c648 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 28 Jul 2013 21:09:20 -0500 Subject: ZVISION: Copy Point struct from rect.h and turn it into a templated class --- engines/zvision/point.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 engines/zvision/point.h (limited to 'engines/zvision') diff --git a/engines/zvision/point.h b/engines/zvision/point.h new file mode 100644 index 0000000000..da244e9449 --- /dev/null +++ b/engines/zvision/point.h @@ -0,0 +1,80 @@ +/* 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 COMMON_ZVISION_POINT_H +#define COMMON_ZVISION_POINT_H + +#include "common/types.h" + +namespace ZVision { + +/** + * Simple class for handling both 2D position and size. + */ +template +class Point { +public: + T x; ///< The horizontal part of the point + T y; ///< The vertical part of the point + +public: + Point() : x(0), y(0) {} + Point(T x1, T y1) : x(x1), y(y1) {} + +public: + bool operator==(const Point &p) const { return x == p.x && y == p.y; } + bool operator!=(const Point &p) const { return x != p.x || y != p.y; } + Point operator+(const Point &delta) const { return Point(x + delta.x, y + delta.y); } + Point operator-(const Point &delta) const { return Point(x - delta.x, y - delta.y); } + + void operator+=(const Point &delta) { + x += delta.x; + y += delta.y; + } + + void operator-=(const Point &delta) { + x -= delta.x; + y -= delta.y; + } + + /** + * Return the square of the distance between this point and the point p. + * + * @param p the other point + * @return the distance between this and p + */ + uint sqrDist(const Point &p) const { + int diffx = ABS(p.x - x); + if (diffx >= 0x1000) + return 0xFFFFFF; + + int diffy = ABS(p.y - y); + if (diffy >= 0x1000) + return 0xFFFFFF; + + return uint(diffx * diffx + diffy * diffy); + } +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From a23970bbc68865ccffa4c2e0849ffe244d48d5f1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 28 Jul 2013 21:37:32 -0500 Subject: ZVISION: Convert RenderTable to only storing (x,y) offsets instead of absolute postions. This allows the destRectangle to be offset within the RenderTable --- engines/zvision/render_manager.cpp | 2 +- engines/zvision/render_table.cpp | 40 ++++++++++++++++++++++++++------------ engines/zvision/render_table.h | 6 ++++-- 3 files changed, 33 insertions(+), 15 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 183f823c56..cfd53fdc4b 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -91,7 +91,7 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left, destRect.top, destRect.width(), destRect.height()); } else { uint16 *destBuffer = new uint16[destRect.width() * destRect.height()]; - _renderTable.mutateImage((uint16 *)buffer, destBuffer, horizontalPitch, subRectangle); + _renderTable.mutateImage((uint16 *)buffer, destBuffer, imageWidth, imageHeight, subRectangle, destRect); _system->copyRectToScreen(destBuffer, subRectangle.width() * sizeof(uint16), destRect.left, destRect.top, destRect.width(), destRect.height()); delete[] destBuffer; diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 388dc85bcb..085908fc68 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -22,8 +22,9 @@ #include "common/scummsys.h" -#include "zvision/render_table.h" +#include "zvision/render_table.h" +#include "zvision/point.h" namespace ZVision { @@ -33,7 +34,7 @@ RenderTable::RenderTable(uint32 numColumns, uint32 numRows) _renderState(RenderState::FLAT) { assert(numRows != 0 && numColumns != 0); - _internalBuffer = new Common::Point[numRows * numColumns]; + _internalBuffer = new Point[numRows * numColumns]; } RenderTable::~RenderTable() { @@ -58,17 +59,33 @@ void RenderTable::setRenderState(RenderState newState) { } } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 horizontalPitch, Common::Rect subRectangle) { - uint32 imageWidth = horizontalPitch / 2; +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle) { + bool isTransposed = _renderState == RenderTable::PANORAMA || _renderState == RenderTable::TILT; for (int y = subRectangle.top; y < subRectangle.bottom; y++) { uint32 normalizedY = y - subRectangle.top; + for (int x = subRectangle.left; x < subRectangle.right; x++) { uint32 normalizedX = x - subRectangle.left; - uint32 index = y * _numColumns + x; - uint32 sourceIndex = _internalBuffer[index].y * imageWidth + _internalBuffer[index].x; - destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceIndex]; + uint32 index = (y + destRectangle.top) * _numColumns + (x + destRectangle.left); + + // RenderTable only stores offsets from the original coordinates + uint32 sourceYIndex = y + _internalBuffer[index].y; + uint32 sourceXIndex = x + _internalBuffer[index].x; + + // Clamp the yIndex to the size of the image + sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); + + // Clamp the xIndex to the size of the image + sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); + + // TODO: Figure out a way to not have branching every loop. The only way that comes to mind is to have a whole separate set of for loops for isTransposed, but that's ugly. The compiler might do this anyway in the end + if (isTransposed) { + destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceXIndex * imageHeight + sourceYIndex]; + } else { + destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; + } } } } @@ -91,7 +108,7 @@ void RenderTable::generatePanoramaLookupTable() { // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) float temp = atan(tanOverHalfHeight * ((float)x - halfWidth + 0.01f)); - int32 newX = floor((halfHeightOverTan * scale * temp) + halfWidth); + int32 newX = floor((halfHeightOverTan * _panoramaOptions.linearScale * temp) + halfWidth); float cosX = cos(temp); for (uint32 y = 0; y < _numRows; y++) { @@ -99,10 +116,9 @@ void RenderTable::generatePanoramaLookupTable() { uint32 index = y * _numColumns + x; - // Panorama images are transposed. Rather than trying to transpose the source, we know - // they will be mutated by this table. Therefore we can swap the axes here - _internalBuffer[index].x = newY; //pixel index - _internalBuffer[index].y = newX; //pixel index + // Only store the x,y offsets instead of the absolute positions + _internalBuffer[index].x = newX - x; //pixel index + _internalBuffer[index].y = newY - y; //pixel index } } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index fca76818e5..cb91f885b4 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -26,6 +26,8 @@ #include "common/types.h" #include "common/rect.h" +#include "zvision/point.h" + namespace ZVision { class RenderTable { @@ -42,7 +44,7 @@ public: private: uint32 _numColumns, _numRows; - Common::Point *_internalBuffer; + Point *_internalBuffer; RenderState _renderState; struct { @@ -59,7 +61,7 @@ private: public: RenderState getRenderState() { return _renderState; } void setRenderState(RenderState newState); - void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 horizontalPitch, Common::Rect subRectangle); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle); private: void generatePanoramaLookupTable(); -- cgit v1.2.3 From 4acdf5b7d51869bfb697e345a9a90f487d8fafc0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 28 Jul 2013 21:38:53 -0500 Subject: ZVISION: Convert panoramaOptions and tiltOptions to floats --- engines/zvision/render_table.cpp | 7 ++----- engines/zvision/render_table.h | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 085908fc68..d1f8258e02 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -47,7 +47,7 @@ void RenderTable::setRenderState(RenderState newState) { switch (newState) { case PANORAMA: _panoramaOptions.fieldOfView = 60; - _panoramaOptions.linearScale = 1; + _panoramaOptions.linearScale = 0.55f; generatePanoramaLookupTable(); break; case TILT: @@ -91,15 +91,12 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 i } void RenderTable::generatePanoramaLookupTable() { - float fieldOfView = _panoramaOptions.fieldOfView; - float scale = _panoramaOptions.linearScale; - memset(_internalBuffer, 0, _numRows * _numColumns * sizeof(uint16)); float halfWidth = (float)_numColumns / 2.0f; float halfHeight = (float)_numRows / 2.0f; - float fovRadians = (fieldOfView * M_PI / 180.0f); + float fovRadians = (_panoramaOptions.fieldOfView * M_PI / 180.0f); float halfHeightOverTan = halfHeight / tan(fovRadians); float tanOverHalfHeight = tan(fovRadians) / halfHeight; diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index cb91f885b4..ec405e5dfe 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -48,14 +48,14 @@ private: RenderState _renderState; struct { - uint16 fieldOfView; - uint16 linearScale; + float fieldOfView; + float linearScale; } _panoramaOptions; // TODO: See if tilt and panorama need to have separate options struct { - uint16 fieldOfView; - uint16 linearScale; + float fieldOfView; + float linearScale; } _tiltOptions; public: -- cgit v1.2.3 From f8bc82080a82d7ed198c88d7a839c32e092ede52 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 10:59:09 -0500 Subject: ZVISION: Create function for mixing two RGB<555> colors --- engines/zvision/render_table.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index d1f8258e02..ca7f9a8030 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -22,6 +22,7 @@ #include "common/scummsys.h" +#include "graphics/colormasks.h" #include "zvision/render_table.h" #include "zvision/point.h" @@ -59,6 +60,27 @@ void RenderTable::setRenderState(RenderState newState) { } } +uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { + assert(percentColorOne < 1.0f); + + float rOne = float((colorOne & Graphics::ColorMasks<555>::kRedMask) >> Graphics::ColorMasks<555>::kRedShift); + float rTwo = float((colorTwo & Graphics::ColorMasks<555>::kRedMask) >> Graphics::ColorMasks<555>::kRedShift); + float gOne = float((colorOne & Graphics::ColorMasks<555>::kGreenMask) >> Graphics::ColorMasks<555>::kGreenShift); + float gTwo = float((colorTwo & Graphics::ColorMasks<555>::kGreenMask) >> Graphics::ColorMasks<555>::kGreenShift); + float bOne = float((colorOne & Graphics::ColorMasks<555>::kBlueMask) >> Graphics::ColorMasks<555>::kBlueShift); + float bTwo = float((colorTwo & Graphics::ColorMasks<555>::kBlueMask) >> Graphics::ColorMasks<555>::kBlueShift); + + float rFinal = rOne * percentColorOne + rTwo * (1.0f - percentColorOne); + float gFinal = gOne * percentColorOne + gTwo * (1.0f - percentColorOne); + float bFinal = bOne * percentColorOne + bTwo * (1.0f - percentColorOne); + + uint16 returnColor = (byte(rFinal + 0.5f) << Graphics::ColorMasks<555>::kRedShift) | + (byte(gFinal + 0.5f) << Graphics::ColorMasks<555>::kGreenShift) | + (byte(bFinal + 0.5f) << Graphics::ColorMasks<555>::kBlueShift); + + return returnColor; +} + void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle) { bool isTransposed = _renderState == RenderTable::PANORAMA || _renderState == RenderTable::TILT; -- cgit v1.2.3 From 48b9741f413fb32ed5efedfe248093be811678c6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 15:03:08 -0500 Subject: ZVISION: Rename Point template class to Vector2 Also remove templating --- engines/zvision/point.h | 80 ---------------------------------------- engines/zvision/render_table.cpp | 4 +- engines/zvision/render_table.h | 4 +- engines/zvision/vector2.h | 79 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 84 deletions(-) delete mode 100644 engines/zvision/point.h create mode 100644 engines/zvision/vector2.h (limited to 'engines/zvision') diff --git a/engines/zvision/point.h b/engines/zvision/point.h deleted file mode 100644 index da244e9449..0000000000 --- a/engines/zvision/point.h +++ /dev/null @@ -1,80 +0,0 @@ -/* 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 COMMON_ZVISION_POINT_H -#define COMMON_ZVISION_POINT_H - -#include "common/types.h" - -namespace ZVision { - -/** - * Simple class for handling both 2D position and size. - */ -template -class Point { -public: - T x; ///< The horizontal part of the point - T y; ///< The vertical part of the point - -public: - Point() : x(0), y(0) {} - Point(T x1, T y1) : x(x1), y(y1) {} - -public: - bool operator==(const Point &p) const { return x == p.x && y == p.y; } - bool operator!=(const Point &p) const { return x != p.x || y != p.y; } - Point operator+(const Point &delta) const { return Point(x + delta.x, y + delta.y); } - Point operator-(const Point &delta) const { return Point(x - delta.x, y - delta.y); } - - void operator+=(const Point &delta) { - x += delta.x; - y += delta.y; - } - - void operator-=(const Point &delta) { - x -= delta.x; - y -= delta.y; - } - - /** - * Return the square of the distance between this point and the point p. - * - * @param p the other point - * @return the distance between this and p - */ - uint sqrDist(const Point &p) const { - int diffx = ABS(p.x - x); - if (diffx >= 0x1000) - return 0xFFFFFF; - - int diffy = ABS(p.y - y); - if (diffy >= 0x1000) - return 0xFFFFFF; - - return uint(diffx * diffx + diffy * diffy); - } -}; - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index ca7f9a8030..5754c91b24 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -25,7 +25,7 @@ #include "graphics/colormasks.h" #include "zvision/render_table.h" -#include "zvision/point.h" +#include "zvision/vector2.h" namespace ZVision { @@ -35,7 +35,7 @@ RenderTable::RenderTable(uint32 numColumns, uint32 numRows) _renderState(RenderState::FLAT) { assert(numRows != 0 && numColumns != 0); - _internalBuffer = new Point[numRows * numColumns]; + _internalBuffer = new Vector2[numRows * numColumns]; } RenderTable::~RenderTable() { diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index ec405e5dfe..3f87c2e026 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -26,7 +26,7 @@ #include "common/types.h" #include "common/rect.h" -#include "zvision/point.h" +#include "zvision/vector2.h" namespace ZVision { @@ -44,7 +44,7 @@ public: private: uint32 _numColumns, _numRows; - Point *_internalBuffer; + Vector2 *_internalBuffer; RenderState _renderState; struct { diff --git a/engines/zvision/vector2.h b/engines/zvision/vector2.h new file mode 100644 index 0000000000..d301aef4c6 --- /dev/null +++ b/engines/zvision/vector2.h @@ -0,0 +1,79 @@ +/* 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 COMMON_ZVISION_POINT_H +#define COMMON_ZVISION_POINT_H + +#include "common/scummsys.h" + +namespace ZVision { + +/** + * Simple class for handling both 2D position and size. + */ +class Vector2 { +public: + int16 x; ///< The horizontal part of the point + int16 y; ///< The vertical part of the point + +public: + Vector2() : x(0), y(0) {} + Vector2(int16 x1, int16 y1) : x(x1), y(y1) {} + +public: + bool operator==(const Vector2 &p) const { return x == p.x && y == p.y; } + bool operator!=(const Vector2 &p) const { return x != p.x || y != p.y; } + Vector2 operator+(const Vector2 &delta) const { return Vector2(x + delta.x, y + delta.y); } + Vector2 operator-(const Vector2 &delta) const { return Vector2(x - delta.x, y - delta.y); } + + void operator+=(const Vector2 &delta) { + x += delta.x; + y += delta.y; + } + + void operator-=(const Vector2 &delta) { + x -= delta.x; + y -= delta.y; + } + + /** + * Return the square of the distance between this point and the point p. + * + * @param p the other point + * @return the distance between this and p + */ + uint sqrDist(const Vector2 &p) const { + int diffx = ABS(p.x - x); + if (diffx >= 0x1000) + return 0xFFFFFF; + + int diffy = ABS(p.y - y); + if (diffy >= 0x1000) + return 0xFFFFFF; + + return uint(diffx * diffx + diffy * diffy); + } +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 564379d3eed127fd6c41a9a42bb149afbc7fb75e Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 15:05:37 -0500 Subject: ZVISION: Create method to get RenderTable object pointer from RenderManager Remove passthrough methods --- engines/zvision/console.cpp | 6 +++--- engines/zvision/render_manager.cpp | 4 ++-- engines/zvision/render_manager.h | 7 +------ 3 files changed, 6 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index bfe2609777..12555fe3cc 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -108,11 +108,11 @@ bool Console::cmdSetRenderState(int argc, const char **argv) { Common::String renderState(argv[1]); if (renderState.matchString("panorama", true)) - _engine->getRenderManager()->setRenderState(RenderTable::PANORAMA); + _engine->getRenderManager()->getRenderTable()->setRenderState(RenderTable::PANORAMA); else if (renderState.matchString("tilt", true)) - _engine->getRenderManager()->setRenderState(RenderTable::TILT); + _engine->getRenderManager()->getRenderTable()->setRenderState(RenderTable::TILT); else if (renderState.matchString("flat", true)) - _engine->getRenderManager()->setRenderState(RenderTable::FLAT); + _engine->getRenderManager()->getRenderTable()->setRenderState(RenderTable::FLAT); else DebugPrintf("Use setrenderstate to change the current render state\n"); diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index cfd53fdc4b..10afe1f201 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -146,8 +146,8 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d _needsScreenUpdate = true; } -void RenderManager::setRenderState(RenderTable::RenderState state) { - _renderTable.setRenderState(state); +RenderTable *RenderManager::getRenderTable() { + return &_renderTable; } } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index db0088811f..8b4d7e840b 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -89,12 +89,7 @@ public: */ void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0)); - /** - * Set how the frame should be rendered - * - * @param state One of the RenderStates - */ - void setRenderState(RenderTable::RenderState state); + RenderTable *getRenderTable(); bool needsScreenUpdate() { return _needsScreenUpdate; }; -- cgit v1.2.3 From 5376aa7b3cb234134cec5923f65ab7c9273a9528 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 15:08:03 -0500 Subject: ZVISION: Move generating the RenderTable to outside setRenderState This allows the panorama/tilt options to mutated without having to generate the table multiple times. --- engines/zvision/console.cpp | 17 +++++++++++++++++ engines/zvision/console.h | 1 + engines/zvision/render_table.cpp | 17 +++++++++++++++-- engines/zvision/render_table.h | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 12555fe3cc..e9bbdd74bb 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -42,6 +42,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("loadsound", WRAP_METHOD(Console, cmdLoadSound)); DCmd_Register("raw2wav", WRAP_METHOD(Console, cmdRawToWav)); DCmd_Register("setrenderstate", WRAP_METHOD(Console, cmdSetRenderState)); + DCmd_Register("generaterendertable", WRAP_METHOD(Console, cmdGenerateRenderTable)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -119,4 +120,20 @@ bool Console::cmdSetRenderState(int argc, const char **argv) { return true; } +bool Console::cmdGenerateRenderTable(int argc, const char **argv) { + _engine->getRenderManager()->getRenderTable()->generateRenderTable(); + + return true; +} + +bool Console::cmdSetPanoramaFoV(int argc, const char **argv) { + + return true; +} + +bool Console::cmdSetPanoramaScale(int argc, const char **argv) { + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index e2937030eb..7fa4acc194 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -42,6 +42,7 @@ private: bool cmdLoadSound(int argc, const char **argv); bool cmdRawToWav(int argc, const char **argv); bool cmdSetRenderState(int argc, const char **argv); + bool cmdGenerateRenderTable(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 5754c91b24..1ba1648d39 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -49,10 +49,9 @@ void RenderTable::setRenderState(RenderState newState) { case PANORAMA: _panoramaOptions.fieldOfView = 60; _panoramaOptions.linearScale = 0.55f; - generatePanoramaLookupTable(); break; case TILT: - generateTiltLookupTable(); + break; case FLAT: // Intentionally left empty @@ -112,6 +111,20 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 i } } +void RenderTable::generateRenderTable() { + switch (_renderState) { + case ZVision::RenderTable::PANORAMA: + generatePanoramaLookupTable(); + break; + case ZVision::RenderTable::TILT: + generateTiltLookupTable(); + break; + case ZVision::RenderTable::FLAT: + // Intentionally left empty + break; + } +} + void RenderTable::generatePanoramaLookupTable() { memset(_internalBuffer, 0, _numRows * _numColumns * sizeof(uint16)); diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 3f87c2e026..a48e608db8 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -62,6 +62,7 @@ public: RenderState getRenderState() { return _renderState; } void setRenderState(RenderState newState); void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle); + void generateRenderTable(); private: void generatePanoramaLookupTable(); -- cgit v1.2.3 From b9dd61437c88fae024fd2d344b1f75020a5f7eb5 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 15:09:49 -0500 Subject: ZVISION: Create class for ActionDelayRender --- engines/zvision/actions.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 9b2267df82..224f9011a1 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -40,9 +40,7 @@ public: // The different types of actions -// CROSSFADE, // DEBUG, -// DELAY_RENDER, // DISABLE_CONTROL, // DISABLE_VENUS, // DISPLAY_MESSAGE, @@ -129,6 +127,16 @@ private: uint16 _timeInMillis; }; +class ActionDelayRender : public ResultAction { +public: + ActionDelayRender(Common::String *line); + bool execute(ZVision *engine); + +private: + // TODO: Check if this should actually be frames or if it should be milliseconds/seconds + byte framesToDelay; +}; + class ActionPlayAnimation : public ResultAction { public: ActionPlayAnimation(Common::String *line); -- cgit v1.2.3 From 0e4e6ee9bf1f3a640191df6b22e6965a7199d171 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 15:20:51 -0500 Subject: ZVISION: Create methods for altering panoramaOptions and create console commands for them --- engines/zvision/console.cpp | 14 ++++++++++++++ engines/zvision/console.h | 2 ++ engines/zvision/render_table.cpp | 9 +++++++++ engines/zvision/render_table.h | 3 +++ 4 files changed, 28 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index e9bbdd74bb..3dad7af376 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -43,6 +43,8 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("raw2wav", WRAP_METHOD(Console, cmdRawToWav)); DCmd_Register("setrenderstate", WRAP_METHOD(Console, cmdSetRenderState)); DCmd_Register("generaterendertable", WRAP_METHOD(Console, cmdGenerateRenderTable)); + DCmd_Register("setpanoramafov", WRAP_METHOD(Console, cmdSetPanoramaFoV)); + DCmd_Register("setpanoramascale", WRAP_METHOD(Console, cmdSetPanoramaScale)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -127,11 +129,23 @@ bool Console::cmdGenerateRenderTable(int argc, const char **argv) { } bool Console::cmdSetPanoramaFoV(int argc, const char **argv) { + if (argc != 2) { + DebugPrintf("Use setpanoramafov to change the current panorama field of view\n"); + return true; + } + + _engine->getRenderManager()->getRenderTable()->setPanoramaFoV(atof(argv[1])); return true; } bool Console::cmdSetPanoramaScale(int argc, const char **argv) { + if (argc != 2) { + DebugPrintf("Use setpanoramascale to change the current panorama scale\n"); + return true; + } + + _engine->getRenderManager()->getRenderTable()->setPanoramaScale(atof(argv[1])); return true; } diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 7fa4acc194..7b1beeb304 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -43,6 +43,8 @@ private: bool cmdRawToWav(int argc, const char **argv); bool cmdSetRenderState(int argc, const char **argv); bool cmdGenerateRenderTable(int argc, const char **argv); + bool cmdSetPanoramaFoV(int argc, const char **argv); + bool cmdSetPanoramaScale(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 1ba1648d39..b5a2809444 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -156,7 +156,16 @@ void RenderTable::generatePanoramaLookupTable() { } void RenderTable::generateTiltLookupTable() { +void RenderTable::setPanoramaFoV(float fov) { + assert(fov > 0.0f); + _panoramaOptions.fieldOfView = fov; +} + +void RenderTable::setPanoramaScale(float scale) { + assert(scale > 0.0f); + + _panoramaOptions.linearScale = scale; } } // End of namespace ZVision diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index a48e608db8..5698feaa03 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -64,6 +64,9 @@ public: void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle); void generateRenderTable(); + void setPanoramaFoV(float fov); + void setPanoramaScale(float scale); + private: void generatePanoramaLookupTable(); void generateTiltLookupTable(); -- cgit v1.2.3 From 8f3e27cbd03831569f37e2edc5beebe9fd93de12 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 15:22:14 -0500 Subject: ZVISION: Fix closing braces on generateTiltLookupTable --- engines/zvision/render_table.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index b5a2809444..90a5aafea5 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -156,6 +156,9 @@ void RenderTable::generatePanoramaLookupTable() { } void RenderTable::generateTiltLookupTable() { + +} + void RenderTable::setPanoramaFoV(float fov) { assert(fov > 0.0f); -- cgit v1.2.3 From e076d8e52ff2917fb68eb7ea302f96fcbe76f84d Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 15:23:25 -0500 Subject: ZVISION: Change default panorama FoV to 27 degrees This is to match Marisa Chan's implementation. Images at this FoV also look better. --- engines/zvision/render_table.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 90a5aafea5..0bd8f23e3d 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -47,7 +47,7 @@ void RenderTable::setRenderState(RenderState newState) { switch (newState) { case PANORAMA: - _panoramaOptions.fieldOfView = 60; + _panoramaOptions.fieldOfView = 27.0f; _panoramaOptions.linearScale = 0.55f; break; case TILT: -- cgit v1.2.3 From 1c551d43595a6acfb7f00bb3f0713435576e0f0e Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 30 Jul 2013 02:10:57 +0300 Subject: ZVISION: Only scale videos when needed This avoids crashes for videos that exceed the screen size when scaled --- engines/zvision/video.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index c0b575b23b..caf43ae0b5 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -91,20 +91,27 @@ void RenderManager::startVideo(Video::VideoDecoder *videoDecoder) { void RenderManager::continueVideo() { byte bytesPerPixel = _currentVideo->getPixelFormat().bytesPerPixel; - uint16 width = _currentVideo->getWidth(); - uint16 height = _currentVideo->getHeight(); - uint16 pitch = width * bytesPerPixel; + uint16 origWidth = _currentVideo->getWidth(); + uint16 origHeight = _currentVideo->getHeight(); + uint16 pitch = origWidth * bytesPerPixel; + bool shouldBeScaled = (origWidth * 2 <= 640 && origHeight * 2 <= 480); + uint16 finalWidth = shouldBeScaled ? origWidth * 2 : origWidth; + uint16 finalHeight = shouldBeScaled ? origHeight * 2 : origHeight; - uint16 x = (_system->getWidth() - (width * 2)) / 2; - uint16 y = (_system->getHeight() - (height * 2)) / 2; + uint16 x = (_system->getWidth() - finalWidth) / 2; + uint16 y = (_system->getHeight() - finalHeight) / 2; if (!_currentVideo->endOfVideo()) { if (_currentVideo->needsUpdate()) { const Graphics::Surface *frame = _currentVideo->decodeNextFrame(); - if (frame) { - scale2x(static_cast(frame->pixels), _scaledVideoFrameBuffer, width, height, bytesPerPixel); - _system->copyRectToScreen(_scaledVideoFrameBuffer, pitch * 2, x, y, width * 2, height * 2); + if (frame) { + if (shouldBeScaled) { + scale2x((byte *)frame->pixels, _scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel); + _system->copyRectToScreen(_scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); + } else { + _system->copyRectToScreen((byte *)frame->pixels, pitch, x, y, finalWidth, finalHeight); + } _needsScreenUpdate = true; } -- cgit v1.2.3 From 032afd3c1a6fe929cafde4f30f4c1e59b7ac6a89 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 30 Jul 2013 02:35:49 +0300 Subject: ZVISION: Fix compilation --- engines/zvision/render_table.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 0bd8f23e3d..e3ce77952b 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -32,7 +32,7 @@ namespace ZVision { RenderTable::RenderTable(uint32 numColumns, uint32 numRows) : _numRows(numRows), _numColumns(numColumns), - _renderState(RenderState::FLAT) { + _renderState(FLAT) { assert(numRows != 0 && numColumns != 0); _internalBuffer = new Vector2[numRows * numColumns]; -- cgit v1.2.3 From 93c6670f6f80b98dd05df09d710b3c683cfd1173 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:42:07 -0500 Subject: ZVISION: Create clone member function for ResultAction class --- engines/zvision/actions.cpp | 36 ++++++++++++++++++++++++++++++++++++ engines/zvision/actions.h | 11 +++++++++++ 2 files changed, 47 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 791eda11e0..35e5d4886d 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -37,6 +37,10 @@ ActionAdd::ActionAdd(Common::String *line) { sscanf(line->c_str(), ":add(%u,%hhu)", &_key, &_value); } +ResultAction *ActionAdd::clone() const { + return new ActionAdd(*this); +} + bool ActionAdd::execute(ZVision *engine) { engine->getScriptManager()->addToStateValue(_key, _value); return true; @@ -51,6 +55,10 @@ ActionAssign::ActionAssign(Common::String *line) { sscanf(line->c_str(), ":assign(%u, %hhu)", &_key, &_value); } +ResultAction *ActionAssign::clone() const { + return new ActionAssign(*this); +} + bool ActionAssign::execute(ZVision *engine) { engine->getScriptManager()->setStateValue(_key, _value); return true; @@ -65,6 +73,10 @@ ActionAttenuate::ActionAttenuate(Common::String *line) { sscanf(line->c_str(), ":assign(%u, %hd)", &_key, &_attenuation); } +ResultAction *ActionAttenuate::clone() const { + return new ActionAttenuate(*this); +} + bool ActionAttenuate::execute(ZVision *engine) { // TODO: Implement return true; @@ -79,6 +91,10 @@ ActionChangeLocation::ActionChangeLocation(Common::String *line) { sscanf(line->c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); } +ResultAction *ActionChangeLocation::clone() const { + return new ActionChangeLocation(*this); +} + bool ActionChangeLocation::execute(ZVision *engine) { // TODO: Implement return true; @@ -95,6 +111,10 @@ ActionCrossfade::ActionCrossfade(Common::String *line) { &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } +ResultAction *ActionCrossfade::clone() const { + return new ActionCrossfade(*this); +} + bool ActionCrossfade::execute(ZVision *engine) { // TODO: Implement return true; @@ -110,6 +130,10 @@ ActionPreloadAnimation::ActionPreloadAnimation(Common::String *line) { sscanf(line->c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); } +ResultAction *ActionPreloadAnimation::clone() const { + return new ActionPreloadAnimation(*this); +} + bool ActionPreloadAnimation::execute(ZVision *engine) { // TODO: Implement return true; @@ -127,6 +151,10 @@ ActionPlayAnimation::ActionPlayAnimation(Common::String *line) { &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); } +ResultAction *ActionPlayAnimation::clone() const { + return new ActionPlayAnimation(*this); +} + bool ActionPlayAnimation::execute(ZVision *engine) { // TODO: Implement return true; @@ -141,6 +169,10 @@ ActionRandom::ActionRandom(Common::String *line) { sscanf(line->c_str(), ":random:%u, %u)", &_key, &_max); } +ResultAction *ActionRandom::clone() const { + return new ActionRandom(*this); +} + bool ActionRandom::execute(ZVision *engine) { uint32 randNumber = engine->getRandomSource()->getRandomNumber(_max); engine->getScriptManager()->setStateValue(_key, randNumber); @@ -156,6 +188,10 @@ ActionTimer::ActionTimer(Common::String *line) { sscanf(line->c_str(), ":timer:%u(%hu)", &_key, &_time); } +ResultAction *ActionTimer::clone() const { + return new ActionTimer(*this); +} + bool ActionTimer::execute(ZVision *engine) { engine->getScriptManager()->addActionNode(new NodeTimer(_key, _time)); return true; diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 224f9011a1..75cffab59b 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -35,6 +35,7 @@ class ZVision; class ResultAction { public: virtual ~ResultAction() {} + virtual ResultAction *clone() const = 0; virtual bool execute(ZVision *engine) = 0; }; @@ -73,6 +74,7 @@ public: class ActionAdd : public ResultAction { public: ActionAdd(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -83,6 +85,7 @@ private: class ActionAssign : public ResultAction { public: ActionAssign(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -93,6 +96,7 @@ private: class ActionAttenuate : public ResultAction { public: ActionAttenuate(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -103,6 +107,7 @@ private: class ActionChangeLocation : public ResultAction { public: ActionChangeLocation(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -115,6 +120,7 @@ private: class ActionCrossfade : public ResultAction { public: ActionCrossfade(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -130,6 +136,7 @@ private: class ActionDelayRender : public ResultAction { public: ActionDelayRender(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -140,6 +147,7 @@ private: class ActionPlayAnimation : public ResultAction { public: ActionPlayAnimation(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -159,6 +167,7 @@ private: class ActionPreloadAnimation : public ResultAction { public: ActionPreloadAnimation(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -178,6 +187,7 @@ private: class ActionRandom : public ResultAction { public: ActionRandom(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -188,6 +198,7 @@ private: class ActionTimer : public ResultAction { public: ActionTimer(Common::String *line); + ResultAction *clone() const; bool execute(ZVision *engine); private: -- cgit v1.2.3 From 7d58ebf2819562893df2f07b916c9712d5b7413f Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:43:49 -0500 Subject: ZVISION: Convert Puzzle to a class It needed a copy constructor and destructor to handle the heap memory ResultActions --- engines/zvision/puzzle.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 06c228d367..08d8a5cfd7 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -58,7 +58,27 @@ enum StateFlags { DISABLED = 0x04 }; -struct Puzzle { +class Puzzle { +public: + ~Puzzle() { + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + delete (*iter); + } + } + + Puzzle() {} + + // Copy constructor + Puzzle(const Puzzle &other) + : key(other.key), + criteriaList(other.criteriaList), + flags(flags) { + // We have to clone the ResultActions since they are on the heap + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + resultActions.push_back((*iter)->clone()); + } + } + uint32 key; Common::List criteriaList; // This has to be list of pointers because ResultAction is abstract -- cgit v1.2.3 From cf9790a9d6407e3bfea46cea1c59abe9ab5de31c Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:45:53 -0500 Subject: ZVISION: Create mutators for _tiltOptions --- engines/zvision/render_table.cpp | 12 ++++++++++++ engines/zvision/render_table.h | 3 +++ 2 files changed, 15 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index e3ce77952b..49203df195 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -171,4 +171,16 @@ void RenderTable::setPanoramaScale(float scale) { _panoramaOptions.linearScale = scale; } +void RenderTable::setTiltFoV(float fov) { + assert(fov > 0.0f); + + _tiltOptions.fieldOfView = fov; +} + +void RenderTable::setTiltScale(float scale) { + assert(scale > 0.0f); + + _tiltOptions.linearScale = scale; +} + } // End of namespace ZVision diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 5698feaa03..ccb5926a51 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -67,6 +67,9 @@ public: void setPanoramaFoV(float fov); void setPanoramaScale(float scale); + void setTiltFoV(float fov); + void setTiltScale(float scale); + private: void generatePanoramaLookupTable(); void generateTiltLookupTable(); -- cgit v1.2.3 From b20437a17d1a740e70dd1fa0bbf3bc6cfeb6c494 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:49:06 -0500 Subject: ZVISION: Modify Criteria parsing to handle empty Criteria --- engines/zvision/scr_file_handling.cpp | 46 +++++++++++++++++++++-------------- engines/zvision/script_manager.h | 7 +++--- 2 files changed, 32 insertions(+), 21 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 168a6d830a..cebb57a786 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -72,22 +72,32 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre trimCommentsAndWhiteSpace(&line); while (!line.contains('}')) { - if (line.matchString("criteria {", true)) - puzzle.criteriaList.push_back(parseCriteria(stream)); - else if (line.matchString("results {", true)) - parseResult(stream, puzzle.resultActions); - else if (line.matchString("flags {", true)) + if (line.matchString("criteria {", true)) { + Criteria criteria; + if (parseCriteria(&criteria, stream)) { + puzzle.criteriaList.push_back(criteria); + } + } else if (line.matchString("results {", true)) { + parseResults(stream, puzzle.resultActions); + } else if (line.matchString("flags {", true)) { puzzle.flags = parseFlags(stream); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); } } -Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const { - Criteria criteria; - +bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + // Criteria can be empty + if (line.contains('}')) { + return false; + } + while (!line.contains('}')) { // Split the string into tokens using ' ' as a delimiter Common::StringTokenizer tokenizer(line); @@ -95,35 +105,35 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const // Parse the id out of the first token token = tokenizer.nextToken(); - sscanf(token.c_str(), "[%u]", &(criteria.key)); + sscanf(token.c_str(), "[%u]", &(criteria->key)); // Parse the operator out of the second token token = tokenizer.nextToken(); if (token.c_str()[0] == '=') - criteria.criteriaOperator = EQUAL_TO; + criteria->criteriaOperator = EQUAL_TO; else if (token.c_str()[0] == '!') - criteria.criteriaOperator = NOT_EQUAL_TO; + criteria->criteriaOperator = NOT_EQUAL_TO; else if (token.c_str()[0] == '>') - criteria.criteriaOperator = GREATER_THAN; + criteria->criteriaOperator = GREATER_THAN; else if (token.c_str()[0] == '<') - criteria.criteriaOperator = LESS_THAN; + criteria->criteriaOperator = LESS_THAN; // First determine if the last token is an id or a value // Then parse it into 'argument' token = tokenizer.nextToken(); if (token.contains('[')) { - sscanf(token.c_str(), "[%u]", &(criteria.argument)); - criteria.argumentIsAKey = true; + sscanf(token.c_str(), "[%u]", &(criteria->argument)); + criteria->argumentIsAKey = true; } else { - sscanf(token.c_str(), "%u", &(criteria.argument)); - criteria.argumentIsAKey = false; + sscanf(token.c_str(), "%u", &(criteria->argument)); + criteria->argumentIsAKey = false; } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } - return criteria; + return true; } void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 2d9bcc3fd5..ec16477b92 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -97,10 +97,11 @@ private: * Parses the stream into a Criteria object * Helper method for parsePuzzle. * - * @param stream Scr file stream - * @return Created Criteria object + * @param criteria Pointer to the Criteria object to fill + * @param stream Scr file stream + * @return Whether any criteria were read */ - Criteria parseCriteria(Common::SeekableReadStream &stream) const; + bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const; /** * Parses the stream into a Results object -- cgit v1.2.3 From c22c91b7d3056fdbb100b3b0fd6bda1aa8626b79 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:50:36 -0500 Subject: ZVISION: Create Control class --- engines/zvision/control.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/control.h | 20 ++++++++- 2 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 engines/zvision/control.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp new file mode 100644 index 0000000000..59ef14eb07 --- /dev/null +++ b/engines/zvision/control.cpp @@ -0,0 +1,101 @@ +/* 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/scummsys.h" + +#include "common/stream.h" + +#include "zvision/zvision.h" +#include "zvision/render_manager.h" +#include "zvision/render_table.h" +#include "zvision/control.h" +#include "zvision/utility.h" + +namespace ZVision { + +void Control::parseFlatControl(ZVision *engine) { + engine->getRenderManager()->getRenderTable()->setRenderState(RenderTable::FLAT); +} + +void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream &stream) { + RenderTable *renderTable = engine->getRenderManager()->getRenderTable(); + renderTable->setRenderState(RenderTable::PANORAMA); + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + while (!line.contains('}')) { + if (line.matchString("angle*", true)) { + float fov; + sscanf(line.c_str(), "angle(%f)", &fov); + renderTable->setPanoramaFoV(fov); + } else if (line.matchString("linscale*", true)) { + float scale; + sscanf(line.c_str(), "angle(%f)", &scale); + renderTable->setPanoramaScale(scale); + } else if (line.matchString("reversepana*", true)) { + byte reverse; + sscanf(line.c_str(), "reversepana(%hhu)", &reverse); + if (reverse == 1) { + renderTable->setPanoramaReverse(true); + } + } else if (line.matchString("zeropoint*", true)) { + // TODO: Implement + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + } +} + +void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream) { + RenderTable *renderTable = engine->getRenderManager()->getRenderTable(); + renderTable->setRenderState(RenderTable::TILT); + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + while (!line.contains('}')) { + if (line.matchString("angle*", true)) { + float fov; + sscanf(line.c_str(), "angle(%f)", &fov); + renderTable->setTiltFoV(fov); + } else if (line.matchString("linscale*", true)) { + float scale; + sscanf(line.c_str(), "angle(%f)", &scale); + renderTable->setTiltScale(scale); + } else if (line.matchString("reversepana*", true)) { + byte reverse; + sscanf(line.c_str(), "reversepana(%hhu)", &reverse); + if (reverse == 1) { + renderTable->setTiltReverse(true); + } + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 1f59478b4c..edc0fc2930 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -25,11 +25,27 @@ #include "common/types.h" +namespace Common { +class SeekableReadStream; +} + namespace ZVision { -struct Control { - uint16 id; +class ZVision; + +class Control { +public: + virtual ~Control() {} + virtual bool execute(ZVision *engine) = 0; + +protected: + uint32 key; +// Static member functions +public: + static void parseFlatControl(ZVision *engine); + static void parsePanoramaControl(ZVision *engine, Common::SeekableReadStream &stream); + static void parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream); }; } // End of namespace ZVision -- cgit v1.2.3 From 48a3a1530db615baf2388eb16118facb79f0a28a Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:52:27 -0500 Subject: ZVISION: Move the criteriaMet bool outside of the loop Only fire off the Results of ALL of the criteria are met --- engines/zvision/script_manager.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 7fcf2f67a3..85c900bc0e 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -77,10 +77,10 @@ void ScriptManager::updateNodes(uint32 deltaTimeMillis) { void ScriptManager::checkPuzzleCriteria() { while (!_puzzlesToCheck.empty()) { Puzzle *puzzle = _puzzlesToCheck.pop(); + // Check each Criteria + bool criteriaMet = false; for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { - bool criteriaMet = false; - // Get the value to compare against byte argumentValue; if ((*iter).argument) @@ -104,11 +104,16 @@ void ScriptManager::checkPuzzleCriteria() { break; } - // TODO: Add logic for the different Flags (aka, ONCE_PER_INST) - if (criteriaMet) { - for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { - (*resultIter)->execute(_engine); - } + if (!criteriaMet) { + break; + } + } + + // TODO: Add logic for the different Flags (aka, ONCE_PER_INST) + // criteriaList can be empty. Aka, the puzzle should be executed immediately + if (puzzle->criteriaList.empty() || criteriaMet) { + for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { + (*resultIter)->execute(_engine); } } } -- cgit v1.2.3 From 2063cb711dce1894125d1cc6bab5a2d27a163be3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:53:24 -0500 Subject: ZVISION: Add 'reverse' to _tiltOptions and _panoramaOptions to handle Control options --- engines/zvision/render_table.cpp | 9 +++++++++ engines/zvision/render_table.h | 4 ++++ 2 files changed, 13 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 49203df195..adf1d647b7 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -49,6 +49,7 @@ void RenderTable::setRenderState(RenderState newState) { case PANORAMA: _panoramaOptions.fieldOfView = 27.0f; _panoramaOptions.linearScale = 0.55f; + _panoramaOptions.reverse = false; break; case TILT: @@ -171,6 +172,10 @@ void RenderTable::setPanoramaScale(float scale) { _panoramaOptions.linearScale = scale; } +void RenderTable::setPanoramaReverse(bool reverse) { + _panoramaOptions.reverse = reverse; +} + void RenderTable::setTiltFoV(float fov) { assert(fov > 0.0f); @@ -183,4 +188,8 @@ void RenderTable::setTiltScale(float scale) { _tiltOptions.linearScale = scale; } +void RenderTable::setTiltReverse(bool reverse) { + _tiltOptions.reverse = reverse; +} + } // End of namespace ZVision diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index ccb5926a51..e5535a0544 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -50,12 +50,14 @@ private: struct { float fieldOfView; float linearScale; + bool reverse; } _panoramaOptions; // TODO: See if tilt and panorama need to have separate options struct { float fieldOfView; float linearScale; + bool reverse; } _tiltOptions; public: @@ -66,9 +68,11 @@ public: void setPanoramaFoV(float fov); void setPanoramaScale(float scale); + void setPanoramaReverse(bool reverse); void setTiltFoV(float fov); void setTiltScale(float scale); + void setTiltReverse(bool reverse); private: void generatePanoramaLookupTable(); -- cgit v1.2.3 From d4ae293f881ae07afd243173ddd11d5b0cfa12b3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:54:10 -0500 Subject: ZVISION: Rename parseResult() to parseResults() --- engines/zvision/scr_file_handling.cpp | 2 +- engines/zvision/script_manager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index cebb57a786..ca66e3bccd 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -136,7 +136,7 @@ bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream return true; } -void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const { +void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index ec16477b92..1b12a0693d 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -110,7 +110,7 @@ private: * @param stream Scr file stream * @return Created Results object */ - void parseResult(Common::SeekableReadStream &stream, Common::List &actionList) const; + void parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const; /** * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum -- cgit v1.2.3 From 070042fcb4ea473cd2bfbebf9838957cdb9150b8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:56:50 -0500 Subject: ZVISION: Modify Control parsing to use new Control class structure --- engines/zvision/scr_file_handling.cpp | 39 ++++++++++++++++++++++++++++------- engines/zvision/script_manager.h | 8 +++---- 2 files changed, 35 insertions(+), 12 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index ca66e3bccd..ec73fa1fdf 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -56,13 +56,11 @@ void ScriptManager::parseScrFile(Common::String fileName) { parsePuzzle(puzzle, file); _activePuzzles.push_back(puzzle); } else if (line.matchString("control:*", true)) { - Control control; - char controlType[20]; - sscanf(line.c_str(),"control:%u %s",&(control.id), controlType); - - parseControl(control, file); - /** Holds the currently active puzzles */ - _activeControls.push_back(control); + Control *control = parseControl(line, file); + // Some controls don't require nodes. They just initialize the scene + if (control != 0) { + _activeControls.push_back(control); + } } } } @@ -284,13 +282,38 @@ byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { } else if (line.matchString("DISABLED", true)) { flags |= DISABLED; } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); } return flags; } -void ScriptManager::parseControl(Control &control, Common::SeekableReadStream &stream) { +Control *ScriptManager::parseControl(Common::String &line, Common::SeekableReadStream &stream) { + Control *control = 0; + uint32 key; + char controlTypeBuffer[20]; + + sscanf(line.c_str(), "control:%u %s {", &key, controlTypeBuffer); + + Common::String controlType(controlTypeBuffer); + + if (controlType.equalsIgnoreCase("push_toggle")) { + + } else if (controlType.equalsIgnoreCase("flat")) { + Control::parseFlatControl(_engine); + return 0; + } else if (controlType.equalsIgnoreCase("pana")) { + Control::parsePanoramaControl(_engine, stream); + return 0; + } + else if (controlType.equalsIgnoreCase("tilt")) { + Control::parseTiltControl(_engine, stream); + return 0; + } + return control; } } // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 1b12a0693d..8ffd3a0ad2 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -60,7 +60,7 @@ private: /** Holds the currently active puzzles */ Common::List _activePuzzles; /** Holds the currently active controls */ - Common::List _activeControls; + Common::List _activeControls; public: @@ -123,10 +123,10 @@ private: /** * Helper method for parseScrFile. Parses the stream into a Control object * - * @param control The object to store what is parsed - * @param stream Scr file stream + * @param line The line initially read + * @param stream Scr file stream */ - void parseControl(Control &control, Common::SeekableReadStream &stream); + Control *parseControl(Common::String &line, Common::SeekableReadStream &stream); }; -- cgit v1.2.3 From 00eb2792438f118775546011d2f1abdc9b0bc0cd Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 21:57:45 -0500 Subject: ZVISION: Create ScriptManager member function to change location --- engines/zvision/actions.cpp | 2 +- engines/zvision/actions.h | 3 ++- engines/zvision/script_manager.cpp | 24 ++++++++++++++++++++++++ engines/zvision/script_manager.h | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 35e5d4886d..0cec6af76e 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -88,7 +88,7 @@ bool ActionAttenuate::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionChangeLocation::ActionChangeLocation(Common::String *line) { - sscanf(line->c_str(), ":change_location(%c,%c,%2c,%hu)", &_world, &_room, &_nodeview, &_x); + sscanf(line->c_str(), ":change_location(%c,%c,%c%c,%hu)", &_world, &_room, &_node, &_view, &_x); } ResultAction *ActionChangeLocation::clone() const { diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 75cffab59b..83f871d4e7 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -113,7 +113,8 @@ public: private: char _world; char _room; - char _nodeview[2]; + char _node; + char _view; int16 _x; }; diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 85c900bc0e..97f2cadfce 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -136,4 +136,28 @@ void ScriptManager::addActionNode(ActionNode *node) { _activeNodes.push_back(node); } +void ScriptManager::changeLocation(char world, char room, char node, char view, uint16 x) { + // Clear all the containers + _referenceTable.clear(); + _puzzlesToCheck.clear(); + _activePuzzles.clear(); + // _activeControls is a list of pointers to the heap, so we have to delete the Controls before we call clear() + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + delete (*iter); + } + _activeControls.clear(); + + // Parse into puzzles and controls + Common::String fileName = Common::String::format("%c%c%c&c.scr", world, room, node, view); + parseScrFile(fileName); + + // Create the puzzle reference table + createReferenceTable(); + + // Add all the puzzles to the stack to be checked + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + _puzzlesToCheck.push(&(*iter)); + } +} + } // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 8ffd3a0ad2..caec0dd550 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -74,6 +74,8 @@ public: void addActionNode(ActionNode *node); + void changeLocation(char world, char room, char node, char view, uint16 x); + private: void createReferenceTable(); -- cgit v1.2.3 From ea47c28ddf20e366d43317ca273e84db0acd32db Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 22:10:59 -0500 Subject: ZVISION: Make ActionNode::process() pure virtual --- engines/zvision/action_node.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h index cd5c9f3b27..324dba279d 100644 --- a/engines/zvision/action_node.h +++ b/engines/zvision/action_node.h @@ -32,7 +32,7 @@ class ZVision; class ActionNode { public: virtual ~ActionNode() {} - virtual bool process(ZVision *engine, uint32 deltaTimeInMillis); + virtual bool process(ZVision *engine, uint32 deltaTimeInMillis) = 0; }; class NodeTimer : public ActionNode { -- cgit v1.2.3 From f975fbe52190ccc0ca1264d6aa63a897ad784f31 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 22:15:24 -0500 Subject: ZVISION: Move Puzzle logic into a .cpp file --- engines/zvision/puzzle.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/puzzle.h | 19 ++----------------- 2 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 engines/zvision/puzzle.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.cpp b/engines/zvision/puzzle.cpp new file mode 100644 index 0000000000..8399919399 --- /dev/null +++ b/engines/zvision/puzzle.cpp @@ -0,0 +1,46 @@ +/* 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/scummsys.h" + +#include "zvision/actions.h" +#include "zvision/puzzle.h" + +namespace ZVision { + +Puzzle::~Puzzle() { + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + delete (*iter); + } +} + +Puzzle::Puzzle(const Puzzle &other) + : key(other.key), + criteriaList(other.criteriaList), + flags(flags) { + // We have to clone the ResultActions since they are on the heap + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + resultActions.push_back((*iter)->clone()); + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 08d8a5cfd7..a0c4e9d758 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -60,24 +60,9 @@ enum StateFlags { class Puzzle { public: - ~Puzzle() { - for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { - delete (*iter); - } - } - Puzzle() {} - - // Copy constructor - Puzzle(const Puzzle &other) - : key(other.key), - criteriaList(other.criteriaList), - flags(flags) { - // We have to clone the ResultActions since they are on the heap - for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { - resultActions.push_back((*iter)->clone()); - } - } + ~Puzzle(); + Puzzle(const Puzzle &other); uint32 key; Common::List criteriaList; -- cgit v1.2.3 From f39e1fdc43a97c0d06bfcda0e5c6dfdfb4e95ef7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 29 Jul 2013 22:16:21 -0500 Subject: ZVISION: Move CriteriaOperator, Criteria, and StateFlag inside the Puzzle class --- engines/zvision/puzzle.h | 60 ++++++++++++++++++----------------- engines/zvision/scr_file_handling.cpp | 18 +++++------ engines/zvision/script_manager.cpp | 12 +++---- engines/zvision/script_manager.h | 2 +- 4 files changed, 47 insertions(+), 45 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index a0c4e9d758..fba139c0a6 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -29,41 +29,43 @@ namespace ZVision { class ResultAction; -/** How criteria should be decided */ -enum CriteriaOperator { - EQUAL_TO, - NOT_EQUAL_TO, - GREATER_THAN, - LESS_THAN -}; - -/** Criteria for a Puzzle result to be fired */ -struct Criteria { - /** The key of a global state */ - uint32 key; - /** - * What we're comparing the value of the global state against - * This can either be a pure value or it can be the key of another global state - */ - uint32 argument; - /** How to do the comparison */ - CriteriaOperator criteriaOperator; - /** Whether 'argument' is the key of a global state (true) or a pure value (false) */ - bool argumentIsAKey; -}; - -enum StateFlags { - ONCE_PER_INST = 0x01, - DO_ME_NOW = 0x02, - DISABLED = 0x04 -}; - class Puzzle { public: Puzzle() {} ~Puzzle(); Puzzle(const Puzzle &other); + +public: + /** How criteria should be decided */ + enum CriteriaOperator { + EQUAL_TO, + NOT_EQUAL_TO, + GREATER_THAN, + LESS_THAN + }; + + /** Criteria for a Puzzle result to be fired */ + struct Criteria { + /** The key of a global state */ + uint32 key; + /** + * What we're comparing the value of the global state against + * This can either be a pure value or it can be the key of another global state + */ + uint32 argument; + /** How to do the comparison */ + CriteriaOperator criteriaOperator; + /** Whether 'argument' is the key of a global state (true) or a pure value (false) */ + bool argumentIsAKey; + }; + enum StateFlags { + ONCE_PER_INST = 0x01, + DO_ME_NOW = 0x02, + DISABLED = 0x04 + }; + +public: uint32 key; Common::List criteriaList; // This has to be list of pointers because ResultAction is abstract diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index ec73fa1fdf..5f2140d45a 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -71,7 +71,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre while (!line.contains('}')) { if (line.matchString("criteria {", true)) { - Criteria criteria; + Puzzle::Criteria criteria; if (parseCriteria(&criteria, stream)) { puzzle.criteriaList.push_back(criteria); } @@ -86,7 +86,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre } } -bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const { +bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -108,13 +108,13 @@ bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream // Parse the operator out of the second token token = tokenizer.nextToken(); if (token.c_str()[0] == '=') - criteria->criteriaOperator = EQUAL_TO; + criteria->criteriaOperator = Puzzle::EQUAL_TO; else if (token.c_str()[0] == '!') - criteria->criteriaOperator = NOT_EQUAL_TO; + criteria->criteriaOperator = Puzzle::NOT_EQUAL_TO; else if (token.c_str()[0] == '>') - criteria->criteriaOperator = GREATER_THAN; + criteria->criteriaOperator = Puzzle::GREATER_THAN; else if (token.c_str()[0] == '<') - criteria->criteriaOperator = LESS_THAN; + criteria->criteriaOperator = Puzzle::LESS_THAN; // First determine if the last token is an id or a value // Then parse it into 'argument' @@ -276,11 +276,11 @@ byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { while (!line.contains('}')) { if (line.matchString("ONCE_PER_INST", true)) { - flags |= ONCE_PER_INST; + flags |= Puzzle::ONCE_PER_INST; } else if (line.matchString("DO_ME_NOW", true)) { - flags |= DO_ME_NOW; + flags |= Puzzle::DO_ME_NOW; } else if (line.matchString("DISABLED", true)) { - flags |= DISABLED; + flags |= Puzzle::DISABLED; } line = stream.readLine(); diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 97f2cadfce..0ff0509737 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -45,7 +45,7 @@ void ScriptManager::createReferenceTable() { Puzzle *puzzlePtr = &(*activePuzzleIter); // Iterate through each Criteria and add a reference from the criteria key to the Puzzle - for (Common::List::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { _referenceTable[criteriaIter->key].push_back(puzzlePtr); // If the argument is a key, add a reference to it as well @@ -80,7 +80,7 @@ void ScriptManager::checkPuzzleCriteria() { // Check each Criteria bool criteriaMet = false; - for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { + for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { // Get the value to compare against byte argumentValue; if ((*iter).argument) @@ -90,16 +90,16 @@ void ScriptManager::checkPuzzleCriteria() { // Do the comparison switch ((*iter).criteriaOperator) { - case EQUAL_TO: + case Puzzle::EQUAL_TO: criteriaMet = getStateValue(iter->key) == argumentValue; break; - case NOT_EQUAL_TO: + case Puzzle::NOT_EQUAL_TO: criteriaMet = getStateValue(iter->key) != argumentValue; break; - case GREATER_THAN: + case Puzzle::GREATER_THAN: criteriaMet = getStateValue(iter->key) > argumentValue; break; - case LESS_THAN: + case Puzzle::LESS_THAN: criteriaMet = getStateValue(iter->key) < argumentValue; break; } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index caec0dd550..3e054ff68a 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -103,7 +103,7 @@ private: * @param stream Scr file stream * @return Whether any criteria were read */ - bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const; + bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const; /** * Parses the stream into a Results object -- cgit v1.2.3 From 89d8496dbac2fb1fc5fc77d5b26fa2a9405f9d77 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 30 Jul 2013 12:56:21 +0300 Subject: ZVISION: Add detection entry and directories for ZGI --- engines/zvision/detection.cpp | 14 ++++++++++++++ engines/zvision/zvision.cpp | 2 ++ 2 files changed, 16 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 8c87c90203..a799cc2aeb 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -71,6 +71,20 @@ static const ZVisionGameDescription gameDescriptions[] = { ZorkNemesis }, + { + // Zork Grand Inquisitor English version + { + "zgi", + 0, + AD_ENTRY1s("SCRIPTS.ZFS", "81efd40ecc3d22531e211368b779f17f", 8336944), + Common::EN_ANY, + Common::kPlatformDOS, + ADGF_NO_FLAGS, + GUIO1(GUIO_NONE) + }, + ZorkGrandInquisitor + }, + { AD_TABLE_END_MARKER } }; diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index b79ecb4993..fa91f8ca29 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -60,6 +60,8 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4, true); SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4, true); SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets1", 0, 2, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets2", 0, 2, true); SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx", 0, 1, true); // Here is the right place to set up the engine specific debug channels -- cgit v1.2.3 From f1135292d0d714187b719988dba8d5a7d487fe94 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 30 Jul 2013 14:25:31 -0500 Subject: ZVISION: Optimize integer type usages The general thought is int is faster than int16 or byte. So if you can afford the space, use it over int16 or byte. Also, only use int32 when you specifically need the 32 bits. --- engines/zvision/action_node.cpp | 2 +- engines/zvision/action_node.h | 2 +- engines/zvision/actions.cpp | 2 +- engines/zvision/actions.h | 32 ++++++++++++++++---------------- engines/zvision/control.cpp | 8 ++++---- engines/zvision/events.cpp | 2 +- engines/zvision/lzss_read_stream.cpp | 6 +++--- engines/zvision/lzss_read_stream.h | 4 ++-- engines/zvision/puzzle.h | 2 +- engines/zvision/render_table.cpp | 14 +++++++------- engines/zvision/render_table.h | 4 ++-- engines/zvision/scr_file_handling.cpp | 4 ++-- engines/zvision/script_manager.cpp | 12 ++++++------ engines/zvision/script_manager.h | 16 ++++++++-------- engines/zvision/utility.h | 2 +- engines/zvision/video.cpp | 14 +++++++------- engines/zvision/zork_raw.cpp | 4 ++-- engines/zvision/zork_raw.h | 4 ++-- engines/zvision/zvision.cpp | 2 +- engines/zvision/zvision.h | 2 +- 20 files changed, 69 insertions(+), 69 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.cpp b/engines/zvision/action_node.cpp index dec52d9615..1a51690b3f 100644 --- a/engines/zvision/action_node.cpp +++ b/engines/zvision/action_node.cpp @@ -28,7 +28,7 @@ namespace ZVision { -NodeTimer::NodeTimer(uint32 key, uint32 timeInSeconds) +NodeTimer::NodeTimer(uint32 key, uint timeInSeconds) : _key(key), _timeLeft(timeInSeconds * 1000) {} bool NodeTimer::process(ZVision *engine, uint32 deltaTimeInMillis) { diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h index 324dba279d..5b4430c3a4 100644 --- a/engines/zvision/action_node.h +++ b/engines/zvision/action_node.h @@ -37,7 +37,7 @@ public: class NodeTimer : public ActionNode { public: - NodeTimer(uint32 key, uint32 timeInSeconds); + NodeTimer(uint32 key, uint timeInSeconds); /** * Decrement the timer by the delta time. If the timer is finished, set the status * in _globalState and let this node be deleted diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 0cec6af76e..2e1334c38b 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -174,7 +174,7 @@ ResultAction *ActionRandom::clone() const { } bool ActionRandom::execute(ZVision *engine) { - uint32 randNumber = engine->getRandomSource()->getRandomNumber(_max); + uint randNumber = engine->getRandomSource()->getRandomNumber(_max); engine->getScriptManager()->setStateValue(_key, randNumber); return true; } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 83f871d4e7..8380f1587a 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -79,7 +79,7 @@ public: private: uint32 _key; - byte _value; + uint _value; }; class ActionAssign : public ResultAction { @@ -90,7 +90,7 @@ public: private: uint32 _key; - byte _value; + uint _value; }; class ActionAttenuate : public ResultAction { @@ -101,7 +101,7 @@ public: private: uint32 _key; - int16 _attenuation; + int _attenuation; }; class ActionChangeLocation : public ResultAction { @@ -115,7 +115,7 @@ private: char _room; char _node; char _view; - int16 _x; + uint32 _x; }; class ActionCrossfade : public ResultAction { @@ -127,11 +127,11 @@ public: private: uint32 _keyOne; uint32 _keyTwo; - byte _oneStartVolume; - byte _twoStartVolume; - byte _oneEndVolume; - byte _twoEndVolume; - uint16 _timeInMillis; + uint _oneStartVolume; + uint _twoStartVolume; + uint _oneEndVolume; + uint _twoEndVolume; + uint _timeInMillis; }; class ActionDelayRender : public ResultAction { @@ -142,7 +142,7 @@ public: private: // TODO: Check if this should actually be frames or if it should be milliseconds/seconds - byte framesToDelay; + uint32 framesToDelay; }; class ActionPlayAnimation : public ResultAction { @@ -160,8 +160,8 @@ private: uint32 _height; uint32 _start; uint32 _end; - uint32 _mask; - byte _framerate; + uint _mask; + uint _framerate; bool _loop; }; @@ -174,8 +174,8 @@ public: private: uint32 _key; Common::String _fileName; - uint32 _mask; - byte _framerate; + uint _mask; + uint _framerate; }; // TODO: See if this exists in ZGI. It doesn't in ZNem @@ -193,7 +193,7 @@ public: private: uint32 _key; - uint32 _max; + uint _max; }; class ActionTimer : public ResultAction { @@ -204,7 +204,7 @@ public: private: uint32 _key; - uint32 _time; + uint _time; }; } // End of namespace ZVision diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index 59ef14eb07..af384cbf2f 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -54,8 +54,8 @@ void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream & sscanf(line.c_str(), "angle(%f)", &scale); renderTable->setPanoramaScale(scale); } else if (line.matchString("reversepana*", true)) { - byte reverse; - sscanf(line.c_str(), "reversepana(%hhu)", &reverse); + uint reverse; + sscanf(line.c_str(), "reversepana(%u)", &reverse); if (reverse == 1) { renderTable->setPanoramaReverse(true); } @@ -86,8 +86,8 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre sscanf(line.c_str(), "angle(%f)", &scale); renderTable->setTiltScale(scale); } else if (line.matchString("reversepana*", true)) { - byte reverse; - sscanf(line.c_str(), "reversepana(%hhu)", &reverse); + uint reverse; + sscanf(line.c_str(), "reversepana(%u)", &reverse); if (reverse == 1) { renderTable->setTiltReverse(true); } diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index a01ea74cd0..e392d3c78a 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -87,7 +87,7 @@ void ZVision::onMouseMove(const Common::Point &pos) { } -void ZVision::onKeyDown(uint16 keyCode) { +void ZVision::onKeyDown(uint keyCode) { } diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index d169620a25..8518c8fff9 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -42,9 +42,9 @@ uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) byte flagbyte = _source->readByte(); if (_source->eos()) break; - byte mask = 1; + uint mask = 1; - for (uint32 i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { if ((flagbyte & mask) == mask) { byte data = _source->readByte(); @@ -70,7 +70,7 @@ uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) uint16 length = (high & 0xF) + 2; uint16 offset = low | ((high & 0xF0)<<4); - for(byte j = 0; j <= length; j++) + for(int j = 0; j <= length; j++) { byte temp = _window[(offset + j) & 0xFFF]; _window[_windowCursor] = temp; diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 0814220728..25bb66339e 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -49,8 +49,8 @@ public: private: Common::SeekableReadStream *_source; - char _window[_blockSize]; - uint16 _windowCursor; + byte _window[BLOCK_SIZE]; + uint _windowCursor; bool _eosFlag; public: diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index fba139c0a6..c73a345c3a 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -70,7 +70,7 @@ public: Common::List criteriaList; // This has to be list of pointers because ResultAction is abstract Common::List resultActions; - byte flags; + uint flags; // Used by the ScriptManager to allow unique-ification of _referenceTable // The unique-ification is done by sorting, then iterating and removing duplicates diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index adf1d647b7..531114cdbe 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -29,7 +29,7 @@ namespace ZVision { -RenderTable::RenderTable(uint32 numColumns, uint32 numRows) +RenderTable::RenderTable(uint numColumns, uint numRows) : _numRows(numRows), _numColumns(numColumns), _renderState(FLAT) { @@ -85,10 +85,10 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 i bool isTransposed = _renderState == RenderTable::PANORAMA || _renderState == RenderTable::TILT; for (int y = subRectangle.top; y < subRectangle.bottom; y++) { - uint32 normalizedY = y - subRectangle.top; + uint normalizedY = y - subRectangle.top; for (int x = subRectangle.left; x < subRectangle.right; x++) { - uint32 normalizedX = x - subRectangle.left; + uint normalizedX = x - subRectangle.left; uint32 index = (y + destRectangle.top) * _numColumns + (x + destRectangle.left); @@ -137,15 +137,15 @@ void RenderTable::generatePanoramaLookupTable() { float tanOverHalfHeight = tan(fovRadians) / halfHeight; // TODO: Change the algorithm to write a whole row at a time instead of a whole column at a time. AKA: for(y) { for(x) {}} instead of for(x) { for(y) {}} - for (uint32 x = 0; x < _numColumns; x++) { + for (uint x = 0; x < _numColumns; x++) { // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) float temp = atan(tanOverHalfHeight * ((float)x - halfWidth + 0.01f)); - int32 newX = floor((halfHeightOverTan * _panoramaOptions.linearScale * temp) + halfWidth); + int32 newX = int32(floor((halfHeightOverTan * _panoramaOptions.linearScale * temp) + halfWidth)); float cosX = cos(temp); - for (uint32 y = 0; y < _numRows; y++) { - int32 newY = floor(halfHeight + (y - halfHeight) * cosX); + for (uint y = 0; y < _numRows; y++) { + int32 newY = int32(floor(halfHeight + ((float)y - halfHeight) * cosX)); uint32 index = y * _numColumns + x; diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index e5535a0544..82bea62769 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -32,7 +32,7 @@ namespace ZVision { class RenderTable { public: - RenderTable(uint32 numRows, uint32 numColumns); + RenderTable(uint numRows, uint numColumns); ~RenderTable(); public: @@ -43,7 +43,7 @@ public: }; private: - uint32 _numColumns, _numRows; + uint _numColumns, _numRows; Vector2 *_internalBuffer; RenderState _renderState; diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 5f2140d45a..fe78a82d8f 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -267,8 +267,8 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis return; } -byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { - byte flags; +uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { + uint flags = 0; // Loop until we find the closing brace Common::String line = stream.readLine(); diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 0ff0509737..90bc202dac 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -60,7 +60,7 @@ void ScriptManager::createReferenceTable() { } } -void ScriptManager::updateNodes(uint32 deltaTimeMillis) { +void ScriptManager::updateNodes(uint deltaTimeMillis) { // If process() returns true, it means the node can be deleted for (Common::List::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) { if ((*iter)->process(_engine, deltaTimeMillis)) { @@ -82,7 +82,7 @@ void ScriptManager::checkPuzzleCriteria() { bool criteriaMet = false; for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { // Get the value to compare against - byte argumentValue; + uint argumentValue; if ((*iter).argument) argumentValue = getStateValue(iter->argument); else @@ -119,16 +119,16 @@ void ScriptManager::checkPuzzleCriteria() { } } -byte ScriptManager::getStateValue(uint32 key) { +uint ScriptManager::getStateValue(uint32 key) { return _globalState[key]; } // TODO: Add logic to check _referenceTable and add to _puzzlesToCheck if necessary -void ScriptManager::setStateValue(uint32 key, byte value) { +void ScriptManager::setStateValue(uint32 key, uint value) { _globalState[key] = value; } -void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) { +void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) { _globalState[key] += valueToAdd; } @@ -136,7 +136,7 @@ void ScriptManager::addActionNode(ActionNode *node) { _activeNodes.push_back(node); } -void ScriptManager::changeLocation(char world, char room, char node, char view, uint16 x) { +void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 x) { // Clear all the containers _referenceTable.clear(); _puzzlesToCheck.clear(); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 3e054ff68a..e8a8324a5c 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -50,7 +50,7 @@ private: * mutators getStateValue() and setStateValue(). This ensures that Puzzles that reference a * particular state key are checked after the key is modified. */ - Common::HashMap _globalState; + Common::HashMap _globalState; /** Holds the currently active ActionNodes */ Common::List _activeNodes; /** References _globalState keys to Puzzles */ @@ -65,16 +65,16 @@ private: public: void initialize(); - void updateNodes(uint32 deltaTimeMillis); + void updateNodes(uint deltaTimeMillis); void checkPuzzleCriteria(); - byte getStateValue(uint32 key); - void setStateValue(uint32 key, byte value); - void addToStateValue(uint32 key, byte valueToAdd); + uint getStateValue(uint32 key); + void setStateValue(uint32 key, uint value); + void addToStateValue(uint32 key, uint valueToAdd); void addActionNode(ActionNode *node); - void changeLocation(char world, char room, char node, char view, uint16 x); + void changeLocation(char world, char room, char node, char view, uint32 x); private: void createReferenceTable(); @@ -118,9 +118,9 @@ private: * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum * * @param stream Scr file stream - * @return Bitwise or of all the flags set within the puzzle + * @return Bitwise OR of all the flags set within the puzzle */ - byte parseFlags(Common::SeekableReadStream &stream) const; + uint parseFlags(Common::SeekableReadStream &stream) const; /** * Helper method for parseScrFile. Parses the stream into a Control object diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 58a7ec3ab7..e68d0de449 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -70,7 +70,7 @@ template void removeDuplicateEntries(Common::Array *container) { Common::sort(container->front(), container->back()); - for (uint32 i = 0; i < container->size(); i++) { + for (int i = 0; i < container->size(); i++) { while (container[i] == container[i +1]) { container->remove_at(i + 1); } diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index caf43ae0b5..1ccf736970 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -33,15 +33,15 @@ namespace ZVision { // Taken from SCI -void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte bytesPerPixel) { +void scale2x(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel) { assert(bytesPerPixel == 1 || bytesPerPixel == 2); - const int newWidth = srcWidth * 2; - const int pitch = newWidth * bytesPerPixel; + const uint32 newWidth = srcWidth * 2; + const uint32 pitch = newWidth * bytesPerPixel; const byte *srcPtr = src; if (bytesPerPixel == 1) { - for (int y = 0; y < srcHeight; y++) { - for (int x = 0; x < srcWidth; x++) { + for (uint32 y = 0; y < srcHeight; y++) { + for (uint32 x = 0; x < srcWidth; x++) { const byte color = *srcPtr++; dst[0] = color; dst[1] = color; @@ -52,8 +52,8 @@ void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte b dst += newWidth; } } else if (bytesPerPixel == 2) { - for (int y = 0; y < srcHeight; y++) { - for (int x = 0; x < srcWidth; x++) { + for (uint32 y = 0; y < srcHeight; y++) { + for (uint32 x = 0; x < srcWidth; x++) { const byte color = *srcPtr++; const byte color2 = *srcPtr++; dst[0] = color; diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 03a35e09ab..742ba188ac 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -73,10 +73,10 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag dis } int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) { - uint32 bytesRead = 0; + int bytesRead = 0; // 0: Left, 1: Right - byte channel = 0; + uint channel = 0; while (bytesRead < numSamples) { byte encodedSample = _stream->readByte(); diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 6d25d197ee..4e40a5716a 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -36,7 +36,7 @@ class ZVision; struct SoundParams { char identifier; - uint16 rate; + uint32 rate; bool stereo; bool packed; }; @@ -73,7 +73,7 @@ private: Audio::Timestamp _playtime; // Calculated total play time Common::DisposablePtr _stream; // Stream to read data from bool _endOfData; // Whether the stream end has been reached - byte _stereo; + uint _stereo; /** * Holds the frequency and index from the last sample diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index fa91f8ca29..ca43549f50 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -117,7 +117,7 @@ Common::Error ZVision::run() { // Main loop uint32 currentTime = _system->getMillis(); uint32 lastTime = currentTime; - const uint32 desiredFrameTime = 33; // ~30 fps + const uint desiredFrameTime = 33; // ~30 fps while (!shouldQuit()) { processEvents(); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 2e6ec11a53..9588623f56 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -83,7 +83,7 @@ private: void processEvents(); void onMouseDown(const Common::Point &pos); void onMouseMove(const Common::Point &pos); - void onKeyDown(uint16 keyCode); + void onKeyDown(uint keyCode); }; } // End of namespace ZVision -- cgit v1.2.3 From 5e442c363ee870b63b13c6325c07be04bfb28fab Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 30 Jul 2013 14:28:47 -0500 Subject: ZVISION: Convert String pointers to const references --- engines/zvision/actions.cpp | 18 +++++++++--------- engines/zvision/actions.h | 22 +++++++++++----------- engines/zvision/scr_file_handling.cpp | 6 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 2e1334c38b..fda6e1b112 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -33,8 +33,8 @@ namespace ZVision { // ActionAdd ////////////////////////////////////////////////////////////////////////////// -ActionAdd::ActionAdd(Common::String *line) { sscanf(line->c_str(), ":add(%u,%hhu)", &_key, &_value); +ActionAdd::ActionAdd(const Common::String &line) { } ResultAction *ActionAdd::clone() const { @@ -51,8 +51,8 @@ bool ActionAdd::execute(ZVision *engine) { // ActionAssign ////////////////////////////////////////////////////////////////////////////// -ActionAssign::ActionAssign(Common::String *line) { sscanf(line->c_str(), ":assign(%u, %hhu)", &_key, &_value); +ActionAssign::ActionAssign(const Common::String &line) { } ResultAction *ActionAssign::clone() const { @@ -69,8 +69,8 @@ bool ActionAssign::execute(ZVision *engine) { // ActionAttenuate ////////////////////////////////////////////////////////////////////////////// -ActionAttenuate::ActionAttenuate(Common::String *line) { sscanf(line->c_str(), ":assign(%u, %hd)", &_key, &_attenuation); +ActionAttenuate::ActionAttenuate(const Common::String &line) { } ResultAction *ActionAttenuate::clone() const { @@ -87,8 +87,8 @@ bool ActionAttenuate::execute(ZVision *engine) { // ActionChangeLocation ////////////////////////////////////////////////////////////////////////////// -ActionChangeLocation::ActionChangeLocation(Common::String *line) { sscanf(line->c_str(), ":change_location(%c,%c,%c%c,%hu)", &_world, &_room, &_node, &_view, &_x); +ActionChangeLocation::ActionChangeLocation(const Common::String &line) { } ResultAction *ActionChangeLocation::clone() const { @@ -105,9 +105,9 @@ bool ActionChangeLocation::execute(ZVision *engine) { // ActionCrossfade ////////////////////////////////////////////////////////////////////////////// -ActionCrossfade::ActionCrossfade(Common::String *line) { sscanf(line->c_str(), ":crossfade(%u %u %hhu %hhu %hhu %hhu %hu)", +ActionCrossfade::ActionCrossfade(const Common::String &line) { &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } @@ -125,9 +125,9 @@ bool ActionCrossfade::execute(ZVision *engine) { // ActionPreloadAnimation ////////////////////////////////////////////////////////////////////////////// -ActionPreloadAnimation::ActionPreloadAnimation(Common::String *line) { // The two %*hhu are always 0 and dont seem to have a use sscanf(line->c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); +ActionPreloadAnimation::ActionPreloadAnimation(const Common::String &line) { } ResultAction *ActionPreloadAnimation::clone() const { @@ -144,10 +144,10 @@ bool ActionPreloadAnimation::execute(ZVision *engine) { // ActionPlayAnimation ////////////////////////////////////////////////////////////////////////////// -ActionPlayAnimation::ActionPlayAnimation(Common::String *line) { // The two %*hhu are always 0 and dont seem to have a use sscanf(line->c_str(), ":animplay:%u(%s %u %u %u %u %u %u %hhu %*hhu %*hhu %u %hhu)", +ActionPlayAnimation::ActionPlayAnimation(const Common::String &line) { &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); } @@ -165,8 +165,8 @@ bool ActionPlayAnimation::execute(ZVision *engine) { // ActionRandom ////////////////////////////////////////////////////////////////////////////// -ActionRandom::ActionRandom(Common::String *line) { sscanf(line->c_str(), ":random:%u, %u)", &_key, &_max); +ActionRandom::ActionRandom(const Common::String &line) { } ResultAction *ActionRandom::clone() const { @@ -184,8 +184,8 @@ bool ActionRandom::execute(ZVision *engine) { // ActionTimer ////////////////////////////////////////////////////////////////////////////// -ActionTimer::ActionTimer(Common::String *line) { sscanf(line->c_str(), ":timer:%u(%hu)", &_key, &_time); +ActionTimer::ActionTimer(const Common::String &line) { } ResultAction *ActionTimer::clone() const { diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 8380f1587a..e10a68869a 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -73,7 +73,7 @@ public: class ActionAdd : public ResultAction { public: - ActionAdd(Common::String *line); + ActionAdd(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -84,7 +84,7 @@ private: class ActionAssign : public ResultAction { public: - ActionAssign(Common::String *line); + ActionAssign(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -95,7 +95,7 @@ private: class ActionAttenuate : public ResultAction { public: - ActionAttenuate(Common::String *line); + ActionAttenuate(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -106,7 +106,7 @@ private: class ActionChangeLocation : public ResultAction { public: - ActionChangeLocation(Common::String *line); + ActionChangeLocation(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -120,7 +120,7 @@ private: class ActionCrossfade : public ResultAction { public: - ActionCrossfade(Common::String *line); + ActionCrossfade(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -136,7 +136,7 @@ private: class ActionDelayRender : public ResultAction { public: - ActionDelayRender(Common::String *line); + ActionDelayRender(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -147,7 +147,7 @@ private: class ActionPlayAnimation : public ResultAction { public: - ActionPlayAnimation(Common::String *line); + ActionPlayAnimation(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -167,7 +167,7 @@ private: class ActionPreloadAnimation : public ResultAction { public: - ActionPreloadAnimation(Common::String *line); + ActionPreloadAnimation(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -181,13 +181,13 @@ private: // TODO: See if this exists in ZGI. It doesn't in ZNem //class ActionUnloadAnimation : public ResultAction { //public: -// ActionUnloadAnimation(Common::String *line); +// ActionUnloadAnimation(const Common::String &line); // bool execute(ZVision *engine); //}; class ActionRandom : public ResultAction { public: - ActionRandom(Common::String *line); + ActionRandom(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); @@ -198,7 +198,7 @@ private: class ActionTimer : public ResultAction { public: - ActionTimer(Common::String *line); + ActionTimer(const Common::String &line); ResultAction *clone() const; bool execute(ZVision *engine); diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index fe78a82d8f..0bd28ec4a9 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -143,11 +143,11 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis while (!line.contains('}')) { // Parse for the action type if (line.matchString("*:add*", true)) { - actionList.push_back(new ActionAdd(&line)); + actionList.push_back(new ActionAdd(line)); } else if (line.matchString("*:animplay*", true)) { - actionList.push_back(new ActionPlayAnimation(&line)); + actionList.push_back(new ActionPlayAnimation(line)); } else if (line.matchString("*:animpreload*", true)) { - actionList.push_back(new ActionPreloadAnimation(&line)); + actionList.push_back(new ActionPreloadAnimation(line)); } else if (line.matchString("*:animunload*", true)) { -- cgit v1.2.3 From d06083aa9625c285454da562bb7397b7cbae8987 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 30 Jul 2013 14:33:53 -0500 Subject: ZVISION: Convert sscanf formats to follow new int lengths --- engines/zvision/actions.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index fda6e1b112..689d5408bf 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -33,8 +33,8 @@ namespace ZVision { // ActionAdd ////////////////////////////////////////////////////////////////////////////// - sscanf(line->c_str(), ":add(%u,%hhu)", &_key, &_value); ActionAdd::ActionAdd(const Common::String &line) { + sscanf(line.c_str(), ":add(%u,%u)", &_key, &_value); } ResultAction *ActionAdd::clone() const { @@ -51,8 +51,8 @@ bool ActionAdd::execute(ZVision *engine) { // ActionAssign ////////////////////////////////////////////////////////////////////////////// - sscanf(line->c_str(), ":assign(%u, %hhu)", &_key, &_value); ActionAssign::ActionAssign(const Common::String &line) { + sscanf(line.c_str(), ":assign(%u, %u)", &_key, &_value); } ResultAction *ActionAssign::clone() const { @@ -69,8 +69,8 @@ bool ActionAssign::execute(ZVision *engine) { // ActionAttenuate ////////////////////////////////////////////////////////////////////////////// - sscanf(line->c_str(), ":assign(%u, %hd)", &_key, &_attenuation); ActionAttenuate::ActionAttenuate(const Common::String &line) { + sscanf(line.c_str(), ":assign(%u, %d)", &_key, &_attenuation); } ResultAction *ActionAttenuate::clone() const { @@ -87,8 +87,8 @@ bool ActionAttenuate::execute(ZVision *engine) { // ActionChangeLocation ////////////////////////////////////////////////////////////////////////////// - sscanf(line->c_str(), ":change_location(%c,%c,%c%c,%hu)", &_world, &_room, &_node, &_view, &_x); ActionChangeLocation::ActionChangeLocation(const Common::String &line) { + sscanf(line.c_str(), ":change_location(%c,%c,%c%c,%u)", &_world, &_room, &_node, &_view, &_x); } ResultAction *ActionChangeLocation::clone() const { @@ -105,9 +105,9 @@ bool ActionChangeLocation::execute(ZVision *engine) { // ActionCrossfade ////////////////////////////////////////////////////////////////////////////// - sscanf(line->c_str(), - ":crossfade(%u %u %hhu %hhu %hhu %hhu %hu)", ActionCrossfade::ActionCrossfade(const Common::String &line) { + sscanf(line.c_str(), + ":crossfade(%u %u %u %u %u %u %u)", &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } @@ -125,9 +125,9 @@ bool ActionCrossfade::execute(ZVision *engine) { // ActionPreloadAnimation ////////////////////////////////////////////////////////////////////////////// - // The two %*hhu are always 0 and dont seem to have a use - sscanf(line->c_str(), ":animpreload:%u(%s %*hhu %*hhu %u %hhu)", &_key, &_fileName, &_mask, &_framerate); ActionPreloadAnimation::ActionPreloadAnimation(const Common::String &line) { + // The two %*u are always 0 and dont seem to have a use + sscanf(line.c_str(), ":animpreload:%u(%s %*u %*u %u %u)", &_key, &_fileName, &_mask, &_framerate); } ResultAction *ActionPreloadAnimation::clone() const { @@ -144,10 +144,10 @@ bool ActionPreloadAnimation::execute(ZVision *engine) { // ActionPlayAnimation ////////////////////////////////////////////////////////////////////////////// - // The two %*hhu are always 0 and dont seem to have a use - sscanf(line->c_str(), - ":animplay:%u(%s %u %u %u %u %u %u %hhu %*hhu %*hhu %u %hhu)", ActionPlayAnimation::ActionPlayAnimation(const Common::String &line) { + // The two %*u are always 0 and dont seem to have a use + sscanf(line.c_str(), + ":animplay:%u(%s %u %u %u %u %u %u %u %*u %*u %u %u)", &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); } @@ -165,8 +165,8 @@ bool ActionPlayAnimation::execute(ZVision *engine) { // ActionRandom ////////////////////////////////////////////////////////////////////////////// - sscanf(line->c_str(), ":random:%u, %u)", &_key, &_max); ActionRandom::ActionRandom(const Common::String &line) { + sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); } ResultAction *ActionRandom::clone() const { @@ -184,8 +184,8 @@ bool ActionRandom::execute(ZVision *engine) { // ActionTimer ////////////////////////////////////////////////////////////////////////////// - sscanf(line->c_str(), ":timer:%u(%hu)", &_key, &_time); ActionTimer::ActionTimer(const Common::String &line) { + sscanf(line.c_str(), ":timer:%u(%u)", &_key, &_time); } ResultAction *ActionTimer::clone() const { -- cgit v1.2.3 From 903e21b8aff563d50f591289eb454cd65bf09d5d Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 30 Jul 2013 14:35:34 -0500 Subject: ZVISION: Initialize the iterator --- engines/zvision/script_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 90bc202dac..2f486c440a 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -55,7 +55,7 @@ void ScriptManager::createReferenceTable() { } // Remove duplicate entries - for (Common::HashMap >::iterator referenceTableIter; referenceTableIter != _referenceTable.end(); referenceTableIter++) { + for (Common::HashMap >::iterator referenceTableIter = _referenceTable.begin(); referenceTableIter != _referenceTable.end(); referenceTableIter++) { removeDuplicateEntries(&(referenceTableIter->_value)); } } -- cgit v1.2.3 From 8ec0a90611560dcb29d0ceb8fc476408c0de4103 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 30 Jul 2013 14:38:58 -0500 Subject: ZVISION: Convert _blockSize to an anonymous enum --- engines/zvision/lzss_read_stream.cpp | 2 +- engines/zvision/lzss_read_stream.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 8518c8fff9..03ab12d8be 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -32,7 +32,7 @@ LzssReadStream::LzssReadStream(Common::SeekableReadStream *source) _windowCursor(0x0FEE), _eosFlag(false) { // Clear the window to null - memset(_window, 0, _blockSize); + memset(_window, 0, BLOCK_SIZE); } uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) { diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 25bb66339e..25a8b67222 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -43,9 +43,10 @@ public: */ LzssReadStream(Common::SeekableReadStream *source); -public: - static const uint32 _npos = 0xFFFFFFFFu; - static const uint16 _blockSize = 0x1000u; +private: + enum { + BLOCK_SIZE = 0x1000 + }; private: Common::SeekableReadStream *_source; -- cgit v1.2.3 From e170be4ea595459065b55c3e218418150c8a53e5 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 30 Jul 2013 14:39:17 -0500 Subject: ZVISION: Remove redundant class qualifier --- engines/zvision/script_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index e8a8324a5c..07dd3d8586 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -103,7 +103,7 @@ private: * @param stream Scr file stream * @return Whether any criteria were read */ - bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const; + bool parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const; /** * Parses the stream into a Results object -- cgit v1.2.3 From 87f2e9a894442bcd2e2e52aa775154045a9304dd Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 30 Jul 2013 20:51:32 -0500 Subject: ZVISION: Update module.mk with current obj --- engines/zvision/module.mk | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 3d672d96bc..f90bb156e6 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -1,17 +1,21 @@ MODULE := engines/zvision MODULE_OBJS := \ + action_node.o \ actions.o \ console.o \ + control.o \ detection.o \ events.o \ - graphics.o \ - image.o \ lzss_read_stream.o \ + puzzle.o \ + render_manager.o \ + render_table.o \ scr_file_handling.o \ script_manager.o \ scripts.o \ single_value_container.o \ + utility.o \ video.o \ zvision.o \ zfs_archive.o \ -- cgit v1.2.3 From d43e1e97419fea23ec2952fd05052e09d71b8037 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 09:59:20 -0500 Subject: ZVISION: Add filename parsing for ActionPlayAnimation --- engines/zvision/actions.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 689d5408bf..d1f5b93431 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -145,10 +145,14 @@ bool ActionPreloadAnimation::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionPlayAnimation::ActionPlayAnimation(const Common::String &line) { + char fileName[25]; + // The two %*u are always 0 and dont seem to have a use sscanf(line.c_str(), ":animplay:%u(%s %u %u %u %u %u %u %u %*u %*u %u %u)", - &_key, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); + &_key, fileName, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); + + _fileName = Common::String(fileName); } ResultAction *ActionPlayAnimation::clone() const { -- cgit v1.2.3 From 8e3ffdece89d608620adfc182b487f683270cbbd Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 09:59:40 -0500 Subject: ZVISION: Initialize _needsScreenUpdate in RenderManager --- engines/zvision/render_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 10afe1f201..7edbf52039 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -40,6 +40,7 @@ RenderManager::RenderManager(OSystem *system, const int width, const int height) _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 _currentVideo(0), _scaledVideoFrameBuffer(0), + _needsScreenUpdate(false), _renderTable(width, height) { } -- cgit v1.2.3 From 4729641cf91eb1ac7528446fb922f5b18e2d46b3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 10:00:24 -0500 Subject: ZVISION: Fix typo in format string --- engines/zvision/script_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 2f486c440a..ad986d6568 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -148,7 +148,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, _activeControls.clear(); // Parse into puzzles and controls - Common::String fileName = Common::String::format("%c%c%c&c.scr", world, room, node, view); + Common::String fileName = Common::String::format("%c%c%c%c.scr", world, room, node, view); parseScrFile(fileName); // Create the puzzle reference table -- cgit v1.2.3 From 3df425004dda026f6989a0020f24bd380cfd34f2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 10:01:00 -0500 Subject: ZVISION: Remove superfluous comma --- engines/zvision/single_value_container.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/single_value_container.h b/engines/zvision/single_value_container.h index 593f11c737..54677ff0a1 100644 --- a/engines/zvision/single_value_container.h +++ b/engines/zvision/single_value_container.h @@ -44,7 +44,7 @@ public: UINT32, FLOAT, DOUBLE, - STRING, + STRING }; // Constructors -- cgit v1.2.3 From 99ecc80e861c17ecb6f3bcc5e9e6c7b5dcb860a7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 10:01:21 -0500 Subject: ZVISION: Initialize iterator --- engines/zvision/utility.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index 2942a35c81..2e1ade663a 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -174,8 +174,8 @@ void dumpEveryResultAction(const Common::String &destFile) { trimCommentsAndWhiteSpace(&line); } - for (Common::HashMap::iterator iter = fileAlreadyUsed.begin(); iter != fileAlreadyUsed.end(); ++iter) { - iter->_value = false; + for (Common::HashMap::iterator fileUsedIter = fileAlreadyUsed.begin(); fileUsedIter != fileAlreadyUsed.end(); ++fileUsedIter) { + fileUsedIter->_value = false; } } -- cgit v1.2.3 From cf453120168ebadacc49d29c8683658fe457963d Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 10:01:44 -0500 Subject: ZVISION: Fix unsigned/signed mismatch warning --- engines/zvision/utility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index e68d0de449..9cc0d1e4e1 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -70,7 +70,7 @@ template void removeDuplicateEntries(Common::Array *container) { Common::sort(container->front(), container->back()); - for (int i = 0; i < container->size(); i++) { + for (uint i = 0; i < container->size(); i++) { while (container[i] == container[i +1]) { container->remove_at(i + 1); } -- cgit v1.2.3 From 2faaf8488bb5bdace2c017b37f825bc38f41ef84 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 15:30:02 -0500 Subject: ZVISION: Convert ResultAction pointers to SharePtr This gets rid of the need for specific destruction as well as making the copy swap operations in the ScriptManger _referenceTable more efficient --- engines/zvision/module.mk | 1 - engines/zvision/puzzle.cpp | 46 ----------------------------------- engines/zvision/puzzle.h | 13 +++------- engines/zvision/scr_file_handling.cpp | 11 ++++----- engines/zvision/script_manager.cpp | 2 +- engines/zvision/script_manager.h | 9 ++++--- 6 files changed, 15 insertions(+), 67 deletions(-) delete mode 100644 engines/zvision/puzzle.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index f90bb156e6..26cf4ee696 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -8,7 +8,6 @@ MODULE_OBJS := \ detection.o \ events.o \ lzss_read_stream.o \ - puzzle.o \ render_manager.o \ render_table.o \ scr_file_handling.o \ diff --git a/engines/zvision/puzzle.cpp b/engines/zvision/puzzle.cpp deleted file mode 100644 index 8399919399..0000000000 --- a/engines/zvision/puzzle.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/actions.h" -#include "zvision/puzzle.h" - -namespace ZVision { - -Puzzle::~Puzzle() { - for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { - delete (*iter); - } -} - -Puzzle::Puzzle(const Puzzle &other) - : key(other.key), - criteriaList(other.criteriaList), - flags(flags) { - // We have to clone the ResultActions since they are on the heap - for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { - resultActions.push_back((*iter)->clone()); - } -} - -} // End of namespace ZVision diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index c73a345c3a..5e060c009a 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -23,19 +23,15 @@ #ifndef ZVISION_PUZZLE_H #define ZVISION_PUZZLE_H + #include "common/list.h" +#include "common/ptr.h" namespace ZVision { class ResultAction; -class Puzzle { -public: - Puzzle() {} - ~Puzzle(); - Puzzle(const Puzzle &other); - -public: +struct Puzzle { /** How criteria should be decided */ enum CriteriaOperator { EQUAL_TO, @@ -65,11 +61,10 @@ public: DISABLED = 0x04 }; -public: uint32 key; Common::List criteriaList; // This has to be list of pointers because ResultAction is abstract - Common::List resultActions; + Common::List> resultActions; uint flags; // Used by the ScriptManager to allow unique-ification of _referenceTable diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 0bd28ec4a9..860e77147d 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -134,7 +134,7 @@ bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableRe return true; } -void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const { +void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::List > &actionList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -143,14 +143,13 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis while (!line.contains('}')) { // Parse for the action type if (line.matchString("*:add*", true)) { - actionList.push_back(new ActionAdd(line)); + actionList.push_back(Common::SharedPtr(new ActionAdd(line))); } else if (line.matchString("*:animplay*", true)) { - actionList.push_back(new ActionPlayAnimation(line)); + actionList.push_back(Common::SharedPtr(new ActionPlayAnimation(line))); } else if (line.matchString("*:animpreload*", true)) { - actionList.push_back(new ActionPreloadAnimation(line)); + actionList.push_back(Common::SharedPtr(new ActionPreloadAnimation(line))); } else if (line.matchString("*:animunload*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionUnloadAnimation(line))); } else if (line.matchString("*:attenuate*", true)) { diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index ad986d6568..540971ad8b 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -112,7 +112,7 @@ void ScriptManager::checkPuzzleCriteria() { // TODO: Add logic for the different Flags (aka, ONCE_PER_INST) // criteriaList can be empty. Aka, the puzzle should be executed immediately if (puzzle->criteriaList.empty() || criteriaMet) { - for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { + for (Common::List >::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { (*resultIter)->execute(_engine); } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 07dd3d8586..c43030d62b 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -106,13 +106,14 @@ private: bool parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const; /** - * Parses the stream into a Results object + * Parses the stream into a ResultAction objects * Helper method for parsePuzzle. * - * @param stream Scr file stream - * @return Created Results object + * @param stream Scr file stream + * @param actionList The list where the results will be added + * @return Created Results object */ - void parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const; + void parseResults(Common::SeekableReadStream &stream, Common::List > &actionList) const; /** * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum -- cgit v1.2.3 From 93e4f4dbf7cb6868e790d877ba01678ba19a8fbb Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 2 Aug 2013 15:31:35 -0500 Subject: ZVISION: Sort using iterators instead of the actual elements Also convert the argument to a reference instead of a pointer --- engines/zvision/script_manager.cpp | 2 +- engines/zvision/utility.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 540971ad8b..cd4e174a7c 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -56,7 +56,7 @@ void ScriptManager::createReferenceTable() { // Remove duplicate entries for (Common::HashMap >::iterator referenceTableIter = _referenceTable.begin(); referenceTableIter != _referenceTable.end(); referenceTableIter++) { - removeDuplicateEntries(&(referenceTableIter->_value)); + removeDuplicateEntries(referenceTableIter->_value); } } diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 9cc0d1e4e1..8974809f97 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -67,12 +67,12 @@ void dumpEveryResultAction(const Common::String &destFile); * @return */ template -void removeDuplicateEntries(Common::Array *container) { - Common::sort(container->front(), container->back()); +void removeDuplicateEntries(Common::Array &container) { + Common::sort(container.begin(), container.end()); - for (uint i = 0; i < container->size(); i++) { - while (container[i] == container[i +1]) { - container->remove_at(i + 1); + for (uint i = 0; i + 1 < container.size(); i++) { + while (container[i] == container[i + 1]) { + container.remove_at(i + 1); } } } -- cgit v1.2.3 From 44ee28c13f39328a4e5e0eca27ac0b5349fe1253 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 13:40:25 -0500 Subject: ZVISION: Remove ResultAction clone member function Puzzle now uses smart pointers so clone is no longer necessary --- engines/zvision/actions.cpp | 33 --------------------------------- engines/zvision/actions.h | 11 ----------- 2 files changed, 44 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index d1f5b93431..438cec7adc 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -37,10 +37,6 @@ ActionAdd::ActionAdd(const Common::String &line) { sscanf(line.c_str(), ":add(%u,%u)", &_key, &_value); } -ResultAction *ActionAdd::clone() const { - return new ActionAdd(*this); -} - bool ActionAdd::execute(ZVision *engine) { engine->getScriptManager()->addToStateValue(_key, _value); return true; @@ -55,10 +51,6 @@ ActionAssign::ActionAssign(const Common::String &line) { sscanf(line.c_str(), ":assign(%u, %u)", &_key, &_value); } -ResultAction *ActionAssign::clone() const { - return new ActionAssign(*this); -} - bool ActionAssign::execute(ZVision *engine) { engine->getScriptManager()->setStateValue(_key, _value); return true; @@ -73,10 +65,6 @@ ActionAttenuate::ActionAttenuate(const Common::String &line) { sscanf(line.c_str(), ":assign(%u, %d)", &_key, &_attenuation); } -ResultAction *ActionAttenuate::clone() const { - return new ActionAttenuate(*this); -} - bool ActionAttenuate::execute(ZVision *engine) { // TODO: Implement return true; @@ -91,10 +79,6 @@ ActionChangeLocation::ActionChangeLocation(const Common::String &line) { sscanf(line.c_str(), ":change_location(%c,%c,%c%c,%u)", &_world, &_room, &_node, &_view, &_x); } -ResultAction *ActionChangeLocation::clone() const { - return new ActionChangeLocation(*this); -} - bool ActionChangeLocation::execute(ZVision *engine) { // TODO: Implement return true; @@ -111,10 +95,6 @@ ActionCrossfade::ActionCrossfade(const Common::String &line) { &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } -ResultAction *ActionCrossfade::clone() const { - return new ActionCrossfade(*this); -} - bool ActionCrossfade::execute(ZVision *engine) { // TODO: Implement return true; @@ -128,10 +108,7 @@ bool ActionCrossfade::execute(ZVision *engine) { ActionPreloadAnimation::ActionPreloadAnimation(const Common::String &line) { // The two %*u are always 0 and dont seem to have a use sscanf(line.c_str(), ":animpreload:%u(%s %*u %*u %u %u)", &_key, &_fileName, &_mask, &_framerate); -} -ResultAction *ActionPreloadAnimation::clone() const { - return new ActionPreloadAnimation(*this); } bool ActionPreloadAnimation::execute(ZVision *engine) { @@ -155,10 +132,6 @@ ActionPlayAnimation::ActionPlayAnimation(const Common::String &line) { _fileName = Common::String(fileName); } -ResultAction *ActionPlayAnimation::clone() const { - return new ActionPlayAnimation(*this); -} - bool ActionPlayAnimation::execute(ZVision *engine) { // TODO: Implement return true; @@ -173,10 +146,6 @@ ActionRandom::ActionRandom(const Common::String &line) { sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); } -ResultAction *ActionRandom::clone() const { - return new ActionRandom(*this); -} - bool ActionRandom::execute(ZVision *engine) { uint randNumber = engine->getRandomSource()->getRandomNumber(_max); engine->getScriptManager()->setStateValue(_key, randNumber); @@ -192,8 +161,6 @@ ActionTimer::ActionTimer(const Common::String &line) { sscanf(line.c_str(), ":timer:%u(%u)", &_key, &_time); } -ResultAction *ActionTimer::clone() const { - return new ActionTimer(*this); } bool ActionTimer::execute(ZVision *engine) { diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index e10a68869a..7ee51ad279 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -35,7 +35,6 @@ class ZVision; class ResultAction { public: virtual ~ResultAction() {} - virtual ResultAction *clone() const = 0; virtual bool execute(ZVision *engine) = 0; }; @@ -74,7 +73,6 @@ public: class ActionAdd : public ResultAction { public: ActionAdd(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -85,7 +83,6 @@ private: class ActionAssign : public ResultAction { public: ActionAssign(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -96,7 +93,6 @@ private: class ActionAttenuate : public ResultAction { public: ActionAttenuate(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -107,7 +103,6 @@ private: class ActionChangeLocation : public ResultAction { public: ActionChangeLocation(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -121,7 +116,6 @@ private: class ActionCrossfade : public ResultAction { public: ActionCrossfade(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -137,7 +131,6 @@ private: class ActionDelayRender : public ResultAction { public: ActionDelayRender(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -148,7 +141,6 @@ private: class ActionPlayAnimation : public ResultAction { public: ActionPlayAnimation(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -168,7 +160,6 @@ private: class ActionPreloadAnimation : public ResultAction { public: ActionPreloadAnimation(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -188,7 +179,6 @@ private: class ActionRandom : public ResultAction { public: ActionRandom(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: @@ -199,7 +189,6 @@ private: class ActionTimer : public ResultAction { public: ActionTimer(const Common::String &line); - ResultAction *clone() const; bool execute(ZVision *engine); private: -- cgit v1.2.3 From 87be3180c73c16af0609f9e734d499233d69784f Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 13:43:46 -0500 Subject: ZVISION: Fix sscanf formatting errors --- engines/zvision/actions.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 438cec7adc..a1ea96707b 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -34,7 +34,7 @@ namespace ZVision { ////////////////////////////////////////////////////////////////////////////// ActionAdd::ActionAdd(const Common::String &line) { - sscanf(line.c_str(), ":add(%u,%u)", &_key, &_value); + sscanf(line.c_str(), "%*[^(](%u,%u)", &_key, &_value); } bool ActionAdd::execute(ZVision *engine) { @@ -48,7 +48,7 @@ bool ActionAdd::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionAssign::ActionAssign(const Common::String &line) { - sscanf(line.c_str(), ":assign(%u, %u)", &_key, &_value); + sscanf(line.c_str(), "%*[^(](%u, %u)", &_key, &_value); } bool ActionAssign::execute(ZVision *engine) { @@ -62,7 +62,7 @@ bool ActionAssign::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionAttenuate::ActionAttenuate(const Common::String &line) { - sscanf(line.c_str(), ":assign(%u, %d)", &_key, &_attenuation); + sscanf(line.c_str(), "%*[^(](%u, %d)", &_key, &_attenuation); } bool ActionAttenuate::execute(ZVision *engine) { @@ -76,7 +76,7 @@ bool ActionAttenuate::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionChangeLocation::ActionChangeLocation(const Common::String &line) { - sscanf(line.c_str(), ":change_location(%c,%c,%c%c,%u)", &_world, &_room, &_node, &_view, &_x); + sscanf(line.c_str(), "%*[^(](%c,%c,%c%c,%u)", &_world, &_room, &_node, &_view, &_x); } bool ActionChangeLocation::execute(ZVision *engine) { @@ -91,7 +91,7 @@ bool ActionChangeLocation::execute(ZVision *engine) { ActionCrossfade::ActionCrossfade(const Common::String &line) { sscanf(line.c_str(), - ":crossfade(%u %u %u %u %u %u %u)", + "%*[^(](%u %u %u %u %u %u %u)", &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } @@ -106,9 +106,12 @@ bool ActionCrossfade::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionPreloadAnimation::ActionPreloadAnimation(const Common::String &line) { + char fileName[25]; + // The two %*u are always 0 and dont seem to have a use - sscanf(line.c_str(), ":animpreload:%u(%s %*u %*u %u %u)", &_key, &_fileName, &_mask, &_framerate); + sscanf(line.c_str(), "%*[^:]:%*[^:]:%u(%25s %*u %*u %u %u)", &_key, fileName, &_mask, &_framerate); + _fileName = Common::String(fileName); } bool ActionPreloadAnimation::execute(ZVision *engine) { @@ -126,7 +129,7 @@ ActionPlayAnimation::ActionPlayAnimation(const Common::String &line) { // The two %*u are always 0 and dont seem to have a use sscanf(line.c_str(), - ":animplay:%u(%s %u %u %u %u %u %u %u %*u %*u %u %u)", + "%*[^:]:%*[^:]:%u(%25s %u %u %u %u %u %u %u %*u %*u %u %u)", &_key, fileName, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); _fileName = Common::String(fileName); @@ -143,7 +146,7 @@ bool ActionPlayAnimation::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionRandom::ActionRandom(const Common::String &line) { - sscanf(line.c_str(), ":random:%u, %u)", &_key, &_max); + sscanf(line.c_str(), "%*[^:]:%*[^:]:%u, %u)", &_key, &_max); } bool ActionRandom::execute(ZVision *engine) { @@ -158,9 +161,9 @@ bool ActionRandom::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionTimer::ActionTimer(const Common::String &line) { - sscanf(line.c_str(), ":timer:%u(%u)", &_key, &_time); } + sscanf(line.c_str(), "%*[^:]:%*[^:]:%u(%u)", &_key, &_time); } bool ActionTimer::execute(ZVision *engine) { -- cgit v1.2.3 From 8d5e92b935966fdae84182dd7e7845280fb38ad4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 13:44:29 -0500 Subject: ZVISION: Add console cmd for changing location --- engines/zvision/console.cpp | 13 +++++++++++++ engines/zvision/console.h | 1 + 2 files changed, 14 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 3dad7af376..aaf43c598f 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -29,6 +29,7 @@ #include "zvision/console.h" #include "zvision/zvision.h" +#include "zvision/script_manager.h" #include "zvision/render_manager.h" #include "zvision/zork_avi_decoder.h" #include "zvision/zork_raw.h" @@ -45,6 +46,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("generaterendertable", WRAP_METHOD(Console, cmdGenerateRenderTable)); DCmd_Register("setpanoramafov", WRAP_METHOD(Console, cmdSetPanoramaFoV)); DCmd_Register("setpanoramascale", WRAP_METHOD(Console, cmdSetPanoramaScale)); + DCmd_Register("changelocation", WRAP_METHOD(Console, cmdChangeLocation)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -150,4 +152,15 @@ bool Console::cmdSetPanoramaScale(int argc, const char **argv) { return true; } +bool Console::cmdChangeLocation(int argc, const char **argv) { + if (argc != 6) { + DebugPrintf("Use changelocation to change your location"); + return true; + } + + _engine->getScriptManager()->changeLocation(*(argv[1]), *(argv[2]), *(argv[3]), *(argv[4]), atoi(argv[5])); + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 7b1beeb304..d7d2ce904b 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -45,6 +45,7 @@ private: bool cmdGenerateRenderTable(int argc, const char **argv); bool cmdSetPanoramaFoV(int argc, const char **argv); bool cmdSetPanoramaScale(int argc, const char **argv); + bool cmdChangeLocation(int argc, const char **argv); }; } // End of namespace ZVision -- cgit v1.2.3 From 5ef19407b4b16943c33265df4dc388738e710522 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 13:48:42 -0500 Subject: ZVISION: Fix typo in panarama and tilt control parsing --- engines/zvision/control.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index af384cbf2f..986a7ae093 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -51,7 +51,7 @@ void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream & renderTable->setPanoramaFoV(fov); } else if (line.matchString("linscale*", true)) { float scale; - sscanf(line.c_str(), "angle(%f)", &scale); + sscanf(line.c_str(), "linscale(%f)", &scale); renderTable->setPanoramaScale(scale); } else if (line.matchString("reversepana*", true)) { uint reverse; @@ -83,7 +83,7 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre renderTable->setTiltFoV(fov); } else if (line.matchString("linscale*", true)) { float scale; - sscanf(line.c_str(), "angle(%f)", &scale); + sscanf(line.c_str(), "linscale(%f)", &scale); renderTable->setTiltScale(scale); } else if (line.matchString("reversepana*", true)) { uint reverse; -- cgit v1.2.3 From ebe83ed3909de75f401278afbf85a02c9a9ccf1a Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 13:49:21 -0500 Subject: ZVISION: Make panorama and tilt control generate the RenderTable after setting all the settings --- engines/zvision/control.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index 986a7ae093..fdb88c68e1 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -66,6 +66,8 @@ void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream & line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } + + renderTable->generateRenderTable(); } void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream) { @@ -96,6 +98,8 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } + + renderTable->generateRenderTable(); } } // End of namespace ZVision -- cgit v1.2.3 From 47f10fe78426159f76abd585f4b40f3025e7473f Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 13:51:11 -0500 Subject: ZVISION: Overload renderImageToScreen to handle fileNames and ReadStreams --- engines/zvision/render_manager.cpp | 22 +++++++++++++--------- engines/zvision/render_manager.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 7edbf52039..4fd1a83088 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -63,14 +63,14 @@ void RenderManager::updateScreen(bool isConsoleActive) { void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle) { // Panoramas are transposed - // The actual data is transposed in the RenderTable lookup + // The actual data is transposed in mutateImage if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { uint32 temp = imageHeight; imageHeight = imageWidth; imageWidth = temp; } - // Check if we truly want a subRect of the image + // If subRect is empty, use the entire image if (subRectangle.isEmpty()) subRectangle = Common::Rect(imageWidth, imageHeight); @@ -107,19 +107,23 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d return; } + renderImageToScreen(file, destinationX, destinationY, subRectangle); +} + +void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle) { // Read the magic number // Some files are true TGA, while others are TGZ uint32 fileType; - fileType = file.readUint32BE(); + fileType = stream.readUint32BE(); // Check for TGZ files if (fileType == MKTAG('T', 'G', 'Z', '\0')) { // TGZ files have a header and then Bitmap data that is compressed with LZSS - uint32 decompressedSize = file.readSint32LE(); - uint32 imageWidth = file.readSint32LE(); - uint32 imageHeight = file.readSint32LE(); + uint32 decompressedSize = stream.readSint32LE(); + uint32 imageWidth = stream.readSint32LE(); + uint32 imageHeight = stream.readSint32LE(); - LzssReadStream stream(&file); + LzssReadStream stream(&stream); byte *buffer = new byte[decompressedSize]; stream.read(buffer, decompressedSize); @@ -129,11 +133,11 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d delete[] buffer; } else { // Reset the cursor - file.seek(0); + stream.seek(0); // Decode Graphics::TGADecoder tga; - if (!tga.loadStream(file)) { + if (!tga.loadStream(stream)) { warning("Error while reading TGA image"); return; } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 8b4d7e840b..f9d1375ecf 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -34,6 +34,7 @@ class OSystem; namespace Common { class String; +class SeekableReadStream; } namespace Video { @@ -89,6 +90,17 @@ public: */ void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0)); + /** + * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. + * The image will be clipped to fit inside the window. + * + * @param stream Stream to read the image data from + * @param destinationX X position where the image should be put + * @param destinationY Y position where the image should be put + * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. + */ + void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0)); + RenderTable *getRenderTable(); bool needsScreenUpdate() { return _needsScreenUpdate; }; -- cgit v1.2.3 From 9e996c4fec6477395d98ddc670df8732db3d7f28 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 14:56:52 -0500 Subject: ZVISION: Convert _activeNodes and _activeControls to Lists of SharedPtr --- engines/zvision/scr_file_handling.cpp | 16 ++++++++-------- engines/zvision/script_manager.cpp | 13 ++++--------- engines/zvision/script_manager.h | 8 ++++---- 3 files changed, 16 insertions(+), 21 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 860e77147d..8c8c6c488a 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -56,9 +56,10 @@ void ScriptManager::parseScrFile(Common::String fileName) { parsePuzzle(puzzle, file); _activePuzzles.push_back(puzzle); } else if (line.matchString("control:*", true)) { - Control *control = parseControl(line, file); + Common::SharedPtr control; + // Some controls don't require nodes. They just initialize the scene - if (control != 0) { + if (parseControl(line, file, control)) { _activeControls.push_back(control); } } @@ -289,8 +290,7 @@ uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { return flags; } -Control *ScriptManager::parseControl(Common::String &line, Common::SeekableReadStream &stream) { - Control *control = 0; +bool ScriptManager::parseControl(Common::String &line, Common::SeekableReadStream &stream, Common::SharedPtr &control) { uint32 key; char controlTypeBuffer[20]; @@ -302,17 +302,17 @@ Control *ScriptManager::parseControl(Common::String &line, Common::SeekableReadS } else if (controlType.equalsIgnoreCase("flat")) { Control::parseFlatControl(_engine); - return 0; + return false; } else if (controlType.equalsIgnoreCase("pana")) { Control::parsePanoramaControl(_engine, stream); - return 0; + return false; } else if (controlType.equalsIgnoreCase("tilt")) { Control::parseTiltControl(_engine, stream); - return 0; + return false; } - return control; + return true; } } // End of namespace ZVision diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index cd4e174a7c..55cd570467 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -62,12 +62,10 @@ void ScriptManager::createReferenceTable() { void ScriptManager::updateNodes(uint deltaTimeMillis) { // If process() returns true, it means the node can be deleted - for (Common::List::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) { + for (Common::List >::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) { if ((*iter)->process(_engine, deltaTimeMillis)) { - // Remove the node from _activeNodes, then delete it - ActionNode *node = *iter; + // Remove the node from _activeNodes, the SharedPtr destructor will delete the actual ActionNode iter = _activeNodes.erase(iter); - delete node; } else { iter++; } @@ -132,7 +130,7 @@ void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) { _globalState[key] += valueToAdd; } -void ScriptManager::addActionNode(ActionNode *node) { +void ScriptManager::addActionNode(const Common::SharedPtr &node) { _activeNodes.push_back(node); } @@ -141,10 +139,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, _referenceTable.clear(); _puzzlesToCheck.clear(); _activePuzzles.clear(); - // _activeControls is a list of pointers to the heap, so we have to delete the Controls before we call clear() - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { - delete (*iter); - } + // We can clear without deleting from the heap because we use SharedPtr _activeControls.clear(); // Parse into puzzles and controls diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index c43030d62b..88340313cc 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -52,7 +52,7 @@ private: */ Common::HashMap _globalState; /** Holds the currently active ActionNodes */ - Common::List _activeNodes; + Common::List > _activeNodes; /** References _globalState keys to Puzzles */ Common::HashMap > _referenceTable; /** Holds the Puzzles that should be checked this frame */ @@ -60,7 +60,7 @@ private: /** Holds the currently active puzzles */ Common::List _activePuzzles; /** Holds the currently active controls */ - Common::List _activeControls; + Common::List > _activeControls; public: @@ -72,7 +72,7 @@ public: void setStateValue(uint32 key, uint value); void addToStateValue(uint32 key, uint valueToAdd); - void addActionNode(ActionNode *node); + void addActionNode(const Common::SharedPtr &node); void changeLocation(char world, char room, char node, char view, uint32 x); @@ -129,7 +129,7 @@ private: * @param line The line initially read * @param stream Scr file stream */ - Control *parseControl(Common::String &line, Common::SeekableReadStream &stream); + bool parseControl(Common::String &line, Common::SeekableReadStream &stream, Common::SharedPtr &control); }; -- cgit v1.2.3 From 11118262e4d884a838ac8ce0f8d674948aac1d33 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 14:59:00 -0500 Subject: ZVISION: Add logic to check _referenceTable Puzzles every time a globalState is changed --- engines/zvision/script_manager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 55cd570467..2e57c18a3e 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -121,9 +121,14 @@ uint ScriptManager::getStateValue(uint32 key) { return _globalState[key]; } -// TODO: Add logic to check _referenceTable and add to _puzzlesToCheck if necessary void ScriptManager::setStateValue(uint32 key, uint value) { _globalState[key] = value; + + if (_referenceTable.contains(key)) { + for (Common::Array::iterator iter = _referenceTable[key].begin(); iter != _referenceTable[key].end(); iter++) { + _puzzlesToCheck.push((*iter)); + } + } } void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) { -- cgit v1.2.3 From 8bbc260b8642d08c049acb81546e82bc88100ee2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 15:00:15 -0500 Subject: ZVISION: Create RenderManager method to set the current background image --- engines/zvision/render_manager.cpp | 16 ++++++++++++++++ engines/zvision/render_manager.h | 10 ++++++++++ 2 files changed, 26 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 4fd1a83088..b6163c83c1 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -24,6 +24,7 @@ #include "common/file.h" #include "common/system.h" +#include "common/stream.h" #include "engines/util.h" #include "graphics/decoders/tga.h" @@ -39,6 +40,7 @@ RenderManager::RenderManager(OSystem *system, const int width, const int height) _height(height), _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 _currentVideo(0), + _currentBackground(0), _scaledVideoFrameBuffer(0), _needsScreenUpdate(false), _renderTable(width, height) { @@ -155,4 +157,18 @@ RenderTable *RenderManager::getRenderTable() { return &_renderTable; } +void RenderManager::setBackgroundImage(const Common::String &fileName) { + Common::File *file = new Common::File; + + if (!file->open(fileName)) { + warning("Could not open file %s", fileName.c_str()); + return; + } + + _currentBackground = file; + + // TODO: Check if all the panoramas are the same height. AKA: can we hardcode the vertical centering to 80px? + renderImageToScreen(*_currentBackground, 0, 80); +} + } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index f9d1375ecf..fc2598ecf9 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -54,6 +54,8 @@ private: const Graphics::PixelFormat _pixelFormat; RenderTable _renderTable; + Common::SeekableReadStream *_currentBackground; + Video::VideoDecoder *_currentVideo; byte *_scaledVideoFrameBuffer; @@ -101,6 +103,14 @@ public: */ void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0)); + /** + * Sets the current background image to be used by the RenderManager and immediately + * blits it to the screen. (It won't show up until the end of the frame) + * + * @param fileName The name of the image file + */ + void setBackgroundImage(const Common::String &fileName); + RenderTable *getRenderTable(); bool needsScreenUpdate() { return _needsScreenUpdate; }; -- cgit v1.2.3 From 32b3363acddcc25fb2380fbb66df829832d5200d Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 15:00:58 -0500 Subject: ZVISION: Add ActionSetScreen --- engines/zvision/actions.cpp | 24 +++++++++++++++++++++--- engines/zvision/actions.h | 9 +++++++++ engines/zvision/scr_file_handling.cpp | 3 +-- 3 files changed, 31 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index a1ea96707b..9a8dee0e32 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -25,6 +25,7 @@ #include "zvision/actions.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" +#include "zvision/render_manager.h" #include "zvision/action_node.h" namespace ZVision { @@ -157,17 +158,34 @@ bool ActionRandom::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// -// ActionTimer +// ActionSetScreen ////////////////////////////////////////////////////////////////////////////// -ActionTimer::ActionTimer(const Common::String &line) { +ActionSetScreen::ActionSetScreen(const Common::String &line) { + char fileName[25]; + sscanf(line.c_str(), "%*[^(](%25[^)])", fileName); + + _fileName = Common::String(fileName); } +bool ActionSetScreen::execute(ZVision *engine) { + RenderManager *renderManager = engine->getRenderManager(); + renderManager->setBackgroundImage(_fileName); + + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionTimer +////////////////////////////////////////////////////////////////////////////// + +ActionTimer::ActionTimer(const Common::String &line) { sscanf(line.c_str(), "%*[^:]:%*[^:]:%u(%u)", &_key, &_time); } bool ActionTimer::execute(ZVision *engine) { - engine->getScriptManager()->addActionNode(new NodeTimer(_key, _time)); + engine->getScriptManager()->addActionNode(Common::SharedPtr(new NodeTimer(_key, _time))); return true; } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 7ee51ad279..3922f92b44 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -186,6 +186,15 @@ private: uint _max; }; +class ActionSetScreen : public ResultAction { +public: + ActionSetScreen(const Common::String &line); + bool execute(ZVision *engine); + +private: + Common::String _fileName; +}; + class ActionTimer : public ResultAction { public: ActionTimer(const Common::String &line); diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 8c8c6c488a..1dc8ee5d4e 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -233,8 +233,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:set_screen*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionSetScreen(line))); } else if (line.matchString("*:set_venus*", true)) { -- cgit v1.2.3 From d89a55d3deb703c23c6bb111c256a11ba17c5faf Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 15:01:25 -0500 Subject: ZVISION: Create class definitions for mutliple ResultAction children --- engines/zvision/actions.h | 66 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 3922f92b44..46b31e9bed 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -128,6 +128,14 @@ private: uint _timeInMillis; }; +class ActionDebug : public ResultAction { +public: + ActionDebug(const Common::String &line); + bool execute(ZVision *engine); + +private: +}; + class ActionDelayRender : public ResultAction { public: ActionDelayRender(const Common::String &line); @@ -138,6 +146,54 @@ private: uint32 framesToDelay; }; +class ActionDisableControl : public ResultAction { +public: + ActionDisableControl(const Common::String &line); + bool execute(ZVision *engine); + +private: +}; + +class ActionDisableVenus : public ResultAction { +public: + ActionDisableVenus(const Common::String &line); + bool execute(ZVision *engine); + +private: +}; + +class ActionDisplayMessage : public ResultAction { +public: + ActionDisplayMessage(const Common::String &line); + bool execute(ZVision *engine); + +private: +}; + +class ActionDissolve : public ResultAction { +public: + ActionDissolve(const Common::String &line); + bool execute(ZVision *engine); + +private: +}; + +class ActionDistort : public ResultAction { +public: + ActionDistort(const Common::String &line); + bool execute(ZVision *engine); + +private: +}; + +class ActionEnableControl : public ResultAction { +public: + ActionEnableControl(const Common::String &line); + bool execute(ZVision *engine); + +private: +}; + class ActionPlayAnimation : public ResultAction { public: ActionPlayAnimation(const Common::String &line); @@ -170,11 +226,11 @@ private: }; // TODO: See if this exists in ZGI. It doesn't in ZNem -//class ActionUnloadAnimation : public ResultAction { -//public: -// ActionUnloadAnimation(const Common::String &line); -// bool execute(ZVision *engine); -//}; +class ActionUnloadAnimation : public ResultAction { +public: + ActionUnloadAnimation(const Common::String &line); + bool execute(ZVision *engine); +}; class ActionRandom : public ResultAction { public: -- cgit v1.2.3 From 3fd5a8ab5a626998a358282e3af7668f3bdd9403 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 17:24:44 -0500 Subject: ZVISION: Offset the RenderTable index by the normalized coords, not the subRect coords --- engines/zvision/render_table.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 531114cdbe..55c11ec4ba 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -90,7 +90,7 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 i for (int x = subRectangle.left; x < subRectangle.right; x++) { uint normalizedX = x - subRectangle.left; - uint32 index = (y + destRectangle.top) * _numColumns + (x + destRectangle.left); + uint32 index = (normalizedY + destRectangle.top) * _numColumns + (normalizedX + destRectangle.left); // RenderTable only stores offsets from the original coordinates uint32 sourceYIndex = y + _internalBuffer[index].y; -- cgit v1.2.3 From c828074df9384b1e6eb3176d346ffc1b18dd2b11 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 3 Aug 2013 17:25:05 -0500 Subject: ZVISION: Remove extraneous comments --- engines/zvision/render_table.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 55c11ec4ba..b6598c12b2 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -150,8 +150,8 @@ void RenderTable::generatePanoramaLookupTable() { uint32 index = y * _numColumns + x; // Only store the x,y offsets instead of the absolute positions - _internalBuffer[index].x = newX - x; //pixel index - _internalBuffer[index].y = newY - y; //pixel index + _internalBuffer[index].x = newX - x; + _internalBuffer[index].y = newY - y; } } } -- cgit v1.2.3 From 0a8f57721bdc2f907e2fb42083341f81fabd9dce Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 4 Aug 2013 22:02:08 -0500 Subject: ZVISION: Create Clock class to handle deltaTime while pausing and unpausing the game --- engines/zvision/clock.cpp | 68 +++++++++++++++++++++++++++++++++++++++++ engines/zvision/clock.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 engines/zvision/clock.cpp create mode 100644 engines/zvision/clock.h (limited to 'engines/zvision') diff --git a/engines/zvision/clock.cpp b/engines/zvision/clock.cpp new file mode 100644 index 0000000000..2324d395c3 --- /dev/null +++ b/engines/zvision/clock.cpp @@ -0,0 +1,68 @@ +/* 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/scummsys.h" + +#include "common/system.h" + +#include "zvision/clock.h" + +namespace ZVision { + +Clock::Clock(OSystem *system) + : _system(system), + _lastTime(0), + _deltaTime(0), + _pausedTime(0), + _paused(false) { +} + +void Clock::update() { + uint32 currentTime = _system->getMillis(); + _deltaTime = currentTime - _lastTime - _pausedTime; + if (_deltaTime < 0) { + _deltaTime = 0; + } + + if (_paused) { + _pausedTime += _deltaTime; + } else if (_pausedTime > 0) { + _pausedTime = 0; + } + + _lastTime = currentTime; +} + +void Clock::start() { + if (_paused) { + _paused = false; + } +} + +void Clock::stop() { + if (!_paused) { + _paused = true; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/clock.h b/engines/zvision/clock.h new file mode 100644 index 0000000000..d17db6c255 --- /dev/null +++ b/engines/zvision/clock.h @@ -0,0 +1,78 @@ +/* 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 ZVISION_CLOCK_H +#define ZVISION_CLOCK_H + +#include "common/types.h" + +class OSystem; + +namespace ZVision { + +/* Class for handling frame to frame deltaTime while keeping track of time pauses/un-pauses */ +class Clock { +public: + Clock(OSystem *system); + +private: + OSystem *_system; + uint32 _lastTime; + uint32 _deltaTime; + uint32 _pausedTime; + bool _paused; + +public: + /** + * Updates _deltaTime with the difference between the current time and + * when the last update() was called. + */ + void update(); + /** + * Get the delta time since the last frame. (The time between update() calls) + * + * @return Delta time since the last frame (in milliseconds) + */ + uint32 getDeltaTime() const { return _deltaTime; } + /** + * Get the time from the program starting to the last update() call + * + * @return Time from program start to last update() call (in milliseconds) + */ + uint32 getLastMeasuredTime() { return _lastTime; } + + /** + * Pause the clock. Any future delta times will take this pause into account. + * Has no effect if the clock is already paused. + */ + void start(); + /** + * Un-pause the clock. + * Has no effect if the clock is already un-paused. + */ + void stop(); +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From a86a0832e08c777ef23f2ce97004963b301dd598 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 4 Aug 2013 23:02:43 -0500 Subject: ZVISION: Create console method for dumping a file by name --- engines/zvision/console.cpp | 12 ++++++++++++ engines/zvision/console.h | 1 + 2 files changed, 13 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index aaf43c598f..9c7d79a8f1 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -47,6 +47,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("setpanoramafov", WRAP_METHOD(Console, cmdSetPanoramaFoV)); DCmd_Register("setpanoramascale", WRAP_METHOD(Console, cmdSetPanoramaScale)); DCmd_Register("changelocation", WRAP_METHOD(Console, cmdChangeLocation)); + DCmd_Register("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -163,4 +164,15 @@ bool Console::cmdChangeLocation(int argc, const char **argv) { return true; } +bool Console::cmdDumpFile(int argc, const char **argv) { + if (argc != 2) { + DebugPrintf("Use dumpfile to dump a file"); + return true; + } + + writeFileContentsToFile(argv[1], argv[1]); + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index d7d2ce904b..be3ebf10dc 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -46,6 +46,7 @@ private: bool cmdSetPanoramaFoV(int argc, const char **argv); bool cmdSetPanoramaScale(int argc, const char **argv); bool cmdChangeLocation(int argc, const char **argv); + bool cmdDumpFile(int argc, const char **argv); }; } // End of namespace ZVision -- cgit v1.2.3 From 7b9858d6b45ad4c02729445975518a48292c3658 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 4 Aug 2013 23:10:27 -0500 Subject: ZVISION: Make video code blocking. The script system requires that all ResultAction::execute() block until they finish. The video system *was* 'asyncronous' in that you would just start a video and then run() would finish processing it. This code forces the video to complely finish before playVideo returns. The Clock object is used to keep track of deltaTime while the video is playing. --- engines/zvision/console.cpp | 6 +-- engines/zvision/events.cpp | 5 --- engines/zvision/render_manager.cpp | 13 ------ engines/zvision/render_manager.h | 24 ----------- engines/zvision/video.cpp | 87 +++++++++++++++++++++++--------------- engines/zvision/zvision.cpp | 31 ++++++++------ engines/zvision/zvision.h | 22 +++++++++- 7 files changed, 93 insertions(+), 95 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 9c7d79a8f1..6634e0bef4 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -69,9 +69,9 @@ bool Console::cmdLoadVideo(int argc, const char **argv) { return true; } - Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); - if (videoDecoder && videoDecoder->loadFile(argv[1])) { - _engine->getRenderManager()->startVideo(videoDecoder); + ZorkAVIDecoder videoDecoder; + if (videoDecoder.loadFile(argv[1])) { + _engine->playVideo(videoDecoder); } return true; diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index e392d3c78a..508d2610aa 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -61,11 +61,6 @@ void ZVision::processEvents() { if (_event.kbd.hasFlags(Common::KBD_CTRL)) quitGame(); break; - case Common::KEYCODE_ESCAPE: - if (_renderManager->isVideoPlaying()) - _renderManager->cancelVideo(); - - break; default: break; } diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b6163c83c1..604c310689 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -38,25 +38,12 @@ RenderManager::RenderManager(OSystem *system, const int width, const int height) : _system(system), _width(width), _height(height), - _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 - _currentVideo(0), _currentBackground(0), - _scaledVideoFrameBuffer(0), _needsScreenUpdate(false), _renderTable(width, height) { } -/** - * Initialize graphics - */ -void RenderManager::initialize() { - initGraphics(_width, _height, true, &_pixelFormat); -} - void RenderManager::updateScreen(bool isConsoleActive) { - if (_currentVideo != 0) - continueVideo(); - if (_needsScreenUpdate || isConsoleActive) { _system->updateScreen(); _needsScreenUpdate = false; diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index fc2598ecf9..9554e888d9 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -26,8 +26,6 @@ #include "common/types.h" #include "common/rect.h" -#include "graphics/pixelformat.h" - #include "zvision/render_table.h" class OSystem; @@ -51,7 +49,6 @@ private: OSystem *_system; const int _width; const int _height; - const Graphics::PixelFormat _pixelFormat; RenderTable _renderTable; Common::SeekableReadStream *_currentBackground; @@ -65,22 +62,6 @@ public: void initialize(); void updateScreen(bool isConsoleActive); - /** - * Start a video playing. It will also load the first frame of the video. - * - * @param videoDecoder The video to play - */ - void startVideo(Video::VideoDecoder *videoDecoder); - /** - * @return Is a video currently being played - */ - bool isVideoPlaying() { return _currentVideo == 0; } - /** - * Cancels a video prematurely. Any sound remaining in the queue will continue to play. - * The last frame of the video will remain on the screen until something else overwrites it - */ - void cancelVideo(); - /** * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. * The image will be clipped to fit inside the window. @@ -116,11 +97,6 @@ public: bool needsScreenUpdate() { return _needsScreenUpdate; }; private: - /** - * Checks the time since the last video frame, and blits the next frame to the screen - */ - void continueVideo(); - void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle); }; diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 1ccf736970..8550a6cfca 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -27,7 +27,9 @@ #include "engines/util.h" #include "graphics/surface.h" +#include "zvision/clock.h" #include "zvision/render_manager.h" +#include "zvision/zvision.h" namespace ZVision { @@ -71,62 +73,77 @@ void scale2x(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, byte } } -void RenderManager::startVideo(Video::VideoDecoder *videoDecoder) { - if (!videoDecoder) - return; - - _currentVideo = videoDecoder; - +void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { + // Videos use a different pixel format Common::List formats; - formats.push_back(videoDecoder->getPixelFormat()); + formats.push_back(videoDecoder.getPixelFormat()); initGraphics(_width, _height, true, formats); - - _scaledVideoFrameBuffer = new byte[_currentVideo->getWidth() * _currentVideo->getHeight() * _currentVideo->getPixelFormat().bytesPerPixel * 4]; - - _currentVideo->start(); - // Load the first frame - continueVideo(); -} - -void RenderManager::continueVideo() { - byte bytesPerPixel = _currentVideo->getPixelFormat().bytesPerPixel; - uint16 origWidth = _currentVideo->getWidth(); - uint16 origHeight = _currentVideo->getHeight(); + byte bytesPerPixel = videoDecoder.getPixelFormat().bytesPerPixel; + uint16 origWidth = videoDecoder.getWidth(); + uint16 origHeight = videoDecoder.getHeight(); uint16 pitch = origWidth * bytesPerPixel; + + // Most videos are very small. Therefore we do a simple 2x scale bool shouldBeScaled = (origWidth * 2 <= 640 && origHeight * 2 <= 480); uint16 finalWidth = shouldBeScaled ? origWidth * 2 : origWidth; uint16 finalHeight = shouldBeScaled ? origHeight * 2 : origHeight; - uint16 x = (_system->getWidth() - finalWidth) / 2; - uint16 y = (_system->getHeight() - finalHeight) / 2; + byte *scaledVideoFrameBuffer = new byte[origHeight * pitch * 4]; + + uint16 x = (_width - finalWidth) / 2; + uint16 y = (_height - finalHeight) / 2; + + _clock->stop(); + videoDecoder.start(); + + // Only continue while the video is still playing + while (videoDecoder.isPlaying()) { + _clock->update(); + uint32 currentTime = _clock->getLastMeasuredTime(); + + // Check for engine quit and video stop key presses + while (_eventMan->pollEvent(_event)) { + switch (_event.type) { + case Common::EVENT_KEYDOWN: + switch (_event.kbd.keycode) { + case Common::KEYCODE_q: + if (_event.kbd.hasFlags(Common::KBD_CTRL)) + quitGame(); + break; + case Common::KEYCODE_SPACE: + videoDecoder.stop(); + break; + } + } + } - if (!_currentVideo->endOfVideo()) { - if (_currentVideo->needsUpdate()) { - const Graphics::Surface *frame = _currentVideo->decodeNextFrame(); + if (videoDecoder.needsUpdate()) { + const Graphics::Surface *frame = videoDecoder.decodeNextFrame(); if (frame) { if (shouldBeScaled) { - scale2x((byte *)frame->pixels, _scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel); - _system->copyRectToScreen(_scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); + scale2x((byte *)frame->pixels, scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel); + _system->copyRectToScreen(scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); } else { _system->copyRectToScreen((byte *)frame->pixels, pitch, x, y, finalWidth, finalHeight); } - _needsScreenUpdate = true; + _system->updateScreen(); } } - } else { - cancelVideo(); + + // Calculate the frame delay based off a desired frame time + int delay = _desiredFrameTime - (currentTime - _system->getMillis()); + // Ensure non-negative + delay = delay < 0 ? 0 : delay; + _system->delayMillis(delay); } -} -void RenderManager::cancelVideo() { + _clock->stop(); + + // Reset the pixel format to the original state initGraphics(_width, _height, true, &_pixelFormat); - delete _currentVideo; - _currentVideo = 0; - delete[] _scaledVideoFrameBuffer; - _scaledVideoFrameBuffer = 0; } } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index ca43549f50..0015c41499 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -31,11 +31,14 @@ #include "common/file.h" #include "engines/util.h" + +#include "audio/mixer.h" #include "zvision/zvision.h" #include "zvision/console.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" +#include "zvision/clock.h" #include "zvision/zfs_archive.h" #include "zvision/detection.h" @@ -47,7 +50,9 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), _width(640), - _height(480) { + _height(480), + _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), /*RGB 555*/ + _desiredFrameTime(33) /* ~30 fps */ { // Put your engine in a sane state, but do nothing big yet; // in particular, do not load data from files; rather, if you // need to do such things, do them from run(). @@ -75,14 +80,19 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _scriptManager = new ScriptManager(this); _renderManager = new RenderManager(_system, _width, _height); + // Create clock + _clock = new Clock(_system); + debug("ZVision::ZVision"); } - + ZVision::~ZVision() { debug("ZVision::~ZVision"); // Dispose of resources delete _console; + delete _clock; + delete _renderManager; delete _scriptManager; delete _rnd; @@ -103,7 +113,7 @@ void ZVision::initialize() { SearchMan.add(name, archive); } - _renderManager->initialize(); + initGraphics(_width, _height, true, &_pixelFormat); _scriptManager->initialize(); @@ -115,25 +125,20 @@ Common::Error ZVision::run() { initialize(); // Main loop - uint32 currentTime = _system->getMillis(); - uint32 lastTime = currentTime; - const uint desiredFrameTime = 33; // ~30 fps - while (!shouldQuit()) { - processEvents(); + _clock->update(); + uint32 currentTime = _clock->getLastMeasuredTime(); - currentTime = _system->getMillis(); - uint32 deltaTime = currentTime - lastTime; - lastTime = currentTime; + processEvents(); - _scriptManager->updateNodes(deltaTime); + _scriptManager->updateNodes(_clock->getDeltaTime()); _scriptManager->checkPuzzleCriteria(); // Render a frame _renderManager->updateScreen(_console->isActive()); // Calculate the frame delay based off a desired frame time - int delay = desiredFrameTime - (currentTime - _system->getMillis()); + int delay = _desiredFrameTime - (currentTime - _system->getMillis()); // Ensure non-negative delay = delay < 0 ? 0 : delay; _system->delayMillis(delay); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 9588623f56..459096a03b 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -29,16 +29,24 @@ #include "engines/engine.h" +#include "graphics/pixelformat.h" + #include "zvision/detection.h" #include "gui/debugger.h" - + + +namespace Video { +class VideoDecoder; +} + namespace ZVision { struct ZVisionGameDescription; class Console; class ScriptManager; class RenderManager; +class Clock; // our engine debug channels enum { @@ -58,25 +66,35 @@ private: const ZVisionGameDescription *_gameDescription; const int _width; const int _height; + const Graphics::PixelFormat _pixelFormat; + + const uint _desiredFrameTime; // We need random numbers Common::RandomSource *_rnd; + // Managers ScriptManager *_scriptManager; RenderManager *_renderManager; + // Clock + Clock *_clock; + // To prevent allocation every time we process events Common::Event _event; public: uint32 getFeatures() const; Common::Language getLanguage() const; - virtual Common::Error run(); + Common::Error run(); + ScriptManager *getScriptManager() const; RenderManager *getRenderManager() const; Common::RandomSource *getRandomSource() const; ZVisionGameId getGameId() const; + void playVideo(Video::VideoDecoder &videoDecoder); + private: void initialize(); -- cgit v1.2.3 From c4dc3989a70939fd98f1d55dffb548e68f80adfb Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 4 Aug 2013 23:53:40 -0500 Subject: ZVISION: Make the return from makeRawZorkStream more specific --- engines/zvision/zork_raw.cpp | 2 +- engines/zvision/zork_raw.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 742ba188ac..92f659203b 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -155,7 +155,7 @@ Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, DisposeAfterUse::YES); } -Audio::AudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) { +Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) { Common::File *file = new Common::File(); assert(file->open(filePath)); diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 4e40a5716a..f19ffc1661 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -126,7 +126,7 @@ Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stre bool stereo, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); -Audio::AudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine); +Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine); } // End of namespace ZVision -- cgit v1.2.3 From ec7036469c57eecb7afb226cc3dd176fcc74c0cb Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 4 Aug 2013 23:54:53 -0500 Subject: ZVISION: Make _clock a member variable instead of a pointer to the heap --- engines/zvision/video.cpp | 8 ++++---- engines/zvision/zvision.cpp | 13 +++++-------- engines/zvision/zvision.h | 4 ++-- 3 files changed, 11 insertions(+), 14 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 8550a6cfca..51cccee639 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -94,13 +94,13 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { uint16 x = (_width - finalWidth) / 2; uint16 y = (_height - finalHeight) / 2; - _clock->stop(); + _clock.stop(); videoDecoder.start(); // Only continue while the video is still playing while (videoDecoder.isPlaying()) { - _clock->update(); - uint32 currentTime = _clock->getLastMeasuredTime(); + _clock.update(); + uint32 currentTime = _clock.getLastMeasuredTime(); // Check for engine quit and video stop key presses while (_eventMan->pollEvent(_event)) { @@ -140,7 +140,7 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { _system->delayMillis(delay); } - _clock->stop(); + _clock.stop(); // Reset the pixel format to the original state initGraphics(_width, _height, true, &_pixelFormat); diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 0015c41499..f406b5e852 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -52,7 +52,8 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _width(640), _height(480), _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), /*RGB 555*/ - _desiredFrameTime(33) /* ~30 fps */ { + _desiredFrameTime(33), /* ~30 fps */ + _clock(_system) { // Put your engine in a sane state, but do nothing big yet; // in particular, do not load data from files; rather, if you // need to do such things, do them from run(). @@ -80,9 +81,6 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _scriptManager = new ScriptManager(this); _renderManager = new RenderManager(_system, _width, _height); - // Create clock - _clock = new Clock(_system); - debug("ZVision::ZVision"); } @@ -91,7 +89,6 @@ ZVision::~ZVision() { // Dispose of resources delete _console; - delete _clock; delete _renderManager; delete _scriptManager; delete _rnd; @@ -126,12 +123,12 @@ Common::Error ZVision::run() { // Main loop while (!shouldQuit()) { - _clock->update(); - uint32 currentTime = _clock->getLastMeasuredTime(); + _clock.update(); + uint32 currentTime = _clock.getLastMeasuredTime(); processEvents(); - _scriptManager->updateNodes(_clock->getDeltaTime()); + _scriptManager->updateNodes(_clock.getDeltaTime()); _scriptManager->checkPuzzleCriteria(); // Render a frame diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 459096a03b..3eff16e5f1 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -32,6 +32,7 @@ #include "graphics/pixelformat.h" #include "zvision/detection.h" +#include "zvision/clock.h" #include "gui/debugger.h" @@ -46,7 +47,6 @@ struct ZVisionGameDescription; class Console; class ScriptManager; class RenderManager; -class Clock; // our engine debug channels enum { @@ -78,7 +78,7 @@ private: RenderManager *_renderManager; // Clock - Clock *_clock; + Clock _clock; // To prevent allocation every time we process events Common::Event _event; -- cgit v1.2.3 From 1d694dcb81604c20a8755f80d509eccb8904017e Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 4 Aug 2013 23:55:36 -0500 Subject: ZVISION: Add support for engine pausing from higher up (GMM, phone call, etc.) --- engines/zvision/zvision.cpp | 10 ++++++++++ engines/zvision/zvision.h | 1 + 2 files changed, 11 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index f406b5e852..aaf843fae2 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -144,6 +144,16 @@ Common::Error ZVision::run() { return Common::kNoError; } +void ZVision::pauseEngineIntern(bool pause) { + _mixer->pauseAll(pause); + + if (pause) { + _clock.stop(); + } else { + _clock.start(); + } +} + ScriptManager *ZVision::getScriptManager() const { return _scriptManager; } diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 3eff16e5f1..990b6e8b93 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -87,6 +87,7 @@ public: uint32 getFeatures() const; Common::Language getLanguage() const; Common::Error run(); + void pauseEngineIntern(bool pause); ScriptManager *getScriptManager() const; RenderManager *getRenderManager() const; -- cgit v1.2.3 From 4b0015b8e997e9ca95141216f2b24ee33df01055 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 00:00:21 -0500 Subject: ZVISION: Check if a key exists before returning _globalState value. operator[] creates a key value pair if it doesn't exist. So blindly returning a value without checking if the key exists could result in undefined behavior, depening on what the value is initialized to in its constructor --- engines/zvision/script_manager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 2e57c18a3e..7fcade22c1 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -118,7 +118,10 @@ void ScriptManager::checkPuzzleCriteria() { } uint ScriptManager::getStateValue(uint32 key) { - return _globalState[key]; + if (_globalState.contains(key)) + return _globalState[key]; + else + return 0; } void ScriptManager::setStateValue(uint32 key, uint value) { -- cgit v1.2.3 From 20c892092907e66c6c13d1598b973486ba2fc95c Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 00:01:20 -0500 Subject: ZVISION: Pass the scr fileName as a const reference --- engines/zvision/scr_file_handling.cpp | 2 +- engines/zvision/script_manager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 1dc8ee5d4e..cd3cfe4269 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -33,7 +33,7 @@ namespace ZVision { -void ScriptManager::parseScrFile(Common::String fileName) { +void ScriptManager::parseScrFile(const Common::String &fileName) { Common::File file; if (!file.open(fileName)) return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 88340313cc..484069b335 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -84,7 +84,7 @@ private: * * @param fileName Name of the .scr file */ - void parseScrFile(Common::String fileName); + void parseScrFile(const Common::String &fileName); /** * Parses the stream into a Puzzle object -- cgit v1.2.3 From 6515e2d31bbbad55168b8b27142cdc50f366795d Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 00:14:20 -0500 Subject: ZVISION: Add ActionMusic --- engines/zvision/actions.cpp | 59 +++++++++++++++++++++++++++++++++++ engines/zvision/actions.h | 19 ++++++++++- engines/zvision/scr_file_handling.cpp | 3 +- 3 files changed, 78 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 9a8dee0e32..cd84a6b85e 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -22,11 +22,16 @@ #include "common/scummsys.h" +#include "common/file.h" + +#include "audio/decoders/wave.h" + #include "zvision/actions.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" #include "zvision/action_node.h" +#include "zvision/zork_raw.h" namespace ZVision { @@ -102,6 +107,60 @@ bool ActionCrossfade::execute(ZVision *engine) { } +////////////////////////////////////////////////////////////////////////////// +// ActionMusic +////////////////////////////////////////////////////////////////////////////// + +ActionMusic::ActionMusic(const Common::String &line) : _volume(255) { + uint type; + char fileNameBuffer[25]; + uint loop; + uint volume = 255; + + sscanf(line.c_str(), "%*[^:]:%*[^:]:%u(%u %25s %u %u)", &_key, &type, fileNameBuffer, &loop, &volume); + + // type 4 are midi sound effect files + if (type == 4) { + _soundType = Audio::Mixer::kSFXSoundType; + _fileName = Common::String::format("midi/%s/%u.wav", fileNameBuffer, loop); + _loop = false; + } else { + // TODO: See what the other types are so we can specify the correct Mixer::SoundType. In the meantime use kPlainSoundType + _soundType = Audio::Mixer::kPlainSoundType; + _fileName = Common::String(fileNameBuffer); + _loop = loop == 1 ? true : false; + } + + // Volume is optional. If it doesn't appear, assume full volume + if (volume != 255) { + // Volume in the script files is mapped to [0, 100], but the ScummVM mixer uses [0, 255] + _volume = volume * 255 / 100; + } +} + +bool ActionMusic::execute(ZVision *engine) { + Audio::RewindableAudioStream *audioStream; + + if (_fileName.contains(".wav")) { + Common::File file; + if (file.open(_fileName)) { + audioStream = Audio::makeWAVStream(&file, DisposeAfterUse::NO); + } + } else { + audioStream = makeRawZorkStream(_fileName, engine); + } + + if (_loop) { + Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES); + engine->_mixer->playStream(_soundType, 0, loopingAudioStream, -1, _volume); + } else { + engine->_mixer->playStream(_soundType, 0, audioStream, -1, _volume); + } + + return true; +} + + ////////////////////////////////////////////////////////////////////////////// // ActionPreloadAnimation ////////////////////////////////////////////////////////////////////////////// diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 46b31e9bed..76db25adf0 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -25,7 +25,11 @@ #include "common/scummsys.h" -#include "common/str.h" +#include "audio/mixer.h" + +namespace Common { +class String; +} namespace ZVision { @@ -194,6 +198,19 @@ public: private: }; +class ActionMusic : public ResultAction { +public: + ActionMusic(const Common::String &line); + bool execute(ZVision *engine); + +private: + uint32 _key; + Audio::Mixer::SoundType _soundType; + Common::String _fileName; + bool _loop; + byte _volume; +}; + class ActionPlayAnimation : public ResultAction { public: ActionPlayAnimation(const Common::String &line); diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index cd3cfe4269..9759fd89b1 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -200,8 +200,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:music*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionMusic(line))); } else if (line.matchString("*:pan_track*", true)) { -- cgit v1.2.3 From 65b5a2797b29dc4c0ca9a1bd2bd2e92083deb081 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 00:18:01 -0500 Subject: ZVISION: Fix index out of range error --- engines/zvision/utility.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 8974809f97..3348a43fe3 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -71,7 +71,7 @@ void removeDuplicateEntries(Common::Array &container) { Common::sort(container.begin(), container.end()); for (uint i = 0; i + 1 < container.size(); i++) { - while (container[i] == container[i + 1]) { + while (i + 1 < container.size() && container[i] == container[i + 1]) { container.remove_at(i + 1); } } -- cgit v1.2.3 From cefb0253ae93dc97e73a83145e314caf7e5f2885 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 10:26:23 -0500 Subject: ZVISION: Change _pausedTime to be a reference to when time was paused, instead of accumulation of time --- engines/zvision/clock.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/clock.cpp b/engines/zvision/clock.cpp index 2324d395c3..fe322525f8 100644 --- a/engines/zvision/clock.cpp +++ b/engines/zvision/clock.cpp @@ -39,15 +39,14 @@ Clock::Clock(OSystem *system) void Clock::update() { uint32 currentTime = _system->getMillis(); - _deltaTime = currentTime - _lastTime - _pausedTime; - if (_deltaTime < 0) { - _deltaTime = 0; - } + _deltaTime = (currentTime - _lastTime); if (_paused) { - _pausedTime += _deltaTime; - } else if (_pausedTime > 0) { - _pausedTime = 0; + _deltaTime -= (currentTime - _pausedTime); + } + + if (_deltaTime < 0) { + _deltaTime = 0; } _lastTime = currentTime; @@ -55,12 +54,14 @@ void Clock::update() { void Clock::start() { if (_paused) { + _lastTime = _system->getMillis(); _paused = false; } } void Clock::stop() { if (!_paused) { + _pausedTime = _system->getMillis(); _paused = true; } } -- cgit v1.2.3 From 3f5cf500498970d2a8f71a9604db31ba00bb262e Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 10:27:00 -0500 Subject: ZVISION: Use videoDecoder.getTimeToNextFrame() to calculate the frame delay --- engines/zvision/video.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 51cccee639..c476cf2d83 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -99,9 +99,6 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { // Only continue while the video is still playing while (videoDecoder.isPlaying()) { - _clock.update(); - uint32 currentTime = _clock.getLastMeasuredTime(); - // Check for engine quit and video stop key presses while (_eventMan->pollEvent(_event)) { switch (_event.type) { @@ -133,11 +130,7 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { } } - // Calculate the frame delay based off a desired frame time - int delay = _desiredFrameTime - (currentTime - _system->getMillis()); - // Ensure non-negative - delay = delay < 0 ? 0 : delay; - _system->delayMillis(delay); + _system->delayMillis(videoDecoder.getTimeToNextFrame()); } _clock.stop(); -- cgit v1.2.3 From 9dec0adcdc20e0a31594f9971a0c828255a36874 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:49:47 -0500 Subject: ZVISION: Conform to gcc template spacing requirements --- engines/zvision/puzzle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 5e060c009a..18dfcb821c 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -64,7 +64,7 @@ struct Puzzle { uint32 key; Common::List criteriaList; // This has to be list of pointers because ResultAction is abstract - Common::List> resultActions; + Common::List > resultActions; uint flags; // Used by the ScriptManager to allow unique-ification of _referenceTable -- cgit v1.2.3 From 3723a0bad3a968e7df30ccb7a4df0fe1e4662e33 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:50:39 -0500 Subject: ZVISION: sscanf to a uint first instead of directly to a bool --- engines/zvision/actions.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index cd84a6b85e..bddec38450 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -186,13 +186,15 @@ bool ActionPreloadAnimation::execute(ZVision *engine) { ActionPlayAnimation::ActionPlayAnimation(const Common::String &line) { char fileName[25]; + uint loop; // The two %*u are always 0 and dont seem to have a use sscanf(line.c_str(), "%*[^:]:%*[^:]:%u(%25s %u %u %u %u %u %u %u %*u %*u %u %u)", - &_key, fileName, &_x, &_y, &_width, &_height, &_start, &_end, &_loop, &_mask, &_framerate); + &_key, fileName, &_x, &_y, &_width, &_height, &_start, &_end, &loop, &_mask, &_framerate); _fileName = Common::String(fileName); + _loop = loop == 1 ? true : false; } bool ActionPlayAnimation::execute(ZVision *engine) { -- cgit v1.2.3 From 914763600352385fdda127aa456419d5e4a9cd7e Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:51:16 -0500 Subject: ZVISION: Allow _deltaTime to go negative so it can be clamped to zero properly --- engines/zvision/clock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/clock.h b/engines/zvision/clock.h index d17db6c255..3939ba1612 100644 --- a/engines/zvision/clock.h +++ b/engines/zvision/clock.h @@ -38,7 +38,7 @@ public: private: OSystem *_system; uint32 _lastTime; - uint32 _deltaTime; + int32 _deltaTime; uint32 _pausedTime; bool _paused; -- cgit v1.2.3 From 9036b8d3d2c42b5b082986ce8c5fffc74c07f6db Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:53:14 -0500 Subject: ZVISION: Create ZVisionGameId entry None This is used to end the AD table --- engines/zvision/detection.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/detection.h b/engines/zvision/detection.h index b1e5dcbe01..f08cfd2fe1 100644 --- a/engines/zvision/detection.h +++ b/engines/zvision/detection.h @@ -28,8 +28,9 @@ namespace ZVision { enum ZVisionGameId { - ZorkNemesis, - ZorkGrandInquisitor + None = 0, + ZorkNemesis = 1, + ZorkGrandInquisitor = 2 }; struct ZVisionGameDescription { -- cgit v1.2.3 From 623b2625ffb4ea77be826d645488d05ecf554538 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:52:19 -0500 Subject: ZVISION: Properly end the AD table --- engines/zvision/detection.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index a799cc2aeb..d9bb692f07 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -85,7 +85,10 @@ static const ZVisionGameDescription gameDescriptions[] = { ZorkGrandInquisitor }, - { AD_TABLE_END_MARKER } + { + AD_TABLE_END_MARKER, + None + } }; } // End of namespace ZVision -- cgit v1.2.3 From 1b05d2fd7d662e692fa22ef7b1ecb59a63a3765a Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:54:43 -0500 Subject: ZVISION: Add linking for clock.o --- engines/zvision/module.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 26cf4ee696..14fc035aa1 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -3,6 +3,7 @@ MODULE := engines/zvision MODULE_OBJS := \ action_node.o \ actions.o \ + clock.o \ console.o \ control.o \ detection.o \ -- cgit v1.2.3 From 6564dc044407d1df9adee74de3376b75114844e1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:55:20 -0500 Subject: ZVISION: Rename inner variable to prevent variable shadowing --- engines/zvision/render_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 604c310689..b38db003d1 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -112,9 +112,9 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint uint32 imageWidth = stream.readSint32LE(); uint32 imageHeight = stream.readSint32LE(); - LzssReadStream stream(&stream); + LzssReadStream lzssStream(&stream); byte *buffer = new byte[decompressedSize]; - stream.read(buffer, decompressedSize); + lzssStream.read(buffer, decompressedSize); uint32 horizontalPitch = imageWidth * sizeof(uint16); -- cgit v1.2.3 From 76d4fb569d2d158ca05b3fb09095efc35ed27a12 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:55:52 -0500 Subject: ZVISION: Comment out usage of ActionUnloadAnimation until it is implemented --- engines/zvision/scr_file_handling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 9759fd89b1..06fb0fab89 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -150,7 +150,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:animpreload*", true)) { actionList.push_back(Common::SharedPtr(new ActionPreloadAnimation(line))); } else if (line.matchString("*:animunload*", true)) { - actionList.push_back(Common::SharedPtr(new ActionUnloadAnimation(line))); + //actionList.push_back(Common::SharedPtr(new ActionUnloadAnimation(line))); } else if (line.matchString("*:attenuate*", true)) { -- cgit v1.2.3 From 4806a3726b02d2e8d00db00f752d3b8818c49206 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:56:32 -0500 Subject: ZVISION: Add default case statements for event handling in videos --- engines/zvision/video.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index c476cf2d83..f27c3faab8 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -111,7 +111,11 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { case Common::KEYCODE_SPACE: videoDecoder.stop(); break; + default: + break; } + default: + break; } } -- cgit v1.2.3 From f2823933b4017fcd51eaa96ffb5dd608fcaacf4f Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 11:56:51 -0500 Subject: ZVISION: Remove extraneous include --- engines/zvision/zvision.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index aaf843fae2..a27f4cbc68 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -38,7 +38,6 @@ #include "zvision/console.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" -#include "zvision/clock.h" #include "zvision/zfs_archive.h" #include "zvision/detection.h" -- cgit v1.2.3 From 9bea3cb1c274d2a003ed4e80004fe2a8dc04373f Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 12:50:40 -0500 Subject: ZVISION: Add memory cleanup for _currentBackground --- engines/zvision/render_manager.cpp | 6 ++++++ engines/zvision/render_manager.h | 1 + 2 files changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b38db003d1..70f67deab7 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -43,6 +43,12 @@ RenderManager::RenderManager(OSystem *system, const int width, const int height) _renderTable(width, height) { } +RenderManager::~RenderManager() { + if (_currentBackground != 0) { + delete _currentBackground; + } +} + void RenderManager::updateScreen(bool isConsoleActive) { if (_needsScreenUpdate || isConsoleActive) { _system->updateScreen(); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 9554e888d9..c4318f7dd3 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -44,6 +44,7 @@ namespace ZVision { class RenderManager { public: RenderManager(OSystem *system, const int width, const int height); + ~RenderManager(); private: OSystem *_system; -- cgit v1.2.3 From 1cff0fb0d6e33f436a998b07037b7a2428de34a8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 12:52:10 -0500 Subject: ZVISION: Fix memory free mismatch caused by MemoryReadStream using free() --- engines/zvision/zfs_archive.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index f815d9ccd3..3577ce3d14 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -138,7 +138,8 @@ Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common:: zfsArchive.open(_fileName); zfsArchive.seek(entryHeader->offset); - byte* buffer = new byte[entryHeader->size]; + // This *HAS* to be malloc (not new[]) because MemoryReadStream uses free() to free the memory + byte* buffer = (byte *)malloc(entryHeader->size); zfsArchive.read(buffer, entryHeader->size); // Decrypt the data in place if (_header.xorKey != 0) -- cgit v1.2.3 From 6598bb20fda6aec37d5d7c96ceb6ecde47fda866 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:06:23 -0500 Subject: ZVISION: Create image auto screen centering during blitting --- engines/zvision/render_manager.cpp | 20 ++++++++++++-------- engines/zvision/render_manager.h | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 70f67deab7..1473dcccac 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -56,7 +56,7 @@ void RenderManager::updateScreen(bool isConsoleActive) { } } -void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle) { +void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter) { // Panoramas are transposed // The actual data is transposed in mutateImage if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { @@ -83,6 +83,11 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty()) return; + // Center the image on the screen if asked + if (autoCenter) { + destRect.moveTo((_width - subRectangle.width()) / 2, (_height - subRectangle.height()) / 2); + } + if (_renderTable.getRenderState() == RenderTable::FLAT) { _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left, destRect.top, destRect.width(), destRect.height()); } else { @@ -94,7 +99,7 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin } } -void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle) { +void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter) { Common::File file; if (!file.open(fileName)) { @@ -102,10 +107,10 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d return; } - renderImageToScreen(file, destinationX, destinationY, subRectangle); + renderImageToScreen(file, destinationX, destinationY, subRectangle, autoCenter); } -void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle) { +void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter) { // Read the magic number // Some files are true TGA, while others are TGZ uint32 fileType; @@ -124,7 +129,7 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint uint32 horizontalPitch = imageWidth * sizeof(uint16); - renderSubRectToScreen((uint16 *)buffer, imageWidth, imageHeight, horizontalPitch, destinationX, destinationY, subRectangle); + renderSubRectToScreen((uint16 *)buffer, imageWidth, imageHeight, horizontalPitch, destinationX, destinationY, subRectangle, autoCenter); delete[] buffer; } else { // Reset the cursor @@ -138,7 +143,7 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint } const Graphics::Surface *tgaSurface = tga.getSurface(); - renderSubRectToScreen((uint16 *)tgaSurface->pixels, tgaSurface->w, tgaSurface->h, tgaSurface->pitch, destinationX, destinationY, subRectangle); + renderSubRectToScreen((uint16 *)tgaSurface->pixels, tgaSurface->w, tgaSurface->h, tgaSurface->pitch, destinationX, destinationY, subRectangle, autoCenter); tga.destroy(); } @@ -160,8 +165,7 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { _currentBackground = file; - // TODO: Check if all the panoramas are the same height. AKA: can we hardcode the vertical centering to 80px? - renderImageToScreen(*_currentBackground, 0, 80); + renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(), true); } } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index c4318f7dd3..3352f415a9 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -72,7 +72,7 @@ public: * @param destinationY Y position where the image should be put * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. */ - void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0)); + void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool autoCenter = false); /** * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. @@ -83,7 +83,7 @@ public: * @param destinationY Y position where the image should be put * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. */ - void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0)); + void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool autoCenter = false); /** * Sets the current background image to be used by the RenderManager and immediately @@ -98,7 +98,7 @@ public: bool needsScreenUpdate() { return _needsScreenUpdate; }; private: - void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle); + void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter); }; } // End of namespace ZVision -- cgit v1.2.3 From 946f98b34d01c06fdea5416f0f0bbd6457bb1b86 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:07:55 -0500 Subject: ZVISION: Fix frame delay calculation being reversed. Also convert to int to ensure proper 0 clamping --- engines/zvision/zvision.cpp | 2 +- engines/zvision/zvision.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index a27f4cbc68..7c9bdd8877 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -134,7 +134,7 @@ Common::Error ZVision::run() { _renderManager->updateScreen(_console->isActive()); // Calculate the frame delay based off a desired frame time - int delay = _desiredFrameTime - (currentTime - _system->getMillis()); + int delay = _desiredFrameTime - int32(_system->getMillis() - currentTime); // Ensure non-negative delay = delay < 0 ? 0 : delay; _system->delayMillis(delay); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 990b6e8b93..5bb3d7cb1d 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -68,7 +68,7 @@ private: const int _height; const Graphics::PixelFormat _pixelFormat; - const uint _desiredFrameTime; + const int _desiredFrameTime; // We need random numbers Common::RandomSource *_rnd; -- cgit v1.2.3 From 30afe1a81532f19c7ab872ff20e2b04c582ff221 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:08:44 -0500 Subject: ZVISION: Add some comments concerning StateFlag::DO_ME_NOW --- engines/zvision/puzzle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 18dfcb821c..e7846f5296 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -57,7 +57,7 @@ struct Puzzle { enum StateFlags { ONCE_PER_INST = 0x01, - DO_ME_NOW = 0x02, + DO_ME_NOW = 0x02, // Somewhat useless flag since anything that needs to be done immediately has no criteria DISABLED = 0x04 }; -- cgit v1.2.3 From a31a97c520bbe49bf351b5178302a529f313a35e Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:09:28 -0500 Subject: ZVISION: Add debug statements for Puzzle checking --- engines/zvision/script_manager.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 7fcade22c1..395d45cff9 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -24,6 +24,7 @@ #include "common/algorithm.h" #include "common/hashmap.h" +#include "common/debug.h" #include "zvision/script_manager.h" #include "zvision/actions.h" @@ -76,6 +77,8 @@ void ScriptManager::checkPuzzleCriteria() { while (!_puzzlesToCheck.empty()) { Puzzle *puzzle = _puzzlesToCheck.pop(); + debug("Checking puzzle: %u", puzzle->key); + // Check each Criteria bool criteriaMet = false; for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { @@ -110,6 +113,8 @@ void ScriptManager::checkPuzzleCriteria() { // TODO: Add logic for the different Flags (aka, ONCE_PER_INST) // criteriaList can be empty. Aka, the puzzle should be executed immediately if (puzzle->criteriaList.empty() || criteriaMet) { + debug("Puzzle %u criteria passed. Executing its ResultActions", puzzle->key); + for (Common::List >::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { (*resultIter)->execute(_engine); } -- cgit v1.2.3 From 435ed16e0360440367ceb36b09e2116b3325a01b Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:09:54 -0500 Subject: ZVISION: Set the puzzle global variable after a Puzzle is completed --- engines/zvision/script_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 395d45cff9..5b42895139 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -118,6 +118,9 @@ void ScriptManager::checkPuzzleCriteria() { for (Common::List >::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { (*resultIter)->execute(_engine); } + + // Set the puzzle as completed + setStateValue(puzzle->key, 1); } } } -- cgit v1.2.3 From 387bfb2806856dcf76cb12a7a3b571aa62a59298 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:10:19 -0500 Subject: ZVISION: Fix typo in Puzzle checking --- engines/zvision/script_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 5b42895139..38ca1075d1 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -84,7 +84,7 @@ void ScriptManager::checkPuzzleCriteria() { for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { // Get the value to compare against uint argumentValue; - if ((*iter).argument) + if ((*iter).argumentIsAKey) argumentValue = getStateValue(iter->argument); else argumentValue = iter->argument; -- cgit v1.2.3 From 931ad00a2d208335fc45885bfc7f53a53e6d9dce Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:18:04 -0500 Subject: ZVISION: Add StateFlag handling to Puzzle checking --- engines/zvision/script_manager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 38ca1075d1..fe6548cd80 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -77,6 +77,15 @@ void ScriptManager::checkPuzzleCriteria() { while (!_puzzlesToCheck.empty()) { Puzzle *puzzle = _puzzlesToCheck.pop(); + // Check if the puzzle is already finished + // If it doesn't have the flag ONCE_PER_INST it can be done more than once + // Also check that the puzzle isn't disabled + if (getStateValue(puzzle->key) == 1 && + (puzzle->flags & Puzzle::StateFlags::ONCE_PER_INST) == Puzzle::StateFlags::ONCE_PER_INST && + (puzzle->flags & Puzzle::StateFlags::DISABLED) == 0) { + continue; + } + debug("Checking puzzle: %u", puzzle->key); // Check each Criteria -- cgit v1.2.3 From b98a8fbf12717457c087b4e169d72f461310c667 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 5 Aug 2013 19:20:36 -0500 Subject: ZVISION: Fix loop logic so videos can end --- engines/zvision/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index f27c3faab8..32f7b1fc8a 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -98,9 +98,9 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { videoDecoder.start(); // Only continue while the video is still playing - while (videoDecoder.isPlaying()) { + while (!shouldQuit() && !videoDecoder.endOfVideo() && videoDecoder.isPlaying()) { // Check for engine quit and video stop key presses - while (_eventMan->pollEvent(_event)) { + while (!videoDecoder.endOfVideo() && videoDecoder.isPlaying() && _eventMan->pollEvent(_event)) { switch (_event.type) { case Common::EVENT_KEYDOWN: switch (_event.kbd.keycode) { -- cgit v1.2.3 From f67e0042b046c57526f72d8f33b7c36b5508a66a Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 7 Aug 2013 15:26:59 -0500 Subject: ZVISION: Create console method to dump all cursor file names --- engines/zvision/console.cpp | 17 +++++++++++++++++ engines/zvision/console.h | 1 + 2 files changed, 18 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 6634e0bef4..f9b4e7008a 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -48,6 +48,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("setpanoramascale", WRAP_METHOD(Console, cmdSetPanoramaScale)); DCmd_Register("changelocation", WRAP_METHOD(Console, cmdChangeLocation)); DCmd_Register("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); + DCmd_Register("dumpcursorfilenames", WRAP_METHOD(Console, cmdDumpAllCursorFileNames)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -175,4 +176,20 @@ bool Console::cmdDumpFile(int argc, const char **argv) { return true; } +bool Console::cmdDumpAllCursorFileNames(int argc, const char **argv) { + Common::DumpFile outputFile; + outputFile.open("cursorFileNames.txt"); + + Common::ArchiveMemberList list; + SearchMan.listMatchingMembers(list, "*.zcr"); + + // Register the file entries within the zfs archives with the SearchMan + for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { + outputFile.writeString((*iter)->getName()); + outputFile.writeByte('\n'); + } + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index be3ebf10dc..3c08f20768 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -47,6 +47,7 @@ private: bool cmdSetPanoramaScale(int argc, const char **argv); bool cmdChangeLocation(int argc, const char **argv); bool cmdDumpFile(int argc, const char **argv); + bool cmdDumpAllCursorFileNames(int argc, const char **argv); }; } // End of namespace ZVision -- cgit v1.2.3 From b4b60e1f632f928bb3f28b99ff4689a9cd24c680 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 12:16:43 -0500 Subject: ZVISION: Call _system->updateScreen() every frame Otherwise the cursor will not be updated --- engines/zvision/render_manager.cpp | 7 ------- engines/zvision/render_manager.h | 1 - engines/zvision/zvision.cpp | 6 +++--- 3 files changed, 3 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 1473dcccac..f759c1fb96 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -49,13 +49,6 @@ RenderManager::~RenderManager() { } } -void RenderManager::updateScreen(bool isConsoleActive) { - if (_needsScreenUpdate || isConsoleActive) { - _system->updateScreen(); - _needsScreenUpdate = false; - } -} - void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter) { // Panoramas are transposed // The actual data is transposed in mutateImage diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 3352f415a9..4b4e178e91 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -61,7 +61,6 @@ private: public: void initialize(); - void updateScreen(bool isConsoleActive); /** * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 7c9bdd8877..338bbc5fbc 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -130,9 +130,9 @@ Common::Error ZVision::run() { _scriptManager->updateNodes(_clock.getDeltaTime()); _scriptManager->checkPuzzleCriteria(); - // Render a frame - _renderManager->updateScreen(_console->isActive()); - + // Update the screen + _system->updateScreen(); + // Calculate the frame delay based off a desired frame time int delay = _desiredFrameTime - int32(_system->getMillis() - currentTime); // Ensure non-negative -- cgit v1.2.3 From 268282ab22d18e92180aa7653ef52b47a6ed1b51 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 14:05:31 -0500 Subject: ZVISION: Create class for decoding .zcr cursor files --- engines/zvision/cursor.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/cursor.h | 66 ++++++++++++++++++++++++++++++ engines/zvision/module.mk | 1 + 3 files changed, 167 insertions(+) create mode 100644 engines/zvision/cursor.cpp create mode 100644 engines/zvision/cursor.h (limited to 'engines/zvision') diff --git a/engines/zvision/cursor.cpp b/engines/zvision/cursor.cpp new file mode 100644 index 0000000000..601c58fa2c --- /dev/null +++ b/engines/zvision/cursor.cpp @@ -0,0 +1,100 @@ +/* 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/scummsys.h" + +#include "common/str.h" +#include "common/file.h" + +#include "zvision/cursor.h" + + +namespace ZVision { + +ZorkCursor::ZorkCursor() + : _width(0), + _height(0), + _hotspotX(0), + _hotspotY(0), + _surface(0) { +} + +ZorkCursor::ZorkCursor(const Common::String &fileName) + : _width(0), + _height(0), + _hotspotX(0), + _hotspotY(0), + _surface(0) { + Common::File file; + if (!file.open(fileName)) + return; + + uint32 magic = file.readUint32BE(); + if (magic != MKTAG('Z', 'C', 'R', '1')) { + warning("%s is not a Zork Cursor file", fileName.c_str()); + return; + } + + _hotspotX = file.readUint16LE(); + _hotspotY = file.readUint16LE(); + _width = file.readUint16LE(); + _height = file.readUint16LE(); + + uint dataSize = _width * _height * 2; + _surface = new byte[dataSize]; + uint32 bytesRead = file.read(_surface, dataSize); + assert(bytesRead == dataSize); +} + +ZorkCursor::ZorkCursor(const ZorkCursor &other) { + _width = other._width; + _height = other._height; + _hotspotX = other._hotspotX; + _hotspotY = other._hotspotY; + + uint dataSize = _width * _height * 2; + _surface = new byte[dataSize]; + + memcpy(_surface, other._surface, dataSize); +} + +ZorkCursor &ZorkCursor::operator=(const ZorkCursor &other) { + _width = other._width; + _height = other._height; + _hotspotX = other._hotspotX; + _hotspotY = other._hotspotY; + + uint dataSize = _width * _height * 2; + _surface = new byte[dataSize]; + + memcpy(_surface, other._surface, dataSize); + + return *this; +} + +ZorkCursor::~ZorkCursor() { + if (_surface != 0) { + delete[] _surface; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/cursor.h b/engines/zvision/cursor.h new file mode 100644 index 0000000000..0d91a48f0f --- /dev/null +++ b/engines/zvision/cursor.h @@ -0,0 +1,66 @@ +/* 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 ZVISION_CURSOR_H +#define ZVISION_CURSOR_H + +#include "common/types.h" + +#include "graphics/cursor.h" + +namespace Common { +class String; +} + +namespace ZVision { + +class ZorkCursor : public Graphics::Cursor { +public: + ZorkCursor(); + ZorkCursor(const Common::String &fileName); + ZorkCursor(const ZorkCursor &other); + ~ZorkCursor(); + +private: + uint16 _width; + uint16 _height; + uint16 _hotspotX; + uint16 _hotspotY; + byte *_surface; + +public: + ZorkCursor &operator=(const ZorkCursor &other); + + uint16 getWidth() const { return _width; } + uint16 getHeight() const { return _height; } + uint16 getHotspotX() const { return _hotspotX; } + uint16 getHotspotY() const { return _hotspotY; } + byte getKeyColor() const { return 0; } + const byte *getSurface() const { return _surface; } + const byte *getPalette() const { return 0; } + byte getPaletteStartIndex() const { return 0; } + uint16 getPaletteCount() const { return 0; } +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 14fc035aa1..feafad5e16 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -6,6 +6,7 @@ MODULE_OBJS := \ clock.o \ console.o \ control.o \ + cursor.o \ detection.o \ events.o \ lzss_read_stream.o \ -- cgit v1.2.3 From f31f35bf7bcd964b970eb4817135c966c9bad823 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 14:06:23 -0500 Subject: ZVISION: Create console command to render a cursor image to the screen --- engines/zvision/console.cpp | 12 ++++++++++++ engines/zvision/console.h | 1 + 2 files changed, 13 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index f9b4e7008a..f1b192fce1 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -22,6 +22,7 @@ #include "common/scummsys.h" +#include "common/system.h" #include "gui/debugger.h" #include "common/file.h" #include "common/bufferedstream.h" @@ -34,6 +35,8 @@ #include "zvision/zork_avi_decoder.h" #include "zvision/zork_raw.h" #include "zvision/utility.h" +#include "zvision/cursor.h" + namespace ZVision { @@ -49,6 +52,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("changelocation", WRAP_METHOD(Console, cmdChangeLocation)); DCmd_Register("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); DCmd_Register("dumpcursorfilenames", WRAP_METHOD(Console, cmdDumpAllCursorFileNames)); + DCmd_Register("showcursor", WRAP_METHOD(Console, cmdShowCursor)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -192,4 +196,12 @@ bool Console::cmdDumpAllCursorFileNames(int argc, const char **argv) { return true; } +bool Console::cmdShowCursor(int argc, const char **argv) { + ZorkCursor cursor(argv[1]); + + _engine->_system->copyRectToScreen(cursor.getSurface(), cursor.getWidth() * 2, 0, 0, cursor.getWidth(), cursor.getHeight()); + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 3c08f20768..995c41881e 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -48,6 +48,7 @@ private: bool cmdChangeLocation(int argc, const char **argv); bool cmdDumpFile(int argc, const char **argv); bool cmdDumpAllCursorFileNames(int argc, const char **argv); + bool cmdShowCursor(int argc, const char **argv); }; } // End of namespace ZVision -- cgit v1.2.3 From 06e6cb5d1f9b6cc7d632e3a7e31267363dad3503 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 14:51:18 -0500 Subject: ZVISION: Create method for cycling through all the cursors so as to identify them more easily --- engines/zvision/events.cpp | 3 +++ engines/zvision/zvision.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/zvision.h | 2 ++ 3 files changed, 61 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 508d2610aa..3163563ad3 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -61,6 +61,9 @@ void ZVision::processEvents() { if (_event.kbd.hasFlags(Common::KBD_CTRL)) quitGame(); break; + case Common::KEYCODE_F1: + cycleThroughCursors(); + break; default: break; } diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 338bbc5fbc..46b6c01781 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -40,6 +40,7 @@ #include "zvision/render_manager.h" #include "zvision/zfs_archive.h" #include "zvision/detection.h" +#include "zvision/cursor.h" #include "zvision/utility.h" @@ -169,4 +170,59 @@ ZVisionGameId ZVision::getGameId() const { return _gameDescription->gameId; } +void ZVision::cycleThroughCursors() { + Common::ArchiveMemberList list; + SearchMan.listMatchingMembers(list, "*.zcr"); + + Common::ArchiveMemberList::iterator iter = list.begin(); + ZorkCursor cursor; + bool cursorChanged = false; + + _system->showMouse(true); + + bool done = false; + while (!done && !shouldQuit()) { + _clock.update(); + uint32 currentTime = _clock.getLastMeasuredTime(); + + while (_eventMan->pollEvent(_event)) { + if (_event.type == Common::EVENT_KEYDOWN) { + switch (_event.kbd.keycode) { + case Common::KEYCODE_LEFT: + --iter; + cursorChanged = true; + break; + case Common::KEYCODE_RIGHT: + ++iter; + cursorChanged = true; + break; + case Common::KEYCODE_RETURN: + debug("%s", (*iter)->getName().c_str()); + break; + case Common::KEYCODE_ESCAPE: + done = true; + break; + default: + break; + } + } + } + + if (cursorChanged) { + cursor = ZorkCursor((*iter)->getName()); + + _system->setMouseCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getHeight(), true, &_pixelFormat); + cursorChanged = false; + } + + _system->updateScreen(); + + // Calculate the frame delay based off a desired frame time + int delay = _desiredFrameTime - int32(_system->getMillis() - currentTime); + // Ensure non-negative + delay = delay < 0 ? 0 : delay; + _system->delayMillis(delay); + } +} + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 5bb3d7cb1d..29c1ddd651 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -96,6 +96,8 @@ public: void playVideo(Video::VideoDecoder &videoDecoder); + void cycleThroughCursors(); + private: void initialize(); -- cgit v1.2.3 From 0feac806b235867aae4078d2b5c58c38b3b23e21 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 14:51:45 -0500 Subject: ZVISION: Add a ZGI folder directory to the SearchMan --- engines/zvision/zvision.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 46b6c01781..7cfa42e125 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -69,6 +69,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) SearchMan.addSubDirectoryMatching(gameDataDir, "zassets1", 0, 2, true); SearchMan.addSubDirectoryMatching(gameDataDir, "zassets2", 0, 2, true); SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx", 0, 1, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "zgi", 0, 4, true); // Here is the right place to set up the engine specific debug channels //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); -- cgit v1.2.3 From f89120310cd08dc0640b51ed1e49dd02c3a028b9 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 14:52:21 -0500 Subject: ZVISION: Test for file.open before trying to read --- engines/zvision/utility.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index 2e1ade663a..fb4fe22ff8 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -33,7 +33,10 @@ namespace ZVision { void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile) { Common::File f; - f.open(sourceFile); + if (!f.open(sourceFile)) { + return; + } + byte* buffer = new byte[f.size()]; f.read(buffer, f.size()); -- cgit v1.2.3 From 1b277d34ac9d7b207e7e42964d00dd6f433daadc Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 18:33:15 -0500 Subject: ZVISION: Add class to manage cursors --- engines/zvision/cursor_manager.cpp | 119 +++++++++++++++++++++++++++++++++++++ engines/zvision/cursor_manager.h | 67 +++++++++++++++++++++ engines/zvision/events.cpp | 7 ++- engines/zvision/module.mk | 1 + engines/zvision/zvision.cpp | 6 +- engines/zvision/zvision.h | 4 ++ 6 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 engines/zvision/cursor_manager.cpp create mode 100644 engines/zvision/cursor_manager.h (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp new file mode 100644 index 0000000000..43d288ea4e --- /dev/null +++ b/engines/zvision/cursor_manager.cpp @@ -0,0 +1,119 @@ +/* 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/scummsys.h" + +#include "common/system.h" +#include "graphics/pixelformat.h" + +#include "zvision/zvision.h" +#include "zvision/cursor_manager.h" + + +namespace ZVision { + +const char *CursorManager::_cursorNames[] = { "active", "arrow", "backward", "downarrow", "forward", "handpt", "handpu", "hdown", "hleft", + "hright", "hup", "idle", "leftarrow", "rightarrow", "suggest_surround", "suggest_tilt", "turnaround", "zuparrow" }; + +const char *CursorManager::_zgiCursorFileNames[] = { "g0gbc011.zcr", "g0gac001.zcr", "g0gac021.zcr", "g0gac031.zcr", "g0gac041.zcr", "g0gac051.zcr", "g0gac061.zcr", "g0gac071.zcr", "g0gac081.zcr", + "g0gac091.zcr", "g0gac101.zcr", "g0gac011.zcr", "g0gac111.zcr", "g0gac121.zcr", "g0gac131.zcr", "g0gac141.zcr", "g0gac151.zcr", "g0gac161.zcr" }; + +const char *CursorManager::_zNemCursorFileNames[] = { "00act", "arrow", "back", "down", "forw", "handpt", "handpu", "hdown", "hleft", + "hright", "hup", "00idle", "left", "right", "ssurr", "stilt", "turn", "up" }; + + +CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat) + : _engine(engine), + _pixelFormat(pixelFormat), + _cursorIsPushed(false), + _currentCursor("idle") { + // WARNING: The index 11 is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly + if (_engine->getGameId() == ZorkNemesis) { + Common::String name(Common::String::format("%sa.zcr", _zNemCursorFileNames[11])); + _idleCursor = ZorkCursor(name); + } else if (_engine->getGameId() == ZorkGrandInquisitor) { + _idleCursor = ZorkCursor(_zgiCursorFileNames[11]); + } +} + +void CursorManager::initialize() { + _engine->_system->setMouseCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); + _engine->_system->showMouse(true); +} + +void CursorManager::changeCursor(Common::String &cursorName, bool pushed) { + _cursorIsPushed = pushed; + + if (cursorName == "idle" && !pushed) { + revertToIdle(); + return; + } + + // WARNING: The range of this loop is hardcoded to the length of _cursorNames + for (int i = 0; i < 18; i++) { + if (_engine->getGameId() == ZorkNemesis) { + if (_cursorNames[i] == cursorName) { + // ZNem uses a/b at the end of the file to signify not pushed/pushed respectively + Common::String pushedFlag = pushed ? "b" : "a"; + Common::String name = Common::String::format("%s%s.zcr", _zNemCursorFileNames[i], pushedFlag); + + changeCursor(ZorkCursor(name)); + return; + } + } else if (_engine->getGameId() == ZorkGrandInquisitor) { + if (_cursorNames[i] == cursorName) { + if (!pushed) { + changeCursor(ZorkCursor(_zgiCursorFileNames[i])); + } else { + // ZGI flips not pushed/pushed between a/c and b/d + // It flips the 4th character of the name + char buffer[25]; + strcpy(buffer, _zgiCursorFileNames[i]); + buffer[3] += 2; + } + return; + } + } + } + + // If we get here, something went wrong + warning("No cursor found for identifier %s", cursorName.c_str()); +} + +void CursorManager::changeCursor(const ZorkCursor &cursor) { + _engine->_system->setMouseCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, _pixelFormat); +} + +void CursorManager::cursorDown(bool pushed) { + if (_cursorIsPushed == pushed) + return; + + _cursorIsPushed = pushed; + changeCursor(_currentCursor, pushed); +} + +void CursorManager::revertToIdle() { + _currentCursor = "idle"; + _engine->_system->setMouseCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); +} + +} // End of namespace ZVision diff --git a/engines/zvision/cursor_manager.h b/engines/zvision/cursor_manager.h new file mode 100644 index 0000000000..914538591d --- /dev/null +++ b/engines/zvision/cursor_manager.h @@ -0,0 +1,67 @@ +/* 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 ZVISION_CURSOR_MANAGER_H +#define ZVISION_CURSOR_MANAGER_H + +#include "common/types.h" + +#include "zvision/cursor.h" + + +namespace Graphics { +struct PixelFormat; +} + +namespace ZVision { + +class ZVision; + +class CursorManager { +public: + CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat); + +private: + ZVision *_engine; + const Graphics::PixelFormat *_pixelFormat; + ZorkCursor _idleCursor; + Common::String _currentCursor; + bool _cursorIsPushed; + + static const char *_cursorNames[]; + static const char *_zgiCursorFileNames[]; + static const char *_zNemCursorFileNames[]; + +public: + void initialize(); + + void changeCursor(Common::String &cursorName, bool pushed); + void cursorDown(bool pushed); + void revertToIdle(); + +private: + void changeCursor(const ZorkCursor &cursor); +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 3163563ad3..17f48db7fc 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -27,7 +27,7 @@ #include "common/events.h" #include "engines/util.h" -#include "zvision/render_manager.h" +#include "zvision/cursor_manager.h" namespace ZVision { @@ -39,6 +39,7 @@ void ZVision::processEvents() { break; case Common::EVENT_LBUTTONUP: + onMouseUp(_event.mouse); break; case Common::EVENT_RBUTTONDOWN: @@ -78,7 +79,11 @@ void ZVision::processEvents() { } void ZVision::onMouseDown(const Common::Point &pos) { + _cursorManager->cursorDown(true); +} +void ZVision::onMouseUp(const Common::Point &pos) { + _cursorManager->cursorDown(false); } void ZVision::onMouseMove(const Common::Point &pos) { diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index feafad5e16..7e74b0bfdd 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -7,6 +7,7 @@ MODULE_OBJS := \ console.o \ control.o \ cursor.o \ + cursor_manager.o \ detection.o \ events.o \ lzss_read_stream.o \ diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 7cfa42e125..e1f719df0a 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -38,9 +38,9 @@ #include "zvision/console.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" +#include "zvision/cursor_manager.h" #include "zvision/zfs_archive.h" #include "zvision/detection.h" -#include "zvision/cursor.h" #include "zvision/utility.h" @@ -81,6 +81,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); _renderManager = new RenderManager(_system, _width, _height); + _cursorManager = new CursorManager(this, &_pixelFormat); debug("ZVision::ZVision"); } @@ -90,6 +91,7 @@ ZVision::~ZVision() { // Dispose of resources delete _console; + delete _cursorManager; delete _renderManager; delete _scriptManager; delete _rnd; @@ -114,6 +116,8 @@ void ZVision::initialize() { initGraphics(_width, _height, true, &_pixelFormat); _scriptManager->initialize(); + // Has to be done after graphics has been initialized + _cursorManager->initialize(); // Create debugger console. It requires GFX to be initialized _console = new Console(this); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 29c1ddd651..0a4ed08974 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -47,6 +47,7 @@ struct ZVisionGameDescription; class Console; class ScriptManager; class RenderManager; +class CursorManager; // our engine debug channels enum { @@ -76,6 +77,7 @@ private: // Managers ScriptManager *_scriptManager; RenderManager *_renderManager; + CursorManager *_cursorManager; // Clock Clock _clock; @@ -91,6 +93,7 @@ public: ScriptManager *getScriptManager() const; RenderManager *getRenderManager() const; + CursorManager *getCursorManager() const; Common::RandomSource *getRandomSource() const; ZVisionGameId getGameId() const; @@ -103,6 +106,7 @@ private: void processEvents(); void onMouseDown(const Common::Point &pos); + void onMouseUp(const Common::Point &pos); void onMouseMove(const Common::Point &pos); void onKeyDown(uint keyCode); }; -- cgit v1.2.3 From ed4977848b1761ebfd09db9ea21d744236b813c6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 9 Aug 2013 18:42:27 -0500 Subject: ZVISION: Fix invalid argument for String::format() --- engines/zvision/cursor_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 43d288ea4e..0115ec9d3c 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -74,7 +74,7 @@ void CursorManager::changeCursor(Common::String &cursorName, bool pushed) { if (_cursorNames[i] == cursorName) { // ZNem uses a/b at the end of the file to signify not pushed/pushed respectively Common::String pushedFlag = pushed ? "b" : "a"; - Common::String name = Common::String::format("%s%s.zcr", _zNemCursorFileNames[i], pushedFlag); + Common::String name = Common::String::format("%s%s.zcr", _zNemCursorFileNames[i], pushedFlag.c_str()); changeCursor(ZorkCursor(name)); return; -- cgit v1.2.3 From 9740087441fa2f5b0655c7065f891686c8579cb0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:07:27 -0500 Subject: ZVISION: Add documentation for the ResultAction base class --- engines/zvision/actions.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 76db25adf0..b75ca8bdad 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -36,9 +36,21 @@ namespace ZVision { // Forward declaration of ZVision. This file is included before ZVision is declared class ZVision; +/** + * The base class that represents any action that a Puzzle can take. + * This class is purely virtual. + */ class ResultAction { public: virtual ~ResultAction() {} + /** + * This is called by the script system whenever a Puzzle's criteria are found to be true. + * It should execute any necessary actions and return a value indicating whether the script + * system should continue to test puzzles. In 99% of cases this will be 'true'. + * + * @param engine A pointer to the base engine so the ResultAction can access all the necessary methods + * @return Should the script system continue to test any remaining puzzles (true) or immediately break and go on to the next frame (false) + */ virtual bool execute(ZVision *engine) = 0; }; -- cgit v1.2.3 From 86b3dfa22105a3edf8e99263637f60bc65f97739 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:07:56 -0500 Subject: ZVISION: Make ZFS Archive member name indexing case-insensitive --- engines/zvision/zfs_archive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zfs_archive.h b/engines/zvision/zfs_archive.h index e683ac1b53..3bf492578c 100644 --- a/engines/zvision/zfs_archive.h +++ b/engines/zvision/zfs_archive.h @@ -52,7 +52,7 @@ struct ZfsEntryHeader { uint32 unknown; }; -typedef Common::HashMap ZfsEntryHeaderMap; +typedef Common::HashMap ZfsEntryHeaderMap; class ZfsArchive : public Common::Archive { public: -- cgit v1.2.3 From 416cde1358ecdb18ae3f6c8bc2f794e9ac13755b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:10:06 -0500 Subject: ZVISION: Change video code to support arbitrary scaling and whether the video can be skipped --- engines/zvision/video.cpp | 77 +++++++++++++++++++++++++++++------------------ engines/zvision/zvision.h | 2 +- 2 files changed, 49 insertions(+), 30 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 32f7b1fc8a..9f98b14746 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -34,10 +34,11 @@ namespace ZVision { -// Taken from SCI -void scale2x(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel) { +// Taken/modified from SCI +void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel, uint scaleAmount) { assert(bytesPerPixel == 1 || bytesPerPixel == 2); - const uint32 newWidth = srcWidth * 2; + + const uint32 newWidth = srcWidth * scaleAmount; const uint32 pitch = newWidth * bytesPerPixel; const byte *srcPtr = src; @@ -45,54 +46,70 @@ void scale2x(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, byte for (uint32 y = 0; y < srcHeight; y++) { for (uint32 x = 0; x < srcWidth; x++) { const byte color = *srcPtr++; - dst[0] = color; - dst[1] = color; - dst[newWidth] = color; - dst[newWidth + 1] = color; - dst += 2; + + for (int i = 0; i < scaleAmount; i++) { + dst[i] = color; + dst[pitch + i] = color; + } + dst += scaleAmount; } - dst += newWidth; + dst += pitch; } } else if (bytesPerPixel == 2) { for (uint32 y = 0; y < srcHeight; y++) { for (uint32 x = 0; x < srcWidth; x++) { const byte color = *srcPtr++; const byte color2 = *srcPtr++; - dst[0] = color; - dst[1] = color2; - dst[2] = color; - dst[3] = color2; - dst[pitch] = color; - dst[pitch + 1] = color2; - dst[pitch + 2] = color; - dst[pitch + 3] = color2; - dst += 4; + + for (int i = 0; i < scaleAmount; i++) { + dst[i] = color; + dst[i + 1] = color2; + dst[pitch + i] = color; + dst[pitch + i + 1] = color2; + } + dst += 2 * scaleAmount; } dst += pitch; } } } -void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { +void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect, bool skippable) { // Videos use a different pixel format Common::List formats; formats.push_back(videoDecoder.getPixelFormat()); initGraphics(_width, _height, true, formats); byte bytesPerPixel = videoDecoder.getPixelFormat().bytesPerPixel; + uint16 origWidth = videoDecoder.getWidth(); uint16 origHeight = videoDecoder.getHeight(); + + uint scale = 1; + // If destRect is empty, no specific scaling was requested. However, we may choose to do scaling anyway + if (destRect.isEmpty()) { + // Most videos are very small. Therefore we do a simple 2x scale + if (origWidth * 2 <= 640 && origHeight * 2 <= 480) { + scale = 2; + } + } else { + // Assume bilinear scaling. AKA calculate the scale from just the width. + // Also assume that the scaling is in integral intervals. AKA no 1.5x scaling + // TODO: Test ^these^ assumptions + uint scale = destRect.width() / origWidth; + + // TODO: Test if we need to support downscale. + } + uint16 pitch = origWidth * bytesPerPixel; - // Most videos are very small. Therefore we do a simple 2x scale - bool shouldBeScaled = (origWidth * 2 <= 640 && origHeight * 2 <= 480); - uint16 finalWidth = shouldBeScaled ? origWidth * 2 : origWidth; - uint16 finalHeight = shouldBeScaled ? origHeight * 2 : origHeight; + uint16 finalWidth = origWidth * scale; + uint16 finalHeight = origHeight * scale; - byte *scaledVideoFrameBuffer = new byte[origHeight * pitch * 4]; + byte *scaledVideoFrameBuffer = new byte[finalWidth * finalHeight * bytesPerPixel]; - uint16 x = (_width - finalWidth) / 2; - uint16 y = (_height - finalHeight) / 2; + uint16 x = ((_width - finalWidth) / 2) + destRect.left; + uint16 y = ((_height - finalHeight) / 2) + destRect.top; _clock.stop(); videoDecoder.start(); @@ -109,7 +126,9 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { quitGame(); break; case Common::KEYCODE_SPACE: - videoDecoder.stop(); + if (skippable) { + videoDecoder.stop(); + } break; default: break; @@ -123,8 +142,8 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder) { const Graphics::Surface *frame = videoDecoder.decodeNextFrame(); if (frame) { - if (shouldBeScaled) { - scale2x((byte *)frame->pixels, scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel); + if (scale != 1) { + scaleBuffer((byte *)frame->pixels, scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); _system->copyRectToScreen(scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); } else { _system->copyRectToScreen((byte *)frame->pixels, pitch, x, y, finalWidth, finalHeight); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 0a4ed08974..8363fb1672 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -97,7 +97,7 @@ public: Common::RandomSource *getRandomSource() const; ZVisionGameId getGameId() const; - void playVideo(Video::VideoDecoder &videoDecoder); + void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true); void cycleThroughCursors(); -- cgit v1.2.3 From 694a6099a6f4da7807b1ac1efba75953522da206 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:12:23 -0500 Subject: ZVISION: Implement ActionQuit --- engines/zvision/actions.cpp | 11 +++++++++++ engines/zvision/actions.h | 6 ++++++ engines/zvision/scr_file_handling.cpp | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index bddec38450..81b6960378 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -203,6 +203,17 @@ bool ActionPlayAnimation::execute(ZVision *engine) { } +////////////////////////////////////////////////////////////////////////////// +// ActionQuit +////////////////////////////////////////////////////////////////////////////// + +bool ActionQuit::execute(ZVision *engine) { + engine->quitGame(); + + return true; +} + + ////////////////////////////////////////////////////////////////////////////// // ActionRandom ////////////////////////////////////////////////////////////////////////////// diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index b75ca8bdad..48703b95e5 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -254,6 +254,12 @@ private: uint _framerate; }; +class ActionQuit : public ResultAction { +public: + ActionQuit() {} + bool execute(ZVision *engine); +}; + // TODO: See if this exists in ZGI. It doesn't in ZNem class ActionUnloadAnimation : public ResultAction { public: diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 06fb0fab89..0bb8d2690b 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -211,8 +211,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:quit*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionQuit())); } else if (line.matchString("*:random*", true)) { -- cgit v1.2.3 From 2176aa55fc71fb7ac8b44f81fcc070c927e3d505 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:18:29 -0500 Subject: ZVISION: Implement ActionStreamVideo --- engines/zvision/actions.cpp | 31 +++++++++++++++++++++++++++++++ engines/zvision/actions.h | 15 +++++++++++++++ engines/zvision/scr_file_handling.cpp | 3 +-- 3 files changed, 47 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 81b6960378..8c10837a1f 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -32,6 +32,7 @@ #include "zvision/render_manager.h" #include "zvision/action_node.h" #include "zvision/zork_raw.h" +#include "zvision/zork_avi_decoder.h" namespace ZVision { @@ -248,6 +249,36 @@ bool ActionSetScreen::execute(ZVision *engine) { } +////////////////////////////////////////////////////////////////////////////// +// ActionStreamVideo +////////////////////////////////////////////////////////////////////////////// + +ActionStreamVideo::ActionStreamVideo(const Common::String &line) { + char fileName[25]; + uint skippable; + + sscanf(line.c_str(), "%*[^(](%25s %u %u %u %u %u %u)", fileName, &_x, &_y, &_width, &_height, &_flags, &skippable); + + _fileName = Common::String(fileName); + _skippable = (skippable == 0) ? false : true; +} + +bool ActionStreamVideo::execute(ZVision *engine) { + ZorkAVIDecoder decoder; + if (!decoder.loadFile(_fileName)) { + return true; + } + + Common::Rect destRect; + if ((_flags & 0x1) == 0x1) { + destRect = Common::Rect(_x, _y, _x + _width, _y + _height); + } + + engine->playVideo(decoder, destRect, _skippable); + return true; +} + + ////////////////////////////////////////////////////////////////////////////// // ActionTimer ////////////////////////////////////////////////////////////////////////////// diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 48703b95e5..bb446171fe 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -286,6 +286,21 @@ private: Common::String _fileName; }; +class ActionStreamVideo : public ResultAction { +public: + ActionStreamVideo(const Common::String &line); + bool execute(ZVision *engine); + +private: + Common::String _fileName; + uint _x; + uint _y; + uint _width; + uint _height; + uint _flags; + bool _skippable; +}; + class ActionTimer : public ResultAction { public: ActionTimer(const Common::String &line); diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 0bb8d2690b..061079cd85 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -239,8 +239,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:streamvideo*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionStreamVideo(line))); } else if (line.matchString("*:syncsound*", true)) { -- cgit v1.2.3 From 5bba509db8a84a5d6c2ab4863990683977203e60 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:23:47 -0500 Subject: ZVISION: Create a global puzzle list and parse universe.scr into it during ScriptManager::initialize() --- engines/zvision/scr_file_handling.cpp | 8 ++++++-- engines/zvision/script_manager.cpp | 21 +++++++++++++++++---- engines/zvision/script_manager.h | 7 +++++-- 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 061079cd85..efd122994d 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -33,7 +33,7 @@ namespace ZVision { -void ScriptManager::parseScrFile(const Common::String &fileName) { +void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) { Common::File file; if (!file.open(fileName)) return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another @@ -54,7 +54,11 @@ void ScriptManager::parseScrFile(const Common::String &fileName) { sscanf(line.c_str(),"puzzle:%u",&(puzzle.key)); parsePuzzle(puzzle, file); - _activePuzzles.push_back(puzzle); + if (isGlobal) { + _globalPuzzles.push_back(puzzle); + } else { + _activePuzzles.push_back(puzzle); + } } else if (line.matchString("control:*", true)) { Common::SharedPtr control; diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index fe6548cd80..027fec43a1 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -35,13 +35,12 @@ namespace ZVision { ScriptManager::ScriptManager(ZVision *engine) : _engine(engine) {} -// TODO: Actually do something in the initialize or remove it void ScriptManager::initialize() { - + parseScrFile("universe.scr", true); } void ScriptManager::createReferenceTable() { - // Iterate through each Puzzle + // Iterate through each local Puzzle for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { Puzzle *puzzlePtr = &(*activePuzzleIter); @@ -50,7 +49,21 @@ void ScriptManager::createReferenceTable() { _referenceTable[criteriaIter->key].push_back(puzzlePtr); // If the argument is a key, add a reference to it as well - if (criteriaIter->argument) + if (criteriaIter->argumentIsAKey) + _referenceTable[criteriaIter->argument].push_back(puzzlePtr); + } + } + + // Iterate through each global Puzzle + for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { + Puzzle *puzzlePtr = &(*globalPuzzleIter); + + // Iterate through each Criteria and add a reference from the criteria key to the Puzzle + for (Common::List::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { + _referenceTable[criteriaIter->key].push_back(puzzlePtr); + + // If the argument is a key, add a reference to it as well + if (criteriaIter->argumentIsAKey) _referenceTable[criteriaIter->argument].push_back(puzzlePtr); } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 484069b335..63dc4f8804 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -59,6 +59,8 @@ private: Common::Stack _puzzlesToCheck; /** Holds the currently active puzzles */ Common::List _activePuzzles; + /** Holds the global puzzles */ + Common::List_globalPuzzles; /** Holds the currently active controls */ Common::List > _activeControls; @@ -82,9 +84,10 @@ private: /** * Parses a script file into triggers and events * - * @param fileName Name of the .scr file + * @param fileName Name of the .scr file + * @param isGlobal Are the puzzles included in the file global (true). AKA, the won't be purged during location changes */ - void parseScrFile(const Common::String &fileName); + void parseScrFile(const Common::String &fileName, bool isGlobal = false); /** * Parses the stream into a Puzzle object -- cgit v1.2.3 From dd11566ffdb46a867550e82b3605e3c76cf194a3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:28:41 -0500 Subject: ZVISION: Move the ScriptManager update functions to a single update() function. Then make the individual update functions private --- engines/zvision/script_manager.cpp | 5 +++++ engines/zvision/script_manager.h | 5 +++-- engines/zvision/zvision.cpp | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 027fec43a1..4ccbbef92d 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -39,6 +39,11 @@ void ScriptManager::initialize() { parseScrFile("universe.scr", true); } +void ScriptManager::update(uint deltaTimeMillis) { + updateNodes(deltaTimeMillis); + checkPuzzleCriteria(); +} + void ScriptManager::createReferenceTable() { // Iterate through each local Puzzle for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 63dc4f8804..29994259c9 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -67,8 +67,7 @@ private: public: void initialize(); - void updateNodes(uint deltaTimeMillis); - void checkPuzzleCriteria(); + void update(uint deltaTimeMillis); uint getStateValue(uint32 key); void setStateValue(uint32 key, uint value); @@ -80,6 +79,8 @@ public: private: void createReferenceTable(); + void updateNodes(uint deltaTimeMillis); + void checkPuzzleCriteria(); /** * Parses a script file into triggers and events diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index e1f719df0a..0dd62d7a29 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -133,8 +133,7 @@ Common::Error ZVision::run() { processEvents(); - _scriptManager->updateNodes(_clock.getDeltaTime()); - _scriptManager->checkPuzzleCriteria(); + _scriptManager->update(_clock.getDeltaTime()); // Update the screen _system->updateScreen(); -- cgit v1.2.3 From 2565f96c55b39f5155d10625def873f2c07207e8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:31:57 -0500 Subject: ZVISION: Make ScriptManager::changeLocation delay the actual change until the end of the frame This prevents memory corruption since changeLocation could be called in the middle of a Puzzle list iteration and changeLocation clears all the Puzzle lists. --- engines/zvision/script_manager.cpp | 29 ++++++++++++++++++++++++++--- engines/zvision/script_manager.h | 12 ++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 4ccbbef92d..586cc2af38 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -33,7 +33,7 @@ namespace ZVision { -ScriptManager::ScriptManager(ZVision *engine) : _engine(engine) {} +ScriptManager::ScriptManager(ZVision *engine) : _engine(engine), _changeLocation(false) {} void ScriptManager::initialize() { parseScrFile("universe.scr", true); @@ -42,6 +42,11 @@ void ScriptManager::initialize() { void ScriptManager::update(uint deltaTimeMillis) { updateNodes(deltaTimeMillis); checkPuzzleCriteria(); + + if (_changeLocation) { + changeLocationIntern(); + _changeLocation = false; + } } void ScriptManager::createReferenceTable() { @@ -178,6 +183,19 @@ void ScriptManager::addActionNode(const Common::SharedPtr &node) { } void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 x) { + _nextLocation.world = world; + _nextLocation.room = room; + _nextLocation.node = node; + _nextLocation.view = view; + _nextLocation.x = x; + + _changeLocation = true; +} + +void ScriptManager::changeLocationIntern() { + assert(_nextLocation.world != 0); + debug("Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.x); + // Clear all the containers _referenceTable.clear(); _puzzlesToCheck.clear(); @@ -186,16 +204,21 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, _activeControls.clear(); // Parse into puzzles and controls - Common::String fileName = Common::String::format("%c%c%c%c.scr", world, room, node, view); + Common::String fileName = Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view); parseScrFile(fileName); // Create the puzzle reference table createReferenceTable(); - // Add all the puzzles to the stack to be checked + // Add all the local puzzles to the stack to be checked for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { _puzzlesToCheck.push(&(*iter)); } + + // Add all the global puzzles to the stack to be checked + for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + _puzzlesToCheck.push(&(*iter)); + } } } // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 29994259c9..8e79548f77 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -39,6 +39,14 @@ namespace ZVision { class ZVision; class ActionNode; +struct Location { + char world; + char room; + char node; + char view; + uint32 x; +}; + class ScriptManager { public: ScriptManager(ZVision *engine); @@ -64,6 +72,9 @@ private: /** Holds the currently active controls */ Common::List > _activeControls; + Location _nextLocation; + bool _changeLocation; + public: void initialize(); @@ -79,6 +90,7 @@ public: private: void createReferenceTable(); + void changeLocationIntern(); void updateNodes(uint deltaTimeMillis); void checkPuzzleCriteria(); -- cgit v1.2.3 From 327d4a1ccff41af28b010679a29168b7e839de29 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:32:57 -0500 Subject: ZVISION: Implement ActionChangeLocation::execute() --- engines/zvision/actions.cpp | 6 ++++-- engines/zvision/scr_file_handling.cpp | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 8c10837a1f..4fe77c19ce 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -87,8 +87,10 @@ ActionChangeLocation::ActionChangeLocation(const Common::String &line) { } bool ActionChangeLocation::execute(ZVision *engine) { - // TODO: Implement - return true; + // We can't directly call ScriptManager::ChangeLocationIntern() because doing so clears all the Puzzles, and thus would corrupt the current puzzle checking + engine->getScriptManager()->changeLocation(_world, _room, _node, _view, _x); + // Tell the puzzle system to stop checking any more puzzles + return false; } diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index efd122994d..a47bf0fc0c 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -162,8 +162,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:change_location*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionChangeLocation(line))); } else if (line.matchString("*:crossfade*", true)) { -- cgit v1.2.3 From 309034c153568372f49d3b5c5c13537e53e2cdeb Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:36:57 -0500 Subject: ZVISION: Stop checking puzzles if ResultAction::execute() returns false --- engines/zvision/script_manager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 586cc2af38..3a574a3668 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -142,17 +142,21 @@ void ScriptManager::checkPuzzleCriteria() { } } - // TODO: Add logic for the different Flags (aka, ONCE_PER_INST) // criteriaList can be empty. Aka, the puzzle should be executed immediately if (puzzle->criteriaList.empty() || criteriaMet) { debug("Puzzle %u criteria passed. Executing its ResultActions", puzzle->key); + bool shouldContinue = true; for (Common::List >::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { - (*resultIter)->execute(_engine); + shouldContinue = shouldContinue && (*resultIter)->execute(_engine); } // Set the puzzle as completed setStateValue(puzzle->key, 1); + + if (!shouldContinue) { + break; + } } } } -- cgit v1.2.3 From 17a806a01b6def7ef59cc2501cf53dacc902b4e2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:38:33 -0500 Subject: ZVISION: Add parsing skip for action::copy_file. It is not used. I don't really know what it is used for, but Marisa Chan completely ignores it. --- engines/zvision/scr_file_handling.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index a47bf0fc0c..f116774546 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -255,6 +255,8 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:universe_music*", true)) { + } else if (line.matchString("*:copy_file*", true)) { + // Not used. Purposely left empty } else { warning("Unhandled result action type: %s", line.c_str()); } -- cgit v1.2.3 From c6b82e7753f24a3ea03596204f62975666aa2239 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 13:39:52 -0500 Subject: ZVISION: Fix parsed arguments in ActionStreamVideo --- engines/zvision/actions.cpp | 5 +++-- engines/zvision/actions.h | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 4fe77c19ce..2316530c67 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -259,7 +259,7 @@ ActionStreamVideo::ActionStreamVideo(const Common::String &line) { char fileName[25]; uint skippable; - sscanf(line.c_str(), "%*[^(](%25s %u %u %u %u %u %u)", fileName, &_x, &_y, &_width, &_height, &_flags, &skippable); + sscanf(line.c_str(), "%*[^(](%25s %u %u %u %u %u %u)", fileName, &_x1, &_y1, &_x2, &_y2, &_flags, &skippable); _fileName = Common::String(fileName); _skippable = (skippable == 0) ? false : true; @@ -272,8 +272,9 @@ bool ActionStreamVideo::execute(ZVision *engine) { } Common::Rect destRect; + // 0x1 flags that the destRect dimensions are different from the original video dimensions if ((_flags & 0x1) == 0x1) { - destRect = Common::Rect(_x, _y, _x + _width, _y + _height); + destRect = Common::Rect(_x1, _y1, _x2, _y2); } engine->playVideo(decoder, destRect, _skippable); diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index bb446171fe..8e00cb5e53 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -293,10 +293,10 @@ public: private: Common::String _fileName; - uint _x; - uint _y; - uint _width; - uint _height; + uint _x1; + uint _y1; + uint _x2; + uint _y2; uint _flags; bool _skippable; }; -- cgit v1.2.3 From bd4e6e0c1873d6a1fe387114d06ec95a0756a2db Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 13:40:23 -0500 Subject: ZVISION: Remove Graphics::Cursor inheritance and remove extraneous methods --- engines/zvision/cursor.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor.h b/engines/zvision/cursor.h index 0d91a48f0f..77093c4daf 100644 --- a/engines/zvision/cursor.h +++ b/engines/zvision/cursor.h @@ -33,7 +33,7 @@ class String; namespace ZVision { -class ZorkCursor : public Graphics::Cursor { +class ZorkCursor { public: ZorkCursor(); ZorkCursor(const Common::String &fileName); @@ -56,9 +56,6 @@ public: uint16 getHotspotY() const { return _hotspotY; } byte getKeyColor() const { return 0; } const byte *getSurface() const { return _surface; } - const byte *getPalette() const { return 0; } - byte getPaletteStartIndex() const { return 0; } - uint16 getPaletteCount() const { return 0; } }; } // End of namespace ZVision -- cgit v1.2.3 From f6033afa0252384e618adebd0f1aef5867a312f8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 13:42:00 -0500 Subject: ZVISION: Change CursorManager to go through CursorMan instead going directly to OSystem This had to be done so the cursor didn't disappear after the user went to GMM or debug console --- engines/zvision/cursor_manager.cpp | 29 +++++++++++++++++++---------- engines/zvision/cursor_manager.h | 9 ++++++++- 2 files changed, 27 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 0115ec9d3c..6f60ddf018 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -24,6 +24,7 @@ #include "common/system.h" #include "graphics/pixelformat.h" +#include "graphics/cursorman.h" #include "zvision/zvision.h" #include "zvision/cursor_manager.h" @@ -44,8 +45,7 @@ const char *CursorManager::_zNemCursorFileNames[] = { "00act", "arrow", "back", CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat) : _engine(engine), _pixelFormat(pixelFormat), - _cursorIsPushed(false), - _currentCursor("idle") { + _cursorIsPushed(false) { // WARNING: The index 11 is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly if (_engine->getGameId() == ZorkNemesis) { Common::String name(Common::String::format("%sa.zcr", _zNemCursorFileNames[11])); @@ -53,15 +53,20 @@ CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixel } else if (_engine->getGameId() == ZorkGrandInquisitor) { _idleCursor = ZorkCursor(_zgiCursorFileNames[11]); } + revertToIdle(); } void CursorManager::initialize() { - _engine->_system->setMouseCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); - _engine->_system->showMouse(true); + CursorMan.showMouse(true); } -void CursorManager::changeCursor(Common::String &cursorName, bool pushed) { - _cursorIsPushed = pushed; +void CursorManager::changeCursor(const Common::String &cursorName) { + changeCursor(cursorName, _cursorIsPushed); +} + +void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) { + if (_cursorIsPushed != pushed) + _cursorIsPushed = pushed; if (cursorName == "idle" && !pushed) { revertToIdle(); @@ -71,7 +76,9 @@ void CursorManager::changeCursor(Common::String &cursorName, bool pushed) { // WARNING: The range of this loop is hardcoded to the length of _cursorNames for (int i = 0; i < 18; i++) { if (_engine->getGameId() == ZorkNemesis) { - if (_cursorNames[i] == cursorName) { + if (cursorName.equals(_cursorNames[i])) { + _currentCursor = cursorName; + // ZNem uses a/b at the end of the file to signify not pushed/pushed respectively Common::String pushedFlag = pushed ? "b" : "a"; Common::String name = Common::String::format("%s%s.zcr", _zNemCursorFileNames[i], pushedFlag.c_str()); @@ -80,7 +87,9 @@ void CursorManager::changeCursor(Common::String &cursorName, bool pushed) { return; } } else if (_engine->getGameId() == ZorkGrandInquisitor) { - if (_cursorNames[i] == cursorName) { + if (cursorName.equals(_cursorNames[i])) { + _currentCursor = cursorName; + if (!pushed) { changeCursor(ZorkCursor(_zgiCursorFileNames[i])); } else { @@ -100,7 +109,7 @@ void CursorManager::changeCursor(Common::String &cursorName, bool pushed) { } void CursorManager::changeCursor(const ZorkCursor &cursor) { - _engine->_system->setMouseCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, _pixelFormat); + CursorMan.replaceCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, _pixelFormat); } void CursorManager::cursorDown(bool pushed) { @@ -113,7 +122,7 @@ void CursorManager::cursorDown(bool pushed) { void CursorManager::revertToIdle() { _currentCursor = "idle"; - _engine->_system->setMouseCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); + CursorMan.replaceCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); } } // End of namespace ZVision diff --git a/engines/zvision/cursor_manager.h b/engines/zvision/cursor_manager.h index 914538591d..9f624c82cc 100644 --- a/engines/zvision/cursor_manager.h +++ b/engines/zvision/cursor_manager.h @@ -36,6 +36,12 @@ namespace ZVision { class ZVision; +/** + * Class to manage cursor changes. The actual changes have to be done + * through CursorMan. Otherwise the cursor will disappear after GMM + * or debug console. + * TODO: Figure out a way to get rid of the extraneous data copying due to having to use CursorMan + */ class CursorManager { public: CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat); @@ -54,7 +60,8 @@ private: public: void initialize(); - void changeCursor(Common::String &cursorName, bool pushed); + void changeCursor(const Common::String &cursorName); + void changeCursor(const Common::String &cursorName, bool pushed); void cursorDown(bool pushed); void revertToIdle(); -- cgit v1.2.3 From b76927ab4eb5e199f7be6d068a94dc3c531122b1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 13:43:29 -0500 Subject: ZVISION: Remove extraneous _needsScreenUpdate bool --- engines/zvision/render_manager.cpp | 2 -- engines/zvision/render_manager.h | 3 --- 2 files changed, 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index f759c1fb96..132c597140 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -39,7 +39,6 @@ RenderManager::RenderManager(OSystem *system, const int width, const int height) _width(width), _height(height), _currentBackground(0), - _needsScreenUpdate(false), _renderTable(width, height) { } @@ -141,7 +140,6 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint tga.destroy(); } - _needsScreenUpdate = true; } RenderTable *RenderManager::getRenderTable() { diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 4b4e178e91..6e267eb395 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -57,8 +57,6 @@ private: Video::VideoDecoder *_currentVideo; byte *_scaledVideoFrameBuffer; - bool _needsScreenUpdate; - public: void initialize(); @@ -94,7 +92,6 @@ public: RenderTable *getRenderTable(); - bool needsScreenUpdate() { return _needsScreenUpdate; }; private: void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter); -- cgit v1.2.3 From a3315037ffde458ff8356c5e7ef9913c4f7b245c Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 13:44:23 -0500 Subject: ZVISION: Create methods for converting screen coords to image coords --- engines/zvision/render_manager.cpp | 12 ++++++++++++ engines/zvision/render_manager.h | 4 +++- engines/zvision/render_table.cpp | 17 +++++++++++++++++ engines/zvision/render_table.h | 3 +++ 4 files changed, 35 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 132c597140..2d45ad835d 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -80,6 +80,8 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin destRect.moveTo((_width - subRectangle.width()) / 2, (_height - subRectangle.height()) / 2); } + _backgroundOffset = Common::Point(destRect.left, destRect.top); + if (_renderTable.getRenderState() == RenderTable::FLAT) { _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left, destRect.top, destRect.width(), destRect.height()); } else { @@ -139,7 +141,17 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint tga.destroy(); } +} + +const Common::Point RenderManager::convertToImageCoords(const Common::Point &point) { + Common::Point newPoint(point); + + if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { + newPoint = _renderTable.convertWarpedPointToFlatCoords(newPoint); + } + newPoint -= _backgroundOffset; + return newPoint; } RenderTable *RenderManager::getRenderTable() { diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 6e267eb395..aea24505a9 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -53,6 +53,7 @@ private: RenderTable _renderTable; Common::SeekableReadStream *_currentBackground; + Common::Point _backgroundOffset; Video::VideoDecoder *_currentVideo; byte *_scaledVideoFrameBuffer; @@ -90,8 +91,9 @@ public: */ void setBackgroundImage(const Common::String &fileName); - RenderTable *getRenderTable(); + const Common::Point convertToImageCoords(const Common::Point &point); + RenderTable *getRenderTable(); private: void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter); diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index b6598c12b2..2a111ce659 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -60,6 +60,16 @@ void RenderTable::setRenderState(RenderState newState) { } } +const Common::Point RenderTable::convertWarpedPointToFlatCoords(const Common::Point &point) { + uint32 index = point.y * _numColumns + point.x; + + Common::Point newPoint(point); + newPoint.x += _internalBuffer[index].x; + newPoint.y += _internalBuffer[index].y; + + return newPoint; +} + uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { assert(percentColorOne < 1.0f); @@ -157,7 +167,14 @@ void RenderTable::generatePanoramaLookupTable() { } void RenderTable::generateTiltLookupTable() { + for (uint x = 0; x < _numColumns; x++) { + for (uint y = 0; y < _numRows; y++) { + uint32 index = y * _numColumns + x; + _internalBuffer[index].x = 0; + _internalBuffer[index].y = 0; + } + } } void RenderTable::setPanoramaFoV(float fov) { diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 82bea62769..5cef062045 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -63,6 +63,9 @@ private: public: RenderState getRenderState() { return _renderState; } void setRenderState(RenderState newState); + + const Common::Point convertWarpedPointToFlatCoords(const Common::Point &point); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle); void generateRenderTable(); -- cgit v1.2.3 From 3eb6c0ebd8c523c0c66e639fc1ea1f02b8575231 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:02:38 -0500 Subject: ZVISION: Convert hardcoded constants to anonymous enum variables --- engines/zvision/cursor_manager.cpp | 23 +++++++++++------------ engines/zvision/cursor_manager.h | 6 ++++++ 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 6f60ddf018..698168b72a 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -32,31 +32,31 @@ namespace ZVision { -const char *CursorManager::_cursorNames[] = { "active", "arrow", "backward", "downarrow", "forward", "handpt", "handpu", "hdown", "hleft", - "hright", "hup", "idle", "leftarrow", "rightarrow", "suggest_surround", "suggest_tilt", "turnaround", "zuparrow" }; +const char *CursorManager::_cursorNames[NUM_CURSORS] = { "active", "arrow", "backward", "downarrow", "forward", "handpt", "handpu", "hdown", "hleft", + "hright", "hup", "idle", "leftarrow", "rightarrow", "suggest_surround", "suggest_tilt", "turnaround", "zuparrow" }; -const char *CursorManager::_zgiCursorFileNames[] = { "g0gbc011.zcr", "g0gac001.zcr", "g0gac021.zcr", "g0gac031.zcr", "g0gac041.zcr", "g0gac051.zcr", "g0gac061.zcr", "g0gac071.zcr", "g0gac081.zcr", - "g0gac091.zcr", "g0gac101.zcr", "g0gac011.zcr", "g0gac111.zcr", "g0gac121.zcr", "g0gac131.zcr", "g0gac141.zcr", "g0gac151.zcr", "g0gac161.zcr" }; +const char *CursorManager::_zgiCursorFileNames[NUM_CURSORS] = { "g0gbc011.zcr", "g0gac001.zcr", "g0gac021.zcr", "g0gac031.zcr", "g0gac041.zcr", "g0gac051.zcr", "g0gac061.zcr", "g0gac071.zcr", "g0gac081.zcr", + "g0gac091.zcr", "g0gac101.zcr", "g0gac011.zcr", "g0gac111.zcr", "g0gac121.zcr", "g0gac131.zcr", "g0gac141.zcr", "g0gac151.zcr", "g0gac161.zcr" }; -const char *CursorManager::_zNemCursorFileNames[] = { "00act", "arrow", "back", "down", "forw", "handpt", "handpu", "hdown", "hleft", - "hright", "hup", "00idle", "left", "right", "ssurr", "stilt", "turn", "up" }; +const char *CursorManager::_zNemCursorFileNames[NUM_CURSORS] = { "00act", "arrow", "back", "down", "forw", "handpt", "handpu", "hdown", "hleft", + "hright", "hup", "00idle", "left", "right", "ssurr", "stilt", "turn", "up" }; CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat) : _engine(engine), _pixelFormat(pixelFormat), _cursorIsPushed(false) { - // WARNING: The index 11 is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly + // WARNING: The index IDLE_CURSOR_INDEX is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly if (_engine->getGameId() == ZorkNemesis) { - Common::String name(Common::String::format("%sa.zcr", _zNemCursorFileNames[11])); + Common::String name(Common::String::format("%sa.zcr", _zNemCursorFileNames[IDLE_CURSOR_INDEX])); _idleCursor = ZorkCursor(name); } else if (_engine->getGameId() == ZorkGrandInquisitor) { - _idleCursor = ZorkCursor(_zgiCursorFileNames[11]); + _idleCursor = ZorkCursor(_zgiCursorFileNames[IDLE_CURSOR_INDEX]); } - revertToIdle(); } void CursorManager::initialize() { + revertToIdle(); CursorMan.showMouse(true); } @@ -73,8 +73,7 @@ void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) return; } - // WARNING: The range of this loop is hardcoded to the length of _cursorNames - for (int i = 0; i < 18; i++) { + for (int i = 0; i < NUM_CURSORS; i++) { if (_engine->getGameId() == ZorkNemesis) { if (cursorName.equals(_cursorNames[i])) { _currentCursor = cursorName; diff --git a/engines/zvision/cursor_manager.h b/engines/zvision/cursor_manager.h index 9f624c82cc..496c652c8c 100644 --- a/engines/zvision/cursor_manager.h +++ b/engines/zvision/cursor_manager.h @@ -47,6 +47,12 @@ public: CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat); private: + enum { + NUM_CURSORS = 18, + // WARNING: The index 11 is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly + IDLE_CURSOR_INDEX = 11 + }; + ZVision *_engine; const Graphics::PixelFormat *_pixelFormat; ZorkCursor _idleCursor; -- cgit v1.2.3 From 668b0e6c892c67253fe5d763ab752bf7dfbd1c3f Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:03:30 -0500 Subject: ZVISION: Throw a warning when a .scr file isn't opened --- engines/zvision/scr_file_handling.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index f116774546..6a71fe474a 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -35,8 +35,10 @@ namespace ZVision { void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) { Common::File file; - if (!file.open(fileName)) - return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another + if (!file.open(fileName)) { + warning("Script file not found: %s", fileName.c_str()); + return; + } while(!file.eos()) { Common::String line = file.readLine(); -- cgit v1.2.3 From 19e829ae95bc69f470d285bdf90d4b45b42248a4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:04:03 -0500 Subject: ZVISION: Ignore .scr file lines that are empty --- engines/zvision/scr_file_handling.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 6a71fe474a..cd4baa34f0 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -148,6 +148,13 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis // TODO: Re-order the if-then statements in order of highest occurrence while (!line.contains('}')) { + if (line.empty()) { + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + continue; + } + // Parse for the action type if (line.matchString("*:add*", true)) { actionList.push_back(Common::SharedPtr(new ActionAdd(line))); -- cgit v1.2.3 From 9f0420e1cef30eaebdf28c32f70fe6467bb9a227 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:04:46 -0500 Subject: ZVISION: Change the initializer list formatting to conform to how everything else is formatted --- engines/zvision/script_manager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 3a574a3668..9faff18d3c 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -33,7 +33,10 @@ namespace ZVision { -ScriptManager::ScriptManager(ZVision *engine) : _engine(engine), _changeLocation(false) {} +ScriptManager::ScriptManager(ZVision *engine) + : _engine(engine), + _changeLocation(false) { +} void ScriptManager::initialize() { parseScrFile("universe.scr", true); -- cgit v1.2.3 From 9681d7515e769b4db2566b4c17328bb836fe9d41 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:05:38 -0500 Subject: ZVISION: Fix enum qualifiers --- engines/zvision/script_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 9faff18d3c..c8c6f6c621 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -107,8 +107,8 @@ void ScriptManager::checkPuzzleCriteria() { // If it doesn't have the flag ONCE_PER_INST it can be done more than once // Also check that the puzzle isn't disabled if (getStateValue(puzzle->key) == 1 && - (puzzle->flags & Puzzle::StateFlags::ONCE_PER_INST) == Puzzle::StateFlags::ONCE_PER_INST && - (puzzle->flags & Puzzle::StateFlags::DISABLED) == 0) { + (puzzle->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST && + (puzzle->flags & Puzzle::DISABLED) == 0) { continue; } -- cgit v1.2.3 From 553a3ced68914f965a5d86c262d338d2bcfc8095 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:06:11 -0500 Subject: ZVISION: Remove a verbose debug message --- engines/zvision/script_manager.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index c8c6f6c621..da2a3814dc 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -112,8 +112,6 @@ void ScriptManager::checkPuzzleCriteria() { continue; } - debug("Checking puzzle: %u", puzzle->key); - // Check each Criteria bool criteriaMet = false; for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { -- cgit v1.2.3 From ca7680599534aec4f89a65bb5a087e3372488896 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:06:45 -0500 Subject: ZVISION: Fix accidental redeclaration of the scale variable --- engines/zvision/video.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 9f98b14746..b3e32b7703 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -96,7 +96,7 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d // Assume bilinear scaling. AKA calculate the scale from just the width. // Also assume that the scaling is in integral intervals. AKA no 1.5x scaling // TODO: Test ^these^ assumptions - uint scale = destRect.width() / origWidth; + scale = destRect.width() / origWidth; // TODO: Test if we need to support downscale. } -- cgit v1.2.3 From dd77956819091d4a8d3578375fc66a02f4e8283b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:08:22 -0500 Subject: ZVISION: Move SearchMan directory registration outside ZVision constructor The launcher can do some extra changes within SearchMan after engine constructor. This makes sure everything is set before registering more directories --- engines/zvision/zvision.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 0dd62d7a29..72441eb8ad 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -60,17 +60,6 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Do not initialize graphics here - // However this is the place to specify all default directories - const Common::FSNode gameDataDir(ConfMan.get("path")); - // TODO: There are 10 file clashes when we flatten the directories. From a quick look, the files are exactly the same, so it shouldn't matter. But I'm noting it here just in-case it does become a problem. - SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4, true); - SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4, true); - SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4, true); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets1", 0, 2, true); - SearchMan.addSubDirectoryMatching(gameDataDir, "zassets2", 0, 2, true); - SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx", 0, 1, true); - SearchMan.addSubDirectoryMatching(gameDataDir, "zgi", 0, 4, true); - // Here is the right place to set up the engine specific debug channels //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); //DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example"); @@ -101,6 +90,16 @@ ZVision::~ZVision() { } void ZVision::initialize() { + const Common::FSNode gameDataDir(ConfMan.get("path")); + // TODO: There are 10 file clashes when we flatten the directories. From a quick look, the files are exactly the same, so it shouldn't matter. But I'm noting it here just in-case it does become a problem. + SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets1", 0, 2, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "zassets2", 0, 2, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx", 0, 1, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "zgi", 0, 4, true); + // Find zfs archive files Common::ArchiveMemberList list; SearchMan.listMatchingMembers(list, "*.zfs"); -- cgit v1.2.3 From 3e8bc76127a66ad631095de94a57c31aabb7d6b4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:09:19 -0500 Subject: ZVISION: Create MousEvent class to handle mouse hovers/clicks --- engines/zvision/module.mk | 1 + engines/zvision/mouse_event.cpp | 45 ++++++++++++++++++++++++++++++++ engines/zvision/mouse_event.h | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 engines/zvision/mouse_event.cpp create mode 100644 engines/zvision/mouse_event.h (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 7e74b0bfdd..f072520d16 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -11,6 +11,7 @@ MODULE_OBJS := \ detection.o \ events.o \ lzss_read_stream.o \ + mouse_event.o \ render_manager.o \ render_table.o \ scr_file_handling.o \ diff --git a/engines/zvision/mouse_event.cpp b/engines/zvision/mouse_event.cpp new file mode 100644 index 0000000000..a7c9fe5573 --- /dev/null +++ b/engines/zvision/mouse_event.cpp @@ -0,0 +1,45 @@ +/* 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/scummsys.h" + +#include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/mouse_event.h" + +namespace ZVision { + +MouseEvent::MouseEvent(uint32 key, const Common::Rect &hotspot, const Common::String hoverCursor) + : _key(key), + _hotspot(hotspot), + _hoverCursor(hoverCursor) { +} + +bool MouseEvent::withinHotspot(const Common::Point &point) { + return _hotspot.contains(point); +} + +void MouseEvent::onClick(ZVision *engine) { + engine->getScriptManager()->setStateValue(_key, 1); +} + +} // End of namespace ZVision diff --git a/engines/zvision/mouse_event.h b/engines/zvision/mouse_event.h new file mode 100644 index 0000000000..1fbd1603a3 --- /dev/null +++ b/engines/zvision/mouse_event.h @@ -0,0 +1,58 @@ +/* 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 ZVISION_MOUSE_EVENT_H +#define ZVISION_MOUSE_EVENT_H + +#include "common/types.h" +#include "common/rect.h" +#include "common/str.h" + +namespace ZVision { + +class ZVision; + +class MouseEvent { +public: + MouseEvent(uint32 key, const Common::Rect &hotspot, const Common::String hoverCursor); + +private: + /** The Control key */ + uint32 _key; + /** + * The area that will trigger the event + * This is in image space coordinates, NOT screen space + */ + Common::Rect _hotspot; + /** The cursor to use when hovering over _hotspot */ + Common::String _hoverCursor; + +public: + bool withinHotspot(const Common::Point &point); + void onClick(ZVision *engine); + const Common::String getHoverCursor() { return _hoverCursor; } +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 269bed7c7d279e0785056a4e5ba1622317402449 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:10:52 -0500 Subject: ZVISION: Implement mouse event handling --- engines/zvision/events.cpp | 32 ++++++++++++++++++++++++++++++++ engines/zvision/script_manager.cpp | 2 ++ engines/zvision/zvision.h | 7 +++++++ 3 files changed, 41 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 17f48db7fc..79ef0bd6b0 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -28,9 +28,19 @@ #include "engines/util.h" #include "zvision/cursor_manager.h" +#include "zvision/render_manager.h" +#include "zvision/mouse_event.h" namespace ZVision { +void ZVision::registerMouseEvent(const MouseEvent &event) { + _mouseEvents.push_back(event); +} + +void ZVision::clearAllMouseEvents() { + _mouseEvents.clear(); +} + void ZVision::processEvents() { while (_eventMan->pollEvent(_event)) { switch (_event.type) { @@ -84,10 +94,32 @@ void ZVision::onMouseDown(const Common::Point &pos) { void ZVision::onMouseUp(const Common::Point &pos) { _cursorManager->cursorDown(false); + + Common::Point imageCoord(_renderManager->convertToImageCoords(pos)); + + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + if (iter->withinHotspot(imageCoord)) { + iter->onClick(this); + } + } } void ZVision::onMouseMove(const Common::Point &pos) { + Common::Point imageCoord(_renderManager->convertToImageCoords(pos)); + + bool isWithinAHotspot = false; + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + if (iter->withinHotspot(imageCoord)) { + _cursorManager->changeCursor(iter->getHoverCursor()); + isWithinAHotspot = true; + } + } + + + if (!isWithinAHotspot) { + _cursorManager->revertToIdle(); + } } void ZVision::onKeyDown(uint keyCode) { diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index da2a3814dc..03e791720c 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -26,6 +26,7 @@ #include "common/hashmap.h" #include "common/debug.h" +#include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/actions.h" #include "zvision/action_node.h" @@ -207,6 +208,7 @@ void ScriptManager::changeLocationIntern() { _activePuzzles.clear(); // We can clear without deleting from the heap because we use SharedPtr _activeControls.clear(); + _engine->clearAllMouseEvents(); // Parse into puzzles and controls Common::String fileName = Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 8363fb1672..bf42bf2621 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -33,6 +33,7 @@ #include "zvision/detection.h" #include "zvision/clock.h" +#include "zvision/mouse_event.h" #include "gui/debugger.h" @@ -82,6 +83,9 @@ private: // Clock Clock _clock; + // To store the current mouse events + Common::List _mouseEvents; + // To prevent allocation every time we process events Common::Event _event; @@ -99,6 +103,9 @@ public: void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true); + void registerMouseEvent(const MouseEvent &event); + void clearAllMouseEvents(); + void cycleThroughCursors(); private: -- cgit v1.2.3 From 00a17a66d0e8317001829fe36639ef9201d15798 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 15:12:01 -0500 Subject: ZVISION: Implement push_toggle control handling --- engines/zvision/control.cpp | 35 +++++++++++++++++++++++++++++++++++ engines/zvision/control.h | 1 + engines/zvision/scr_file_handling.cpp | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index fdb88c68e1..02d15fe9d0 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -102,4 +102,39 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre renderTable->generateRenderTable(); } +void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream) { + Common::Rect hotspot; + Common::String cursorName; + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + while (!line.contains('}')) { + if (line.matchString("*_hotspot*", true)) { + uint x; + uint y; + uint width; + uint height; + + sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); + + hotspot = Common::Rect(x, y, x + width, y + height); + } else if (line.matchString("cursor*", true)) { + char nameBuffer[25]; + + sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); + + cursorName = Common::String(nameBuffer); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + } + + if (!hotspot.isEmpty() && !cursorName.empty()) { + engine->registerMouseEvent(MouseEvent(key, hotspot, cursorName)); + } +} + } // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index edc0fc2930..2d5426c0c4 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -46,6 +46,7 @@ public: static void parseFlatControl(ZVision *engine); static void parsePanoramaControl(ZVision *engine, Common::SeekableReadStream &stream); static void parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream); + static void parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream); }; } // End of namespace ZVision diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index cd4baa34f0..5b8af48047 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -309,7 +309,8 @@ bool ScriptManager::parseControl(Common::String &line, Common::SeekableReadStrea Common::String controlType(controlTypeBuffer); if (controlType.equalsIgnoreCase("push_toggle")) { - + Control::parsePushToggleControl(key, _engine, stream); + return false; } else if (controlType.equalsIgnoreCase("flat")) { Control::parseFlatControl(_engine); return false; -- cgit v1.2.3 From a49b77cd799a081d04a14f8eeaf8e61b678507bf Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 16:38:10 -0500 Subject: ZVISION: Fix memory leak --- engines/zvision/render_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 2d45ad835d..e705a7f8b4 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -166,6 +166,9 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { return; } + if (_currentBackground != 0) { + delete _currentBackground; + } _currentBackground = file; renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(), true); -- cgit v1.2.3 From 19a2a59c3cf9c9baf8d0366ab59d8a0ec2d0d7e4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 16:39:21 -0500 Subject: ZVISION: Fix unsigned/signed mismatch --- engines/zvision/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index b3e32b7703..ca95a7e5f3 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -47,7 +47,7 @@ void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, for (uint32 x = 0; x < srcWidth; x++) { const byte color = *srcPtr++; - for (int i = 0; i < scaleAmount; i++) { + for (uint i = 0; i < scaleAmount; i++) { dst[i] = color; dst[pitch + i] = color; } @@ -61,11 +61,11 @@ void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, const byte color = *srcPtr++; const byte color2 = *srcPtr++; - for (int i = 0; i < scaleAmount; i++) { dst[i] = color; dst[i + 1] = color2; dst[pitch + i] = color; dst[pitch + i + 1] = color2; + for (uint i = 0; i < scaleAmount; i++) { } dst += 2 * scaleAmount; } -- cgit v1.2.3 From 5ef23e6f8daffd65dd605a28252398d1556760fe Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 16:39:56 -0500 Subject: ZVISION: Restart the Clock after the video finishes --- engines/zvision/video.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index ca95a7e5f3..0d707e7037 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -156,7 +156,7 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d _system->delayMillis(videoDecoder.getTimeToNextFrame()); } - _clock.stop(); + _clock.start(); // Reset the pixel format to the original state initGraphics(_width, _height, true, &_pixelFormat); -- cgit v1.2.3 From e3f352cb0c3247f72dfc1f6fe65c57ada64f9755 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 16:40:32 -0500 Subject: ZVISION: Delete the scaledVideoFrameBuffer after we're done with it --- engines/zvision/video.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 0d707e7037..2a320cb790 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -158,6 +158,8 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d _clock.start(); + delete[] scaledVideoFrameBuffer; + // Reset the pixel format to the original state initGraphics(_width, _height, true, &_pixelFormat); } -- cgit v1.2.3 From d8e45fc438a546bd7e1f8c66e345aafb33bb2a56 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 16:42:40 -0500 Subject: ZVISION: Only allocate memory for the scaled buffer if we're actually going to scale the video --- engines/zvision/video.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 2a320cb790..0836eef496 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -106,7 +106,10 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d uint16 finalWidth = origWidth * scale; uint16 finalHeight = origHeight * scale; - byte *scaledVideoFrameBuffer = new byte[finalWidth * finalHeight * bytesPerPixel]; + byte *scaledVideoFrameBuffer; + if (scale != 1) { + scaledVideoFrameBuffer = new byte[finalWidth * finalHeight * bytesPerPixel]; + } uint16 x = ((_width - finalWidth) / 2) + destRect.left; uint16 y = ((_height - finalHeight) / 2) + destRect.top; @@ -158,7 +161,9 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d _clock.start(); - delete[] scaledVideoFrameBuffer; + if (scale != 1) { + delete[] scaledVideoFrameBuffer; + } // Reset the pixel format to the original state initGraphics(_width, _height, true, &_pixelFormat); -- cgit v1.2.3 From 7e93b6407a14c3c3fe75f03667362fcf8555e69d Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 16:44:13 -0500 Subject: ZVISION: Fix frame scaling for 2bpp --- engines/zvision/video.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 0836eef496..f9637d36a4 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -61,11 +61,13 @@ void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, const byte color = *srcPtr++; const byte color2 = *srcPtr++; - dst[i] = color; - dst[i + 1] = color2; - dst[pitch + i] = color; - dst[pitch + i + 1] = color2; for (uint i = 0; i < scaleAmount; i++) { + uint index = i *2; + + dst[index] = color; + dst[index + 1] = color2; + dst[pitch + index] = color; + dst[pitch + index + 1] = color2; } dst += 2 * scaleAmount; } -- cgit v1.2.3 From b9b8207a140531079f3e200e6858a8dc9cc7b5d2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 16:44:52 -0500 Subject: ZVISION: Dispose of .zfs file streams after processing them --- engines/zvision/zvision.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 72441eb8ad..7f925e9828 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -107,7 +107,10 @@ void ZVision::initialize() { // Register the file entries within the zfs archives with the SearchMan for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { Common::String name = (*iter)->getName(); - ZfsArchive *archive = new ZfsArchive(name, (*iter)->createReadStream()); + Common::SeekableReadStream *stream = (*iter)->createReadStream(); + ZfsArchive *archive = new ZfsArchive(name, stream); + + delete stream; SearchMan.add(name, archive); } -- cgit v1.2.3 From 878fde365ea74e52ec1539f87fee53ed6c8c4279 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:16:42 -0500 Subject: ZVISION: Fix alignment formatting --- engines/zvision/zork_avi_decoder.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_avi_decoder.h b/engines/zvision/zork_avi_decoder.h index 1dff304894..1ce2508828 100644 --- a/engines/zvision/zork_avi_decoder.h +++ b/engines/zvision/zork_avi_decoder.h @@ -47,11 +47,11 @@ private: Video::AVIDecoder::AVIAudioTrack *createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo); - private: - // Audio Codecs - enum { - kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM) - }; +private: + // Audio Codecs + enum { + kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM) + }; }; } // End of namespace ZVision -- cgit v1.2.3 From c020c6bf539d2a9fc4f91a422e1f63d9d9f374b3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:17:24 -0500 Subject: ZVISION: Add check to CursorMan::changeCursor to prevent extraneous cursor changes --- engines/zvision/cursor_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 698168b72a..361fe11714 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -65,6 +65,9 @@ void CursorManager::changeCursor(const Common::String &cursorName) { } void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) { + if (_currentCursor.equals(cursorName) && _cursorIsPushed == pushed) + return; + if (_cursorIsPushed != pushed) _cursorIsPushed = pushed; -- cgit v1.2.3 From 4c1e8b3f453fec9e18743a636bcf2d1c83135c2e Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:18:17 -0500 Subject: ZVISION: Allow CursorManager::revertToIdle to take _cursorIsPushed into account --- engines/zvision/cursor_manager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 361fe11714..0e7c2bc6cd 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -72,7 +72,7 @@ void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) _cursorIsPushed = pushed; if (cursorName == "idle" && !pushed) { - revertToIdle(); + CursorMan.replaceCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); return; } @@ -124,7 +124,10 @@ void CursorManager::cursorDown(bool pushed) { void CursorManager::revertToIdle() { _currentCursor = "idle"; - CursorMan.replaceCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); + if (!_cursorIsPushed) + CursorMan.replaceCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); + else + changeCursor(_currentCursor, _cursorIsPushed); } } // End of namespace ZVision -- cgit v1.2.3 From 003b30c77b34c9447bab3927d206101d5f341b4f Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:18:41 -0500 Subject: ZVISION: Create methods for setting left, right, up, down cursors --- engines/zvision/cursor_manager.cpp | 16 ++++++++++++++++ engines/zvision/cursor_manager.h | 6 ++++++ 2 files changed, 22 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 0e7c2bc6cd..50fa5031b2 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -122,6 +122,22 @@ void CursorManager::cursorDown(bool pushed) { changeCursor(_currentCursor, pushed); } +void CursorManager::setLeftCursor() { + changeCursor("leftarrow"); +} + +void CursorManager::setRightCursor() { + changeCursor("rightarrow"); +} + +void CursorManager::setUpCursor() { + changeCursor("zuparrow"); +} + +void CursorManager::setDownCursor() { + changeCursor("downarrow"); +} + void CursorManager::revertToIdle() { _currentCursor = "idle"; if (!_cursorIsPushed) diff --git a/engines/zvision/cursor_manager.h b/engines/zvision/cursor_manager.h index 496c652c8c..fd61ac25be 100644 --- a/engines/zvision/cursor_manager.h +++ b/engines/zvision/cursor_manager.h @@ -69,6 +69,12 @@ public: void changeCursor(const Common::String &cursorName); void changeCursor(const Common::String &cursorName, bool pushed); void cursorDown(bool pushed); + + void setLeftCursor(); + void setRightCursor(); + void setUpCursor(); + void setDownCursor(); + void revertToIdle(); private: -- cgit v1.2.3 From 54f16f2539d619b7cdb4e43d7de03e1f538a1c1f Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:25:50 -0500 Subject: ZVISION: Create the concept of a working window The working window is a Rect centered inside the actual window edges. All in-game coordinates are in the working window coordinate system. Also, all images in-game are clipped to the edges of the working window. --- engines/zvision/render_manager.cpp | 30 ++++++++++++++++++------------ engines/zvision/render_manager.h | 25 +++++++++++++------------ engines/zvision/video.cpp | 8 ++++---- engines/zvision/zvision.cpp | 7 +++---- engines/zvision/zvision.h | 13 +++++++++++-- 5 files changed, 49 insertions(+), 34 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index e705a7f8b4..7855dc3903 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -34,12 +34,13 @@ namespace ZVision { -RenderManager::RenderManager(OSystem *system, const int width, const int height) +RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow) : _system(system), - _width(width), - _height(height), + _workingWidth(workingWindow.width()), + _workingHeight(workingWindow.height()), + _workingWindow(workingWindow), _currentBackground(0), - _renderTable(width, height) { + _renderTable(workingWindow.width(), workingWindow.height()) { } RenderManager::~RenderManager() { @@ -75,20 +76,19 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty()) return; - // Center the image on the screen if asked - if (autoCenter) { - destRect.moveTo((_width - subRectangle.width()) / 2, (_height - subRectangle.height()) / 2); } _backgroundOffset = Common::Point(destRect.left, destRect.top); if (_renderTable.getRenderState() == RenderTable::FLAT) { - _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left, destRect.top, destRect.width(), destRect.height()); + // Convert destRect to screen space by adding _workingWindowOffset + _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left + _workingWindow.left, destRect.top + _workingWindow.top, destRect.width(), destRect.height()); } else { uint16 *destBuffer = new uint16[destRect.width() * destRect.height()]; _renderTable.mutateImage((uint16 *)buffer, destBuffer, imageWidth, imageHeight, subRectangle, destRect); - _system->copyRectToScreen(destBuffer, subRectangle.width() * sizeof(uint16), destRect.left, destRect.top, destRect.width(), destRect.height()); + // Convert destRect to screen space by adding _workingWindow offest + _system->copyRectToScreen(destBuffer, subRectangle.width() * sizeof(uint16), destRect.left + _workingWindow.left, destRect.top + _workingWindow.top, destRect.width(), destRect.height()); delete[] destBuffer; } } @@ -143,14 +143,20 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint } } -const Common::Point RenderManager::convertToImageCoords(const Common::Point &point) { - Common::Point newPoint(point); +const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { + // Convert from screen space to working window space + Common::Point newPoint(point - Common::Point(_workingWindow.left, _workingWindow.top)); if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { - newPoint = _renderTable.convertWarpedPointToFlatCoords(newPoint); + newPoint = _renderTable.convertWarpedCoordToFlatCoord(newPoint); } newPoint -= _backgroundOffset; + if (newPoint.x < 0) + newPoint.x += _backgroundWidth; + if (newPoint.y < 0) + newPoint.y += _backgroundHeight; + return newPoint; } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index aea24505a9..8731675ef6 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -43,13 +43,14 @@ namespace ZVision { class RenderManager { public: - RenderManager(OSystem *system, const int width, const int height); + RenderManager(OSystem *system, const Common::Rect workingWindow); ~RenderManager(); private: OSystem *_system; - const int _width; - const int _height; + const int _workingWidth; + const int _workingHeight; + const Common::Rect _workingWindow; RenderTable _renderTable; Common::SeekableReadStream *_currentBackground; @@ -63,23 +64,23 @@ public: /** * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. - * The image will be clipped to fit inside the window. + * The image will be clipped to fit inside the working window. Coords are in working window space, not screen space! * * @param fileName Name of the image file - * @param destinationX X position where the image should be put - * @param destinationY Y position where the image should be put - * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. + * @param destinationX X position where the image should be put. Coords are in working window space, not screen space! + * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! + * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool autoCenter = false); /** * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. - * The image will be clipped to fit inside the window. + * The image will be clipped to fit inside the working window. Coords are in working window space, not screen space! * * @param stream Stream to read the image data from - * @param destinationX X position where the image should be put - * @param destinationY Y position where the image should be put - * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. + * @param destinationX X position where the image should be put. Coords are in working window space, not screen space! + * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! + * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool autoCenter = false); @@ -91,7 +92,7 @@ public: */ void setBackgroundImage(const Common::String &fileName); - const Common::Point convertToImageCoords(const Common::Point &point); + const Common::Point screenSpaceToImageSpace(const Common::Point &point); RenderTable *getRenderTable(); diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index f9637d36a4..5497d0af0c 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -80,7 +80,7 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d // Videos use a different pixel format Common::List formats; formats.push_back(videoDecoder.getPixelFormat()); - initGraphics(_width, _height, true, formats); + initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, formats); byte bytesPerPixel = videoDecoder.getPixelFormat().bytesPerPixel; @@ -113,8 +113,8 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d scaledVideoFrameBuffer = new byte[finalWidth * finalHeight * bytesPerPixel]; } - uint16 x = ((_width - finalWidth) / 2) + destRect.left; - uint16 y = ((_height - finalHeight) / 2) + destRect.top; + uint16 x = ((WINDOW_WIDTH - finalWidth) / 2) + destRect.left; + uint16 y = ((WINDOW_HEIGHT - finalHeight) / 2) + destRect.top; _clock.stop(); videoDecoder.start(); @@ -168,7 +168,7 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d } // Reset the pixel format to the original state - initGraphics(_width, _height, true, &_pixelFormat); + initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, &_pixelFormat); } } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 7f925e9828..0f6ec14120 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -49,8 +49,7 @@ namespace ZVision { ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), - _width(640), - _height(480), + _workingWindow((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2, (WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2, ((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2) + WORKING_WINDOW_WIDTH, ((WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2) + WORKING_WINDOW_HEIGHT), _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), /*RGB 555*/ _desiredFrameTime(33), /* ~30 fps */ _clock(_system) { @@ -69,7 +68,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); - _renderManager = new RenderManager(_system, _width, _height); + _renderManager = new RenderManager(_system, _workingWindow); _cursorManager = new CursorManager(this, &_pixelFormat); debug("ZVision::ZVision"); @@ -115,7 +114,7 @@ void ZVision::initialize() { SearchMan.add(name, archive); } - initGraphics(_width, _height, true, &_pixelFormat); + initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, &_pixelFormat); _scriptManager->initialize(); // Has to be done after graphics has been initialized diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index bf42bf2621..ca710804b0 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -64,10 +64,19 @@ public: ~ZVision(); private: + enum { + WINDOW_WIDTH = 640, + WINDOW_HEIGHT = 480, + WORKING_WINDOW_WIDTH = 512, + WORKING_WINDOW_HEIGHT = 320, + + ROTATION_SCREEN_EDGE_OFFSET = 60, + MAX_ROTATION_SPEED = 150 // Pixels per second + }; + Console *_console; const ZVisionGameDescription *_gameDescription; - const int _width; - const int _height; + const Common::Rect _workingWindow; const Graphics::PixelFormat _pixelFormat; const int _desiredFrameTime; -- cgit v1.2.3 From 85c67e5e2f87290bd6669e120c68a71b916c892d Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:26:58 -0500 Subject: ZVISION: Implement ZVISION::getCursorManager() --- engines/zvision/zvision.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 0f6ec14120..f7e0ab821d 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -167,6 +167,10 @@ RenderManager *ZVision::getRenderManager() const { return _renderManager; } +CursorManager *ZVision::getCursorManager() const { + return _cursorManager; +} + Common::RandomSource *ZVision::getRandomSource() const { return _rnd; } -- cgit v1.2.3 From 65853bfe2ba4c7e526cce5d232efb6f645a9c96d Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:28:01 -0500 Subject: ZVISION: Fix header #defines to match their file names --- engines/zvision/actions.h | 4 ++-- engines/zvision/single_value_container.h | 4 ++-- engines/zvision/vector2.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 8e00cb5e53..511f3d9b83 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -20,8 +20,8 @@ * */ -#ifndef ZVISION_RESULT_ACTION_H -#define ZVISION_RESULT_ACTION_H +#ifndef ZVISION_ACTIONS_H +#define ZVISION_ACTIONS_H #include "common/scummsys.h" diff --git a/engines/zvision/single_value_container.h b/engines/zvision/single_value_container.h index 54677ff0a1..45b5a89e95 100644 --- a/engines/zvision/single_value_container.h +++ b/engines/zvision/single_value_container.h @@ -20,8 +20,8 @@ * */ -#ifndef ZVISION_OBJECT_H -#define ZVISION_OBJECT_H +#ifndef ZVISION_SINGLE_VALUE_CONTAINER_H +#define ZVISION_SINGLE_VALUE_CONTAINER_H namespace Common { class String; diff --git a/engines/zvision/vector2.h b/engines/zvision/vector2.h index d301aef4c6..575915c87d 100644 --- a/engines/zvision/vector2.h +++ b/engines/zvision/vector2.h @@ -20,8 +20,8 @@ * */ -#ifndef COMMON_ZVISION_POINT_H -#define COMMON_ZVISION_POINT_H +#ifndef ZVISION_VECTOR2_H +#define ZVISION_VECTOR2_H #include "common/scummsys.h" -- cgit v1.2.3 From 39934b1da7c6a7c0cf0a8d1e01af981ad83d09f0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:29:16 -0500 Subject: ZVISION: Set the initial game location (The opening video and menu) --- engines/zvision/script_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 03e791720c..93564ee6ad 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -41,6 +41,7 @@ ScriptManager::ScriptManager(ZVision *engine) void ScriptManager::initialize() { parseScrFile("universe.scr", true); + changeLocation('g', 'a', 'r', 'y', 0); } void ScriptManager::update(uint deltaTimeMillis) { -- cgit v1.2.3 From 1dcc56f7d27717f0ea0becd027639a41a37f6f2f Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:36:52 -0500 Subject: ZVISION: Slight function name change to increase clarity --- engines/zvision/render_table.cpp | 2 +- engines/zvision/render_table.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 2a111ce659..ba506b1206 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -60,7 +60,7 @@ void RenderTable::setRenderState(RenderState newState) { } } -const Common::Point RenderTable::convertWarpedPointToFlatCoords(const Common::Point &point) { +const Common::Point RenderTable::convertWarpedCoordToFlatCoord(const Common::Point &point) { uint32 index = point.y * _numColumns + point.x; Common::Point newPoint(point); diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 5cef062045..c38b5a6f0b 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -64,7 +64,7 @@ public: RenderState getRenderState() { return _renderState; } void setRenderState(RenderState newState); - const Common::Point convertWarpedPointToFlatCoords(const Common::Point &point); + const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle); void generateRenderTable(); -- cgit v1.2.3 From d8f9be74ff63d2ab21f23e6c1520a7bdebdf1286 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:41:20 -0500 Subject: ZVISION: Add panning support --- engines/zvision/events.cpp | 92 +++++++++++++++++++++++++++++++++++--- engines/zvision/render_manager.cpp | 62 +++++++++++++++++++++++++ engines/zvision/render_manager.h | 10 +++++ 3 files changed, 157 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 79ef0bd6b0..68fa81ede3 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -26,6 +26,8 @@ #include "zvision/console.h" #include "common/events.h" #include "engines/util.h" +#include "common/system.h" +#include "common/rational.h" #include "zvision/cursor_manager.h" #include "zvision/render_manager.h" @@ -95,7 +97,7 @@ void ZVision::onMouseDown(const Common::Point &pos) { void ZVision::onMouseUp(const Common::Point &pos) { _cursorManager->cursorDown(false); - Common::Point imageCoord(_renderManager->convertToImageCoords(pos)); + Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { if (iter->withinHotspot(imageCoord)) { @@ -105,17 +107,93 @@ void ZVision::onMouseUp(const Common::Point &pos) { } void ZVision::onMouseMove(const Common::Point &pos) { - Common::Point imageCoord(_renderManager->convertToImageCoords(pos)); + Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); bool isWithinAHotspot = false; - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - if (iter->withinHotspot(imageCoord)) { - _cursorManager->changeCursor(iter->getHoverCursor()); - isWithinAHotspot = true; + if (_workingWindow.contains(pos)) { + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + if (iter->withinHotspot(imageCoord)) { + _cursorManager->changeCursor(iter->getHoverCursor()); + isWithinAHotspot = true; + } } } - + // Graph of the function governing rotation velocity: + // + // |--------------- working window -----------------| + // ^ |--------| + // | | + // +Max velocity | rotation screen edge offset _____________________ + // | / + // | / + // | / + // | / + // | / + // | / + // | / + // | / + // | / + // Zero velocity |______________________________ ______________________________/____________________________________> + // | Position -> / + // | / + // | / + // | / + // | / + // | / + // | / + // | / + // | / + // -Max velocity |_____________________/ + // | + // | + // ^ + + // NOTE: RenderManger uses the inverse of velocity (ms/pixel instead of pixels/ms) because it allows you to accumulate whole + // pixels 'steps' instead of rounding pixels every frame + + if (_workingWindow.contains(pos)) { + RenderTable::RenderState renderState = _renderManager->getRenderTable()->getRenderState(); + if (renderState == RenderTable::PANORAMA) { + if (pos.x >= _workingWindow.left && pos.x < _workingWindow.left + ROTATION_SCREEN_EDGE_OFFSET) { + // Linear function of distance to the left edge (y = -mx + b) + // We use fixed point math to get better accuracy + Common::Rational velocity = (Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.x - _workingWindow.left)) - MAX_ROTATION_SPEED; + _renderManager->setBackgroundVelocity(velocity.toInt()); + _cursorManager->setLeftCursor(); + isWithinAHotspot = true; + } else if (pos.x <= _workingWindow.right && pos.x > _workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET) { + // Linear function of distance to the right edge (y = mx) + // We use fixed point math to get better accuracy + Common::Rational velocity = Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.x - _workingWindow.right + ROTATION_SCREEN_EDGE_OFFSET); + _renderManager->setBackgroundVelocity(velocity.toInt()); + _cursorManager->setRightCursor(); + isWithinAHotspot = true; + } else { + _renderManager->setBackgroundVelocity(0); + } + } else if (renderState == RenderTable::TILT) { + if (pos.y >= _workingWindow.top && pos.y < _workingWindow.top + ROTATION_SCREEN_EDGE_OFFSET) { + // Linear function of distance to top edge + // We use fixed point math to get better accuracy + Common::Rational velocity = (Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.top)) - MAX_ROTATION_SPEED; + _renderManager->setBackgroundVelocity(velocity.toInt()); + _cursorManager->setUpCursor(); + isWithinAHotspot = true; + } else if (pos.y <= _workingWindow.bottom && pos.y > _workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET) { + // Linear function of distance to the bottom edge (y = mx) + // We use fixed point math to get better accuracy + Common::Rational velocity = Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.bottom + ROTATION_SCREEN_EDGE_OFFSET); + _renderManager->setBackgroundVelocity(velocity.toInt()); + _cursorManager->setDownCursor(); + isWithinAHotspot = true; + } else { + _renderManager->setBackgroundVelocity(0); + } + } + } else { + _renderManager->setBackgroundVelocity(0); + } if (!isWithinAHotspot) { _cursorManager->revertToIdle(); diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 7855dc3903..b8dcd0dd87 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -40,6 +40,10 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow) _workingHeight(workingWindow.height()), _workingWindow(workingWindow), _currentBackground(0), + _backgroundWidth(0), + _backgroundHeight(0), + _backgroundInverseVelocity(0), + _accumulatedVelocityMilliseconds(0), _renderTable(workingWindow.width(), workingWindow.height()) { } @@ -56,6 +60,24 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin uint32 temp = imageHeight; imageHeight = imageWidth; imageWidth = temp; +void RenderManager::update(uint deltaTimeInMillis) { + // An inverse velocity of 0 would be infinitely fast, so we'll let 0 mean no velocity. + if (_backgroundInverseVelocity == 0) + return; + + _accumulatedVelocityMilliseconds += deltaTimeInMillis; + + int absVelocity = abs(_backgroundInverseVelocity); + + uint numberOfSteps = 0; + while (_accumulatedVelocityMilliseconds >= absVelocity) { + _accumulatedVelocityMilliseconds -= absVelocity; + numberOfSteps++; + } + + // Choose the direction of movement using the sign of the velocity + moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps); +} } // If subRect is empty, use the entire image @@ -178,6 +200,46 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { _currentBackground = file; renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(), true); +void RenderManager::setBackgroundPosition(int offset) { + if (_renderTable.getRenderState() == RenderTable::TILT) { + _backgroundOffset = Common::Point(0, offset); + } else { + _backgroundOffset = Common::Point(offset, 0); + } +} + +void RenderManager::setBackgroundVelocity(int velocity) { + // setBackgroundVelocity(0) will be called quite often, so make sure + // _backgroundInverseVelocity isn't already 0 to prevent an extraneous assignment + if (velocity == 0) { + if (_backgroundInverseVelocity != 0) { + _backgroundInverseVelocity = 0; + } + } else { + _backgroundInverseVelocity = 1000 / velocity; + } +} + +void RenderManager::moveBackground(int offset) { + if (_renderTable.getRenderState() == RenderTable::TILT) { + _backgroundOffset += Common::Point(0, offset); + } else { + _backgroundOffset += Common::Point(offset, 0); + } + + // Make sure the offset is within image bounds + if (_backgroundOffset.x < 0) + _backgroundOffset.x += _backgroundWidth; + if (_backgroundOffset.x > _backgroundWidth) + _backgroundOffset.x -= _backgroundWidth; + if (_backgroundOffset.y < 0) + _backgroundOffset.y += _backgroundHeight; + if (_backgroundOffset.y > _backgroundHeight) + _backgroundOffset.y -= _backgroundHeight; + + _currentBackground->seek(0); + // Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically. + renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); } } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 8731675ef6..7d44a37726 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -55,12 +55,18 @@ private: Common::SeekableReadStream *_currentBackground; Common::Point _backgroundOffset; + uint16 _backgroundWidth; + uint16 _backgroundHeight; + + int _backgroundInverseVelocity; + uint _accumulatedVelocityMilliseconds; Video::VideoDecoder *_currentVideo; byte *_scaledVideoFrameBuffer; public: void initialize(); + void update(uint deltaTimeInMillis); /** * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. @@ -92,6 +98,10 @@ public: */ void setBackgroundImage(const Common::String &fileName); + void setBackgroundPosition(int offset); + + void setBackgroundVelocity(int velocity); + const Common::Point screenSpaceToImageSpace(const Common::Point &point); RenderTable *getRenderTable(); -- cgit v1.2.3 From 8d57880c51f29374a745c2060260fd222a26afe4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:43:37 -0500 Subject: ZVISION: Clip coords outside the working window --- engines/zvision/render_table.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index ba506b1206..aab4735d81 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -61,6 +61,13 @@ void RenderTable::setRenderState(RenderState newState) { } const Common::Point RenderTable::convertWarpedCoordToFlatCoord(const Common::Point &point) { + // If we're outside the range of the RenderTable, no warping is happening. Return the maximum image coords + if (point.x >= _numColumns || point.y >= _numRows) { + int16 x = CLIP(point.x, 0, _numColumns); + int16 y = CLIP(point.y, 0, _numRows); + return Common::Point(x, y); + } + uint32 index = point.y * _numColumns + point.x; Common::Point newPoint(point); -- cgit v1.2.3 From 6be19d850abd9123960c6f4bcf00ba73d5549953 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:45:04 -0500 Subject: ZVISION: Add background image wrapping There is still a discontinuity when wrapping, but I am committing so that others can look at the code --- engines/zvision/render_manager.cpp | 106 ++++++++++++++++++++++++++++--------- engines/zvision/render_manager.h | 11 ++-- 2 files changed, 88 insertions(+), 29 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b8dcd0dd87..78fcf59a56 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -53,13 +53,6 @@ RenderManager::~RenderManager() { } } -void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter) { - // Panoramas are transposed - // The actual data is transposed in mutateImage - if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { - uint32 temp = imageHeight; - imageHeight = imageWidth; - imageWidth = temp; void RenderManager::update(uint deltaTimeInMillis) { // An inverse velocity of 0 would be infinitely fast, so we'll let 0 mean no velocity. if (_backgroundInverseVelocity == 0) @@ -78,29 +71,72 @@ void RenderManager::update(uint deltaTimeInMillis) { // Choose the direction of movement using the sign of the velocity moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps); } + +void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { + if (wrap) { + _backgroundWidth = imageWidth; + _backgroundHeight = imageHeight; } // If subRect is empty, use the entire image if (subRectangle.isEmpty()) - subRectangle = Common::Rect(imageWidth, imageHeight); + subRectangle = Common::Rect(subRectangle.left, subRectangle.top, subRectangle.left + imageWidth, subRectangle.top + imageHeight); - // Clip to image bounds - subRectangle.clip(imageWidth, imageHeight); - // Clip destRect to screen bounds + // Clip destRect to working window bounds Common::Rect destRect(destinationX, destinationY, destinationX + subRectangle.width(), destinationY + subRectangle.height()); - destRect.clip(_width, _height); - // Clip subRect to screen bounds + destRect.clip(_workingWidth, _workingHeight); + // Clip subRect to working window bounds subRectangle.translate(destRect.left - destinationX, destRect.top - destinationY); subRectangle.setWidth(destRect.width()); subRectangle.setHeight(destRect.height()); + // Clip to image bounds + Common::Point subRectOrigOrigin(subRectangle.left, subRectangle.top); + subRectangle.clip(imageWidth, imageHeight); - // Check for validity - if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty()) - return; + // If the image is to be wrapped, check if it's smaller than destRect + // If it is, then call renderSubRectToScreen with a subRect representing wrapping + if (wrap && subRectangle.width() < destRect.width()) { + uint32 wrapDestX; + uint32 wrapDestY; + Common::Rect wrapSubRect; + + if (_backgroundWidth - subRectangle.left < destRect.width()) { + wrapDestX = destRect.left + subRectangle.width(); + wrapDestY = destRect.top; + wrapSubRect = Common::Rect(0, 0, destRect.width() - subRectangle.width(), subRectangle.bottom); + } else { + wrapDestX = destRect.left; + wrapDestY = destRect.top; + wrapSubRect = Common::Rect(_backgroundWidth - subRectangle.width(), 0, _backgroundWidth - 1, subRectangle.bottom); + } + renderSubRectToScreen(buffer, imageWidth, imageHeight, horizontalPitch, wrapDestX, wrapDestY, wrapSubRect, false); + } else if (wrap && subRectangle.height() < destRect.height()) { + uint32 wrapDestX; + uint32 wrapDestY; + Common::Rect wrapSubRect; + + if (_backgroundHeight - subRectangle.top < destRect.height()) { + wrapDestX = destRect.left; + wrapDestY = destRect.height() - subRectangle.height(); + wrapSubRect = Common::Rect(0, 0, subRectangle.right, destRect.height() - subRectangle.height()); + } else { + wrapDestX = destRect.left; + wrapDestY = destRect.top; + wrapSubRect = Common::Rect(0, _backgroundHeight - subRectangle.height(), subRectangle.right, _backgroundHeight - 1); + } + + renderSubRectToScreen(buffer, imageWidth, imageHeight, horizontalPitch, wrapDestX, wrapDestY, wrapSubRect, false); } - _backgroundOffset = Common::Point(destRect.left, destRect.top); + // Clip destRect to image bounds + destRect.translate(subRectangle.left - subRectOrigOrigin.x, subRectangle.top - subRectOrigOrigin.y); + destRect.setWidth(subRectangle.width()); + destRect.setHeight(subRectangle.height()); + + // Check all Rects for validity + if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty()) + return; if (_renderTable.getRenderState() == RenderTable::FLAT) { // Convert destRect to screen space by adding _workingWindowOffset @@ -109,13 +145,13 @@ void RenderManager::update(uint deltaTimeInMillis) { uint16 *destBuffer = new uint16[destRect.width() * destRect.height()]; _renderTable.mutateImage((uint16 *)buffer, destBuffer, imageWidth, imageHeight, subRectangle, destRect); - // Convert destRect to screen space by adding _workingWindow offest + // Convert destRect to screen space by adding _workingWindow offset _system->copyRectToScreen(destBuffer, subRectangle.width() * sizeof(uint16), destRect.left + _workingWindow.left, destRect.top + _workingWindow.top, destRect.width(), destRect.height()); delete[] destBuffer; } } -void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter) { +void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { Common::File file; if (!file.open(fileName)) { @@ -123,10 +159,10 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d return; } - renderImageToScreen(file, destinationX, destinationY, subRectangle, autoCenter); + renderImageToScreen(file, destinationX, destinationY, subRectangle); } -void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter) { +void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { // Read the magic number // Some files are true TGA, while others are TGZ uint32 fileType; @@ -145,7 +181,15 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint uint32 horizontalPitch = imageWidth * sizeof(uint16); - renderSubRectToScreen((uint16 *)buffer, imageWidth, imageHeight, horizontalPitch, destinationX, destinationY, subRectangle, autoCenter); + // Panoramas are transposed + // The actual data is transposed in mutateImage + if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { + uint32 temp = imageHeight; + imageHeight = imageWidth; + imageWidth = temp; + } + + renderSubRectToScreen((uint16 *)buffer, imageWidth, imageHeight, horizontalPitch, destinationX, destinationY, subRectangle, wrap); delete[] buffer; } else { // Reset the cursor @@ -159,8 +203,19 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint } const Graphics::Surface *tgaSurface = tga.getSurface(); - renderSubRectToScreen((uint16 *)tgaSurface->pixels, tgaSurface->w, tgaSurface->h, tgaSurface->pitch, destinationX, destinationY, subRectangle, autoCenter); + uint32 imageWidth = tgaSurface->w; + uint32 imageHeight = tgaSurface->h; + + // Panoramas are transposed + // The actual data is transposed in mutateImage + if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { + uint32 temp = imageHeight; + imageHeight = imageWidth; + imageWidth = temp; + } + + renderSubRectToScreen((uint16 *)tgaSurface->pixels, tgaSurface->w, tgaSurface->h, tgaSurface->pitch, destinationX, destinationY, subRectangle, wrap); tga.destroy(); } } @@ -199,7 +254,10 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { } _currentBackground = file; - renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(), true); + // Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically. + renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); +} + void RenderManager::setBackgroundPosition(int offset) { if (_renderTable.getRenderState() == RenderTable::TILT) { _backgroundOffset = Common::Point(0, offset); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 7d44a37726..a394586380 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -61,7 +61,6 @@ private: int _backgroundInverseVelocity; uint _accumulatedVelocityMilliseconds; - Video::VideoDecoder *_currentVideo; byte *_scaledVideoFrameBuffer; public: @@ -77,7 +76,7 @@ public: * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ - void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool autoCenter = false); + void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); /** * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. @@ -88,7 +87,7 @@ public: * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ - void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool autoCenter = false); + void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); /** * Sets the current background image to be used by the RenderManager and immediately @@ -99,7 +98,7 @@ public: void setBackgroundImage(const Common::String &fileName); void setBackgroundPosition(int offset); - + void setBackgroundVelocity(int velocity); const Common::Point screenSpaceToImageSpace(const Common::Point &point); @@ -107,7 +106,9 @@ public: RenderTable *getRenderTable(); private: - void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter); + void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap); + + void moveBackground(int offset); }; } // End of namespace ZVision -- cgit v1.2.3 From 0fe3ae711a4a2fb20e6fb23664b18cdda8400c9b Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:45:39 -0500 Subject: ZVISION: Add cursor and background image resets during location change --- engines/zvision/script_manager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 93564ee6ad..6aaf5773e0 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -28,6 +28,8 @@ #include "zvision/zvision.h" #include "zvision/script_manager.h" +#include "zvision/render_manager.h" +#include "zvision/cursor_manager.h" #include "zvision/actions.h" #include "zvision/action_node.h" #include "zvision/utility.h" @@ -211,6 +213,15 @@ void ScriptManager::changeLocationIntern() { _activeControls.clear(); _engine->clearAllMouseEvents(); + // Revert to the idle cursor + _engine->getCursorManager()->revertToIdle(); + + // Change the background position + _engine->getRenderManager()->setBackgroundPosition(_nextLocation.x); + + // Reset the background velocity + _engine->getRenderManager()->setBackgroundVelocity(0); + // Parse into puzzles and controls Common::String fileName = Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view); parseScrFile(fileName); -- cgit v1.2.3 From 9b8bad3c834ebb4287305d86cdb991f565738814 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 10:46:12 -0500 Subject: ZVISION: Add _renderManager::update() to ZEngene::run() --- engines/zvision/zvision.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index f7e0ab821d..2090d8abfe 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -116,9 +116,8 @@ void ZVision::initialize() { initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, &_pixelFormat); - _scriptManager->initialize(); - // Has to be done after graphics has been initialized _cursorManager->initialize(); + _scriptManager->initialize(); // Create debugger console. It requires GFX to be initialized _console = new Console(this); @@ -131,10 +130,12 @@ Common::Error ZVision::run() { while (!shouldQuit()) { _clock.update(); uint32 currentTime = _clock.getLastMeasuredTime(); - + uint32 deltaTime = _clock.getDeltaTime(); + processEvents(); - _scriptManager->update(_clock.getDeltaTime()); + _scriptManager->update(deltaTime); + _renderManager->update(deltaTime); // Update the screen _system->updateScreen(); -- cgit v1.2.3 From 4e827b4dda458813dce650545b6f9fb923c514f4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 12:04:13 -0500 Subject: ZVISION: Add documentation --- engines/zvision/cursor.h | 4 +++ engines/zvision/cursor_manager.h | 28 ++++++++++++++++++++ engines/zvision/mouse_event.h | 16 +++++++++++ engines/zvision/render_manager.h | 57 ++++++++++++++++++++++++++++++++++++++++ engines/zvision/zvision.h | 28 ++++++++++++++++++++ 5 files changed, 133 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor.h b/engines/zvision/cursor.h index 77093c4daf..9a561fcac3 100644 --- a/engines/zvision/cursor.h +++ b/engines/zvision/cursor.h @@ -33,6 +33,10 @@ class String; namespace ZVision { +/** + * Utility class to parse and hold cursor data + * Modeled off Graphics::Cursor + */ class ZorkCursor { public: ZorkCursor(); diff --git a/engines/zvision/cursor_manager.h b/engines/zvision/cursor_manager.h index fd61ac25be..1c09620b7e 100644 --- a/engines/zvision/cursor_manager.h +++ b/engines/zvision/cursor_manager.h @@ -64,20 +64,48 @@ private: static const char *_zNemCursorFileNames[]; public: + /** Creates the idle cursor and shows it */ void initialize(); + /** + * Parses a cursor name into a cursor file then creates and shows that cursor. + * It will use the current _isCursorPushed state to choose the correct cursor + * + * @param cursorName The name of a cursor. This *HAS* to correspond to one of the entries in _cursorNames[] + */ void changeCursor(const Common::String &cursorName); + /** + * Parses a cursor name into a cursor file then creates and shows that cursor. + * + * @param cursorName The name of a cursor. This *HAS* to correspond to one of the entries in _cursorNames[] + * @param pushed Should the cursor be pushed (true) or not pushed (false) (Another way to say it: down or up) + */ void changeCursor(const Common::String &cursorName, bool pushed); + /** + * Change the cursor to a certain push state. If the cursor is already in the specified push state, nothing will happen. + * + * @param pushed Should the cursor be pushed (true) or not pushed (false) (Another way to say it: down or up) + */ void cursorDown(bool pushed); + /** Set the cursor to 'Left Arrow'. It will retain the current _isCursorPushed state */ void setLeftCursor(); + /** Set the cursor to 'Right Arrow'. It will retain the current _isCursorPushed state */ void setRightCursor(); + /** Set the cursor to 'Up Arrow'. It will retain the current _isCursorPushed state */ void setUpCursor(); + /** Set the cursor to 'Down Arrow'. It will retain the current _isCursorPushed state */ void setDownCursor(); + /** Set the cursor to 'Idle'. It will retain the current _isCursorPushed state */ void revertToIdle(); private: + /** + * Calls CursorMan.replaceCursor() using the data in cursor + * + * @param cursor The cursor to show + */ void changeCursor(const ZorkCursor &cursor); }; diff --git a/engines/zvision/mouse_event.h b/engines/zvision/mouse_event.h index 1fbd1603a3..5537bcc4e5 100644 --- a/engines/zvision/mouse_event.h +++ b/engines/zvision/mouse_event.h @@ -48,8 +48,24 @@ private: Common::String _hoverCursor; public: + /** + * Does a simple Rect::contains() using _hotspot + * + * @param point The point to check against _hotspot + * @return The point is inside _hotspot (true) or not (false) + */ bool withinHotspot(const Common::Point &point); + /** + * Calls ScriptManager::setStateValue(_key, 1) + * + * @param engine The base engine + */ void onClick(ZVision *engine); + /** + * Gets the name of the cursor that should be displayed when withinHotspot returns true + * + * @return The name of the cursor. This should correspond to one of the names in CursorManager::_cursorNames[] + */ const Common::String getHoverCursor() { return _hoverCursor; } }; diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index a394586380..073a2f61e0 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -48,23 +48,45 @@ public: private: OSystem *_system; + + /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ const int _workingWidth; + /** Height of the working window. Saved to prevent extraneous calls to _workingWindow.height() */ const int _workingHeight; + /** + * A Rectangle centered inside the actual window. All in-game coordinates + * are given in this coordinate space. Also, all images are clipped to the + * edges of this Rectangle + */ const Common::Rect _workingWindow; + /** Used to warp the background image */ RenderTable _renderTable; Common::SeekableReadStream *_currentBackground; + /** The (x1,y1) coordinates of the subRectangle of the background that is currently displayed on the screen */ Common::Point _backgroundOffset; + /** The width of the current background image */ uint16 _backgroundWidth; + /** The height of the current background image */ uint16 _backgroundHeight; + /** + * The "velocity" at which the background image is panning. We actually store the inverse of velocity (ms/pixel instead of pixels/ms) + * because it allows you to accumulate whole pixels 'steps' instead of rounding pixels every frame + */ int _backgroundInverseVelocity; + /** Holds any 'leftover' milliseconds between frames */ uint _accumulatedVelocityMilliseconds; byte *_scaledVideoFrameBuffer; public: void initialize(); + /** + * Rotates the background image in accordance to the current _backgroundInverseVelocity + * + * @param deltaTimeInMillis The amount of time that has passed since the last frame + */ void update(uint deltaTimeInMillis); /** @@ -97,15 +119,50 @@ public: */ void setBackgroundImage(const Common::String &fileName); + /** + * Set the background position (_backgroundOffset). If the current RenderState is PANORAMA, the offset + * will be in the horizontal direction. If the current RenderState is TILT, the offset will be in the + * vertical direction. + * + * This method will not render anything on the screen. So if nothing else is called that renders the + * background, the change won't be seen until next frame. + * + * @param offset The amount to offset the background + */ void setBackgroundPosition(int offset); + /** + * Set the background scroll velocity. Negative velocities correspond to left / up scrolling and + * positive velocities correspond to right / down scrolling + * + * @param velocity Velocity + */ void setBackgroundVelocity(int velocity); + /** + * Converts a point in screen coordinate space to image coordinate space + * + * @param point Point in screen coordinate space + * @return Point in image coordinate space + */ const Common::Point screenSpaceToImageSpace(const Common::Point &point); RenderTable *getRenderTable(); private: + /** + * Renders a subRectangle of an image to the screen. The destinationRect and SubRect + * will be clipped to image bound and to working window bounds + * + * @param buffer Pointer to (0, 0) of the image data + * @param imageWidth The width of the original image (not of the subRectangle) + * @param imageHeight The width of the original image (not of the subRectangle) + * @param horizontalPitch The horizontal pitch of the original image + * @param destinationX The x coordinate (in working window space) of where to put the final image + * @param destinationY The y coordinate (in working window space) of where to put the final image + * @param subRectangle A rectangle representing the part of the image that should be rendered + * @param wrap Should the image wrap (tile) if it doesn't completely fill the screen? + */ void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap); void moveBackground(int offset); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index ca710804b0..58812d4d11 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -76,6 +76,11 @@ private: Console *_console; const ZVisionGameDescription *_gameDescription; + /** + * A Rectangle centered inside the actual window. All in-game coordinates + * are given in this coordinate space. Also, all images are clipped to the + * edges of this Rectangle + */ const Common::Rect _workingWindow; const Graphics::PixelFormat _pixelFormat; @@ -110,17 +115,40 @@ public: Common::RandomSource *getRandomSource() const; ZVisionGameId getGameId() const; + /** + * Play a video until it is finished. This is a blocking call. It will call + * _clock.stop() when the video starts and _clock.start() when the video finishes. + * It will also consume all events during video playback. + * + * @param videoDecoder The video to play + * @param destRect Where to put the video. (In working window coords) + * @param skippable If true, the video can be skipped at any time using [Spacebar] + */ void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true); + /** + * Register a MouseEvent with the event system. These will be checked at every + * MOUSE_UP, MOUSE_DOWN, MOUSE_MOVE, etc. + * + * @param event The event to register + */ void registerMouseEvent(const MouseEvent &event); + /** Remove all MouseEvents from the event system */ void clearAllMouseEvents(); + /** + * Utility method to cycle through all the cursors in the game. After + * calling, use Left and Right arrows to cycle. Esc to quit. This is a + * blocking function call. + */ void cycleThroughCursors(); private: void initialize(); + /** Called every frame from ZVision::run() to process any events from EventMan */ void processEvents(); + void onMouseDown(const Common::Point &pos); void onMouseUp(const Common::Point &pos); void onMouseMove(const Common::Point &pos); -- cgit v1.2.3 From 435419cfe91eefa3a709af91f2ab172c3cbde022 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 12:12:34 -0500 Subject: ZVISION: Modify ASCII velocity drawing to represent the actual code Velocity outside the working window is zero --- engines/zvision/events.cpp | 49 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 68fa81ede3..ca96f52457 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -121,37 +121,34 @@ void ZVision::onMouseMove(const Common::Point &pos) { // Graph of the function governing rotation velocity: // - // |--------------- working window -----------------| - // ^ |--------| + // |---------------- working window ------------------| + // ^ |---------| // | | - // +Max velocity | rotation screen edge offset _____________________ - // | / - // | / - // | / - // | / - // | / - // | / - // | / - // | / - // | / - // Zero velocity |______________________________ ______________________________/____________________________________> - // | Position -> / - // | / - // | / - // | / - // | / - // | / - // | / - // | / - // | / - // -Max velocity |_____________________/ + // +Max velocity | rotation screen edge offset + // | /| + // | / | + // | / | + // | / | + // | / | + // | / | + // | / | + // | / | + // | / | + // Zero velocity |______________________________ ______________________________/_________|__________________________> + // | Position -> | / + // | | / + // | | / + // | | / + // | | / + // | | / + // | | / + // | | / + // | | / + // -Max velocity | |/ // | // | // ^ - // NOTE: RenderManger uses the inverse of velocity (ms/pixel instead of pixels/ms) because it allows you to accumulate whole - // pixels 'steps' instead of rounding pixels every frame - if (_workingWindow.contains(pos)) { RenderTable::RenderState renderState = _renderManager->getRenderTable()->getRenderState(); if (renderState == RenderTable::PANORAMA) { -- cgit v1.2.3 From c0305d9534763d69223cb6a5ea20d20101236401 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 14 Aug 2013 18:05:13 -0500 Subject: ZVISION: Rename variables and add comments to clarify the math behind panorama warping --- engines/zvision/render_table.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index aab4735d81..3bd0103054 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -149,26 +149,32 @@ void RenderTable::generatePanoramaLookupTable() { float halfWidth = (float)_numColumns / 2.0f; float halfHeight = (float)_numRows / 2.0f; - float fovRadians = (_panoramaOptions.fieldOfView * M_PI / 180.0f); - float halfHeightOverTan = halfHeight / tan(fovRadians); - float tanOverHalfHeight = tan(fovRadians) / halfHeight; + float fovInRadians = (_panoramaOptions.fieldOfView * M_PI / 180.0f); + float cylinderRadius = halfHeight / tan(fovInRadians); // TODO: Change the algorithm to write a whole row at a time instead of a whole column at a time. AKA: for(y) { for(x) {}} instead of for(x) { for(y) {}} for (uint x = 0; x < _numColumns; x++) { // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) - float temp = atan(tanOverHalfHeight * ((float)x - halfWidth + 0.01f)); + // Alpha represents the horizontal angle between the viewer at the center of a cylinder and x + float alpha = atan(((float)x - halfWidth + 0.01f) / cylinderRadius); - int32 newX = int32(floor((halfHeightOverTan * _panoramaOptions.linearScale * temp) + halfWidth)); - float cosX = cos(temp); + // To get x in cylinder coordinates, we just need to calculate the arc length + // We also scale it by _panoramaOptions.linearScale + int32 xInCylinderCoords = int32(floor((cylinderRadius * _panoramaOptions.linearScale * alpha) + halfWidth)); + + + float cosAlpha = cos(alpha); for (uint y = 0; y < _numRows; y++) { - int32 newY = int32(floor(halfHeight + ((float)y - halfHeight) * cosX)); + // To calculate y in cylinder coordinates, we can do similar triangles comparison, + // comparing the triangle from the center to the screen and from the center to the edge of the cylinder + int32 yInCylinderCoords = int32(floor(halfHeight + ((float)y - halfHeight) * cosAlpha)); uint32 index = y * _numColumns + x; - // Only store the x,y offsets instead of the absolute positions - _internalBuffer[index].x = newX - x; - _internalBuffer[index].y = newY - y; + // Only store the (x,y) offsets instead of the absolute positions + _internalBuffer[index].x = xInCylinderCoords - x; + _internalBuffer[index].y = yInCylinderCoords - y; } } } -- cgit v1.2.3 From 08a8ab885bf6a2eea1f0eb9d7526cdbe240561e6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 15 Aug 2013 13:35:39 -0500 Subject: ZVISION: Apply panorama/tilt warping after all images have been rendered to a backbuffer This makes wrapped warping much easier as well as allowing changeLocation offsets to work properly --- engines/zvision/console.cpp | 4 +- engines/zvision/render_manager.cpp | 125 +++++++++++++++++++++---------------- engines/zvision/render_manager.h | 22 ++++--- engines/zvision/render_table.cpp | 21 ++----- engines/zvision/render_table.h | 2 +- engines/zvision/zvision.cpp | 2 +- 6 files changed, 95 insertions(+), 81 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index f1b192fce1..6c7ac94181 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -57,9 +57,9 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { bool Console::cmdLoadImage(int argc, const char **argv) { if (argc == 4) - _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); + _engine->getRenderManager()->renderImageToBackbuffer(argv[1], atoi(argv[2]), atoi(argv[3])); else if (argc == 8) - _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3]), Common::Rect(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]))); + _engine->getRenderManager()->renderImageToBackbuffer(argv[1], atoi(argv[2]), atoi(argv[3]), Common::Rect(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]))); else { DebugPrintf("Use loadimage [ ] to load an image to the screen\n"); return true; diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 78fcf59a56..05536f3fbe 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -34,23 +34,28 @@ namespace ZVision { -RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow) - : _system(system), - _workingWidth(workingWindow.width()), - _workingHeight(workingWindow.height()), - _workingWindow(workingWindow), - _currentBackground(0), - _backgroundWidth(0), - _backgroundHeight(0), - _backgroundInverseVelocity(0), - _accumulatedVelocityMilliseconds(0), - _renderTable(workingWindow.width(), workingWindow.height()) { +RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat) + : _system(system), + _workingWidth(workingWindow.width()), + _workingHeight(workingWindow.height()), + _workingWindow(workingWindow), + _pixelFormat(pixelFormat), + _currentBackground(0), + _backgroundWidth(0), + _backgroundHeight(0), + _backgroundInverseVelocity(0), + _accumulatedVelocityMilliseconds(0), + _renderTable(workingWindow.width(), workingWindow.height()) { + _backbuffer.create(_workingWidth, _workingHeight, pixelFormat); + _warpedBackbuffer = new uint16[_workingWidth *_workingHeight]; } RenderManager::~RenderManager() { if (_currentBackground != 0) { delete _currentBackground; } + + _backbuffer.free(); } void RenderManager::update(uint deltaTimeInMillis) { @@ -62,7 +67,7 @@ void RenderManager::update(uint deltaTimeInMillis) { int absVelocity = abs(_backgroundInverseVelocity); - uint numberOfSteps = 0; + int numberOfSteps = 0; while (_accumulatedVelocityMilliseconds >= absVelocity) { _accumulatedVelocityMilliseconds -= absVelocity; numberOfSteps++; @@ -70,17 +75,23 @@ void RenderManager::update(uint deltaTimeInMillis) { // Choose the direction of movement using the sign of the velocity moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps); + + // Warp the entire backbuffer + _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight); + + // Blit the backbuffer to the screen + _system->copyRectToScreen(_backbuffer.getBasePtr(0, 0), _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h); } -void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { +void RenderManager::renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed) { if (wrap) { - _backgroundWidth = imageWidth; - _backgroundHeight = imageHeight; + _backgroundWidth = surface.w; + _backgroundHeight = surface.h; } // If subRect is empty, use the entire image if (subRectangle.isEmpty()) - subRectangle = Common::Rect(subRectangle.left, subRectangle.top, subRectangle.left + imageWidth, subRectangle.top + imageHeight); + subRectangle = Common::Rect(subRectangle.left, subRectangle.top, subRectangle.left + surface.w, subRectangle.top + surface.h); // Clip destRect to working window bounds Common::Rect destRect(destinationX, destinationY, destinationX + subRectangle.width(), destinationY + subRectangle.height()); @@ -91,7 +102,7 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin subRectangle.setHeight(destRect.height()); // Clip to image bounds Common::Point subRectOrigOrigin(subRectangle.left, subRectangle.top); - subRectangle.clip(imageWidth, imageHeight); + subRectangle.clip(surface.w, surface.h); // If the image is to be wrapped, check if it's smaller than destRect // If it is, then call renderSubRectToScreen with a subRect representing wrapping @@ -110,7 +121,7 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin wrapSubRect = Common::Rect(_backgroundWidth - subRectangle.width(), 0, _backgroundWidth - 1, subRectangle.bottom); } - renderSubRectToScreen(buffer, imageWidth, imageHeight, horizontalPitch, wrapDestX, wrapDestY, wrapSubRect, false); + renderSubRectToBackbuffer(surface, wrapDestX, wrapDestY, wrapSubRect, false, isTransposed); } else if (wrap && subRectangle.height() < destRect.height()) { uint32 wrapDestX; uint32 wrapDestY; @@ -126,32 +137,38 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin wrapSubRect = Common::Rect(0, _backgroundHeight - subRectangle.height(), subRectangle.right, _backgroundHeight - 1); } - renderSubRectToScreen(buffer, imageWidth, imageHeight, horizontalPitch, wrapDestX, wrapDestY, wrapSubRect, false); + renderSubRectToBackbuffer(surface, wrapDestX, wrapDestY, wrapSubRect, false, isTransposed); + } else { + // Clip destRect to image bounds + destRect.translate(subRectangle.left - subRectOrigOrigin.x, subRectangle.top - subRectOrigOrigin.y); + destRect.setWidth(subRectangle.width()); + destRect.setHeight(subRectangle.height()); } - // Clip destRect to image bounds - destRect.translate(subRectangle.left - subRectOrigOrigin.x, subRectangle.top - subRectOrigOrigin.y); - destRect.setWidth(subRectangle.width()); - destRect.setHeight(subRectangle.height()); - // Check all Rects for validity if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty()) return; - if (_renderTable.getRenderState() == RenderTable::FLAT) { - // Convert destRect to screen space by adding _workingWindowOffset - _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left + _workingWindow.left, destRect.top + _workingWindow.top, destRect.width(), destRect.height()); + if (isTransposed) { + copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(subRectangle.left, subRectangle.right), surface.w, destRect.left, destRect.top, destRect.width(), destRect.height()); } else { - uint16 *destBuffer = new uint16[destRect.width() * destRect.height()]; - _renderTable.mutateImage((uint16 *)buffer, destBuffer, imageWidth, imageHeight, subRectangle, destRect); + _backbuffer.copyRectToSurface(surface.getBasePtr(subRectangle.left, subRectangle.right), surface.pitch, destRect.left, destRect.top, destRect.width(), destRect.height()); + } +} - // Convert destRect to screen space by adding _workingWindow offset - _system->copyRectToScreen(destBuffer, subRectangle.width() * sizeof(uint16), destRect.left + _workingWindow.left, destRect.top + _workingWindow.top, destRect.width(), destRect.height()); - delete[] destBuffer; +void RenderManager::copyTransposedRectToBackbuffer(const uint16 *buffer, int imageHeight, int x, int y, int width, int height) { + uint16 *dest = (uint16 *)_backbuffer.getBasePtr(x, y); + + for (int x = 0; x < width; x++) { + int columnOffset = x * imageHeight; + for (int y = 0; y < height; y++) { + *dest = buffer[columnOffset + y]; + dest++; + } } } -void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { +void RenderManager::renderImageToBackbuffer(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { Common::File file; if (!file.open(fileName)) { @@ -159,10 +176,10 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d return; } - renderImageToScreen(file, destinationX, destinationY, subRectangle); + renderImageToBackbuffer(file, destinationX, destinationY, subRectangle); } -void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { +void RenderManager::renderImageToBackbuffer(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { // Read the magic number // Some files are true TGA, while others are TGZ uint32 fileType; @@ -179,17 +196,21 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint byte *buffer = new byte[decompressedSize]; lzssStream.read(buffer, decompressedSize); - uint32 horizontalPitch = imageWidth * sizeof(uint16); + uint32 pitch = imageWidth * sizeof(uint16); + bool isTransposed = _renderTable.getRenderState() == RenderTable::PANORAMA; - // Panoramas are transposed - // The actual data is transposed in mutateImage - if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { - uint32 temp = imageHeight; + if (isTransposed) { + uint16 temp = imageHeight; imageHeight = imageWidth; imageWidth = temp; } - renderSubRectToScreen((uint16 *)buffer, imageWidth, imageHeight, horizontalPitch, destinationX, destinationY, subRectangle, wrap); + Graphics::Surface surface; + surface.init(imageWidth, imageHeight, pitch, buffer, _pixelFormat); + + renderSubRectToBackbuffer(surface, destinationX, destinationY, subRectangle, wrap, isTransposed); + + // We have to use delete[] instead of calling surface.free() because we created the memory with new[] delete[] buffer; } else { // Reset the cursor @@ -202,20 +223,16 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint return; } - const Graphics::Surface *tgaSurface = tga.getSurface(); + Graphics::Surface tgaSurface = *(tga.getSurface()); + bool isTransposed = _renderTable.getRenderState() == RenderTable::PANORAMA; - uint32 imageWidth = tgaSurface->w; - uint32 imageHeight = tgaSurface->h; - - // Panoramas are transposed - // The actual data is transposed in mutateImage - if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { - uint32 temp = imageHeight; - imageHeight = imageWidth; - imageWidth = temp; + if (isTransposed) { + uint16 temp = tgaSurface.h; + tgaSurface.h = tgaSurface.w; + tgaSurface.w = temp; } - renderSubRectToScreen((uint16 *)tgaSurface->pixels, tgaSurface->w, tgaSurface->h, tgaSurface->pitch, destinationX, destinationY, subRectangle, wrap); + renderSubRectToBackbuffer(tgaSurface, destinationX, destinationY, subRectangle, wrap, isTransposed); tga.destroy(); } } @@ -255,7 +272,7 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { _currentBackground = file; // Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically. - renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); + renderImageToBackbuffer(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); } void RenderManager::setBackgroundPosition(int offset) { @@ -297,7 +314,7 @@ void RenderManager::moveBackground(int offset) { _currentBackground->seek(0); // Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically. - renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); + renderImageToBackbuffer(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); } } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 073a2f61e0..d5bf61f6a0 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -26,6 +26,8 @@ #include "common/types.h" #include "common/rect.h" +#include "graphics/surface.h" + #include "zvision/render_table.h" class OSystem; @@ -43,11 +45,15 @@ namespace ZVision { class RenderManager { public: - RenderManager(OSystem *system, const Common::Rect workingWindow); + RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat); ~RenderManager(); private: OSystem *_system; + const Graphics::PixelFormat _pixelFormat; + + Graphics::Surface _backbuffer; + uint16 *_warpedBackbuffer; /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ const int _workingWidth; @@ -90,7 +96,7 @@ public: void update(uint deltaTimeInMillis); /** - * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. + * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. * The image will be clipped to fit inside the working window. Coords are in working window space, not screen space! * * @param fileName Name of the image file @@ -98,10 +104,10 @@ public: * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ - void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); + void renderImageToBackbuffer(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); /** - * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame. + * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. * The image will be clipped to fit inside the working window. Coords are in working window space, not screen space! * * @param stream Stream to read the image data from @@ -109,7 +115,7 @@ public: * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ - void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); + void renderImageToBackbuffer(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); /** * Sets the current background image to be used by the RenderManager and immediately @@ -151,7 +157,7 @@ public: private: /** - * Renders a subRectangle of an image to the screen. The destinationRect and SubRect + * Renders a subRectangle of an image to the backbuffer. The destinationRect and SubRect * will be clipped to image bound and to working window bounds * * @param buffer Pointer to (0, 0) of the image data @@ -163,7 +169,9 @@ private: * @param subRectangle A rectangle representing the part of the image that should be rendered * @param wrap Should the image wrap (tile) if it doesn't completely fill the screen? */ - void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap); + void renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed); + + void copyTransposedRectToBackbuffer(const uint16 *buffer, int imageHeight, int x, int y, int width, int height); void moveBackground(int offset); }; diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 3bd0103054..a28f82baa6 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -98,16 +98,10 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { return returnColor; } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle) { - bool isTransposed = _renderState == RenderTable::PANORAMA || _renderState == RenderTable::TILT; - - for (int y = subRectangle.top; y < subRectangle.bottom; y++) { - uint normalizedY = y - subRectangle.top; - - for (int x = subRectangle.left; x < subRectangle.right; x++) { - uint normalizedX = x - subRectangle.left; - - uint32 index = (normalizedY + destRectangle.top) * _numColumns + (normalizedX + destRectangle.left); +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight) { + for (uint32 y = 0; y < imageHeight; y++) { + for (uint32 x = 0; x < imageWidth; x++) { + uint32 index = y * _numColumns + x; // RenderTable only stores offsets from the original coordinates uint32 sourceYIndex = y + _internalBuffer[index].y; @@ -119,12 +113,7 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 i // Clamp the xIndex to the size of the image sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); - // TODO: Figure out a way to not have branching every loop. The only way that comes to mind is to have a whole separate set of for loops for isTransposed, but that's ugly. The compiler might do this anyway in the end - if (isTransposed) { - destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceXIndex * imageHeight + sourceYIndex]; - } else { - destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; - } + destBuffer[index] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; } } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index c38b5a6f0b..7c04564cd0 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -66,7 +66,7 @@ public: const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); - void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight); void generateRenderTable(); void setPanoramaFoV(float fov); diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 2090d8abfe..ff234bf3fe 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -68,7 +68,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); - _renderManager = new RenderManager(_system, _workingWindow); + _renderManager = new RenderManager(_system, _workingWindow, _pixelFormat); _cursorManager = new CursorManager(this, &_pixelFormat); debug("ZVision::ZVision"); -- cgit v1.2.3 From 999de6d400be8374a6834a81bb8b8f4da4a1756c Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 15 Aug 2013 13:36:10 -0500 Subject: ZVISION: Convert Surface::pixels to Surface::getBasePtr(0, 0) --- engines/zvision/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 5497d0af0c..28c26f6f2a 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -148,10 +148,10 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d if (frame) { if (scale != 1) { - scaleBuffer((byte *)frame->pixels, scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); + scaleBuffer((byte *)frame->getBasePtr(0, 0), scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); _system->copyRectToScreen(scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); } else { - _system->copyRectToScreen((byte *)frame->pixels, pitch, x, y, finalWidth, finalHeight); + _system->copyRectToScreen((byte *)frame->getBasePtr(0, 0), pitch, x, y, finalWidth, finalHeight); } _system->updateScreen(); -- cgit v1.2.3 From c2366dc99e7028fdf94ec7d020016e674bf33100 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 15 Aug 2013 15:11:24 -0500 Subject: ZVISION: Fix error using subRectangle.right instead of .top --- engines/zvision/render_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 05536f3fbe..a2ae7e8b28 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -152,7 +152,7 @@ void RenderManager::renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 if (isTransposed) { copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(subRectangle.left, subRectangle.right), surface.w, destRect.left, destRect.top, destRect.width(), destRect.height()); } else { - _backbuffer.copyRectToSurface(surface.getBasePtr(subRectangle.left, subRectangle.right), surface.pitch, destRect.left, destRect.top, destRect.width(), destRect.height()); + _backbuffer.copyRectToSurface(surface.getBasePtr(subRectangle.left, subRectangle.top), surface.pitch, destRect.left, destRect.top, destRect.width(), destRect.height()); } } -- cgit v1.2.3 From bdd9b18292105b2cd8d894d2e042accecd001913 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 10:43:12 -0500 Subject: ZVISION: Disable videos until I can figure out how to fix the decoder --- engines/zvision/scr_file_handling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 5b8af48047..ff7df20ac5 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -251,7 +251,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:streamvideo*", true)) { - actionList.push_back(Common::SharedPtr(new ActionStreamVideo(line))); + //actionList.push_back(Common::SharedPtr(new ActionStreamVideo(line))); } else if (line.matchString("*:syncsound*", true)) { -- cgit v1.2.3 From e6aa2d15ca75788065012ea64e881277ef4e5565 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 10:44:35 -0500 Subject: ZVISION: Only skip the background moving if velocity is 0 instead of returning and skipping everything --- engines/zvision/render_manager.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index a2ae7e8b28..31b54b4a15 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -60,22 +60,21 @@ RenderManager::~RenderManager() { void RenderManager::update(uint deltaTimeInMillis) { // An inverse velocity of 0 would be infinitely fast, so we'll let 0 mean no velocity. - if (_backgroundInverseVelocity == 0) - return; + if (_backgroundInverseVelocity != 0) { + _accumulatedVelocityMilliseconds += deltaTimeInMillis; - _accumulatedVelocityMilliseconds += deltaTimeInMillis; + int absVelocity = abs(_backgroundInverseVelocity); - int absVelocity = abs(_backgroundInverseVelocity); + int numberOfSteps = 0; + while (_accumulatedVelocityMilliseconds >= absVelocity) { + _accumulatedVelocityMilliseconds -= absVelocity; + numberOfSteps++; + } - int numberOfSteps = 0; - while (_accumulatedVelocityMilliseconds >= absVelocity) { - _accumulatedVelocityMilliseconds -= absVelocity; - numberOfSteps++; + // Choose the direction of movement using the sign of the velocity + moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps); } - // Choose the direction of movement using the sign of the velocity - moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps); - // Warp the entire backbuffer _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight); -- cgit v1.2.3 From 26159e6ea52cab35eeba425c066e2faaa0540c2f Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 10:44:56 -0500 Subject: ZVISION: Only warp the backbuffer if we're in PANORAMA or TILT --- engines/zvision/render_manager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 31b54b4a15..5bc709553b 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -76,7 +76,10 @@ void RenderManager::update(uint deltaTimeInMillis) { } // Warp the entire backbuffer - _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight); + //RenderTable::RenderState state = _renderTable.getRenderState(); + //if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + // _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight); + //} // Blit the backbuffer to the screen _system->copyRectToScreen(_backbuffer.getBasePtr(0, 0), _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h); -- cgit v1.2.3 From af0a58ecda26f12c630db759667d7adc79e733d6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 10:45:31 -0500 Subject: ZVISION: Fix copyTransposedRectToBackBuffer --- engines/zvision/render_manager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 5bc709553b..bfafd7fe19 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -152,21 +152,23 @@ void RenderManager::renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 return; if (isTransposed) { - copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(subRectangle.left, subRectangle.right), surface.w, destRect.left, destRect.top, destRect.width(), destRect.height()); + copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(subRectangle.left, subRectangle.top), surface.h, destRect.left, destRect.top, destRect.width(), destRect.height()); } else { _backbuffer.copyRectToSurface(surface.getBasePtr(subRectangle.left, subRectangle.top), surface.pitch, destRect.left, destRect.top, destRect.width(), destRect.height()); } } -void RenderManager::copyTransposedRectToBackbuffer(const uint16 *buffer, int imageHeight, int x, int y, int width, int height) { +void RenderManager::copyTransposedRectToBackbuffer(const uint16 *buffer, int imageWidth, int x, int y, int width, int height) { uint16 *dest = (uint16 *)_backbuffer.getBasePtr(x, y); - for (int x = 0; x < width; x++) { - int columnOffset = x * imageHeight; - for (int y = 0; y < height; y++) { - *dest = buffer[columnOffset + y]; + for (int i = 0; i < width; i++) { + int columnOffset = i * imageWidth; + for (int j = 0; j < height; j++) { + *dest = buffer[columnOffset + j]; dest++; } + + dest += _backbuffer.w; } } -- cgit v1.2.3 From e0937a12cd47201a6dce6822e20657b2df5785af Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 12:17:29 -0500 Subject: ZVISION: Move _cursorManager construction after the folder directories have been registered with SearchMan --- engines/zvision/zvision.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index ff234bf3fe..080c763342 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -69,7 +69,6 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); _renderManager = new RenderManager(_system, _workingWindow, _pixelFormat); - _cursorManager = new CursorManager(this, &_pixelFormat); debug("ZVision::ZVision"); } @@ -116,6 +115,8 @@ void ZVision::initialize() { initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, &_pixelFormat); + // CursorManager must be created after all the directories have been added + _cursorManager = new CursorManager(this, &_pixelFormat); _cursorManager->initialize(); _scriptManager->initialize(); -- cgit v1.2.3 From 1c6ffd133acdddb8d08249d3a49caf523fd1d01e Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 12:18:19 -0500 Subject: ZVISION: Clean up backbuffer memory after we're finished with it --- engines/zvision/render_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index bfafd7fe19..d8b8ce167d 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -56,6 +56,7 @@ RenderManager::~RenderManager() { } _backbuffer.free(); + delete[] _warpedBackbuffer; } void RenderManager::update(uint deltaTimeInMillis) { -- cgit v1.2.3 From a3c39f48767b06a8015269e48ca929fbc5bfa637 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 12:19:00 -0500 Subject: ZVISION: Fix memory corruption in copyTransposedRectToBackBuffer --- engines/zvision/render_manager.cpp | 34 +++++++++++++++++++--------------- engines/zvision/render_manager.h | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index d8b8ce167d..1f2c3a20c7 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -77,13 +77,16 @@ void RenderManager::update(uint deltaTimeInMillis) { } // Warp the entire backbuffer - //RenderTable::RenderState state = _renderTable.getRenderState(); - //if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { - // _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight); - //} + RenderTable::RenderState state = _renderTable.getRenderState(); + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight); + _system->copyRectToScreen(_warpedBackbuffer, _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h); + } else { + _system->copyRectToScreen(_backbuffer.getBasePtr(0, 0), _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h); + } // Blit the backbuffer to the screen - _system->copyRectToScreen(_backbuffer.getBasePtr(0, 0), _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h); + } void RenderManager::renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed) { @@ -153,23 +156,24 @@ void RenderManager::renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 return; if (isTransposed) { - copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(subRectangle.left, subRectangle.top), surface.h, destRect.left, destRect.top, destRect.width(), destRect.height()); + copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(0, 0), surface.h, destRect.left, destRect.top, destRect.width(), destRect.height(), subRectangle); } else { _backbuffer.copyRectToSurface(surface.getBasePtr(subRectangle.left, subRectangle.top), surface.pitch, destRect.left, destRect.top, destRect.width(), destRect.height()); } } -void RenderManager::copyTransposedRectToBackbuffer(const uint16 *buffer, int imageWidth, int x, int y, int width, int height) { - uint16 *dest = (uint16 *)_backbuffer.getBasePtr(x, y); +void RenderManager::copyTransposedRectToBackbuffer(const uint16 *buffer, int imageWidth, int destinationX, int destinationY, int width, int height, const Common::Rect &subRect) { + uint16 *dest = (uint16 *)_backbuffer.getBasePtr(0, 0); + + for (int16 x = subRect.left; x < subRect.right; x++) { + int16 normalizedX = x - subRect.left + destinationX; + int columnOffset = x * imageWidth; - for (int i = 0; i < width; i++) { - int columnOffset = i * imageWidth; - for (int j = 0; j < height; j++) { - *dest = buffer[columnOffset + j]; - dest++; - } + for (int16 y = subRect.top; y < subRect.bottom; y++) { + int16 normalizeY = y - subRect.top + destinationY; - dest += _backbuffer.w; + dest[normalizeY * _backbuffer.w + normalizedX] = buffer[columnOffset + y]; + } } } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index d5bf61f6a0..f59f50d4d7 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -171,7 +171,7 @@ private: */ void renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed); - void copyTransposedRectToBackbuffer(const uint16 *buffer, int imageHeight, int x, int y, int width, int height); + void copyTransposedRectToBackbuffer(const uint16 *buffer, int imageWidth, int destinationX, int destinationY, int width, int height, const Common::Rect &subRect); void moveBackground(int offset); }; -- cgit v1.2.3 From 0a840fa664c210dfb85d6c62d4a80a08ca650843 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 16 Aug 2013 17:27:51 -0500 Subject: ZVISION: Rename 'x' variable in changeLocation to 'offset' Since it can be in either the x or the y direction --- engines/zvision/actions.cpp | 4 ++-- engines/zvision/actions.h | 2 +- engines/zvision/script_manager.cpp | 8 ++++---- engines/zvision/script_manager.h | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 2316530c67..504c250597 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -83,12 +83,12 @@ bool ActionAttenuate::execute(ZVision *engine) { ////////////////////////////////////////////////////////////////////////////// ActionChangeLocation::ActionChangeLocation(const Common::String &line) { - sscanf(line.c_str(), "%*[^(](%c,%c,%c%c,%u)", &_world, &_room, &_node, &_view, &_x); + sscanf(line.c_str(), "%*[^(](%c,%c,%c%c,%u)", &_world, &_room, &_node, &_view, &_offset); } bool ActionChangeLocation::execute(ZVision *engine) { // We can't directly call ScriptManager::ChangeLocationIntern() because doing so clears all the Puzzles, and thus would corrupt the current puzzle checking - engine->getScriptManager()->changeLocation(_world, _room, _node, _view, _x); + engine->getScriptManager()->changeLocation(_world, _room, _node, _view, _offset); // Tell the puzzle system to stop checking any more puzzles return false; } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 511f3d9b83..aa67be20c7 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -126,7 +126,7 @@ private: char _room; char _node; char _view; - uint32 _x; + uint32 _offset; }; class ActionCrossfade : public ResultAction { diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 6aaf5773e0..5c0e336a5d 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -191,19 +191,19 @@ void ScriptManager::addActionNode(const Common::SharedPtr &node) { _activeNodes.push_back(node); } -void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 x) { +void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 offset) { _nextLocation.world = world; _nextLocation.room = room; _nextLocation.node = node; _nextLocation.view = view; - _nextLocation.x = x; + _nextLocation.offset = offset; _changeLocation = true; } void ScriptManager::changeLocationIntern() { assert(_nextLocation.world != 0); - debug("Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.x); + debug("Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.offset); // Clear all the containers _referenceTable.clear(); @@ -217,7 +217,7 @@ void ScriptManager::changeLocationIntern() { _engine->getCursorManager()->revertToIdle(); // Change the background position - _engine->getRenderManager()->setBackgroundPosition(_nextLocation.x); + _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); // Reset the background velocity _engine->getRenderManager()->setBackgroundVelocity(0); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 8e79548f77..c0801edd5e 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -44,7 +44,7 @@ struct Location { char room; char node; char view; - uint32 x; + uint32 offset; }; class ScriptManager { @@ -86,7 +86,7 @@ public: void addActionNode(const Common::SharedPtr &node); - void changeLocation(char world, char room, char node, char view, uint32 x); + void changeLocation(char world, char room, char node, char view, uint32 offset); private: void createReferenceTable(); -- cgit v1.2.3 From 7d24f46e7e2c7d6322b2842d349986dc484eb063 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 09:38:24 -0500 Subject: ZVISION: Modify cmdLoadSound to allow manual rate and isStereo Usually those variables are parsed from the file name --- engines/zvision/console.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 6c7ac94181..e7c46b95a9 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -83,19 +83,29 @@ bool Console::cmdLoadVideo(int argc, const char **argv) { } bool Console::cmdLoadSound(int argc, const char **argv) { - if (argc != 2) { - DebugPrintf("Use loadsound to load a sound\n"); - return true; - } - if (!Common::File::exists(argv[1])) { DebugPrintf("File does not exist\n"); return true; } - Audio::AudioStream *soundStream = makeRawZorkStream(argv[1], _engine); - Audio::SoundHandle handle; - _engine->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); + if (argc == 2) { + Audio::AudioStream *soundStream = makeRawZorkStream(argv[1], _engine); + Audio::SoundHandle handle; + _engine->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); + + } else if (argc == 4) { + int isStereo = atoi(argv[3]); + + Common::File *file = new Common::File(); + file->open(argv[1]); + + Audio::AudioStream *soundStream = makeRawZorkStream(file, atoi(argv[2]), isStereo == 0 ? false : true); + Audio::SoundHandle handle; + _engine->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, soundStream, -1, 100, 0, DisposeAfterUse::YES, false, false); + } else { + DebugPrintf("Use loadsound [ ] to load a sound\n"); + return true; + } return true; } -- cgit v1.2.3 From e769164f791d19b69cbe7cb0be99fc474c562ed4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 09:46:18 -0500 Subject: ZVISION: Render images by specifying a destination and then clipping Instead of specifying a subRect. This also reverts the code that rendered to a backbuffer and then did a full backbuffer warp. Wrapping is done in the RenderTable --- engines/zvision/render_manager.cpp | 200 ++++++++++++++++--------------------- engines/zvision/render_manager.h | 18 ++-- engines/zvision/render_table.cpp | 50 +++++++--- engines/zvision/render_table.h | 2 +- 4 files changed, 134 insertions(+), 136 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 1f2c3a20c7..e4106109ba 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -38,16 +38,19 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, : _system(system), _workingWidth(workingWindow.width()), _workingHeight(workingWindow.height()), + _screenCenterX((workingWindow.left + workingWindow.right) /2), + _screenCenterY((workingWindow.top + workingWindow.bottom) /2), _workingWindow(workingWindow), _pixelFormat(pixelFormat), _currentBackground(0), _backgroundWidth(0), _backgroundHeight(0), _backgroundInverseVelocity(0), + _backgroundOffset(0, 0), _accumulatedVelocityMilliseconds(0), - _renderTable(workingWindow.width(), workingWindow.height()) { - _backbuffer.create(_workingWidth, _workingHeight, pixelFormat); - _warpedBackbuffer = new uint16[_workingWidth *_workingHeight]; + _renderTable(_workingWidth, _workingHeight) { + + _warpedBuffer = new uint16[_workingWidth *_workingHeight]; } RenderManager::~RenderManager() { @@ -55,8 +58,7 @@ RenderManager::~RenderManager() { delete _currentBackground; } - _backbuffer.free(); - delete[] _warpedBackbuffer; + delete[] _warpedBuffer; } void RenderManager::update(uint deltaTimeInMillis) { @@ -73,111 +75,83 @@ void RenderManager::update(uint deltaTimeInMillis) { } // Choose the direction of movement using the sign of the velocity - moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps); + moveBackground(_backgroundInverseVelocity < 0 ? numberOfSteps : -numberOfSteps); } +} - // Warp the entire backbuffer - RenderTable::RenderState state = _renderTable.getRenderState(); - if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { - _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight); - _system->copyRectToScreen(_warpedBackbuffer, _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h); - } else { - _system->copyRectToScreen(_backbuffer.getBasePtr(0, 0), _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h); +void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap, bool isTransposed) { + int16 subRectX = 0; + int16 subRectY = 0; + + // Take care of negative destinations + if (destinationX < 0) { + subRectX = destinationX + surface.w; + destinationX = 0; + if (wrap) { + _backgroundOffset.x += surface.w; + } + } else if (destinationX >= surface.w) { + // Take care of extreme positive destinations + destinationX -= surface.w; + if (wrap) { + _backgroundOffset.x -= surface.w; + } } - // Blit the backbuffer to the screen - -} + // Take care of negative destinations + if (destinationY < 0) { + subRectY = destinationY + surface.h; + destinationY = 0; + if (wrap) { + _backgroundOffset.y += surface.h; + } + } else if (destinationY >= surface.h) { + // Take care of extreme positive destinations + destinationY -= surface.h; + if (wrap) { + _backgroundOffset.y -= surface.h; + } + } -void RenderManager::renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed) { if (wrap) { _backgroundWidth = surface.w; _backgroundHeight = surface.h; - } - // If subRect is empty, use the entire image - if (subRectangle.isEmpty()) - subRectangle = Common::Rect(subRectangle.left, subRectangle.top, subRectangle.left + surface.w, subRectangle.top + surface.h); - - // Clip destRect to working window bounds - Common::Rect destRect(destinationX, destinationY, destinationX + subRectangle.width(), destinationY + subRectangle.height()); - destRect.clip(_workingWidth, _workingHeight); - // Clip subRect to working window bounds - subRectangle.translate(destRect.left - destinationX, destRect.top - destinationY); - subRectangle.setWidth(destRect.width()); - subRectangle.setHeight(destRect.height()); - // Clip to image bounds - Common::Point subRectOrigOrigin(subRectangle.left, subRectangle.top); - subRectangle.clip(surface.w, surface.h); - - // If the image is to be wrapped, check if it's smaller than destRect - // If it is, then call renderSubRectToScreen with a subRect representing wrapping - if (wrap && subRectangle.width() < destRect.width()) { - uint32 wrapDestX; - uint32 wrapDestY; - Common::Rect wrapSubRect; - - if (_backgroundWidth - subRectangle.left < destRect.width()) { - wrapDestX = destRect.left + subRectangle.width(); - wrapDestY = destRect.top; - wrapSubRect = Common::Rect(0, 0, destRect.width() - subRectangle.width(), subRectangle.bottom); - } else { - wrapDestX = destRect.left; - wrapDestY = destRect.top; - wrapSubRect = Common::Rect(_backgroundWidth - subRectangle.width(), 0, _backgroundWidth - 1, subRectangle.bottom); + if (destinationX > 0) { + // Move destinationX to 0 + subRectX = surface.w - destinationX; + destinationX = 0; } - renderSubRectToBackbuffer(surface, wrapDestX, wrapDestY, wrapSubRect, false, isTransposed); - } else if (wrap && subRectangle.height() < destRect.height()) { - uint32 wrapDestX; - uint32 wrapDestY; - Common::Rect wrapSubRect; - - if (_backgroundHeight - subRectangle.top < destRect.height()) { - wrapDestX = destRect.left; - wrapDestY = destRect.height() - subRectangle.height(); - wrapSubRect = Common::Rect(0, 0, subRectangle.right, destRect.height() - subRectangle.height()); - } else { - wrapDestX = destRect.left; - wrapDestY = destRect.top; - wrapSubRect = Common::Rect(0, _backgroundHeight - subRectangle.height(), subRectangle.right, _backgroundHeight - 1); + if (destinationY > 0) { + // Move destinationY to 0 + subRectX = surface.w - destinationX; + destinationY = 0; } - - renderSubRectToBackbuffer(surface, wrapDestX, wrapDestY, wrapSubRect, false, isTransposed); - } else { - // Clip destRect to image bounds - destRect.translate(subRectangle.left - subRectOrigOrigin.x, subRectangle.top - subRectOrigOrigin.y); - destRect.setWidth(subRectangle.width()); - destRect.setHeight(subRectangle.height()); } - // Check all Rects for validity - if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty()) - return; + // Clip subRect to working window bounds + Common::Rect subRect(subRectX, subRectY, subRectX + _workingWidth, subRectY + _workingHeight); - if (isTransposed) { - copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(0, 0), surface.h, destRect.left, destRect.top, destRect.width(), destRect.height(), subRectangle); - } else { - _backbuffer.copyRectToSurface(surface.getBasePtr(subRectangle.left, subRectangle.top), surface.pitch, destRect.left, destRect.top, destRect.width(), destRect.height()); + if (!wrap) { + // Clip to image bounds + subRect.clip(surface.w, surface.h); } -} -void RenderManager::copyTransposedRectToBackbuffer(const uint16 *buffer, int imageWidth, int destinationX, int destinationY, int width, int height, const Common::Rect &subRect) { - uint16 *dest = (uint16 *)_backbuffer.getBasePtr(0, 0); - - for (int16 x = subRect.left; x < subRect.right; x++) { - int16 normalizedX = x - subRect.left + destinationX; - int columnOffset = x * imageWidth; + // Check destRect for validity + if (!subRect.isValidRect() || subRect.isEmpty()) + return; - for (int16 y = subRect.top; y < subRect.bottom; y++) { - int16 normalizeY = y - subRect.top + destinationY; + if (_renderTable.getRenderState() == RenderTable::FLAT) { + _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); + } else { + _renderTable.mutateImage((uint16 *)surface.getBasePtr(0, 0), _warpedBuffer, surface.w, surface.h, destinationX, destinationY, subRect, wrap, isTransposed); - dest[normalizeY * _backbuffer.w + normalizedX] = buffer[columnOffset + y]; - } + _system->copyRectToScreen(_warpedBuffer, _workingWidth * sizeof(uint16), destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); } } -void RenderManager::renderImageToBackbuffer(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { +void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, bool wrap) { Common::File file; if (!file.open(fileName)) { @@ -185,10 +159,10 @@ void RenderManager::renderImageToBackbuffer(const Common::String &fileName, uint return; } - renderImageToBackbuffer(file, destinationX, destinationY, subRectangle); + renderImageToScreen(file, destinationX, destinationY); } -void RenderManager::renderImageToBackbuffer(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) { +void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, bool wrap) { // Read the magic number // Some files are true TGA, while others are TGZ uint32 fileType; @@ -217,7 +191,7 @@ void RenderManager::renderImageToBackbuffer(Common::SeekableReadStream &stream, Graphics::Surface surface; surface.init(imageWidth, imageHeight, pitch, buffer, _pixelFormat); - renderSubRectToBackbuffer(surface, destinationX, destinationY, subRectangle, wrap, isTransposed); + renderSubRectToScreen(surface, destinationX, destinationY, wrap, isTransposed); // We have to use delete[] instead of calling surface.free() because we created the memory with new[] delete[] buffer; @@ -241,7 +215,7 @@ void RenderManager::renderImageToBackbuffer(Common::SeekableReadStream &stream, tgaSurface.w = temp; } - renderSubRectToBackbuffer(tgaSurface, destinationX, destinationY, subRectangle, wrap, isTransposed); + renderSubRectToScreen(tgaSurface, destinationX, destinationY, wrap, isTransposed); tga.destroy(); } } @@ -280,15 +254,20 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { } _currentBackground = file; - // Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically. - renderImageToBackbuffer(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); + renderImageToScreen(*_currentBackground, _backgroundOffset.x, _backgroundOffset.y, true); } void RenderManager::setBackgroundPosition(int offset) { - if (_renderTable.getRenderState() == RenderTable::TILT) { - _backgroundOffset = Common::Point(0, offset); + RenderTable::RenderState state = _renderTable.getRenderState(); + if (state == RenderTable::TILT) { + _backgroundOffset.x = 0; + _backgroundOffset.y = _screenCenterY - offset; + } else if (state == RenderTable::PANORAMA) { + _backgroundOffset.x = _screenCenterX - offset; + _backgroundOffset.y = 0; } else { - _backgroundOffset = Common::Point(offset, 0); + _backgroundOffset.x = 0; + _backgroundOffset.y = 0; } } @@ -305,25 +284,20 @@ void RenderManager::setBackgroundVelocity(int velocity) { } void RenderManager::moveBackground(int offset) { - if (_renderTable.getRenderState() == RenderTable::TILT) { + _currentBackground->seek(0); + + RenderTable::RenderState state = _renderTable.getRenderState(); + if (state == RenderTable::TILT) { _backgroundOffset += Common::Point(0, offset); - } else { - _backgroundOffset += Common::Point(offset, 0); - } - // Make sure the offset is within image bounds - if (_backgroundOffset.x < 0) - _backgroundOffset.x += _backgroundWidth; - if (_backgroundOffset.x > _backgroundWidth) - _backgroundOffset.x -= _backgroundWidth; - if (_backgroundOffset.y < 0) - _backgroundOffset.y += _backgroundHeight; - if (_backgroundOffset.y > _backgroundHeight) - _backgroundOffset.y -= _backgroundHeight; + renderImageToScreen(*_currentBackground, 0, _backgroundOffset.y, true); + } else if (state == RenderTable::PANORAMA) { + _backgroundOffset += Common::Point(offset, 0); - _currentBackground->seek(0); - // Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically. - renderImageToBackbuffer(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true); + renderImageToScreen(*_currentBackground, _backgroundOffset.x, 0, true); + } else { + renderImageToScreen(*_currentBackground, 0, 0); + } } } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index f59f50d4d7..cdcd52b67d 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -52,13 +52,17 @@ private: OSystem *_system; const Graphics::PixelFormat _pixelFormat; - Graphics::Surface _backbuffer; - uint16 *_warpedBackbuffer; + uint16 *_warpedBuffer; /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ const int _workingWidth; /** Height of the working window. Saved to prevent extraneous calls to _workingWindow.height() */ const int _workingHeight; + /** Center of the screen in the x direction */ + const int _screenCenterX; + /** Center of the screen in the y direction */ + const int _screenCenterY; + /** * A Rectangle centered inside the actual window. All in-game coordinates * are given in this coordinate space. Also, all images are clipped to the @@ -102,9 +106,8 @@ public: * @param fileName Name of the image file * @param destinationX X position where the image should be put. Coords are in working window space, not screen space! * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! - * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ - void renderImageToBackbuffer(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); + void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, bool wrap = false); /** * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. @@ -113,9 +116,8 @@ public: * @param stream Stream to read the image data from * @param destinationX X position where the image should be put. Coords are in working window space, not screen space! * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! - * @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space! */ - void renderImageToBackbuffer(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false); + void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, bool wrap = false); /** * Sets the current background image to be used by the RenderManager and immediately @@ -169,9 +171,7 @@ private: * @param subRectangle A rectangle representing the part of the image that should be rendered * @param wrap Should the image wrap (tile) if it doesn't completely fill the screen? */ - void renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed); - - void copyTransposedRectToBackbuffer(const uint16 *buffer, int imageWidth, int destinationX, int destinationY, int width, int height, const Common::Rect &subRect); + void renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap, bool isTransposed); void moveBackground(int offset); }; diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index a28f82baa6..23394b7bc2 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -98,22 +98,46 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { return returnColor; } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight) { - for (uint32 y = 0; y < imageHeight; y++) { - for (uint32 x = 0; x < imageWidth; x++) { - uint32 index = y * _numColumns + x; - - // RenderTable only stores offsets from the original coordinates - uint32 sourceYIndex = y + _internalBuffer[index].y; - uint32 sourceXIndex = x + _internalBuffer[index].x; +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap, bool isTransposed) { + for (int16 y = subRect.top; y < subRect.bottom; y++) { + uint16 normalizedY = y - subRect.top; + uint32 internalColumnIndex = (normalizedY + destinationY) * _numColumns; + uint32 destColumnIndex = normalizedY * _numColumns; - // Clamp the yIndex to the size of the image - sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); + for (int16 x = subRect.left; x < subRect.right; x++) { + uint16 normalizedX = x - subRect.left; - // Clamp the xIndex to the size of the image - sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); + uint32 index = internalColumnIndex + normalizedX + destinationX; - destBuffer[index] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; + // RenderTable only stores offsets from the original coordinates + uint16 sourceYIndex = y + _internalBuffer[index].y; + uint16 sourceXIndex = x + _internalBuffer[index].x; + + if (wrap) { + if (sourceXIndex >= imageWidth) { + sourceXIndex -= imageWidth; + } else if (sourceXIndex < 0) { + sourceXIndex += imageWidth; + } + + if (sourceYIndex >= imageHeight) { + sourceYIndex -= imageHeight; + } else if (sourceYIndex < 0) { + sourceYIndex += imageHeight; + } + } else { + // Clamp the yIndex to the size of the image + sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); + + // Clamp the xIndex to the size of the image + sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); + } + + if (isTransposed) { + destBuffer[destColumnIndex + normalizedX] = sourceBuffer[sourceXIndex * imageHeight + sourceYIndex]; + } else { + destBuffer[destColumnIndex + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; + } } } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 7c04564cd0..bbf5e1b22a 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -66,7 +66,7 @@ public: const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); - void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap, bool isTransposed); void generateRenderTable(); void setPanoramaFoV(float fov); -- cgit v1.2.3 From b22ed391fe35bd999060f5d3b7c87dcbfbca8ab4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 09:47:05 -0500 Subject: ZVISION: Set the background position after the .scr file has been parsed so we know the RenderState --- engines/zvision/script_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 5c0e336a5d..3ca9f01adc 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -216,9 +216,6 @@ void ScriptManager::changeLocationIntern() { // Revert to the idle cursor _engine->getCursorManager()->revertToIdle(); - // Change the background position - _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); - // Reset the background velocity _engine->getRenderManager()->setBackgroundVelocity(0); @@ -226,6 +223,9 @@ void ScriptManager::changeLocationIntern() { Common::String fileName = Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view); parseScrFile(fileName); + // Change the background position + _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); + // Create the puzzle reference table createReferenceTable(); -- cgit v1.2.3 From bbb8598a3e62e80b1a5efc5de4598276770ca6f1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 09:48:29 -0500 Subject: ZVISION: Modify cmdLoadImage to match new render code --- engines/zvision/console.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index e7c46b95a9..dfafb26e2a 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -57,11 +57,9 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { bool Console::cmdLoadImage(int argc, const char **argv) { if (argc == 4) - _engine->getRenderManager()->renderImageToBackbuffer(argv[1], atoi(argv[2]), atoi(argv[3])); - else if (argc == 8) - _engine->getRenderManager()->renderImageToBackbuffer(argv[1], atoi(argv[2]), atoi(argv[3]), Common::Rect(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]))); + _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3])); else { - DebugPrintf("Use loadimage [ ] to load an image to the screen\n"); + DebugPrintf("Use loadimage to load an image to the screen\n"); return true; } -- cgit v1.2.3 From 8fafde8a33a84fd5819e2a3a9ff9ebf6a66889a5 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 09:51:24 -0500 Subject: ZVISION: Re-enable video handling now that AVI code is fixed --- engines/zvision/scr_file_handling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index ff7df20ac5..5b8af48047 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -251,7 +251,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:streamvideo*", true)) { - //actionList.push_back(Common::SharedPtr(new ActionStreamVideo(line))); + actionList.push_back(Common::SharedPtr(new ActionStreamVideo(line))); } else if (line.matchString("*:syncsound*", true)) { -- cgit v1.2.3 From 7e6a04dc62161f1b013445ba20ee7465b57d6412 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 11:13:14 -0500 Subject: ZVISION: Store the background offset from the center instead of from the top left corner --- engines/zvision/render_manager.cpp | 66 ++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index e4106109ba..7d8ba75b8d 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -38,8 +38,8 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, : _system(system), _workingWidth(workingWindow.width()), _workingHeight(workingWindow.height()), - _screenCenterX((workingWindow.left + workingWindow.right) /2), - _screenCenterY((workingWindow.top + workingWindow.bottom) /2), + _screenCenterX(_workingWidth / 2), + _screenCenterY(_workingHeight / 2), _workingWindow(workingWindow), _pixelFormat(pixelFormat), _currentBackground(0), @@ -75,7 +75,7 @@ void RenderManager::update(uint deltaTimeInMillis) { } // Choose the direction of movement using the sign of the velocity - moveBackground(_backgroundInverseVelocity < 0 ? numberOfSteps : -numberOfSteps); + moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps); } } @@ -85,32 +85,20 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest // Take care of negative destinations if (destinationX < 0) { - subRectX = destinationX + surface.w; + subRectX = -destinationX; destinationX = 0; - if (wrap) { - _backgroundOffset.x += surface.w; - } } else if (destinationX >= surface.w) { // Take care of extreme positive destinations destinationX -= surface.w; - if (wrap) { - _backgroundOffset.x -= surface.w; - } } // Take care of negative destinations if (destinationY < 0) { - subRectY = destinationY + surface.h; + subRectY = -destinationY; destinationY = 0; - if (wrap) { - _backgroundOffset.y += surface.h; - } } else if (destinationY >= surface.h) { // Take care of extreme positive destinations destinationY -= surface.h; - if (wrap) { - _backgroundOffset.y -= surface.h; - } } if (wrap) { @@ -224,15 +212,25 @@ const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point & // Convert from screen space to working window space Common::Point newPoint(point - Common::Point(_workingWindow.left, _workingWindow.top)); - if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { + RenderTable::RenderState state = _renderTable.getRenderState(); + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { newPoint = _renderTable.convertWarpedCoordToFlatCoord(newPoint); } - newPoint -= _backgroundOffset; + if (state == RenderTable::PANORAMA) { + newPoint -= (Common::Point(_screenCenterX, 0) - _backgroundOffset); + } else if (state == RenderTable::TILT) { + newPoint -= (Common::Point(0, _screenCenterY) - _backgroundOffset); + } + if (newPoint.x < 0) newPoint.x += _backgroundWidth; + else if (newPoint.x >= _backgroundWidth) + newPoint.x -= _backgroundWidth; if (newPoint.y < 0) newPoint.y += _backgroundHeight; + else if (newPoint.y >= _backgroundHeight) + newPoint.y -= _backgroundHeight; return newPoint; } @@ -254,16 +252,16 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { } _currentBackground = file; - renderImageToScreen(*_currentBackground, _backgroundOffset.x, _backgroundOffset.y, true); + moveBackground(0); } void RenderManager::setBackgroundPosition(int offset) { RenderTable::RenderState state = _renderTable.getRenderState(); if (state == RenderTable::TILT) { _backgroundOffset.x = 0; - _backgroundOffset.y = _screenCenterY - offset; + _backgroundOffset.y = offset; } else if (state == RenderTable::PANORAMA) { - _backgroundOffset.x = _screenCenterX - offset; + _backgroundOffset.x = offset; _backgroundOffset.y = 0; } else { _backgroundOffset.x = 0; @@ -290,11 +288,31 @@ void RenderManager::moveBackground(int offset) { if (state == RenderTable::TILT) { _backgroundOffset += Common::Point(0, offset); - renderImageToScreen(*_currentBackground, 0, _backgroundOffset.y, true); + if (_backgroundOffset.x <= -_backgroundWidth) + _backgroundOffset.x += _backgroundWidth; + else if (_backgroundOffset.x >= _backgroundWidth) + _backgroundOffset.x += _backgroundWidth; + + if (_backgroundOffset.y <= -_backgroundHeight) + _backgroundOffset.y += _backgroundHeight; + else if (_backgroundOffset.y >= _backgroundHeight) + _backgroundOffset.y += _backgroundHeight; + + renderImageToScreen(*_currentBackground, 0, _screenCenterY - _backgroundOffset.y, true); } else if (state == RenderTable::PANORAMA) { _backgroundOffset += Common::Point(offset, 0); - renderImageToScreen(*_currentBackground, _backgroundOffset.x, 0, true); + if (_backgroundOffset.x <= -_backgroundWidth) + _backgroundOffset.x += _backgroundWidth; + else if (_backgroundOffset.x >= _backgroundWidth) + _backgroundOffset.x += _backgroundWidth; + + if (_backgroundOffset.y <= -_backgroundHeight) + _backgroundOffset.y += _backgroundHeight; + else if (_backgroundOffset.y >= _backgroundHeight) + _backgroundOffset.y += _backgroundHeight; + + renderImageToScreen(*_currentBackground, _screenCenterX - _backgroundOffset.x, 0, true); } else { renderImageToScreen(*_currentBackground, 0, 0); } -- cgit v1.2.3 From acea03a9cd9ce14b210fe4b2fc650e34e8ae657b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 11:36:42 -0500 Subject: ZVISION: Allow RenderTable indicies to be negative --- engines/zvision/render_table.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 23394b7bc2..7188530075 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -100,18 +100,18 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap, bool isTransposed) { for (int16 y = subRect.top; y < subRect.bottom; y++) { - uint16 normalizedY = y - subRect.top; - uint32 internalColumnIndex = (normalizedY + destinationY) * _numColumns; - uint32 destColumnIndex = normalizedY * _numColumns; + int16 normalizedY = y - subRect.top; + int32 internalColumnIndex = (normalizedY + destinationY) * _numColumns; + int32 destColumnIndex = normalizedY * _numColumns; for (int16 x = subRect.left; x < subRect.right; x++) { - uint16 normalizedX = x - subRect.left; + int16 normalizedX = x - subRect.left; - uint32 index = internalColumnIndex + normalizedX + destinationX; + int32 index = internalColumnIndex + normalizedX + destinationX; // RenderTable only stores offsets from the original coordinates - uint16 sourceYIndex = y + _internalBuffer[index].y; - uint16 sourceXIndex = x + _internalBuffer[index].x; + int16 sourceYIndex = y + _internalBuffer[index].y; + int16 sourceXIndex = x + _internalBuffer[index].x; if (wrap) { if (sourceXIndex >= imageWidth) { @@ -127,10 +127,10 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 im } } else { // Clamp the yIndex to the size of the image - sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); + sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); // Clamp the xIndex to the size of the image - sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); + sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); } if (isTransposed) { -- cgit v1.2.3 From 80cba07b311a56a9e3dd6ce5ca5a291299b95a8d Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 20:32:34 -0500 Subject: ZVISION: Allow destinations to be negative --- engines/zvision/render_manager.cpp | 4 ++-- engines/zvision/render_manager.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 7d8ba75b8d..932c797c11 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -139,7 +139,7 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest } } -void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, bool wrap) { +void RenderManager::renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap) { Common::File file; if (!file.open(fileName)) { @@ -150,7 +150,7 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d renderImageToScreen(file, destinationX, destinationY); } -void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, bool wrap) { +void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, int16 destinationX, int16 destinationY, bool wrap) { // Read the magic number // Some files are true TGA, while others are TGZ uint32 fileType; diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index cdcd52b67d..9683ee0bf2 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -107,7 +107,7 @@ public: * @param destinationX X position where the image should be put. Coords are in working window space, not screen space! * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! */ - void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, bool wrap = false); + void renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap = false); /** * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. @@ -117,7 +117,7 @@ public: * @param destinationX X position where the image should be put. Coords are in working window space, not screen space! * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! */ - void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, bool wrap = false); + void renderImageToScreen(Common::SeekableReadStream &stream, int16 destinationX, int16 destinationY, bool wrap = false); /** * Sets the current background image to be used by the RenderManager and immediately -- cgit v1.2.3 From f1d44bdf8cbcf69805713f042b16480227e14d6c Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 20:34:44 -0500 Subject: ZVISION: Protect against indicies that are more than an imageWidth/Height from the actual image dimensions --- engines/zvision/render_table.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 7188530075..ec0cdba7c2 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -114,15 +114,17 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 im int16 sourceXIndex = x + _internalBuffer[index].x; if (wrap) { - if (sourceXIndex >= imageWidth) { + while (sourceXIndex >= imageWidth) { sourceXIndex -= imageWidth; - } else if (sourceXIndex < 0) { + } + while (sourceXIndex < 0) { sourceXIndex += imageWidth; } - if (sourceYIndex >= imageHeight) { + while (sourceYIndex >= imageHeight) { sourceYIndex -= imageHeight; - } else if (sourceYIndex < 0) { + } + while (sourceYIndex < 0) { sourceYIndex += imageHeight; } } else { -- cgit v1.2.3 From 77219705e6f225c4296b5d5346b2abd8fe2aaade Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 20:35:57 -0500 Subject: ZVISION: Prevent endless looping due to incorrect file structure Some of the .scr files don't properly close the last curly brace --- engines/zvision/control.cpp | 6 +++--- engines/zvision/scr_file_handling.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index 02d15fe9d0..eeba9b3214 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -44,7 +44,7 @@ void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream & Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); - while (!line.contains('}')) { + while (!stream.eos() && !line.contains('}')) { if (line.matchString("angle*", true)) { float fov; sscanf(line.c_str(), "angle(%f)", &fov); @@ -78,7 +78,7 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); - while (!line.contains('}')) { + while (!stream.eos() && !line.contains('}')) { if (line.matchString("angle*", true)) { float fov; sscanf(line.c_str(), "angle(%f)", &fov); @@ -110,7 +110,7 @@ void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::Seekab Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); - while (!line.contains('}')) { + while (!stream.eos() && !line.contains('}')) { if (line.matchString("*_hotspot*", true)) { uint x; uint y; diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 5b8af48047..9c99ce184d 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -76,7 +76,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); - while (!line.contains('}')) { + while (!stream.eos() && !line.contains('}')) { if (line.matchString("criteria {", true)) { Puzzle::Criteria criteria; if (parseCriteria(&criteria, stream)) { @@ -103,7 +103,7 @@ bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableRe return false; } - while (!line.contains('}')) { + while (!stream.eos() && !line.contains('}')) { // Split the string into tokens using ' ' as a delimiter Common::StringTokenizer tokenizer(line); Common::String token; @@ -147,7 +147,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis trimCommentsAndWhiteSpace(&line); // TODO: Re-order the if-then statements in order of highest occurrence - while (!line.contains('}')) { + while (!stream.eos() && !line.contains('}')) { if (line.empty()) { line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -284,7 +284,7 @@ uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); - while (!line.contains('}')) { + while (!stream.eos() && !line.contains('}')) { if (line.matchString("ONCE_PER_INST", true)) { flags |= Puzzle::ONCE_PER_INST; } else if (line.matchString("DO_ME_NOW", true)) { -- cgit v1.2.3 From eafd6608cf1e54bb3551671e6fd4a8c6626d44d9 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 20:36:46 -0500 Subject: ZVISION: Change the CLIP template argument to match the type of the indicies --- engines/zvision/render_table.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index ec0cdba7c2..0a8175e54e 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -129,10 +129,10 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 im } } else { // Clamp the yIndex to the size of the image - sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); + sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); // Clamp the xIndex to the size of the image - sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); + sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); } if (isTransposed) { -- cgit v1.2.3 From c840d082ceee068446176024b86031f24ed0a968 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 20:38:06 -0500 Subject: ZVISION: Allow ONCE_PER_INST puzzles to be repeated once per room instead of once per game --- engines/zvision/script_manager.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 3ca9f01adc..8a1d1c98ed 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -108,11 +108,9 @@ void ScriptManager::checkPuzzleCriteria() { Puzzle *puzzle = _puzzlesToCheck.pop(); // Check if the puzzle is already finished - // If it doesn't have the flag ONCE_PER_INST it can be done more than once // Also check that the puzzle isn't disabled if (getStateValue(puzzle->key) == 1 && - (puzzle->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST && - (puzzle->flags & Puzzle::DISABLED) == 0) { + (puzzle->flags & Puzzle::DISABLED) == 0) { continue; } @@ -226,18 +224,28 @@ void ScriptManager::changeLocationIntern() { // Change the background position _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); - // Create the puzzle reference table - createReferenceTable(); - // Add all the local puzzles to the stack to be checked for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + // Reset any Puzzles that have the flag ONCE_PER_INST + if ((*iter).flags & Puzzle::ONCE_PER_INST == Puzzle::ONCE_PER_INST) { + setStateValue((*iter).key, 0); + } + _puzzlesToCheck.push(&(*iter)); } // Add all the global puzzles to the stack to be checked for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + // Reset any Puzzles that have the flag ONCE_PER_INST + if ((*iter).flags & Puzzle::ONCE_PER_INST == Puzzle::ONCE_PER_INST) { + setStateValue((*iter).key, 0); + } + _puzzlesToCheck.push(&(*iter)); } + + // Create the puzzle reference table + createReferenceTable(); } } // End of namespace ZVision -- cgit v1.2.3 From 09ae4443d4d8ea9781ce7c98c26c4010b4a3427a Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 17 Aug 2013 20:39:29 -0500 Subject: ZVISION: Reset push_toggle controls global state value to 0 during initialization --- engines/zvision/control.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index eeba9b3214..b55452c876 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -27,6 +27,7 @@ #include "zvision/zvision.h" #include "zvision/render_manager.h" #include "zvision/render_table.h" +#include "zvision/script_manager.h" #include "zvision/control.h" #include "zvision/utility.h" @@ -103,6 +104,8 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre } void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream) { + engine->getScriptManager()->setStateValue(key, 0); + Common::Rect hotspot; Common::String cursorName; -- cgit v1.2.3 From 589c29e6e15e5d2957b92b1a03c6bf43a327f541 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:17:37 -0500 Subject: ZVISION: Add newlines to console debug statements --- engines/zvision/console.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index dfafb26e2a..69d19ab53a 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -168,7 +168,7 @@ bool Console::cmdSetPanoramaScale(int argc, const char **argv) { bool Console::cmdChangeLocation(int argc, const char **argv) { if (argc != 6) { - DebugPrintf("Use changelocation to change your location"); + DebugPrintf("Use changelocation to change your location\n"); return true; } @@ -179,7 +179,7 @@ bool Console::cmdChangeLocation(int argc, const char **argv) { bool Console::cmdDumpFile(int argc, const char **argv) { if (argc != 2) { - DebugPrintf("Use dumpfile to dump a file"); + DebugPrintf("Use dumpfile to dump a file\n"); return true; } -- cgit v1.2.3 From 1f653f9a34e3462c0ab13aeaf5f68b7070f45770 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:19:01 -0500 Subject: ZVISION: Allow MouseEvents to be unregistered --- engines/zvision/events.cpp | 11 +++++++++++ engines/zvision/zvision.h | 3 +++ 2 files changed, 14 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index ca96f52457..bea476fa41 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -39,6 +39,17 @@ void ZVision::registerMouseEvent(const MouseEvent &event) { _mouseEvents.push_back(event); } +bool ZVision::removeMouseEvent(const uint32 key) { + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + if ((*iter)._key == key) { + _mouseEvents.erase(iter); + return true; + } + } + + return false; +} + void ZVision::clearAllMouseEvents() { _mouseEvents.clear(); } diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 58812d4d11..9e9d5db951 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -133,6 +133,9 @@ public: * @param event The event to register */ void registerMouseEvent(const MouseEvent &event); + + bool removeMouseEvent(const uint32 key); + /** Remove all MouseEvents from the event system */ void clearAllMouseEvents(); -- cgit v1.2.3 From 9051f6213671316c336242274490e17d356fef0e Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:19:22 -0500 Subject: ZVISION: Make MousEvent fully public --- engines/zvision/mouse_event.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/mouse_event.h b/engines/zvision/mouse_event.h index 5537bcc4e5..90a093f894 100644 --- a/engines/zvision/mouse_event.h +++ b/engines/zvision/mouse_event.h @@ -34,9 +34,9 @@ class ZVision; class MouseEvent { public: + MouseEvent() : _key(0) {} MouseEvent(uint32 key, const Common::Rect &hotspot, const Common::String hoverCursor); -private: /** The Control key */ uint32 _key; /** @@ -47,7 +47,6 @@ private: /** The cursor to use when hovering over _hotspot */ Common::String _hoverCursor; -public: /** * Does a simple Rect::contains() using _hotspot * -- cgit v1.2.3 From 25deaf3a35efac8e5103e193f5f68409a87047a0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:20:22 -0500 Subject: ZVISION: Reset MouseEvent globalStateValue's when clearing them --- engines/zvision/events.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index bea476fa41..f382bb63e0 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -31,6 +31,7 @@ #include "zvision/cursor_manager.h" #include "zvision/render_manager.h" +#include "zvision/script_manager.h" #include "zvision/mouse_event.h" namespace ZVision { @@ -42,6 +43,7 @@ void ZVision::registerMouseEvent(const MouseEvent &event) { bool ZVision::removeMouseEvent(const uint32 key) { for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { if ((*iter)._key == key) { + _scriptManager->setStateValue((*iter)._key, 0); _mouseEvents.erase(iter); return true; } @@ -51,6 +53,11 @@ bool ZVision::removeMouseEvent(const uint32 key) { } void ZVision::clearAllMouseEvents() { + // Clear the state values of all the events + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + _scriptManager->setStateValue((*iter)._key, 0); + } + _mouseEvents.clear(); } -- cgit v1.2.3 From 3a23873c45f8b274836eacd8d1de471da6defb5b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:25:34 -0500 Subject: ZVISION: Convert _activeControls from a List to a HashMap --- engines/zvision/scr_file_handling.cpp | 21 +++++++-------------- engines/zvision/script_manager.h | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 9c99ce184d..10e5c8f0eb 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -62,12 +62,7 @@ void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) _activePuzzles.push_back(puzzle); } } else if (line.matchString("control:*", true)) { - Common::SharedPtr control; - - // Some controls don't require nodes. They just initialize the scene - if (parseControl(line, file, control)) { - _activeControls.push_back(control); - } + parseControl(line, file); } } } @@ -300,7 +295,7 @@ uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { return flags; } -bool ScriptManager::parseControl(Common::String &line, Common::SeekableReadStream &stream, Common::SharedPtr &control) { +void ScriptManager::parseControl(Common::String &line, Common::SeekableReadStream &stream) { uint32 key; char controlTypeBuffer[20]; @@ -309,21 +304,19 @@ bool ScriptManager::parseControl(Common::String &line, Common::SeekableReadStrea Common::String controlType(controlTypeBuffer); if (controlType.equalsIgnoreCase("push_toggle")) { - Control::parsePushToggleControl(key, _engine, stream); - return false; + _activeControls[key] = new PushToggleControl(key, stream); + return; } else if (controlType.equalsIgnoreCase("flat")) { Control::parseFlatControl(_engine); - return false; + return; } else if (controlType.equalsIgnoreCase("pana")) { Control::parsePanoramaControl(_engine, stream); - return false; + return; } else if (controlType.equalsIgnoreCase("tilt")) { Control::parseTiltControl(_engine, stream); - return false; + return; } - - return true; } } // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index c0801edd5e..3d64727506 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -70,7 +70,7 @@ private: /** Holds the global puzzles */ Common::List_globalPuzzles; /** Holds the currently active controls */ - Common::List > _activeControls; + Common::HashMap _activeControls; Location _nextLocation; bool _changeLocation; @@ -145,7 +145,7 @@ private: * @param line The line initially read * @param stream Scr file stream */ - bool parseControl(Common::String &line, Common::SeekableReadStream &stream, Common::SharedPtr &control); + void parseControl(Common::String &line, Common::SeekableReadStream &stream); }; -- cgit v1.2.3 From 908e784957ec3cf01bc54a5c76c18f5ed6a8faa6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:28:16 -0500 Subject: ZVISION: Allow controls to be enabled or disabled --- engines/zvision/control.h | 9 +++++++-- engines/zvision/script_manager.cpp | 21 +++++++++++++++++++++ engines/zvision/script_manager.h | 3 +++ 3 files changed, 31 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 2d5426c0c4..b374383a45 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -35,11 +35,16 @@ class ZVision; class Control { public: + Control() : _key(0), _enabled(false) {} virtual ~Control() {} - virtual bool execute(ZVision *engine) = 0; + virtual bool enable(ZVision *engine) = 0; + virtual bool disable(ZVision *engine) { return true; } + +public: + uint32 _key; protected: - uint32 key; + bool _enabled; // Static member functions public: diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 8a1d1c98ed..13f30ca0d2 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -185,6 +185,22 @@ void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) { _globalState[key] += valueToAdd; } +bool ScriptManager::enableControl(uint32 key) { + if (!_activeControls.contains(key)) { + return false; + } else { + return _activeControls[key]->enable(_engine); + } +} + +bool ScriptManager::disableControl(uint32 key) { + if (!_activeControls.contains(key)) { + return false; + } else { + return _activeControls[key]->disable(_engine); + } +} + void ScriptManager::addActionNode(const Common::SharedPtr &node) { _activeNodes.push_back(node); } @@ -225,6 +241,11 @@ void ScriptManager::changeLocationIntern() { _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); // Add all the local puzzles to the stack to be checked + // Enable all the controls + for (Common::HashMap::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + (*iter)._value->enable(_engine); + } + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST if ((*iter).flags & Puzzle::ONCE_PER_INST == Puzzle::ONCE_PER_INST) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 3d64727506..7012ee0c5e 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -84,6 +84,9 @@ public: void setStateValue(uint32 key, uint value); void addToStateValue(uint32 key, uint valueToAdd); + bool enableControl(uint32 key); + bool disableControl(uint32 key); + void addActionNode(const Common::SharedPtr &node); void changeLocation(char world, char room, char node, char view, uint32 offset); -- cgit v1.2.3 From 5a86355e7dae3b00924ce95275f1fea9346a6211 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:29:23 -0500 Subject: ZVISION: Implement ActionEnableControl and ActionDisableControl --- engines/zvision/actions.cpp | 34 ++++++++++++++++++++++++++++++++++ engines/zvision/actions.h | 6 +++--- engines/zvision/scr_file_handling.cpp | 6 ++---- 3 files changed, 39 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 504c250597..affa8f5a9c 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -110,6 +110,40 @@ bool ActionCrossfade::execute(ZVision *engine) { } +////////////////////////////////////////////////////////////////////////////// +// ActionDisableControl +////////////////////////////////////////////////////////////////////////////// + +ActionDisableControl::ActionDisableControl(const Common::String &line) { + sscanf(line.c_str(), "%*[^(](%u)", &_key); +} + +bool ActionDisableControl::execute(ZVision *engine) { + debug("Disabling control %u", _key); + + engine->getScriptManager()->disableControl(_key); + + return true; +} + + +////////////////////////////////////////////////////////////////////////////// +// ActionEnableControl +////////////////////////////////////////////////////////////////////////////// + +ActionEnableControl::ActionEnableControl(const Common::String &line) { + sscanf(line.c_str(), "%*[^(](%u)", &_key); +} + +bool ActionEnableControl::execute(ZVision *engine) { + debug("Enabling control %u", _key); + + engine->getScriptManager()->enableControl(_key); + + return true; +} + + ////////////////////////////////////////////////////////////////////////////// // ActionMusic ////////////////////////////////////////////////////////////////////////////// diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index aa67be20c7..1d87b8025c 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -168,6 +168,7 @@ public: bool execute(ZVision *engine); private: + uint32 _key; }; class ActionDisableVenus : public ResultAction { @@ -188,10 +189,8 @@ private: class ActionDissolve : public ResultAction { public: - ActionDissolve(const Common::String &line); + ActionDissolve(); bool execute(ZVision *engine); - -private: }; class ActionDistort : public ResultAction { @@ -208,6 +207,7 @@ public: bool execute(ZVision *engine); private: + uint32 _key; }; class ActionMusic : public ResultAction { diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 10e5c8f0eb..3fee767135 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -177,8 +177,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:disable_control*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionDisableControl(line))); } else if (line.matchString("*:disable_venus*", true)) { @@ -192,8 +191,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:enable_control*", true)) { - - + actionList.push_back(Common::SharedPtr(new ActionEnableControl(line))); } else if (line.matchString("*:flush_mouse_events*", true)) { -- cgit v1.2.3 From 46ab3557660221b2896c0d5cd4a7d3fb0464d1d1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:38:56 -0500 Subject: ZVISION: Allow Puzzles to have mutiple 'sets' of CriteriaEntries --- engines/zvision/puzzle.h | 4 +- engines/zvision/scr_file_handling.cpp | 32 +++++++------ engines/zvision/script_manager.cpp | 89 +++++++++++++++++++++-------------- engines/zvision/script_manager.h | 2 +- 4 files changed, 74 insertions(+), 53 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index e7846f5296..36787e7ba1 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -41,7 +41,7 @@ struct Puzzle { }; /** Criteria for a Puzzle result to be fired */ - struct Criteria { + struct CriteriaEntry { /** The key of a global state */ uint32 key; /** @@ -62,7 +62,7 @@ struct Puzzle { }; uint32 key; - Common::List criteriaList; + Common::List > criteriaList; // This has to be list of pointers because ResultAction is abstract Common::List > resultActions; uint flags; diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 3fee767135..dd2754c12f 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -73,10 +73,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre while (!stream.eos() && !line.contains('}')) { if (line.matchString("criteria {", true)) { - Puzzle::Criteria criteria; - if (parseCriteria(&criteria, stream)) { - puzzle.criteriaList.push_back(criteria); - } + parseCriteria(stream, puzzle.criteriaList); } else if (line.matchString("results {", true)) { parseResults(stream, puzzle.resultActions); } else if (line.matchString("flags {", true)) { @@ -88,7 +85,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre } } -bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const { +bool ScriptManager::parseCriteria(Common::SeekableReadStream &stream, Common::List > &criteriaList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -98,37 +95,44 @@ bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableRe return false; } + // Create a new List to hold the CriteriaEntries + criteriaList.push_back(Common::List()); + while (!stream.eos() && !line.contains('}')) { + Puzzle::CriteriaEntry entry; + // Split the string into tokens using ' ' as a delimiter Common::StringTokenizer tokenizer(line); Common::String token; // Parse the id out of the first token token = tokenizer.nextToken(); - sscanf(token.c_str(), "[%u]", &(criteria->key)); + sscanf(token.c_str(), "[%u]", &(entry.key)); // Parse the operator out of the second token token = tokenizer.nextToken(); if (token.c_str()[0] == '=') - criteria->criteriaOperator = Puzzle::EQUAL_TO; + entry.criteriaOperator = Puzzle::EQUAL_TO; else if (token.c_str()[0] == '!') - criteria->criteriaOperator = Puzzle::NOT_EQUAL_TO; + entry.criteriaOperator = Puzzle::NOT_EQUAL_TO; else if (token.c_str()[0] == '>') - criteria->criteriaOperator = Puzzle::GREATER_THAN; + entry.criteriaOperator = Puzzle::GREATER_THAN; else if (token.c_str()[0] == '<') - criteria->criteriaOperator = Puzzle::LESS_THAN; + entry.criteriaOperator = Puzzle::LESS_THAN; // First determine if the last token is an id or a value // Then parse it into 'argument' token = tokenizer.nextToken(); if (token.contains('[')) { - sscanf(token.c_str(), "[%u]", &(criteria->argument)); - criteria->argumentIsAKey = true; + sscanf(token.c_str(), "[%u]", &(entry.argument)); + entry.argumentIsAKey = true; } else { - sscanf(token.c_str(), "%u", &(criteria->argument)); - criteria->argumentIsAKey = false; + sscanf(token.c_str(), "%u", &(entry.argument)); + entry.argumentIsAKey = false; } + criteriaList.back().push_back(entry); + line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 13f30ca0d2..9796a95353 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -61,13 +61,16 @@ void ScriptManager::createReferenceTable() { for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { Puzzle *puzzlePtr = &(*activePuzzleIter); - // Iterate through each Criteria and add a reference from the criteria key to the Puzzle - for (Common::List::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { - _referenceTable[criteriaIter->key].push_back(puzzlePtr); - - // If the argument is a key, add a reference to it as well - if (criteriaIter->argumentIsAKey) - _referenceTable[criteriaIter->argument].push_back(puzzlePtr); + // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle + for (Common::List >::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + _referenceTable[entryIter->key].push_back(puzzlePtr); + + // If the argument is a key, add a reference to it as well + if (entryIter->argumentIsAKey) { + _referenceTable[entryIter->argument].push_back(puzzlePtr); + } + } } } @@ -75,13 +78,16 @@ void ScriptManager::createReferenceTable() { for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { Puzzle *puzzlePtr = &(*globalPuzzleIter); - // Iterate through each Criteria and add a reference from the criteria key to the Puzzle - for (Common::List::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { - _referenceTable[criteriaIter->key].push_back(puzzlePtr); + // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle + for (Common::List >::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + _referenceTable[entryIter->key].push_back(puzzlePtr); - // If the argument is a key, add a reference to it as well - if (criteriaIter->argumentIsAKey) - _referenceTable[criteriaIter->argument].push_back(puzzlePtr); + // If the argument is a key, add a reference to it as well + if (entryIter->argumentIsAKey) { + _referenceTable[entryIter->argument].push_back(puzzlePtr); + } + } } } @@ -115,32 +121,43 @@ void ScriptManager::checkPuzzleCriteria() { } // Check each Criteria + bool criteriaMet = false; - for (Common::List::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { - // Get the value to compare against - uint argumentValue; - if ((*iter).argumentIsAKey) - argumentValue = getStateValue(iter->argument); - else - argumentValue = iter->argument; - - // Do the comparison - switch ((*iter).criteriaOperator) { - case Puzzle::EQUAL_TO: - criteriaMet = getStateValue(iter->key) == argumentValue; - break; - case Puzzle::NOT_EQUAL_TO: - criteriaMet = getStateValue(iter->key) != argumentValue; - break; - case Puzzle::GREATER_THAN: - criteriaMet = getStateValue(iter->key) > argumentValue; - break; - case Puzzle::LESS_THAN: - criteriaMet = getStateValue(iter->key) < argumentValue; - break; + for (Common::List >::iterator criteriaIter = puzzle->criteriaList.begin(); criteriaIter != puzzle->criteriaList.end(); criteriaIter++) { + criteriaMet = false; + + for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + // Get the value to compare against + uint argumentValue; + if ((*entryIter).argumentIsAKey) + argumentValue = getStateValue(entryIter->argument); + else + argumentValue = entryIter->argument; + + // Do the comparison + switch ((*entryIter).criteriaOperator) { + case Puzzle::EQUAL_TO: + criteriaMet = getStateValue(entryIter->key) == argumentValue; + break; + case Puzzle::NOT_EQUAL_TO: + criteriaMet = getStateValue(entryIter->key) != argumentValue; + break; + case Puzzle::GREATER_THAN: + criteriaMet = getStateValue(entryIter->key) > argumentValue; + break; + case Puzzle::LESS_THAN: + criteriaMet = getStateValue(entryIter->key) < argumentValue; + break; + } + + // If one check returns false, don't keep checking + if (!criteriaMet) { + break; + } } - if (!criteriaMet) { + // If any of the Criteria are *fully* met, then execute the results + if (criteriaMet) { break; } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 7012ee0c5e..d484531470 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -122,7 +122,7 @@ private: * @param stream Scr file stream * @return Whether any criteria were read */ - bool parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const; + bool parseCriteria(Common::SeekableReadStream &stream, Common::List > &criteriaList) const; /** * Parses the stream into a ResultAction objects -- cgit v1.2.3 From 6ee93ad5c2b2ea577a587af172a28b100a9956d8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:41:52 -0500 Subject: ZVISION: Convert _puzzlesToCheck to a Queue instead of a Stack --- engines/zvision/script_manager.cpp | 4 ++-- engines/zvision/script_manager.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 9796a95353..8a1b60a0dc 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -257,12 +257,12 @@ void ScriptManager::changeLocationIntern() { // Change the background position _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); - // Add all the local puzzles to the stack to be checked // Enable all the controls for (Common::HashMap::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { (*iter)._value->enable(_engine); } + // Add all the local puzzles to the queue to be checked for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST if ((*iter).flags & Puzzle::ONCE_PER_INST == Puzzle::ONCE_PER_INST) { @@ -272,7 +272,7 @@ void ScriptManager::changeLocationIntern() { _puzzlesToCheck.push(&(*iter)); } - // Add all the global puzzles to the stack to be checked + // Add all the global puzzles to the queue to be checked for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST if ((*iter).flags & Puzzle::ONCE_PER_INST == Puzzle::ONCE_PER_INST) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index d484531470..362c4efed9 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -24,7 +24,7 @@ #define ZVISION_SCRIPT_MANAGER_H #include "common/hashmap.h" -#include "common/stack.h" +#include "common/queue.h" #include "zvision/puzzle.h" #include "zvision/control.h" @@ -64,7 +64,7 @@ private: /** References _globalState keys to Puzzles */ Common::HashMap > _referenceTable; /** Holds the Puzzles that should be checked this frame */ - Common::Stack _puzzlesToCheck; + Common::Queue _puzzlesToCheck; /** Holds the currently active puzzles */ Common::List _activePuzzles; /** Holds the global puzzles */ -- cgit v1.2.3 From d26c814d1e0ed76b4b4440e5798ccd012bd4858d Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:42:24 -0500 Subject: ZVISION: Force & operator to have precedence over == operator --- engines/zvision/script_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 8a1b60a0dc..c80b5a2bc4 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -265,7 +265,7 @@ void ScriptManager::changeLocationIntern() { // Add all the local puzzles to the queue to be checked for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST - if ((*iter).flags & Puzzle::ONCE_PER_INST == Puzzle::ONCE_PER_INST) { + if (((*iter).flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { setStateValue((*iter).key, 0); } @@ -275,7 +275,7 @@ void ScriptManager::changeLocationIntern() { // Add all the global puzzles to the queue to be checked for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST - if ((*iter).flags & Puzzle::ONCE_PER_INST == Puzzle::ONCE_PER_INST) { + if (((*iter).flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { setStateValue((*iter).key, 0); } -- cgit v1.2.3 From 5eab8a8d77a070b752d5f4e02bad73c5e85dd4a6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 15:42:45 -0500 Subject: ZVISION: Reimplement PushToggleControl --- engines/zvision/control.cpp | 49 ++++++++++++++++++++++++++++++++++++--------- engines/zvision/control.h | 12 +++++++++++ 2 files changed, 51 insertions(+), 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index b55452c876..acc970e167 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -103,12 +103,15 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre renderTable->generateRenderTable(); } -void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream) { - engine->getScriptManager()->setStateValue(key, 0); - Common::Rect hotspot; - Common::String cursorName; - +////////////////////////////////////////////////////////////////////////////// +// PushToggleControl +////////////////////////////////////////////////////////////////////////////// + +PushToggleControl::PushToggleControl(uint32 key, Common::SeekableReadStream &stream) + : Control() { + _event._key = _key = key; + // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -121,23 +124,49 @@ void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::Seekab uint height; sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); - - hotspot = Common::Rect(x, y, x + width, y + height); + + _event._hotspot = Common::Rect(x, y, x + width, y + height); } else if (line.matchString("cursor*", true)) { char nameBuffer[25]; sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); - cursorName = Common::String(nameBuffer); + _event._hoverCursor = Common::String(nameBuffer); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } - if (!hotspot.isEmpty() && !cursorName.empty()) { - engine->registerMouseEvent(MouseEvent(key, hotspot, cursorName)); + if (_event._hotspot.isEmpty() || _event._hoverCursor.empty()) { + warning("Push_toggle cursor %u was parsed incorrectly", &key); + } +} + +bool PushToggleControl::enable(ZVision *engine) { + if (!_enabled) { + engine->registerMouseEvent(_event); + _enabled = true; + return true; + } + + debug("Control %u is already enabled", _key); + return false; +} + +bool PushToggleControl::disable(ZVision *engine) { + if (_enabled) { + engine->removeMouseEvent(_key); + _enabled = false; + return true; } + + debug("Control %u is already disabled", _key); + return false; +} + +void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream) { + } } // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index b374383a45..f17ee7750d 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -25,6 +25,8 @@ #include "common/types.h" +#include "zvision/mouse_event.h" + namespace Common { class SeekableReadStream; } @@ -54,6 +56,16 @@ public: static void parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream); }; +class PushToggleControl : public Control { +public: + PushToggleControl(uint32 key, Common::SeekableReadStream &stream); + bool enable(ZVision *engine); + bool disable(ZVision *engine); + +private: + MouseEvent _event; +}; + } // End of namespace ZVision #endif -- cgit v1.2.3 From 4d5914ac2157073339b0c348345dedbffd5ee030 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 16:08:37 -0500 Subject: ZVISION: Fix argument passing for warning() --- engines/zvision/control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index acc970e167..106d938889 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -139,7 +139,7 @@ PushToggleControl::PushToggleControl(uint32 key, Common::SeekableReadStream &str } if (_event._hotspot.isEmpty() || _event._hoverCursor.empty()) { - warning("Push_toggle cursor %u was parsed incorrectly", &key); + warning("Push_toggle cursor %u was parsed incorrectly", key); } } -- cgit v1.2.3 From 2fcba2743c1670ba8a7428945714e896238e082e Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 16:09:08 -0500 Subject: ZVISION: Don't cast away const qualifier --- engines/zvision/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 28c26f6f2a..4066c5dcd5 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -148,10 +148,10 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d if (frame) { if (scale != 1) { - scaleBuffer((byte *)frame->getBasePtr(0, 0), scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); + scaleBuffer((const byte *)frame->getBasePtr(0, 0), scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); _system->copyRectToScreen(scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); } else { - _system->copyRectToScreen((byte *)frame->getBasePtr(0, 0), pitch, x, y, finalWidth, finalHeight); + _system->copyRectToScreen((const byte *)frame->getBasePtr(0, 0), pitch, x, y, finalWidth, finalHeight); } _system->updateScreen(); -- cgit v1.2.3 From b0635edff8c0d5b05cef8a22c74c569921a8346b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 18 Aug 2013 19:51:27 -0500 Subject: ZVISION: Revert to normal pointers instead of shared pointers --- engines/zvision/puzzle.h | 2 +- engines/zvision/scr_file_handling.cpp | 24 ++++++++++++------------ engines/zvision/script_manager.cpp | 2 +- engines/zvision/script_manager.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 36787e7ba1..227183ab02 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -64,7 +64,7 @@ struct Puzzle { uint32 key; Common::List > criteriaList; // This has to be list of pointers because ResultAction is abstract - Common::List > resultActions; + Common::List resultActions; uint flags; // Used by the ScriptManager to allow unique-ification of _referenceTable diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index dd2754c12f..eb15d04070 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -140,7 +140,7 @@ bool ScriptManager::parseCriteria(Common::SeekableReadStream &stream, Common::Li return true; } -void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::List > &actionList) const { +void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -156,13 +156,13 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis // Parse for the action type if (line.matchString("*:add*", true)) { - actionList.push_back(Common::SharedPtr(new ActionAdd(line))); + actionList.push_back(new ActionAdd(line)); } else if (line.matchString("*:animplay*", true)) { - actionList.push_back(Common::SharedPtr(new ActionPlayAnimation(line))); + actionList.push_back(new ActionPlayAnimation(line)); } else if (line.matchString("*:animpreload*", true)) { - actionList.push_back(Common::SharedPtr(new ActionPreloadAnimation(line))); + actionList.push_back(new ActionPreloadAnimation(line)); } else if (line.matchString("*:animunload*", true)) { - //actionList.push_back(Common::SharedPtr(new ActionUnloadAnimation(line))); + //actionList.push_back(new ActionUnloadAnimation(line)); } else if (line.matchString("*:attenuate*", true)) { @@ -170,7 +170,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:change_location*", true)) { - actionList.push_back(Common::SharedPtr(new ActionChangeLocation(line))); + actionList.push_back(new ActionChangeLocation(line)); } else if (line.matchString("*:crossfade*", true)) { @@ -181,7 +181,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:disable_control*", true)) { - actionList.push_back(Common::SharedPtr(new ActionDisableControl(line))); + actionList.push_back(new ActionDisableControl(line)); } else if (line.matchString("*:disable_venus*", true)) { @@ -195,7 +195,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:enable_control*", true)) { - actionList.push_back(Common::SharedPtr(new ActionEnableControl(line))); + actionList.push_back(new ActionEnableControl(line)); } else if (line.matchString("*:flush_mouse_events*", true)) { @@ -209,7 +209,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:music*", true)) { - actionList.push_back(Common::SharedPtr(new ActionMusic(line))); + actionList.push_back(new ActionMusic(line)); } else if (line.matchString("*:pan_track*", true)) { @@ -220,7 +220,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:quit*", true)) { - actionList.push_back(Common::SharedPtr(new ActionQuit())); + actionList.push_back(new ActionQuit()); } else if (line.matchString("*:random*", true)) { @@ -240,7 +240,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:set_screen*", true)) { - actionList.push_back(Common::SharedPtr(new ActionSetScreen(line))); + actionList.push_back(new ActionSetScreen(line)); } else if (line.matchString("*:set_venus*", true)) { @@ -248,7 +248,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:streamvideo*", true)) { - actionList.push_back(Common::SharedPtr(new ActionStreamVideo(line))); + actionList.push_back(new ActionStreamVideo(line)); } else if (line.matchString("*:syncsound*", true)) { diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index c80b5a2bc4..6a1794dabf 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -167,7 +167,7 @@ void ScriptManager::checkPuzzleCriteria() { debug("Puzzle %u criteria passed. Executing its ResultActions", puzzle->key); bool shouldContinue = true; - for (Common::List >::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { + for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { shouldContinue = shouldContinue && (*resultIter)->execute(_engine); } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 362c4efed9..884699a6b0 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -132,7 +132,7 @@ private: * @param actionList The list where the results will be added * @return Created Results object */ - void parseResults(Common::SeekableReadStream &stream, Common::List > &actionList) const; + void parseResults(Common::SeekableReadStream &stream, Common::List &actionList) const; /** * Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum -- cgit v1.2.3 From 695257cb79f8666a74d4bc67996234eab391c67c Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:43:33 -0500 Subject: ZVISION: Create class to parse RLF animation files --- engines/zvision/rlf_animation.cpp | 230 ++++++++++++++++++++++++++++++++++++++ engines/zvision/rlf_animation.h | 60 ++++++++++ 2 files changed, 290 insertions(+) create mode 100644 engines/zvision/rlf_animation.cpp create mode 100644 engines/zvision/rlf_animation.h (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp new file mode 100644 index 0000000000..abc31c1d1d --- /dev/null +++ b/engines/zvision/rlf_animation.cpp @@ -0,0 +1,230 @@ +/* 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/scummsys.h" + +#include "common/str.h" +#include "common/file.h" +#include "common/textconsole.h" +#include "common/debug.h" +#include "common/endian.h" + +#include "zvision/rlf_animation.h" + + +namespace ZVision { + +RlfAnimation::RlfAnimation(const Common::String &fileName) + : _frames(0) { + Common::File file; + if (!file.open(fileName)) { + warning("RLF animation file %s could not be opened", fileName.c_str()); + return; + } + + if (file.readUint32BE() != MKTAG('F', 'E', 'L', 'R')) { + warning("%s is not a RLF animation file. Wrong magic number", fileName.c_str()); + return; + } + + // Read the header + file.readUint32LE(); // Size1 + file.readUint32LE(); // Unknown1 + file.readUint32LE(); // Unknown2 + _frameCount = file.readUint32LE(); // Frame count + + // Since we don't need any of the data, we can just seek right to the + // entries we need rather than read in all the individual entries. + file.seek(136, file.pos()); + + //// Read CIN header + //file.readUint32BE(); // Magic number FNIC + //file.readUint32LE(); // Size2 + //file.readUint32LE(); // Unknown3 + //file.readUint32LE(); // Unknown4 + //file.readUint32LE(); // Unknown5 + //file.seek(0x18, file.pos()); // VRLE + //file.readUint32LE(); // LRVD + //file.readUint32LE(); // Unknown6 + //file.seek(0x18, file.pos()); // HRLE + //file.readUint32LE(); // ELHD + //file.readUint32LE(); // Unknown7 + //file.seek(0x18, file.pos()); // HKEY + //file.readUint32LE(); // ELRH + + //// Read MIN info header + //file.readUint32BE(); // Magic number FNIM + //file.readUint32LE(); // Size3 + //file.readUint32LE(); // OEDV + //file.readUint32LE(); // Unknown8 + //file.readUint32LE(); // Unknown9 + //file.readUint32LE(); // Unknown10 + _width = file.readUint32LE(); // Width + _height = file.readUint32LE(); // Height + + // Read time header + file.readUint32BE(); // Magic number EMIT + file.readUint32LE(); // Size4 + file.readUint32LE(); // Unknown11 + _frameTime = file.readUint32LE() / 10; // Frame time in microseconds + + // Read in each frame + _frames = new uint16 *[_frameCount]; + for (uint i = 0; i < _frameCount; i++) { + file.readUint32BE(); // Magic number MARF + uint32 size = file.readUint32LE(); // Size + file.readUint32LE(); // Unknown1 + file.readUint32LE(); // Unknown2 + uint32 type = file.readUint32BE(); // Either ELHD or ELRH + uint32 offset = file.readUint32LE(); // Offset from the beginning of this frame to the frame data. Should always be 28 + file.readUint32LE(); // Unknown3 + + int8 *buffer = new int8[size - headerSize]; + file.read(buffer, size - headerSize); + + _frames[i] = new uint16[_width * _height]; + uint frameByteSize = _width * _height * sizeof(uint16); + memset(_frames[i], 0x7C00, frameByteSize); + // Decode the data + debug("Decoding frame %u", i); + if (type == MKTAG('E', 'L', 'H', 'D')) { + debug("Decoding with masked RLE"); + decodeMaskedRunLengthEncoding(buffer, (int8 *)_frames[i], size - headerSize, frameByteSize); + } else if (type == MKTAG('E', 'L', 'R', 'H')) { + debug("Decoding with simple RLE"); + decodeSimpleRunLengthEncoding(buffer, (int8 *)_frames[i], size - headerSize, frameByteSize); + } else { + warning("Frame %u of %s doesn't have type that can be decoded", i, fileName.c_str()); + return; + } + + // Cleanup + delete[] buffer; + } +}; + +RlfAnimation::~RlfAnimation() { + if (_frames != 0) { + delete[] _frames; + } +} + + + +void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const { + uint32 sourceOffset = 0; + uint32 destOffset = 0; + + while (sourceOffset < sourceSize) { + int8 numberOfSamples = source[sourceOffset]; + sourceOffset++; + + // If numberOfSamples is negative, the next abs(numberOfSamples) samples should + // be copied directly from source to dest + if (numberOfSamples < 0) { + numberOfSamples = abs(numberOfSamples); + + while (numberOfSamples > 0) { + if (sourceOffset + 1 >= sourceSize) { + return; + } else if (destOffset + 1 >= destSize) { + warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + return; + } + + WRITE_UINT16(dest + destOffset, READ_LE_UINT16(source + sourceOffset)); + + sourceOffset += 2; + destOffset += 2; + numberOfSamples--; + } + + // If numberOfSamples is >= 0, move destOffset forward ((numberOfSamples * 2) + 2) + // This function assumes the dest buffer has been memset with 0's. + } else { + if (sourceOffset + 1 >= sourceSize) { + return; + } else if (destOffset + 1 >= destSize) { + warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + return; + } + + destOffset += (numberOfSamples * 2) + 2; + } + } +} + +void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const { + uint32 sourceOffset = 0; + uint32 destOffset = 0; + + while (sourceOffset < sourceSize) { + int8 numberOfSamples = source[sourceOffset]; + sourceOffset++; + + // If numberOfSamples is negative, the next abs(numberOfSamples) samples should + // be copied directly from source to dest + if (numberOfSamples < 0) { + numberOfSamples = abs(numberOfSamples); + + while (numberOfSamples > 0) { + if (sourceOffset + 1 >= sourceSize) { + return; + } else if (destOffset + 1 >= destSize) { + warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + return; + } + + WRITE_UINT16(dest + destOffset, READ_LE_UINT16(source + sourceOffset)); + + sourceOffset += 2; + destOffset += 2; + numberOfSamples--; + } + + // If numberOfSamples is >= 0, copy one sample from source to the + // next (numberOfSamples + 2) dest spots + } else { + if (sourceOffset + 1 >= sourceSize) { + return; + } + + uint16 sampleColor = READ_LE_UINT16(source + sourceOffset); + sourceOffset += 2; + + numberOfSamples += 2; + while (numberOfSamples > 0) { + if (destOffset + 1 >= destSize) { + warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + return; + } + + WRITE_UINT16(dest + destOffset, sampleColor); + destOffset += 2; + numberOfSamples--; + } + } + } +} + + +} // End of namespace ZVision diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h new file mode 100644 index 0000000000..7ece4e5063 --- /dev/null +++ b/engines/zvision/rlf_animation.h @@ -0,0 +1,60 @@ +/* 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 ZVISION_RLF_ANIMATION_H +#define ZVISION_RLF_ANIMATION_H + + +namespace Common { +class String; +} + +namespace ZVision { + +class RlfAnimation { +public: + RlfAnimation(const Common::String &fileName); + ~RlfAnimation(); + +private: +private: + uint _frameCount; + uint _width; + uint _height; + uint32 _frameTime; // In milliseconds + uint16 **_frames; + +public: + uint frameCount() { return _frameCount; } + uint width() { return _width; } + uint height() { return _height; } + uint32 frameTime() { return _frameTime; } + const uint16 *getFrameData(uint frameNumber) const { return _frames[frameNumber]; } + +private: + void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; + void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 760dd3e63202ff92d206fb83015f8b05e4aa969c Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:47:33 -0500 Subject: ZVISION: Rename _warpedBuffer to _workingWindowBuffer To better represent its function --- engines/zvision/render_manager.cpp | 8 ++++---- engines/zvision/render_manager.h | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 932c797c11..4e67cbbd7b 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -50,7 +50,7 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, _accumulatedVelocityMilliseconds(0), _renderTable(_workingWidth, _workingHeight) { - _warpedBuffer = new uint16[_workingWidth *_workingHeight]; + _workingWindowBuffer = new uint16[_workingWidth *_workingHeight]; } RenderManager::~RenderManager() { @@ -58,7 +58,7 @@ RenderManager::~RenderManager() { delete _currentBackground; } - delete[] _warpedBuffer; + delete[] _workingWindowBuffer; } void RenderManager::update(uint deltaTimeInMillis) { @@ -133,9 +133,9 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (_renderTable.getRenderState() == RenderTable::FLAT) { _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); } else { - _renderTable.mutateImage((uint16 *)surface.getBasePtr(0, 0), _warpedBuffer, surface.w, surface.h, destinationX, destinationY, subRect, wrap, isTransposed); + _renderTable.mutateImage((uint16 *)surface.getBasePtr(0, 0), _workingWindowBuffer, surface.w, surface.h, destinationX, destinationY, subRect, wrap, isTransposed); - _system->copyRectToScreen(_warpedBuffer, _workingWidth * sizeof(uint16), destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); + _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); } } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 9683ee0bf2..5b517031ae 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -52,7 +52,9 @@ private: OSystem *_system; const Graphics::PixelFormat _pixelFormat; - uint16 *_warpedBuffer; + // A buffer the exact same size as the workingWindow + // It's used for panorama/tilt warping and for clearing the workingWindow to a single color + uint16 *_workingWindowBuffer; /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ const int _workingWidth; @@ -88,6 +90,7 @@ private: /** Holds any 'leftover' milliseconds between frames */ uint _accumulatedVelocityMilliseconds; + // TODO: Potentially merge this buffer and _workingWindowBuffer byte *_scaledVideoFrameBuffer; public: -- cgit v1.2.3 From 7c02b66b2e556816c70b75e69e53ba1fb3d1b895 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:49:38 -0500 Subject: ZVISION: Create method to clear the working window area of the screen to a single color --- engines/zvision/render_manager.cpp | 10 ++++++++++ engines/zvision/render_manager.h | 7 +++++++ 2 files changed, 17 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 4e67cbbd7b..6c006d9320 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -79,6 +79,16 @@ void RenderManager::update(uint deltaTimeInMillis) { } } +void RenderManager::clearWorkingWindowToColor(uint16 color) { + uint32 workingWindowSize = _workingWidth * _workingHeight; + + for (uint32 i = 0; i < workingWindowSize; i++) { + _workingWindowBuffer[i] = color; + } + + _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), _workingWindow.left, _workingWindow.top, _workingWidth, _workingHeight); +} + void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap, bool isTransposed) { int16 subRectX = 0; int16 subRectY = 0; diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 5b517031ae..d82e40fa4c 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -102,6 +102,13 @@ public: */ void update(uint deltaTimeInMillis); + /** + * Fills the entire workingWindow with the specified color + * + * @param color The color to fill the working window with. (In RGB 555) + */ + void clearWorkingWindowToColor(uint16 color); + /** * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. * The image will be clipped to fit inside the working window. Coords are in working window space, not screen space! -- cgit v1.2.3 From 683e24cd75e629061a7f5d0733b29daf10bba2ec Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:43:02 -0500 Subject: ZVISION: Implement ActionSetPartialScreen --- engines/zvision/actions.cpp | 33 +++++++++++++++++++++++++++++++-- engines/zvision/actions.h | 12 ++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index affa8f5a9c..16499138c7 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -266,6 +266,36 @@ bool ActionRandom::execute(ZVision *engine) { } +////////////////////////////////////////////////////////////////////////////// +// ActionSetPartialScreen +////////////////////////////////////////////////////////////////////////////// + +ActionSetPartialScreen::ActionSetPartialScreen(const Common::String &line) { + char fileName[25]; + uint color; + + sscanf(line.c_str(), "%*[^(](%u %u %25s %*u %u)", &_x, &_y, fileName, &color); + + _fileName = Common::String(fileName); + + if (color > 0xFFFF) { + warning("Background color for ActionSetPartialScreen is bigger than a uint16"); + } + _backgroundColor = color; +} + +bool ActionSetPartialScreen::execute(ZVision *engine) { + RenderManager *renderManager = engine->getRenderManager(); + + if (_backgroundColor > 0) { + renderManager->clearWorkingWindowToColor(_backgroundColor); + } + renderManager->renderImageToScreen(_fileName, _x, _y); + + return true; +} + + ////////////////////////////////////////////////////////////////////////////// // ActionSetScreen ////////////////////////////////////////////////////////////////////////////// @@ -278,8 +308,7 @@ ActionSetScreen::ActionSetScreen(const Common::String &line) { } bool ActionSetScreen::execute(ZVision *engine) { - RenderManager *renderManager = engine->getRenderManager(); - renderManager->setBackgroundImage(_fileName); + engine->getRenderManager()->setBackgroundImage(_fileName); return true; } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 1d87b8025c..5e7c2c63e3 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -277,6 +277,18 @@ private: uint _max; }; +class ActionSetPartialScreen : public ResultAction { +public: + ActionSetPartialScreen(const Common::String &line); + bool execute(ZVision *engine); + +private: + uint _x; + uint _y; + Common::String _fileName; + uint16 _backgroundColor; +}; + class ActionSetScreen : public ResultAction { public: ActionSetScreen(const Common::String &line); -- cgit v1.2.3 From 6e427ebef8b29e48b679c7c19ed4b715c7dfaef8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:51:50 -0500 Subject: ZVISION: Create method to play RlfAnimations --- engines/zvision/animation.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++ engines/zvision/zvision.h | 3 ++ 2 files changed, 93 insertions(+) create mode 100644 engines/zvision/animation.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/animation.cpp b/engines/zvision/animation.cpp new file mode 100644 index 0000000000..7c41c23a06 --- /dev/null +++ b/engines/zvision/animation.cpp @@ -0,0 +1,90 @@ +/* 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/scummsys.h" + +#include "common/system.h" + +#include "zvision/zvision.h" +#include "zvision/rlf_animation.h" + + +namespace ZVision { + +void ZVision::playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse) { + uint currentFrame = 0; + uint lastFrame = animation->frameCount(); + bool skip = false; + uint32 frameTime = animation->frameTime(); + uint width = animation->width(); + uint height = animation->height(); + + uint16 newX = x + _workingWindow.left; + uint16 newY = y + _workingWindow.top; + + uint32 accumulatedTime = 0; + + // Only continue while the video is still playing + while (!shouldQuit() && !skip && currentFrame < lastFrame) { + _clock.update(); + uint32 currentTime = _clock.getLastMeasuredTime(); + accumulatedTime += _clock.getDeltaTime(); + + // Check for engine quit and video stop key presses + while (_eventMan->pollEvent(_event)) { + switch (_event.type) { + case Common::EVENT_KEYDOWN: + switch (_event.kbd.keycode) { + case Common::KEYCODE_q: + if (_event.kbd.hasFlags(Common::KBD_CTRL)) + quitGame(); + break; + case Common::KEYCODE_SPACE: + skip = true; + break; + default: + break; + } + default: + break; + } + } + + if (accumulatedTime >= frameTime) { + accumulatedTime -= frameTime; + + _system->copyRectToScreen(animation->getFrameData(currentFrame), width * sizeof(uint16), newX, newY, width, height); + currentFrame++; + } + + // Always update the screen so the mouse continues to render + _system->updateScreen(); + + // Calculate the frame delay based off a desired frame time + int delay = _desiredFrameTime - int32(_system->getMillis() - currentTime); + // Ensure non-negative + delay = delay < 0 ? 0 : delay; + _system->delayMillis(delay); + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 9e9d5db951..366e96f6a7 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -49,6 +49,7 @@ class Console; class ScriptManager; class RenderManager; class CursorManager; +class RlfAnimation; // our engine debug channels enum { @@ -126,6 +127,8 @@ public: */ void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true); + void playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + /** * Register a MouseEvent with the event system. These will be checked at every * MOUSE_UP, MOUSE_DOWN, MOUSE_MOVE, etc. -- cgit v1.2.3 From 9294c5eac969967a294abd97982e5baed6507355 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:52:14 -0500 Subject: ZVISION: Initialize inline with construction --- engines/zvision/render_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 6c006d9320..ac02cc24d6 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -163,8 +163,7 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, int16 de void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, int16 destinationX, int16 destinationY, bool wrap) { // Read the magic number // Some files are true TGA, while others are TGZ - uint32 fileType; - fileType = stream.readUint32BE(); + uint32 fileType = stream.readUint32BE(); // Check for TGZ files if (fileType == MKTAG('T', 'G', 'Z', '\0')) { -- cgit v1.2.3 From 6c7303995f6fb4eb488ef8a7bba6fc60bc765d04 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:54:17 -0500 Subject: ZVISION: Always update the screen to ensure the mouse continues to render --- engines/zvision/video.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 4066c5dcd5..377b24af2a 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -153,11 +153,12 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d } else { _system->copyRectToScreen((const byte *)frame->getBasePtr(0, 0), pitch, x, y, finalWidth, finalHeight); } - - _system->updateScreen(); } } + // Always update the screen so the mouse continues to render + _system->updateScreen(); + _system->delayMillis(videoDecoder.getTimeToNextFrame()); } -- cgit v1.2.3 From 7dcfa9ef4c849251e32b60f5d3cd609fb0fd2921 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 19 Aug 2013 23:55:36 -0500 Subject: ZVISION: Call RenderManager::update() before ScriptManager::update() This ensures the background will be rendered before anything from Puzzles or Controls --- engines/zvision/zvision.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 080c763342..c32e78214f 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -135,8 +135,10 @@ Common::Error ZVision::run() { processEvents(); - _scriptManager->update(deltaTime); + // Call _renderManager->update() first so the background renders + // before anything that puzzles/controls will render _renderManager->update(deltaTime); + _scriptManager->update(deltaTime); // Update the screen _system->updateScreen(); -- cgit v1.2.3 From 94a55024ac9384747130aa1cd94d4cb36f35e922 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 11:25:58 -0500 Subject: ZVISION: Fix seek() whence argument --- engines/zvision/rlf_animation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index abc31c1d1d..8a087c1ccc 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -54,7 +54,7 @@ RlfAnimation::RlfAnimation(const Common::String &fileName) // Since we don't need any of the data, we can just seek right to the // entries we need rather than read in all the individual entries. - file.seek(136, file.pos()); + file.seek(136, SEEK_CUR); //// Read CIN header //file.readUint32BE(); // Magic number FNIC @@ -62,13 +62,13 @@ RlfAnimation::RlfAnimation(const Common::String &fileName) //file.readUint32LE(); // Unknown3 //file.readUint32LE(); // Unknown4 //file.readUint32LE(); // Unknown5 - //file.seek(0x18, file.pos()); // VRLE + //file.seek(0x18, SEEK_CUR); // VRLE //file.readUint32LE(); // LRVD //file.readUint32LE(); // Unknown6 - //file.seek(0x18, file.pos()); // HRLE + //file.seek(0x18, SEEK_CUR); // HRLE //file.readUint32LE(); // ELHD //file.readUint32LE(); // Unknown7 - //file.seek(0x18, file.pos()); // HKEY + //file.seek(0x18, SEEK_CUR); // HKEY //file.readUint32LE(); // ELRH //// Read MIN info header -- cgit v1.2.3 From 4bd7951840b7e995b4857ee6ee1c6288668cd66f Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 11:30:52 -0500 Subject: ZVISION: Normalize comment alignment --- engines/zvision/rlf_animation.cpp | 72 +++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 8a087c1ccc..c072aaf053 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -47,56 +47,56 @@ RlfAnimation::RlfAnimation(const Common::String &fileName) } // Read the header - file.readUint32LE(); // Size1 - file.readUint32LE(); // Unknown1 - file.readUint32LE(); // Unknown2 - _frameCount = file.readUint32LE(); // Frame count + file.readUint32LE(); // Size1 + file.readUint32LE(); // Unknown1 + file.readUint32LE(); // Unknown2 + _frameCount = file.readUint32LE(); // Frame count // Since we don't need any of the data, we can just seek right to the // entries we need rather than read in all the individual entries. file.seek(136, SEEK_CUR); //// Read CIN header - //file.readUint32BE(); // Magic number FNIC - //file.readUint32LE(); // Size2 - //file.readUint32LE(); // Unknown3 - //file.readUint32LE(); // Unknown4 - //file.readUint32LE(); // Unknown5 - //file.seek(0x18, SEEK_CUR); // VRLE - //file.readUint32LE(); // LRVD - //file.readUint32LE(); // Unknown6 - //file.seek(0x18, SEEK_CUR); // HRLE - //file.readUint32LE(); // ELHD - //file.readUint32LE(); // Unknown7 - //file.seek(0x18, SEEK_CUR); // HKEY - //file.readUint32LE(); // ELRH + //file.readUint32BE(); // Magic number FNIC + //file.readUint32LE(); // Size2 + //file.readUint32LE(); // Unknown3 + //file.readUint32LE(); // Unknown4 + //file.readUint32LE(); // Unknown5 + //file.seek(0x18, SEEK_CUR); // VRLE + //file.readUint32LE(); // LRVD + //file.readUint32LE(); // Unknown6 + //file.seek(0x18, SEEK_CUR); // HRLE + //file.readUint32LE(); // ELHD + //file.readUint32LE(); // Unknown7 + //file.seek(0x18, SEEK_CUR); // HKEY + //file.readUint32LE(); // ELRH //// Read MIN info header - //file.readUint32BE(); // Magic number FNIM - //file.readUint32LE(); // Size3 - //file.readUint32LE(); // OEDV - //file.readUint32LE(); // Unknown8 - //file.readUint32LE(); // Unknown9 - //file.readUint32LE(); // Unknown10 - _width = file.readUint32LE(); // Width - _height = file.readUint32LE(); // Height + //file.readUint32BE(); // Magic number FNIM + //file.readUint32LE(); // Size3 + //file.readUint32LE(); // OEDV + //file.readUint32LE(); // Unknown8 + //file.readUint32LE(); // Unknown9 + //file.readUint32LE(); // Unknown10 + _width = file.readUint32LE(); // Width + _height = file.readUint32LE(); // Height // Read time header - file.readUint32BE(); // Magic number EMIT - file.readUint32LE(); // Size4 - file.readUint32LE(); // Unknown11 - _frameTime = file.readUint32LE() / 10; // Frame time in microseconds + file.readUint32BE(); // Magic number EMIT + file.readUint32LE(); // Size4 + file.readUint32LE(); // Unknown11 + _frameTime = file.readUint32LE() / 10; // Frame time in microseconds // Read in each frame _frames = new uint16 *[_frameCount]; for (uint i = 0; i < _frameCount; i++) { - file.readUint32BE(); // Magic number MARF - uint32 size = file.readUint32LE(); // Size - file.readUint32LE(); // Unknown1 - file.readUint32LE(); // Unknown2 - uint32 type = file.readUint32BE(); // Either ELHD or ELRH - uint32 offset = file.readUint32LE(); // Offset from the beginning of this frame to the frame data. Should always be 28 - file.readUint32LE(); // Unknown3 + file.readUint32BE(); // Magic number MARF + uint32 size = file.readUint32LE(); // Size + file.readUint32LE(); // Unknown1 + file.readUint32LE(); // Unknown2 + uint32 type = file.readUint32BE(); // Either ELHD or ELRH + uint32 headerSize = file.readUint32LE(); // Offset from the beginning of this frame to the frame data. Should always be 28 + file.readUint32LE(); // Unknown3 int8 *buffer = new int8[size - headerSize]; file.read(buffer, size - headerSize); -- cgit v1.2.3 From 6f080b3631c8dc111bc6775877b58a9e5d783565 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 11:34:37 -0500 Subject: ZVISION: Create keypress event to test rlf animation --- engines/zvision/events.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index f382bb63e0..798d75b375 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -33,6 +33,7 @@ #include "zvision/render_manager.h" #include "zvision/script_manager.h" #include "zvision/mouse_event.h" +#include "zvision/rlf_animation.h" namespace ZVision { @@ -95,6 +96,12 @@ void ZVision::processEvents() { case Common::KEYCODE_F1: cycleThroughCursors(); break; + case Common::KEYCODE_F2: + { + RlfAnimation *animation = new RlfAnimation("te2ea21c.rlf"); + playAnimation(animation, 0, 0); + break; + } default: break; } -- cgit v1.2.3 From 610b563790ded5c43f757675a9acdc49ce555a1d Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 11:55:08 -0500 Subject: ZVISION: Convert abs() to ABS() to ensure portability --- engines/zvision/rlf_animation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index c072aaf053..26ce2e217c 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -141,7 +141,7 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 // If numberOfSamples is negative, the next abs(numberOfSamples) samples should // be copied directly from source to dest if (numberOfSamples < 0) { - numberOfSamples = abs(numberOfSamples); + numberOfSamples = ABS(numberOfSamples); while (numberOfSamples > 0) { if (sourceOffset + 1 >= sourceSize) { @@ -184,7 +184,7 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 // If numberOfSamples is negative, the next abs(numberOfSamples) samples should // be copied directly from source to dest if (numberOfSamples < 0) { - numberOfSamples = abs(numberOfSamples); + numberOfSamples = ABS(numberOfSamples); while (numberOfSamples > 0) { if (sourceOffset + 1 >= sourceSize) { -- cgit v1.2.3 From 9af92b8723bdba3b9e540d9e0ba3a9142bc2e480 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 15:55:42 -0500 Subject: ZVISION: Handle rlf frame transitions internally Animations use incremental frame changes. That is, only a few frames are complete (I-frames), the rest are just the pixels that change between the current frame and both the previous frame and the next frame (B-frames). See https://en.wikipedia.org/wiki/Video_compression_picture_types --- engines/zvision/animation.cpp | 9 ++-- engines/zvision/rlf_animation.cpp | 86 +++++++++++++++++++++++++++++++-------- engines/zvision/rlf_animation.h | 24 ++++++++++- 3 files changed, 93 insertions(+), 26 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/animation.cpp b/engines/zvision/animation.cpp index 7c41c23a06..8ca892dfda 100644 --- a/engines/zvision/animation.cpp +++ b/engines/zvision/animation.cpp @@ -31,8 +31,6 @@ namespace ZVision { void ZVision::playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse) { - uint currentFrame = 0; - uint lastFrame = animation->frameCount(); bool skip = false; uint32 frameTime = animation->frameTime(); uint width = animation->width(); @@ -44,7 +42,7 @@ void ZVision::playAnimation(RlfAnimation *animation, uint16 x, uint16 y, Dispose uint32 accumulatedTime = 0; // Only continue while the video is still playing - while (!shouldQuit() && !skip && currentFrame < lastFrame) { + while (!shouldQuit() && !skip && !animation->endOfAnimation()) { _clock.update(); uint32 currentTime = _clock.getLastMeasuredTime(); accumulatedTime += _clock.getDeltaTime(); @@ -69,11 +67,10 @@ void ZVision::playAnimation(RlfAnimation *animation, uint16 x, uint16 y, Dispose } } - if (accumulatedTime >= frameTime) { + while (accumulatedTime >= frameTime && !animation->endOfAnimation()) { accumulatedTime -= frameTime; - _system->copyRectToScreen(animation->getFrameData(currentFrame), width * sizeof(uint16), newX, newY, width, height); - currentFrame++; + _system->copyRectToScreen(animation->getNextFrame(), width * sizeof(uint16), newX, newY, width, height); } // Always update the screen so the mouse continues to render diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 26ce2e217c..90086e9bd0 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -34,7 +34,14 @@ namespace ZVision { RlfAnimation::RlfAnimation(const Common::String &fileName) - : _frames(0) { + : _frameCount(0), + _width(0), + _height(0), + _frameTime(0), + _frames(0), + _currentFrameBuffer(0), + _currentFrame(-1), + _frameBufferByteSize(0) { Common::File file; if (!file.open(fileName)) { warning("RLF animation file %s could not be opened", fileName.c_str()); @@ -87,8 +94,11 @@ RlfAnimation::RlfAnimation(const Common::String &fileName) file.readUint32LE(); // Unknown11 _frameTime = file.readUint32LE() / 10; // Frame time in microseconds + _frames = new Frame[_frameCount]; + _currentFrameBuffer = new uint16[_width * _height]; + _frameBufferByteSize = _width * _height * sizeof(uint16); + // Read in each frame - _frames = new uint16 *[_frameCount]; for (uint i = 0; i < _frameCount; i++) { file.readUint32BE(); // Magic number MARF uint32 size = file.readUint32LE(); // Size @@ -98,27 +108,19 @@ RlfAnimation::RlfAnimation(const Common::String &fileName) uint32 headerSize = file.readUint32LE(); // Offset from the beginning of this frame to the frame data. Should always be 28 file.readUint32LE(); // Unknown3 - int8 *buffer = new int8[size - headerSize]; - file.read(buffer, size - headerSize); - - _frames[i] = new uint16[_width * _height]; - uint frameByteSize = _width * _height * sizeof(uint16); - memset(_frames[i], 0x7C00, frameByteSize); - // Decode the data - debug("Decoding frame %u", i); + _frames[i].encodedSize = size - headerSize; + _frames[i].encodedData = new int8[_frames[i].encodedSize]; + file.read(_frames[i].encodedData, _frames[i].encodedSize); + if (type == MKTAG('E', 'L', 'H', 'D')) { - debug("Decoding with masked RLE"); - decodeMaskedRunLengthEncoding(buffer, (int8 *)_frames[i], size - headerSize, frameByteSize); + _frames[i].type = Masked; } else if (type == MKTAG('E', 'L', 'R', 'H')) { - debug("Decoding with simple RLE"); - decodeSimpleRunLengthEncoding(buffer, (int8 *)_frames[i], size - headerSize, frameByteSize); + _frames[i].type = Simple; + _completeFrames.push_back(i); } else { warning("Frame %u of %s doesn't have type that can be decoded", i, fileName.c_str()); return; } - - // Cleanup - delete[] buffer; } }; @@ -126,9 +128,58 @@ RlfAnimation::~RlfAnimation() { if (_frames != 0) { delete[] _frames; } + if (_currentFrameBuffer != 0) { + delete[] _currentFrameBuffer; + } +} + +const uint16 *RlfAnimation::getFrameData(uint frameNumber) { + assert(frameNumber < _frameCount && frameNumber >= 0); + + if (frameNumber == _currentFrame) { + return _currentFrameBuffer; + } + + uint closestFrame = _currentFrame; + uint distance = ABS(_currentFrame - frameNumber); + for (Common::List::const_iterator iter = _completeFrames.begin(); iter != _completeFrames.end(); iter++) { + uint newDistance = ABS((*iter) - frameNumber); + if (closestFrame == -1 || newDistance < distance) { + closestFrame = (*iter); + distance = newDistance; + } + } + + bool forwards = frameNumber > closestFrame; + if (forwards) { + for (uint i = closestFrame; i <= frameNumber; i++) { + applyFrameToCurrent(i); + } + } else { + for (uint i = closestFrame; i >= frameNumber; i--) { + applyFrameToCurrent(i); + } + } + + return _currentFrameBuffer; } +const uint16 *RlfAnimation::getNextFrame() { + assert(_currentFrame + 1 < _frameCount); + applyFrameToCurrent(_currentFrame + 1); + return _currentFrameBuffer; +} + +void RlfAnimation::applyFrameToCurrent(uint frameNumber) { + if (_frames[frameNumber].type == Masked) { + decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer, _frames[frameNumber].encodedSize, _frameBufferByteSize); + } else if (_frames[frameNumber].type == Simple) { + decodeSimpleRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer, _frames[frameNumber].encodedSize, _frameBufferByteSize); + } + + _currentFrame = frameNumber; +} void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const { uint32 sourceOffset = 0; @@ -226,5 +277,4 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 } } - } // End of namespace ZVision diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index 7ece4e5063..e204a50090 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -36,21 +36,41 @@ public: ~RlfAnimation(); private: + enum EncodingType { + Masked, + Simple + }; + + struct Frame { + EncodingType type; + int8 *encodedData; + uint32 encodedSize; + }; + private: uint _frameCount; uint _width; uint _height; uint32 _frameTime; // In milliseconds - uint16 **_frames; + Frame *_frames; + Common::List _completeFrames; + + int _currentFrame; + uint16 *_currentFrameBuffer; + uint32 _frameBufferByteSize; public: uint frameCount() { return _frameCount; } uint width() { return _width; } uint height() { return _height; } uint32 frameTime() { return _frameTime; } - const uint16 *getFrameData(uint frameNumber) const { return _frames[frameNumber]; } + const uint16 *getFrameData(uint frameNumber); + const uint16 *getNextFrame(); + bool endOfAnimation() { return _currentFrame == _frameCount - 1; } private: + void applyFrameToCurrent(uint frameNumber); + void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; }; -- cgit v1.2.3 From cf8a8df776a28d5c4474848448b231d55b0c0c71 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 20:28:00 -0500 Subject: ZVISION: Remove superfluous file --- engines/zvision/tests.h | 54 ------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 engines/zvision/tests.h (limited to 'engines/zvision') diff --git a/engines/zvision/tests.h b/engines/zvision/tests.h deleted file mode 100644 index 14f80ed83b..0000000000 --- a/engines/zvision/tests.h +++ /dev/null @@ -1,54 +0,0 @@ - -namespace ZVision { - -void tests() { -#if 0 - // Video test - Video::VideoDecoder *videoDecoder = new ZorkAVIDecoder(); - if (videoDecoder && videoDecoder->loadFile("zassets/temple/t000a11c.avi")) { - Common::List formats; - formats.push_back(videoDecoder->getPixelFormat()); - //initGraphics(640, 480, true, formats); - - playVideo(videoDecoder); - } -#endif - - Common::File f; - -#if 1 - // Image test - - //initGraphics(640, 480, true, &format); - - if (f.open(" zassets/global/GJDEB11C.TGA")) { - Graphics::TGADecoder tga; - if (!tga.loadStream(f)) - error("Error while reading TGA image"); - f.close(); - - const Graphics::Surface *tgaSurface = tga.getSurface(); - - Graphics::Surface *screen = g_system->lockScreen(); - for (uint16 y = 0; y < tgaSurface->h; y++) - memcpy(screen->getBasePtr(0, y), tgaSurface->getBasePtr(0, y), tgaSurface->pitch); - g_system->unlockScreen(); - - tga.destroy(); - } - - -#endif - -#if 0 - // Sound test - if (f.open("zassets/castle/c000h9tc.raw")) { - Audio::SeekableAudioStream *audioStream = makeRawZorkStream(&f, 22050, DisposeAfterUse::YES); - Audio::SoundHandle handle; - g_system->getMixer()->playStream(Audio::Mixer::kSFXSoundType, &handle, audioStream); - } - -#endif -} - -} // End of namespace ZVision -- cgit v1.2.3 From 1251da96e22e56c13c81e4fa6f08efe99cbcbbb3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 20:28:36 -0500 Subject: ZVISION: Add animation.o and rlf_animation.o to module.mk --- engines/zvision/module.mk | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index f072520d16..317e4b11d4 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -3,6 +3,7 @@ MODULE := engines/zvision MODULE_OBJS := \ action_node.o \ actions.o \ + animation.o \ clock.o \ console.o \ control.o \ @@ -14,6 +15,7 @@ MODULE_OBJS := \ mouse_event.o \ render_manager.o \ render_table.o \ + rlf_animation.o \ scr_file_handling.o \ script_manager.o \ scripts.o \ -- cgit v1.2.3 From aba3ba634cbadd6f245580171322fa5debc6ffd3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 20:29:28 -0500 Subject: ZVISION: Add TODO's of what is left for the engine to be complete --- engines/zvision/control.h | 10 +++++ engines/zvision/inventory_manager.h | 28 ++++++++++++ engines/zvision/menu.h | 28 ++++++++++++ engines/zvision/save_manager.h | 28 ++++++++++++ engines/zvision/scr_file_handling.cpp | 84 ++++++++++++----------------------- engines/zvision/subtitles.h | 29 ++++++++++++ 6 files changed, 151 insertions(+), 56 deletions(-) create mode 100644 engines/zvision/inventory_manager.h create mode 100644 engines/zvision/menu.h create mode 100644 engines/zvision/save_manager.h create mode 100644 engines/zvision/subtitles.h (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index f17ee7750d..e3cb0d4afa 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -66,6 +66,16 @@ private: MouseEvent _event; }; +// TODO: Implement InputControl +// TODO: Implement SaveControl +// TODO: Implement SlotControl +// TODO: Implement LeverControl +// TODO: Implement SafeControl +// TODO: Implement FistControl +// TODO: Implement HotMovieControl +// TODO: Implement PaintControl +// TODO: Implement TilterControl + } // End of namespace ZVision #endif diff --git a/engines/zvision/inventory_manager.h b/engines/zvision/inventory_manager.h new file mode 100644 index 0000000000..ae6d116b18 --- /dev/null +++ b/engines/zvision/inventory_manager.h @@ -0,0 +1,28 @@ +/* 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 ZVISION_INVENTORY_MANAGER_H +#define ZVISION_INVENTORY_MANAGER_H + +// TODO: Implement InventoryManager + +#endif diff --git a/engines/zvision/menu.h b/engines/zvision/menu.h new file mode 100644 index 0000000000..affc69abd5 --- /dev/null +++ b/engines/zvision/menu.h @@ -0,0 +1,28 @@ +/* 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 ZVISION_MENU_H +#define ZVISION_MENU_H + +// TODO: Implement MenuHandler + +#endif diff --git a/engines/zvision/save_manager.h b/engines/zvision/save_manager.h new file mode 100644 index 0000000000..487cf203fb --- /dev/null +++ b/engines/zvision/save_manager.h @@ -0,0 +1,28 @@ +/* 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 ZVISION_SAVE_MANAGER_H +#define ZVISION_SAVE_MANAGER_H + +// TODO: Implement SaveManager + +#endif diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index eb15d04070..f4d4563c63 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -164,103 +164,75 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:animunload*", true)) { //actionList.push_back(new ActionUnloadAnimation(line)); } else if (line.matchString("*:attenuate*", true)) { - - + // TODO: Implement ActionAttenuate } else if (line.matchString("*:assign*", true)) { - - + // TODO: Implement ActionAssign } else if (line.matchString("*:change_location*", true)) { actionList.push_back(new ActionChangeLocation(line)); } else if (line.matchString("*:crossfade*", true)) { - - + // TODO: Implement ActionCrossfade } else if (line.matchString("*:debug*", true)) { - - + // TODO: Implement ActionDebug } else if (line.matchString("*:delay_render*", true)) { - - + // TODO: Implement ActionDelayRender } else if (line.matchString("*:disable_control*", true)) { actionList.push_back(new ActionDisableControl(line)); } else if (line.matchString("*:disable_venus*", true)) { - - + // TODO: Implement ActionDisableVenus } else if (line.matchString("*:display_message*", true)) { - - + // TODO: Implement ActionDisplayMessage } else if (line.matchString("*:dissolve*", true)) { - - + // TODO: Implement ActionDissolve } else if (line.matchString("*:distort*", true)) { - - + // TODO: Implement ActionDistort } else if (line.matchString("*:enable_control*", true)) { actionList.push_back(new ActionEnableControl(line)); } else if (line.matchString("*:flush_mouse_events*", true)) { - - + // TODO: Implement ActionFlushMouseEvents } else if (line.matchString("*:inventory*", true)) { - - + // TODO: Implement ActionInventory } else if (line.matchString("*:kill*", true)) { - - + // TODO: Implement ActionKill } else if (line.matchString("*:menu_bar_enable*", true)) { - - + // TODO: Implement ActionMenuBarEnable } else if (line.matchString("*:music*", true)) { actionList.push_back(new ActionMusic(line)); } else if (line.matchString("*:pan_track*", true)) { - - + // TODO: Implement ActionPanTrack } else if (line.matchString("*:playpreload*", true)) { - - + // TODO: Implement ActionPlayPreload } else if (line.matchString("*:preferences*", true)) { - - + // TODO: Implement ActionPreferences } else if (line.matchString("*:quit*", true)) { actionList.push_back(new ActionQuit()); } else if (line.matchString("*:random*", true)) { - - + // TODO: Implement ActionRandom } else if (line.matchString("*:region*", true)) { - - + // TODO: Implement ActionRegion } else if (line.matchString("*:restore_game*", true)) { - - + // TODO: Implement ActionRestoreGame } else if (line.matchString("*:rotate_to*", true)) { - - + // TODO: Implement ActionRotateTo } else if (line.matchString("*:save_game*", true)) { - - + // TODO: Implement ActionSaveGame } else if (line.matchString("*:set_partial_screen*", true)) { - - + actionList.push_back(new ActionSetPartialScreen(line)); } else if (line.matchString("*:set_screen*", true)) { actionList.push_back(new ActionSetScreen(line)); } else if (line.matchString("*:set_venus*", true)) { - - + // TODO: Implement ActionSetVenus } else if (line.matchString("*:stop*", true)) { - - + // TODO: Implement ActionStop } else if (line.matchString("*:streamvideo*", true)) { actionList.push_back(new ActionStreamVideo(line)); } else if (line.matchString("*:syncsound*", true)) { - - + // TODO: Implement ActionSyncSound } else if (line.matchString("*:timer*", true)) { - - + // TODO: Implement ActionTimer } else if (line.matchString("*:ttytext*", true)) { - - + // TODO: Implement ActionTTYText } else if (line.matchString("*:universe_music*", true)) { - - + // TODO: Implement ActionUniverseMusic } else if (line.matchString("*:copy_file*", true)) { // Not used. Purposely left empty } else { diff --git a/engines/zvision/subtitles.h b/engines/zvision/subtitles.h new file mode 100644 index 0000000000..00eeef2a8a --- /dev/null +++ b/engines/zvision/subtitles.h @@ -0,0 +1,29 @@ +/* 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 ZVISION_SUBTITLES_H +#define ZVISION_SUBTITLES_H + +// Implement Subtitles + +#endif \ No newline at end of file -- cgit v1.2.3 From ad5756fa31113b88fb486c679adfe2197daeca08 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 20:48:34 -0500 Subject: ZVISION: Add a destructor to Puzzle --- engines/zvision/puzzle.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 227183ab02..371af83d91 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -27,11 +27,17 @@ #include "common/list.h" #include "common/ptr.h" -namespace ZVision { +#include "zvision/actions.h" -class ResultAction; +namespace ZVision { struct Puzzle { + ~Puzzle() { + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + delete (*iter); + } + } + /** How criteria should be decided */ enum CriteriaOperator { EQUAL_TO, -- cgit v1.2.3 From 35622827f8e8b507e6c2450773857975f2864a56 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 20:50:14 -0500 Subject: ZVISION: Store the Puzzles in _activePuzzles and _globalPuzzles on the heap This allows List::push_back() to not cause a data copy --- engines/zvision/scr_file_handling.cpp | 12 ++++++------ engines/zvision/script_manager.cpp | 37 ++++++++++++++++++++++------------- engines/zvision/script_manager.h | 7 ++++--- 3 files changed, 33 insertions(+), 23 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index f4d4563c63..7ccd939e54 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -52,8 +52,8 @@ void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) continue; if (line.matchString("puzzle:*", true)) { - Puzzle puzzle; - sscanf(line.c_str(),"puzzle:%u",&(puzzle.key)); + Puzzle *puzzle = new Puzzle(); + sscanf(line.c_str(),"puzzle:%u",&(puzzle->key)); parsePuzzle(puzzle, file); if (isGlobal) { @@ -67,17 +67,17 @@ void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) } } -void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream) { +void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream) { Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("criteria {", true)) { - parseCriteria(stream, puzzle.criteriaList); + parseCriteria(stream, puzzle->criteriaList); } else if (line.matchString("results {", true)) { - parseResults(stream, puzzle.resultActions); + parseResults(stream, puzzle->resultActions); } else if (line.matchString("flags {", true)) { - puzzle.flags = parseFlags(stream); + puzzle->flags = parseFlags(stream); } line = stream.readLine(); diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 6a1794dabf..390fe0d742 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -41,6 +41,15 @@ ScriptManager::ScriptManager(ZVision *engine) _changeLocation(false) { } +ScriptManager::~ScriptManager() { + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + delete (*iter); + } + for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + delete (*iter); + } +} + void ScriptManager::initialize() { parseScrFile("universe.scr", true); changeLocation('g', 'a', 'r', 'y', 0); @@ -58,11 +67,11 @@ void ScriptManager::update(uint deltaTimeMillis) { void ScriptManager::createReferenceTable() { // Iterate through each local Puzzle - for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { - Puzzle *puzzlePtr = &(*activePuzzleIter); + for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { + Puzzle *puzzlePtr = (*activePuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle - for (Common::List >::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List >::iterator criteriaIter = (*activePuzzleIter)->criteriaList.begin(); criteriaIter != (*activePuzzleIter)->criteriaList.end(); criteriaIter++) { for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { _referenceTable[entryIter->key].push_back(puzzlePtr); @@ -75,11 +84,11 @@ void ScriptManager::createReferenceTable() { } // Iterate through each global Puzzle - for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { - Puzzle *puzzlePtr = &(*globalPuzzleIter); + for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { + Puzzle *puzzlePtr = (*globalPuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle - for (Common::List >::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List >::iterator criteriaIter = (*globalPuzzleIter)->criteriaList.begin(); criteriaIter != (*globalPuzzleIter)->criteriaList.end(); criteriaIter++) { for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { _referenceTable[entryIter->key].push_back(puzzlePtr); @@ -263,23 +272,23 @@ void ScriptManager::changeLocationIntern() { } // Add all the local puzzles to the queue to be checked - for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST - if (((*iter).flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { - setStateValue((*iter).key, 0); + if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { + setStateValue((*iter)->key, 0); } - _puzzlesToCheck.push(&(*iter)); + _puzzlesToCheck.push((*iter)); } // Add all the global puzzles to the queue to be checked - for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { // Reset any Puzzles that have the flag ONCE_PER_INST - if (((*iter).flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { - setStateValue((*iter).key, 0); + if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { + setStateValue((*iter)->key, 0); } - _puzzlesToCheck.push(&(*iter)); + _puzzlesToCheck.push((*iter)); } // Create the puzzle reference table diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 884699a6b0..2372703cbe 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -50,6 +50,7 @@ struct Location { class ScriptManager { public: ScriptManager(ZVision *engine); + ~ScriptManager(); private: ZVision *_engine; @@ -66,9 +67,9 @@ private: /** Holds the Puzzles that should be checked this frame */ Common::Queue _puzzlesToCheck; /** Holds the currently active puzzles */ - Common::List _activePuzzles; + Common::List _activePuzzles; /** Holds the global puzzles */ - Common::List_globalPuzzles; + Common::List_globalPuzzles; /** Holds the currently active controls */ Common::HashMap _activeControls; @@ -112,7 +113,7 @@ private: * @param puzzle The object to store what is parsed * @param stream Scr file stream */ - void parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stream); + void parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream); /** * Parses the stream into a Criteria object -- cgit v1.2.3 From 8e22af36b7e1500fa8ccca971225d87066cb9e26 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 20:51:00 -0500 Subject: ZVISION: Add TODO to subtitles --- engines/zvision/subtitles.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/subtitles.h b/engines/zvision/subtitles.h index 00eeef2a8a..e88108327f 100644 --- a/engines/zvision/subtitles.h +++ b/engines/zvision/subtitles.h @@ -24,6 +24,6 @@ #ifndef ZVISION_SUBTITLES_H #define ZVISION_SUBTITLES_H -// Implement Subtitles +// TODO: Implement Subtitles #endif \ No newline at end of file -- cgit v1.2.3 From ac7b2251bb3cb41b10d2b69b3d3540895db057d8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 20:55:00 -0500 Subject: ZVISION: Delete Puzzles from heap before clearing _activePuzzles --- engines/zvision/script_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 390fe0d742..c217cb8612 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -248,6 +248,9 @@ void ScriptManager::changeLocationIntern() { // Clear all the containers _referenceTable.clear(); _puzzlesToCheck.clear(); + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + delete (*iter); + } _activePuzzles.clear(); // We can clear without deleting from the heap because we use SharedPtr _activeControls.clear(); -- cgit v1.2.3 From fa7fb2e029adec318cf963292b4b9b375189b487 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 21:26:53 -0500 Subject: ZVISION: Initialize Puzzle::key and Puzzle::flags Some Puzzles don't have flags, which caused it to never be initialized --- engines/zvision/puzzle.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 371af83d91..512a9636b9 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -32,6 +32,8 @@ namespace ZVision { struct Puzzle { + Puzzle() : key(0), flags(0) {} + ~Puzzle() { for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { delete (*iter); -- cgit v1.2.3 From ca5066db526d3fc8cc9f45f494da29a34bd41537 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 23:04:16 -0500 Subject: ZVISION: Remove static Control::parsePushToggleControl The code was moved to the class PushToggleControl --- engines/zvision/control.cpp | 4 ---- engines/zvision/control.h | 1 - 2 files changed, 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index 106d938889..94e0c477ab 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -165,8 +165,4 @@ bool PushToggleControl::disable(ZVision *engine) { return false; } -void Control::parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream) { - -} - } // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index e3cb0d4afa..32a2b863b0 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -53,7 +53,6 @@ public: static void parseFlatControl(ZVision *engine); static void parsePanoramaControl(ZVision *engine, Common::SeekableReadStream &stream); static void parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream); - static void parsePushToggleControl(uint32 key, ZVision *engine, Common::SeekableReadStream &stream); }; class PushToggleControl : public Control { -- cgit v1.2.3 From 25f95ebdcd2c269cf4016748dc51584aaa9125c5 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 20 Aug 2013 23:05:01 -0500 Subject: ZVISION: Implement streaming support for RlfAnimations --- engines/zvision/rlf_animation.cpp | 185 +++++++++++++++++++++++--------------- engines/zvision/rlf_animation.h | 18 +++- 2 files changed, 131 insertions(+), 72 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 90086e9bd0..2b37ff147e 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -33,8 +33,10 @@ namespace ZVision { -RlfAnimation::RlfAnimation(const Common::String &fileName) - : _frameCount(0), +RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) + : _stream(stream), + _lastFrameRead(0), + _frameCount(0), _width(0), _height(0), _frameTime(0), @@ -42,84 +44,25 @@ RlfAnimation::RlfAnimation(const Common::String &fileName) _currentFrameBuffer(0), _currentFrame(-1), _frameBufferByteSize(0) { - Common::File file; - if (!file.open(fileName)) { + if (!_file.open(fileName)) { warning("RLF animation file %s could not be opened", fileName.c_str()); return; } - if (file.readUint32BE() != MKTAG('F', 'E', 'L', 'R')) { + if (!readHeader()) { warning("%s is not a RLF animation file. Wrong magic number", fileName.c_str()); return; } - // Read the header - file.readUint32LE(); // Size1 - file.readUint32LE(); // Unknown1 - file.readUint32LE(); // Unknown2 - _frameCount = file.readUint32LE(); // Frame count - - // Since we don't need any of the data, we can just seek right to the - // entries we need rather than read in all the individual entries. - file.seek(136, SEEK_CUR); - - //// Read CIN header - //file.readUint32BE(); // Magic number FNIC - //file.readUint32LE(); // Size2 - //file.readUint32LE(); // Unknown3 - //file.readUint32LE(); // Unknown4 - //file.readUint32LE(); // Unknown5 - //file.seek(0x18, SEEK_CUR); // VRLE - //file.readUint32LE(); // LRVD - //file.readUint32LE(); // Unknown6 - //file.seek(0x18, SEEK_CUR); // HRLE - //file.readUint32LE(); // ELHD - //file.readUint32LE(); // Unknown7 - //file.seek(0x18, SEEK_CUR); // HKEY - //file.readUint32LE(); // ELRH - - //// Read MIN info header - //file.readUint32BE(); // Magic number FNIM - //file.readUint32LE(); // Size3 - //file.readUint32LE(); // OEDV - //file.readUint32LE(); // Unknown8 - //file.readUint32LE(); // Unknown9 - //file.readUint32LE(); // Unknown10 - _width = file.readUint32LE(); // Width - _height = file.readUint32LE(); // Height - - // Read time header - file.readUint32BE(); // Magic number EMIT - file.readUint32LE(); // Size4 - file.readUint32LE(); // Unknown11 - _frameTime = file.readUint32LE() / 10; // Frame time in microseconds - - _frames = new Frame[_frameCount]; _currentFrameBuffer = new uint16[_width * _height]; _frameBufferByteSize = _width * _height * sizeof(uint16); - // Read in each frame - for (uint i = 0; i < _frameCount; i++) { - file.readUint32BE(); // Magic number MARF - uint32 size = file.readUint32LE(); // Size - file.readUint32LE(); // Unknown1 - file.readUint32LE(); // Unknown2 - uint32 type = file.readUint32BE(); // Either ELHD or ELRH - uint32 headerSize = file.readUint32LE(); // Offset from the beginning of this frame to the frame data. Should always be 28 - file.readUint32LE(); // Unknown3 - - _frames[i].encodedSize = size - headerSize; - _frames[i].encodedData = new int8[_frames[i].encodedSize]; - file.read(_frames[i].encodedData, _frames[i].encodedSize); - - if (type == MKTAG('E', 'L', 'H', 'D')) { - _frames[i].type = Masked; - } else if (type == MKTAG('E', 'L', 'R', 'H')) { - _frames[i].type = Simple; - _completeFrames.push_back(i); - } else { - warning("Frame %u of %s doesn't have type that can be decoded", i, fileName.c_str()); - return; + if (!stream) { + _frames = new Frame[_frameCount]; + + // Read in each frame + for (uint i = 0; i < _frameCount; i++) { + _frames[i] = readNextFrame(); } } }; @@ -133,7 +76,85 @@ RlfAnimation::~RlfAnimation() { } } +bool RlfAnimation::readHeader() { + if (_file.readUint32BE() != MKTAG('F', 'E', 'L', 'R')) { + return false; + } + + // Read the header + _file.readUint32LE(); // Size1 + _file.readUint32LE(); // Unknown1 + _file.readUint32LE(); // Unknown2 + _frameCount = _file.readUint32LE(); // Frame count + + // Since we don't need any of the data, we can just seek right to the + // entries we need rather than read in all the individual entries. + _file.seek(136, SEEK_CUR); + + //// Read CIN header + //_file.readUint32BE(); // Magic number FNIC + //_file.readUint32LE(); // Size2 + //_file.readUint32LE(); // Unknown3 + //_file.readUint32LE(); // Unknown4 + //_file.readUint32LE(); // Unknown5 + //_file.seek(0x18, SEEK_CUR); // VRLE + //_file.readUint32LE(); // LRVD + //_file.readUint32LE(); // Unknown6 + //_file.seek(0x18, SEEK_CUR); // HRLE + //_file.readUint32LE(); // ELHD + //_file.readUint32LE(); // Unknown7 + //_file.seek(0x18, SEEK_CUR); // HKEY + //_file.readUint32LE(); // ELRH + + //// Read MIN info header + //_file.readUint32BE(); // Magic number FNIM + //_file.readUint32LE(); // Size3 + //_file.readUint32LE(); // OEDV + //_file.readUint32LE(); // Unknown8 + //_file.readUint32LE(); // Unknown9 + //_file.readUint32LE(); // Unknown10 + _width = _file.readUint32LE(); // Width + _height = _file.readUint32LE(); // Height + + // Read time header + _file.readUint32BE(); // Magic number EMIT + _file.readUint32LE(); // Size4 + _file.readUint32LE(); // Unknown11 + _frameTime = _file.readUint32LE() / 10; // Frame time in microseconds + + return true; +} + +RlfAnimation::Frame RlfAnimation::readNextFrame() { + RlfAnimation::Frame frame; + + _file.readUint32BE(); // Magic number MARF + uint32 size = _file.readUint32LE(); // Size + _file.readUint32LE(); // Unknown1 + _file.readUint32LE(); // Unknown2 + uint32 type = _file.readUint32BE(); // Either ELHD or ELRH + uint32 headerSize = _file.readUint32LE(); // Offset from the beginning of this frame to the frame data. Should always be 28 + _file.readUint32LE(); // Unknown3 + + frame.encodedSize = size - headerSize; + frame.encodedData = new int8[frame.encodedSize]; + _file.read(frame.encodedData, frame.encodedSize); + + if (type == MKTAG('E', 'L', 'H', 'D')) { + frame.type = Masked; + } else if (type == MKTAG('E', 'L', 'R', 'H')) { + frame.type = Simple; + _completeFrames.push_back(_lastFrameRead); + } else { + warning("Frame %u doesn't have type that can be decoded", _lastFrameRead); + } + + _lastFrameRead++; + return frame; +} + const uint16 *RlfAnimation::getFrameData(uint frameNumber) { + assert(!_stream); assert(frameNumber < _frameCount && frameNumber >= 0); if (frameNumber == _currentFrame) { @@ -161,13 +182,29 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { } } + _currentFrame = frameNumber; return _currentFrameBuffer; } const uint16 *RlfAnimation::getNextFrame() { assert(_currentFrame + 1 < _frameCount); - applyFrameToCurrent(_currentFrame + 1); + if (_stream) { + applyFrameToCurrent(readNextFrame()); + } else { + applyFrameToCurrent(_currentFrame + 1); + } + + _currentFrame -= 1; + return _currentFrameBuffer; +} + +const uint16 *RlfAnimation::getPreviousFrame() { + assert(!_stream); + assert(_currentFrame - 1 >= 0); + + applyFrameToCurrent(_currentFrame - 1); + _currentFrame =- 1; return _currentFrameBuffer; } @@ -177,8 +214,14 @@ void RlfAnimation::applyFrameToCurrent(uint frameNumber) { } else if (_frames[frameNumber].type == Simple) { decodeSimpleRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer, _frames[frameNumber].encodedSize, _frameBufferByteSize); } +} - _currentFrame = frameNumber; +void RlfAnimation::applyFrameToCurrent(const RlfAnimation::Frame &frame) { + if (frame.type == Masked) { + decodeMaskedRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer, frame.encodedSize, _frameBufferByteSize); + } else if (frame.type == Simple) { + decodeSimpleRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer, frame.encodedSize, _frameBufferByteSize); + } } void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const { diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index e204a50090..09d0bac71e 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -23,6 +23,10 @@ #ifndef ZVISION_RLF_ANIMATION_H #define ZVISION_RLF_ANIMATION_H +#include "common/types.h" + +#include "common/file.h" + namespace Common { class String; @@ -32,7 +36,7 @@ namespace ZVision { class RlfAnimation { public: - RlfAnimation(const Common::String &fileName); + RlfAnimation(const Common::String &fileName, bool stream = true); ~RlfAnimation(); private: @@ -48,6 +52,10 @@ private: }; private: + Common::File _file; + bool _stream; + uint _lastFrameRead; + uint _frameCount; uint _width; uint _height; @@ -64,12 +72,20 @@ public: uint width() { return _width; } uint height() { return _height; } uint32 frameTime() { return _frameTime; } + const uint16 *getFrameData(uint frameNumber); + const uint16 *getNextFrame(); + const uint16 *getPreviousFrame(); + bool endOfAnimation() { return _currentFrame == _frameCount - 1; } private: + bool readHeader(); + Frame readNextFrame(); + void applyFrameToCurrent(uint frameNumber); + void applyFrameToCurrent(const RlfAnimation::Frame &frame); void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; -- cgit v1.2.3 From f759584d3b4bf802163fde9c721fda5c6f36ff4d Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 23 Aug 2013 23:50:33 -0500 Subject: ZVISION: Make ZVision::_workingWindow and ZVision::_pixelFormat public --- engines/zvision/zvision.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 366e96f6a7..844b8ad18f 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -64,6 +64,15 @@ public: ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc); ~ZVision(); +public: + /** + * A Rectangle centered inside the actual window. All in-game coordinates + * are given in this coordinate space. Also, all images are clipped to the + * edges of this Rectangle + */ + const Common::Rect _workingWindow; + const Graphics::PixelFormat _pixelFormat; + private: enum { WINDOW_WIDTH = 640, @@ -72,18 +81,11 @@ private: WORKING_WINDOW_HEIGHT = 320, ROTATION_SCREEN_EDGE_OFFSET = 60, - MAX_ROTATION_SPEED = 150 // Pixels per second + MAX_ROTATION_SPEED = 250 // Pixels per second }; Console *_console; const ZVisionGameDescription *_gameDescription; - /** - * A Rectangle centered inside the actual window. All in-game coordinates - * are given in this coordinate space. Also, all images are clipped to the - * edges of this Rectangle - */ - const Common::Rect _workingWindow; - const Graphics::PixelFormat _pixelFormat; const int _desiredFrameTime; -- cgit v1.2.3 From b28d502288fe96657fadbf9679f67601583036b3 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 23 Aug 2013 23:53:19 -0500 Subject: ZVISION: Convert ScriptManager::_activeNodes to normal pointers instead of SharedPtrs --- engines/zvision/actions.cpp | 2 +- engines/zvision/script_manager.cpp | 11 ++++++----- engines/zvision/script_manager.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 16499138c7..baa89aa165 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -354,7 +354,7 @@ ActionTimer::ActionTimer(const Common::String &line) { } bool ActionTimer::execute(ZVision *engine) { - engine->getScriptManager()->addActionNode(Common::SharedPtr(new NodeTimer(_key, _time))); + engine->getScriptManager()->addActionNode(new TimerNode(engine, _key, _time)); return true; } diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index c217cb8612..9a4e9d13be 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -108,9 +108,10 @@ void ScriptManager::createReferenceTable() { void ScriptManager::updateNodes(uint deltaTimeMillis) { // If process() returns true, it means the node can be deleted - for (Common::List >::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) { - if ((*iter)->process(_engine, deltaTimeMillis)) { - // Remove the node from _activeNodes, the SharedPtr destructor will delete the actual ActionNode + for (Common::List::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) { + if ((*iter)->process(deltaTimeMillis)) { + // Delete the node then remove the pointer + delete (*iter); iter = _activeNodes.erase(iter); } else { iter++; @@ -223,11 +224,11 @@ bool ScriptManager::disableControl(uint32 key) { if (!_activeControls.contains(key)) { return false; } else { - return _activeControls[key]->disable(_engine); + return _activeControls[key]->disable(); } } -void ScriptManager::addActionNode(const Common::SharedPtr &node) { +void ScriptManager::addActionNode(ActionNode *node) { _activeNodes.push_back(node); } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 2372703cbe..28bce07dc8 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -61,7 +61,7 @@ private: */ Common::HashMap _globalState; /** Holds the currently active ActionNodes */ - Common::List > _activeNodes; + Common::List _activeNodes; /** References _globalState keys to Puzzles */ Common::HashMap > _referenceTable; /** Holds the Puzzles that should be checked this frame */ @@ -88,7 +88,7 @@ public: bool enableControl(uint32 key); bool disableControl(uint32 key); - void addActionNode(const Common::SharedPtr &node); + void addActionNode(ActionNode *node); void changeLocation(char world, char room, char node, char view, uint32 offset); -- cgit v1.2.3 From adb3bd7b711ba9daf62e06bbe55d2ca55e5219b4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 23 Aug 2013 23:58:14 -0500 Subject: ZVISION: Make MouseEvent purely virtual --- engines/zvision/module.mk | 1 - engines/zvision/mouse_event.cpp | 45 ----------------------------------------- engines/zvision/mouse_event.h | 36 ++++++++++++++++----------------- 3 files changed, 17 insertions(+), 65 deletions(-) delete mode 100644 engines/zvision/mouse_event.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 317e4b11d4..a4b7c68cde 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -12,7 +12,6 @@ MODULE_OBJS := \ detection.o \ events.o \ lzss_read_stream.o \ - mouse_event.o \ render_manager.o \ render_table.o \ rlf_animation.o \ diff --git a/engines/zvision/mouse_event.cpp b/engines/zvision/mouse_event.cpp deleted file mode 100644 index a7c9fe5573..0000000000 --- a/engines/zvision/mouse_event.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/zvision.h" -#include "zvision/script_manager.h" -#include "zvision/mouse_event.h" - -namespace ZVision { - -MouseEvent::MouseEvent(uint32 key, const Common::Rect &hotspot, const Common::String hoverCursor) - : _key(key), - _hotspot(hotspot), - _hoverCursor(hoverCursor) { -} - -bool MouseEvent::withinHotspot(const Common::Point &point) { - return _hotspot.contains(point); -} - -void MouseEvent::onClick(ZVision *engine) { - engine->getScriptManager()->setStateValue(_key, 1); -} - -} // End of namespace ZVision diff --git a/engines/zvision/mouse_event.h b/engines/zvision/mouse_event.h index 90a093f894..fe81adaf19 100644 --- a/engines/zvision/mouse_event.h +++ b/engines/zvision/mouse_event.h @@ -35,37 +35,35 @@ class ZVision; class MouseEvent { public: MouseEvent() : _key(0) {} - MouseEvent(uint32 key, const Common::Rect &hotspot, const Common::String hoverCursor); + MouseEvent(uint32 key) : _key(key) {} + virtual ~MouseEvent() {} - /** The Control key */ +public: uint32 _key; - /** - * The area that will trigger the event - * This is in image space coordinates, NOT screen space - */ - Common::Rect _hotspot; - /** The cursor to use when hovering over _hotspot */ - Common::String _hoverCursor; +public: /** - * Does a simple Rect::contains() using _hotspot + * Called when LeftMouse is pushed. * - * @param point The point to check against _hotspot - * @return The point is inside _hotspot (true) or not (false) + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space */ - bool withinHotspot(const Common::Point &point); + virtual void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) = 0; /** - * Calls ScriptManager::setStateValue(_key, 1) + * Called when LeftMouse is lifted. * - * @param engine The base engine + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space */ - void onClick(ZVision *engine); + virtual void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) = 0; /** - * Gets the name of the cursor that should be displayed when withinHotspot returns true + * Called on every MouseMove. * - * @return The name of the cursor. This should correspond to one of the names in CursorManager::_cursorNames[] + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + * @return Was the cursor changed? */ - const Common::String getHoverCursor() { return _hoverCursor; } + virtual bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) = 0; }; } // End of namespace ZVision -- cgit v1.2.3 From 2431f60c02197585bd252393a013f8e50a2ae30a Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 23 Aug 2013 23:59:28 -0500 Subject: ZVISION: Make Control purely virtual --- engines/zvision/control.h | 9 +++------ engines/zvision/script_manager.cpp | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 32a2b863b0..17408c79f1 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -37,13 +37,10 @@ class ZVision; class Control { public: - Control() : _key(0), _enabled(false) {} + Control() : _enabled(false) {} virtual ~Control() {} - virtual bool enable(ZVision *engine) = 0; - virtual bool disable(ZVision *engine) { return true; } - -public: - uint32 _key; + virtual bool enable() = 0; + virtual bool disable() = 0; protected: bool _enabled; diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 9a4e9d13be..d671c6178c 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -216,7 +216,7 @@ bool ScriptManager::enableControl(uint32 key) { if (!_activeControls.contains(key)) { return false; } else { - return _activeControls[key]->enable(_engine); + return _activeControls[key]->enable(); } } @@ -272,7 +272,7 @@ void ScriptManager::changeLocationIntern() { // Enable all the controls for (Common::HashMap::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { - (*iter)._value->enable(_engine); + (*iter)._value->enable(); } // Add all the local puzzles to the queue to be checked -- cgit v1.2.3 From 7095e613d59630ec03dbf8a17e18ae9b4aabf289 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:00:30 -0500 Subject: ZVISION: Keep a member variable ZVision pointer instead of passing it in every process() --- engines/zvision/action_node.cpp | 9 +++++---- engines/zvision/action_node.h | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.cpp b/engines/zvision/action_node.cpp index 1a51690b3f..f51801a75d 100644 --- a/engines/zvision/action_node.cpp +++ b/engines/zvision/action_node.cpp @@ -28,14 +28,15 @@ namespace ZVision { -NodeTimer::NodeTimer(uint32 key, uint timeInSeconds) - : _key(key), _timeLeft(timeInSeconds * 1000) {} +TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds) + : _engine(engine), _key(key), _timeLeft(timeInSeconds * 1000) { +} -bool NodeTimer::process(ZVision *engine, uint32 deltaTimeInMillis) { +bool TimerNode::process(uint32 deltaTimeInMillis) { _timeLeft -= deltaTimeInMillis; if (_timeLeft <= 0) { - engine->getScriptManager()->setStateValue(_key, 0); + _engine->getScriptManager()->setStateValue(_key, 0); return true; } diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h index 5b4430c3a4..9a5ca0be0b 100644 --- a/engines/zvision/action_node.h +++ b/engines/zvision/action_node.h @@ -32,23 +32,29 @@ class ZVision; class ActionNode { public: virtual ~ActionNode() {} - virtual bool process(ZVision *engine, uint32 deltaTimeInMillis) = 0; + /** + * Processes the node given the deltaTime since last frame + * + * @param deltaTimeInMillis The number of milliseconds that have passed since last frame + * @return If true, the node can be deleted after process() finishes + */ + virtual bool process(uint32 deltaTimeInMillis) = 0; }; -class NodeTimer : public ActionNode { +class TimerNode : public ActionNode { public: - NodeTimer(uint32 key, uint timeInSeconds); + TimerNode(ZVision *engine, uint32 key, uint timeInSeconds); /** * Decrement the timer by the delta time. If the timer is finished, set the status * in _globalState and let this node be deleted * - * @param engine Pointer to the ZVision instance - * @param deltaTimeInMillis Amount of time that has passed since the last frame - * @return Node should be deleted after this (true) or kept (false) + * @param deltaTimeInMillis The number of milliseconds that have passed since last frame + * @return If true, the node can be deleted after process() finishes */ - bool process(ZVision *engine, uint32 deltaTimeInMillis); + bool process(uint32 deltaTimeInMillis); private: + ZVision *_engine; uint32 _key; uint32 _timeLeft; }; -- cgit v1.2.3 From 3054489a8bcc9604028ac16a0b074e13bff258eb Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:06:20 -0500 Subject: ZVISION: Have PushToggleControl inherit from MouseEvent and handle the methods internally. Rather than creating an instance of MouseEvent and passing argument around. --- engines/zvision/control.cpp | 33 ++++++++++++++++-------- engines/zvision/control.h | 47 +++++++++++++++++++++++++++++++---- engines/zvision/scr_file_handling.cpp | 2 +- 3 files changed, 65 insertions(+), 17 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index 94e0c477ab..ff767863f4 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -108,10 +108,9 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre // PushToggleControl ////////////////////////////////////////////////////////////////////////////// -PushToggleControl::PushToggleControl(uint32 key, Common::SeekableReadStream &stream) - : Control() { - _event._key = _key = key; - +PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) + : MouseEvent(key), + _engine(engine) { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -125,27 +124,27 @@ PushToggleControl::PushToggleControl(uint32 key, Common::SeekableReadStream &str sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); - _event._hotspot = Common::Rect(x, y, x + width, y + height); + _hotspot = Common::Rect(x, y, x + width, y + height); } else if (line.matchString("cursor*", true)) { char nameBuffer[25]; sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); - _event._hoverCursor = Common::String(nameBuffer); + _hoverCursor = Common::String(nameBuffer); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } - if (_event._hotspot.isEmpty() || _event._hoverCursor.empty()) { + if (_hotspot.isEmpty() || _hoverCursor.empty()) { warning("Push_toggle cursor %u was parsed incorrectly", key); } } -bool PushToggleControl::enable(ZVision *engine) { +bool PushToggleControl::enable() { if (!_enabled) { - engine->registerMouseEvent(_event); + _engine->registerMouseEvent(this); _enabled = true; return true; } @@ -154,9 +153,9 @@ bool PushToggleControl::enable(ZVision *engine) { return false; } -bool PushToggleControl::disable(ZVision *engine) { +bool PushToggleControl::disable() { if (_enabled) { - engine->removeMouseEvent(_key); + _engine->removeMouseEvent(_key); _enabled = false; return true; } @@ -165,4 +164,16 @@ bool PushToggleControl::disable(ZVision *engine) { return false; } +void PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + _engine->getScriptManager()->setStateValue(_key, 1); +} + +bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + if (_hotspot.contains(backgroundImageSpacePos)) { + _engine->getCursorManager()->changeCursor(_hoverCursor); + return true; + } + + return false; +} } // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 17408c79f1..28079d52e7 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -52,14 +52,51 @@ public: static void parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream); }; -class PushToggleControl : public Control { + +class PushToggleControl : public Control, public MouseEvent { +public: + PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); + bool enable(); + bool disable(); + + /** + * Called when LeftMouse is pushed. Calls ScriptManager::setStateValue(_key, 1); + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + /** + * Called when LeftMouse is lifted. Does nothing + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {} + /** + * Called on every MouseMove. Tests if the mouse is inside _hotspot, and if so, sets the cursor. + * + * @param engine The base engine + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + * @return Was the cursor changed? + */ + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + +private: + ZVision * _engine; + /** + * The area that will trigger the event + * This is in image space coordinates, NOT screen space + */ + Common::Rect _hotspot; + /** The cursor to use when hovering over _hotspot */ + Common::String _hoverCursor; +}; + public: - PushToggleControl(uint32 key, Common::SeekableReadStream &stream); - bool enable(ZVision *engine); - bool disable(ZVision *engine); private: - MouseEvent _event; }; // TODO: Implement InputControl diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 7ccd939e54..921c1d5b44 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -278,7 +278,7 @@ void ScriptManager::parseControl(Common::String &line, Common::SeekableReadStrea Common::String controlType(controlTypeBuffer); if (controlType.equalsIgnoreCase("push_toggle")) { - _activeControls[key] = new PushToggleControl(key, stream); + _activeControls[key] = new PushToggleControl(_engine, key, stream); return; } else if (controlType.equalsIgnoreCase("flat")) { Control::parseFlatControl(_engine); -- cgit v1.2.3 From 0da3d3e5eb3c332f943a63fea4e3777fb24ba577 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:09:15 -0500 Subject: ZVISION: Convert _mouseEvents to pointers since MouseEvent is now abstract --- engines/zvision/events.cpp | 35 ++++++++++++++++++----------------- engines/zvision/zvision.h | 4 ++-- 2 files changed, 20 insertions(+), 19 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 798d75b375..f751d02386 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -37,14 +37,14 @@ namespace ZVision { -void ZVision::registerMouseEvent(const MouseEvent &event) { +void ZVision::registerMouseEvent(MouseEvent *event) { _mouseEvents.push_back(event); } bool ZVision::removeMouseEvent(const uint32 key) { - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - if ((*iter)._key == key) { - _scriptManager->setStateValue((*iter)._key, 0); + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + if ((*iter)->_key == key) { + _scriptManager->setStateValue((*iter)->_key, 0); _mouseEvents.erase(iter); return true; } @@ -55,8 +55,10 @@ bool ZVision::removeMouseEvent(const uint32 key) { void ZVision::clearAllMouseEvents() { // Clear the state values of all the events - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - _scriptManager->setStateValue((*iter)._key, 0); + // Then delete the nodes + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + _scriptManager->setStateValue((*iter)->_key, 0); + delete (*iter); } _mouseEvents.clear(); @@ -117,6 +119,12 @@ void ZVision::processEvents() { void ZVision::onMouseDown(const Common::Point &pos) { _cursorManager->cursorDown(true); + + Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); + + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + (*iter)->onMouseDown(pos, imageCoord); + } } void ZVision::onMouseUp(const Common::Point &pos) { @@ -124,10 +132,8 @@ void ZVision::onMouseUp(const Common::Point &pos) { Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - if (iter->withinHotspot(imageCoord)) { - iter->onClick(this); - } + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + (*iter)->onMouseUp(pos, imageCoord); } } @@ -135,13 +141,8 @@ void ZVision::onMouseMove(const Common::Point &pos) { Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); bool isWithinAHotspot = false; - if (_workingWindow.contains(pos)) { - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - if (iter->withinHotspot(imageCoord)) { - _cursorManager->changeCursor(iter->getHoverCursor()); - isWithinAHotspot = true; - } - } + for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { + cursorWasChanged = cursorWasChanged || (*iter)->onMouseMove(pos, imageCoord); } // Graph of the function governing rotation velocity: diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 844b8ad18f..84e4da9d20 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -101,7 +101,7 @@ private: Clock _clock; // To store the current mouse events - Common::List _mouseEvents; + Common::List _mouseEvents; // To prevent allocation every time we process events Common::Event _event; @@ -137,7 +137,7 @@ public: * * @param event The event to register */ - void registerMouseEvent(const MouseEvent &event); + void registerMouseEvent(MouseEvent *event); bool removeMouseEvent(const uint32 key); -- cgit v1.2.3 From aed38867ceb4fc13f221322aae15054fece7cff2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:10:34 -0500 Subject: ZVISION: Change variable name to match its purpose --- engines/zvision/events.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index f751d02386..94e8f088dd 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -140,7 +140,7 @@ void ZVision::onMouseUp(const Common::Point &pos) { void ZVision::onMouseMove(const Common::Point &pos) { Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); - bool isWithinAHotspot = false; + bool cursorWasChanged = false; for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { cursorWasChanged = cursorWasChanged || (*iter)->onMouseMove(pos, imageCoord); } @@ -184,14 +184,14 @@ void ZVision::onMouseMove(const Common::Point &pos) { Common::Rational velocity = (Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.x - _workingWindow.left)) - MAX_ROTATION_SPEED; _renderManager->setBackgroundVelocity(velocity.toInt()); _cursorManager->setLeftCursor(); - isWithinAHotspot = true; + cursorWasChanged = true; } else if (pos.x <= _workingWindow.right && pos.x > _workingWindow.right - ROTATION_SCREEN_EDGE_OFFSET) { // Linear function of distance to the right edge (y = mx) // We use fixed point math to get better accuracy Common::Rational velocity = Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.x - _workingWindow.right + ROTATION_SCREEN_EDGE_OFFSET); _renderManager->setBackgroundVelocity(velocity.toInt()); _cursorManager->setRightCursor(); - isWithinAHotspot = true; + cursorWasChanged = true; } else { _renderManager->setBackgroundVelocity(0); } @@ -202,14 +202,14 @@ void ZVision::onMouseMove(const Common::Point &pos) { Common::Rational velocity = (Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.top)) - MAX_ROTATION_SPEED; _renderManager->setBackgroundVelocity(velocity.toInt()); _cursorManager->setUpCursor(); - isWithinAHotspot = true; + cursorWasChanged = true; } else if (pos.y <= _workingWindow.bottom && pos.y > _workingWindow.bottom - ROTATION_SCREEN_EDGE_OFFSET) { // Linear function of distance to the bottom edge (y = mx) // We use fixed point math to get better accuracy Common::Rational velocity = Common::Rational(MAX_ROTATION_SPEED, ROTATION_SCREEN_EDGE_OFFSET) * (pos.y - _workingWindow.bottom + ROTATION_SCREEN_EDGE_OFFSET); _renderManager->setBackgroundVelocity(velocity.toInt()); _cursorManager->setDownCursor(); - isWithinAHotspot = true; + cursorWasChanged = true; } else { _renderManager->setBackgroundVelocity(0); } @@ -218,7 +218,7 @@ void ZVision::onMouseMove(const Common::Point &pos) { _renderManager->setBackgroundVelocity(0); } - if (!isWithinAHotspot) { + if (!cursorWasChanged) { _cursorManager->revertToIdle(); } } -- cgit v1.2.3 From 6610ca1b82a1e335eecf139aaa4ba062574f48b7 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:14:25 -0500 Subject: ZVISION: Fix error: decrementing instead of incrementing --- engines/zvision/rlf_animation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 2b37ff147e..52ca96f0e1 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -195,7 +195,7 @@ const uint16 *RlfAnimation::getNextFrame() { applyFrameToCurrent(_currentFrame + 1); } - _currentFrame -= 1; + _currentFrame++; return _currentFrameBuffer; } @@ -204,7 +204,7 @@ const uint16 *RlfAnimation::getPreviousFrame() { assert(_currentFrame - 1 >= 0); applyFrameToCurrent(_currentFrame - 1); - _currentFrame =- 1; + _currentFrame--; return _currentFrameBuffer; } -- cgit v1.2.3 From c6242e71344d260af49cf5b2368a16d8679aac45 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:14:53 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/rlf_animation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index 09d0bac71e..d49e6a9395 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -78,7 +78,7 @@ public: const uint16 *getNextFrame(); const uint16 *getPreviousFrame(); - bool endOfAnimation() { return _currentFrame == _frameCount - 1; } + bool endOfAnimation() { return _currentFrame == (int)_frameCount - 1; } private: bool readHeader(); -- cgit v1.2.3 From d2df3eb24ea68eec5538fac73829b168f747e7a6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:16:59 -0500 Subject: ZVISION: Check if we can use getNextFrame() or getPreviousFrame() before using getFrameData() --- engines/zvision/rlf_animation.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 52ca96f0e1..5c0a88a18f 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -157,8 +157,14 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { assert(!_stream); assert(frameNumber < _frameCount && frameNumber >= 0); + // Since this method is so expensive, first check to see if we can use + // getNextFrame() or getPreviousFrame() since they are cheap. if (frameNumber == _currentFrame) { return _currentFrameBuffer; + } else if (_currentFrame + 1 == frameNumber) { + return getNextFrame(); + } else if (_currentFrame - 1 == frameNumber) { + return getPreviousFrame(); } uint closestFrame = _currentFrame; -- cgit v1.2.3 From 0ed7df9a3632207d65f3aef11d5f07e185484207 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:18:02 -0500 Subject: ZVISION: Add TODO's about the verbosity of the frame decoding overflow warning --- engines/zvision/rlf_animation.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 5c0a88a18f..905a540924 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -247,6 +247,7 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 if (sourceOffset + 1 >= sourceSize) { return; } else if (destOffset + 1 >= destSize) { + // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } @@ -264,6 +265,7 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 if (sourceOffset + 1 >= sourceSize) { return; } else if (destOffset + 1 >= destSize) { + // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } @@ -290,6 +292,7 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 if (sourceOffset + 1 >= sourceSize) { return; } else if (destOffset + 1 >= destSize) { + // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } @@ -314,6 +317,7 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 numberOfSamples += 2; while (numberOfSamples > 0) { if (destOffset + 1 >= destSize) { + // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } -- cgit v1.2.3 From fc5727c522d4313ab1912a52898405d083c60363 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:24:43 -0500 Subject: ZVISION: Fix memory leak We no longer use SharedPtr --- engines/zvision/script_manager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index d671c6178c..bcede2060d 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -253,7 +253,9 @@ void ScriptManager::changeLocationIntern() { delete (*iter); } _activePuzzles.clear(); - // We can clear without deleting from the heap because we use SharedPtr + for (Common::HashMap::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + delete (*iter)._value; + } _activeControls.clear(); _engine->clearAllMouseEvents(); -- cgit v1.2.3 From a9db1e17124639dfbd856f59afbf396d3c60452b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:25:01 -0500 Subject: ZVISION: Add note about _activeNodes --- engines/zvision/script_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index bcede2060d..50d7e58091 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -258,6 +258,7 @@ void ScriptManager::changeLocationIntern() { } _activeControls.clear(); _engine->clearAllMouseEvents(); + // TODO: See if we need to clear _activeNodes as well. And if so, remember to delete the nodes before clearing the list // Revert to the idle cursor _engine->getCursorManager()->revertToIdle(); -- cgit v1.2.3 From a596d1241cf0b443d3c2f8099546bc620116dcb2 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:25:21 -0500 Subject: ZVISION: Add console method to dump all .lev files --- engines/zvision/console.cpp | 13 +++++++++++++ engines/zvision/console.h | 1 + 2 files changed, 14 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 69d19ab53a..fd8347e74f 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -53,6 +53,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); DCmd_Register("dumpcursorfilenames", WRAP_METHOD(Console, cmdDumpAllCursorFileNames)); DCmd_Register("showcursor", WRAP_METHOD(Console, cmdShowCursor)); + DCmd_Register("dumpalllevfiles", WRAP_METHOD(Console, cmdDumpAllLevFiles)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -212,4 +213,16 @@ bool Console::cmdShowCursor(int argc, const char **argv) { return true; } +bool Console::cmdDumpAllLevFiles(int argc, const char **argv) { + Common::ArchiveMemberList list; + SearchMan.listMatchingMembers(list, "*.lev"); + + for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { + Common::String fileName = (*iter)->getName(); + writeFileContentsToFile(fileName, fileName); + } + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 995c41881e..e518467438 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -49,6 +49,7 @@ private: bool cmdDumpFile(int argc, const char **argv); bool cmdDumpAllCursorFileNames(int argc, const char **argv); bool cmdShowCursor(int argc, const char **argv); + bool cmdDumpAllLevFiles(int argc, const char **argv); }; } // End of namespace ZVision -- cgit v1.2.3 From 7d48a3e4b129784c7870472cbbaf6fa9488fffe6 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:25:55 -0500 Subject: ZVISION: Partially implement LeverControl --- engines/zvision/control.cpp | 323 ++++++++++++++++++++++++++++++++++++++++++++ engines/zvision/control.h | 88 +++++++++++- 2 files changed, 410 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index ff767863f4..9a1d52bd4f 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -23,16 +23,25 @@ #include "common/scummsys.h" #include "common/stream.h" +#include "common/system.h" +#include "common/tokenizer.h" #include "zvision/zvision.h" #include "zvision/render_manager.h" #include "zvision/render_table.h" #include "zvision/script_manager.h" +#include "zvision/cursor_manager.h" #include "zvision/control.h" #include "zvision/utility.h" +#include "zvision/rlf_animation.h" +#include "zvision/zork_avi_decoder.h" namespace ZVision { +////////////////////////////////////////////////////////////////////////////// +// Static member functions +////////////////////////////////////////////////////////////////////////////// + void Control::parseFlatControl(ZVision *engine) { engine->getRenderManager()->getRenderTable()->setRenderState(RenderTable::FLAT); } @@ -176,4 +185,318 @@ bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const C return false; } + +////////////////////////////////////////////////////////////////////////////// +// LeverControl +////////////////////////////////////////////////////////////////////////////// + +LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) + : MouseEvent(key), + _engine(engine), + _frameInfo(0), + _frameCount(0), + _startFrame(0), + _currentFrame(0), + _mouseIsCaptured(false), + _isReturning(false) { + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + while (!stream.eos() && !line.contains('}')) { + if (line.matchString("*descfile*", true)) { + char levFileName[25]; + sscanf(line.c_str(), "%*[^(](%25[^)])", levFileName); + + parseLevFile(levFileName); + } else if (line.matchString("*cursor*", true)) { + char cursorName[25]; + sscanf(line.c_str(), "%*[^(](%25[^)])", cursorName); + + _cursorName = Common::String(cursorName); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + } + + renderFrame(_currentFrame); + + _engine->getScriptManager()->addActionNode(this); +} + +LeverControl::~LeverControl() { + if (_fileType == AVI) { + delete _animation.avi; + } else if (_fileType == RLF) { + delete _animation.rlf; + } + if (_frameInfo != 0) { + delete[] _frameInfo; + } +} + +void LeverControl::parseLevFile(const Common::String &fileName) { + Common::File file; + if (!file.open(fileName)) { + warning("LEV file %s could could be opened", fileName.c_str()); + return; + } + + Common::String line = file.readLine(); + + while (!file.eos()) { + if (line.matchString("*animation_id*", true)) { + // Not used + } else if (line.matchString("*filename*", true)) { + char fileNameBuffer[25]; + sscanf(line.c_str(), "%*[^:]:%25[^~]~", fileNameBuffer); + + Common::String fileName(fileNameBuffer); + + if (fileName.hasSuffix(".avi")) { + _animation.avi = new ZorkAVIDecoder(); + _animation.avi->loadFile(fileName); + } else if (fileName.hasSuffix(".rlf")) { + _animation.rlf = new RlfAnimation(fileNameBuffer, false); + } + } else if (line.matchString("*skipcolor*", true)) { + // Not used + } else if (line.matchString("*anim_coords*", true)) { + sscanf(line.c_str(), "%*[^:]:%u %u %u %u~", &_animationCoords.left, &_animationCoords.top, &_animationCoords.right, &_animationCoords.bottom); + } else if (line.matchString("*mirrored*", true)) { + uint mirrored; + sscanf(line.c_str(), "%*[^:]:%u~", &mirrored); + + _mirrored = mirrored == 0 ? false : true; + } else if (line.matchString("*frames*", true)) { + sscanf(line.c_str(), "%*[^:]:%u~", &_frameCount); + + _frameInfo = new FrameInfo[_frameCount]; + } else if (line.matchString("*elsewhere*", true)) { + // Not used + } else if (line.matchString("*out_of_control*", true)) { + // Not used + } else if (line.matchString("*start_pos*", true)) { + sscanf(line.c_str(), "%*[^:]:%u~", &_startFrame); + _currentFrame = _startFrame; + } else if (line.matchString("*hotspot_deltas*", true)) { + uint x; + uint y; + sscanf(line.c_str(), "%*[^:]:%u %u~", &x, &y); + + _hotspotDelta.x = x; + _hotspotDelta.y = y; + } else { + uint frameNumber; + uint x, y; + + if (sscanf(line.c_str(), "%u:%u %u", &frameNumber, &x, &y) == 3) { + _frameInfo[frameNumber].hotspot.left = x; + _frameInfo[frameNumber].hotspot.top = y; + _frameInfo[frameNumber].hotspot.right = x + _hotspotDelta.x; + _frameInfo[frameNumber].hotspot.bottom = y + _hotspotDelta.y; + } + + Common::StringTokenizer tokenizer(line, " ^="); + tokenizer.nextToken(); + tokenizer.nextToken(); + + Common::String token = tokenizer.nextToken(); + while (!tokenizer.empty()) { + if (token == "D") { + token = tokenizer.nextToken(); + + uint angle; + uint toFrame; + sscanf(token.c_str(), "%u,%u", &toFrame, &angle); + + _frameInfo[frameNumber].directions.push_back(Direction(angle, toFrame)); + } else if (token.hasPrefix("P")) { + uint to; + sscanf(token.c_str(), "P(%*u to %u)", &to); + + _frameInfo[frameNumber].returnRoute.push_back(to); + } + + token = tokenizer.nextToken(); + } + } + + line = file.readLine(); + } +} + +void LeverControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { + _mouseIsCaptured = true; + _lastMousePos = backgroundImageSpacePos; + } +} + +void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + _mouseIsCaptured = false; + _engine->getScriptManager()->setStateValue(_key, _currentFrame); + + if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { + + } + + // TODO: Animation reversal back to origin +} + +bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + bool cursorWasChanged = false; + + if (_mouseIsCaptured) { + // Make sure the square distance between the last point and the current point is greater than 64 + // This is a heuristic. This determines how responsive the lever is to mouse movement. + // TODO: Fiddle with the heuristic to get a good lever responsiveness 'feel' + if (_lastMousePos.sqrDist(backgroundImageSpacePos) >= 64) { + int angle = calculateVectorAngle(_lastMousePos, backgroundImageSpacePos); + _lastMousePos = backgroundImageSpacePos; + + for (Common::List::iterator iter = _frameInfo[_currentFrame].directions.begin(); iter != _frameInfo[_currentFrame].directions.end(); iter++) { + if (angle >= (int)(*iter).angle - ANGLE_DELTA && angle <= (int)(*iter).angle) { + _currentFrame = (*iter).toFrame; + renderFrame(_currentFrame); + break; + } + } + } + } else if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { + _engine->getCursorManager()->changeCursor(_cursorName); + } + + return cursorWasChanged; +} + +bool LeverControl::process(uint32 deltaTimeInMillis) { + // TODO: Implement reversal over time + + return false; +} + +int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo) { + // Check for the easy angles first + if (pointOne.x == pointTwo.x && pointOne.y == pointTwo.y) + return -1; // This should never happen + else if (pointOne.x == pointTwo.x) { + if (pointTwo.y > pointOne.y) + return 90; + else + return 270; + } else if (pointOne.y == pointTwo.y) { + if (pointTwo.x > pointOne.x) + return 0; + else + return 180; + } else { + // Calculate the angle with trig + int16 xDist = pointTwo.x - pointOne.x; + int16 yDist = pointTwo.y - pointOne.y; + + int angle = int(atan((float)yDist / (float)xDist)); + + // Convert to degrees. (180 / 3.14159 = 57.2958) + angle *= 57; + + // Calculate what quadrant pointTwo is in + uint quadrant = ((yDist > 0 ? 1 : 0) << 1) | (xDist < 0 ? 1 : 0); + + // Explanation of quadrants: + // + // yDist > 0 | xDist < 0 | Quadrant number + // 0 | 0 | 0 + // 0 | 1 | 1 + // 1 | 0 | 2 + // 1 | 1 | 3 + // + // Note: I know this doesn't line up with traditional mathematical quadrants + // but doing it this way allows you can use a switch and is a bit cleaner IMO. + // + // The graph below shows the 4 quadrants pointTwo can end up in as well + // as what the angle as calculated above refers to. + // Note: The calculated angle in quadrants 0 and 3 is negative + // due to arctan(-x) = -theta + // + // Origin => (pointOne.x, pointOne.y) + // * => (pointTwo.x, pointTwo.y) + // + // 90 + // ^ + // * | * + // \ | / + // \ | / + // \ | / + // Quadrant 3 \ | / Quadrant 2 + // \ | / + // \ | / + // -angle ( \|/ ) angle + // 180 <----------------------------------------> 0 + // angle ( /|\ ) -angle + // / | \ + // / | \ + // Quadrant 1 / | \ Quadrant 0 + // / | \ + // / | \ + // / | \ + // * | * + // ^ + // 270 + + // Convert the local angles to unit circle angles + switch (quadrant) { + case 0: + angle = 360 + angle; + break; + case 1: + angle = 180 + angle; + break; + case 2: + angle = 180 + angle; + break; + case 3: + // Do nothing + break; + } + + return angle; + } +} + +void LeverControl::renderFrame(uint frameNumber) { + const uint16 *frameData; + int pitch; + int x; + int y; + int width; + int height; + + if (_fileType == RLF) { + // getFrameData() will automatically optimize to getNextFrame() / getPreviousFrame() if it can + frameData = _animation.rlf->getFrameData(_currentFrame); + pitch = _animation.rlf->width() * sizeof(uint16); + x = _animationCoords.left; + y = _animationCoords.right; + width = _animation.rlf->width(); // Use the animation width instead of _animationCoords.width() + height = _animation.rlf->height(); // Use the animation height instead of _animationCoords.height() + } else if (_fileType == AVI) { + // Cry because AVI seeking isn't implemented (yet) + } + + _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); +} + +bool LeverControl::enable() { + // TODO: Implement + return true; +} + +bool LeverControl::disable() { + // TODO: Implement + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 28079d52e7..d764f914bb 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -26,6 +26,7 @@ #include "common/types.h" #include "zvision/mouse_event.h" +#include "zvision/action_node.h" namespace Common { class SeekableReadStream; @@ -34,6 +35,8 @@ class SeekableReadStream; namespace ZVision { class ZVision; +class RlfAnimation; +class ZorkAVIDecoder; class Control { public: @@ -94,15 +97,98 @@ private: Common::String _hoverCursor; }; + +class LeverControl : public Control, public MouseEvent, public ActionNode { public: + LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); + ~LeverControl(); + +private: + enum FileType { + RLF = 1, + AVI = 2 + }; + + struct Direction { + Direction(uint angle, uint toFrame) : angle(angle), toFrame(toFrame) {} + + uint angle; + uint toFrame; + }; + + struct FrameInfo { + Common::Rect hotspot; + Common::List directions; + Common::List returnRoute; + }; + + enum { + ANGLE_DELTA = 30 // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA) + }; private: + ZVision *_engine; + + union { + RlfAnimation *rlf; + ZorkAVIDecoder *avi; + } _animation; + FileType _fileType; + + Common::String _cursorName; + Common::Rect _animationCoords; + bool _mirrored; + uint _frameCount; + uint _startFrame; + Common::Point _hotspotDelta; + FrameInfo *_frameInfo; + + uint _currentFrame; + bool _mouseIsCaptured; + bool _isReturning; + Common::Point _lastMousePos; + Common::List::iterator _returnRoutesCurrentProgress; + +public: + bool enable(); + bool disable(); + void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + bool process(uint32 deltaTimeInMillis); + +private: + void parseLevFile(const Common::String &fileName); + /** + * Calculates the angle a vector makes with the negative y-axis + * + * 90 + * pointTwo * ^ + * \ | + * \ | + * \ | + * \ | + * angle ( \|pointOne + * 180 <-----------*-----------> 0 + * | + * | + * | + * | + * | + * ^ + * 270 + * + * @param pointOne The origin of the vector + * @param pointTwo The end of the vector + * @return The angle the vector makes with the negative y-axis + */ + static int calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo); + void renderFrame(uint frameNumber); }; // TODO: Implement InputControl // TODO: Implement SaveControl // TODO: Implement SlotControl -// TODO: Implement LeverControl // TODO: Implement SafeControl // TODO: Implement FistControl // TODO: Implement HotMovieControl -- cgit v1.2.3 From af762dc41799bd08138a1f8fbcb7b441c4a03480 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 00:32:33 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/rlf_animation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 905a540924..c95a8640c1 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -159,11 +159,11 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { // Since this method is so expensive, first check to see if we can use // getNextFrame() or getPreviousFrame() since they are cheap. - if (frameNumber == _currentFrame) { + if ((int)frameNumber == _currentFrame) { return _currentFrameBuffer; - } else if (_currentFrame + 1 == frameNumber) { + } else if (_currentFrame + 1 == (int)frameNumber) { return getNextFrame(); - } else if (_currentFrame - 1 == frameNumber) { + } else if (_currentFrame - 1 == (int)frameNumber) { return getPreviousFrame(); } -- cgit v1.2.3 From 5ff032c27d5110ebd8b6f73e0c822eba2245246b Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 01:11:10 -0500 Subject: ZVISION: Cast completeFrame and frameNumber to int so their difference can go negative --- engines/zvision/rlf_animation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index c95a8640c1..ff855a1a39 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -168,9 +168,9 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { } uint closestFrame = _currentFrame; - uint distance = ABS(_currentFrame - frameNumber); + int distance = ABS(_currentFrame - (int)frameNumber); for (Common::List::const_iterator iter = _completeFrames.begin(); iter != _completeFrames.end(); iter++) { - uint newDistance = ABS((*iter) - frameNumber); + int newDistance = ABS((int)(*iter) - (int)frameNumber); if (closestFrame == -1 || newDistance < distance) { closestFrame = (*iter); distance = newDistance; -- cgit v1.2.3 From 9d8243245c8b7f21333a54479a9c5354686faa03 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 01:11:25 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/rlf_animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index ff855a1a39..6b6120fb63 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -193,7 +193,7 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { } const uint16 *RlfAnimation::getNextFrame() { - assert(_currentFrame + 1 < _frameCount); + assert(_currentFrame + 1 < (int)_frameCount); if (_stream) { applyFrameToCurrent(readNextFrame()); -- cgit v1.2.3 From ff97bb2eadcd26abb9a085f266e33b76594d2a21 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 24 Aug 2013 01:47:12 -0500 Subject: ZVISION: Move PushToggleControl and LeverControl to their own files --- engines/zvision/control.cpp | 401 +------------------------------- engines/zvision/control.h | 136 ----------- engines/zvision/lever_control.cpp | 349 +++++++++++++++++++++++++++ engines/zvision/lever_control.h | 130 +++++++++++ engines/zvision/module.mk | 2 + engines/zvision/push_toggle_control.cpp | 104 +++++++++ engines/zvision/push_toggle_control.h | 77 ++++++ engines/zvision/scr_file_handling.cpp | 1 + 8 files changed, 665 insertions(+), 535 deletions(-) create mode 100644 engines/zvision/lever_control.cpp create mode 100644 engines/zvision/lever_control.h create mode 100644 engines/zvision/push_toggle_control.cpp create mode 100644 engines/zvision/push_toggle_control.h (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index 9a1d52bd4f..1cef2a0ab8 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -23,24 +23,14 @@ #include "common/scummsys.h" #include "common/stream.h" -#include "common/system.h" -#include "common/tokenizer.h" +#include "zvision/control.h" #include "zvision/zvision.h" #include "zvision/render_manager.h" -#include "zvision/render_table.h" -#include "zvision/script_manager.h" -#include "zvision/cursor_manager.h" -#include "zvision/control.h" #include "zvision/utility.h" -#include "zvision/rlf_animation.h" -#include "zvision/zork_avi_decoder.h" -namespace ZVision { -////////////////////////////////////////////////////////////////////////////// -// Static member functions -////////////////////////////////////////////////////////////////////////////// +namespace ZVision { void Control::parseFlatControl(ZVision *engine) { engine->getRenderManager()->getRenderTable()->setRenderState(RenderTable::FLAT); @@ -112,391 +102,4 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre renderTable->generateRenderTable(); } - -////////////////////////////////////////////////////////////////////////////// -// PushToggleControl -////////////////////////////////////////////////////////////////////////////// - -PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) - : MouseEvent(key), - _engine(engine) { - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(&line); - - while (!stream.eos() && !line.contains('}')) { - if (line.matchString("*_hotspot*", true)) { - uint x; - uint y; - uint width; - uint height; - - sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); - - _hotspot = Common::Rect(x, y, x + width, y + height); - } else if (line.matchString("cursor*", true)) { - char nameBuffer[25]; - - sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); - - _hoverCursor = Common::String(nameBuffer); - } - - line = stream.readLine(); - trimCommentsAndWhiteSpace(&line); - } - - if (_hotspot.isEmpty() || _hoverCursor.empty()) { - warning("Push_toggle cursor %u was parsed incorrectly", key); - } -} - -bool PushToggleControl::enable() { - if (!_enabled) { - _engine->registerMouseEvent(this); - _enabled = true; - return true; - } - - debug("Control %u is already enabled", _key); - return false; -} - -bool PushToggleControl::disable() { - if (_enabled) { - _engine->removeMouseEvent(_key); - _enabled = false; - return true; - } - - debug("Control %u is already disabled", _key); - return false; -} - -void PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { - _engine->getScriptManager()->setStateValue(_key, 1); -} - -bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { - if (_hotspot.contains(backgroundImageSpacePos)) { - _engine->getCursorManager()->changeCursor(_hoverCursor); - return true; - } - - return false; -} - -////////////////////////////////////////////////////////////////////////////// -// LeverControl -////////////////////////////////////////////////////////////////////////////// - -LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) - : MouseEvent(key), - _engine(engine), - _frameInfo(0), - _frameCount(0), - _startFrame(0), - _currentFrame(0), - _mouseIsCaptured(false), - _isReturning(false) { - - // Loop until we find the closing brace - Common::String line = stream.readLine(); - trimCommentsAndWhiteSpace(&line); - - while (!stream.eos() && !line.contains('}')) { - if (line.matchString("*descfile*", true)) { - char levFileName[25]; - sscanf(line.c_str(), "%*[^(](%25[^)])", levFileName); - - parseLevFile(levFileName); - } else if (line.matchString("*cursor*", true)) { - char cursorName[25]; - sscanf(line.c_str(), "%*[^(](%25[^)])", cursorName); - - _cursorName = Common::String(cursorName); - } - - line = stream.readLine(); - trimCommentsAndWhiteSpace(&line); - } - - renderFrame(_currentFrame); - - _engine->getScriptManager()->addActionNode(this); -} - -LeverControl::~LeverControl() { - if (_fileType == AVI) { - delete _animation.avi; - } else if (_fileType == RLF) { - delete _animation.rlf; - } - if (_frameInfo != 0) { - delete[] _frameInfo; - } -} - -void LeverControl::parseLevFile(const Common::String &fileName) { - Common::File file; - if (!file.open(fileName)) { - warning("LEV file %s could could be opened", fileName.c_str()); - return; - } - - Common::String line = file.readLine(); - - while (!file.eos()) { - if (line.matchString("*animation_id*", true)) { - // Not used - } else if (line.matchString("*filename*", true)) { - char fileNameBuffer[25]; - sscanf(line.c_str(), "%*[^:]:%25[^~]~", fileNameBuffer); - - Common::String fileName(fileNameBuffer); - - if (fileName.hasSuffix(".avi")) { - _animation.avi = new ZorkAVIDecoder(); - _animation.avi->loadFile(fileName); - } else if (fileName.hasSuffix(".rlf")) { - _animation.rlf = new RlfAnimation(fileNameBuffer, false); - } - } else if (line.matchString("*skipcolor*", true)) { - // Not used - } else if (line.matchString("*anim_coords*", true)) { - sscanf(line.c_str(), "%*[^:]:%u %u %u %u~", &_animationCoords.left, &_animationCoords.top, &_animationCoords.right, &_animationCoords.bottom); - } else if (line.matchString("*mirrored*", true)) { - uint mirrored; - sscanf(line.c_str(), "%*[^:]:%u~", &mirrored); - - _mirrored = mirrored == 0 ? false : true; - } else if (line.matchString("*frames*", true)) { - sscanf(line.c_str(), "%*[^:]:%u~", &_frameCount); - - _frameInfo = new FrameInfo[_frameCount]; - } else if (line.matchString("*elsewhere*", true)) { - // Not used - } else if (line.matchString("*out_of_control*", true)) { - // Not used - } else if (line.matchString("*start_pos*", true)) { - sscanf(line.c_str(), "%*[^:]:%u~", &_startFrame); - _currentFrame = _startFrame; - } else if (line.matchString("*hotspot_deltas*", true)) { - uint x; - uint y; - sscanf(line.c_str(), "%*[^:]:%u %u~", &x, &y); - - _hotspotDelta.x = x; - _hotspotDelta.y = y; - } else { - uint frameNumber; - uint x, y; - - if (sscanf(line.c_str(), "%u:%u %u", &frameNumber, &x, &y) == 3) { - _frameInfo[frameNumber].hotspot.left = x; - _frameInfo[frameNumber].hotspot.top = y; - _frameInfo[frameNumber].hotspot.right = x + _hotspotDelta.x; - _frameInfo[frameNumber].hotspot.bottom = y + _hotspotDelta.y; - } - - Common::StringTokenizer tokenizer(line, " ^="); - tokenizer.nextToken(); - tokenizer.nextToken(); - - Common::String token = tokenizer.nextToken(); - while (!tokenizer.empty()) { - if (token == "D") { - token = tokenizer.nextToken(); - - uint angle; - uint toFrame; - sscanf(token.c_str(), "%u,%u", &toFrame, &angle); - - _frameInfo[frameNumber].directions.push_back(Direction(angle, toFrame)); - } else if (token.hasPrefix("P")) { - uint to; - sscanf(token.c_str(), "P(%*u to %u)", &to); - - _frameInfo[frameNumber].returnRoute.push_back(to); - } - - token = tokenizer.nextToken(); - } - } - - line = file.readLine(); - } -} - -void LeverControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { - if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { - _mouseIsCaptured = true; - _lastMousePos = backgroundImageSpacePos; - } -} - -void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { - _mouseIsCaptured = false; - _engine->getScriptManager()->setStateValue(_key, _currentFrame); - - if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { - - } - - // TODO: Animation reversal back to origin -} - -bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { - bool cursorWasChanged = false; - - if (_mouseIsCaptured) { - // Make sure the square distance between the last point and the current point is greater than 64 - // This is a heuristic. This determines how responsive the lever is to mouse movement. - // TODO: Fiddle with the heuristic to get a good lever responsiveness 'feel' - if (_lastMousePos.sqrDist(backgroundImageSpacePos) >= 64) { - int angle = calculateVectorAngle(_lastMousePos, backgroundImageSpacePos); - _lastMousePos = backgroundImageSpacePos; - - for (Common::List::iterator iter = _frameInfo[_currentFrame].directions.begin(); iter != _frameInfo[_currentFrame].directions.end(); iter++) { - if (angle >= (int)(*iter).angle - ANGLE_DELTA && angle <= (int)(*iter).angle) { - _currentFrame = (*iter).toFrame; - renderFrame(_currentFrame); - break; - } - } - } - } else if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { - _engine->getCursorManager()->changeCursor(_cursorName); - } - - return cursorWasChanged; -} - -bool LeverControl::process(uint32 deltaTimeInMillis) { - // TODO: Implement reversal over time - - return false; -} - -int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo) { - // Check for the easy angles first - if (pointOne.x == pointTwo.x && pointOne.y == pointTwo.y) - return -1; // This should never happen - else if (pointOne.x == pointTwo.x) { - if (pointTwo.y > pointOne.y) - return 90; - else - return 270; - } else if (pointOne.y == pointTwo.y) { - if (pointTwo.x > pointOne.x) - return 0; - else - return 180; - } else { - // Calculate the angle with trig - int16 xDist = pointTwo.x - pointOne.x; - int16 yDist = pointTwo.y - pointOne.y; - - int angle = int(atan((float)yDist / (float)xDist)); - - // Convert to degrees. (180 / 3.14159 = 57.2958) - angle *= 57; - - // Calculate what quadrant pointTwo is in - uint quadrant = ((yDist > 0 ? 1 : 0) << 1) | (xDist < 0 ? 1 : 0); - - // Explanation of quadrants: - // - // yDist > 0 | xDist < 0 | Quadrant number - // 0 | 0 | 0 - // 0 | 1 | 1 - // 1 | 0 | 2 - // 1 | 1 | 3 - // - // Note: I know this doesn't line up with traditional mathematical quadrants - // but doing it this way allows you can use a switch and is a bit cleaner IMO. - // - // The graph below shows the 4 quadrants pointTwo can end up in as well - // as what the angle as calculated above refers to. - // Note: The calculated angle in quadrants 0 and 3 is negative - // due to arctan(-x) = -theta - // - // Origin => (pointOne.x, pointOne.y) - // * => (pointTwo.x, pointTwo.y) - // - // 90 - // ^ - // * | * - // \ | / - // \ | / - // \ | / - // Quadrant 3 \ | / Quadrant 2 - // \ | / - // \ | / - // -angle ( \|/ ) angle - // 180 <----------------------------------------> 0 - // angle ( /|\ ) -angle - // / | \ - // / | \ - // Quadrant 1 / | \ Quadrant 0 - // / | \ - // / | \ - // / | \ - // * | * - // ^ - // 270 - - // Convert the local angles to unit circle angles - switch (quadrant) { - case 0: - angle = 360 + angle; - break; - case 1: - angle = 180 + angle; - break; - case 2: - angle = 180 + angle; - break; - case 3: - // Do nothing - break; - } - - return angle; - } -} - -void LeverControl::renderFrame(uint frameNumber) { - const uint16 *frameData; - int pitch; - int x; - int y; - int width; - int height; - - if (_fileType == RLF) { - // getFrameData() will automatically optimize to getNextFrame() / getPreviousFrame() if it can - frameData = _animation.rlf->getFrameData(_currentFrame); - pitch = _animation.rlf->width() * sizeof(uint16); - x = _animationCoords.left; - y = _animationCoords.right; - width = _animation.rlf->width(); // Use the animation width instead of _animationCoords.width() - height = _animation.rlf->height(); // Use the animation height instead of _animationCoords.height() - } else if (_fileType == AVI) { - // Cry because AVI seeking isn't implemented (yet) - } - - _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); -} - -bool LeverControl::enable() { - // TODO: Implement - return true; -} - -bool LeverControl::disable() { - // TODO: Implement - return true; -} - } // End of namespace ZVision diff --git a/engines/zvision/control.h b/engines/zvision/control.h index d764f914bb..616589f055 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -25,9 +25,6 @@ #include "common/types.h" -#include "zvision/mouse_event.h" -#include "zvision/action_node.h" - namespace Common { class SeekableReadStream; } @@ -35,8 +32,6 @@ class SeekableReadStream; namespace ZVision { class ZVision; -class RlfAnimation; -class ZorkAVIDecoder; class Control { public: @@ -55,137 +50,6 @@ public: static void parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream); }; - -class PushToggleControl : public Control, public MouseEvent { -public: - PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); - bool enable(); - bool disable(); - - /** - * Called when LeftMouse is pushed. Calls ScriptManager::setStateValue(_key, 1); - * - * @param screenSpacePos The position of the mouse in screen space - * @param backgroundImageSpacePos The position of the mouse in background image space - */ - void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - /** - * Called when LeftMouse is lifted. Does nothing - * - * @param screenSpacePos The position of the mouse in screen space - * @param backgroundImageSpacePos The position of the mouse in background image space - */ - void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {} - /** - * Called on every MouseMove. Tests if the mouse is inside _hotspot, and if so, sets the cursor. - * - * @param engine The base engine - * @param screenSpacePos The position of the mouse in screen space - * @param backgroundImageSpacePos The position of the mouse in background image space - * @return Was the cursor changed? - */ - bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - -private: - ZVision * _engine; - /** - * The area that will trigger the event - * This is in image space coordinates, NOT screen space - */ - Common::Rect _hotspot; - /** The cursor to use when hovering over _hotspot */ - Common::String _hoverCursor; -}; - - -class LeverControl : public Control, public MouseEvent, public ActionNode { -public: - LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); - ~LeverControl(); - -private: - enum FileType { - RLF = 1, - AVI = 2 - }; - - struct Direction { - Direction(uint angle, uint toFrame) : angle(angle), toFrame(toFrame) {} - - uint angle; - uint toFrame; - }; - - struct FrameInfo { - Common::Rect hotspot; - Common::List directions; - Common::List returnRoute; - }; - - enum { - ANGLE_DELTA = 30 // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA) - }; - -private: - ZVision *_engine; - - union { - RlfAnimation *rlf; - ZorkAVIDecoder *avi; - } _animation; - FileType _fileType; - - Common::String _cursorName; - Common::Rect _animationCoords; - bool _mirrored; - uint _frameCount; - uint _startFrame; - Common::Point _hotspotDelta; - FrameInfo *_frameInfo; - - uint _currentFrame; - bool _mouseIsCaptured; - bool _isReturning; - Common::Point _lastMousePos; - Common::List::iterator _returnRoutesCurrentProgress; - -public: - bool enable(); - bool disable(); - void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - bool process(uint32 deltaTimeInMillis); - -private: - void parseLevFile(const Common::String &fileName); - /** - * Calculates the angle a vector makes with the negative y-axis - * - * 90 - * pointTwo * ^ - * \ | - * \ | - * \ | - * \ | - * angle ( \|pointOne - * 180 <-----------*-----------> 0 - * | - * | - * | - * | - * | - * ^ - * 270 - * - * @param pointOne The origin of the vector - * @param pointTwo The end of the vector - * @return The angle the vector makes with the negative y-axis - */ - static int calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo); - void renderFrame(uint frameNumber); -}; - // TODO: Implement InputControl // TODO: Implement SaveControl // TODO: Implement SlotControl diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp new file mode 100644 index 0000000000..34877cd23f --- /dev/null +++ b/engines/zvision/lever_control.cpp @@ -0,0 +1,349 @@ +/* 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/scummsys.h" + +#include "common/stream.h" +#include "common/file.h" +#include "common/tokenizer.h" +#include "common/system.h" + +#include "zvision/lever_control.h" +#include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/cursor_manager.h" +#include "zvision/rlf_animation.h" +#include "zvision/zork_avi_decoder.h" +#include "zvision/utility.h" + +namespace ZVision { + +LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) + : MouseEvent(key), + _engine(engine), + _frameInfo(0), + _frameCount(0), + _startFrame(0), + _currentFrame(0), + _mouseIsCaptured(false), + _isReturning(false) { + + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + while (!stream.eos() && !line.contains('}')) { + if (line.matchString("*descfile*", true)) { + char levFileName[25]; + sscanf(line.c_str(), "%*[^(](%25[^)])", levFileName); + + parseLevFile(levFileName); + } else if (line.matchString("*cursor*", true)) { + char cursorName[25]; + sscanf(line.c_str(), "%*[^(](%25[^)])", cursorName); + + _cursorName = Common::String(cursorName); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + } + + renderFrame(_currentFrame); + + _engine->getScriptManager()->addActionNode(this); +} + +LeverControl::~LeverControl() { + if (_fileType == AVI) { + delete _animation.avi; + } else if (_fileType == RLF) { + delete _animation.rlf; + } + if (_frameInfo != 0) { + delete[] _frameInfo; + } +} + +void LeverControl::parseLevFile(const Common::String &fileName) { + Common::File file; + if (!file.open(fileName)) { + warning("LEV file %s could could be opened", fileName.c_str()); + return; + } + + Common::String line = file.readLine(); + + while (!file.eos()) { + if (line.matchString("*animation_id*", true)) { + // Not used + } else if (line.matchString("*filename*", true)) { + char fileNameBuffer[25]; + sscanf(line.c_str(), "%*[^:]:%25[^~]~", fileNameBuffer); + + Common::String fileName(fileNameBuffer); + + if (fileName.hasSuffix(".avi")) { + _animation.avi = new ZorkAVIDecoder(); + _animation.avi->loadFile(fileName); + } else if (fileName.hasSuffix(".rlf")) { + _animation.rlf = new RlfAnimation(fileNameBuffer, false); + } + } else if (line.matchString("*skipcolor*", true)) { + // Not used + } else if (line.matchString("*anim_coords*", true)) { + sscanf(line.c_str(), "%*[^:]:%u %u %u %u~", &_animationCoords.left, &_animationCoords.top, &_animationCoords.right, &_animationCoords.bottom); + } else if (line.matchString("*mirrored*", true)) { + uint mirrored; + sscanf(line.c_str(), "%*[^:]:%u~", &mirrored); + + _mirrored = mirrored == 0 ? false : true; + } else if (line.matchString("*frames*", true)) { + sscanf(line.c_str(), "%*[^:]:%u~", &_frameCount); + + _frameInfo = new FrameInfo[_frameCount]; + } else if (line.matchString("*elsewhere*", true)) { + // Not used + } else if (line.matchString("*out_of_control*", true)) { + // Not used + } else if (line.matchString("*start_pos*", true)) { + sscanf(line.c_str(), "%*[^:]:%u~", &_startFrame); + _currentFrame = _startFrame; + } else if (line.matchString("*hotspot_deltas*", true)) { + uint x; + uint y; + sscanf(line.c_str(), "%*[^:]:%u %u~", &x, &y); + + _hotspotDelta.x = x; + _hotspotDelta.y = y; + } else { + uint frameNumber; + uint x, y; + + if (sscanf(line.c_str(), "%u:%u %u", &frameNumber, &x, &y) == 3) { + _frameInfo[frameNumber].hotspot.left = x; + _frameInfo[frameNumber].hotspot.top = y; + _frameInfo[frameNumber].hotspot.right = x + _hotspotDelta.x; + _frameInfo[frameNumber].hotspot.bottom = y + _hotspotDelta.y; + } + + Common::StringTokenizer tokenizer(line, " ^="); + tokenizer.nextToken(); + tokenizer.nextToken(); + + Common::String token = tokenizer.nextToken(); + while (!tokenizer.empty()) { + if (token == "D") { + token = tokenizer.nextToken(); + + uint angle; + uint toFrame; + sscanf(token.c_str(), "%u,%u", &toFrame, &angle); + + _frameInfo[frameNumber].directions.push_back(Direction(angle, toFrame)); + } else if (token.hasPrefix("P")) { + uint to; + sscanf(token.c_str(), "P(%*u to %u)", &to); + + _frameInfo[frameNumber].returnRoute.push_back(to); + } + + token = tokenizer.nextToken(); + } + } + + line = file.readLine(); + } +} + +void LeverControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { + _mouseIsCaptured = true; + _lastMousePos = backgroundImageSpacePos; + } +} + +void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + _mouseIsCaptured = false; + _engine->getScriptManager()->setStateValue(_key, _currentFrame); + + if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { + + } + + // TODO: Animation reversal back to origin +} + +bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + bool cursorWasChanged = false; + + if (_mouseIsCaptured) { + // Make sure the square distance between the last point and the current point is greater than 64 + // This is a heuristic. This determines how responsive the lever is to mouse movement. + // TODO: Fiddle with the heuristic to get a good lever responsiveness 'feel' + if (_lastMousePos.sqrDist(backgroundImageSpacePos) >= 64) { + int angle = calculateVectorAngle(_lastMousePos, backgroundImageSpacePos); + _lastMousePos = backgroundImageSpacePos; + + for (Common::List::iterator iter = _frameInfo[_currentFrame].directions.begin(); iter != _frameInfo[_currentFrame].directions.end(); iter++) { + if (angle >= (int)(*iter).angle - ANGLE_DELTA && angle <= (int)(*iter).angle) { + _currentFrame = (*iter).toFrame; + renderFrame(_currentFrame); + break; + } + } + } + } else if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { + _engine->getCursorManager()->changeCursor(_cursorName); + } + + return cursorWasChanged; +} + +bool LeverControl::process(uint32 deltaTimeInMillis) { + // TODO: Implement reversal over time + + return false; +} + +int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo) { + // Check for the easy angles first + if (pointOne.x == pointTwo.x && pointOne.y == pointTwo.y) + return -1; // This should never happen + else if (pointOne.x == pointTwo.x) { + if (pointTwo.y > pointOne.y) + return 90; + else + return 270; + } else if (pointOne.y == pointTwo.y) { + if (pointTwo.x > pointOne.x) + return 0; + else + return 180; + } else { + // Calculate the angle with trig + int16 xDist = pointTwo.x - pointOne.x; + int16 yDist = pointTwo.y - pointOne.y; + + int angle = int(atan((float)yDist / (float)xDist)); + + // Convert to degrees. (180 / 3.14159 = 57.2958) + angle *= 57; + + // Calculate what quadrant pointTwo is in + uint quadrant = ((yDist > 0 ? 1 : 0) << 1) | (xDist < 0 ? 1 : 0); + + // Explanation of quadrants: + // + // yDist > 0 | xDist < 0 | Quadrant number + // 0 | 0 | 0 + // 0 | 1 | 1 + // 1 | 0 | 2 + // 1 | 1 | 3 + // + // Note: I know this doesn't line up with traditional mathematical quadrants + // but doing it this way allows you can use a switch and is a bit cleaner IMO. + // + // The graph below shows the 4 quadrants pointTwo can end up in as well + // as what the angle as calculated above refers to. + // Note: The calculated angle in quadrants 0 and 3 is negative + // due to arctan(-x) = -theta + // + // Origin => (pointOne.x, pointOne.y) + // * => (pointTwo.x, pointTwo.y) + // + // 90 + // ^ + // * | * + // \ | / + // \ | / + // \ | / + // Quadrant 3 \ | / Quadrant 2 + // \ | / + // \ | / + // -angle ( \|/ ) angle + // 180 <----------------------------------------> 0 + // angle ( /|\ ) -angle + // / | \ + // / | \ + // Quadrant 1 / | \ Quadrant 0 + // / | \ + // / | \ + // / | \ + // * | * + // ^ + // 270 + + // Convert the local angles to unit circle angles + switch (quadrant) { + case 0: + angle = 360 + angle; + break; + case 1: + angle = 180 + angle; + break; + case 2: + angle = 180 + angle; + break; + case 3: + // Do nothing + break; + } + + return angle; + } +} + +void LeverControl::renderFrame(uint frameNumber) { + const uint16 *frameData; + int pitch; + int x; + int y; + int width; + int height; + + if (_fileType == RLF) { + // getFrameData() will automatically optimize to getNextFrame() / getPreviousFrame() if it can + frameData = _animation.rlf->getFrameData(_currentFrame); + pitch = _animation.rlf->width() * sizeof(uint16); + x = _animationCoords.left; + y = _animationCoords.right; + width = _animation.rlf->width(); // Use the animation width instead of _animationCoords.width() + height = _animation.rlf->height(); // Use the animation height instead of _animationCoords.height() + } else if (_fileType == AVI) { + // Cry because AVI seeking isn't implemented (yet) + } + + _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); +} + +bool LeverControl::enable() { + // TODO: Implement + return true; +} + +bool LeverControl::disable() { + // TODO: Implement + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h new file mode 100644 index 0000000000..dbfd172c45 --- /dev/null +++ b/engines/zvision/lever_control.h @@ -0,0 +1,130 @@ +/* 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 ZVISION_PUSH_TOGGLE_CONTROL_H +#define ZVISION_PUSH_TOGGLE_CONTROL_H + +#include "common/types.h" + +#include "common/list.h" + +#include "zvision/control.h" +#include "zvision/mouse_event.h" +#include "zvision/action_node.h" + + +namespace ZVision { + +class ZorkAVIDecoder; +class RlfAnimation; + +class LeverControl : public Control, public MouseEvent, public ActionNode { +public: + LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); + ~LeverControl(); + +private: + enum FileType { + RLF = 1, + AVI = 2 + }; + + struct Direction { + Direction(uint angle, uint toFrame) : angle(angle), toFrame(toFrame) {} + + uint angle; + uint toFrame; + }; + + struct FrameInfo { + Common::Rect hotspot; + Common::List directions; + Common::List returnRoute; + }; + + enum { + ANGLE_DELTA = 30 // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA) + }; + +private: + ZVision *_engine; + + union { + RlfAnimation *rlf; + ZorkAVIDecoder *avi; + } _animation; + FileType _fileType; + + Common::String _cursorName; + Common::Rect _animationCoords; + bool _mirrored; + uint _frameCount; + uint _startFrame; + Common::Point _hotspotDelta; + FrameInfo *_frameInfo; + + uint _currentFrame; + bool _mouseIsCaptured; + bool _isReturning; + Common::Point _lastMousePos; + Common::List::iterator _returnRoutesCurrentProgress; + +public: + bool enable(); + bool disable(); + void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + bool process(uint32 deltaTimeInMillis); + +private: + void parseLevFile(const Common::String &fileName); + /** + * Calculates the angle a vector makes with the negative y-axis + * + * 90 + * pointTwo * ^ + * \ | + * \ | + * \ | + * \ | + * angle ( \|pointOne + * 180 <-----------*-----------> 0 + * | + * | + * | + * | + * | + * ^ + * 270 + * + * @param pointOne The origin of the vector + * @param pointTwo The end of the vector + * @return The angle the vector makes with the negative y-axis + */ + static int calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo); + void renderFrame(uint frameNumber); +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index a4b7c68cde..7412ad8916 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -11,7 +11,9 @@ MODULE_OBJS := \ cursor_manager.o \ detection.o \ events.o \ + lever_control.o \ lzss_read_stream.o \ + push_toggle_control.o \ render_manager.o \ render_table.o \ rlf_animation.o \ diff --git a/engines/zvision/push_toggle_control.cpp b/engines/zvision/push_toggle_control.cpp new file mode 100644 index 0000000000..9e68bdb8be --- /dev/null +++ b/engines/zvision/push_toggle_control.cpp @@ -0,0 +1,104 @@ +/* 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/scummsys.h" + +#include "common/stream.h" + +#include "zvision/push_toggle_control.h" +#include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/cursor_manager.h" +#include "zvision/utility.h" + +namespace ZVision { + +PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) + : MouseEvent(key), + _engine(engine) { + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + while (!stream.eos() && !line.contains('}')) { + if (line.matchString("*_hotspot*", true)) { + uint x; + uint y; + uint width; + uint height; + + sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); + + _hotspot = Common::Rect(x, y, x + width, y + height); + } else if (line.matchString("cursor*", true)) { + char nameBuffer[25]; + + sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); + + _hoverCursor = Common::String(nameBuffer); + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + } + + if (_hotspot.isEmpty() || _hoverCursor.empty()) { + warning("Push_toggle cursor %u was parsed incorrectly", key); + } +} + + bool PushToggleControl::enable() { + if (!_enabled) { + _engine->registerMouseEvent(this); + _enabled = true; + return true; + } + + debug("Control %u is already enabled", _key); + return false; + } + + bool PushToggleControl::disable() { + if (_enabled) { + _engine->removeMouseEvent(_key); + _enabled = false; + return true; + } + + debug("Control %u is already disabled", _key); + return false; + } + + void PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + _engine->getScriptManager()->setStateValue(_key, 1); + } + + bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { + if (_hotspot.contains(backgroundImageSpacePos)) { + _engine->getCursorManager()->changeCursor(_hoverCursor); + return true; + } + + return false; + } + +} // End of namespace ZVision diff --git a/engines/zvision/push_toggle_control.h b/engines/zvision/push_toggle_control.h new file mode 100644 index 0000000000..9384a43d93 --- /dev/null +++ b/engines/zvision/push_toggle_control.h @@ -0,0 +1,77 @@ +/* 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 ZVISION_PUSH_TOGGLE_CONTROL_H +#define ZVISION_PUSH_TOGGLE_CONTROL_H + +#include "common/types.h" + +#include "zvision/control.h" +#include "zvision/mouse_event.h" + + +namespace ZVision { + +class PushToggleControl : public Control, public MouseEvent { +public: + PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); + bool enable(); + bool disable(); + + /** + * Called when LeftMouse is pushed. Calls ScriptManager::setStateValue(_key, 1); + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + /** + * Called when LeftMouse is lifted. Does nothing + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {} + /** + * Called on every MouseMove. Tests if the mouse is inside _hotspot, and if so, sets the cursor. + * + * @param engine The base engine + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + * @return Was the cursor changed? + */ + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + +private: + ZVision * _engine; + /** + * The area that will trigger the event + * This is in image space coordinates, NOT screen space + */ + Common::Rect _hotspot; + /** The cursor to use when hovering over _hotspot */ + Common::String _hoverCursor; +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 921c1d5b44..c4aed70ac5 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -26,6 +26,7 @@ #include "zvision/utility.h" #include "zvision/puzzle.h" #include "zvision/actions.h" +#include "zvision/push_toggle_control.h" #include "common/textconsole.h" #include "common/file.h" -- cgit v1.2.3 From 5e1215837ae29899dbb759a55b3de10b3dc0bee8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 13:58:51 -0500 Subject: ZVISION: Fixed signed/unsigned mismatch --- engines/zvision/render_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index ac02cc24d6..fa45a6f576 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -66,7 +66,7 @@ void RenderManager::update(uint deltaTimeInMillis) { if (_backgroundInverseVelocity != 0) { _accumulatedVelocityMilliseconds += deltaTimeInMillis; - int absVelocity = abs(_backgroundInverseVelocity); + uint absVelocity = uint(abs(_backgroundInverseVelocity)); int numberOfSteps = 0; while (_accumulatedVelocityMilliseconds >= absVelocity) { -- cgit v1.2.3 From 52af1f7f1019ddb2f95d1cff034d58f3cffd224a Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:03:25 -0500 Subject: ZVISION: Bake ActionNode and MouseEvent into Control This makes memory management a lot easier as well as removes the need for multiple lists that point to the same objects. However, there will be quite a few Controls that don't need all the functionality of ActionNode and MouseEvent, so the default implementations are No Op. --- engines/zvision/action_node.h | 11 ------- engines/zvision/control.h | 39 +++++++++++++++++++++++- engines/zvision/mouse_event.h | 71 ------------------------------------------- 3 files changed, 38 insertions(+), 83 deletions(-) delete mode 100644 engines/zvision/mouse_event.h (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h index 9a5ca0be0b..9df06c750f 100644 --- a/engines/zvision/action_node.h +++ b/engines/zvision/action_node.h @@ -29,17 +29,6 @@ namespace ZVision { class ZVision; -class ActionNode { -public: - virtual ~ActionNode() {} - /** - * Processes the node given the deltaTime since last frame - * - * @param deltaTimeInMillis The number of milliseconds that have passed since last frame - * @return If true, the node can be deleted after process() finishes - */ - virtual bool process(uint32 deltaTimeInMillis) = 0; -}; class TimerNode : public ActionNode { public: diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 616589f055..8d4ea9f65d 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -25,8 +25,10 @@ #include "common/types.h" + namespace Common { class SeekableReadStream; +struct Point; } namespace ZVision { @@ -35,12 +37,47 @@ class ZVision; class Control { public: - Control() : _enabled(false) {} + Control() : _engine(0), _key(0), _enabled(false) {} + Control(ZVision *engine, uint32 key) : _engine(engine), _key(key), _enabled(false) {} virtual ~Control() {} virtual bool enable() = 0; virtual bool disable() = 0; + uint32 getKey() { return _key; } + + /** + * Called when LeftMouse is pushed. Default is NOP. + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + virtual void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {} + /** + * Called when LeftMouse is lifted. Default is NOP. + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + virtual void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {} + /** + * Called on every MouseMove. Default is NOP. + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + * @return Was the cursor changed? + */ + virtual bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { return false; } + /** + * Processes the node given the deltaTime since last frame. Default is NOP. + * + * @param deltaTimeInMillis The number of milliseconds that have passed since last frame + * @return If true, the node can be deleted after process() finishes + */ + virtual bool process(uint32 deltaTimeInMillis) { return false; } + protected: + ZVision * _engine; + uint32 _key; bool _enabled; // Static member functions diff --git a/engines/zvision/mouse_event.h b/engines/zvision/mouse_event.h deleted file mode 100644 index fe81adaf19..0000000000 --- a/engines/zvision/mouse_event.h +++ /dev/null @@ -1,71 +0,0 @@ -/* 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 ZVISION_MOUSE_EVENT_H -#define ZVISION_MOUSE_EVENT_H - -#include "common/types.h" -#include "common/rect.h" -#include "common/str.h" - -namespace ZVision { - -class ZVision; - -class MouseEvent { -public: - MouseEvent() : _key(0) {} - MouseEvent(uint32 key) : _key(key) {} - virtual ~MouseEvent() {} - -public: - uint32 _key; - -public: - /** - * Called when LeftMouse is pushed. - * - * @param screenSpacePos The position of the mouse in screen space - * @param backgroundImageSpacePos The position of the mouse in background image space - */ - virtual void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) = 0; - /** - * Called when LeftMouse is lifted. - * - * @param screenSpacePos The position of the mouse in screen space - * @param backgroundImageSpacePos The position of the mouse in background image space - */ - virtual void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) = 0; - /** - * Called on every MouseMove. - * - * @param screenSpacePos The position of the mouse in screen space - * @param backgroundImageSpacePos The position of the mouse in background image space - * @return Was the cursor changed? - */ - virtual bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) = 0; -}; - -} // End of namespace ZVision - -#endif -- cgit v1.2.3 From 93bc3570ea33e3f5d21d5b14fe081800f9c7e700 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:04:21 -0500 Subject: ZVISION: Create the default implementation for Control::enable()/disable() --- engines/zvision/control.cpp | 18 ++++++++++++++++++ engines/zvision/control.h | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index 1cef2a0ab8..ad0a4c5013 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -32,6 +32,24 @@ namespace ZVision { +void Control::enable() { + if (!_enabled) { + _enabled = true; + return; + } + + debug("Control %u is already enabled", _key); +} + +void Control::disable() { + if (_enabled) { + _enabled = false; + return; + } + + debug("Control %u is already disabled", _key); +} + void Control::parseFlatControl(ZVision *engine) { engine->getRenderManager()->getRenderTable()->setRenderState(RenderTable::FLAT); } diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 8d4ea9f65d..b16ca7f73d 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -40,11 +40,11 @@ public: Control() : _engine(0), _key(0), _enabled(false) {} Control(ZVision *engine, uint32 key) : _engine(engine), _key(key), _enabled(false) {} virtual ~Control() {} - virtual bool enable() = 0; - virtual bool disable() = 0; uint32 getKey() { return _key; } + virtual void enable(); + virtual void disable(); /** * Called when LeftMouse is pushed. Default is NOP. * -- cgit v1.2.3 From 3263ab7390fe2197983f28012cfc7199cd3ec500 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:05:01 -0500 Subject: ZVISION: Modify TimerNode to use Control base class --- engines/zvision/action_node.cpp | 2 +- engines/zvision/action_node.h | 8 ++++---- engines/zvision/actions.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.cpp b/engines/zvision/action_node.cpp index f51801a75d..8e354606f8 100644 --- a/engines/zvision/action_node.cpp +++ b/engines/zvision/action_node.cpp @@ -29,7 +29,7 @@ namespace ZVision { TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds) - : _engine(engine), _key(key), _timeLeft(timeInSeconds * 1000) { + : Control(engine, key), _timeLeft(timeInSeconds * 1000) { } bool TimerNode::process(uint32 deltaTimeInMillis) { diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h index 9df06c750f..b0b8cae4b1 100644 --- a/engines/zvision/action_node.h +++ b/engines/zvision/action_node.h @@ -25,14 +25,16 @@ #include "common/types.h" +#include "zvision/control.h" + namespace ZVision { class ZVision; - -class TimerNode : public ActionNode { +class TimerNode : public Control { public: TimerNode(ZVision *engine, uint32 key, uint timeInSeconds); + /** * Decrement the timer by the delta time. If the timer is finished, set the status * in _globalState and let this node be deleted @@ -43,8 +45,6 @@ public: bool process(uint32 deltaTimeInMillis); private: - ZVision *_engine; - uint32 _key; uint32 _timeLeft; }; diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index baa89aa165..d039f04d95 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -354,7 +354,7 @@ ActionTimer::ActionTimer(const Common::String &line) { } bool ActionTimer::execute(ZVision *engine) { - engine->getScriptManager()->addActionNode(new TimerNode(engine, _key, _time)); + engine->getScriptManager()->addControl(new TimerNode(engine, _key, _time)); return true; } -- cgit v1.2.3 From 4d344cb5a8eb2f0b66262deb9b1ff6b9112e64d8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:06:46 -0500 Subject: ZVISION: Change LeverControl to comply with the new Control base class --- engines/zvision/lever_control.cpp | 21 ++++----------------- engines/zvision/lever_control.h | 15 +++++---------- 2 files changed, 9 insertions(+), 27 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 34877cd23f..5d9ea4db36 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -38,8 +38,7 @@ namespace ZVision { LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) - : MouseEvent(key), - _engine(engine), + : Control(engine, key), _frameInfo(0), _frameCount(0), _startFrame(0), @@ -69,8 +68,6 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre } renderFrame(_currentFrame); - - _engine->getScriptManager()->addActionNode(this); } LeverControl::~LeverControl() { @@ -175,14 +172,14 @@ void LeverControl::parseLevFile(const Common::String &fileName) { } } -void LeverControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { +void LeverControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { _mouseIsCaptured = true; _lastMousePos = backgroundImageSpacePos; } } -void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { +void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { _mouseIsCaptured = false; _engine->getScriptManager()->setStateValue(_key, _currentFrame); @@ -193,7 +190,7 @@ void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common:: // TODO: Animation reversal back to origin } -bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { +bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { bool cursorWasChanged = false; if (_mouseIsCaptured) { @@ -336,14 +333,4 @@ void LeverControl::renderFrame(uint frameNumber) { _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); } -bool LeverControl::enable() { - // TODO: Implement - return true; -} - -bool LeverControl::disable() { - // TODO: Implement - return true; -} - } // End of namespace ZVision diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h index dbfd172c45..42577a1776 100644 --- a/engines/zvision/lever_control.h +++ b/engines/zvision/lever_control.h @@ -26,10 +26,9 @@ #include "common/types.h" #include "common/list.h" +#include "common/rect.h" #include "zvision/control.h" -#include "zvision/mouse_event.h" -#include "zvision/action_node.h" namespace ZVision { @@ -37,7 +36,7 @@ namespace ZVision { class ZorkAVIDecoder; class RlfAnimation; -class LeverControl : public Control, public MouseEvent, public ActionNode { +class LeverControl : public Control { public: LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); ~LeverControl(); @@ -66,8 +65,6 @@ private: }; private: - ZVision *_engine; - union { RlfAnimation *rlf; ZorkAVIDecoder *avi; @@ -89,11 +86,9 @@ private: Common::List::iterator _returnRoutesCurrentProgress; public: - bool enable(); - bool disable(); - void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); bool process(uint32 deltaTimeInMillis); private: -- cgit v1.2.3 From 7fb024c7fccb58442440f06af1bbd32b95122d72 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:07:47 -0500 Subject: ZVISION: Change PushToggleControl to comply with new Control base class --- engines/zvision/push_toggle_control.cpp | 46 +++++++++++---------------------- engines/zvision/push_toggle_control.h | 22 +++++----------- engines/zvision/scr_file_handling.cpp | 2 +- 3 files changed, 23 insertions(+), 47 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/push_toggle_control.cpp b/engines/zvision/push_toggle_control.cpp index 9e68bdb8be..be038e767a 100644 --- a/engines/zvision/push_toggle_control.cpp +++ b/engines/zvision/push_toggle_control.cpp @@ -33,8 +33,7 @@ namespace ZVision { PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) - : MouseEvent(key), - _engine(engine) { + : Control(engine, key) { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -66,39 +65,24 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab } } - bool PushToggleControl::enable() { - if (!_enabled) { - _engine->registerMouseEvent(this); - _enabled = true; - return true; - } - - debug("Control %u is already enabled", _key); - return false; - } - - bool PushToggleControl::disable() { - if (_enabled) { - _engine->removeMouseEvent(_key); - _enabled = false; - return true; - } - - debug("Control %u is already disabled", _key); - return false; - } +PushToggleControl::~PushToggleControl() { + // Clear the state value back to 0 + _engine->getScriptManager()->setStateValue(_key, 0); +} - void PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { +void PushToggleControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (_hotspot.contains(backgroundImageSpacePos)) { _engine->getScriptManager()->setStateValue(_key, 1); } +} - bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) { - if (_hotspot.contains(backgroundImageSpacePos)) { - _engine->getCursorManager()->changeCursor(_hoverCursor); - return true; - } - - return false; +bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (_hotspot.contains(backgroundImageSpacePos)) { + _engine->getCursorManager()->changeCursor(_hoverCursor); + return true; } + return false; +} + } // End of namespace ZVision diff --git a/engines/zvision/push_toggle_control.h b/engines/zvision/push_toggle_control.h index 9384a43d93..8ab6f619bb 100644 --- a/engines/zvision/push_toggle_control.h +++ b/engines/zvision/push_toggle_control.h @@ -25,32 +25,25 @@ #include "common/types.h" +#include "common/rect.h" + #include "zvision/control.h" -#include "zvision/mouse_event.h" namespace ZVision { -class PushToggleControl : public Control, public MouseEvent { +class PushToggleControl : public Control { public: PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); - bool enable(); - bool disable(); + ~PushToggleControl(); /** - * Called when LeftMouse is pushed. Calls ScriptManager::setStateValue(_key, 1); - * - * @param screenSpacePos The position of the mouse in screen space - * @param backgroundImageSpacePos The position of the mouse in background image space - */ - void onMouseDown(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); - /** - * Called when LeftMouse is lifted. Does nothing + * Called when LeftMouse is lifted. Calls ScriptManager::setStateValue(_key, 1); * * @param screenSpacePos The position of the mouse in screen space * @param backgroundImageSpacePos The position of the mouse in background image space */ - void onMouseUp(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos) {} + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); /** * Called on every MouseMove. Tests if the mouse is inside _hotspot, and if so, sets the cursor. * @@ -59,10 +52,9 @@ public: * @param backgroundImageSpacePos The position of the mouse in background image space * @return Was the cursor changed? */ - bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point backgroundImageSpacePos); + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); private: - ZVision * _engine; /** * The area that will trigger the event * This is in image space coordinates, NOT screen space diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index c4aed70ac5..212d7140b0 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -279,7 +279,7 @@ void ScriptManager::parseControl(Common::String &line, Common::SeekableReadStrea Common::String controlType(controlTypeBuffer); if (controlType.equalsIgnoreCase("push_toggle")) { - _activeControls[key] = new PushToggleControl(_engine, key, stream); + _activeControls.push_back(new PushToggleControl(_engine, key, stream)); return; } else if (controlType.equalsIgnoreCase("flat")) { Control::parseFlatControl(_engine); -- cgit v1.2.3 From e32f6f7e38a8fde2283dcefa2042056778cb4579 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:08:09 -0500 Subject: ZVISION: Remove extraneous semicolon --- engines/zvision/rlf_animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 6b6120fb63..f58aa0cdfe 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -65,7 +65,7 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) _frames[i] = readNextFrame(); } } -}; +} RlfAnimation::~RlfAnimation() { if (_frames != 0) { -- cgit v1.2.3 From a1d11054b52822e3d85e0ad88e6d2ebbbeca8518 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:08:31 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/rlf_animation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index f58aa0cdfe..77c1a50266 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -155,7 +155,7 @@ RlfAnimation::Frame RlfAnimation::readNextFrame() { const uint16 *RlfAnimation::getFrameData(uint frameNumber) { assert(!_stream); - assert(frameNumber < _frameCount && frameNumber >= 0); + assert(frameNumber < _frameCount); // Since this method is so expensive, first check to see if we can use // getNextFrame() or getPreviousFrame() since they are cheap. @@ -167,7 +167,7 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { return getPreviousFrame(); } - uint closestFrame = _currentFrame; + int closestFrame = _currentFrame; int distance = ABS(_currentFrame - (int)frameNumber); for (Common::List::const_iterator iter = _completeFrames.begin(); iter != _completeFrames.end(); iter++) { int newDistance = ABS((int)(*iter) - (int)frameNumber); @@ -177,7 +177,7 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { } } - bool forwards = frameNumber > closestFrame; + bool forwards = (int)frameNumber > closestFrame; if (forwards) { for (uint i = closestFrame; i <= frameNumber; i++) { applyFrameToCurrent(i); -- cgit v1.2.3 From b66700212479bb05ce1367a43fe6341cdfca1b00 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:10:37 -0500 Subject: ZVISION: Update ScriptManager::enableControl()/disableControl() to fit new Control syntax --- engines/zvision/script_manager.cpp | 28 ++++++++++++++++------------ engines/zvision/script_manager.h | 6 +++--- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 50d7e58091..dcfcf02048 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -212,24 +212,28 @@ void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) { _globalState[key] += valueToAdd; } -bool ScriptManager::enableControl(uint32 key) { - if (!_activeControls.contains(key)) { - return false; - } else { - return _activeControls[key]->enable(); +void ScriptManager::addControl(Control *control) { + _activeControls.push_back(control); +} + +void ScriptManager::enableControl(uint32 key) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + if ((*iter)->getKey() == key) { + (*iter)->enable(); + break; + } } } -bool ScriptManager::disableControl(uint32 key) { - if (!_activeControls.contains(key)) { - return false; - } else { - return _activeControls[key]->disable(); +void ScriptManager::disableControl(uint32 key) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + if ((*iter)->getKey() == key) { + (*iter)->disable(); + break; + } } } -void ScriptManager::addActionNode(ActionNode *node) { - _activeNodes.push_back(node); } void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 offset) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 28bce07dc8..27e2e61238 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -85,10 +85,10 @@ public: void setStateValue(uint32 key, uint value); void addToStateValue(uint32 key, uint valueToAdd); - bool enableControl(uint32 key); - bool disableControl(uint32 key); + void addControl(Control *control); - void addActionNode(ActionNode *node); + void enableControl(uint32 key); + void disableControl(uint32 key); void changeLocation(char world, char room, char node, char view, uint32 offset); -- cgit v1.2.3 From a6b2bb75819554a779b238045c21867943ce5f6c Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:13:27 -0500 Subject: ZVISION: Remove ScriptManager::_activeNodes and change all iterators to iterate over _activeControls We also change _activeControls to a List instead of a HashMap because a List should have slightly better iteration time. --- engines/zvision/script_manager.cpp | 17 +++++++---------- engines/zvision/script_manager.h | 6 +----- 2 files changed, 8 insertions(+), 15 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index dcfcf02048..3cc4c92f0b 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -108,11 +108,10 @@ void ScriptManager::createReferenceTable() { void ScriptManager::updateNodes(uint deltaTimeMillis) { // If process() returns true, it means the node can be deleted - for (Common::List::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end();) { if ((*iter)->process(deltaTimeMillis)) { - // Delete the node then remove the pointer - delete (*iter); - iter = _activeNodes.erase(iter); + // Remove the node + iter = _activeControls.erase(iter); } else { iter++; } @@ -257,12 +256,10 @@ void ScriptManager::changeLocationIntern() { delete (*iter); } _activePuzzles.clear(); - for (Common::HashMap::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { - delete (*iter)._value; + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + delete (*iter); } _activeControls.clear(); - _engine->clearAllMouseEvents(); - // TODO: See if we need to clear _activeNodes as well. And if so, remember to delete the nodes before clearing the list // Revert to the idle cursor _engine->getCursorManager()->revertToIdle(); @@ -278,8 +275,8 @@ void ScriptManager::changeLocationIntern() { _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); // Enable all the controls - for (Common::HashMap::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { - (*iter)._value->enable(); + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + (*iter)->enable(); } // Add all the local puzzles to the queue to be checked diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 27e2e61238..0f3ea43dc3 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -37,7 +37,6 @@ class SeekableReadStream; namespace ZVision { class ZVision; -class ActionNode; struct Location { char world; @@ -60,8 +59,6 @@ private: * particular state key are checked after the key is modified. */ Common::HashMap _globalState; - /** Holds the currently active ActionNodes */ - Common::List _activeNodes; /** References _globalState keys to Puzzles */ Common::HashMap > _referenceTable; /** Holds the Puzzles that should be checked this frame */ @@ -71,13 +68,12 @@ private: /** Holds the global puzzles */ Common::List_globalPuzzles; /** Holds the currently active controls */ - Common::HashMap _activeControls; + Common::List _activeControls; Location _nextLocation; bool _changeLocation; public: - void initialize(); void update(uint deltaTimeMillis); -- cgit v1.2.3 From e3b08793dddbf8cf8214328b4b3780995496645c Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:15:10 -0500 Subject: ZVISION: Add ScriptManager mouse event handlers This allows the main engine to pass mouse events to Controls --- engines/zvision/script_manager.cpp | 19 +++++++++++++++++++ engines/zvision/script_manager.h | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 3cc4c92f0b..98bc2e3a3a 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -233,6 +233,25 @@ void ScriptManager::disableControl(uint32 key) { } } +void ScriptManager::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + (*iter)->onMouseDown(screenSpacePos, backgroundImageSpacePos); + } +} + +void ScriptManager::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + (*iter)->onMouseUp(screenSpacePos, backgroundImageSpacePos); + } +} + +bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + bool cursorWasChanged = false; + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + cursorWasChanged = cursorWasChanged || (*iter)->onMouseMove(screenSpacePos, backgroundImageSpacePos); + } + + return cursorWasChanged; } void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 offset) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 0f3ea43dc3..9b4763764f 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -86,6 +86,29 @@ public: void enableControl(uint32 key); void disableControl(uint32 key); + /** + * Called when LeftMouse is pushed. + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + /** + * Called when LeftMouse is lifted. + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + /** + * Called on every MouseMove. + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + * @return Was the cursor changed? + */ + bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + void changeLocation(char world, char room, char node, char view, uint32 offset); private: -- cgit v1.2.3 From 84c645968c9e93ca343e7c80c6f4546a793c2d41 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:16:04 -0500 Subject: ZVISION: Remove ZVision::_mousEvents and all associated functions Instead, pass all mouse events to ScriptManager --- engines/zvision/events.cpp | 43 +++---------------------------------------- engines/zvision/zvision.h | 17 ----------------- 2 files changed, 3 insertions(+), 57 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 94e8f088dd..9283328202 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -32,38 +32,10 @@ #include "zvision/cursor_manager.h" #include "zvision/render_manager.h" #include "zvision/script_manager.h" -#include "zvision/mouse_event.h" #include "zvision/rlf_animation.h" namespace ZVision { -void ZVision::registerMouseEvent(MouseEvent *event) { - _mouseEvents.push_back(event); -} - -bool ZVision::removeMouseEvent(const uint32 key) { - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - if ((*iter)->_key == key) { - _scriptManager->setStateValue((*iter)->_key, 0); - _mouseEvents.erase(iter); - return true; - } - } - - return false; -} - -void ZVision::clearAllMouseEvents() { - // Clear the state values of all the events - // Then delete the nodes - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - _scriptManager->setStateValue((*iter)->_key, 0); - delete (*iter); - } - - _mouseEvents.clear(); -} - void ZVision::processEvents() { while (_eventMan->pollEvent(_event)) { switch (_event.type) { @@ -121,29 +93,20 @@ void ZVision::onMouseDown(const Common::Point &pos) { _cursorManager->cursorDown(true); Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); - - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - (*iter)->onMouseDown(pos, imageCoord); - } + _scriptManager->onMouseDown(pos, imageCoord); } void ZVision::onMouseUp(const Common::Point &pos) { _cursorManager->cursorDown(false); Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); - - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - (*iter)->onMouseUp(pos, imageCoord); - } + _scriptManager->onMouseUp(pos, imageCoord); } void ZVision::onMouseMove(const Common::Point &pos) { Common::Point imageCoord(_renderManager->screenSpaceToImageSpace(pos)); - bool cursorWasChanged = false; - for (Common::List::iterator iter = _mouseEvents.begin(); iter != _mouseEvents.end(); iter++) { - cursorWasChanged = cursorWasChanged || (*iter)->onMouseMove(pos, imageCoord); - } + bool cursorWasChanged = _scriptManager->onMouseMove(pos, imageCoord); // Graph of the function governing rotation velocity: // diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 84e4da9d20..6bf6d2acc0 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -33,7 +33,6 @@ #include "zvision/detection.h" #include "zvision/clock.h" -#include "zvision/mouse_event.h" #include "gui/debugger.h" @@ -100,9 +99,6 @@ private: // Clock Clock _clock; - // To store the current mouse events - Common::List _mouseEvents; - // To prevent allocation every time we process events Common::Event _event; @@ -131,19 +127,6 @@ public: void playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); - /** - * Register a MouseEvent with the event system. These will be checked at every - * MOUSE_UP, MOUSE_DOWN, MOUSE_MOVE, etc. - * - * @param event The event to register - */ - void registerMouseEvent(MouseEvent *event); - - bool removeMouseEvent(const uint32 key); - - /** Remove all MouseEvents from the event system */ - void clearAllMouseEvents(); - /** * Utility method to cycle through all the cursors in the game. After * calling, use Left and Right arrows to cycle. Esc to quit. This is a -- cgit v1.2.3 From 610eb118246531e38173d67d6790b4737b1a6744 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:17:04 -0500 Subject: ZVISION: Prevent variable shadowing --- engines/zvision/lever_control.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 5d9ea4db36..847defd942 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -97,13 +97,13 @@ void LeverControl::parseLevFile(const Common::String &fileName) { char fileNameBuffer[25]; sscanf(line.c_str(), "%*[^:]:%25[^~]~", fileNameBuffer); - Common::String fileName(fileNameBuffer); + Common::String animationFileName(fileNameBuffer); - if (fileName.hasSuffix(".avi")) { + if (animationFileName.hasSuffix(".avi")) { _animation.avi = new ZorkAVIDecoder(); - _animation.avi->loadFile(fileName); - } else if (fileName.hasSuffix(".rlf")) { - _animation.rlf = new RlfAnimation(fileNameBuffer, false); + _animation.avi->loadFile(animationFileName); + } else if (animationFileName.hasSuffix(".rlf")) { + _animation.rlf = new RlfAnimation(animationFileName, false); } } else if (line.matchString("*skipcolor*", true)) { // Not used -- cgit v1.2.3 From da3f137b6b4c4c1a06b206d47f8818868cc227ff Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:17:43 -0500 Subject: ZVISION: sscanf to ints before storing them in Rect coords --- engines/zvision/lever_control.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 847defd942..6555fe5ce1 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -108,7 +108,13 @@ void LeverControl::parseLevFile(const Common::String &fileName) { } else if (line.matchString("*skipcolor*", true)) { // Not used } else if (line.matchString("*anim_coords*", true)) { - sscanf(line.c_str(), "%*[^:]:%u %u %u %u~", &_animationCoords.left, &_animationCoords.top, &_animationCoords.right, &_animationCoords.bottom); + int left, top, right, bottom; + sscanf(line.c_str(), "%*[^:]:%d %d %d %d~", &left, &top, &right, &bottom); + + _animationCoords.left = left; + _animationCoords.top = top; + _animationCoords.right = right; + _animationCoords.bottom = bottom; } else if (line.matchString("*mirrored*", true)) { uint mirrored; sscanf(line.c_str(), "%*[^:]:%u~", &mirrored); -- cgit v1.2.3 From f60b054b490ca13f79f849b5981e15140a239434 Mon Sep 17 00:00:00 2001 From: richiesams Date: Mon, 26 Aug 2013 14:17:56 -0500 Subject: ZVISION: Fix comment spacing --- engines/zvision/lever_control.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 6555fe5ce1..15b0bf771d 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -287,12 +287,12 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm // 180 <----------------------------------------> 0 // angle ( /|\ ) -angle // / | \ - // / | \ - // Quadrant 1 / | \ Quadrant 0 + // / | \ + // Quadrant 1 / | \ Quadrant 0 // / | \ - // / | \ - // / | \ - // * | * + // / | \ + // / | \ + // * | * // ^ // 270 -- cgit v1.2.3 From b317ea45fed9cdf444bba3b972ff1e12c12717ad Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:10:22 -0500 Subject: ZVISION: Allow a angle buffer zone on *both* sides of the actual angle --- engines/zvision/lever_control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 15b0bf771d..08a620f646 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -208,7 +208,7 @@ bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common _lastMousePos = backgroundImageSpacePos; for (Common::List::iterator iter = _frameInfo[_currentFrame].directions.begin(); iter != _frameInfo[_currentFrame].directions.end(); iter++) { - if (angle >= (int)(*iter).angle - ANGLE_DELTA && angle <= (int)(*iter).angle) { + if (angle >= (int)(*iter).angle - ANGLE_DELTA && angle <= (int)(*iter).angle + ANGLE_DELTA) { _currentFrame = (*iter).toFrame; renderFrame(_currentFrame); break; -- cgit v1.2.3 From 3a9b3841149d22d9a8221a8ae32d2b0feca0b14f Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:10:59 -0500 Subject: ZVISION: Round to int *after* converting to degrees --- engines/zvision/lever_control.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 08a620f646..71b284c459 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -247,10 +247,9 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm int16 xDist = pointTwo.x - pointOne.x; int16 yDist = pointTwo.y - pointOne.y; - int angle = int(atan((float)yDist / (float)xDist)); - - // Convert to degrees. (180 / 3.14159 = 57.2958) - angle *= 57; + // Calculate the angle using arctan + // Then convert to degrees. (180 / 3.14159 = 57.2958) + int angle = int(atan((float)yDist / (float)xDist) * 57); // Calculate what quadrant pointTwo is in uint quadrant = ((yDist > 0 ? 1 : 0) << 1) | (xDist < 0 ? 1 : 0); -- cgit v1.2.3 From ab18d20ead93b5e1f65f474fe73212724394c1fc Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:12:14 -0500 Subject: ZVISION: Fix the quadrant numbers in angle calculations Because y increases as you go down, not up --- engines/zvision/lever_control.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 71b284c459..3c5b6370bb 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -233,7 +233,7 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm if (pointOne.x == pointTwo.x && pointOne.y == pointTwo.y) return -1; // This should never happen else if (pointOne.x == pointTwo.x) { - if (pointTwo.y > pointOne.y) + if (pointTwo.y < pointOne.y) return 90; else return 270; @@ -279,15 +279,15 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm // \ | / // \ | / // \ | / - // Quadrant 3 \ | / Quadrant 2 + // Quadrant 1 \ | / Quadrant 0 // \ | / // \ | / - // -angle ( \|/ ) angle + // angle ( \|/ ) -angle // 180 <----------------------------------------> 0 - // angle ( /|\ ) -angle + // -angle ( /|\ ) angle // / | \ // / | \ - // Quadrant 1 / | \ Quadrant 0 + // Quadrant 3 / | \ Quadrant 2 // / | \ // / | \ // / | \ @@ -298,16 +298,16 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm // Convert the local angles to unit circle angles switch (quadrant) { case 0: - angle = 360 + angle; + angle = 180 + angle; break; case 1: - angle = 180 + angle; + // Do nothing break; case 2: angle = 180 + angle; break; case 3: - // Do nothing + angle = 360 + angle; break; } -- cgit v1.2.3 From 3e6144970e2674380a8adab3b17e5bd1ce24ffea Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:13:05 -0500 Subject: ZVISION: Implement avi frame seeking --- engines/zvision/lever_control.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 3c5b6370bb..7592968413 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -27,6 +27,8 @@ #include "common/tokenizer.h" #include "common/system.h" +#include "graphics/surface.h" + #include "zvision/lever_control.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" @@ -318,21 +320,24 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm void LeverControl::renderFrame(uint frameNumber) { const uint16 *frameData; int pitch; - int x; - int y; + int x = _animationCoords.left; + int y = _animationCoords.top; int width; int height; if (_fileType == RLF) { // getFrameData() will automatically optimize to getNextFrame() / getPreviousFrame() if it can - frameData = _animation.rlf->getFrameData(_currentFrame); + frameData = _animation.rlf->getFrameData(frameNumber); pitch = _animation.rlf->width() * sizeof(uint16); - x = _animationCoords.left; - y = _animationCoords.right; width = _animation.rlf->width(); // Use the animation width instead of _animationCoords.width() height = _animation.rlf->height(); // Use the animation height instead of _animationCoords.height() } else if (_fileType == AVI) { - // Cry because AVI seeking isn't implemented (yet) + _animation.avi->seekToFrame(frameNumber); + const Graphics::Surface *surface = _animation.avi->decodeNextFrame(); + frameData = (const uint16 *)surface->getBasePtr(0, 0); + pitch = surface->pitch; + width = surface->w; + height = surface->h; } _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); -- cgit v1.2.3 From 945982c8577b9c8a34333898841b5ffcfaa7138b Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:14:32 -0500 Subject: ZVISION: Add support for animation 'mirroring' If an animation is 'mirrored', it doesn't have B-frames, only I-frames. However the animations are built so the last half of the animation is the reverse of the first half --- engines/zvision/lever_control.cpp | 6 ++++++ engines/zvision/lever_control.h | 1 + 2 files changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 7592968413..4ed3f10878 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -45,6 +45,7 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre _frameCount(0), _startFrame(0), _currentFrame(0), + _lastRenderedFrame(0), _mouseIsCaptured(false), _isReturning(false) { @@ -318,6 +319,10 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm } void LeverControl::renderFrame(uint frameNumber) { + if (frameNumber < _lastRenderedFrame && _mirrored) { + frameNumber = (_frameCount * 2) - 1 - frameNumber; + } + const uint16 *frameData; int pitch; int x = _animationCoords.left; @@ -341,6 +346,7 @@ void LeverControl::renderFrame(uint frameNumber) { } _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); + _lastRenderedFrame = frameNumber; } } // End of namespace ZVision diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h index 42577a1776..cf41aac6b3 100644 --- a/engines/zvision/lever_control.h +++ b/engines/zvision/lever_control.h @@ -80,6 +80,7 @@ private: FrameInfo *_frameInfo; uint _currentFrame; + uint _lastRenderedFrame; bool _mouseIsCaptured; bool _isReturning; Common::Point _lastMousePos; -- cgit v1.2.3 From a1a70170d4a28a426fe916225a2aa9adbdcf5f95 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:15:51 -0500 Subject: ZVISION: Remove RlfAnimation::getPreviousFrame() I realized that RlfAnimations don't use B-frames, therefore, can not easily go backwards. --- engines/zvision/rlf_animation.cpp | 30 ++++++------------------------ engines/zvision/rlf_animation.h | 2 -- 2 files changed, 6 insertions(+), 26 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 77c1a50266..90b39dc757 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -158,34 +158,25 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { assert(frameNumber < _frameCount); // Since this method is so expensive, first check to see if we can use - // getNextFrame() or getPreviousFrame() since they are cheap. + // getNextFrame() it's cheap. if ((int)frameNumber == _currentFrame) { return _currentFrameBuffer; } else if (_currentFrame + 1 == (int)frameNumber) { return getNextFrame(); - } else if (_currentFrame - 1 == (int)frameNumber) { - return getPreviousFrame(); } int closestFrame = _currentFrame; - int distance = ABS(_currentFrame - (int)frameNumber); + int distance = (int)frameNumber - _currentFrame; for (Common::List::const_iterator iter = _completeFrames.begin(); iter != _completeFrames.end(); iter++) { - int newDistance = ABS((int)(*iter) - (int)frameNumber); - if (closestFrame == -1 || newDistance < distance) { + int newDistance = (int)frameNumber - (int)(*iter); + if (newDistance > 0 && (closestFrame == -1 || newDistance < distance)) { closestFrame = (*iter); distance = newDistance; } } - bool forwards = (int)frameNumber > closestFrame; - if (forwards) { - for (uint i = closestFrame; i <= frameNumber; i++) { - applyFrameToCurrent(i); - } - } else { - for (uint i = closestFrame; i >= frameNumber; i--) { - applyFrameToCurrent(i); - } + for (uint i = closestFrame; i <= frameNumber; i++) { + applyFrameToCurrent(i); } _currentFrame = frameNumber; @@ -205,15 +196,6 @@ const uint16 *RlfAnimation::getNextFrame() { return _currentFrameBuffer; } -const uint16 *RlfAnimation::getPreviousFrame() { - assert(!_stream); - assert(_currentFrame - 1 >= 0); - - applyFrameToCurrent(_currentFrame - 1); - _currentFrame--; - return _currentFrameBuffer; -} - void RlfAnimation::applyFrameToCurrent(uint frameNumber) { if (_frames[frameNumber].type == Masked) { decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer, _frames[frameNumber].encodedSize, _frameBufferByteSize); diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index d49e6a9395..5091185a36 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -74,9 +74,7 @@ public: uint32 frameTime() { return _frameTime; } const uint16 *getFrameData(uint frameNumber); - const uint16 *getNextFrame(); - const uint16 *getPreviousFrame(); bool endOfAnimation() { return _currentFrame == (int)_frameCount - 1; } -- cgit v1.2.3 From 7d255c3d8014987b76d8ef974af1c9c7f536d396 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:16:16 -0500 Subject: ZVISION: Fix: Signal a cursor change --- engines/zvision/lever_control.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 4ed3f10878..97e1f66fb5 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -220,6 +220,7 @@ bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common } } else if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { _engine->getCursorManager()->changeCursor(_cursorName); + cursorWasChanged = true; } return cursorWasChanged; -- cgit v1.2.3 From ce9e9a55c6969ca1127f00f5d5a22e0c0c0bc046 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:16:38 -0500 Subject: ZVISION: Fix: Store what type of animation file is used --- engines/zvision/lever_control.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 97e1f66fb5..d515f9e784 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -105,8 +105,10 @@ void LeverControl::parseLevFile(const Common::String &fileName) { if (animationFileName.hasSuffix(".avi")) { _animation.avi = new ZorkAVIDecoder(); _animation.avi->loadFile(animationFileName); + _fileType = AVI; } else if (animationFileName.hasSuffix(".rlf")) { _animation.rlf = new RlfAnimation(animationFileName, false); + _fileType = RLF; } } else if (line.matchString("*skipcolor*", true)) { // Not used -- cgit v1.2.3 From 952fb83793fb99a3e8d7db849a4b66f830e4e3ad Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:17:23 -0500 Subject: ZVISION: Fix: Change infndef to correct constant --- engines/zvision/lever_control.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h index cf41aac6b3..d359318d2f 100644 --- a/engines/zvision/lever_control.h +++ b/engines/zvision/lever_control.h @@ -20,8 +20,8 @@ * */ -#ifndef ZVISION_PUSH_TOGGLE_CONTROL_H -#define ZVISION_PUSH_TOGGLE_CONTROL_H +#ifndef ZVISION_LEVER_CONTROL_H +#define ZVISION_LEVER_CONTROL_H #include "common/types.h" -- cgit v1.2.3 From f1f36e7c9db0b78a5ae04ebdadebe431e2840bfc Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:18:18 -0500 Subject: ZVISION: Add LeverControl to scr file parsing --- engines/zvision/scr_file_handling.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 212d7140b0..06767c5340 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -27,6 +27,7 @@ #include "zvision/puzzle.h" #include "zvision/actions.h" #include "zvision/push_toggle_control.h" +#include "zvision/lever_control.h" #include "common/textconsole.h" #include "common/file.h" @@ -287,10 +288,12 @@ void ScriptManager::parseControl(Common::String &line, Common::SeekableReadStrea } else if (controlType.equalsIgnoreCase("pana")) { Control::parsePanoramaControl(_engine, stream); return; - } - else if (controlType.equalsIgnoreCase("tilt")) { + } else if (controlType.equalsIgnoreCase("tilt")) { Control::parseTiltControl(_engine, stream); return; + } else if (controlType.equalsIgnoreCase("lever")) { + _activeControls.push_back(new LeverControl(_engine, key, stream)); + return; } } -- cgit v1.2.3 From f3514534ce46bad5e3ffadfdf0b3af403045e5ef Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 28 Aug 2013 09:19:39 -0500 Subject: ZVISION: Increase background rotation speed This could probably still go higher. The DOS version is *very* sensitive, too sensitive. But this is still a bit slow. --- engines/zvision/zvision.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 6bf6d2acc0..a02fecc43d 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -80,7 +80,7 @@ private: WORKING_WINDOW_HEIGHT = 320, ROTATION_SCREEN_EDGE_OFFSET = 60, - MAX_ROTATION_SPEED = 250 // Pixels per second + MAX_ROTATION_SPEED = 400 // Pixels per second }; Console *_console; -- cgit v1.2.3 From bb77333d4f4025b053ad311092ad0390368522ea Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 01:49:01 -0500 Subject: ZVISION: Create console method for parsing ALL .scr files Useful for putting a breakpoint at certain ResultActions/Controls to test out different instances of them. --- engines/zvision/console.cpp | 12 ++++++++++++ engines/zvision/console.h | 1 + engines/zvision/script_manager.h | 3 +++ 3 files changed, 16 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index fd8347e74f..8b4dffa98a 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -54,6 +54,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("dumpcursorfilenames", WRAP_METHOD(Console, cmdDumpAllCursorFileNames)); DCmd_Register("showcursor", WRAP_METHOD(Console, cmdShowCursor)); DCmd_Register("dumpalllevfiles", WRAP_METHOD(Console, cmdDumpAllLevFiles)); + DCmd_Register("parseallscrfiles", WRAP_METHOD(Console, cmdParseAllScrFiles)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -225,4 +226,15 @@ bool Console::cmdDumpAllLevFiles(int argc, const char **argv) { return true; } +bool Console::cmdParseAllScrFiles(int argc, const char **argv) { + Common::ArchiveMemberList list; + SearchMan.listMatchingMembers(list, "*.scr"); + + for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { + _engine->getScriptManager()->parseScrFile((*iter)->getName()); + } + + return true; +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index e518467438..612e5eec00 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -50,6 +50,7 @@ private: bool cmdDumpAllCursorFileNames(int argc, const char **argv); bool cmdShowCursor(int argc, const char **argv); bool cmdDumpAllLevFiles(int argc, const char **argv); + bool cmdParseAllScrFiles(int argc, const char **argv); }; } // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 9b4763764f..1a272f1970 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -117,6 +117,8 @@ private: void updateNodes(uint deltaTimeMillis); void checkPuzzleCriteria(); +// TODO: Make this private. It was only made public so Console::cmdParseAllScrFiles() could use it +public: /** * Parses a script file into triggers and events * @@ -125,6 +127,7 @@ private: */ void parseScrFile(const Common::String &fileName, bool isGlobal = false); +private: /** * Parses the stream into a Puzzle object * Helper method for parseScrFile. -- cgit v1.2.3 From a81c9a52a34cba1ecf358d612ddbcd6e517a2830 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 01:52:37 -0500 Subject: ZVISION: Fix LeverControl 'mirrored' support --- engines/zvision/lever_control.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index d515f9e784..7d23b68768 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -322,8 +322,13 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm } void LeverControl::renderFrame(uint frameNumber) { - if (frameNumber < _lastRenderedFrame && _mirrored) { - frameNumber = (_frameCount * 2) - 1 - frameNumber; + if (frameNumber == 0) { + _lastRenderedFrame = frameNumber; + } else if (frameNumber < _lastRenderedFrame && _mirrored) { + _lastRenderedFrame = frameNumber; + frameNumber = (_frameCount * 2) - frameNumber - 1; + } else { + _lastRenderedFrame = frameNumber; } const uint16 *frameData; @@ -342,14 +347,13 @@ void LeverControl::renderFrame(uint frameNumber) { } else if (_fileType == AVI) { _animation.avi->seekToFrame(frameNumber); const Graphics::Surface *surface = _animation.avi->decodeNextFrame(); - frameData = (const uint16 *)surface->getBasePtr(0, 0); + frameData = (const uint16 *)surface->getPixels(); pitch = surface->pitch; width = surface->w; height = surface->h; } _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); - _lastRenderedFrame = frameNumber; } } // End of namespace ZVision -- cgit v1.2.3 From c15454d7d4a8b670f6e71f035f5b8439166e71e1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 01:56:23 -0500 Subject: ZVISION: Keep a Graphics::Surface of the current background instead of re-reading the file each time This is both more efficient and is part of the process of converting the entire game to RBG 565 --- engines/zvision/render_manager.cpp | 128 ++++++++++++++++++++++--------------- engines/zvision/render_manager.h | 10 +-- 2 files changed, 82 insertions(+), 56 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index fa45a6f576..99c987f7dd 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -42,7 +42,6 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, _screenCenterY(_workingHeight / 2), _workingWindow(workingWindow), _pixelFormat(pixelFormat), - _currentBackground(0), _backgroundWidth(0), _backgroundHeight(0), _backgroundInverseVelocity(0), @@ -54,10 +53,6 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, } RenderManager::~RenderManager() { - if (_currentBackground != 0) { - delete _currentBackground; - } - delete[] _workingWindowBuffer; } @@ -89,7 +84,7 @@ void RenderManager::clearWorkingWindowToColor(uint16 color) { _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), _workingWindow.left, _workingWindow.top, _workingWidth, _workingHeight); } -void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap, bool isTransposed) { +void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap) { int16 subRectX = 0; int16 subRectY = 0; @@ -143,13 +138,24 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (_renderTable.getRenderState() == RenderTable::FLAT) { _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); } else { - _renderTable.mutateImage((uint16 *)surface.getBasePtr(0, 0), _workingWindowBuffer, surface.w, surface.h, destinationX, destinationY, subRect, wrap, isTransposed); + _renderTable.mutateImage((uint16 *)surface.getPixels(), _workingWindowBuffer, surface.w, surface.h, destinationX, destinationY, subRect, wrap); _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); } } void RenderManager::renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap) { + Graphics::Surface surface; + readImageToSurface(fileName, surface); + + renderSubRectToScreen(surface, destinationX, destinationY, wrap); +} + +void RenderManager::renderImageToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap) { + renderSubRectToScreen(surface, destinationX, destinationY, wrap); +} + +void RenderManager::readImageToSurface(const Common::String &fileName, Graphics::Surface &destination) { Common::File file; if (!file.open(fileName)) { @@ -157,62 +163,85 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, int16 de return; } - renderImageToScreen(file, destinationX, destinationY); -} - -void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, int16 destinationX, int16 destinationY, bool wrap) { // Read the magic number // Some files are true TGA, while others are TGZ - uint32 fileType = stream.readUint32BE(); + uint32 fileType = file.readUint32BE(); + + uint32 imageWidth; + uint32 imageHeight; + Graphics::TGADecoder tga; + uint16 *buffer; + bool isTransposed = _renderTable.getRenderState() == RenderTable::PANORAMA; + // All ZVision images are in RGB 555 + Graphics::PixelFormat pixelFormat555 = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); + destination.format = pixelFormat555; + + bool isTGZ; // Check for TGZ files if (fileType == MKTAG('T', 'G', 'Z', '\0')) { + isTGZ = true; + // TGZ files have a header and then Bitmap data that is compressed with LZSS - uint32 decompressedSize = stream.readSint32LE(); - uint32 imageWidth = stream.readSint32LE(); - uint32 imageHeight = stream.readSint32LE(); + uint32 decompressedSize = file.readSint32LE(); + imageWidth = file.readSint32LE(); + imageHeight = file.readSint32LE(); - LzssReadStream lzssStream(&stream); - byte *buffer = new byte[decompressedSize]; + LzssReadStream lzssStream(&file); + buffer = (uint16 *)(new uint16[decompressedSize]); lzssStream.read(buffer, decompressedSize); - - uint32 pitch = imageWidth * sizeof(uint16); - bool isTransposed = _renderTable.getRenderState() == RenderTable::PANORAMA; - - if (isTransposed) { - uint16 temp = imageHeight; - imageHeight = imageWidth; - imageWidth = temp; - } - - Graphics::Surface surface; - surface.init(imageWidth, imageHeight, pitch, buffer, _pixelFormat); - - renderSubRectToScreen(surface, destinationX, destinationY, wrap, isTransposed); - - // We have to use delete[] instead of calling surface.free() because we created the memory with new[] - delete[] buffer; } else { + isTGZ = false; + // Reset the cursor - stream.seek(0); + file.seek(0); // Decode - Graphics::TGADecoder tga; - if (!tga.loadStream(stream)) { + if (!tga.loadStream(file)) { warning("Error while reading TGA image"); return; } Graphics::Surface tgaSurface = *(tga.getSurface()); - bool isTransposed = _renderTable.getRenderState() == RenderTable::PANORAMA; + imageWidth = tgaSurface.w; + imageHeight = tgaSurface.h; + + buffer = (uint16 *)tgaSurface.getPixels(); + } + + // Flip the width and height if transposed + if (isTransposed) { + uint16 temp = imageHeight; + imageHeight = imageWidth; + imageWidth = temp; + } + + // If the destination internal buffer is the same size as what we're copying into it, + // there is no need to free() and re-create + if (imageWidth != destination.w || imageHeight != destination.h) { + destination.create(imageWidth, imageHeight, pixelFormat555); + } - if (isTransposed) { - uint16 temp = tgaSurface.h; - tgaSurface.h = tgaSurface.w; - tgaSurface.w = temp; + // If transposed, 'un-transpose' the data while copying it to the destination + // Otherwise, just do a simple copy + if (isTransposed) { + uint16 *dest = (uint16 *)destination.getPixels(); + + for (uint32 y = 0; y < imageHeight; y++) { + uint32 columnIndex = y * imageWidth; + + for (uint32 x = 0; x < imageWidth; x++) { + dest[columnIndex + x] = buffer[x * imageHeight + y]; + } } + } else { + memcpy(destination.getPixels(), buffer, imageWidth * imageHeight * _pixelFormat.bytesPerPixel); + } - renderSubRectToScreen(tgaSurface, destinationX, destinationY, wrap, isTransposed); + // Cleanup + if (isTGZ) { + delete[] buffer; + } else { tga.destroy(); } } @@ -256,10 +285,7 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) { return; } - if (_currentBackground != 0) { - delete _currentBackground; - } - _currentBackground = file; + readImageToSurface(fileName, _currentBackground); moveBackground(0); } @@ -291,8 +317,6 @@ void RenderManager::setBackgroundVelocity(int velocity) { } void RenderManager::moveBackground(int offset) { - _currentBackground->seek(0); - RenderTable::RenderState state = _renderTable.getRenderState(); if (state == RenderTable::TILT) { _backgroundOffset += Common::Point(0, offset); @@ -307,7 +331,7 @@ void RenderManager::moveBackground(int offset) { else if (_backgroundOffset.y >= _backgroundHeight) _backgroundOffset.y += _backgroundHeight; - renderImageToScreen(*_currentBackground, 0, _screenCenterY - _backgroundOffset.y, true); + renderImageToScreen(_currentBackground, 0, _screenCenterY - _backgroundOffset.y, true); } else if (state == RenderTable::PANORAMA) { _backgroundOffset += Common::Point(offset, 0); @@ -321,9 +345,9 @@ void RenderManager::moveBackground(int offset) { else if (_backgroundOffset.y >= _backgroundHeight) _backgroundOffset.y += _backgroundHeight; - renderImageToScreen(*_currentBackground, _screenCenterX - _backgroundOffset.x, 0, true); + renderImageToScreen(_currentBackground, _screenCenterX - _backgroundOffset.x, 0, true); } else { - renderImageToScreen(*_currentBackground, 0, 0); + renderImageToScreen(_currentBackground, 0, 0); } } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index d82e40fa4c..41dedab792 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -74,7 +74,7 @@ private: /** Used to warp the background image */ RenderTable _renderTable; - Common::SeekableReadStream *_currentBackground; + Graphics::Surface _currentBackground; /** The (x1,y1) coordinates of the subRectangle of the background that is currently displayed on the screen */ Common::Point _backgroundOffset; /** The width of the current background image */ @@ -123,11 +123,11 @@ public: * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. * The image will be clipped to fit inside the working window. Coords are in working window space, not screen space! * - * @param stream Stream to read the image data from + * @param stream Surface to read the image data from * @param destinationX X position where the image should be put. Coords are in working window space, not screen space! * @param destinationY Y position where the image should be put. Coords are in working window space, not screen space! */ - void renderImageToScreen(Common::SeekableReadStream &stream, int16 destinationX, int16 destinationY, bool wrap = false); + void renderImageToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap = false); /** * Sets the current background image to be used by the RenderManager and immediately @@ -181,7 +181,9 @@ private: * @param subRectangle A rectangle representing the part of the image that should be rendered * @param wrap Should the image wrap (tile) if it doesn't completely fill the screen? */ - void renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap, bool isTransposed); + void renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap); + + void readImageToSurface(const Common::String &fileName, Graphics::Surface &destination); void moveBackground(int offset); }; -- cgit v1.2.3 From 0271a2c59dd553b79cae95376b40654a70190089 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 01:58:12 -0500 Subject: ZVISION: Transpose is done in RenderManager::readImageToSurface(), so remove it from mutateImage --- engines/zvision/render_table.cpp | 8 ++------ engines/zvision/render_table.h | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 0a8175e54e..ee3628299a 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -98,7 +98,7 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { return returnColor; } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap, bool isTransposed) { +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap) { for (int16 y = subRect.top; y < subRect.bottom; y++) { int16 normalizedY = y - subRect.top; int32 internalColumnIndex = (normalizedY + destinationY) * _numColumns; @@ -135,11 +135,7 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 im sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); } - if (isTransposed) { - destBuffer[destColumnIndex + normalizedX] = sourceBuffer[sourceXIndex * imageHeight + sourceYIndex]; - } else { - destBuffer[destColumnIndex + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; - } + destBuffer[destColumnIndex + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; } } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index bbf5e1b22a..e5820803cb 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -66,7 +66,7 @@ public: const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); - void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap, bool isTransposed); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap); void generateRenderTable(); void setPanoramaFoV(float fov); -- cgit v1.2.3 From 94378d064405992905a9ffcb24c72f0c86d51bd4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 01:59:13 -0500 Subject: ZVISION: Force comparison to be between signed ints and ensure CLIP happens on a signed int --- engines/zvision/render_table.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index ee3628299a..55285b45e6 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -62,9 +62,9 @@ void RenderTable::setRenderState(RenderState newState) { const Common::Point RenderTable::convertWarpedCoordToFlatCoord(const Common::Point &point) { // If we're outside the range of the RenderTable, no warping is happening. Return the maximum image coords - if (point.x >= _numColumns || point.y >= _numRows) { - int16 x = CLIP(point.x, 0, _numColumns); - int16 y = CLIP(point.y, 0, _numRows); + if (point.x >= (int16)_numColumns || point.y >= (int16)_numRows || point.x < 0 || point.y , 0) { + int16 x = CLIP(point.x, 0, (int16)_numColumns); + int16 y = CLIP(point.y, 0, (int16)_numRows); return Common::Point(x, y); } -- cgit v1.2.3 From 07770eeafbf72fa4ffcee2f474b212d2a67ee234 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 02:01:04 -0500 Subject: ZVISION: Convert cursors to RBG 565 This is part of a series of commits converting all game assets to RBG 565 from RBG 555. The argument is that certain backends do not support RGB 555. --- engines/zvision/cursor.cpp | 31 ++++++++++--------------------- engines/zvision/cursor.h | 7 +++---- 2 files changed, 13 insertions(+), 25 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor.cpp b/engines/zvision/cursor.cpp index 601c58fa2c..57859b9b46 100644 --- a/engines/zvision/cursor.cpp +++ b/engines/zvision/cursor.cpp @@ -34,16 +34,14 @@ ZorkCursor::ZorkCursor() : _width(0), _height(0), _hotspotX(0), - _hotspotY(0), - _surface(0) { + _hotspotY(0) { } ZorkCursor::ZorkCursor(const Common::String &fileName) : _width(0), _height(0), _hotspotX(0), - _hotspotY(0), - _surface(0) { + _hotspotY(0) { Common::File file; if (!file.open(fileName)) return; @@ -59,10 +57,13 @@ ZorkCursor::ZorkCursor(const Common::String &fileName) _width = file.readUint16LE(); _height = file.readUint16LE(); - uint dataSize = _width * _height * 2; - _surface = new byte[dataSize]; - uint32 bytesRead = file.read(_surface, dataSize); + uint dataSize = _width * _height * sizeof(uint16); + _surface.create(_width, _height, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)); + uint32 bytesRead = file.read(_surface.getPixels(), dataSize); assert(bytesRead == dataSize); + + // Convert to RGB 565 + _surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 6, 0, 11, 5, 0, 0)); } ZorkCursor::ZorkCursor(const ZorkCursor &other) { @@ -71,10 +72,7 @@ ZorkCursor::ZorkCursor(const ZorkCursor &other) { _hotspotX = other._hotspotX; _hotspotY = other._hotspotY; - uint dataSize = _width * _height * 2; - _surface = new byte[dataSize]; - - memcpy(_surface, other._surface, dataSize); + _surface.copyFrom(other._surface); } ZorkCursor &ZorkCursor::operator=(const ZorkCursor &other) { @@ -83,18 +81,9 @@ ZorkCursor &ZorkCursor::operator=(const ZorkCursor &other) { _hotspotX = other._hotspotX; _hotspotY = other._hotspotY; - uint dataSize = _width * _height * 2; - _surface = new byte[dataSize]; - - memcpy(_surface, other._surface, dataSize); + _surface.copyFrom(other._surface); return *this; } -ZorkCursor::~ZorkCursor() { - if (_surface != 0) { - delete[] _surface; - } -} - } // End of namespace ZVision diff --git a/engines/zvision/cursor.h b/engines/zvision/cursor.h index 9a561fcac3..ec9f5ed0d7 100644 --- a/engines/zvision/cursor.h +++ b/engines/zvision/cursor.h @@ -25,7 +25,7 @@ #include "common/types.h" -#include "graphics/cursor.h" +#include "graphics/surface.h" namespace Common { class String; @@ -42,14 +42,13 @@ public: ZorkCursor(); ZorkCursor(const Common::String &fileName); ZorkCursor(const ZorkCursor &other); - ~ZorkCursor(); private: uint16 _width; uint16 _height; uint16 _hotspotX; uint16 _hotspotY; - byte *_surface; + Graphics::Surface _surface; public: ZorkCursor &operator=(const ZorkCursor &other); @@ -59,7 +58,7 @@ public: uint16 getHotspotX() const { return _hotspotX; } uint16 getHotspotY() const { return _hotspotY; } byte getKeyColor() const { return 0; } - const byte *getSurface() const { return _surface; } + const byte *getSurface() const { return (const byte *)_surface.getPixels(); } }; } // End of namespace ZVision -- cgit v1.2.3 From f146a0209fdc3bf0dd5e26dbca8b5257b6ee7c0e Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 02:01:34 -0500 Subject: ZVISION: Convert image rendering to RBG 565 This is part of a series of commits converting all game assets to RBG 565 from RBG 555. The argument is that certain backends do not support RGB 555. --- engines/zvision/render_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 99c987f7dd..b1282dc007 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -244,6 +244,9 @@ void RenderManager::readImageToSurface(const Common::String &fileName, Graphics: } else { tga.destroy(); } + + // Convert in place to RGB 565 from RGB 555 + destination.convertToInPlace(_pixelFormat); } const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { -- cgit v1.2.3 From cdc484218186daa9a4f60792a2070ad089b7853e Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 02:01:57 -0500 Subject: ZVISION: Convert RLF animations to RBG 565 This is part of a series of commits converting all game assets to RBG 565 from RBG 555. The argument is that certain backends do not support RGB 555. --- engines/zvision/rlf_animation.cpp | 35 +++++++++++++++++++++-------------- engines/zvision/rlf_animation.h | 4 ++++ 2 files changed, 25 insertions(+), 14 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 90b39dc757..df1fe118da 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -33,6 +33,9 @@ namespace ZVision { +const Graphics::PixelFormat RlfAnimation::_pixelFormat555 = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); +const Graphics::PixelFormat RlfAnimation::_pixelFormat565 = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); + RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) : _stream(stream), _lastFrameRead(0), @@ -41,8 +44,8 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) _height(0), _frameTime(0), _frames(0), - _currentFrameBuffer(0), _currentFrame(-1), + _currentFrameBuffer(0), _frameBufferByteSize(0) { if (!_file.open(fileName)) { warning("RLF animation file %s could not be opened", fileName.c_str()); @@ -68,12 +71,8 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) } RlfAnimation::~RlfAnimation() { - if (_frames != 0) { - delete[] _frames; - } - if (_currentFrameBuffer != 0) { - delete[] _currentFrameBuffer; - } + delete[] _currentFrameBuffer; + delete[] _frames; } bool RlfAnimation::readHeader() { @@ -230,11 +229,14 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 return; } else if (destOffset + 1 >= destSize) { // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } - WRITE_UINT16(dest + destOffset, READ_LE_UINT16(source + sourceOffset)); + byte r, g, b; + _pixelFormat555.colorToRGB(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 destColor = _pixelFormat565.RGBToColor(r, g, b); + WRITE_UINT16(dest + destOffset, destColor); sourceOffset += 2; destOffset += 2; @@ -248,7 +250,7 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 return; } else if (destOffset + 1 >= destSize) { // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } @@ -275,11 +277,14 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 return; } else if (destOffset + 1 >= destSize) { // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } - WRITE_UINT16(dest + destOffset, READ_LE_UINT16(source + sourceOffset)); + byte r, g, b; + _pixelFormat555.colorToRGB(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 destColor = _pixelFormat565.RGBToColor(r, g, b); + WRITE_UINT16(dest + destOffset, destColor); sourceOffset += 2; destOffset += 2; @@ -293,14 +298,16 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 return; } - uint16 sampleColor = READ_LE_UINT16(source + sourceOffset); + byte r, g, b; + _pixelFormat555.colorToRGB(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 sampleColor = _pixelFormat565.RGBToColor(r, g, b); sourceOffset += 2; numberOfSamples += 2; while (numberOfSamples > 0) { if (destOffset + 1 >= destSize) { // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index 5091185a36..6f93934f1f 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -26,6 +26,7 @@ #include "common/types.h" #include "common/file.h" +#include "graphics/surface.h" namespace Common { @@ -51,6 +52,9 @@ private: uint32 encodedSize; }; + const static Graphics::PixelFormat _pixelFormat555; + const static Graphics::PixelFormat _pixelFormat565; + private: Common::File _file; bool _stream; -- cgit v1.2.3 From 4288c4fa0e36d2274257154c5365f71f6f6dd015 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 02:04:06 -0500 Subject: ZVISION: Remove unnecessary pixel format switching from video code This is part of a series of commits converting all game assets to RBG 565 from RBG 555. The argument is that certain backends do not support RGB 555. AVI videos are already in RGB 565, so we just need to remove the code that switched the pixelFormat during videos. --- engines/zvision/video.cpp | 8 -------- engines/zvision/zvision.cpp | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 377b24af2a..d0dbbc5755 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -77,11 +77,6 @@ void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, } void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect, bool skippable) { - // Videos use a different pixel format - Common::List formats; - formats.push_back(videoDecoder.getPixelFormat()); - initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, formats); - byte bytesPerPixel = videoDecoder.getPixelFormat().bytesPerPixel; uint16 origWidth = videoDecoder.getWidth(); @@ -167,9 +162,6 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d if (scale != 1) { delete[] scaledVideoFrameBuffer; } - - // Reset the pixel format to the original state - initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, &_pixelFormat); } } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index c32e78214f..b5cae8acd3 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -50,9 +50,10 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), _workingWindow((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2, (WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2, ((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2) + WORKING_WINDOW_WIDTH, ((WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2) + WORKING_WINDOW_HEIGHT), - _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), /*RGB 555*/ + _pixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), /*RGB 565*/ _desiredFrameTime(33), /* ~30 fps */ _clock(_system) { + // Put your engine in a sane state, but do nothing big yet; // in particular, do not load data from files; rather, if you // need to do such things, do them from run(). -- cgit v1.2.3 From fa578497b3ceb745c31f789a40b95b4a15f1cbe0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 02:05:07 -0500 Subject: ZVISION: Use Surface::getPixels() rather than getBasePtr(0, 0) Prevents unnecessary algebra --- engines/zvision/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index d0dbbc5755..5230653ca3 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -143,10 +143,10 @@ void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &d if (frame) { if (scale != 1) { - scaleBuffer((const byte *)frame->getBasePtr(0, 0), scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); + scaleBuffer((const byte *)frame->getPixels(), scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); _system->copyRectToScreen(scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); } else { - _system->copyRectToScreen((const byte *)frame->getBasePtr(0, 0), pitch, x, y, finalWidth, finalHeight); + _system->copyRectToScreen((const byte *)frame->getPixels(), pitch, x, y, finalWidth, finalHeight); } } } -- cgit v1.2.3 From 03d3646f8463cddddb17f043b7b827be1ca1bb39 Mon Sep 17 00:00:00 2001 From: richiesams Date: Thu, 29 Aug 2013 02:06:24 -0500 Subject: ZVISION: Remove unnecessary check if a pointer was non-NULL before deleting. I found out that you can call delete/free/delete[] on NULL and the function's defined behavior is to do nothing. --- engines/zvision/lever_control.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 7d23b68768..45c21efd49 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -79,9 +79,8 @@ LeverControl::~LeverControl() { } else if (_fileType == RLF) { delete _animation.rlf; } - if (_frameInfo != 0) { - delete[] _frameInfo; - } + + delete[] _frameInfo; } void LeverControl::parseLevFile(const Common::String &fileName) { -- cgit v1.2.3 From 7d1dca9ad10c3121fc44f991e6b21c68db939344 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 30 Aug 2013 15:34:42 -0500 Subject: ZVISION: Implement enabled/disabled support in Controls --- engines/zvision/lever_control.cpp | 16 ++++++++++++++++ engines/zvision/push_toggle_control.cpp | 8 ++++++++ 2 files changed, 24 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 45c21efd49..2a5fe4fcac 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -183,6 +183,10 @@ void LeverControl::parseLevFile(const Common::String &fileName) { } void LeverControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (!_enabled) { + return; + } + if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { _mouseIsCaptured = true; _lastMousePos = backgroundImageSpacePos; @@ -190,6 +194,10 @@ void LeverControl::onMouseDown(const Common::Point &screenSpacePos, const Common } void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (!_enabled) { + return; + } + _mouseIsCaptured = false; _engine->getScriptManager()->setStateValue(_key, _currentFrame); @@ -201,6 +209,10 @@ void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common:: } bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (!_enabled) { + return false; + } + bool cursorWasChanged = false; if (_mouseIsCaptured) { @@ -228,6 +240,10 @@ bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common } bool LeverControl::process(uint32 deltaTimeInMillis) { + if (!_enabled) { + return false; + } + // TODO: Implement reversal over time return false; diff --git a/engines/zvision/push_toggle_control.cpp b/engines/zvision/push_toggle_control.cpp index be038e767a..f4c0bc987e 100644 --- a/engines/zvision/push_toggle_control.cpp +++ b/engines/zvision/push_toggle_control.cpp @@ -71,12 +71,20 @@ PushToggleControl::~PushToggleControl() { } void PushToggleControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (!_enabled) { + return; + } + if (_hotspot.contains(backgroundImageSpacePos)) { _engine->getScriptManager()->setStateValue(_key, 1); } } bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (!_enabled) { + return false; + } + if (_hotspot.contains(backgroundImageSpacePos)) { _engine->getCursorManager()->changeCursor(_hoverCursor); return true; -- cgit v1.2.3 From ef3e26a0730b070d2026641f554b525ae9f4b138 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 30 Aug 2013 17:07:53 -0500 Subject: ZVISION: Fix typo in PixelFormat --- engines/zvision/cursor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor.cpp b/engines/zvision/cursor.cpp index 57859b9b46..4731d29f00 100644 --- a/engines/zvision/cursor.cpp +++ b/engines/zvision/cursor.cpp @@ -63,7 +63,7 @@ ZorkCursor::ZorkCursor(const Common::String &fileName) assert(bytesRead == dataSize); // Convert to RGB 565 - _surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 6, 0, 11, 5, 0, 0)); + _surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); } ZorkCursor::ZorkCursor(const ZorkCursor &other) { -- cgit v1.2.3 From 21474d32ab2d2de784c6cd12f85e0f9ad68bcea4 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 30 Aug 2013 17:08:38 -0500 Subject: ZVISION: Fix error is RenderManager backgroundOffset handling --- engines/zvision/render_manager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b1282dc007..96030ba2b9 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -118,7 +118,7 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (destinationY > 0) { // Move destinationY to 0 - subRectX = surface.w - destinationX; + subRectY = surface.h - destinationY; destinationY = 0; } } @@ -327,12 +327,12 @@ void RenderManager::moveBackground(int offset) { if (_backgroundOffset.x <= -_backgroundWidth) _backgroundOffset.x += _backgroundWidth; else if (_backgroundOffset.x >= _backgroundWidth) - _backgroundOffset.x += _backgroundWidth; + _backgroundOffset.x -= _backgroundWidth; if (_backgroundOffset.y <= -_backgroundHeight) _backgroundOffset.y += _backgroundHeight; else if (_backgroundOffset.y >= _backgroundHeight) - _backgroundOffset.y += _backgroundHeight; + _backgroundOffset.y -= _backgroundHeight; renderImageToScreen(_currentBackground, 0, _screenCenterY - _backgroundOffset.y, true); } else if (state == RenderTable::PANORAMA) { @@ -341,12 +341,12 @@ void RenderManager::moveBackground(int offset) { if (_backgroundOffset.x <= -_backgroundWidth) _backgroundOffset.x += _backgroundWidth; else if (_backgroundOffset.x >= _backgroundWidth) - _backgroundOffset.x += _backgroundWidth; + _backgroundOffset.x -= _backgroundWidth; if (_backgroundOffset.y <= -_backgroundHeight) _backgroundOffset.y += _backgroundHeight; else if (_backgroundOffset.y >= _backgroundHeight) - _backgroundOffset.y += _backgroundHeight; + _backgroundOffset.y -= _backgroundHeight; renderImageToScreen(_currentBackground, _screenCenterX - _backgroundOffset.x, 0, true); } else { -- cgit v1.2.3 From dfe143137aa89909c9bf0fd24a359be8af9c2834 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 30 Aug 2013 17:09:46 -0500 Subject: ZVISION: Remove extraneous TODO After redoing the math, I now know that the algorithm requires for(x) { for(y) {}} --- engines/zvision/render_table.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 55285b45e6..a4dfe67c53 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -163,7 +163,6 @@ void RenderTable::generatePanoramaLookupTable() { float fovInRadians = (_panoramaOptions.fieldOfView * M_PI / 180.0f); float cylinderRadius = halfHeight / tan(fovInRadians); - // TODO: Change the algorithm to write a whole row at a time instead of a whole column at a time. AKA: for(y) { for(x) {}} instead of for(x) { for(y) {}} for (uint x = 0; x < _numColumns; x++) { // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) // Alpha represents the horizontal angle between the viewer at the center of a cylinder and x @@ -173,7 +172,6 @@ void RenderTable::generatePanoramaLookupTable() { // We also scale it by _panoramaOptions.linearScale int32 xInCylinderCoords = int32(floor((cylinderRadius * _panoramaOptions.linearScale * alpha) + halfWidth)); - float cosAlpha = cos(alpha); for (uint y = 0; y < _numRows; y++) { -- cgit v1.2.3 From 3c3a6bd93542ad82bd7972050db141628b413b30 Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 30 Aug 2013 17:10:06 -0500 Subject: ZVISION: Fix typo in point range clipping --- engines/zvision/render_table.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index a4dfe67c53..0a83d5e4ae 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -62,7 +62,7 @@ void RenderTable::setRenderState(RenderState newState) { const Common::Point RenderTable::convertWarpedCoordToFlatCoord(const Common::Point &point) { // If we're outside the range of the RenderTable, no warping is happening. Return the maximum image coords - if (point.x >= (int16)_numColumns || point.y >= (int16)_numRows || point.x < 0 || point.y , 0) { + if (point.x >= (int16)_numColumns || point.y >= (int16)_numRows || point.x < 0 || point.y < 0) { int16 x = CLIP(point.x, 0, (int16)_numColumns); int16 y = CLIP(point.y, 0, (int16)_numRows); return Common::Point(x, y); -- cgit v1.2.3 From 94f350b1542e3129ad6c9597fe3fefdface444ae Mon Sep 17 00:00:00 2001 From: richiesams Date: Fri, 30 Aug 2013 17:10:31 -0500 Subject: ZVISION: Implement TILT RenderTable creation --- engines/zvision/render_table.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 0a83d5e4ae..b457ae0240 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -189,12 +189,35 @@ void RenderTable::generatePanoramaLookupTable() { } void RenderTable::generateTiltLookupTable() { - for (uint x = 0; x < _numColumns; x++) { - for (uint y = 0; y < _numRows; y++) { - uint32 index = y * _numColumns + x; + float halfWidth = (float)_numColumns / 2.0f; + float halfHeight = (float)_numRows / 2.0f; + + float fovInRadians = (_tiltOptions.fieldOfView * M_PI / 180.0f); + float cylinderRadius = halfWidth / tan(fovInRadians); + + for (uint y = 0; y < _numRows; y++) { + + // Add an offset of 0.01 to overcome zero tan/atan issue (horizontal line on half of screen) + // Alpha represents the horizontal angle between the viewer at the center of a cylinder and y + float alpha = atan(((float)y - halfHeight + 0.01f) / cylinderRadius); + + // To get y in cylinder coordinates, we just need to calculate the arc length + // We also scale it by _tiltOptions.linearScale + int32 yInCylinderCoords = int32(floor((cylinderRadius * _tiltOptions.linearScale * alpha) + halfHeight)); - _internalBuffer[index].x = 0; - _internalBuffer[index].y = 0; + float cosAlpha = cos(alpha); + uint32 columnIndex = y * _numColumns; + + for (uint x = 0; x < _numColumns; x++) { + // To calculate x in cylinder coordinates, we can do similar triangles comparison, + // comparing the triangle from the center to the screen and from the center to the edge of the cylinder + int32 xInCylinderCoords = int32(floor(halfWidth + ((float)x - halfWidth) * cosAlpha)); + + uint32 index = columnIndex + x; + + // Only store the (x,y) offsets instead of the absolute positions + _internalBuffer[index].x = xInCylinderCoords - x; + _internalBuffer[index].y = yInCylinderCoords - y; } } } -- cgit v1.2.3 From 97b0d5988ade1a2453e268706343d6aaacceb5de Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 17:53:13 -0500 Subject: ZVISION: Fix how LeverControl return routes are parsed --- engines/zvision/lever_control.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 2a5fe4fcac..3c452c3dd8 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -153,7 +153,7 @@ void LeverControl::parseLevFile(const Common::String &fileName) { _frameInfo[frameNumber].hotspot.bottom = y + _hotspotDelta.y; } - Common::StringTokenizer tokenizer(line, " ^="); + Common::StringTokenizer tokenizer(line, " ^=()"); tokenizer.nextToken(); tokenizer.nextToken(); @@ -168,8 +168,11 @@ void LeverControl::parseLevFile(const Common::String &fileName) { _frameInfo[frameNumber].directions.push_back(Direction(angle, toFrame)); } else if (token.hasPrefix("P")) { - uint to; - sscanf(token.c_str(), "P(%*u to %u)", &to); + // Format: P( to ) + tokenizer.nextToken(); + tokenizer.nextToken(); + token = tokenizer.nextToken(); + uint to = atoi(token.c_str()); _frameInfo[frameNumber].returnRoute.push_back(to); } -- cgit v1.2.3 From 1ad594bd30e238f4da7f686d2680abbc1e1450bd Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 17:53:37 -0500 Subject: ZVISION: Add default values for tilt options --- engines/zvision/render_table.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index b457ae0240..1f3e556090 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -52,7 +52,9 @@ void RenderTable::setRenderState(RenderState newState) { _panoramaOptions.reverse = false; break; case TILT: - + _tiltOptions.fieldOfView = 27.0f; + _tiltOptions.linearScale = 0.55f; + _tiltOptions.reverse = false; break; case FLAT: // Intentionally left empty -- cgit v1.2.3 From d2d375500954100cbb32a052baa00349ce1d3ec1 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 17:54:07 -0500 Subject: ZVISION: Fix tilt render table comment --- engines/zvision/render_table.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 1f3e556090..5fd7a16cac 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -200,7 +200,7 @@ void RenderTable::generateTiltLookupTable() { for (uint y = 0; y < _numRows; y++) { // Add an offset of 0.01 to overcome zero tan/atan issue (horizontal line on half of screen) - // Alpha represents the horizontal angle between the viewer at the center of a cylinder and y + // Alpha represents the vertical angle between the viewer at the center of a cylinder and y float alpha = atan(((float)y - halfHeight + 0.01f) / cylinderRadius); // To get y in cylinder coordinates, we just need to calculate the arc length -- cgit v1.2.3 From 04bf6f79e93d3a86e6ec2e8c391e59a5f1dd230c Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 17:54:34 -0500 Subject: ZVISION: Implement return pathing for LeverControls --- engines/zvision/lever_control.cpp | 37 ++++++++++++++++++++++++++++++------- engines/zvision/lever_control.h | 5 ++++- 2 files changed, 34 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 3c452c3dd8..91e54075b6 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -47,7 +47,9 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre _currentFrame(0), _lastRenderedFrame(0), _mouseIsCaptured(false), - _isReturning(false) { + _isReturning(false), + _accumulatedTime(0), + _returnRoutesCurrentFrame(0) { // Loop until we find the closing brace Common::String line = stream.readLine(); @@ -204,11 +206,9 @@ void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common:: _mouseIsCaptured = false; _engine->getScriptManager()->setStateValue(_key, _currentFrame); - if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { - - } - - // TODO: Animation reversal back to origin + _isReturning = true; + _returnRoutesCurrentProgress = _frameInfo[_currentFrame].returnRoute.begin(); + _returnRoutesCurrentFrame = _currentFrame; } bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { @@ -247,8 +247,31 @@ bool LeverControl::process(uint32 deltaTimeInMillis) { return false; } - // TODO: Implement reversal over time + if (_isReturning) { + _accumulatedTime += deltaTimeInMillis; + while (_accumulatedTime >= ANIMATION_FRAME_TIME) { + _accumulatedTime -= ANIMATION_FRAME_TIME; + if (_returnRoutesCurrentFrame == *_returnRoutesCurrentProgress) { + _returnRoutesCurrentProgress++; + } + if (_returnRoutesCurrentProgress == _frameInfo[_currentFrame].returnRoute.end()) { + _isReturning = false; + _currentFrame = _returnRoutesCurrentFrame; + _engine->getScriptManager()->setStateValue(_key, _currentFrame); + return false; + } + uint toFrame = *_returnRoutesCurrentProgress; + if (_returnRoutesCurrentFrame < toFrame) { + _returnRoutesCurrentFrame++; + } else if (_returnRoutesCurrentFrame > toFrame) { + _returnRoutesCurrentFrame--; + } + + renderFrame(_returnRoutesCurrentFrame); + } + } + return false; } diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h index d359318d2f..b5677a269e 100644 --- a/engines/zvision/lever_control.h +++ b/engines/zvision/lever_control.h @@ -61,7 +61,8 @@ private: }; enum { - ANGLE_DELTA = 30 // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA) + ANGLE_DELTA = 30, // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA) + ANIMATION_FRAME_TIME = 30 // In millis }; private: @@ -85,6 +86,8 @@ private: bool _isReturning; Common::Point _lastMousePos; Common::List::iterator _returnRoutesCurrentProgress; + uint _returnRoutesCurrentFrame; + uint32 _accumulatedTime; public: void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); -- cgit v1.2.3 From 07fdcdf312e5498508affe825db37a6f1644f738 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 18:09:24 -0500 Subject: ZVISION: Only do return pathing after the mouse is captured --- engines/zvision/lever_control.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 91e54075b6..744fde1e1c 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -203,12 +203,14 @@ void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common:: return; } - _mouseIsCaptured = false; - _engine->getScriptManager()->setStateValue(_key, _currentFrame); + if (_mouseIsCaptured) { + _mouseIsCaptured = false; + _engine->getScriptManager()->setStateValue(_key, _currentFrame); - _isReturning = true; - _returnRoutesCurrentProgress = _frameInfo[_currentFrame].returnRoute.begin(); - _returnRoutesCurrentFrame = _currentFrame; + _isReturning = true; + _returnRoutesCurrentProgress = _frameInfo[_currentFrame].returnRoute.begin(); + _returnRoutesCurrentFrame = _currentFrame; + } } bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { -- cgit v1.2.3 From 2ad40edd47098144cecb808cf308bca8329479ff Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 18:10:58 -0500 Subject: ZVISION: Limit tilt movement to the size of the image // TODO: Remove image wrapping logic for the vertical direction since this can never happen now --- engines/zvision/render_manager.cpp | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 96030ba2b9..ea34469baf 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -324,15 +324,7 @@ void RenderManager::moveBackground(int offset) { if (state == RenderTable::TILT) { _backgroundOffset += Common::Point(0, offset); - if (_backgroundOffset.x <= -_backgroundWidth) - _backgroundOffset.x += _backgroundWidth; - else if (_backgroundOffset.x >= _backgroundWidth) - _backgroundOffset.x -= _backgroundWidth; - - if (_backgroundOffset.y <= -_backgroundHeight) - _backgroundOffset.y += _backgroundHeight; - else if (_backgroundOffset.y >= _backgroundHeight) - _backgroundOffset.y -= _backgroundHeight; + _backgroundOffset.y = CLIP(_backgroundOffset.y, _screenCenterY, (int16)_backgroundHeight - _screenCenterY); renderImageToScreen(_currentBackground, 0, _screenCenterY - _backgroundOffset.y, true); } else if (state == RenderTable::PANORAMA) { @@ -343,11 +335,6 @@ void RenderManager::moveBackground(int offset) { else if (_backgroundOffset.x >= _backgroundWidth) _backgroundOffset.x -= _backgroundWidth; - if (_backgroundOffset.y <= -_backgroundHeight) - _backgroundOffset.y += _backgroundHeight; - else if (_backgroundOffset.y >= _backgroundHeight) - _backgroundOffset.y -= _backgroundHeight; - renderImageToScreen(_currentBackground, _screenCenterX - _backgroundOffset.x, 0, true); } else { renderImageToScreen(_currentBackground, 0, 0); -- cgit v1.2.3 From f1bd8de21dd504fd9b8fa07c76ab75b5c40d29cd Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 23:42:00 -0500 Subject: ZVISION: Overload ZVision::playAnimation to support general video files --- engines/zvision/animation.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ engines/zvision/zvision.h | 1 + 2 files changed, 45 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/animation.cpp b/engines/zvision/animation.cpp index 8ca892dfda..f43e854f73 100644 --- a/engines/zvision/animation.cpp +++ b/engines/zvision/animation.cpp @@ -23,6 +23,7 @@ #include "common/scummsys.h" #include "common/system.h" +#include "video/video_decoder.h" #include "zvision/zvision.h" #include "zvision/rlf_animation.h" @@ -84,4 +85,47 @@ void ZVision::playAnimation(RlfAnimation *animation, uint16 x, uint16 y, Dispose } } +void ZVision::playAnimation(Video::VideoDecoder *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse) { + _clock.stop(); + animation->start(); + + // Only continue while the video is still playing + while (!shouldQuit() && !animation->endOfVideo() && animation->isPlaying()) { + // Check for engine quit and video stop key presses + while (!animation->endOfVideo() && animation->isPlaying() && _eventMan->pollEvent(_event)) { + switch (_event.type) { + case Common::EVENT_KEYDOWN: + switch (_event.kbd.keycode) { + case Common::KEYCODE_q: + if (_event.kbd.hasFlags(Common::KBD_CTRL)) + quitGame(); + break; + case Common::KEYCODE_SPACE: + animation->stop(); + break; + default: + break; + } + default: + break; + } + } + + if (animation->needsUpdate()) { + const Graphics::Surface *frame = animation->decodeNextFrame(); + + if (frame) { + _system->copyRectToScreen((const byte *)frame->getPixels(), frame->pitch, x, y, frame->w, frame->h); + } + } + + // Always update the screen so the mouse continues to render + _system->updateScreen(); + + _system->delayMillis(animation->getTimeToNextFrame()); + } + + _clock.start(); +} + } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index a02fecc43d..f961f1fda9 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -126,6 +126,7 @@ public: void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true); void playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + void playAnimation(Video::VideoDecoder *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); /** * Utility method to cycle through all the cursors in the game. After -- cgit v1.2.3 From c3fcff96124190e847e714fbed23c60c1785c169 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 31 Aug 2013 23:42:56 -0500 Subject: ZVISION: Move TimerNode to it's own file --- engines/zvision/action_node.cpp | 13 ---------- engines/zvision/action_node.h | 19 +-------------- engines/zvision/actions.cpp | 1 + engines/zvision/module.mk | 1 + engines/zvision/timer_node.cpp | 46 +++++++++++++++++++++++++++++++++++ engines/zvision/timer_node.h | 53 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 31 deletions(-) create mode 100644 engines/zvision/timer_node.cpp create mode 100644 engines/zvision/timer_node.h (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.cpp b/engines/zvision/action_node.cpp index 8e354606f8..eeb8930924 100644 --- a/engines/zvision/action_node.cpp +++ b/engines/zvision/action_node.cpp @@ -28,19 +28,6 @@ namespace ZVision { -TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds) - : Control(engine, key), _timeLeft(timeInSeconds * 1000) { -} -bool TimerNode::process(uint32 deltaTimeInMillis) { - _timeLeft -= deltaTimeInMillis; - - if (_timeLeft <= 0) { - _engine->getScriptManager()->setStateValue(_key, 0); - return true; - } - - return false; -} } // End of namespace ZVision diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h index b0b8cae4b1..c9beb7b38e 100644 --- a/engines/zvision/action_node.h +++ b/engines/zvision/action_node.h @@ -29,24 +29,7 @@ namespace ZVision { -class ZVision; - -class TimerNode : public Control { -public: - TimerNode(ZVision *engine, uint32 key, uint timeInSeconds); - - /** - * Decrement the timer by the delta time. If the timer is finished, set the status - * in _globalState and let this node be deleted - * - * @param deltaTimeInMillis The number of milliseconds that have passed since last frame - * @return If true, the node can be deleted after process() finishes - */ - bool process(uint32 deltaTimeInMillis); - -private: - uint32 _timeLeft; -}; + } // End of namespace ZVision diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index d039f04d95..0265ebd410 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -33,6 +33,7 @@ #include "zvision/action_node.h" #include "zvision/zork_raw.h" #include "zvision/zork_avi_decoder.h" +#include "zvision/timer_node.h" namespace ZVision { diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 7412ad8916..48b8a66077 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -21,6 +21,7 @@ MODULE_OBJS := \ script_manager.o \ scripts.o \ single_value_container.o \ + timer_node.o \ utility.o \ video.o \ zvision.o \ diff --git a/engines/zvision/timer_node.cpp b/engines/zvision/timer_node.cpp new file mode 100644 index 0000000000..c9ef9d29d1 --- /dev/null +++ b/engines/zvision/timer_node.cpp @@ -0,0 +1,46 @@ +/* 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/scummsys.h" + +#include "zvision/timer_node.h" +#include "zvision/zvision.h" +#include "zvision/script_manager.h" + +namespace ZVision { + +TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds) + : Control(engine, key), _timeLeft(timeInSeconds * 1000) { +} + +bool TimerNode::process(uint32 deltaTimeInMillis) { + _timeLeft -= deltaTimeInMillis; + + if (_timeLeft <= 0) { + _engine->getScriptManager()->setStateValue(_key, 0); + return true; + } + + return false; +} + +} // End of namespace ZVision diff --git a/engines/zvision/timer_node.h b/engines/zvision/timer_node.h new file mode 100644 index 0000000000..d692f1f0ca --- /dev/null +++ b/engines/zvision/timer_node.h @@ -0,0 +1,53 @@ +/* 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 ZVISION_TIMER_NODE_H +#define ZVISION_TIMER_NODE_H + +#include "common/types.h" + +#include "zvision/control.h" + +namespace ZVision { + +class ZVision; + +class TimerNode : public Control { +public: + TimerNode(ZVision *engine, uint32 key, uint timeInSeconds); + + /** + * Decrement the timer by the delta time. If the timer is finished, set the status + * in _globalState and let this node be deleted + * + * @param deltaTimeInMillis The number of milliseconds that have passed since last frame + * @return If true, the node can be deleted after process() finishes + */ + bool process(uint32 deltaTimeInMillis); + +private: + uint32 _timeLeft; +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 78d5a41cd0812353e0dbc675f010540dc630f343 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 00:26:13 -0500 Subject: ZVISION: Call Surface::free() in the cursor destructor --- engines/zvision/cursor.cpp | 5 +++++ engines/zvision/cursor.h | 1 + 2 files changed, 6 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor.cpp b/engines/zvision/cursor.cpp index 4731d29f00..bb0700cebe 100644 --- a/engines/zvision/cursor.cpp +++ b/engines/zvision/cursor.cpp @@ -81,9 +81,14 @@ ZorkCursor &ZorkCursor::operator=(const ZorkCursor &other) { _hotspotX = other._hotspotX; _hotspotY = other._hotspotY; + _surface.free(); _surface.copyFrom(other._surface); return *this; } +ZorkCursor::~ZorkCursor() { + _surface.free(); +} + } // End of namespace ZVision diff --git a/engines/zvision/cursor.h b/engines/zvision/cursor.h index ec9f5ed0d7..805a8e7982 100644 --- a/engines/zvision/cursor.h +++ b/engines/zvision/cursor.h @@ -42,6 +42,7 @@ public: ZorkCursor(); ZorkCursor(const Common::String &fileName); ZorkCursor(const ZorkCursor &other); + ~ZorkCursor(); private: uint16 _width; -- cgit v1.2.3 From 34dcea106a2d1d7a7ba3412ef43ca547e67a66dd Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 00:27:03 -0500 Subject: ZVISION: Cleanup _activeControls in ScriptManager destructor --- engines/zvision/script_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 98bc2e3a3a..b95f2636b0 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -48,6 +48,9 @@ ScriptManager::~ScriptManager() { for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { delete (*iter); } + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + delete (*iter); + } } void ScriptManager::initialize() { -- cgit v1.2.3 From 4d86061b5714ea7e27edffc343572eb85c57a674 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 00:31:44 -0500 Subject: ZVISION: Cleanup all used memory in RLF animations --- engines/zvision/rlf_animation.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index df1fe118da..73fbe05bfc 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -72,6 +72,9 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) RlfAnimation::~RlfAnimation() { delete[] _currentFrameBuffer; + for (int i = 0; i < _frameCount; i++) { + delete[] _frames[i].encodedData; + } delete[] _frames; } -- cgit v1.2.3 From 98dc015dc1329ef233d4fe9606ab98c26b0f8438 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 00:32:12 -0500 Subject: ZVISION: Free the _currentBackground Surface in RenderManager destructor --- engines/zvision/render_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index ea34469baf..463faefdeb 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -54,6 +54,7 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, RenderManager::~RenderManager() { delete[] _workingWindowBuffer; + _currentBackground.free(); } void RenderManager::update(uint deltaTimeInMillis) { -- cgit v1.2.3 From efb0495758b8f5ee5f59d148a15cf03265cd6c2d Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 00:34:01 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/rlf_animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 73fbe05bfc..ffc272c1c8 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -72,7 +72,7 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) RlfAnimation::~RlfAnimation() { delete[] _currentFrameBuffer; - for (int i = 0; i < _frameCount; i++) { + for (uint i = 0; i < _frameCount; i++) { delete[] _frames[i].encodedData; } delete[] _frames; -- cgit v1.2.3 From b3a32746162399d065efc33b71770ddb6e3eeab0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 00:39:39 -0500 Subject: ZVISION: Remove unnecessary file.open() It's done inside readImageToSurface() and it no longer needs to be on the heap --- engines/zvision/render_manager.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 463faefdeb..837e3880c7 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -282,13 +282,6 @@ RenderTable *RenderManager::getRenderTable() { } void RenderManager::setBackgroundImage(const Common::String &fileName) { - Common::File *file = new Common::File; - - if (!file->open(fileName)) { - warning("Could not open file %s", fileName.c_str()); - return; - } - readImageToSurface(fileName, _currentBackground); moveBackground(0); -- cgit v1.2.3 From 5d86eb4a4af6416b8c40a6cb5aaf234bddabde95 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 01:23:17 -0500 Subject: ZVISION: Change ActionPlayAnimation::_loop refer to a count rather than a boolean _loopCount refers to the number of times an animation should be played, where 0 corresponds to infinite. --- engines/zvision/actions.cpp | 4 +--- engines/zvision/actions.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 0265ebd410..4c532ebf9d 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -224,15 +224,13 @@ bool ActionPreloadAnimation::execute(ZVision *engine) { ActionPlayAnimation::ActionPlayAnimation(const Common::String &line) { char fileName[25]; - uint loop; // The two %*u are always 0 and dont seem to have a use sscanf(line.c_str(), "%*[^:]:%*[^:]:%u(%25s %u %u %u %u %u %u %u %*u %*u %u %u)", - &_key, fileName, &_x, &_y, &_width, &_height, &_start, &_end, &loop, &_mask, &_framerate); + &_key, fileName, &_x, &_y, &_width, &_height, &_start, &_end, &_loopCount, &_mask, &_framerate); _fileName = Common::String(fileName); - _loop = loop == 1 ? true : false; } bool ActionPlayAnimation::execute(ZVision *engine) { diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 5e7c2c63e3..b36e277d0e 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -239,7 +239,7 @@ private: uint32 _end; uint _mask; uint _framerate; - bool _loop; + uint _loopCount; }; class ActionPreloadAnimation : public ResultAction { -- cgit v1.2.3 From 9ea91f5c9c311276339e93ef64eaa53fd4435692 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:44:26 -0500 Subject: ZVISION: Convert ZVision singleton accessors to be inline --- engines/zvision/zvision.cpp | 16 ---------------- engines/zvision/zvision.h | 10 +++++----- 2 files changed, 5 insertions(+), 21 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index b5cae8acd3..eb474c75ed 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -164,24 +164,8 @@ void ZVision::pauseEngineIntern(bool pause) { } } -ScriptManager *ZVision::getScriptManager() const { - return _scriptManager; } -RenderManager *ZVision::getRenderManager() const { - return _renderManager; -} - -CursorManager *ZVision::getCursorManager() const { - return _cursorManager; -} - -Common::RandomSource *ZVision::getRandomSource() const { - return _rnd; -} - -ZVisionGameId ZVision::getGameId() const { - return _gameDescription->gameId; } void ZVision::cycleThroughCursors() { diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index f961f1fda9..331fa2a9f8 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -108,11 +108,11 @@ public: Common::Error run(); void pauseEngineIntern(bool pause); - ScriptManager *getScriptManager() const; - RenderManager *getRenderManager() const; - CursorManager *getCursorManager() const; - Common::RandomSource *getRandomSource() const; - ZVisionGameId getGameId() const; + ScriptManager *getScriptManager() const { return _scriptManager; } + RenderManager *getRenderManager() const { return _renderManager; } + CursorManager *getCursorManager() const { return _cursorManager; } + Common::RandomSource *getRandomSource() const { return _rnd; } + ZVisionGameId getGameId() const { return _gameDescription->gameId; } /** * Play a video until it is finished. This is a blocking call. It will call -- cgit v1.2.3 From 117eea1be6231ad26fe43f9080fa572b4deb73cb Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:46:14 -0500 Subject: ZVISION: Allow changeLocation to be executed right away instead of next frame --- engines/zvision/script_manager.cpp | 22 +++++++++------------- engines/zvision/script_manager.h | 4 +--- 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index b95f2636b0..f3c945d658 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -181,6 +181,9 @@ void ScriptManager::checkPuzzleCriteria() { bool shouldContinue = true; for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { shouldContinue = shouldContinue && (*resultIter)->execute(_engine); + if (!shouldContinue) { + break; + } } // Set the puzzle as completed @@ -258,18 +261,11 @@ bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Commo } void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 offset) { - _nextLocation.world = world; - _nextLocation.room = room; - _nextLocation.node = node; - _nextLocation.view = view; - _nextLocation.offset = offset; - - _changeLocation = true; -} + assert(world != 0); + debug("Changing location to: %c %c %c %c %u", world, room, node, view, offset); -void ScriptManager::changeLocationIntern() { - assert(_nextLocation.world != 0); - debug("Changing location to: %c %c %c %c %u", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view, _nextLocation.offset); + // Auto save + _engine->getSaveManager()->autoSave(); // Clear all the containers _referenceTable.clear(); @@ -290,11 +286,11 @@ void ScriptManager::changeLocationIntern() { _engine->getRenderManager()->setBackgroundVelocity(0); // Parse into puzzles and controls - Common::String fileName = Common::String::format("%c%c%c%c.scr", _nextLocation.world, _nextLocation.room, _nextLocation.node, _nextLocation.view); + Common::String fileName = Common::String::format("%c%c%c%c.scr", world, room, node, view); parseScrFile(fileName); // Change the background position - _engine->getRenderManager()->setBackgroundPosition(_nextLocation.offset); + _engine->getRenderManager()->setBackgroundPosition(offset); // Enable all the controls for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 1a272f1970..75be66c3f0 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -70,8 +70,7 @@ private: /** Holds the currently active controls */ Common::List _activeControls; - Location _nextLocation; - bool _changeLocation; + Location _currentLocation; public: void initialize(); @@ -113,7 +112,6 @@ public: private: void createReferenceTable(); - void changeLocationIntern(); void updateNodes(uint deltaTimeMillis); void checkPuzzleCriteria(); -- cgit v1.2.3 From dd307c2484f7d251fa447bc6c05a3c4512928681 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:48:11 -0500 Subject: ZVISION: Create method to get the current background offset --- engines/zvision/render_manager.cpp | 12 ++++++++++++ engines/zvision/render_manager.h | 1 + 2 files changed, 13 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 837e3880c7..e394baf504 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -335,4 +335,16 @@ void RenderManager::moveBackground(int offset) { } } +uint32 RenderManager::getCurrentBackgroundOffset() { + RenderTable::RenderState state = _renderTable.getRenderState(); + + if (state == RenderTable::PANORAMA) { + return _backgroundOffset.x; + } else if (state == RenderTable::TILT) { + return _backgroundOffset.y; + } else { + return 0; + } +} + } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 41dedab792..1dcbf76d8c 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -166,6 +166,7 @@ public: const Common::Point screenSpaceToImageSpace(const Common::Point &point); RenderTable *getRenderTable(); + uint32 getCurrentBackgroundOffset(); private: /** -- cgit v1.2.3 From 9dd54a16e00be09cf549e38b03387e28efe9195d Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:53:30 -0500 Subject: ZVISION: Remove zero valued entries in the global state table once a frame --- engines/zvision/script_manager.cpp | 14 ++++++++++++++ engines/zvision/script_manager.h | 1 + 2 files changed, 15 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index f3c945d658..45e1459293 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -196,6 +196,17 @@ void ScriptManager::checkPuzzleCriteria() { } } +void ScriptManager::cleanStateTable() { + for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); iter++) { + // If the value is equal to zero, we can purge it since getStateValue() + // will return zero if _globalState doesn't contain a key + if ((*iter)._value == 0) { + // Remove the node + _globalState.erase(iter); + } + } +} + uint ScriptManager::getStateValue(uint32 key) { if (_globalState.contains(key)) return _globalState[key]; @@ -285,6 +296,9 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, // Reset the background velocity _engine->getRenderManager()->setBackgroundVelocity(0); + // Clean the global state table + cleanStateTable(); + // Parse into puzzles and controls Common::String fileName = Common::String::format("%c%c%c%c.scr", world, room, node, view); parseScrFile(fileName); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 75be66c3f0..723f4fe032 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -114,6 +114,7 @@ private: void createReferenceTable(); void updateNodes(uint deltaTimeMillis); void checkPuzzleCriteria(); + void cleanStateTable(); // TODO: Make this private. It was only made public so Console::cmdParseAllScrFiles() could use it public: -- cgit v1.2.3 From b45c9e7c2683ee73ca1f54718b630597e9bc42c9 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:56:06 -0500 Subject: ZVISION: Create method for getting the current location --- engines/zvision/script_manager.cpp | 22 +++++++++++++++------- engines/zvision/script_manager.h | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 45e1459293..6330e206be 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -37,8 +37,7 @@ namespace ZVision { ScriptManager::ScriptManager(ZVision *engine) - : _engine(engine), - _changeLocation(false) { + : _engine(engine) { } ScriptManager::~ScriptManager() { @@ -61,11 +60,6 @@ void ScriptManager::initialize() { void ScriptManager::update(uint deltaTimeMillis) { updateNodes(deltaTimeMillis); checkPuzzleCriteria(); - - if (_changeLocation) { - changeLocationIntern(); - _changeLocation = false; - } } void ScriptManager::createReferenceTable() { @@ -333,6 +327,20 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, // Create the puzzle reference table createReferenceTable(); + + // Update _currentLocation + _currentLocation.world = world; + _currentLocation.room = room; + _currentLocation.node = node; + _currentLocation.view = view; + _currentLocation.offset = offset; +} + +Location ScriptManager::getCurrentLocation() const { + Location location = _currentLocation; + location.offset = _engine->getRenderManager()->getCurrentBackgroundOffset(); + + return location; } } // End of namespace ZVision diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 723f4fe032..96123a8468 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -110,6 +110,8 @@ public: void changeLocation(char world, char room, char node, char view, uint32 offset); + Location getCurrentLocation() const; + private: void createReferenceTable(); void updateNodes(uint deltaTimeMillis); -- cgit v1.2.3 From 11bf2405f80378dd49d539d61384bad7b32daad0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:56:55 -0500 Subject: ZVISION: Create base methods for Control serialization --- engines/zvision/control.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index b16ca7f73d..9144c32dd4 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -29,6 +29,7 @@ namespace Common { class SeekableReadStream; struct Point; +class WriteStream; } namespace ZVision { @@ -74,6 +75,36 @@ public: * @return If true, the node can be deleted after process() finishes */ virtual bool process(uint32 deltaTimeInMillis) { return false; } + /** + * Serialize a Control for save game use. This should only be used if a Control needs + * to save values that would be different from initialization. AKA a TimerNode needs to + * store the amount of time left on the timer. Any Controls overriding this *MUST* write + * their key as the first data outputted. The default implementation is NOP. + * + * NOTE: If this method is overridden, you MUST also override deserialize() + * and needsSerialization() + * + * @param stream Stream to write any needed data to + */ + virtual void serialize(Common::WriteStream *stream) {} + /** + * De-serialize data from a save game stream. This should only be implemented if the + * Control also implements serialize(). The calling method assumes the size of the + * data read from the stream exactly equals that written in serialize(). The default + * implementation is NOP. + * + * NOTE: If this method is overridden, you MUST also override serialize() + * and needsSerialization() + * + * @param stream Save game file stream + */ + virtual void deserialize(Common::SeekableReadStream *stream) {} + /** + * If a Control overrides serialize() and deserialize(), this should return true + * + * @return Does the Control need save game serialization? + */ + virtual inline bool needsSerialization() { return false; } protected: ZVision * _engine; -- cgit v1.2.3 From ac578bf9b7b9c58dbaad58c874517b7af45dfa3f Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:57:19 -0500 Subject: ZVISION: Implement TimerNode serialization --- engines/zvision/timer_node.cpp | 11 +++++++++++ engines/zvision/timer_node.h | 3 +++ 2 files changed, 14 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/timer_node.cpp b/engines/zvision/timer_node.cpp index c9ef9d29d1..81468dbb0b 100644 --- a/engines/zvision/timer_node.cpp +++ b/engines/zvision/timer_node.cpp @@ -22,6 +22,8 @@ #include "common/scummsys.h" +#include "common/stream.h" + #include "zvision/timer_node.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" @@ -43,4 +45,13 @@ bool TimerNode::process(uint32 deltaTimeInMillis) { return false; } +void TimerNode::serialize(Common::WriteStream *stream) { + stream->writeUint32LE(_key); + stream->writeUint32LE(_timeLeft); +} + +void TimerNode::deserialize(Common::SeekableReadStream *stream) { + _timeLeft = stream->readUint32LE(); +} + } // End of namespace ZVision diff --git a/engines/zvision/timer_node.h b/engines/zvision/timer_node.h index d692f1f0ca..21c344bb15 100644 --- a/engines/zvision/timer_node.h +++ b/engines/zvision/timer_node.h @@ -43,6 +43,9 @@ public: * @return If true, the node can be deleted after process() finishes */ bool process(uint32 deltaTimeInMillis); + void serialize(Common::WriteStream *stream); + void deserialize(Common::SeekableReadStream *stream); + inline bool needsSerialization() { return true; } private: uint32 _timeLeft; -- cgit v1.2.3 From 644af30df572f4965d63e1dba77c574a1d5ad69a Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:58:25 -0500 Subject: ZVISION: Create ScriptManager state table serialization methods --- engines/zvision/script_manager.cpp | 24 ++++++++++++++++++++++++ engines/zvision/script_manager.h | 2 ++ 2 files changed, 26 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 6330e206be..25cbc6d285 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -25,11 +25,13 @@ #include "common/algorithm.h" #include "common/hashmap.h" #include "common/debug.h" +#include "common/stream.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" #include "zvision/cursor_manager.h" +#include "zvision/save_manager.h" #include "zvision/actions.h" #include "zvision/action_node.h" #include "zvision/utility.h" @@ -336,6 +338,28 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, _currentLocation.offset = offset; } +void ScriptManager::serializeStateTable(Common::WriteStream *stream) { + // Write the number of state value entries + stream->writeUint32LE(_globalState.size()); + + for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); iter++) { + // Write out the key/value pair + stream->writeUint32LE((*iter)._key); + stream->writeUint32LE((*iter)._value); + } +} + +void ScriptManager::deserializeStateTable(Common::SeekableReadStream *stream) { + // Read the number of key/value pairs + uint32 numberOfPairs = stream->readUint32LE(); + + for (uint32 i = 0; i < numberOfPairs; i++) { + uint32 key = stream->readUint32LE(); + uint32 value = stream->readUint32LE(); + setStateValue(key, value); + } +} + Location ScriptManager::getCurrentLocation() const { Location location = _currentLocation; location.offset = _engine->getRenderManager()->getCurrentBackgroundOffset(); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 96123a8468..c5377504a8 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -110,6 +110,8 @@ public: void changeLocation(char world, char room, char node, char view, uint32 offset); + void serializeStateTable(Common::WriteStream *stream); + void deserializeStateTable(Common::SeekableReadStream *stream); Location getCurrentLocation() const; private: -- cgit v1.2.3 From 23ae67c7776f5f3a2207109e7d6cdaef16940979 Mon Sep 17 00:00:00 2001 From: richiesams Date: Tue, 3 Sep 2013 23:59:00 -0500 Subject: ZVISION: Create ScriptManager _activeControls serialization methods --- engines/zvision/script_manager.cpp | 30 ++++++++++++++++++++++++++++++ engines/zvision/script_manager.h | 3 +++ 2 files changed, 33 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 25cbc6d285..d5fcf81ed5 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -360,6 +360,36 @@ void ScriptManager::deserializeStateTable(Common::SeekableReadStream *stream) { } } +void ScriptManager::serializeControls(Common::WriteStream *stream) { + // Count how many controls need to save their data + // Because WriteStream isn't seekable + uint32 numberOfControlsNeedingSerialization = 0; + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + if ((*iter)->needsSerialization()) { + numberOfControlsNeedingSerialization++; + } + } + stream->writeUint32LE(numberOfControlsNeedingSerialization); + + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + (*iter)->serialize(stream); + } +} + +void ScriptManager::deserializeControls(Common::SeekableReadStream *stream) { + uint32 numberOfControls = stream->readUint32LE(); + + for (uint32 i = 0; i < numberOfControls; i++) { + uint32 key = stream->readUint32LE(); + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + if ((*iter)->getKey() == key) { + (*iter)->deserialize(stream); + break; + } + } + } +} + Location ScriptManager::getCurrentLocation() const { Location location = _currentLocation; location.offset = _engine->getRenderManager()->getCurrentBackgroundOffset(); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index c5377504a8..d2ad4acfff 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -112,6 +112,9 @@ public: void serializeStateTable(Common::WriteStream *stream); void deserializeStateTable(Common::SeekableReadStream *stream); + void serializeControls(Common::WriteStream *stream); + void deserializeControls(Common::SeekableReadStream *stream); + Location getCurrentLocation() const; private: -- cgit v1.2.3 From 235620750a493afdb592f36521fb693533c6dec0 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 4 Sep 2013 00:12:41 -0500 Subject: ZVISION: Create methods for generating save file names --- engines/zvision/zvision.cpp | 4 ++++ engines/zvision/zvision.h | 3 +++ 2 files changed, 7 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index eb474c75ed..85e357e80f 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -164,8 +164,12 @@ void ZVision::pauseEngineIntern(bool pause) { } } +Common::String ZVision::generateSaveFileName(uint slot) { + return Common::String::format("%s.%02u", _targetName.c_str(), slot); } +Common::String ZVision::generateAutoSaveFileName() { + return Common::String::format("%s.auto", _targetName.c_str()); } void ZVision::cycleThroughCursors() { diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 331fa2a9f8..a43855737d 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -135,6 +135,9 @@ public: */ void cycleThroughCursors(); + Common::String generateSaveFileName(uint slot); + Common::String generateAutoSaveFileName(); + private: void initialize(); -- cgit v1.2.3 From 488484d2dccc146421da452420a3966a40970c55 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 4 Sep 2013 00:17:37 -0500 Subject: ZVISION: Implement SaveManager --- engines/zvision/module.mk | 1 + engines/zvision/save_manager.cpp | 176 +++++++++++++++++++++++++++++++++++++++ engines/zvision/save_manager.h | 39 ++++++++- 3 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 engines/zvision/save_manager.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 48b8a66077..c8c60ca8ce 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -17,6 +17,7 @@ MODULE_OBJS := \ render_manager.o \ render_table.o \ rlf_animation.o \ + save_manager.o \ scr_file_handling.o \ script_manager.o \ scripts.o \ diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp new file mode 100644 index 0000000000..9611b9c9b7 --- /dev/null +++ b/engines/zvision/save_manager.cpp @@ -0,0 +1,176 @@ +/* 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/scummsys.h" + +#include "common/system.h" + +#include "graphics/surface.h" +#include "graphics/thumbnail.h" + +#include "zvision/save_manager.h" +#include "zvision/zvision.h" +#include "zvision/script_manager.h" + + +namespace ZVision { + +const uint32 SaveManager::SAVEGAME_ID = MKTAG('Z', 'E', 'N', 'G'); + +void SaveManager::saveGame(uint slot, const Common::String &saveName) { + Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); + Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot)); + + // Write out the savegame header + file->writeUint32BE(SAVEGAME_ID); + + // Write savegame name + file->writeString(saveName); + file->writeByte(0); + + // We can't call writeGameSaveData because the save menu is actually + // a room, so writeGameSaveData would save us in the save menu. + // However, an auto save is performed before each room change, so we + // can copy the data from there. We can guarantee that an auto save file will + // exist before this is called because the save menu can only be accessed + // after the first room (the main menu) has loaded. + Common::InSaveFile *autoSaveFile = saveFileManager->openForLoading(_engine->generateAutoSaveFileName()); + + // Skip over the header info + autoSaveFile->readSint32BE(); // SAVEGAME_ID + autoSaveFile->seek(5, SEEK_CUR); // The string "auto" with terminating NULL + + // Read the rest to a buffer + uint32 size = autoSaveFile->size() - autoSaveFile->pos(); + byte *buffer = new byte[size]; + autoSaveFile->read(buffer, size); + + // Then write the buffer to the new file + file->write(buffer, size); + + // Cleanup + delete[] buffer; + file->finalize(); +} + +void SaveManager::autoSave() { + Common::OutSaveFile *file = g_system->getSavefileManager()->openForSaving(_engine->generateAutoSaveFileName()); + + // Write out the savegame header + file->writeUint32BE(SAVEGAME_ID); + + file->writeString("auto"); + file->writeByte(0); + + writeSaveGameData(file); + + file->finalize(); +} + +void SaveManager::writeSaveGameData(Common::OutSaveFile *file) { + // Create a thumbnail and save it + Graphics::saveThumbnail(*file); + + // Write out the save date/time + TimeDate td; + g_system->getTimeAndDate(td); + file->writeSint16LE(td.tm_year + 1900); + file->writeSint16LE(td.tm_mon + 1); + file->writeSint16LE(td.tm_mday); + file->writeSint16LE(td.tm_hour); + file->writeSint16LE(td.tm_min); + + ScriptManager *scriptManager = _engine->getScriptManager(); + // Write out the current location + Location currentLocation = scriptManager->getCurrentLocation(); + file->writeByte(currentLocation.world); + file->writeByte(currentLocation.room); + file->writeByte(currentLocation.node); + file->writeByte(currentLocation.view); + file->writeUint32LE(currentLocation.offset); + + // Write out the current state table values + scriptManager->serializeStateTable(file); + + // Write out any controls needing to save state + scriptManager->serializeControls(file); +} + +Common::Error SaveManager::loadGame(uint slot) { + Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(_engine->generateSaveFileName(slot)); + if (saveFile == 0) { + return Common::kPathDoesNotExist; + } + + // Read the header + SaveGameHeader header; + if (!readSaveGameHeader(saveFile, header)) { + return Common::kUnknownError; + } + + char world = (char)saveFile->readByte(); + char room = (char)saveFile->readByte(); + char node = (char)saveFile->readByte(); + char view = (char)saveFile->readByte(); + uint32 offset = (char)saveFile->readUint32LE(); + + ScriptManager *scriptManager = _engine->getScriptManager(); + // Load the room + scriptManager->changeLocation(world, room, node, view, offset); + + // Update the state table values + scriptManager->deserializeStateTable(saveFile); + + // Update the controls + scriptManager->deserializeControls(saveFile); + + return Common::kNoError; +} + +bool SaveManager::readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header) { + if (in->readSint32BE() != SAVEGAME_ID) { + warning("File is not a ZVision save file. Aborting load"); + return false; + } + + // Read in the save name + header.saveName.clear(); + char ch; + while ((ch = (char)in->readByte()) != '\0') + header.saveName += ch; + + // Get the thumbnail + header.thumbnail = Graphics::loadThumbnail(*in); + if (!header.thumbnail) + return false; + + // Read in save date/time + header.saveYear = in->readSint16LE(); + header.saveMonth = in->readSint16LE(); + header.saveDay = in->readSint16LE(); + header.saveHour = in->readSint16LE(); + header.saveMinutes = in->readSint16LE(); + + return true; +} + +} // End of namespace ZVision diff --git a/engines/zvision/save_manager.h b/engines/zvision/save_manager.h index 487cf203fb..ae65750b42 100644 --- a/engines/zvision/save_manager.h +++ b/engines/zvision/save_manager.h @@ -23,6 +23,43 @@ #ifndef ZVISION_SAVE_MANAGER_H #define ZVISION_SAVE_MANAGER_H -// TODO: Implement SaveManager +#include "common/types.h" + +#include "common/savefile.h" + +namespace Common { +class String; +} + +namespace ZVision { + +class ZVision; + +struct SaveGameHeader { + Common::String saveName; + Graphics::Surface *thumbnail; + int saveYear, saveMonth, saveDay; + int saveHour, saveMinutes; +}; + +class SaveManager { +public: + SaveManager(ZVision *engine); + +private: + ZVision *_engine; + static const uint32 SAVEGAME_ID; + +public: + void autoSave(); + void saveGame(uint slot, const Common::String &saveName); + Common::Error loadGame(uint slot); + +private: + void writeSaveGameData(Common::OutSaveFile *file); + bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header); +}; + +} // End of namespace ZVision #endif -- cgit v1.2.3 From 7ff45447adca39bca5be78bac34e8f900644edae Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 4 Sep 2013 00:18:05 -0500 Subject: ZVISION: Create an instance of SaveManager --- engines/zvision/zvision.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index a43855737d..1a259d0a22 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -48,6 +48,7 @@ class Console; class ScriptManager; class RenderManager; class CursorManager; +class SaveManager; class RlfAnimation; // our engine debug channels @@ -95,6 +96,7 @@ private: ScriptManager *_scriptManager; RenderManager *_renderManager; CursorManager *_cursorManager; + SaveManager *_saveManager; // Clock Clock _clock; @@ -111,6 +113,7 @@ public: ScriptManager *getScriptManager() const { return _scriptManager; } RenderManager *getRenderManager() const { return _renderManager; } CursorManager *getCursorManager() const { return _cursorManager; } + SaveManager *getSaveManager() const { return _saveManager; } Common::RandomSource *getRandomSource() const { return _rnd; } ZVisionGameId getGameId() const { return _gameDescription->gameId; } -- cgit v1.2.3 From 150a4793a670fb06b7997d7964f9626f3a238766 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 4 Sep 2013 00:19:03 -0500 Subject: ZVISION: Initialize Location to the main menu This ensures that the first auto save of the game will have a useful location --- engines/zvision/script_manager.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index d2ad4acfff..61ad4fa87a 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -39,6 +39,8 @@ namespace ZVision { class ZVision; struct Location { + Location() : world('g'), room('a'), node('r'), view('y'), offset(0) {} + char world; char room; char node; -- cgit v1.2.3 From 2dab04e14b82a110ea8b49b2f6778b5a5fe79375 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 6 Sep 2013 22:29:19 -0500 Subject: ZVISION: Do full working window warp instead of image at a time --- engines/zvision/render_manager.cpp | 77 +++++++++++++++++++++++++++++++------- engines/zvision/render_manager.h | 17 ++++++--- engines/zvision/render_table.cpp | 50 +++++++++---------------- engines/zvision/render_table.h | 2 +- engines/zvision/zvision.cpp | 5 ++- 5 files changed, 96 insertions(+), 55 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index e394baf504..6c0e8d24f6 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -34,7 +34,7 @@ namespace ZVision { -RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat) +RenderManager::RenderManager(OSystem *system, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat) : _system(system), _workingWidth(workingWindow.width()), _workingHeight(workingWindow.height()), @@ -49,12 +49,14 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, _accumulatedVelocityMilliseconds(0), _renderTable(_workingWidth, _workingHeight) { - _workingWindowBuffer = new uint16[_workingWidth *_workingHeight]; + _workingWindowBuffer.create(_workingWidth, _workingHeight, _pixelFormat); + _backBuffer.create(windowWidth, windowHeight, pixelFormat); } RenderManager::~RenderManager() { - delete[] _workingWindowBuffer; + _workingWindowBuffer.free(); _currentBackground.free(); + _backBuffer.free(); } void RenderManager::update(uint deltaTimeInMillis) { @@ -75,14 +77,29 @@ void RenderManager::update(uint deltaTimeInMillis) { } } -void RenderManager::clearWorkingWindowToColor(uint16 color) { +void RenderManager::renderBackbufferToScreen() { + //RenderTable::RenderState state = _renderTable.getRenderState(); + //if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + // _renderTable.mutateImage((uint16 *)_workingWindowBuffer.getPixels(), (uint16 *)_backBuffer.getBasePtr(_workingWindow.left, _workingWindow.top), _backBuffer.w); + //} else { + //_system->copyRectToScreen(_workingWindowBuffer.getPixels(), _workingWindowBuffer.pitch, _workingWindow.left, _workingWindow.top, _workingWindowBuffer.w, _workingWindowBuffer.h); + //} + + // TODO: Add menu rendering + + //_system->copyRectToScreen(_backBuffer.getPixels(), _backBuffer.pitch, 0, 0, _backBuffer.w, _backBuffer.h); +} + +void RenderManager::clearWorkingWindowTo555Color(uint16 color) { uint32 workingWindowSize = _workingWidth * _workingHeight; + byte r, g, b; + Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0).colorToRGB(color, r, g, b); + uint16 colorIn565 = _pixelFormat.RGBToColor(r, g, b); + uint16 *bufferPtr = (uint16 *)_workingWindowBuffer.getPixels(); for (uint32 i = 0; i < workingWindowSize; i++) { - _workingWindowBuffer[i] = color; + bufferPtr[i] = color; } - - _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), _workingWindow.left, _workingWindow.top, _workingWidth, _workingHeight); } void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap) { @@ -136,13 +153,7 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (!subRect.isValidRect() || subRect.isEmpty()) return; - if (_renderTable.getRenderState() == RenderTable::FLAT) { - _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); - } else { - _renderTable.mutateImage((uint16 *)surface.getPixels(), _workingWindowBuffer, surface.w, surface.h, destinationX, destinationY, subRect, wrap); - - _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); - } + _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX, destinationY, subRect.width(), subRect.height()/*, wrap*/); } void RenderManager::renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap) { @@ -250,6 +261,44 @@ void RenderManager::readImageToSurface(const Common::String &fileName, Graphics: destination.convertToInPlace(_pixelFormat); } +void RenderManager::renderRectToWorkingWindow(uint16 *buffer, int32 destX, int32 destY, int32 width, int32 height, bool wrap) { + uint32 destOffset = 0; + uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(destX, destY); + + for (int32 y = 0; y < height; y++) { + for (int32 x = 0; x < width; x++) { + int32 sourceYIndex = y; + int32 sourceXIndex = x; + + if (wrap) { + while (sourceXIndex >= width) { + sourceXIndex -= width; + } + while (sourceXIndex < 0) { + sourceXIndex += width; + } + + while (sourceYIndex >= height) { + sourceYIndex -= height; + } + while (sourceYIndex < 0) { + sourceYIndex += height; + } + } else { + // Clamp the yIndex to the size of the image + sourceYIndex = CLIP(sourceYIndex, 0, height - 1); + + // Clamp the xIndex to the size of the image + sourceXIndex = CLIP(sourceXIndex, 0, width - 1); + } + + workingWindowBufferPtr[destOffset + x] = buffer[sourceYIndex * width + sourceXIndex]; + } + + destOffset += _workingWidth; + } +} + const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { // Convert from screen space to working window space Common::Point newPoint(point - Common::Point(_workingWindow.left, _workingWindow.top)); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 1dcbf76d8c..bf44c884e8 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -45,7 +45,7 @@ namespace ZVision { class RenderManager { public: - RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat); + RenderManager(OSystem *system, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat); ~RenderManager(); private: @@ -54,7 +54,8 @@ private: // A buffer the exact same size as the workingWindow // It's used for panorama/tilt warping and for clearing the workingWindow to a single color - uint16 *_workingWindowBuffer; + Graphics::Surface _workingWindowBuffer; + Graphics::Surface _backBuffer; /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ const int _workingWidth; @@ -90,9 +91,6 @@ private: /** Holds any 'leftover' milliseconds between frames */ uint _accumulatedVelocityMilliseconds; - // TODO: Potentially merge this buffer and _workingWindowBuffer - byte *_scaledVideoFrameBuffer; - public: void initialize(); /** @@ -102,12 +100,17 @@ public: */ void update(uint deltaTimeInMillis); + /** + * Renders the current state of the backbuffer to the screen + */ + void renderBackbufferToScreen(); + /** * Fills the entire workingWindow with the specified color * * @param color The color to fill the working window with. (In RGB 555) */ - void clearWorkingWindowToColor(uint16 color); + void clearWorkingWindowTo555Color(uint16 color); /** * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. @@ -186,6 +189,8 @@ private: void readImageToSurface(const Common::String &fileName, Graphics::Surface &destination); + void renderRectToWorkingWindow(uint16 *buffer, int32 x, int32 y, int32 width, int32 height, bool wrap); + void moveBackground(int offset); }; diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 5fd7a16cac..c72775b1ab 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -100,45 +100,29 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { return returnColor; } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap) { - for (int16 y = subRect.top; y < subRect.bottom; y++) { - int16 normalizedY = y - subRect.top; - int32 internalColumnIndex = (normalizedY + destinationY) * _numColumns; - int32 destColumnIndex = normalizedY * _numColumns; +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint16 destWidth) { + uint32 destColumnOffset = 0; - for (int16 x = subRect.left; x < subRect.right; x++) { - int16 normalizedX = x - subRect.left; + for (int16 y = 0; y < _numRows; y++) { + int32 sourceColumnOffset = y * _numColumns; - int32 index = internalColumnIndex + normalizedX + destinationX; + for (int16 x = 0; x < _numColumns; x++) { + int32 index = sourceColumnOffset + x; // RenderTable only stores offsets from the original coordinates - int16 sourceYIndex = y + _internalBuffer[index].y; - int16 sourceXIndex = x + _internalBuffer[index].x; - - if (wrap) { - while (sourceXIndex >= imageWidth) { - sourceXIndex -= imageWidth; - } - while (sourceXIndex < 0) { - sourceXIndex += imageWidth; - } - - while (sourceYIndex >= imageHeight) { - sourceYIndex -= imageHeight; - } - while (sourceYIndex < 0) { - sourceYIndex += imageHeight; - } - } else { - // Clamp the yIndex to the size of the image - sourceYIndex = CLIP(sourceYIndex, 0, imageHeight - 1); - - // Clamp the xIndex to the size of the image - sourceXIndex = CLIP(sourceXIndex, 0, imageWidth - 1); - } + int32 sourceYIndex = y + _internalBuffer[index].y; + int32 sourceXIndex = x + _internalBuffer[index].x; + + // Clamp the yIndex to the size of the image + sourceYIndex = CLIP(sourceYIndex, 0, _numRows - 1); + + // Clamp the xIndex to the size of the image + sourceXIndex = CLIP(sourceXIndex, 0, _numColumns - 1); - destBuffer[destColumnIndex + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; + destBuffer[destColumnOffset + x] = sourceBuffer[sourceYIndex * _numColumns + sourceXIndex]; } + + destColumnOffset += destWidth; } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index e5820803cb..737fc84bfc 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -66,7 +66,7 @@ public: const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); - void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint16 destWidth); void generateRenderTable(); void setPanoramaFoV(float fov); diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 85e357e80f..f8580703ca 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -69,7 +69,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); - _renderManager = new RenderManager(_system, _workingWindow, _pixelFormat); + _renderManager = new RenderManager(_system, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _pixelFormat); debug("ZVision::ZVision"); } @@ -141,6 +141,9 @@ Common::Error ZVision::run() { _renderManager->update(deltaTime); _scriptManager->update(deltaTime); + // Render the backBuffer to the screen + _renderManager->renderBackbufferToScreen(); + // Update the screen _system->updateScreen(); -- cgit v1.2.3 From 6ce62475ca19e4c395ad0e341d9875fb8825fde4 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 6 Sep 2013 22:29:48 -0500 Subject: ZVISION: Disable saving until it can be fixed --- engines/zvision/script_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index d5fcf81ed5..84d39ffe06 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -272,7 +272,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, debug("Changing location to: %c %c %c %c %u", world, room, node, view, offset); // Auto save - _engine->getSaveManager()->autoSave(); + //_engine->getSaveManager()->autoSave(); // Clear all the containers _referenceTable.clear(); -- cgit v1.2.3 From b6366a2697f9d604fbb19ed38f1a1e51cf0d2b7f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 6 Sep 2013 22:45:41 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/render_table.cpp | 18 +++++++++--------- engines/zvision/render_table.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index c72775b1ab..3e7a86e348 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -100,24 +100,24 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { return returnColor; } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint16 destWidth) { +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth) { uint32 destColumnOffset = 0; - for (int16 y = 0; y < _numRows; y++) { - int32 sourceColumnOffset = y * _numColumns; + for (uint32 y = 0; y < _numRows; y++) { + uint32 sourceColumnOffset = y * _numColumns; - for (int16 x = 0; x < _numColumns; x++) { - int32 index = sourceColumnOffset + x; + for (uint32 x = 0; x < _numColumns; x++) { + uint32 index = sourceColumnOffset + x; // RenderTable only stores offsets from the original coordinates - int32 sourceYIndex = y + _internalBuffer[index].y; - int32 sourceXIndex = x + _internalBuffer[index].x; + uint32 sourceYIndex = y + _internalBuffer[index].y; + uint32 sourceXIndex = x + _internalBuffer[index].x; // Clamp the yIndex to the size of the image - sourceYIndex = CLIP(sourceYIndex, 0, _numRows - 1); + sourceYIndex = CLIP(sourceYIndex, 0, _numRows - 1); // Clamp the xIndex to the size of the image - sourceXIndex = CLIP(sourceXIndex, 0, _numColumns - 1); + sourceXIndex = CLIP(sourceXIndex, 0, _numColumns - 1); destBuffer[destColumnOffset + x] = sourceBuffer[sourceYIndex * _numColumns + sourceXIndex]; } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 737fc84bfc..ba3c7d2f5d 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -66,7 +66,7 @@ public: const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); - void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint16 destWidth); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth); void generateRenderTable(); void setPanoramaFoV(float fov); -- cgit v1.2.3 From 2840ce750eee4409dc4926d57dbe686640cac625 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 6 Sep 2013 22:46:25 -0500 Subject: ZVISION: Save the Puzzle key, since ChangeLocation could be called Which wipes all the puzzles --- engines/zvision/script_manager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 84d39ffe06..860697c61e 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -174,6 +174,8 @@ void ScriptManager::checkPuzzleCriteria() { if (puzzle->criteriaList.empty() || criteriaMet) { debug("Puzzle %u criteria passed. Executing its ResultActions", puzzle->key); + uint32 key = puzzle->key; + bool shouldContinue = true; for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { shouldContinue = shouldContinue && (*resultIter)->execute(_engine); @@ -183,7 +185,7 @@ void ScriptManager::checkPuzzleCriteria() { } // Set the puzzle as completed - setStateValue(puzzle->key, 1); + setStateValue(key, 1); if (!shouldContinue) { break; -- cgit v1.2.3 From e92e3c5b0b59869a78a41fe1013ed73ab6ac59fe Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 6 Sep 2013 22:47:49 -0500 Subject: ZVISION: Delete action_node --- engines/zvision/action_node.cpp | 33 --------------------------------- engines/zvision/action_node.h | 36 ------------------------------------ engines/zvision/actions.cpp | 1 - engines/zvision/module.mk | 1 - engines/zvision/script_manager.cpp | 1 - 5 files changed, 72 deletions(-) delete mode 100644 engines/zvision/action_node.cpp delete mode 100644 engines/zvision/action_node.h (limited to 'engines/zvision') diff --git a/engines/zvision/action_node.cpp b/engines/zvision/action_node.cpp deleted file mode 100644 index eeb8930924..0000000000 --- a/engines/zvision/action_node.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/action_node.h" -#include "zvision/zvision.h" -#include "zvision/script_manager.h" - -namespace ZVision { - - - -} // End of namespace ZVision diff --git a/engines/zvision/action_node.h b/engines/zvision/action_node.h deleted file mode 100644 index c9beb7b38e..0000000000 --- a/engines/zvision/action_node.h +++ /dev/null @@ -1,36 +0,0 @@ -/* 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 ZVISION_ACTION_NODE_H -#define ZVISION_ACTION_NODE_H - -#include "common/types.h" - -#include "zvision/control.h" - -namespace ZVision { - - - -} // End of namespace ZVision - -#endif diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 4c532ebf9d..2a0a72be20 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -30,7 +30,6 @@ #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" -#include "zvision/action_node.h" #include "zvision/zork_raw.h" #include "zvision/zork_avi_decoder.h" #include "zvision/timer_node.h" diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index c8c60ca8ce..c916ab81d3 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -1,7 +1,6 @@ MODULE := engines/zvision MODULE_OBJS := \ - action_node.o \ actions.o \ animation.o \ clock.o \ diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 860697c61e..0af1ff131a 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -33,7 +33,6 @@ #include "zvision/cursor_manager.h" #include "zvision/save_manager.h" #include "zvision/actions.h" -#include "zvision/action_node.h" #include "zvision/utility.h" namespace ZVision { -- cgit v1.2.3 From 558a987143a23826c25779f2a8c139130bf341c0 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 6 Sep 2013 22:48:15 -0500 Subject: ZVISION: Fix accidental signed read from save file header --- engines/zvision/save_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index 9611b9c9b7..595a0525c7 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -147,7 +147,7 @@ Common::Error SaveManager::loadGame(uint slot) { } bool SaveManager::readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header) { - if (in->readSint32BE() != SAVEGAME_ID) { + if (in->readUint32BE() != SAVEGAME_ID) { warning("File is not a ZVision save file. Aborting load"); return false; } -- cgit v1.2.3 From db83d1b5e58e461051ec3d74efa89f332ddae1f9 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 6 Sep 2013 22:49:03 -0500 Subject: ZVISION: Actually use the converted color instead of the old one --- engines/zvision/render_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 6c0e8d24f6..b10a35d531 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -98,7 +98,7 @@ void RenderManager::clearWorkingWindowTo555Color(uint16 color) { uint16 *bufferPtr = (uint16 *)_workingWindowBuffer.getPixels(); for (uint32 i = 0; i < workingWindowSize; i++) { - bufferPtr[i] = color; + bufferPtr[i] = colorIn565; } } -- cgit v1.2.3 From 1e1d5cafe50b6860875c2bb392c1180852e5037d Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 11:52:20 -0500 Subject: ZVISION: Re-enable rendering to the backbuffer --- engines/zvision/render_manager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b10a35d531..f528acfcac 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -78,16 +78,16 @@ void RenderManager::update(uint deltaTimeInMillis) { } void RenderManager::renderBackbufferToScreen() { - //RenderTable::RenderState state = _renderTable.getRenderState(); - //if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { - // _renderTable.mutateImage((uint16 *)_workingWindowBuffer.getPixels(), (uint16 *)_backBuffer.getBasePtr(_workingWindow.left, _workingWindow.top), _backBuffer.w); - //} else { - //_system->copyRectToScreen(_workingWindowBuffer.getPixels(), _workingWindowBuffer.pitch, _workingWindow.left, _workingWindow.top, _workingWindowBuffer.w, _workingWindowBuffer.h); - //} + RenderTable::RenderState state = _renderTable.getRenderState(); + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + _renderTable.mutateImage((uint16 *)_workingWindowBuffer.getPixels(), (uint16 *)_backBuffer.getBasePtr(_workingWindow.left, _workingWindow.top), _backBuffer.w); + } else { + renderRectToWorkingWindow((uint16 *)_workingWindowBuffer.getPixels(), _workingWindow.left, _workingWindow.top, _workingWindowBuffer.w, _workingWindowBuffer.h, false); + } // TODO: Add menu rendering - //_system->copyRectToScreen(_backBuffer.getPixels(), _backBuffer.pitch, 0, 0, _backBuffer.w, _backBuffer.h); + _system->copyRectToScreen(_backBuffer.getPixels(), _backBuffer.pitch, 0, 0, _backBuffer.w, _backBuffer.h); } void RenderManager::clearWorkingWindowTo555Color(uint16 color) { @@ -153,7 +153,7 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (!subRect.isValidRect() || subRect.isEmpty()) return; - _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX, destinationY, subRect.width(), subRect.height()/*, wrap*/); + renderRectToWorkingWindow((uint16 *)surface.getBasePtr(subRect.left, subRect.top), destinationX, destinationY, subRect.width(), subRect.height(), wrap); } void RenderManager::renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap) { -- cgit v1.2.3 From 94268fed060761b85a2d3d848590e658e2a9de8f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 11:52:49 -0500 Subject: ZVISION: Update ActionSetPartialScreen to use new function name --- engines/zvision/actions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 2a0a72be20..d91c3b879d 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -286,7 +286,7 @@ bool ActionSetPartialScreen::execute(ZVision *engine) { RenderManager *renderManager = engine->getRenderManager(); if (_backgroundColor > 0) { - renderManager->clearWorkingWindowToColor(_backgroundColor); + renderManager->clearWorkingWindowTo555Color(_backgroundColor); } renderManager->renderImageToScreen(_fileName, _x, _y); -- cgit v1.2.3 From 2f12ac0d719e38b966c2e2123531364212b3d2db Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 14:07:13 -0500 Subject: ZVISION: Fix pixel copying errors in renderRectToWorkingWindow --- engines/zvision/render_manager.cpp | 35 ++++++----------------------------- engines/zvision/render_manager.h | 2 +- 2 files changed, 7 insertions(+), 30 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index f528acfcac..7f796451f4 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -82,7 +82,7 @@ void RenderManager::renderBackbufferToScreen() { if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { _renderTable.mutateImage((uint16 *)_workingWindowBuffer.getPixels(), (uint16 *)_backBuffer.getBasePtr(_workingWindow.left, _workingWindow.top), _backBuffer.w); } else { - renderRectToWorkingWindow((uint16 *)_workingWindowBuffer.getPixels(), _workingWindow.left, _workingWindow.top, _workingWindowBuffer.w, _workingWindowBuffer.h, false); + _backBuffer.copyRectToSurface(_workingWindowBuffer.getPixels(), _workingWindowBuffer.pitch, _workingWindow.left, _workingWindow.top, _workingWindowBuffer.w, _workingWindowBuffer.h); } // TODO: Add menu rendering @@ -153,7 +153,7 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (!subRect.isValidRect() || subRect.isEmpty()) return; - renderRectToWorkingWindow((uint16 *)surface.getBasePtr(subRect.left, subRect.top), destinationX, destinationY, subRect.width(), subRect.height(), wrap); + renderRectToWorkingWindow((uint16 *)surface.getBasePtr(subRect.left, subRect.top), surface.w, destinationX, destinationY, subRect.width(), subRect.height()); } void RenderManager::renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap) { @@ -261,41 +261,18 @@ void RenderManager::readImageToSurface(const Common::String &fileName, Graphics: destination.convertToInPlace(_pixelFormat); } -void RenderManager::renderRectToWorkingWindow(uint16 *buffer, int32 destX, int32 destY, int32 width, int32 height, bool wrap) { +void RenderManager::renderRectToWorkingWindow(uint16 *buffer, int32 imageWidth, int32 destX, int32 destY, int32 width, int32 height) { uint32 destOffset = 0; + uint32 sourceOffset = 0; uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(destX, destY); for (int32 y = 0; y < height; y++) { for (int32 x = 0; x < width; x++) { - int32 sourceYIndex = y; - int32 sourceXIndex = x; - - if (wrap) { - while (sourceXIndex >= width) { - sourceXIndex -= width; - } - while (sourceXIndex < 0) { - sourceXIndex += width; - } - - while (sourceYIndex >= height) { - sourceYIndex -= height; - } - while (sourceYIndex < 0) { - sourceYIndex += height; - } - } else { - // Clamp the yIndex to the size of the image - sourceYIndex = CLIP(sourceYIndex, 0, height - 1); - - // Clamp the xIndex to the size of the image - sourceXIndex = CLIP(sourceXIndex, 0, width - 1); - } - - workingWindowBufferPtr[destOffset + x] = buffer[sourceYIndex * width + sourceXIndex]; + workingWindowBufferPtr[destOffset + x] = buffer[sourceOffset + x]; } destOffset += _workingWidth; + sourceOffset += imageWidth; } } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index bf44c884e8..07b2e854ae 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -189,7 +189,7 @@ private: void readImageToSurface(const Common::String &fileName, Graphics::Surface &destination); - void renderRectToWorkingWindow(uint16 *buffer, int32 x, int32 y, int32 width, int32 height, bool wrap); + void renderRectToWorkingWindow(uint16 *buffer, int32 x, int32 y, int32 imageWidth, int32 width, int32 height); void moveBackground(int offset); }; -- cgit v1.2.3 From 48745ad197b2986c784bd18c5ae73c569a20b3e9 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 14:32:51 -0500 Subject: ZVISION: Add dirty rectangling support for pure image rendering Still need to add support for ResultActions and Controls that directly use OSystem::copyRectToScreen() --- engines/zvision/render_manager.cpp | 27 +++++++++++++++++++++------ engines/zvision/render_manager.h | 3 +++ engines/zvision/render_table.cpp | 17 +++++++++-------- engines/zvision/render_table.h | 2 +- 4 files changed, 34 insertions(+), 15 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 7f796451f4..bd3e73563f 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -60,6 +60,10 @@ RenderManager::~RenderManager() { } void RenderManager::update(uint deltaTimeInMillis) { + // Clear the dirty rects from last frame + _workingWindowDirtyRect = Common::Rect(); + _backBufferDirtyRect = Common::Rect(); + // An inverse velocity of 0 would be infinitely fast, so we'll let 0 mean no velocity. if (_backgroundInverseVelocity != 0) { _accumulatedVelocityMilliseconds += deltaTimeInMillis; @@ -78,16 +82,25 @@ void RenderManager::update(uint deltaTimeInMillis) { } void RenderManager::renderBackbufferToScreen() { - RenderTable::RenderState state = _renderTable.getRenderState(); - if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { - _renderTable.mutateImage((uint16 *)_workingWindowBuffer.getPixels(), (uint16 *)_backBuffer.getBasePtr(_workingWindow.left, _workingWindow.top), _backBuffer.w); - } else { - _backBuffer.copyRectToSurface(_workingWindowBuffer.getPixels(), _workingWindowBuffer.pitch, _workingWindow.left, _workingWindow.top, _workingWindowBuffer.w, _workingWindowBuffer.h); + if (!_workingWindowDirtyRect.isEmpty()) { + RenderTable::RenderState state = _renderTable.getRenderState(); + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + _renderTable.mutateImage((uint16 *)_workingWindowBuffer.getPixels(), (uint16 *)_backBuffer.getBasePtr(_workingWindow.left + _workingWindowDirtyRect.left, _workingWindow.top + _workingWindowDirtyRect.top), _backBuffer.w, _workingWindowDirtyRect); + } else { + _backBuffer.copyRectToSurface(_workingWindowBuffer.getBasePtr(_workingWindowDirtyRect.left, _workingWindowDirtyRect.top), _workingWindowBuffer.pitch, _workingWindow.left + _workingWindowDirtyRect.left, _workingWindow.top + _workingWindowDirtyRect.top, _workingWindowDirtyRect.width(), _workingWindowDirtyRect.height()); + } + + // Translate the working window dirty rect to screen coords + _workingWindowDirtyRect.translate(_workingWindow.left, _workingWindow.top); + // Then extend the backbuffer dirty rect to contain it + _backBufferDirtyRect.extend(_workingWindowDirtyRect); } // TODO: Add menu rendering - _system->copyRectToScreen(_backBuffer.getPixels(), _backBuffer.pitch, 0, 0, _backBuffer.w, _backBuffer.h); + if (!_backBufferDirtyRect.isEmpty()) { + _system->copyRectToScreen(_backBuffer.getBasePtr(_backBufferDirtyRect.left, _backBufferDirtyRect.top), _backBuffer.pitch, _backBufferDirtyRect.left, _backBufferDirtyRect.top, _backBufferDirtyRect.width(), _backBufferDirtyRect.height()); + } } void RenderManager::clearWorkingWindowTo555Color(uint16 color) { @@ -274,6 +287,8 @@ void RenderManager::renderRectToWorkingWindow(uint16 *buffer, int32 imageWidth, destOffset += _workingWidth; sourceOffset += imageWidth; } + + _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); } const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 07b2e854ae..fd36ab5730 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -57,6 +57,9 @@ private: Graphics::Surface _workingWindowBuffer; Graphics::Surface _backBuffer; + Common::Rect _workingWindowDirtyRect; + Common::Rect _backBufferDirtyRect; + /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ const int _workingWidth; /** Height of the working window. Saved to prevent extraneous calls to _workingWindow.height() */ diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 3e7a86e348..5eb208eb8c 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -100,14 +100,15 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { return returnColor; } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth) { - uint32 destColumnOffset = 0; +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth, const Common::Rect &subRect) { + uint32 destOffset = 0; - for (uint32 y = 0; y < _numRows; y++) { - uint32 sourceColumnOffset = y * _numColumns; + for (uint32 y = subRect.top; y < subRect.bottom; y++) { + uint32 sourceOffset = y * _numColumns; - for (uint32 x = 0; x < _numColumns; x++) { - uint32 index = sourceColumnOffset + x; + for (uint32 x = subRect.left; x < subRect.right; x++) { + uint32 normalizedX = x - subRect.left; + uint32 index = sourceOffset + x; // RenderTable only stores offsets from the original coordinates uint32 sourceYIndex = y + _internalBuffer[index].y; @@ -119,10 +120,10 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 d // Clamp the xIndex to the size of the image sourceXIndex = CLIP(sourceXIndex, 0, _numColumns - 1); - destBuffer[destColumnOffset + x] = sourceBuffer[sourceYIndex * _numColumns + sourceXIndex]; + destBuffer[destOffset + normalizedX] = sourceBuffer[sourceYIndex * _numColumns + sourceXIndex]; } - destColumnOffset += destWidth; + destOffset += destWidth; } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index ba3c7d2f5d..7c8e7d6a2d 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -66,7 +66,7 @@ public: const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); - void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth, const Common::Rect &subRect); void generateRenderTable(); void setPanoramaFoV(float fov); -- cgit v1.2.3 From 70e75dd6403a25f220e2e5eb0af9c3f0e940288c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:03:25 -0500 Subject: ZVISION: Make the declaration and implementation of copyRectToWorkingWindow be the same --- engines/zvision/render_manager.cpp | 4 ++-- engines/zvision/render_manager.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index bd3e73563f..3793ea8cf9 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -166,7 +166,7 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (!subRect.isValidRect() || subRect.isEmpty()) return; - renderRectToWorkingWindow((uint16 *)surface.getBasePtr(subRect.left, subRect.top), surface.w, destinationX, destinationY, subRect.width(), subRect.height()); + copyRectToWorkingWindow((const uint16 *)surface.getBasePtr(subRect.left, subRect.top), destinationX, destinationY, surface.w, subRect.width(), subRect.height()); } void RenderManager::renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap) { @@ -274,7 +274,7 @@ void RenderManager::readImageToSurface(const Common::String &fileName, Graphics: destination.convertToInPlace(_pixelFormat); } -void RenderManager::renderRectToWorkingWindow(uint16 *buffer, int32 imageWidth, int32 destX, int32 destY, int32 width, int32 height) { +void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height) { uint32 destOffset = 0; uint32 sourceOffset = 0; uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(destX, destY); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index fd36ab5730..9881676583 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -108,6 +108,8 @@ public: */ void renderBackbufferToScreen(); + void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height); + /** * Fills the entire workingWindow with the specified color * @@ -192,8 +194,6 @@ private: void readImageToSurface(const Common::String &fileName, Graphics::Surface &destination); - void renderRectToWorkingWindow(uint16 *buffer, int32 x, int32 y, int32 imageWidth, int32 width, int32 height); - void moveBackground(int offset); }; -- cgit v1.2.3 From 47ee636f0503f39531371e3e611a4b6fb81906e0 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:04:01 -0500 Subject: ZVISION: Make LeverControl render to the working window instead of directly to the screen --- engines/zvision/lever_control.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 744fde1e1c..318710e627 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -32,6 +32,7 @@ #include "zvision/lever_control.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" +#include "zvision/render_manager.h" #include "zvision/cursor_manager.h" #include "zvision/rlf_animation.h" #include "zvision/zork_avi_decoder.h" @@ -375,7 +376,6 @@ void LeverControl::renderFrame(uint frameNumber) { } const uint16 *frameData; - int pitch; int x = _animationCoords.left; int y = _animationCoords.top; int width; @@ -384,19 +384,17 @@ void LeverControl::renderFrame(uint frameNumber) { if (_fileType == RLF) { // getFrameData() will automatically optimize to getNextFrame() / getPreviousFrame() if it can frameData = _animation.rlf->getFrameData(frameNumber); - pitch = _animation.rlf->width() * sizeof(uint16); width = _animation.rlf->width(); // Use the animation width instead of _animationCoords.width() height = _animation.rlf->height(); // Use the animation height instead of _animationCoords.height() } else if (_fileType == AVI) { _animation.avi->seekToFrame(frameNumber); const Graphics::Surface *surface = _animation.avi->decodeNextFrame(); frameData = (const uint16 *)surface->getPixels(); - pitch = surface->pitch; width = surface->w; height = surface->h; } - _engine->_system->copyRectToScreen(frameData, pitch, x + _engine->_workingWindow.left, y + _engine->_workingWindow.top, width, height); + _engine->getRenderManager()->copyRectToWorkingWindow(frameData, x, y, width, width, height); } } // End of namespace ZVision -- cgit v1.2.3 From aea107071350a9566c1bd2a8362c2df937f29f67 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:04:42 -0500 Subject: ZVISION: Allow RLF seeking without returning a frame --- engines/zvision/rlf_animation.cpp | 28 ++++++++++++++++++++-------- engines/zvision/rlf_animation.h | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index ffc272c1c8..dfd3289f66 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -155,16 +155,13 @@ RlfAnimation::Frame RlfAnimation::readNextFrame() { return frame; } -const uint16 *RlfAnimation::getFrameData(uint frameNumber) { +void RlfAnimation::seekToFrame(int frameNumber) { assert(!_stream); - assert(frameNumber < _frameCount); + assert(frameNumber < _frameCount || frameNumber >= -1); - // Since this method is so expensive, first check to see if we can use - // getNextFrame() it's cheap. - if ((int)frameNumber == _currentFrame) { - return _currentFrameBuffer; - } else if (_currentFrame + 1 == (int)frameNumber) { - return getNextFrame(); + if (frameNumber == -1) { + _currentFrame = -1; + return; } int closestFrame = _currentFrame; @@ -182,6 +179,21 @@ const uint16 *RlfAnimation::getFrameData(uint frameNumber) { } _currentFrame = frameNumber; +} + +const uint16 *RlfAnimation::getFrameData(uint frameNumber) { + assert(!_stream); + assert(frameNumber < _frameCount); + + // Since this method is so expensive, first check to see if we can use + // getNextFrame() it's cheap. + if ((int)frameNumber == _currentFrame) { + return _currentFrameBuffer; + } else if (_currentFrame + 1 == (int)frameNumber) { + return getNextFrame(); + } + + seekToFrame(frameNumber); return _currentFrameBuffer; } diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index 6f93934f1f..b7d2595295 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -77,6 +77,8 @@ public: uint height() { return _height; } uint32 frameTime() { return _frameTime; } + void seekToFrame(int frameNumber); + const uint16 *getFrameData(uint frameNumber); const uint16 *getNextFrame(); -- cgit v1.2.3 From acfa7ff3e11bf9024451a6e3505f5f07d5646e1f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:05:15 -0500 Subject: ZVISION: Add scr parse line for ActionAssign It was already implemented, just not added to the scr parsing --- engines/zvision/scr_file_handling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 06767c5340..378408df66 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -168,7 +168,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:attenuate*", true)) { // TODO: Implement ActionAttenuate } else if (line.matchString("*:assign*", true)) { - // TODO: Implement ActionAssign + actionList.push_back(new ActionAssign(line)); } else if (line.matchString("*:change_location*", true)) { actionList.push_back(new ActionChangeLocation(line)); } else if (line.matchString("*:crossfade*", true)) { -- cgit v1.2.3 From 81184d342c6c03932d4c9c4620302283a09273be Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:05:47 -0500 Subject: ZVISION: Delete a Control * when removing it from _activeControls --- engines/zvision/script_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 0af1ff131a..f499adaa44 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -108,6 +108,7 @@ void ScriptManager::updateNodes(uint deltaTimeMillis) { // If process() returns true, it means the node can be deleted for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end();) { if ((*iter)->process(deltaTimeMillis)) { + delete (*iter); // Remove the node iter = _activeControls.erase(iter); } else { -- cgit v1.2.3 From eeace477a08d68ead85d39b90084b4e633a6127a Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:06:20 -0500 Subject: ZVISION: Set a Puzzle as completed before executing its ResultActions --- engines/zvision/script_manager.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index f499adaa44..4952ebdda4 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -174,7 +174,8 @@ void ScriptManager::checkPuzzleCriteria() { if (puzzle->criteriaList.empty() || criteriaMet) { debug("Puzzle %u criteria passed. Executing its ResultActions", puzzle->key); - uint32 key = puzzle->key; + // Set the puzzle as completed + setStateValue(puzzle->key, 1); bool shouldContinue = true; for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { @@ -184,9 +185,6 @@ void ScriptManager::checkPuzzleCriteria() { } } - // Set the puzzle as completed - setStateValue(key, 1); - if (!shouldContinue) { break; } -- cgit v1.2.3 From 6a9572670cf4a325e2f583e492c14f2f9edbd2b9 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:06:42 -0500 Subject: ZVISION: Add method for getting a pointer to a Control --- engines/zvision/script_manager.cpp | 8 ++++++++ engines/zvision/script_manager.h | 1 + 2 files changed, 9 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 4952ebdda4..b9217e7250 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -228,6 +228,14 @@ void ScriptManager::addControl(Control *control) { _activeControls.push_back(control); } +Control *ScriptManager::getControl(uint32 key) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + if ((*iter)->getKey() == key) { + return (*iter); + } + } +} + void ScriptManager::enableControl(uint32 key) { for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { if ((*iter)->getKey() == key) { diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 61ad4fa87a..15d456ea6b 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -83,6 +83,7 @@ public: void addToStateValue(uint32 key, uint valueToAdd); void addControl(Control *control); + Control *getControl(uint32 key); void enableControl(uint32 key); void disableControl(uint32 key); -- cgit v1.2.3 From 46278f6f59505050d516460094237e30abaa58e0 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:07:47 -0500 Subject: ZVISION: Implement AnimationControl This handles playing animations asyncronously over numerous frames --- engines/zvision/animation_control.cpp | 122 ++++++++++++++++++++++++++++++++++ engines/zvision/animation_control.h | 78 ++++++++++++++++++++++ engines/zvision/module.mk | 1 + 3 files changed, 201 insertions(+) create mode 100644 engines/zvision/animation_control.cpp create mode 100644 engines/zvision/animation_control.h (limited to 'engines/zvision') diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp new file mode 100644 index 0000000000..5da39e4583 --- /dev/null +++ b/engines/zvision/animation_control.cpp @@ -0,0 +1,122 @@ +/* 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/scummsys.h" + +#include "video/video_decoder.h" + +#include "zvision/animation_control.h" +#include "zvision/zvision.h" +#include "zvision/render_manager.h" +#include "zvision/script_manager.h" +#include "zvision/rlf_animation.h" +#include "zvision/zork_avi_decoder.h" + + +namespace ZVision { + +AnimationControl::AnimationControl(ZVision *engine, uint32 controlKey, const Common::String &fileName) + : Control(engine, controlKey), + _fileType(RLF), + _loopCount(1), + _currentLoop(0), + _accumulatedTime(0) { + if (fileName.hasSuffix(".rlf")) { + _fileType = RLF; + _animation.rlf = new RlfAnimation(fileName, false); + } else if (fileName.hasSuffix(".avi")) { + _fileType = AVI; + _animation.avi = new ZorkAVIDecoder(); + _animation.avi->loadFile(fileName); + } else { + warning("Unrecognized animation file type: %s", fileName.c_str()); + } +} + +AnimationControl::~AnimationControl() { + if (_fileType == RLF) { + delete _animation.rlf; + } else if (_fileType == AVI) { + delete _animation.avi; + } +} + +bool AnimationControl::process(uint32 deltaTimeInMillis) { + if (!_enabled) { + return false; + } + + bool finished = false; + + if (_fileType == RLF) { + _accumulatedTime += deltaTimeInMillis; + + uint32 frameTime = _animation.rlf->frameTime(); + if (_accumulatedTime >= frameTime) { + _accumulatedTime -= frameTime; + + _engine->getRenderManager()->copyRectToWorkingWindow(_animation.rlf->getNextFrame(), _x, _y, _animation.rlf->width(), _animation.rlf->width(), _animation.rlf->height()); + + if (_animation.rlf->endOfAnimation()) { + _animation.rlf->seekToFrame(-1); + if (_loopCount > 0) { + _currentLoop++; + if (_currentLoop >= _loopCount) { + finished = true; + } + } + } + } + } else if (_fileType == AVI) { + if (!_animation.avi->isPlaying()) { + _animation.avi->start(); + } + + if (_animation.avi->needsUpdate()) { + const Graphics::Surface *frame = _animation.avi->decodeNextFrame(); + + if (frame) { + _engine->getRenderManager()->copyRectToWorkingWindow((const uint16 *)frame->getPixels(), _x, _y, frame->w, frame->w, frame->h); + } + } + + if (_animation.avi->endOfVideo()) { + _animation.avi->rewind(); + if (_loopCount > 0) { + _currentLoop++; + if (_currentLoop >= _loopCount) { + finished = true; + } + } + } + } + + if (finished) { + _engine->getScriptManager()->setStateValue(_animationKey, 2); + disable(); + _currentLoop = 0; + } + + return false; +} + +} // End of namespace ZVision diff --git a/engines/zvision/animation_control.h b/engines/zvision/animation_control.h new file mode 100644 index 0000000000..036ce4b66b --- /dev/null +++ b/engines/zvision/animation_control.h @@ -0,0 +1,78 @@ +/* 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 ZVISION_ANIMATION_CONTROL_H +#define ZVISION_ANIMATION_CONTROL_H + +#include "common/types.h" + +#include "zvision/control.h" + + +namespace Video { +class VideoDecoder; +} + +namespace ZVision { + +class ZVision; +class RlfAnimation; + +class AnimationControl : public Control { +public: + AnimationControl(ZVision *engine, uint32 controlKey, const Common::String &fileName); + ~AnimationControl(); + +private: + enum FileType { + RLF = 1, + AVI = 2 + }; + +private: + uint32 _animationKey; + + union { + RlfAnimation *rlf; + Video::VideoDecoder *avi; + } _animation; + + FileType _fileType; + uint _loopCount; + int32 _x; + int32 _y; + + uint _accumulatedTime; + uint _currentLoop; + +public: + bool process(uint32 deltaTimeInMillis); + + void setAnimationKey(uint32 animationKey) { _animationKey = animationKey; } + void setLoopCount(uint loopCount) { _loopCount = loopCount; } + void setXPos(int32 x) { _x = x; } + void setYPost(int32 y) { _y = y; } +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index c916ab81d3..814a4ba0c2 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -3,6 +3,7 @@ MODULE := engines/zvision MODULE_OBJS := \ actions.o \ animation.o \ + animation_control.o \ clock.o \ console.o \ control.o \ -- cgit v1.2.3 From 5c3cfaa6d2428da3ed33bcdf163008457df8000b Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:08:20 -0500 Subject: ZVISION: Implement ActionPreloadAnimation::execute() --- engines/zvision/actions.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index d91c3b879d..86eca58411 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -33,6 +33,7 @@ #include "zvision/zork_raw.h" #include "zvision/zork_avi_decoder.h" #include "zvision/timer_node.h" +#include "zvision/animation_control.h" namespace ZVision { @@ -212,7 +213,13 @@ ActionPreloadAnimation::ActionPreloadAnimation(const Common::String &line) { } bool ActionPreloadAnimation::execute(ZVision *engine) { - // TODO: Implement + // TODO: We ignore the mask and framerate atm. Mask refers to a key color used for binary alpha. We assume the framerate is the default framerate embedded in the videos + + // TODO: Check if the Control already exists + + // Create the control, but disable it until PlayPreload is called + engine->getScriptManager()->addControl(new AnimationControl(engine, _key, _fileName)); + engine->getScriptManager()->disableControl(_key); return true; } -- cgit v1.2.3 From b1587f8ba0f335aff7133f7422953be83aa4c5ae Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:08:49 -0500 Subject: ZVISION: Implement ActionPlayPreloadAnimation --- engines/zvision/actions.cpp | 27 +++++++++++++++++++++++++++ engines/zvision/actions.h | 17 +++++++++++++++++ engines/zvision/scr_file_handling.cpp | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 86eca58411..3d25fa9e99 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -245,6 +245,33 @@ bool ActionPlayAnimation::execute(ZVision *engine) { } +////////////////////////////////////////////////////////////////////////////// +// ActionPlayPreloadAnimation +////////////////////////////////////////////////////////////////////////////// + +ActionPlayPreloadAnimation::ActionPlayPreloadAnimation(const Common::String &line) { + sscanf(line.c_str(), + "%*[^:]:%*[^:]:%u(%u %u %u %u %u %u %u %u)", + &_animationKey, &_controlKey, &_x1, &_y1, &_x2, &_y2, &_startFrame, &_endFrame, &_loopCount); +} + +bool ActionPlayPreloadAnimation::execute(ZVision *engine) { + // Find the control + AnimationControl *control = (AnimationControl *)engine->getScriptManager()->getControl(_controlKey); + + // Set the needed values within the control + control->setAnimationKey(_animationKey); + control->setLoopCount(_loopCount); + control->setXPos(_x1); + control->setYPost(_y1); + + // Enable the control. ScriptManager will take care of the rest + control->enable(); + + return true; +} + + ////////////////////////////////////////////////////////////////////////////// // ActionQuit ////////////////////////////////////////////////////////////////////////////// diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index b36e277d0e..5d7cdad68f 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -242,6 +242,23 @@ private: uint _loopCount; }; +class ActionPlayPreloadAnimation : public ResultAction { +public: + ActionPlayPreloadAnimation(const Common::String &line); + bool execute(ZVision *engine); + +private: + uint32 _animationKey; + uint32 _controlKey; + uint32 _x1; + uint32 _y1; + uint32 _x2; + uint32 _y2; + uint _startFrame; + uint _endFrame; + uint _loopCount; +}; + class ActionPreloadAnimation : public ResultAction { public: ActionPreloadAnimation(const Common::String &line); diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 378408df66..3d4718557f 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -202,7 +202,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:pan_track*", true)) { // TODO: Implement ActionPanTrack } else if (line.matchString("*:playpreload*", true)) { - // TODO: Implement ActionPlayPreload + actionList.push_back(new ActionPlayPreloadAnimation(line)); } else if (line.matchString("*:preferences*", true)) { // TODO: Implement ActionPreferences } else if (line.matchString("*:quit*", true)) { -- cgit v1.2.3 From 6e806e51ad38a43fc82fc269ed12151b79ea01bd Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 7 Sep 2013 18:15:24 -0500 Subject: ZVISION: Stop avi playback once the animation is finished --- engines/zvision/animation_control.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp index 5da39e4583..2d401d2b6f 100644 --- a/engines/zvision/animation_control.cpp +++ b/engines/zvision/animation_control.cpp @@ -104,6 +104,7 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { if (_loopCount > 0) { _currentLoop++; if (_currentLoop >= _loopCount) { + _animation.avi->stop(); finished = true; } } -- cgit v1.2.3 From 106522661c70e4ff270016f5419cccca5c86820c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 03:17:50 -0500 Subject: ZVISION: Create method for rendering to the working window with binary alpha --- engines/zvision/render_manager.cpp | 20 ++++++++++++++++++++ engines/zvision/render_manager.h | 1 + 2 files changed, 21 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 3793ea8cf9..3f19cae6fe 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -291,6 +291,26 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); } +void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor) { + uint32 destOffset = 0; + uint32 sourceOffset = 0; + uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(destX, destY); + + for (int32 y = 0; y < height; y++) { + for (int32 x = 0; x < width; x++) { + uint16 color = buffer[sourceOffset + x]; + if (color != alphaColor) { + workingWindowBufferPtr[destOffset + x] = color; + } + } + + destOffset += _workingWidth; + sourceOffset += imageWidth; + } + + _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); +} + const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { // Convert from screen space to working window space Common::Point newPoint(point - Common::Point(_workingWindow.left, _workingWindow.top)); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 9881676583..41a11bd113 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -109,6 +109,7 @@ public: void renderBackbufferToScreen(); void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height); + void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor); /** * Fills the entire workingWindow with the specified color -- cgit v1.2.3 From 87e78e4c338aa7cde9c53e00eaa6ca1ad97d5d94 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 03:20:20 -0500 Subject: ZVISION: Create method for getting the RenderManager backbuffer --- engines/zvision/render_manager.h | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 41a11bd113..bb673e9929 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -176,6 +176,7 @@ public: RenderTable *getRenderTable(); uint32 getCurrentBackgroundOffset(); + const Graphics::Surface *getBackBuffer() { return &_backBuffer; } private: /** -- cgit v1.2.3 From af94158723c2698b17faf83fccc585ce747c7e68 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 03:18:51 -0500 Subject: ZVISION: Save a thumbnail of the RenderManager backbuffer instead of the actual screen This prevents things like the GMM being in the thumbnail --- engines/zvision/save_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index 595a0525c7..4f8bfeb836 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -30,6 +30,7 @@ #include "zvision/save_manager.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" +#include "zvision/render_manager.h" namespace ZVision { @@ -88,7 +89,7 @@ void SaveManager::autoSave() { void SaveManager::writeSaveGameData(Common::OutSaveFile *file) { // Create a thumbnail and save it - Graphics::saveThumbnail(*file); + Graphics::saveThumbnail(*file, *_engine->getRenderManager()->getBackBuffer()); // Write out the save date/time TimeDate td; -- cgit v1.2.3 From c7358ed4f78437e26aeb05d2113e86ee35d14632 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 03:20:47 -0500 Subject: ZVISION: Create class for rendering TrueType fonts --- engines/zvision/module.mk | 1 + engines/zvision/truetype_font.cpp | 191 ++++++++++++++++++++++++++++++++++++++ engines/zvision/truetype_font.h | 129 +++++++++++++++++++++++++ 3 files changed, 321 insertions(+) create mode 100644 engines/zvision/truetype_font.cpp create mode 100644 engines/zvision/truetype_font.h (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 814a4ba0c2..9fa119d353 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -23,6 +23,7 @@ MODULE_OBJS := \ scripts.o \ single_value_container.o \ timer_node.o \ + truetype_font.o \ utility.o \ video.o \ zvision.o \ diff --git a/engines/zvision/truetype_font.cpp b/engines/zvision/truetype_font.cpp new file mode 100644 index 0000000000..b3aafc26d7 --- /dev/null +++ b/engines/zvision/truetype_font.cpp @@ -0,0 +1,191 @@ +/* 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/scummsys.h" + +#include "common/debug.h" +#include "common/file.h" +#include "common/system.h" + +#include "graphics/fonts/ttf.h" +#include "graphics/surface.h" + +#include "zvision/truetype_font.h" +#include "zvision/zvision.h" +#include "zvision/render_manager.h" + + +namespace ZVision { + +TruetypeFont::TruetypeFont(ZVision *engine, int32 fontHeight, const Graphics::PixelFormat pixelFormat) + : _engine(engine), + _pixelFormat(pixelFormat), + _isBold(false), + _isItalic(false), + _isStriked(false), + _isUnderline(false), + _fontHeight(fontHeight), + _font(0), + _lineHeight(0), + _maxCharWidth(0), + _maxCharHeight(0) { + for (int i = 0; i < NUM_CACHED_TEXTS; i++) { + _cachedTexts[i] = 0; + } +} + +TruetypeFont::~TruetypeFont(void) { + clearCache(); + + delete _font; +} + +void TruetypeFont::clearCache() { + for (int i = 0; i < NUM_CACHED_TEXTS; i++) { + if (_cachedTexts[i]) { + delete _cachedTexts[i]; + } + _cachedTexts[i] = 0; + } +} + +bool TruetypeFont::loadFile(const Common::String &filename) { + Common::File file; + if (file.open(filename)) { + debug("TTF font file %s could not be opened", filename.c_str()); + return false; + } + + _font = Graphics::loadTTFFont(file, 96, _fontHeight); // Use the same dpi as WME (96 vs 72). + _lineHeight = _font->getFontHeight(); + + return true; +} + +void TruetypeFont::drawText(const Common::String &text, int x, int y, int width, TextAlign align, int maxHeight) { + if (text.equals("")) { + return; + } + + // Find the cached surface, if it exists + uint32 minUseTime = UINT_MAX; + int minIndex = -1; + Graphics::Surface *surface = nullptr; + + for (int i = 0; i < NUM_CACHED_TEXTS; i++) { + if (_cachedTexts[i] == nullptr) { + minUseTime = 0; + minIndex = i; + } else { + if (_cachedTexts[i]->_text == text && _cachedTexts[i]->_align == align && _cachedTexts[i]->_width == width && _cachedTexts[i]->_maxHeight == maxHeight) { + surface = _cachedTexts[i]->_surface; + _cachedTexts[i]->_marked = true; + _cachedTexts[i]->_lastUsed = g_system->getMillis(); + break; + } else { + if (_cachedTexts[i]->_lastUsed < minUseTime) { + minUseTime = _cachedTexts[i]->_lastUsed; + minIndex = i; + } + } + } + } + + // It's not cached, so create one + if (!surface) { + surface = renderTextToTexture(text, width, align, maxHeight); + if (surface) { + // Write the new surface to cache + if (_cachedTexts[minIndex] != nullptr) { + delete _cachedTexts[minIndex]; + } + _cachedTexts[minIndex] = new CachedText; + + _cachedTexts[minIndex]->_surface = surface; + _cachedTexts[minIndex]->_align = align; + _cachedTexts[minIndex]->_width = width; + _cachedTexts[minIndex]->_maxHeight = maxHeight; + _cachedTexts[minIndex]->_text = text; + _cachedTexts[minIndex]->_marked = true; + _cachedTexts[minIndex]->_lastUsed = _engine->_system->getMillis(); + } + } + + + // Render it to the working window + if (surface) { + _engine->getRenderManager()->copyRectToWorkingWindow((uint16 *)surface->getPixels(), x, y, surface->w, surface->w, surface->h); + } +} + +Graphics::Surface *TruetypeFont::renderTextToTexture(const Common::String &text, int width, TextAlign align, int maxHeight) { + Common::Array lines; + _font->wordWrapText(text, width, lines); + + while (maxHeight > 0 && lines.size() * _lineHeight > maxHeight) { + lines.pop_back(); + } + if (lines.size() == 0) { + return nullptr; + } + + Graphics::TextAlign alignment = Graphics::kTextAlignInvalid; + if (align == ALIGN_LEFT) { + alignment = Graphics::kTextAlignLeft; + } else if (align == ALIGN_CENTER) { + alignment = Graphics::kTextAlignCenter; + } else if (align == ALIGN_RIGHT) { + alignment = Graphics::kTextAlignRight; + } + + Graphics::Surface *surface = new Graphics::Surface(); + surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), _pixelFormat); + + uint32 alphaColor = 0xffffffff; + int heightOffset = 0; + for (Common::Array::iterator it = lines.begin(); it != lines.end(); it++) { + _font->drawString(surface, *it, 0, heightOffset, width, alphaColor, alignment); + heightOffset += (int)_lineHeight; + } + + return surface; + // TODO: _isUnderline, _isBold, _isItalic, _isStriked +} + +void TruetypeFont::measureText(const Common::String &text, int maxWidth, int maxHeight, int &textWidthOut, int &textHeightOut) { + if (maxWidth >= 0) { + Common::Array lines; + _font->wordWrapText(text, maxWidth, lines); + Common::Array::iterator it; + textWidthOut = 0; + for (it = lines.begin(); it != lines.end(); ++it) { + textWidthOut = MAX(textWidthOut, _font->getStringWidth(*it)); + } + + textHeightOut = (int)(lines.size() * getLineHeight()); + } else { + textWidthOut = _font->getStringWidth(text); + textHeightOut = _fontHeight; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/truetype_font.h b/engines/zvision/truetype_font.h new file mode 100644 index 0000000000..2618dc407e --- /dev/null +++ b/engines/zvision/truetype_font.h @@ -0,0 +1,129 @@ +/* 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. + * + */ + +// This file is based on engines/wintermute/base/fonts/base_font_truetype.h/.cpp + +#ifndef ZVISION_TRUETYPE_FONT_H +#define ZVISION_TRUETYPE_FONT_H + +#include "common/types.h" + +#include "graphics/font.h" + + +namespace Graphics { +struct Surface; +} + +namespace ZVision { + +class ZVision; + +class TruetypeFont { +public: + TruetypeFont(ZVision *engine, int32 fontHeight, const Graphics::PixelFormat pixelFormat); + ~TruetypeFont(); + +public: + enum { + NUM_CACHED_TEXTS = 30 + }; + + enum TextAlign { + ALIGN_LEFT = 0, + ALIGN_RIGHT, + ALIGN_CENTER + }; + + class CachedText { + public: + Common::String _text; + int32 _width; + TextAlign _align; + int32 _maxHeight; + Graphics::Surface *_surface; + int32 _textOffset; + bool _marked; + uint32 _lastUsed; + + CachedText() { + _width = _maxHeight = -1; + _align = ALIGN_LEFT; + _surface = 0; + _lastUsed = 0; + _marked = false; + } + + virtual ~CachedText() { + delete _surface; + } + }; + +private: + ZVision *_engine; + const Graphics::PixelFormat _pixelFormat; + + Graphics::Font *_font; + + float _lineHeight; + + size_t _maxCharWidth; + size_t _maxCharHeight; + + CachedText *_cachedTexts[NUM_CACHED_TEXTS]; + +public: + bool _isBold; + bool _isItalic; + bool _isUnderline; + bool _isStriked; + int32 _fontHeight; + + //BaseArray _layers; + +public: + int getTextWidth(const byte *text, int maxLength = -1); + int getTextHeight(const byte *text, int width); + void drawText(const Common::String &text, int x, int y, int width, TextAlign align = ALIGN_LEFT, int max_height = -1); + int getLetterHeight(); + + void initLoop() {} + void afterLoad() {} + + bool loadBuffer(byte *buffer); + bool loadFile(const Common::String &filename); + + float getLineHeight() const { return _lineHeight; } + + void clearCache(); + + static TruetypeFont *createFromFile(ZVision *game, const Common::String &filename); + +private: + void measureText(const Common::String &text, int maxWidth, int maxHeight, int &textWidthOut, int &textHeightOut); + Graphics::Surface *renderTextToTexture(const Common::String &text, int width, TextAlign align, int maxHeight); + bool initFont(); +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From 511cb7447e6ebd9a0c54c3e767eb8ea754fd5398 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:12:36 -0500 Subject: ZVISION: Create method for converting image space to working window space --- engines/zvision/render_manager.cpp | 13 +++++++++++++ engines/zvision/render_manager.h | 9 +++++++++ 2 files changed, 22 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 3f19cae6fe..c0554dc20a 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -338,6 +338,19 @@ const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point & return newPoint; } +const Common::Point RenderManager::imageSpaceToWorkingWindowSpace(const Common::Point &point) { + Common::Point newPoint(point); + + RenderTable::RenderState state = _renderTable.getRenderState(); + if (state == RenderTable::PANORAMA) { + newPoint += (Common::Point(_screenCenterX, 0) - _backgroundOffset); + } else if (state == RenderTable::TILT) { + newPoint += (Common::Point(0, _screenCenterY) - _backgroundOffset); + } + + return newPoint; +} + RenderTable *RenderManager::getRenderTable() { return &_renderTable; } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index bb673e9929..0294d6a19f 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -173,6 +173,15 @@ public: * @return Point in image coordinate space */ const Common::Point screenSpaceToImageSpace(const Common::Point &point); + /** + * Converts a point in image coordinate space to ***PRE-WARP*** + * working window coordinate space + * + * @param point Point in image coordinate space + * @return Point in PRE-WARP working window coordinate space + */ + const Common::Point imageSpaceToWorkingWindowSpace(const Common::Point &point); + RenderTable *getRenderTable(); uint32 getCurrentBackgroundOffset(); -- cgit v1.2.3 From a415964c6da8f36fcf649f7e0f9fb94791cd02ff Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:13:01 -0500 Subject: ZVISION: Create method for clipping a rect to the working window --- engines/zvision/render_manager.cpp | 11 +++++++++++ engines/zvision/render_manager.h | 8 ++++++++ 2 files changed, 19 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index c0554dc20a..8ac07632d6 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -351,6 +351,17 @@ const Common::Point RenderManager::imageSpaceToWorkingWindowSpace(const Common:: return newPoint; } +bool RenderManager::clipRectToWorkingWindow(Common::Rect &rect) { + if (!_workingWindow.contains(rect)) { + return false; + } + + // We can't clip against the actual working window rect because it's in screen space + // But rect is in working window space + rect.clip(_workingWidth, _workingHeight); + return true; +} + RenderTable *RenderManager::getRenderTable() { return &_renderTable; } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 0294d6a19f..cbf69b9df2 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -182,6 +182,14 @@ public: */ const Common::Point imageSpaceToWorkingWindowSpace(const Common::Point &point); + /** + * Clip a rectangle to the working window. If it returns false, the original rect + * is not inside the working window. + * + * @param rect The rectangle to clip against the working window + * @return Is rect at least partially inside the working window (true) or completely outside (false) + */ + bool clipRectToWorkingWindow(Common::Rect &rect); RenderTable *getRenderTable(); uint32 getCurrentBackgroundOffset(); -- cgit v1.2.3 From f9b9bf5b9b5b6a438a12a77aab90bdb77deeca65 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:13:39 -0500 Subject: ZVISION: Create method for transposing a surface --- engines/zvision/render_manager.cpp | 18 ++++++++++++++++++ engines/zvision/render_manager.h | 11 +++++++++++ 2 files changed, 29 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 8ac07632d6..441580c1bc 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -432,4 +432,22 @@ uint32 RenderManager::getCurrentBackgroundOffset() { } } +Graphics::Surface *RenderManager::tranposeSurface(const Graphics::Surface *surface) { + Graphics::Surface *tranposedSurface = new Graphics::Surface(); + tranposedSurface->create(surface->h, surface->w, surface->format); + + uint16 *source = (uint16 *)surface->getPixels(); + uint16 *dest = (uint16 *)tranposedSurface->getPixels(); + + for (uint32 y = 0; y < tranposedSurface->h; y++) { + uint32 columnIndex = y * tranposedSurface->w; + + for (uint32 x = 0; x < tranposedSurface->w; x++) { + dest[columnIndex + x] = source[x * surface->w + y]; + } + } + + return tranposedSurface; +} + } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index cbf69b9df2..51636ef682 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -195,6 +195,17 @@ public: uint32 getCurrentBackgroundOffset(); const Graphics::Surface *getBackBuffer() { return &_backBuffer; } + /** + * Creates a copy of surface and transposes the data. + * + * Note: The user is responsible for calling free() on the returned surface + * and then deleting it + * + * @param surface The data to be transposed + * @return A copy of the surface with the data transposed + */ + static Graphics::Surface *tranposeSurface(const Graphics::Surface *surface); + private: /** * Renders a subRectangle of an image to the backbuffer. The destinationRect and SubRect -- cgit v1.2.3 From 3b7189993c3fbd6f6f98108b8e1d828964dc84a9 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:14:33 -0500 Subject: ZVISION: Let Rlf animations output Surfaces instead of uint16 arrays --- engines/zvision/rlf_animation.cpp | 22 ++++++++++------------ engines/zvision/rlf_animation.h | 6 +++--- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index dfd3289f66..0ffeeb0f0f 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -45,7 +45,6 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) _frameTime(0), _frames(0), _currentFrame(-1), - _currentFrameBuffer(0), _frameBufferByteSize(0) { if (!_file.open(fileName)) { warning("RLF animation file %s could not be opened", fileName.c_str()); @@ -57,7 +56,7 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) return; } - _currentFrameBuffer = new uint16[_width * _height]; + _currentFrameBuffer.create(_width, _height, _pixelFormat565); _frameBufferByteSize = _width * _height * sizeof(uint16); if (!stream) { @@ -71,7 +70,6 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) } RlfAnimation::~RlfAnimation() { - delete[] _currentFrameBuffer; for (uint i = 0; i < _frameCount; i++) { delete[] _frames[i].encodedData; } @@ -181,23 +179,23 @@ void RlfAnimation::seekToFrame(int frameNumber) { _currentFrame = frameNumber; } -const uint16 *RlfAnimation::getFrameData(uint frameNumber) { +const Graphics::Surface *RlfAnimation::getFrameData(uint frameNumber) { assert(!_stream); assert(frameNumber < _frameCount); // Since this method is so expensive, first check to see if we can use // getNextFrame() it's cheap. if ((int)frameNumber == _currentFrame) { - return _currentFrameBuffer; + return &_currentFrameBuffer; } else if (_currentFrame + 1 == (int)frameNumber) { return getNextFrame(); } seekToFrame(frameNumber); - return _currentFrameBuffer; + return &_currentFrameBuffer; } -const uint16 *RlfAnimation::getNextFrame() { +const Graphics::Surface *RlfAnimation::getNextFrame() { assert(_currentFrame + 1 < (int)_frameCount); if (_stream) { @@ -207,22 +205,22 @@ const uint16 *RlfAnimation::getNextFrame() { } _currentFrame++; - return _currentFrameBuffer; + return &_currentFrameBuffer; } void RlfAnimation::applyFrameToCurrent(uint frameNumber) { if (_frames[frameNumber].type == Masked) { - decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer, _frames[frameNumber].encodedSize, _frameBufferByteSize); + decodeMaskedRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize); } else if (_frames[frameNumber].type == Simple) { - decodeSimpleRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer, _frames[frameNumber].encodedSize, _frameBufferByteSize); + decodeSimpleRunLengthEncoding(_frames[frameNumber].encodedData, (int8 *)_currentFrameBuffer.getPixels(), _frames[frameNumber].encodedSize, _frameBufferByteSize); } } void RlfAnimation::applyFrameToCurrent(const RlfAnimation::Frame &frame) { if (frame.type == Masked) { - decodeMaskedRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer, frame.encodedSize, _frameBufferByteSize); + decodeMaskedRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize); } else if (frame.type == Simple) { - decodeSimpleRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer, frame.encodedSize, _frameBufferByteSize); + decodeSimpleRunLengthEncoding(frame.encodedData, (int8 *)_currentFrameBuffer.getPixels(), frame.encodedSize, _frameBufferByteSize); } } diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index b7d2595295..133bf3913e 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -68,7 +68,7 @@ private: Common::List _completeFrames; int _currentFrame; - uint16 *_currentFrameBuffer; + Graphics::Surface _currentFrameBuffer; uint32 _frameBufferByteSize; public: @@ -79,8 +79,8 @@ public: void seekToFrame(int frameNumber); - const uint16 *getFrameData(uint frameNumber); - const uint16 *getNextFrame(); + const Graphics::Surface *getFrameData(uint frameNumber); + const Graphics::Surface *getNextFrame(); bool endOfAnimation() { return _currentFrame == (int)_frameCount - 1; } -- cgit v1.2.3 From 31cdf227d20906986884113910680e2b22965be8 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:15:08 -0500 Subject: ZVISION: Clip animations to the working window --- engines/zvision/animation_control.cpp | 48 ++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp index 2d401d2b6f..cd5ebf1549 100644 --- a/engines/zvision/animation_control.cpp +++ b/engines/zvision/animation_control.cpp @@ -71,10 +71,31 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { _accumulatedTime += deltaTimeInMillis; uint32 frameTime = _animation.rlf->frameTime(); - if (_accumulatedTime >= frameTime) { + while (_accumulatedTime >= frameTime) { _accumulatedTime -= frameTime; - _engine->getRenderManager()->copyRectToWorkingWindow(_animation.rlf->getNextFrame(), _x, _y, _animation.rlf->width(), _animation.rlf->width(), _animation.rlf->height()); + RenderManager *renderManager = _engine->getRenderManager(); + Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); + Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + _animation.rlf->width(), workingWindowPoint.y + _animation.rlf->height()); + + // If the clip returns false, it means the animation is outside the working window + if (!renderManager->clipRectToWorkingWindow(subRect)) { + return false; + } + + const Graphics::Surface *frame = _animation.rlf->getNextFrame(); + + RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); + if (state == RenderTable::PANORAMA) { + Graphics::Surface *tranposedFrame = RenderManager::tranposeSurface(frame); + + renderManager->copyRectToWorkingWindow((uint16 *)tranposedFrame->getBasePtr(tranposedFrame->w - subRect.width(), tranposedFrame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); + + tranposedFrame->free(); + delete tranposedFrame; + } else { + renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); + } if (_animation.rlf->endOfAnimation()) { _animation.rlf->seekToFrame(-1); @@ -95,7 +116,28 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { const Graphics::Surface *frame = _animation.avi->decodeNextFrame(); if (frame) { - _engine->getRenderManager()->copyRectToWorkingWindow((const uint16 *)frame->getPixels(), _x, _y, frame->w, frame->w, frame->h); + RenderManager *renderManager = _engine->getRenderManager(); + Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); + Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + frame->w, workingWindowPoint.y + frame->h); + + // If the clip returns false, it means the animation is outside the working window + if (!renderManager->clipRectToWorkingWindow(subRect)) { + return false; + } + + RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); + if (state == RenderTable::PANORAMA) { + Graphics::Surface *tranposedFrame = RenderManager::tranposeSurface(frame); + + renderManager->copyRectToWorkingWindow((uint16 *)tranposedFrame->getBasePtr(tranposedFrame->w - subRect.width(), tranposedFrame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); + + tranposedFrame->free(); + delete tranposedFrame; + } else { + renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); + } + + } } -- cgit v1.2.3 From 8354f236285bfd55536a19b177a4fcfbdd0aaa1b Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:15:32 -0500 Subject: ZVISION: Add a debug assert to make sure we're not trying to render ouside the working window --- engines/zvision/render_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 441580c1bc..04163fab61 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -289,6 +289,9 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i } _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); + + // TODO: Remove this from release. It's here to make sure code that uses this function clips their destinations correctly + assert(_workingWindowDirtyRect.width() <= _workingWidth && _workingWindowDirtyRect.height() <= _workingHeight); } void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor) { -- cgit v1.2.3 From 077f0b24912688b53adb24757a2a87ce52175ae9 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:15:55 -0500 Subject: ZVISION: Update LeverControl to use the new RlfAnimation outputs --- engines/zvision/lever_control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 318710e627..93a6054850 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -383,7 +383,7 @@ void LeverControl::renderFrame(uint frameNumber) { if (_fileType == RLF) { // getFrameData() will automatically optimize to getNextFrame() / getPreviousFrame() if it can - frameData = _animation.rlf->getFrameData(frameNumber); + frameData = (const uint16 *)_animation.rlf->getFrameData(frameNumber)->getPixels(); width = _animation.rlf->width(); // Use the animation width instead of _animationCoords.width() height = _animation.rlf->height(); // Use the animation height instead of _animationCoords.height() } else if (_fileType == AVI) { -- cgit v1.2.3 From 9e563f01134ec9063d743ef487eb25cae581e2d2 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:25:34 -0500 Subject: ZVISION: Add comments to AnimationControl::process() --- engines/zvision/animation_control.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp index cd5ebf1549..ca3e225a8a 100644 --- a/engines/zvision/animation_control.cpp +++ b/engines/zvision/animation_control.cpp @@ -74,6 +74,9 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { while (_accumulatedTime >= frameTime) { _accumulatedTime -= frameTime; + // Make sure the frame is inside the working window + // If it's not, then just return + RenderManager *renderManager = _engine->getRenderManager(); Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + _animation.rlf->width(), workingWindowPoint.y + _animation.rlf->height()); @@ -85,18 +88,21 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { const Graphics::Surface *frame = _animation.rlf->getNextFrame(); + // Animation frames for PANORAMAs are transposed, so un-transpose them RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); if (state == RenderTable::PANORAMA) { Graphics::Surface *tranposedFrame = RenderManager::tranposeSurface(frame); renderManager->copyRectToWorkingWindow((uint16 *)tranposedFrame->getBasePtr(tranposedFrame->w - subRect.width(), tranposedFrame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); + // Cleanup tranposedFrame->free(); delete tranposedFrame; } else { renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); } + // Check if we should continue looping if (_animation.rlf->endOfAnimation()) { _animation.rlf->seekToFrame(-1); if (_loopCount > 0) { @@ -116,6 +122,9 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { const Graphics::Surface *frame = _animation.avi->decodeNextFrame(); if (frame) { + // Make sure the frame is inside the working window + // If it's not, then just return + RenderManager *renderManager = _engine->getRenderManager(); Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + frame->w, workingWindowPoint.y + frame->h); @@ -125,22 +134,23 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { return false; } + // Animation frames for PANORAMAs are transposed, so un-transpose them RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); if (state == RenderTable::PANORAMA) { Graphics::Surface *tranposedFrame = RenderManager::tranposeSurface(frame); renderManager->copyRectToWorkingWindow((uint16 *)tranposedFrame->getBasePtr(tranposedFrame->w - subRect.width(), tranposedFrame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); + // Cleanup tranposedFrame->free(); delete tranposedFrame; } else { renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); } - - } } + // Check if we should continue looping if (_animation.avi->endOfVideo()) { _animation.avi->rewind(); if (_loopCount > 0) { @@ -153,6 +163,8 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { } } + // If we're done, set _animation key = 2 (Why 2? I don't know. It's just the value that they used) + // Then disable the control. DON'T delete it. It can be re-used if (finished) { _engine->getScriptManager()->setStateValue(_animationKey, 2); disable(); -- cgit v1.2.3 From edd1a117ae821d96498a78a357ab29018f1c019a Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 15:47:06 -0500 Subject: ZVISION: Cache animation frames so they can be re-rendered when the background moves --- engines/zvision/animation_control.cpp | 128 +++++++++++++++++++++++++--------- engines/zvision/animation_control.h | 2 + 2 files changed, 96 insertions(+), 34 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp index ca3e225a8a..8c8f6eb238 100644 --- a/engines/zvision/animation_control.cpp +++ b/engines/zvision/animation_control.cpp @@ -39,7 +39,8 @@ AnimationControl::AnimationControl(ZVision *engine, uint32 controlKey, const Com _fileType(RLF), _loopCount(1), _currentLoop(0), - _accumulatedTime(0) { + _accumulatedTime(0), + _cachedFrame(0) { if (fileName.hasSuffix(".rlf")) { _fileType = RLF; _animation.rlf = new RlfAnimation(fileName, false); @@ -50,6 +51,8 @@ AnimationControl::AnimationControl(ZVision *engine, uint32 controlKey, const Com } else { warning("Unrecognized animation file type: %s", fileName.c_str()); } + + _cachedFrame = new Graphics::Surface(); } AnimationControl::~AnimationControl() { @@ -58,6 +61,9 @@ AnimationControl::~AnimationControl() { } else if (_fileType == AVI) { delete _animation.avi; } + + _cachedFrame->free(); + delete _cachedFrame; } bool AnimationControl::process(uint32 deltaTimeInMillis) { @@ -71,47 +77,75 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { _accumulatedTime += deltaTimeInMillis; uint32 frameTime = _animation.rlf->frameTime(); - while (_accumulatedTime >= frameTime) { - _accumulatedTime -= frameTime; + if (_accumulatedTime >= frameTime) { + while (_accumulatedTime >= frameTime) { + _accumulatedTime -= frameTime; - // Make sure the frame is inside the working window - // If it's not, then just return + // Make sure the frame is inside the working window + // If it's not, then just return - RenderManager *renderManager = _engine->getRenderManager(); - Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); - Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + _animation.rlf->width(), workingWindowPoint.y + _animation.rlf->height()); + RenderManager *renderManager = _engine->getRenderManager(); + Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); + Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + _animation.rlf->width(), workingWindowPoint.y + _animation.rlf->height()); - // If the clip returns false, it means the animation is outside the working window - if (!renderManager->clipRectToWorkingWindow(subRect)) { - return false; - } + // If the clip returns false, it means the animation is outside the working window + if (!renderManager->clipRectToWorkingWindow(subRect)) { + return false; + } - const Graphics::Surface *frame = _animation.rlf->getNextFrame(); + const Graphics::Surface *frame = _animation.rlf->getNextFrame(); - // Animation frames for PANORAMAs are transposed, so un-transpose them - RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); - if (state == RenderTable::PANORAMA) { - Graphics::Surface *tranposedFrame = RenderManager::tranposeSurface(frame); + // Animation frames for PANORAMAs are transposed, so un-transpose them + RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); + if (state == RenderTable::PANORAMA) { + Graphics::Surface *tranposedFrame = RenderManager::tranposeSurface(frame); - renderManager->copyRectToWorkingWindow((uint16 *)tranposedFrame->getBasePtr(tranposedFrame->w - subRect.width(), tranposedFrame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); + renderManager->copyRectToWorkingWindow((uint16 *)tranposedFrame->getBasePtr(tranposedFrame->w - subRect.width(), tranposedFrame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); - // Cleanup - tranposedFrame->free(); - delete tranposedFrame; - } else { - renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); - } + // If the background can move, we need to cache the last frame so it can be rendered during background movement + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + _cachedFrame = tranposedFrame; + } else { + // Cleanup + tranposedFrame->free(); + delete tranposedFrame; + } + } else { + renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); + + // If the background can move, we need to cache the last frame so it can be rendered during background movement + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + _cachedFrame->copyFrom(*frame); + } + } - // Check if we should continue looping - if (_animation.rlf->endOfAnimation()) { - _animation.rlf->seekToFrame(-1); - if (_loopCount > 0) { - _currentLoop++; - if (_currentLoop >= _loopCount) { - finished = true; + // Check if we should continue looping + if (_animation.rlf->endOfAnimation()) { + _animation.rlf->seekToFrame(-1); + if (_loopCount > 0) { + _currentLoop++; + if (_currentLoop >= _loopCount) { + finished = true; + } } } } + } else { + // If the background can move, we have to keep rendering animation frames, otherwise the animation flickers during background movement + RenderManager *renderManager = _engine->getRenderManager(); + RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); + + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); + Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + _cachedFrame->w, workingWindowPoint.y + _cachedFrame->h); + + // If the clip returns false, it means the animation is outside the working window + if (!renderManager->clipRectToWorkingWindow(subRect)) { + return false; + } + + renderManager->copyRectToWorkingWindow((uint16 *)_cachedFrame->getBasePtr(_cachedFrame->w - subRect.width(), _cachedFrame->h - subRect.height()), subRect.left, subRect.top, _cachedFrame->w, subRect.width(), subRect.height()); + } } } else if (_fileType == AVI) { if (!_animation.avi->isPlaying()) { @@ -141,11 +175,37 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { renderManager->copyRectToWorkingWindow((uint16 *)tranposedFrame->getBasePtr(tranposedFrame->w - subRect.width(), tranposedFrame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); - // Cleanup - tranposedFrame->free(); - delete tranposedFrame; + // If the background can move, we need to cache the last frame so it can be rendered during background movement + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + _cachedFrame = tranposedFrame; + } else { + // Cleanup + tranposedFrame->free(); + delete tranposedFrame; + } } else { renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); + + // If the background can move, we need to cache the last frame so it can be rendered during background movement + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + _cachedFrame->copyFrom(*frame); + } + } + } else { + // If the background can move, we have to keep rendering animation frames, otherwise the animation flickers during background movement + RenderManager *renderManager = _engine->getRenderManager(); + RenderTable::RenderState state = renderManager->getRenderTable()->getRenderState(); + + if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + Common::Point workingWindowPoint = renderManager->imageSpaceToWorkingWindowSpace(Common::Point(_x, _y)); + Common::Rect subRect(workingWindowPoint.x, workingWindowPoint.y, workingWindowPoint.x + _cachedFrame->w, workingWindowPoint.y + _cachedFrame->h); + + // If the clip returns false, it means the animation is outside the working window + if (!renderManager->clipRectToWorkingWindow(subRect)) { + return false; + } + + renderManager->copyRectToWorkingWindow((uint16 *)_cachedFrame->getBasePtr(_cachedFrame->w - subRect.width(), _cachedFrame->h - subRect.height()), subRect.left, subRect.top, _cachedFrame->w, subRect.width(), subRect.height()); } } } diff --git a/engines/zvision/animation_control.h b/engines/zvision/animation_control.h index 036ce4b66b..6b104d4c06 100644 --- a/engines/zvision/animation_control.h +++ b/engines/zvision/animation_control.h @@ -64,6 +64,8 @@ private: uint _accumulatedTime; uint _currentLoop; + Graphics::Surface *_cachedFrame; + public: bool process(uint32 deltaTimeInMillis); -- cgit v1.2.3 From 072b852cdc627b060505d1a4da4e0bb4a0300c51 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 16:40:10 -0500 Subject: ZVISION: Remove extraneous methods from TrueTypeFont --- engines/zvision/truetype_font.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/truetype_font.h b/engines/zvision/truetype_font.h index 2618dc407e..48657417a2 100644 --- a/engines/zvision/truetype_font.h +++ b/engines/zvision/truetype_font.h @@ -106,10 +106,6 @@ public: void drawText(const Common::String &text, int x, int y, int width, TextAlign align = ALIGN_LEFT, int max_height = -1); int getLetterHeight(); - void initLoop() {} - void afterLoad() {} - - bool loadBuffer(byte *buffer); bool loadFile(const Common::String &filename); float getLineHeight() const { return _lineHeight; } @@ -121,7 +117,6 @@ public: private: void measureText(const Common::String &text, int maxWidth, int maxHeight, int &textWidthOut, int &textHeightOut); Graphics::Surface *renderTextToTexture(const Common::String &text, int width, TextAlign align, int maxHeight); - bool initFont(); }; } // End of namespace ZVision -- cgit v1.2.3 From f5f053d335f019a0c26dc8c11730cf0231d9bc60 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 16:40:38 -0500 Subject: ZVISION: Use default dpi for font --- engines/zvision/truetype_font.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/truetype_font.cpp b/engines/zvision/truetype_font.cpp index b3aafc26d7..dacd7967d3 100644 --- a/engines/zvision/truetype_font.cpp +++ b/engines/zvision/truetype_font.cpp @@ -75,7 +75,7 @@ bool TruetypeFont::loadFile(const Common::String &filename) { return false; } - _font = Graphics::loadTTFFont(file, 96, _fontHeight); // Use the same dpi as WME (96 vs 72). + _font = Graphics::loadTTFFont(file, _fontHeight); _lineHeight = _font->getFontHeight(); return true; -- cgit v1.2.3 From 4a4330cec727fd5e08015479bdec94331b2e7662 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 17:05:35 -0500 Subject: ZVISION: Cleanup the cached frame before loading the next one --- engines/zvision/animation_control.cpp | 25 ++++++++++++++++++++++++- engines/zvision/animation_control.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp index 8c8f6eb238..f80faea0f9 100644 --- a/engines/zvision/animation_control.cpp +++ b/engines/zvision/animation_control.cpp @@ -40,7 +40,8 @@ AnimationControl::AnimationControl(ZVision *engine, uint32 controlKey, const Com _loopCount(1), _currentLoop(0), _accumulatedTime(0), - _cachedFrame(0) { + _cachedFrame(0), + _cachedFrameNeedsDeletion(false) { if (fileName.hasSuffix(".rlf")) { _fileType = RLF; _animation.rlf = new RlfAnimation(fileName, false); @@ -104,7 +105,13 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { // If the background can move, we need to cache the last frame so it can be rendered during background movement if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + if (_cachedFrameNeedsDeletion) { + _cachedFrame->free(); + delete _cachedFrame; + _cachedFrameNeedsDeletion = false; + } _cachedFrame = tranposedFrame; + _cachedFrameNeedsDeletion = true; } else { // Cleanup tranposedFrame->free(); @@ -115,6 +122,11 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { // If the background can move, we need to cache the last frame so it can be rendered during background movement if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + if (_cachedFrameNeedsDeletion) { + _cachedFrame->free(); + delete _cachedFrame; + _cachedFrameNeedsDeletion = false; + } _cachedFrame->copyFrom(*frame); } } @@ -177,7 +189,13 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { // If the background can move, we need to cache the last frame so it can be rendered during background movement if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + if (_cachedFrameNeedsDeletion) { + _cachedFrame->free(); + delete _cachedFrame; + _cachedFrameNeedsDeletion = false; + } _cachedFrame = tranposedFrame; + _cachedFrameNeedsDeletion = true; } else { // Cleanup tranposedFrame->free(); @@ -188,6 +206,11 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { // If the background can move, we need to cache the last frame so it can be rendered during background movement if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + if (_cachedFrameNeedsDeletion) { + _cachedFrame->free(); + delete _cachedFrame; + _cachedFrameNeedsDeletion = false; + } _cachedFrame->copyFrom(*frame); } } diff --git a/engines/zvision/animation_control.h b/engines/zvision/animation_control.h index 6b104d4c06..935f4abb4b 100644 --- a/engines/zvision/animation_control.h +++ b/engines/zvision/animation_control.h @@ -65,6 +65,7 @@ private: uint _currentLoop; Graphics::Surface *_cachedFrame; + bool _cachedFrameNeedsDeletion; public: bool process(uint32 deltaTimeInMillis); -- cgit v1.2.3 From 0874212fa72264404803c3ebc0b75fc63f2be754 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 8 Sep 2013 17:06:06 -0500 Subject: ZVISION: Cleanup _currentFrameBuffer during descruction --- engines/zvision/rlf_animation.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 0ffeeb0f0f..5ce58e68fd 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -74,6 +74,7 @@ RlfAnimation::~RlfAnimation() { delete[] _frames[i].encodedData; } delete[] _frames; + _currentFrameBuffer.free(); } bool RlfAnimation::readHeader() { -- cgit v1.2.3 From d643ca1571eef1f81b5880fcb796f1ee268ef234 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:04:58 -0500 Subject: ZVISION: Remove unused Console functions --- engines/zvision/console.cpp | 39 --------------------------------------- engines/zvision/console.h | 3 --- 2 files changed, 42 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 8b4dffa98a..4ea4a8e963 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -51,9 +51,6 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("setpanoramascale", WRAP_METHOD(Console, cmdSetPanoramaScale)); DCmd_Register("changelocation", WRAP_METHOD(Console, cmdChangeLocation)); DCmd_Register("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); - DCmd_Register("dumpcursorfilenames", WRAP_METHOD(Console, cmdDumpAllCursorFileNames)); - DCmd_Register("showcursor", WRAP_METHOD(Console, cmdShowCursor)); - DCmd_Register("dumpalllevfiles", WRAP_METHOD(Console, cmdDumpAllLevFiles)); DCmd_Register("parseallscrfiles", WRAP_METHOD(Console, cmdParseAllScrFiles)); } @@ -190,42 +187,6 @@ bool Console::cmdDumpFile(int argc, const char **argv) { return true; } -bool Console::cmdDumpAllCursorFileNames(int argc, const char **argv) { - Common::DumpFile outputFile; - outputFile.open("cursorFileNames.txt"); - - Common::ArchiveMemberList list; - SearchMan.listMatchingMembers(list, "*.zcr"); - - // Register the file entries within the zfs archives with the SearchMan - for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { - outputFile.writeString((*iter)->getName()); - outputFile.writeByte('\n'); - } - - return true; -} - -bool Console::cmdShowCursor(int argc, const char **argv) { - ZorkCursor cursor(argv[1]); - - _engine->_system->copyRectToScreen(cursor.getSurface(), cursor.getWidth() * 2, 0, 0, cursor.getWidth(), cursor.getHeight()); - - return true; -} - -bool Console::cmdDumpAllLevFiles(int argc, const char **argv) { - Common::ArchiveMemberList list; - SearchMan.listMatchingMembers(list, "*.lev"); - - for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { - Common::String fileName = (*iter)->getName(); - writeFileContentsToFile(fileName, fileName); - } - - return true; -} - bool Console::cmdParseAllScrFiles(int argc, const char **argv) { Common::ArchiveMemberList list; SearchMan.listMatchingMembers(list, "*.scr"); diff --git a/engines/zvision/console.h b/engines/zvision/console.h index 612e5eec00..fdb20642e9 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -47,9 +47,6 @@ private: bool cmdSetPanoramaScale(int argc, const char **argv); bool cmdChangeLocation(int argc, const char **argv); bool cmdDumpFile(int argc, const char **argv); - bool cmdDumpAllCursorFileNames(int argc, const char **argv); - bool cmdShowCursor(int argc, const char **argv); - bool cmdDumpAllLevFiles(int argc, const char **argv); bool cmdParseAllScrFiles(int argc, const char **argv); }; -- cgit v1.2.3 From c20a9ac6ae3cac5ff45d5d2329ff8571d507b01f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:05:25 -0500 Subject: ZVISION: Add key press support to Controls --- engines/zvision/control.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index 9144c32dd4..baa2dfb4f3 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -25,6 +25,8 @@ #include "common/types.h" +#include "common/keyboard.h" + namespace Common { class SeekableReadStream; @@ -68,6 +70,18 @@ public: * @return Was the cursor changed? */ virtual bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { return false; } + /** + * Called when a key is pressed. Default is NOP. + * + * @param keycode The key that was pressed + */ + virtual void onKeyDown(Common::KeyState keyState) {} + /** + * Called when a key is released. Default is NOP. + * + * @param keycode The key that was pressed + */ + virtual void onKeyUp(Common::KeyState keyState) {} /** * Processes the node given the deltaTime since last frame. Default is NOP. * -- cgit v1.2.3 From d3b6caab2f122f05bc5ecae49bcce1c285cb09de Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:07:02 -0500 Subject: ZVISION: Remove unused key functions --- engines/zvision/events.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 9283328202..ae84a22d39 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -67,15 +67,6 @@ void ZVision::processEvents() { if (_event.kbd.hasFlags(Common::KBD_CTRL)) quitGame(); break; - case Common::KEYCODE_F1: - cycleThroughCursors(); - break; - case Common::KEYCODE_F2: - { - RlfAnimation *animation = new RlfAnimation("te2ea21c.rlf"); - playAnimation(animation, 0, 0); - break; - } default: break; } -- cgit v1.2.3 From 752807b4710ae7ff5c96f3ced985a56da0227d7c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:07:46 -0500 Subject: ZVISION: Add method to copy a portion of the working window to a surface --- engines/zvision/render_manager.cpp | 14 ++++++++++++++ engines/zvision/render_manager.h | 1 + 2 files changed, 15 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 04163fab61..38807a7457 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -311,6 +311,20 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i sourceOffset += imageWidth; } +void RenderManager::copyWorkingWindowSubRectToSurface(Graphics::Surface *destSurface, uint16 destX, uint16 destY, Common::Rect subRect) const { + uint32 destOffset = 0; + uint32 sourceOffset = 0; + uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(subRect.left, subRect.top); + uint16 *destPtr = (uint16 *)destSurface->getBasePtr(destX, destY); + + for (int32 y = 0; y < subRect.height(); y++) { + for (int32 x = 0; x < subRect.width(); x++) { + destPtr[destOffset + x] = workingWindowBufferPtr[sourceOffset + x]; + } + + destOffset += destSurface->w; + sourceOffset += _workingWidth; + } _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 51636ef682..ce5c774917 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -194,6 +194,7 @@ public: RenderTable *getRenderTable(); uint32 getCurrentBackgroundOffset(); const Graphics::Surface *getBackBuffer() { return &_backBuffer; } + void copyWorkingWindowSubRectToSurface(Graphics::Surface *destSurface, uint16 destX, uint16 destY, Common::Rect subRect) const; /** * Creates a copy of surface and transposes the data. -- cgit v1.2.3 From b50afa2b154c412c40b534a41e9654da8786f5e6 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:08:14 -0500 Subject: ZVISION: Remove unused function --- engines/zvision/zvision.cpp | 55 --------------------------------------------- engines/zvision/zvision.h | 10 +++------ 2 files changed, 3 insertions(+), 62 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index f8580703ca..09f5ea30b1 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -175,59 +175,4 @@ Common::String ZVision::generateAutoSaveFileName() { return Common::String::format("%s.auto", _targetName.c_str()); } -void ZVision::cycleThroughCursors() { - Common::ArchiveMemberList list; - SearchMan.listMatchingMembers(list, "*.zcr"); - - Common::ArchiveMemberList::iterator iter = list.begin(); - ZorkCursor cursor; - bool cursorChanged = false; - - _system->showMouse(true); - - bool done = false; - while (!done && !shouldQuit()) { - _clock.update(); - uint32 currentTime = _clock.getLastMeasuredTime(); - - while (_eventMan->pollEvent(_event)) { - if (_event.type == Common::EVENT_KEYDOWN) { - switch (_event.kbd.keycode) { - case Common::KEYCODE_LEFT: - --iter; - cursorChanged = true; - break; - case Common::KEYCODE_RIGHT: - ++iter; - cursorChanged = true; - break; - case Common::KEYCODE_RETURN: - debug("%s", (*iter)->getName().c_str()); - break; - case Common::KEYCODE_ESCAPE: - done = true; - break; - default: - break; - } - } - } - - if (cursorChanged) { - cursor = ZorkCursor((*iter)->getName()); - - _system->setMouseCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getHeight(), true, &_pixelFormat); - cursorChanged = false; - } - - _system->updateScreen(); - - // Calculate the frame delay based off a desired frame time - int delay = _desiredFrameTime - int32(_system->getMillis() - currentTime); - // Ensure non-negative - delay = delay < 0 ? 0 : delay; - _system->delayMillis(delay); - } -} - } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 1a259d0a22..2e5359b10b 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -131,18 +131,14 @@ public: void playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); void playAnimation(Video::VideoDecoder *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); - /** - * Utility method to cycle through all the cursors in the game. After - * calling, use Left and Right arrows to cycle. Esc to quit. This is a - * blocking function call. - */ - void cycleThroughCursors(); - Common::String generateSaveFileName(uint slot); Common::String generateAutoSaveFileName(); private: void initialize(); + void initFonts(); + + void parseStrFile(const Common::String fileName); /** Called every frame from ZVision::run() to process any events from EventMan */ void processEvents(); -- cgit v1.2.3 From 0eeeeded920d50444b0e8ca865725231dffb0961 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:09:16 -0500 Subject: ZVISION: Add ScriptManager support for key press events --- engines/zvision/script_manager.cpp | 12 ++++++++++++ engines/zvision/script_manager.h | 12 ++++++++++++ 2 files changed, 24 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index b9217e7250..8dd944b1e9 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -275,6 +275,18 @@ bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Commo return cursorWasChanged; } +void ScriptManager::onKeyDown(Common::KeyState keyState) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + (*iter)->onKeyDown(keyState); + } +} + +void ScriptManager::onKeyUp(Common::KeyState keyState) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + (*iter)->onKeyUp(keyState); + } +} + void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 offset) { assert(world != 0); debug("Changing location to: %c %c %c %c %u", world, room, node, view, offset); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 15d456ea6b..274905f88d 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -110,6 +110,18 @@ public: * @return Was the cursor changed? */ bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + /** + * Called when a key is pressed. + * + * @param keycode The key that was pressed + */ + void onKeyDown(Common::KeyState keyState); + /** + * Called when a key is released. + * + * @param keycode The key that was pressed + */ + void onKeyUp(Common::KeyState keyState); void changeLocation(char world, char room, char node, char view, uint32 offset); -- cgit v1.2.3 From 8ba295d7103322a5193cc051da81ae82ccf5947b Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:09:42 -0500 Subject: ZVISION: Add key press support to the main event loop --- engines/zvision/events.cpp | 10 ++++------ engines/zvision/zvision.h | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index ae84a22d39..1b6b2c2508 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -71,9 +71,11 @@ void ZVision::processEvents() { break; } - onKeyDown(_event.kbd.keycode); + _scriptManager->onKeyDown(_event.kbd); + break; + case Common::EVENT_KEYUP: + _scriptManager->onKeyUp(_event.kbd); break; - default: break; } @@ -177,8 +179,4 @@ void ZVision::onMouseMove(const Common::Point &pos) { } } -void ZVision::onKeyDown(uint keyCode) { - -} - } // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 2e5359b10b..94bcfdf171 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -146,7 +146,6 @@ private: void onMouseDown(const Common::Point &pos); void onMouseUp(const Common::Point &pos); void onMouseMove(const Common::Point &pos); - void onKeyDown(uint keyCode); }; } // End of namespace ZVision -- cgit v1.2.3 From 466eba1e9fb271b3d6b3a4e9f02a30a9333f68da Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:10:17 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/rlf_animation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 5ce58e68fd..79638511ad 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -156,7 +156,7 @@ RlfAnimation::Frame RlfAnimation::readNextFrame() { void RlfAnimation::seekToFrame(int frameNumber) { assert(!_stream); - assert(frameNumber < _frameCount || frameNumber >= -1); + assert(frameNumber < (int)_frameCount || frameNumber >= -1); if (frameNumber == -1) { _currentFrame = -1; @@ -173,7 +173,7 @@ void RlfAnimation::seekToFrame(int frameNumber) { } } - for (uint i = closestFrame; i <= frameNumber; i++) { + for (int i = closestFrame; i <= frameNumber; i++) { applyFrameToCurrent(i); } -- cgit v1.2.3 From 3986f333eff094d3104feae263b42e6e9ed85968 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:30:47 -0500 Subject: ZVISION: Move dirty rect extension to the correct function Source control mishap --- engines/zvision/render_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 38807a7457..62580323d3 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -311,6 +311,8 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i sourceOffset += imageWidth; } + _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); +} void RenderManager::copyWorkingWindowSubRectToSurface(Graphics::Surface *destSurface, uint16 destX, uint16 destY, Common::Rect subRect) const { uint32 destOffset = 0; uint32 sourceOffset = 0; @@ -325,7 +327,6 @@ void RenderManager::copyWorkingWindowSubRectToSurface(Graphics::Surface *destSur destOffset += destSurface->w; sourceOffset += _workingWidth; } - _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); } const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { -- cgit v1.2.3 From 36a0b666b3096da5a7ef169c598897be1cb06078 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:41:45 -0500 Subject: ZVISION: Add better alpha support for blitting Instead of blitting directly to the working window, we cache the alpha pixels, then blit directly to the backbuffer instead of to the working window. This ensures that if the alpha'd content changes, the old changes won't appear in any new frames --- engines/zvision/render_manager.cpp | 49 +++++++++++++++++++++++++++++++------- engines/zvision/render_manager.h | 13 ++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 62580323d3..72fa5d3fc6 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -98,11 +98,37 @@ void RenderManager::renderBackbufferToScreen() { // TODO: Add menu rendering + // Render alpha entries + processAlphaEntries(); + if (!_backBufferDirtyRect.isEmpty()) { _system->copyRectToScreen(_backBuffer.getBasePtr(_backBufferDirtyRect.left, _backBufferDirtyRect.top), _backBuffer.pitch, _backBufferDirtyRect.left, _backBufferDirtyRect.top, _backBufferDirtyRect.width(), _backBufferDirtyRect.height()); } } +void RenderManager::processAlphaEntries() { + for (Common::List::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { + uint32 destOffset = 0; + uint32 sourceOffset = 0; + uint16 *backbufferPtr = (uint16 *)_backBuffer.getBasePtr((*iter).destX + _workingWindow.left, (*iter).destY + _workingWindow.top); + uint16 *entryPtr = (uint16 *)(*iter).data->getPixels(); + + for (int32 y = 0; y < (*iter).height; y++) { + for (int32 x = 0; x < (*iter).width; x++) { + uint16 color = entryPtr[sourceOffset + x]; + if (color != (*iter).alphaColor) { + backbufferPtr[destOffset + x] = color; + } + } + + destOffset += _workingWidth; + sourceOffset += (*iter).width; + } + + _backBufferDirtyRect.extend(Common::Rect((*iter).destX + _workingWindow.left, (*iter).destY + _workingWindow.top, (*iter).destX + _workingWindow.left + (*iter).width, (*iter).destY + _workingWindow.top + (*iter).height)); + } +} + void RenderManager::clearWorkingWindowTo555Color(uint16 color) { uint32 workingWindowSize = _workingWidth * _workingHeight; byte r, g, b; @@ -295,24 +321,31 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i } void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor) { - uint32 destOffset = 0; + AlphaDataEntry entry; + entry.alphaColor = alphaColor; + entry.data = new Graphics::Surface(); + entry.data->create(width, height, _pixelFormat); + entry.destX = destX; + entry.destY = destY; + entry.width = width; + entry.height = height; + uint32 sourceOffset = 0; - uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(destX, destY); + uint32 destOffset = 0; + uint16 *surfacePtr = (uint16 *)entry.data->getPixels(); for (int32 y = 0; y < height; y++) { for (int32 x = 0; x < width; x++) { - uint16 color = buffer[sourceOffset + x]; - if (color != alphaColor) { - workingWindowBufferPtr[destOffset + x] = color; - } + surfacePtr[destOffset + x] = buffer[sourceOffset + x]; } - destOffset += _workingWidth; + destOffset += width; sourceOffset += imageWidth; } - _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); + _alphaDataEntries.push_back(entry); } + void RenderManager::copyWorkingWindowSubRectToSurface(Graphics::Surface *destSurface, uint16 destX, uint16 destY, Common::Rect subRect) const { uint32 destOffset = 0; uint32 sourceOffset = 0; diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index ce5c774917..f6106b39a3 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -48,6 +48,16 @@ public: RenderManager(OSystem *system, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat); ~RenderManager(); +private: + struct AlphaDataEntry { + Graphics::Surface *data; + uint16 alphaColor; + uint16 destX; + uint16 destY; + uint16 width; + uint16 height; + }; + private: OSystem *_system; const Graphics::PixelFormat _pixelFormat; @@ -56,6 +66,7 @@ private: // It's used for panorama/tilt warping and for clearing the workingWindow to a single color Graphics::Surface _workingWindowBuffer; Graphics::Surface _backBuffer; + Common::List _alphaDataEntries; Common::Rect _workingWindowDirtyRect; Common::Rect _backBufferDirtyRect; @@ -108,6 +119,8 @@ public: */ void renderBackbufferToScreen(); + void processAlphaEntries(); + void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height); void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor); -- cgit v1.2.3 From 259d11762dbf32ec1db6869510657331bb8c88e9 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:42:55 -0500 Subject: ZVISION: Add support for ActionRandom and ActionTimer They were already implemented, they just weren't being used --- engines/zvision/scr_file_handling.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 3d4718557f..fa89f756e4 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -208,7 +208,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:quit*", true)) { actionList.push_back(new ActionQuit()); } else if (line.matchString("*:random*", true)) { - // TODO: Implement ActionRandom + actionList.push_back(new ActionRandom(line)); } else if (line.matchString("*:region*", true)) { // TODO: Implement ActionRegion } else if (line.matchString("*:restore_game*", true)) { @@ -230,7 +230,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:syncsound*", true)) { // TODO: Implement ActionSyncSound } else if (line.matchString("*:timer*", true)) { - // TODO: Implement ActionTimer + actionList.push_back(new ActionTimer(line)); } else if (line.matchString("*:ttytext*", true)) { // TODO: Implement ActionTTYText } else if (line.matchString("*:universe_music*", true)) { -- cgit v1.2.3 From 0d78208562ad1709170734195587ac6e6a597dae Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:43:41 -0500 Subject: ZVISION: Add focus support for Controls --- engines/zvision/control.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/control.h b/engines/zvision/control.h index baa2dfb4f3..a279381298 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -48,6 +48,8 @@ public: virtual void enable(); virtual void disable(); + virtual void focus() {} + virtual void unfocus() {} /** * Called when LeftMouse is pushed. Default is NOP. * -- cgit v1.2.3 From 6ee253a4d8dce2f8c45f8d8256b49505db9eff4e Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:44:33 -0500 Subject: ZVISION: Add focus support for the ScriptManager --- engines/zvision/script_manager.cpp | 17 ++++++++++++++++- engines/zvision/script_manager.h | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 8dd944b1e9..3126aee8bb 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -38,7 +38,8 @@ namespace ZVision { ScriptManager::ScriptManager(ZVision *engine) - : _engine(engine) { + : _engine(engine), + _currentlyFocusedControl(0) { } ScriptManager::~ScriptManager() { @@ -254,6 +255,20 @@ void ScriptManager::disableControl(uint32 key) { } } +void ScriptManager::focusControl(uint32 key) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + uint32 controlKey = (*iter)->getKey(); + + if (controlKey == key) { + (*iter)->focus(); + } else if (controlKey == _currentlyFocusedControl) { + (*iter)->unfocus(); + } + } + + _currentlyFocusedControl = key; +} + void ScriptManager::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { (*iter)->onMouseDown(screenSpacePos, backgroundImageSpacePos); diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 274905f88d..349f259198 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -74,6 +74,8 @@ private: Location _currentLocation; + uint32 _currentlyFocusedControl; + public: void initialize(); void update(uint deltaTimeMillis); @@ -88,6 +90,8 @@ public: void enableControl(uint32 key); void disableControl(uint32 key); + void focusControl(uint32 key); + /** * Called when LeftMouse is pushed. * -- cgit v1.2.3 From 5cd1d2d1c2d9fc754450f548cff9aa8afaffd975 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:45:02 -0500 Subject: ZVISION: Ensure getControl always returns something --- engines/zvision/script_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 3126aee8bb..1acbcdfcf2 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -235,6 +235,8 @@ Control *ScriptManager::getControl(uint32 key) { return (*iter); } } + + return nullptr; } void ScriptManager::enableControl(uint32 key) { -- cgit v1.2.3 From 2900aaa90a87a1821578cadd457ba2465f02de01 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:45:23 -0500 Subject: ZVISION: Add a reminder for how inventory is accessed --- engines/zvision/events.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 1b6b2c2508..c1b894c290 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -48,6 +48,7 @@ void ZVision::processEvents() { break; case Common::EVENT_RBUTTONDOWN: + // TODO: Inventory logic break; case Common::EVENT_MOUSEMOVE: -- cgit v1.2.3 From a2d19c7a6e5f80d8a3a6e0fa296e45c24442ed5f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:45:53 -0500 Subject: ZVISION: Actually store the ZVision pointer --- engines/zvision/save_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.h b/engines/zvision/save_manager.h index ae65750b42..219a8e7715 100644 --- a/engines/zvision/save_manager.h +++ b/engines/zvision/save_manager.h @@ -44,7 +44,7 @@ struct SaveGameHeader { class SaveManager { public: - SaveManager(ZVision *engine); + SaveManager(ZVision *engine) : _engine(engine) {} private: ZVision *_engine; -- cgit v1.2.3 From f6c36aa14ce31340694292063722e1e7d0ba6840 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:46:35 -0500 Subject: ZVISION: Create an instance of the SaveManager --- engines/zvision/zvision.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 09f5ea30b1..f1e525d2d5 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -39,6 +39,7 @@ #include "zvision/script_manager.h" #include "zvision/render_manager.h" #include "zvision/cursor_manager.h" +#include "zvision/save_manager.h" #include "zvision/zfs_archive.h" #include "zvision/detection.h" @@ -71,6 +72,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _scriptManager = new ScriptManager(this); _renderManager = new RenderManager(_system, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _pixelFormat); + _saveManager = new SaveManager(this); debug("ZVision::ZVision"); } -- cgit v1.2.3 From c643718dae5ca7f7fce8672ffa6000661e9fceaa Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:51:32 -0500 Subject: ZVISION: Clean up the TruetypeFont class and add alpha support Remove caching. We don't render font enough to warrant it. Use Graphics::TextAlign instead of rolling our own. Remove methods we don't use. --- engines/zvision/truetype_font.cpp | 128 +++++++------------------------------- engines/zvision/truetype_font.h | 65 +------------------ 2 files changed, 26 insertions(+), 167 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/truetype_font.cpp b/engines/zvision/truetype_font.cpp index dacd7967d3..d88f22a727 100644 --- a/engines/zvision/truetype_font.cpp +++ b/engines/zvision/truetype_font.cpp @@ -26,6 +26,7 @@ #include "common/file.h" #include "common/system.h" +#include "graphics/font.h" #include "graphics/fonts/ttf.h" #include "graphics/surface.h" @@ -36,43 +37,27 @@ namespace ZVision { -TruetypeFont::TruetypeFont(ZVision *engine, int32 fontHeight, const Graphics::PixelFormat pixelFormat) +TruetypeFont::TruetypeFont(ZVision *engine, int32 fontHeight) : _engine(engine), - _pixelFormat(pixelFormat), - _isBold(false), - _isItalic(false), - _isStriked(false), - _isUnderline(false), _fontHeight(fontHeight), _font(0), _lineHeight(0), _maxCharWidth(0), _maxCharHeight(0) { - for (int i = 0; i < NUM_CACHED_TEXTS; i++) { - _cachedTexts[i] = 0; - } } TruetypeFont::~TruetypeFont(void) { - clearCache(); - delete _font; } -void TruetypeFont::clearCache() { - for (int i = 0; i < NUM_CACHED_TEXTS; i++) { - if (_cachedTexts[i]) { - delete _cachedTexts[i]; - } - _cachedTexts[i] = 0; - } -} - bool TruetypeFont::loadFile(const Common::String &filename) { Common::File file; - if (file.open(filename)) { - debug("TTF font file %s could not be opened", filename.c_str()); - return false; + + if (!Common::File::exists(filename)) { + debug("TTF font file %s was not found. Reverting to arial.ttf", filename.c_str()); + file.open("arial.ttf"); + } else { + file.open(filename); } _font = Graphics::loadTTFFont(file, _fontHeight); @@ -81,65 +66,25 @@ bool TruetypeFont::loadFile(const Common::String &filename) { return true; } -void TruetypeFont::drawText(const Common::String &text, int x, int y, int width, TextAlign align, int maxHeight) { +Graphics::Surface *TruetypeFont::drawTextToSurface(const Common::String &text, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap) { if (text.equals("")) { - return; - } - - // Find the cached surface, if it exists - uint32 minUseTime = UINT_MAX; - int minIndex = -1; - Graphics::Surface *surface = nullptr; - - for (int i = 0; i < NUM_CACHED_TEXTS; i++) { - if (_cachedTexts[i] == nullptr) { - minUseTime = 0; - minIndex = i; - } else { - if (_cachedTexts[i]->_text == text && _cachedTexts[i]->_align == align && _cachedTexts[i]->_width == width && _cachedTexts[i]->_maxHeight == maxHeight) { - surface = _cachedTexts[i]->_surface; - _cachedTexts[i]->_marked = true; - _cachedTexts[i]->_lastUsed = g_system->getMillis(); - break; - } else { - if (_cachedTexts[i]->_lastUsed < minUseTime) { - minUseTime = _cachedTexts[i]->_lastUsed; - minIndex = i; - } - } - } + return nullptr; } - // It's not cached, so create one - if (!surface) { - surface = renderTextToTexture(text, width, align, maxHeight); - if (surface) { - // Write the new surface to cache - if (_cachedTexts[minIndex] != nullptr) { - delete _cachedTexts[minIndex]; - } - _cachedTexts[minIndex] = new CachedText; - - _cachedTexts[minIndex]->_surface = surface; - _cachedTexts[minIndex]->_align = align; - _cachedTexts[minIndex]->_width = width; - _cachedTexts[minIndex]->_maxHeight = maxHeight; - _cachedTexts[minIndex]->_text = text; - _cachedTexts[minIndex]->_marked = true; - _cachedTexts[minIndex]->_lastUsed = _engine->_system->getMillis(); - } - } + Graphics::Surface *surface = new Graphics::Surface(); + if (!wrap) { + int width = MIN(_font->getStringWidth(text), maxWidth); + surface->create(width, _lineHeight, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); + // Copy the pixels from the RenderManager::_workingWindow, so we can get nice antialiasing + _engine->getRenderManager()->copyWorkingWindowSubRectToSurface(surface, 0, 0, Common::Rect(destX, destY, destX + width, destY + _lineHeight)); - // Render it to the working window - if (surface) { - _engine->getRenderManager()->copyRectToWorkingWindow((uint16 *)surface->getPixels(), x, y, surface->w, surface->w, surface->h); + _font->drawString(surface, text, destX, destY, maxWidth, textColor, align); + return surface; } -} -Graphics::Surface *TruetypeFont::renderTextToTexture(const Common::String &text, int width, TextAlign align, int maxHeight) { Common::Array lines; - _font->wordWrapText(text, width, lines); + _font->wordWrapText(text, maxWidth, lines); while (maxHeight > 0 && lines.size() * _lineHeight > maxHeight) { lines.pop_back(); @@ -148,44 +93,17 @@ Graphics::Surface *TruetypeFont::renderTextToTexture(const Common::String &text, return nullptr; } - Graphics::TextAlign alignment = Graphics::kTextAlignInvalid; - if (align == ALIGN_LEFT) { - alignment = Graphics::kTextAlignLeft; - } else if (align == ALIGN_CENTER) { - alignment = Graphics::kTextAlignCenter; - } else if (align == ALIGN_RIGHT) { - alignment = Graphics::kTextAlignRight; - } - - Graphics::Surface *surface = new Graphics::Surface(); - surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), _pixelFormat); + surface->create(maxWidth, lines.size() * _lineHeight, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); + // Copy the pixels from the RenderManager::_workingWindow, so we can get nice antialiasing + _engine->getRenderManager()->copyWorkingWindowSubRectToSurface(surface, 0, 0, Common::Rect(destX, destY, destX + maxWidth, destY + lines.size() * _lineHeight)); - uint32 alphaColor = 0xffffffff; int heightOffset = 0; for (Common::Array::iterator it = lines.begin(); it != lines.end(); it++) { - _font->drawString(surface, *it, 0, heightOffset, width, alphaColor, alignment); + _font->drawString(surface, *it, destX, destY + heightOffset, maxWidth, textColor, align); heightOffset += (int)_lineHeight; } return surface; - // TODO: _isUnderline, _isBold, _isItalic, _isStriked -} - -void TruetypeFont::measureText(const Common::String &text, int maxWidth, int maxHeight, int &textWidthOut, int &textHeightOut) { - if (maxWidth >= 0) { - Common::Array lines; - _font->wordWrapText(text, maxWidth, lines); - Common::Array::iterator it; - textWidthOut = 0; - for (it = lines.begin(); it != lines.end(); ++it) { - textWidthOut = MAX(textWidthOut, _font->getStringWidth(*it)); - } - - textHeightOut = (int)(lines.size() * getLineHeight()); - } else { - textWidthOut = _font->getStringWidth(text); - textHeightOut = _fontHeight; - } } } // End of namespace ZVision diff --git a/engines/zvision/truetype_font.h b/engines/zvision/truetype_font.h index 48657417a2..c8d0a95b28 100644 --- a/engines/zvision/truetype_font.h +++ b/engines/zvision/truetype_font.h @@ -28,7 +28,7 @@ #include "common/types.h" #include "graphics/font.h" - +#include "graphics/pixelformat.h" namespace Graphics { struct Surface; @@ -40,83 +40,24 @@ class ZVision; class TruetypeFont { public: - TruetypeFont(ZVision *engine, int32 fontHeight, const Graphics::PixelFormat pixelFormat); + TruetypeFont(ZVision *engine, int32 fontHeight); ~TruetypeFont(); -public: - enum { - NUM_CACHED_TEXTS = 30 - }; - - enum TextAlign { - ALIGN_LEFT = 0, - ALIGN_RIGHT, - ALIGN_CENTER - }; - - class CachedText { - public: - Common::String _text; - int32 _width; - TextAlign _align; - int32 _maxHeight; - Graphics::Surface *_surface; - int32 _textOffset; - bool _marked; - uint32 _lastUsed; - - CachedText() { - _width = _maxHeight = -1; - _align = ALIGN_LEFT; - _surface = 0; - _lastUsed = 0; - _marked = false; - } - - virtual ~CachedText() { - delete _surface; - } - }; - private: ZVision *_engine; - const Graphics::PixelFormat _pixelFormat; - Graphics::Font *_font; - float _lineHeight; size_t _maxCharWidth; size_t _maxCharHeight; - CachedText *_cachedTexts[NUM_CACHED_TEXTS]; - public: - bool _isBold; - bool _isItalic; - bool _isUnderline; - bool _isStriked; int32 _fontHeight; - //BaseArray _layers; - public: - int getTextWidth(const byte *text, int maxLength = -1); - int getTextHeight(const byte *text, int width); - void drawText(const Common::String &text, int x, int y, int width, TextAlign align = ALIGN_LEFT, int max_height = -1); - int getLetterHeight(); - bool loadFile(const Common::String &filename); - - float getLineHeight() const { return _lineHeight; } - void clearCache(); - - static TruetypeFont *createFromFile(ZVision *game, const Common::String &filename); - -private: - void measureText(const Common::String &text, int maxWidth, int maxHeight, int &textWidthOut, int &textHeightOut); - Graphics::Surface *renderTextToTexture(const Common::String &text, int width, TextAlign align, int maxHeight); + Graphics::Surface *drawTextToSurface(const Common::String &text, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap); }; } // End of namespace ZVision -- cgit v1.2.3 From dc8c7ca2c04372a39af5cca80040daa8923e9658 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:52:27 -0500 Subject: ZVISION: Add RenderManager text support --- engines/zvision/render_manager.cpp | 16 ++++++++++++++++ engines/zvision/render_manager.h | 3 +++ 2 files changed, 19 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 72fa5d3fc6..1c1ce40c6c 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -346,6 +346,22 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i _alphaDataEntries.push_back(entry); } +Common::Rect RenderManager::renderTextToWorkingWindow(const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap) { + AlphaDataEntry entry; + entry.alphaColor = 0; + entry.destX = destX; + entry.destY = destY; + + // Draw the text to the working window + entry.data = font->drawTextToSurface(text, destX, destY, textColor, maxWidth, maxHeight, align, wrap); + entry.width = entry.data->w; + entry.height = entry.data->h; + + _alphaDataEntries.push_back(entry); + + return Common::Rect(destX, destY, destX + entry.width, destY + entry.height); +} + void RenderManager::copyWorkingWindowSubRectToSurface(Graphics::Surface *destSurface, uint16 destX, uint16 destY, Common::Rect subRect) const { uint32 destOffset = 0; uint32 sourceOffset = 0; diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index f6106b39a3..84914cc5d3 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -29,6 +29,7 @@ #include "graphics/surface.h" #include "zvision/render_table.h" +#include "zvision/truetype_font.h" class OSystem; @@ -124,6 +125,8 @@ public: void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height); void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor); + Common::Rect renderTextToWorkingWindow(const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight = -1, Graphics::TextAlign align = Graphics::kTextAlignLeft, bool wrap = true); + /** * Fills the entire workingWindow with the specified color * -- cgit v1.2.3 From 05b3b170d45125ba52c7b795a89d3ce8141c77ab Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:53:23 -0500 Subject: ZVISION: Add more documentation for clearWorkingWindowTo555Color() --- engines/zvision/render_manager.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 84914cc5d3..50d2d1076f 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -128,7 +128,8 @@ public: Common::Rect renderTextToWorkingWindow(const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight = -1, Graphics::TextAlign align = Graphics::kTextAlignLeft, bool wrap = true); /** - * Fills the entire workingWindow with the specified color + * Fills the entire workingWindow with the specified color. Internally, the color + * will be converted to RGB 565 and then blitted. * * @param color The color to fill the working window with. (In RGB 555) */ -- cgit v1.2.3 From 82ea7ca0e7bad570195f41392f717a42254aff5f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:55:37 -0500 Subject: ZVISION: Create the StringManager class This parses the XXXXX.STR files into styled fonts and phrases. The styles and the phrases are used in the game for messages to the user and for general purpose fonts. --- engines/zvision/module.mk | 1 + engines/zvision/string_manager.cpp | 235 +++++++++++++++++++++++++++++++++++++ engines/zvision/string_manager.h | 84 +++++++++++++ 3 files changed, 320 insertions(+) create mode 100644 engines/zvision/string_manager.cpp create mode 100644 engines/zvision/string_manager.h (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 9fa119d353..cb4a3609e9 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -22,6 +22,7 @@ MODULE_OBJS := \ script_manager.o \ scripts.o \ single_value_container.o \ + string_manager.o \ timer_node.o \ truetype_font.o \ utility.o \ diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp new file mode 100644 index 0000000000..818b60c732 --- /dev/null +++ b/engines/zvision/string_manager.cpp @@ -0,0 +1,235 @@ +/* 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/scummsys.h" + +#include "common/file.h" +#include "common/tokenizer.h" +#include "common/debug.h" + +#include "graphics/fontman.h" + +#include "zvision/string_manager.h" +#include "zvision/truetype_font.h" + + +namespace ZVision { + +const Graphics::PixelFormat StringManager::_pixelFormat565 = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); + +StringManager::StringManager(ZVision *engine) + : _engine(engine) { +} + +StringManager::~StringManager() { + for (Common::HashMap::iterator iter = _fonts.begin(); iter != _fonts.end(); iter++) { + delete (*iter)._value; + } +} + +void StringManager::initialize(ZVisionGameId gameId) { + if (gameId == ZorkNemesis) { + // TODO: Check this hardcoded filename against all versions of Nemesis + parseStrFile("nemesis.str"); + } else if (gameId == ZorkGrandInquisitor) { + // TODO: Check this hardcoded filename against all versions of Grand Inquisitor + parseStrFile("inquis.str"); + } +} + +void StringManager::parseStrFile(const Common::String &fileName) { + Common::File file; + if (!file.open(fileName)) { + warning("%s does not exist. String parsing failed", fileName.c_str()); + return; + } + + Common::String line = file.readLine(); + + uint lineNumber = 0; + while (!file.eos()) { + Common::String asciiLine = wideToASCII(line.c_str(), line.size()); + + char tagString[150]; + uint tagStringCursor = 0; + char textString[150]; + uint textStringCursor = 0; + bool inTag = false; + + for (uint i = 0; i < asciiLine.size(); i++) { + switch (asciiLine[i]) { + case '<': + inTag = true; + break; + case '>': + inTag = false; + parseTag(Common::String(tagString, tagStringCursor), Common::String(textString, textStringCursor), i); + tagStringCursor = 0; + textStringCursor = 0; + break; + default: + if (inTag) { + textString[tagStringCursor] = asciiLine[i]; + tagStringCursor++; + } else { + textString[textStringCursor] = asciiLine[i]; + textStringCursor++; + } + break; + } + } + + // STR files add a null character after the CR/LF. We need to skip over that before we can read another line + file.readByte(); + + line = file.readLine(); + lineNumber++; + } +} + +void StringManager::parseTag(const Common::String &tagString, const Common::String &textString, uint lineNumber) { + Common::StringTokenizer tokenizer(tagString); + + Common::String token = tokenizer.nextToken(); + + Common::String fontName; + bool bold = false; + Graphics::TextAlign align = Graphics::kTextAlignLeft; + int point = 12; + int red = 0; + int green = 0; + int blue = 0; + + while (!token.empty()) { + if (token.matchString("font", true)) { + fontName = tokenizer.nextToken(); + } else if (token.matchString("bold", true)) { + token = tokenizer.nextToken(); + if (token.matchString("on", false)) { + bold = true; + } + } else if (token.matchString("justify", true)) { + token = tokenizer.nextToken(); + if (token.matchString("center", false)) { + align = Graphics::kTextAlignCenter; + } else if (token.matchString("right", false)) { + align = Graphics::kTextAlignRight; + } + } else if (token.matchString("point", true)) { + point = atoi(tokenizer.nextToken().c_str()); + } else if (token.matchString("red", true)) { + red = atoi(tokenizer.nextToken().c_str()); + } else if (token.matchString("green", true)) { + green = atoi(tokenizer.nextToken().c_str()); + } else if (token.matchString("blue", true)) { + blue = atoi(tokenizer.nextToken().c_str()); + } + + token = tokenizer.nextToken(); + } + + Common::String newFontName; + if (fontName.matchString("times new roman", true)) { + if (bold) { + newFontName = "timesbd.ttf"; + } else { + newFontName = "times.ttf"; + } + } else if (fontName.matchString("courier new", true)) { + if (bold) { + newFontName = "courbd.ttf"; + } else { + newFontName = "cour.ttf"; + } + } else if (fontName.matchString("century schoolbook", true)) { + if (bold) { + newFontName = "censcbkbd.ttf"; + } else { + newFontName = "censcbk.ttf"; + } + } else if (fontName.matchString("times new roman", true)) { + if (bold) { + newFontName = "courbd.ttf"; + } else { + newFontName = "cour.ttf"; + } + } else { + debug("Could not identify font: %s. Reverting to Arial", fontName.c_str()); + if (bold) { + newFontName = "zorknorm.ttf"; + } else { + newFontName = "arial.ttf"; + } + } + + // Push an empty TextFragment onto the end of the list + // Creating the TextFragement before filling it prevents extra data copying during creation + _inGameText->fragments.push_back(TextFragment()); + TextFragment *fragment = &_inGameText->fragments.back(); + + Common::String fontKey = Common::String::format("%s-&d", newFontName.c_str(), point); + if (_fonts.contains(fontKey)) { + fragment->style.font = _fonts[fontKey]; + } else { + fragment->style.font = new TruetypeFont(_engine, point); + fragment->style.font->loadFile(newFontName); + } + + fragment->style.align = align; + fragment->style.color = _pixelFormat565.ARGBToColor(0, red, green, blue); + fragment->text = textString; +} + +Common::String StringManager::wideToASCII(const char *wideStr, uint arrayLength) { + // TODO: Contemplate using a largish static buffer instead of a dynamic heap buffer + uint newSize = arrayLength / 2; + char *asciiString = new char[newSize]; + + // Don't spam the user with warnings about UTF-16 support. + // Just do one warning per String + bool charOverflowWarning = false; + // Crush each octet pair to a single octet with a simple cast + for (uint i = 0; i < newSize; i++) { + uint16 value = READ_LE_UINT16(wideStr + (i * 2)); + if (value > 255) { + charOverflowWarning = true; + value = 255; + } + asciiString[i] = (char)value; + } + + if (charOverflowWarning) { + warning("UTF-16 is not supported. Characters greater than 255 are clamped to 255"); + } + + Common::String returnString(asciiString, newSize); + // Cleanup. Common::String constructor does a memmove() internally so we can safely delete + delete[] asciiString; + + return returnString; +} + +StringManager::TextStyle StringManager::getTextStyle(uint stringNumber) { + return _inGameText[stringNumber].fragments.front().style; +} + +} // End of namespace ZVision diff --git a/engines/zvision/string_manager.h b/engines/zvision/string_manager.h new file mode 100644 index 0000000000..a9d2dc1a1d --- /dev/null +++ b/engines/zvision/string_manager.h @@ -0,0 +1,84 @@ +/* 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 ZVISION_STRING_MANAGER_H +#define ZVISION_STRING_MANAGER_H + +#include "common/types.h" + +#include "zvision/detection.h" +#include "zvision/truetype_font.h" + + +namespace Graphics { +class FontManager; +} + +namespace ZVision { + +class ZVision; + +class StringManager { +public: + StringManager(ZVision *engine); + ~StringManager(); + +public: + struct TextStyle { + TruetypeFont *font; + uint16 color; // In RBG 565 + Graphics::TextAlign align; + }; + + struct TextFragment { + TextStyle style; + Common::String text; + }; + +private: + struct InGameText { + Common::List fragments; + }; + +private: + ZVision *_engine; + // NOTE: We hardcode this number because we know ZNem uses 42 strings and ZGI uses 56 + InGameText _inGameText[56]; + Common::HashMap _fonts; + + static const Graphics::PixelFormat _pixelFormat565; + +public: + void initialize(ZVisionGameId gameId); + StringManager::TextStyle getTextStyle(uint stringNumber); + +private: + void parseStrFile(const Common::String &fileName); + void parseTag(const Common::String &tagString, const Common::String &textString, uint lineNumber); + + static Common::String wideToASCII(const char *wideStr, uint arrayLength); +}; + +} // End of namespace ZVision + +#endif -- cgit v1.2.3 From c312b147fa7f5a28491975ae0bcc4b419e7e126a Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 14:55:59 -0500 Subject: ZVISION: Create an instance of StringManager --- engines/zvision/zvision.cpp | 3 ++- engines/zvision/zvision.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index f1e525d2d5..dc1cf476a7 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -40,6 +40,7 @@ #include "zvision/render_manager.h" #include "zvision/cursor_manager.h" #include "zvision/save_manager.h" +#include "zvision/string_manager.h" #include "zvision/zfs_archive.h" #include "zvision/detection.h" @@ -71,8 +72,8 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); _renderManager = new RenderManager(_system, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _pixelFormat); - _saveManager = new SaveManager(this); + _stringManager = new StringManager(this); debug("ZVision::ZVision"); } diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 94bcfdf171..a481aba28f 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -48,6 +48,7 @@ class Console; class ScriptManager; class RenderManager; class CursorManager; +class StringManager; class SaveManager; class RlfAnimation; @@ -97,6 +98,7 @@ private: RenderManager *_renderManager; CursorManager *_cursorManager; SaveManager *_saveManager; + StringManager *_stringManager; // Clock Clock _clock; @@ -114,6 +116,7 @@ public: RenderManager *getRenderManager() const { return _renderManager; } CursorManager *getCursorManager() const { return _cursorManager; } SaveManager *getSaveManager() const { return _saveManager; } + StringManager *getStringManager() const { return _stringManager; } Common::RandomSource *getRandomSource() const { return _rnd; } ZVisionGameId getGameId() const { return _gameDescription->gameId; } -- cgit v1.2.3 From d82ff7aea8d866bf5be2accfab321c39dd727c66 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 16:26:49 -0500 Subject: ZVISION: Create Console method to render text --- engines/zvision/console.cpp | 12 ++++++++++++ engines/zvision/console.h | 1 + 2 files changed, 13 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 4ea4a8e963..3969aa1f14 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -32,6 +32,7 @@ #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" +#include "zvision/string_manager.h" #include "zvision/zork_avi_decoder.h" #include "zvision/zork_raw.h" #include "zvision/utility.h" @@ -52,6 +53,7 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) { DCmd_Register("changelocation", WRAP_METHOD(Console, cmdChangeLocation)); DCmd_Register("dumpfile", WRAP_METHOD(Console, cmdDumpFile)); DCmd_Register("parseallscrfiles", WRAP_METHOD(Console, cmdParseAllScrFiles)); + DCmd_Register("rendertext", WRAP_METHOD(Console, cmdRenderText)); } bool Console::cmdLoadImage(int argc, const char **argv) { @@ -198,4 +200,14 @@ 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(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); +} + } // End of namespace ZVision diff --git a/engines/zvision/console.h b/engines/zvision/console.h index fdb20642e9..0ca1b8cc70 100644 --- a/engines/zvision/console.h +++ b/engines/zvision/console.h @@ -48,6 +48,7 @@ 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 -- cgit v1.2.3 From 2b2f85063afd2fcd5d7b24851ad697de58e9c8a6 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 15 Sep 2013 16:27:19 -0500 Subject: ZVISION: Clean up StringManager and SaveManager after use --- engines/zvision/zvision.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index dc1cf476a7..2d14e5d6a8 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -83,6 +83,8 @@ ZVision::~ZVision() { // Dispose of resources delete _console; delete _cursorManager; + delete _stringManager; + delete _saveManager; delete _renderManager; delete _scriptManager; delete _rnd; -- cgit v1.2.3 From 41afb2dd90caa5dc09a688d253c119e28ef25318 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:00:52 -0500 Subject: ZVISION: Move clearing dirty rects to after they are blitted instead the beginning of each frame --- engines/zvision/render_manager.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 1c1ce40c6c..a5c659d115 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -60,10 +60,6 @@ RenderManager::~RenderManager() { } void RenderManager::update(uint deltaTimeInMillis) { - // Clear the dirty rects from last frame - _workingWindowDirtyRect = Common::Rect(); - _backBufferDirtyRect = Common::Rect(); - // An inverse velocity of 0 would be infinitely fast, so we'll let 0 mean no velocity. if (_backgroundInverseVelocity != 0) { _accumulatedVelocityMilliseconds += deltaTimeInMillis; @@ -93,7 +89,14 @@ void RenderManager::renderBackbufferToScreen() { // Translate the working window dirty rect to screen coords _workingWindowDirtyRect.translate(_workingWindow.left, _workingWindow.top); // Then extend the backbuffer dirty rect to contain it - _backBufferDirtyRect.extend(_workingWindowDirtyRect); + if (_backBufferDirtyRect.isEmpty()) { + _backBufferDirtyRect = _workingWindowDirtyRect; + } else { + _backBufferDirtyRect.extend(_workingWindowDirtyRect); + } + + // Clear the dirty rect + _workingWindowDirtyRect = Common::Rect(); } // TODO: Add menu rendering @@ -103,6 +106,7 @@ void RenderManager::renderBackbufferToScreen() { if (!_backBufferDirtyRect.isEmpty()) { _system->copyRectToScreen(_backBuffer.getBasePtr(_backBufferDirtyRect.left, _backBufferDirtyRect.top), _backBuffer.pitch, _backBufferDirtyRect.left, _backBufferDirtyRect.top, _backBufferDirtyRect.width(), _backBufferDirtyRect.height()); + _backBufferDirtyRect = Common::Rect(); } } -- cgit v1.2.3 From 7ce6823158122d0b1922e675eccf31fd5382f9ef Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:02:57 -0500 Subject: ZVISION: Convert _alphaDataEntries to a HashMap So entries can be easily identified and removed if necessary --- engines/zvision/render_manager.cpp | 32 +++++++++++++++++++------------- engines/zvision/render_manager.h | 7 ++++--- 2 files changed, 23 insertions(+), 16 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index a5c659d115..c25f670acf 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -111,25 +111,31 @@ void RenderManager::renderBackbufferToScreen() { } void RenderManager::processAlphaEntries() { - for (Common::List::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { + // TODO: Add dirty rectangling support. AKA only draw an entry if the _backbufferDirtyRect intersects/contains the entry Rect + + for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { uint32 destOffset = 0; uint32 sourceOffset = 0; - uint16 *backbufferPtr = (uint16 *)_backBuffer.getBasePtr((*iter).destX + _workingWindow.left, (*iter).destY + _workingWindow.top); - uint16 *entryPtr = (uint16 *)(*iter).data->getPixels(); + uint16 *backbufferPtr = (uint16 *)_backBuffer.getBasePtr((*iter)._value.destX + _workingWindow.left, (*iter)._value.destY + _workingWindow.top); + uint16 *entryPtr = (uint16 *)(*iter)._value.data->getPixels(); - for (int32 y = 0; y < (*iter).height; y++) { - for (int32 x = 0; x < (*iter).width; x++) { + for (int32 y = 0; y < (*iter)._value.height; y++) { + for (int32 x = 0; x < (*iter)._value.width; x++) { uint16 color = entryPtr[sourceOffset + x]; - if (color != (*iter).alphaColor) { + if (color != (*iter)._value.alphaColor) { backbufferPtr[destOffset + x] = color; } } - destOffset += _workingWidth; - sourceOffset += (*iter).width; + destOffset += _backBuffer.w; + sourceOffset += (*iter)._value.width; } - _backBufferDirtyRect.extend(Common::Rect((*iter).destX + _workingWindow.left, (*iter).destY + _workingWindow.top, (*iter).destX + _workingWindow.left + (*iter).width, (*iter).destY + _workingWindow.top + (*iter).height)); + if (_backBufferDirtyRect.isEmpty()) { + _backBufferDirtyRect = Common::Rect((*iter)._value.destX + _workingWindow.left, (*iter)._value.destY + _workingWindow.top, (*iter)._value.destX + _workingWindow.left + (*iter)._value.width, (*iter)._value.destY + _workingWindow.top + (*iter)._value.height); + } else { + _backBufferDirtyRect.extend(Common::Rect((*iter)._value.destX + _workingWindow.left, (*iter)._value.destY + _workingWindow.top, (*iter)._value.destX + _workingWindow.left + (*iter)._value.width, (*iter)._value.destY + _workingWindow.top + (*iter)._value.height)); + } } } @@ -324,7 +330,7 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i assert(_workingWindowDirtyRect.width() <= _workingWidth && _workingWindowDirtyRect.height() <= _workingHeight); } -void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor) { +void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor, uint32 idNumber) { AlphaDataEntry entry; entry.alphaColor = alphaColor; entry.data = new Graphics::Surface(); @@ -347,10 +353,10 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i sourceOffset += imageWidth; } - _alphaDataEntries.push_back(entry); + _alphaDataEntries[idNumber] = entry; } -Common::Rect RenderManager::renderTextToWorkingWindow(const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap) { +Common::Rect RenderManager::renderTextToWorkingWindow(uint32 idNumber, const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap) { AlphaDataEntry entry; entry.alphaColor = 0; entry.destX = destX; @@ -361,7 +367,7 @@ Common::Rect RenderManager::renderTextToWorkingWindow(const Common::String &text entry.width = entry.data->w; entry.height = entry.data->h; - _alphaDataEntries.push_back(entry); + _alphaDataEntries[idNumber] = entry; return Common::Rect(destX, destY, destX + entry.width, destY + entry.height); } diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 50d2d1076f..e7030b06fe 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -25,6 +25,7 @@ #include "common/types.h" #include "common/rect.h" +#include "common/hashmap.h" #include "graphics/surface.h" @@ -67,7 +68,7 @@ private: // It's used for panorama/tilt warping and for clearing the workingWindow to a single color Graphics::Surface _workingWindowBuffer; Graphics::Surface _backBuffer; - Common::List _alphaDataEntries; + Common::HashMap _alphaDataEntries; Common::Rect _workingWindowDirtyRect; Common::Rect _backBufferDirtyRect; @@ -123,9 +124,9 @@ public: void processAlphaEntries(); void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height); - void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor); + void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor, uint32 idNumber); - Common::Rect renderTextToWorkingWindow(const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight = -1, Graphics::TextAlign align = Graphics::kTextAlignLeft, bool wrap = true); + Common::Rect renderTextToWorkingWindow(uint32 idNumber, const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight = -1, Graphics::TextAlign align = Graphics::kTextAlignLeft, bool wrap = true); /** * Fills the entire workingWindow with the specified color. Internally, the color -- cgit v1.2.3 From cdd793ed224579870daa73061ff0478e179ff21d Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:03:35 -0500 Subject: ZVISION: Check is a dirty rect is empty before extending it So extends dont extend from 0,0 --- engines/zvision/render_manager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index c25f670acf..13e8cba240 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -324,7 +324,11 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i sourceOffset += imageWidth; } - _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); + if (_workingWindowDirtyRect.isEmpty()) { + _workingWindowDirtyRect = Common::Rect(destX, destY, destX + width, destY + height); + } else { + _workingWindowDirtyRect.extend(Common::Rect(destX, destY, destX + width, destY + height)); + } // TODO: Remove this from release. It's here to make sure code that uses this function clips their destinations correctly assert(_workingWindowDirtyRect.width() <= _workingWidth && _workingWindowDirtyRect.height() <= _workingHeight); -- cgit v1.2.3 From 3a6cb86489c7e0a7c171dbb9d317dd2cdbf4cccf Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:04:03 -0500 Subject: ZVISION: Add methods to clear and remove AlphaEntries --- engines/zvision/render_manager.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index e7030b06fe..2fc3f230df 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -122,6 +122,8 @@ public: void renderBackbufferToScreen(); void processAlphaEntries(); + void clearAlphaEntries() { _alphaDataEntries.clear(); } + void removeAlphaEntry(uint32 idNumber) { _alphaDataEntries.erase(idNumber); } void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height); void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor, uint32 idNumber); -- cgit v1.2.3 From 2187245012c2912fdebc8ec74a52a6488bc6d045 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:04:23 -0500 Subject: ZVISION: Remove all AlphaEntries on room change --- engines/zvision/script_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 1acbcdfcf2..e014983293 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -329,6 +329,9 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, // Reset the background velocity _engine->getRenderManager()->setBackgroundVelocity(0); + // Remove any alphaEntries + _engine->getRenderManager()->clearAlphaEntries(); + // Clean the global state table cleanStateTable(); -- cgit v1.2.3 From 1f9f392279b05433e265711758bc5ecec65eb08b Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:04:34 -0500 Subject: ZVISION: Enable auto saving --- engines/zvision/script_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index e014983293..4b4e0f74fe 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -309,7 +309,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, debug("Changing location to: %c %c %c %c %u", world, room, node, view, offset); // Auto save - //_engine->getSaveManager()->autoSave(); + _engine->getSaveManager()->autoSave(); // Clear all the containers _referenceTable.clear(); -- cgit v1.2.3 From 4c4f08a99e0b7ff914c6f9c2cb1b38caeba9009f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:05:24 -0500 Subject: ZVISION: Convert cmdRenderText to use new function syntax --- engines/zvision/console.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 3969aa1f14..0d290a661a 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -207,7 +207,9 @@ bool Console::cmdRenderText(int argc, const char **argv) { } StringManager::TextStyle style = _engine->getStringManager()->getTextStyle(atoi(argv[2])); - _engine->getRenderManager()->renderTextToWorkingWindow(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); + _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 -- cgit v1.2.3 From 14cfc65c0d3f3ac678c17614140ea32902abec69 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:07:45 -0500 Subject: ZVISION: Use wide-to-ASCII conversion to read a line instead of stream.readLine() SeekableReadStream::readLine() wasn't finding the CRLF's properly --- engines/zvision/string_manager.cpp | 42 +++++++++++++++++++++++--------------- engines/zvision/string_manager.h | 2 +- 2 files changed, 27 insertions(+), 17 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 818b60c732..127b62f34e 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -98,10 +98,10 @@ void StringManager::parseStrFile(const Common::String &fileName) { } } - // STR files add a null character after the CR/LF. We need to skip over that before we can read another line - file.readByte(); + if (textStringCursor > 0) { + _inGameText[lineNumber].fragments.back().text = Common::String(textString, textStringCursor); + } - line = file.readLine(); lineNumber++; } } @@ -199,33 +199,43 @@ void StringManager::parseTag(const Common::String &tagString, const Common::Stri fragment->text = textString; } -Common::String StringManager::wideToASCII(const char *wideStr, uint arrayLength) { - // TODO: Contemplate using a largish static buffer instead of a dynamic heap buffer - uint newSize = arrayLength / 2; - char *asciiString = new char[newSize]; +Common::String StringManager::readWideLine(Common::SeekableReadStream &stream) { + // NOTE: Hardcoded size. All strings I've checked are less than 290 chars + char asciiString[300]; // Don't spam the user with warnings about UTF-16 support. // Just do one warning per String bool charOverflowWarning = false; - // Crush each octet pair to a single octet with a simple cast - for (uint i = 0; i < newSize; i++) { - uint16 value = READ_LE_UINT16(wideStr + (i * 2)); + + uint16 value = stream.readUint16LE(); + uint i = 0; + while (!stream.eos()) { + // Check for CRLF + if (value == 0x0A0D) { + // Read in the extra NULL char + stream.readByte(); // \0 + // End of the line. Break + break; + } + + // Crush each octet pair to a single octet with a simple cast if (value > 255) { charOverflowWarning = true; value = 255; } - asciiString[i] = (char)value; + char charValue = (char)value; + + asciiString[i] = charValue; + i++; + + value = stream.readUint16LE(); } if (charOverflowWarning) { warning("UTF-16 is not supported. Characters greater than 255 are clamped to 255"); } - Common::String returnString(asciiString, newSize); - // Cleanup. Common::String constructor does a memmove() internally so we can safely delete - delete[] asciiString; - - return returnString; + return Common::String(asciiString, i); } StringManager::TextStyle StringManager::getTextStyle(uint stringNumber) { diff --git a/engines/zvision/string_manager.h b/engines/zvision/string_manager.h index a9d2dc1a1d..a214c6c625 100644 --- a/engines/zvision/string_manager.h +++ b/engines/zvision/string_manager.h @@ -76,7 +76,7 @@ private: void parseStrFile(const Common::String &fileName); void parseTag(const Common::String &tagString, const Common::String &textString, uint lineNumber); - static Common::String wideToASCII(const char *wideStr, uint arrayLength); + static Common::String readWideLine(Common::SeekableReadStream &stream); }; } // End of namespace ZVision -- cgit v1.2.3 From d59cf9fda66f8bcd89f12248d7337727d708f425 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:10:35 -0500 Subject: ZVISION: Convert StringManager::parseStr to use readWideLine() --- engines/zvision/string_manager.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 127b62f34e..1cc3c15fd2 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -63,11 +63,16 @@ void StringManager::parseStrFile(const Common::String &fileName) { return; } - Common::String line = file.readLine(); - uint lineNumber = 0; while (!file.eos()) { - Common::String asciiLine = wideToASCII(line.c_str(), line.size()); + _lastStyle.align = Graphics::kTextAlignLeft; + _lastStyle.color = 0; + _lastStyle.font = nullptr; + + Common::String asciiLine = readWideLine(file); + if (asciiLine.empty()) { + continue; + } char tagString[150]; uint tagStringCursor = 0; @@ -79,16 +84,19 @@ void StringManager::parseStrFile(const Common::String &fileName) { switch (asciiLine[i]) { case '<': inTag = true; + if (!_inGameText[lineNumber].fragments.empty()) { + _inGameText[lineNumber].fragments.back().text = Common::String(textString, textStringCursor); + textStringCursor = 0; + } break; case '>': inTag = false; - parseTag(Common::String(tagString, tagStringCursor), Common::String(textString, textStringCursor), i); + parseTag(Common::String(tagString, tagStringCursor), lineNumber); tagStringCursor = 0; - textStringCursor = 0; break; default: if (inTag) { - textString[tagStringCursor] = asciiLine[i]; + tagString[tagStringCursor] = asciiLine[i]; tagStringCursor++; } else { textString[textStringCursor] = asciiLine[i]; -- cgit v1.2.3 From a2c36a16b52d5bccbfdc141e3f75bfca9aa8535a Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:11:52 -0500 Subject: ZVISION: Fix parseTag font name logic --- engines/zvision/string_manager.cpp | 96 ++++++++++++++++++++------------------ engines/zvision/string_manager.h | 4 +- 2 files changed, 53 insertions(+), 47 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 1cc3c15fd2..4c4fc7b168 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -114,15 +114,15 @@ void StringManager::parseStrFile(const Common::String &fileName) { } } -void StringManager::parseTag(const Common::String &tagString, const Common::String &textString, uint lineNumber) { +void StringManager::parseTag(const Common::String &tagString, uint lineNumber) { Common::StringTokenizer tokenizer(tagString); Common::String token = tokenizer.nextToken(); Common::String fontName; bool bold = false; - Graphics::TextAlign align = Graphics::kTextAlignLeft; - int point = 12; + Graphics::TextAlign align = _lastStyle.align; + int point = _lastStyle.font != nullptr ? _lastStyle.font->_fontHeight : 12; int red = 0; int green = 0; int blue = 0; @@ -155,56 +155,60 @@ void StringManager::parseTag(const Common::String &tagString, const Common::Stri token = tokenizer.nextToken(); } - Common::String newFontName; - if (fontName.matchString("times new roman", true)) { - if (bold) { - newFontName = "timesbd.ttf"; - } else { - newFontName = "times.ttf"; - } - } else if (fontName.matchString("courier new", true)) { - if (bold) { - newFontName = "courbd.ttf"; - } else { - newFontName = "cour.ttf"; - } - } else if (fontName.matchString("century schoolbook", true)) { - if (bold) { - newFontName = "censcbkbd.ttf"; - } else { - newFontName = "censcbk.ttf"; - } - } else if (fontName.matchString("times new roman", true)) { - if (bold) { - newFontName = "courbd.ttf"; + TextFragment fragment = _inGameText->fragments.back(); + + if (fontName.empty()) { + fragment.style.font = _lastStyle.font; + } else { + Common::String newFontName; + if (fontName.matchString("*times new roman*", true)) { + if (bold) { + newFontName = "timesbd.ttf"; + } else { + newFontName = "times.ttf"; + } + } else if (fontName.matchString("*courier new*", true)) { + if (bold) { + newFontName = "courbd.ttf"; + } else { + newFontName = "cour.ttf"; + } + } else if (fontName.matchString("*century schoolbook*", true)) { + if (bold) { + newFontName = "censcbkbd.ttf"; + } else { + newFontName = "censcbk.ttf"; + } + } else if (fontName.matchString("*garamond*", true)) { + if (bold) { + newFontName = "garabd.ttf"; + } else { + newFontName = "gara.ttf"; + } } else { - newFontName = "cour.ttf"; + debug("Could not identify font: %s. Reverting to Arial", fontName.c_str()); + if (bold) { + newFontName = "zorknorm.ttf"; + } else { + newFontName = "arial.ttf"; + } } - } else { - debug("Could not identify font: %s. Reverting to Arial", fontName.c_str()); - if (bold) { - newFontName = "zorknorm.ttf"; + + Common::String fontKey = Common::String::format("%s-%d", newFontName.c_str(), point); + if (_fonts.contains(fontKey)) { + fragment.style.font = _fonts[fontKey]; } else { - newFontName = "arial.ttf"; + fragment.style.font = new TruetypeFont(_engine, point); + fragment.style.font->loadFile(newFontName); + _fonts[fontKey] = fragment.style.font; } } - // Push an empty TextFragment onto the end of the list - // Creating the TextFragement before filling it prevents extra data copying during creation - _inGameText->fragments.push_back(TextFragment()); - TextFragment *fragment = &_inGameText->fragments.back(); - - Common::String fontKey = Common::String::format("%s-&d", newFontName.c_str(), point); - if (_fonts.contains(fontKey)) { - fragment->style.font = _fonts[fontKey]; - } else { - fragment->style.font = new TruetypeFont(_engine, point); - fragment->style.font->loadFile(newFontName); - } + fragment.style.align = align; + fragment.style.color = _pixelFormat565.ARGBToColor(0, red, green, blue); + _inGameText[lineNumber].fragments.push_back(fragment); - fragment->style.align = align; - fragment->style.color = _pixelFormat565.ARGBToColor(0, red, green, blue); - fragment->text = textString; + _lastStyle = fragment.style; } Common::String StringManager::readWideLine(Common::SeekableReadStream &stream) { diff --git a/engines/zvision/string_manager.h b/engines/zvision/string_manager.h index a214c6c625..e3539a732c 100644 --- a/engines/zvision/string_manager.h +++ b/engines/zvision/string_manager.h @@ -68,13 +68,15 @@ private: static const Graphics::PixelFormat _pixelFormat565; + TextStyle _lastStyle; + public: void initialize(ZVisionGameId gameId); StringManager::TextStyle getTextStyle(uint stringNumber); private: void parseStrFile(const Common::String &fileName); - void parseTag(const Common::String &tagString, const Common::String &textString, uint lineNumber); + void parseTag(const Common::String &tagString, uint lineNumber); static Common::String readWideLine(Common::SeekableReadStream &stream); }; -- cgit v1.2.3 From c7e2bdd2b2730225d1d76b22c71e7733ed61f23c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:12:08 -0500 Subject: ZVISION: Remove extraneous function --- engines/zvision/render_manager.cpp | 16 ---------------- engines/zvision/render_manager.h | 1 - 2 files changed, 17 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 13e8cba240..7f10535bb2 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -376,22 +376,6 @@ Common::Rect RenderManager::renderTextToWorkingWindow(uint32 idNumber, const Com return Common::Rect(destX, destY, destX + entry.width, destY + entry.height); } -void RenderManager::copyWorkingWindowSubRectToSurface(Graphics::Surface *destSurface, uint16 destX, uint16 destY, Common::Rect subRect) const { - uint32 destOffset = 0; - uint32 sourceOffset = 0; - uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(subRect.left, subRect.top); - uint16 *destPtr = (uint16 *)destSurface->getBasePtr(destX, destY); - - for (int32 y = 0; y < subRect.height(); y++) { - for (int32 x = 0; x < subRect.width(); x++) { - destPtr[destOffset + x] = workingWindowBufferPtr[sourceOffset + x]; - } - - destOffset += destSurface->w; - sourceOffset += _workingWidth; - } -} - const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { // Convert from screen space to working window space Common::Point newPoint(point - Common::Point(_workingWindow.left, _workingWindow.top)); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 2fc3f230df..b0a42d9ba7 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -214,7 +214,6 @@ public: RenderTable *getRenderTable(); uint32 getCurrentBackgroundOffset(); const Graphics::Surface *getBackBuffer() { return &_backBuffer; } - void copyWorkingWindowSubRectToSurface(Graphics::Surface *destSurface, uint16 destX, uint16 destY, Common::Rect subRect) const; /** * Creates a copy of surface and transposes the data. -- cgit v1.2.3 From 2b60cc8a0c9bd4e1e95b78c96aafe22e0d17bf3a Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:12:45 -0500 Subject: ZVISION: Test for file.open() success before continuing with font loading --- engines/zvision/truetype_font.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/truetype_font.cpp b/engines/zvision/truetype_font.cpp index d88f22a727..8c5c279e78 100644 --- a/engines/zvision/truetype_font.cpp +++ b/engines/zvision/truetype_font.cpp @@ -53,11 +53,17 @@ TruetypeFont::~TruetypeFont(void) { bool TruetypeFont::loadFile(const Common::String &filename) { Common::File file; + bool fileOpened = false; if (!Common::File::exists(filename)) { debug("TTF font file %s was not found. Reverting to arial.ttf", filename.c_str()); - file.open("arial.ttf"); + fileOpened = file.open("arial.ttf"); } else { - file.open(filename); + fileOpened = file.open(filename); + } + + if (!fileOpened) { + debug("TTF file could not be opened"); + return false; } _font = Graphics::loadTTFFont(file, _fontHeight); -- cgit v1.2.3 From ff5b7ba2a8102ae04bc2743d88a6d343b7247210 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:14:28 -0500 Subject: ZVISION: Draw string to 0, 0 instead of destX, destY --- engines/zvision/truetype_font.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/truetype_font.cpp b/engines/zvision/truetype_font.cpp index 8c5c279e78..8fd331df48 100644 --- a/engines/zvision/truetype_font.cpp +++ b/engines/zvision/truetype_font.cpp @@ -82,10 +82,11 @@ Graphics::Surface *TruetypeFont::drawTextToSurface(const Common::String &text, i if (!wrap) { int width = MIN(_font->getStringWidth(text), maxWidth); surface->create(width, _lineHeight, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); - // Copy the pixels from the RenderManager::_workingWindow, so we can get nice antialiasing - _engine->getRenderManager()->copyWorkingWindowSubRectToSurface(surface, 0, 0, Common::Rect(destX, destY, destX + width, destY + _lineHeight)); + // TODO: Add better alpha support by getting the pixels from the backbuffer. + // However doing that requires some kind of caching system so future text doesn't try to use this text as it's alpha background. + surface->fillRect(Common::Rect(0, 0, surface->w, surface->h), 0); - _font->drawString(surface, text, destX, destY, maxWidth, textColor, align); + _font->drawString(surface, text, 0, 0, maxWidth, textColor, align); return surface; } @@ -100,12 +101,11 @@ Graphics::Surface *TruetypeFont::drawTextToSurface(const Common::String &text, i } surface->create(maxWidth, lines.size() * _lineHeight, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); - // Copy the pixels from the RenderManager::_workingWindow, so we can get nice antialiasing - _engine->getRenderManager()->copyWorkingWindowSubRectToSurface(surface, 0, 0, Common::Rect(destX, destY, destX + maxWidth, destY + lines.size() * _lineHeight)); + surface->fillRect(Common::Rect(0, 0, surface->w, surface->h), 0); int heightOffset = 0; for (Common::Array::iterator it = lines.begin(); it != lines.end(); it++) { - _font->drawString(surface, *it, destX, destY + heightOffset, maxWidth, textColor, align); + _font->drawString(surface, *it, 0, 0 + heightOffset, maxWidth, textColor, align); heightOffset += (int)_lineHeight; } -- cgit v1.2.3 From 0c28fbca7c49ae70779f1e7aa150c42e7ac1276c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:14:49 -0500 Subject: ZVISION: Remove extraneous empty line --- engines/zvision/truetype_font.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/truetype_font.h b/engines/zvision/truetype_font.h index c8d0a95b28..ae7732cba4 100644 --- a/engines/zvision/truetype_font.h +++ b/engines/zvision/truetype_font.h @@ -55,8 +55,7 @@ public: int32 _fontHeight; public: - bool loadFile(const Common::String &filename); - + bool loadFile(const Common::String &filename); Graphics::Surface *drawTextToSurface(const Common::String &text, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap); }; -- cgit v1.2.3 From 035ee29f1d084316cad130fbc9de66073983c47e Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:15:10 -0500 Subject: ZVISION: Initialize StringManager --- engines/zvision/zvision.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 2d14e5d6a8..c8a4cbb0ca 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -125,6 +125,7 @@ void ZVision::initialize() { _cursorManager = new CursorManager(this, &_pixelFormat); _cursorManager->initialize(); _scriptManager->initialize(); + _stringManager->initialize(_gameDescription->gameId); // Create debugger console. It requires GFX to be initialized _console = new Console(this); -- cgit v1.2.3 From 4af62cfd3a9e0826c7303d3a0759fd103f8c92ea Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:15:30 -0500 Subject: ZVISION: Register the "fonts" directory with SearchMan --- engines/zvision/zvision.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index c8a4cbb0ca..b071908698 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -103,6 +103,7 @@ void ZVision::initialize() { SearchMan.addSubDirectoryMatching(gameDataDir, "zassets2", 0, 2, true); SearchMan.addSubDirectoryMatching(gameDataDir, "znemmx", 0, 1, true); SearchMan.addSubDirectoryMatching(gameDataDir, "zgi", 0, 4, true); + SearchMan.addSubDirectoryMatching(gameDataDir, "fonts", 0, 1, true); // Find zfs archive files Common::ArchiveMemberList list; -- cgit v1.2.3 From a0a67a2d470816b13bab10371494652d77b23611 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 00:16:42 -0500 Subject: ZVISION: Partially implement InputControl --- engines/zvision/input_control.cpp | 141 ++++++++++++++++++++++++++++++++++++++ engines/zvision/input_control.h | 60 ++++++++++++++++ engines/zvision/module.mk | 1 + 3 files changed, 202 insertions(+) create mode 100644 engines/zvision/input_control.cpp create mode 100644 engines/zvision/input_control.h (limited to 'engines/zvision') diff --git a/engines/zvision/input_control.cpp b/engines/zvision/input_control.cpp new file mode 100644 index 0000000000..ab4cc6bd62 --- /dev/null +++ b/engines/zvision/input_control.cpp @@ -0,0 +1,141 @@ +/* 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/scummsys.h" + +#include "common/str.h" +#include "common/stream.h" +#include "common/rect.h" + +#include "zvision/input_control.h" +#include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/string_manager.h" +#include "zvision/render_manager.h" +#include "zvision/utility.h" + + +namespace ZVision { + +InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) + : Control(engine, key), + _nextTabstop(0), + _focused(false), + _textChanged(false), + _cursorOffset(0) { + // Loop until we find the closing brace + Common::String line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + + while (!stream.eos() && !line.contains('}')) { + if (line.matchString("*rectangle*", true)) { + int x1; + int y1; + int x2; + int y2; + + sscanf(line.c_str(), "%*[^(](%d %d %d %d)", &x1, &y1, &x2, &y2); + + _textRectangle = Common::Rect(x1, y1, x2, y2); + } else if (line.matchString("*aux_hotspot*", true)) { + int x1; + int y1; + int x2; + int y2; + + sscanf(line.c_str(), "%*[^(](%d %d %d %d)", &x1, &y1, &x2, &y2); + + _headerRectangle = Common::Rect(x1, y1, x2, y2); + } else if (line.matchString("*string_init*", true)) { + uint fontFormatNumber; + + sscanf(line.c_str(), "%*[^(](%u)", &fontFormatNumber); + + _textStyle = _engine->getStringManager()->getTextStyle(fontFormatNumber); + } else if (line.matchString("*next_tabstop*", true)) { + sscanf(line.c_str(), "%*[^(](%u)", &_nextTabstop); + } else if (line.matchString("*cursor_animation*", true)) { + char fileName[25]; + + sscanf(line.c_str(), "%*[^(](%25s %*u)", fileName); + + _cursorAnimationFileName = Common::String(fileName); + } else if (line.matchString("*cursor_dimensions*", true)) { + // Ignore, use the dimensions in the animation file + } else if (line.matchString("*cursor_animation_frames*", true)) { + // Ignore, use the frame count in the animation file + } else if (line.matchString("*focus*", true)) { + _focused = true; + } + + line = stream.readLine(); + trimCommentsAndWhiteSpace(&line); + } +} + +void InputControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + _engine->getScriptManager()->focusControl(_key); +} + +void InputControl::onKeyDown(Common::KeyState keyState) { + if (!_focused) { + return; + } + + if (keyState.keycode == Common::KEYCODE_BACKSPACE) { + _currentInputText.deleteLastChar(); + } else if (keyState.keycode == Common::KEYCODE_TAB) { + _focused = false; + // Focus the next input control + _engine->getScriptManager()->focusControl(_nextTabstop); + } else { + // Otherwise, append the new character to the end of the current text + + uint16 asciiValue = keyState.ascii; + // We only care about text values + if (asciiValue >= 32 && asciiValue <= 126) { + _currentInputText += (char)asciiValue; + _textChanged = true; + } + } +} + +bool InputControl::process(uint32 deltaTimeInMillis) { + if (!_focused) { + return false; + } + + // First see if we need to render the text + if (_textChanged) { + // Blit the text using the RenderManager + Common::Rect destRect = _engine->getRenderManager()->renderTextToWorkingWindow(_key, _currentInputText, _textStyle.font, _textRectangle.left, _textRectangle.top, _textStyle.color, _textRectangle.width()); + + _cursorOffset = destRect.left - _textRectangle.left; + } + + // Render the next frame of the animation + // TODO: Implement animation handling + + return false; +} + +} // End of namespace ZVision diff --git a/engines/zvision/input_control.h b/engines/zvision/input_control.h new file mode 100644 index 0000000000..33a1b34313 --- /dev/null +++ b/engines/zvision/input_control.h @@ -0,0 +1,60 @@ +/* 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 ZVISION_INPUT_CONTROL_H +#define ZVISION_INPUT_CONTROL_H + +#include "common/types.h" + +#include "zvision/control.h" +#include "zvision/string_manager.h" + + +namespace ZVision { + +class InputControl : public Control { +public: + InputControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); + +private: + Common::Rect _textRectangle; + Common::Rect _headerRectangle; + StringManager::TextStyle _textStyle; + uint32 _nextTabstop; + Common::String _cursorAnimationFileName; + bool _focused; + + Common::String _currentInputText; + bool _textChanged; + uint _cursorOffset; + +public: + void focus() { _focused = true; } + void unfocus() { _focused = false; } + void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + void onKeyDown(Common::KeyState keyState); + bool process(uint32 deltaTimeInMillis); +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index cb4a3609e9..2f2929db67 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -11,6 +11,7 @@ MODULE_OBJS := \ cursor_manager.o \ detection.o \ events.o \ + input_control.o \ lever_control.o \ lzss_read_stream.o \ push_toggle_control.o \ -- cgit v1.2.3 From 5ec472ae2fc5d391714617457ec01c24d67057c2 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Mon, 16 Sep 2013 22:10:26 -0500 Subject: ZVISION: Add version support for save files --- engines/zvision/save_manager.cpp | 10 ++++++++++ engines/zvision/save_manager.h | 1 + 2 files changed, 11 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index 4f8bfeb836..ff6e1c36fa 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -44,6 +44,9 @@ void SaveManager::saveGame(uint slot, const Common::String &saveName) { // Write out the savegame header file->writeUint32BE(SAVEGAME_ID); + // Write version + file->writeByte(1); + // Write savegame name file->writeString(saveName); file->writeByte(0); @@ -58,6 +61,7 @@ void SaveManager::saveGame(uint slot, const Common::String &saveName) { // Skip over the header info autoSaveFile->readSint32BE(); // SAVEGAME_ID + autoSaveFile->readByte(); // Version autoSaveFile->seek(5, SEEK_CUR); // The string "auto" with terminating NULL // Read the rest to a buffer @@ -79,6 +83,9 @@ void SaveManager::autoSave() { // Write out the savegame header file->writeUint32BE(SAVEGAME_ID); + // Version + file->writeByte(1); + file->writeString("auto"); file->writeByte(0); @@ -153,6 +160,9 @@ bool SaveManager::readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &hea return false; } + // Read in the version + header.version = in->readByte(); + // Read in the save name header.saveName.clear(); char ch; diff --git a/engines/zvision/save_manager.h b/engines/zvision/save_manager.h index 219a8e7715..864f176e10 100644 --- a/engines/zvision/save_manager.h +++ b/engines/zvision/save_manager.h @@ -36,6 +36,7 @@ namespace ZVision { class ZVision; struct SaveGameHeader { + byte version; Common::String saveName; Graphics::Surface *thumbnail; int saveYear, saveMonth, saveDay; -- cgit v1.2.3 From 6664f31ed24b2d8b384221faffdeb6eda0f69835 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 17 Sep 2013 11:03:49 -0500 Subject: ZVISION: Convert the current save version to a const --- engines/zvision/save_manager.cpp | 4 ++-- engines/zvision/save_manager.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index ff6e1c36fa..cf2d96575e 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -45,7 +45,7 @@ void SaveManager::saveGame(uint slot, const Common::String &saveName) { file->writeUint32BE(SAVEGAME_ID); // Write version - file->writeByte(1); + file->writeByte(SAVE_VERSION); // Write savegame name file->writeString(saveName); @@ -84,7 +84,7 @@ void SaveManager::autoSave() { file->writeUint32BE(SAVEGAME_ID); // Version - file->writeByte(1); + file->writeByte(SAVE_VERSION); file->writeString("auto"); file->writeByte(0); diff --git a/engines/zvision/save_manager.h b/engines/zvision/save_manager.h index 864f176e10..8d0ebc75af 100644 --- a/engines/zvision/save_manager.h +++ b/engines/zvision/save_manager.h @@ -51,6 +51,10 @@ private: ZVision *_engine; static const uint32 SAVEGAME_ID; + enum { + SAVE_VERSION = 1 + }; + public: void autoSave(); void saveGame(uint slot, const Common::String &saveName); -- cgit v1.2.3 From 6148a0a878eb543731653870fcb369a8c86a2dfc Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 17 Sep 2013 11:04:41 -0500 Subject: ZVISION: Add a check against reading newer save game versions --- engines/zvision/save_manager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index cf2d96575e..e09d31557a 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -27,6 +27,8 @@ #include "graphics/surface.h" #include "graphics/thumbnail.h" +#include "gui/message.h" + #include "zvision/save_manager.h" #include "zvision/zvision.h" #include "zvision/script_manager.h" @@ -163,6 +165,13 @@ bool SaveManager::readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &hea // Read in the version header.version = in->readByte(); + // Check that the save version isn't newer than this binary + if (header.version > SAVE_VERSION) { + uint tempVersion = header.version; + GUI::MessageDialog dialog(Common::String::format("This save file uses version %u, but this engine only supports up to version %d. You will need an updated version of the engine to use this save file.", tempVersion, SAVE_VERSION), "OK"); + dialog.runModal(); + } + // Read in the save name header.saveName.clear(); char ch; -- cgit v1.2.3 From d06c64d0762eb5f4b3f32c5402d05e801bb80ed8 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 17 Sep 2013 11:05:49 -0500 Subject: ZVISION: Append chars to a Common::String object instead of using a static buffer --- engines/zvision/string_manager.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 4c4fc7b168..8c7e0aaa3d 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -212,15 +212,13 @@ void StringManager::parseTag(const Common::String &tagString, uint lineNumber) { } Common::String StringManager::readWideLine(Common::SeekableReadStream &stream) { - // NOTE: Hardcoded size. All strings I've checked are less than 290 chars - char asciiString[300]; + Common::String asciiString; // Don't spam the user with warnings about UTF-16 support. // Just do one warning per String bool charOverflowWarning = false; uint16 value = stream.readUint16LE(); - uint i = 0; while (!stream.eos()) { // Check for CRLF if (value == 0x0A0D) { @@ -233,12 +231,11 @@ Common::String StringManager::readWideLine(Common::SeekableReadStream &stream) { // Crush each octet pair to a single octet with a simple cast if (value > 255) { charOverflowWarning = true; - value = 255; + value = '?'; } char charValue = (char)value; - asciiString[i] = charValue; - i++; + asciiString += charValue; value = stream.readUint16LE(); } @@ -247,7 +244,7 @@ Common::String StringManager::readWideLine(Common::SeekableReadStream &stream) { warning("UTF-16 is not supported. Characters greater than 255 are clamped to 255"); } - return Common::String(asciiString, i); + return asciiString; } StringManager::TextStyle StringManager::getTextStyle(uint stringNumber) { -- cgit v1.2.3 From 8557b06197bde4574be34810bcf59c3530acc326 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 00:03:49 -0500 Subject: ZVISION: Load the state values before changing location --- engines/zvision/save_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index e09d31557a..70de9050e8 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -144,12 +144,12 @@ Common::Error SaveManager::loadGame(uint slot) { uint32 offset = (char)saveFile->readUint32LE(); ScriptManager *scriptManager = _engine->getScriptManager(); - // Load the room - scriptManager->changeLocation(world, room, node, view, offset); - // Update the state table values scriptManager->deserializeStateTable(saveFile); + // Load the room + scriptManager->changeLocation(world, room, node, view, offset); + // Update the controls scriptManager->deserializeControls(saveFile); -- cgit v1.2.3 From ca80deea62a0ca675ec53148e0e3237e716c5082 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 00:04:31 -0500 Subject: ZVISION: Only allow save slots in the range [1, 20] This is the range supported by the ZNem / ZGI save menus --- engines/zvision/save_manager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index 70de9050e8..dbed109d51 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -40,6 +40,9 @@ namespace ZVision { const uint32 SaveManager::SAVEGAME_ID = MKTAG('Z', 'E', 'N', 'G'); void SaveManager::saveGame(uint slot, const Common::String &saveName) { + // The games only support 20 slots + assert(slot <=1 && slot <= 20); + Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot)); @@ -126,6 +129,9 @@ void SaveManager::writeSaveGameData(Common::OutSaveFile *file) { } Common::Error SaveManager::loadGame(uint slot) { + // The games only support 20 slots + assert(slot <= 1 && slot <= 20); + Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(_engine->generateSaveFileName(slot)); if (saveFile == 0) { return Common::kPathDoesNotExist; -- cgit v1.2.3 From 51fc627c05e4fdbd240c75399a249ce8378e999a Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 00:05:38 -0500 Subject: ZVISION: Clear out the current state table values before loading any from a save file --- engines/zvision/script_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 4b4e0f74fe..b968e51213 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -390,6 +390,9 @@ void ScriptManager::serializeStateTable(Common::WriteStream *stream) { } void ScriptManager::deserializeStateTable(Common::SeekableReadStream *stream) { + // Clear out the current table values + _globalState.clear(); + // Read the number of key/value pairs uint32 numberOfPairs = stream->readUint32LE(); -- cgit v1.2.3 From 8f7fa517d627ad81ca6a07b5a86b6de0774713a1 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 00:08:36 -0500 Subject: ZVISION: Directly access _globalState instead of using setStateValue setStateValue does a _referenceTable lookup and potentially adds Puzzles to _puzzlesToCheck. We know that _referenceTable and _puzzlesToCheck with be cleared during ScriptManager::changeLocation(), so using setStateValues ends up just being wasteful. --- engines/zvision/script_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index b968e51213..75f88ddd8a 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -399,7 +399,8 @@ void ScriptManager::deserializeStateTable(Common::SeekableReadStream *stream) { for (uint32 i = 0; i < numberOfPairs; i++) { uint32 key = stream->readUint32LE(); uint32 value = stream->readUint32LE(); - setStateValue(key, value); + // Directly access the state table so we don't trigger Puzzle checks + _globalState[key] = value; } } -- cgit v1.2.3 From 1ced56fee7a90ff79cf97f34f3721f7234f2f9bc Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 00:09:05 -0500 Subject: ZVISION: Add documentation to SaveManager --- engines/zvision/save_manager.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.h b/engines/zvision/save_manager.h index 8d0ebc75af..6445f10caf 100644 --- a/engines/zvision/save_manager.h +++ b/engines/zvision/save_manager.h @@ -56,8 +56,27 @@ private: }; public: + /** + * Called every room change. Saves the state of the room just before + * we switched rooms. Uses ZVision::generateAutoSaveFileName() to + * create the save file name. + */ void autoSave(); + /** + * Copies the data from the last auto-save into a new save file. We + * can't use the current state data because the save menu *IS* a room. + * The file is named using ZVision::generateSaveFileName(slot) + * + * @param slot The save slot this save pertains to. Must be [1, 20] + * @param saveName The internal name for this save. This is NOT the name of the actual save file. + */ void saveGame(uint slot, const Common::String &saveName); + /** + * Loads the state data from the save file that slot references. Uses + * ZVision::generateSaveFileName(slot) to get the save file name. + * + * @param slot The save slot to load. Must be [1, 20] + */ Common::Error loadGame(uint slot); private: -- cgit v1.2.3 From 7ff86ba6f9ce7a549a1b327396bce166de083803 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 00:31:59 -0500 Subject: ZVISION: Add documentation for RlfAnimation --- engines/zvision/rlf_animation.h | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index 133bf3913e..3f205d9666 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -77,21 +77,88 @@ public: uint height() { return _height; } uint32 frameTime() { return _frameTime; } + /** + * Seeks to the frameNumber and updates the internal Surface with + * the new frame data. If frameNumber == -1, it only sets _currentFrame, + * the internal Surface is unchanged. This function requires _stream = false + * + * @param frameNumber The frame number to seek to + */ void seekToFrame(int frameNumber); + /** + * Returns the pixel data of the frame specified. It will try to use + * getNextFrame() if possible. If not, it uses seekToFrame() to + * update the internal Surface and then returns a pointer to it. + * This function requires _stream = false + * + * @param frameNumber The frame number to get data for + * @return A pointer to the pixel data. Do NOT delete this. + */ const Graphics::Surface *getFrameData(uint frameNumber); + /** + * Returns the pixel data of the next frame. It is up to the user to + * check if the next frame is valid before calling this. + * IE. Use endOfAnimation() + * + * @return A pointer to the pixel data. Do NOT delete this. + */ const Graphics::Surface *getNextFrame(); + /** + * @return Is the currentFrame is the last frame in the animation? + */ bool endOfAnimation() { return _currentFrame == (int)_frameCount - 1; } private: + /** + * Reads in the header of the RLF file + * + * @return Will return false if the header magic number is wrong + */ bool readHeader(); + /** + * Reads the next frame from the RLF file, stores the data in + * a Frame object, then returns the object + * + * @return A Frame object representing the frame data + */ Frame readNextFrame(); + /** + * Applies the frame corresponding to frameNumber on top of _currentFrameBuffer. + * This function requires _stream = false so it can look up the Frame object + * referenced by frameNumber. + * + * @param frameNumber The frame number to apply to _currentFrameBuffer + */ void applyFrameToCurrent(uint frameNumber); + /** + * Applies the data from a Frame object on top of a _currentFrameBuffer. + * + * @param frame A Frame object to apply to _currentFrameBuffer + */ void applyFrameToCurrent(const RlfAnimation::Frame &frame); + /** + * Decode frame data that uses masked run length encoding. This is the encoding + * used by P-frames. + * + * @param source The source pixel data + * @param dest The destination buffer + * @param sourceSize The size of the source pixel data + * @param destSize The size of the destination buffer + */ void decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; + /** + * Decode frame data that uses simple run length encoding. This is the encoding + * used by I-frames. + * + * @param source The source pixel data + * @param dest The destination buffer + * @param sourceSize The size of the source pixel data + * @param destSize The size of the destination buffer + */ void decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint32 sourceSize, uint32 destSize) const; }; -- cgit v1.2.3 From 2d9c9e8c7f26a2c5977d52214283893617d97ffc Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 00:42:20 -0500 Subject: ZVISION: Remove unused animation functions --- engines/zvision/animation.cpp | 131 ------------------------------------------ engines/zvision/zvision.h | 3 - 2 files changed, 134 deletions(-) delete mode 100644 engines/zvision/animation.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/animation.cpp b/engines/zvision/animation.cpp deleted file mode 100644 index f43e854f73..0000000000 --- a/engines/zvision/animation.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* 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/scummsys.h" - -#include "common/system.h" -#include "video/video_decoder.h" - -#include "zvision/zvision.h" -#include "zvision/rlf_animation.h" - - -namespace ZVision { - -void ZVision::playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse) { - bool skip = false; - uint32 frameTime = animation->frameTime(); - uint width = animation->width(); - uint height = animation->height(); - - uint16 newX = x + _workingWindow.left; - uint16 newY = y + _workingWindow.top; - - uint32 accumulatedTime = 0; - - // Only continue while the video is still playing - while (!shouldQuit() && !skip && !animation->endOfAnimation()) { - _clock.update(); - uint32 currentTime = _clock.getLastMeasuredTime(); - accumulatedTime += _clock.getDeltaTime(); - - // Check for engine quit and video stop key presses - while (_eventMan->pollEvent(_event)) { - switch (_event.type) { - case Common::EVENT_KEYDOWN: - switch (_event.kbd.keycode) { - case Common::KEYCODE_q: - if (_event.kbd.hasFlags(Common::KBD_CTRL)) - quitGame(); - break; - case Common::KEYCODE_SPACE: - skip = true; - break; - default: - break; - } - default: - break; - } - } - - while (accumulatedTime >= frameTime && !animation->endOfAnimation()) { - accumulatedTime -= frameTime; - - _system->copyRectToScreen(animation->getNextFrame(), width * sizeof(uint16), newX, newY, width, height); - } - - // Always update the screen so the mouse continues to render - _system->updateScreen(); - - // Calculate the frame delay based off a desired frame time - int delay = _desiredFrameTime - int32(_system->getMillis() - currentTime); - // Ensure non-negative - delay = delay < 0 ? 0 : delay; - _system->delayMillis(delay); - } -} - -void ZVision::playAnimation(Video::VideoDecoder *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse) { - _clock.stop(); - animation->start(); - - // Only continue while the video is still playing - while (!shouldQuit() && !animation->endOfVideo() && animation->isPlaying()) { - // Check for engine quit and video stop key presses - while (!animation->endOfVideo() && animation->isPlaying() && _eventMan->pollEvent(_event)) { - switch (_event.type) { - case Common::EVENT_KEYDOWN: - switch (_event.kbd.keycode) { - case Common::KEYCODE_q: - if (_event.kbd.hasFlags(Common::KBD_CTRL)) - quitGame(); - break; - case Common::KEYCODE_SPACE: - animation->stop(); - break; - default: - break; - } - default: - break; - } - } - - if (animation->needsUpdate()) { - const Graphics::Surface *frame = animation->decodeNextFrame(); - - if (frame) { - _system->copyRectToScreen((const byte *)frame->getPixels(), frame->pitch, x, y, frame->w, frame->h); - } - } - - // Always update the screen so the mouse continues to render - _system->updateScreen(); - - _system->delayMillis(animation->getTimeToNextFrame()); - } - - _clock.start(); -} - -} // End of namespace ZVision diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index a481aba28f..efd94f1074 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -131,9 +131,6 @@ public: */ void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true); - void playAnimation(RlfAnimation *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); - void playAnimation(Video::VideoDecoder *animation, uint16 x, uint16 y, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); - Common::String generateSaveFileName(uint slot); Common::String generateAutoSaveFileName(); -- cgit v1.2.3 From cfe176619a52de5d31eebbca228639db49110102 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 01:37:41 -0500 Subject: ZVISION: Remove unused function arguments --- engines/zvision/render_manager.cpp | 2 +- engines/zvision/truetype_font.cpp | 2 +- engines/zvision/truetype_font.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 7f10535bb2..dc942fe3d0 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -367,7 +367,7 @@ Common::Rect RenderManager::renderTextToWorkingWindow(uint32 idNumber, const Com entry.destY = destY; // Draw the text to the working window - entry.data = font->drawTextToSurface(text, destX, destY, textColor, maxWidth, maxHeight, align, wrap); + entry.data = font->drawTextToSurface(text, textColor, maxWidth, maxHeight, align, wrap); entry.width = entry.data->w; entry.height = entry.data->h; diff --git a/engines/zvision/truetype_font.cpp b/engines/zvision/truetype_font.cpp index 8fd331df48..80d0d6bddb 100644 --- a/engines/zvision/truetype_font.cpp +++ b/engines/zvision/truetype_font.cpp @@ -72,7 +72,7 @@ bool TruetypeFont::loadFile(const Common::String &filename) { return true; } -Graphics::Surface *TruetypeFont::drawTextToSurface(const Common::String &text, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap) { +Graphics::Surface *TruetypeFont::drawTextToSurface(const Common::String &text, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap) { if (text.equals("")) { return nullptr; } diff --git a/engines/zvision/truetype_font.h b/engines/zvision/truetype_font.h index ae7732cba4..d35da878ee 100644 --- a/engines/zvision/truetype_font.h +++ b/engines/zvision/truetype_font.h @@ -56,7 +56,7 @@ public: public: bool loadFile(const Common::String &filename); - Graphics::Surface *drawTextToSurface(const Common::String &text, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap); + Graphics::Surface *drawTextToSurface(const Common::String &text, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap); }; } // End of namespace ZVision -- cgit v1.2.3 From 7a557c4bcd970582fcd28eacb9644bac5714edbf Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 01:43:28 -0500 Subject: ZVISION: Add documentation to TruetypeFont --- engines/zvision/truetype_font.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/truetype_font.h b/engines/zvision/truetype_font.h index d35da878ee..c7475d1adb 100644 --- a/engines/zvision/truetype_font.h +++ b/engines/zvision/truetype_font.h @@ -55,7 +55,25 @@ public: int32 _fontHeight; public: + /** + * Loads a .ttf file into memory. This must be called + * before any calls to drawTextToSurface + * + * @param filename The file name of the .ttf file to load + */ bool loadFile(const Common::String &filename); + /** + * Renders the supplied text to a Surface using 0x0 as the + * background color. + * + * @param text The to render + * @param textColor The color to render the text with + * @param maxWidth The max width the text should take up. + * @param maxHeight The max height the text should take up. + * @param align The alignment of the text within the bounds of maxWidth + * @param wrap If true, any words extending past maxWidth will wrap to a new line. If false, ellipses will be rendered to show that the text didn't fit + * @return A Surface containing the rendered text + */ Graphics::Surface *drawTextToSurface(const Common::String &text, uint16 textColor, int maxWidth, int maxHeight, Graphics::TextAlign align, bool wrap); }; -- cgit v1.2.3 From 69bcb76d050c162b02295784f8a3bb83d73d82c8 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sat, 21 Sep 2013 02:14:11 -0500 Subject: ZVISION: Add documentation to RenderManager --- engines/zvision/render_manager.h | 76 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index b0a42d9ba7..71f4807c29 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -65,12 +65,17 @@ private: const Graphics::PixelFormat _pixelFormat; // A buffer the exact same size as the workingWindow - // It's used for panorama/tilt warping and for clearing the workingWindow to a single color + // This buffer stores everything un-warped, then does a warp at the end of the frame Graphics::Surface _workingWindowBuffer; + // A buffer representing the entire screen. Any graphical updates are first done with this buffer + // before actually being blitted to the screen Graphics::Surface _backBuffer; + // A list of Alpha Entries that need to be blitted to the backbuffer Common::HashMap _alphaDataEntries; + // A rectangle representing the portion of the working window where the pixels have been changed since last frame Common::Rect _workingWindowDirtyRect; + // A rectangle representing the portion of the backbuffer where the pixels have been changed since last frame Common::Rect _backBufferDirtyRect; /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ @@ -121,13 +126,61 @@ public: */ void renderBackbufferToScreen(); + /** + * Renders all AlphaEntries to the backbuffer + */ void processAlphaEntries(); + /** + * Clears the AlphaEntry list + */ void clearAlphaEntries() { _alphaDataEntries.clear(); } + /** + * Removes a specific AlphaEntry from the list + * + * @param idNumber The id number identifing the AlphaEntry + */ void removeAlphaEntry(uint32 idNumber) { _alphaDataEntries.erase(idNumber); } + /** + * Copies a sub-rectangle of a buffer to the working window + * + * @param buffer The pixel data to copy to the working window + * @param destX The X destination in the working window where the subRect of data should be put + * @param destY The Y destination in the working window where the subRect of data should be put + * @param imageWidth The width of the source image + * @param width The width of the sub rectangle + * @param height The height of the sub rectangle + */ void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height); + /** + * Copies a sub-rectangle of a buffer to the working window with binary alpha support. + * + * @param buffer The pixel data to copy to the working window + * @param destX The X destination in the working window where the subRect of data should be put + * @param destY The Y destination in the working window where the subRect of data should be put + * @param imageWidth The width of the source image + * @param width The width of the sub rectangle + * @param height The height of the sub rectangle + * @param alphaColor The color to interpret as meaning 'transparent' + * @param idNumber A unique identifier for the data being copied over. + */ void copyRectToWorkingWindow(const uint16 *buffer, int32 destX, int32 destY, int32 imageWidth, int32 width, int32 height, int16 alphaColor, uint32 idNumber); + /** + * Renders the supplied text to the working window + * + * @param idNumber A unique identifier for the text + * @param text The text to be rendered + * @param font The font to use to render the text + * @param destX The X destination in the working window where the text should be rendered + * @param destY The Y destination in the working window where the text should be rendered + * @param textColor The color to render the text with (in RBG 565) + * @param maxWidth The max width the text should take up. + * @param maxHeight The max height the text should take up. + * @param align The alignment of the text within the bounds of maxWidth + * @param wrap If true, any words extending past maxWidth will wrap to a new line. If false, ellipses will be rendered to show that the text didn't fit + * @return A rectangle representing where the text was drawn in the working window + */ Common::Rect renderTextToWorkingWindow(uint32 idNumber, const Common::String &text, TruetypeFont *font, int destX, int destY, uint16 textColor, int maxWidth, int maxHeight = -1, Graphics::TextAlign align = Graphics::kTextAlignLeft, bool wrap = true); /** @@ -242,8 +295,29 @@ private: */ void renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap); + /** + * Reads an image file pixel data into a Surface buffer. In the process + * it converts the pixel data from RGB 555 to RGB 565. Also, if the image + * is transposed, it will un-transpose the pixel data. The function will + * call destination::create() if the dimensions of destination do not match + * up with the dimensions of the image. + * + * @param fileName The name of a .tga file + * @param destination A reference to the Surface to store the pixel data in + */ void readImageToSurface(const Common::String &fileName, Graphics::Surface &destination); + /** + * Move the background image by an offset. If we are currently in Panorama mode, + * the offset will correspond to a horizontal motion. If we are currently in Tilt mode, + * the offset will correspond to a vertical motion. This function should not be called + * if we are in Flat mode. + * + * The RenderManager will take care of wrapping the image. + * Ex: If the image has width 1400px, it is legal to offset 1500px. + * + * @param offset The amount to move the background + */ void moveBackground(int offset); }; -- cgit v1.2.3 From 48979c557bc580efa3fc02021fbae955a3ce4f09 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 14:41:56 -0500 Subject: ZVISION: Remove animation.o since animation.cpp is now gone --- engines/zvision/module.mk | 1 - 1 file changed, 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 2f2929db67..6a6eedc4d5 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -2,7 +2,6 @@ MODULE := engines/zvision MODULE_OBJS := \ actions.o \ - animation.o \ animation_control.o \ clock.o \ console.o \ -- cgit v1.2.3 From 9a5305a977b3b4c72c73196c4f67cee4d767fbbe Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 14:55:32 -0500 Subject: ZVISION: Add vertical pipes to prevent multi-line comments --- engines/zvision/lever_control.cpp | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 93a6054850..7f0cd401b2 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -323,27 +323,27 @@ int LeverControl::calculateVectorAngle(const Common::Point &pointOne, const Comm // Origin => (pointOne.x, pointOne.y) // * => (pointTwo.x, pointTwo.y) // - // 90 - // ^ - // * | * - // \ | / - // \ | / - // \ | / - // Quadrant 1 \ | / Quadrant 0 - // \ | / - // \ | / - // angle ( \|/ ) -angle - // 180 <----------------------------------------> 0 - // -angle ( /|\ ) angle - // / | \ - // / | \ - // Quadrant 3 / | \ Quadrant 2 - // / | \ - // / | \ - // / | \ - // * | * - // ^ - // 270 + // 90 | + // ^ | + // * | * | + // \ | / | + // \ | / | + // \ | / | + // Quadrant 1 \ | / Quadrant 0 | + // \ | / | + // \ | / | + // angle ( \|/ ) -angle | + // 180 <----------------------------------------> 0 | + // -angle ( /|\ ) angle | + // / | \ | + // / | \ | + // Quadrant 3 / | \ Quadrant 2 | + // / | \ | + // / | \ | + // / | \ | + // * | * | + // ^ | + // 270 | // Convert the local angles to unit circle angles switch (quadrant) { -- cgit v1.2.3 From 79573d0331b108162149f00f47b208376be2b8a5 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 15:02:58 -0500 Subject: ZVISION: Fix shadowing in the Direction constructor --- engines/zvision/lever_control.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h index b5677a269e..80fda4f5fd 100644 --- a/engines/zvision/lever_control.h +++ b/engines/zvision/lever_control.h @@ -48,7 +48,7 @@ private: }; struct Direction { - Direction(uint angle, uint toFrame) : angle(angle), toFrame(toFrame) {} + Direction(uint a, uint t) : angle(a), toFrame(t) {} uint angle; uint toFrame; -- cgit v1.2.3 From 9fefed67f420b2097d43592850947144b2630b3d Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 15:11:38 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/render_table.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 5eb208eb8c..dc5ebdb791 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -103,10 +103,10 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth, const Common::Rect &subRect) { uint32 destOffset = 0; - for (uint32 y = subRect.top; y < subRect.bottom; y++) { + for (int16 y = subRect.top; y < subRect.bottom; y++) { uint32 sourceOffset = y * _numColumns; - for (uint32 x = subRect.left; x < subRect.right; x++) { + for (int16 x = subRect.left; x < subRect.right; x++) { uint32 normalizedX = x - subRect.left; uint32 index = sourceOffset + x; -- cgit v1.2.3 From 713baa37695104e2aa23c4e821b2aeb5ce41a576 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 15:47:16 -0500 Subject: ZVISION: Fix memory leak in SaveManager --- engines/zvision/save_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index dbed109d51..631885e5ae 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -80,6 +80,7 @@ void SaveManager::saveGame(uint slot, const Common::String &saveName) { // Cleanup delete[] buffer; file->finalize(); + delete file; } void SaveManager::autoSave() { @@ -96,7 +97,9 @@ void SaveManager::autoSave() { writeSaveGameData(file); + // Cleanup file->finalize(); + delete file; } void SaveManager::writeSaveGameData(Common::OutSaveFile *file) { -- cgit v1.2.3 From dd0a6fe0e3258ca1e71051705b5603fd8d9ca3fd Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 15:52:24 -0500 Subject: ZVISION: Convert hardcoded number to an anonymous enum --- engines/zvision/string_manager.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.h b/engines/zvision/string_manager.h index e3539a732c..b67573b3a3 100644 --- a/engines/zvision/string_manager.h +++ b/engines/zvision/string_manager.h @@ -60,10 +60,13 @@ private: Common::List fragments; }; + enum { + NUM_TEXT_LINES = 56 // Max number of lines in a .str file. We hardcode this number because we know ZNem uses 42 strings and ZGI uses 56 + }; + private: ZVision *_engine; - // NOTE: We hardcode this number because we know ZNem uses 42 strings and ZGI uses 56 - InGameText _inGameText[56]; + InGameText _inGameText[NUM_TEXT_LINES]; Common::HashMap _fonts; static const Graphics::PixelFormat _pixelFormat565; -- cgit v1.2.3 From 9d1b0e1f8bf991abb8eb0cd484ce5025757e1efe Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 15:52:56 -0500 Subject: ZVISION: Assert that we don't exceed our hardcoded number of lines --- engines/zvision/string_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 8c7e0aaa3d..d00ea21369 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -111,6 +111,7 @@ void StringManager::parseStrFile(const Common::String &fileName) { } lineNumber++; + assert(lineNumber <= NUM_TEXT_LINES); } } -- cgit v1.2.3 From a7ffd9ade641a2fd63ea8b04822942bda16a8f4c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 15:55:22 -0500 Subject: ZVISION: Cleanup all AlphaEntries after use --- engines/zvision/render_manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index dc942fe3d0..d0356abba4 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -57,6 +57,10 @@ RenderManager::~RenderManager() { _workingWindowBuffer.free(); _currentBackground.free(); _backBuffer.free(); + + for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { + delete (*iter)._value.data; + } } void RenderManager::update(uint deltaTimeInMillis) { -- cgit v1.2.3 From fdd477df616f307bc599c2274d312ae1b62703a2 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 17:50:39 -0500 Subject: ZVISION: Free AlphaDataEntry Surfaces before deleting them --- engines/zvision/render_manager.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index d0356abba4..b3561fffaf 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -59,6 +59,7 @@ RenderManager::~RenderManager() { _backBuffer.free(); for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { + (*iter)._value.data->free(); delete (*iter)._value.data; } } -- cgit v1.2.3 From dfba1a01446a32245944a86ee08a843587050753 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 17:56:41 -0500 Subject: ZVISION: Don't cast away const-ness --- engines/zvision/render_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b3561fffaf..55a24c9c86 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -506,7 +506,7 @@ Graphics::Surface *RenderManager::tranposeSurface(const Graphics::Surface *surfa Graphics::Surface *tranposedSurface = new Graphics::Surface(); tranposedSurface->create(surface->h, surface->w, surface->format); - uint16 *source = (uint16 *)surface->getPixels(); + const uint16 *source = (const uint16 *)surface->getPixels(); uint16 *dest = (uint16 *)tranposedSurface->getPixels(); for (uint32 y = 0; y < tranposedSurface->h; y++) { -- cgit v1.2.3 From 29db14c7ddac3ba0afbe9f40c3f9219392c86f53 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 22 Sep 2013 23:28:32 -0500 Subject: ZVISION: Don't cast away const-ness --- engines/zvision/animation_control.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp index f80faea0f9..bb810a86d0 100644 --- a/engines/zvision/animation_control.cpp +++ b/engines/zvision/animation_control.cpp @@ -118,7 +118,7 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { delete tranposedFrame; } } else { - renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); + renderManager->copyRectToWorkingWindow((const uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, _animation.rlf->width(), subRect.width(), subRect.height()); // If the background can move, we need to cache the last frame so it can be rendered during background movement if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { @@ -202,7 +202,7 @@ bool AnimationControl::process(uint32 deltaTimeInMillis) { delete tranposedFrame; } } else { - renderManager->copyRectToWorkingWindow((uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); + renderManager->copyRectToWorkingWindow((const uint16 *)frame->getBasePtr(frame->w - subRect.width(), frame->h - subRect.height()), subRect.left, subRect.top, frame->w, subRect.width(), subRect.height()); // If the background can move, we need to cache the last frame so it can be rendered during background movement if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { -- cgit v1.2.3 From dfb37fb2f0f38b489d15df56ae71b261d0c0229c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 24 Sep 2013 17:32:58 -0500 Subject: ZVISION: Remove CLIPs from mutateImage Due to the math of the Panorama/Tilt, all pixel offsets are going to be closer to the center of the image. Also, mutateImage is now being called on a finished buffer, rather than an image at a time. Therefore, it no longer has to handle image wrapping. Thus, there is no case in which a pixel offset would be outside the image bounds. --- engines/zvision/render_table.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index dc5ebdb791..19f95a5d8f 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -113,12 +113,6 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 d // RenderTable only stores offsets from the original coordinates uint32 sourceYIndex = y + _internalBuffer[index].y; uint32 sourceXIndex = x + _internalBuffer[index].x; - - // Clamp the yIndex to the size of the image - sourceYIndex = CLIP(sourceYIndex, 0, _numRows - 1); - - // Clamp the xIndex to the size of the image - sourceXIndex = CLIP(sourceXIndex, 0, _numColumns - 1); destBuffer[destOffset + normalizedX] = sourceBuffer[sourceYIndex * _numColumns + sourceXIndex]; } -- cgit v1.2.3 From d8bee6be1388167b46811abfbec4102cc768df52 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Wed, 25 Sep 2013 02:30:02 -0500 Subject: ZVISION: Set the state value at each frame of a return animation Some Puzzles trigger off the intermediate frames --- engines/zvision/lever_control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 7f0cd401b2..f3d369fbfb 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -260,7 +260,6 @@ bool LeverControl::process(uint32 deltaTimeInMillis) { if (_returnRoutesCurrentProgress == _frameInfo[_currentFrame].returnRoute.end()) { _isReturning = false; _currentFrame = _returnRoutesCurrentFrame; - _engine->getScriptManager()->setStateValue(_key, _currentFrame); return false; } @@ -271,6 +270,7 @@ bool LeverControl::process(uint32 deltaTimeInMillis) { _returnRoutesCurrentFrame--; } + _engine->getScriptManager()->setStateValue(_key, _returnRoutesCurrentFrame); renderFrame(_returnRoutesCurrentFrame); } } -- cgit v1.2.3 From cd3dc276d9c3f4b2311e86a65e1f16491bf79961 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Wed, 25 Sep 2013 02:30:37 -0500 Subject: ZVISION: Only save a thumbnail of the backbuffer instead of the whole thing --- engines/zvision/save_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index 631885e5ae..08a72648f7 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -104,8 +104,8 @@ void SaveManager::autoSave() { void SaveManager::writeSaveGameData(Common::OutSaveFile *file) { // Create a thumbnail and save it - Graphics::saveThumbnail(*file, *_engine->getRenderManager()->getBackBuffer()); - + Graphics::saveThumbnail(*file); + // Write out the save date/time TimeDate td; g_system->getTimeAndDate(td); -- cgit v1.2.3 From 07c32312146bb7fe5adec41f03a2463893756361 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Wed, 25 Sep 2013 02:32:42 -0500 Subject: ZVISION: Remove memory corrupting assignment This was a code error left over from previous changes. We just create a new TextFramgment each time and hand it to List::push_back() --- engines/zvision/string_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index d00ea21369..d069e28a76 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -156,7 +156,7 @@ void StringManager::parseTag(const Common::String &tagString, uint lineNumber) { token = tokenizer.nextToken(); } - TextFragment fragment = _inGameText->fragments.back(); + TextFragment fragment; if (fontName.empty()) { fragment.style.font = _lastStyle.font; -- cgit v1.2.3 From 11576c5aa940bbdf90f6fb79f39fbc23118cfd6c Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:41:43 -0500 Subject: ZVISION: Rename ZVisionGameIds to use standard format --- engines/zvision/cursor_manager.cpp | 8 ++++---- engines/zvision/detection.cpp | 6 +++--- engines/zvision/detection.h | 6 +++--- engines/zvision/string_manager.cpp | 4 ++-- engines/zvision/zork_raw.cpp | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 50fa5031b2..69a4280157 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -47,10 +47,10 @@ CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixel _pixelFormat(pixelFormat), _cursorIsPushed(false) { // WARNING: The index IDLE_CURSOR_INDEX is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly - if (_engine->getGameId() == ZorkNemesis) { + if (_engine->getGameId() == GID_NEMESIS) { Common::String name(Common::String::format("%sa.zcr", _zNemCursorFileNames[IDLE_CURSOR_INDEX])); _idleCursor = ZorkCursor(name); - } else if (_engine->getGameId() == ZorkGrandInquisitor) { + } else if (_engine->getGameId() == GID_GRANDINQUISITOR) { _idleCursor = ZorkCursor(_zgiCursorFileNames[IDLE_CURSOR_INDEX]); } } @@ -77,7 +77,7 @@ void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) } for (int i = 0; i < NUM_CURSORS; i++) { - if (_engine->getGameId() == ZorkNemesis) { + if (_engine->getGameId() == GID_NEMESIS) { if (cursorName.equals(_cursorNames[i])) { _currentCursor = cursorName; @@ -88,7 +88,7 @@ void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) changeCursor(ZorkCursor(name)); return; } - } else if (_engine->getGameId() == ZorkGrandInquisitor) { + } else if (_engine->getGameId() == GID_GRANDINQUISITOR) { if (cursorName.equals(_cursorNames[i])) { _currentCursor = cursorName; diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index d9bb692f07..28b7134fae 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -68,7 +68,7 @@ static const ZVisionGameDescription gameDescriptions[] = { ADGF_NO_FLAGS, GUIO1(GUIO_NONE) }, - ZorkNemesis + GID_NEMESIS }, { @@ -82,12 +82,12 @@ static const ZVisionGameDescription gameDescriptions[] = { ADGF_NO_FLAGS, GUIO1(GUIO_NONE) }, - ZorkGrandInquisitor + GID_GRANDINQUISITOR }, { AD_TABLE_END_MARKER, - None + GID_NONE } }; diff --git a/engines/zvision/detection.h b/engines/zvision/detection.h index f08cfd2fe1..f9acb4d144 100644 --- a/engines/zvision/detection.h +++ b/engines/zvision/detection.h @@ -28,9 +28,9 @@ namespace ZVision { enum ZVisionGameId { - None = 0, - ZorkNemesis = 1, - ZorkGrandInquisitor = 2 + GID_NONE = 0, + GID_NEMESIS = 1, + GID_GRANDINQUISITOR = 2 }; struct ZVisionGameDescription { diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index d069e28a76..b2d19d904e 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -47,10 +47,10 @@ StringManager::~StringManager() { } void StringManager::initialize(ZVisionGameId gameId) { - if (gameId == ZorkNemesis) { + if (gameId == GID_NEMESIS) { // TODO: Check this hardcoded filename against all versions of Nemesis parseStrFile("nemesis.str"); - } else if (gameId == ZorkGrandInquisitor) { + } else if (gameId == GID_GRANDINQUISITOR) { // TODO: Check this hardcoded filename against all versions of Grand Inquisitor parseStrFile("inquis.str"); } diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 92f659203b..ebb7508748 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -164,13 +164,13 @@ Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, SoundParams soundParams; - if (engine->getGameId() == ZorkNemesis) { + if (engine->getGameId() == GID_NEMESIS) { for (int i = 0; i < 6; i++) { if (zNemSoundParamLookupTable[i].identifier == (fileName[6])) soundParams = zNemSoundParamLookupTable[i]; } } - else if (engine->getGameId() == ZorkGrandInquisitor) { + else if (engine->getGameId() == GID_GRANDINQUISITOR) { for (int i = 0; i < 6; i++) { if (zgiSoundParamLookupTable[i].identifier == (fileName[7])) soundParams = zgiSoundParamLookupTable[i]; -- cgit v1.2.3 From 7854f05b794eece823390f348875bd17512202e0 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:41:56 -0500 Subject: ZVISION: Remove empty file --- engines/zvision/module.mk | 1 - engines/zvision/scripts.cpp | 31 ------------------------------- 2 files changed, 32 deletions(-) delete mode 100644 engines/zvision/scripts.cpp (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index 6a6eedc4d5..c2c99502c6 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -20,7 +20,6 @@ MODULE_OBJS := \ save_manager.o \ scr_file_handling.o \ script_manager.o \ - scripts.o \ single_value_container.o \ string_manager.o \ timer_node.o \ diff --git a/engines/zvision/scripts.cpp b/engines/zvision/scripts.cpp deleted file mode 100644 index b6deb1b510..0000000000 --- a/engines/zvision/scripts.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* 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/scummsys.h" - -#include "zvision/zvision.h" - -namespace ZVision { - - - -} // End of namespace ZVision -- cgit v1.2.3 From a6ae661ef89a5c86b33dd84bf7b4dbd3dfbaec45 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:42:46 -0500 Subject: ZVISION: Add newline at end of file --- engines/zvision/subtitles.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/subtitles.h b/engines/zvision/subtitles.h index e88108327f..13426e03e4 100644 --- a/engines/zvision/subtitles.h +++ b/engines/zvision/subtitles.h @@ -26,4 +26,4 @@ // TODO: Implement Subtitles -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From ea5a6a7bde5b3da4b3f568151c60a0789f26093f Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:43:27 -0500 Subject: ZVISION: Fix debug typo copy-paste error --- engines/zvision/zfs_archive.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index 3577ce3d14..5f4b2a2cd9 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -41,13 +41,13 @@ ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { readHeaders(&zfsFile); - debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); + debug(0, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); } ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) { readHeaders(stream); - debug(0, "ArjArchive::ArjArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); + debug(0, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); } ZfsArchive::~ZfsArchive() { -- cgit v1.2.3 From 229e4fe3be9770a3c91fa78ddb892043a6277cf0 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:45:57 -0500 Subject: ZVISION: Move creation of the managers to ZVision::initialize() In order to make the ZVision constructor as lightweight as possible --- engines/zvision/zvision.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index b071908698..1e34587f3c 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -54,7 +54,6 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _workingWindow((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2, (WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2, ((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2) + WORKING_WINDOW_WIDTH, ((WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2) + WORKING_WINDOW_HEIGHT), _pixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), /*RGB 565*/ _desiredFrameTime(33), /* ~30 fps */ - _clock(_system) { // Put your engine in a sane state, but do nothing big yet; // in particular, do not load data from files; rather, if you @@ -65,15 +64,13 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Here is the right place to set up the engine specific debug channels //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); //DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example"); + _clock(_system), + _scriptManager(nullptr), + _renderManager(nullptr), + _saveManager(nullptr), + _stringManager(nullptr), + _cursorManager(nullptr) { - // Register random source - _rnd = new Common::RandomSource("zvision"); - - // Create managers - _scriptManager = new ScriptManager(this); - _renderManager = new RenderManager(_system, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _pixelFormat); - _saveManager = new SaveManager(this); - _stringManager = new StringManager(this); debug("ZVision::ZVision"); } @@ -122,8 +119,17 @@ void ZVision::initialize() { initGraphics(WINDOW_WIDTH, WINDOW_HEIGHT, true, &_pixelFormat); - // CursorManager must be created after all the directories have been added + // Register random source + _rnd = new Common::RandomSource("zvision"); + + // Create managers + _scriptManager = new ScriptManager(this); + _renderManager = new RenderManager(_system, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _pixelFormat); + _saveManager = new SaveManager(this); + _stringManager = new StringManager(this); _cursorManager = new CursorManager(this, &_pixelFormat); + + // Initialize the managers _cursorManager->initialize(); _scriptManager->initialize(); _stringManager->initialize(_gameDescription->gameId); -- cgit v1.2.3 From 031be61b07ba52d1ac561332981790e877f9768e Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:46:25 -0500 Subject: ZVISION: Clean up the ZVision constructor --- engines/zvision/zvision.cpp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 1e34587f3c..86e0aedebf 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -54,16 +54,6 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _workingWindow((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2, (WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2, ((WINDOW_WIDTH - WORKING_WINDOW_WIDTH) / 2) + WORKING_WINDOW_WIDTH, ((WINDOW_HEIGHT - WORKING_WINDOW_HEIGHT) / 2) + WORKING_WINDOW_HEIGHT), _pixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), /*RGB 565*/ _desiredFrameTime(33), /* ~30 fps */ - - // Put your engine in a sane state, but do nothing big yet; - // in particular, do not load data from files; rather, if you - // need to do such things, do them from run(). - - // Do not initialize graphics here - - // Here is the right place to set up the engine specific debug channels - //DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel"); - //DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example"); _clock(_system), _scriptManager(nullptr), _renderManager(nullptr), -- cgit v1.2.3 From 02aaffd8943bd6713bf6b9e473124956c1f9d592 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:48:27 -0500 Subject: ZVISION: Break comment into multiple lines for readability --- engines/zvision/zvision.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 86e0aedebf..9fa3cd32e7 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -82,7 +82,9 @@ ZVision::~ZVision() { void ZVision::initialize() { const Common::FSNode gameDataDir(ConfMan.get("path")); - // TODO: There are 10 file clashes when we flatten the directories. From a quick look, the files are exactly the same, so it shouldn't matter. But I'm noting it here just in-case it does become a problem. + // TODO: There are 10 file clashes when we flatten the directories. + // From a quick look, the files are exactly the same, so it shouldn't matter. + // But I'm noting it here just in-case it does become a problem. SearchMan.addSubDirectoryMatching(gameDataDir, "data1", 0, 4, true); SearchMan.addSubDirectoryMatching(gameDataDir, "data2", 0, 4, true); SearchMan.addSubDirectoryMatching(gameDataDir, "data3", 0, 4, true); -- cgit v1.2.3 From 72ae75e64a1aa15839f489895220c76250e2943a Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:57:15 -0500 Subject: ZVISION: Clean up zvision.h --- engines/zvision/zvision.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index efd94f1074..bc7f9e32db 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -52,14 +52,6 @@ class StringManager; class SaveManager; class RlfAnimation; -// our engine debug channels -enum { - kZDebugExample = 1 << 0, - kZDebugExample2 = 1 << 1 - // next new channel must be 1 << 2 (4) - // the current limitation is 32 debug channels (1 << 31 is the last one) -}; - class ZVision : public Engine { public: ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc); -- cgit v1.2.3 From 98e7627591ca8ac2acde347d9f41f6d810f94f67 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Sun, 29 Sep 2013 21:57:35 -0500 Subject: ZVISION: Add debug levels --- engines/zvision/rlf_animation.cpp | 12 ++++-------- engines/zvision/script_manager.cpp | 4 ++-- engines/zvision/zfs_archive.cpp | 6 +++--- engines/zvision/zvision.cpp | 4 ++-- 4 files changed, 11 insertions(+), 15 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 79638511ad..72da42737c 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -242,8 +242,7 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 if (sourceOffset + 1 >= sourceSize) { return; } else if (destOffset + 1 >= destSize) { - // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } @@ -263,8 +262,7 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 if (sourceOffset + 1 >= sourceSize) { return; } else if (destOffset + 1 >= destSize) { - // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } @@ -290,8 +288,7 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 if (sourceOffset + 1 >= sourceSize) { return; } else if (destOffset + 1 >= destSize) { - // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } @@ -320,8 +317,7 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 numberOfSamples += 2; while (numberOfSamples > 0) { if (destOffset + 1 >= destSize) { - // TODO: Make this warning silent or in a high debug level. It happens for almost all frames. - //warning("Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); + debug(2, "Frame decoding overflow\n\tsourceOffset=%u\tsourceSize=%u\n\tdestOffset=%u\tdestSize=%u", sourceOffset, sourceSize, destOffset, destSize); return; } diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 75f88ddd8a..e23a08f92e 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -173,7 +173,7 @@ void ScriptManager::checkPuzzleCriteria() { // criteriaList can be empty. Aka, the puzzle should be executed immediately if (puzzle->criteriaList.empty() || criteriaMet) { - debug("Puzzle %u criteria passed. Executing its ResultActions", puzzle->key); + debug(1, "Puzzle %u criteria passed. Executing its ResultActions", puzzle->key); // Set the puzzle as completed setStateValue(puzzle->key, 1); @@ -306,7 +306,7 @@ void ScriptManager::onKeyUp(Common::KeyState keyState) { void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 offset) { assert(world != 0); - debug("Changing location to: %c %c %c %c %u", world, room, node, view, offset); + debug(1, "Changing location to: %c %c %c %c %u", world, room, node, view, offset); // Auto save _engine->getSaveManager()->autoSave(); diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index 5f4b2a2cd9..0836336f30 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -41,17 +41,17 @@ ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { readHeaders(&zfsFile); - debug(0, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); + debug(1, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); } ZfsArchive::ZfsArchive(const Common::String &fileName, Common::SeekableReadStream *stream) : _fileName(fileName) { readHeaders(stream); - debug(0, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); + debug(1, "ZfsArchive::ZfsArchive(%s): Located %d files", _fileName.c_str(), _entryHeaders.size()); } ZfsArchive::~ZfsArchive() { - debug(0, "ZfsArchive Destructor Called"); + debug(1, "ZfsArchive Destructor Called"); ZfsEntryHeaderMap::iterator it = _entryHeaders.begin(); for ( ; it != _entryHeaders.end(); ++it) { delete it->_value; diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 9fa3cd32e7..6cdc144424 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -61,11 +61,11 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) _stringManager(nullptr), _cursorManager(nullptr) { - debug("ZVision::ZVision"); + debug(1, "ZVision::ZVision"); } ZVision::~ZVision() { - debug("ZVision::~ZVision"); + debug(1, "ZVision::~ZVision"); // Dispose of resources delete _console; -- cgit v1.2.3 From 3c8c4c836f2ac544570f032516aa2e90bc2dd4bf Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:01:56 -0500 Subject: ZVISION: Move bit flag to an enum for clarity --- engines/zvision/actions.cpp | 3 +-- engines/zvision/actions.h | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 3d25fa9e99..461c4493eb 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -367,8 +367,7 @@ bool ActionStreamVideo::execute(ZVision *engine) { } Common::Rect destRect; - // 0x1 flags that the destRect dimensions are different from the original video dimensions - if ((_flags & 0x1) == 0x1) { + if ((_flags & DIFFERENT_DIMENSIONS) == DIFFERENT_DIMENSIONS) { destRect = Common::Rect(_x1, _y1, _x2, _y2); } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 5d7cdad68f..206b5e16b1 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -321,6 +321,10 @@ public: bool execute(ZVision *engine); private: + enum { + DIFFERENT_DIMENSIONS = 0x1 // 0x1 flags that the destRect dimensions are different from the original video dimensions + }; + Common::String _fileName; uint _x1; uint _y1; -- cgit v1.2.3 From db28babf066b83576a5d9b67d5c7e29c931fbb66 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:02:44 -0500 Subject: ZVISION: Create file on the heap to prevent memory scope problems --- engines/zvision/actions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 461c4493eb..75b771c143 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -180,9 +180,9 @@ bool ActionMusic::execute(ZVision *engine) { Audio::RewindableAudioStream *audioStream; if (_fileName.contains(".wav")) { - Common::File file; - if (file.open(_fileName)) { - audioStream = Audio::makeWAVStream(&file, DisposeAfterUse::NO); + Common::File *file = new Common::File(); + if (file->open(_fileName)) { + audioStream = Audio::makeWAVStream(file, DisposeAfterUse::YES); } } else { audioStream = makeRawZorkStream(_fileName, engine); -- cgit v1.2.3 From 01238925da50c8467ce24cfe6c2cca07494a8b8e Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:09:53 -0500 Subject: ZVISION: Fix curly braces formatting --- engines/zvision/lzss_read_stream.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 03ab12d8be..4a5a4f3657 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -45,39 +45,38 @@ uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) uint mask = 1; for (int i = 0; i < 8; i++) { - if ((flagbyte & mask) == mask) - { + if ((flagbyte & mask) == mask) { byte data = _source->readByte(); - if (_source->eos()) + if (_source->eos()) { return destinationCursor; + } _window[_windowCursor] = data; destination[destinationCursor++] = data; // Increment and wrap the window cursor _windowCursor = (_windowCursor + 1) & 0xFFF; - } - else - { + } else { byte low = _source->readByte(); - if (_source->eos()) + if (_source->eos()) { return destinationCursor; + } byte high = _source->readByte(); - if (_source->eos()) + if (_source->eos()) { return destinationCursor; + } uint16 length = (high & 0xF) + 2; uint16 offset = low | ((high & 0xF0)<<4); - for(int j = 0; j <= length; j++) - { + for(int j = 0; j <= length; j++) { byte temp = _window[(offset + j) & 0xFFF]; _window[_windowCursor] = temp; destination[destinationCursor++] = temp; _windowCursor = (_windowCursor + 1) & 0xFFF; } - }; + } mask = mask << 1; } -- cgit v1.2.3 From e08023c4b62f5cbd74de93af924f7e4d689a4754 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:10:55 -0500 Subject: ZVISION: Add newline to end of module.mk --- engines/zvision/module.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index c2c99502c6..261168f133 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -40,4 +40,4 @@ PLUGIN := 1 endif # Include common rules -include $(srcdir)/rules.mk \ No newline at end of file +include $(srcdir)/rules.mk -- cgit v1.2.3 From 239493305d1662c38c015e5cc1d321b6fe5baef7 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:15:44 -0500 Subject: ZVISION: Replace all occurances of (*iter). with iter-> --- engines/zvision/lever_control.cpp | 4 ++-- engines/zvision/puzzle.h | 2 +- engines/zvision/render_manager.cpp | 20 ++++++++++---------- engines/zvision/script_manager.cpp | 16 ++++++++-------- engines/zvision/string_manager.cpp | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index f3d369fbfb..62d147c8cd 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -230,8 +230,8 @@ bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common _lastMousePos = backgroundImageSpacePos; for (Common::List::iterator iter = _frameInfo[_currentFrame].directions.begin(); iter != _frameInfo[_currentFrame].directions.end(); iter++) { - if (angle >= (int)(*iter).angle - ANGLE_DELTA && angle <= (int)(*iter).angle + ANGLE_DELTA) { - _currentFrame = (*iter).toFrame; + if (angle >= (int)iter->angle - ANGLE_DELTA && angle <= (int)iter->angle + ANGLE_DELTA) { + _currentFrame = iter->toFrame; renderFrame(_currentFrame); break; } diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 512a9636b9..679a017262 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -36,7 +36,7 @@ struct Puzzle { ~Puzzle() { for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { - delete (*iter); + delete *iter; } } diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 55a24c9c86..7c4fe43353 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -59,8 +59,8 @@ RenderManager::~RenderManager() { _backBuffer.free(); for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { - (*iter)._value.data->free(); - delete (*iter)._value.data; + iter->_value.data->free(); + delete iter->_value.data; } } @@ -121,25 +121,25 @@ void RenderManager::processAlphaEntries() { for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { uint32 destOffset = 0; uint32 sourceOffset = 0; - uint16 *backbufferPtr = (uint16 *)_backBuffer.getBasePtr((*iter)._value.destX + _workingWindow.left, (*iter)._value.destY + _workingWindow.top); - uint16 *entryPtr = (uint16 *)(*iter)._value.data->getPixels(); + uint16 *backbufferPtr = (uint16 *)_backBuffer.getBasePtr(iter->_value.destX + _workingWindow.left, iter->_value.destY + _workingWindow.top); + uint16 *entryPtr = (uint16 *)iter->_value.data->getPixels(); - for (int32 y = 0; y < (*iter)._value.height; y++) { - for (int32 x = 0; x < (*iter)._value.width; x++) { + for (int32 y = 0; y < iter->_value.height; y++) { + for (int32 x = 0; x < iter->_value.width; x++) { uint16 color = entryPtr[sourceOffset + x]; - if (color != (*iter)._value.alphaColor) { + if (color != iter->_value.alphaColor) { backbufferPtr[destOffset + x] = color; } } destOffset += _backBuffer.w; - sourceOffset += (*iter)._value.width; + sourceOffset += iter->_value.width; } if (_backBufferDirtyRect.isEmpty()) { - _backBufferDirtyRect = Common::Rect((*iter)._value.destX + _workingWindow.left, (*iter)._value.destY + _workingWindow.top, (*iter)._value.destX + _workingWindow.left + (*iter)._value.width, (*iter)._value.destY + _workingWindow.top + (*iter)._value.height); + _backBufferDirtyRect = Common::Rect(iter->_value.destX + _workingWindow.left, iter->_value.destY + _workingWindow.top, iter->_value.destX + _workingWindow.left + iter->_value.width, iter->_value.destY + _workingWindow.top + iter->_value.height); } else { - _backBufferDirtyRect.extend(Common::Rect((*iter)._value.destX + _workingWindow.left, (*iter)._value.destY + _workingWindow.top, (*iter)._value.destX + _workingWindow.left + (*iter)._value.width, (*iter)._value.destY + _workingWindow.top + (*iter)._value.height)); + _backBufferDirtyRect.extend(Common::Rect(iter->_value.destX + _workingWindow.left, iter->_value.destY + _workingWindow.top, iter->_value.destX + _workingWindow.left + iter->_value.width, iter->_value.destY + _workingWindow.top + iter->_value.height)); } } } diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index e23a08f92e..5cc7846b3a 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -71,7 +71,7 @@ void ScriptManager::createReferenceTable() { // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle for (Common::List >::iterator criteriaIter = (*activePuzzleIter)->criteriaList.begin(); criteriaIter != (*activePuzzleIter)->criteriaList.end(); criteriaIter++) { - for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); entryIter++) { _referenceTable[entryIter->key].push_back(puzzlePtr); // If the argument is a key, add a reference to it as well @@ -88,7 +88,7 @@ void ScriptManager::createReferenceTable() { // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle for (Common::List >::iterator criteriaIter = (*globalPuzzleIter)->criteriaList.begin(); criteriaIter != (*globalPuzzleIter)->criteriaList.end(); criteriaIter++) { - for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); entryIter++) { _referenceTable[entryIter->key].push_back(puzzlePtr); // If the argument is a key, add a reference to it as well @@ -135,16 +135,16 @@ void ScriptManager::checkPuzzleCriteria() { for (Common::List >::iterator criteriaIter = puzzle->criteriaList.begin(); criteriaIter != puzzle->criteriaList.end(); criteriaIter++) { criteriaMet = false; - for (Common::List::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); entryIter++) { // Get the value to compare against uint argumentValue; - if ((*entryIter).argumentIsAKey) + if (entryIter->argumentIsAKey) argumentValue = getStateValue(entryIter->argument); else argumentValue = entryIter->argument; // Do the comparison - switch ((*entryIter).criteriaOperator) { + switch (entryIter->criteriaOperator) { case Puzzle::EQUAL_TO: criteriaMet = getStateValue(entryIter->key) == argumentValue; break; @@ -197,7 +197,7 @@ void ScriptManager::cleanStateTable() { for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); iter++) { // If the value is equal to zero, we can purge it since getStateValue() // will return zero if _globalState doesn't contain a key - if ((*iter)._value == 0) { + if (iter->_value == 0) { // Remove the node _globalState.erase(iter); } @@ -384,8 +384,8 @@ void ScriptManager::serializeStateTable(Common::WriteStream *stream) { for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); iter++) { // Write out the key/value pair - stream->writeUint32LE((*iter)._key); - stream->writeUint32LE((*iter)._value); + stream->writeUint32LE(iter->_key); + stream->writeUint32LE(iter->_value); } } diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index b2d19d904e..9ae479b47d 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -42,7 +42,7 @@ StringManager::StringManager(ZVision *engine) StringManager::~StringManager() { for (Common::HashMap::iterator iter = _fonts.begin(); iter != _fonts.end(); iter++) { - delete (*iter)._value; + delete iter->_value; } } -- cgit v1.2.3 From ffaffa2bc4163fcc72c40416ba713076ba9e8a01 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:27:03 -0500 Subject: ZVISION: Convert all for-loops to use pre-increment instead of post-increment --- engines/zvision/cursor_manager.cpp | 2 +- engines/zvision/lever_control.cpp | 2 +- engines/zvision/lzss_read_stream.cpp | 4 +- engines/zvision/puzzle.h | 2 +- engines/zvision/render_manager.cpp | 26 ++++++------- engines/zvision/render_table.cpp | 12 +++--- engines/zvision/rlf_animation.cpp | 8 ++-- engines/zvision/script_manager.cpp | 72 ++++++++++++++++++------------------ engines/zvision/string_manager.cpp | 4 +- engines/zvision/utility.h | 2 +- engines/zvision/video.cpp | 12 +++--- engines/zvision/zfs_archive.cpp | 4 +- engines/zvision/zork_raw.cpp | 4 +- 13 files changed, 77 insertions(+), 77 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 69a4280157..0f524bf807 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -76,7 +76,7 @@ void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) return; } - for (int i = 0; i < NUM_CURSORS; i++) { + for (int i = 0; i < NUM_CURSORS; ++i) { if (_engine->getGameId() == GID_NEMESIS) { if (cursorName.equals(_cursorNames[i])) { _currentCursor = cursorName; diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 62d147c8cd..4e04ed4263 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -229,7 +229,7 @@ bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common int angle = calculateVectorAngle(_lastMousePos, backgroundImageSpacePos); _lastMousePos = backgroundImageSpacePos; - for (Common::List::iterator iter = _frameInfo[_currentFrame].directions.begin(); iter != _frameInfo[_currentFrame].directions.end(); iter++) { + for (Common::List::iterator iter = _frameInfo[_currentFrame].directions.begin(); iter != _frameInfo[_currentFrame].directions.end(); ++iter) { if (angle >= (int)iter->angle - ANGLE_DELTA && angle <= (int)iter->angle + ANGLE_DELTA) { _currentFrame = iter->toFrame; renderFrame(_currentFrame); diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 4a5a4f3657..a90f40b3e4 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -44,7 +44,7 @@ uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) break; uint mask = 1; - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8; ++i) { if ((flagbyte & mask) == mask) { byte data = _source->readByte(); if (_source->eos()) { @@ -70,7 +70,7 @@ uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes) uint16 length = (high & 0xF) + 2; uint16 offset = low | ((high & 0xF0)<<4); - for(int j = 0; j <= length; j++) { + for(int j = 0; j <= length; ++j) { byte temp = _window[(offset + j) & 0xFFF]; _window[_windowCursor] = temp; destination[destinationCursor++] = temp; diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 679a017262..75ea9541d2 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -35,7 +35,7 @@ struct Puzzle { Puzzle() : key(0), flags(0) {} ~Puzzle() { - for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); iter++) { + for (Common::List::iterator iter = resultActions.begin(); iter != resultActions.end(); ++iter) { delete *iter; } } diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 7c4fe43353..b8286266da 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -58,7 +58,7 @@ RenderManager::~RenderManager() { _currentBackground.free(); _backBuffer.free(); - for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { + for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); ++iter) { iter->_value.data->free(); delete iter->_value.data; } @@ -118,14 +118,14 @@ void RenderManager::renderBackbufferToScreen() { void RenderManager::processAlphaEntries() { // TODO: Add dirty rectangling support. AKA only draw an entry if the _backbufferDirtyRect intersects/contains the entry Rect - for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); iter++) { + for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); ++iter) { uint32 destOffset = 0; uint32 sourceOffset = 0; uint16 *backbufferPtr = (uint16 *)_backBuffer.getBasePtr(iter->_value.destX + _workingWindow.left, iter->_value.destY + _workingWindow.top); uint16 *entryPtr = (uint16 *)iter->_value.data->getPixels(); - for (int32 y = 0; y < iter->_value.height; y++) { - for (int32 x = 0; x < iter->_value.width; x++) { + for (int32 y = 0; y < iter->_value.height; ++y) { + for (int32 x = 0; x < iter->_value.width; ++x) { uint16 color = entryPtr[sourceOffset + x]; if (color != iter->_value.alphaColor) { backbufferPtr[destOffset + x] = color; @@ -151,7 +151,7 @@ void RenderManager::clearWorkingWindowTo555Color(uint16 color) { uint16 colorIn565 = _pixelFormat.RGBToColor(r, g, b); uint16 *bufferPtr = (uint16 *)_workingWindowBuffer.getPixels(); - for (uint32 i = 0; i < workingWindowSize; i++) { + for (uint32 i = 0; i < workingWindowSize; ++i) { bufferPtr[i] = colorIn565; } } @@ -293,10 +293,10 @@ void RenderManager::readImageToSurface(const Common::String &fileName, Graphics: if (isTransposed) { uint16 *dest = (uint16 *)destination.getPixels(); - for (uint32 y = 0; y < imageHeight; y++) { + for (uint32 y = 0; y < imageHeight; ++y) { uint32 columnIndex = y * imageWidth; - for (uint32 x = 0; x < imageWidth; x++) { + for (uint32 x = 0; x < imageWidth; ++x) { dest[columnIndex + x] = buffer[x * imageHeight + y]; } } @@ -320,8 +320,8 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i uint32 sourceOffset = 0; uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(destX, destY); - for (int32 y = 0; y < height; y++) { - for (int32 x = 0; x < width; x++) { + for (int32 y = 0; y < height; ++y) { + for (int32 x = 0; x < width; ++x) { workingWindowBufferPtr[destOffset + x] = buffer[sourceOffset + x]; } @@ -353,8 +353,8 @@ void RenderManager::copyRectToWorkingWindow(const uint16 *buffer, int32 destX, i uint32 destOffset = 0; uint16 *surfacePtr = (uint16 *)entry.data->getPixels(); - for (int32 y = 0; y < height; y++) { - for (int32 x = 0; x < width; x++) { + for (int32 y = 0; y < height; ++y) { + for (int32 x = 0; x < width; ++x) { surfacePtr[destOffset + x] = buffer[sourceOffset + x]; } @@ -509,10 +509,10 @@ Graphics::Surface *RenderManager::tranposeSurface(const Graphics::Surface *surfa const uint16 *source = (const uint16 *)surface->getPixels(); uint16 *dest = (uint16 *)tranposedSurface->getPixels(); - for (uint32 y = 0; y < tranposedSurface->h; y++) { + for (uint32 y = 0; y < tranposedSurface->h; ++y) { uint32 columnIndex = y * tranposedSurface->w; - for (uint32 x = 0; x < tranposedSurface->w; x++) { + for (uint32 x = 0; x < tranposedSurface->w; ++x) { dest[columnIndex + x] = source[x * surface->w + y]; } } diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 19f95a5d8f..ce247e23fd 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -103,10 +103,10 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 destWidth, const Common::Rect &subRect) { uint32 destOffset = 0; - for (int16 y = subRect.top; y < subRect.bottom; y++) { + for (int16 y = subRect.top; y < subRect.bottom; ++y) { uint32 sourceOffset = y * _numColumns; - for (int16 x = subRect.left; x < subRect.right; x++) { + for (int16 x = subRect.left; x < subRect.right; ++x) { uint32 normalizedX = x - subRect.left; uint32 index = sourceOffset + x; @@ -144,7 +144,7 @@ void RenderTable::generatePanoramaLookupTable() { float fovInRadians = (_panoramaOptions.fieldOfView * M_PI / 180.0f); float cylinderRadius = halfHeight / tan(fovInRadians); - for (uint x = 0; x < _numColumns; x++) { + for (uint x = 0; x < _numColumns; ++x) { // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) // Alpha represents the horizontal angle between the viewer at the center of a cylinder and x float alpha = atan(((float)x - halfWidth + 0.01f) / cylinderRadius); @@ -155,7 +155,7 @@ void RenderTable::generatePanoramaLookupTable() { float cosAlpha = cos(alpha); - for (uint y = 0; y < _numRows; y++) { + for (uint y = 0; y < _numRows; ++y) { // To calculate y in cylinder coordinates, we can do similar triangles comparison, // comparing the triangle from the center to the screen and from the center to the edge of the cylinder int32 yInCylinderCoords = int32(floor(halfHeight + ((float)y - halfHeight) * cosAlpha)); @@ -176,7 +176,7 @@ void RenderTable::generateTiltLookupTable() { float fovInRadians = (_tiltOptions.fieldOfView * M_PI / 180.0f); float cylinderRadius = halfWidth / tan(fovInRadians); - for (uint y = 0; y < _numRows; y++) { + for (uint y = 0; y < _numRows; ++y) { // Add an offset of 0.01 to overcome zero tan/atan issue (horizontal line on half of screen) // Alpha represents the vertical angle between the viewer at the center of a cylinder and y @@ -189,7 +189,7 @@ void RenderTable::generateTiltLookupTable() { float cosAlpha = cos(alpha); uint32 columnIndex = y * _numColumns; - for (uint x = 0; x < _numColumns; x++) { + for (uint x = 0; x < _numColumns; ++x) { // To calculate x in cylinder coordinates, we can do similar triangles comparison, // comparing the triangle from the center to the screen and from the center to the edge of the cylinder int32 xInCylinderCoords = int32(floor(halfWidth + ((float)x - halfWidth) * cosAlpha)); diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 72da42737c..d932fa7698 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -63,14 +63,14 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) _frames = new Frame[_frameCount]; // Read in each frame - for (uint i = 0; i < _frameCount; i++) { + for (uint i = 0; i < _frameCount; ++i) { _frames[i] = readNextFrame(); } } } RlfAnimation::~RlfAnimation() { - for (uint i = 0; i < _frameCount; i++) { + for (uint i = 0; i < _frameCount; ++i) { delete[] _frames[i].encodedData; } delete[] _frames; @@ -165,7 +165,7 @@ void RlfAnimation::seekToFrame(int frameNumber) { int closestFrame = _currentFrame; int distance = (int)frameNumber - _currentFrame; - for (Common::List::const_iterator iter = _completeFrames.begin(); iter != _completeFrames.end(); iter++) { + for (Common::List::const_iterator iter = _completeFrames.begin(); iter != _completeFrames.end(); ++iter) { int newDistance = (int)frameNumber - (int)(*iter); if (newDistance > 0 && (closestFrame == -1 || newDistance < distance)) { closestFrame = (*iter); @@ -173,7 +173,7 @@ void RlfAnimation::seekToFrame(int frameNumber) { } } - for (int i = closestFrame; i <= frameNumber; i++) { + for (int i = closestFrame; i <= frameNumber; ++i) { applyFrameToCurrent(i); } diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 5cc7846b3a..31983a684e 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -43,13 +43,13 @@ ScriptManager::ScriptManager(ZVision *engine) } ScriptManager::~ScriptManager() { - for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { delete (*iter); } - for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) { delete (*iter); } - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { delete (*iter); } } @@ -66,12 +66,12 @@ void ScriptManager::update(uint deltaTimeMillis) { void ScriptManager::createReferenceTable() { // Iterate through each local Puzzle - for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { + for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); ++activePuzzleIter) { Puzzle *puzzlePtr = (*activePuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle - for (Common::List >::iterator criteriaIter = (*activePuzzleIter)->criteriaList.begin(); criteriaIter != (*activePuzzleIter)->criteriaList.end(); criteriaIter++) { - for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); entryIter++) { + for (Common::List >::iterator criteriaIter = (*activePuzzleIter)->criteriaList.begin(); criteriaIter != (*activePuzzleIter)->criteriaList.end(); ++criteriaIter) { + for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); ++entryIter) { _referenceTable[entryIter->key].push_back(puzzlePtr); // If the argument is a key, add a reference to it as well @@ -83,12 +83,12 @@ void ScriptManager::createReferenceTable() { } // Iterate through each global Puzzle - for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { + for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); ++globalPuzzleIter) { Puzzle *puzzlePtr = (*globalPuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle - for (Common::List >::iterator criteriaIter = (*globalPuzzleIter)->criteriaList.begin(); criteriaIter != (*globalPuzzleIter)->criteriaList.end(); criteriaIter++) { - for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); entryIter++) { + for (Common::List >::iterator criteriaIter = (*globalPuzzleIter)->criteriaList.begin(); criteriaIter != (*globalPuzzleIter)->criteriaList.end(); ++criteriaIter) { + for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); ++entryIter) { _referenceTable[entryIter->key].push_back(puzzlePtr); // If the argument is a key, add a reference to it as well @@ -100,7 +100,7 @@ void ScriptManager::createReferenceTable() { } // Remove duplicate entries - for (Common::HashMap >::iterator referenceTableIter = _referenceTable.begin(); referenceTableIter != _referenceTable.end(); referenceTableIter++) { + for (Common::HashMap >::iterator referenceTableIter = _referenceTable.begin(); referenceTableIter != _referenceTable.end(); ++referenceTableIter) { removeDuplicateEntries(referenceTableIter->_value); } } @@ -113,7 +113,7 @@ void ScriptManager::updateNodes(uint deltaTimeMillis) { // Remove the node iter = _activeControls.erase(iter); } else { - iter++; + ++iter; } } } @@ -132,10 +132,10 @@ void ScriptManager::checkPuzzleCriteria() { // Check each Criteria bool criteriaMet = false; - for (Common::List >::iterator criteriaIter = puzzle->criteriaList.begin(); criteriaIter != puzzle->criteriaList.end(); criteriaIter++) { + for (Common::List >::iterator criteriaIter = puzzle->criteriaList.begin(); criteriaIter != puzzle->criteriaList.end(); ++criteriaIter) { criteriaMet = false; - for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); entryIter++) { + for (Common::List::iterator entryIter = criteriaIter->begin(); entryIter != criteriaIter->end(); ++entryIter) { // Get the value to compare against uint argumentValue; if (entryIter->argumentIsAKey) @@ -179,7 +179,7 @@ void ScriptManager::checkPuzzleCriteria() { setStateValue(puzzle->key, 1); bool shouldContinue = true; - for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); resultIter++) { + for (Common::List::iterator resultIter = puzzle->resultActions.begin(); resultIter != puzzle->resultActions.end(); ++resultIter) { shouldContinue = shouldContinue && (*resultIter)->execute(_engine); if (!shouldContinue) { break; @@ -194,7 +194,7 @@ void ScriptManager::checkPuzzleCriteria() { } void ScriptManager::cleanStateTable() { - for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); iter++) { + for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); ++iter) { // If the value is equal to zero, we can purge it since getStateValue() // will return zero if _globalState doesn't contain a key if (iter->_value == 0) { @@ -215,7 +215,7 @@ void ScriptManager::setStateValue(uint32 key, uint value) { _globalState[key] = value; if (_referenceTable.contains(key)) { - for (Common::Array::iterator iter = _referenceTable[key].begin(); iter != _referenceTable[key].end(); iter++) { + for (Common::Array::iterator iter = _referenceTable[key].begin(); iter != _referenceTable[key].end(); ++iter) { _puzzlesToCheck.push((*iter)); } } @@ -230,7 +230,7 @@ void ScriptManager::addControl(Control *control) { } Control *ScriptManager::getControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { return (*iter); } @@ -240,7 +240,7 @@ Control *ScriptManager::getControl(uint32 key) { } void ScriptManager::enableControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { (*iter)->enable(); break; @@ -249,7 +249,7 @@ void ScriptManager::enableControl(uint32 key) { } void ScriptManager::disableControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { (*iter)->disable(); break; @@ -258,7 +258,7 @@ void ScriptManager::disableControl(uint32 key) { } void ScriptManager::focusControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { uint32 controlKey = (*iter)->getKey(); if (controlKey == key) { @@ -272,20 +272,20 @@ void ScriptManager::focusControl(uint32 key) { } void ScriptManager::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onMouseDown(screenSpacePos, backgroundImageSpacePos); } } void ScriptManager::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onMouseUp(screenSpacePos, backgroundImageSpacePos); } } bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { bool cursorWasChanged = false; - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { cursorWasChanged = cursorWasChanged || (*iter)->onMouseMove(screenSpacePos, backgroundImageSpacePos); } @@ -293,13 +293,13 @@ bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Commo } void ScriptManager::onKeyDown(Common::KeyState keyState) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onKeyDown(keyState); } } void ScriptManager::onKeyUp(Common::KeyState keyState) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onKeyUp(keyState); } } @@ -314,11 +314,11 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, // Clear all the containers _referenceTable.clear(); _puzzlesToCheck.clear(); - for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { delete (*iter); } _activePuzzles.clear(); - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { delete (*iter); } _activeControls.clear(); @@ -343,12 +343,12 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, _engine->getRenderManager()->setBackgroundPosition(offset); // Enable all the controls - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->enable(); } // Add all the local puzzles to the queue to be checked - for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); iter++) { + for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { // Reset any Puzzles that have the flag ONCE_PER_INST if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { setStateValue((*iter)->key, 0); @@ -358,7 +358,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, } // Add all the global puzzles to the queue to be checked - for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); iter++) { + for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) { // Reset any Puzzles that have the flag ONCE_PER_INST if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { setStateValue((*iter)->key, 0); @@ -382,7 +382,7 @@ void ScriptManager::serializeStateTable(Common::WriteStream *stream) { // Write the number of state value entries stream->writeUint32LE(_globalState.size()); - for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); iter++) { + for (Common::HashMap::iterator iter = _globalState.begin(); iter != _globalState.end(); ++iter) { // Write out the key/value pair stream->writeUint32LE(iter->_key); stream->writeUint32LE(iter->_value); @@ -396,7 +396,7 @@ void ScriptManager::deserializeStateTable(Common::SeekableReadStream *stream) { // Read the number of key/value pairs uint32 numberOfPairs = stream->readUint32LE(); - for (uint32 i = 0; i < numberOfPairs; i++) { + for (uint32 i = 0; i < numberOfPairs; ++i) { uint32 key = stream->readUint32LE(); uint32 value = stream->readUint32LE(); // Directly access the state table so we don't trigger Puzzle checks @@ -408,14 +408,14 @@ void ScriptManager::serializeControls(Common::WriteStream *stream) { // Count how many controls need to save their data // Because WriteStream isn't seekable uint32 numberOfControlsNeedingSerialization = 0; - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->needsSerialization()) { numberOfControlsNeedingSerialization++; } } stream->writeUint32LE(numberOfControlsNeedingSerialization); - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->serialize(stream); } } @@ -423,9 +423,9 @@ void ScriptManager::serializeControls(Common::WriteStream *stream) { void ScriptManager::deserializeControls(Common::SeekableReadStream *stream) { uint32 numberOfControls = stream->readUint32LE(); - for (uint32 i = 0; i < numberOfControls; i++) { + for (uint32 i = 0; i < numberOfControls; ++i) { uint32 key = stream->readUint32LE(); - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); iter++) { + for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { (*iter)->deserialize(stream); break; diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 9ae479b47d..9ff1dd2e87 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -41,7 +41,7 @@ StringManager::StringManager(ZVision *engine) } StringManager::~StringManager() { - for (Common::HashMap::iterator iter = _fonts.begin(); iter != _fonts.end(); iter++) { + for (Common::HashMap::iterator iter = _fonts.begin(); iter != _fonts.end(); ++iter) { delete iter->_value; } } @@ -80,7 +80,7 @@ void StringManager::parseStrFile(const Common::String &fileName) { uint textStringCursor = 0; bool inTag = false; - for (uint i = 0; i < asciiLine.size(); i++) { + for (uint i = 0; i < asciiLine.size(); ++i) { switch (asciiLine[i]) { case '<': inTag = true; diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 3348a43fe3..af47de7fe0 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -70,7 +70,7 @@ template void removeDuplicateEntries(Common::Array &container) { Common::sort(container.begin(), container.end()); - for (uint i = 0; i + 1 < container.size(); i++) { + for (uint i = 0; i + 1 < container.size(); ++i) { while (i + 1 < container.size() && container[i] == container[i + 1]) { container.remove_at(i + 1); } diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 5230653ca3..2fe4d231ef 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -43,11 +43,11 @@ void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, const byte *srcPtr = src; if (bytesPerPixel == 1) { - for (uint32 y = 0; y < srcHeight; y++) { - for (uint32 x = 0; x < srcWidth; x++) { + for (uint32 y = 0; y < srcHeight; ++y) { + for (uint32 x = 0; x < srcWidth; ++x) { const byte color = *srcPtr++; - for (uint i = 0; i < scaleAmount; i++) { + for (uint i = 0; i < scaleAmount; ++i) { dst[i] = color; dst[pitch + i] = color; } @@ -56,12 +56,12 @@ void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, dst += pitch; } } else if (bytesPerPixel == 2) { - for (uint32 y = 0; y < srcHeight; y++) { - for (uint32 x = 0; x < srcWidth; x++) { + for (uint32 y = 0; y < srcHeight; ++y) { + for (uint32 x = 0; x < srcWidth; ++x) { const byte color = *srcPtr++; const byte color2 = *srcPtr++; - for (uint i = 0; i < scaleAmount; i++) { + for (uint i = 0; i < scaleAmount; ++i) { uint index = i *2; dst[index] = color; diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index 0836336f30..b0444fa511 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -78,7 +78,7 @@ void ZfsArchive::readHeaders(Common::SeekableReadStream *stream) { nextOffset = stream->readUint32LE(); // Read in each entry header - for (uint32 i = 0; i < _header.filesPerBlock; i++) { + for (uint32 i = 0; i < _header.filesPerBlock; ++i) { ZfsEntryHeader entryHeader; entryHeader.name = readEntryName(stream); @@ -149,7 +149,7 @@ Common::SeekableReadStream *ZfsArchive::createReadStreamForMember(const Common:: } void ZfsArchive::unXor(byte *buffer, uint32 length, const byte *xorKey) const { - for (uint32 i = 0; i < length; i++) + for (uint32 i = 0; i < length; ++i) buffer[i] ^= xorKey[i % 4]; } diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index ebb7508748..1231e406cb 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -165,13 +165,13 @@ Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, SoundParams soundParams; if (engine->getGameId() == GID_NEMESIS) { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 6; ++i) { if (zNemSoundParamLookupTable[i].identifier == (fileName[6])) soundParams = zNemSoundParamLookupTable[i]; } } else if (engine->getGameId() == GID_GRANDINQUISITOR) { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < 6; ++i) { if (zgiSoundParamLookupTable[i].identifier == (fileName[7])) soundParams = zgiSoundParamLookupTable[i]; } -- cgit v1.2.3 From 4172334b51a33c0b68ad81ceba2aaf1a6e70d8f2 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:44:29 -0500 Subject: ZVISION: Remove global const variables Instead, use ColorMasks --- engines/zvision/rlf_animation.cpp | 19 +++++++++---------- engines/zvision/rlf_animation.h | 3 --- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index d932fa7698..008a246267 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -28,14 +28,13 @@ #include "common/debug.h" #include "common/endian.h" +#include "graphics/colormasks.h" + #include "zvision/rlf_animation.h" namespace ZVision { -const Graphics::PixelFormat RlfAnimation::_pixelFormat555 = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); -const Graphics::PixelFormat RlfAnimation::_pixelFormat565 = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); - RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) : _stream(stream), _lastFrameRead(0), @@ -56,7 +55,7 @@ RlfAnimation::RlfAnimation(const Common::String &fileName, bool stream) return; } - _currentFrameBuffer.create(_width, _height, _pixelFormat565); + _currentFrameBuffer.create(_width, _height, Graphics::createPixelFormat<565>()); _frameBufferByteSize = _width * _height * sizeof(uint16); if (!stream) { @@ -247,8 +246,8 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 } byte r, g, b; - _pixelFormat555.colorToRGB(READ_LE_UINT16(source + sourceOffset), r, g, b); - uint16 destColor = _pixelFormat565.RGBToColor(r, g, b); + Graphics::colorToRGB>(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 destColor = Graphics::RGBToColor>(r, g, b); WRITE_UINT16(dest + destOffset, destColor); sourceOffset += 2; @@ -293,8 +292,8 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 } byte r, g, b; - _pixelFormat555.colorToRGB(READ_LE_UINT16(source + sourceOffset), r, g, b); - uint16 destColor = _pixelFormat565.RGBToColor(r, g, b); + Graphics::colorToRGB>(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 destColor = Graphics::RGBToColor>(r, g, b); WRITE_UINT16(dest + destOffset, destColor); sourceOffset += 2; @@ -310,8 +309,8 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 } byte r, g, b; - _pixelFormat555.colorToRGB(READ_LE_UINT16(source + sourceOffset), r, g, b); - uint16 sampleColor = _pixelFormat565.RGBToColor(r, g, b); + Graphics::colorToRGB>(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 sampleColor = Graphics::RGBToColor>(r, g, b); sourceOffset += 2; numberOfSamples += 2; diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index 3f205d9666..ca9004f8b6 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -52,9 +52,6 @@ private: uint32 encodedSize; }; - const static Graphics::PixelFormat _pixelFormat555; - const static Graphics::PixelFormat _pixelFormat565; - private: Common::File _file; bool _stream; -- cgit v1.2.3 From 4c06affe84640ffa1fc8487a4344b41c225d7d8e Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:47:57 -0500 Subject: ZVISION: Convert _completeFrames to an Array --- engines/zvision/rlf_animation.cpp | 6 +++--- engines/zvision/rlf_animation.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 008a246267..f0d5ac5284 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -164,10 +164,10 @@ void RlfAnimation::seekToFrame(int frameNumber) { int closestFrame = _currentFrame; int distance = (int)frameNumber - _currentFrame; - for (Common::List::const_iterator iter = _completeFrames.begin(); iter != _completeFrames.end(); ++iter) { - int newDistance = (int)frameNumber - (int)(*iter); + for (int i = 0; i < _completeFrames.size(); ++i) { + int newDistance = (int)frameNumber - (int)(_completeFrames[i]); if (newDistance > 0 && (closestFrame == -1 || newDistance < distance)) { - closestFrame = (*iter); + closestFrame = _completeFrames[i]; distance = newDistance; } } diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index ca9004f8b6..53247eb4ab 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -62,7 +62,7 @@ private: uint _height; uint32 _frameTime; // In milliseconds Frame *_frames; - Common::List _completeFrames; + Common::Array _completeFrames; int _currentFrame; Graphics::Surface _currentFrameBuffer; -- cgit v1.2.3 From afe8cba1a1d161062a54400258467167cab76776 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:49:33 -0500 Subject: ZVISION: Fix spacing --- engines/zvision/save_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index 08a72648f7..9cc664ce5a 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -41,7 +41,7 @@ const uint32 SaveManager::SAVEGAME_ID = MKTAG('Z', 'E', 'N', 'G'); void SaveManager::saveGame(uint slot, const Common::String &saveName) { // The games only support 20 slots - assert(slot <=1 && slot <= 20); + assert(slot <= 1 && slot <= 20); Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); Common::OutSaveFile *file = saveFileManager->openForSaving(_engine->generateSaveFileName(slot)); -- cgit v1.2.3 From 0deb84522988488b8b93d57bb525fd4a6f8e4588 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:56:35 -0500 Subject: ZVISION: Remove global const variable Replace with ColorMasks --- engines/zvision/string_manager.cpp | 5 ++--- engines/zvision/string_manager.h | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 9ff1dd2e87..cac6858ef0 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -27,6 +27,7 @@ #include "common/debug.h" #include "graphics/fontman.h" +#include "graphics/colormasks.h" #include "zvision/string_manager.h" #include "zvision/truetype_font.h" @@ -34,8 +35,6 @@ namespace ZVision { -const Graphics::PixelFormat StringManager::_pixelFormat565 = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); - StringManager::StringManager(ZVision *engine) : _engine(engine) { } @@ -206,7 +205,7 @@ void StringManager::parseTag(const Common::String &tagString, uint lineNumber) { } fragment.style.align = align; - fragment.style.color = _pixelFormat565.ARGBToColor(0, red, green, blue); + fragment.style.color = Graphics::ARGBToColor>(0, red, green, blue); _inGameText[lineNumber].fragments.push_back(fragment); _lastStyle = fragment.style; diff --git a/engines/zvision/string_manager.h b/engines/zvision/string_manager.h index b67573b3a3..74d13cd994 100644 --- a/engines/zvision/string_manager.h +++ b/engines/zvision/string_manager.h @@ -69,8 +69,6 @@ private: InGameText _inGameText[NUM_TEXT_LINES]; Common::HashMap _fonts; - static const Graphics::PixelFormat _pixelFormat565; - TextStyle _lastStyle; public: -- cgit v1.2.3 From 28ac59307b43da50964ad732a65dc676d613ad73 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 17:57:32 -0500 Subject: ZVISION: Update warning message to correspond to the behavior --- engines/zvision/string_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index cac6858ef0..3c9a3c6f0c 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -241,7 +241,7 @@ Common::String StringManager::readWideLine(Common::SeekableReadStream &stream) { } if (charOverflowWarning) { - warning("UTF-16 is not supported. Characters greater than 255 are clamped to 255"); + warning("UTF-16 is not supported. Characters greater than 255 are replaced with '?'"); } return asciiString; -- cgit v1.2.3 From 1f9ba897b8aa8afe776928ecd5ca480b8b2fc3a8 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 18:00:57 -0500 Subject: ZVISION: Convert _timeLeft to a signed int This allows time decrementing to go negative instead of wrapping to UINT_MAX. Which makes comparisons easier. --- engines/zvision/timer_node.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/timer_node.h b/engines/zvision/timer_node.h index 21c344bb15..4bc8397ff0 100644 --- a/engines/zvision/timer_node.h +++ b/engines/zvision/timer_node.h @@ -48,7 +48,7 @@ public: inline bool needsSerialization() { return true; } private: - uint32 _timeLeft; + int32 _timeLeft; }; } // End of namespace ZVision -- cgit v1.2.3 From b913e9f8a330328a6600539ecd03754e19560f97 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 18:46:57 -0500 Subject: ZVISION: Update removeDuplicateEntries to preserve order The new algorithm is potentially slower, but it doesn't need to use sort. Speed shouldn't be a problem because the function isn't used that often and in each case the size of the container is small. --- engines/zvision/utility.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index af47de7fe0..14077080f5 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -61,20 +61,34 @@ void trimCommentsAndWhiteSpace(Common::String *string); void dumpEveryResultAction(const Common::String &destFile); /** - * Removes all duplicate entries from container. + * Removes all duplicate entries from container. Relative order will be preserved. * - * @param container - * @return + * @param container The Array to remove duplicate entries from */ template void removeDuplicateEntries(Common::Array &container) { - Common::sort(container.begin(), container.end()); + // Length of modified array + int newLength = 1; + int j; + + for(int i = 1; i < container.size(); i++) { + for(j = 0; j < newLength; j++) { + if (container[i] == container[j]) { + break; + } + } - for (uint i = 0; i + 1 < container.size(); ++i) { - while (i + 1 < container.size() && container[i] == container[i + 1]) { - container.remove_at(i + 1); + // 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(); + } } /** -- cgit v1.2.3 From 1c8a5582a2dd23c01bda6002e746a4e5749b21b6 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 18:47:16 -0500 Subject: ZVISION: Remove unnesessary operator overload --- engines/zvision/puzzle.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 75ea9541d2..97b839f9a7 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -74,13 +74,6 @@ struct Puzzle { // This has to be list of pointers because ResultAction is abstract Common::List resultActions; uint flags; - - // Used by the ScriptManager to allow unique-ification of _referenceTable - // The unique-ification is done by sorting, then iterating and removing duplicates - // The sort uses operator< - inline bool operator<(const Puzzle &other) const { - return key < other.key; - } }; } // End of namespace ZVision -- cgit v1.2.3 From 18b1c3130fa1c6dbce79b83491c524e4a1f37867 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 18:48:34 -0500 Subject: ZVISION: Move two lookup tables inside the RawZorkStream class Instead of being global variables. --- engines/zvision/zork_raw.cpp | 23 +++++++++++++++++++---- engines/zvision/zork_raw.h | 17 ++--------------- 2 files changed, 21 insertions(+), 19 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 1231e406cb..55ad2076e0 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -52,6 +52,21 @@ const int32 RawZorkStream::_amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B, 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF}; +const SoundParams RawZorkStream::_zNemSoundParamLookupTable[6] = {{'6', 0x2B11, false, false}, + {'a', 0x5622, false, true}, + {'b', 0x5622, true, true}, + {'n', 0x2B11, false, true}, + {'s', 0x5622, false, true}, + {'t', 0x5622, true, true} +}; + +const SoundParams RawZorkStream::_zgiSoundParamLookupTable[5] = {{'a',0x5622, false, false}, + {'k',0x2B11, true, true}, + {'p',0x5622, false, true}, + {'q',0x5622, true, true}, + {'u',0xAC44, true, true} +}; + RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream) : _rate(rate), _stereo(0), @@ -166,14 +181,14 @@ Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, if (engine->getGameId() == GID_NEMESIS) { for (int i = 0; i < 6; ++i) { - if (zNemSoundParamLookupTable[i].identifier == (fileName[6])) - soundParams = zNemSoundParamLookupTable[i]; + if (RawZorkStream::_zNemSoundParamLookupTable[i].identifier == (fileName[6])) + soundParams = RawZorkStream::_zNemSoundParamLookupTable[i]; } } else if (engine->getGameId() == GID_GRANDINQUISITOR) { for (int i = 0; i < 6; ++i) { - if (zgiSoundParamLookupTable[i].identifier == (fileName[7])) - soundParams = zgiSoundParamLookupTable[i]; + if (RawZorkStream::_zgiSoundParamLookupTable[i].identifier == (fileName[7])) + soundParams = RawZorkStream::_zgiSoundParamLookupTable[i]; } } diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index f19ffc1661..62433b137b 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -41,21 +41,6 @@ struct SoundParams { bool packed; }; -const SoundParams zNemSoundParamLookupTable[6] = {{'6', 0x2B11, false, false}, - {'a', 0x5622, false, true}, - {'b', 0x5622, true, true}, - {'n', 0x2B11, false, true}, - {'s', 0x5622, false, true}, - {'t', 0x5622, true, true} -}; - -const SoundParams zgiSoundParamLookupTable[5] = {{'a',0x5622, false, false}, - {'k',0x2B11, true, true}, - {'p',0x5622, false, true}, - {'q',0x5622, true, true}, - {'u',0xAC44, true, true} -}; - /** * This is a stream, which allows for playing raw ADPCM data from a stream. */ @@ -67,6 +52,8 @@ public: } public: + static const SoundParams _zNemSoundParamLookupTable[6]; + static const SoundParams _zgiSoundParamLookupTable[5]; private: const int _rate; // Sample rate of stream -- cgit v1.2.3 From 1140c8b48d6d814aa512af348bcb0463006250d3 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 18:49:01 -0500 Subject: ZVISION: Fix space formatting --- engines/zvision/zork_raw.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 62433b137b..51248e341a 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -89,28 +89,28 @@ public: /** * Creates an audio stream, which plays from the given buffer. * - * @param buffer Buffer to play from. - * @param size Size of the buffer in bytes. - * @param rate Rate of the sound data. - * @param disposeAfterUse Whether to free the buffer after use (with free!). - * @return The new SeekableAudioStream (or 0 on failure). + * @param buffer Buffer to play from. + * @param size Size of the buffer in bytes. + * @param rate Rate of the sound data. + * @param dispose AfterUse Whether to free the buffer after use (with free!). + * @return The new SeekableAudioStream (or 0 on failure). */ Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size, int rate, - bool stereo, + bool stereo, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); /** * Creates an audio stream, which plays from the given stream. * - * @param stream Stream object to play from. - * @param rate Rate of the sound data. - * @param disposeAfterUse Whether to delete the stream after use. - * @return The new SeekableAudioStream (or 0 on failure). + * @param stream Stream object to play from. + * @param rate Rate of the sound data. + * @param dispose AfterUse Whether to delete the stream after use. + * @return The new SeekableAudioStream (or 0 on failure). */ Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream, int rate, - bool stereo, + bool stereo, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine); -- cgit v1.2.3 From 1bdcae7f18c652b5ab0ab1b8993503745bf5102e Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 18:50:36 -0500 Subject: ZVISION: Rename zvision.h inclusion guard to be consistent with the other files --- engines/zvision/zvision.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index bc7f9e32db..13bdb3c755 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -21,8 +21,8 @@ * */ -#ifndef ZVISION_H -#define ZVISION_H +#ifndef ZVISION_ZVISION_H +#define ZVISION_ZVISION_H #include "common/random.h" #include "common/events.h" -- cgit v1.2.3 From bad28dc15872e208bf21f1e6fa2ab906bca598c4 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 20:08:41 -0500 Subject: ZVISION: Standardize includes order and format Format is: common/scummsys.h (Only if a .cpp file) header file for this file (Only if a .cpp file) zengine includes other includes, grouped by module --- engines/zvision/actions.cpp | 10 ++++++---- engines/zvision/actions.h | 5 +---- engines/zvision/animation_control.cpp | 7 +++++-- engines/zvision/animation_control.h | 10 ++++++++-- engines/zvision/clock.cpp | 3 ++- engines/zvision/console.cpp | 15 +++++++++------ engines/zvision/control.cpp | 5 +++-- engines/zvision/control.h | 2 -- engines/zvision/cursor.cpp | 4 ++-- engines/zvision/cursor.h | 3 +-- engines/zvision/cursor_manager.cpp | 8 +++++--- engines/zvision/cursor_manager.h | 4 ++-- engines/zvision/detection.cpp | 8 +++++--- engines/zvision/detection.h | 1 + engines/zvision/events.cpp | 13 ++++++++----- engines/zvision/input_control.cpp | 9 +++++---- engines/zvision/input_control.h | 4 ++-- engines/zvision/lever_control.cpp | 16 +++++++++------- engines/zvision/lever_control.h | 4 +--- engines/zvision/lzss_read_stream.cpp | 1 + engines/zvision/lzss_read_stream.h | 2 +- engines/zvision/push_toggle_control.cpp | 6 ++++-- engines/zvision/push_toggle_control.h | 4 +--- engines/zvision/puzzle.h | 2 +- engines/zvision/render_manager.cpp | 7 +++++-- engines/zvision/render_manager.h | 6 +++--- engines/zvision/render_table.cpp | 6 ++++-- engines/zvision/render_table.h | 5 ++--- engines/zvision/rlf_animation.cpp | 4 ++-- engines/zvision/rlf_animation.h | 3 +-- engines/zvision/save_manager.cpp | 11 ++++++----- engines/zvision/save_manager.h | 6 ++++-- engines/zvision/scr_file_handling.cpp | 2 ++ engines/zvision/script_manager.cpp | 12 +++++++----- engines/zvision/script_manager.h | 5 +++-- engines/zvision/single_value_container.cpp | 3 ++- engines/zvision/string_manager.cpp | 7 ++++--- engines/zvision/string_manager.h | 2 -- engines/zvision/timer_node.cpp | 6 ++++-- engines/zvision/timer_node.h | 2 -- engines/zvision/truetype_font.cpp | 9 +++++---- engines/zvision/truetype_font.h | 3 +-- engines/zvision/utility.cpp | 8 +++++--- engines/zvision/utility.h | 1 + engines/zvision/vector2.h | 3 +++ engines/zvision/video.cpp | 12 ++++++++---- engines/zvision/zfs_archive.cpp | 5 ++--- engines/zvision/zfs_archive.h | 1 + engines/zvision/zork_avi_decoder.cpp | 7 +++++-- engines/zvision/zork_avi_decoder.h | 1 + engines/zvision/zork_raw.cpp | 11 +++++++---- engines/zvision/zork_raw.h | 2 +- engines/zvision/zvision.cpp | 22 +++++++++++----------- engines/zvision/zvision.h | 6 +++--- 54 files changed, 186 insertions(+), 138 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 75b771c143..eae4ec2ed5 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -22,11 +22,8 @@ #include "common/scummsys.h" -#include "common/file.h" - -#include "audio/decoders/wave.h" - #include "zvision/actions.h" + #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" @@ -35,6 +32,11 @@ #include "zvision/timer_node.h" #include "zvision/animation_control.h" +#include "common/file.h" + +#include "audio/decoders/wave.h" + + namespace ZVision { ////////////////////////////////////////////////////////////////////////////// diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 206b5e16b1..afa3e3a2ac 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -23,13 +23,10 @@ #ifndef ZVISION_ACTIONS_H #define ZVISION_ACTIONS_H -#include "common/scummsys.h" +#include "common/str.h" #include "audio/mixer.h" -namespace Common { -class String; -} namespace ZVision { diff --git a/engines/zvision/animation_control.cpp b/engines/zvision/animation_control.cpp index bb810a86d0..1143380501 100644 --- a/engines/zvision/animation_control.cpp +++ b/engines/zvision/animation_control.cpp @@ -22,15 +22,18 @@ #include "common/scummsys.h" -#include "video/video_decoder.h" - #include "zvision/animation_control.h" + #include "zvision/zvision.h" #include "zvision/render_manager.h" #include "zvision/script_manager.h" #include "zvision/rlf_animation.h" #include "zvision/zork_avi_decoder.h" +#include "video/video_decoder.h" + +#include "graphics/surface.h" + namespace ZVision { diff --git a/engines/zvision/animation_control.h b/engines/zvision/animation_control.h index 935f4abb4b..2ac3691483 100644 --- a/engines/zvision/animation_control.h +++ b/engines/zvision/animation_control.h @@ -23,15 +23,21 @@ #ifndef ZVISION_ANIMATION_CONTROL_H #define ZVISION_ANIMATION_CONTROL_H -#include "common/types.h" - #include "zvision/control.h" +namespace Common { +class String; +} + namespace Video { class VideoDecoder; } +namespace Graphics { +struct Surface; +} + namespace ZVision { class ZVision; diff --git a/engines/zvision/clock.cpp b/engines/zvision/clock.cpp index fe322525f8..c8ee717a33 100644 --- a/engines/zvision/clock.cpp +++ b/engines/zvision/clock.cpp @@ -23,9 +23,10 @@ #include "common/scummsys.h" +#include "zvision/clock.h" + #include "common/system.h" -#include "zvision/clock.h" namespace ZVision { diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp index 0d290a661a..a095d3fa6a 100644 --- a/engines/zvision/console.cpp +++ b/engines/zvision/console.cpp @@ -22,13 +22,8 @@ #include "common/scummsys.h" -#include "common/system.h" -#include "gui/debugger.h" -#include "common/file.h" -#include "common/bufferedstream.h" -#include "audio/mixer.h" - #include "zvision/console.h" + #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" @@ -38,6 +33,14 @@ #include "zvision/utility.h" #include "zvision/cursor.h" +#include "common/system.h" +#include "common/file.h" +#include "common/bufferedstream.h" + +#include "gui/debugger.h" + +#include "audio/mixer.h" + namespace ZVision { diff --git a/engines/zvision/control.cpp b/engines/zvision/control.cpp index ad0a4c5013..bcbdabc143 100644 --- a/engines/zvision/control.cpp +++ b/engines/zvision/control.cpp @@ -22,13 +22,14 @@ #include "common/scummsys.h" -#include "common/stream.h" - #include "zvision/control.h" + #include "zvision/zvision.h" #include "zvision/render_manager.h" #include "zvision/utility.h" +#include "common/stream.h" + namespace ZVision { diff --git a/engines/zvision/control.h b/engines/zvision/control.h index a279381298..770c540a12 100644 --- a/engines/zvision/control.h +++ b/engines/zvision/control.h @@ -23,8 +23,6 @@ #ifndef ZVISION_CONTROL_H #define ZVISION_CONTROL_H -#include "common/types.h" - #include "common/keyboard.h" diff --git a/engines/zvision/cursor.cpp b/engines/zvision/cursor.cpp index bb0700cebe..9023d97e0d 100644 --- a/engines/zvision/cursor.cpp +++ b/engines/zvision/cursor.cpp @@ -22,11 +22,11 @@ #include "common/scummsys.h" +#include "zvision/cursor.h" + #include "common/str.h" #include "common/file.h" -#include "zvision/cursor.h" - namespace ZVision { diff --git a/engines/zvision/cursor.h b/engines/zvision/cursor.h index 805a8e7982..18ac28ce8b 100644 --- a/engines/zvision/cursor.h +++ b/engines/zvision/cursor.h @@ -23,10 +23,9 @@ #ifndef ZVISION_CURSOR_H #define ZVISION_CURSOR_H -#include "common/types.h" - #include "graphics/surface.h" + namespace Common { class String; } diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index 0f524bf807..595e7946dd 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -22,13 +22,15 @@ #include "common/scummsys.h" +#include "zvision/cursor_manager.h" + +#include "zvision/zvision.h" + #include "common/system.h" + #include "graphics/pixelformat.h" #include "graphics/cursorman.h" -#include "zvision/zvision.h" -#include "zvision/cursor_manager.h" - namespace ZVision { diff --git a/engines/zvision/cursor_manager.h b/engines/zvision/cursor_manager.h index 1c09620b7e..0a369aaf9e 100644 --- a/engines/zvision/cursor_manager.h +++ b/engines/zvision/cursor_manager.h @@ -23,10 +23,10 @@ #ifndef ZVISION_CURSOR_MANAGER_H #define ZVISION_CURSOR_MANAGER_H -#include "common/types.h" - #include "zvision/cursor.h" +#include "common/str.h" + namespace Graphics { struct PixelFormat; diff --git a/engines/zvision/detection.cpp b/engines/zvision/detection.cpp index 28b7134fae..06e921dfa8 100644 --- a/engines/zvision/detection.cpp +++ b/engines/zvision/detection.cpp @@ -21,16 +21,18 @@ * */ +#include "common/scummsys.h" + #include "base/plugins.h" +#include "zvision/zvision.h" +#include "zvision/detection.h" + #include "common/translation.h" #include "common/savefile.h" #include "common/str-array.h" #include "common/system.h" -#include "zvision/zvision.h" -#include "zvision/detection.h" - namespace ZVision { diff --git a/engines/zvision/detection.h b/engines/zvision/detection.h index f9acb4d144..34417601e8 100644 --- a/engines/zvision/detection.h +++ b/engines/zvision/detection.h @@ -25,6 +25,7 @@ #include "engines/advancedDetector.h" + namespace ZVision { enum ZVisionGameId { diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index c1b894c290..1103dc3000 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -23,17 +23,20 @@ #include "common/scummsys.h" #include "zvision/zvision.h" -#include "zvision/console.h" -#include "common/events.h" -#include "engines/util.h" -#include "common/system.h" -#include "common/rational.h" +#include "zvision/console.h" #include "zvision/cursor_manager.h" #include "zvision/render_manager.h" #include "zvision/script_manager.h" #include "zvision/rlf_animation.h" +#include "common/events.h" +#include "common/system.h" +#include "common/rational.h" + +#include "engines/util.h" + + namespace ZVision { void ZVision::processEvents() { diff --git a/engines/zvision/input_control.cpp b/engines/zvision/input_control.cpp index ab4cc6bd62..a445e1aae5 100644 --- a/engines/zvision/input_control.cpp +++ b/engines/zvision/input_control.cpp @@ -22,17 +22,18 @@ #include "common/scummsys.h" -#include "common/str.h" -#include "common/stream.h" -#include "common/rect.h" - #include "zvision/input_control.h" + #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/string_manager.h" #include "zvision/render_manager.h" #include "zvision/utility.h" +#include "common/str.h" +#include "common/stream.h" +#include "common/rect.h" + namespace ZVision { diff --git a/engines/zvision/input_control.h b/engines/zvision/input_control.h index 33a1b34313..aab2c991dc 100644 --- a/engines/zvision/input_control.h +++ b/engines/zvision/input_control.h @@ -23,11 +23,11 @@ #ifndef ZVISION_INPUT_CONTROL_H #define ZVISION_INPUT_CONTROL_H -#include "common/types.h" - #include "zvision/control.h" #include "zvision/string_manager.h" +#include "common/rect.h" + namespace ZVision { diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp index 4e04ed4263..79049b8fcb 100644 --- a/engines/zvision/lever_control.cpp +++ b/engines/zvision/lever_control.cpp @@ -22,14 +22,8 @@ #include "common/scummsys.h" -#include "common/stream.h" -#include "common/file.h" -#include "common/tokenizer.h" -#include "common/system.h" - -#include "graphics/surface.h" - #include "zvision/lever_control.h" + #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/render_manager.h" @@ -38,6 +32,14 @@ #include "zvision/zork_avi_decoder.h" #include "zvision/utility.h" +#include "common/stream.h" +#include "common/file.h" +#include "common/tokenizer.h" +#include "common/system.h" + +#include "graphics/surface.h" + + namespace ZVision { LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h index 80fda4f5fd..8ef8f06fec 100644 --- a/engines/zvision/lever_control.h +++ b/engines/zvision/lever_control.h @@ -23,13 +23,11 @@ #ifndef ZVISION_LEVER_CONTROL_H #define ZVISION_LEVER_CONTROL_H -#include "common/types.h" +#include "zvision/control.h" #include "common/list.h" #include "common/rect.h" -#include "zvision/control.h" - namespace ZVision { diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index a90f40b3e4..bbbda6f526 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -24,6 +24,7 @@ #include "zvision/lzss_read_stream.h" + namespace ZVision { LzssReadStream::LzssReadStream(Common::SeekableReadStream *source) diff --git a/engines/zvision/lzss_read_stream.h b/engines/zvision/lzss_read_stream.h index 25a8b67222..f6b1eb1a65 100644 --- a/engines/zvision/lzss_read_stream.h +++ b/engines/zvision/lzss_read_stream.h @@ -23,10 +23,10 @@ #ifndef ZVISION_LZSS_STREAM_H #define ZVISION_LZSS_STREAM_H -#include "common/types.h" #include "common/stream.h" #include "common/array.h" + namespace Common { class SeekableReadStream; } diff --git a/engines/zvision/push_toggle_control.cpp b/engines/zvision/push_toggle_control.cpp index f4c0bc987e..689311ba5b 100644 --- a/engines/zvision/push_toggle_control.cpp +++ b/engines/zvision/push_toggle_control.cpp @@ -22,14 +22,16 @@ #include "common/scummsys.h" -#include "common/stream.h" - #include "zvision/push_toggle_control.h" + #include "zvision/zvision.h" #include "zvision/script_manager.h" #include "zvision/cursor_manager.h" #include "zvision/utility.h" +#include "common/stream.h" + + namespace ZVision { PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) diff --git a/engines/zvision/push_toggle_control.h b/engines/zvision/push_toggle_control.h index 8ab6f619bb..2a407cada9 100644 --- a/engines/zvision/push_toggle_control.h +++ b/engines/zvision/push_toggle_control.h @@ -23,12 +23,10 @@ #ifndef ZVISION_PUSH_TOGGLE_CONTROL_H #define ZVISION_PUSH_TOGGLE_CONTROL_H -#include "common/types.h" +#include "zvision/control.h" #include "common/rect.h" -#include "zvision/control.h" - namespace ZVision { diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 97b839f9a7..1e730365dc 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -23,11 +23,11 @@ #ifndef ZVISION_PUZZLE_H #define ZVISION_PUZZLE_H +#include "zvision/actions.h" #include "common/list.h" #include "common/ptr.h" -#include "zvision/actions.h" namespace ZVision { diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index b8286266da..a8ceabcd74 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -22,15 +22,18 @@ #include "common/scummsys.h" +#include "zvision/render_manager.h" + +#include "zvision/lzss_read_stream.h" + #include "common/file.h" #include "common/system.h" #include "common/stream.h" #include "engines/util.h" + #include "graphics/decoders/tga.h" -#include "zvision/render_manager.h" -#include "zvision/lzss_read_stream.h" namespace ZVision { diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 71f4807c29..64d36f5c9d 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -23,14 +23,14 @@ #ifndef ZVISION_RENDER_MANAGER_H #define ZVISION_RENDER_MANAGER_H -#include "common/types.h" +#include "zvision/render_table.h" +#include "zvision/truetype_font.h" + #include "common/rect.h" #include "common/hashmap.h" #include "graphics/surface.h" -#include "zvision/render_table.h" -#include "zvision/truetype_font.h" class OSystem; diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index ce247e23fd..f4437101db 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -22,11 +22,13 @@ #include "common/scummsys.h" -#include "graphics/colormasks.h" - #include "zvision/render_table.h" + #include "zvision/vector2.h" +#include "graphics/colormasks.h" + + namespace ZVision { RenderTable::RenderTable(uint numColumns, uint numRows) diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 7c8e7d6a2d..b188b1492f 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -23,11 +23,10 @@ #ifndef ZVISION_RENDER_TABLE_H #define ZVISION_RENDER_TABLE_H -#include "common/types.h" -#include "common/rect.h" - #include "zvision/vector2.h" +#include "common/rect.h" + namespace ZVision { class RenderTable { diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index f0d5ac5284..94e48d3609 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -22,6 +22,8 @@ #include "common/scummsys.h" +#include "zvision/rlf_animation.h" + #include "common/str.h" #include "common/file.h" #include "common/textconsole.h" @@ -30,8 +32,6 @@ #include "graphics/colormasks.h" -#include "zvision/rlf_animation.h" - namespace ZVision { diff --git a/engines/zvision/rlf_animation.h b/engines/zvision/rlf_animation.h index 53247eb4ab..fe5b0d68b4 100644 --- a/engines/zvision/rlf_animation.h +++ b/engines/zvision/rlf_animation.h @@ -23,9 +23,8 @@ #ifndef ZVISION_RLF_ANIMATION_H #define ZVISION_RLF_ANIMATION_H -#include "common/types.h" - #include "common/file.h" + #include "graphics/surface.h" diff --git a/engines/zvision/save_manager.cpp b/engines/zvision/save_manager.cpp index 9cc664ce5a..c3deadd703 100644 --- a/engines/zvision/save_manager.cpp +++ b/engines/zvision/save_manager.cpp @@ -22,6 +22,12 @@ #include "common/scummsys.h" +#include "zvision/save_manager.h" + +#include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/render_manager.h" + #include "common/system.h" #include "graphics/surface.h" @@ -29,11 +35,6 @@ #include "gui/message.h" -#include "zvision/save_manager.h" -#include "zvision/zvision.h" -#include "zvision/script_manager.h" -#include "zvision/render_manager.h" - namespace ZVision { diff --git a/engines/zvision/save_manager.h b/engines/zvision/save_manager.h index 6445f10caf..b4770e68b2 100644 --- a/engines/zvision/save_manager.h +++ b/engines/zvision/save_manager.h @@ -23,14 +23,16 @@ #ifndef ZVISION_SAVE_MANAGER_H #define ZVISION_SAVE_MANAGER_H -#include "common/types.h" - #include "common/savefile.h" namespace Common { class String; } +namespace Graphics { +struct Surface; +} + namespace ZVision { class ZVision; diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index fa89f756e4..e90408cf0d 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -23,6 +23,7 @@ #include "common/scummsys.h" #include "zvision/script_manager.h" + #include "zvision/utility.h" #include "zvision/puzzle.h" #include "zvision/actions.h" @@ -33,6 +34,7 @@ #include "common/file.h" #include "common/tokenizer.h" + namespace ZVision { void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) { diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 31983a684e..f3e14e6f5b 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -22,19 +22,21 @@ #include "common/scummsys.h" -#include "common/algorithm.h" -#include "common/hashmap.h" -#include "common/debug.h" -#include "common/stream.h" +#include "zvision/script_manager.h" #include "zvision/zvision.h" -#include "zvision/script_manager.h" #include "zvision/render_manager.h" #include "zvision/cursor_manager.h" #include "zvision/save_manager.h" #include "zvision/actions.h" #include "zvision/utility.h" +#include "common/algorithm.h" +#include "common/hashmap.h" +#include "common/debug.h" +#include "common/stream.h" + + namespace ZVision { ScriptManager::ScriptManager(ZVision *engine) diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 349f259198..6276095e12 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -23,11 +23,12 @@ #ifndef ZVISION_SCRIPT_MANAGER_H #define ZVISION_SCRIPT_MANAGER_H +#include "zvision/puzzle.h" +#include "zvision/control.h" + #include "common/hashmap.h" #include "common/queue.h" -#include "zvision/puzzle.h" -#include "zvision/control.h" namespace Common { class String; diff --git a/engines/zvision/single_value_container.cpp b/engines/zvision/single_value_container.cpp index 0fd758a85e..837bd8d7fc 100644 --- a/engines/zvision/single_value_container.cpp +++ b/engines/zvision/single_value_container.cpp @@ -22,10 +22,11 @@ #include "common/scummsys.h" +#include "zvision/single_value_container.h" + #include "common/textconsole.h" #include "common/str.h" -#include "zvision/single_value_container.h" namespace ZVision { diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 3c9a3c6f0c..fde99c02a1 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -22,6 +22,10 @@ #include "common/scummsys.h" +#include "zvision/string_manager.h" + +#include "zvision/truetype_font.h" + #include "common/file.h" #include "common/tokenizer.h" #include "common/debug.h" @@ -29,9 +33,6 @@ #include "graphics/fontman.h" #include "graphics/colormasks.h" -#include "zvision/string_manager.h" -#include "zvision/truetype_font.h" - namespace ZVision { diff --git a/engines/zvision/string_manager.h b/engines/zvision/string_manager.h index 74d13cd994..9cfed5261b 100644 --- a/engines/zvision/string_manager.h +++ b/engines/zvision/string_manager.h @@ -24,8 +24,6 @@ #ifndef ZVISION_STRING_MANAGER_H #define ZVISION_STRING_MANAGER_H -#include "common/types.h" - #include "zvision/detection.h" #include "zvision/truetype_font.h" diff --git a/engines/zvision/timer_node.cpp b/engines/zvision/timer_node.cpp index 81468dbb0b..55dfa51dfe 100644 --- a/engines/zvision/timer_node.cpp +++ b/engines/zvision/timer_node.cpp @@ -22,12 +22,14 @@ #include "common/scummsys.h" -#include "common/stream.h" - #include "zvision/timer_node.h" + #include "zvision/zvision.h" #include "zvision/script_manager.h" +#include "common/stream.h" + + namespace ZVision { TimerNode::TimerNode(ZVision *engine, uint32 key, uint timeInSeconds) diff --git a/engines/zvision/timer_node.h b/engines/zvision/timer_node.h index 4bc8397ff0..32dca71548 100644 --- a/engines/zvision/timer_node.h +++ b/engines/zvision/timer_node.h @@ -23,8 +23,6 @@ #ifndef ZVISION_TIMER_NODE_H #define ZVISION_TIMER_NODE_H -#include "common/types.h" - #include "zvision/control.h" namespace ZVision { diff --git a/engines/zvision/truetype_font.cpp b/engines/zvision/truetype_font.cpp index 80d0d6bddb..8d6aaca51e 100644 --- a/engines/zvision/truetype_font.cpp +++ b/engines/zvision/truetype_font.cpp @@ -22,6 +22,11 @@ #include "common/scummsys.h" +#include "zvision/truetype_font.h" + +#include "zvision/zvision.h" +#include "zvision/render_manager.h" + #include "common/debug.h" #include "common/file.h" #include "common/system.h" @@ -30,10 +35,6 @@ #include "graphics/fonts/ttf.h" #include "graphics/surface.h" -#include "zvision/truetype_font.h" -#include "zvision/zvision.h" -#include "zvision/render_manager.h" - namespace ZVision { diff --git a/engines/zvision/truetype_font.h b/engines/zvision/truetype_font.h index c7475d1adb..4f2ff864a8 100644 --- a/engines/zvision/truetype_font.h +++ b/engines/zvision/truetype_font.h @@ -25,11 +25,10 @@ #ifndef ZVISION_TRUETYPE_FONT_H #define ZVISION_TRUETYPE_FONT_H -#include "common/types.h" - #include "graphics/font.h" #include "graphics/pixelformat.h" + namespace Graphics { struct Surface; } diff --git a/engines/zvision/utility.cpp b/engines/zvision/utility.cpp index fb4fe22ff8..d973cb2f4c 100644 --- a/engines/zvision/utility.cpp +++ b/engines/zvision/utility.cpp @@ -22,13 +22,15 @@ #include "common/scummsys.h" -#include "common/tokenizer.h" -#include "common/file.h" - #include "zvision/utility.h" + #include "zvision/zvision.h" #include "zvision/zork_raw.h" +#include "common/tokenizer.h" +#include "common/file.h" + + namespace ZVision { void writeFileContentsToFile(const Common::String &sourceFile, const Common::String &destFile) { diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 14077080f5..4aceec6e4f 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -26,6 +26,7 @@ #include "common/array.h" + namespace Common { class String; } diff --git a/engines/zvision/vector2.h b/engines/zvision/vector2.h index 575915c87d..9616a43218 100644 --- a/engines/zvision/vector2.h +++ b/engines/zvision/vector2.h @@ -25,6 +25,9 @@ #include "common/scummsys.h" +#include "common/util.h" + + namespace ZVision { /** diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 2fe4d231ef..cd11618e67 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -22,14 +22,18 @@ #include "common/scummsys.h" +#include "zvision/zvision.h" + +#include "zvision/clock.h" +#include "zvision/render_manager.h" + #include "common/system.h" + #include "video/video_decoder.h" + #include "engines/util.h" -#include "graphics/surface.h" -#include "zvision/clock.h" -#include "zvision/render_manager.h" -#include "zvision/zvision.h" +#include "graphics/surface.h" namespace ZVision { diff --git a/engines/zvision/zfs_archive.cpp b/engines/zvision/zfs_archive.cpp index b0444fa511..24cff27fc4 100644 --- a/engines/zvision/zfs_archive.cpp +++ b/engines/zvision/zfs_archive.cpp @@ -22,13 +22,12 @@ #include "common/scummsys.h" -#include "common/hashmap.h" +#include "zvision/zfs_archive.h" + #include "common/memstream.h" #include "common/debug.h" #include "common/file.h" -#include "zvision/zfs_archive.h" - namespace ZVision { ZfsArchive::ZfsArchive(const Common::String &fileName) : _fileName(fileName) { diff --git a/engines/zvision/zfs_archive.h b/engines/zvision/zfs_archive.h index 3bf492578c..d7b45e4b47 100644 --- a/engines/zvision/zfs_archive.h +++ b/engines/zvision/zfs_archive.h @@ -25,6 +25,7 @@ #include "common/archive.h" #include "common/hashmap.h" +#include "common/hash-str.h" namespace Common { diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp index d9b9511175..a614f77bb7 100644 --- a/engines/zvision/zork_avi_decoder.cpp +++ b/engines/zvision/zork_avi_decoder.cpp @@ -23,11 +23,14 @@ #include "common/scummsys.h" +#include "zvision/zork_avi_decoder.h" + +#include "zvision/zork_raw.h" + #include "common/stream.h" + #include "audio/audiostream.h" -#include "zvision/zork_avi_decoder.h" -#include "zvision/zork_raw.h" namespace ZVision { diff --git a/engines/zvision/zork_avi_decoder.h b/engines/zvision/zork_avi_decoder.h index 1ce2508828..ec2be1bb13 100644 --- a/engines/zvision/zork_avi_decoder.h +++ b/engines/zvision/zork_avi_decoder.h @@ -26,6 +26,7 @@ #include "video/avi_decoder.h" + namespace ZVision { class ZorkAVIDecoder : public Video::AVIDecoder { diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp index 55ad2076e0..55493da9b3 100644 --- a/engines/zvision/zork_raw.cpp +++ b/engines/zvision/zork_raw.cpp @@ -22,19 +22,22 @@ #include "common/scummsys.h" +#include "zvision/zork_raw.h" + +#include "zvision/zvision.h" +#include "zvision/detection.h" +#include "zvision/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 "audio/audiostream.h" #include "audio/decoders/raw.h" -#include "zvision/zork_raw.h" -#include "zvision/zvision.h" -#include "zvision/detection.h" -#include "zvision/utility.h" namespace ZVision { diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h index 51248e341a..481ea79f2d 100644 --- a/engines/zvision/zork_raw.h +++ b/engines/zvision/zork_raw.h @@ -23,9 +23,9 @@ #ifndef ZVISION_ZORK_RAW_H #define ZVISION_ZORK_RAW_H -#include "common/types.h" #include "audio/audiostream.h" + namespace Common { class SeekableReadStream; } diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 6cdc144424..6d8ae6d5a7 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -22,6 +22,17 @@ #include "common/scummsys.h" +#include "zvision/zvision.h" + +#include "zvision/console.h" +#include "zvision/script_manager.h" +#include "zvision/render_manager.h" +#include "zvision/cursor_manager.h" +#include "zvision/save_manager.h" +#include "zvision/string_manager.h" +#include "zvision/zfs_archive.h" +#include "zvision/detection.h" + #include "common/config-manager.h" #include "common/debug.h" #include "common/debug-channels.h" @@ -33,18 +44,7 @@ #include "engines/util.h" #include "audio/mixer.h" - -#include "zvision/zvision.h" -#include "zvision/console.h" -#include "zvision/script_manager.h" -#include "zvision/render_manager.h" -#include "zvision/cursor_manager.h" -#include "zvision/save_manager.h" -#include "zvision/string_manager.h" -#include "zvision/zfs_archive.h" -#include "zvision/detection.h" -#include "zvision/utility.h" namespace ZVision { diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 13bdb3c755..84784d9a89 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -24,6 +24,9 @@ #ifndef ZVISION_ZVISION_H #define ZVISION_ZVISION_H +#include "zvision/detection.h" +#include "zvision/clock.h" + #include "common/random.h" #include "common/events.h" @@ -31,9 +34,6 @@ #include "graphics/pixelformat.h" -#include "zvision/detection.h" -#include "zvision/clock.h" - #include "gui/debugger.h" -- cgit v1.2.3 From 23a1a1a70fd0481f17e49631e0884d7027d21528 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 1 Oct 2013 20:08:57 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/utility.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h index 4aceec6e4f..fb571f3fe8 100644 --- a/engines/zvision/utility.h +++ b/engines/zvision/utility.h @@ -69,10 +69,10 @@ void dumpEveryResultAction(const Common::String &destFile); template void removeDuplicateEntries(Common::Array &container) { // Length of modified array - int newLength = 1; - int j; + uint newLength = 1; + uint j; - for(int i = 1; i < container.size(); i++) { + for(uint i = 1; i < container.size(); i++) { for(j = 0; j < newLength; j++) { if (container[i] == container[j]) { break; -- cgit v1.2.3 From 8a69bcfe97716ae8f0098fd62231ac13717f1484 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Wed, 2 Oct 2013 14:51:03 -0500 Subject: ZVISION: Add typedefs to shorten long type names --- engines/zvision/render_manager.cpp | 4 ++-- engines/zvision/render_manager.h | 4 +++- engines/zvision/script_manager.cpp | 48 +++++++++++++++++++------------------- engines/zvision/script_manager.h | 15 ++++++++---- 4 files changed, 39 insertions(+), 32 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index a8ceabcd74..af8ca7fd64 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -61,7 +61,7 @@ RenderManager::~RenderManager() { _currentBackground.free(); _backBuffer.free(); - for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); ++iter) { + for (AlphaEntryMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); ++iter) { iter->_value.data->free(); delete iter->_value.data; } @@ -121,7 +121,7 @@ void RenderManager::renderBackbufferToScreen() { void RenderManager::processAlphaEntries() { // TODO: Add dirty rectangling support. AKA only draw an entry if the _backbufferDirtyRect intersects/contains the entry Rect - for (Common::HashMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); ++iter) { + for (AlphaEntryMap::iterator iter = _alphaDataEntries.begin(); iter != _alphaDataEntries.end(); ++iter) { uint32 destOffset = 0; uint32 sourceOffset = 0; uint16 *backbufferPtr = (uint16 *)_backBuffer.getBasePtr(iter->_value.destX + _workingWindow.left, iter->_value.destY + _workingWindow.top); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 64d36f5c9d..111bf6276c 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -60,6 +60,8 @@ private: uint16 height; }; + typedef Common::HashMap AlphaEntryMap; + private: OSystem *_system; const Graphics::PixelFormat _pixelFormat; @@ -71,7 +73,7 @@ private: // before actually being blitted to the screen Graphics::Surface _backBuffer; // A list of Alpha Entries that need to be blitted to the backbuffer - Common::HashMap _alphaDataEntries; + AlphaEntryMap _alphaDataEntries; // A rectangle representing the portion of the working window where the pixels have been changed since last frame Common::Rect _workingWindowDirtyRect; diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index f3e14e6f5b..b33ca4c515 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -45,13 +45,13 @@ ScriptManager::ScriptManager(ZVision *engine) } ScriptManager::~ScriptManager() { - for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { + for (PuzzleList::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { delete (*iter); } - for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) { + for (PuzzleList::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) { delete (*iter); } - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { delete (*iter); } } @@ -68,7 +68,7 @@ void ScriptManager::update(uint deltaTimeMillis) { void ScriptManager::createReferenceTable() { // Iterate through each local Puzzle - for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); ++activePuzzleIter) { + for (PuzzleList::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); ++activePuzzleIter) { Puzzle *puzzlePtr = (*activePuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle @@ -85,7 +85,7 @@ void ScriptManager::createReferenceTable() { } // Iterate through each global Puzzle - for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); ++globalPuzzleIter) { + for (PuzzleList::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); ++globalPuzzleIter) { Puzzle *puzzlePtr = (*globalPuzzleIter); // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle @@ -102,14 +102,14 @@ void ScriptManager::createReferenceTable() { } // Remove duplicate entries - for (Common::HashMap >::iterator referenceTableIter = _referenceTable.begin(); referenceTableIter != _referenceTable.end(); ++referenceTableIter) { + for (PuzzleMap::iterator referenceTableIter = _referenceTable.begin(); referenceTableIter != _referenceTable.end(); ++referenceTableIter) { removeDuplicateEntries(referenceTableIter->_value); } } void ScriptManager::updateNodes(uint deltaTimeMillis) { // If process() returns true, it means the node can be deleted - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end();) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end();) { if ((*iter)->process(deltaTimeMillis)) { delete (*iter); // Remove the node @@ -232,7 +232,7 @@ void ScriptManager::addControl(Control *control) { } Control *ScriptManager::getControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { return (*iter); } @@ -242,7 +242,7 @@ Control *ScriptManager::getControl(uint32 key) { } void ScriptManager::enableControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { (*iter)->enable(); break; @@ -251,7 +251,7 @@ void ScriptManager::enableControl(uint32 key) { } void ScriptManager::disableControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { (*iter)->disable(); break; @@ -260,7 +260,7 @@ void ScriptManager::disableControl(uint32 key) { } void ScriptManager::focusControl(uint32 key) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { uint32 controlKey = (*iter)->getKey(); if (controlKey == key) { @@ -274,20 +274,20 @@ void ScriptManager::focusControl(uint32 key) { } void ScriptManager::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onMouseDown(screenSpacePos, backgroundImageSpacePos); } } void ScriptManager::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onMouseUp(screenSpacePos, backgroundImageSpacePos); } } bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { bool cursorWasChanged = false; - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { cursorWasChanged = cursorWasChanged || (*iter)->onMouseMove(screenSpacePos, backgroundImageSpacePos); } @@ -295,13 +295,13 @@ bool ScriptManager::onMouseMove(const Common::Point &screenSpacePos, const Commo } void ScriptManager::onKeyDown(Common::KeyState keyState) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onKeyDown(keyState); } } void ScriptManager::onKeyUp(Common::KeyState keyState) { - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->onKeyUp(keyState); } } @@ -316,11 +316,11 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, // Clear all the containers _referenceTable.clear(); _puzzlesToCheck.clear(); - for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { + for (PuzzleList::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { delete (*iter); } _activePuzzles.clear(); - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { delete (*iter); } _activeControls.clear(); @@ -345,12 +345,12 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, _engine->getRenderManager()->setBackgroundPosition(offset); // Enable all the controls - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->enable(); } // Add all the local puzzles to the queue to be checked - for (Common::List::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { + for (PuzzleList::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { // Reset any Puzzles that have the flag ONCE_PER_INST if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { setStateValue((*iter)->key, 0); @@ -360,7 +360,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, } // Add all the global puzzles to the queue to be checked - for (Common::List::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) { + for (PuzzleList::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) { // Reset any Puzzles that have the flag ONCE_PER_INST if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { setStateValue((*iter)->key, 0); @@ -410,14 +410,14 @@ void ScriptManager::serializeControls(Common::WriteStream *stream) { // Count how many controls need to save their data // Because WriteStream isn't seekable uint32 numberOfControlsNeedingSerialization = 0; - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->needsSerialization()) { numberOfControlsNeedingSerialization++; } } stream->writeUint32LE(numberOfControlsNeedingSerialization); - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { (*iter)->serialize(stream); } } @@ -427,7 +427,7 @@ void ScriptManager::deserializeControls(Common::SeekableReadStream *stream) { for (uint32 i = 0; i < numberOfControls; ++i) { uint32 key = stream->readUint32LE(); - for (Common::List::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { + for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { if ((*iter)->getKey() == key) { (*iter)->deserialize(stream); break; diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 6276095e12..c44c836171 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -49,6 +49,11 @@ struct Location { uint32 offset; }; +typedef Common::HashMap > PuzzleMap; +typedef Common::List PuzzleList; +typedef Common::Queue PuzzleQueue; +typedef Common::List ControlList; + class ScriptManager { public: ScriptManager(ZVision *engine); @@ -63,15 +68,15 @@ private: */ Common::HashMap _globalState; /** References _globalState keys to Puzzles */ - Common::HashMap > _referenceTable; + PuzzleMap _referenceTable; /** Holds the Puzzles that should be checked this frame */ - Common::Queue _puzzlesToCheck; + PuzzleQueue _puzzlesToCheck; /** Holds the currently active puzzles */ - Common::List _activePuzzles; + PuzzleList _activePuzzles; /** Holds the global puzzles */ - Common::List_globalPuzzles; + PuzzleList _globalPuzzles; /** Holds the currently active controls */ - Common::List _activeControls; + ControlList _activeControls; Location _currentLocation; -- cgit v1.2.3 From 39a8243c696f3883f5d1609b1dc333dfae2264ed Mon Sep 17 00:00:00 2001 From: RichieSams Date: Wed, 2 Oct 2013 14:56:38 -0500 Subject: ZVISION: Remove Vector2 class Originally, the render table needed int32 (x, y) coords, so I created a copy of Common::Point that used int32. After some code changes, the render table reverted to int16 coords. Therefore, this class is unnessessary since Common::Point uses int16 coords. --- engines/zvision/render_table.cpp | 4 +- engines/zvision/render_table.h | 5 +-- engines/zvision/vector2.h | 82 ---------------------------------------- 3 files changed, 4 insertions(+), 87 deletions(-) delete mode 100644 engines/zvision/vector2.h (limited to 'engines/zvision') diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index f4437101db..b6a6a3d2bb 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -24,7 +24,7 @@ #include "zvision/render_table.h" -#include "zvision/vector2.h" +#include "common/rect.h" #include "graphics/colormasks.h" @@ -37,7 +37,7 @@ RenderTable::RenderTable(uint numColumns, uint numRows) _renderState(FLAT) { assert(numRows != 0 && numColumns != 0); - _internalBuffer = new Vector2[numRows * numColumns]; + _internalBuffer = new Common::Point[numRows * numColumns]; } RenderTable::~RenderTable() { diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index b188b1492f..898091193a 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -23,10 +23,9 @@ #ifndef ZVISION_RENDER_TABLE_H #define ZVISION_RENDER_TABLE_H -#include "zvision/vector2.h" - #include "common/rect.h" + namespace ZVision { class RenderTable { @@ -43,7 +42,7 @@ public: private: uint _numColumns, _numRows; - Vector2 *_internalBuffer; + Common::Point *_internalBuffer; RenderState _renderState; struct { diff --git a/engines/zvision/vector2.h b/engines/zvision/vector2.h deleted file mode 100644 index 9616a43218..0000000000 --- a/engines/zvision/vector2.h +++ /dev/null @@ -1,82 +0,0 @@ -/* 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 ZVISION_VECTOR2_H -#define ZVISION_VECTOR2_H - -#include "common/scummsys.h" - -#include "common/util.h" - - -namespace ZVision { - -/** - * Simple class for handling both 2D position and size. - */ -class Vector2 { -public: - int16 x; ///< The horizontal part of the point - int16 y; ///< The vertical part of the point - -public: - Vector2() : x(0), y(0) {} - Vector2(int16 x1, int16 y1) : x(x1), y(y1) {} - -public: - bool operator==(const Vector2 &p) const { return x == p.x && y == p.y; } - bool operator!=(const Vector2 &p) const { return x != p.x || y != p.y; } - Vector2 operator+(const Vector2 &delta) const { return Vector2(x + delta.x, y + delta.y); } - Vector2 operator-(const Vector2 &delta) const { return Vector2(x - delta.x, y - delta.y); } - - void operator+=(const Vector2 &delta) { - x += delta.x; - y += delta.y; - } - - void operator-=(const Vector2 &delta) { - x -= delta.x; - y -= delta.y; - } - - /** - * Return the square of the distance between this point and the point p. - * - * @param p the other point - * @return the distance between this and p - */ - uint sqrDist(const Vector2 &p) const { - int diffx = ABS(p.x - x); - if (diffx >= 0x1000) - return 0xFFFFFF; - - int diffy = ABS(p.y - y); - if (diffy >= 0x1000) - return 0xFFFFFF; - - return uint(diffx * diffx + diffy * diffy); - } -}; - -} // End of namespace ZVision - -#endif -- cgit v1.2.3 From 2887e8295d707df99dc21c5e04eecc76953b4d41 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 4 Oct 2013 09:08:40 -0500 Subject: ZVISION: Fix nested template formatting --- engines/zvision/rlf_animation.cpp | 12 ++++++------ engines/zvision/string_manager.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 94e48d3609..8981a6983c 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -246,8 +246,8 @@ void RlfAnimation::decodeMaskedRunLengthEncoding(int8 *source, int8 *dest, uint3 } byte r, g, b; - Graphics::colorToRGB>(READ_LE_UINT16(source + sourceOffset), r, g, b); - uint16 destColor = Graphics::RGBToColor>(r, g, b); + Graphics::colorToRGB >(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 destColor = Graphics::RGBToColor >(r, g, b); WRITE_UINT16(dest + destOffset, destColor); sourceOffset += 2; @@ -292,8 +292,8 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 } byte r, g, b; - Graphics::colorToRGB>(READ_LE_UINT16(source + sourceOffset), r, g, b); - uint16 destColor = Graphics::RGBToColor>(r, g, b); + Graphics::colorToRGB >(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 destColor = Graphics::RGBToColor >(r, g, b); WRITE_UINT16(dest + destOffset, destColor); sourceOffset += 2; @@ -309,8 +309,8 @@ void RlfAnimation::decodeSimpleRunLengthEncoding(int8 *source, int8 *dest, uint3 } byte r, g, b; - Graphics::colorToRGB>(READ_LE_UINT16(source + sourceOffset), r, g, b); - uint16 sampleColor = Graphics::RGBToColor>(r, g, b); + Graphics::colorToRGB >(READ_LE_UINT16(source + sourceOffset), r, g, b); + uint16 sampleColor = Graphics::RGBToColor >(r, g, b); sourceOffset += 2; numberOfSamples += 2; diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index fde99c02a1..ab42f3d3e0 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -206,7 +206,7 @@ void StringManager::parseTag(const Common::String &tagString, uint lineNumber) { } fragment.style.align = align; - fragment.style.color = Graphics::ARGBToColor>(0, red, green, blue); + fragment.style.color = Graphics::ARGBToColor >(0, red, green, blue); _inGameText[lineNumber].fragments.push_back(fragment); _lastStyle = fragment.style; -- cgit v1.2.3 From 260ba64bdaf76cc201c57284b99890fe3a9422ad Mon Sep 17 00:00:00 2001 From: RichieSams Date: Fri, 4 Oct 2013 14:13:21 -0500 Subject: ZVISION: Fix signed/unsigned mismatch --- engines/zvision/rlf_animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/zvision') diff --git a/engines/zvision/rlf_animation.cpp b/engines/zvision/rlf_animation.cpp index 8981a6983c..5f1d41daae 100644 --- a/engines/zvision/rlf_animation.cpp +++ b/engines/zvision/rlf_animation.cpp @@ -164,7 +164,7 @@ void RlfAnimation::seekToFrame(int frameNumber) { int closestFrame = _currentFrame; int distance = (int)frameNumber - _currentFrame; - for (int i = 0; i < _completeFrames.size(); ++i) { + for (uint i = 0; i < _completeFrames.size(); ++i) { int newDistance = (int)frameNumber - (int)(_completeFrames[i]); if (newDistance > 0 && (closestFrame == -1 || newDistance < distance)) { closestFrame = _completeFrames[i]; -- cgit v1.2.3