-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/non blocking for loading game info #240
base: develop
Are you sure you want to change the base?
Changes from 5 commits
3c5f33d
632c670
edbee7c
f891ad9
73814e3
4f86eac
e7610e4
99c5529
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done in other places of the code with https://github.com/MegaGlest/megaglest-source/blob/develop/source/shared_lib/include/platform/common/simple_threads.h#L71 |
||
|
||
#include <functional> | ||
#include <thread> | ||
#include <utility> | ||
|
||
using std::function; | ||
using std::thread; | ||
|
||
namespace Shared{ namespace Util{ | ||
|
||
template<typename T> | ||
class CallBack { | ||
|
||
|
||
private: | ||
function<void()> _onThen = [](){}; | ||
function<T()> _mainFunc = [](){}; | ||
T _result; | ||
|
||
public: | ||
CallBack(function<T()> func){ | ||
_mainFunc = func; | ||
}; | ||
|
||
~CallBack() { | ||
//printf("CallBack::~CallBack p [%p]\n",this); | ||
}; | ||
|
||
void then(function<void()> onThen){ | ||
_onThen = onThen; | ||
}; | ||
|
||
T getResult(){ | ||
return _result; | ||
} | ||
|
||
void run(){ | ||
_result = _mainFunc(); | ||
_onThen(); | ||
}; | ||
}; | ||
|
||
template<> | ||
class CallBack<void> { | ||
|
||
private: | ||
function<void()> _onThen = [](){}; | ||
function<void()> _mainFunc = [](){}; | ||
|
||
public: | ||
CallBack(function<void()> func){ | ||
_mainFunc = func; | ||
}; | ||
|
||
~CallBack() { | ||
//printf("CallBack::~CallBack p [%p]\n",this); | ||
}; | ||
|
||
void then(function<void()> onThen){ | ||
_onThen = onThen; | ||
}; | ||
|
||
void run(){ | ||
_mainFunc(); | ||
_onThen(); | ||
}; | ||
|
||
}; | ||
|
||
}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,12 @@ | |
#endif | ||
|
||
#include "rapidxml/rapidxml.hpp" | ||
#include "callback.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you forgot to include memory |
||
#include "data_types.h" | ||
#include "leak_dumper.h" | ||
|
||
using namespace rapidxml; | ||
using namespace Shared::Util; | ||
using namespace std; | ||
|
||
#if defined(WANT_XERCES) | ||
|
@@ -151,6 +153,7 @@ class XmlTree{ | |
void setSkipUpdatePathClimbingParts(bool value); | ||
void init(const string &name); | ||
void load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation=false,bool skipStackCheck=false,bool skipStackTrace=false); | ||
std::shared_ptr<CallBack<void>> loadAsync(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation=false,bool skipStackCheck=false,bool skipStackTrace=false); | ||
void save(const string &path); | ||
|
||
XmlNode *getRootNode() const {return rootNode;} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces vs tabs, this codebase uses mostly tabs, let's try to keep it consistent :)