Skip to content

Commit

Permalink
Version 2.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ersh1 committed May 28, 2024
1 parent 050d0de commit 65cffba
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 53 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.2
VERSION 2.3.3
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
17 changes: 15 additions & 2 deletions src/ActiveClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ 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)) {
const float blendTime = HasReplacementAnimation() ? GetReplacementAnimation()->GetCustomBlendTime(CustomBlendType::kInterrupt, false) : Settings::fDefaultBlendTimeOnInterrupt;
float blendTime = HasReplacementAnimation() ? GetReplacementAnimation()->GetCustomBlendTime(CustomBlendType::kInterrupt, false) : Settings::fDefaultBlendTimeOnInterrupt;
if (a_clipGenerator->animationControl->playbackSpeed > 0.f) {
blendTime /= a_clipGenerator->animationControl->playbackSpeed;
}
QueueReplacementAnimation(newReplacementAnim, blendTime, QueuedReplacement::Type::kRestart, AnimationLogEntry::Event::kInterrupt);
}
}
Expand All @@ -274,6 +277,10 @@ void ActiveClip::PreUpdate(RE::hkbClipGenerator* a_clipGenerator, const RE::hkbC
blendTime = 0.f;
}

if (a_clipGenerator->animationControl->playbackSpeed > 0.f) {
blendTime /= a_clipGenerator->animationControl->playbackSpeed;
}

bool bTryReplaceOnLoop = false;
hkbClipGenerator_ComputeBeginAndEndLocalTime(a_clipGenerator, a_timestep + blendTime, &prevLocalTime, &newLocalTime, &numLoops, &newAtEnd);
if (numLoops > 0) {
Expand Down Expand Up @@ -492,7 +499,10 @@ 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);
const float blendTime = GetReplacementAnimation()->GetCustomBlendTime(a_bIsEcho ? CustomBlendType::kEcho : CustomBlendType::kLoop, true);
float blendTime = GetReplacementAnimation()->GetCustomBlendTime(a_bIsEcho ? CustomBlendType::kEcho : CustomBlendType::kLoop, true);
if (a_clipGenerator->animationControl->playbackSpeed > 0.f) {
blendTime /= a_clipGenerator->animationControl->playbackSpeed;
}
QueueReplacementAnimation(_currentReplacementAnimation, blendTime, a_bIsEcho ? QueuedReplacement::Type::kRestart : QueuedReplacement::Type::kLoop, a_bIsEcho ? AnimationLogEntry::Event::kEchoReplace : AnimationLogEntry::Event::kLoopReplace, variant);
return true;
}
Expand All @@ -507,6 +517,9 @@ bool ActiveClip::OnLoopOrEcho(RE::hkbClipGenerator* a_clipGenerator, bool a_bIsE
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);
if (a_clipGenerator->animationControl->playbackSpeed > 0.f) {
blendTime /= a_clipGenerator->animationControl->playbackSpeed;
}
QueueReplacementAnimation(newReplacementAnim, blendTime, a_bIsEcho ? QueuedReplacement::Type::kRestart : QueuedReplacement::Type::kLoop, a_bIsEcho ? AnimationLogEntry::Event::kEchoReplace : AnimationLogEntry::Event::kLoopReplace, variant);
return true;
}
Expand Down
137 changes: 87 additions & 50 deletions src/Variants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,23 +545,29 @@ bool VariantStateDataContainer::UpdateData(float a_deltaTime)

std::unordered_set<RE::ObjectRefHandle> activeKeys{};

