diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6be563e9e..1e0042a93 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,10 +13,10 @@ Debian: before_script: - export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR - apt-get update -yq - - apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libsdl2-dev libqt4-dev libopenal-dev libopenscenegraph-3.4-dev libunshield-dev libtinyxml-dev + - apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-iostreams-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libsdl2-dev libqt4-dev libopenal-dev libopenscenegraph-3.4-dev libunshield-dev libtinyxml-dev # - apt-get install -y libmygui-dev libbullet-dev # to be updated to latest below because stretch is too old - - curl -L http://ftp.us.debian.org/debian/pool/main/b/bullet/libbullet-dev_2.87+dfsg-3_amd64.deb -o libbullet-dev_2.87+dfsg-3_amd64.deb - - curl -L http://ftp.us.debian.org/debian/pool/main/b/bullet/libbullet2.87_2.87+dfsg-3_amd64.deb -o libbullet2.87_2.87+dfsg-3_amd64.deb + - curl -L http://archive.ubuntu.com/ubuntu/pool/universe/b/bullet/libbullet-dev_2.87+dfsg-2_amd64.deb -o libbullet-dev_2.87+dfsg-2_amd64.deb + - curl -L http://archive.ubuntu.com/ubuntu/pool/universe/b/bullet/libbullet2.87_2.87+dfsg-2_amd64.deb -o libbullet2.87_2.87+dfsg-2_amd64.deb - curl -L https://http.kali.org/pool/main/m/mygui/libmygui.openglplatform0debian1v5_3.2.2+dfsg-1_amd64.deb -o libmygui.openglplatform0debian1v5_3.2.2+dfsg-1_amd64.deb - curl -L https://http.kali.org/pool/main/m/mygui/libmyguiengine3debian1v5_3.2.2+dfsg-1_amd64.deb -o libmyguiengine3debian1v5_3.2.2+dfsg-1_amd64.deb - curl -L https://http.kali.org/pool/main/m/mygui/libmygui-dev_3.2.2+dfsg-1_amd64.deb -o libmygui-dev_3.2.2+dfsg-1_amd64.deb diff --git a/.travis.yml b/.travis.yml index ebc1cae76..022a49836 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ addons: # Dev cmake, clang-7, clang-tools-7, gcc-8, g++-8, # Boost - libboost-filesystem-dev, libboost-program-options-dev, libboost-system-dev, + libboost-filesystem-dev, libboost-iostreams-dev, libboost-program-options-dev, libboost-system-dev, # FFmpeg libavcodec-dev, libavformat-dev, libavutil-dev, libswresample-dev, libswscale-dev, # Audio, Video and Misc. deps diff --git a/CHANGELOG.md b/CHANGELOG.md index 0da3ba67d..1e7e6db78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Bug #2987: Editor: some chance and AI data fields can overflow Bug #3623: Fix HiDPI on Windows + Bug #3733: Normal maps are inverted on mirrored UVs + Bug #4329: Removed birthsign abilities are restored after reloading the save + Bug #4383: Bow model obscures crosshair when arrow is drawn Bug #4411: Reloading a saved game while falling prevents damage in some cases Bug #4540: Rain delay when exiting water Bug #4701: PrisonMarker record is not hardcoded like other markers @@ -14,11 +17,21 @@ Bug #4746: Non-solid player can't run or sneak Bug #4750: Sneaking doesn't work in first person view if the player is in attack ready state Bug #4768: Fallback numerical value recovery chokes on invalid arguments + Bug #4775: Slowfall effect resets player jumping flag + Bug #4778: Interiors of Illusion puzzle in Sotha Sil Expanded mod is broken + Bug #4800: Standing collisions are not updated immediately when an object is teleported without a cell change + Bug #4803: Stray special characters before begin statement break script compilation + Bug #4804: Particle system with the "Has Sizes = false" causes an exception + Bug #4813: Creatures with known file but no "Sound Gen Creature" assigned use default sounds + Bug #4820: Spell absorption is broken + Bug #4827: NiUVController is handled incorrectly + Bug #4828: Potion looping effects VFX are not shown for NPCs Feature #2229: Improve pathfinding AI Feature #3442: Default values for fallbacks from ini file Feature #3610: Option to invert X axis Feature #4673: Weapon sheathing Feature #4730: Native animated containers support + Feature #4812: Support NiSwitchNode Task #4686: Upgrade media decoder to a more current FFmpeg API 0.45.0 diff --git a/CI/before_install.osx.sh b/CI/before_install.osx.sh index 43102356e..e411a1d9b 100755 --- a/CI/before_install.osx.sh +++ b/CI/before_install.osx.sh @@ -7,5 +7,5 @@ brew switch cmake 3.12.4 brew outdated pkgconfig || brew upgrade pkgconfig brew install qt -curl -fSL -R -J https://downloads.openmw.org/osx/dependencies/openmw-deps-55c27b1.zip -o ~/openmw-deps.zip +curl -fSL -R -J https://downloads.openmw.org/osx/dependencies/openmw-deps-110f3d3.zip -o ~/openmw-deps.zip unzip -o ~/openmw-deps.zip -d /private/tmp/openmw-deps > /dev/null diff --git a/CI/before_script.msvc.sh b/CI/before_script.msvc.sh index 4fd352f7d..b5bf0b632 100644 --- a/CI/before_script.msvc.sh +++ b/CI/before_script.msvc.sh @@ -34,6 +34,8 @@ VS_VERSION="" NMAKE="" PLATFORM="" CONFIGURATION="" +TEST_FRAMEWORK="" +GOOGLE_INSTALL_ROOT="" while [ $# -gt 0 ]; do ARGSTR=$1 @@ -78,6 +80,9 @@ while [ $# -gt 0 ]; do CONFIGURATION=$1 shift ;; + t ) + TEST_FRAMEWORK=true ;; + h ) cat < Set the build platform, can also be set with environment variable PLATFORM. + -t + Build unit tests / Google test -u Configure for unity builds. -v <2013/2015/2017> @@ -395,6 +402,16 @@ if [ -z $SKIP_DOWNLOAD ]; then download "SDL 2.0.7" \ "https://www.libsdl.org/release/SDL2-devel-2.0.7-VC.zip" \ "SDL2-2.0.7.zip" + + # Google test and mock + if [ ! -z $TEST_FRAMEWORK ]; then + echo "Google test 1.8.1..." + if [ -d googletest ]; then + printf " Google test exists, skipping." + else + git clone -b release-1.8.1 https://github.com/google/googletest.git + fi + fi fi cd .. #/.. @@ -670,6 +687,52 @@ printf "SDL 2.0.7... " add_runtime_dlls "$(pwd)/SDL2-2.0.7/lib/x${ARCHSUFFIX}/SDL2.dll" echo Done. } +cd $DEPS +echo +# Google Test and Google Mock +if [ ! -z $TEST_FRAMEWORK ]; then + printf "Google test 1.8.1 ..." + + cd googletest + if [ ! -d build ]; then + mkdir build + fi + + cd build + + GOOGLE_INSTALL_ROOT="${DEPS_INSTALL}/GoogleTest" + if [ $CONFIGURATION == "Debug" ]; then + DEBUG_SUFFIX="d" + else + DEBUG_SUFFIX="" + fi + + if [ ! -d $GOOGLE_INSTALL_ROOT ]; then + + cmake .. -DCMAKE_BUILD_TYPE="${CONFIGURATION}" -DCMAKE_INSTALL_PREFIX="${GOOGLE_INSTALL_ROOT}" -DCMAKE_USE_WIN32_THREADS_INIT=1 -G "${GENERATOR}" -DBUILD_SHARED_LIBS=1 + cmake --build . --config "${CONFIGURATION}" + cmake --build . --target install --config "${CONFIGURATION}" + + add_runtime_dlls "${GOOGLE_INSTALL_ROOT}\bin\gtest_main${DEBUG_SUFFIX}.dll" + add_runtime_dlls "${GOOGLE_INSTALL_ROOT}\bin\gtest${DEBUG_SUFFIX}.dll" + add_runtime_dlls "${GOOGLE_INSTALL_ROOT}\bin\gmock_main${DEBUG_SUFFIX}.dll" + add_runtime_dlls "${GOOGLE_INSTALL_ROOT}\bin\gmock${DEBUG_SUFFIX}.dll" + fi + + add_cmake_opts -DBUILD_UNITTESTS=yes + # FindGTest and FindGMock do not work perfectly on Windows + # but we can help them by telling them everything we know about installation + add_cmake_opts -DGMOCK_ROOT="$GOOGLE_INSTALL_ROOT" + add_cmake_opts -DGTEST_ROOT="$GOOGLE_INSTALL_ROOT" + add_cmake_opts -DGTEST_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gtest${DEBUG_SUFFIX}.lib" + add_cmake_opts -DGTEST_MAIN_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gtest_main${DEBUG_SUFFIX}.lib" + add_cmake_opts -DGMOCK_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gmock${DEBUG_SUFFIX}.lib" + add_cmake_opts -DGMOCK_MAIN_LIBRARY="$GOOGLE_INSTALL_ROOT/lib/gmock_main${DEBUG_SUFFIX}.lib" + add_cmake_opts -DGTEST_LINKED_AS_SHARED_LIBRARY=True + echo Done. + +fi + echo cd $DEPS_INSTALL/.. echo diff --git a/CI/deploy.osx.sh b/CI/deploy.osx.sh index 5fa2b70a3..339ff955d 100755 --- a/CI/deploy.osx.sh +++ b/CI/deploy.osx.sh @@ -1,11 +1,26 @@ #!/bin/sh -cd build +# This script expect the following environment variables to be set: +# - OSX_DEPLOY_KEY: private SSH key, must be encoded like this before adding it to Travis secrets: https://github.com/travis-ci/travis-ci/issues/7715#issuecomment-433301692 +# - OSX_DEPLOY_HOST: string specifying SSH of the following format: ssh-user@ssh-host +# - OSX_DEPLOY_PORT: SSH port, it can't be a part of the host string because scp doesn't accept hosts with ports +# - OSX_DEPLOY_HOST_FINGERPRINT: fingerprint of the host, can be obtained by using ssh-keygen -F [host]:port & putting it in double quotes when adding to Travis secrets -DATE=`date +'%d%m%Y'` -SHORT_COMMIT=`git rev-parse --short ${TRAVIS_COMMIT}` +SSH_KEY_PATH="$HOME/.ssh/openmw_deploy" +REMOTE_PATH="\$HOME/nightly" + +echo "$OSX_DEPLOY_KEY" > "$SSH_KEY_PATH" +chmod 600 "$SSH_KEY_PATH" +echo "$OSX_DEPLOY_HOST_FINGERPRINT" >> "$HOME/.ssh/known_hosts" + +cd build || exit 1 + +DATE=$(date +'%d%m%Y') +SHORT_COMMIT=$(git rev-parse --short "${TRAVIS_COMMIT}") TARGET_FILENAME="OpenMW-${DATE}-${SHORT_COMMIT}.dmg" -if ! curl --ssl -u $OSX_FTP_USER:$OSX_FTP_PASSWORD "${OSX_FTP_URL}" --silent | grep $SHORT_COMMIT > /dev/null; then - curl --ssl --ftp-create-dirs -T *.dmg -u $OSX_FTP_USER:$OSX_FTP_PASSWORD "${OSX_FTP_URL}${TARGET_FILENAME}" +if ! ssh -p "$OSX_DEPLOY_PORT" -i "$SSH_KEY_PATH" "$OSX_DEPLOY_HOST" sh -c "ls \"$REMOTE_PATH\"" | grep "$SHORT_COMMIT" > /dev/null; then + scp -P "$OSX_DEPLOY_PORT" -i "$SSH_KEY_PATH" ./*.dmg "$OSX_DEPLOY_HOST:$REMOTE_PATH/$TARGET_FILENAME" +else + echo "An existing nightly build for commit ${SHORT_COMMIT} has been found, skipping upload." fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 6281785a8..18ade201c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -319,9 +319,9 @@ ELSE() ENDIF(BUILD_OPENMW OR BUILD_OPENCS) -set(BOOST_COMPONENTS system filesystem program_options) +set(BOOST_COMPONENTS system filesystem program_options iostreams) if(WIN32) - set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale) + set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale zlib) endif(WIN32) IF(BOOST_STATIC) diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index f9c028e29..b7eb369d7 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -269,7 +269,7 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) bool interior = cellRecord.mId.substr (0, 1)!="#"; // count new references and adjust RefNumCount accordingsly - int newRefNum = cellRecord.mRefNumCounter; + unsigned int newRefNum = cellRecord.mRefNumCounter; if (references!=mState.getSubRecords().end()) { @@ -279,11 +279,17 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) const CSMWorld::Record& ref = mDocument.getData().getReferences().getRecord (*iter); - if (ref.get().mNew || + CSMWorld::CellRef refRecord = ref.get(); + + if (refRecord.mNew || (!interior && ref.mState==CSMWorld::RecordBase::State_ModifiedOnly && /// \todo consider worldspace - CSMWorld::CellCoordinates (ref.get().getCellIndex()).getId("")!=ref.get().mCell)) + CSMWorld::CellCoordinates (refRecord.getCellIndex()).getId("") != refRecord.mCell)) ++cellRecord.mRefNumCounter; + + if (refRecord.mRefNum.mIndex >= newRefNum) + newRefNum = refRecord.mRefNum.mIndex + 1; + } } @@ -328,7 +334,7 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages) stream << "#" << index.first << " " << index.second; } - if (refRecord.mNew || + if (refRecord.mNew || refRecord.mRefNum.mIndex == 0 || (!interior && ref.mState==CSMWorld::RecordBase::State_ModifiedOnly && refRecord.mCell!=stream.str())) { diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 57d47ebbc..9bc0e0877 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -3,7 +3,6 @@ #include #include -#include #include "intsetting.hpp" #include "doublesetting.hpp" @@ -393,9 +392,7 @@ CSMPrefs::IntSetting& CSMPrefs::State::declareInt (const std::string& key, if (mCurrentCategory==mCategories.end()) throw std::logic_error ("no category for setting"); - std::ostringstream stream; - stream << default_; - setDefault (key, stream.str()); + setDefault(key, std::to_string(default_)); default_ = mSettings.getInt (key, mCurrentCategory->second.getKey()); @@ -414,9 +411,7 @@ CSMPrefs::DoubleSetting& CSMPrefs::State::declareDouble (const std::string& key, if (mCurrentCategory==mCategories.end()) throw std::logic_error ("no category for setting"); - std::ostringstream stream; - stream << default_; - setDefault (key, stream.str()); + setDefault(key, std::to_string(default_)); default_ = mSettings.getFloat (key, mCurrentCategory->second.getKey()); diff --git a/apps/opencs/model/tools/search.cpp b/apps/opencs/model/tools/search.cpp index 7cf89f3b5..e2cfd177b 100644 --- a/apps/opencs/model/tools/search.cpp +++ b/apps/opencs/model/tools/search.cpp @@ -77,14 +77,9 @@ void CSMTools::Search::searchRecordStateCell (const CSMWorld::IdTableBase *model { std::vector states = CSMWorld::Columns::getEnums (CSMWorld::Columns::ColumnId_Modification); - - std::ostringstream message; - message << states.at (data); - std::ostringstream hint; - hint << "r: " << model->getColumnId (index.column()); - - messages.add (id, message.str(), hint.str()); + const std::string hint = "r: " + std::to_string(model->getColumnId(index.column())); + messages.add (id, states.at(data), hint); } } diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index 80117d0c6..3d6802b86 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -17,6 +17,7 @@ #include "collectionbase.hpp" #include "land.hpp" #include "landtexture.hpp" +#include "ref.hpp" namespace CSMWorld { @@ -259,6 +260,11 @@ namespace CSMWorld copy.mState = RecordBase::State_ModifiedOnly; IdAccessorT().setId(copy.get(), destination); + if (type == UniversalId::Type_Reference) { + CSMWorld::CellRef* ptr = (CSMWorld::CellRef*) ©.mModified; + ptr->mRefNum.mIndex = 0; + } + int index = getAppendIndex(destination, type); insertRecord(copy, getAppendIndex(destination, type)); diff --git a/apps/opencs/model/world/commanddispatcher.cpp b/apps/opencs/model/world/commanddispatcher.cpp index 5d6a35cc5..2493813a6 100644 --- a/apps/opencs/model/world/commanddispatcher.cpp +++ b/apps/opencs/model/world/commanddispatcher.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "../doc/document.hpp" @@ -140,29 +141,44 @@ void CSMWorld::CommandDispatcher::executeModify (QAbstractItemModel *model, cons std::unique_ptr modifyCell; + std::unique_ptr modifyDataRefNum; + int columnId = model->data (index, ColumnBase::Role_ColumnId).toInt(); if (columnId==Columns::ColumnId_PositionXPos || columnId==Columns::ColumnId_PositionYPos) { - IdTableProxyModel *proxy = dynamic_cast (model); - - int row = proxy ? proxy->mapToSource (index).row() : index.row(); + const float oldPosition = model->data (index).toFloat(); - // This is not guaranteed to be the same as \a model, since a proxy could be used. - IdTable& model2 = dynamic_cast (*mDocument.getData().getTableModel (mId)); + // Modulate by cell size, update cell id if reference has been moved to a new cell + if (std::abs(std::fmod(oldPosition, Constants::CellSizeInUnits)) + - std::abs(std::fmod(new_.toFloat(), Constants::CellSizeInUnits)) >= 0.5f) + { + IdTableProxyModel *proxy = dynamic_cast (model); - int cellColumn = model2.searchColumnIndex (Columns::ColumnId_Cell); + int row = proxy ? proxy->mapToSource (index).row() : index.row(); - if (cellColumn!=-1) - { - QModelIndex cellIndex = model2.index (row, cellColumn); + // This is not guaranteed to be the same as \a model, since a proxy could be used. + IdTable& model2 = dynamic_cast (*mDocument.getData().getTableModel (mId)); - std::string cellId = model2.data (cellIndex).toString().toUtf8().data(); + int cellColumn = model2.searchColumnIndex (Columns::ColumnId_Cell); - if (cellId.find ('#')!=std::string::npos) + if (cellColumn!=-1) { - // Need to recalculate the cell - modifyCell.reset (new UpdateCellCommand (model2, row)); + QModelIndex cellIndex = model2.index (row, cellColumn); + + std::string cellId = model2.data (cellIndex).toString().toUtf8().data(); + + if (cellId.find ('#')!=std::string::npos) + { + // Need to recalculate the cell and (if necessary) clear the instance's refNum + modifyCell.reset (new UpdateCellCommand (model2, row)); + + // Not sure which model this should be applied to + int refNumColumn = model2.searchColumnIndex (Columns::ColumnId_RefNum); + + if (refNumColumn!=-1) + modifyDataRefNum.reset (new ModifyCommand(*model, model->index(row, refNumColumn), 0)); + } } } } @@ -175,6 +191,8 @@ void CSMWorld::CommandDispatcher::executeModify (QAbstractItemModel *model, cons CommandMacro macro (mDocument.getUndoStack()); macro.push (modifyData.release()); macro.push (modifyCell.release()); + if (modifyDataRefNum.get()) + macro.push (modifyDataRefNum.release()); } else mDocument.getUndoStack().push (modifyData.release()); diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index cb48fc85f..a0dbd7bad 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -221,7 +221,11 @@ std::string CSMWorld::IdTable::getId(int row) const ///This method can return only indexes to the top level table cells QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column) const { - return index(mIdCollection->getIndex (id), column); + int row = mIdCollection->searchId (id); + if (row != -1) + return index(row, column); + + return QModelIndex(); } void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& record, CSMWorld::UniversalId::Type type) diff --git a/apps/opencs/model/world/ref.cpp b/apps/opencs/model/world/ref.cpp index 0439b9448..b33623590 100644 --- a/apps/opencs/model/world/ref.cpp +++ b/apps/opencs/model/world/ref.cpp @@ -1,9 +1,5 @@ #include "ref.hpp" -#include - -#include - #include "cellcoordinates.hpp" CSMWorld::CellRef::CellRef() : mNew (true) diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 7767cca6d..30ffb310f 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -1,8 +1,5 @@ #include "refcollection.hpp" -#include - -#include #include #include @@ -32,40 +29,31 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool if (cell.get().isExterior()) { - // ignoring moved references sub-record; instead calculate cell from coordinates + // Autocalculate the cell index from coordinates first std::pair index = ref.getCellIndex(); - std::ostringstream stream; - stream << "#" << index.first << " " << index.second; - - ref.mCell = stream.str(); + ref.mCell = "#" + std::to_string(index.first) + " " + std::to_string(index.second); - if (!base && // don't try to update base records - mref.mRefNum.mIndex != 0) // MVRF tag found + // Handle non-base moved references + if (!base && mref.mRefNum.mIndex != 0) { - // there is a requirement for a placeholder where the original object was - // - // see the forum discussions here for more details: - // https://forum.openmw.org/viewtopic.php?f=6&t=577&start=30 + // Moved references must have a link back to their original cell + // See discussion: https://forum.openmw.org/viewtopic.php?f=6&t=577&start=30 ref.mOriginalCell = cell2.mId; - // It is not always possibe to ignore moved references sub-record and - // calculate from coordinates. Some mods may place the ref in positions - // outside normal bounds, resulting in non sensical cell id's. This often - // happens if the moved ref was deleted. - // - // Use the target cell from the MVRF tag but if different output an error - // message + // Some mods may move references outside of the bounds, which often happens they are deleted. + // This results in nonsensical autocalculated cell IDs, so we must use the record target cell. + + // Log a warning if the record target cell is different if (index.first != mref.mTarget[0] || index.second != mref.mTarget[1]) { - Log(Debug::Warning) << "Warning: the Position of moved ref " - << ref.mRefID << " does not match the target cell"; - Log(Debug::Warning) << "Position: #" << index.first << " " << index.second - <<", Target #"<< mref.mTarget[0] << " " << mref.mTarget[1]; - - stream.clear(); - stream << "#" << mref.mTarget[0] << " " << mref.mTarget[1]; - ref.mCell = stream.str(); // overwrite + std::string indexCell = ref.mCell; + ref.mCell = "#" + std::to_string(mref.mTarget[0]) + " " + std::to_string(mref.mTarget[1]); + + CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Cell, mCells.getId (cellIndex)); + messages.add(id, "The position of the moved reference " + ref.mRefID + " (cell " + indexCell + ")" + " does not match the target cell (" + ref.mCell + ")", + std::string(), CSMDoc::Message::Severity_Warning); } } } @@ -87,7 +75,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Cell, mCells.getId (cellIndex)); - messages.add (id, "Attempt to delete a non-existing reference"); + messages.add (id, "Attempt to delete a non-existent reference"); continue; } @@ -140,7 +128,5 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool std::string CSMWorld::RefCollection::getNewId() { - std::ostringstream stream; - stream << "ref#" << mNextId++; - return stream.str(); + return "ref#" + std::to_string(mNextId++); } diff --git a/apps/opencs/model/world/resources.cpp b/apps/opencs/model/world/resources.cpp index 5bf0267bb..b40ab1389 100644 --- a/apps/opencs/model/world/resources.cpp +++ b/apps/opencs/model/world/resources.cpp @@ -77,7 +77,7 @@ int CSMWorld::Resources::getIndex (const std::string& id) const std::ostringstream stream; stream << "Invalid resource: " << mBaseDirectory << '/' << id; - throw std::runtime_error (stream.str().c_str()); + throw std::runtime_error (stream.str()); } return index; diff --git a/apps/opencs/model/world/resourcetable.cpp b/apps/opencs/model/world/resourcetable.cpp index f55f87873..0e7864e48 100644 --- a/apps/opencs/model/world/resourcetable.cpp +++ b/apps/opencs/model/world/resourcetable.cpp @@ -110,7 +110,11 @@ QModelIndex CSMWorld::ResourceTable::parent (const QModelIndex& index) const QModelIndex CSMWorld::ResourceTable::getModelIndex (const std::string& id, int column) const { - return index (mResources->getIndex (id), column); + int row = mResources->searchId(id); + if (row != -1) + return index (row, column); + + return QModelIndex(); } int CSMWorld::ResourceTable::searchColumnIndex (Columns::ColumnId id) const diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index 026625795..0a3a950e0 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -670,27 +670,40 @@ void CSVRender::Object::apply (CSMWorld::CommandMacro& commands) if (mOverrideFlags & Override_Position) { - for (int i=0; i<3; ++i) + //Do cell check first so positions can be compared + const CSMWorld::CellRef& ref = collection.getRecord(recordIndex).get(); + + if (CSMWorld::CellCoordinates::isExteriorCell(ref.mCell)) { - int column = collection.findColumnIndex (static_cast ( - CSMWorld::Columns::ColumnId_PositionXPos+i)); + // Find cell index at new position + std::pair cellIndex = CSMWorld::CellCoordinates::coordinatesToCellIndex( + mPositionOverride.pos[0], mPositionOverride.pos[1]); + std::pair originalIndex = ref.getCellIndex(); - commands.push (new CSMWorld::ModifyCommand (*model, - model->index (recordIndex, column), mPositionOverride.pos[i])); - } + int cellColumn = collection.findColumnIndex (static_cast ( + CSMWorld::Columns::ColumnId_Cell)); + int refNumColumn = collection.findColumnIndex (static_cast ( + CSMWorld::Columns::ColumnId_RefNum)); + + if (cellIndex != originalIndex) + { + /// \todo figure out worldspace (not important until multiple worldspaces are supported) + std::string cellId = CSMWorld::CellCoordinates (cellIndex).getId (""); - int column = collection.findColumnIndex (static_cast ( - CSMWorld::Columns::ColumnId_Cell)); + commands.push (new CSMWorld::ModifyCommand (*model, + model->index (recordIndex, cellColumn), QString::fromUtf8 (cellId.c_str()))); + commands.push (new CSMWorld::ModifyCommand( *model, + model->index (recordIndex, refNumColumn), 0)); + } + } - if (CSMWorld::CellCoordinates::isExteriorCell(collection.getRecord (recordIndex).get().mCell)) + for (int i=0; i<3; ++i) { - std::pair cellIndex = collection.getRecord (recordIndex).get().getCellIndex(); - - /// \todo figure out worldspace (not important until multiple worldspaces are supported) - std::string cellId = CSMWorld::CellCoordinates (cellIndex).getId (""); + int column = collection.findColumnIndex (static_cast ( + CSMWorld::Columns::ColumnId_PositionXPos+i)); commands.push (new CSMWorld::ModifyCommand (*model, - model->index (recordIndex, column), QString::fromUtf8 (cellId.c_str()))); + model->index (recordIndex, column), mPositionOverride.pos[i])); } } diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index b03cf8fdb..4b129d32a 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -150,10 +150,8 @@ std::string CSVWorld::SceneSubView::getTitle() const void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::UniversalId& id) { setUniversalId(id); - std::ostringstream stream; - stream << "Scene: " << getUniversalId().getId(); - mTitle = stream.str(); + mTitle = "Scene: " + getUniversalId().getId(); setWindowTitle (QString::fromUtf8 (mTitle.c_str())); emit updateTitle(); } diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index c9b8127f6..58ad09451 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include "../../model/doc/document.hpp" #include "../../model/world/universalid.hpp" #include "../../model/world/data.hpp" @@ -210,18 +212,28 @@ void CSVWorld::ScriptSubView::useHint (const std::string& hint) unsigned line = 0, column = 0; char c; std::istringstream stream (hint.c_str()+1); - switch(hint[0]){ + switch(hint[0]) + { case 'R': case 'r': { QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn); QString source = mModel->data (index).toString(); + unsigned stringSize = source.length(); unsigned pos, dummy; if (!(stream >> c >> dummy >> pos) ) return; - for (unsigned i = 0; i <= pos; ++i){ - if (source[i] == '\n'){ + if (pos > stringSize) + { + Log(Debug::Warning) << "CSVWorld::ScriptSubView: requested position is higher than actual string length"; + pos = stringSize; + } + + for (unsigned i = 0; i <= pos; ++i) + { + if (source[i] == '\n') + { ++line; column = i+1; } @@ -231,7 +243,7 @@ void CSVWorld::ScriptSubView::useHint (const std::string& hint) } case 'l': if (!(stream >> c >> line >> column)) - return; + return; } QTextCursor cursor = mEditor->textCursor(); diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index 8cdb2d2db..fef805d56 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -1,5 +1,6 @@ #include "util.hpp" +#include #include #include @@ -214,7 +215,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO case CSMWorld::ColumnBase::Display_UnsignedInteger8: { DialogueSpinBox *sb = new DialogueSpinBox(parent); - sb->setRange(0, UCHAR_MAX); + sb->setRange(0, std::numeric_limits::max()); return sb; } @@ -225,7 +226,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO case CSMWorld::ColumnBase::Display_Float: { DialogueDoubleSpinBox *dsb = new DialogueDoubleSpinBox(parent); - dsb->setRange(-FLT_MAX, FLT_MAX); + dsb->setRange(-std::numeric_limits::max(), std::numeric_limits::max()); dsb->setSingleStep(0.01f); dsb->setDecimals(3); return dsb; @@ -234,7 +235,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO case CSMWorld::ColumnBase::Display_Double: { DialogueDoubleSpinBox *dsb = new DialogueDoubleSpinBox(parent); - dsb->setRange(-FLT_MAX, FLT_MAX); + dsb->setRange(-std::numeric_limits::max(), std::numeric_limits::max()); dsb->setSingleStep(0.01f); dsb->setDecimals(6); return dsb; diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index fcb8e216f..416159edd 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -245,14 +245,23 @@ bool OMW::Engine::frame(float frametime) */ } + // update physics + osg::Timer_t beforePhysicsTick = osg::Timer::instance()->tick(); + if (mEnvironment.getStateManager()->getState()!= + MWBase::StateManager::State_NoGame) + { + mEnvironment.getWorld()->updatePhysics(frametime, guiActive); + } + osg::Timer_t afterPhysicsTick = osg::Timer::instance()->tick(); + // update world - osg::Timer_t beforePhysicsTick = osg::Timer::instance()->tick();; + osg::Timer_t beforeWorldTick = osg::Timer::instance()->tick(); if (mEnvironment.getStateManager()->getState()!= MWBase::StateManager::State_NoGame) { mEnvironment.getWorld()->update(frametime, guiActive); } - osg::Timer_t afterPhysicsTick = osg::Timer::instance()->tick(); + osg::Timer_t afterWorldTick = osg::Timer::instance()->tick(); // update GUI mEnvironment.getWindowManager()->onFrame(frametime); @@ -271,6 +280,10 @@ bool OMW::Engine::frame(float frametime) stats->setAttribute(frameNumber, "physics_time_taken", osg::Timer::instance()->delta_s(beforePhysicsTick, afterPhysicsTick)); stats->setAttribute(frameNumber, "physics_time_end", osg::Timer::instance()->delta_s(mStartTick, afterPhysicsTick)); + stats->setAttribute(frameNumber, "world_time_begin", osg::Timer::instance()->delta_s(mStartTick, beforeWorldTick)); + stats->setAttribute(frameNumber, "world_time_taken", osg::Timer::instance()->delta_s(beforeWorldTick, afterWorldTick)); + stats->setAttribute(frameNumber, "world_time_end", osg::Timer::instance()->delta_s(mStartTick, afterWorldTick)); + if (stats->collectStats("resource")) { mResourceSystem->reportStats(frameNumber, stats); @@ -819,10 +832,12 @@ void OMW::Engine::go() statshandler->addUserStatsLine("Script", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), "script_time_taken", 1000.0, true, false, "script_time_begin", "script_time_end", 10000); - statshandler->addUserStatsLine("Mechanics", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), + statshandler->addUserStatsLine("Mech", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), "mechanics_time_taken", 1000.0, true, false, "mechanics_time_begin", "mechanics_time_end", 10000); - statshandler->addUserStatsLine("Physics", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), + statshandler->addUserStatsLine("Phys", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), "physics_time_taken", 1000.0, true, false, "physics_time_begin", "physics_time_end", 10000); + statshandler->addUserStatsLine("World", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), + "world_time_taken", 1000.0, true, false, "world_time_begin", "world_time_end", 10000); mViewer->addEventHandler(statshandler); diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index eea8033db..b51359356 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -523,6 +523,7 @@ namespace MWBase /// \return pointer to created record virtual void update (float duration, bool paused) = 0; + virtual void updatePhysics (float duration, bool paused) = 0; virtual void updateWindowManager () = 0; diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index e83424a59..64d0130a1 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -775,34 +775,59 @@ namespace MWClass std::string Creature::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const { - const MWWorld::Store &store = MWBase::Environment::get().getWorld()->getStore().get(); - int type = getSndGenTypeFromName(ptr, name); - if(type >= 0) - { - std::vector sounds; - std::vector fallbacksounds; + if (type < 0) + return std::string(); + + std::vector sounds; + std::vector fallbacksounds; - MWWorld::LiveCellRef* ref = ptr.get(); + MWWorld::LiveCellRef* ref = ptr.get(); - const std::string& ourId = (ref->mBase->mOriginal.empty()) ? ptr.getCellRef().getRefId() : ref->mBase->mOriginal; + const std::string& ourId = (ref->mBase->mOriginal.empty()) ? ptr.getCellRef().getRefId() : ref->mBase->mOriginal; + + const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); + auto sound = store.get().begin(); + while (sound != store.get().end()) + { + if (type == sound->mType && !sound->mCreature.empty() && Misc::StringUtils::ciEqual(ourId, sound->mCreature)) + sounds.push_back(&*sound); + if (type == sound->mType && sound->mCreature.empty()) + fallbacksounds.push_back(&*sound); + ++sound; + } - MWWorld::Store::iterator sound = store.begin(); - while (sound != store.end()) + if (sounds.empty()) + { + const std::string model = getModel(ptr); + if (!model.empty()) { - if (type == sound->mType && !sound->mCreature.empty() && (Misc::StringUtils::ciEqual(ourId, sound->mCreature))) - sounds.push_back(&*sound); - if (type == sound->mType && sound->mCreature.empty()) - fallbacksounds.push_back(&*sound); - ++sound; + for (const ESM::Creature &creature : store.get()) + { + if (creature.mId != ourId && creature.mOriginal != ourId && !creature.mModel.empty() + && Misc::StringUtils::ciEqual(model, "meshes\\" + creature.mModel)) + { + const std::string& fallbackId = !creature.mOriginal.empty() ? creature.mOriginal : creature.mId; + sound = store.get().begin(); + while (sound != store.get().end()) + { + if (type == sound->mType && !sound->mCreature.empty() + && Misc::StringUtils::ciEqual(fallbackId, sound->mCreature)) + sounds.push_back(&*sound); + ++sound; + } + break; + } + } } - if (!sounds.empty()) - return sounds[Misc::Rng::rollDice(sounds.size())]->mSound; - if (!fallbacksounds.empty()) - return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size())]->mSound; } - return ""; + if (!sounds.empty()) + return sounds[Misc::Rng::rollDice(sounds.size())]->mSound; + if (!fallbacksounds.empty()) + return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size())]->mSound; + + return std::string(); } MWWorld::Ptr Creature::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index fb763fafd..131a8a0de 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1357,6 +1357,17 @@ namespace MWClass const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(ref->mBase->mRace); + // Race weight should not affect 1st-person meshes, otherwise it will change hand proportions and can break aiming. + if (ptr == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->isFirstPerson()) + { + if (ref->mBase->isMale()) + scale *= race->mData.mHeight.mMale; + else + scale *= race->mData.mHeight.mFemale; + + return; + } + if (ref->mBase->isMale()) { scale.x() *= race->mData.mWeight.mMale; @@ -1369,7 +1380,6 @@ namespace MWClass scale.y() *= race->mData.mWeight.mFemale; scale.z() *= race->mData.mHeight.mFemale; } - } int Npc::getServices(const MWWorld::ConstPtr &actor) const diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 4b1e802a2..257d3c5e1 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -476,8 +476,7 @@ namespace MWGui icon.insert(slashPos+1, "b_"); icon = MWBase::Environment::get().getWindowManager()->correctIconPath(icon); - mSpellImage->setItem(MWWorld::Ptr()); - mSpellImage->setIcon(icon); + mSpellImage->setSpellIcon(icon); } void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index 73428c034..c33c4efad 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -15,6 +15,7 @@ namespace MWGui class DragAndDrop; class SpellIcons; class ItemWidget; + class SpellWidget; class HUD : public WindowBase, public LocalMapBase { @@ -64,7 +65,8 @@ namespace MWGui MyGUI::ProgressBar *mHealth, *mMagicka, *mStamina, *mEnemyHealth, *mDrowning; MyGUI::Widget* mHealthFrame; MyGUI::Widget *mWeapBox, *mSpellBox, *mSneakBox; - ItemWidget *mWeapImage, *mSpellImage; + ItemWidget *mWeapImage; + SpellWidget *mSpellImage; MyGUI::ProgressBar *mWeapStatus, *mSpellStatus; MyGUI::Widget *mEffectBox, *mMinimapBox; MyGUI::Button* mMinimapButton; diff --git a/apps/openmw/mwgui/itemwidget.cpp b/apps/openmw/mwgui/itemwidget.cpp index 223bced4f..ba3039a16 100644 --- a/apps/openmw/mwgui/itemwidget.cpp +++ b/apps/openmw/mwgui/itemwidget.cpp @@ -43,6 +43,7 @@ namespace MWGui void ItemWidget::registerComponents() { MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); } void ItemWidget::initialiseOverride() @@ -153,4 +154,14 @@ namespace MWGui setIcon(ptr); } + void SpellWidget::setSpellIcon(const std::string& icon) + { + if (mFrame) + mFrame->setImageTexture(""); + if (mItemShadow) + mItemShadow->setImageTexture(icon); + if (mItem) + mItem->setImageTexture(icon); + } + } diff --git a/apps/openmw/mwgui/itemwidget.hpp b/apps/openmw/mwgui/itemwidget.hpp index dd1717d11..e9b9ba1d5 100644 --- a/apps/openmw/mwgui/itemwidget.hpp +++ b/apps/openmw/mwgui/itemwidget.hpp @@ -40,7 +40,7 @@ namespace MWGui void setIcon (const MWWorld::Ptr& ptr); void setFrame (const std::string& frame, const MyGUI::IntCoord& coord); - private: + protected: virtual void initialiseOverride(); MyGUI::ImageBox* mItem; @@ -52,6 +52,14 @@ namespace MWGui std::string mCurrentFrame; }; + class SpellWidget : public ItemWidget + { + MYGUI_RTTI_DERIVED(SpellWidget) + public: + + void setSpellIcon (const std::string& icon); + }; + } #endif diff --git a/apps/openmw/mwgui/layout.cpp b/apps/openmw/mwgui/layout.cpp index 6bdb1a9f4..3035adebb 100644 --- a/apps/openmw/mwgui/layout.cpp +++ b/apps/openmw/mwgui/layout.cpp @@ -58,7 +58,10 @@ namespace MWGui void Layout::setTitle(const std::string& title) { - static_cast(mMainWidget)->setCaptionWithReplacing(title); + MyGUI::Window* window = static_cast(mMainWidget); + + if (window->getCaption() != title) + window->setCaptionWithReplacing(title); } MyGUI::Widget* Layout::getWidget(const std::string &_name) diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index e58993a55..df292cfaa 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -125,9 +125,7 @@ namespace MWGui for (int i=0; ids[i]; ++i) if (ids[i]==id) { - std::ostringstream valueString; - valueString << value.getModified(); - setText (id, valueString.str()); + setText (id, std::to_string(value.getModified())); MyGUI::TextBox* box; getWidget(box, id); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index b8a866402..a1879c2f9 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -599,9 +599,7 @@ namespace MWGui std::string ToolTips::toString(const int value) { - std::ostringstream stream; - stream << value; - return stream.str(); + return std::to_string(value); } std::string ToolTips::getWeightString(const float weight, const std::string& prefix) diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index f8116d4a3..f0ed4c317 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -87,10 +87,7 @@ namespace MWGui else toAdd->setUserString("interior","n"); - std::ostringstream oss; - oss << price; - toAdd->setUserString("price",oss.str()); - + toAdd->setUserString("price", std::to_string(price)); toAdd->setCaptionWithReplacing("#{sCell=" + name + "} - " + MyGUI::utility::toString(price)+"#{sgp}"); toAdd->setSize(mDestinationsView->getWidth(),lineHeight); toAdd->eventMouseWheel += MyGUI::newDelegate(this, &TravelWindow::onMouseWheel); diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index c9aa8e0f7..f31f9fb18 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -922,8 +922,13 @@ namespace MWMechanics bool hasSummonEffect = false; for (MagicEffects::Collection::const_iterator it = effects.begin(); it != effects.end(); ++it) + { if (isSummoningEffect(it->first.mId)) + { hasSummonEffect = true; + break; + } + } if (!creatureStats.getSummonedCreatureMap().empty() || !creatureStats.getSummonedCreatureGraveyard().empty() || hasSummonEffect) { @@ -1524,6 +1529,14 @@ namespace MWMechanics bool cellChanged = world->hasCellChanged(); MWWorld::Ptr actor = iter->first; // make a copy of the map key to avoid it being invalidated when the player teleports updateActor(actor, duration); + + // Looping magic VFX update + // Note: we need to do this before any of the animations are updated. + // Reaching the text keys may trigger Hit / Spellcast (and as such, particles), + // so updating VFX immediately after that would just remove the particle effects instantly. + // There needs to be a magic effect update in between. + ctrl->updateContinuousVfx(); + if (!cellChanged && world->hasCellChanged()) { return; // for now abort update of the old cell when cell changes by teleportation magic effect @@ -1609,14 +1622,6 @@ namespace MWMechanics timerUpdateEquippedLight += duration; mTimerDisposeSummonsCorpses += duration; - // Looping magic VFX update - // Note: we need to do this before any of the animations are updated. - // Reaching the text keys may trigger Hit / Spellcast (and as such, particles), - // so updating VFX immediately after that would just remove the particle effects instantly. - // There needs to be a magic effect update in between. - for(PtrActorMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter) - iter->second->getCharacterController()->updateContinuousVfx(); - // Animation/movement update CharacterController* playerCharacter = nullptr; for(PtrActorMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter) diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 837d49f38..d2a57c354 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -1,7 +1,5 @@ #include "aiwander.hpp" -#include - #include #include #include diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index b0c699ecd..13c06225a 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -167,9 +167,8 @@ void MWMechanics::Alchemy::updateEffects() if (magicEffect->mData.mBaseCost<=0) { - std::ostringstream os; - os << "invalid base cost for magic effect " << iter->mId; - throw std::runtime_error (os.str()); + const std::string os = "invalid base cost for magic effect " + std::to_string(iter->mId); + throw std::runtime_error (os); } float fPotionT1MagMul = diff --git a/apps/openmw/mwmechanics/autocalcspell.cpp b/apps/openmw/mwmechanics/autocalcspell.cpp index 144449cf0..f55bebfc9 100644 --- a/apps/openmw/mwmechanics/autocalcspell.cpp +++ b/apps/openmw/mwmechanics/autocalcspell.cpp @@ -240,19 +240,6 @@ namespace MWMechanics return true; } - ESM::Skill::SkillEnum mapSchoolToSkill(int school) - { - std::map schoolSkillMap; // maps spell school to skill id - schoolSkillMap[0] = ESM::Skill::Alteration; - schoolSkillMap[1] = ESM::Skill::Conjuration; - schoolSkillMap[3] = ESM::Skill::Illusion; - schoolSkillMap[2] = ESM::Skill::Destruction; - schoolSkillMap[4] = ESM::Skill::Mysticism; - schoolSkillMap[5] = ESM::Skill::Restoration; - assert(schoolSkillMap.find(school) != schoolSkillMap.end()); - return schoolSkillMap[school]; - } - void calcWeakestSchool (const ESM::Spell* spell, const int* actorSkills, int& effectiveSchool, float& skillTerm) { // Morrowind for some reason uses a formula slightly different from magicka cost calculation @@ -288,7 +275,7 @@ namespace MWMechanics if (effect.mRange == ESM::RT_Target) x *= 1.5f; - float s = 2.f * actorSkills[mapSchoolToSkill(magicEffect->mData.mSchool)]; + float s = 2.f * actorSkills[spellSchoolToSkill(magicEffect->mData.mSchool)]; if (s - x < minChance) { minChance = s - x; @@ -308,7 +295,7 @@ namespace MWMechanics float skillTerm = 0; if (effectiveSchool != -1) - skillTerm = 2.f * actorSkills[mapSchoolToSkill(effectiveSchool)]; + skillTerm = 2.f * actorSkills[spellSchoolToSkill(effectiveSchool)]; else calcWeakestSchool(spell, actorSkills, effectiveSchool, skillTerm); // Note effectiveSchool is unused after this diff --git a/apps/openmw/mwmechanics/autocalcspell.hpp b/apps/openmw/mwmechanics/autocalcspell.hpp index 6bf3e834b..50be8a5d9 100644 --- a/apps/openmw/mwmechanics/autocalcspell.hpp +++ b/apps/openmw/mwmechanics/autocalcspell.hpp @@ -1,9 +1,6 @@ #ifndef OPENMW_AUTOCALCSPELL_H #define OPENMW_AUTOCALCSPELL_H -#include -#include - #include #include #include @@ -22,8 +19,6 @@ std::vector autoCalcPlayerSpells(const int* actorSkills, const int* bool attrSkillCheck (const ESM::Spell* spell, const int* actorSkills, const int* actorAttributes); -ESM::Skill::SkillEnum mapSchoolToSkill(int school); - void calcWeakestSchool(const ESM::Spell* spell, const int* actorSkills, int& effectiveSchool, float& skillTerm); float calcAutoCastChance(const ESM::Spell* spell, const int* actorSkills, const int* actorAttributes, int effectiveSchool); diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 92e06bc7a..575bd9463 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -76,13 +76,6 @@ void wrap(float& rad) rad = std::fmod(rad-osg::PI, 2.0f*osg::PI)+osg::PI; } -std::string toString(int num) -{ - std::ostringstream stream; - stream << num; - return stream.str(); -} - std::string getBestAttack (const ESM::Weapon* weapon) { int slash = (weapon->mData.mSlash[0] + weapon->mData.mSlash[1])/2; @@ -251,13 +244,13 @@ public: std::string CharacterController::chooseRandomGroup (const std::string& prefix, int* num) const { int numAnims=0; - while (mAnimation->hasAnimation(prefix + toString(numAnims+1))) + while (mAnimation->hasAnimation(prefix + std::to_string(numAnims+1))) ++numAnims; int roll = Misc::Rng::rollDice(numAnims) + 1; // [1, numAnims] if (num) *num = roll; - return prefix + toString(roll); + return prefix + std::to_string(roll); } void CharacterController::refreshHitRecoilAnims(CharacterState& idle) @@ -799,7 +792,7 @@ void CharacterController::playDeath(float startpoint, CharacterState death) mCurrentDeath = "deathknockout"; break; default: - mCurrentDeath = "death" + toString(death - CharState_Death1 + 1); + mCurrentDeath = "death" + std::to_string(death - CharState_Death1 + 1); } mDeathState = death; diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index c47d3e248..d405ce6b7 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1,8 +1,5 @@ #include "mechanicsmanagerimp.hpp" -#include -#include - #include #include @@ -252,7 +249,7 @@ namespace MWMechanics // mWatchedTimeToStartDrowning = -1 for correct drowning state check, // if stats.getTimeToStartDrowning() == 0 already on game start MechanicsManager::MechanicsManager() - : mWatchedTimeToStartDrowning(-1), mWatchedStatsEmpty (true), mUpdatePlayer (true), mClassSelected (false), + : mWatchedLevel(-1), mWatchedTimeToStartDrowning(-1), mWatchedStatsEmpty (true), mUpdatePlayer (true), mClassSelected (false), mRaceSelected (false), mAI(true) { //buildPlayer no longer here, needs to be done explicitly after all subsystems are up and running @@ -377,7 +374,11 @@ namespace MWMechanics } } - winMgr->setValue("level", stats.getLevel()); + if(stats.getLevel() != mWatchedLevel) + { + mWatchedLevel = stats.getLevel(); + winMgr->setValue("level", mWatchedLevel); + } mWatchedStatsEmpty = false; @@ -393,10 +394,15 @@ namespace MWMechanics MWWorld::ContainerStoreIterator enchantItem = inv.getSelectedEnchantItem(); if (enchantItem != inv.end()) winMgr->setSelectedEnchantItem(*enchantItem); - else if (!winMgr->getSelectedSpell().empty()) - winMgr->setSelectedSpell(winMgr->getSelectedSpell(), int(MWMechanics::getSpellSuccessChance(winMgr->getSelectedSpell(), mWatched))); else - winMgr->unsetSelectedSpell(); + { + const std::string& spell = winMgr->getSelectedSpell(); + if (!spell.empty()) + winMgr->setSelectedSpell(spell, int(MWMechanics::getSpellSuccessChance(spell, mWatched))); + else + winMgr->unsetSelectedSpell(); + } + } if (mUpdatePlayer) diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index 84f4e568c..47e7c9200 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -30,6 +30,8 @@ namespace MWMechanics DynamicStat mWatchedMagicka; DynamicStat mWatchedFatigue; + int mWatchedLevel; + float mWatchedTimeToStartDrowning; bool mWatchedStatsEmpty; diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 3d1c4f474..7c62e8dba 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -152,20 +152,18 @@ float MWMechanics::NpcStats::getSkillProgressRequirement (int skillIndex, const float typeFactor = gmst.find ("fMiscSkillBonus")->mValue.getFloat(); for (int i=0; i<5; ++i) + { if (class_.mData.mSkills[i][0]==skillIndex) { typeFactor = gmst.find ("fMinorSkillBonus")->mValue.getFloat(); - break; } - - for (int i=0; i<5; ++i) - if (class_.mData.mSkills[i][1]==skillIndex) + else if (class_.mData.mSkills[i][1]==skillIndex) { typeFactor = gmst.find ("fMajorSkillBonus")->mValue.getFloat(); - break; } + } progressRequirement *= typeFactor; @@ -233,15 +231,14 @@ void MWMechanics::NpcStats::increaseSkill(int skillIndex, const ESM::Class &clas if (class_.mData.mSkills[k][0] == skillIndex) { mLevelProgress += gmst.find("iLevelUpMinorMult")->mValue.getInteger(); - increase = gmst.find("iLevelUpMajorMultAttribute")->mValue.getInteger(); + increase = gmst.find("iLevelUpMinorMultAttribute")->mValue.getInteger(); + break; } - } - for (int k=0; k<5; ++k) - { - if (class_.mData.mSkills[k][1] == skillIndex) + else if (class_.mData.mSkills[k][1] == skillIndex) { mLevelProgress += gmst.find("iLevelUpMajorMult")->mValue.getInteger(); - increase = gmst.find("iLevelUpMinorMultAttribute")->mValue.getInteger(); + increase = gmst.find("iLevelUpMajorMultAttribute")->mValue.getInteger(); + break; } } diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index bd5fc4b15..512e60611 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -1,6 +1,5 @@ #include "spellcasting.hpp" -#include #include #include @@ -519,8 +518,11 @@ namespace MWMechanics float magnitudeMult = 1; - if (!absorbed && target.getClass().isActor()) + if (target.getClass().isActor()) { + if (absorbed) + continue; + bool isHarmful = magicEffect->mData.mFlags & ESM::MagicEffect::Harmful; // Reflect harmful effects if (isHarmful && !reflected && !caster.isEmpty() && caster != target && !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable)) diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 555e9239e..5607fc0a6 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -1339,6 +1339,7 @@ namespace MWPhysics float slowFall = 1.f - std::max(0.f, std::min(1.f, effects.get(ESM::MagicEffect::SlowFall).getMagnitude() * 0.005f)); bool flying = world->isFlying(iter->first); + bool swimming = world->isSwimming(iter->first); bool wasOnGround = physicActor->getOnGround(); osg::Vec3f position = physicActor->getPosition(); @@ -1361,8 +1362,9 @@ namespace MWPhysics float heightDiff = position.z() - oldHeight; MWMechanics::CreatureStats& stats = iter->first.getClass().getCreatureStats(iter->first); - if ((numSteps > 0 && wasOnGround && physicActor->getOnGround()) || flying || world->isSwimming(iter->first) || slowFall < 1) - stats.land(iter->first == player); + bool isStillOnGround = (numSteps > 0 && wasOnGround && physicActor->getOnGround()); + if (isStillOnGround || flying || swimming || slowFall < 1) + stats.land(iter->first == player && (flying || swimming)); else if (heightDiff < 0) stats.addToFallHeight(-heightDiff); diff --git a/apps/openmw/mwrender/landmanager.cpp b/apps/openmw/mwrender/landmanager.cpp index 38c28a72a..e3b19ca47 100644 --- a/apps/openmw/mwrender/landmanager.cpp +++ b/apps/openmw/mwrender/landmanager.cpp @@ -2,8 +2,6 @@ #include -#include - #include #include "../mwbase/environment.hpp" @@ -21,9 +19,7 @@ LandManager::LandManager(int loadFlags) osg::ref_ptr LandManager::getLand(int x, int y) { - std::ostringstream id; - id << x << " " << y; - std::string idstr = id.str(); + std::string idstr = std::to_string(x) + " " + std::to_string(y); osg::ref_ptr obj = mCache->getRefFromObjectCache(idstr); if (obj) diff --git a/apps/openmw/mwrender/navmesh.hpp b/apps/openmw/mwrender/navmesh.hpp index 29205ca27..d329b895d 100644 --- a/apps/openmw/mwrender/navmesh.hpp +++ b/apps/openmw/mwrender/navmesh.hpp @@ -30,6 +30,11 @@ namespace MWRender void disable(); + bool isEnabled() const + { + return mEnabled; + } + private: osg::ref_ptr mRootNode; bool mEnabled; diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index e088728a0..920e09a69 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -317,8 +317,9 @@ void NpcAnimation::setViewMode(NpcAnimation::ViewMode viewMode) mWeaponSheathing = Settings::Manager::getBool("weapon sheathing", "Game"); mViewMode = viewMode; - rebuild(); + MWBase::Environment::get().getWorld()->scaleObject(mPtr, mPtr.getCellRef().getScale()); // apply race height after view change + rebuild(); setRenderBin(); } diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index a0f48ad27..882c9856f 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -1,7 +1,5 @@ #include "objects.hpp" -#include - #include #include diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 4d79fd3de..322c310a2 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -599,28 +599,8 @@ namespace MWRender mWater->update(dt); } - const auto navMeshes = mNavigator.getNavMeshes(); + updateNavMesh(); - auto it = navMeshes.begin(); - for (std::size_t i = 0; it != navMeshes.end() && i < mNavMeshNumber; ++i) - ++it; - if (it == navMeshes.end()) - { - mNavMesh->reset(); - } - else - { - try - { - const auto locked = it->second.lockConst(); - mNavMesh->update(locked->getValue(), mNavMeshNumber, locked->getGeneration(), - locked->getNavMeshRevision(), mNavigator.getSettings()); - } - catch (const std::exception& e) - { - Log(Debug::Error) << "NavMesh render update exception: " << e.what(); - } - } mCamera->update(dt, paused); osg::Vec3f focal, cameraPos; @@ -1402,4 +1382,33 @@ namespace MWRender { mNavMeshNumber = value; } + + void RenderingManager::updateNavMesh() + { + if (!mNavMesh->isEnabled()) + return; + + const auto navMeshes = mNavigator.getNavMeshes(); + + auto it = navMeshes.begin(); + for (std::size_t i = 0; it != navMeshes.end() && i < mNavMeshNumber; ++i) + ++it; + if (it == navMeshes.end()) + { + mNavMesh->reset(); + } + else + { + try + { + const auto locked = it->second.lockConst(); + mNavMesh->update(locked->getValue(), mNavMeshNumber, locked->getGeneration(), + locked->getNavMeshRevision(), mNavigator.getSettings()); + } + catch (const std::exception& e) + { + Log(Debug::Error) << "NavMesh render update exception: " << e.what(); + } + } + } } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 7a4500ac9..2a48097bd 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -240,6 +240,8 @@ namespace MWRender void renderCameraToImage(osg::Camera *camera, osg::Image *image, int w, int h); + void updateNavMesh(); + osg::ref_ptr getIntersectionVisitor(osgUtil::Intersector* intersector, bool ignorePlayer, bool ignoreActors); osg::ref_ptr mIntersectionVisitor; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 6d0c75a36..9cbc4c60a 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -517,6 +517,12 @@ namespace MWScript std::string effect = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); + if (!ptr.getClass().isActor()) + { + runtime.push(0); + return; + } + char *end; long key = strtol(effect.c_str(), &end, 10); if(key < 0 || key > 32767 || *end != '\0') @@ -745,6 +751,12 @@ namespace MWScript std::string id = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); + if (!ptr.getClass().isActor()) + { + runtime.push(0); + return; + } + const MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); runtime.push(stats.getActiveSpells().isSpellActive(id) || stats.getSpells().isSpellActive(id)); } diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 34e490c4d..1eaedb19a 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -583,7 +583,7 @@ namespace MWScript Interpreter::Type_Integer value = 0; - if (ptr.getClass().getCreatureStats(ptr).getSpells().hasSpell(id)) + if (ptr.getClass().isActor() && ptr.getClass().getCreatureStats(ptr).getSpells().hasSpell(id)) value = 1; runtime.push (value); diff --git a/apps/openmw/mwstate/character.cpp b/apps/openmw/mwstate/character.cpp index 4f7d365b4..a8fffaec6 100644 --- a/apps/openmw/mwstate/character.cpp +++ b/apps/openmw/mwstate/character.cpp @@ -58,10 +58,8 @@ void MWState::Character::addSlot (const ESM::SavedGame& profile) int i=0; while (boost::filesystem::exists(slot.mPath)) { - std::ostringstream test; - test << stream.str(); - test << " - " << ++i; - slot.mPath = mPath / (test.str() + ext); + const std::string test = stream.str() + " - " + std::to_string(++i); + slot.mPath = mPath / (test + ext); } slot.mProfile = profile; diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 3bf66a5a1..89e5357f0 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -1,6 +1,7 @@ #include "cellpreloader.hpp" #include +#include #include #include @@ -251,7 +252,7 @@ namespace MWWorld { // throw out oldest cell to make room PreloadMap::iterator oldestCell = mPreloadCells.begin(); - double oldestTimestamp = DBL_MAX; + double oldestTimestamp = std::numeric_limits::max(); double threshold = 1.0; // seconds for (PreloadMap::iterator it = mPreloadCells.begin(); it != mPreloadCells.end(); ++it) { diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index c85e3d30e..fe92f570d 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -140,8 +140,6 @@ void ESMStore::setUp(bool validateRecords) mMagicEffects.setUp(); mAttributes.setUp(); mDialogs.setUp(); - mStatics.setUp(); - mDoors.setUp(); if (validateRecords) validate(); diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index f4d792118..d170a32c5 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -170,19 +170,19 @@ namespace MWWorld /// Insert a custom record (i.e. with a generated ID that will not clash will pre-existing records) template - const T *insert(const T &x) { - std::ostringstream id; - id << "$dynamic" << mDynamicCount++; + const T *insert(const T &x) + { + const std::string id = "$dynamic" + std::to_string(mDynamicCount++); Store &store = const_cast &>(get()); - if (store.search(id.str()) != 0) { - std::ostringstream msg; - msg << "Try to override existing record '" << id.str() << "'"; - throw std::runtime_error(msg.str()); + if (store.search(id) != 0) + { + const std::string msg = "Try to override existing record '" + id + "'"; + throw std::runtime_error(msg); } T record = x; - record.mId = id.str(); + record.mId = id; T *ptr = store.insert(record); for (iterator it = mStores.begin(); it != mStores.end(); ++it) { @@ -208,15 +208,15 @@ namespace MWWorld } template - const T *insertStatic(const T &x) { - std::ostringstream id; - id << "$dynamic" << mDynamicCount++; + const T *insertStatic(const T &x) + { + const std::string id = "$dynamic" + std::to_string(mDynamicCount++); Store &store = const_cast &>(get()); - if (store.search(id.str()) != 0) { - std::ostringstream msg; - msg << "Try to override existing record '" << id.str() << "'"; - throw std::runtime_error(msg.str()); + if (store.search(id) != 0) + { + const std::string msg = "Try to override existing record '" + id + "'"; + throw std::runtime_error(msg); } T record = x; @@ -247,20 +247,22 @@ namespace MWWorld } template <> - inline const ESM::NPC *ESMStore::insert(const ESM::NPC &npc) { - std::ostringstream id; - id << "$dynamic" << mDynamicCount++; + inline const ESM::NPC *ESMStore::insert(const ESM::NPC &npc) + { + const std::string id = "$dynamic" + std::to_string(mDynamicCount++); - if (Misc::StringUtils::ciEqual(npc.mId, "player")) { + if (Misc::StringUtils::ciEqual(npc.mId, "player")) + { return mNpcs.insert(npc); - } else if (mNpcs.search(id.str()) != 0) { - std::ostringstream msg; - msg << "Try to override existing record '" << id.str() << "'"; - throw std::runtime_error(msg.str()); + } + else if (mNpcs.search(id) != 0) + { + const std::string msg = "Try to override existing record '" + id + "'"; + throw std::runtime_error(msg); } ESM::NPC record = npc; - record.mId = id.str(); + record.mId = id; ESM::NPC *ptr = mNpcs.insert(record); mIds[ptr->mId] = ESM::REC_NPC_; diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index b771d3768..9853a9163 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -449,14 +449,6 @@ namespace MWWorld const ESM::BirthSign* sign = world.getStore().get().search (player.mBirthsign); if (!sign) throw std::runtime_error ("invalid player state record (birthsign does not exist)"); - - // To handle the case where a birth sign was edited in between play sessions (does not yet handle removing the old spells) - // Also needed for ess-imported savegames which do not specify the birtsign spells in the player's spell list. - for (std::vector::const_iterator iter (sign->mPowers.mList.begin()); - iter!=sign->mPowers.mList.end(); ++iter) - { - getPlayer().getClass().getCreatureStats(getPlayer()).getSpells().add (*iter); - } } mCurrentCrimeId = player.mCurrentCrimeId; diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 4698ba011..ff449acf5 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -109,11 +109,10 @@ namespace if (projectileEffects.mList.size() > 1) // insert a VFX_Multiple projectile if there are multiple projectile effects { - std::ostringstream ID; - ID << "VFX_Multiple" << effects->mList.size(); + const std::string ID = "VFX_Multiple" + std::to_string(effects->mList.size()); std::vector::iterator it; it = projectileIDs.begin(); - it = projectileIDs.insert(it, ID.str()); + it = projectileIDs.insert(it, ID); } return projectileEffects; } diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 7df61bec3..631b6e081 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -9,7 +9,6 @@ #include #include -#include namespace { @@ -102,10 +101,10 @@ namespace MWWorld const T *IndexedStore::find(int index) const { const T *ptr = search(index); - if (ptr == 0) { - std::ostringstream msg; - msg << T::getRecordType() << " with index " << index << " not found"; - throw std::runtime_error(msg.str()); + if (ptr == 0) + { + const std::string msg = T::getRecordType() + " with index " + std::to_string(index) + " not found"; + throw std::runtime_error(msg); } return ptr; } @@ -171,10 +170,10 @@ namespace MWWorld const T *Store::find(const std::string &id) const { const T *ptr = search(id); - if (ptr == 0) { - std::ostringstream msg; - msg << T::getRecordType() << " '" << id << "' not found"; - throw std::runtime_error(msg.str()); + if (ptr == 0) + { + const std::string msg = T::getRecordType() + " '" + id + "' not found"; + throw std::runtime_error(msg); } return ptr; } @@ -184,14 +183,13 @@ namespace MWWorld const T *ptr = searchRandom(id); if(ptr == 0) { - std::ostringstream msg; - msg << T::getRecordType() << " starting with '"< - RecordId Store::load(ESM::ESMReader &esm) + RecordId Store::load(ESM::ESMReader &esm) { T record; bool isDeleted = false; @@ -364,10 +362,10 @@ namespace MWWorld const ESM::LandTexture *Store::find(size_t index, size_t plugin) const { const ESM::LandTexture *ptr = search(index, plugin); - if (ptr == 0) { - std::ostringstream msg; - msg << "Land texture with index " << index << " not found"; - throw std::runtime_error(msg.str()); + if (ptr == 0) + { + const std::string msg = "Land texture with index " + std::to_string(index) + " not found"; + throw std::runtime_error(msg); } return ptr; } @@ -456,10 +454,10 @@ namespace MWWorld const ESM::Land *Store::find(int x, int y) const { const ESM::Land *ptr = search(x, y); - if (ptr == 0) { - std::ostringstream msg; - msg << "Land at (" << x << ", " << y << ") not found"; - throw std::runtime_error(msg.str()); + if (ptr == 0) + { + const std::string msg = "Land at (" + std::to_string(x) + ", " + std::to_string(y) + ") not found"; + throw std::runtime_error(msg); } return ptr; } @@ -591,20 +589,20 @@ namespace MWWorld const ESM::Cell *Store::find(const std::string &id) const { const ESM::Cell *ptr = search(id); - if (ptr == 0) { - std::ostringstream msg; - msg << "Cell '" << id << "' not found"; - throw std::runtime_error(msg.str()); + if (ptr == 0) + { + const std::string msg = "Cell '" + id + "' not found"; + throw std::runtime_error(msg); } return ptr; } const ESM::Cell *Store::find(int x, int y) const { const ESM::Cell *ptr = search(x, y); - if (ptr == 0) { - std::ostringstream msg; - msg << "Exterior at (" << x << ", " << y << ") not found"; - throw std::runtime_error(msg.str()); + if (ptr == 0) + { + const std::string msg = "Exterior at (" + std::to_string(x) + ", " + std::to_string(y) + ") not found"; + throw std::runtime_error(msg); } return ptr; } @@ -784,13 +782,10 @@ namespace MWWorld } ESM::Cell *Store::insert(const ESM::Cell &cell) { - if (search(cell) != 0) { - std::ostringstream msg; - msg << "Failed to create "; - msg << ((cell.isExterior()) ? "exterior" : "interior"); - msg << " cell"; - - throw std::runtime_error(msg.str()); + if (search(cell) != 0) + { + const std::string cellType = (cell.isExterior()) ? "exterior" : "interior"; + throw std::runtime_error("Failed to create " + cellType + " cell"); } ESM::Cell *ptr; if (cell.isExterior()) { @@ -931,9 +926,8 @@ namespace MWWorld const ESM::Pathgrid* pathgrid = search(x,y); if (!pathgrid) { - std::ostringstream msg; - msg << "Pathgrid in cell '" << x << " " << y << "' not found"; - throw std::runtime_error(msg.str()); + const std::string msg = "Pathgrid in cell '" + std::to_string(x) + " " + std::to_string(y) + "' not found"; + throw std::runtime_error(msg); } return pathgrid; } @@ -942,9 +936,8 @@ namespace MWWorld const ESM::Pathgrid* pathgrid = search(name); if (!pathgrid) { - std::ostringstream msg; - msg << "Pathgrid in cell '" << name << "' not found"; - throw std::runtime_error(msg.str()); + const std::string msg = "Pathgrid in cell '" + name + "' not found"; + throw std::runtime_error(msg); } return pathgrid; } @@ -998,10 +991,10 @@ namespace MWWorld const ESM::Attribute *Store::find(size_t index) const { const ESM::Attribute *ptr = search(index); - if (ptr == 0) { - std::ostringstream msg; - msg << "Attribute with index " << index << " not found"; - throw std::runtime_error(msg.str()); + if (ptr == 0) + { + const std::string msg = "Attribute with index " + std::to_string(index) + " not found"; + throw std::runtime_error(msg); } return ptr; } @@ -1053,58 +1046,6 @@ namespace MWWorld } } - template<> - void Store::setUp() - { - // Load default marker definitions, if game files do not have them for some reason - std::pair markers[] = { - std::make_pair("divinemarker", "marker_divine.nif"), - std::make_pair("doormarker", "marker_arrow.nif"), - std::make_pair("northmarker", "marker_north.nif"), - std::make_pair("templemarker", "marker_temple.nif"), - std::make_pair("travelmarker", "marker_travel.nif") - }; - - for (const std::pair &marker : markers) - { - if (search(marker.first) == 0) - { - ESM::Static newMarker; - newMarker.mId = marker.first; - newMarker.mModel = marker.second; - std::pair ret = mStatic.insert(std::make_pair(marker.first, newMarker)); - if (ret.first != mStatic.end()) - { - mShared.push_back(&ret.first->second); - } - } - } - } - - template<> - void Store::setUp() - { - // Load default Door type marker definitions - std::pair markers[] = { - std::make_pair("prisonmarker", "marker_prison.nif") - }; - - for (const std::pair &marker : markers) - { - if (search(marker.first) == 0) - { - ESM::Door newMarker; - newMarker.mId = marker.first; - newMarker.mModel = marker.second; - std::pair ret = mStatic.insert(std::make_pair(marker.first, newMarker)); - if (ret.first != mStatic.end()) - { - mShared.push_back(&ret.first->second); - } - } - } - } - template <> inline RecordId Store::load(ESM::ESMReader &esm) { // The original letter case of a dialogue ID is saved, because it's printed diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 7dd826fd9..8f81dd4a0 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -417,10 +417,8 @@ namespace MWWorld void World::write (ESM::ESMWriter& writer, Loading::Listener& progress) const { // Active cells could have a dirty fog of war, sync it to the CellStore first - for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) + for (CellStore* cellstore : mWorldScene->getActiveCells()) { - CellStore* cellstore = *iter; MWBase::Environment::get().getWindowManager()->writeFog(cellstore); } @@ -524,6 +522,17 @@ namespace MWWorld gmst["iWereWolfBounty"] = ESM::Variant(1000); gmst["fCombatDistanceWerewolfMod"] = ESM::Variant(0.3f); + for (const std::pair ¶ms : gmst) + { + if (!mStore.get().search(params.first)) + { + ESM::GameSetting record; + record.mId = params.first; + record.mValue = params.second; + mStore.insertStatic(record); + } + } + std::map globals; // vanilla Morrowind does not define dayspassed. globals["dayspassed"] = ESM::Variant(1); // but the addons start counting at 1 :( @@ -543,25 +552,47 @@ namespace MWWorld globals["crimegoldturnin"] = ESM::Variant(0); globals["pchasturnin"] = ESM::Variant(0); - for (std::map::iterator it = gmst.begin(); it != gmst.end(); ++it) + for (const std::pair ¶ms : globals) + { + if (!mStore.get().search(params.first)) + { + ESM::Global record; + record.mId = params.first; + record.mValue = params.second; + mStore.insertStatic(record); + } + } + + std::map statics; + // Total conversions from SureAI lack marker records + statics["divinemarker"] = "marker_divine.nif"; + statics["doormarker"] = "marker_arrow.nif"; + statics["northmarker"] = "marker_north.nif"; + statics["templemarker"] = "marker_temple.nif"; + statics["travelmarker"] = "marker_travel.nif"; + + for (const std::pair ¶ms : statics) { - if (!mStore.get().search(it->first)) + if (!mStore.get().search(params.first)) { - ESM::GameSetting setting; - setting.mId = it->first; - setting.mValue = it->second; - mStore.insertStatic(setting); + ESM::Static record; + record.mId = params.first; + record.mModel = params.second; + mStore.insertStatic(record); } } - for (std::map::iterator it = globals.begin(); it != globals.end(); ++it) + std::map doors; + doors["prisonmarker"] = "marker_prison.nif"; + + for (const std::pair ¶ms : doors) { - if (!mStore.get().search(it->first)) + if (!mStore.get().search(params.first)) { - ESM::Global setting; - setting.mId = it->first; - setting.mValue = it->second; - mStore.insertStatic(setting); + ESM::Door record; + record.mId = params.first; + record.mModel = params.second; + mStore.insertStatic(record); } } } @@ -576,22 +607,19 @@ namespace MWWorld { // first try named cells const ESM::Cell *cell = mStore.get().searchExtByName (cellName); - if (cell != 0) { + if (cell) return cell; - } // didn't work -> now check for regions - const MWWorld::Store ®ions = mStore.get(); - MWWorld::Store::iterator it = regions.begin(); - for (; it != regions.end(); ++it) + for (const ESM::Region ®ion : mStore.get()) { - if (Misc::StringUtils::ciEqual(cellName, it->mName)) + if (Misc::StringUtils::ciEqual(cellName, region.mName)) { - return mStore.get().searchExtByRegion(it->mId); + return mStore.get().searchExtByRegion(region.mId); } } - return 0; + return nullptr; } const Fallback::Map *World::getFallback() const @@ -713,10 +741,10 @@ namespace MWWorld if (!cell->getCell()->isExterior() || !cell->getCell()->mName.empty()) return cell->getCell()->mName; - if (const ESM::Region* region = getStore().get().search (cell->getCell()->mRegion)) + if (const ESM::Region* region = mStore.get().search (cell->getCell()->mRegion)) return region->mName; - return getStore().get().find ("sDefaultCellname")->mValue.getString(); + return mStore.get().find ("sDefaultCellname")->mValue.getString(); } void World::removeRefScript (MWWorld::RefData *ref) @@ -735,11 +763,9 @@ namespace MWWorld std::string lowerCaseName = Misc::StringUtils::lowerCase(name); - for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) + for (CellStore* cellstore : mWorldScene->getActiveCells()) { // TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is in) - CellStore* cellstore = *iter; Ptr ptr = mCells.getPtr (lowerCaseName, *cellstore, false); if (!ptr.isEmpty()) @@ -753,10 +779,8 @@ namespace MWWorld return ret; } - for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) + for (CellStore* cellstore : mWorldScene->getActiveCells()) { - CellStore* cellstore = *iter; Ptr ptr = cellstore->searchInContainer(lowerCaseName); if (!ptr.isEmpty()) return ptr; @@ -884,15 +908,14 @@ namespace MWWorld if (ptr.getContainerStore() == &player.getClass().getContainerStore(player)) return player; - const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells(); - for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt) + for (CellStore* cellstore : mWorldScene->getActiveCells()) { FindContainerVisitor visitor(ptr); - (*cellIt)->forEachType(visitor); + cellstore->forEachType(visitor); if (visitor.mResult.isEmpty()) - (*cellIt)->forEachType(visitor); + cellstore->forEachType(visitor); if (visitor.mResult.isEmpty()) - (*cellIt)->forEachType(visitor); + cellstore->forEachType(visitor); if (!visitor.mResult.isEmpty()) return visitor.mResult; @@ -1135,7 +1158,7 @@ namespace MWWorld "sMonthHeartfire", "sMonthFrostfall", "sMonthSunsdusk", "sMonthEveningstar" }; - return getStore().get().find (monthNames[month])->mValue.getString(); + return mStore.get().find (monthNames[month])->mValue.getString(); } TimeStamp World::getTimeStamp() const @@ -1224,7 +1247,7 @@ namespace MWWorld if (mActivationDistanceOverride >= 0) return static_cast(mActivationDistanceOverride); - static const int iMaxActivateDist = getStore().get().find("iMaxActivateDist")->mValue.getInteger(); + static const int iMaxActivateDist = mStore.get().find("iMaxActivateDist")->mValue.getInteger(); return static_cast(iMaxActivateDist); } @@ -1492,7 +1515,10 @@ namespace MWWorld { mRendering->moveObject(newPtr, vec); if (movePhysics) + { mPhysics->updatePosition(newPtr); + mPhysics->updatePtr(ptr, newPtr); + } } if (isPlayer) { @@ -2019,7 +2045,6 @@ namespace MWWorld if (!paused) { - doPhysics (duration); updateNavigator(); } @@ -2039,6 +2064,14 @@ namespace MWWorld } } + void World::updatePhysics (float duration, bool paused) + { + if (!paused) + { + doPhysics (duration); + } + } + void World::updatePlayer() { MWWorld::Ptr player = getPlayerPtr(); @@ -2071,7 +2104,7 @@ namespace MWWorld bool swimming = isSwimming(player); bool flying = isFlying(player); - static const float i1stPersonSneakDelta = getStore().get().find("i1stPersonSneakDelta")->mValue.getFloat(); + static const float i1stPersonSneakDelta = mStore.get().find("i1stPersonSneakDelta")->mValue.getFloat(); if (sneaking && !swimming && !flying) mRendering->getCamera()->setSneakOffset(i1stPersonSneakDelta); else @@ -2697,9 +2730,8 @@ namespace MWWorld player.getClass().getInventoryStore(player).setInvListener(anim, player); player.getClass().getInventoryStore(player).setContListener(anim); - scaleObject(getPlayerPtr(), 1.f); // apply race height - - rotateObject(getPlayerPtr(), 0.f, 0.f, 0.f, true); + scaleObject(player, player.getCellRef().getScale()); // apply race height + rotateObject(player, 0.f, 0.f, 0.f, true); MWBase::Environment::get().getMechanicsManager()->add(getPlayerPtr()); MWBase::Environment::get().getMechanicsManager()->watchActor(getPlayerPtr()); @@ -2893,17 +2925,16 @@ namespace MWWorld std::vector actors; mPhysics->getActorsStandingOn(object, actors); - for (std::vector::iterator it = actors.begin(); it != actors.end(); ++it) + for (const Ptr &actor : actors) { - MWWorld::Ptr actor = *it; MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor); if (stats.isDead()) continue; mPhysics->markAsNonSolid (object); - if (actor == getPlayerPtr() && MWBase::Environment::get().getWorld()->getGodModeState()) - return; + if (actor == getPlayerPtr() && mGodMode) + continue; MWMechanics::DynamicStat health = stats.getHealth(); health.setCurrent(health.getCurrent()-healthPerSecond*MWBase::Environment::get().getFrameDuration()); @@ -2934,19 +2965,18 @@ namespace MWWorld End of tes3mp change (major) */ - std::vector actors; + std::vector actors; mPhysics->getActorsCollidingWith(object, actors); - for (std::vector::iterator it = actors.begin(); it != actors.end(); ++it) + for (const Ptr &actor : actors) { - MWWorld::Ptr actor = *it; MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor); if (stats.isDead()) continue; mPhysics->markAsNonSolid (object); - if (actor == getPlayerPtr() && MWBase::Environment::get().getWorld()->getGodModeState()) - return; + if (actor == getPlayerPtr() && mGodMode) + continue; MWMechanics::DynamicStat health = stats.getHealth(); health.setCurrent(health.getCurrent()-healthPerSecond*MWBase::Environment::get().getFrameDuration()); @@ -3016,11 +3046,10 @@ namespace MWWorld void World::getContainersOwnedBy (const MWWorld::ConstPtr& owner, std::vector& out) { - const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells(); - for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt) + for (CellStore* cellstore : mWorldScene->getActiveCells()) { GetContainersOwnedByVisitor visitor (owner, out); - (*cellIt)->forEachType(visitor); + cellstore->forEachType(visitor); } } @@ -3038,15 +3067,14 @@ namespace MWWorld void World::getItemsOwnedBy (const MWWorld::ConstPtr& npc, std::vector& out) { - const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells(); - for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt) + for (CellStore* cellstore : mWorldScene->getActiveCells()) { ListObjectsVisitor visitor; - (*cellIt)->forEach(visitor); + cellstore->forEach(visitor); - for (std::vector::iterator it = visitor.mObjects.begin(); it != visitor.mObjects.end(); ++it) - if (Misc::StringUtils::ciEqual(it->getCellRef().getOwner(), npc.getCellRef().getRefId())) - out.push_back(*it); + for (const Ptr &object : visitor.mObjects) + if (Misc::StringUtils::ciEqual(object.getCellRef().getOwner(), npc.getCellRef().getRefId())) + out.push_back(object); } } @@ -3087,28 +3115,21 @@ namespace MWWorld bool World::findInteriorPosition(const std::string &name, ESM::Position &pos) { - typedef MWWorld::CellRefList::List DoorList; - typedef MWWorld::CellRefList::List StaticList; - pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; pos.pos[0] = pos.pos[1] = pos.pos[2] = 0; MWWorld::CellStore *cellStore = getInterior(name); - if (0 == cellStore) { + if (!cellStore) return false; - } std::vector sortedDoors; - const DoorList &doors = cellStore->getReadOnlyDoors().mList; - for (DoorList::const_iterator it = doors.begin(); it != doors.end(); ++it) + for (const MWWorld::LiveCellRef& door : cellStore->getReadOnlyDoors().mList) { - if (!it->mRef.getTeleport()) - { + if (!door.mRef.getTeleport()) continue; - } - sortedDoors.push_back(&it->mRef); + sortedDoors.push_back(&door.mRef); } // Sort teleporting doors alphabetically, first by ID, then by destination cell to make search consistent @@ -3120,44 +3141,43 @@ namespace MWWorld return lhs->getDestCell() < rhs->getDestCell(); }); - for (std::vector::const_iterator it = sortedDoors.begin(); it != sortedDoors.end(); ++it) + for (const MWWorld::CellRef* door : sortedDoors) { - MWWorld::CellStore *source = 0; + MWWorld::CellStore *source = nullptr; // door to exterior - if ((*it)->getDestCell().empty()) + if (door->getDestCell().empty()) { int x, y; - ESM::Position doorDest = (*it)->getDoorDest(); + ESM::Position doorDest = door->getDoorDest(); positionToIndex(doorDest.pos[0], doorDest.pos[1], x, y); source = getExterior(x, y); } // door to interior else { - source = getInterior((*it)->getDestCell()); + source = getInterior(door->getDestCell()); } - if (0 != source) + if (source) { // Find door leading to our current teleport door // and use its destination to position inside cell. - const DoorList &destinationDoors = source->getReadOnlyDoors().mList; - for (DoorList::const_iterator jt = destinationDoors.begin(); jt != destinationDoors.end(); ++jt) + for (const MWWorld::LiveCellRef& destDoor : source->getReadOnlyDoors().mList) { - if ((*it)->getTeleport() && - Misc::StringUtils::ciEqual(name, jt->mRef.getDestCell())) + if (Misc::StringUtils::ciEqual(name, destDoor.mRef.getDestCell())) { /// \note Using _any_ door pointed to the interior, /// not the one pointed to current door. - pos = jt->mRef.getDoorDest(); + pos = destDoor.mRef.getDoorDest(); return true; } } } } // Fall back to the first static location. - const StaticList &statics = cellStore->getReadOnlyStatics().mList; - if ( statics.begin() != statics.end() ) { + const MWWorld::CellRefList::List &statics = cellStore->getReadOnlyStatics().mList; + if (!statics.empty()) + { pos = statics.begin()->mRef.getPosition(); return true; } @@ -3252,22 +3272,21 @@ namespace MWWorld void World::loadContentFiles(const Files::Collections& fileCollections, const std::vector& content, ContentLoader& contentLoader) { - std::vector::const_iterator it(content.begin()); - std::vector::const_iterator end(content.end()); - for (int idx = 0; it != end; ++it, ++idx) + int idx = 0; + for (const std::string &file : content) { - boost::filesystem::path filename(*it); + boost::filesystem::path filename(file); const Files::MultiDirCollection& col = fileCollections.getCollection(filename.extension().string()); - if (col.doesExist(*it)) + if (col.doesExist(file)) { - contentLoader.load(col.getPath(*it), idx); + contentLoader.load(col.getPath(file), idx); } else { - std::stringstream msg; - msg << "Failed loading " << *it << ": the content file does not exist"; - throw std::runtime_error(msg.str()); + std::string message = "Failed loading " + file + ": the content file does not exist"; + throw std::runtime_error(message); } + idx++; } } @@ -3307,10 +3326,10 @@ namespace MWWorld End of tes3mp addition */ - const ESM::Spell* spell = getStore().get().find(selectedSpell); + const ESM::Spell* spell = mStore.get().find(selectedSpell); // Check mana - bool godmode = (isPlayer && getGodModeState()); + bool godmode = (isPlayer && mGodMode); MWMechanics::DynamicStat magicka = stats.getMagicka(); if (magicka.getCurrent() < spell->mData.mCost && !godmode) { @@ -3348,7 +3367,7 @@ namespace MWWorld if (!actor.isEmpty() && actor != MWMechanics::getPlayer() && !manualSpell) stats.getAiSequence().getCombatTargets(targetActors); - const float fCombatDistance = getStore().get().find("fCombatDistance")->mValue.getFloat(); + const float fCombatDistance = mStore.get().find("fCombatDistance")->mValue.getFloat(); osg::Vec3f hitPosition = actor.getRefData().getPosition().asVec3(); @@ -3366,14 +3385,13 @@ namespace MWWorld // For scripted spells we should not use hit contact if (manualSpell) { - // Actors that are targeted by this actor's Follow or Escort packages also side with them if (actor != MWMechanics::getPlayer()) { - for (std::list::const_iterator it = stats.getAiSequence().begin(); it != stats.getAiSequence().end(); ++it) + for (const MWMechanics::AiPackage* package : stats.getAiSequence()) { - if ((*it)->getTypeId() == MWMechanics::AiPackage::TypeIdCast) + if (package->getTypeId() == MWMechanics::AiPackage::TypeIdCast) { - target = (*it)->getTarget(); + target = package->getTarget(); break; } } @@ -3431,7 +3449,7 @@ namespace MWWorld if (!selectedSpell.empty()) { - const ESM::Spell* spell = getStore().get().find(selectedSpell); + const ESM::Spell* spell = mStore.get().find(selectedSpell); cast.cast(spell); } else if (actor.getClass().hasInventoryStore(actor)) @@ -3566,17 +3584,14 @@ namespace MWWorld while ( !nextCells.empty() ) { currentCells = nextCells; nextCells.clear(); - for( std::set< std::string >::const_iterator i = currentCells.begin(); i != currentCells.end(); ++i ) { - MWWorld::CellStore *next = getInterior( *i ); + for (const std::string ¤tCell : currentCells) + { + MWWorld::CellStore *next = getInterior(currentCell); if ( !next ) continue; - const MWWorld::CellRefList& doors = next->getReadOnlyDoors(); - const CellRefList::List& refList = doors.mList; - // Check if any door in the cell leads to an exterior directly - for (CellRefList::List::const_iterator it = refList.begin(); it != refList.end(); ++it) + for (const MWWorld::LiveCellRef& ref : next->getReadOnlyDoors().mList) { - const MWWorld::LiveCellRef& ref = *it; if (!ref.mRef.getTeleport()) continue; if (ref.mRef.getDestCell().empty()) @@ -3593,7 +3608,7 @@ namespace MWWorld } } - checkedCells.insert( *i ); + checkedCells.insert(currentCell); } } @@ -3619,9 +3634,9 @@ namespace MWWorld while ( !nextCells.empty() ) { currentCells = nextCells; nextCells.clear(); - for( std::set< std::string >::const_iterator i = currentCells.begin(); i != currentCells.end(); ++i ) { - MWWorld::CellStore *next = getInterior( *i ); - checkedCells.insert( *i ); + for (const std::string &cell : currentCells) { + MWWorld::CellStore *next = getInterior(cell); + checkedCells.insert(cell); if ( !next ) continue; closestMarker = next->searchConst( id ); @@ -3630,14 +3645,9 @@ namespace MWWorld return closestMarker; } - const MWWorld::CellRefList& doors = next->getReadOnlyDoors(); - const CellRefList::List& doorList = doors.mList; - // Check if any door in the cell leads to an exterior directly - for (CellRefList::List::const_iterator it = doorList.begin(); it != doorList.end(); ++it) + for (const MWWorld::LiveCellRef& ref : next->getReadOnlyDoors().mList) { - const MWWorld::LiveCellRef& ref = *it; - if (!ref.mRef.getTeleport()) continue; if (ref.mRef.getDestCell().empty()) @@ -3663,15 +3673,14 @@ namespace MWWorld std::vector markers; mCells.getExteriorPtrs(id, markers); - for (std::vector::iterator it2 = markers.begin(); it2 != markers.end(); ++it2) + for (const Ptr& marker : markers) { - ESM::Position pos = it2->getRefData().getPosition(); - osg::Vec3f markerPos = pos.asVec3(); + osg::Vec3f markerPos = marker.getRefData().getPosition().asVec3(); float distance = (worldPos - markerPos).length2(); if (distance < closestDistance) { closestDistance = distance; - closestMarker = *it2; + closestMarker = marker; } } @@ -3802,10 +3811,8 @@ namespace MWWorld AddDetectedReferenceVisitor visitor (out, ptr, type, dist*dist); - const Scene::CellStoreCollection& active = mWorldScene->getActiveCells(); - for (Scene::CellStoreCollection::const_iterator it = active.begin(); it != active.end(); ++it) + for (CellStore* cellStore : mWorldScene->getActiveCells()) { - MWWorld::CellStore* cellStore = *it; cellStore->forEach(visitor); } } @@ -3840,8 +3847,8 @@ namespace MWWorld int bounty = player.getClass().getNpcStats(player).getBounty(); int playerGold = player.getClass().getContainerStore(player).count(ContainerStore::sGoldId); - float fCrimeGoldDiscountMult = getStore().get().find("fCrimeGoldDiscountMult")->mValue.getFloat(); - float fCrimeGoldTurnInMult = getStore().get().find("fCrimeGoldTurnInMult")->mValue.getFloat(); + static float fCrimeGoldDiscountMult = mStore.get().find("fCrimeGoldDiscountMult")->mValue.getFloat(); + static float fCrimeGoldTurnInMult = mStore.get().find("fCrimeGoldTurnInMult")->mValue.getFloat(); int discount = static_cast(bounty * fCrimeGoldDiscountMult); int turnIn = static_cast(bounty * fCrimeGoldTurnInMult); @@ -3906,7 +3913,7 @@ namespace MWWorld mPlayer->recordCrimeId(); confiscateStolenItems(player); - int iDaysinPrisonMod = getStore().get().find("iDaysinPrisonMod")->mValue.getInteger(); + static int iDaysinPrisonMod = mStore.get().find("iDaysinPrisonMod")->mValue.getInteger(); mDaysInPrison = std::max(1, bounty / iDaysinPrisonMod); return; @@ -3962,18 +3969,18 @@ namespace MWWorld void World::spawnRandomCreature(const std::string &creatureList) { - const ESM::CreatureLevList* list = getStore().get().find(creatureList); + const ESM::CreatureLevList* list = mStore.get().find(creatureList); - int iNumberCreatures = getStore().get().find("iNumberCreatures")->mValue.getInteger(); + static int iNumberCreatures = mStore.get().find("iNumberCreatures")->mValue.getInteger(); int numCreatures = 1 + Misc::Rng::rollDice(iNumberCreatures); // [1, iNumberCreatures] for (int i=0; igetFallbackString("Blood_Texture_2"); - break; - case 1: - texture = getFallback()->getFallbackString("Blood_Texture_1"); - break; - case 0: - default: - texture = getFallback()->getFallbackString("Blood_Texture_0"); - break; - } - - std::stringstream modelName; - modelName << "Blood_Model_"; - int roll = Misc::Rng::rollDice(3); // [0, 2] - modelName << roll; - std::string model = "meshes\\" + getFallback()->getFallbackString(modelName.str()); + std::string texture = getFallback()->getFallbackString("Blood_Texture_" + std::to_string(ptr.getClass().getBloodTexture(ptr))); + std::string model = "meshes\\" + getFallback()->getFallbackString("Blood_Model_" + std::to_string(Misc::Rng::rollDice(3))); // [0, 2] mRendering->spawnEffect(model, texture, worldPosition, 1.0f, false); } @@ -4038,7 +4026,7 @@ namespace MWWorld for (std::vector::const_iterator effectIt = effects.mList.begin(); effectIt != effects.mList.end(); ++effectIt) { - const ESM::MagicEffect* effect = getStore().get().find(effectIt->mEffectID); + const ESM::MagicEffect* effect = mStore.get().find(effectIt->mEffectID); if (effectIt->mRange != rangeType || (effectIt->mArea <= 0 && !ignore.isEmpty() && ignore.getClass().isActor())) continue; // Not right range type, or not area effect and hit an actor @@ -4052,9 +4040,9 @@ namespace MWWorld // Spawn the explosion orb effect const ESM::Static* areaStatic; if (!effect->mArea.empty()) - areaStatic = getStore().get().find (effect->mArea); + areaStatic = mStore.get().find (effect->mArea); else - areaStatic = getStore().get().find ("VFX_DefaultArea"); + areaStatic = mStore.get().find ("VFX_DefaultArea"); std::string texture = effect->mParticle; @@ -4082,13 +4070,13 @@ namespace MWWorld std::vector objects; MWBase::Environment::get().getMechanicsManager()->getObjectsInRange( origin, feetToGameUnits(static_cast(effectIt->mArea)), objects); - for (std::vector::iterator affected = objects.begin(); affected != objects.end(); ++affected) + for (const Ptr& affected : objects) { // Ignore actors without collisions here, otherwise it will be possible to hit actors outside processing range. - if (affected->getClass().isActor() && !isActorCollisionEnabled(*affected)) + if (affected.getClass().isActor() && !isActorCollisionEnabled(affected)) continue; - toApply[*affected].push_back(*effectIt); + toApply[affected].push_back(*effectIt); } } @@ -4148,10 +4136,8 @@ namespace MWWorld }; void World::resetActors() { - for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); - iter!=mWorldScene->getActiveCells().end(); ++iter) + for (CellStore* cellstore : mWorldScene->getActiveCells()) { - CellStore* cellstore = *iter; ResetActorsVisitor visitor; cellstore->forEach(visitor); } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 63be4575b..18f1f3ac4 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -619,6 +619,7 @@ namespace MWWorld /// \return pointer to created record void update (float duration, bool paused) override; + void updatePhysics (float duration, bool paused) override; void updateWindowManager () override; diff --git a/apps/openmw_test_suite/CMakeLists.txt b/apps/openmw_test_suite/CMakeLists.txt index 7f10ab2fb..907052882 100644 --- a/apps/openmw_test_suite/CMakeLists.txt +++ b/apps/openmw_test_suite/CMakeLists.txt @@ -40,4 +40,13 @@ if (GTEST_FOUND AND GMOCK_FOUND) add_definitions(--coverage) target_link_libraries(openmw_test_suite gcov) endif() + + if (MSVC) + if (CMAKE_CL_64) + # Debug version of openmw_unit_tests needs increased number of sections beyond 2^16 + # just like openmw and openmw-cs + set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") + endif (CMAKE_CL_64) + endif (MSVC) + endif() diff --git a/apps/openmw_test_suite/openmw_test_suite.cpp b/apps/openmw_test_suite/openmw_test_suite.cpp index 7cc76b25b..7364b20fd 100644 --- a/apps/openmw_test_suite/openmw_test_suite.cpp +++ b/apps/openmw_test_suite/openmw_test_suite.cpp @@ -1,6 +1,12 @@ #include +#ifdef WIN32 +//we cannot use GTEST_API_ before main if we're building standalone exe application, +//and we're linking GoogleTest / GoogleMock as DLLs and not linking gtest_main / gmock_main +int main(int argc, char **argv) { +#else GTEST_API_ int main(int argc, char **argv) { +#endif testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/apps/wizard/unshield/unshieldworker.cpp b/apps/wizard/unshield/unshieldworker.cpp index 9cdb4cd78..7aa84d3b1 100644 --- a/apps/wizard/unshield/unshieldworker.cpp +++ b/apps/wizard/unshield/unshieldworker.cpp @@ -856,7 +856,7 @@ QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QSt if (info.isDir()) { if (directories) { - if (info.fileName() == fileName) { + if (!info.fileName().compare(fileName, Qt::CaseInsensitive)) { result.append(info.absoluteFilePath()); } else { if (recursive) @@ -872,11 +872,11 @@ QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QSt switch (flags) { case Qt::MatchExactly: - if (info.fileName() == fileName) + if (!info.fileName().compare(fileName, Qt::CaseInsensitive)) result.append(info.absoluteFilePath()); break; case Qt::MatchEndsWith: - if (info.fileName().endsWith(fileName)) + if (info.fileName().endsWith(fileName), Qt::CaseInsensitive) result.append(info.absoluteFilePath()); break; } diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 8754cec85..08662c282 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -33,7 +33,7 @@ add_component_dir (settings ) add_component_dir (bsa - bsa_file + bsa_file compressedbsafile memorystream ) add_component_dir (vfs @@ -285,6 +285,7 @@ target_link_libraries(components ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_IOSTREAMS_LIBRARY} ${OSG_LIBRARIES} ${OPENTHREADS_LIBRARIES} ${OSGPARTICLE_LIBRARIES} @@ -298,6 +299,7 @@ target_link_libraries(components ${SDL2_LIBRARIES} ${OPENGL_gl_LIBRARY} ${MyGUI_LIBRARIES} + ${BSAOPTHASH_LIBRARIES} RecastNavigation::DebugUtils RecastNavigation::Detour RecastNavigation::Recast @@ -305,7 +307,8 @@ target_link_libraries(components if (WIN32) target_link_libraries(components - ${Boost_LOCALE_LIBRARY}) + ${Boost_LOCALE_LIBRARY} + ${Boost_ZLIB_LIBRARY}) endif() if (USE_QT) diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp index 8905a86a1..abeca5326 100644 --- a/components/bsa/bsa_file.cpp +++ b/components/bsa/bsa_file.cpp @@ -35,7 +35,7 @@ using namespace Bsa; /// Error handling void BSAFile::fail(const string &msg) { - throw std::runtime_error("BSA Error: " + msg + "\nArchive: " + filename); + throw std::runtime_error("BSA Error: " + msg + "\nArchive: " + mFilename); } /// Read header information from the input source @@ -71,10 +71,10 @@ void BSAFile::readHeader() * the beginning of this buffer. * */ - assert(!isLoaded); + assert(!mIsLoaded); namespace bfs = boost::filesystem; - bfs::ifstream input(bfs::path(filename), std::ios_base::binary); + bfs::ifstream input(bfs::path(mFilename), std::ios_base::binary); // Total archive size std::streamoff fsize = 0; @@ -117,8 +117,8 @@ void BSAFile::readHeader() input.read(reinterpret_cast(&offsets[0]), 12*filenum); // Read the string table - stringBuf.resize(dirsize-12*filenum); - input.read(&stringBuf[0], stringBuf.size()); + mStringBuf.resize(dirsize-12*filenum); + input.read(&mStringBuf[0], mStringBuf.size()); // Check our position assert(input.tellg() == std::streampos(12+dirsize)); @@ -129,40 +129,40 @@ void BSAFile::readHeader() size_t fileDataOffset = 12 + dirsize + 8*filenum; // Set up the the FileStruct table - files.resize(filenum); + mFiles.resize(filenum); for(size_t i=0;i fsize) fail("Archive contains offsets outside itself"); // Add the file name to the lookup - lookup[fs.name] = i; + mLookup[fs.name] = i; } - isLoaded = true; + mIsLoaded = true; } /// Get the index of a given file name, or -1 if not found int BSAFile::getIndex(const char *str) const { - Lookup::const_iterator it = lookup.find(str); - if(it == lookup.end()) + Lookup::const_iterator it = mLookup.find(str); + if(it == mLookup.end()) return -1; int res = it->second; - assert(res >= 0 && (size_t)res < files.size()); + assert(res >= 0 && (size_t)res < mFiles.size()); return res; } /// Open an archive file. void BSAFile::open(const string &file) { - filename = file; + mFilename = file; readHeader(); } @@ -173,12 +173,12 @@ Files::IStreamPtr BSAFile::getFile(const char *file) if(i == -1) fail("File not found: " + string(file)); - const FileStruct &fs = files[i]; + const FileStruct &fs = mFiles[i]; - return Files::openConstrainedFileStream (filename.c_str (), fs.offset, fs.fileSize); + return Files::openConstrainedFileStream (mFilename.c_str (), fs.offset, fs.fileSize); } Files::IStreamPtr BSAFile::getFile(const FileStruct *file) { - return Files::openConstrainedFileStream (filename.c_str (), file->offset, file->fileSize); + return Files::openConstrainedFileStream (mFilename.c_str (), file->offset, file->fileSize); } diff --git a/components/bsa/bsa_file.hpp b/components/bsa/bsa_file.hpp index 196dc30fb..d12d01b0c 100644 --- a/components/bsa/bsa_file.hpp +++ b/components/bsa/bsa_file.hpp @@ -56,18 +56,18 @@ public: }; typedef std::vector FileList; -private: +protected: /// Table of files in this archive - FileList files; + FileList mFiles; /// Filename string buffer - std::vector stringBuf; + std::vector mStringBuf; /// True when an archive has been loaded - bool isLoaded; + bool mIsLoaded; /// Used for error messages - std::string filename; + std::string mFilename; /// Case insensitive string comparison struct iltstr @@ -81,13 +81,16 @@ private: checks are case insensitive. */ typedef std::map Lookup; - Lookup lookup; + Lookup mLookup; /// Error handling void fail(const std::string &msg); /// Read header information from the input source - void readHeader(); + virtual void readHeader(); + + /// Read header information from the input source + /// Get the index of a given file name, or -1 if not found /// @note Thread safe. @@ -100,7 +103,10 @@ public: */ BSAFile() - : isLoaded(false) + : mIsLoaded(false) + { } + + virtual ~BSAFile() { } /// Open an archive file. @@ -112,24 +118,24 @@ public: */ /// Check if a file exists - bool exists(const char *file) const + virtual bool exists(const char *file) const { return getIndex(file) != -1; } /** Open a file contained in the archive. Throws an exception if the file doesn't exist. * @note Thread safe. */ - Files::IStreamPtr getFile(const char *file); + virtual Files::IStreamPtr getFile(const char *file); /** Open a file contained in the archive. * @note Thread safe. */ - Files::IStreamPtr getFile(const FileStruct* file); + virtual Files::IStreamPtr getFile(const FileStruct* file); /// Get a list of all files /// @note Thread safe. const FileList &getList() const - { return files; } + { return mFiles; } }; } diff --git a/components/bsa/compressedbsafile.cpp b/components/bsa/compressedbsafile.cpp new file mode 100644 index 000000000..ba96ee8de --- /dev/null +++ b/components/bsa/compressedbsafile.cpp @@ -0,0 +1,453 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008-2010 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.sourceforge.net/ + + This file (compressedbsafile.cpp) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + Compressed BSA stuff added by cc9cii 2018 + + */ +#include "compressedbsafile.hpp" + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace Bsa +{ +//special marker for invalid records, +//equal to max uint32_t value +const uint32_t CompressedBSAFile::sInvalidOffset = std::numeric_limits::max(); + +//bit marking compression on file size +const uint32_t CompressedBSAFile::sCompressedFlag = 1u << 30u; + + +CompressedBSAFile::FileRecord::FileRecord() : size(0), offset(sInvalidOffset) +{ } + +bool CompressedBSAFile::FileRecord::isValid() const +{ + return offset != sInvalidOffset; +} + +bool CompressedBSAFile::FileRecord::isCompressed(bool bsaCompressedByDefault) const +{ + bool recordCompressionFlagEnabled = ((size & sCompressedFlag) == sCompressedFlag); + + //record is compressed when: + //- bsaCompressedByDefault flag is set and 30th bit is NOT set, or + //- bsaCompressedByDefault flag is NOT set and 30th bit is set + //record is NOT compressed when: + //- bsaCompressedByDefault flag is NOT set and 30th bit is NOT set, or + //- bsaCompressedByDefault flag is set and 30th bit is set + return (bsaCompressedByDefault != recordCompressionFlagEnabled); +} + +std::uint32_t CompressedBSAFile::FileRecord::getSizeWithoutCompressionFlag() const { + return size & (~sCompressedFlag); +} + +void CompressedBSAFile::getBZString(std::string& str, std::istream& filestream) +{ + char size = 0; + filestream.read(&size, 1); + + boost::scoped_array buf(new char[size]); + filestream.read(buf.get(), size); + + if (buf[size - 1] != 0) + { + str.assign(buf.get(), size); + if (str.size() != ((size_t)size)) { + fail("getBZString string size mismatch"); + } + } + else + { + str.assign(buf.get(), size - 1); // don't copy null terminator + if (str.size() != ((size_t)size - 1)) { + fail("getBZString string size mismatch (null terminator)"); + } + } +} + +CompressedBSAFile::CompressedBSAFile() + : mCompressedByDefault(false), mEmbeddedFileNames(false) +{ } + +CompressedBSAFile::~CompressedBSAFile() +{ } + +/// Read header information from the input source +void CompressedBSAFile::readHeader() +{ + assert(!mIsLoaded); + + namespace bfs = boost::filesystem; + bfs::ifstream input(bfs::path(mFilename), std::ios_base::binary); + + // Total archive size + std::streamoff fsize = 0; + if(input.seekg(0, std::ios_base::end)) + { + fsize = input.tellg(); + input.seekg(0); + } + + if(fsize < 36) // header is 36 bytes + fail("File too small to be a valid BSA archive"); + + // Get essential header numbers + //size_t dirsize, filenum; + std::uint32_t archiveFlags, folderCount, totalFileNameLength; + { + // First 36 bytes + std::uint32_t header[9]; + + input.read(reinterpret_cast(header), 36); + + if(header[0] != 0x00415342 /*"BSA\x00"*/ || (header[1] != 0x67 /*TES4*/ && header[1] != 0x68 /*TES5*/)) + fail("Unrecognized TES4 BSA header"); + + // header[2] is offset, should be 36 = 0x24 which is the size of the header + + // Oblivion - Meshes.bsa + // + // 0111 1000 0111 = 0x0787 + // ^^^ ^ ^^^ + // ||| | ||+-- has names for dirs (mandatory?) + // ||| | |+--- has names for files (mandatory?) + // ||| | +---- files are compressed by default + // ||| | + // ||| +---------- unknown (TES5: retain strings during startup) + // ||+------------ unknown (TES5: embedded file names) + // |+------------- unknown + // +-------------- unknown + // + archiveFlags = header[3]; + folderCount = header[4]; + // header[5] - fileCount + // totalFolderNameLength = header[6]; + totalFileNameLength = header[7]; + // header[8]; // fileFlags : an opportunity to optimize here + + mCompressedByDefault = (archiveFlags & 0x4) != 0; + mEmbeddedFileNames = header[1] == 0x68 /*TES5*/ && (archiveFlags & 0x100) != 0; + } + + // folder records + std::uint64_t hash; + FolderRecord fr; + for (std::uint32_t i = 0; i < folderCount; ++i) + { + input.read(reinterpret_cast(&hash), 8); + input.read(reinterpret_cast(&fr.count), 4); // not sure purpose of count + input.read(reinterpret_cast(&fr.offset), 4); // not sure purpose of offset + + std::map::const_iterator lb = mFolders.lower_bound(hash); + if (lb != mFolders.end() && !(mFolders.key_comp()(hash, lb->first))) + fail("Archive found duplicate folder name hash"); + else + mFolders.insert(lb, std::pair(hash, fr)); + } + + // file record blocks + std::uint64_t fileHash; + FileRecord file; + + std::string folder(""); + std::uint64_t folderHash; + if ((archiveFlags & 0x1) == 0) + folderCount = 1; // TODO: not tested - unit test necessary + + mFiles.clear(); + std::vector fullPaths; + + for (std::uint32_t i = 0; i < folderCount; ++i) + { + if ((archiveFlags & 0x1) != 0) + getBZString(folder, input); + + folderHash = generateHash(folder, std::string()); + + std::map::iterator iter = mFolders.find(folderHash); + if (iter == mFolders.end()) + fail("Archive folder name hash not found"); + + for (std::uint32_t j = 0; j < iter->second.count; ++j) + { + input.read(reinterpret_cast(&fileHash), 8); + input.read(reinterpret_cast(&file.size), 4); + input.read(reinterpret_cast(&file.offset), 4); + + std::map::const_iterator lb = iter->second.files.lower_bound(fileHash); + if (lb != iter->second.files.end() && !(iter->second.files.key_comp()(fileHash, lb->first))) + fail("Archive found duplicate file name hash"); + + iter->second.files.insert(lb, std::pair(fileHash, file)); + + FileStruct fileStruct; + fileStruct.fileSize = file.getSizeWithoutCompressionFlag(); + fileStruct.offset = file.offset; + fileStruct.name = nullptr; + mFiles.push_back(fileStruct); + + fullPaths.push_back(folder); + } + } + + // file record blocks + if ((archiveFlags & 0x2) != 0) + { + mStringBuf.resize(totalFileNameLength); + input.read(&mStringBuf[0], mStringBuf.size()); // TODO: maybe useful in building a lookup map? + } + + size_t mStringBuffOffset = 0; + size_t totalStringsSize = 0; + for (std::uint32_t fileIndex = 0; fileIndex < mFiles.size(); ++fileIndex) { + + if (mStringBuffOffset >= totalFileNameLength) { + fail("Corrupted names record in BSA file"); + } + + //The vector guarantees that its elements occupy contiguous memory + mFiles[fileIndex].name = reinterpret_cast(mStringBuf.data() + mStringBuffOffset); + + fullPaths.at(fileIndex) += "\\" + std::string(mStringBuf.data() + mStringBuffOffset); + + while (mStringBuffOffset < totalFileNameLength) { + if (mStringBuf[mStringBuffOffset] != '\0') { + mStringBuffOffset++; + } + else { + mStringBuffOffset++; + break; + } + } + //we want to keep one more 0 character at the end of each string + totalStringsSize += fullPaths.at(fileIndex).length() + 1u; + } + mStringBuf.resize(totalStringsSize); + + mStringBuffOffset = 0; + for (std::uint32_t fileIndex = 0u; fileIndex < mFiles.size(); fileIndex++) { + size_t stringLength = fullPaths.at(fileIndex).length(); + + std::copy(fullPaths.at(fileIndex).c_str(), + //plus 1 because we also want to copy 0 at the end of the string + fullPaths.at(fileIndex).c_str() + stringLength + 1u, + mStringBuf.data() + mStringBuffOffset); + + mFiles[fileIndex].name = reinterpret_cast(mStringBuf.data() + mStringBuffOffset); + + mLookup[reinterpret_cast(mStringBuf.data() + mStringBuffOffset)] = fileIndex; + mStringBuffOffset += stringLength + 1u; + } + + if (mStringBuffOffset != mStringBuf.size()) { + fail("Could not resolve names of files in BSA file"); + } + + convertCompressedSizesToUncompressed(); + mIsLoaded = true; +} + +CompressedBSAFile::FileRecord CompressedBSAFile::getFileRecord(const std::string& str) const +{ + // Force-convert the path into something both Windows and UNIX can handle first + // to make sure Boost doesn't think the entire path is the filename on Linux + // and subsequently purge it to determine the file folder. + std::string path = str; + std::replace(path.begin(), path.end(), '\\', '/'); + + boost::filesystem::path p(path); + std::string stem = p.stem().string(); + std::string ext = p.extension().string(); + p.remove_filename(); + + std::string folder = p.string(); + std::uint64_t folderHash = generateHash(folder, std::string()); + + std::map::const_iterator it = mFolders.find(folderHash); + if (it == mFolders.end()) + return FileRecord(); // folder not found, return default which has offset of sInvalidOffset + + std::uint64_t fileHash = generateHash(stem, ext); + std::map::const_iterator iter = it->second.files.find(fileHash); + if (iter == it->second.files.end()) + return FileRecord(); // file not found, return default which has offset of sInvalidOffset + + return iter->second; +} + +Files::IStreamPtr CompressedBSAFile::getFile(const FileStruct* file) +{ + FileRecord fileRec = getFileRecord(file->name); + if (!fileRec.isValid()) { + fail("File not found: " + std::string(file->name)); + } + return getFile(fileRec); +} + +Files::IStreamPtr CompressedBSAFile::getFile(const char* file) +{ + FileRecord fileRec = getFileRecord(file); + if (!fileRec.isValid()) { + fail("File not found: " + std::string(file)); + } + return getFile(fileRec); +} + +Files::IStreamPtr CompressedBSAFile::getFile(const FileRecord& fileRecord) +{ + if (fileRecord.isCompressed(mCompressedByDefault)) { + Files::IStreamPtr streamPtr = Files::openConstrainedFileStream(mFilename.c_str(), fileRecord.offset, fileRecord.getSizeWithoutCompressionFlag()); + + std::istream* fileStream = streamPtr.get(); + + if (mEmbeddedFileNames) { + std::string embeddedFileName; + getBZString(embeddedFileName, *fileStream); + } + + uint32_t uncompressedSize = 0u; + fileStream->read(reinterpret_cast(&uncompressedSize), sizeof(uncompressedSize)); + + boost::iostreams::filtering_streambuf inputStreamBuf; + inputStreamBuf.push(boost::iostreams::zlib_decompressor()); + inputStreamBuf.push(*fileStream); + + std::shared_ptr memoryStreamPtr = std::make_shared(uncompressedSize); + + boost::iostreams::basic_array_sink sr(memoryStreamPtr->getRawData(), uncompressedSize); + boost::iostreams::copy(inputStreamBuf, sr); + + return std::shared_ptr(memoryStreamPtr, (std::istream*)memoryStreamPtr.get()); + } + + return Files::openConstrainedFileStream(mFilename.c_str(), fileRecord.offset, fileRecord.size); +} + +BsaVersion CompressedBSAFile::detectVersion(std::string filePath) +{ + namespace bfs = boost::filesystem; + bfs::ifstream input(bfs::path(filePath), std::ios_base::binary); + + // Total archive size + std::streamoff fsize = 0; + if (input.seekg(0, std::ios_base::end)) + { + fsize = input.tellg(); + input.seekg(0); + } + + if (fsize < 12) { + return BSAVER_UNKNOWN; + } + + // Get essential header numbers + + // First 12 bytes + uint32_t head[3]; + + input.read(reinterpret_cast(head), 12); + + if (head[0] == static_cast(BSAVER_UNCOMPRESSED)) { + return BSAVER_UNCOMPRESSED; + } + + if (head[0] == static_cast(BSAVER_COMPRESSED)) { + return BSAVER_COMPRESSED; + } + + return BSAVER_UNKNOWN; +} + +//mFiles used by OpenMW expects uncompressed sizes +void CompressedBSAFile::convertCompressedSizesToUncompressed() +{ + for (auto iter = mFiles.begin(); iter != mFiles.end(); ++iter) + { + const FileRecord& fileRecord = getFileRecord(iter->name); + if (!fileRecord.isValid()) + { + fail("Could not find file " + std::string(iter->name) + " in BSA"); + } + + if (!fileRecord.isCompressed(mCompressedByDefault)) + { + //no need to fix fileSize in mFiles - uncompressed size already set + continue; + } + + Files::IStreamPtr dataBegin = Files::openConstrainedFileStream(mFilename.c_str(), fileRecord.offset, fileRecord.getSizeWithoutCompressionFlag()); + + if (mEmbeddedFileNames) + { + std::string embeddedFileName; + getBZString(embeddedFileName, *(dataBegin.get())); + } + + dataBegin->read(reinterpret_cast(&(iter->fileSize)), sizeof(iter->fileSize)); + } +} + +std::uint64_t CompressedBSAFile::generateHash(std::string stem, std::string extension) const +{ + size_t len = stem.length(); + if (len == 0) return 0; + std::uint64_t hash = 0; + unsigned int hash2 = 0; + Misc::StringUtils::lowerCaseInPlace(stem); + if (extension.empty()) // It's a folder. + std::replace(stem.begin(), stem.end(), '/', '\\'); + else + { + Misc::StringUtils::lowerCaseInPlace(extension); + for (const char &c : extension) + hash = hash * 0x1003f + c; + } + for (size_t i = 1; i < len-2 && len > 3; i++) + hash2 = hash2 * 0x1003f + stem[i]; + hash = (hash + hash2) << 32; + hash2 = (stem[0] << 24) | (len << 16); + if (len >= 3) hash2 |= stem[len-2] << 8; + if (len >= 2) hash2 |= stem[len-1]; + if (!extension.empty()) + { + if (extension == ".kf") hash2 |= 0x80; + else if (extension == ".nif") hash2 |= 0x8000; + else if (extension == ".dds") hash2 |= 0x8080; + else if (extension == ".wav") hash2 |= 0x80000000; + } + return hash + hash2; +} + +} //namespace Bsa diff --git a/components/bsa/compressedbsafile.hpp b/components/bsa/compressedbsafile.hpp new file mode 100644 index 000000000..a22d6e149 --- /dev/null +++ b/components/bsa/compressedbsafile.hpp @@ -0,0 +1,99 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008-2010 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.sourceforge.net/ + + This file (compressedbsafile.hpp) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + Compressed BSA stuff added by cc9cii 2018 + + */ + +#ifndef BSA_COMPRESSED_BSA_FILE_H +#define BSA_COMPRESSED_BSA_FILE_H + +#include + +namespace Bsa +{ + enum BsaVersion + { + BSAVER_UNKNOWN = 0x0, + BSAVER_UNCOMPRESSED = 0x100, + BSAVER_COMPRESSED = 0x415342 //B, S, A + }; + + class CompressedBSAFile : public BSAFile + { + private: + //special marker for invalid records, + //equal to max uint32_t value + static const uint32_t sInvalidOffset; + + //bit marking compression on file size + static const uint32_t sCompressedFlag; + + struct FileRecord + { + std::uint32_t size; + std::uint32_t offset; + + FileRecord(); + bool isCompressed(bool bsaCompressedByDefault) const; + bool isValid() const; + std::uint32_t getSizeWithoutCompressionFlag() const; + }; + + //if files in BSA without 30th bit enabled are compressed + bool mCompressedByDefault; + + //if each file record begins with BZ string with file name + bool mEmbeddedFileNames; + + struct FolderRecord + { + std::uint32_t count; + std::uint32_t offset; + std::map files; + }; + std::map mFolders; + + FileRecord getFileRecord(const std::string& str) const; + + void getBZString(std::string& str, std::istream& filestream); + //mFiles used by OpenMW will contain uncompressed file sizes + void convertCompressedSizesToUncompressed(); + /// \brief Normalizes given filename or folder and generates format-compatible hash. See https://en.uesp.net/wiki/Tes4Mod:Hash_Calculation. + std::uint64_t generateHash(std::string stem, std::string extension) const; + Files::IStreamPtr getFile(const FileRecord& fileRecord); + public: + CompressedBSAFile(); + virtual ~CompressedBSAFile(); + + //checks version of BSA from file header + static BsaVersion detectVersion(std::string filePath); + + /// Read header information from the input source + virtual void readHeader(); + + Files::IStreamPtr getFile(const char* filePath); + Files::IStreamPtr getFile(const FileStruct* fileStruct); + + }; +} + +#endif diff --git a/components/bsa/memorystream.cpp b/components/bsa/memorystream.cpp new file mode 100644 index 000000000..34e98e6b6 --- /dev/null +++ b/components/bsa/memorystream.cpp @@ -0,0 +1,48 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008-2010 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.sourceforge.net/ + + This file (memorystream.cpp) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + Compressed BSA upgrade added by Azdul 2019 + + */ +#include "memorystream.hpp" + + +namespace Bsa +{ +MemoryInputStreamBuf::MemoryInputStreamBuf(size_t bufferSize) : mBufferPtr(bufferSize) +{ + this->setg(mBufferPtr.data(), mBufferPtr.data(), mBufferPtr.data() + bufferSize); +} + +char* MemoryInputStreamBuf::getRawData() { + return mBufferPtr.data(); +} + +MemoryInputStream::MemoryInputStream(size_t bufferSize) : + MemoryInputStreamBuf(bufferSize), + std::istream(static_cast(this)) { + +} + +char* MemoryInputStream::getRawData() { + return MemoryInputStreamBuf::getRawData(); +} +} diff --git a/components/bsa/memorystream.hpp b/components/bsa/memorystream.hpp new file mode 100644 index 000000000..5dbe16ebe --- /dev/null +++ b/components/bsa/memorystream.hpp @@ -0,0 +1,62 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008-2010 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.sourceforge.net/ + + This file (memorystream.hpp) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + 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 + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + Compressed BSA upgrade added by Azdul 2019 + + */ + +#ifndef BSA_MEMORY_STREAM_H +#define BSA_MEMORY_STREAM_H + +#include +#include + +namespace Bsa +{ +/** +Class used internally by MemoryInputStream. +*/ +class MemoryInputStreamBuf : public std::streambuf { + +public: + MemoryInputStreamBuf(size_t bufferSize); + char* getRawData(); +private: + //correct call to delete [] on C++ 11 + std::vector mBufferPtr; +}; + +/** + Class replaces Ogre memory streams without introducing any new external dependencies + beyond standard library. + + Allows to pass memory buffer as Files::IStreamPtr. + + Memory buffer is freed once the class instance is destroyed. + */ +class MemoryInputStream : virtual MemoryInputStreamBuf, std::istream { +public: + MemoryInputStream(size_t bufferSize); + char* getRawData(); +}; + +} +#endif diff --git a/components/compiler/fileparser.cpp b/components/compiler/fileparser.cpp index c9e205b8a..8b2f1fe08 100644 --- a/components/compiler/fileparser.cpp +++ b/components/compiler/fileparser.cpp @@ -94,14 +94,16 @@ namespace Compiler bool FileParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner) { - if (code==Scanner::S_newline) + // Ignore any junk special characters + if (mState == BeginState) { - if (mState==BeginState) - { - // ignore empty lines - return true; - } + if (code != Scanner::S_newline) + reportWarning ("Ignoring stray special character before begin statement", loc); + return true; + } + if (code==Scanner::S_newline) + { if (mState==BeginCompleteState) { // parse the script body diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index 29dbe0391..b20805a11 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -338,6 +338,9 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) if (!comments.empty() && index != -1 && settingRegex.captureCount() >= 2 && mUserSettings.find(settingRegex.cap(1)) != mUserSettings.end()) { + if (commentStart == fileCopy.end()) + throw std::runtime_error("Config::GameSettings: failed to parse settings - iterator is past of end of settings file"); + for (std::vector::const_iterator it = comments.begin(); it != comments.end(); ++it) { *commentStart = *it; diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index 39e91d5a3..7a4558d57 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -474,9 +474,13 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path) void ContentSelectorModel::ContentModel::clearFiles() { - beginRemoveRows(QModelIndex(), 0, mFiles.count()-1); - mFiles.clear(); - endRemoveRows(); + const int filesCount = mFiles.count(); + + if (filesCount > 0) { + beginRemoveRows(QModelIndex(), 0, filesCount - 1); + mFiles.clear(); + endRemoveRows(); + } } QStringList ContentSelectorModel::ContentModel::gameFiles() const diff --git a/components/crashcatcher/crashcatcher.cpp b/components/crashcatcher/crashcatcher.cpp index 2e2ddd1f2..006b190ba 100644 --- a/components/crashcatcher/crashcatcher.cpp +++ b/components/crashcatcher/crashcatcher.cpp @@ -17,6 +17,7 @@ #include #include +#include namespace bfs = boost::filesystem; @@ -34,9 +35,13 @@ namespace bfs = boost::filesystem; #if defined(__APPLE__) #include +#include #endif -#define UNUSED(x) (void)(x) +#if defined(__FreeBSD__) +#include +#include +#endif static const char crash_switch[] = "--cc-handle-crash"; @@ -413,6 +418,39 @@ static void crash_handler(const char *logfile) exit(0); } +static void getExecPath(char **argv) +{ +#if defined (__FreeBSD__) + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + size_t size = sizeof(argv0); + + if (sysctl(mib, 4, argv0, &size, nullptr, 0) == 0) + return; +#endif + +#if defined (__APPLE__) + if(proc_pidpath(getpid(), argv0, sizeof(argv0)) > 0) + return; +#endif + int cwdlen; + const char *statusPaths[] = {"/proc/self/exe", "/proc/self/file", "/proc/curproc/exe", "/proc/curproc/file"}; + memset(argv0, 0, sizeof(argv0)); + + for(const char *path : statusPaths) + { + if (readlink(path, argv0, sizeof(argv0)) != -1) + return; + } + + if(argv[0][0] == '/') + snprintf(argv0, sizeof(argv0), "%s", argv[0]); + else if (getcwd(argv0, sizeof(argv0)) != NULL) + { + cwdlen = strlen(argv0); + snprintf(argv0+cwdlen, sizeof(argv0)-cwdlen, "/%s", argv[0]); + } +} + int crashCatcherInstallHandlers(int argc, char **argv, int num_signals, int *signals, const char *logfile, int (*user_info)(char*, char*)) { struct sigaction sa; @@ -424,20 +462,7 @@ int crashCatcherInstallHandlers(int argc, char **argv, int num_signals, int *sig cc_user_info = user_info; - if(argv[0][0] == '/') - snprintf(argv0, sizeof(argv0), "%s", argv[0]); - else - { - { - /* we don't want to disable "ignoring return value" warnings, so we make - * a special exception here. */ - char * unused; - unused = getcwd(argv0, sizeof(argv0)); - UNUSED(unused); - } - retval = strlen(argv0); - snprintf(argv0+retval, sizeof(argv0)-retval, "/%s", argv[0]); - } + getExecPath(argv); /* Set an alternate signal stack so SIGSEGVs caused by stack overflows * still run */ @@ -467,20 +492,24 @@ int crashCatcherInstallHandlers(int argc, char **argv, int num_signals, int *sig static bool is_debugger_present() { -#if !defined (__APPLE__) - bfs::ifstream file((bfs::path("/proc/self/status"))); - while (!file.eof()) +#if defined (__linux__) + bfs::path procstatus = bfs::path("/proc/self/status"); + if (bfs::exists(procstatus)) { - std::string word; - file >> word; - if (word == "TracerPid:") + bfs::ifstream file((procstatus)); + while (!file.eof()) { + std::string word; file >> word; - return word != "0"; + if (word == "TracerPid:") + { + file >> word; + return word != "0"; + } } } return false; -#else +#elif defined(__APPLE__) int junk; int mib[4]; struct kinfo_proc info; @@ -508,12 +537,24 @@ static bool is_debugger_present() // We're being debugged if the P_TRACED flag is set. return (info.kp_proc.p_flag & P_TRACED) != 0; +#elif defined(__FreeBSD__) + struct kinfo_proc info; + size_t size = sizeof(info); + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; + + if (sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) == 0) + return (info.ki_flag & P_TRACED) != 0; + else + perror("Failed to retrieve process info"); + return false; +#else + return false; #endif } void crashCatcherInstall(int argc, char **argv, const std::string &crashLogPath) { - if ((argc == 2 && strcmp(argv[1], "--cc-handle-crash") == 0) || !is_debugger_present()) + if ((argc == 2 && strcmp(argv[1], crash_switch) == 0) || !is_debugger_present()) { int s[5] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS, SIGABRT }; if (crashCatcherInstallHandlers(argc, argv, 5, s, crashLogPath.c_str(), nullptr) == -1) diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 7c4349d31..657d92d6e 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -1,7 +1,6 @@ #include "loadcell.hpp" #include -#include #include #include @@ -209,9 +208,7 @@ namespace ESM } else { - std::ostringstream stream; - stream << mData.mX << ", " << mData.mY; - return stream.str(); + return std::to_string(mData.mX) + ", " + std::to_string(mData.mY); } } diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 83315a5b8..f04439041 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -23,6 +23,7 @@ namespace ESM { mScale = 1.f; mHasAI = false; + mAiData.blank(); bool hasName = false; bool hasNpdt = false; @@ -160,7 +161,6 @@ namespace ESM { mSpells.mList.clear(); mHasAI = false; mAiData.blank(); - mAiData.mServices = 0; mAiPackage.mList.clear(); mTransport.mList.clear(); } diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index 9e5e9d07e..722154757 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -1,5 +1,6 @@ #include "loadland.hpp" +#include #include #include "esmreader.hpp" @@ -200,9 +201,9 @@ namespace ESM mLandData->mTextures[i] = 0; for (int i = 0; i < LAND_NUM_VERTS; ++i) { - mLandData->mColours[i*3+0] = -1; - mLandData->mColours[i*3+1] = -1; - mLandData->mColours[i*3+2] = -1; + mLandData->mColours[i*3+0] = 255; + mLandData->mColours[i*3+1] = 255; + mLandData->mColours[i*3+2] = 255; } mLandData->mUnk1 = 0; mLandData->mUnk2 = 0; @@ -252,8 +253,8 @@ namespace ESM if (reader.isNextSub("VHGT")) { VHGT vhgt; if (condLoad(reader, flags, target->mDataLoaded, DATA_VHGT, &vhgt, sizeof(vhgt))) { - target->mMinHeight = FLT_MAX; - target->mMaxHeight = -FLT_MAX; + target->mMinHeight = std::numeric_limits::max(); + target->mMaxHeight = -std::numeric_limits::max(); float rowOffset = vhgt.mHeightOffset; for (int y = 0; y < LAND_SIZE; y++) { rowOffset += vhgt.mHeightData[y * LAND_SIZE]; diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index dd34934ad..6e7ba66c5 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -18,6 +18,7 @@ namespace ESM mInventory.mList.clear(); mTransport.mList.clear(); mAiPackage.mList.clear(); + mAiData.blank(); mHasAI = false; bool hasName = false; diff --git a/components/interpreter/interpreter.cpp b/components/interpreter/interpreter.cpp index e77a0bb72..b64369e70 100644 --- a/components/interpreter/interpreter.cpp +++ b/components/interpreter/interpreter.cpp @@ -1,7 +1,6 @@ #include "interpreter.hpp" #include -#include #include #include "opcodes.hpp" @@ -116,20 +115,14 @@ namespace Interpreter void Interpreter::abortUnknownCode (int segment, int opcode) { - std::ostringstream error; - - error << "unknown opcode " << opcode << " in segment " << segment; - - throw std::runtime_error (error.str()); + const std::string error = "unknown opcode " + std::to_string(opcode) + " in segment " + std::to_string(segment); + throw std::runtime_error (error); } void Interpreter::abortUnknownSegment (Type_Code code) { - std::ostringstream error; - - error << "opcode outside of the allocated segment range: " << code; - - throw std::runtime_error (error.str()); + const std::string error = "opcode outside of the allocated segment range: " + std::to_string(code); + throw std::runtime_error (error); } void Interpreter::begin() diff --git a/components/nif/controller.cpp b/components/nif/controller.cpp index 49f591b47..26c3f43f0 100644 --- a/components/nif/controller.cpp +++ b/components/nif/controller.cpp @@ -139,7 +139,7 @@ namespace Nif { Controller::read(nif); - nif->getUShort(); // always 0 + uvSet = nif->getUShort(); data.read(nif); } diff --git a/components/nif/controller.hpp b/components/nif/controller.hpp index f22d10622..7a05b0715 100644 --- a/components/nif/controller.hpp +++ b/components/nif/controller.hpp @@ -112,6 +112,7 @@ class NiUVController : public Controller { public: NiUVDataPtr data; + int uvSet; void read(NIFStream *nif); void post(NIFFile *nif); diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index eb20b7702..1b064c85c 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -324,6 +325,7 @@ namespace NifOsg osg::ref_ptr handleLodNode(const Nif::NiLODNode* niLodNode) { osg::ref_ptr lod (new osg::LOD); + lod->setName(niLodNode->name); lod->setCenterMode(osg::LOD::USER_DEFINED_CENTER); lod->setCenter(niLodNode->lodCenter); for (unsigned int i=0; ilodLevels.size(); ++i) @@ -335,6 +337,14 @@ namespace NifOsg return lod; } + osg::ref_ptr handleSwitchNode(const Nif::NiSwitchNode* niSwitchNode) + { + osg::ref_ptr switchNode (new osg::Switch); + switchNode->setName(niSwitchNode->name); + switchNode->setNewChildDefaultValue(false); + return switchNode; + } + osg::ref_ptr handleSourceTexture(const Nif::NiSourceTexture* st, Resource::ImageManager* imageManager) { if (!st) @@ -593,6 +603,23 @@ namespace NifOsg node = lod; } + if (nifNode->recType == Nif::RC_NiSwitchNode) + { + const Nif::NiSwitchNode* niSwitchNode = static_cast(nifNode); + osg::ref_ptr switchNode = handleSwitchNode(niSwitchNode); + node->addChild(switchNode); + const Nif::NodeList &children = niSwitchNode->children; + for(size_t i = 0;i < children.length();++i) + { + if(!children[i].empty()) + handleNode(children[i].getPtr(), switchNode, imageManager, boundTextures, animflags, skipMeshes, hasMarkers, isAnimated, textKeys, rootNode); + } + + // show only first child by default + switchNode->setSingleChildOn(0); + return switchNode; + } + const Nif::NiNode *ninode = dynamic_cast(nifNode); if(ninode) { @@ -623,9 +650,14 @@ namespace NifOsg if (ctrl->recType == Nif::RC_NiUVController) { const Nif::NiUVController *niuvctrl = static_cast(ctrl.getPtr()); + const int uvSet = niuvctrl->uvSet; std::set texUnits; + // UVController should work only for textures which use a given UV Set, usually 0. for (unsigned int i=0; i uvctrl = new UVController(niuvctrl->data.getPtr(), texUnits); setupController(niuvctrl, uvctrl, animflags); @@ -822,7 +854,9 @@ namespace NifOsg if (particle.vertex < int(particledata->colors.size())) partcolor = particledata->colors.at(particle.vertex); - float size = particledata->sizes.at(particle.vertex) * partctrl->size; + float size = partctrl->size; + if (particle.vertex < int(particledata->sizes.size())) + size *= particledata->sizes.at(particle.vertex); created->setSizeRange(osgParticle::rangef(size, size)); box.expandBy(osg::BoundingSphere(position, size)); @@ -1092,13 +1126,12 @@ namespace NifOsg const std::vector &weights = data->bones[i].weights; for(size_t j = 0;j < weights.size();j++) { - std::pair indexWeight = std::make_pair(weights[j].vertex, weights[j].weight); - influence.mWeights.insert(indexWeight); + influence.mWeights.emplace_back(weights[j].vertex, weights[j].weight); } influence.mInvBindMatrix = data->bones[i].trafo.toMatrix(); influence.mBoundSphere = osg::BoundingSpheref(data->bones[i].boundSphereCenter, data->bones[i].boundSphereRadius); - map->mMap.insert(std::make_pair(boneName, influence)); + map->mData.emplace_back(boneName, influence); } rig->setInfluenceMap(map); diff --git a/components/sceneutil/optimizer.cpp b/components/sceneutil/optimizer.cpp index 5d50c369d..25ad03fba 100644 --- a/components/sceneutil/optimizer.cpp +++ b/components/sceneutil/optimizer.cpp @@ -737,6 +737,20 @@ bool Optimizer::CombineStaticTransformsVisitor::removeTransforms(osg::Node* node // RemoveEmptyNodes. //////////////////////////////////////////////////////////////////////////// +void Optimizer::RemoveEmptyNodesVisitor::apply(osg::Switch& switchNode) +{ + // We should keep all switch child nodes since they reflect different switch states. + for (unsigned int i=0; i0) @@ -807,6 +821,13 @@ void Optimizer::RemoveRedundantNodesVisitor::apply(osg::LOD& lod) traverse(*lod.getChild(i)); } +void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Switch& switchNode) +{ + // We should keep all switch child nodes since they reflect different switch states. + for (unsigned int i=0; i > Vertex2BoneMap; Vertex2BoneMap vertex2BoneMap; - for (std::map::const_iterator it = mInfluenceMap->mMap.begin(); it != mInfluenceMap->mMap.end(); ++it) + mBoneSphereVector.clear(); + for (auto& influencePair : mInfluenceMap->mData) { - Bone* bone = mSkeleton->getBone(it->first); + Bone* bone = mSkeleton->getBone(influencePair.first); if (!bone) { - Log(Debug::Error) << "Error: RigGeometry did not find bone " << it->first ; + Log(Debug::Error) << "Error: RigGeometry did not find bone " << influencePair.first; continue; } - mBoneSphereMap[bone] = it->second.mBoundSphere; + const BoneInfluence& bi = influencePair.second; + mBoneSphereVector.emplace_back(bone, bi.mBoundSphere); - const BoneInfluence& bi = it->second; - - const std::map& weights = it->second.mWeights; - for (std::map::const_iterator weightIt = weights.begin(); weightIt != weights.end(); ++weightIt) + for (auto& weightPair: bi.mWeights) { - std::vector& vec = vertex2BoneMap[weightIt->first]; - - BoneWeight b = std::make_pair(std::make_pair(bone, bi.mInvBindMatrix), weightIt->second); + std::vector& vec = vertex2BoneMap[weightPair.first]; - vec.push_back(b); + vec.emplace_back(std::make_pair(bone, bi.mInvBindMatrix), weightPair.second); } } + Bone2VertexMap bone2VertexMap; for (Vertex2BoneMap::iterator it = vertex2BoneMap.begin(); it != vertex2BoneMap.end(); ++it) { - mBone2VertexMap[it->second].push_back(it->first); + bone2VertexMap[it->second].push_back(it->first); } + mBone2VertexVector.assign(bone2VertexMap.begin(), bone2VertexMap.end()); + return true; } @@ -201,7 +201,7 @@ void RigGeometry::cull(osg::NodeVisitor* nv) osg::Vec3Array* normalDst = static_cast(geom.getNormalArray()); osg::Vec4Array* tangentDst = static_cast(geom.getTexCoordArray(7)); - for (auto &pair : mBone2VertexMap) + for (auto &pair : mBone2VertexVector) { osg::Matrixf resultMat (0, 0, 0, 0, 0, 0, 0, 0, @@ -263,10 +263,10 @@ void RigGeometry::updateBounds(osg::NodeVisitor *nv) updateGeomToSkelMatrix(nv->getNodePath()); osg::BoundingBox box; - for (BoneSphereMap::const_iterator it = mBoneSphereMap.begin(); it != mBoneSphereMap.end(); ++it) + for (auto& boundPair : mBoneSphereVector) { - Bone* bone = it->first; - osg::BoundingSpheref bs = it->second; + Bone* bone = boundPair.first; + osg::BoundingSpheref bs = boundPair.second; if (mGeomToSkelMatrix) transformBoundingSphere(bone->mMatrixInSkeletonSpace * (*mGeomToSkelMatrix), bs); else diff --git a/components/sceneutil/riggeometry.hpp b/components/sceneutil/riggeometry.hpp index 60b3edc9d..5dd05507c 100644 --- a/components/sceneutil/riggeometry.hpp +++ b/components/sceneutil/riggeometry.hpp @@ -31,12 +31,12 @@ namespace SceneUtil osg::Matrixf mInvBindMatrix; osg::BoundingSpheref mBoundSphere; // - std::map mWeights; + std::vector> mWeights; }; struct InfluenceMap : public osg::Referenced { - std::map mMap; + std::vector> mData; }; void setInfluenceMap(osg::ref_ptr influenceMap); @@ -73,12 +73,13 @@ namespace SceneUtil typedef std::vector VertexList; typedef std::map, VertexList> Bone2VertexMap; + typedef std::vector, VertexList>> Bone2VertexVector; - Bone2VertexMap mBone2VertexMap; + Bone2VertexVector mBone2VertexVector; - typedef std::map BoneSphereMap; + typedef std::vector> BoneSphereVector; - BoneSphereMap mBoneSphereMap; + BoneSphereVector mBoneSphereVector; unsigned int mLastFrameNumber; bool mBoundsFirstFrame; diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 66e5dfc04..27463ea88 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -8,48 +8,6 @@ #include #include -namespace -{ - - bool parseBool(const std::string& string) - { - return (Misc::StringUtils::ciEqual(string, "true")); - } - - float parseFloat(const std::string& string) - { - std::stringstream stream; - stream << string; - float ret = 0.f; - stream >> ret; - return ret; - } - - int parseInt(const std::string& string) - { - std::stringstream stream; - stream << string; - int ret = 0; - stream >> ret; - return ret; - } - - template - std::string toString(T val) - { - std::ostringstream stream; - stream << val; - return stream.str(); - } - - template <> - std::string toString(bool val) - { - return val ? "true" : "false"; - } - -} - namespace Settings { @@ -393,17 +351,36 @@ std::string Manager::getString(const std::string &setting, const std::string &ca float Manager::getFloat (const std::string& setting, const std::string& category) { - return parseFloat( getString(setting, category) ); + const std::string value = getString(setting, category); + try + { + return std::stof(value); + } + catch(const std::exception& e) + { + Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ")."; + return 0; + } } int Manager::getInt (const std::string& setting, const std::string& category) { - return parseInt( getString(setting, category) ); + const std::string value = getString(setting, category); + try + { + return std::stoi(value); + } + catch(const std::exception& e) + { + Log(Debug::Warning) << "Cannot parse setting '" << setting << "' (invalid setting value: " << value << ")."; + return 0; + } } bool Manager::getBool (const std::string& setting, const std::string& category) { - return parseBool( getString(setting, category) ); + const std::string& string = getString(setting, category); + return Misc::StringUtils::ciEqual(string, "true"); } void Manager::setString(const std::string &setting, const std::string &category, const std::string &value) @@ -424,17 +401,17 @@ void Manager::setString(const std::string &setting, const std::string &category, void Manager::setInt (const std::string& setting, const std::string& category, const int value) { - setString(setting, category, toString(value)); + setString(setting, category, std::to_string(value)); } void Manager::setFloat (const std::string &setting, const std::string &category, const float value) { - setString(setting, category, toString(value)); + setString(setting, category, std::to_string(value)); } void Manager::setBool(const std::string &setting, const std::string &category, const bool value) { - setString(setting, category, toString(value)); + setString(setting, category, value ? "true" : "false"); } const CategorySettingVector Manager::apply() diff --git a/components/vfs/bsaarchive.cpp b/components/vfs/bsaarchive.cpp index a527a6ad9..925c1076e 100644 --- a/components/vfs/bsaarchive.cpp +++ b/components/vfs/bsaarchive.cpp @@ -1,20 +1,33 @@ #include "bsaarchive.hpp" +#include +#include namespace VFS { - BsaArchive::BsaArchive(const std::string &filename) { - mFile.open(filename); + Bsa::BsaVersion bsaVersion = Bsa::CompressedBSAFile::detectVersion(filename); + + if (bsaVersion == Bsa::BSAVER_COMPRESSED) { + mFile = std::unique_ptr(new Bsa::CompressedBSAFile()); + } + else { + mFile = std::unique_ptr(new Bsa::BSAFile()); + } - const Bsa::BSAFile::FileList &filelist = mFile.getList(); + mFile->open(filename); + + const Bsa::BSAFile::FileList &filelist = mFile->getList(); for(Bsa::BSAFile::FileList::const_iterator it = filelist.begin();it != filelist.end();++it) { - mResources.push_back(BsaArchiveFile(&*it, &mFile)); + mResources.push_back(BsaArchiveFile(&*it, mFile.get())); } } +BsaArchive::~BsaArchive() { +} + void BsaArchive::listResources(std::map &out, char (*normalize_function)(char)) { for (std::vector::iterator it = mResources.begin(); it != mResources.end(); ++it) diff --git a/components/vfs/bsaarchive.hpp b/components/vfs/bsaarchive.hpp index a6e274037..a87f278c7 100644 --- a/components/vfs/bsaarchive.hpp +++ b/components/vfs/bsaarchive.hpp @@ -7,7 +7,6 @@ namespace VFS { - class BsaArchiveFile : public File { public: @@ -23,15 +22,13 @@ namespace VFS { public: BsaArchive(const std::string& filename); - + virtual ~BsaArchive(); virtual void listResources(std::map& out, char (*normalize_function) (char)); private: - Bsa::BSAFile mFile; - + std::unique_ptr mFile; std::vector mResources; }; - } #endif diff --git a/components/widgets/fontwrapper.hpp b/components/widgets/fontwrapper.hpp index 2424b22a7..84406c70c 100644 --- a/components/widgets/fontwrapper.hpp +++ b/components/widgets/fontwrapper.hpp @@ -14,18 +14,10 @@ namespace Gui virtual void setFontName(const std::string& name) { T::setFontName(name); - T::setPropertyOverride ("FontHeight", mFontSize); + T::setPropertyOverride ("FontHeight", getFontSize()); } protected: - FontWrapper() - { - // Note: we can not use the WindowManager here, so there is a code duplication a bit. - int fontSize = Settings::Manager::getInt("font size", "GUI"); - fontSize = std::min(std::max(12, fontSize), 20); - mFontSize = std::to_string(fontSize); - } - virtual void setPropertyOverride(const std::string& _key, const std::string& _value) { T::setPropertyOverride (_key, _value); @@ -34,11 +26,22 @@ namespace Gui // We should restore it. if (_key == "FontName") { - T::setPropertyOverride ("FontHeight", mFontSize); + T::setPropertyOverride ("FontHeight", getFontSize()); } } - std::string mFontSize; + private: + static int clamp(const int& value, const int& lowBound, const int& highBound) + { + return std::min(std::max(lowBound, value), highBound); + } + + std::string getFontSize() + { + // Note: we can not use the WindowManager here, so there is a code duplication a bit. + static const std::string fontSize = std::to_string(clamp(Settings::Manager::getInt("font size", "GUI"), 12, 20)); + return fontSize; + } }; } diff --git a/docs/source/reference/modding/font.rst b/docs/source/reference/modding/font.rst index cae320633..d230164c5 100644 --- a/docs/source/reference/modding/font.rst +++ b/docs/source/reference/modding/font.rst @@ -23,11 +23,12 @@ This is the recommended way to install replacement fonts. - To replace the primary "Magic Cards" font: - #. Download `Pelagiad `_ by Isak Larborn (aka Isaskar). - #. Create ``Fonts`` folder at the location of your ``openmw.cfg``. - #. Copy ``openmw_font.xml`` and ``Pelagiad.ttf`` files into the folder. - #. If desired, you can now delete the original ``Magic_Cards.*`` files from your ``Data Files/Fonts`` directory. - #. Pelagiad glyphs may appear to be pretty small, so open ``openmw.cfg`` and adjust the following settings as you deem necessary:: + 1. Download `Pelagiad `_ by Isak Larborn (aka Isaskar). + 2. Create ``Fonts`` folder at the location of your ``openmw.cfg``. + 3. Copy ``openmw_font.xml`` and ``Pelagiad.ttf`` files into the folder. + 4. Either remove the ``MonoFont`` entry from the created ``openmw_font.xml`` or copy the ``DejaVuLGCSansMono.ttf`` to the ``Fonts`` folder (prefer latter option on Windows). + 5. If desired, you can now delete the original ``Magic_Cards.*`` files from your ``Data Files/Fonts`` directory. + 6. Pelagiad glyphs may appear to be pretty small, so open ``settings.cfg`` and adjust the following settings as you deem necessary:: [GUI] font size = 17 @@ -35,9 +36,9 @@ This is the recommended way to install replacement fonts. - You can also replace the Daedric font: - #. Download `Ayembedt `_ by Georg Duffner. - #. Install ``OMWAyembedt.otf`` into the ``Fonts`` folder. - #. Add the following lines into ``openmw_font.xml``:: + 1. Download `Ayembedt `_ by Georg Duffner. + 2. Install ``OMWAyembedt.otf`` into the ``Fonts`` folder. + 3. Add the following lines into ``openmw_font.xml``:: @@ -51,7 +52,7 @@ This is the recommended way to install replacement fonts. - #. This font is missing a few glyphs (mostly punctuation), but it has all the primary glyphs. If desired, you can now delete the original ``daedric.*`` files from your ``Data Files/Fonts`` directory. + 4. This font is missing a few glyphs (mostly punctuation), but it has all the primary glyphs. If desired, you can now delete the original ``daedric.*`` files from your ``Data Files/Fonts`` directory. Any Resolution or Size properties in the file have no effect because the engine settings override them. @@ -62,15 +63,15 @@ Pre-0.45.0 way - To replace the primary "Magic Cards" font: - #. Download `Pelagiad `_ by Isak Larborn (aka Isaskar). - #. Install the ``openmw_font.xml`` file into ``resources/mygui/openmw_font.xml`` in your OpenMW installation. - #. Copy ``Pelagiad.ttf`` into ``resources/mygui/`` as well. - #. If desired, you can now delete the original ``Magic_Cards.*`` files from your ``Data Files/Fonts`` directory. + 1. Download `Pelagiad `_ by Isak Larborn (aka Isaskar). + 2. Install the ``openmw_font.xml`` file into ``resources/mygui/openmw_font.xml`` in your OpenMW installation. + 3. Copy ``Pelagiad.ttf`` into ``resources/mygui/`` as well. + 4. If desired, you can now delete the original ``Magic_Cards.*`` files from your ``Data Files/Fonts`` directory. - You can also replace the Daedric font: - #. Download `Ayembedt `_ by Georg Duffner. - #. Install ``OMWAyembedt.otf`` into ``/resources/mygui/`` folder in your OpenMW installation. - #. Add the following lines to ``openmw_font.xml``:: + 1. Download `Ayembedt `_ by Georg Duffner. + 2. Install ``OMWAyembedt.otf`` into ``/resources/mygui/`` folder in your OpenMW installation. + 3. Add the following lines to ``openmw_font.xml``:: @@ -86,12 +87,12 @@ Pre-0.45.0 way - #. This font is missing a few glyphs (mostly punctuation), but it has all the primary glyphs. If desired, you can now delete the original ``daedric.*`` files from your ``Data Files/Fonts`` directory. + 4. This font is missing a few glyphs (mostly punctuation), but it has all the primary glyphs. If desired, you can now delete the original ``daedric.*`` files from your ``Data Files/Fonts`` directory. - Another replacement for the Daedric font is `Oblivion `_ by Dongle. - #. Install the ``Oblivion.ttf`` file into ``resources/mygui/``. - #. The ``openmw_font.xml`` entry is:: + 1. Install the ``Oblivion.ttf`` file into ``resources/mygui/``. + 2. The ``openmw_font.xml`` entry is:: diff --git a/docs/source/reference/modding/texture-modding/convert-bump-mapped-mods.rst b/docs/source/reference/modding/texture-modding/convert-bump-mapped-mods.rst index 5fbff38d4..d87e4d244 100644 --- a/docs/source/reference/modding/texture-modding/convert-bump-mapped-mods.rst +++ b/docs/source/reference/modding/texture-modding/convert-bump-mapped-mods.rst @@ -237,9 +237,9 @@ Since we want the glory of normal mapping in our OpenMW setup, we will go with t #. OpenMW detects normal maps if they have the same name as the base diffuse texture, but with a *_n.dds* suffix. In this mod, the normal maps has a suffix of *_nm.dds*. Change all the files that ends with *_nm.dds* to instead end with *_n.dds*. #. Finally, `we are done`_! -Since these models have one or two textures applied to them, the fix was not that time-consuming. -It gets worse when you have to fix a model that uses loads of textures. The principle is the same, -it just requires more manual work which is annoying and takes time. +Since these models have one or two textures applied to them, the fix was not that time-consuming. The process continues to work for more complex models that use more textures, but looking through each category for texture effects and normal mapped textures rapidly becomes tedious. Luckily, NifSkope provides a feature to do the same automatically. + +Rightclick in NifSkope to access the *Spells* dropdown menu, also available via the top bar, hover over the *Blocks* section, and `choose the action to Remove by ID`_. You can then input the RegEx expression ``^NiTextureEffect`` (directing it to remove any block whose name starts with "NiTextureEffect") to automatically remove all texture effect blocks within the NIF. This also has the helpful side effect of listing `all the blocks within the NIF in the bottom section`_, allowing you to additionally root out any blocks referencing *_nm.dds* textures without having to painstakingly open each category. .. _`Netch Bump mapped`: https://www.nexusmods.com/morrowind/mods/42851/? .. _`Hlaalu Bump mapped`: https://www.nexusmods.com/morrowind/mods/42396/? @@ -256,3 +256,5 @@ it just requires more manual work which is annoying and takes time. .. _Blocks: https://imgur.com/VmQC0WG .. _`no longer have shiny models`: https://imgur.com/vu1k7n1 .. _`we are done`: https://imgur.com/yyZxlTw +.. _`choose the action to Remove by ID`: https://imgur.com/a/qs2t0tC +.. _`all the blocks within the NIF in the bottom section`: https://imgur.com/a/UFFNyWt diff --git a/files/mygui/openmw_hud.layout b/files/mygui/openmw_hud.layout index cee3f4682..b3e3cfb9d 100644 --- a/files/mygui/openmw_hud.layout +++ b/files/mygui/openmw_hud.layout @@ -72,7 +72,7 @@ - + diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index ed1322609..731e8cbd8 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -68,7 +68,7 @@ void main() vec3 normalizedNormal = normalize(passNormal); vec3 normalizedTangent = normalize(passTangent.xyz); - vec3 binormal = cross(normalizedTangent, normalizedNormal); + vec3 binormal = cross(normalizedTangent, normalizedNormal) * passTangent.w; mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal); vec3 viewNormal = gl_NormalMatrix * normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));