From 90f3ff2da4b37a6766e0eb369150d866ec488d06 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 12 Apr 2018 18:18:17 +0300 Subject: [PATCH 1/3] Don't force DDS file usage (fixes #1392) Fallback to a DDS file if the requested texture path doesn't point to an existing file, not vice versa --- components/misc/resourcehelpers.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 5cf4378b8..f38387ff8 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -63,28 +63,16 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev std::string origExt = correctedPath; - // since we know all (GOTY edition or less) textures end - // in .dds, we change the extension - bool changedToDds = changeExtensionToDds(correctedPath); - if (vfs->exists(correctedPath)) + if (vfs->exists(origExt) + || (changeExtensionToDds(correctedPath) && vfs->exists(correctedPath))) return correctedPath; - // if it turns out that the above wasn't true in all cases (not for vanilla, but maybe mods) - // verify, and revert if false (this call succeeds quickly, but fails slowly) - if (changedToDds && vfs->exists(origExt)) - return origExt; // fall back to a resource in the top level directory if it exists - std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath); - if (vfs->exists(fallback)) + std::string fallback = topLevelDirectory + "\\" + getBasename(origExt); + if (vfs->exists(fallback) + || (changeExtensionToDds(fallback) && vfs->exists(fallback))) return fallback; - if (changedToDds) - { - fallback = topLevelDirectory + "\\" + getBasename(origExt); - if (vfs->exists(fallback)) - return fallback; - } - return correctedPath; } From 8617d0603b9d8b0fe4ce89cdee593bb032505230 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Wed, 18 Apr 2018 18:25:53 +0300 Subject: [PATCH 2/3] Display a message if a spell the player tries to use via a quick key is missing (fixes #4391) --- apps/openmw/mwgui/quickkeysmenu.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 6da7b0905..2ce9d04e5 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -330,7 +330,12 @@ namespace MWGui MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); if (!spells.hasSpell(spellId)) + { + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); + MWBase::Environment::get().getWindowManager()->messageBox ( + "#{sQuickMenu5} " + spell->mName); return; + } store.setSelectedEnchantItem(store.end()); MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player))); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell); From 48467814d4745cfe27835bd59cd1be6a98f29d58 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sun, 8 Apr 2018 23:10:14 +0300 Subject: [PATCH 3/3] Improve random number generation --- components/misc/rng.cpp | 15 +++++++++------ components/misc/rng.hpp | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/components/misc/rng.cpp b/components/misc/rng.cpp index df0fc687e..dfe0eff40 100644 --- a/components/misc/rng.cpp +++ b/components/misc/rng.cpp @@ -1,28 +1,31 @@ #include "rng.hpp" -#include -#include + +#include +#include namespace Misc { + std::mt19937 Rng::generator = std::mt19937(); + void Rng::init() { - std::srand(static_cast(std::time(NULL))); + generator.seed(static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count())); } float Rng::rollProbability() { - return static_cast(std::rand() / (static_cast(RAND_MAX)+1.0)); + return std::uniform_real_distribution(0, 1 - std::numeric_limits::epsilon())(generator); } float Rng::rollClosedProbability() { - return static_cast(std::rand() / static_cast(RAND_MAX)); + return std::uniform_real_distribution(0, 1)(generator); } int Rng::rollDice(int max) { - return static_cast((std::rand() / (static_cast(RAND_MAX)+1.0)) * (max)); + return std::uniform_int_distribution(0, max - 1)(generator); } } diff --git a/components/misc/rng.hpp b/components/misc/rng.hpp index 01fcdd763..ff56906d9 100644 --- a/components/misc/rng.hpp +++ b/components/misc/rng.hpp @@ -2,6 +2,7 @@ #define OPENMW_COMPONENTS_MISC_RNG_H #include +#include namespace Misc { @@ -13,6 +14,9 @@ class Rng { public: + /// create a RNG + static std::mt19937 generator; + /// seed the RNG static void init();