Remove sgct inclusion from SyncBuffer header and move to the source file

Fix serialization of MatrixProperty
This commit is contained in:
Alexander Bock
2016-07-06 17:52:16 +02:00
parent fb39949daf
commit c9ac04d3cd
3 changed files with 26 additions and 19 deletions

View File

@@ -25,11 +25,16 @@
#ifndef SYNCBUFFER_H
#define SYNCBUFFER_H
#include <vector>
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/misc/assert.h>
#include <sgct.h>
#include <stdint.h>
#include <vector>
namespace sgct {
template <typename T>
class SharedVector;
} // namespace sgct
namespace openspace {
@@ -40,7 +45,7 @@ public:
void encode(const std::string& s) {
const size_t size = sizeof(char) * s.size() + sizeof(int32_t);
assert(_encodeOffset + size < _n);
ghoul_assert(_encodeOffset + size < _n, "");
int32_t length = static_cast<int32_t>(s.length());
memcpy(_dataStream.data() + _encodeOffset, reinterpret_cast<const char*>(&length), sizeof(int32_t));
@@ -52,7 +57,7 @@ public:
template <typename T>
void encode(const T& v) {
const size_t size = sizeof(T);
assert(_encodeOffset + size < _n);
ghoul_assert(_encodeOffset + size < _n, "");
memcpy(_dataStream.data() + _encodeOffset, &v, size);
_encodeOffset += size;
@@ -74,7 +79,7 @@ public:
template <typename T>
T decode() {
const size_t size = sizeof(T);
assert(_decodeOffset + size < _n);
ghoul_assert(_decodeOffset + size < _n, "");
T value;
memcpy(&value, _dataStream.data() + _decodeOffset, size);
_decodeOffset += size;
@@ -88,7 +93,7 @@ public:
template <typename T>
void decode(T& value) {
const size_t size = sizeof(T);
assert(_decodeOffset + size < _n);
ghoul_assert(_decodeOffset + size < _n, "");
memcpy(&value, _dataStream.data() + _decodeOffset, size);
_decodeOffset += size;
}
@@ -102,7 +107,7 @@ private:
size_t _encodeOffset;
size_t _decodeOffset;
std::vector<char> _dataStream;
sgct::SharedVector<char> _synchronizationBuffer;
sgct::SharedVector<char>* _synchronizationBuffer;
};
} // namespace openspace

View File

@@ -39,8 +39,8 @@ namespace properties {
[](lua_State* state, bool& success) -> __TYPE__ { \
__TYPE__ result; \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_rows<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_cols<__TYPE__>::value; ++j) { \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_getfield(state, -1, std::to_string(number).c_str()); \
if (lua_isnumber(state, -1) != 1) { \
success = false; \
@@ -61,8 +61,8 @@ namespace properties {
[](lua_State* state, __TYPE__ value) -> bool { \
lua_newtable(state); \
int number = 1; \
for (glm::length_t i = 0; i < ghoul::glm_rows<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_cols<__TYPE__>::value; ++j) { \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
lua_setfield(state, -2, std::to_string(number).c_str()); \
++number; \
@@ -82,8 +82,8 @@ namespace properties {
return result; \
} \
int number = 0; \
for (glm::length_t i = 0; i < ghoul::glm_rows<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_cols<__TYPE__>::value; ++j) { \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
std::stringstream s(tokens[number]); \
__TYPE__::value_type v; \
s >> v; \
@@ -104,8 +104,8 @@ namespace properties {
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
[](std::string& outValue, __TYPE__ inValue) -> bool { \
outValue = ""; \
for (glm::length_t i = 0; i < ghoul::glm_rows<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_cols<__TYPE__>::value; ++j) { \
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
outValue += std::to_string(inValue[i][j]) + ","; \
} \
outValue.pop_back(); \

View File

@@ -24,6 +24,8 @@
#include <openspace/util/syncbuffer.h>
#include <sgct.h>
namespace openspace {
SyncBuffer::SyncBuffer(size_t n)
@@ -35,15 +37,15 @@ SyncBuffer::SyncBuffer(size_t n)
}
void SyncBuffer::write() {
_synchronizationBuffer.setVal(_dataStream);
sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
_synchronizationBuffer->setVal(_dataStream);
sgct::SharedData::instance()->writeVector(_synchronizationBuffer);
_encodeOffset = 0;
_decodeOffset = 0;
}
void SyncBuffer::read() {
sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
_dataStream = std::move(_synchronizationBuffer.getVal());
sgct::SharedData::instance()->readVector(_synchronizationBuffer);
_dataStream = std::move(_synchronizationBuffer->getVal());
_encodeOffset = 0;
_decodeOffset = 0;
}