Skip to content

Commit

Permalink
Merge branch 'mehah:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanhoare authored Aug 26, 2024
2 parents b544efc + 1ba14ee commit 214b7cb
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 45 deletions.
9 changes: 7 additions & 2 deletions modules/game_attachedeffects/effects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
duration, loop, transform, hideOwner, size{width, height}
offset{x, y, onTop}, dirOffset[dir]{x, y, onTop},
light { color, intensity}, drawOrder(only for tiles),
bounce{minHeight, height, speed}
bounce{minHeight, height, speed},
pulse{minHeight, height, speed},
fade{start, end, speed}
onAttach, onDetach
}
]]
Expand Down Expand Up @@ -97,7 +100,9 @@ AttachedEffectManager.register(7, 'Pentagram Aura', '/images/game/effects/pentag

AttachedEffectManager.register(8, 'Ki', '/images/game/effects/ki', ThingExternalTexture, {
size = { 140, 110 },
offset = { 60, 75, true }
offset = { 60, 75, true },
pulse = { 0, 50, 3000 },
--fade = { 0, 100, 1000 },
})

AttachedEffectManager.register(9, 'Thunder', '/images/game/effects/thunder', ThingExternalTexture, {
Expand Down
8 changes: 8 additions & 0 deletions modules/game_attachedeffects/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ local executeConfig = function(attachedEffect, config)
attachedEffect:setBounce(config.bounce[1], config.bounce[2], config.bounce[3] or 1000)
end

if config.pulse then
attachedEffect:setPulse(config.pulse[1], config.pulse[2], config.pulse[3] or 1000)
end

if config.fade then
attachedEffect:setFade(config.fade[1], config.fade[2], config.fade[3] or 1000)
end

if config.duration ~= nil and config.duration > 0 then
attachedEffect:setDuration(config.duration)
end
Expand Down
2 changes: 1 addition & 1 deletion modules/game_mainpanel/mainpanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function optionsController:onInit()
end

function toggleStore()
if g_game.getFeature(GamePurseSlot) then
if g_game.getClientVersion() >= 1332 then
modules.game_store.toggle()
else
modules.game_shop.toggle() --game_shopv8
Expand Down
5 changes: 4 additions & 1 deletion modules/game_quickloot/quickloot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function quickLootController:onGameStart()
end

function quickLootController:onGameEnd()
if not g_game.getFeature(GameThingQuickLoot) then
return
end
QuickLoot.save()
QuickLoot.toggle()
if quickLootController.ui:isVisible() then
Expand Down Expand Up @@ -177,7 +180,7 @@ function QuickLoot.Define()
end)

if not status then
return g_logger.error("Error while saving top bar settings. Data won't be saved. Details: " .. result)
return g_logger.warning("Error while saving QuickLoot settings. Data won't be saved. Details: " .. result)
end

if result:len() > 104857600 then
Expand Down
33 changes: 28 additions & 5 deletions src/client/attachedeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ AttachedEffectPtr AttachedEffect::clone()

obj->m_frame = 0;
obj->m_animationTimer.restart();
obj->m_bounceTimer.restart();
obj->m_bounce.timer.restart();
obj->m_pulse.timer.restart();
obj->m_fade.timer.restart();

if (!obj->m_texturePath.empty()) {
if (obj->m_texture = g_textures.getTexture(obj->m_texturePath, obj->m_smooth)) {
Expand All @@ -63,6 +65,12 @@ AttachedEffectPtr AttachedEffect::clone()
return obj;
}

int getBounce(const AttachedEffect::Bounce bounce, const ticks_t ticks) {
const auto minHeight = bounce.minHeight * g_drawPool.getScaleFactor();
const auto height = bounce.height * g_drawPool.getScaleFactor();
return minHeight + (height - std::abs(height - static_cast<int>(ticks / (bounce.speed / 100.f)) % static_cast<int>(height * 2)));
}

void AttachedEffect::draw(const Point& dest, bool isOnTop, const LightViewPtr& lightView, const bool drawThing) {
if (m_transform)
return;
Expand All @@ -85,17 +93,24 @@ void AttachedEffect::draw(const Point& dest, bool isOnTop, const LightViewPtr& l
if (m_shader) g_drawPool.setShaderProgram(m_shader, true);
if (m_opacity < 100) g_drawPool.setOpacity(getOpacity(), true);

const auto scaleFactor = g_drawPool.getScaleFactor();

if (m_pulse.height > 0 && m_pulse.speed > 0) {
g_drawPool.setScaleFactor(scaleFactor + getBounce(m_pulse, m_pulse.timer.ticksElapsed()) / 100.f);
}

if (m_fade.height > 0 && m_fade.speed > 0) {
g_drawPool.setOpacity(std::clamp<float>(getBounce(m_fade, m_fade.timer.ticksElapsed()) / 100.f, 0, 1.f));
}

auto point = dest - (dirControl.offset * g_drawPool.getScaleFactor());
if (!m_toPoint.isNull()) {
const float fraction = std::min<float>(m_animationTimer.ticksElapsed() / static_cast<float>(m_duration), 1.f);
point += m_toPoint * fraction * g_drawPool.getScaleFactor();
}

if (m_bounce.height > 0 && m_bounce.speed > 0) {
const auto minHeight = m_bounce.minHeight * g_drawPool.getScaleFactor();
const auto height = m_bounce.height * g_drawPool.getScaleFactor();
const auto pixel = minHeight + (height - std::abs(height - static_cast<int>(m_bounceTimer.ticksElapsed() / (m_bounce.speed / 100.f)) % static_cast<int>(height * 2)));
point -= pixel;
point -= getBounce(m_bounce, m_bounce.timer.ticksElapsed());
}

if (lightView && m_light.intensity > 0)
Expand All @@ -111,6 +126,14 @@ void AttachedEffect::draw(const Point& dest, bool isOnTop, const LightViewPtr& l
} else {
getThingType()->draw(point, 0, m_direction, 0, 0, animation, Color::white, drawThing, lightView, { .order = getDrawOrder() });
}

if (m_pulse.height > 0 && m_pulse.speed > 0) {
g_drawPool.setScaleFactor(scaleFactor);
}

if (m_fade.height > 0 && m_fade.speed > 0) {
g_drawPool.resetOpacity();
}
}

if (drawThing) {
Expand Down
21 changes: 14 additions & 7 deletions src/client/attachedeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class AttachedEffect : public LuaObject
void setDirection(const Otc::Direction dir) { m_direction = std::min<Otc::Direction>(dir, Otc::NorthWest); }

void setBounce(uint8_t minHeight, uint8_t height, uint16_t speed) { m_bounce = { minHeight, height , speed }; }

Check warning on line 73 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 73 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 73 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 73 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 73 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 73 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]
void setPulse(uint8_t minHeight, uint8_t height, uint16_t speed) { m_pulse = { minHeight, height , speed }; }

Check warning on line 74 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 74 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 74 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 74 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 74 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 74 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]
void setFade(uint8_t start, uint8_t end, uint16_t speed) { m_fade = { start, end , speed }; }

Check warning on line 75 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 75 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 75 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

Check warning on line 75 in src/client/attachedeffect.h

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

missing initializer for member ‘AttachedEffect::Bounce::timer’ [-Wmissing-field-initializers]

void setOnTop(bool onTop) { for (auto& control : m_offsetDirections) control.onTop = onTop; }
void setOffset(int16_t x, int16_t y) { for (auto& control : m_offsetDirections) control.offset = { x, y }; }
void setOnTopByDir(Otc::Direction direction, bool onTop) { m_offsetDirections[direction].onTop = onTop; }
Expand All @@ -91,6 +94,14 @@ class AttachedEffect : public LuaObject

ThingType* getThingType() const;

struct Bounce
{
uint8_t minHeight{ 0 };
uint8_t height{ 0 };
uint16_t speed{ 0 };
Timer timer;
};

private:
int getCurrentAnimationPhase();

Expand Down Expand Up @@ -128,19 +139,15 @@ class AttachedEffect : public LuaObject
Size m_size;

Timer m_animationTimer;
Timer m_bounceTimer;

Otc::Direction m_direction{ Otc::North };

std::array<DirControl, Otc::Direction::NorthWest + 1> m_offsetDirections;
std::string m_texturePath;

struct
{
uint8_t minHeight{ 0 };
uint8_t height{ 0 };
uint16_t speed{ 0 };
} m_bounce;
Bounce m_bounce;
Bounce m_pulse;
Bounce m_fade;

PainterShaderProgramPtr m_shader;
TexturePtr m_texture;
Expand Down
4 changes: 4 additions & 0 deletions src/client/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Creature>("isStaticSquareVisible", &Creature::isStaticSquareVisible);
g_lua.bindClassMemberFunction<Creature>("getStaticSquareColor", &Creature::getStaticSquareColor);
g_lua.bindClassMemberFunction<Creature>("setBounce", &Creature::setBounce);

g_lua.bindClassMemberFunction<Creature>("setTyping", &Creature::setTyping);
g_lua.bindClassMemberFunction<Creature>("getTyping", &Creature::getTyping);
g_lua.bindClassMemberFunction<Creature>("sendTyping", &Creature::sendTyping);
Expand Down Expand Up @@ -760,6 +761,9 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<AttachedEffect>("setDrawOrder", &AttachedEffect::setDrawOrder);
g_lua.bindClassMemberFunction<AttachedEffect>("setLight", &AttachedEffect::setLight);
g_lua.bindClassMemberFunction<AttachedEffect>("setBounce", &AttachedEffect::setBounce);
g_lua.bindClassMemberFunction<AttachedEffect>("setPulse", &AttachedEffect::setPulse);
g_lua.bindClassMemberFunction<AttachedEffect>("setFade", &AttachedEffect::setFade);

g_lua.bindClassMemberFunction<AttachedEffect>("setDirection", &AttachedEffect::setDirection);
g_lua.bindClassMemberFunction<AttachedEffect>("getDirection", &AttachedEffect::getDirection);
g_lua.bindClassMemberFunction<AttachedEffect>("move", &AttachedEffect::move);
Expand Down
4 changes: 2 additions & 2 deletions src/client/protocolgameparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ void ProtocolGame::parseWorldTime(const InputMessagePtr& msg)

void ProtocolGame::parseStore(const InputMessagePtr& msg) const
{
if (g_game.getClientVersion() <= 1332) {
if (g_game.getClientVersion() < 1332) {
parseCoinBalance(msg);
}

Expand All @@ -719,7 +719,7 @@ void ProtocolGame::parseStore(const InputMessagePtr& msg) const
StoreCategory category;
category.name = msg->getString();

if (g_game.getClientVersion() <= 1332) {
if (g_game.getClientVersion() < 1332) {
msg->getString();
}

Expand Down
34 changes: 9 additions & 25 deletions src/framework/core/garbagecollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,16 @@ void GarbageCollection::drawpoll() {
void GarbageCollection::texture() {
static constexpr uint32_t IDLE_TIME = 25 * 60 * 1000; // 25min

std::vector<std::string> textureRemove;
std::vector<AnimatedTexturePtr> animatedTextureRemove;

{
std::shared_lock l(g_textures.m_mutex);
for (const auto& [fileName, tex] : g_textures.m_textures) {
if (tex->m_lastTimeUsage.ticksElapsed() > IDLE_TIME) {
textureRemove.emplace_back(fileName);
}
}

for (const auto& tex : g_textures.m_animatedTextures) {
if (tex->m_lastTimeUsage.ticksElapsed() > IDLE_TIME) {
animatedTextureRemove.emplace_back(tex);
}
}
}
std::shared_lock l(g_textures.m_mutex);

if (!textureRemove.empty() || !animatedTextureRemove.empty()) {
std::unique_lock l(g_textures.m_mutex);
for (const auto& path : textureRemove)
g_textures.m_textures.erase(path);
std::erase_if(g_textures.m_textures, [](const auto& item) {
const auto& [key, tex] = item;
return tex.use_count() == 1 && tex->m_lastTimeUsage.ticksElapsed() > IDLE_TIME;
});

for (const auto& text : animatedTextureRemove)
std::erase(g_textures.m_animatedTextures, text);
}
std::erase_if(g_textures.m_animatedTextures, [](const TexturePtr& tex) {
return tex.use_count() == 1 && tex->m_lastTimeUsage.ticksElapsed() > IDLE_TIME;
});
}

void GarbageCollection::thingType() {
Expand Down Expand Up @@ -122,4 +106,4 @@ void GarbageCollection::thingType() {
thingType->unload();
});
}
}
}
6 changes: 4 additions & 2 deletions src/framework/graphics/texturemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ TexturePtr TextureManager::getTexture(const std::string& fileName, bool smooth)
if (texture) {
texture->setTime(stdext::time());
texture->setSmooth(smooth);

std::unique_lock l(m_mutex);
m_textures[filePath] = texture;
}
}

texture->m_lastTimeUsage.restart();
if (texture) {
texture->m_lastTimeUsage.restart();
}

return texture;
}

Expand Down

0 comments on commit 214b7cb

Please sign in to comment.