Skip to content

Commit

Permalink
Version 2.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ersh1 committed May 31, 2024
1 parent a5acc9a commit 6b1fc1e
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22)

project(
OpenAnimationReplacer
VERSION 2.3.3
VERSION 2.3.4
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"windows"
],
"name": "vs2022-windows",
"toolset": "v143,version=14.38"
"toolset": "v143"
}
],
"version": 3
Expand Down
9 changes: 5 additions & 4 deletions src/ActiveClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ void ActiveClip::ReplaceActiveAnimation(RE::hkbClipGenerator* a_clipGenerator, c

if (startTime != 0.f) {
a_clipGenerator->animationControl->localTime = startTime;
a_clipGenerator->localTime = startTime;
}
}

Expand Down Expand Up @@ -251,7 +252,7 @@ void ActiveClip::PreUpdate(RE::hkbClipGenerator* a_clipGenerator, const RE::hkbC
// do not try to replace with other variants here
Variant* dummy = nullptr;
if (ShouldReplaceAnimation(newReplacementAnim, false, dummy)) {
float blendTime = HasReplacementAnimation() ? GetReplacementAnimation()->GetCustomBlendTime(CustomBlendType::kInterrupt, false) : Settings::fDefaultBlendTimeOnInterrupt;
float blendTime = HasReplacementAnimation() ? GetReplacementAnimation()->GetCustomBlendTime(this, CustomBlendType::kInterrupt, false) : Settings::fDefaultBlendTimeOnInterrupt;
if (a_clipGenerator->animationControl->playbackSpeed > 0.f) {
blendTime /= a_clipGenerator->animationControl->playbackSpeed;
}
Expand All @@ -270,7 +271,7 @@ void ActiveClip::PreUpdate(RE::hkbClipGenerator* a_clipGenerator, const RE::hkbC
bool newAtEnd = false;
float blendTime = Settings::fDefaultBlendTimeOnLoop;
if (HasReplacementAnimation()) {
blendTime = GetReplacementAnimation()->GetCustomBlendTime(CustomBlendType::kLoop, true);
blendTime = GetReplacementAnimation()->GetCustomBlendTime(this, CustomBlendType::kLoop, true);
}

if (hkbClipGenerator_GetAnimDuration(a_clipGenerator) <= blendTime) {
Expand Down Expand Up @@ -499,7 +500,7 @@ bool ActiveClip::OnLoopOrEcho(RE::hkbClipGenerator* a_clipGenerator, bool a_bIsE
// don't run the entire logic - we don't want to replace this with another animation, just replace with the next variant of the same animation
Variant* variant = nullptr;
[[maybe_unused]] const uint16_t newVariantIndex = _currentReplacementAnimation->GetIndex(this, variant);
float blendTime = GetReplacementAnimation()->GetCustomBlendTime(a_bIsEcho ? CustomBlendType::kEcho : CustomBlendType::kLoop, true);
float blendTime = GetReplacementAnimation()->GetCustomBlendTime(this, a_bIsEcho ? CustomBlendType::kEcho : CustomBlendType::kLoop, true);
if (a_clipGenerator->animationControl->playbackSpeed > 0.f) {
blendTime /= a_clipGenerator->animationControl->playbackSpeed;
}
Expand All @@ -516,7 +517,7 @@ bool ActiveClip::OnLoopOrEcho(RE::hkbClipGenerator* a_clipGenerator, bool a_bIsE
Variant* variant = nullptr;
if (ShouldReplaceAnimation(newReplacementAnim, bHasVariants, variant)) {
const bool bBetweenVariants = newReplacementAnim == _currentReplacementAnimation;
float blendTime = HasReplacementAnimation() ? GetReplacementAnimation()->GetCustomBlendTime(a_bIsEcho ? CustomBlendType::kEcho : CustomBlendType::kLoop, bBetweenVariants) : (a_bIsEcho ? a_echoDuration : Settings::fDefaultBlendTimeOnLoop);
float blendTime = HasReplacementAnimation() ? GetReplacementAnimation()->GetCustomBlendTime(this, a_bIsEcho ? CustomBlendType::kEcho : CustomBlendType::kLoop, bBetweenVariants) : (a_bIsEcho ? a_echoDuration : Settings::fDefaultBlendTimeOnLoop);
if (a_clipGenerator->animationControl->playbackSpeed > 0.f) {
blendTime /= a_clipGenerator->animationControl->playbackSpeed;
}
Expand Down
4 changes: 2 additions & 2 deletions src/FakeClipGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ void FakeClipGenerator::Activate(const RE::hkbContext& a_context)
}

// create new animation control
auto animControl = static_cast<RE::hkaDefaultAnimationControl*>(hkHeapAlloc(sizeof(RE::hkaDefaultAnimationControl)));
/*auto animControl = static_cast<RE::hkaDefaultAnimationControl*>(hkHeapAlloc(sizeof(RE::hkaDefaultAnimationControl)));
RE::hkRefPtr animControlPtr(animControl);
hkaDefaultAnimationControl_ctor(animControl, binding, true, 2);
animationControl = animControlPtr;
animationControl = animControlPtr;*/
}

void FakeClipGenerator::Update(const RE::hkbContext& a_context, float a_deltaTime)
Expand Down
8 changes: 4 additions & 4 deletions src/OpenAnimationReplacer.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ class OpenAnimationReplacer : public IStateDataContainerHolder

ExclusiveLock _factoriesLock;
bool _bFactoriesInitialized = false;
std::map<std::string, std::function<std::unique_ptr<Conditions::ICondition>()>> _conditionFactories;
std::map<std::string, std::function<std::unique_ptr<Conditions::ICondition>()>> _hiddenConditionFactories;
std::map<std::string, std::function<std::unique_ptr<Conditions::ICondition>()>, CaseInsensitiveCompare> _conditionFactories;
std::map<std::string, std::function<std::unique_ptr<Conditions::ICondition>()>, CaseInsensitiveCompare> _hiddenConditionFactories;

mutable SharedLock _customConditionsLock;
std::unordered_map<std::string, REL::Version> _customConditionPlugins;
std::unordered_map<std::string, Conditions::ConditionFactory> _customConditionFactories;
std::unordered_map<std::string, REL::Version, CaseInsensitiveHash, CaseInsensitiveEqual> _customConditionPlugins;
std::unordered_map<std::string, Conditions::ConditionFactory, CaseInsensitiveHash, CaseInsensitiveEqual> _customConditionFactories;

mutable SharedLock _jobsLock;
std::vector<std::unique_ptr<Jobs::GenericJob>> _jobs;
Expand Down
34 changes: 34 additions & 0 deletions src/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@ struct KeyHash<std::string>
}
};

struct CaseInsensitiveHash
{
size_t operator()(const std::string& a_key) const
{
std::string lowerStr = a_key;
std::ranges::transform(lowerStr, lowerStr.begin(), [](char c) {
return static_cast<char>(std::tolower(c));
});
return std::hash<std::string>()(lowerStr);
}
};

struct CaseInsensitiveEqual
{
bool operator()(const std::string& a, const std::string& b) const
{
return std::equal(a.begin(), a.end(), b.begin(), b.end(),
[](char a, char b) {
return std::tolower(a) == std::tolower(b);
});
}
};

struct CaseInsensitiveCompare
{
bool operator()(const std::string& a, const std::string& b) const
{
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(),
[](char a, char b) {
return std::tolower(a) < std::tolower(b);
});
}
};

// Case-insensitive hash function for std::filesystem::path
struct CaseInsensitivePathHash
{
Expand Down
29 changes: 10 additions & 19 deletions src/ReplacementAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,19 @@ bool ReplacementAnimation::GetReplaceOnEcho() const
return _parentSubMod->IsReevaluatingOnEcho();
}

bool ReplacementAnimation::HasCustomBlendTime(CustomBlendType a_type, bool a_bBetweenVariants) const
float ReplacementAnimation::GetCustomBlendTime(ActiveClip* a_activeClip, CustomBlendType a_type, bool a_bBetweenVariants) const
{
if (a_bBetweenVariants) {
if (a_bBetweenVariants && a_activeClip) {
if (a_type != CustomBlendType::kInterrupt) {
if (HasVariants()) {
if (!GetVariants().ShouldBlendBetweenVariants()) {
return true;
}
}
}
}

return _parentSubMod->HasCustomBlendTime(a_type);
}

float ReplacementAnimation::GetCustomBlendTime(CustomBlendType a_type, bool a_bBetweenVariants) const
{
if (a_bBetweenVariants) {
if (a_type != CustomBlendType::kInterrupt) {
if (HasVariants()) {
if (!GetVariants().ShouldBlendBetweenVariants()) {
return 0.f;
// figure out if we're in the middle of a variant sequence
const auto& variants = GetVariants();
if (!variants.ShouldBlendBetweenVariants()) {
if (const auto stateData = variants.GetVariantStateData(a_activeClip)) {
if (!stateData->IsAtBeginningOfSequence(a_activeClip->GetClipGenerator(), &variants)) {
return 0.f;
}
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ReplacementAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class ReplacementAnimation
bool GetInterruptible() const;
bool GetReplaceOnLoop() const;
bool GetReplaceOnEcho() const;
bool HasCustomBlendTime(CustomBlendType a_type, bool a_bBetweenVariants = false) const;
float GetCustomBlendTime(CustomBlendType a_type, bool a_bBetweenVariants = false) const;
float GetCustomBlendTime(ActiveClip* a_activeClip, CustomBlendType a_type, bool a_bBetweenVariants = false) const;
void SetDisabled(bool a_bDisable) { _bDisabled = a_bDisable; }
std::string_view GetAnimPath() const { return _path; }
std::string_view GetProjectName() const { return _projectName; }
Expand Down
20 changes: 10 additions & 10 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ struct Settings
static inline bool bEnableDebugDraws = false;

// Internal
static inline float fDefaultBlendTimeOnInterrupt = 0.3f;
static inline float fDefaultBlendTimeOnLoop = 0.3f;
static inline float fDefaultBlendTimeOnEcho = 0.1f;
static inline float fStateDataLifetime = 0.5f;
static inline float fSequentialVariantLifetime = 0.5f;
static inline float fQueueFadeTime = 1.f;
static inline uint32_t uQueueMinSize = 10;
static inline float fAnimationLogEntryFadeTime = 0.5f;
static inline float fAnimationEventLogEntryColorTimeLong = 1.f;
static inline float fWelcomeBannerFadeTime = 1.f;
constexpr static inline float fDefaultBlendTimeOnInterrupt = 0.3f;
constexpr static inline float fDefaultBlendTimeOnLoop = 0.3f;
constexpr static inline float fDefaultBlendTimeOnEcho = 0.1f;
constexpr static inline float fStateDataLifetime = 0.5f;
constexpr static inline float fSequentialVariantLifetime = 0.5f;
constexpr static inline float fQueueFadeTime = 1.f;
constexpr static inline uint32_t uQueueMinSize = 10;
constexpr static inline float fAnimationLogEntryFadeTime = 0.5f;
constexpr static inline float fAnimationEventLogEntryColorTimeLong = 1.f;
constexpr static inline float fWelcomeBannerFadeTime = 1.f;

static inline uint16_t maxAnimLimitDefault = 0x7FFF;
static inline uint16_t maxAnimLimitIncreased = 0xFFFE;
Expand Down

0 comments on commit 6b1fc1e

Please sign in to comment.