diff --git a/engines/nancy/action/actionmanager.cpp b/engines/nancy/action/actionmanager.cpp index eb284aa86f2..a4f19c6ccd1 100644 --- a/engines/nancy/action/actionmanager.cpp +++ b/engines/nancy/action/actionmanager.cpp @@ -127,6 +127,7 @@ bool ActionManager::addNewActionRecord(Common::SeekableReadStream &inputData) { // Initialize the dependencies data inputData.seek(localChunkSize); + newRecord->_dependencies.reserve(numDependencies); for (uint16 i = 0; i < numDependencies; ++i) { newRecord->_dependencies.push_back(DependencyRecord()); DependencyRecord &dep = newRecord->_dependencies.back(); diff --git a/engines/nancy/action/leverpuzzle.cpp b/engines/nancy/action/leverpuzzle.cpp index bb9b4562cfb..7a7d5794cea 100644 --- a/engines/nancy/action/leverpuzzle.cpp +++ b/engines/nancy/action/leverpuzzle.cpp @@ -44,14 +44,17 @@ void LeverPuzzle::init() { void LeverPuzzle::readData(Common::SeekableReadStream &stream) { readFilename(stream, _imageName); + _srcRects.reserve(3); for (uint leverID = 0; leverID < 3; ++leverID) { _srcRects.push_back(Common::Array()); + _srcRects.back().reserve(3); for (uint i = 0; i < 4; ++i) { _srcRects.back().push_back(Common::Rect()); readRect(stream, _srcRects.back().back()); } } + _destRects.reserve(3); for (uint leverID = 0; leverID < 3; ++leverID) { _destRects.push_back(Common::Rect()); readRect(stream, _destRects.back()); @@ -63,11 +66,14 @@ void LeverPuzzle::readData(Common::SeekableReadStream &stream) { } } + _playerSequence.reserve(3); + _leverDirection.reserve(3); for (uint leverID = 0; leverID < 3; ++leverID) { _playerSequence.push_back(stream.readByte()); _leverDirection.push_back(true); } + _correctSequence.reserve(3); for (uint leverID = 0; leverID < 3; ++leverID) { _correctSequence.push_back(stream.readByte()); } diff --git a/engines/nancy/action/orderingpuzzle.cpp b/engines/nancy/action/orderingpuzzle.cpp index 3480ae6e5bf..e9be9770b24 100644 --- a/engines/nancy/action/orderingpuzzle.cpp +++ b/engines/nancy/action/orderingpuzzle.cpp @@ -56,6 +56,7 @@ void OrderingPuzzle::readData(Common::SeekableReadStream &stream) { readFilename(stream, _imageName); uint16 numElements = stream.readUint16LE(); + _srcRects.reserve(numElements); for (uint i = 0; i < numElements; ++i) { _srcRects.push_back(Common::Rect()); readRect(stream, _srcRects.back()); @@ -63,6 +64,8 @@ void OrderingPuzzle::readData(Common::SeekableReadStream &stream) { stream.skip(16 * (15 - numElements)); + _destRects.reserve(numElements); + _drawnElements.reserve(numElements); for (uint i = 0; i < numElements; ++i) { _destRects.push_back(Common::Rect()); readRect(stream, _destRects.back()); @@ -80,6 +83,7 @@ void OrderingPuzzle::readData(Common::SeekableReadStream &stream) { _sequenceLength = stream.readUint16LE(); + _correctSequence.reserve(15); for (uint i = 0; i < 15; ++i) { _correctSequence.push_back(stream.readByte()); } diff --git a/engines/nancy/action/primaryvideo.cpp b/engines/nancy/action/primaryvideo.cpp index 2fc01cc4065..e11d4a945a5 100644 --- a/engines/nancy/action/primaryvideo.cpp +++ b/engines/nancy/action/primaryvideo.cpp @@ -78,6 +78,7 @@ void PlayPrimaryVideoChan0::ConditionFlag::set() const { void PlayPrimaryVideoChan0::ConditionFlags::read(Common::SeekableReadStream &stream) { uint16 numFlags = stream.readUint16LE(); + conditionFlags.reserve(numFlags); for (uint i = 0; i < numFlags; ++i) { conditionFlags.push_back(ConditionFlag()); conditionFlags.back().read(stream); @@ -180,21 +181,20 @@ void PlayPrimaryVideoChan0::readData(Common::SeekableReadStream &stream) { uint16 numResponses = stream.readUint16LE(); rawText = new char[400]; - if (numResponses > 0) { - for (uint i = 0; i < numResponses; ++i) { - _responses.push_back(ResponseStruct()); - ResponseStruct &response = _responses[i]; - response.conditionFlags.read(stream); - stream.read(rawText, 400); - UI::Textbox::assembleTextLine(rawText, response.text, 400); - readFilename(stream, response.soundName); - stream.skip(1); - response._sceneChange.readData(stream); - response.flagDesc.label = stream.readSint16LE(); - response.flagDesc.flag = (NancyFlag)stream.readByte(); + _responses.reserve(numResponses); + for (uint i = 0; i < numResponses; ++i) { + _responses.push_back(ResponseStruct()); + ResponseStruct &response = _responses[i]; + response.conditionFlags.read(stream); + stream.read(rawText, 400); + UI::Textbox::assembleTextLine(rawText, response.text, 400); + readFilename(stream, response.soundName); + stream.skip(1); + response._sceneChange.readData(stream); + response.flagDesc.label = stream.readSint16LE(); + response.flagDesc.flag = (NancyFlag)stream.readByte(); - stream.skip(0x32); - } + stream.skip(0x32); } delete[] rawText; @@ -205,15 +205,14 @@ void PlayPrimaryVideoChan0::readData(Common::SeekableReadStream &stream) { } uint16 numFlagsStructs = stream.readUint16LE(); - if (numFlagsStructs > 0) { - for (uint16 i = 0; i < numFlagsStructs; ++i) { - _flagsStructs.push_back(FlagsStruct()); - FlagsStruct &flagsStruct = _flagsStructs.back(); - flagsStruct.conditions.read(stream); - flagsStruct.flagToSet.type = (ConditionFlag::ConditionType)stream.readByte(); - flagsStruct.flagToSet.flag.label = stream.readSint16LE(); - flagsStruct.flagToSet.flag.flag = (NancyFlag)stream.readByte(); - } + _flagsStructs.reserve(numFlagsStructs); + for (uint16 i = 0; i < numFlagsStructs; ++i) { + _flagsStructs.push_back(FlagsStruct()); + FlagsStruct &flagsStruct = _flagsStructs.back(); + flagsStruct.conditions.read(stream); + flagsStruct.flagToSet.type = (ConditionFlag::ConditionType)stream.readByte(); + flagsStruct.flagToSet.flag.label = stream.readSint16LE(); + flagsStruct.flagToSet.flag.flag = (NancyFlag)stream.readByte(); } } diff --git a/engines/nancy/action/recordtypes.cpp b/engines/nancy/action/recordtypes.cpp index e0ef70a2618..c63fbc42935 100644 --- a/engines/nancy/action/recordtypes.cpp +++ b/engines/nancy/action/recordtypes.cpp @@ -53,6 +53,7 @@ void HotMultiframeSceneChange::readData(Common::SeekableReadStream &stream) { SceneChange::readData(stream); uint16 numHotspots = stream.readUint16LE(); + _hotspots.reserve(numHotspots); for (uint i = 0; i < numHotspots; ++i) { _hotspots.push_back(HotspotDescription()); HotspotDescription &newDesc = _hotspots[i]; @@ -152,6 +153,7 @@ void MapCallHot1Fr::execute() { void MapCallHotMultiframe::readData(Common::SeekableReadStream &stream) { uint16 numDescs = stream.readUint16LE(); + _hotspots.reserve(numDescs); for (uint i = 0; i < numDescs; ++i) { _hotspots.push_back(HotspotDescription()); _hotspots[i].readData(stream); @@ -254,6 +256,7 @@ void EventFlagsMultiHS::readData(Common::SeekableReadStream &stream) { EventFlags::readData(stream); uint16 numHotspots = stream.readUint16LE(); + _hotspots.reserve(numHotspots); for (uint16 i = 0; i < numHotspots; ++i) { _hotspots.push_back(HotspotDescription()); HotspotDescription &newDesc = _hotspots[i]; @@ -360,6 +363,7 @@ void ShowInventoryItem::readData(Common::SeekableReadStream &stream) { uint16 numFrames = stream.readUint16LE(); + _bitmaps.reserve(numFrames); for (uint i = 0; i < numFrames; ++i) { _bitmaps.push_back(BitmapDescription()); _bitmaps[i].readData(stream); @@ -462,6 +466,7 @@ void PlaySoundMultiHS::readData(Common::SeekableReadStream &stream) { stream.skip(2); uint16 numHotspots = stream.readUint16LE(); + _hotspots.reserve(numHotspots); for (uint i = 0; i < numHotspots; ++i) { _hotspots.push_back(HotspotDescription()); _hotspots.back().frameID = stream.readUint16LE(); diff --git a/engines/nancy/action/rotatinglockpuzzle.cpp b/engines/nancy/action/rotatinglockpuzzle.cpp index faf090f70bd..4e9f1d05bf4 100644 --- a/engines/nancy/action/rotatinglockpuzzle.cpp +++ b/engines/nancy/action/rotatinglockpuzzle.cpp @@ -48,11 +48,13 @@ void RotatingLockPuzzle::readData(Common::SeekableReadStream &stream) { uint numDials = stream.readUint16LE(); + _srcRects.reserve(10); for (uint i = 0; i < 10; ++i) { _srcRects.push_back(Common::Rect()); readRect(stream, _srcRects.back()); } + _destRects.reserve(numDials); for (uint i = 0; i < numDials; ++i) { _destRects.push_back(Common::Rect()); readRect(stream, _destRects.back()); @@ -66,11 +68,13 @@ void RotatingLockPuzzle::readData(Common::SeekableReadStream &stream) { stream.skip((8 - numDials) * 16); + _upHotspots.reserve(numDials); for (uint i = 0; i < numDials; ++i) { _upHotspots.push_back(Common::Rect()); readRect(stream, _upHotspots.back()); } + _downHotspots.reserve(numDials); stream.skip((8 - numDials) * 16); for (uint i = 0; i < numDials; ++i) { @@ -80,6 +84,7 @@ void RotatingLockPuzzle::readData(Common::SeekableReadStream &stream) { stream.skip((8 - numDials) * 16); + _correctSequence.reserve(numDials); for (uint i = 0; i < numDials; ++i) { _correctSequence.push_back(stream.readByte()); } diff --git a/engines/nancy/action/secondarymovie.cpp b/engines/nancy/action/secondarymovie.cpp index 223b57c2d37..ecfc65c977a 100644 --- a/engines/nancy/action/secondarymovie.cpp +++ b/engines/nancy/action/secondarymovie.cpp @@ -59,6 +59,7 @@ void PlaySecondaryMovie::readData(Common::SeekableReadStream &stream) { _sceneChange.readData(stream); uint16 numVideoDescs = stream.readUint16LE(); + _videoDescs.reserve(numVideoDescs); for (uint i = 0; i < numVideoDescs; ++i) { _videoDescs.push_back(SecondaryVideoDescription()); _videoDescs[i].readData(stream); diff --git a/engines/nancy/action/secondaryvideo.cpp b/engines/nancy/action/secondaryvideo.cpp index 77abaa80acc..318bd10ffc1 100644 --- a/engines/nancy/action/secondaryvideo.cpp +++ b/engines/nancy/action/secondaryvideo.cpp @@ -170,6 +170,7 @@ void PlaySecondaryVideo::readData(Common::SeekableReadStream &stream) { } uint16 numVideoDescs = stream.readUint16LE(); + _videoDescs.reserve(numVideoDescs); for (uint i = 0; i < numVideoDescs; ++i) { _videoDescs.push_back(SecondaryVideoDescription()); _videoDescs[i].readData(stream); diff --git a/engines/nancy/action/sliderpuzzle.cpp b/engines/nancy/action/sliderpuzzle.cpp index 82f0f57d29b..d808a56e7ba 100644 --- a/engines/nancy/action/sliderpuzzle.cpp +++ b/engines/nancy/action/sliderpuzzle.cpp @@ -49,19 +49,26 @@ void SliderPuzzle::readData(Common::SeekableReadStream &stream) { _width = stream.readUint16LE(); _height = stream.readUint16LE(); + _srcRects.reserve(_height); for (uint y = 0; y < _height; ++y) { _srcRects.push_back(Common::Array()); + _srcRects.back().reserve(_width); + for (uint x = 0; x < _width; ++x) { _srcRects.back().push_back(Common::Rect()); readRect(stream, _srcRects.back().back()); } + stream.skip((6 - _width) * 16); } stream.skip((6 - _height) * 6 * 16); + _destRects.reserve(_height); for (uint y = 0; y < _height; ++y) { _destRects.push_back(Common::Array()); + _destRects.back().reserve(_width); + for (uint x = 0; x < _width; ++x) { _destRects.back().push_back(Common::Rect()); readRect(stream, _destRects.back().back()); @@ -77,11 +84,15 @@ void SliderPuzzle::readData(Common::SeekableReadStream &stream) { stream.skip((6 - _height) * 6 * 16); + _correctTileOrder.reserve(_height); for (uint y = 0; y < _height; ++y) { _correctTileOrder.push_back(Common::Array()); + _correctTileOrder.back().reserve(_width); + for (uint x = 0; x < _width; ++x) { _correctTileOrder.back().push_back(stream.readSint16LE()); } + stream.skip((6 - _width) * 2); } diff --git a/engines/nancy/action/staticbitmapanim.cpp b/engines/nancy/action/staticbitmapanim.cpp index 318723649a3..9abf7a698f4 100644 --- a/engines/nancy/action/staticbitmapanim.cpp +++ b/engines/nancy/action/staticbitmapanim.cpp @@ -69,11 +69,13 @@ void PlayStaticBitmapAnimation::readData(Common::SeekableReadStream &stream) { _sound.read(stream, SoundDescription::kNormal); uint numViewportFrames = stream.readUint16LE(); + _srcRects.reserve(_loopLastFrame - _firstFrame); for (uint i = _firstFrame; i <= _loopLastFrame; ++i) { _srcRects.push_back(Common::Rect()); readRect(stream, _srcRects[i]); } + _bitmaps.reserve(numViewportFrames); for (uint i = 0; i < numViewportFrames; ++i) { _bitmaps.push_back(BitmapDescription()); BitmapDescription &rects = _bitmaps.back(); diff --git a/engines/nancy/action/telephone.cpp b/engines/nancy/action/telephone.cpp index c478936b2db..50786f1f0dc 100644 --- a/engines/nancy/action/telephone.cpp +++ b/engines/nancy/action/telephone.cpp @@ -52,11 +52,13 @@ void Telephone::init() { void Telephone::readData(Common::SeekableReadStream &stream) { readFilename(stream, _imageName); + _srcRects.reserve(12); for (uint i = 0; i < 12; ++i) { _srcRects.push_back(Common::Rect()); readRect(stream, _srcRects.back()); } + _destRects.reserve(12); for (uint i = 0; i < 12; ++i) { _destRects.push_back(Common::Rect()); readRect(stream, _destRects.back()); @@ -75,6 +77,7 @@ void Telephone::readData(Common::SeekableReadStream &stream) { _dialAgainSound.read(stream, SoundDescription::kNormal); _hangUpSound.read(stream, SoundDescription::kNormal); + _buttonSoundNames.reserve(12); for (uint i = 0; i < 12; ++i) { Common::String buttonSoundName; readFilename(stream, buttonSoundName); @@ -100,10 +103,12 @@ void Telephone::readData(Common::SeekableReadStream &stream) { uint numCalls = stream.readUint16LE(); + _calls.reserve(numCalls); for (uint i = 0; i < numCalls; ++i) { _calls.push_back(PhoneCall()); PhoneCall &call = _calls.back(); + call.phoneNumber.reserve(11); for (uint j = 0; j < 11; ++j) { call.phoneNumber.push_back(stream.readByte()); } diff --git a/engines/nancy/cursor.cpp b/engines/nancy/cursor.cpp index 901cc1ff9bb..60944185850 100644 --- a/engines/nancy/cursor.cpp +++ b/engines/nancy/cursor.cpp @@ -38,6 +38,7 @@ void CursorManager::init() { Common::String inventoryCursorsImageName = chunk->readString(); chunk = g_nancy->getBootChunkStream("CURS"); + _cursors.reserve(56); for (uint i = 0; i < 56; ++i) { _cursors.push_back(Cursor()); chunk->seek(i * 16, SEEK_SET); diff --git a/engines/nancy/font.cpp b/engines/nancy/font.cpp index 9df4024361e..dbe484a5d64 100644 --- a/engines/nancy/font.cpp +++ b/engines/nancy/font.cpp @@ -70,6 +70,7 @@ void Font::read(Common::SeekableReadStream &stream) { _semicolonOffset = stream.readUint16LE(); _slashOffset = stream.readUint16LE(); + _symbolRects.reserve(78); for (uint i = 0; i < 78; ++i) { _symbolRects.push_back(Common::Rect()); Common::Rect &cur = _symbolRects[i]; diff --git a/engines/nancy/iff.cpp b/engines/nancy/iff.cpp index 099ca07d058..372a613f090 100644 --- a/engines/nancy/iff.cpp +++ b/engines/nancy/iff.cpp @@ -146,6 +146,7 @@ uint32 IFF::stringToId(const Common::String &s) { } void IFF::list(Common::Array &nameList) { + nameList.reserve(_chunks.size()); for (uint i = 0; i < _chunks.size(); ++i) { nameList.push_back(idToString(_chunks[i].id)); } diff --git a/engines/nancy/resource.cpp b/engines/nancy/resource.cpp index 87fd5fa645f..4988d96f57d 100644 --- a/engines/nancy/resource.cpp +++ b/engines/nancy/resource.cpp @@ -233,6 +233,7 @@ bool CifTree::initialize() { if (f.eos()) error("Error reading CifTree '%s'", _name.c_str()); + _cifInfo.reserve(infoBlockCount); for (int i = 0; i < infoBlockCount; i++) { CifInfoChain chain; readCifInfo(f, chain); diff --git a/engines/nancy/state/map.cpp b/engines/nancy/state/map.cpp index 53c57878043..f62866c4aab 100644 --- a/engines/nancy/state/map.cpp +++ b/engines/nancy/state/map.cpp @@ -84,6 +84,7 @@ void Map::init() { _locations.clear(); + _locations.reserve(4); for (uint i = 0; i < 4; ++i) { chunk->seek(0x162 + i * 16, SEEK_SET); _locations.push_back(Location()); @@ -96,6 +97,7 @@ void Map::init() { loc.isActive = true; } + loc.scenes.reserve(2); for (uint j = 0; j < 2; ++j) { loc.scenes.push_back(Location::SceneChange()); Location::SceneChange &sc = loc.scenes[j]; diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp index de50f88ff38..3f8c6d3ab94 100644 --- a/engines/nancy/state/scene.cpp +++ b/engines/nancy/state/scene.cpp @@ -397,6 +397,7 @@ void Scene::init() { _hintsRemaining.clear(); + _hintsRemaining.reserve(3); for (uint i = 0; i < 3; ++i) { _hintsRemaining.push_back(chunk->readByte()); } @@ -575,6 +576,7 @@ void Scene::initStaticData() { // Hardcoded by original engine _mapAccessSceneIDs.clear(); + _mapAccessSceneIDs.reserve(8); _mapAccessSceneIDs.push_back(9); _mapAccessSceneIDs.push_back(10); _mapAccessSceneIDs.push_back(11); diff --git a/engines/nancy/video.cpp b/engines/nancy/video.cpp index f4625415fa3..32ca875f98a 100644 --- a/engines/nancy/video.cpp +++ b/engines/nancy/video.cpp @@ -114,6 +114,7 @@ AVFDecoder::AVFVideoTrack::AVFVideoTrack(Common::SeekableReadStream *stream, uin _surface->create(_width, _height, _pixelFormat); _frameSize = _width * _height * _pixelFormat.bytesPerPixel; + _chunkInfo.reserve(_frameCount); for (uint i = 0; i < _frameCount; i++) { ChunkInfo info;