Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Dec 13, 2024
1 parent ca56936 commit 8c1cd22
Show file tree
Hide file tree
Showing 236 changed files with 2,143 additions and 2,157 deletions.
6 changes: 3 additions & 3 deletions src/client/animatedtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
#include <framework/luaengine/luaobject.h>

// @bindclass
class AnimatedText : public LuaObject
class AnimatedText final : public LuaObject
{
public:
AnimatedText();
AnimatedText(const std::string_view text, int color) : AnimatedText() {
AnimatedText(const std::string_view text, const int color) : AnimatedText() {
setText(text);
setColor(color);
}
Expand All @@ -42,7 +42,7 @@ class AnimatedText : public LuaObject

void onAppear();

void setColor(int color) { m_color = Color::from8bit(color); }
void setColor(const int color) { m_color = Color::from8bit(color); }
void setText(const std::string_view text) { m_cachedText.setText(text); }
void setOffset(const Point& offset) { m_offset = offset; }

Expand Down
8 changes: 4 additions & 4 deletions src/client/animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Animator::unserializeAppearance(const appearances::SpriteAnimation& animati
assert(m_startPhase >= -1 && m_startPhase < m_animationPhases);
}

void Animator::unserialize(int animationPhases, const FileStreamPtr& fin)
void Animator::unserialize(const int animationPhases, const FileStreamPtr& fin)
{
m_animationPhases = animationPhases;
m_async = fin->getU8() == 0;
Expand Down Expand Up @@ -77,7 +77,7 @@ void Animator::serialize(const FileStreamPtr& fin) const
}
}

void Animator::setPhase(int phase)
void Animator::setPhase(const int phase)
{
if (m_phase == phase)
return;
Expand Down Expand Up @@ -133,7 +133,7 @@ int Animator::getPhase()
return m_phase;
}

int Animator::getPhaseAt(Timer& timer, float durationFactor) const
int Animator::getPhaseAt(Timer& timer, const float durationFactor) const
{
const ticks_t time = timer.ticksElapsed();

Expand Down Expand Up @@ -195,7 +195,7 @@ int Animator::getLoopPhase()
return m_phase;
}

int Animator::getPhaseDuration(int phase) const
int Animator::getPhaseDuration(const int phase) const
{
assert(phase < static_cast<int>(m_phaseDurations.size()));

Expand Down
51 changes: 27 additions & 24 deletions src/client/attachableobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void AttachableObject::attachEffect(const AttachedEffectPtr& obj)
++m_ownerHidden;

if (obj->getDuration() > 0) {
g_dispatcher.scheduleEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect = obj]() {
g_dispatcher.scheduleEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect = obj]
{
self->detachEffect(effect);
}, obj->getDuration());
}
Expand Down Expand Up @@ -95,7 +96,7 @@ bool AttachableObject::detachEffectById(uint16_t id)
return true;
}

