diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 2ebfdeb8ae..940eb30d2b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -319,7 +319,7 @@ bool OMW::Engine::frame(unsigned frameNumber, float frametime) const bool reportResource = stats->collectStats("resource"); if (reportResource) - stats->setAttribute(frameNumber, "UnrefQueue", mUnrefQueue->getSize()); + stats->setAttribute(frameNumber, "UnrefQueue", static_cast(mUnrefQueue->getSize())); mUnrefQueue->flush(*mWorkQueue); @@ -329,8 +329,8 @@ bool OMW::Engine::frame(unsigned frameNumber, float frametime) mResourceSystem->reportStats(frameNumber, stats); - stats->setAttribute(frameNumber, "WorkQueue", mWorkQueue->getNumItems()); - stats->setAttribute(frameNumber, "WorkThread", mWorkQueue->getNumActiveThreads()); + stats->setAttribute(frameNumber, "WorkQueue", static_cast(mWorkQueue->getNumItems())); + stats->setAttribute(frameNumber, "WorkThread", static_cast(mWorkQueue->getNumActiveThreads())); mMechanicsManager->reportStats(frameNumber, *stats); mWorld->reportStats(frameNumber, *stats); @@ -740,7 +740,8 @@ void OMW::Engine::prepareEngine() mResourceSystem->getSceneManager()->setUnRefImageDataAfterApply( false); // keep to Off for now to allow better state sharing mResourceSystem->getSceneManager()->setFilterSettings(Settings::general().mTextureMagFilter, - Settings::general().mTextureMinFilter, Settings::general().mTextureMipmap, Settings::general().mAnisotropy); + Settings::general().mTextureMinFilter, Settings::general().mTextureMipmap, + static_cast(Settings::general().mAnisotropy)); mEnvironment.setResourceSystem(*mResourceSystem); mWorkQueue = new SceneUtil::WorkQueue(Settings::cells().mPreloadNumThreads); @@ -1039,7 +1040,7 @@ void OMW::Engine::go() const unsigned frameNumber = mViewer->getFrameStamp()->getFrameNumber(); - if (!frame(frameNumber, dt)) + if (!frame(frameNumber, static_cast(dt))) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); continue; diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index e4c60e596d..17645ff5e5 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -100,7 +100,7 @@ namespace MWBase /// @note Controlled by an option, gets discarded when dialogue ends by default virtual void applyBarterDispositionChange(int delta) = 0; - virtual int countSavedGameRecords() const = 0; + virtual size_t countSavedGameRecords() const = 0; virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) const = 0; diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp index 2861ab88e9..400189c7ab 100644 --- a/apps/openmw/mwbase/inputmanager.hpp +++ b/apps/openmw/mwbase/inputmanager.hpp @@ -86,7 +86,7 @@ namespace MWBase virtual std::string getControllerButtonIcon(int button) = 0; virtual std::string getControllerAxisIcon(int axis) = 0; - virtual int countSavedGameRecords() const = 0; + virtual size_t countSavedGameRecords() const = 0; virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) = 0; virtual void readRecord(ESM::ESMReader& reader, uint32_t type) = 0; diff --git a/apps/openmw/mwbase/journal.hpp b/apps/openmw/mwbase/journal.hpp index 50be0959bf..9e73d03709 100644 --- a/apps/openmw/mwbase/journal.hpp +++ b/apps/openmw/mwbase/journal.hpp @@ -74,7 +74,7 @@ namespace MWBase virtual const TQuestContainer& getQuests() const = 0; - virtual int countSavedGameRecords() const = 0; + virtual size_t countSavedGameRecords() const = 0; virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) const = 0; diff --git a/apps/openmw/mwbase/luamanager.hpp b/apps/openmw/mwbase/luamanager.hpp index 5772c555a3..f44e680cd2 100644 --- a/apps/openmw/mwbase/luamanager.hpp +++ b/apps/openmw/mwbase/luamanager.hpp @@ -141,7 +141,7 @@ namespace MWBase virtual void setupPlayer(const MWWorld::Ptr&) = 0; // Saving - int countSavedGameRecords() const { return 1; } + size_t countSavedGameRecords() const { return 1; } virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) = 0; virtual void saveLocalScripts(const MWWorld::Ptr& ptr, ESM::LuaScripts& data) = 0; diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index 091b851261..59cf81f71d 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -245,7 +245,7 @@ namespace MWBase virtual void playerLoaded() = 0; - virtual int countSavedGameRecords() const = 0; + virtual size_t countSavedGameRecords() const = 0; virtual void write(ESM::ESMWriter& writer, Loading::Listener& listener) const = 0; diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 101bbd2390..8385e85b5f 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -311,7 +311,7 @@ namespace MWBase virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) = 0; virtual void readRecord(ESM::ESMReader& reader, uint32_t type) = 0; - virtual int countSavedGameRecords() const = 0; + virtual size_t countSavedGameRecords() const = 0; /// Does the current stack of GUI-windows permit saving? virtual bool isSavingAllowed() const = 0; diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 983e2ef228..6149dccfed 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -120,7 +120,7 @@ namespace MWBase World() {} - virtual ~World() {} + virtual ~World() = default; virtual void setRandomSeed(uint32_t seed) = 0; ///< \param seed The seed used when starting a new game. @@ -130,8 +130,8 @@ namespace MWBase virtual void clear() = 0; - virtual int countSavedGameRecords() const = 0; - virtual int countSavedGameCells() const = 0; + virtual size_t countSavedGameRecords() const = 0; + virtual size_t countSavedGameCells() const = 0; virtual void write(ESM::ESMWriter& writer, Loading::Listener& listener) const = 0; diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 52c5a4a7b7..20da682208 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -653,7 +653,7 @@ namespace MWDialogue return info != nullptr; } - int DialogueManager::countSavedGameRecords() const + size_t DialogueManager::countSavedGameRecords() const { return 1; // known topics } diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index a735c57fef..ce3f3d1bda 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -112,7 +112,7 @@ namespace MWDialogue /// @note Controlled by an option, gets discarded when dialogue ends by default void applyBarterDispositionChange(int delta) override; - int countSavedGameRecords() const override; + size_t countSavedGameRecords() const override; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const override; diff --git a/apps/openmw/mwdialogue/journalimp.cpp b/apps/openmw/mwdialogue/journalimp.cpp index c607c5aa25..c318dc6644 100644 --- a/apps/openmw/mwdialogue/journalimp.cpp +++ b/apps/openmw/mwdialogue/journalimp.cpp @@ -151,7 +151,7 @@ namespace MWDialogue return iter->second.getIndex(); } - int Journal::countSavedGameRecords() const + size_t Journal::countSavedGameRecords() const { std::size_t count = mQuests.size(); @@ -163,7 +163,7 @@ namespace MWDialogue for (const auto& [_, topic] : mTopics) count += topic.size(); - return static_cast(count); + return count; } void Journal::write(ESM::ESMWriter& writer, Loading::Listener& progress) const diff --git a/apps/openmw/mwdialogue/journalimp.hpp b/apps/openmw/mwdialogue/journalimp.hpp index 9531652222..58c1f94371 100644 --- a/apps/openmw/mwdialogue/journalimp.hpp +++ b/apps/openmw/mwdialogue/journalimp.hpp @@ -53,7 +53,7 @@ namespace MWDialogue const TQuestContainer& getQuests() const override { return mQuests; } - int countSavedGameRecords() const override; + size_t countSavedGameRecords() const override; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const override; diff --git a/apps/openmw/mwgui/bookpage.cpp b/apps/openmw/mwgui/bookpage.cpp index 3ed47b64c6..db6eabbb2c 100644 --- a/apps/openmw/mwgui/bookpage.cpp +++ b/apps/openmw/mwgui/bookpage.cpp @@ -670,7 +670,7 @@ namespace MWGui { int top = mLine ? mLine->mRect.top : mBook->mRect.bottom; - append_run(i->mStyle, i->mBegin, i->mEnd, 0, left + i->mWidth, top + fontHeight); + appendRun(i->mStyle, i->mBegin, i->mEnd, 0, left + i->mWidth, top + fontHeight); left = mLine->mRect.right; } @@ -679,8 +679,8 @@ namespace MWGui for (PartialTextConstIterator i = mPartialWord.begin(); i != mPartialWord.end(); ++i) { int top = mLine ? mLine->mRect.top : mBook->mRect.bottom; - - append_run(i->mStyle, i->mBegin, i->mEnd, i->mEnd - i->mBegin, left + i->mWidth, top + fontHeight); + const int numChars = static_cast(i->mEnd - i->mBegin); + appendRun(i->mStyle, i->mBegin, i->mEnd, numChars, left + i->mWidth, top + fontHeight); left = mLine->mRect.right; } @@ -689,7 +689,7 @@ namespace MWGui mPartialWord.clear(); } - void append_run(StyleImpl* style, Utf8Stream::Point begin, Utf8Stream::Point end, int pc, int right, int bottom) + void appendRun(StyleImpl* style, Utf8Stream::Point begin, Utf8Stream::Point end, int pc, int right, int bottom) { if (mSection == nullptr) { diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 61d1132a28..860608cb0c 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -151,7 +151,7 @@ namespace MWGui mReviewDialog->onFrame(duration); } - void CharacterCreation::spawnDialog(const char id) + void CharacterCreation::spawnDialog(const GuiMode id) { try { diff --git a/apps/openmw/mwgui/charactercreation.hpp b/apps/openmw/mwgui/charactercreation.hpp index b92e3c2f5b..c888e94422 100644 --- a/apps/openmw/mwgui/charactercreation.hpp +++ b/apps/openmw/mwgui/charactercreation.hpp @@ -7,6 +7,7 @@ #include #include +#include "mode.hpp" #include "statswatcher.hpp" namespace osg @@ -42,7 +43,7 @@ namespace MWGui virtual ~CharacterCreation(); // Show a dialog - void spawnDialog(const char id); + void spawnDialog(const GuiMode id); void setAttribute(ESM::RefId id, const MWMechanics::AttributeValue& value) override; void setValue(std::string_view id, const MWMechanics::DynamicStat& value) override; diff --git a/apps/openmw/mwgui/inventorytabsoverlay.cpp b/apps/openmw/mwgui/inventorytabsoverlay.cpp index d95079ab53..9affdee800 100644 --- a/apps/openmw/mwgui/inventorytabsoverlay.cpp +++ b/apps/openmw/mwgui/inventorytabsoverlay.cpp @@ -14,9 +14,9 @@ namespace MWGui : WindowBase("openmw_inventory_tabs.layout") { MyGUI::Button* tab; - static const char* kTabIds[] = { "TabMap", "TabInventory", "TabSpells", "TabStats" }; + constexpr std::string_view kTabIds[] = { "TabMap", "TabInventory", "TabSpells", "TabStats" }; - for (const char* id : kTabIds) + for (const std::string_view id : kTabIds) { getWidget(tab, id); tab->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryTabsOverlay::onTabClicked); @@ -44,7 +44,7 @@ namespace MWGui if (!MWBase::Environment::get().getWindowManager()->getJournalAllowed()) return; - for (int i = 0; i < static_cast(mTabs.size()); i++) + for (size_t i = 0; i < mTabs.size(); ++i) { if (mTabs[i] == sender) { @@ -55,9 +55,9 @@ namespace MWGui } } - void InventoryTabsOverlay::setTab(int index) + void InventoryTabsOverlay::setTab(size_t index) { - for (int i = 0; i < static_cast(mTabs.size()); i++) + for (size_t i = 0; i < mTabs.size(); ++i) mTabs[i]->setStateSelected(i == index); } } diff --git a/apps/openmw/mwgui/inventorytabsoverlay.hpp b/apps/openmw/mwgui/inventorytabsoverlay.hpp index 26544aa310..7211e87cf8 100644 --- a/apps/openmw/mwgui/inventorytabsoverlay.hpp +++ b/apps/openmw/mwgui/inventorytabsoverlay.hpp @@ -16,7 +16,7 @@ namespace MWGui InventoryTabsOverlay(); int getHeight(); - void setTab(int index); + void setTab(size_t index); private: std::vector mTabs; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 0c26ee7222..4552434b1f 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -748,10 +748,10 @@ namespace MWGui { MWWorld::Ptr player = MWMechanics::getPlayer(); - float capacity = player.getClass().getCapacity(player); + int capacity = static_cast(player.getClass().getCapacity(player)); float encumbrance = player.getClass().getEncumbrance(player); mTradeModel->adjustEncumbrance(encumbrance); - mEncumbranceBar->setValue(std::ceil(encumbrance), static_cast(capacity)); + mEncumbranceBar->setValue(static_cast(std::ceil(encumbrance)), capacity); } void InventoryWindow::onFrame(float dt) diff --git a/apps/openmw/mwgui/journalviewmodel.cpp b/apps/openmw/mwgui/journalviewmodel.cpp index 8c47edc9ea..b5a0215db2 100644 --- a/apps/openmw/mwgui/journalviewmodel.cpp +++ b/apps/openmw/mwgui/journalviewmodel.cpp @@ -172,11 +172,8 @@ namespace MWGui mModel->mKeywordSearch.highlightKeywords(utf8text.begin(), utf8text.end(), matches); std::string::const_iterator i = utf8text.begin(); - for (std::vector::const_iterator it = matches.begin(); it != matches.end(); - ++it) + for (const KeywordSearchT::Match& match : matches) { - const KeywordSearchT::Match& match = *it; - if (i != match.mBeg) visitor(0, i - utf8text.begin(), match.mBeg - utf8text.begin()); diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 4695ae6054..c1aeeb9518 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -209,8 +209,7 @@ namespace MWGui { if (!mSplashScreens.empty()) { - std::string const& randomSplash - = mSplashScreens.at(Misc::Rng::rollDice(static_cast(mSplashScreens.size()))); + std::string const& randomSplash = mSplashScreens.at(Misc::Rng::rollDice(mSplashScreens.size())); // TODO: add option (filename pattern?) to use image aspect ratio instead of 4:3 // we can't do this by default, because the Morrowind splash screens are 1024x1024, but should be displayed diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index cb0f197718..85aadb2079 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -1004,7 +1004,8 @@ namespace MWGui for (auto& [marker, col] : mGlobalMapMarkers) { - marker.widget->setCoord(createMarkerCoords(marker.position.x(), marker.position.y(), col.size())); + marker.widget->setCoord( + createMarkerCoords(marker.position.x(), marker.position.y(), static_cast(col.size()))); marker.widget->setVisible(marker.widget->getHeight() >= 6); } } @@ -1036,10 +1037,10 @@ namespace MWGui // Restore the window to pinned size. MyGUI::Window* window = mMainWidget->castType(); MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - const float x = Settings::windows().mMapX * viewSize.width; - const float y = Settings::windows().mMapY * viewSize.height; - const float w = Settings::windows().mMapW * viewSize.width; - const float h = Settings::windows().mMapH * viewSize.height; + const int x = static_cast(Settings::windows().mMapX * viewSize.width); + const int y = static_cast(Settings::windows().mMapY * viewSize.height); + const int w = static_cast(Settings::windows().mMapW * viewSize.width); + const int h = static_cast(Settings::windows().mMapH * viewSize.height); window->setCoord(x, y, w, h); } } @@ -1063,10 +1064,10 @@ namespace MWGui worldPosToGlobalMapImageSpace( (x + 0.5f) * Constants::CellSizeInUnits, (y + 0.5f) * Constants::CellSizeInUnits, worldX, worldY); - const float markerSize = getMarkerSize(agregatedWeight); + const float markerSize = getMarkerSize(static_cast(agregatedWeight)); const float halfMarkerSize = markerSize / 2.0f; return MyGUI::IntCoord(static_cast(worldX - halfMarkerSize), static_cast(worldY - halfMarkerSize), - markerSize, markerSize); + static_cast(markerSize), static_cast(markerSize)); } MyGUI::Widget* MapWindow::createMarker(const std::string& name, float x, float y, float agregatedWeight) @@ -1075,7 +1076,7 @@ namespace MWGui "MarkerButton", createMarkerCoords(x, y, agregatedWeight), MyGUI::Align::Default); markerWidget->setVisible(markerWidget->getHeight() >= 6.0); markerWidget->setUserString("Caption_TextOneLine", "#{sCell=" + name + "}"); - setGlobalMapMarkerTooltip(markerWidget, x, y); + setGlobalMapMarkerTooltip(markerWidget, static_cast(x), static_cast(y)); markerWidget->setUserString("ToolTipLayout", "TextToolTipOneLine"); @@ -1098,14 +1099,15 @@ namespace MWGui cell.second = y; if (mMarkers.insert(cell).second) { - MapMarkerType mapMarkerWidget = { osg::Vec2f(x, y), createMarker(name, x, y, 0) }; + const osg::Vec2f pos(static_cast(x), static_cast(y)); + MapMarkerType mapMarkerWidget = { pos, createMarker(name, pos.x(), pos.y(), 0) }; mGlobalMapMarkers.emplace(mapMarkerWidget, std::vector()); const std::string markerName = name.substr(0, name.find(',')); auto& entry = mGlobalMapMarkersByName[markerName]; if (!entry.widget) { - entry = { osg::Vec2f(x, y), entry.widget }; // update the coords + entry = { pos, entry.widget }; // update the coords entry.widget = createMarker(markerName, entry.position.x(), entry.position.y(), 1); mGlobalMapMarkers.emplace(entry, std::vector{ entry }); @@ -1123,7 +1125,8 @@ namespace MWGui [](const auto& left, const auto& right) { return left + right.position; }) / float(elements.size()); - marker.widget->setCoord(createMarkerCoords(marker.position.x(), marker.position.y(), elements.size())); + marker.widget->setCoord( + createMarkerCoords(marker.position.x(), marker.position.y(), static_cast(elements.size()))); marker.widget->setVisible(marker.widget->getHeight() >= 6); } } @@ -1167,16 +1170,16 @@ namespace MWGui { float markerSize = 12.f * mGlobalMapZoom; if (mGlobalMapZoom < 1) - return markerSize * std::sqrt(agregatedWeight); // we want to see agregated object + return static_cast(markerSize * std::sqrt(agregatedWeight)); // we want to see agregated object return agregatedWeight ? 0 : markerSize; // we want to see only original markers (i.e. non agregated) } void MapWindow::resizeGlobalMap() { - mGlobalMap->setCanvasSize( - mGlobalMapRender->getWidth() * mGlobalMapZoom, mGlobalMapRender->getHeight() * mGlobalMapZoom); - mGlobalMapImage->setSize( - mGlobalMapRender->getWidth() * mGlobalMapZoom, mGlobalMapRender->getHeight() * mGlobalMapZoom); + int width = static_cast(mGlobalMapRender->getWidth() * mGlobalMapZoom); + int height = static_cast(mGlobalMapRender->getHeight() * mGlobalMapZoom); + mGlobalMap->setCanvasSize(width, height); + mGlobalMapImage->setSize(width, height); } void MapWindow::worldPosToGlobalMapImageSpace(float x, float y, float& imageX, float& imageY) const @@ -1191,7 +1194,8 @@ namespace MWGui LocalMapBase::updateCustomMarkers(); for (auto& [widgetPair, ignore] : mGlobalMapMarkers) - setGlobalMapMarkerTooltip(widgetPair.widget, widgetPair.position.x(), widgetPair.position.y()); + setGlobalMapMarkerTooltip(widgetPair.widget, static_cast(widgetPair.position.x()), + static_cast(widgetPair.position.y())); } void MapWindow::onDragStart(MyGUI::Widget* /*sender*/, int left, int top, MyGUI::MouseButton id) diff --git a/apps/openmw/mwgui/postprocessorhud.cpp b/apps/openmw/mwgui/postprocessorhud.cpp index 1a1f838abc..1d1bd6a2f2 100644 --- a/apps/openmw/mwgui/postprocessorhud.cpp +++ b/apps/openmw/mwgui/postprocessorhud.cpp @@ -279,7 +279,7 @@ namespace MWGui void PostProcessorHud::notifyMouseWheel(MyGUI::Widget* /*sender*/, int rel) { - int offset = mConfigLayout->getViewOffset().top + rel * 0.3; + double offset = mConfigLayout->getViewOffset().top + rel * 0.3; if (offset > 0) mConfigLayout->setViewOffset(MyGUI::IntPoint(0, 0)); else diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 40cd1cd00e..a42ea5e566 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -333,8 +333,8 @@ namespace MWGui if (texture) scale = texture->getHeight() / 64.f; - mSelected->button->setFrame( - "textures\\menu_icon_select_magic.dds", MyGUI::IntCoord(0, 0, 44 * scale, 44 * scale)); + const int diameter = static_cast(44 * scale); + mSelected->button->setFrame("textures\\menu_icon_select_magic.dds", MyGUI::IntCoord(0, 0, diameter, diameter)); mSelected->button->setIcon(path); if (mMagicSelectionDialog) diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 71b0cf40ca..0e13e4df49 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -241,7 +241,7 @@ namespace MWGui SettingsWindow::SettingsWindow(Files::ConfigurationManager& cfgMgr) : WindowBase("openmw_settings_window.layout") , mKeyboardMode(true) - , mCurrentPage(-1) + , mCurrentPage(static_cast(-1)) , mCfgMgr(cfgMgr) { const bool terrain = Settings::terrain().mDistantTerrain; @@ -629,7 +629,7 @@ namespace MWGui void SettingsWindow::onMaxLightsChanged(MyGUI::ComboBox* /*sender*/, size_t pos) { - Settings::shaders().mMaxLights.set(8 * (pos + 1)); + Settings::shaders().mMaxLights.set(8 * static_cast(pos + 1)); apply(); configureWidgets(mMainWidget, false); } @@ -752,7 +752,7 @@ namespace MWGui } else { - Settings::get(getSettingCategory(scroller), getSettingName(scroller)).set(pos); + Settings::get(getSettingCategory(scroller), getSettingName(scroller)).set(static_cast(pos)); valueStr = MyGUI::utility::toString(pos); } updateSliderLabel(scroller, valueStr); @@ -927,12 +927,12 @@ namespace MWGui const int h = Settings::gui().mFontSize + 2; const int w = mControlsBox->getWidth() - 28; const int noWidgetsInRow = 2; - const int totalH = mControlsBox->getChildCount() / noWidgetsInRow * h; + const int totalH = static_cast(mControlsBox->getChildCount() / noWidgetsInRow) * h; for (size_t i = 0; i < mControlsBox->getChildCount(); i++) { MyGUI::Widget* widget = mControlsBox->getChildAt(i); - widget->setCoord(0, i / noWidgetsInRow * h, w, h); + widget->setCoord(0, static_cast(i / noWidgetsInRow * h), w, h); } // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the @@ -1030,7 +1030,7 @@ namespace MWGui void SettingsWindow::onScriptListSelection(MyGUI::ListBox*, size_t index) { mScriptAdapter->detach(); - mCurrentPage = -1; + mCurrentPage = static_cast(-1); if (index < mScriptList->getItemCount()) { mCurrentPage = *mScriptList->getItemDataAt(index); diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index d13d23e43b..45eda0f315 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -72,7 +72,7 @@ namespace MWGui MyGUI::Widget* mScriptDisabled; MyGUI::ScrollView* mScriptView; LuaUi::LuaAdapter* mScriptAdapter; - int mCurrentPage; + size_t mCurrentPage; void onTabChanged(MyGUI::TabControl* sender, size_t index); void onOkButtonClicked(MyGUI::Widget* sender); diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 202c9341b2..c471c036e3 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -382,7 +382,7 @@ namespace MWGui void EditEffectDialog::onAreaChanged(MyGUI::ScrollBar* sender, size_t pos) { mAreaValue->setCaption(MyGUI::utility::toString(pos)); - mEffect.mArea = pos; + mEffect.mArea = static_cast(pos); eventEffectModified(mEffect); } @@ -1014,7 +1014,7 @@ namespace MWGui void EffectEditorBase::onEffectAdded(ESM::ENAMstruct effect) { mEffects.push_back(effect); - mSelectedEffect = mEffects.size() - 1; + mSelectedEffect = static_cast(mEffects.size() - 1); updateEffectsView(); } diff --git a/apps/openmw/mwgui/spellview.hpp b/apps/openmw/mwgui/spellview.hpp index b7f46896a4..e054334b95 100644 --- a/apps/openmw/mwgui/spellview.hpp +++ b/apps/openmw/mwgui/spellview.hpp @@ -28,7 +28,7 @@ namespace MWGui { MYGUI_RTTI_DERIVED(SpellView) public: - SpellView() {}; + SpellView() {} /// Register needed components with MyGUI's factory manager static void registerComponents(); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index a1bb907a95..ec56644aa4 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -961,8 +961,7 @@ namespace MWGui const std::string& name = ESM::MagicEffect::indexToGmstString(id); std::string icon = effect->mIcon; - int slashPos = icon.rfind('\\'); - icon.insert(slashPos + 1, "b_"); + icon.insert(icon.rfind('\\') + 1, "b_"); icon = Misc::ResourceHelpers::correctIconPath(icon, MWBase::Environment::get().getResourceSystem()->getVFS()); widget->setUserString("ToolTipType", "Layout"); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index e1f9340fb8..00d8f37fc8 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -439,7 +439,7 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->messageBox(msg); MWBase::Environment::get().getMechanicsManager()->confiscateStolenItemToOwner( - player, itemStack.mBase, mPtr, itemStack.mCount); + player, itemStack.mBase, mPtr, static_cast(itemStack.mCount)); onCancelButtonClicked(mCancelButton); MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 708fa724c3..c97d392ff6 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -203,14 +203,13 @@ namespace MWGui if (mPtr.getCell()->isExterior()) { ESM::Position playerPos = player.getRefData().getPosition(); - float d - = (osg::Vec3f(pos.pos[0], pos.pos[1], 0) - osg::Vec3f(playerPos.pos[0], playerPos.pos[1], 0)).length(); - int hours = static_cast(d - / MWBase::Environment::get() - .getESMStore() - ->get() - .find("fTravelTimeMult") - ->mValue.getFloat()); + float d = (osg::Vec2f(pos.pos[0], pos.pos[1]) - osg::Vec2f(playerPos.pos[0], playerPos.pos[1])).length(); + const float fTravelTimeMult = MWBase::Environment::get() + .getESMStore() + ->get() + .find("fTravelTimeMult") + ->mValue.getFloat(); + int hours = static_cast(d / fTravelTimeMult); MWBase::Environment::get().getMechanicsManager()->rest(hours, true); MWBase::Environment::get().getWorld()->advanceTime(hours); } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index f88bb3e9d9..ac8c0475a0 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -492,7 +492,7 @@ namespace MWGui if (!mResourceSystem->getVFS()->exists(hitFaderTexture)) { hitFaderTexture = "textures\\player_hit_01.dds"; - hitFaderCoord = MyGUI::FloatCoord(0.2, 0.25, 0.6, 0.5); + hitFaderCoord = MyGUI::FloatCoord(0.2f, 0.25f, 0.6f, 0.5f); } auto hitFader = std::make_unique(hitFaderTexture, hitFaderLayout, hitFaderCoord); mHitFader = hitFader.get(); @@ -790,8 +790,8 @@ namespace MWGui while (mMessageBoxManager->readPressedButton(false) == -1 && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) { - const double dt - = std::chrono::duration_cast>(frameRateLimiter.getLastFrameDuration()) + const float dt + = std::chrono::duration_cast>(frameRateLimiter.getLastFrameDuration()) .count(); mKeyboardNavigation->onFrame(); @@ -906,8 +906,7 @@ namespace MWGui if (state.mWindows.empty()) return nullptr; - size_t activeIndex - = std::clamp(mActiveControllerWindows[mode], 0, state.mWindows.size() - 1); + size_t activeIndex = std::clamp(mActiveControllerWindows[mode], 0, state.mWindows.size() - 1); // If the active window is no longer visible, find the next visible window. if (!state.mWindows[activeIndex]->isVisible()) @@ -1920,10 +1919,10 @@ namespace MWGui const WindowRectSettingValues& rect = settings.mIsMaximized ? settings.mRegular : settings.mMaximized; MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); - const float x = rect.mX * viewSize.width; - const float y = rect.mY * viewSize.height; - const float w = rect.mW * viewSize.width; - const float h = rect.mH * viewSize.height; + const int x = static_cast(rect.mX * viewSize.width); + const int y = static_cast(rect.mY * viewSize.height); + const int w = static_cast(rect.mW * viewSize.width); + const int h = static_cast(rect.mH * viewSize.height); window->setCoord(x, y, w, h); settings.mIsMaximized.set(!settings.mIsMaximized.get()); @@ -1997,11 +1996,10 @@ namespace MWGui writer.endRecord(ESM::REC_ASPL); } - for (CustomMarkerCollection::ContainerType::const_iterator it = mCustomMarkers.begin(); - it != mCustomMarkers.end(); ++it) + for (const auto& [_, marker] : mCustomMarkers) { writer.startRecord(ESM::REC_MARK); - it->second.save(writer); + marker.save(writer); writer.endRecord(ESM::REC_MARK); } } @@ -2027,7 +2025,7 @@ namespace MWGui } } - int WindowManager::countSavedGameRecords() const + size_t WindowManager::countSavedGameRecords() const { return 1 // Global map + 1 // QuickKeysMenu @@ -2075,8 +2073,8 @@ namespace MWGui = Misc::makeFrameRateLimiter(MWBase::Environment::get().getFrameRateLimit()); while (mVideoWidget->update() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) { - const double dt - = std::chrono::duration_cast>(frameRateLimiter.getLastFrameDuration()) + const float dt + = std::chrono::duration_cast>(frameRateLimiter.getLastFrameDuration()) .count(); MWBase::Environment::get().getInputManager()->update(dt, true, false); @@ -2425,8 +2423,8 @@ namespace MWGui if (image.valid()) { // everything looks good, send it to the cursor manager - const Uint8 hotspotX = imgSetPointer->getHotSpot().left; - const Uint8 hotspotY = imgSetPointer->getHotSpot().top; + const Uint8 hotspotX = static_cast(imgSetPointer->getHotSpot().left); + const Uint8 hotspotY = static_cast(imgSetPointer->getHotSpot().top); int rotation = imgSetPointer->getRotation(); MyGUI::IntSize pointerSize = imgSetPointer->getSize(); diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index c763a433f9..03f0ea5572 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -331,7 +331,7 @@ namespace MWGui void write(ESM::ESMWriter& writer, Loading::Listener& progress) override; void readRecord(ESM::ESMReader& reader, uint32_t type) override; - int countSavedGameRecords() const override; + size_t countSavedGameRecords() const override; /// Does the current stack of GUI-windows permit saving? bool isSavingAllowed() const override; diff --git a/apps/openmw/mwinput/controlswitch.cpp b/apps/openmw/mwinput/controlswitch.cpp index 974cfbbbb5..744c2f4632 100644 --- a/apps/openmw/mwinput/controlswitch.cpp +++ b/apps/openmw/mwinput/controlswitch.cpp @@ -78,7 +78,7 @@ namespace MWInput set("playermagic", !controls.mSpellDrawingDisabled); } - int ControlSwitch::countSavedGameRecords() const + size_t ControlSwitch::countSavedGameRecords() const { return 1; } diff --git a/apps/openmw/mwinput/controlswitch.hpp b/apps/openmw/mwinput/controlswitch.hpp index b86744a06f..7ec72c321c 100644 --- a/apps/openmw/mwinput/controlswitch.hpp +++ b/apps/openmw/mwinput/controlswitch.hpp @@ -31,7 +31,7 @@ namespace MWInput void write(ESM::ESMWriter& writer, Loading::Listener& progress); void readRecord(ESM::ESMReader& reader, uint32_t type); - int countSavedGameRecords() const; + size_t countSavedGameRecords() const; private: std::map> mSwitches; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 250b25aeaa..c1dda59e51 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -211,7 +211,7 @@ namespace MWInput mBindingsManager->enableDetectingBindingMode(action, keyboard); } - int InputManager::countSavedGameRecords() const + size_t InputManager::countSavedGameRecords() const { return mControlSwitch->countSavedGameRecords(); } diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index 3e964ae2a8..611679ac9d 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -95,7 +95,7 @@ namespace MWInput std::string getControllerButtonIcon(int button) override; std::string getControllerAxisIcon(int axis) override; - int countSavedGameRecords() const override; + size_t countSavedGameRecords() const override; void write(ESM::ESMWriter& writer, Loading::Listener& progress) override; void readRecord(ESM::ESMReader& reader, uint32_t type) override; diff --git a/apps/openmw/mwlua/camerabindings.cpp b/apps/openmw/mwlua/camerabindings.cpp index 454f966538..c2e2cac4ff 100644 --- a/apps/openmw/mwlua/camerabindings.cpp +++ b/apps/openmw/mwlua/camerabindings.cpp @@ -105,14 +105,14 @@ namespace MWLua double fovTan = std::tan(osg::DegreesToRadians(renderingManager->getFieldOfView()) / 2); osg::Matrixf invertedViewMatrix; invertedViewMatrix.invert(camera->getViewMatrix()); - float x = (pos.x() * 2 - 1) * aspect * fovTan; - float y = (1 - pos.y() * 2) * fovTan; + float x = static_cast((pos.x() * 2 - 1) * aspect * fovTan); + float y = static_cast((1 - pos.y() * 2) * fovTan); return invertedViewMatrix.preMult(osg::Vec3f(x, y, -1)) - camera->getPosition(); }; api["worldToViewportVector"] = [camera](osg::Vec3f pos) { - const double width = Settings::video().mResolutionX; - const double height = Settings::video().mResolutionY; + const int width = Settings::video().mResolutionX; + const int height = Settings::video().mResolutionY; osg::Matrix windowMatrix = osg::Matrix::translate(1.0, 1.0, 1.0) * osg::Matrix::scale(0.5 * width, 0.5 * height, 0.5); diff --git a/apps/openmw/mwlua/cellbindings.cpp b/apps/openmw/mwlua/cellbindings.cpp index 4e4542d89f..c21239c463 100644 --- a/apps/openmw/mwlua/cellbindings.cpp +++ b/apps/openmw/mwlua/cellbindings.cpp @@ -40,6 +40,8 @@ #include #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwworld/cellstore.hpp" @@ -307,7 +309,7 @@ namespace MWLua { sol::table table(lua, sol::create); table["autoGenerated"] = point.mAutogenerated == 0; - table["relativePosition"] = osg::Vec3f(point.mX, point.mY, point.mZ); + table["relativePosition"] = Misc::Convert::makeOsgVec3f(point); sol::table edges(lua, sol::create); table["connections"] = edges; points.add(table); diff --git a/apps/openmw/mwlua/corebindings.cpp b/apps/openmw/mwlua/corebindings.cpp index cce3aa8eed..2c77990f75 100644 --- a/apps/openmw/mwlua/corebindings.cpp +++ b/apps/openmw/mwlua/corebindings.cpp @@ -41,10 +41,10 @@ namespace MWLua list[LuaUtil::toLuaIndex(i)] = Misc::StringUtils::lowerCase(contentList[i]); sol::table res(lua, sol::create); res["list"] = LuaUtil::makeReadOnly(list); - res["indexOf"] = [&contentList](std::string_view contentFile) -> sol::optional { + res["indexOf"] = [&contentList](std::string_view contentFile) -> sol::optional { for (size_t i = 0; i < contentList.size(); ++i) if (Misc::StringUtils::ciEqual(contentList[i], contentFile)) - return LuaUtil::toLuaIndex(i); + return LuaUtil::toLuaIndex(static_cast(i)); return sol::nullopt; }; res["has"] = [&contentList](std::string_view contentFile) -> bool { diff --git a/apps/openmw/mwlua/dialoguebindings.cpp b/apps/openmw/mwlua/dialoguebindings.cpp index d0ca799cb6..6028d0e1b2 100644 --- a/apps/openmw/mwlua/dialoguebindings.cpp +++ b/apps/openmw/mwlua/dialoguebindings.cpp @@ -220,7 +220,7 @@ namespace return rec.mFaction.serializeText(); }); recordInfoBindingsClass["filterActorFactionRank"] - = sol::readonly_property([](const ESM::DialInfo& rec) -> sol::optional { + = sol::readonly_property([](const ESM::DialInfo& rec) -> sol::optional { if (rec.mData.mType == ESM::Dialogue::Type::Journal || rec.mData.mRank == -1) { return sol::nullopt; @@ -260,7 +260,7 @@ namespace return rec.mPcFaction.serializeText(); }); recordInfoBindingsClass["filterPlayerFactionRank"] - = sol::readonly_property([](const ESM::DialInfo& rec) -> sol::optional { + = sol::readonly_property([](const ESM::DialInfo& rec) -> sol::optional { if (rec.mData.mType == ESM::Dialogue::Type::Journal || rec.mData.mPCrank == -1) { return sol::nullopt; diff --git a/apps/openmw/mwlua/itemdata.cpp b/apps/openmw/mwlua/itemdata.cpp index 1b809383db..75848e477b 100644 --- a/apps/openmw/mwlua/itemdata.cpp +++ b/apps/openmw/mwlua/itemdata.cpp @@ -130,7 +130,7 @@ namespace MWLua { // if the value set is less than 0, chargeInt and chargeIntRemainder is set to 0 ptr.getCellRef().setChargeIntRemainder(std::max(0.f, std::modf(cond, &cond))); - ptr.getCellRef().setCharge(std::max(0.f, cond)); + ptr.getCellRef().setCharge(std::max(0, static_cast(cond))); } } else diff --git a/apps/openmw/mwlua/landbindings.cpp b/apps/openmw/mwlua/landbindings.cpp index 2b053802db..6458eba6c0 100644 --- a/apps/openmw/mwlua/landbindings.cpp +++ b/apps/openmw/mwlua/landbindings.cpp @@ -89,8 +89,8 @@ namespace MWLua if (worldspace != ESM::Cell::sDefaultWorldspaceId) return values; - const float cellSize = ESM::getCellSize(worldspace); - const float offset = (cellSize / ESM::LandRecordData::sLandTextureSize) * 0.25; + const int cellSize = ESM::getCellSize(worldspace); + const float offset = (cellSize / ESM::LandRecordData::sLandTextureSize) * 0.25f; const osg::Vec3f correctedPos = pos + osg::Vec3f{ -offset, +offset, 0.0f }; const ESM::Land* land = nullptr; @@ -110,7 +110,7 @@ namespace MWLua return values; const ESMTerrain::UniqueTextureId textureId - = getTextureAt(landData->mTextures, land->getPlugin(), correctedPos, cellSize); + = getTextureAt(landData->mTextures, land->getPlugin(), correctedPos, static_cast(cellSize)); // Need to check for 0, 0 so that we can safely subtract 1 later, as per documentation on UniqueTextureId if (textureId.first != 0) diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index 0b760ccdf0..23c11f81fd 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -281,8 +281,8 @@ namespace MWLua } mInputEvents.clear(); mLuaEvents.callMenuEventHandlers(); - double frameDuration = MWBase::Environment::get().getWorld()->getTimeManager()->isPaused() - ? 0.0 + float frameDuration = MWBase::Environment::get().getWorld()->getTimeManager()->isPaused() + ? 0.f : MWBase::Environment::get().getFrameDuration(); mInputActions.update(frameDuration); mMenuScripts.onFrame(frameDuration); @@ -826,7 +826,7 @@ namespace MWLua void LuaManager::reportStats(unsigned int frameNumber, osg::Stats& stats) const { - stats.setAttribute(frameNumber, "Lua UsedMemory", mLua.getTotalMemoryUsage()); + stats.setAttribute(frameNumber, "Lua UsedMemory", static_cast(mLua.getTotalMemoryUsage())); } std::string LuaManager::formatResourceUsageStats() const @@ -836,11 +836,11 @@ namespace MWLua std::stringstream out; - constexpr int nameW = 50; + constexpr unsigned nameW = 50; constexpr int valueW = 12; - auto outMemSize = [&](int64_t bytes) { - constexpr int64_t limit = 10000; + auto outMemSize = [&](size_t bytes) { + constexpr size_t limit = 10000; out << std::right << std::setw(valueW - 3); if (bytes < limit) out << bytes << " B "; @@ -924,21 +924,22 @@ namespace MWLua out << "\n " << std::setw(nameW) << ""; // if path is too long, break line out << std::right; out << std::setw(valueW) << static_cast(activeStats[i].mAvgInstructionCount); - outMemSize(activeStats[i].mMemoryUsage); - outMemSize(mLua.getMemoryUsageByScriptIndex(i) - activeStats[i].mMemoryUsage); + outMemSize(static_cast(activeStats[i].mMemoryUsage)); + outMemSize(mLua.getMemoryUsageByScriptIndex(static_cast(i)) + - static_cast(activeStats[i].mMemoryUsage)); if (isGlobal) out << std::setw(valueW * 2) << "NA (global script)"; - else if (isMenu && (!selectedScripts || !selectedScripts->hasScript(i))) + else if (isMenu && (!selectedScripts || !selectedScripts->hasScript(static_cast(i)))) out << std::setw(valueW * 2) << "NA (menu script)"; else if (selectedPtr.isEmpty()) out << std::setw(valueW * 2) << "NA (not selected) "; - else if (!selectedScripts || !selectedScripts->hasScript(i)) + else if (!selectedScripts || !selectedScripts->hasScript(static_cast(i))) out << std::setw(valueW * 2) << "NA"; else { out << std::setw(valueW) << static_cast(selectedStats[i].mAvgInstructionCount); - outMemSize(selectedStats[i].mMemoryUsage); + outMemSize(static_cast(selectedStats[i].mMemoryUsage)); } out << "\n"; } diff --git a/apps/openmw/mwlua/magicbindings.cpp b/apps/openmw/mwlua/magicbindings.cpp index 3831cf656e..40c3935c31 100644 --- a/apps/openmw/mwlua/magicbindings.cpp +++ b/apps/openmw/mwlua/magicbindings.cpp @@ -770,7 +770,7 @@ namespace MWLua resetEnchantItem(); if (objPtr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { - int chance = MWMechanics::getSpellSuccessChance(spellId, objPtr); + int chance = static_cast(MWMechanics::getSpellSuccessChance(spellId, objPtr)); MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, chance); } else @@ -963,9 +963,9 @@ namespace MWLua effect.mEffectId = enam.mData.mEffectID; effect.mArg = MWMechanics::EffectKey(enam.mData).mArg; effect.mMagnitude = 0.f; - effect.mMinMagnitude = enam.mData.mMagnMin; - effect.mMaxMagnitude = enam.mData.mMagnMax; - effect.mEffectIndex = enam.mIndex; + effect.mMinMagnitude = static_cast(enam.mData.mMagnMin); + effect.mMaxMagnitude = static_cast(enam.mData.mMagnMax); + effect.mEffectIndex = static_cast(enam.mIndex); effect.mFlags = ESM::ActiveEffect::Flag_None; if (ignoreReflect) effect.mFlags |= ESM::ActiveEffect::Flag_Ignore_Reflect; @@ -1089,7 +1089,7 @@ namespace MWLua throw std::runtime_error("Local scripts can modify effect only on the actor they are attached to."); MWMechanics::EffectKey key = getEffectKey(idStr, argStr); - int currentValue = effects.getStore()->getOrDefault(key).getMagnitude(); + int currentValue = static_cast(effects.getStore()->getOrDefault(key).getMagnitude()); effects.getStore()->modifyBase(key, value - currentValue); }; diff --git a/apps/openmw/mwlua/mwscriptbindings.cpp b/apps/openmw/mwlua/mwscriptbindings.cpp index 179b35aa5c..b8d14faa09 100644 --- a/apps/openmw/mwlua/mwscriptbindings.cpp +++ b/apps/openmw/mwlua/mwscriptbindings.cpp @@ -90,7 +90,7 @@ namespace MWLua } else if (varType == 's' || varType == 'l') { - MWBase::Environment::get().getWorld()->setGlobalInt(globalId, value); + MWBase::Environment::get().getWorld()->setGlobalInt(globalId, static_cast(value)); } } diff --git a/apps/openmw/mwlua/nearbybindings.cpp b/apps/openmw/mwlua/nearbybindings.cpp index b31a934a54..c1ef54fe7f 100644 --- a/apps/openmw/mwlua/nearbybindings.cpp +++ b/apps/openmw/mwlua/nearbybindings.cpp @@ -356,9 +356,9 @@ namespace MWLua if (!searchAreaHalfExtents.has_value()) { const bool isEsm4 = MWBase::Environment::get().getWorldScene()->getCurrentCell()->getCell()->isEsm4(); - const float halfExtents = isEsm4 - ? (1 + 2 * Constants::ESM4CellGridRadius) * Constants::ESM4CellSizeInUnits - : (1 + 2 * Constants::CellGridRadius) * Constants::CellSizeInUnits; + const float halfExtents = static_cast(isEsm4 + ? (1 + 2 * Constants::ESM4CellGridRadius) * Constants::ESM4CellSizeInUnits + : (1 + 2 * Constants::CellGridRadius) * Constants::CellSizeInUnits); searchAreaHalfExtents = osg::Vec3f(halfExtents, halfExtents, halfExtents); } diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index 2a0aa87d15..100ec5bd4b 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -259,16 +259,17 @@ namespace MWLua }; ownerT["factionId"] = sol::property(getOwnerFactionId, setOwnerFactionId); - auto getOwnerFactionRank = [](const OwnerT& o) -> sol::optional { + auto getOwnerFactionRank = [](const OwnerT& o) -> sol::optional { int rank = o.mObj.ptr().getCellRef().getFactionRank(); if (rank < 0) return sol::nullopt; return LuaUtil::toLuaIndex(rank); }; - auto setOwnerFactionRank = [](const OwnerT& o, sol::optional factionRank) { + auto setOwnerFactionRank = [](const OwnerT& o, sol::optional factionRank) { if (std::is_same_v && !dynamic_cast(&o.mObj)) throw std::runtime_error("Local scripts can set an owner faction rank only on self"); - o.mObj.ptr().getCellRef().setFactionRank(LuaUtil::fromLuaIndex(factionRank.value_or(0))); + int64_t rank = std::max(0, LuaUtil::fromLuaIndex(factionRank.value_or(0))); + o.mObj.ptr().getCellRef().setFactionRank(static_cast(rank)); }; ownerT["factionRank"] = sol::property(getOwnerFactionRank, setOwnerFactionRank); diff --git a/apps/openmw/mwlua/uibindings.cpp b/apps/openmw/mwlua/uibindings.cpp index 7c708fefa9..b5188b19d7 100644 --- a/apps/openmw/mwlua/uibindings.cpp +++ b/apps/openmw/mwlua/uibindings.cpp @@ -243,7 +243,8 @@ namespace MWLua return luaManager->uiResourceManager()->registerTexture(std::move(data)); }; - api["screenSize"] = []() { return osg::Vec2f(Settings::video().mResolutionX, Settings::video().mResolutionY); }; + api["screenSize"] + = []() { return osg::Vec2f(float(Settings::video().mResolutionX), float(Settings::video().mResolutionY)); }; api["_getAllUiModes"] = [](sol::this_state thisState) { sol::table res(thisState, sol::create); @@ -269,16 +270,16 @@ namespace MWLua if (arg.has_value()) ptr = arg->ptr(); const std::vector& stack = windowManager->getGuiModeStack(); - unsigned common = 0; + size_t common = 0; while (common < std::min(stack.size(), newStack.size()) && stack[common] == newStack[common]) common++; // TODO: Maybe disallow opening/closing special modes (main menu, settings, loading screen) // from player scripts. Add new Lua context "menu" that can do it. - for (unsigned i = stack.size() - common; i > 0; i--) + for (size_t i = stack.size() - common; i > 0; i--) windowManager->popGuiMode(true); if (common == newStack.size() && !newStack.empty() && arg.has_value()) windowManager->pushGuiMode(newStack.back(), ptr); - for (unsigned i = common; i < newStack.size(); ++i) + for (size_t i = common; i < newStack.size(); ++i) windowManager->pushGuiMode(newStack[i], ptr); }, "Set UI modes"); diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 78d335738c..109b75e1d4 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -58,9 +58,9 @@ namespace effect.mEffectId = enam.mData.mEffectID; effect.mArg = MWMechanics::EffectKey(enam.mData).mArg; effect.mMagnitude = 0.f; - effect.mMinMagnitude = enam.mData.mMagnMin; - effect.mMaxMagnitude = enam.mData.mMagnMax; - effect.mEffectIndex = enam.mIndex; + effect.mMinMagnitude = static_cast(enam.mData.mMagnMin); + effect.mMaxMagnitude = static_cast(enam.mData.mMagnMax); + effect.mEffectIndex = static_cast(enam.mIndex); effect.mFlags = ESM::ActiveEffect::Flag_None; if (ignoreResistances) effect.mFlags |= ESM::ActiveEffect::Flag_Ignore_Resistances; diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 04f4e12b65..786539e585 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -584,8 +584,8 @@ namespace MWMechanics float to = dir.y(); float angle = std::atan2(from, to); actorState.setAngleToPlayer(angle); - float deltaAngle = Misc::normalizeAngle(angle - actor.getRefData().getPosition().rot[2]); - if (!Settings::game().mSmoothMovement || std::abs(deltaAngle) > osg::DegreesToRadians(60.f)) + double deltaAngle = Misc::normalizeAngle(angle - actor.getRefData().getPosition().rot[2]); + if (!Settings::game().mSmoothMovement || std::abs(deltaAngle) > osg::DegreesToRadians(60.0)) actorState.setTurningToPlayer(true); } } @@ -849,7 +849,7 @@ namespace MWMechanics const auto [health, magicka] = getRestorationPerHourOfSleep(ptr); DynamicStat stat = stats.getHealth(); - stat.setCurrent(stat.getCurrent() + health * hours); + stat.setCurrent(static_cast(stat.getCurrent() + health * hours)); stats.setHealth(stat); double restoreHours = hours; @@ -876,7 +876,7 @@ namespace MWMechanics if (restoreHours > 0) { stat = stats.getMagicka(); - stat.setCurrent(stat.getCurrent() + magicka * restoreHours); + stat.setCurrent(static_cast(stat.getCurrent() + magicka * restoreHours)); stats.setMagicka(stat); } } @@ -901,7 +901,7 @@ namespace MWMechanics const float x = (fFatigueReturnBase + fFatigueReturnMult * (1 - normalizedEncumbrance)) * (fEndFatigueMult * endurance); - fatigue.setCurrent(fatigue.getCurrent() + 3600 * x * hours); + fatigue.setCurrent(static_cast(fatigue.getCurrent() + 3600 * x * hours)); stats.setFatigue(fatigue); } @@ -1156,9 +1156,8 @@ namespace MWMechanics if (playerStats.getBounty() >= cutoff * iCrimeThresholdMultiplier) { mechanicsManager->startCombat(ptr, player, &cachedAllies.getActorsSidingWith(player)); - creatureStats.setHitAttemptActorId( - playerClass.getCreatureStats(player) - .getActorId()); // Stops the guard from quitting combat if player is unreachable + // Stops the guard from quitting combat if player is unreachable + creatureStats.setHitAttemptActorId(playerClass.getCreatureStats(player).getActorId()); } else creatureStats.getAiSequence().stack(AiPursue(player), ptr); @@ -1234,7 +1233,7 @@ namespace MWMechanics // Fade away actors on large distance (>90% of actor's processing distance) float visibilityRatio = 1.0; const float fadeStartDistance = actorsProcessingRange * 0.9f; - const float fadeEndDistance = actorsProcessingRange; + const float fadeEndDistance = static_cast(actorsProcessingRange); const float fadeRatio = (dist - fadeStartDistance) / (fadeEndDistance - fadeStartDistance); if (fadeRatio > 0) visibilityRatio -= std::max(0.f, fadeRatio); @@ -1278,7 +1277,7 @@ namespace MWMechanics // Otherwise check if any actor in AI processing range sees the target actor std::vector neighbors; osg::Vec3f position(actor.getRefData().getPosition().asVec3()); - getObjectsInRange(position, Settings::game().mActorsProcessingRange, neighbors); + getObjectsInRange(position, static_cast(Settings::game().mActorsProcessingRange), neighbors); for (const MWWorld::Ptr& neighbor : neighbors) { if (neighbor == actor) @@ -1877,7 +1876,7 @@ namespace MWMechanics void Actors::rest(double hours, bool sleep) const { - float duration = hours * 3600.f; + float duration = static_cast(hours * 3600); const float timeScale = MWBase::Environment::get().getWorld()->getTimeManager()->getGameTimeScale(); if (timeScale != 0.f) duration /= timeScale; @@ -1952,7 +1951,7 @@ namespace MWMechanics std::vector observers; const osg::Vec3f position(player.getRefData().getPosition().asVec3()); - const float radius = std::min(fSneakUseDist, Settings::game().mActorsProcessingRange); + const float radius = std::min(fSneakUseDist, static_cast(Settings::game().mActorsProcessingRange)); getObjectsInRange(position, radius, observers); std::set sidingActors; @@ -2256,7 +2255,7 @@ namespace MWMechanics std::vector list; std::vector neighbors; const osg::Vec3f position(actor.getRefData().getPosition().asVec3()); - getObjectsInRange(position, Settings::game().mActorsProcessingRange, neighbors); + getObjectsInRange(position, static_cast(Settings::game().mActorsProcessingRange), neighbors); for (const MWWorld::Ptr& neighbor : neighbors) { if (neighbor == actor) @@ -2277,7 +2276,7 @@ namespace MWMechanics std::vector list; std::vector neighbors; osg::Vec3f position(actor.getRefData().getPosition().asVec3()); - getObjectsInRange(position, Settings::game().mActorsProcessingRange, neighbors); + getObjectsInRange(position, static_cast(Settings::game().mActorsProcessingRange), neighbors); std::set followers; getActorsFollowing(actor, followers); diff --git a/apps/openmw/mwmechanics/aiavoiddoor.cpp b/apps/openmw/mwmechanics/aiavoiddoor.cpp index 1f229f61bf..79e765711c 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.cpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.cpp @@ -88,5 +88,5 @@ void MWMechanics::AiAvoidDoor::adjustDirection() float MWMechanics::AiAvoidDoor::getAdjustedAngle() const { - return 2 * osg::PI / MAX_DIRECTIONS * mDirection; + return 2 * osg::PIf / MAX_DIRECTIONS * mDirection; } diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 4eb0c762eb..0ddcf409b6 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -432,7 +432,7 @@ namespace MWMechanics storage.mFleeBlindRunTimer += duration; storage.mMovement.mRotation[0] = -actor.getRefData().getPosition().rot[0]; - storage.mMovement.mRotation[2] = osg::PI + storage.mMovement.mRotation[2] = osg::PIf + getZAngleToDir( target.getRefData().getPosition().asVec3() - actor.getRefData().getPosition().asVec3()); storage.mMovement.mPosition[1] = 1; @@ -486,7 +486,7 @@ namespace MWMechanics actorMovementSettings.mRotation[axis] = 0; bool isRangedCombat = false; storage.mCurrentAction->getCombatRange(isRangedCombat); - float eps = isRangedCombat ? osg::DegreesToRadians(0.5) : osg::DegreesToRadians(3.f); + float eps = isRangedCombat ? osg::DegreesToRadians(0.5f) : osg::DegreesToRadians(3.f); float targetAngleRadians = storage.mMovement.mRotation[axis]; storage.mRotateMove = !smoothTurn(actor, targetAngleRadians, axis, eps); } @@ -567,7 +567,7 @@ namespace MWMechanics else if (actor.getClass().isBipedal(actor) && !isDistantCombat) { float moveDuration = 0; - float angleToTarget + double angleToTarget = Misc::normalizeAngle(mMovement.mRotation[2] - actor.getRefData().getPosition().rot[2]); // Apply a big side step if enemy tries to get around and come from behind. // Otherwise apply a random side step (kind of dodging) with some probability @@ -683,7 +683,7 @@ namespace MWMechanics MWBase::Environment::get().getDialogueManager()->say(actor, ESM::RefId::stringRefId("attack")); } } - mAttackCooldown = std::min(baseDelay + 0.01 * Misc::Rng::roll0to99(prng), baseDelay + 0.9); + mAttackCooldown = std::min(baseDelay + 0.01f * Misc::Rng::roll0to99(prng), baseDelay + 0.9f); } else mAttackCooldown -= AI_REACTION_TIME; diff --git a/apps/openmw/mwmechanics/aicombataction.cpp b/apps/openmw/mwmechanics/aicombataction.cpp index ac59de0426..334da834cd 100644 --- a/apps/openmw/mwmechanics/aicombataction.cpp +++ b/apps/openmw/mwmechanics/aicombataction.cpp @@ -514,7 +514,7 @@ namespace MWMechanics const int flee = stats.getAiSetting(AiSetting::Flee).getModified(); if (flee >= 100) - return flee; + return static_cast(flee); static const float fAIFleeHealthMult = gmst.find("fAIFleeHealthMult")->mValue.getFloat(); static const float fAIFleeFleeMult = gmst.find("fAIFleeFleeMult")->mValue.getFloat(); @@ -529,7 +529,7 @@ namespace MWMechanics if (enemy.getClass().getNpcStats(enemy).isWerewolf() && stats.getLevel() < iWereWolfLevelToAttack) { static const int iWereWolfFleeMod = gmst.find("iWereWolfFleeMod")->mValue.getInteger(); - rating = iWereWolfFleeMod; + rating = static_cast(iWereWolfFleeMod); } } diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 9e6df46340..a375aea33c 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -29,7 +29,7 @@ namespace MWMechanics , mX(x) , mY(y) , mZ(z) - , mDuration(duration) + , mDuration(static_cast(duration)) , mRemainingDuration(static_cast(duration)) { mTargetActorRefId = actorId; @@ -42,7 +42,7 @@ namespace MWMechanics , mX(x) , mY(y) , mZ(z) - , mDuration(duration) + , mDuration(static_cast(duration)) , mRemainingDuration(static_cast(duration)) { mTargetActorRefId = actorId; @@ -129,7 +129,7 @@ namespace MWMechanics escort->mData.mX = mX; escort->mData.mY = mY; escort->mData.mZ = mZ; - escort->mData.mDuration = mDuration; + escort->mData.mDuration = static_cast(mDuration); escort->mTargetId = mTargetActorRefId; escort->mTargetActorId = mTargetActorId; escort->mRemainingDuration = mRemainingDuration; diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index b4779dc900..ec128ae2a9 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -244,7 +244,7 @@ namespace MWMechanics follow->mData.mX = mX; follow->mData.mY = mY; follow->mData.mZ = mZ; - follow->mData.mDuration = mDuration; + follow->mData.mDuration = static_cast(mDuration); follow->mTargetId = mTargetActorRefId; follow->mTargetActorId = mTargetActorId; follow->mRemainingDuration = mRemainingDuration; diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index 3fcb28307c..146124fcbf 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -37,7 +37,7 @@ namespace float getPointTolerance(float speed, float duration, const osg::Vec3f& halfExtents) { - const float actorTolerance = 2 * speed * duration + 1.2 * std::max(halfExtents.x(), halfExtents.y()); + const float actorTolerance = 2 * speed * duration + 1.2f * std::max(halfExtents.x(), halfExtents.y()); return std::max(MWMechanics::MIN_TOLERANCE, actorTolerance); } diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 4499304303..ff937305ae 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -65,10 +65,10 @@ namespace MWMechanics osg::Vec3f getRandomPointAround(const osg::Vec3f& position, const float distance) { auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const float randomDirection = Misc::Rng::rollClosedProbability(prng) * 2.0f * osg::PI; + const float randomDirection = Misc::Rng::rollClosedProbability(prng) * 2.f * osg::PIf; osg::Matrixf rotation; - rotation.makeRotate(randomDirection, osg::Vec3f(0.0, 0.0, 1.0)); - return position + osg::Vec3f(distance, 0.0, 0.0) * rotation; + rotation.makeRotate(randomDirection, osg::Vec3f(0.f, 0.f, 1.f)); + return position + osg::Vec3f(distance, 0.f, 0.f) * rotation; } bool isDestinationHidden(const MWWorld::ConstPtr& actor, const osg::Vec3f& destination) @@ -158,13 +158,11 @@ namespace MWMechanics : TypedAiPackage(repeat) , mDistance(static_cast(std::max(0, distance))) , mDuration(static_cast(std::max(0, duration))) - , mRemainingDuration(duration) + , mRemainingDuration(static_cast(duration)) , mTimeOfDay(timeOfDay) , mIdle(getInitialIdle(idle)) , mStoredInitialActorPosition(false) - , mInitialActorPosition(osg::Vec3f(0, 0, 0)) , mHasDestination(false) - , mDestination(osg::Vec3f(0, 0, 0)) , mUsePathgrid(false) { } @@ -283,7 +281,7 @@ namespace MWMechanics { stopWalking(actor); // Reset package so it can be used again - mRemainingDuration = mDuration; + mRemainingDuration = static_cast(mDuration); return true; } @@ -628,8 +626,7 @@ namespace MWMechanics { MWBase::World& world = *MWBase::Environment::get().getWorld(); Misc::Rng::Generator& prng = world.getPrng(); - const std::size_t randomAllowedPositionIndex - = static_cast(Misc::Rng::rollDice(storage.mAllowedPositions.size(), prng)); + const std::size_t randomAllowedPositionIndex = Misc::Rng::rollDice(storage.mAllowedPositions.size(), prng); const osg::Vec3f randomAllowedPosition = storage.mAllowedPositions[randomAllowedPositionIndex]; const osg::Vec3f start = actorPos.asVec3(); @@ -734,7 +731,7 @@ namespace MWMechanics } } - int AiWander::getRandomIdle() const + unsigned short AiWander::getRandomIdle() const { MWBase::World* world = MWBase::Environment::get().getWorld(); static const float fIdleChanceMultiplier @@ -742,14 +739,14 @@ namespace MWMechanics if (Misc::Rng::rollClosedProbability(world->getPrng()) > fIdleChanceMultiplier) return 0; - int newIdle = 0; + unsigned short newIdle = 0; float maxRoll = 0.f; for (size_t i = 0; i < mIdle.size(); i++) { float roll = Misc::Rng::rollClosedProbability(world->getPrng()) * 100.f; if (roll <= mIdle[i] && roll > maxRoll) { - newIdle = GroupIndex_MinIdle + i; + newIdle = static_cast(GroupIndex_MinIdle + i); maxRoll = roll; } } @@ -772,7 +769,7 @@ namespace MWMechanics return; auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - int index = Misc::Rng::rollDice(storage.mAllowedPositions.size(), prng); + size_t index = Misc::Rng::rollDice(storage.mAllowedPositions.size(), prng); const osg::Vec3f worldDest = storage.mAllowedPositions[index]; const Misc::CoordinateConverter converter = Misc::makeCoordinateConverter(*actor.getCell()->getCell()); osg::Vec3f dest = converter.toLocalVec3(worldDest); @@ -794,7 +791,7 @@ namespace MWMechanics // AI will try to move the NPC towards every neighboring node until suitable place will be found while (!points.empty()) { - int randomIndex = Misc::Rng::rollDice(points.size(), prng); + size_t randomIndex = Misc::Rng::rollDice(points.size(), prng); const ESM::Pathgrid::Point& connDest = points[randomIndex]; // add an offset towards random neighboring node @@ -940,7 +937,7 @@ namespace MWMechanics // must not travel longer than distance between waypoints or NPC goes past waypoint distance = std::min(distance, static_cast(length)); - delta *= distance; + delta *= static_cast(distance); storage.mAllowedPositions.push_back(vectorStart + delta); } @@ -968,12 +965,12 @@ namespace MWMechanics if (mRemainingDuration > 0 && mRemainingDuration < 24) remainingDuration = mRemainingDuration; else - remainingDuration = mDuration; + remainingDuration = static_cast(mDuration); auto wander = std::make_unique(); - wander->mData.mDistance = mDistance; - wander->mData.mDuration = mDuration; - wander->mData.mTimeOfDay = mTimeOfDay; + wander->mData.mDistance = static_cast(mDistance); + wander->mData.mDuration = static_cast(mDuration); + wander->mData.mTimeOfDay = static_cast(mTimeOfDay); wander->mDurationData.mRemainingDuration = remainingDuration; assert(mIdle.size() == 8); for (int i = 0; i < 8; ++i) @@ -998,12 +995,11 @@ namespace MWMechanics , mIdle(getInitialIdle(wander->mData.mIdle)) , mStoredInitialActorPosition(wander->mStoredInitialActorPosition) , mHasDestination(false) - , mDestination(osg::Vec3f(0, 0, 0)) , mUsePathgrid(false) { if (mStoredInitialActorPosition) mInitialActorPosition = wander->mInitialActorPosition; if (mRemainingDuration <= 0 || mRemainingDuration >= 24) - mRemainingDuration = mDuration; + mRemainingDuration = static_cast(mDuration); } } diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index 3e0b704524..b99d2638a4 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -131,7 +131,7 @@ namespace MWMechanics /// @return Success or error bool playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect); bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect); - int getRandomIdle() const; + unsigned short getRandomIdle() const; void setPathToAnAllowedPosition( const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos); void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage); diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index 9fdae5d66a..12eb78a630 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -217,15 +217,15 @@ void MWMechanics::Alchemy::updateEffects() if (magnitude > 0 && duration > 0) { ESM::ENAMstruct effect; - effect.mEffectID = effectKey.mId; + effect.mEffectID = static_cast(effectKey.mId); effect.mAttribute = -1; effect.mSkill = -1; if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill) - effect.mSkill = ESM::Skill::refIdToIndex(effectKey.mArg); + effect.mSkill = static_cast(ESM::Skill::refIdToIndex(effectKey.mArg)); else if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute) - effect.mAttribute = ESM::Attribute::refIdToIndex(effectKey.mArg); + effect.mAttribute = static_cast(ESM::Attribute::refIdToIndex(effectKey.mArg)); effect.mRange = 0; effect.mArea = 0; @@ -395,8 +395,7 @@ void MWMechanics::Alchemy::setAlchemist(const MWWorld::Ptr& npc) MWWorld::ContainerStore& store = npc.getClass().getContainerStore(npc); - for (MWWorld::ContainerStoreIterator iter(store.begin(MWWorld::ContainerStore::Type_Apparatus)); - iter != store.end(); ++iter) + for (auto iter(store.begin(MWWorld::ContainerStore::Type_Apparatus)); iter != store.end(); ++iter) { MWWorld::LiveCellRef* ref = iter->get(); @@ -604,7 +603,8 @@ std::string MWMechanics::Alchemy::suggestPotionName() return effects.begin()->toString(); } -std::vector MWMechanics::Alchemy::effectsDescription(const MWWorld::ConstPtr& ptr, const float alchemySkill) +std::vector MWMechanics::Alchemy::effectsDescription( + const MWWorld::ConstPtr& ptr, const float alchemySkill) { std::vector effects; diff --git a/apps/openmw/mwmechanics/autocalcspell.cpp b/apps/openmw/mwmechanics/autocalcspell.cpp index 5bab25fbe5..dcd3ec7dcb 100644 --- a/apps/openmw/mwmechanics/autocalcspell.cpp +++ b/apps/openmw/mwmechanics/autocalcspell.cpp @@ -278,10 +278,10 @@ namespace MWMechanics .find("fEffectCostMult") ->mValue.getFloat(); - float x = 0.5 * (std::max(1, minMagn) + std::max(1, maxMagn)); - x *= 0.1 * magicEffect->mData.mBaseCost; + float x = 0.5f * (std::max(1, minMagn) + std::max(1, maxMagn)); + x *= 0.1f * magicEffect->mData.mBaseCost; x *= 1 + duration; - x += 0.05 * std::max(1, effect.mData.mArea) * magicEffect->mData.mBaseCost; + x += 0.05f * std::max(1, effect.mData.mArea) * magicEffect->mData.mBaseCost; x *= fEffectCostMult; if (effect.mData.mRange == ESM::RT_Target) diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index 7c0c674986..1e19390c67 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -131,7 +131,7 @@ namespace MWMechanics static const int iBlockMaxChance = gmst.find("iBlockMaxChance")->mValue.getInteger(); static const int iBlockMinChance = gmst.find("iBlockMinChance")->mValue.getInteger(); - int x = std::clamp(blockerTerm - attackerTerm, iBlockMinChance, iBlockMaxChance); + int x = std::clamp(static_cast(blockerTerm - attackerTerm), iBlockMinChance, iBlockMaxChance); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); if (Misc::Rng::roll0to99(prng) < x) @@ -237,7 +237,7 @@ namespace MWMechanics if (attacker == getPlayer()) MWBase::Environment::get().getWindowManager()->setEnemy(victim); - int skillValue = attacker.getClass().getSkill(attacker, weaponSkill); + int skillValue = static_cast(attacker.getClass().getSkill(attacker, weaponSkill)); if (Misc::Rng::roll0to99(world->getPrng()) >= getHitChance(attacker, victim, skillValue)) { @@ -373,7 +373,7 @@ namespace MWMechanics float x = std::max(0.f, saveTerm - Misc::Rng::roll0to99(prng)); - int element = ESM::MagicEffect::FireDamage; + short element = ESM::MagicEffect::FireDamage; if (i == 1) element = ESM::MagicEffect::ShockDamage; if (i == 2) @@ -627,7 +627,7 @@ namespace MWMechanics actor.getClass().getCreatureStats(actor).getAiSequence().getCombatTargets(targets); else MWBase::Environment::get().getMechanicsManager()->getActorsInRange( - actorPos, Settings::game().mActorsProcessingRange, targets); + actorPos, static_cast(Settings::game().mActorsProcessingRange), targets); for (MWWorld::Ptr& target : targets) { diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 0a14d46097..24b5891c1c 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -407,8 +407,8 @@ namespace MWMechanics else base = world->getStore().get().find("fNPCbaseMagickaMult")->mValue.getFloat(); - double magickaFactor = base - + mMagicEffects.getOrDefault(EffectKey(ESM::MagicEffect::FortifyMaximumMagicka)).getMagnitude() * 0.1; + float magickaFactor = base + + mMagicEffects.getOrDefault(EffectKey(ESM::MagicEffect::FortifyMaximumMagicka)).getMagnitude() * 0.1f; DynamicStat magicka = getMagicka(); float currentToBaseRatio = magicka.getBase() > 0 ? magicka.getCurrent() / magicka.getBase() : 0; @@ -507,7 +507,7 @@ namespace MWMechanics void CreatureStats::writeState(ESM::CreatureStats& state) const { for (size_t i = 0; i < state.mAttributes.size(); ++i) - getAttribute(ESM::Attribute::indexToRefId(i)).writeState(state.mAttributes[i]); + getAttribute(ESM::Attribute::indexToRefId(static_cast(i))).writeState(state.mAttributes[i]); for (size_t i = 0; i < state.mDynamic.size(); ++i) mDynamic[i].writeState(state.mDynamic[i]); @@ -564,7 +564,7 @@ namespace MWMechanics if (!state.mMissingACDT) { for (size_t i = 0; i < state.mAttributes.size(); ++i) - mAttributes[ESM::Attribute::indexToRefId(i)].readState(state.mAttributes[i]); + mAttributes[ESM::Attribute::indexToRefId(static_cast(i))].readState(state.mAttributes[i]); for (size_t i = 0; i < state.mDynamic.size(); ++i) mDynamic[i].readState(state.mDynamic[i]); diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 66bef89e2c..0efb6aa641 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -300,7 +300,7 @@ namespace MWMechanics ->mValue.getFloat(); int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer( mEnchanter, static_cast(finalEffectCost * priceMultipler), true); - price *= count * getTypeMultiplier(); + price *= static_cast(count * getTypeMultiplier()); return std::max(1, price); } @@ -381,8 +381,9 @@ namespace MWMechanics { MWWorld::Ptr player = getPlayer(); count = player.getClass().getContainerStore(player).count(mOldItemPtr.getCellRef().getRefId()); - count = std::clamp( - getGemCharge() * Settings::game().mProjectilesEnchantMultiplier / enchantPoints, 1, count); + count = std::clamp( + static_cast(getGemCharge() * Settings::game().mProjectilesEnchantMultiplier / enchantPoints), + 1, count); } } diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index f70605b809..2d2f5057b0 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -135,10 +135,10 @@ namespace MWMechanics creatureStats.getActiveSpells().clear(ptr); for (size_t i = 0; i < player->mNpdt.mSkills.size(); ++i) - npcStats.getSkill(ESM::Skill::indexToRefId(i)).setBase(player->mNpdt.mSkills[i]); + npcStats.getSkill(ESM::Skill::indexToRefId(static_cast(i))).setBase(player->mNpdt.mSkills[i]); for (size_t i = 0; i < player->mNpdt.mAttributes.size(); ++i) - npcStats.setAttribute(ESM::Attribute::indexToRefId(i), player->mNpdt.mSkills[i]); + npcStats.setAttribute(ESM::Attribute::indexToRefId(static_cast(i)), player->mNpdt.mSkills[i]); const MWWorld::ESMStore& esmStore = *MWBase::Environment::get().getESMStore(); @@ -150,7 +150,8 @@ namespace MWMechanics bool male = (player->mFlags & ESM::NPC::Female) == 0; for (const ESM::Attribute& attribute : esmStore.get()) - creatureStats.setAttribute(attribute.mId, race->mData.getAttribute(attribute.mId, male)); + creatureStats.setAttribute( + attribute.mId, static_cast(race->mData.getAttribute(attribute.mId, male))); for (const ESM::Skill& skill : esmStore.get()) { @@ -161,7 +162,7 @@ namespace MWMechanics if (bonusIt != race->mData.mBonus.end()) bonus = bonusIt->mBonus; - npcStats.getSkill(skill.mId).setBase(5 + bonus); + npcStats.getSkill(skill.mId).setBase(5.f + bonus); } for (const ESM::RefId& power : race->mPowers.mList) @@ -566,7 +567,7 @@ namespace MWMechanics .getMagnitude(); if (clamp) - return std::clamp(x, 0, 100); //, normally clamped to [0..100] when used + return std::clamp(static_cast(x), 0, 100); //, normally clamped to [0..100] when used return static_cast(x); } @@ -1733,10 +1734,8 @@ namespace MWMechanics // if guard starts combat with player, guards pursuing player should do the same if (ptr.getClass().isClass(ptr, "Guard")) { - stats.setHitAttemptActorId( - target.getClass() - .getCreatureStats(target) - .getActorId()); // Stops guard from ending combat if player is unreachable + // Stops guard from ending combat if player is unreachable + stats.setHitAttemptActorId(target.getClass().getCreatureStats(target).getActorId()); for (const Actor& actor : mActors) { if (actor.isInvalid()) @@ -1749,13 +1748,11 @@ namespace MWMechanics { aiSeq.stopPursuit(); aiSeq.stack(MWMechanics::AiCombat(target), ptr); + // Stops guard from ending combat if player is unreachable actor.getPtr() .getClass() .getCreatureStats(actor.getPtr()) - .setHitAttemptActorId( - target.getClass() - .getCreatureStats(target) - .getActorId()); // Stops guard from ending combat if player is unreachable + .setHitAttemptActorId(target.getClass().getCreatureStats(target).getActorId()); } } } @@ -1830,7 +1827,7 @@ namespace MWMechanics mActors.getActorsSidingWith(actor, out); } - int MechanicsManager::countSavedGameRecords() const + size_t MechanicsManager::countSavedGameRecords() const { return 1 // Death counter + 1; // Stolen items @@ -2051,8 +2048,8 @@ namespace MWMechanics void MechanicsManager::reportStats(unsigned int frameNumber, osg::Stats& stats) const { - stats.setAttribute(frameNumber, "Mechanics Actors", mActors.size()); - stats.setAttribute(frameNumber, "Mechanics Objects", mObjects.size()); + stats.setAttribute(frameNumber, "Mechanics Actors", static_cast(mActors.size())); + stats.setAttribute(frameNumber, "Mechanics Objects", static_cast(mObjects.size())); } int MechanicsManager::getGreetingTimer(const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index 11ef21852c..4e310e451e 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -182,7 +182,7 @@ namespace MWMechanics bool onOpen(const MWWorld::Ptr& ptr) override; void onClose(const MWWorld::Ptr& ptr) override; - int countSavedGameRecords() const override; + size_t countSavedGameRecords() const override; void write(ESM::ESMWriter& writer, Loading::Listener& listener) const override; diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index a55374411a..6f0fe667f1 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -493,7 +493,7 @@ void MWMechanics::NpcStats::readState(const ESM::NpcStats& state) for (size_t i = 0; i < state.mSkills.size(); ++i) { // TODO extend format - ESM::RefId id = ESM::Skill::indexToRefId(i); + ESM::RefId id = ESM::Skill::indexToRefId(static_cast(i)); assert(!id.empty()); mSkills[id].readState(state.mSkills[i]); } @@ -507,7 +507,7 @@ void MWMechanics::NpcStats::readState(const ESM::NpcStats& state) mLevelProgress = state.mLevelProgress; for (size_t i = 0; i < state.mSkillIncrease.size(); ++i) - mSkillIncreases[ESM::Attribute::indexToRefId(i)] = state.mSkillIncrease[i]; + mSkillIncreases[ESM::Attribute::indexToRefId(static_cast(i))] = state.mSkillIncrease[i]; for (size_t i = 0; i < state.mSpecIncreases.size(); ++i) mSpecIncreases[i] = state.mSpecIncreases[i]; diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index 6c30f43cef..c14b9ddffd 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -80,7 +80,7 @@ namespace { const auto world = MWBase::Environment::get().getWorld(); const auto halfExtents = world->getHalfExtents(actor); - return 2.0 * halfExtents.z(); + return 2.f * halfExtents.z(); } // Returns true if turn in `p2` is less than 10 degrees and all the 3 points are almost on one line. @@ -93,7 +93,7 @@ namespace float crossProduct = v1.x() * v3.y() - v1.y() * v3.x(); // Check that the angle between v1 and v3 is less or equal than 5 degrees. - static const float cos175 = std::cos(osg::PI * (175.0 / 180)); + static const float cos175 = std::cos(osg::PIf * (175.f / 180)); bool checkAngle = dotProduct <= cos175 * v1.length() * v3.length(); // Check that distance from p2 to the line (p1, p3) is less or equal than `pointTolerance`. @@ -246,12 +246,11 @@ namespace MWMechanics // Add Z offset since path node can overlap with other objects. // Also ignore doors in raytesting. const int mask = MWPhysics::CollisionType_World; - bool isPathClear = !MWBase::Environment::get() - .getWorld() - ->getRayCasting() - ->castRay(osg::Vec3f(startPoint.x(), startPoint.y(), startPoint.z() + 16), - osg::Vec3f(temp.mX, temp.mY, temp.mZ + 16), mask) - .mHit; + const osg::Vec3f zOffset(0.f, 0.f, 16.f); + const osg::Vec3f from = startPoint + zOffset; + const osg::Vec3f to = Misc::Convert::makeOsgVec3f(temp) + zOffset; + bool isPathClear + = !MWBase::Environment::get().getWorld()->getRayCasting()->castRay(from, to, mask).mHit; if (isPathClear) path.pop_front(); } diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index bf9d6aa025..d17bd97744 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -92,7 +92,7 @@ namespace MWMechanics } // Get the actors in range of the effect std::vector objects; - static const int unitsPerFoot = ceil(Constants::UnitsPerFoot); + static const int unitsPerFoot = static_cast(std::ceil(Constants::UnitsPerFoot)); MWBase::Environment::get().getMechanicsManager()->getObjectsInRange( mHitPosition, static_cast(effectInfo.mData.mArea * unitsPerFoot), objects); for (const MWWorld::Ptr& affected : objects) @@ -204,8 +204,8 @@ namespace MWMechanics effect.mEffectId = enam.mData.mEffectID; effect.mArg = MWMechanics::EffectKey(enam.mData).mArg; effect.mMagnitude = 0.f; - effect.mMinMagnitude = enam.mData.mMagnMin; - effect.mMaxMagnitude = enam.mData.mMagnMax; + effect.mMinMagnitude = static_cast(enam.mData.mMagnMin); + effect.mMaxMagnitude = static_cast(enam.mData.mMagnMax); effect.mTimeLeft = 0.f; effect.mEffectIndex = enam.mIndex; effect.mFlags = ESM::ActiveEffect::Flag_None; diff --git a/apps/openmw/mwmechanics/spelleffects.cpp b/apps/openmw/mwmechanics/spelleffects.cpp index c2a7924c77..2930c2dfbc 100644 --- a/apps/openmw/mwmechanics/spelleffects.cpp +++ b/apps/openmw/mwmechanics/spelleffects.cpp @@ -41,7 +41,8 @@ namespace if (effect.mMinMagnitude == effect.mMaxMagnitude) return effect.mMinMagnitude; auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - return effect.mMinMagnitude + Misc::Rng::rollDice(effect.mMaxMagnitude - effect.mMinMagnitude + 1, prng); + return effect.mMinMagnitude + + Misc::Rng::rollDice(static_cast(effect.mMaxMagnitude - effect.mMinMagnitude + 1), prng); } void modifyAiSetting(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, @@ -365,8 +366,8 @@ namespace { const ESM::Spell* spell = spellParams.hasFlag(ESM::ActiveSpells::Flag_Temporary) ? spellParams.getSpell() : nullptr; - float magnitudeMult - = MWMechanics::getEffectMultiplier(effect.mEffectId, target, caster, spell, &magnitudes); + float magnitudeMult = MWMechanics::getEffectMultiplier( + static_cast(effect.mEffectId), target, caster, spell, &magnitudes); if (magnitudeMult == 0) { // Fully resisted, show message diff --git a/apps/openmw/mwmechanics/spellutil.cpp b/apps/openmw/mwmechanics/spellutil.cpp index fc7637afc1..8dca5f3a00 100644 --- a/apps/openmw/mwmechanics/spellutil.cpp +++ b/apps/openmw/mwmechanics/spellutil.cpp @@ -75,10 +75,10 @@ namespace MWMechanics costMult = iAlchemyMod; } - float x = 0.5 * (minMagn + maxMagn); - x *= 0.1 * magicEffect->mData.mBaseCost; + float x = 0.5f * (minMagn + maxMagn); + x *= 0.1f * magicEffect->mData.mBaseCost; x *= durationOffset + duration; - x += 0.05 * std::max(minArea, effect.mArea) * magicEffect->mData.mBaseCost; + x += 0.05f * std::max(minArea, effect.mArea) * magicEffect->mData.mBaseCost; return x * costMult; } @@ -90,7 +90,7 @@ namespace MWMechanics float cost = getTotalCost(spell.mEffects); - return std::round(cost); + return static_cast(std::round(cost)); } int getEffectiveEnchantmentCastCost(float castCost, const MWWorld::Ptr& actor) @@ -99,7 +99,7 @@ namespace MWMechanics * Each point of enchant skill above/under 10 subtracts/adds * one percent of enchantment cost while minimum is 1. */ - int eSkill = actor.getClass().getSkill(actor, ESM::Skill::Enchant); + float eSkill = actor.getClass().getSkill(actor, ESM::Skill::Enchant); const float result = castCost - (castCost / 100) * (eSkill - 10); return static_cast((result < 1) ? 1 : result); @@ -154,7 +154,7 @@ namespace MWMechanics if (potion.mData.mFlags & ESM::Potion::Autocalc) { float cost = getTotalCost(potion.mEffects, EffectCostMethod::GamePotion); - return std::round(cost); + return static_cast(std::round(cost)); } return potion.mData.mValue; } @@ -166,9 +166,9 @@ namespace MWMechanics throw std::range_error("Index out of range"); ESM::ENAMstruct effect; - effect.mEffectID = ingredient->mData.mEffectID[index]; - effect.mSkill = ingredient->mData.mSkills[index]; - effect.mAttribute = ingredient->mData.mAttributes[index]; + effect.mEffectID = static_cast(ingredient->mData.mEffectID[index]); + effect.mSkill = static_cast(ingredient->mData.mSkills[index]); + effect.mAttribute = static_cast(ingredient->mData.mAttributes[index]); effect.mRange = ESM::RT_Self; effect.mArea = 0; @@ -275,22 +275,22 @@ namespace MWMechanics CreatureStats& stats = actor.getClass().getCreatureStats(actor); if (spell->mData.mType == ESM::Spell::ST_Power) - return stats.getSpells().canUsePower(spell) ? 100 : 0; + return stats.getSpells().canUsePower(spell) ? 100.f : 0.f; if (godmode) - return 100; + return 100.f; if (stats.getMagicEffects().getOrDefault(ESM::MagicEffect::Silence).getMagnitude()) - return 0; + return 0.f; if (spell->mData.mType != ESM::Spell::ST_Spell) - return 100; + return 100.f; if (checkMagicka && calcSpellCost(*spell) > 0 && stats.getMagicka().getCurrent() < calcSpellCost(*spell)) - return 0; + return 0.f; if (spell->mData.mFlags & ESM::Spell::F_Always) - return 100; + return 100.f; float castBonus = -stats.getMagicEffects().getOrDefault(ESM::MagicEffect::Sound).getMagnitude(); float castChance = baseChance + castBonus; diff --git a/apps/openmw/mwmechanics/steering.cpp b/apps/openmw/mwmechanics/steering.cpp index fe7d12e6df..a5a02d3574 100644 --- a/apps/openmw/mwmechanics/steering.cpp +++ b/apps/openmw/mwmechanics/steering.cpp @@ -16,7 +16,8 @@ namespace MWMechanics bool smoothTurn(const MWWorld::Ptr& actor, float targetAngleRadians, int axis, float epsilonRadians) { MWMechanics::Movement& movement = actor.getClass().getMovementSettings(actor); - float diff = Misc::normalizeAngle(targetAngleRadians - actor.getRefData().getPosition().rot[axis]); + float diff + = static_cast(Misc::normalizeAngle(targetAngleRadians - actor.getRefData().getPosition().rot[axis])); float absDiff = std::abs(diff); // The turning animation actually moves you slightly, so the angle will be wrong again. @@ -27,7 +28,7 @@ namespace MWMechanics float limit = getAngularVelocity(actor.getClass().getMaxSpeed(actor)) * MWBase::Environment::get().getFrameDuration(); if (Settings::game().mSmoothMovement) - limit *= std::min(absDiff / osg::PI + 0.1, 0.5); + limit *= std::min(absDiff / osg::PIf + 0.1f, 0.5f); if (absDiff > limit) diff = osg::sign(diff) * limit; diff --git a/apps/openmw/mwmechanics/weaponpriority.cpp b/apps/openmw/mwmechanics/weaponpriority.cpp index dd83db286f..c44e5f842d 100644 --- a/apps/openmw/mwmechanics/weaponpriority.cpp +++ b/apps/openmw/mwmechanics/weaponpriority.cpp @@ -117,12 +117,12 @@ namespace MWMechanics } } - int value = 50.f; + int value = 50; ESM::RefId skill = item.getClass().getEquipmentSkill(item); if (!skill.empty()) - value = actor.getClass().getSkill(actor, skill); + value = static_cast(actor.getClass().getSkill(actor, skill)); // Prefer hand-to-hand if our skill is 0 (presumably due to magic) - if (value <= 0.f) + if (value <= 0) return 0.f; // Note that a creature with a dagger and 0 Stealth will forgo the weapon despite using Combat for hit chance. // The same creature will use a sword provided its Combat stat isn't 0. We're using the "skill" value here to diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index aafefe7019..310061cfd7 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -458,10 +458,10 @@ namespace MWPhysics thread.join(); } - std::tuple PhysicsTaskScheduler::calculateStepConfig(float timeAccum) const + std::tuple PhysicsTaskScheduler::calculateStepConfig(float timeAccum) const { - int maxAllowedSteps = 2; - int numSteps = timeAccum / mDefaultPhysicsDt; + unsigned maxAllowedSteps = 2; + unsigned numSteps = static_cast(timeAccum / mDefaultPhysicsDt); // adjust maximum step count based on whether we're likely physics bottlenecked or not // if maxAllowedSteps ends up higher than numSteps, we will not invoke delta time @@ -478,13 +478,13 @@ namespace MWPhysics // ensure sane minimum value budgetMeasurement = std::max(0.00001f, budgetMeasurement); // we're spending almost or more than realtime per physics frame; limit to a single step - if (budgetMeasurement > 0.95) + if (budgetMeasurement > 0.95f) maxAllowedSteps = 1; // physics is fairly cheap; limit based on expense - if (budgetMeasurement < 0.5) - maxAllowedSteps = std::ceil(1.0 / budgetMeasurement); + if (budgetMeasurement < 0.5f) + maxAllowedSteps = static_cast(std::ceil(1.f / budgetMeasurement)); // limit to a reasonable amount - maxAllowedSteps = std::min(10, maxAllowedSteps); + maxAllowedSteps = std::min(10u, maxAllowedSteps); // fall back to delta time for this frame if fixed timestep physics would fall behind float actualDelta = mDefaultPhysicsDt; @@ -523,7 +523,7 @@ namespace MWPhysics MaybeExclusiveLock lock(mSimulationMutex, mLockingPolicy); - double timeStart = mTimer->tick(); + auto timeStart = mTimer->tick(); // start by finishing previous background computation if (mNumThreads != 0) @@ -550,7 +550,7 @@ namespace MWPhysics mPhysicsDt = newDelta; mSimulations = &simulations; mAdvanceSimulation = (mRemainingSteps != 0); - mNumJobs = mSimulations->size(); + mNumJobs = static_cast(mSimulations->size()); mNextLOS.store(0, std::memory_order_relaxed); mNextJob.store(0, std::memory_order_release); @@ -699,7 +699,7 @@ namespace MWPhysics { MaybeSharedLock lock(mLOSCacheMutex, mLockingPolicy); int job = 0; - int numLOS = mLOSCache.size(); + int numLOS = static_cast(mLOSCache.size()); while ((job = mNextLOS.fetch_add(1, std::memory_order_relaxed)) < numLOS) { auto& req = mLOSCache[job]; @@ -764,9 +764,9 @@ namespace MWPhysics bool PhysicsTaskScheduler::hasLineOfSight(const Actor* actor1, const Actor* actor2) { btVector3 pos1 = Misc::Convert::toBullet( - actor1->getCollisionObjectPosition() + osg::Vec3f(0, 0, actor1->getHalfExtents().z() * 0.9)); // eye level + actor1->getCollisionObjectPosition() + osg::Vec3f(0, 0, actor1->getHalfExtents().z() * 0.9f)); // eye level btVector3 pos2 = Misc::Convert::toBullet( - actor2->getCollisionObjectPosition() + osg::Vec3f(0, 0, actor2->getHalfExtents().z() * 0.9)); + actor2->getCollisionObjectPosition() + osg::Vec3f(0, 0, actor2->getHalfExtents().z() * 0.9f)); btCollisionWorld::ClosestRayResultCallback resultCallback(pos1, pos2); resultCallback.m_collisionFilterGroup = CollisionType_AnyPhysical; diff --git a/apps/openmw/mwphysics/mtphysics.hpp b/apps/openmw/mwphysics/mtphysics.hpp index 579211b489..e25ac13ccc 100644 --- a/apps/openmw/mwphysics/mtphysics.hpp +++ b/apps/openmw/mwphysics/mtphysics.hpp @@ -83,7 +83,7 @@ namespace MWPhysics void updateAabbs(); void updatePtrAabb(const std::shared_ptr& ptr); void updateStats(osg::Timer_t frameStart, unsigned int frameNumber, osg::Stats& stats); - std::tuple calculateStepConfig(float timeAccum) const; + std::tuple calculateStepConfig(float timeAccum) const; void afterPreStep(); void afterPostStep(); void afterPostSim(); @@ -111,7 +111,7 @@ namespace MWPhysics LockingPolicy mLockingPolicy; unsigned mNumThreads; int mNumJobs; - int mRemainingSteps; + unsigned mRemainingSteps; int mLOSCacheExpiry; bool mAdvanceSimulation; std::atomic mNextJob; @@ -126,7 +126,7 @@ namespace MWPhysics unsigned int mFrameNumber; const osg::Timer* mTimer; - int mPrevStepCount; + unsigned mPrevStepCount; Misc::BudgetMeasurement mBudget; Misc::BudgetMeasurement mAsyncBudget; unsigned int mBudgetCursor; diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 9620befe6e..3c2238bac3 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -865,10 +865,10 @@ namespace MWPhysics void PhysicsSystem::reportStats(unsigned int frameNumber, osg::Stats& stats) const { - stats.setAttribute(frameNumber, "Physics Actors", mActors.size()); - stats.setAttribute(frameNumber, "Physics Objects", mObjects.size()); - stats.setAttribute(frameNumber, "Physics Projectiles", mProjectiles.size()); - stats.setAttribute(frameNumber, "Physics HeightFields", mHeightFields.size()); + stats.setAttribute(frameNumber, "Physics Actors", static_cast(mActors.size())); + stats.setAttribute(frameNumber, "Physics Objects", static_cast(mObjects.size())); + stats.setAttribute(frameNumber, "Physics Projectiles", static_cast(mProjectiles.size())); + stats.setAttribute(frameNumber, "Physics HeightFields", static_cast(mHeightFields.size())); } void PhysicsSystem::reportCollision(const btVector3& position, const btVector3& normal) diff --git a/apps/openmw/mwphysics/trace.cpp b/apps/openmw/mwphysics/trace.cpp index 93aa5086ba..6eed92bb95 100644 --- a/apps/openmw/mwphysics/trace.cpp +++ b/apps/openmw/mwphysics/trace.cpp @@ -67,10 +67,10 @@ namespace MWPhysics // Copy the hit data over to our trace results struct: if (traceCallback.hasHit()) { - mFraction = traceCallback.m_closestHitFraction; + mFraction = static_cast(traceCallback.m_closestHitFraction); // ensure fraction is correct (covers intended distance traveled instead of actual distance traveled) if (doingShortTrace && (end - start).length2() > 0.0) - mFraction *= (btend - btstart).length() / (end - start).length(); + mFraction *= static_cast((btend - btstart).length() / (end - start).length()); mPlaneNormal = Misc::Convert::toOsg(traceCallback.m_hitNormalWorld); mEndPos = (end - start) * mFraction + start; mHitPoint = Misc::Convert::toOsg(traceCallback.m_hitPointWorld); @@ -85,7 +85,7 @@ namespace MWPhysics if (newTraceCallback.hasHit()) { - mFraction = newTraceCallback.m_closestHitFraction; + mFraction = static_cast(newTraceCallback.m_closestHitFraction); mPlaneNormal = Misc::Convert::toOsg(newTraceCallback.m_hitNormalWorld); mEndPos = (end - start) * mFraction + start; mHitPoint = Misc::Convert::toOsg(newTraceCallback.m_hitPointWorld); @@ -109,7 +109,7 @@ namespace MWPhysics actor->getCollisionObject(), Misc::Convert::toBullet(start), Misc::Convert::toBullet(end), world, true); if (traceCallback.hasHit()) { - mFraction = traceCallback.m_closestHitFraction; + mFraction = static_cast(traceCallback.m_closestHitFraction); mPlaneNormal = Misc::Convert::toOsg(traceCallback.m_hitNormalWorld); mEndPos = (end - start) * mFraction + start; } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 5912895855..589bd09bc4 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -516,7 +516,7 @@ namespace MWRender double duration = newTime - mStartingTime; mStartingTime = newTime; - mParams.mAnimTime->addTime(duration); + mParams.mAnimTime->addTime(static_cast(duration)); if (mParams.mAnimTime->getTime() >= mParams.mMaxControllerLength) { if (mParams.mLoop) diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index 9f8b1ed86c..c7c92f61c9 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -261,7 +261,7 @@ namespace MWRender for (const osg::Callback* callback = node->getCullCallback(); callback != nullptr; callback = callback->getNestedCallback()) { - if (callback->className() == std::string("BillboardCallback")) + if (callback->className() == std::string_view("BillboardCallback")) { if (mOptimizeBillboards) { @@ -310,8 +310,8 @@ namespace MWRender const osg::Matrix& oldMatrix = matrixTransform->getMatrix(); float mag[3]; // attempt to preserve scale for (int i = 0; i < 3; ++i) - mag[i] = std::sqrt(oldMatrix(0, i) * oldMatrix(0, i) + oldMatrix(1, i) * oldMatrix(1, i) - + oldMatrix(2, i) * oldMatrix(2, i)); + mag[i] = static_cast(std::sqrt(oldMatrix(0, i) * oldMatrix(0, i) + + oldMatrix(1, i) * oldMatrix(1, i) + oldMatrix(2, i) * oldMatrix(2, i))); osg::Matrix newMatrix; worldToLocal.setTrans(0, 0, 0); newMatrix *= worldToLocal; @@ -651,7 +651,8 @@ namespace MWRender osg::ref_ptr ObjectPaging::createChunk(float size, const osg::Vec2f& center, bool activeGrid, const osg::Vec3f& viewPoint, bool compile, unsigned char lod) { - const osg::Vec2i startCell(std::floor(center.x() - size / 2.f), std::floor(center.y() - size / 2.f)); + const osg::Vec2i startCell(static_cast(std::floor(center.x() - size / 2.f)), + static_cast(std::floor(center.y() - size / 2.f))); const MWBase::World& world = *MWBase::Environment::get().getWorld(); const MWWorld::ESMStore& store = world.getStore(); @@ -683,8 +684,10 @@ namespace MWRender const osg::Vec2f minBound = (center - osg::Vec2f(size / 2.f, size / 2.f)); const osg::Vec2f maxBound = (center + osg::Vec2f(size / 2.f, size / 2.f)); - const osg::Vec2i floorMinBound(std::floor(minBound.x()), std::floor(minBound.y())); - const osg::Vec2i ceilMaxBound(std::ceil(maxBound.x()), std::ceil(maxBound.y())); + const osg::Vec2i floorMinBound( + static_cast(std::floor(minBound.x())), static_cast(std::floor(minBound.y()))); + const osg::Vec2i ceilMaxBound( + static_cast(std::ceil(maxBound.x())), static_cast(std::ceil(maxBound.y()))); struct InstanceList { std::vector mInstances; @@ -712,7 +715,7 @@ namespace MWRender { if (size < 1.f) { - const osg::Vec3f cellPos = ref.mPosition / cellSize; + const osg::Vec3f cellPos = ref.mPosition / static_cast(cellSize); if ((minBound.x() > floorMinBound.x() && cellPos.x() < minBound.x()) || (minBound.y() > floorMinBound.y() && cellPos.y() < minBound.y()) || (maxBound.x() < ceilMaxBound.x() && cellPos.x() >= maxBound.x()) @@ -808,7 +811,8 @@ namespace MWRender emplaced.first->second.mInstances.push_back(&ref); } - const osg::Vec3f worldCenter = osg::Vec3f(center.x(), center.y(), 0) * getCellSize(mWorldspace); + const osg::Vec3f worldCenter + = osg::Vec3f(center.x(), center.y(), 0) * static_cast(getCellSize(mWorldspace)); osg::ref_ptr group = new osg::Group; osg::ref_ptr mergeGroup = new osg::Group; osg::ref_ptr templateRefs = new Resource::TemplateMultiRef; @@ -980,8 +984,8 @@ namespace MWRender { osg::Vec2f clampToCell(const osg::Vec3f& cellPos, const osg::Vec2i& cell) { - return osg::Vec2f(std::clamp(cellPos.x(), cell.x(), cell.x() + 1), - std::clamp(cellPos.y(), cell.y(), cell.y() + 1)); + return osg::Vec2f(std::clamp(cellPos.x(), static_cast(cell.x()), cell.x() + 1.f), + std::clamp(cellPos.y(), static_cast(cell.y()), cell.y() + 1.f)); } class CollectIntersecting @@ -990,7 +994,7 @@ namespace MWRender explicit CollectIntersecting( bool activeGridOnly, const osg::Vec3f& position, const osg::Vec2i& cell, ESM::RefId worldspace) : mActiveGridOnly(activeGridOnly) - , mPosition(clampToCell(position / getCellSize(worldspace), cell)) + , mPosition(clampToCell(position / static_cast(getCellSize(worldspace)), cell)) { } diff --git a/apps/openmw/mwrender/postprocessor.cpp b/apps/openmw/mwrender/postprocessor.cpp index a06b9a83de..ce7c2b7765 100644 --- a/apps/openmw/mwrender/postprocessor.cpp +++ b/apps/openmw/mwrender/postprocessor.cpp @@ -135,7 +135,7 @@ namespace MWRender mHUDCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); mHUDCamera->setRenderOrder(osg::Camera::POST_RENDER); - mHUDCamera->setClearColor(osg::Vec4(0.45, 0.45, 0.14, 1.0)); + mHUDCamera->setClearColor(osg::Vec4(0.45f, 0.45f, 0.14f, 1.f)); mHUDCamera->setClearMask(0); mHUDCamera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1, 0, 1)); mHUDCamera->setAllowEventFocus(false); @@ -205,7 +205,7 @@ namespace MWRender else Log(Debug::Error) << "'glDisablei' unsupported, pass normals will not be available to shaders."; - mGLSLVersion = ext->glslLanguageVersion * 100; + mGLSLVersion = static_cast(ext->glslLanguageVersion * 100); mUBO = ext->isUniformBufferObjectSupported && mGLSLVersion >= 330; mStateUpdater = new Fx::StateUpdater(mUBO); @@ -275,7 +275,7 @@ namespace MWRender void PostProcessor::traverse(osg::NodeVisitor& nv) { - size_t frameId = nv.getTraversalNumber() % 2; + unsigned frameId = nv.getTraversalNumber() % 2; if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) cull(frameId, static_cast(&nv)); @@ -285,7 +285,7 @@ namespace MWRender osg::Group::traverse(nv); } - void PostProcessor::cull(size_t frameId, osgUtil::CullVisitor* cv) + void PostProcessor::cull(unsigned frameId, osgUtil::CullVisitor* cv) { if (const auto& fbo = getFbo(FBO_Intercept, frameId)) { @@ -312,7 +312,8 @@ namespace MWRender size_t frame = cv->getTraversalNumber(); - mStateUpdater->setResolution(osg::Vec2f(cv->getViewport()->width(), cv->getViewport()->height())); + mStateUpdater->setResolution(osg::Vec2f( + static_cast(cv->getViewport()->width()), static_cast(cv->getViewport()->height()))); // per-frame data if (frame != mLastFrameNumber) @@ -467,8 +468,8 @@ namespace MWRender textures[Tex_Distortion]->setSourceFormat(GL_RGB); textures[Tex_Distortion]->setInternalFormat(GL_RGB); - Stereo::setMultiviewCompatibleTextureSize( - textures[Tex_Distortion], width * DistortionRatio, height * DistortionRatio); + Stereo::setMultiviewCompatibleTextureSize(textures[Tex_Distortion], static_cast(width * DistortionRatio), + static_cast(height * DistortionRatio)); textures[Tex_Distortion]->dirtyTextureObject(); auto setupDepth = [](osg::Texture* tex) { @@ -632,7 +633,7 @@ namespace MWRender if (auto type = uniform->getType()) uniform->setUniform(node.mRootStateSet->getOrCreateUniform( - uniform->mName.c_str(), *type, uniform->getNumElements())); + uniform->mName, *type, static_cast(uniform->getNumElements()))); } for (const auto& pass : technique->getPasses()) @@ -724,7 +725,7 @@ namespace MWRender disableTechnique(technique, false); - int pos = std::min(location.value_or(mTechniques.size()) + mInternalTechniques.size(), mTechniques.size()); + size_t pos = std::min(location.value_or(mTechniques.size()) + mInternalTechniques.size(), mTechniques.size()); mTechniques.insert(mTechniques.begin() + pos, technique); dirtyTechniques(Settings::ShaderManager::get().getMode() == Settings::ShaderManager::Mode::Debug); diff --git a/apps/openmw/mwrender/postprocessor.hpp b/apps/openmw/mwrender/postprocessor.hpp index f81a50e9d6..962ec920ff 100644 --- a/apps/openmw/mwrender/postprocessor.hpp +++ b/apps/openmw/mwrender/postprocessor.hpp @@ -220,7 +220,7 @@ namespace MWRender void updateLiveReload(); - void cull(size_t frameId, osgUtil::CullVisitor* cv); + void cull(unsigned frameId, osgUtil::CullVisitor* cv); osg::ref_ptr mRootNode; osg::ref_ptr mHUDCamera; @@ -241,7 +241,7 @@ namespace MWRender size_t mDirtyFrameId = 0; size_t mLastFrameNumber = 0; - float mLastSimulationTime = 0.f; + double mLastSimulationTime = 0.0; bool mDirty = false; bool mReload = true; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 67d1cfb587..09330b4a54 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -711,9 +711,9 @@ namespace MWRender if (needsAdjusting) { - constexpr float pR = 0.2126; - constexpr float pG = 0.7152; - constexpr float pB = 0.0722; + constexpr float pR = 0.2126f; + constexpr float pG = 0.7152f; + constexpr float pB = 0.0722f; // we already work in linear RGB so no conversions are needed for the luminosity function float relativeLuminance = pR * ambient.r() + pG * ambient.g() + pB * ambient.b(); @@ -1053,14 +1053,13 @@ namespace MWRender PtrHolder* ptrHolder = nullptr; std::vector refnumMarkers; bool hitNonObjectWorld = false; - for (osg::NodePath::const_iterator it = intersection.nodePath.begin(); it != intersection.nodePath.end(); - ++it) + for (osg::Node* node : intersection.nodePath) { - const auto& nodeMask = (*it)->getNodeMask(); + const auto& nodeMask = node->getNodeMask(); if (!hitNonObjectWorld) hitNonObjectWorld = nodeMask & nonObjectWorldMask; - osg::UserDataContainer* userDataContainer = (*it)->getUserDataContainer(); + osg::UserDataContainer* userDataContainer = node->getUserDataContainer(); if (!userDataContainer) continue; for (unsigned int i = 0; i < userDataContainer->getNumUserObjects(); ++i) @@ -1110,7 +1109,7 @@ namespace MWRender result.mHit = true; result.mHitPointWorld = intersection.getWorldIntersectPoint(); result.mHitNormalWorld = intersection.getWorldIntersectNormal(); - result.mRatio = intersection.ratio; + result.mRatio = static_cast(intersection.ratio); } }; @@ -1385,12 +1384,12 @@ namespace MWRender if (Stereo::getStereo()) { auto res = Stereo::Manager::instance().eyeResolution(); - mSharedUniformStateUpdater->setScreenRes(res.x(), res.y()); + setScreenRes(res.x(), res.y()); Stereo::Manager::instance().setMasterProjectionMatrix(mPerViewUniformStateUpdater->getProjectionMatrix()); } else { - mSharedUniformStateUpdater->setScreenRes(width, height); + mSharedUniformStateUpdater->setScreenRes(static_cast(width), static_cast(height)); } // Since our fog is not radial yet, we should take FOV in account, otherwise terrain near viewing distance may @@ -1407,7 +1406,7 @@ namespace MWRender void RenderingManager::setScreenRes(int width, int height) { - mSharedUniformStateUpdater->setScreenRes(width, height); + mSharedUniformStateUpdater->setScreenRes(static_cast(width), static_cast(height)); } void RenderingManager::updateTextureFiltering() @@ -1415,7 +1414,8 @@ namespace MWRender mViewer->stopThreading(); mResourceSystem->getSceneManager()->setFilterSettings(Settings::general().mTextureMagFilter, - Settings::general().mTextureMinFilter, Settings::general().mTextureMipmap, Settings::general().mAnisotropy); + Settings::general().mTextureMinFilter, Settings::general().mTextureMipmap, + static_cast(Settings::general().mAnisotropy)); mTerrain->updateTextureFiltering(); mWater->processChangedSettings({}); @@ -1428,7 +1428,7 @@ namespace MWRender osg::Vec4f color = mAmbientColor; if (mNightEyeFactor > 0.f) - color += osg::Vec4f(0.7, 0.7, 0.7, 0.0) * mNightEyeFactor; + color += osg::Vec4f(0.7f, 0.7f, 0.7f, 0.0f) * mNightEyeFactor; mPostProcessor->getStateUpdater()->setAmbientColor(color); mStateUpdater->setAmbientColor(color); @@ -1456,7 +1456,7 @@ namespace MWRender { const int compMapResolution = Settings::terrain().mCompositeMapResolution; const int compMapPower = Settings::terrain().mCompositeMapLevel; - const float compMapLevel = std::pow(2, compMapPower); + const float compMapLevel = static_cast(std::pow(2, compMapPower)); const int vertexLodMod = Settings::terrain().mVertexLodMod; const float maxCompGeometrySize = Settings::terrain().mMaxCompositeGeometrySize; const bool debugChunks = Settings::terrain().mDebugChunks; diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index e5aa3b1f91..55717a4a5d 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -226,7 +226,7 @@ namespace MWScript { if (!repeat) repeat = true; - Interpreter::Type_Integer idleValue = std::clamp(runtime[0].mInteger, 0, 255); + auto idleValue = static_cast(std::clamp(runtime[0].mInteger, 0, 255)); idleList.push_back(idleValue); runtime.pop(); --arg0; diff --git a/apps/openmw/mwscript/globalscripts.cpp b/apps/openmw/mwscript/globalscripts.cpp index c20e2fe255..8e4e7c05be 100644 --- a/apps/openmw/mwscript/globalscripts.cpp +++ b/apps/openmw/mwscript/globalscripts.cpp @@ -217,7 +217,7 @@ namespace MWScript } } - int GlobalScripts::countSavedGameRecords() const + size_t GlobalScripts::countSavedGameRecords() const { return mScripts.size(); } diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index 47c3f1ef6c..7013beddbe 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -76,7 +76,7 @@ namespace MWScript void addStartup(); ///< Add startup script - int countSavedGameRecords() const; + size_t countSavedGameRecords() const; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 1511909332..5eb59fcc8f 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -95,7 +95,7 @@ namespace if (stateset) { const osg::StateSet::TextureAttributeList& texAttributes = stateset->getTextureAttributeList(); - for (size_t i = 0; i < texAttributes.size(); i++) + for (unsigned i = 0; i < static_cast(texAttributes.size()); i++) { const osg::StateAttribute* attr = stateset->getTextureAttribute(i, osg::StateAttribute::TEXTURE); if (!attr) @@ -115,7 +115,7 @@ namespace } }; - void addToLevList(ESM::LevelledListBase* list, const ESM::RefId& itemId, int level) + void addToLevList(ESM::LevelledListBase* list, const ESM::RefId& itemId, uint16_t level) { for (auto& levelItem : list->mList) { @@ -1578,7 +1578,7 @@ namespace MWScript ESM::CreatureLevList listCopy = *MWBase::Environment::get().getESMStore()->get().find(levId); - addToLevList(&listCopy, creatureId, level); + addToLevList(&listCopy, creatureId, static_cast(level)); MWBase::Environment::get().getESMStore()->overrideRecord(listCopy); } }; @@ -1616,7 +1616,7 @@ namespace MWScript ESM::ItemLevList listCopy = *MWBase::Environment::get().getESMStore()->get().find(levId); - addToLevList(&listCopy, itemId, level); + addToLevList(&listCopy, itemId, static_cast(level)); MWBase::Environment::get().getESMStore()->overrideRecord(listCopy); } }; diff --git a/apps/openmw/mwsound/openaloutput.cpp b/apps/openmw/mwsound/openaloutput.cpp index 4b0e6ff72b..90668fe35a 100644 --- a/apps/openmw/mwsound/openaloutput.cpp +++ b/apps/openmw/mwsound/openaloutput.cpp @@ -311,7 +311,7 @@ namespace MWSound bool isPlaying(); double getStreamDelay() const; - double getStreamOffset() const; + float getStreamOffset() const; float getCurrentLoudness() const; @@ -469,7 +469,7 @@ namespace MWSound OpenAL_SoundStream::~OpenAL_SoundStream() { if (mBuffers[0] && alIsBuffer(mBuffers[0])) - alDeleteBuffers(mBuffers.size(), mBuffers.data()); + alDeleteBuffers(static_cast(mBuffers.size()), mBuffers.data()); alGetError(); mDecoder->close(); @@ -477,7 +477,7 @@ namespace MWSound bool OpenAL_SoundStream::init(bool getLoudnessData) { - alGenBuffers(mBuffers.size(), mBuffers.data()); + alGenBuffers(static_cast(mBuffers.size()), mBuffers.data()); ALenum err = getALError(); if (err != AL_NO_ERROR) return false; @@ -509,7 +509,7 @@ namespace MWSound break; } - mFrameSize = framesToBytes(1, chans, type); + mFrameSize = static_cast(framesToBytes(1, chans, type)); mBufferSize = static_cast(sBufferLength * mSampleRate); mBufferSize *= mFrameSize; @@ -552,11 +552,11 @@ namespace MWSound return d; } - double OpenAL_SoundStream::getStreamOffset() const + float OpenAL_SoundStream::getStreamOffset() const { ALint state = AL_STOPPED; ALint offset; - double t; + float t; alGetSourcei(mSource, AL_SAMPLE_OFFSET, &offset); alGetSourcei(mSource, AL_SOURCE_STATE, &state); @@ -565,13 +565,13 @@ namespace MWSound ALint queued; alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued); ALint inqueue = mBufferSize / mFrameSize * queued - offset; - t = (double)(mDecoder->getSampleOffset() - inqueue) / (double)mSampleRate; + t = (mDecoder->getSampleOffset() - inqueue) / static_cast(mSampleRate); } else { /* Underrun, or not started yet. The decoder offset is where we'll play * next. */ - t = (double)mDecoder->getSampleOffset() / (double)mSampleRate; + t = mDecoder->getSampleOffset() / static_cast(mSampleRate); } getALError(); @@ -642,7 +642,7 @@ namespace MWSound mLoudnessAnalyzer->analyzeLoudness(data); ALuint bufid = mBuffers[mCurrentBufIdx]; - alBufferData(bufid, mFormat, data.data(), data.size(), mSampleRate); + alBufferData(bufid, mFormat, data.data(), static_cast(data.size()), mSampleRate); alSourceQueueBuffers(mSource, 1, &bufid); mCurrentBufIdx = (mCurrentBufIdx + 1) % mBuffers.size(); } @@ -801,7 +801,7 @@ namespace MWSound if (alEventControlSOFT) { static const std::array events{ { AL_EVENT_TYPE_DISCONNECTED_SOFT } }; - alEventControlSOFT(events.size(), events.data(), AL_TRUE); + alEventControlSOFT(static_cast(events.size()), events.data(), AL_TRUE); alEventCallbackSOFT(&OpenALOutput::eventCallback, this); } else @@ -1065,7 +1065,7 @@ namespace MWSound ALint size; ALuint buf = 0; alGenBuffers(1, &buf); - alBufferData(buf, format, data.data(), data.size(), srate); + alBufferData(buf, format, data.data(), static_cast(data.size()), srate); alGetBufferi(buf, AL_SIZE, &size); if (getALError() != AL_NO_ERROR) { @@ -1412,10 +1412,10 @@ namespace MWSound return stream->getStreamDelay(); } - double OpenALOutput::getStreamOffset(Stream* sound) + float OpenALOutput::getStreamOffset(Stream* sound) { if (!sound->mHandle) - return 0.0; + return 0.f; OpenAL_SoundStream* stream = reinterpret_cast(sound->mHandle); std::lock_guard lock(mStreamThread->mMutex); return stream->getStreamOffset(); @@ -1523,7 +1523,7 @@ namespace MWSound } if (!sources.empty()) { - alSourcePausev(sources.size(), sources.data()); + alSourcePausev(static_cast(sources.size()), sources.data()); getALError(); } } @@ -1578,7 +1578,7 @@ namespace MWSound } if (!sources.empty()) { - alSourcePlayv(sources.size(), sources.data()); + alSourcePlayv(static_cast(sources.size()), sources.data()); getALError(); } } diff --git a/apps/openmw/mwsound/openaloutput.hpp b/apps/openmw/mwsound/openaloutput.hpp index d689d08546..107c3f4c61 100644 --- a/apps/openmw/mwsound/openaloutput.hpp +++ b/apps/openmw/mwsound/openaloutput.hpp @@ -101,7 +101,7 @@ namespace MWSound bool streamSound3D(DecoderPtr decoder, Stream* sound, bool getLoudnessData) override; void finishStream(Stream* sound) override; double getStreamDelay(Stream* sound) override; - double getStreamOffset(Stream* sound) override; + float getStreamOffset(Stream* sound) override; float getStreamLoudness(Stream* sound) override; bool isStreamPlaying(Stream* sound) override; void updateStream(Stream* sound) override; diff --git a/apps/openmw/mwsound/soundoutput.hpp b/apps/openmw/mwsound/soundoutput.hpp index 4b24f159d3..def95ac693 100644 --- a/apps/openmw/mwsound/soundoutput.hpp +++ b/apps/openmw/mwsound/soundoutput.hpp @@ -53,7 +53,7 @@ namespace MWSound virtual bool streamSound3D(DecoderPtr decoder, Stream* sound, bool getLoudnessData) = 0; virtual void finishStream(Stream* sound) = 0; virtual double getStreamDelay(Stream* sound) = 0; - virtual double getStreamOffset(Stream* sound) = 0; + virtual float getStreamOffset(Stream* sound) = 0; virtual float getStreamLoudness(Stream* sound) = 0; virtual bool isStreamPlaying(Stream* sound) = 0; virtual void updateStream(Stream* sound) = 0; diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 34aa3eaa46..3fb559c568 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -289,7 +289,7 @@ void MWState::StateManager::saveGame(std::string_view description, const Slot* s writer.setAuthor(""); writer.setDescription(""); - int recordCount = 1 // saved game header + size_t recordCount = 1 // saved game header + MWBase::Environment::get().getJournal()->countSavedGameRecords() + MWBase::Environment::get().getLuaManager()->countSavedGameRecords() + MWBase::Environment::get().getWorld()->countSavedGameRecords() @@ -298,7 +298,7 @@ void MWState::StateManager::saveGame(std::string_view description, const Slot* s + MWBase::Environment::get().getMechanicsManager()->countSavedGameRecords() + MWBase::Environment::get().getInputManager()->countSavedGameRecords() + MWBase::Environment::get().getWindowManager()->countSavedGameRecords(); - writer.setRecordCount(recordCount); + writer.setRecordCount(static_cast(recordCount)); writer.save(stream); @@ -325,7 +325,7 @@ void MWState::StateManager::saveGame(std::string_view description, const Slot* s MWBase::Environment::get().getWindowManager()->write(writer, listener); // Ensure we have written the number of records that was estimated - if (writer.getRecordCount() != recordCount + 1) // 1 extra for TES3 record + if (static_cast(writer.getRecordCount()) != recordCount + 1) // 1 extra for TES3 record Log(Debug::Warning) << "Warning: number of written savegame records does not match. Estimated: " << recordCount + 1 << ", written: " << writer.getRecordCount(); diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 5540982f26..8aa95878f6 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -402,7 +402,7 @@ namespace MWWorld mTerrainViews.resize(positions.size()); else if (mTerrainViews.size() < positions.size()) { - for (unsigned int i = mTerrainViews.size(); i < positions.size(); ++i) + for (size_t i = mTerrainViews.size(); i < positions.size(); ++i) mTerrainViews.emplace_back(mTerrain->createView()); } @@ -456,10 +456,10 @@ namespace MWWorld void CellPreloader::reportStats(unsigned int frameNumber, osg::Stats& stats) const { - stats.setAttribute(frameNumber, "CellPreloader Count", mPreloadCells.size()); - stats.setAttribute(frameNumber, "CellPreloader Added", mAdded); - stats.setAttribute(frameNumber, "CellPreloader Evicted", mEvicted); - stats.setAttribute(frameNumber, "CellPreloader Loaded", mLoaded); - stats.setAttribute(frameNumber, "CellPreloader Expired", mExpired); + stats.setAttribute(frameNumber, "CellPreloader Count", static_cast(mPreloadCells.size())); + stats.setAttribute(frameNumber, "CellPreloader Added", static_cast(mAdded)); + stats.setAttribute(frameNumber, "CellPreloader Evicted", static_cast(mEvicted)); + stats.setAttribute(frameNumber, "CellPreloader Loaded", static_cast(mLoaded)); + stats.setAttribute(frameNumber, "CellPreloader Expired", static_cast(mExpired)); } } diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index 854348c2a8..82270f3276 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -308,7 +308,7 @@ namespace MWWorld { mChanged = true; std::visit(ESM::VisitOverload{ - [&](ESM4::Reference& ref) { ref.mLockLevel = lockLevel; }, + [&](ESM4::Reference& ref) { ref.mLockLevel = static_cast(lockLevel); }, [&](ESM4::ActorCharacter&) {}, [&](ESM::CellRef& ref) { ref.mLockLevel = lockLevel; }, }, diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 91d30c91d1..773e4a80e8 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -681,7 +681,7 @@ namespace MWWorld } } - int ESMStore::countSavedGameRecords() const + size_t ESMStore::countSavedGameRecords() const { return 1 // DYNA (dynamic name counter) + get().getDynamicSize() + get().getDynamicSize() diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 56a8e57bcc..bab0fb81d1 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -286,7 +286,7 @@ namespace MWWorld void setUp(); void validateRecords(ESM::ReadersCache& readers); - int countSavedGameRecords() const; + size_t countSavedGameRecords() const; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const; diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index 4977df56c0..5e7888eab0 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -72,7 +72,7 @@ namespace MWWorld } } - int Globals::countSavedGameRecords() const + size_t Globals::countSavedGameRecords() const { return mVariables.size(); } diff --git a/apps/openmw/mwworld/globals.hpp b/apps/openmw/mwworld/globals.hpp index ab94f0f8dd..22c3e319ef 100644 --- a/apps/openmw/mwworld/globals.hpp +++ b/apps/openmw/mwworld/globals.hpp @@ -64,7 +64,7 @@ namespace MWWorld void fill(const MWWorld::ESMStore& store); ///< Replace variables with variables from \a store with default values. - int countSavedGameRecords() const; + size_t countSavedGameRecords() const; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const; diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index d7fd58c6c1..eb39d42bbb 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -64,7 +64,7 @@ void MWWorld::InventoryStore::readEquipmentState( if (index == inventory.mSelectedEnchantItem) mSelectedEnchantItem = iter; - auto found = inventory.mEquipmentSlots.find(index); + auto found = inventory.mEquipmentSlots.find(static_cast(index)); if (found != inventory.mEquipmentSlots.end()) { if (found->second < 0 || found->second >= MWWorld::InventoryStore::Slots) diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 9535d9987a..f4d7569fe9 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -144,8 +144,8 @@ namespace = MWBase::Environment::get().getESMStore()->get().find(enam.mData.mEffectID); lightDiffuseColor += magicEffect->getColor(); } - int numberOfEffects = effects.mList.size(); - lightDiffuseColor /= numberOfEffects; + size_t numberOfEffects = effects.mList.size(); + lightDiffuseColor /= static_cast(numberOfEffects); return lightDiffuseColor; } @@ -793,7 +793,7 @@ namespace MWWorld return false; } - int ProjectileManager::countSavedGameRecords() const + size_t ProjectileManager::countSavedGameRecords() const { return mMagicBolts.size() + mProjectiles.size(); } diff --git a/apps/openmw/mwworld/projectilemanager.hpp b/apps/openmw/mwworld/projectilemanager.hpp index 3003136ffc..432f463dbd 100644 --- a/apps/openmw/mwworld/projectilemanager.hpp +++ b/apps/openmw/mwworld/projectilemanager.hpp @@ -67,7 +67,7 @@ namespace MWWorld void write(ESM::ESMWriter& writer, Loading::Listener& progress) const; bool readRecord(ESM::ESMReader& reader, uint32_t type); - int countSavedGameRecords() const; + size_t countSavedGameRecords() const; private: osg::ref_ptr mParent; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 3bb76c5215..a7b9179839 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -460,8 +460,6 @@ namespace MWWorld if (const auto heightField = mPhysics->getHeightField(cellX, cellY)) { const osg::Vec2i cellPosition(cellX, cellY); - const btVector3& origin = heightField->getCollisionObject()->getWorldTransform().getOrigin(); - const osg::Vec3f shift(origin.x(), origin.y(), origin.z()); const HeightfieldShape shape = [&]() -> HeightfieldShape { if (data == nullptr) { @@ -562,7 +560,7 @@ namespace MWWorld const osg::Vec2f center = ESM::indexToPosition( ESM::ExteriorCellLocation(currentGridCenter->x(), currentGridCenter->y(), worldspace), true); float distance = std::max(std::abs(center.x() - pos.x()), std::abs(center.y() - pos.y())); - float cellSize = ESM::getCellSize(worldspace); + int cellSize = ESM::getCellSize(worldspace); const float maxDistance = cellSize / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold if (distance <= maxDistance) return *currentGridCenter; @@ -1226,7 +1224,7 @@ namespace MWWorld cellY = mCurrentGridCenter.y(); ESM::RefId extWorldspace = mWorld.getCurrentWorldspace(); - float cellSize = ESM::getCellSize(extWorldspace); + int cellSize = ESM::getCellSize(extWorldspace); for (int dx = -halfGridSizePlusOne; dx <= halfGridSizePlusOne; ++dx) { diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 12120b998d..a0405507ba 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -81,7 +81,7 @@ namespace MWWorld mStatic.insert_or_assign(idx, std::move(record)); } template - int IndexedStore::getSize() const + size_t IndexedStore::getSize() const { return mStatic.size(); } @@ -255,7 +255,7 @@ namespace MWWorld } template - int TypedDynamicStore::getDynamicSize() const + size_t TypedDynamicStore::getDynamicSize() const { return mDynamic.size(); } diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 5ce287c34e..ecb22c1d33 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -61,7 +61,7 @@ namespace MWWorld class DynamicStoreBase : public StoreBase { public: - virtual ~DynamicStoreBase() {} + virtual ~DynamicStoreBase() = default; virtual void setUp() {} @@ -70,7 +70,7 @@ namespace MWWorld virtual void listIdentifier(std::vector& list) const {} virtual size_t getSize() const = 0; - virtual int getDynamicSize() const { return 0; } + virtual size_t getDynamicSize() const { return 0; } virtual RecordId load(ESM::ESMReader& esm) = 0; virtual bool eraseStatic(const Id& id) { return false; } @@ -102,7 +102,7 @@ namespace MWWorld void load(ESM::ESMReader& esm); - int getSize() const; + size_t getSize() const; void setUp(); const T* search(int index) const; @@ -230,7 +230,7 @@ namespace MWWorld const T* at(size_t index) const { return mShared.at(index); } size_t getSize() const override; - int getDynamicSize() const override; + size_t getDynamicSize() const override; /// @note The record identifiers are listed in the order that the records were defined by the content files. void listIdentifier(std::vector& list) const override; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 60d63fe46b..45d3138ce0 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -175,7 +175,7 @@ namespace MWWorld , mIsStorm(mWindSpeed > stormWindSpeed) , mRainSpeed(rainSpeed) , mRainEntranceSpeed(Fallback::Map::getFloat("Weather_" + name + "_Rain_Entrance_Speed")) - , mRainMaxRaindrops(Fallback::Map::getFloat("Weather_" + name + "_Max_Raindrops")) + , mRainMaxRaindrops(Fallback::Map::getInt("Weather_" + name + "_Max_Raindrops")) , mRainDiameter(Fallback::Map::getFloat("Weather_" + name + "_Rain_Diameter")) , mRainThreshold(Fallback::Map::getFloat("Weather_" + name + "_Rain_Threshold")) , mRainMinHeight(Fallback::Map::getFloat("Weather_" + name + "_Rain_Height_Min")) @@ -709,7 +709,7 @@ namespace MWWorld auto rIt = mRegions.find(regionID); if (rIt != mRegions.end()) { - rIt->second.setWeather(std::distance(mWeatherSettings.begin(), wIt)); + rIt->second.setWeather(wIt->mScriptId); regionalWeatherChanged(rIt->first, rIt->second); } } @@ -981,7 +981,7 @@ namespace MWWorld { // In Morrowind, when the player sleeps/waits, serves jail time, travels, or trains, all weather transitions are // immediately applied, regardless of whatever transition time might have been remaining. - mTimePassed += hours; + mTimePassed += static_cast(hours); mFastForward = !incremental ? true : mFastForward; } @@ -1093,8 +1093,8 @@ namespace MWWorld { static const float fStromWindSpeed = mStore.get().find("fStromWindSpeed")->mValue.getFloat(); ESM::StringRefId id(name); - Weather weather( - id, mWeatherSettings.size(), name, fStromWindSpeed, mRainSpeed, dlFactor, dlOffset, particleEffect); + Weather weather(id, static_cast(mWeatherSettings.size()), name, fStromWindSpeed, mRainSpeed, dlFactor, + dlOffset, particleEffect); mWeatherSettings.push_back(std::move(weather)); } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 957ab98f24..59135a8b6e 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -442,7 +442,7 @@ namespace MWWorld fillGlobalVariables(); } - int World::countSavedGameRecords() const + size_t World::countSavedGameRecords() const { return mWorldModel.countSavedGameRecords() + mStore.countSavedGameRecords() + mGlobalVariables.countSavedGameRecords() + mProjectileManager->countSavedGameRecords() @@ -454,7 +454,7 @@ namespace MWWorld + 1; // random state. } - int World::countSavedGameCells() const + size_t World::countSavedGameCells() const { return mWorldModel.countSavedGameRecords(); } @@ -899,7 +899,7 @@ namespace MWWorld { // When we fast-forward time, we should recharge magic items // in all loaded cells, using game world time - float duration = hours * 3600; + float duration = static_cast(hours * 3600); const float timeScaleFactor = mTimeManager->getGameTimeScale(); if (timeScaleFactor != 0.0f) duration /= timeScaleFactor; @@ -1280,9 +1280,9 @@ namespace MWWorld * currently it's done so for rotating the camera, which needs * clamping. */ - objRot[0] = std::clamp(objRot[0], -osg::PI_2, osg::PI_2); - objRot[1] = Misc::normalizeAngle(objRot[1]); - objRot[2] = Misc::normalizeAngle(objRot[2]); + objRot[0] = std::clamp(objRot[0], -osg::PI_2f, osg::PI_2f); + objRot[1] = static_cast(Misc::normalizeAngle(objRot[1])); + objRot[2] = static_cast(Misc::normalizeAngle(objRot[2])); } ptr.getRefData().setPosition(pos); @@ -1335,8 +1335,8 @@ namespace MWWorld && !(ptr.getClass().isPersistent(ptr) && ptr.getClass().getCreatureStats(ptr).isDeathAnimationFinished()); if (force || !ptr.getClass().isActor() || (!isFlying(ptr) && !swims && isActorCollisionEnabled(ptr))) { - osg::Vec3f traced - = mPhysics->traceDown(ptr, pos, ESM::getCellSize(ptr.getCell()->getCell()->getWorldSpace())); + float height = static_cast(ESM::getCellSize(ptr.getCell()->getCell()->getWorldSpace())); + osg::Vec3f traced = mPhysics->traceDown(ptr, pos, height); pos.z() = std::min(pos.z(), traced.z()); } @@ -1372,8 +1372,8 @@ namespace MWWorld break; } targetPos.z() += distance / 2.f; // move up a bit to get out from geometry, will snap down later - osg::Vec3f traced - = mPhysics->traceDown(actor, targetPos, ESM::getCellSize(actor.getCell()->getCell()->getWorldSpace())); + float height = static_cast(ESM::getCellSize(actor.getCell()->getCell()->getWorldSpace())); + osg::Vec3f traced = mPhysics->traceDown(actor, targetPos, height); if (traced != pos) { esmPos.pos[0] = traced.x(); @@ -2379,7 +2379,7 @@ namespace MWWorld result |= Rest_PlayerIsUnderwater; float fallHeight = player.getClass().getCreatureStats(player).getFallHeight(); - float epsilon = 1e-4; + float epsilon = 1e-4f; if ((actor->getCollisionMode() && (!mPhysics->isOnSolidGround(player) || fallHeight >= epsilon)) || isFlying(player)) result |= Rest_PlayerIsInAir; @@ -3366,7 +3366,7 @@ namespace MWWorld mWorldModel.forEachLoadedCellStore([hours](CellStore& store) { store.rest(hours); }); } - void World::rechargeItems(double duration, bool activeOnly) + void World::rechargeItems(float duration, bool activeOnly) { MWWorld::Ptr player = getPlayerPtr(); player.getClass().getInventoryStore(player).rechargeItems(duration); @@ -3531,7 +3531,7 @@ namespace MWWorld float World::feetToGameUnits(float feet) { // Original engine rounds size upward - static const int unitsPerFoot = ceil(Constants::UnitsPerFoot); + static const float unitsPerFoot = std::ceil(Constants::UnitsPerFoot); return feet * unitsPerFoot; } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 4b99f3c687..82db3bb00c 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -214,8 +214,8 @@ namespace MWWorld void clear() override; - int countSavedGameRecords() const override; - int countSavedGameCells() const override; + size_t countSavedGameRecords() const override; + size_t countSavedGameCells() const override; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const override; @@ -516,7 +516,7 @@ namespace MWWorld ///< check if the player is allowed to rest void rest(double hours) override; - void rechargeItems(double duration, bool activeOnly); + void rechargeItems(float duration, bool activeOnly); /// \todo Probably shouldn't be here MWRender::Animation* getAnimation(const MWWorld::Ptr& ptr) override; diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 39ed27e96b..8d550b1855 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -449,7 +449,7 @@ std::vector MWWorld::WorldModel::getAll(const ESM::RefId& id) return result; } -int MWWorld::WorldModel::countSavedGameRecords() const +size_t MWWorld::WorldModel::countSavedGameRecords() const { return std::count_if(mCells.begin(), mCells.end(), [](const auto& v) { return v.second.hasState(); }); } diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index 0b555c4b9e..68d3c6d198 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -97,7 +97,7 @@ namespace MWWorld std::vector getAll(const ESM::RefId& id); - int countSavedGameRecords() const; + size_t countSavedGameRecords() const; void write(ESM::ESMWriter& writer, Loading::Listener& progress) const; diff --git a/components/fallback/validate.cpp b/components/fallback/validate.cpp index 571f0f9b19..6c289c873d 100644 --- a/components/fallback/validate.cpp +++ b/components/fallback/validate.cpp @@ -5,14 +5,18 @@ #include #include -static const std::set allowedKeysInt = { "LightAttenuation_LinearMethod", - "LightAttenuation_OutQuadInLin", "LightAttenuation_QuadraticMethod", "LightAttenuation_UseConstant", - "LightAttenuation_UseLinear", "LightAttenuation_UseQuadratic", "Water_MaxNumberRipples", "Water_NearWaterRadius", - "Water_NearWaterPoints", "Water_RippleFrameCount", "Water_SurfaceTileCount", "Water_SurfaceFrameCount", - "Weather_Clear_Using_Precip", "Weather_Cloudy_Using_Precip", "Weather_Foggy_Using_Precip", - "Weather_Overcast_Using_Precip", "Weather_Rain_Using_Precip", "Weather_Thunderstorm_Using_Precip", - "Weather_Ashstorm_Using_Precip", "Weather_Blight_Using_Precip", "Weather_Snow_Using_Precip", - "Weather_Blizzard_Using_Precip", "Weather_Rain_Ripples", "Weather_Snow_Ripples", "Weather_Timescale_Clouds" }; +static const std::set allowedKeysInt + = { "LightAttenuation_LinearMethod", "LightAttenuation_OutQuadInLin", "LightAttenuation_QuadraticMethod", + "LightAttenuation_UseConstant", "LightAttenuation_UseLinear", "LightAttenuation_UseQuadratic", + "Water_MaxNumberRipples", "Water_NearWaterRadius", "Water_NearWaterPoints", "Water_RippleFrameCount", + "Water_SurfaceTileCount", "Water_SurfaceFrameCount", "Weather_Ashstorm_Max_Raindrops", + "Weather_Blight_Max_Raindrops", "Weather_Blizzard_Max_Raindrops", "Weather_Clear_Max_Raindrops", + "Weather_Cloudy_Max_Raindrops", "Weather_Foggy_Max_Raindrops", "Weather_Overcast_Max_Raindrops", + "Weather_Rain_Max_Raindrops", "Weather_Snow_Max_Raindrops", "Weather_Thunderstorm_Max_Raindrops", + "Weather_Clear_Using_Precip", "Weather_Cloudy_Using_Precip", "Weather_Foggy_Using_Precip", + "Weather_Overcast_Using_Precip", "Weather_Rain_Using_Precip", "Weather_Thunderstorm_Using_Precip", + "Weather_Ashstorm_Using_Precip", "Weather_Blight_Using_Precip", "Weather_Snow_Using_Precip", + "Weather_Blizzard_Using_Precip", "Weather_Rain_Ripples", "Weather_Snow_Ripples", "Weather_Timescale_Clouds" }; static const std::set allowedKeysFloat = { "General_Werewolf_FOV", "Inventory_DirectionalAmbientB", "Inventory_DirectionalAmbientG", "Inventory_DirectionalAmbientR", "Inventory_DirectionalDiffuseB", @@ -32,34 +36,32 @@ static const std::set allowedKeysFloat = { "General_Werewolf_F "Weather_Ambient_Post-Sunrise_Time", "Weather_Ambient_Post-Sunset_Time", "Weather_Ambient_Pre-Sunrise_Time", "Weather_Ambient_Pre-Sunset_Time", "Weather_Ashstorm_Clouds_Maximum_Percent", "Weather_Ashstorm_Cloud_Speed", "Weather_Ashstorm_Flash_Decrement", "Weather_Ashstorm_Glare_View", "Weather_Ashstorm_Land_Fog_Day_Depth", - "Weather_Ashstorm_Land_Fog_Night_Depth", "Weather_Ashstorm_Max_Raindrops", "Weather_Ashstorm_Rain_Diameter", - "Weather_Ashstorm_Rain_Entrance_Speed", "Weather_Ashstorm_Rain_Height_Max", "Weather_Ashstorm_Rain_Height_Min", - "Weather_Ashstorm_Rain_Threshold", "Weather_Ashstorm_Thunder_Frequency", "Weather_Ashstorm_Thunder_Threshold", - "Weather_Ashstorm_Transition_Delta", "Weather_Ashstorm_Wind_Speed", "Weather_Blight_Clouds_Maximum_Percent", - "Weather_Blight_Cloud_Speed", "Weather_Blight_Flash_Decrement", "Weather_Blight_Glare_View", - "Weather_Blight_Land_Fog_Day_Depth", "Weather_Blight_Land_Fog_Night_Depth", "Weather_Blight_Max_Raindrops", - "Weather_Blight_Rain_Diameter", "Weather_Blight_Rain_Entrance_Speed", "Weather_Blight_Rain_Height_Max", - "Weather_Blight_Rain_Height_Min", "Weather_Blight_Rain_Threshold", "Weather_Blight_Thunder_Frequency", - "Weather_Blight_Thunder_Threshold", "Weather_Blight_Transition_Delta", "Weather_Blight_Wind_Speed", - "Weather_Blizzard_Clouds_Maximum_Percent", "Weather_Blizzard_Cloud_Speed", "Weather_Blizzard_Flash_Decrement", - "Weather_Blizzard_Glare_View", "Weather_Blizzard_Land_Fog_Day_Depth", "Weather_Blizzard_Land_Fog_Night_Depth", - "Weather_Blizzard_Max_Raindrops", "Weather_Blizzard_Rain_Diameter", "Weather_Blizzard_Rain_Entrance_Speed", + "Weather_Ashstorm_Land_Fog_Night_Depth", "Weather_Ashstorm_Rain_Diameter", "Weather_Ashstorm_Rain_Entrance_Speed", + "Weather_Ashstorm_Rain_Height_Max", "Weather_Ashstorm_Rain_Height_Min", "Weather_Ashstorm_Rain_Threshold", + "Weather_Ashstorm_Thunder_Frequency", "Weather_Ashstorm_Thunder_Threshold", "Weather_Ashstorm_Transition_Delta", + "Weather_Ashstorm_Wind_Speed", "Weather_Blight_Clouds_Maximum_Percent", "Weather_Blight_Cloud_Speed", + "Weather_Blight_Flash_Decrement", "Weather_Blight_Glare_View", "Weather_Blight_Land_Fog_Day_Depth", + "Weather_Blight_Land_Fog_Night_Depth", "Weather_Blight_Rain_Diameter", "Weather_Blight_Rain_Entrance_Speed", + "Weather_Blight_Rain_Height_Max", "Weather_Blight_Rain_Height_Min", "Weather_Blight_Rain_Threshold", + "Weather_Blight_Thunder_Frequency", "Weather_Blight_Thunder_Threshold", "Weather_Blight_Transition_Delta", + "Weather_Blight_Wind_Speed", "Weather_Blizzard_Clouds_Maximum_Percent", "Weather_Blizzard_Cloud_Speed", + "Weather_Blizzard_Flash_Decrement", "Weather_Blizzard_Glare_View", "Weather_Blizzard_Land_Fog_Day_Depth", + "Weather_Blizzard_Land_Fog_Night_Depth", "Weather_Blizzard_Rain_Diameter", "Weather_Blizzard_Rain_Entrance_Speed", "Weather_Blizzard_Rain_Height_Max", "Weather_Blizzard_Rain_Height_Min", "Weather_Blizzard_Rain_Threshold", "Weather_Blizzard_Thunder_Frequency", "Weather_Blizzard_Thunder_Threshold", "Weather_Blizzard_Transition_Delta", "Weather_Blizzard_Wind_Speed", "Weather_Clear_Clouds_Maximum_Percent", "Weather_Clear_Cloud_Speed", "Weather_Clear_Flash_Decrement", "Weather_Clear_Glare_View", "Weather_Clear_Land_Fog_Day_Depth", - "Weather_Clear_Land_Fog_Night_Depth", "Weather_Clear_Max_Raindrops", "Weather_Clear_Rain_Diameter", - "Weather_Clear_Rain_Entrance_Speed", "Weather_Clear_Rain_Height_Max", "Weather_Clear_Rain_Height_Min", - "Weather_Clear_Rain_Threshold", "Weather_Clear_Thunder_Frequency", "Weather_Clear_Thunder_Threshold", - "Weather_Clear_Transition_Delta", "Weather_Clear_Wind_Speed", "Weather_Cloudy_Clouds_Maximum_Percent", - "Weather_Cloudy_Cloud_Speed", "Weather_Cloudy_Flash_Decrement", "Weather_Cloudy_Glare_View", - "Weather_Cloudy_Land_Fog_Day_Depth", "Weather_Cloudy_Land_Fog_Night_Depth", "Weather_Cloudy_Max_Raindrops", - "Weather_Cloudy_Rain_Diameter", "Weather_Cloudy_Rain_Entrance_Speed", "Weather_Cloudy_Rain_Height_Max", - "Weather_Cloudy_Rain_Height_Min", "Weather_Cloudy_Rain_Threshold", "Weather_Cloudy_Thunder_Frequency", - "Weather_Cloudy_Thunder_Threshold", "Weather_Cloudy_Transition_Delta", "Weather_Cloudy_Wind_Speed", - "Weather_Foggy_Clouds_Maximum_Percent", "Weather_Foggy_Cloud_Speed", "Weather_Foggy_Flash_Decrement", - "Weather_Foggy_Glare_View", "Weather_Foggy_Land_Fog_Day_Depth", "Weather_Foggy_Land_Fog_Night_Depth", - "Weather_Foggy_Max_Raindrops", "Weather_Foggy_Rain_Diameter", "Weather_Foggy_Rain_Entrance_Speed", + "Weather_Clear_Land_Fog_Night_Depth", "Weather_Clear_Rain_Diameter", "Weather_Clear_Rain_Entrance_Speed", + "Weather_Clear_Rain_Height_Max", "Weather_Clear_Rain_Height_Min", "Weather_Clear_Rain_Threshold", + "Weather_Clear_Thunder_Frequency", "Weather_Clear_Thunder_Threshold", "Weather_Clear_Transition_Delta", + "Weather_Clear_Wind_Speed", "Weather_Cloudy_Clouds_Maximum_Percent", "Weather_Cloudy_Cloud_Speed", + "Weather_Cloudy_Flash_Decrement", "Weather_Cloudy_Glare_View", "Weather_Cloudy_Land_Fog_Day_Depth", + "Weather_Cloudy_Land_Fog_Night_Depth", "Weather_Cloudy_Rain_Diameter", "Weather_Cloudy_Rain_Entrance_Speed", + "Weather_Cloudy_Rain_Height_Max", "Weather_Cloudy_Rain_Height_Min", "Weather_Cloudy_Rain_Threshold", + "Weather_Cloudy_Thunder_Frequency", "Weather_Cloudy_Thunder_Threshold", "Weather_Cloudy_Transition_Delta", + "Weather_Cloudy_Wind_Speed", "Weather_Foggy_Clouds_Maximum_Percent", "Weather_Foggy_Cloud_Speed", + "Weather_Foggy_Flash_Decrement", "Weather_Foggy_Glare_View", "Weather_Foggy_Land_Fog_Day_Depth", + "Weather_Foggy_Land_Fog_Night_Depth", "Weather_Foggy_Rain_Diameter", "Weather_Foggy_Rain_Entrance_Speed", "Weather_Foggy_Rain_Height_Max", "Weather_Foggy_Rain_Height_Min", "Weather_Foggy_Rain_Threshold", "Weather_Foggy_Thunder_Frequency", "Weather_Foggy_Thunder_Threshold", "Weather_Foggy_Transition_Delta", "Weather_Foggy_Wind_Speed", "Weather_Fog_Post-Sunrise_Time", "Weather_Fog_Post-Sunset_Time", @@ -67,19 +69,18 @@ static const std::set allowedKeysFloat = { "General_Werewolf_F "Weather_Maximum_Time_Between_Environmental_Sounds", "Weather_Minimum_Time_Between_Environmental_Sounds", "Weather_Overcast_Clouds_Maximum_Percent", "Weather_Overcast_Cloud_Speed", "Weather_Overcast_Flash_Decrement", "Weather_Overcast_Glare_View", "Weather_Overcast_Land_Fog_Day_Depth", "Weather_Overcast_Land_Fog_Night_Depth", - "Weather_Overcast_Max_Raindrops", "Weather_Overcast_Rain_Diameter", "Weather_Overcast_Rain_Entrance_Speed", - "Weather_Overcast_Rain_Height_Max", "Weather_Overcast_Rain_Height_Min", "Weather_Overcast_Rain_Threshold", - "Weather_Overcast_Thunder_Frequency", "Weather_Overcast_Thunder_Threshold", "Weather_Overcast_Transition_Delta", - "Weather_Overcast_Wind_Speed", "Weather_Precip_Gravity", "Weather_Rain_Clouds_Maximum_Percent", - "Weather_Rain_Cloud_Speed", "Weather_Rain_Flash_Decrement", "Weather_Rain_Glare_View", - "Weather_Rain_Land_Fog_Day_Depth", "Weather_Rain_Land_Fog_Night_Depth", "Weather_Rain_Max_Raindrops", - "Weather_Rain_Rain_Diameter", "Weather_Rain_Rain_Entrance_Speed", "Weather_Rain_Rain_Height_Max", - "Weather_Rain_Rain_Height_Min", "Weather_Rain_Rain_Threshold", "Weather_Rain_Thunder_Frequency", - "Weather_Rain_Thunder_Threshold", "Weather_Rain_Transition_Delta", "Weather_Rain_Wind_Speed", - "Weather_Sky_Post-Sunrise_Time", "Weather_Sky_Post-Sunset_Time", "Weather_Sky_Pre-Sunrise_Time", - "Weather_Sky_Pre-Sunset_Time", "Weather_Snow_Clouds_Maximum_Percent", "Weather_Snow_Cloud_Speed", - "Weather_Snow_Flash_Decrement", "Weather_Snow_Glare_View", "Weather_Snow_Land_Fog_Day_Depth", - "Weather_Snow_Land_Fog_Night_Depth", "Weather_Snow_Max_Raindrops", "Weather_Snow_Rain_Diameter", + "Weather_Overcast_Rain_Diameter", "Weather_Overcast_Rain_Entrance_Speed", "Weather_Overcast_Rain_Height_Max", + "Weather_Overcast_Rain_Height_Min", "Weather_Overcast_Rain_Threshold", "Weather_Overcast_Thunder_Frequency", + "Weather_Overcast_Thunder_Threshold", "Weather_Overcast_Transition_Delta", "Weather_Overcast_Wind_Speed", + "Weather_Precip_Gravity", "Weather_Rain_Clouds_Maximum_Percent", "Weather_Rain_Cloud_Speed", + "Weather_Rain_Flash_Decrement", "Weather_Rain_Glare_View", "Weather_Rain_Land_Fog_Day_Depth", + "Weather_Rain_Land_Fog_Night_Depth", "Weather_Rain_Rain_Diameter", "Weather_Rain_Rain_Entrance_Speed", + "Weather_Rain_Rain_Height_Max", "Weather_Rain_Rain_Height_Min", "Weather_Rain_Rain_Threshold", + "Weather_Rain_Thunder_Frequency", "Weather_Rain_Thunder_Threshold", "Weather_Rain_Transition_Delta", + "Weather_Rain_Wind_Speed", "Weather_Sky_Post-Sunrise_Time", "Weather_Sky_Post-Sunset_Time", + "Weather_Sky_Pre-Sunrise_Time", "Weather_Sky_Pre-Sunset_Time", "Weather_Snow_Clouds_Maximum_Percent", + "Weather_Snow_Cloud_Speed", "Weather_Snow_Flash_Decrement", "Weather_Snow_Glare_View", + "Weather_Snow_Land_Fog_Day_Depth", "Weather_Snow_Land_Fog_Night_Depth", "Weather_Snow_Rain_Diameter", "Weather_Snow_Rain_Entrance_Speed", "Weather_Snow_Rain_Height_Max", "Weather_Snow_Rain_Height_Min", "Weather_Snow_Rain_Threshold", "Weather_Snow_Thunder_Frequency", "Weather_Snow_Thunder_Threshold", "Weather_Snow_Transition_Delta", "Weather_Snow_Wind_Speed", "Weather_Stars_Fading_Duration", @@ -89,11 +90,11 @@ static const std::set allowedKeysFloat = { "General_Werewolf_F "Weather_Sunset_Duration", "Weather_Sunset_Time", "Weather_Thunderstorm_Clouds_Maximum_Percent", "Weather_Thunderstorm_Cloud_Speed", "Weather_Thunderstorm_Flash_Decrement", "Weather_Thunderstorm_Glare_View", "Weather_Thunderstorm_Land_Fog_Day_Depth", "Weather_Thunderstorm_Land_Fog_Night_Depth", - "Weather_Thunderstorm_Max_Raindrops", "Weather_Thunderstorm_Rain_Diameter", - "Weather_Thunderstorm_Rain_Entrance_Speed", "Weather_Thunderstorm_Rain_Height_Max", - "Weather_Thunderstorm_Rain_Height_Min", "Weather_Thunderstorm_Rain_Threshold", - "Weather_Thunderstorm_Thunder_Frequency", "Weather_Thunderstorm_Thunder_Threshold", - "Weather_Thunderstorm_Transition_Delta", "Weather_Thunderstorm_Wind_Speed" }; + "Weather_Thunderstorm_Rain_Diameter", "Weather_Thunderstorm_Rain_Entrance_Speed", + "Weather_Thunderstorm_Rain_Height_Max", "Weather_Thunderstorm_Rain_Height_Min", + "Weather_Thunderstorm_Rain_Threshold", "Weather_Thunderstorm_Thunder_Frequency", + "Weather_Thunderstorm_Thunder_Threshold", "Weather_Thunderstorm_Transition_Delta", + "Weather_Thunderstorm_Wind_Speed" }; static const std::set allowedKeysNonNumeric = { "Blood_Model_0", "Blood_Model_1", "Blood_Model_2", "FontColor_color_active", "FontColor_color_active_over", "FontColor_color_active_pressed", "FontColor_color_answer", diff --git a/components/lua/configuration.hpp b/components/lua/configuration.hpp index 4a619019ba..caa8f27c6f 100644 --- a/components/lua/configuration.hpp +++ b/components/lua/configuration.hpp @@ -18,7 +18,7 @@ namespace LuaUtil void init(ESM::LuaScriptsCfg); size_t size() const { return mScripts.size(); } - const ESM::LuaScriptCfg& operator[](int id) const { return mScripts[id]; } + const ESM::LuaScriptCfg& operator[](size_t id) const { return mScripts[id]; } std::optional findId(VFS::Path::NormalizedView path) const; diff --git a/components/misc/budgetmeasurement.hpp b/components/misc/budgetmeasurement.hpp index 647ab3e61a..f5ea7dff8b 100644 --- a/components/misc/budgetmeasurement.hpp +++ b/components/misc/budgetmeasurement.hpp @@ -13,25 +13,25 @@ namespace Misc std::array mBudgetStepCount; public: - BudgetMeasurement(const float default_expense) + BudgetMeasurement(const float defaultExpense) { - mBudgetHistory = { default_expense, default_expense, default_expense, default_expense }; + mBudgetHistory = { defaultExpense, defaultExpense, defaultExpense, defaultExpense }; mBudgetStepCount = { 1, 1, 1, 1 }; } - void reset(const float default_expense) + void reset(const float defaultExpense) { - mBudgetHistory = { default_expense, default_expense, default_expense, default_expense }; + mBudgetHistory = { defaultExpense, defaultExpense, defaultExpense, defaultExpense }; mBudgetStepCount = { 1, 1, 1, 1 }; } void update(double delta, unsigned int stepCount, size_t cursor) { - mBudgetHistory[cursor % 4] = delta; + mBudgetHistory[cursor % 4] = static_cast(delta); mBudgetStepCount[cursor % 4] = stepCount; } - double get() const + float get() const { float sum = (mBudgetHistory[0] + mBudgetHistory[1] + mBudgetHistory[2] + mBudgetHistory[3]); unsigned int stepCountSum diff --git a/components/misc/rng.cpp b/components/misc/rng.cpp index 8da61b12a2..639ec19f5f 100644 --- a/components/misc/rng.cpp +++ b/components/misc/rng.cpp @@ -41,41 +41,16 @@ namespace Misc::Rng sGenerator.seed(seed); } - float rollProbability() - { - return std::uniform_real_distribution(0, 1 - std::numeric_limits::epsilon())(getGenerator()); - } - float rollProbability(Generator& prng) { return std::uniform_real_distribution(0, 1 - std::numeric_limits::epsilon())(prng); } - float rollClosedProbability() - { - return std::uniform_real_distribution(0, 1)(getGenerator()); - } - float rollClosedProbability(Generator& prng) { return std::uniform_real_distribution(0, 1)(prng); } - int rollDice(int max) - { - return max > 0 ? std::uniform_int_distribution(0, max - 1)(getGenerator()) : 0; - } - - int rollDice(int max, Generator& prng) - { - return max > 0 ? std::uniform_int_distribution(0, max - 1)(prng) : 0; - } - - float deviate(float mean, float deviation) - { - return std::uniform_real_distribution(mean - deviation, mean + deviation)(getGenerator()); - } - float deviate(float mean, float deviation, Generator& prng) { return std::uniform_real_distribution(mean - deviation, mean + deviation)(prng); diff --git a/components/misc/rng.hpp b/components/misc/rng.hpp index 9dd5a0da99..72f374cc35 100644 --- a/components/misc/rng.hpp +++ b/components/misc/rng.hpp @@ -2,6 +2,7 @@ #define OPENMW_COMPONENTS_MISC_RNG_H #include +#include #include #include @@ -25,29 +26,25 @@ namespace Misc::Rng void init(unsigned int seed = generateDefaultSeed()); /// return value in range [0.0f, 1.0f) <- note open upper range. - float rollProbability(); - float rollProbability(Generator& prng); + float rollProbability(Generator& prng = getGenerator()); /// return value in range [0.0f, 1.0f] <- note closed upper range. - float rollClosedProbability(); - float rollClosedProbability(Generator& prng); + float rollClosedProbability(Generator& prng = getGenerator()); /// return value in range [0, max) <- note open upper range. - int rollDice(int max); - int rollDice(int max, Generator& prng); + template + inline T rollDice(T max, Generator& prng = getGenerator()) + { + return max > 0 ? std::uniform_int_distribution(0, max - 1)(prng) : 0; + } /// return value in range [0, 99] - inline int roll0to99(Generator& prng) + inline int roll0to99(Generator& prng = getGenerator()) { return rollDice(100, prng); } - inline int roll0to99() - { - return rollDice(100); - } - float deviate(float mean, float deviation); - float deviate(float mean, float deviation, Generator& prng); + float deviate(float mean, float deviation, Generator& prng = getGenerator()); } #endif diff --git a/components/settings/categories/stereoview.hpp b/components/settings/categories/stereoview.hpp index 7f08d9bc35..0c3c74846c 100644 --- a/components/settings/categories/stereoview.hpp +++ b/components/settings/categories/stereoview.hpp @@ -20,9 +20,9 @@ namespace Settings SettingValue mEyeResolutionX{ mIndex, "Stereo View", "eye resolution x", makeMaxSanitizerInt(1) }; SettingValue mEyeResolutionY{ mIndex, "Stereo View", "eye resolution y", makeMaxSanitizerInt(1) }; - SettingValue mLeftEyeOffsetX{ mIndex, "Stereo View", "left eye offset x" }; - SettingValue mLeftEyeOffsetY{ mIndex, "Stereo View", "left eye offset y" }; - SettingValue mLeftEyeOffsetZ{ mIndex, "Stereo View", "left eye offset z" }; + SettingValue mLeftEyeOffsetX{ mIndex, "Stereo View", "left eye offset x" }; + SettingValue mLeftEyeOffsetY{ mIndex, "Stereo View", "left eye offset y" }; + SettingValue mLeftEyeOffsetZ{ mIndex, "Stereo View", "left eye offset z" }; SettingValue mLeftEyeOrientationX{ mIndex, "Stereo View", "left eye orientation x", makeClampSanitizerDouble(-1, 1) }; SettingValue mLeftEyeOrientationY{ mIndex, "Stereo View", "left eye orientation y", @@ -39,9 +39,9 @@ namespace Settings makeClampSanitizerFloat(-osg::PIf, osg::PIf) }; SettingValue mLeftEyeFovDown{ mIndex, "Stereo View", "left eye fov down", makeClampSanitizerFloat(-osg::PIf, osg::PIf) }; - SettingValue mRightEyeOffsetX{ mIndex, "Stereo View", "right eye offset x" }; - SettingValue mRightEyeOffsetY{ mIndex, "Stereo View", "right eye offset y" }; - SettingValue mRightEyeOffsetZ{ mIndex, "Stereo View", "right eye offset z" }; + SettingValue mRightEyeOffsetX{ mIndex, "Stereo View", "right eye offset x" }; + SettingValue mRightEyeOffsetY{ mIndex, "Stereo View", "right eye offset y" }; + SettingValue mRightEyeOffsetZ{ mIndex, "Stereo View", "right eye offset z" }; SettingValue mRightEyeOrientationX{ mIndex, "Stereo View", "right eye orientation x", makeClampSanitizerDouble(-1, 1) }; SettingValue mRightEyeOrientationY{ mIndex, "Stereo View", "right eye orientation y",