Skip to content

Commit

Permalink
Fixed crash (bug in resource loading), fixed blue spring strength, fi…
Browse files Browse the repository at this point in the history
…xed crouch animation
  • Loading branch information
deathkiller committed Nov 10, 2023
1 parent 4f9cbb8 commit 738f6be
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
11 changes: 5 additions & 6 deletions Sources/Jazz2/Actors/ActorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ namespace Jazz2::Actors
}
}

bool ActorBase::SetAnimation(AnimState state)
bool ActorBase::SetAnimation(AnimState state, bool skipAnimation)
{
if (_metadata == nullptr) {
LOGE("No metadata loaded");
Expand Down Expand Up @@ -475,7 +475,7 @@ namespace Jazz2::Actors
}

_currentAnimation = anim;
RefreshAnimation();
RefreshAnimation(skipAnimation);

return true;
}
Expand Down Expand Up @@ -1017,12 +1017,12 @@ namespace Jazz2::Actors
AABB.B = AABB.T + size.Y;
}
} else {
OnUpdateHitbox();
OnUpdateHitbox();
AABB = AABBInner;
}
}

void ActorBase::RefreshAnimation()
void ActorBase::RefreshAnimation(bool skipAnimation)
{
GraphicResource* res = (_currentTransition != nullptr ? _currentTransition : _currentAnimation);
if (res == nullptr) {
Expand All @@ -1041,13 +1041,12 @@ namespace Jazz2::Actors
_renderer.LoopMode = AnimationLoopMode::FixedSingle;
} else {
_renderer.FirstFrame = res->FrameOffset;

_renderer.LoopMode = res->LoopMode;
}

_renderer.FrameCount = res->FrameCount;
_renderer.AnimDuration = res->AnimDuration;
_renderer.AnimTime = 0.0f;
_renderer.AnimTime = (skipAnimation && res->AnimDuration >= 0.0f && _renderer.LoopMode != AnimationLoopMode::FixedSingle ? _renderer.AnimDuration : 0.0f);

_renderer.Hotspot.X = -((res->Base->FrameDimensions.X / 2) - (IsFacingLeft() ? (res->Base->FrameDimensions.X - res->Base->Hotspot.X) : res->Base->Hotspot.X));
_renderer.Hotspot.Y = -((res->Base->FrameDimensions.Y / 2) - res->Base->Hotspot.Y);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/ActorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ namespace Jazz2::Actors
virtual float GetIceShrapnelScale() const;

std::shared_ptr<AudioBufferPlayer> PlaySfx(const StringView& identifier, float gain = 1.0f, float pitch = 1.0f);
bool SetAnimation(AnimState state);
bool SetAnimation(AnimState state, bool skipAnimation = false);
bool SetTransition(AnimState state, bool cancellable, const std::function<void()>& callback = nullptr);
bool SetTransition(AnimState state, bool cancellable, std::function<void()>&& callback);
void CancelTransition();
Expand Down Expand Up @@ -352,6 +352,6 @@ namespace Jazz2::Actors
bool IsCollidingWithAngled(ActorBase* other);
bool IsCollidingWithAngled(const AABBf& aabb);

void RefreshAnimation();
void RefreshAnimation(bool skipAnimation = false);
};
}
2 changes: 1 addition & 1 deletion Sources/Jazz2/Actors/Environment/Spring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace Jazz2::Actors::Environment
_strength = 1.50f;
break;
case 2: // Blue
_strength = 1.65f;
_strength = (_levelHandler->IsReforged() ? 1.65f : 1.72f);
break;
}
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/Jazz2/Actors/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ namespace Jazz2::Actors

if (_fireFramesLeft <= 0.0f) {
// Play post-fire animation
if ((_currentAnimation->State & (AnimState::Walk | AnimState::Run | AnimState::Dash | AnimState::Crouch | AnimState::Buttstomp | AnimState::Swim | AnimState::Airboard | AnimState::Lift | AnimState::Spring)) == AnimState::Idle &&
if ((_currentAnimation->State & (AnimState::Walk | AnimState::Run | AnimState::Dash | AnimState::Buttstomp | AnimState::Swim | AnimState::Airboard | AnimState::Lift | AnimState::Spring)) == AnimState::Idle &&
(_currentTransition == nullptr || (_currentTransition->State != AnimState::TransitionRunToIdle && _currentTransition->State != AnimState::TransitionDashToIdle)) &&
!_isAttachedToPole) {

Expand All @@ -414,6 +414,8 @@ namespace Jazz2::Actors
SetTransition(AnimState::TransitionCopterShootToCopter, false);
} else if ((_currentAnimation->State & AnimState::Fall) == AnimState::Fall) {
SetTransition(AnimState::TransitionFallShootToFall, false);
} else if ((_currentAnimation->State & AnimState::Crouch) == AnimState::Crouch) {
SetAnimation(AnimState::Crouch, true);
} else {
SetTransition(AnimState::TransitionShootToIdle, false);
}
Expand Down Expand Up @@ -721,7 +723,9 @@ namespace Jazz2::Actors
if (GetState(ActorState::CanJump)) {
if (!_isLifting && std::abs(_speed.X) < std::numeric_limits<float>::epsilon()) {
_wasDownPressed = true;
SetAnimation(AnimState::Crouch);
if (_fireFramesLeft <= 0.0f) {
SetAnimation(AnimState::Crouch);
}
}
} else if (!_wasDownPressed && _playerType != PlayerType::Frog) {
_wasDownPressed = true;
Expand Down
22 changes: 21 additions & 1 deletion Sources/nCine/Base/HashFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ namespace nCine
}
};

template <class F, class S>
template<class F, class S>
class FNV1aHashFunc<Pair<F, S>>
{
public:
Expand Down Expand Up @@ -365,6 +365,16 @@ namespace nCine
}
};

template<class F, class S>
class CityHash32Func<Pair<F, S>>
{
public:
hash_t operator()(const Pair<F, S>& pair) const
{
return CityHash32Func<F>()(pair.first()) ^ CityHash32Func<S>()(pair.second());
}
};

template<class K>
class CityHash64Func
{
Expand All @@ -384,4 +394,14 @@ namespace nCine
return CityHash64(string.data(), string.size());
}
};

template<class F, class S>
class CityHash64Func<Pair<F, S>>
{
public:
hash64_t operator()(const Pair<F, S>& pair) const
{
return CityHash64Func<F>()(pair.first()) ^ CityHash64Func<S>()(pair.second());
}
};
}

0 comments on commit 738f6be

Please sign in to comment.