void AttachableObject::onDetachEffect(const AttachedEffectPtr& effect, bool callEvent)
void AttachableObject::onDetachEffect(const AttachedEffectPtr& effect, const bool callEvent)
{
if (effect->isHidedOwner())
--m_ownerHidden;
Expand All @@ -106,7 +107,7 @@ void AttachableObject::onDetachEffect(const AttachedEffectPtr& effect, bool call
effect->callLuaField("onDetach", attachedObjectToLuaObject());
}

void AttachableObject::clearAttachedEffects(bool ignoreLuaEvent)
void AttachableObject::clearAttachedEffects(const bool ignoreLuaEvent)
{
if (!hasAttachedEffects()) return;
for (const auto& e : m_data->attachedEffects)
Expand All @@ -117,27 +118,27 @@ void AttachableObject::clearAttachedEffects(bool ignoreLuaEvent)
void AttachableObject::clearTemporaryAttachedEffects()
{
if (!hasAttachedEffects()) return;
m_data->attachedEffects.erase(std::remove_if(m_data->attachedEffects.begin(), m_data->attachedEffects.end(),
[this](const AttachedEffectPtr& obj) {
if (!obj->isPermanent()) {
onDetachEffect(obj);
return true;
}
return false;
}), m_data->attachedEffects.end());
std::erase_if(m_data->attachedEffects,
[this](const AttachedEffectPtr& obj) {
if (!obj->isPermanent()) {
onDetachEffect(obj);
return true;
}
return false;
});
}

void AttachableObject::clearPermanentAttachedEffects()
{
if (!hasAttachedEffects()) return;
m_data->attachedEffects.erase(std::remove_if(m_data->attachedEffects.begin(), m_data->attachedEffects.end(),
[this](const AttachedEffectPtr& obj) {
if (obj->isPermanent()) {
onDetachEffect(obj);
return true;
}
return false;
}), m_data->attachedEffects.end());
std::erase_if(m_data->attachedEffects,
[this](const AttachedEffectPtr& obj) {
if (obj->isPermanent()) {
onDetachEffect(obj);
return true;
}
return false;
});
}

AttachedEffectPtr AttachableObject::getAttachedEffectById(uint16_t id)
Expand All @@ -152,13 +153,14 @@ AttachedEffectPtr AttachableObject::getAttachedEffectById(uint16_t id)
return *it;
}

void AttachableObject::drawAttachedEffect(const Point& dest, const LightViewPtr& lightView, bool isOnTop)
void AttachableObject::drawAttachedEffect(const Point& dest, const LightViewPtr& lightView, const bool isOnTop)
{
if (!hasAttachedEffects()) return;
for (const auto& effect : m_data->attachedEffects) {
effect->draw(dest, isOnTop, lightView);
if (effect->getLoop() == 0) {
g_dispatcher.addEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect]() {
g_dispatcher.addEvent([self = std::static_pointer_cast<AttachableObject>(shared_from_this()), effect]
{
self->detachEffect(effect);
});
}
Expand Down Expand Up @@ -262,7 +264,8 @@ void AttachableObject::attachWidget(const UIWidgetPtr& widget) {
getData()->attachedWidgets.emplace_back(widget);
g_map.addAttachedWidgetToObject(widget, std::static_pointer_cast<AttachableObject>(shared_from_this()));
widget->callLuaField("onAttached", asLuaObject());
widget->addOnDestroyCallback("attached-widget-destroy", [this, widget]() {
widget->addOnDestroyCallback("attached-widget-destroy", [this, widget]
{
detachWidget(widget);
});
}
Expand Down Expand Up @@ -301,12 +304,12 @@ bool AttachableObject::detachWidget(const UIWidgetPtr widget)
return true;
}

void AttachableObject::clearAttachedWidgets(bool callEvent)
void AttachableObject::clearAttachedWidgets(const bool callEvent)
{
if (!hasAttachedWidgets()) return;

// keep the same behavior as detachWidget
auto oldList = std::move(m_data->attachedWidgets);
const auto oldList = std::move(m_data->attachedWidgets);
m_data->attachedWidgets.clear();

for (const auto& widget : oldList) {
Expand Down
6 changes: 3 additions & 3 deletions src/client/attachableobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AttachableObject : public LuaObject
{
public:
AttachableObject() = default;
virtual ~AttachableObject();
~AttachableObject() override;

virtual LuaObjectPtr attachedObjectToLuaObject() = 0;
virtual bool isTile() { return false; }
Expand Down Expand Up @@ -67,7 +67,7 @@ class AttachableObject : public LuaObject
void attachWidget(const UIWidgetPtr& widget);
void clearAttachedWidgets(bool callEvent = true);
bool detachWidgetById(const std::string& id);
bool detachWidget(const UIWidgetPtr widget);
bool detachWidget(UIWidgetPtr widget);
UIWidgetPtr getAttachedWidgetById(const std::string& id);

protected:
Expand All @@ -84,7 +84,7 @@ class AttachableObject : public LuaObject
void onDetachEffect(const AttachedEffectPtr& effect, bool callEvent = true);
void drawAttachedParticlesEffect(const Point& dest);

inline auto getData() {
auto getData() {
if (!m_data)
m_data = std::make_shared<Data>();
return m_data;
Expand Down
4 changes: 2 additions & 2 deletions src/client/attachedeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <framework/graphics/animatedtexture.h>
#include <framework/graphics/shadermanager.h>

AttachedEffectPtr AttachedEffect::create(uint16_t thingId, ThingCategory category) {
AttachedEffectPtr AttachedEffect::create(const uint16_t thingId, const ThingCategory category) {
if (!g_things.isValidDatId(thingId, category)) {
g_logger.error(stdext::format("AttachedEffectManager::getInstance(%d, %d): invalid thing with id or category.", thingId, static_cast<uint8_t>(category)));
return nullptr;
Expand Down Expand Up @@ -71,7 +71,7 @@ int getBounce(const AttachedEffect::Bounce bounce, const ticks_t ticks) {
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) {
void AttachedEffect::draw(const Point& dest, const bool isOnTop, const LightViewPtr& lightView, const bool drawThing) {
if (m_transform)
return;

Expand Down
40 changes: 20 additions & 20 deletions src/client/attachedeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,70 +25,70 @@
#include "thingtype.h"
#include "outfit.h"

class AttachedEffect : public LuaObject
class AttachedEffect final : public LuaObject
{
public:
static AttachedEffectPtr create(uint16_t thingId, ThingCategory category);

void draw(const Point& /*dest*/, bool /*isOnTop*/, const LightViewPtr & = nullptr, const bool drawThing = true);
void draw(const Point& /*dest*/, bool /*isOnTop*/, const LightViewPtr & = nullptr, bool drawThing = true);
void drawLight(const Point& /*dest*/, const LightViewPtr&);

uint16_t getId() { return m_id; }

AttachedEffectPtr clone();

float getSpeed() { return m_speed / 100.f; }
void setSpeed(float speed) { m_speed = speed * 100u; }
void setSpeed(const float speed) { m_speed = speed * 100u; }

float getOpacity() { return m_opacity / 100.f; }
void setOpacity(float opacity) { m_opacity = opacity * 100u; }
void setOpacity(const float opacity) { m_opacity = opacity * 100u; }

Size getSize() { return m_size; }
void setSize(const Size& s) { m_size = s; }

bool isHidedOwner() { return m_hideOwner; }
void setHideOwner(bool v) { m_hideOwner = v; }
void setHideOwner(const bool v) { m_hideOwner = v; }

bool isTransform() { return m_transform; }
void setTransform(bool v) { m_transform = v; }
void setTransform(const bool v) { m_transform = v; }

bool isDisabledWalkAnimation() { return m_disableWalkAnimation; }
void setDisableWalkAnimation(bool v) { m_disableWalkAnimation = v; }
void setDisableWalkAnimation(const bool v) { m_disableWalkAnimation = v; }

bool isPermanent() { return m_permanent; }
void setPermanent(bool permanent) { m_permanent = permanent; }
void setPermanent(const bool permanent) { m_permanent = permanent; }

uint16_t getDuration() { return m_duration; }
void setDuration(uint16_t v) { m_duration = v; }
void setDuration(const uint16_t v) { m_duration = v; }

int8_t getLoop() { return m_loop; }
void setLoop(int8_t v) { m_loop = v; }
void setLoop(const int8_t v) { m_loop = v; }

void setName(std::string_view n) { m_name = { n.data() }; }
std::string getName() { return m_name; }

Otc::Direction getDirection() { return m_direction; }
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 }; }
void setPulse(uint8_t minHeight, uint8_t height, uint16_t speed) { m_pulse = { minHeight, height , speed }; }
void setFade(uint8_t start, uint8_t end, uint16_t speed) { m_fade = { start, end , speed }; }
void setBounce(const uint8_t minHeight, const uint8_t height, const uint16_t speed) { m_bounce = { minHeight, height , speed }; }
void setPulse(const uint8_t minHeight, const uint8_t height, const uint16_t speed) { m_pulse = { minHeight, height , speed }; }
void setFade(const uint8_t start, const uint8_t end, const uint16_t speed) { m_fade = { start, end , speed }; }

void setOnTop(bool onTop) { for (auto& control : m_offsetDirections) control.onTop = onTop; }
void setOnTop(const 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; }
void setOnTopByDir(const Otc::Direction direction, const bool onTop) { m_offsetDirections[direction].onTop = onTop; }

void setDirOffset(Otc::Direction direction, int8_t x, int8_t y, bool onTop = false) { m_offsetDirections[direction] = { onTop, {x, y} }; }
void setShader(const std::string_view name);
void setCanDrawOnUI(bool canDraw) { m_canDrawOnUI = canDraw; }
void setDirOffset(const Otc::Direction direction, int8_t x, int8_t y, const bool onTop = false) { m_offsetDirections[direction] = { onTop, {x, y} }; }
void setShader(std::string_view name);
void setCanDrawOnUI(const bool canDraw) { m_canDrawOnUI = canDraw; }
bool canDrawOnUI() { return m_canDrawOnUI; }

void move(const Position& fromPosition, const Position& toPosition);

void attachEffect(const AttachedEffectPtr& e) { m_effects.emplace_back(e); }

DrawOrder getDrawOrder() { return m_drawOrder; }
void setDrawOrder(DrawOrder drawOrder) { m_drawOrder = drawOrder; }
void setDrawOrder(const DrawOrder drawOrder) { m_drawOrder = drawOrder; }
const Light& getLight() const { return m_light; }
void setLight(const Light& light) { m_light = light; }

Expand Down Expand Up @@ -116,7 +116,7 @@ class AttachedEffect : public LuaObject
uint8_t m_speed{ 100 };
uint8_t m_opacity{ 100 };
uint8_t m_lastAnimation{ 0 };
DrawOrder m_drawOrder{ DrawOrder::FIRST };
DrawOrder m_drawOrder{ FIRST };

uint16_t m_id{ 0 };
uint16_t m_duration{ 0 };
Expand Down
8 changes: 4 additions & 4 deletions src/client/attachedeffectmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

AttachedEffectManager g_attachedEffects;

AttachedEffectPtr AttachedEffectManager::getById(uint16_t id) {
AttachedEffectPtr AttachedEffectManager::getById(const uint16_t id) {
const auto it = m_effects.find(id);
if (it == m_effects.end()) {
g_logger.error(stdext::format("AttachedEffectManager::getById(%d): not found.", id));
return nullptr;
}

const auto& obj = (*it).second;
const auto& obj = it->second;
if (obj->m_thingId > 0 && !g_things.isValidDatId(obj->m_thingId, obj->m_thingCategory)) {
g_logger.error(stdext::format("AttachedEffectManager::getById(%d): invalid thing with id %d.", id, obj->m_thingId));
return nullptr;
Expand All @@ -44,7 +44,7 @@ AttachedEffectPtr AttachedEffectManager::getById(uint16_t id) {
return obj->clone();
}

AttachedEffectPtr AttachedEffectManager::registerByThing(uint16_t id, const std::string_view name, uint16_t thingId, ThingCategory category) {
AttachedEffectPtr AttachedEffectManager::registerByThing(uint16_t id, const std::string_view name, const uint16_t thingId, const ThingCategory category) {
const auto it = m_effects.find(id);
if (it != m_effects.end()) {
g_logger.error(stdext::format("AttachedEffectManager::registerByThing(%d, %s): has already been registered.", id, name));
Expand All @@ -62,7 +62,7 @@ AttachedEffectPtr AttachedEffectManager::registerByThing(uint16_t id, const std:
return obj;
}

AttachedEffectPtr AttachedEffectManager::registerByImage(uint16_t id, const std::string_view name, const std::string_view path, bool smooth) {
AttachedEffectPtr AttachedEffectManager::registerByImage(uint16_t id, const std::string_view name, const std::string_view path, const bool smooth) {
const auto it = m_effects.find(id);
if (it != m_effects.end()) {
g_logger.error(stdext::format("AttachedEffectManager::registerByImage(%d, %s): has already been registered.", id, name));
Expand Down
6 changes: 3 additions & 3 deletions src/client/attachedeffectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
class AttachedEffectManager
{
public:
AttachedEffectPtr registerByThing(uint16_t id, const std::string_view name, uint16_t thingId, ThingCategory category);
AttachedEffectPtr registerByImage(uint16_t id, const std::string_view name, const std::string_view path, bool smooth);
AttachedEffectPtr registerByThing(uint16_t id, std::string_view name, uint16_t thingId, ThingCategory category);
AttachedEffectPtr registerByImage(uint16_t id, std::string_view name, std::string_view path, bool smooth);

AttachedEffectPtr getById(uint16_t id);
void remove(uint16_t id) { m_effects.erase(id); }
void remove(const uint16_t id) { m_effects.erase(id); }
void clear() { m_effects.clear(); }

private:
Expand Down
4 changes: 2 additions & 2 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Client::preLoad() {
}
}

void Client::draw(DrawPoolType type)
void Client::draw(const DrawPoolType type)
{
if (!g_game.isOnline()) {
m_mapWidget = nullptr;
Expand All @@ -96,7 +96,7 @@ void Client::draw(DrawPoolType type)
m_mapWidget->draw(type);
}

bool Client::canDraw(DrawPoolType type) const
bool Client::canDraw(const DrawPoolType type) const
{
switch (type) {
case DrawPoolType::FOREGROUND:
Expand Down
4 changes: 2 additions & 2 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class Client : public ApplicationDrawEvents
UIMapPtr getMapWidget() { return m_mapWidget; }

float getEffectAlpha() const { return m_effectAlpha; }
void setEffectAlpha(float v) { m_effectAlpha = v; }
void setEffectAlpha(const float v) { m_effectAlpha = v; }

float getMissileAlpha() const { return m_missileAlpha; }
void setMissileAlpha(float v) { m_missileAlpha = v; }
void setMissileAlpha(const float v) { m_missileAlpha = v; }

private:
UIMapPtr m_mapWidget;
Expand Down
Loading

0 comments on commit 8c1cd22

Please sign in to comment.