mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Code cleanup, add comments where relevant
This commit is contained in:
@@ -23,21 +23,17 @@
|
||||
#include "media/CVideoHandler.h"
|
||||
#include "media/CEmptyVideoPlayer.h"
|
||||
|
||||
#include "CPlayerInterface.h"
|
||||
#include "adventureMap/AdventureMapInterface.h"
|
||||
#include "render/Canvas.h"
|
||||
#include "render/Colors.h"
|
||||
#include "render/Graphics.h"
|
||||
#include "render/IFont.h"
|
||||
#include "render/EFont.h"
|
||||
#include "renderSDL/ScreenHandler.h"
|
||||
#include "renderSDL/RenderHandler.h"
|
||||
#include "CMT.h"
|
||||
#include "GameEngineUser.h"
|
||||
#include "battle/BattleInterface.h"
|
||||
|
||||
#include "../lib/AsyncRunner.h"
|
||||
#include "../lib/CThreadHelper.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
|
||||
#include <SDL_render.h>
|
||||
@@ -84,8 +80,8 @@ GameEngine::GameEngine()
|
||||
|
||||
soundPlayerInstance = std::make_unique<CSoundHandler>();
|
||||
musicPlayerInstance = std::make_unique<CMusicHandler>();
|
||||
sound().setVolume((ui32)settings["general"]["sound"].Float());
|
||||
music().setVolume((ui32)settings["general"]["music"].Float());
|
||||
sound().setVolume(settings["general"]["sound"].Integer());
|
||||
music().setVolume(settings["general"]["music"].Integer());
|
||||
cursorHandlerInstance = std::make_unique<CursorHandler>();
|
||||
|
||||
asyncTasks = std::make_unique<AsyncRunner>();
|
||||
@@ -244,7 +240,7 @@ std::shared_ptr<IStatusBar> GameEngine::statusbar()
|
||||
return locked;
|
||||
}
|
||||
|
||||
void GameEngine::setStatusbar(std::shared_ptr<IStatusBar> newStatusBar)
|
||||
void GameEngine::setStatusbar(const std::shared_ptr<IStatusBar> & newStatusBar)
|
||||
{
|
||||
currentStatusBar = newStatusBar;
|
||||
}
|
||||
|
@@ -58,6 +58,8 @@ private:
|
||||
IGameEngineUser *engineUser = nullptr;
|
||||
|
||||
void updateFrame();
|
||||
void handleEvents(); //takes events from queue and calls interested objects
|
||||
void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
|
||||
|
||||
public:
|
||||
std::mutex interfaceMutex;
|
||||
@@ -102,7 +104,9 @@ public:
|
||||
std::shared_ptr<IStatusBar> statusbar();
|
||||
|
||||
/// Set currently active status bar
|
||||
void setStatusbar(std::shared_ptr<IStatusBar>);
|
||||
void setStatusbar(const std::shared_ptr<IStatusBar> &);
|
||||
|
||||
/// Sets engine user that is used as target of callback for events received by engine
|
||||
void setEngineUser(IGameEngineUser * user);
|
||||
|
||||
bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
|
||||
@@ -111,15 +115,17 @@ public:
|
||||
GameEngine();
|
||||
~GameEngine();
|
||||
|
||||
/// Performs main game loop till game shutdown
|
||||
/// This method never returns, to abort main loop throw GameShutdownException
|
||||
[[noreturn]] void mainLoop();
|
||||
|
||||
/// called whenever SDL_WINDOWEVENT_RESTORED is reported or the user selects a different resolution, requiring to center/resize all windows
|
||||
void onScreenResize(bool resolutionChanged);
|
||||
|
||||
void handleEvents(); //takes events from queue and calls interested objects
|
||||
/// Simulate mouse movement to force refresh UI state that updates on mouse move
|
||||
void fakeMouseMove();
|
||||
void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
|
||||
|
||||
/// Returns true for calls made from main (GUI) thread, false othervice
|
||||
bool amIGuiThread();
|
||||
|
||||
/// Calls provided functor in main thread on next execution frame
|
||||
|
@@ -235,14 +235,14 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
|
||||
Settings session = settings.write["session"];
|
||||
auto setSettingBool = [&](std::string key, std::string arg) {
|
||||
auto setSettingBool = [&](const std::string & key, const std::string & arg) {
|
||||
Settings s = settings.write(vstd::split(key, "/"));
|
||||
if(vm.count(arg))
|
||||
s->Bool() = true;
|
||||
else if(s->isNull())
|
||||
s->Bool() = false;
|
||||
};
|
||||
auto setSettingInteger = [&](std::string key, std::string arg, si64 defaultValue) {
|
||||
auto setSettingInteger = [&](const std::string & key, const std::string & arg, si64 defaultValue) {
|
||||
Settings s = settings.write(vstd::split(key, "/"));
|
||||
if(vm.count(arg))
|
||||
s->Integer() = vm[arg].as<si64>();
|
||||
@@ -280,7 +280,7 @@ int main(int argc, char * argv[])
|
||||
logGlobal->debug("settings = %s", settings.toJsonNode().toString());
|
||||
|
||||
// Some basic data validation to produce better error messages in cases of incorrect install
|
||||
auto testFile = [](std::string filename, std::string message)
|
||||
auto testFile = [](const std::string & filename, const std::string & message)
|
||||
{
|
||||
if (!CResourceHandler::get()->existsResource(ResourcePath(filename)))
|
||||
handleFatalError(message, false);
|
||||
|
@@ -9,23 +9,27 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <tbb/task_group.h>
|
||||
#include <tbb/task_arena.h>
|
||||
#include <tbb/task_group.h>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
/// Helper class for running asynchronous tasks using TBB thread pool
|
||||
class AsyncRunner : boost::noncopyable
|
||||
{
|
||||
tbb::task_arena arena;
|
||||
tbb::task_group taskGroup;
|
||||
|
||||
public:
|
||||
template <typename Functor>
|
||||
/// Runs the provided functor asynchronously on a thread from the TBB worker pool.
|
||||
template<typename Functor>
|
||||
void run(Functor && f)
|
||||
{
|
||||
arena.enqueue(taskGroup.defer(std::forward<Functor>(f)));
|
||||
}
|
||||
|
||||
/// Waits for all previously enqueued task.
|
||||
/// Re-entrable - waiting for tasks does not prevent submitting new tasks
|
||||
void wait()
|
||||
{
|
||||
taskGroup.wait();
|
||||
|
Reference in New Issue
Block a user