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 ef0a945a5..51b1720c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,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 @@ -37,9 +37,9 @@ addons: build_command: "make VERBOSE=1 -j3" matrix: include: - - name: OpenMW (all) on MacOS xcode9.4 + - name: OpenMW (all) on macOS Xcode 10.1 os: osx - osx_image: xcode9.4 + osx_image: xcode10.1 if: branch != coverity_scan - name: OpenMW (all) on Ubuntu Xenial GCC-5 os: linux @@ -90,6 +90,7 @@ script: - cd ./build - if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ${ANALYZE} make -j3; fi - if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TRAVIS_OS_NAME}" = "osx" ]; then make package; fi + - if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TRAVIS_OS_NAME}" = "osx" ]; then ../CI/check_package.osx.sh; fi - if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./openmw_test_suite; fi - if [ "${COVERITY_SCAN_BRANCH}" != 1 ] && [ "${TRAVIS_OS_NAME}" = "linux" ]; then cd .. && ./CI/check_tabs.sh; fi - cd "${TRAVIS_BUILD_DIR}" diff --git a/CHANGELOG.md b/CHANGELOG.md index d28da21ce..31e086842 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ 0.46.0 ------ + Bug #2987: Editor: some chance and AI data fields can overflow Bug #3623: Fix HiDPI on Windows + 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 Bug #4714: Crash upon game load in the repair menu while the "Your repair failed!" message is active @@ -11,11 +15,18 @@ Bug #4745: Editor: Interior cell lighting field values are not displayed as colors 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 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 d75ee3be5..e411a1d9b 100755 --- a/CI/before_install.osx.sh +++ b/CI/before_install.osx.sh @@ -1,10 +1,11 @@ #!/bin/sh -e brew update - -brew outdated cmake || brew upgrade cmake +brew unlink cmake || true +brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/a3b64391ebace30b84de8e7997665a1621c0b2c0/Formula/cmake.rb +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-7cf2789.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 dfc3b3147..4a114490c 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/before_script.osx.sh b/CI/before_script.osx.sh index 16f461639..d3994a7ae 100755 --- a/CI/before_script.osx.sh +++ b/CI/before_script.osx.sh @@ -11,7 +11,7 @@ cd build cmake \ -D CMAKE_PREFIX_PATH="$DEPENDENCIES_ROOT;$QT_PATH" \ -D CMAKE_OSX_DEPLOYMENT_TARGET="10.9" \ --D CMAKE_OSX_SYSROOT="macosx10.13" \ +-D CMAKE_OSX_SYSROOT="macosx10.14" \ -D CMAKE_BUILD_TYPE=Release \ -D OPENMW_OSX_DEPLOYMENT=TRUE \ -D DESIRED_QT_VERSION=5 \ diff --git a/CI/check_package.osx.sh b/CI/check_package.osx.sh new file mode 100755 index 000000000..f5da5c273 --- /dev/null +++ b/CI/check_package.osx.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +hdiutil attach ./*.dmg -mountpoint "${TRAVIS_BUILD_DIR}/openmw-package" > /dev/null || echo "hdutil has failed" + +EXPECTED_PACKAGE_FILES=('Applications' 'OpenMW-CS.app' 'OpenMW.app') +PACKAGE_FILES=$(ls "${TRAVIS_BUILD_DIR}/openmw-package" | LC_ALL=C sort) + +DIFF=$(diff <(printf "%s\n" "${EXPECTED_PACKAGE_FILES[@]}") <(printf "%s\n" "${PACKAGE_FILES[@]}")) +DIFF_STATUS=$? + +if [[ $DIFF_STATUS -ne 0 ]]; then + echo "The package should only contain an Applications symlink and two applications, see the following diff for details." >&2 + echo "$DIFF" >&2 + exit 1 +fi 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 722467f32..795a7d309 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -296,9 +296,9 @@ if(QT_STATIC) endif() -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) @@ -604,7 +604,7 @@ set(RECASTNAVIGATION_DEMO OFF CACHE BOOL "Do not build RecastDemo") set(RECASTNAVIGATION_STATIC ON CACHE BOOL "Build recastnavigation static libraries") set(RECASTNAVIGATION_TESTS OFF CACHE BOOL "Do not build recastnavigation tests") -add_subdirectory (extern/recastnavigation) +add_subdirectory (extern/recastnavigation EXCLUDE_FROM_ALL) add_subdirectory (extern/osg-ffmpeg-videoplayer) add_subdirectory (extern/oics) if (BUILD_OPENCS) @@ -795,6 +795,10 @@ endif() # Apple bundling if (OPENMW_OSX_DEPLOYMENT AND APPLE AND DESIRED_QT_VERSION MATCHES 5) + if (${CMAKE_MAJOR_VERSION} STREQUAL "3" AND ${CMAKE_MINOR_VERSION} STREQUAL "13") + message(FATAL_ERROR "macOS packaging is broken in CMake 3.13.*, see https://gitlab.com/OpenMW/openmw/issues/4767. Please use an older version like 3.12.4") + endif () + get_property(QT_COCOA_PLUGIN_PATH TARGET Qt5::QCocoaIntegrationPlugin PROPERTY LOCATION_RELEASE) get_filename_component(QT_COCOA_PLUGIN_DIR "${QT_COCOA_PLUGIN_PATH}" DIRECTORY) get_filename_component(QT_COCOA_PLUGIN_GROUP "${QT_COCOA_PLUGIN_DIR}" NAME) 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/referenceablecheck.cpp b/apps/opencs/model/tools/referenceablecheck.cpp index fdbab7fd0..73c28f564 100644 --- a/apps/opencs/model/tools/referenceablecheck.cpp +++ b/apps/opencs/model/tools/referenceablecheck.cpp @@ -470,6 +470,13 @@ void CSMTools::ReferenceableCheckStage::creatureCheck ( if (creature.mData.mSoul < 0) messages.add(id, "Soul value is negative", "", CSMDoc::Message::Severity_Error); + if (creature.mAiData.mAlarm > 100) + messages.add(id, "Alarm rating is over 100", "", CSMDoc::Message::Severity_Warning); + if (creature.mAiData.mFight > 100) + messages.add(id, "Fight rating is over 100", "", CSMDoc::Message::Severity_Warning); + if (creature.mAiData.mFlee > 100) + messages.add(id, "Flee rating is over 100", "", CSMDoc::Message::Severity_Warning); + for (int i = 0; i < 6; ++i) { if (creature.mData.mAttack[i] < 0) @@ -700,6 +707,13 @@ void CSMTools::ReferenceableCheckStage::npcCheck ( if (level <= 0) messages.add(id, "Level is non-positive", "", CSMDoc::Message::Severity_Warning); + if (npc.mAiData.mAlarm > 100) + messages.add(id, "Alarm rating is over 100", "", CSMDoc::Message::Severity_Warning); + if (npc.mAiData.mFight > 100) + messages.add(id, "Fight rating is over 100", "", CSMDoc::Message::Severity_Warning); + if (npc.mAiData.mFlee > 100) + messages.add(id, "Flee rating is over 100", "", CSMDoc::Message::Severity_Warning); + if (gold < 0) messages.add(id, "Gold count is negative", "", CSMDoc::Message::Severity_Error); @@ -1014,6 +1028,11 @@ template void CSMTools::ReferenceableCheckStage::toolCheck ( template void CSMTools::ReferenceableCheckStage::listCheck ( const List& someList, CSMDoc::Messages& messages, const std::string& someID) { + if (someList.mChanceNone > 100) + { + messages.add(someID, "Chance that no object is used is over 100 percent", "", CSMDoc::Message::Severity_Warning); + } + for (unsigned i = 0; i < someList.mList.size(); ++i) { if (mReferencables.searchId(someList.mList[i].mId).first == -1) diff --git a/apps/opencs/model/tools/regioncheck.cpp b/apps/opencs/model/tools/regioncheck.cpp index 0b6537d7f..1e6f64786 100644 --- a/apps/opencs/model/tools/regioncheck.cpp +++ b/apps/opencs/model/tools/regioncheck.cpp @@ -42,5 +42,11 @@ void CSMTools::RegionCheckStage::perform (int stage, CSMDoc::Messages& messages) if (chances != 100) messages.add(id, "Weather chances do not add up to 100", "", CSMDoc::Message::Severity_Error); + for (const ESM::Region::SoundRef& sound : region.mSoundList) + { + if (sound.mChance > 100) + messages.add(id, "Chance of '" + sound.mSound.toString() + "' sound to play is over 100 percent", "", CSMDoc::Message::Severity_Warning); + } + /// \todo check data members that can't be edited in the table view } 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/data.cpp b/apps/opencs/model/world/data.cpp index 53bd04147..9e9447c5a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -205,7 +205,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, bool fsStrict, const Files::Pat mRegions.getNestableColumn(index)->addColumn( new NestedChildColumn (Columns::ColumnId_SoundName, ColumnBase::Display_Sound)); mRegions.getNestableColumn(index)->addColumn( - new NestedChildColumn (Columns::ColumnId_SoundChance, ColumnBase::Display_Integer)); + new NestedChildColumn (Columns::ColumnId_SoundChance, ColumnBase::Display_UnsignedInteger8)); mBirthsigns.addColumn (new StringIdColumn); mBirthsigns.addColumn (new RecordStateColumn); @@ -989,23 +989,29 @@ void CSMWorld::Data::loadFallbackEntries() std::make_pair("PrisonMarker", "marker_prison.nif") }; - for (const std::pair marker : staticMarkers) + for (const std::pair &marker : staticMarkers) { if (mReferenceables.searchId (marker.first)==-1) { + ESM::Static newMarker; + newMarker.mId = marker.first; + newMarker.mModel = marker.second; CSMWorld::Record record; - record.mBase = ESM::Static(marker.first, marker.second); + record.mBase = newMarker; record.mState = CSMWorld::RecordBase::State_BaseOnly; mReferenceables.appendRecord (record, CSMWorld::UniversalId::Type_Static); } } - for (const std::pair marker : doorMarkers) + for (const std::pair &marker : doorMarkers) { if (mReferenceables.searchId (marker.first)==-1) { + ESM::Door newMarker; + newMarker.mId = marker.first; + newMarker.mModel = marker.second; CSMWorld::Record record; - record.mBase = ESM::Door(marker.first, std::string(), marker.second, std::string(), std::string(), std::string()); + record.mBase = newMarker; record.mState = CSMWorld::RecordBase::State_BaseOnly; mReferenceables.appendRecord (record, CSMWorld::UniversalId::Type_Door); } 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/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 272722f64..89d346204 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -128,13 +128,13 @@ CSMWorld::RefIdCollection::RefIdCollection() ActorColumns actorsColumns (nameColumns); - mColumns.push_back (RefIdColumn (Columns::ColumnId_AiHello, ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiHello, ColumnBase::Display_UnsignedInteger8)); actorsColumns.mHello = &mColumns.back(); - mColumns.push_back (RefIdColumn (Columns::ColumnId_AiFlee, ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiFlee, ColumnBase::Display_UnsignedInteger8)); actorsColumns.mFlee = &mColumns.back(); - mColumns.push_back (RefIdColumn (Columns::ColumnId_AiFight, ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiFight, ColumnBase::Display_UnsignedInteger8)); actorsColumns.mFight = &mColumns.back(); - mColumns.push_back (RefIdColumn (Columns::ColumnId_AiAlarm, ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiAlarm, ColumnBase::Display_UnsignedInteger8)); actorsColumns.mAlarm = &mColumns.back(); // Nested table @@ -645,7 +645,7 @@ CSMWorld::RefIdCollection::RefIdCollection() mColumns.back().addColumn( new RefIdColumn (Columns::ColumnId_LevelledItemType, CSMWorld::ColumnBase::Display_Boolean)); mColumns.back().addColumn( - new RefIdColumn (Columns::ColumnId_LevelledItemChanceNone, CSMWorld::ColumnBase::Display_Integer)); + new RefIdColumn (Columns::ColumnId_LevelledItemChanceNone, CSMWorld::ColumnBase::Display_UnsignedInteger8)); mAdapters.insert (std::make_pair (UniversalId::Type_Activator, new NameRefIdAdapter (UniversalId::Type_Activator, nameColumns))); 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/android_main.c b/apps/openmw/android_main.c index 9a7b6bc50..393d48d77 100644 --- a/apps/openmw/android_main.c +++ b/apps/openmw/android_main.c @@ -20,14 +20,14 @@ void releaseArgv(); int Java_org_libsdl_app_SDLActivity_getMouseX(JNIEnv *env, jclass cls, jobject obj) { int ret = 0; - SDL_GetMouseState(&ret, nullptr); + SDL_GetMouseState(&ret, NULL); return ret; } int Java_org_libsdl_app_SDLActivity_getMouseY(JNIEnv *env, jclass cls, jobject obj) { int ret = 0; - SDL_GetMouseState(nullptr, &ret); + SDL_GetMouseState(NULL, &ret); return ret; } @@ -35,6 +35,17 @@ int Java_org_libsdl_app_SDLActivity_isMouseShown(JNIEnv *env, jclass cls, jobjec return SDL_ShowCursor(SDL_QUERY); } +extern SDL_Window *Android_Window; +int SDL_SendMouseMotion(SDL_Window * window, int mouseID, int relative, int x, int y); +void Java_org_libsdl_app_SDLActivity_sendRelativeMouseMotion(JNIEnv *env, jclass cls, int x, int y) { + SDL_SendMouseMotion(Android_Window, 0, 1, x, y); +} + +int SDL_SendMouseButton(SDL_Window * window, int mouseID, Uint8 state, Uint8 button); +void Java_org_libsdl_app_SDLActivity_sendMouseButton(JNIEnv *env, jclass cls, int state, int button) { + SDL_SendMouseButton(Android_Window, 0, state, button); +} + int Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj) { setenv("OPENMW_DECOMPRESS_TEXTURES", "1", 1); diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index f5b4171d4..15a8f0f32 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -154,14 +154,23 @@ bool OMW::Engine::frame(float frametime) mEnvironment.getStateManager()->endGame(); } + // 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); @@ -180,6 +189,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); @@ -667,10 +680,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 dfae5700b..429a12880 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -371,6 +371,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/npc.cpp b/apps/openmw/mwclass/npc.cpp index ec0671afc..317764e0c 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1172,6 +1172,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; @@ -1184,7 +1195,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/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 7f641d408..a9480f261 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -133,22 +133,23 @@ namespace MWGui public: CopyFramebufferToTextureCallback(osg::Texture2D* texture) : mTexture(texture) + , oneshot(true) { } virtual void operator () (osg::RenderInfo& renderInfo) const { + if (!oneshot) + return; + oneshot = false; int w = renderInfo.getCurrentCamera()->getViewport()->width(); int h = renderInfo.getCurrentCamera()->getViewport()->height(); mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h); - - // Callback removes itself when done - if (renderInfo.getCurrentCamera()) - renderInfo.getCurrentCamera()->setInitialDrawCallback(nullptr); } private: osg::ref_ptr mTexture; + mutable bool oneshot; }; class DontComputeBoundCallback : public osg::Node::ComputeBoundingSphereCallback @@ -308,6 +309,8 @@ namespace MWGui mGuiTexture.reset(new osgMyGUI::OSGTexture(mTexture)); } + // Notice that the next time this is called, the current CopyFramebufferToTextureCallback will be deleted + // so there's no memory leak as at most one object of type CopyFramebufferToTextureCallback is allocated at a time. mViewer->getCamera()->setInitialDrawCallback(new CopyFramebufferToTextureCallback(mTexture)); mBackgroundImage->setBackgroundImage(""); 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 5f5430524..1bcbc2d12 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 87338c912..4166ece11 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -860,8 +860,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) { 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 c199bfb3f..facac4291 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -154,9 +154,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 418962901..553b4e406 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -60,13 +60,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; @@ -235,13 +228,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) @@ -783,7 +776,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 43a082348..0a4486928 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1,8 +1,5 @@ #include "mechanicsmanagerimp.hpp" -#include -#include - #include #include diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 47d886e3f..bdd4e6968 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 7c9e207e9..58d5a85a0 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -1,6 +1,5 @@ #include "spellcasting.hpp" -#include #include #include diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 836370255..c1a08227e 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -1317,6 +1317,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(); @@ -1339,8 +1340,9 @@ namespace MWPhysics float heightDiff = position.z() - oldHeight; MWMechanics::CreatureStats& stats = iter->first.getClass().getCreatureStats(iter->first); - if ((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 9f1795905..05b8a281f 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 92cd33a5a..ec1c4397b 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 7358d1755..51a92a280 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -625,28 +625,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; @@ -1428,4 +1408,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 081a81002..82bc9e159 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -241,6 +241,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 0cf2fc464..d3b49239c 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -431,6 +431,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') @@ -659,6 +665,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 53316c44c..10d1252b9 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -536,7 +536,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/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 39e872b0c..ccb3f22b5 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -279,7 +280,7 @@ private: std::unique_ptr mLoudnessAnalyzer; - volatile bool mIsFinished; + std::atomic mIsFinished; void updateAll(bool local); @@ -313,7 +314,7 @@ struct OpenAL_Output::StreamThread : public OpenThreads::Thread { typedef std::vector StreamVec; StreamVec mStreams; - volatile bool mQuitNow; + std::atomic mQuitNow; OpenThreads::Mutex mMutex; OpenThreads::Condition mCondVar; 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 a06c208b5..89e5357f0 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -1,5 +1,8 @@ #include "cellpreloader.hpp" +#include +#include + #include #include #include @@ -159,7 +162,7 @@ namespace MWWorld MWRender::LandManager* mLandManager; bool mPreloadInstances; - volatile bool mAbort; + std::atomic mAbort; osg::ref_ptr mTerrainView; @@ -249,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) { @@ -392,7 +395,7 @@ namespace MWWorld } private: - volatile bool mAbort; + std::atomic mAbort; std::vector > mTerrainViews; Terrain::World* mWorld; std::vector mPreloadPositions; 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 85181e998..faf15215a 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -414,14 +414,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 70f8cf44f..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,23 +991,22 @@ 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; } void Store::setUp() { - for (int i = 0; i < ESM::Attribute::Length; ++i) { - mStatic.push_back( - ESM::Attribute( - ESM::Attribute::sAttributeIds[i], - ESM::Attribute::sGmstAttributeIds[i], - ESM::Attribute::sGmstAttributeDescIds[i] - ) - ); + for (int i = 0; i < ESM::Attribute::Length; ++i) + { + ESM::Attribute newAttribute; + newAttribute.mId = ESM::Attribute::sAttributeIds[i]; + newAttribute.mName = ESM::Attribute::sGmstAttributeIds[i]; + newAttribute.mDescription = ESM::Attribute::sGmstAttributeDescIds[i]; + mStatic.push_back(newAttribute); } } size_t Store::getSize() const @@ -1054,54 +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 = ESM::Static(marker.first, 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 = ESM::Door(marker.first, std::string(), marker.second, std::string(), std::string(), std::string()); - 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 cb5ded593..57556e1cb 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -387,10 +387,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); } @@ -494,6 +492,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 :( @@ -513,25 +522,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(it->first)) + if (!mStore.get().search(params.first)) { - ESM::GameSetting setting; - setting.mId = it->first; - setting.mValue = it->second; - mStore.insertStatic(setting); + ESM::Global record; + record.mId = params.first; + record.mValue = params.second; + mStore.insertStatic(record); } } - for (std::map::iterator it = globals.begin(); it != globals.end(); ++it) + 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::Global 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); + } + } + + std::map doors; + doors["prisonmarker"] = "marker_prison.nif"; + + for (const std::pair ¶ms : doors) + { + if (!mStore.get().search(params.first)) + { + ESM::Door record; + record.mId = params.first; + record.mModel = params.second; + mStore.insertStatic(record); } } } @@ -546,22 +577,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 @@ -670,10 +698,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) @@ -692,11 +720,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()) @@ -710,10 +736,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; @@ -770,15 +794,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; @@ -982,7 +1005,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 @@ -1071,7 +1094,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); } @@ -1291,7 +1314,10 @@ namespace MWWorld { mRendering->moveObject(newPtr, vec); if (movePhysics) + { mPhysics->updatePosition(newPtr); + mPhysics->updatePtr(ptr, newPtr); + } } if (isPlayer) { @@ -1784,7 +1810,6 @@ namespace MWWorld if (!paused) { - doPhysics (duration); updateNavigator(); } @@ -1804,6 +1829,14 @@ namespace MWWorld } } + void World::updatePhysics (float duration, bool paused) + { + if (!paused) + { + doPhysics (duration); + } + } + void World::updatePlayer() { MWWorld::Ptr player = getPlayerPtr(); @@ -1836,7 +1869,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 @@ -2405,9 +2438,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()); @@ -2535,17 +2567,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()); @@ -2567,19 +2598,18 @@ namespace MWWorld if (MWBase::Environment::get().getWindowManager()->isGuiMode()) return; - 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()); @@ -2649,11 +2679,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); } } @@ -2671,15 +2700,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); } } @@ -2720,28 +2748,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 @@ -2753,44 +2774,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; } @@ -2885,22 +2905,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++; } } @@ -2916,10 +2935,10 @@ namespace MWWorld if (!selectedSpell.empty()) { - 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) { @@ -2957,7 +2976,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(); @@ -2975,14 +2994,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; } } @@ -3040,7 +3058,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)) @@ -3151,17 +3169,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()) @@ -3178,7 +3193,7 @@ namespace MWWorld } } - checkedCells.insert( *i ); + checkedCells.insert(currentCell); } } @@ -3204,9 +3219,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 ); @@ -3215,14 +3230,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()) @@ -3248,15 +3258,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; } } @@ -3387,10 +3396,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); } } @@ -3425,8 +3432,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); @@ -3491,7 +3498,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; @@ -3547,18 +3554,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); } @@ -3606,7 +3594,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 @@ -3620,9 +3608,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; @@ -3650,13 +3638,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); } } @@ -3716,10 +3704,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 51953cd40..bfd3e918c 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -480,6 +480,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 e749a7c7d..8bb29136f 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 @@ -218,6 +218,7 @@ target_link_libraries(components ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_IOSTREAMS_LIBRARY} ${OSG_LIBRARIES} ${OPENTHREADS_LIBRARIES} ${OSGPARTICLE_LIBRARIES} @@ -232,6 +233,7 @@ target_link_libraries(components ${SDL2_LIBRARIES} ${OPENGL_gl_LIBRARY} ${MyGUI_LIBRARIES} + ${BSAOPTHASH_LIBRARIES} RecastNavigation::DebugUtils RecastNavigation::Detour RecastNavigation::Recast @@ -239,7 +241,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/attr.hpp b/components/esm/attr.hpp index 993de6ccb..c0a54c659 100644 --- a/components/esm/attr.hpp +++ b/components/esm/attr.hpp @@ -32,13 +32,6 @@ struct Attribute static const std::string sGmstAttributeIds[Length]; static const std::string sGmstAttributeDescIds[Length]; static const std::string sAttributeIcons[Length]; - - Attribute(AttributeID id, const std::string &name, const std::string &description) - : mId(id) - , mName(name) - , mDescription(description) - { - } }; } #endif 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/loaddoor.hpp b/components/esm/loaddoor.hpp index 955abec89..3afe5d5e4 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -22,21 +22,6 @@ struct Door void blank(); ///< Set record to default state (does not touch the ID). - - Door(const std::string id, const std::string name, const std::string &model, - const std::string script, const std::string opensound, const std::string closesound) - : mId(id) - , mName(name) - , mModel(model) - , mScript(script) - , mOpenSound(opensound) - , mCloseSound(closesound) - { - } - - Door() - { - } }; } #endif 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/esm/loadstat.hpp b/components/esm/loadstat.hpp index f80875b65..3d9144040 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -33,16 +33,6 @@ struct Static void blank(); ///< Set record to default state (does not touch the ID). - - Static(const std::string id, const std::string &model) - : mId(id) - , mModel(model) - { - } - - Static() - { - } }; } #endif diff --git a/components/fallback/fallback.cpp b/components/fallback/fallback.cpp index edc3f2678..9e64d5fea 100644 --- a/components/fallback/fallback.cpp +++ b/components/fallback/fallback.cpp @@ -1,70 +1,95 @@ #include "fallback.hpp" -#include +#include +#include namespace Fallback { - bool stob(std::string const& s) { - return s != "0"; - } - Map::Map(const std::map& fallback):mFallbackMap(fallback) {} std::string Map::getFallbackString(const std::string& fall) const { std::map::const_iterator it; - if((it = mFallbackMap.find(fall)) == mFallbackMap.end()) + if ((it = mFallbackMap.find(fall)) == mFallbackMap.end()) { - return ""; + return std::string(); } return it->second; } float Map::getFallbackFloat(const std::string& fall) const { - std::string fallback=getFallbackString(fall); - if (fallback.empty()) - return 0; - else - return boost::lexical_cast(fallback); + std::string fallback = getFallbackString(fall); + if (!fallback.empty()) + { + try + { + // We have to rely on Boost because std::stof from C++11 + // uses the current locale for separators which we don't want and often silently ignores parsing errors. + return boost::lexical_cast(fallback); + } + catch (boost::bad_lexical_cast&) + { + Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback"; + } + } + + return 0; } int Map::getFallbackInt(const std::string& fall) const { - std::string fallback=getFallbackString(fall); - if (fallback.empty()) - return 0; - else - return std::stoi(fallback); + std::string fallback = getFallbackString(fall); + if (!fallback.empty()) + { + try + { + return std::stoi(fallback); + } + catch (const std::invalid_argument&) + { + Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback"; + } + catch (const std::out_of_range&) + { + Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is out of range, using 0 as a fallback"; + } + } + + return 0; } bool Map::getFallbackBool(const std::string& fall) const { - std::string fallback=getFallbackString(fall); - if (fallback.empty()) - return false; - else - return stob(fallback); + std::string fallback = getFallbackString(fall); + return !fallback.empty() && fallback != "0"; } osg::Vec4f Map::getFallbackColour(const std::string& fall) const { - std::string sum=getFallbackString(fall); - if (sum.empty()) - return osg::Vec4f(0.5f,0.5f,0.5f,1.f); - else + std::string sum = getFallbackString(fall); + if (!sum.empty()) { - std::string ret[3]; - unsigned int j=0; - for(unsigned int i=0;i -#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/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index f37f271ed..cf6104351 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -335,6 +336,13 @@ namespace NifOsg return lod; } + osg::ref_ptr handleSwitchNode(const Nif::NiSwitchNode* niSwitchNode) + { + osg::ref_ptr switchNode (new osg::Switch); + switchNode->setNewChildDefaultValue(false); + return switchNode; + } + osg::ref_ptr handleSourceTexture(const Nif::NiSourceTexture* st, Resource::ImageManager* imageManager) { if (!st) @@ -593,6 +601,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) { @@ -822,7 +847,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 +1119,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/morphgeometry.cpp b/components/sceneutil/morphgeometry.cpp index 1b7e4ca93..01bb35c45 100644 --- a/components/sceneutil/morphgeometry.cpp +++ b/components/sceneutil/morphgeometry.cpp @@ -2,6 +2,8 @@ #include +#include + namespace SceneUtil { @@ -176,6 +178,10 @@ void MorphGeometry::cull(osg::NodeVisitor *nv) positionDst->dirty(); +#if OSG_MIN_VERSION_REQUIRED(3, 5, 6) + geom.dirtyGLObjects(); +#endif + nv->pushOntoNodePath(&geom); nv->apply(geom); nv->popFromNodePath(); diff --git a/components/sceneutil/optimizer.cpp b/components/sceneutil/optimizer.cpp index 5d50c369d..f2717fea2 100644 --- a/components/sceneutil/optimizer.cpp +++ b/components/sceneutil/optimizer.cpp @@ -807,6 +807,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 #include +#include + #include #include "skeleton.hpp" @@ -136,35 +138,35 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv) typedef std::map > 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 = it->second; + const BoneInfluence& bi = influencePair.second; + mBoneSphereVector.emplace_back(bone, bi.mBoundSphere); - 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 +203,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, @@ -237,6 +239,10 @@ void RigGeometry::cull(osg::NodeVisitor* nv) if (tangentDst) tangentDst->dirty(); +#if OSG_MIN_VERSION_REQUIRED(3, 5, 6) + geom.dirtyGLObjects(); +#endif + nv->pushOntoNodePath(&geom); nv->apply(geom); nv->popFromNodePath(); @@ -259,10 +265,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 0d8dcbddd..8ac60cb66 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); @@ -87,12 +87,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/sceneutil/workqueue.hpp b/components/sceneutil/workqueue.hpp index 2084df328..0b16db0e7 100644 --- a/components/sceneutil/workqueue.hpp +++ b/components/sceneutil/workqueue.hpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace SceneUtil @@ -87,7 +88,7 @@ namespace SceneUtil private: WorkQueue* mWorkQueue; - volatile bool mActive; + std::atomic mActive; }; 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 213cdf760..cae320633 100644 --- a/docs/source/reference/modding/font.rst +++ b/docs/source/reference/modding/font.rst @@ -4,9 +4,8 @@ Fonts Morrowind .fnt fonts -------------------- -Morrowind uses a custom ``.fnt`` file format. It is not compatible with the Windows Font File ``.fnt`` format, -nor compatible with ``.fnt`` formats from any other Bethesda games. To our knowledge, -the format is undocumented and no tools for viewing or editing these fonts exist. +Morrowind uses a custom ``.fnt`` file format. It is not compatible with the Windows Font File ``.fnt`` format. +To our knowledge, the format is undocumented. OpenMW can load this format and convert it on the fly into something usable (see font loader `source code `_). @@ -16,20 +15,62 @@ In OpenMW 0.32, an --export-fonts command line option was added to write the con TrueType fonts -------------- -Unlike vanilla Morrowind, OpenMW directly supports TrueType (``.ttf``) fonts. -This is the recommended way to create new fonts. +Unlike vanilla Morrowind, OpenMW directly supports TrueType (``.ttf``) fonts. + +0.45.0+ way +----------- +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:: + + [GUI] + font size = 17 + ttf resolution = 96 + +- 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``:: + + + + + + + + + + + + + + #. 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. + +The engine automatically takes UI scaling factor into account, so don't account for it when tweaking the settings. + +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. + #. 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:: + #. Add the following lines to ``openmw_font.xml``:: @@ -45,12 +86,12 @@ This is the recommended way to create new fonts. - #. This font is missing a few glyphs (mostly punctuation), but is complete in the primary glyphs. If desired, you can now delete the original ``daedric.*`` files from your Data Files/Fonts directory. + #. 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 resources/mygui/. - #. The openmw_fonts.xml entry is:: + #. Install the ``Oblivion.ttf`` file into ``resources/mygui/``. + #. The ``openmw_font.xml`` entry is:: @@ -80,7 +121,7 @@ This is the recommended way to create new fonts. Bitmap fonts ------------ -Morrowind ``.fnt`` files are essentially a bitmap font, but using them is discouraged because of no Unicode support. +Morrowind ``.fnt`` files are essentially a bitmap font, but using them is discouraged because they don't have Unicode support. MyGUI has its own format for bitmap fonts. An example can be seen by using the --export-fonts command line option (see above), which converts Morrowind ``.fnt`` to a MyGUI bitmap font. This is the recommended format to use if you wish to edit Morrowind's bitmap font or create a new bitmap font. 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/extern/osg-ffmpeg-videoplayer/videostate.hpp b/extern/osg-ffmpeg-videoplayer/videostate.hpp index a60d6032f..6abaa64cd 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.hpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.hpp @@ -2,6 +2,7 @@ #define VIDEOPLAYER_VIDEOSTATE_H #include +#include #include #include #include @@ -78,7 +79,7 @@ struct PacketQueue { { clear(); } AVPacketList *first_pkt, *last_pkt; - volatile bool flushing; + std::atomic flushing; int nb_packets; int size; @@ -169,12 +170,12 @@ struct VideoState { std::unique_ptr parse_thread; std::unique_ptr video_thread; - volatile bool mSeekRequested; + std::atomic mSeekRequested; uint64_t mSeekPos; - volatile bool mVideoEnded; - volatile bool mPaused; - volatile bool mQuit; + std::atomic mVideoEnded; + std::atomic mPaused; + std::atomic mQuit; }; }