Merge branch 'master' into feature/DU

This commit is contained in:
Jonathas Costa
2017-10-04 09:36:37 -04:00
77 changed files with 1635 additions and 224 deletions
@@ -69,8 +69,8 @@ public:
static const std::string KeyFactoryDocumentation;
/// The key that stores the location of the scene file that is initially loaded
static const std::string KeyConfigScene;
/// The key that stores the location of the tasks file that is initially loaded
static const std::string KeyConfigTask;
/// The key that stores the location of the tasks files
static const std::string KeyConfigTasksRoot;
/// The key that stores the subdirectory containing a list of all startup scripts to
/// be executed on application start before the scene file is loaded
static const std::string KeyStartupScript;
@@ -46,7 +46,6 @@ namespace ghoul::opengl {
namespace openspace {
class RenderableVolume;
class Camera;
class Scene;
@@ -0,0 +1,73 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___CONCURRENT_JOB_MANAGER___H__
#define __OPENSPACE_CORE___CONCURRENT_JOB_MANAGER___H__
#include <openspace/util/concurrentqueue.h>
#include <openspace/util/threadpool.h>
#include <mutex>
namespace openspace {
// Templated abstract base class representing a job to be done.
// Client code derive from this class and implement the virtual execute() method
template<typename P>
struct Job {
Job();
virtual ~Job();
virtual void execute() = 0;
virtual std::shared_ptr<P> product() = 0;
};
/*
* Templated Concurrent Job Manager
* This class is used execute specific jobs on one (1) parallell thread
*/
template<typename P>
class ConcurrentJobManager {
public:
ConcurrentJobManager(ThreadPool pool);
void enqueueJob(std::shared_ptr<Job<P>> job);
void clearEnqueuedJobs();
std::shared_ptr<Job<P>> popFinishedJob();
size_t numFinishedJobs() const;
private:
ConcurrentQueue<std::shared_ptr<Job<P>>> _finishedJobs;
std::mutex _finishedJobsMutex;
ThreadPool threadPool;
};
} // namespace openspace
#include "concurrentjobmanager.inl"
#endif // __OPENSPACE_CORE___CONCURRENT_JOB_MANAGER___H__
@@ -0,0 +1,66 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <ghoul/misc/assert.h>
namespace openspace {
template<typename P>
Job<P>::Job() {}
template<typename P>
Job<P>::~Job() {}
template<typename P>
ConcurrentJobManager<P>::ConcurrentJobManager(ThreadPool pool)
: threadPool(pool)
{ }
template<typename P>
void ConcurrentJobManager<P>::enqueueJob(std::shared_ptr<Job<P>> job) {
threadPool.enqueue([this, job]() {
job->execute();
std::lock_guard<std::mutex> lock(_finishedJobsMutex);
_finishedJobs.push(job);
});
}
template<typename P>
void ConcurrentJobManager<P>::clearEnqueuedJobs() {
threadPool.clearTasks();
}
template<typename P>
std::shared_ptr<Job<P>> ConcurrentJobManager<P>::popFinishedJob() {
ghoul_assert(_finishedJobs.size() > 0, "There is no finished job to pop!");
std::lock_guard<std::mutex> lock(_finishedJobsMutex);
return _finishedJobs.pop();
}
template<typename P>
size_t ConcurrentJobManager<P>::numFinishedJobs() const {
return _finishedJobs.size();
}
} // namespace openspace
+60
View File
@@ -0,0 +1,60 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___CONCURRENT_QUEUE___H__
#define __OPENSPACE_CORE___CONCURRENT_QUEUE___H__
#include <condition_variable>
#include <mutex>
#include <queue>
namespace openspace {
/**
* Templated thread-safe queue based on std::thread and std::queue
*/
template <typename T>
class ConcurrentQueue {
public:
T pop();
void pop(T& item);
void push(const T& item);
void push(T&& item);
size_t size() const;
private:
std::queue<T> _queue;
mutable std::mutex _mutex;
mutable std::condition_variable _cond;
};
} // namespace openspace
#include "concurrentqueue.inl"
#endif // __OPENSPACE_CORE___CONCURRENT_QUEUE___H__
@@ -0,0 +1,73 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
namespace openspace {
template <typename T>
T ConcurrentQueue<T>::pop() {
std::unique_lock<std::mutex> mlock(_mutex);
while (_queue.empty()) {
_cond.wait(mlock);
}
auto item = _queue.front();
_queue.pop();
return item;
}
template <typename T>
void ConcurrentQueue<T>::pop(T& item) {
std::unique_lock<std::mutex> mlock(_mutex);
while (_queue.empty()) {
_cond.wait(mlock);
}
item = _queue.front();
_queue.pop();
}
template <typename T>
void ConcurrentQueue<T>::push(const T& item) {
std::unique_lock<std::mutex> mlock(_mutex);
_queue.push(item);
mlock.unlock();
_cond.notify_one();
}
template <typename T>
void ConcurrentQueue<T>::push(T&& item) {
std::unique_lock<std::mutex> mlock(_mutex);
_queue.push(std::move(item));
mlock.unlock();
_cond.notify_one();
}
template <typename T>
size_t ConcurrentQueue<T>::size() const {
std::unique_lock<std::mutex> mlock(_mutex);
size_t s = _queue.size();
mlock.unlock();
_cond.notify_one();
return s;
}
} // namespace openspace
+74
View File
@@ -0,0 +1,74 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2017 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___THREAD_POOL___H__
#define __OPENSPACE_CORE___THREAD_POOL___H__
#include <condition_variable>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
#include <atomic>
// Implementatin based on http://progsch.net/wordpress/?p=81
namespace openspace {
class ThreadPool;
class Worker {
public:
Worker(ThreadPool& pool);
void operator()();
private:
ThreadPool& pool;
};
class ThreadPool {
public:
ThreadPool(size_t numThreads);
ThreadPool(const ThreadPool& toCopy);
~ThreadPool();
void enqueue(std::function<void()> f);
void clearTasks();
private:
friend class Worker;
std::vector<std::thread> workers;
std::deque<std::function<void()>> tasks;
std::mutex queue_mutex;
std::condition_variable condition;
bool stop;
};
} // namespace openspace
#endif // __OPENSPACE_CORE___THREAD_POOL___H__
+3
View File
@@ -42,8 +42,11 @@ public:
void removeKeyframesBefore(double timestamp);
void removeKeyframesAfter(double timestamp);
void clearKeyframes();
void setTimeNextFrame(Time t);
size_t nKeyframes() const;
private:
bool _shouldSetTime;
Time _timeNextFrame;
Timeline<Time> _timeline;
SyncData<Time> _currentTime;
void consumeKeyframes(double dt);