for (auto it = _localVariantStateData.begin(); it != _localVariantStateData.end();) {
auto& entry = it->second;
if (entry.UpdateData(a_deltaTime, activeKeys)) {
++it;
bActive = true;
} else {
it = _localVariantStateData.erase(it);
{
WriteLocker locker(_localMapLock);
for (auto it = _localVariantStateData.begin(); it != _localVariantStateData.end();) {
auto& entry = it->second;
if (entry.UpdateData(a_deltaTime, activeKeys)) {
++it;
bActive = true;
} else {
it = _localVariantStateData.erase(it);
}
}
}

for (auto it = _subModVariantStateData.begin(); it != _subModVariantStateData.end();) {
auto& entry = it->second;
if (entry.UpdateData(a_deltaTime, activeKeys)) {
++it;
bActive = true;
} else {
it = _subModVariantStateData.erase(it);
{
WriteLocker locker(_subModMapLock);
for (auto it = _subModVariantStateData.begin(); it != _subModVariantStateData.end();) {
auto& entry = it->second;
if (entry.UpdateData(a_deltaTime, activeKeys)) {
++it;
bActive = true;
} else {
it = _subModVariantStateData.erase(it);
}
}
}

Expand All @@ -576,23 +582,29 @@ bool VariantStateDataContainer::OnLoopOrEcho(RE::ObjectRefHandle a_refHandle, Ac
{
bool bActive = false;

for (auto it = _localVariantStateData.begin(); it != _localVariantStateData.end();) {
auto& entry = it->second;
if (entry.OnLoopOrEcho(a_refHandle, a_activeClip, a_bIsEcho)) {
++it;
bActive = true;
} else {
it = _localVariantStateData.erase(it);
{
WriteLocker locker(_localMapLock);
for (auto it = _localVariantStateData.begin(); it != _localVariantStateData.end();) {
auto& entry = it->second;
if (entry.OnLoopOrEcho(a_refHandle, a_activeClip, a_bIsEcho)) {
++it;
bActive = true;
} else {
it = _localVariantStateData.erase(it);
}
}
}

for (auto it = _subModVariantStateData.begin(); it != _subModVariantStateData.end();) {
auto& entry = it->second;
if (entry.OnLoopOrEcho(a_refHandle, a_activeClip, a_bIsEcho)) {
++it;
bActive = true;
} else {
it = _subModVariantStateData.erase(it);
{
WriteLocker locker(_subModMapLock);
for (auto it = _subModVariantStateData.begin(); it != _subModVariantStateData.end();) {
auto& entry = it->second;
if (entry.OnLoopOrEcho(a_refHandle, a_activeClip, a_bIsEcho)) {
++it;
bActive = true;
} else {
it = _subModVariantStateData.erase(it);
}
}
}

Expand All @@ -607,23 +619,29 @@ bool VariantStateDataContainer::ClearRefrData(RE::ObjectRefHandle a_refHandle)
{
bool bActive = false;

for (auto it = _localVariantStateData.begin(); it != _localVariantStateData.end();) {
auto& entry = it->second;
if (entry.ClearRefrData(a_refHandle)) {
++it;
bActive = true;
} else {
it = _localVariantStateData.erase(it);
{
WriteLocker locker(_localMapLock);
for (auto it = _localVariantStateData.begin(); it != _localVariantStateData.end();) {
auto& entry = it->second;
if (entry.ClearRefrData(a_refHandle)) {
++it;
bActive = true;
} else {
it = _localVariantStateData.erase(it);
}
}
}

for (auto it = _subModVariantStateData.begin(); it != _subModVariantStateData.end();) {
auto& entry = it->second;
if (entry.ClearRefrData(a_refHandle)) {
++it;
bActive = true;
} else {
it = _subModVariantStateData.erase(it);
{
WriteLocker locker(_subModMapLock);
for (auto it = _subModVariantStateData.begin(); it != _subModVariantStateData.end();) {
auto& entry = it->second;
if (entry.ClearRefrData(a_refHandle)) {
++it;
bActive = true;
} else {
it = _subModVariantStateData.erase(it);
}
}
}

Expand All @@ -636,22 +654,35 @@ bool VariantStateDataContainer::ClearRefrData(RE::ObjectRefHandle a_refHandle)

void VariantStateDataContainer::Clear()
{
_localVariantStateData.clear();
_subModVariantStateData.clear();
{
WriteLocker locker(_localMapLock);
_localVariantStateData.clear();
}

{
WriteLocker locker(_subModMapLock);
_subModVariantStateData.clear();
}
_replacerModVariantStateData.Clear();
}

Conditions::IStateData* VariantStateDataContainer::AccessStateData(RE::ObjectRefHandle a_key, RE::hkbClipGenerator* a_clipGenerator, const Variants* a_variants)
{
switch (a_variants->GetVariantStateScope()) {
case Conditions::StateDataScope::kLocal:
if (auto search = _localVariantStateData.find(a_clipGenerator); search != _localVariantStateData.end()) {
return search->second.AccessStateData(a_key, a_clipGenerator);
{
ReadLocker locker(_localMapLock);
if (auto search = _localVariantStateData.find(a_clipGenerator); search != _localVariantStateData.end()) {
return search->second.AccessStateData(a_key, a_clipGenerator);
}
}
break;
case Conditions::StateDataScope::kSubMod:
if (auto search = _subModVariantStateData.find(a_variants->GetParentSubMod()); search != _subModVariantStateData.end()) {
return search->second.AccessStateData(a_key, a_clipGenerator);
{
ReadLocker locker(_subModMapLock);
if (auto search = _subModVariantStateData.find(a_variants->GetParentSubMod()); search != _subModVariantStateData.end()) {
return search->second.AccessStateData(a_key, a_clipGenerator);
}
}
break;
case Conditions::StateDataScope::kReplacerMod:
Expand All @@ -665,9 +696,15 @@ Conditions::IStateData* VariantStateDataContainer::AddStateData(RE::ObjectRefHan
{
switch (a_variants->GetVariantStateScope()) {
case Conditions::StateDataScope::kLocal:
return _localVariantStateData[a_clipGenerator].AddStateData(a_key, a_stateData, a_clipGenerator);
{
WriteLocker locker(_localMapLock);
return _localVariantStateData[a_clipGenerator].AddStateData(a_key, a_stateData, a_clipGenerator);
}
case Conditions::StateDataScope::kSubMod:
return _subModVariantStateData[a_variants->GetParentSubMod()].AddStateData(a_key, a_stateData, a_clipGenerator);
{
WriteLocker locker(_subModMapLock);
return _subModVariantStateData[a_variants->GetParentSubMod()].AddStateData(a_key, a_stateData, a_clipGenerator);
}
case Conditions::StateDataScope::kReplacerMod:
return _replacerModVariantStateData.AddStateData(a_key, a_stateData, a_clipGenerator);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Variants.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ struct VariantStateDataContainer

protected:
StateDataContainer<> _replacerModVariantStateData{};

mutable SharedLock _subModMapLock;
std::unordered_map<SubMod*, StateDataContainer<>> _subModVariantStateData{};

mutable SharedLock _localMapLock;
std::unordered_map<RE::hkbClipGenerator*, StateDataContainer<>> _localVariantStateData{};
};

0 comments on commit 65cffba

Please sign in to comment.