Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to disable animation for Thing #1021

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading