Some cleanup of ModuleEngine

Some cleanup of SettingsEngine
Some cleanup of SyncEngine
This commit is contained in:
Alexander Bock
2017-03-02 15:43:54 -05:00
parent d6b5bb753b
commit c12bd7182b
12 changed files with 165 additions and 204 deletions

View File

@@ -23,73 +23,67 @@
****************************************************************************************/
#include <openspace/engine/syncengine.h>
#include <openspace/util/syncdata.h>
#include <openspace/util/syncbuffer.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <algorithm>
#include <string>
namespace {
const std::string _loggerCat = "SyncEngine";
}
namespace openspace {
SyncEngine::SyncEngine(SyncBuffer* syncBuffer)
: _syncBuffer(syncBuffer)
{
}
void SyncEngine::presync(bool isMaster) {
for (const auto& syncable : _syncables) {
syncable->presync(isMaster);
}
}
// should be called on sgct master
void SyncEngine::encodeSyncables() {
for (const auto& syncable : _syncables) {
syncable->encode(_syncBuffer.get());
}
_syncBuffer->write();
}
//should be called on sgct slaves
void SyncEngine::decodeSyncables() {
_syncBuffer->read();
for (const auto& syncable : _syncables) {
syncable->decode(_syncBuffer.get());
}
}
void SyncEngine::postsync(bool isMaster) {
for (const auto& syncable : _syncables) {
syncable->postsync(isMaster);
}
}
void SyncEngine::addSyncable(Syncable* syncable) {
_syncables.push_back(syncable);
}
void SyncEngine::addSyncables(const std::vector<Syncable*>& syncables) {
for (const auto& syncable : syncables) {
addSyncable(syncable);
}
}
void SyncEngine::removeSyncable(Syncable* syncable) {
_syncables.erase(
std::remove(_syncables.begin(), _syncables.end(), syncable),
_syncables.end()
);
}
SyncEngine::SyncEngine(unsigned int syncBufferSize)
: _syncBuffer(syncBufferSize)
{
ghoul_assert(syncBufferSize > 0, "syncBufferSize must be bigger than 0");
}
// should be called on sgct master
void SyncEngine::encodeSyncables() {
for (Syncable* syncable : _syncables) {
syncable->encode(&_syncBuffer);
}
_syncBuffer.write();
}
//should be called on sgct slaves
void SyncEngine::decodeSyncables() {
_syncBuffer.read();
for (Syncable* syncable : _syncables) {
syncable->decode(&_syncBuffer);
}
}
void SyncEngine::preSynchronization(IsMaster isMaster) {
for (Syncable* syncable : _syncables) {
syncable->presync(isMaster);
}
}
void SyncEngine::postSynchronization(IsMaster isMaster) {
for (Syncable* syncable : _syncables) {
syncable->postsync(isMaster);
}
}
void SyncEngine::addSyncable(Syncable* syncable) {
ghoul_assert(syncable, "synable must not be nullptr");
_syncables.push_back(syncable);
}
void SyncEngine::addSyncables(const std::vector<Syncable*>& syncables) {
for (Syncable* syncable : syncables) {
ghoul_assert(syncable, "syncables must not contain any nullptr");
addSyncable(syncable);
}
}
void SyncEngine::removeSyncable(Syncable* syncable) {
_syncables.erase(
std::remove(_syncables.begin(), _syncables.end(), syncable),
_syncables.end()
);
}
} // namespace openspace