Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Aug 20, 2024
1 parent aa08454 commit 75ed98e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/client/attachableobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void AttachableObject::clearTemporaryAttachedEffects()
{
if (!hasAttachedEffects()) return;
m_data->attachedEffects.erase(std::remove_if(m_data->attachedEffects.begin(), m_data->attachedEffects.end(),
[&](const AttachedEffectPtr& obj) {
[this](const AttachedEffectPtr& obj) {
if (!obj->isPermanent()) {
onDetachEffect(obj);
return true;
Expand All @@ -131,7 +131,7 @@ void AttachableObject::clearPermanentAttachedEffects()
{
if (!hasAttachedEffects()) return;
m_data->attachedEffects.erase(std::remove_if(m_data->attachedEffects.begin(), m_data->attachedEffects.end(),
[&](const AttachedEffectPtr& obj) {
[this](const AttachedEffectPtr& obj) {
if (obj->isPermanent()) {
onDetachEffect(obj);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,4 +1748,4 @@ void Game::openContainerQuickLoot(uint8_t action, uint8_t category, const Positi
m_denyBotCall = false;
m_protocolGame->openContainerQuickLoot(action, category, pos, itemId, stackpos, useMainAsFallback);
m_denyBotCall = true;
}
}
2 changes: 1 addition & 1 deletion src/client/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Map g_map;

void Map::init()
{
g_window.addKeyListener([&](const InputEvent& inputEvent) {
g_window.addKeyListener([this](const InputEvent& inputEvent) {
notificateKeyRelease(inputEvent);
});

Expand Down
19 changes: 10 additions & 9 deletions src/framework/core/graphicalapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void GraphicalApplication::init(std::vector<std::string>& args, ApplicationConte
else g_dispatcher.addEvent([&, PH1]() { inputEvent(PH1); });
});

g_window.setOnClose([this] { g_dispatcher.addEvent([&]() { close(); }); });
g_window.setOnClose([this] { g_dispatcher.addEvent([this]() { close(); }); });

g_mouse.init();

Expand Down Expand Up @@ -139,16 +139,18 @@ void GraphicalApplication::run()

g_lua.callGlobalField("g_app", "onRun");

const auto& FPS = [&] {
const auto& FPS = [this] {
m_mapProcessFrameCounter.setTargetFps(g_window.vsyncEnabled() || getMaxFps() || getTargetFps() ? 500u : 0u);
return m_graphicFrameCounter.getFps();
};

// THREAD - POOL & MAP
const auto& mapThread = g_asyncDispatcher.submit_task([&] {
const auto& mapThread = g_asyncDispatcher.submit_task([this] {
const auto uiPool = g_drawPool.get(DrawPoolType::FOREGROUND);
const auto fgMapPool = g_drawPool.get(DrawPoolType::FOREGROUND_MAP);

BS::multi_future<void> tasks;

g_eventThreadId = EventDispatcher::getThreadId();
while (!m_stopping) {
poll();
Expand All @@ -167,31 +169,30 @@ void GraphicalApplication::run()

m_drawEvents->preLoad();

BS::multi_future<void> threads;
threads.reserve(3);
tasks.clear();

if (m_drawEvents->canDraw(DrawPoolType::LIGHT)) {
threads.emplace_back(g_asyncDispatcher.submit_task([&] {
tasks.emplace_back(g_asyncDispatcher.submit_task([this] {
m_drawEvents->draw(DrawPoolType::LIGHT);
}));
}

if (uiPool->canRepaint()) {
threads.emplace_back(g_asyncDispatcher.submit_task([&] {
tasks.emplace_back(g_asyncDispatcher.submit_task([this] {
g_ui.render(DrawPoolType::FOREGROUND);
}));
}

if (fgMapPool->canRepaint()) {
threads.emplace_back(g_asyncDispatcher.submit_task([&] {
tasks.emplace_back(g_asyncDispatcher.submit_task([this] {
m_drawEvents->draw(DrawPoolType::CREATURE_INFORMATION);
m_drawEvents->draw(DrawPoolType::FOREGROUND_MAP);
}));
}

m_drawEvents->draw(DrawPoolType::MAP);

threads.wait();
tasks.wait();

m_mapProcessFrameCounter.update();
}
Expand Down
6 changes: 3 additions & 3 deletions src/framework/graphics/animatedtexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void AnimatedTexture::buildHardwareMipmaps()
if (getProp(Prop::hasMipMaps)) return;
setProp(Prop::hasMipMaps, true);

g_mainDispatcher.addEvent([&] {
g_mainDispatcher.addEvent([this] {
for (const auto& frame : m_frames)
frame->buildHardwareMipmaps();
});
Expand All @@ -58,7 +58,7 @@ void AnimatedTexture::buildHardwareMipmaps()
void AnimatedTexture::setSmooth(bool smooth)
{
setProp(Prop::smooth, smooth);
g_mainDispatcher.addEvent([&] {
g_mainDispatcher.addEvent([this, smooth] {
for (const auto& frame : m_frames)
frame->setSmooth(smooth);
});
Expand All @@ -67,7 +67,7 @@ void AnimatedTexture::setSmooth(bool smooth)
void AnimatedTexture::setRepeat(bool repeat)
{
setProp(Prop::repeat, repeat);
g_mainDispatcher.addEvent([&] {
g_mainDispatcher.addEvent([this, repeat] {
for (const auto& frame : m_frames)
frame->setRepeat(repeat);
});
Expand Down
6 changes: 3 additions & 3 deletions src/framework/net/httplogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void LoginHttp::startHttpLogin(const std::string& host, const std::string& path,
httplib::SSLClient cli(host, port);

cli.set_logger(
[&](const auto& req, const auto& res) { LoginHttp::Logger(req, res); });
[this](const auto& req, const auto& res) { LoginHttp::Logger(req, res); });

json body = json{ {"email", email}, {"password", password}, {"stayloggedin", true}, {"type", "login"} };
httplib::Headers headers = { {"User-Agent", "Mozilla/5.0"} };
Expand Down Expand Up @@ -137,7 +137,7 @@ httplib::Result LoginHttp::loginHttpsJson(const std::string& host,
httplib::SSLClient client(host, port);

client.set_logger(
[&](const auto& req, const auto& res) { LoginHttp::Logger(req, res); });
[this](const auto& req, const auto& res) { LoginHttp::Logger(req, res); });

json body = { {"email", email}, {"password", password}, {"stayloggedin", true}, {"type", "login"} };
httplib::Headers headers = { {"User-Agent", "Mozilla/5.0"} };
Expand Down Expand Up @@ -169,7 +169,7 @@ httplib::Result LoginHttp::loginHttpJson(const std::string& host,
const std::string& password) {
httplib::Client client(host, port);
client.set_logger(
[&](const auto& req, const auto& res) { LoginHttp::Logger(req, res); });
[this](const auto& req, const auto& res) { LoginHttp::Logger(req, res); });

httplib::Headers headers = { {"User-Agent", "Mozilla/5.0"} };
json body = { {"email", email}, {"password", password}, {"stayloggedin", true}, {"type", "login"} };
Expand Down
21 changes: 4 additions & 17 deletions src/framework/net/protocolhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int Http::get(const std::string& url, int timeout)
result->operationId = operationId;
m_operations[operationId] = result;
const auto& session = std::make_shared<HttpSession>(m_ios, url, m_userAgent, m_enable_time_out_on_read_write, m_custom_header, timeout,
false, true, result, [&](HttpResult_ptr result) {
false, true, result, [this, operationId](HttpResult_ptr result) {
bool finished = result->finished;
g_dispatcher.addEvent([result, finished] {
if (!finished) {
Expand Down Expand Up @@ -104,7 +104,7 @@ int Http::post(const std::string& url, const std::string& data, int timeout, boo
result->postData = data;
m_operations[operationId] = result;
const auto& session = std::make_shared<HttpSession>(m_ios, url, m_userAgent, m_enable_time_out_on_read_write, m_custom_header, timeout,
isJson, checkContentLength, result, [&](HttpResult_ptr result) {
isJson, checkContentLength, result, [this, operationId](HttpResult_ptr result) {
bool finished = result->finished;
g_dispatcher.addEvent([result, finished] {
if (!finished) {
Expand Down Expand Up @@ -437,7 +437,7 @@ void HttpSession::on_request_sent(const std::error_code& ec, size_t /*bytes_tran

void HttpSession::on_read(const std::error_code& ec, size_t bytes_transferred)
{
auto on_done_read = [&]() {
auto on_done_read = [this]() {
m_timer.cancel();
const auto& data = m_response.data();
m_result->response.append(asio::buffers_begin(data), asio::buffers_end(data));
Expand Down Expand Up @@ -559,19 +559,6 @@ void WebsocketSession::start()
});
}














void WebsocketSession::on_resolve(const std::error_code& ec, asio::ip::tcp::resolver::iterator iterator)
{
if (ec) {
Expand Down Expand Up @@ -989,4 +976,4 @@ void WebsocketSession::close()
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/framework/platform/win32window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ void WIN32Window::resize(const Size& size)

void WIN32Window::show()
{
g_mainDispatcher.addEvent([&] {
g_mainDispatcher.addEvent([this] {
m_hidden = false;
if (m_maximized)
ShowWindow(m_window, SW_MAXIMIZE);
Expand Down

0 comments on commit 75ed98e

Please sign in to comment.