Skip to content

Commit

Permalink
Merge branch 'main' into attachable-widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
conde2 committed Nov 27, 2023
2 parents 187f3ec + 94fbbbc commit c090331
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Services = {

g_app.setName("OTClient - Redemption");
g_app.setCompactName("otclient");
g_app.setOrganizationName("otbr");
g_app.setOrganizationName("otcr");

g_app.hasUpdater = function()
return (Services.updater and Services.updater ~= "" and g_modules.getModule("updater"))
Expand Down
6 changes: 3 additions & 3 deletions src/client/lightview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ void LightView::draw(const Rect& dest, const Rect& src)
});
}

g_drawPool.preDraw(DrawPoolType::LIGHT, [this, dest, src] {
g_drawPool.preDraw(DrawPoolType::LIGHT, [this, &dest, &src] {
g_drawPool.addAction([=, this] {
{
std::scoped_lock l(m_pool->getMutexPreDraw());
m_texture->updatePixels(m_pixels.data());
}

updateCoords(dest, src);
g_painter->resetColor();
g_painter->setCompositionMode(CompositionMode::MULTIPLY);
g_painter->resetTransformMatrix();
g_painter->resetColor();
g_painter->setTexture(m_texture.get());
g_painter->setCompositionMode(CompositionMode::MULTIPLY);
g_painter->drawCoords(m_coords);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/adaptativeframecounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AdaptativeFrameCounter
uint16_t getTargetFps() const { return m_targetFps; }

void setMaxFps(const uint16_t max) { m_maxFps = max; }
void setTargetFps(const uint16_t target) { m_targetFps = target; }
void setTargetFps(const uint16_t target) { if (m_targetFps != target) m_targetFps = target; }

void resetTargetFps() { m_targetFps = 0; }

Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Application
std::string m_charset{ "cp1252" };
std::string m_organizationName{ "otbr" };
std::string m_appName{ "OTClient - Redemption" };
std::string m_appCompactName{ "otclient" };
std::string m_appCompactName{ "otcr" };
std::string m_startupOptions;

std::vector<std::string> m_startupArgs;
Expand Down
20 changes: 6 additions & 14 deletions src/framework/core/graphicalapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void GraphicalApplication::init(std::vector<std::string>& args, uint8_t asyncDis
g_sounds.init();
#endif

m_frameCounter.init();
m_mapProcessFrameCounter.init();
m_graphicFrameCounter.init();
}

void GraphicalApplication::deinit()
Expand Down Expand Up @@ -136,18 +137,9 @@ void GraphicalApplication::run()

std::condition_variable foregroundUICondition, foregroundMapCondition;

AdaptativeFrameCounter frameCounter2;
frameCounter2.setTargetFps(500u); // The secondary thread is limited to 500 fps.

const auto& realFPS = [&] {
if (g_window.vsyncEnabled() || getMaxFps() || getTargetFps()) {
// get min fps between the two threads
return std::min<int>(m_frameCounter.getFps(), frameCounter2.getFps());
}

return getFps() < frameCounter2.getFps() ? getFps() :
// adjusts the main FPS according to the secondary FPS percentage.
std::max<int>(10, getFps() - m_frameCounter.getFpsPercent(frameCounter2.getPercent()));
m_mapProcessFrameCounter.setTargetFps(g_window.vsyncEnabled() || getMaxFps() || getTargetFps() ? 500u : 999u);
return std::min<int>(m_graphicFrameCounter.getFps(), m_mapProcessFrameCounter.getFps());
};

const auto& drawForeground = [&] {
Expand Down Expand Up @@ -206,7 +198,7 @@ void GraphicalApplication::run()
g_ui.m_mapWidget->drawSelf(DrawPoolType::MAP);
} else g_ui.m_mapWidget = nullptr;

frameCounter2.update();
m_mapProcessFrameCounter.update();
}

foregroundUICondition.notify_one();
Expand All @@ -227,7 +219,7 @@ void GraphicalApplication::run()
// update screen pixels
g_window.swapBuffers();

if (m_frameCounter.update()) {
if (m_graphicFrameCounter.update()) {
g_dispatcher.addEvent([this, fps = realFPS()] {
g_lua.callGlobalField("g_app", "onFps", fps);
});
Expand Down
15 changes: 8 additions & 7 deletions src/framework/core/graphicalapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class GraphicalApplication : public Application
void mainPoll();
void close() override;

void setMaxFps(uint16_t maxFps) { m_frameCounter.setMaxFps(maxFps); }
void setTargetFps(uint16_t targetFps) { m_frameCounter.setTargetFps(targetFps); }
void setMaxFps(uint16_t maxFps) { m_graphicFrameCounter.setMaxFps(maxFps); }
void setTargetFps(uint16_t targetFps) { m_graphicFrameCounter.setTargetFps(targetFps); }

uint16_t getFps() { return m_frameCounter.getFps(); }
uint8_t getMaxFps() { return m_frameCounter.getMaxFps(); }
uint8_t getTargetFps() { return m_frameCounter.getTargetFps(); }
uint16_t getFps() { return m_graphicFrameCounter.getFps(); }
uint8_t getMaxFps() { return m_graphicFrameCounter.getMaxFps(); }
uint8_t getTargetFps() { return m_graphicFrameCounter.getTargetFps(); }

void resetTargetFps() { m_frameCounter.resetTargetFps(); }
void resetTargetFps() { m_graphicFrameCounter.resetTargetFps(); }

bool isOnInputEvent() { return m_onInputEvent; }
bool mustOptimize() {
Expand Down Expand Up @@ -112,7 +112,8 @@ class GraphicalApplication : public Application
float m_animatedTextScale{ PlatformWindow::DEFAULT_DISPLAY_DENSITY };
float m_staticTextScale{ PlatformWindow::DEFAULT_DISPLAY_DENSITY };

AdaptativeFrameCounter m_frameCounter;
AdaptativeFrameCounter m_mapProcessFrameCounter;
AdaptativeFrameCounter m_graphicFrameCounter;
};

extern GraphicalApplication g_app;
2 changes: 1 addition & 1 deletion src/gitinfo.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define GIT_BRANCH desenv
#define GIT_VERSION 1.0
#define GIT_VERSION 3.x
#define GIT_COMMITS 0

0 comments on commit c090331

Please sign in to comment.