Skip to content

Commit

Permalink
Allow disable animation for Thing
Browse files Browse the repository at this point in the history
  • Loading branch information
nekiro committed Jan 6, 2025
1 parent 4fb7ba8 commit df74e14
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,8 @@ ThingType* Creature::getMountThingType() const {

uint16_t Creature::getCurrentAnimationPhase(const bool mount)
{
if (!canAnimate()) return 0;

const auto thingType = mount ? getMountThingType() : getThingType();

if (const auto idleAnimator = thingType->getIdleAnimator()) {
Expand Down
32 changes: 17 additions & 15 deletions src/client/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,24 @@ void Effect::draw(const Point& dest, const bool drawThings, const LightViewPtr&
if (m_animationTimer.ticksElapsed() < m_timeToStartDrawing)
return;

int animationPhase;
if (g_game.getFeature(Otc::GameEnhancedAnimations)) {
const auto* animator = getThingType()->getIdleAnimator();
if (!animator)
return;

// This requires a separate getPhaseAt method as using getPhase would make all magic effects use the same phase regardless of their appearance time
animationPhase = animator->getPhaseAt(m_animationTimer);
} else {
// hack to fix some animation phases duration, currently there is no better solution
int ticks = g_gameConfig.getEffectTicksPerFrame();
if (m_clientId == 33) {
ticks <<= 2;
int animationPhase = 0;
if (canAnimate()) {
if (g_game.getFeature(Otc::GameEnhancedAnimations)) {
const auto* animator = getThingType()->getIdleAnimator();
if (!animator)
return;

// This requires a separate getPhaseAt method as using getPhase would make all magic effects use the same phase regardless of their appearance time
animationPhase = animator->getPhaseAt(m_animationTimer);
} else {
// hack to fix some animation phases duration, currently there is no better solution
int ticks = g_gameConfig.getEffectTicksPerFrame();
if (m_clientId == 33) {
ticks <<= 2;
}

animationPhase = std::min<int>(static_cast<int>(m_animationTimer.ticksElapsed() / ticks), getAnimationPhases() - 1);
}

animationPhase = std::min<int>(static_cast<int>(m_animationTimer.ticksElapsed() / ticks), getAnimationPhases() - 1);
}

const int offsetX = m_position.x - g_map.getCentralPosition().x;
Expand Down
2 changes: 1 addition & 1 deletion src/client/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void Item::updatePatterns()

int Item::calculateAnimationPhase()
{
if (!hasAnimationPhases()) return 0;
if (!hasAnimationPhases() || !canAnimate()) return 0;

if (getIdleAnimator()) return getIdleAnimator()->getPhase();

Expand Down
2 changes: 2 additions & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("setShader", &Thing::setShader);
g_lua.bindClassMemberFunction<Thing>("setPosition", &Thing::setPosition);
g_lua.bindClassMemberFunction<Thing>("setMarked", &Thing::lua_setMarked);
g_lua.bindClassMemberFunction<Thing>("setAnimate", &Thing::setAnimate);
g_lua.bindClassMemberFunction<Thing>("isMarked", &Thing::isMarked);
g_lua.bindClassMemberFunction<Thing>("getId", &Thing::getId);
g_lua.bindClassMemberFunction<Thing>("getTile", &Thing::getTile);
Expand Down Expand Up @@ -498,6 +499,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("setHighlight", &Thing::lua_setHighlight);
g_lua.bindClassMemberFunction<Thing>("isHighlighted", &Thing::isHighlighted);
g_lua.bindClassMemberFunction<Thing>("getExactSize", &Thing::getExactSize);
g_lua.bindClassMemberFunction<Thing>("canAnimate", &Thing::canAnimate);

#ifdef FRAMEWORK_EDITOR
g_lua.registerClass<House>();
Expand Down
4 changes: 4 additions & 0 deletions src/client/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class Thing : public AttachableObject
uint8_t getPatternY()const { return m_numPatternY; }
uint8_t getPatternZ()const { return m_numPatternZ; }

bool canAnimate() { return m_animate; }
void setAnimate(bool aniamte) { m_animate = aniamte; }

protected:
virtual ThingType* getThingType() const = 0;

Expand Down Expand Up @@ -242,6 +245,7 @@ class Thing : public AttachableObject
void lua_setHighlight(const std::string_view color) { setHighlight(Color(color)); }

bool m_canDraw{ true };
bool m_animate{ true };

friend class Client;
friend class Tile;
Expand Down

0 comments on commit df74e14

Please sign in to comment.