mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-01 16:32:31 +01:00
Merge pull request #184 from darkf/omgthreadz
Fix the construction of WorkContext
This commit is contained in:
commit
a0057d1a01
@ -1,6 +1,7 @@
|
|||||||
#include "benchmarkstate.hpp"
|
#include "benchmarkstate.hpp"
|
||||||
#include "RWGame.hpp"
|
#include "RWGame.hpp"
|
||||||
#include <engine/GameState.hpp>
|
#include <engine/GameState.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
BenchmarkState::BenchmarkState(RWGame* game, const std::string& benchfile)
|
BenchmarkState::BenchmarkState(RWGame* game, const std::string& benchfile)
|
||||||
: State(game)
|
: State(game)
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _LOADCONTEXT_HPP_
|
|
||||||
#define _LOADCONTEXT_HPP_
|
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@ -8,7 +6,6 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class WorkContext;
|
class WorkContext;
|
||||||
@ -58,9 +55,6 @@ public:
|
|||||||
virtual void complete() {}
|
virtual void complete() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: refactor everything to remove this.
|
|
||||||
class GameWorld;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A worker queue that runs work in the background.
|
* @brief A worker queue that runs work in the background.
|
||||||
*
|
*
|
||||||
@ -69,13 +63,15 @@ class GameWorld;
|
|||||||
*/
|
*/
|
||||||
class WorkContext
|
class WorkContext
|
||||||
{
|
{
|
||||||
std::unique_ptr<LoadWorker> _worker;
|
std::mutex _inMutex;
|
||||||
|
std::mutex _outMutex;
|
||||||
|
|
||||||
std::queue<WorkJob*> _workQueue;
|
std::queue<WorkJob*> _workQueue;
|
||||||
std::queue<WorkJob*> _completeQueue;
|
std::queue<WorkJob*> _completeQueue;
|
||||||
|
|
||||||
std::mutex _inMutex;
|
// Construct the worker last, so that it may use the queues
|
||||||
std::mutex _outMutex;
|
// immediately after initialization.
|
||||||
|
std::unique_ptr<LoadWorker> _worker;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -97,17 +93,12 @@ public:
|
|||||||
// Called by the worker thread - don't touch
|
// Called by the worker thread - don't touch
|
||||||
void workNext();
|
void workNext();
|
||||||
|
|
||||||
const std::queue<WorkJob*> getWorkQueue() const { return _workQueue; }
|
|
||||||
const std::queue<WorkJob*> getCompleteQueue() const { return _completeQueue; }
|
|
||||||
|
|
||||||
bool isEmpty() {
|
bool isEmpty() {
|
||||||
std::lock_guard<std::mutex> guardIn( _inMutex );
|
std::lock_guard<std::mutex> guardIn( _inMutex );
|
||||||
std::lock_guard<std::mutex> guardOu( _outMutex );
|
std::lock_guard<std::mutex> guardOut( _outMutex );
|
||||||
|
|
||||||
return (getWorkQueue().size() + getCompleteQueue().size()) == 0;
|
return (_workQueue.size() + _completeQueue.size()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <engine/Animator.hpp>
|
#include <engine/Animator.hpp>
|
||||||
#include <objects/GameObject.hpp>
|
#include <objects/GameObject.hpp>
|
||||||
#include "ViewerWidget.hpp"
|
#include "ViewerWidget.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
ModelViewer::ModelViewer(ViewerWidget* viewer, QWidget* parent, Qt::WindowFlags f)
|
||||||
: ViewerInterface(parent, f), viewing(nullptr), skeleton(nullptr)
|
: ViewerInterface(parent, f), viewing(nullptr), skeleton(nullptr)
|
||||||
|
Loading…
Reference in New Issue
Block a user