mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 03:00:58 -06:00
Correctly rollback the previous rollback
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
@@ -43,6 +44,8 @@ public:
|
||||
|
||||
SyncBuffer(size_t n);
|
||||
|
||||
~SyncBuffer();
|
||||
|
||||
void encode(const std::string& s) {
|
||||
const size_t size = sizeof(char) * s.size() + sizeof(int32_t);
|
||||
ghoul_assert(_encodeOffset + size < _n, "");
|
||||
@@ -107,7 +110,7 @@ private:
|
||||
size_t _encodeOffset;
|
||||
size_t _decodeOffset;
|
||||
std::vector<char> _dataStream;
|
||||
sgct::SharedVector<char> _synchronizationBuffer;
|
||||
std::unique_ptr<sgct::SharedVector<char>> _synchronizationBuffer;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -32,22 +32,29 @@ SyncBuffer::SyncBuffer(size_t n)
|
||||
: _n(n)
|
||||
, _encodeOffset(0)
|
||||
, _decodeOffset(0)
|
||||
, _synchronizationBuffer(new sgct::SharedVector<char>())
|
||||
{
|
||||
_dataStream.resize(_n);
|
||||
}
|
||||
|
||||
SyncBuffer::~SyncBuffer() {
|
||||
// The destructor is defined here, so that the otherwise default inlined destructor is
|
||||
// not created (which would make it impossible to use a forward declaration with
|
||||
// unique_ptr
|
||||
}
|
||||
|
||||
void SyncBuffer::write() {
|
||||
_synchronizationBuffer.setVal(_dataStream);
|
||||
sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
|
||||
_synchronizationBuffer->setVal(_dataStream);
|
||||
sgct::SharedData::instance()->writeVector(_synchronizationBuffer.get());
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
}
|
||||
|
||||
void SyncBuffer::read() {
|
||||
sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
|
||||
_dataStream = std::move(_synchronizationBuffer.getVal());
|
||||
sgct::SharedData::instance()->readVector(_synchronizationBuffer.get());
|
||||
_dataStream = std::move(_synchronizationBuffer->getVal());
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user