Closed markusobi closed 6 years ago
Should I refactor the whole executeInThread
system into a separate class?
@ataulien I've refactored the threading stuff into it's own class: JobManager
The JobManager
does not have any dependency (BaseEngine
is forward declarated).
The BaseEngine has got a JobManager
(public) member variable.
The two execute functions executeInThread
and executeInMainThread
are still in the BaseEngine
and are simply calling the JobManager
's functions of the same name.
Since they are only wrapper functions, I could remove them and refactor all usages.
Which of the following variants do you prefer?
m_Engine.executeInMainThread<void>(...)
m_Engine.m_JobManager.executeInMainThread<void>(...)
m_Engine.getJobManager().executeInMainThread<void>(...)
with JobManager
being private member@markusobi Sounds reasonable. I would prefer something along the lines of
m_Engine.getJobManager().executeInMainThread<void>(...)
.
Having the method directly inside the engine would make the code less cluttered, on the caller-side, but it would also lead to a more bloated engine-object. We would have to wrap stuff like loading textures, etc too, to stay consistent.
~WorldInstance
calling bgfx functions from non-main-thread (i.e. if exception occurs inGameSession::createWorld
)m_EnableMultiThreading
is set to false, all tasks will be executed with policyMainThread
(mainthread->mainthread is immediately). This makes tracing exceptions much easier, when being thrown in non-main-threadBaseEngine::executeInThread
. Now directly returns a future, which was created by a promise.(this example actually doesn't make much sense, since it blocks in the main thread until the worker thread finished)