aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEugene Sandulenko2018-05-04 10:13:34 +0200
committerEugene Sandulenko2018-05-05 23:17:34 +0200
commitfaf579c48ffe7dfb8f49130cf30b47f27156acc3 (patch)
tree317d28609a9434e46fa97c56761479b24f0bd74d /engines
parent132f77fd1629158e27c2487ef94cc9b6cb1c0150 (diff)
downloadscummvm-rg350-faf579c48ffe7dfb8f49130cf30b47f27156acc3.tar.gz
scummvm-rg350-faf579c48ffe7dfb8f49130cf30b47f27156acc3.tar.bz2
scummvm-rg350-faf579c48ffe7dfb8f49130cf30b47f27156acc3.zip
PRINCE: Move resource loading methods to separate file
Diffstat (limited to 'engines')
-rw-r--r--engines/prince/module.mk1
-rw-r--r--engines/prince/prince.cpp287
-rw-r--r--engines/prince/resources.cpp321
3 files changed, 322 insertions, 287 deletions
diff --git a/engines/prince/module.mk b/engines/prince/module.mk
index 6e9e80debd..1a9e4ac142 100644
--- a/engines/prince/module.mk
+++ b/engines/prince/module.mk
@@ -17,6 +17,7 @@ MODULE_OBJS = \
object.o \
prince.o \
pscr.o \
+ resources.o \
saveload.o \
script.o \
variatxt.o \
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index fcdf3f5fa2..18fea8aaae 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -57,7 +57,6 @@
#include "prince/cursor.h"
#include "prince/archive.h"
#include "prince/hero.h"
-#include "prince/resource.h"
#include "prince/animation.h"
#include "prince/option_text.h"
#include "prince/curve_values.h"
@@ -469,142 +468,6 @@ void PrinceEngine::pauseEngineIntern(bool pause) {
}
}
-bool AnimListItem::loadFromStream(Common::SeekableReadStream &stream) {
- int32 pos = stream.pos();
-
- uint16 type = stream.readUint16LE();
- if (type == 0xFFFF) {
- return false;
- }
- _type = type;
- _fileNumber = stream.readUint16LE();
- _startPhase = stream.readUint16LE();
- _endPhase = stream.readUint16LE();
- _loopPhase = stream.readUint16LE();
- _x = stream.readSint16LE();
- _y = stream.readSint16LE();
- _loopType = stream.readUint16LE();
- _nextAnim = stream.readUint16LE();
- _flags = stream.readUint16LE();
-
- //debug("AnimListItem type %d, fileNumber %d, x %d, y %d, flags %d", _type, _fileNumber, _x, _y, _flags);
- //debug("startPhase %d, endPhase %d, loopPhase %d", _startPhase, _endPhase, _loopPhase);
-
- // 32 byte aligment
- stream.seek(pos + 32);
-
- return true;
-}
-
-bool PrinceEngine::loadLocation(uint16 locationNr) {
-
- blackPalette();
-
- _flicPlayer.close();
-
- memset(_textSlots, 0, sizeof(_textSlots));
- freeAllSamples();
-
- debugEngine("PrinceEngine::loadLocation %d", locationNr);
- const Common::FSNode gameDataDir(ConfMan.get("path"));
- SearchMan.remove(Common::String::format("%02d", _locationNr));
-
- _locationNr = locationNr;
- _debugger->_locationNr = locationNr;
-
- _flags->setFlagValue(Flags::CURRROOM, _locationNr);
- _interpreter->stopBg();
-
- changeCursor(0);
-
- const Common::String locationNrStr = Common::String::format("%02d", _locationNr);
- debugEngine("loadLocation %s", locationNrStr.c_str());
-
- PtcArchive *locationArchive = new PtcArchive();
- if (!locationArchive->open(locationNrStr + "/databank.ptc"))
- error("Can't open location %s", locationNrStr.c_str());
-
- SearchMan.add(locationNrStr, locationArchive);
-
- loadMusic(_locationNr);
-
- // load location background, replace old one
- Resource::loadResource(_roomBmp, "room", true);
- if (_roomBmp->getSurface()) {
- _sceneWidth = _roomBmp->getSurface()->w;
- }
-
- loadZoom(_zoomBitmap, kZoomBitmapLen, "zoom");
- loadShadow(_shadowBitmap, kShadowBitmapSize, "shadow", "shadow2");
- loadTrans(_transTable, "trans");
- loadPath("path");
-
- for (uint32 i = 0; i < _pscrList.size(); i++) {
- delete _pscrList[i];
- }
- _pscrList.clear();
- Resource::loadResource(_pscrList, "pscr.lst", false);
-
- loadMobPriority("mobpri");
-
- _mobList.clear();
- if (getGameType() == kPrinceDataDE) {
- const Common::String mobLstName = Common::String::format("mob%02d.lst", _locationNr);
- debug("name: %s", mobLstName.c_str());
- Resource::loadResource(_mobList, mobLstName.c_str(), false);
- } else if (getGameType() == kPrinceDataPL) {
- Resource::loadResource(_mobList, "mob.lst", false);
- }
- if (getFeatures() & GF_TRANSLATED) {
- // update Mob texts for translated version
- setMobTranslationTexts();
- }
-
- _animList.clear();
- Resource::loadResource(_animList, "anim.lst", false);
-
- for (uint32 i = 0; i < _objList.size(); i++) {
- delete _objList[i];
- }
- _objList.clear();
- Resource::loadResource(_objList, "obj.lst", false);
-
- _room->loadRoom(_script->getRoomOffset(_locationNr));
-
- for (uint i = 0; i < _maskList.size(); i++) {
- free(_maskList[i]._data);
- }
- _maskList.clear();
- _script->loadAllMasks(_maskList, _room->_nak);
-
- _picWindowX = 0;
-
- _lightX = _script->getLightX(_locationNr);
- _lightY = _script->getLightY(_locationNr);
- setShadowScale(_script->getShadowScale(_locationNr));
-
- for (uint i = 0; i < _mobList.size(); i++) {
- _mobList[i]._visible = _script->getMobVisible(_room->_mobs, i);
- }
-
- _script->installObjects(_room->_obj);
-
- freeAllNormAnims();
-
- clearBackAnimList();
- _script->installBackAnims(_backAnimList, _room->_backAnim);
-
- _graph->makeShadowTable(70, _graph->_shadowTable70);
- _graph->makeShadowTable(50, _graph->_shadowTable50);
-
- _mainHero->freeOldMove();
- _secondHero->freeOldMove();
-
- _mainHero->scrollHero();
-
- return true;
-}
-
void PrinceEngine::setShadowScale(int32 shadowScale) {
shadowScale = 100 - shadowScale;
if (!shadowScale) {
@@ -886,156 +749,6 @@ void PrinceEngine::setVoice(uint16 slot, uint32 sampleSlot, uint16 flag) {
loadVoice(slot, sampleSlot, sampleName);
}
-bool PrinceEngine::loadAnim(uint16 animNr, bool loop) {
- Common::String streamName = Common::String::format("AN%02d", animNr);
- Common::SeekableReadStream *flicStream = SearchMan.createReadStreamForMember(streamName);
-
- if (!flicStream) {
- error("Can't open %s", streamName.c_str());
- return false;
- }
-
- if (!_flicPlayer.loadStream(flicStream)) {
- error("Can't load flic stream %s", streamName.c_str());
- }
-
- debugEngine("%s loaded", streamName.c_str());
- _flicLooped = loop;
- _flicPlayer.start();
- playNextFLCFrame();
- return true;
-}
-
-bool PrinceEngine::loadZoom(byte *zoomBitmap, uint32 dataSize, const char *resourceName) {
- Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
- if (!stream) {
- delete stream;
- return false;
- }
- if (stream->read(zoomBitmap, dataSize) != dataSize) {
- free(zoomBitmap);
- delete stream;
- return false;
- }
- delete stream;
- return true;
-}
-
-bool PrinceEngine::loadShadow(byte *shadowBitmap, uint32 dataSize, const char *resourceName1, const char *resourceName2) {
- Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName1);
- if (!stream) {
- delete stream;
- return false;
- }
-
- if (stream->read(shadowBitmap, dataSize) != dataSize) {
- free(shadowBitmap);
- delete stream;
- return false;
- }
-
- Common::SeekableReadStream *stream2 = SearchMan.createReadStreamForMember(resourceName2);
- if (!stream2) {
- delete stream;
- delete stream2;
- return false;
- }
-
- byte *shadowBitmap2 = shadowBitmap + dataSize;
- if (stream2->read(shadowBitmap2, dataSize) != dataSize) {
- free(shadowBitmap);
- delete stream;
- delete stream2;
- return false;
- }
-
- delete stream;
- delete stream2;
- return true;
-}
-
-bool PrinceEngine::loadTrans(byte *transTable, const char *resourceName) {
- Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
- if (!stream) {
- delete stream;
- for (int i = 0; i < 256; i++) {
- for (int j = 0; j < 256; j++) {
- transTable[i * 256 + j] = j;
- }
- }
- return true;
- }
- if (stream->read(transTable, kTransTableSize) != kTransTableSize) {
- delete stream;
- return false;
- }
- delete stream;
- return true;
-}
-
-bool PrinceEngine::loadPath(const char *resourceName) {
- Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
- if (!stream) {
- delete stream;
- return false;
- }
- if (stream->read(_roomPathBitmap, kPathBitmapLen) != kPathBitmapLen) {
- delete stream;
- return false;
- }
- delete stream;
- return true;
-}
-
-bool PrinceEngine::loadAllInv() {
- for (int i = 0; i < kMaxInv; i++) {
- InvItem tempInvItem;
-
- const Common::String invStreamName = Common::String::format("INV%02d", i);
- Common::SeekableReadStream *invStream = SearchMan.createReadStreamForMember(invStreamName);
- if (!invStream) {
- delete invStream;
- return true;
- }
-
- tempInvItem._x = invStream->readUint16LE();
- tempInvItem._y = invStream->readUint16LE();
- int width = invStream->readUint16LE();
- int height = invStream->readUint16LE();
- tempInvItem._surface = new Graphics::Surface();
- tempInvItem._surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
-
- for (int h = 0; h < tempInvItem._surface->h; h++) {
- invStream->read(tempInvItem._surface->getBasePtr(0, h), tempInvItem._surface->w);
- }
-
- _allInvList.push_back(tempInvItem);
- delete invStream;
- }
-
- return true;
-}
-
-bool PrinceEngine::loadMobPriority(const char *resourceName) {
- Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
- if (!stream) {
- delete stream;
- return false;
- }
-
- _mobPriorityList.clear();
- uint mobId;
- while (1) {
- mobId = stream->readUint32LE();
- if (mobId == 0xFFFFFFFF) {
- break;
- }
- _mobPriorityList.push_back(mobId);
- }
- delete stream;
- return true;
-}
-
void PrinceEngine::loadMobTranslationTexts() {
Common::SeekableReadStream *mobTranslationStream = SearchMan.createReadStreamForMember("mob_translate.dat");
if (!mobTranslationStream) {
diff --git a/engines/prince/resources.cpp b/engines/prince/resources.cpp
new file mode 100644
index 0000000000..bb3db04032
--- /dev/null
+++ b/engines/prince/resources.cpp
@@ -0,0 +1,321 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/config-manager.h"
+
+#include "prince/prince.h"
+#include "prince/graphics.h"
+#include "prince/debugger.h"
+#include "prince/script.h"
+#include "prince/hero.h"
+#include "prince/resource.h"
+#include "prince/archive.h"
+
+namespace Prince {
+
+bool AnimListItem::loadFromStream(Common::SeekableReadStream &stream) {
+ int32 pos = stream.pos();
+
+ uint16 type = stream.readUint16LE();
+ if (type == 0xFFFF) {
+ return false;
+ }
+ _type = type;
+ _fileNumber = stream.readUint16LE();
+ _startPhase = stream.readUint16LE();
+ _endPhase = stream.readUint16LE();
+ _loopPhase = stream.readUint16LE();
+ _x = stream.readSint16LE();
+ _y = stream.readSint16LE();
+ _loopType = stream.readUint16LE();
+ _nextAnim = stream.readUint16LE();
+ _flags = stream.readUint16LE();
+
+ //debug("AnimListItem type %d, fileNumber %d, x %d, y %d, flags %d", _type, _fileNumber, _x, _y, _flags);
+ //debug("startPhase %d, endPhase %d, loopPhase %d", _startPhase, _endPhase, _loopPhase);
+
+ // 32 byte aligment
+ stream.seek(pos + 32);
+
+ return true;
+}
+
+bool PrinceEngine::loadLocation(uint16 locationNr) {
+
+ blackPalette();
+
+ _flicPlayer.close();
+
+ memset(_textSlots, 0, sizeof(_textSlots));
+ freeAllSamples();
+
+ debugEngine("PrinceEngine::loadLocation %d", locationNr);
+ const Common::FSNode gameDataDir(ConfMan.get("path"));
+ SearchMan.remove(Common::String::format("%02d", _locationNr));
+
+ _locationNr = locationNr;
+ _debugger->_locationNr = locationNr;
+
+ _flags->setFlagValue(Flags::CURRROOM, _locationNr);
+ _interpreter->stopBg();
+
+ changeCursor(0);
+
+ const Common::String locationNrStr = Common::String::format("%02d", _locationNr);
+ debugEngine("loadLocation %s", locationNrStr.c_str());
+
+ PtcArchive *locationArchive = new PtcArchive();
+ if (!locationArchive->open(locationNrStr + "/databank.ptc"))
+ error("Can't open location %s", locationNrStr.c_str());
+
+ SearchMan.add(locationNrStr, locationArchive);
+
+ loadMusic(_locationNr);
+
+ // load location background, replace old one
+ Resource::loadResource(_roomBmp, "room", true);
+ if (_roomBmp->getSurface()) {
+ _sceneWidth = _roomBmp->getSurface()->w;
+ }
+
+ loadZoom(_zoomBitmap, kZoomBitmapLen, "zoom");
+ loadShadow(_shadowBitmap, kShadowBitmapSize, "shadow", "shadow2");
+ loadTrans(_transTable, "trans");
+ loadPath("path");
+
+ for (uint32 i = 0; i < _pscrList.size(); i++) {
+ delete _pscrList[i];
+ }
+ _pscrList.clear();
+ Resource::loadResource(_pscrList, "pscr.lst", false);
+
+ loadMobPriority("mobpri");
+
+ _mobList.clear();
+ if (getGameType() == kPrinceDataDE) {
+ const Common::String mobLstName = Common::String::format("mob%02d.lst", _locationNr);
+ debug("name: %s", mobLstName.c_str());
+ Resource::loadResource(_mobList, mobLstName.c_str(), false);
+ } else if (getGameType() == kPrinceDataPL) {
+ Resource::loadResource(_mobList, "mob.lst", false);
+ }
+ if (getFeatures() & GF_TRANSLATED) {
+ // update Mob texts for translated version
+ setMobTranslationTexts();
+ }
+
+ _animList.clear();
+ Resource::loadResource(_animList, "anim.lst", false);
+
+ for (uint32 i = 0; i < _objList.size(); i++) {
+ delete _objList[i];
+ }
+ _objList.clear();
+ Resource::loadResource(_objList, "obj.lst", false);
+
+ _room->loadRoom(_script->getRoomOffset(_locationNr));
+
+ for (uint i = 0; i < _maskList.size(); i++) {
+ free(_maskList[i]._data);
+ }
+ _maskList.clear();
+ _script->loadAllMasks(_maskList, _room->_nak);
+
+ _picWindowX = 0;
+
+ _lightX = _script->getLightX(_locationNr);
+ _lightY = _script->getLightY(_locationNr);
+ setShadowScale(_script->getShadowScale(_locationNr));
+
+ for (uint i = 0; i < _mobList.size(); i++) {
+ _mobList[i]._visible = _script->getMobVisible(_room->_mobs, i);
+ }
+
+ _script->installObjects(_room->_obj);
+
+ freeAllNormAnims();
+
+ clearBackAnimList();
+ _script->installBackAnims(_backAnimList, _room->_backAnim);
+
+ _graph->makeShadowTable(70, _graph->_shadowTable70);
+ _graph->makeShadowTable(50, _graph->_shadowTable50);
+
+ _mainHero->freeOldMove();
+ _secondHero->freeOldMove();
+
+ _mainHero->scrollHero();
+
+ return true;
+}
+
+bool PrinceEngine::loadAnim(uint16 animNr, bool loop) {
+ Common::String streamName = Common::String::format("AN%02d", animNr);
+ Common::SeekableReadStream *flicStream = SearchMan.createReadStreamForMember(streamName);
+
+ if (!flicStream) {
+ error("Can't open %s", streamName.c_str());
+ return false;
+ }
+
+ if (!_flicPlayer.loadStream(flicStream)) {
+ error("Can't load flic stream %s", streamName.c_str());
+ }
+
+ debugEngine("%s loaded", streamName.c_str());
+ _flicLooped = loop;
+ _flicPlayer.start();
+ playNextFLCFrame();
+ return true;
+}
+
+bool PrinceEngine::loadZoom(byte *zoomBitmap, uint32 dataSize, const char *resourceName) {
+ Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
+ if (!stream) {
+ delete stream;
+ return false;
+ }
+ if (stream->read(zoomBitmap, dataSize) != dataSize) {
+ free(zoomBitmap);
+ delete stream;
+ return false;
+ }
+ delete stream;
+ return true;
+}
+
+bool PrinceEngine::loadShadow(byte *shadowBitmap, uint32 dataSize, const char *resourceName1, const char *resourceName2) {
+ Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName1);
+ if (!stream) {
+ delete stream;
+ return false;
+ }
+
+ if (stream->read(shadowBitmap, dataSize) != dataSize) {
+ free(shadowBitmap);
+ delete stream;
+ return false;
+ }
+
+ Common::SeekableReadStream *stream2 = SearchMan.createReadStreamForMember(resourceName2);
+ if (!stream2) {
+ delete stream;
+ delete stream2;
+ return false;
+ }
+
+ byte *shadowBitmap2 = shadowBitmap + dataSize;
+ if (stream2->read(shadowBitmap2, dataSize) != dataSize) {
+ free(shadowBitmap);
+ delete stream;
+ delete stream2;
+ return false;
+ }
+
+ delete stream;
+ delete stream2;
+ return true;
+}
+
+bool PrinceEngine::loadTrans(byte *transTable, const char *resourceName) {
+ Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
+ if (!stream) {
+ delete stream;
+ for (int i = 0; i < 256; i++) {
+ for (int j = 0; j < 256; j++) {
+ transTable[i * 256 + j] = j;
+ }
+ }
+ return true;
+ }
+ if (stream->read(transTable, kTransTableSize) != kTransTableSize) {
+ delete stream;
+ return false;
+ }
+ delete stream;
+ return true;
+}
+
+bool PrinceEngine::loadPath(const char *resourceName) {
+ Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
+ if (!stream) {
+ delete stream;
+ return false;
+ }
+ if (stream->read(_roomPathBitmap, kPathBitmapLen) != kPathBitmapLen) {
+ delete stream;
+ return false;
+ }
+ delete stream;
+ return true;
+}
+
+bool PrinceEngine::loadAllInv() {
+ for (int i = 0; i < kMaxInv; i++) {
+ InvItem tempInvItem;
+
+ const Common::String invStreamName = Common::String::format("INV%02d", i);
+ Common::SeekableReadStream *invStream = SearchMan.createReadStreamForMember(invStreamName);
+ if (!invStream) {
+ delete invStream;
+ return true;
+ }
+
+ tempInvItem._x = invStream->readUint16LE();
+ tempInvItem._y = invStream->readUint16LE();
+ int width = invStream->readUint16LE();
+ int height = invStream->readUint16LE();
+ tempInvItem._surface = new Graphics::Surface();
+ tempInvItem._surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
+
+ for (int h = 0; h < tempInvItem._surface->h; h++) {
+ invStream->read(tempInvItem._surface->getBasePtr(0, h), tempInvItem._surface->w);
+ }
+
+ _allInvList.push_back(tempInvItem);
+ delete invStream;
+ }
+
+ return true;
+}
+
+bool PrinceEngine::loadMobPriority(const char *resourceName) {
+ Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
+ if (!stream) {
+ delete stream;
+ return false;
+ }
+
+ _mobPriorityList.clear();
+ uint mobId;
+ while (1) {
+ mobId = stream->readUint32LE();
+ if (mobId == 0xFFFFFFFF) {
+ break;
+ }
+ _mobPriorityList.push_back(mobId);
+ }
+ delete stream;
+ return true;
+}
+
+} // End of namespace Prince