aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/kernel/inputpersistenceblock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword25/kernel/inputpersistenceblock.cpp')
-rw-r--r--engines/sword25/kernel/inputpersistenceblock.cpp144
1 files changed, 57 insertions, 87 deletions
diff --git a/engines/sword25/kernel/inputpersistenceblock.cpp b/engines/sword25/kernel/inputpersistenceblock.cpp
index b51b1037a7..652c2f362f 100644
--- a/engines/sword25/kernel/inputpersistenceblock.cpp
+++ b/engines/sword25/kernel/inputpersistenceblock.cpp
@@ -34,146 +34,116 @@
#define BS_LOG_PREFIX "INPUTPERSISTENCEBLOCK"
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
-
#include "sword25/kernel/inputpersistenceblock.h"
namespace Sword25 {
-// -----------------------------------------------------------------------------
-// Constructor / Destructor
-// -----------------------------------------------------------------------------
-
-InputPersistenceBlock::InputPersistenceBlock(const void *Data, uint DataLength) :
- m_Data(static_cast<const byte *>(Data), DataLength),
- m_ErrorState(NONE) {
- m_Iter = m_Data.begin();
+InputPersistenceBlock::InputPersistenceBlock(const void *data, uint dataLength) :
+ _data(static_cast<const byte *>(data), dataLength),
+ _errorState(NONE) {
+ _iter = _data.begin();
}
-// -----------------------------------------------------------------------------
-
InputPersistenceBlock::~InputPersistenceBlock() {
- if (m_Iter != m_Data.end()) BS_LOG_WARNINGLN("Persistence block was not read to the end.");
+ if (_iter != _data.end())
+ BS_LOG_WARNINGLN("Persistence block was not read to the end.");
}
-// -----------------------------------------------------------------------------
-// Reading
-// -----------------------------------------------------------------------------
-
-void InputPersistenceBlock::read(int16 &Value) {
+void InputPersistenceBlock::read(int16 &value) {
signed int v;
read(v);
- Value = static_cast<int16>(v);
+ value = static_cast<int16>(v);
}
-// -----------------------------------------------------------------------------
-
-void InputPersistenceBlock::read(signed int &Value) {
- if (CheckMarker(SINT_MARKER)) {
- RawRead(&Value, sizeof(signed int));
- Value = ConvertEndianessFromStorageToSystem(Value);
+void InputPersistenceBlock::read(signed int &value) {
+ if (checkMarker(SINT_MARKER)) {
+ rawRead(&value, sizeof(signed int));
+ value = convertEndianessFromStorageToSystem(value);
} else {
- Value = 0;
+ value = 0;
}
}
-// -----------------------------------------------------------------------------
-
-void InputPersistenceBlock::read(uint &Value) {
- if (CheckMarker(UINT_MARKER)) {
- RawRead(&Value, sizeof(uint));
- Value = ConvertEndianessFromStorageToSystem(Value);
+void InputPersistenceBlock::read(uint &value) {
+ if (checkMarker(UINT_MARKER)) {
+ rawRead(&value, sizeof(uint));
+ value = convertEndianessFromStorageToSystem(value);
} else {
- Value = 0;
+ value = 0;
}
}
-// -----------------------------------------------------------------------------
-
-void InputPersistenceBlock::read(float &Value) {
- if (CheckMarker(FLOAT_MARKER)) {
- RawRead(&Value, sizeof(float));
- Value = ConvertEndianessFromStorageToSystem(Value);
+void InputPersistenceBlock::read(float &value) {
+ if (checkMarker(FLOAT_MARKER)) {
+ rawRead(&value, sizeof(float));
+ value = convertEndianessFromStorageToSystem(value);
} else {
- Value = 0.0f;
+ value = 0.0f;
}
}
-// -----------------------------------------------------------------------------
-
-void InputPersistenceBlock::read(bool &Value) {
- if (CheckMarker(BOOL_MARKER)) {
- uint UIntBool;
- RawRead(&UIntBool, sizeof(float));
- UIntBool = ConvertEndianessFromStorageToSystem(UIntBool);
- Value = UIntBool == 0 ? false : true;
+void InputPersistenceBlock::read(bool &value) {
+ if (checkMarker(BOOL_MARKER)) {
+ uint uintBool;
+ rawRead(&uintBool, sizeof(float));
+ uintBool = convertEndianessFromStorageToSystem(uintBool);
+ value = uintBool == 0 ? false : true;
} else {
- Value = 0.0f;
+ value = 0.0f;
}
}
-// -----------------------------------------------------------------------------
-
-void InputPersistenceBlock::read(Common::String &Value) {
- Value = "";
+void InputPersistenceBlock::readString(Common::String &value) {
+ value = "";
- if (CheckMarker(STRING_MARKER)) {
- uint Size;
- read(Size);
+ if (checkMarker(STRING_MARKER)) {
+ uint size;
+ read(size);
- if (CheckBlockSize(Size)) {
- Value = Common::String(reinterpret_cast<const char *>(&*m_Iter), Size);
- m_Iter += Size;
+ if (checkBlockSize(size)) {
+ value = Common::String(reinterpret_cast<const char *>(&*_iter), size);
+ _iter += size;
}
}
}
-// -----------------------------------------------------------------------------
+void InputPersistenceBlock::readByteArray(Common::Array<byte> &value) {
+ if (checkMarker(BLOCK_MARKER)) {
+ uint size;
+ read(size);
-void InputPersistenceBlock::read(Common::Array<byte> &Value) {
- if (CheckMarker(BLOCK_MARKER)) {
- uint Size;
- read(Size);
-
- if (CheckBlockSize(Size)) {
- Value = Common::Array<byte>(m_Iter, Size);
- m_Iter += Size;
+ if (checkBlockSize(size)) {
+ value = Common::Array<byte>(_iter, size);
+ _iter += size;
}
}
}
-// -----------------------------------------------------------------------------
-
-void InputPersistenceBlock::RawRead(void *DestPtr, size_t Size) {
- if (CheckBlockSize(Size)) {
- memcpy(DestPtr, &*m_Iter, Size);
- m_Iter += Size;
+void InputPersistenceBlock::rawRead(void *destPtr, size_t size) {
+ if (checkBlockSize(size)) {
+ memcpy(destPtr, &*_iter, size);
+ _iter += size;
}
}
-// -----------------------------------------------------------------------------
-
-bool InputPersistenceBlock::CheckBlockSize(int Size) {
- if (m_Data.end() - m_Iter >= Size) {
+bool InputPersistenceBlock::checkBlockSize(int size) {
+ if (_data.end() - _iter >= size) {
return true;
} else {
- m_ErrorState = END_OF_DATA;
+ _errorState = END_OF_DATA;
BS_LOG_ERRORLN("Unexpected end of persistence block.");
return false;
}
}
-// -----------------------------------------------------------------------------
-
-bool InputPersistenceBlock::CheckMarker(byte Marker) {
- if (!isGood() || !CheckBlockSize(1)) return false;
+bool InputPersistenceBlock::checkMarker(byte marker) {
+ if (!isGood() || !checkBlockSize(1))
+ return false;
- if (*m_Iter++ == Marker) {
+ if (*_iter++ == marker) {
return true;
} else {
- m_ErrorState = OUT_OF_SYNC;
+ _errorState = OUT_OF_SYNC;
BS_LOG_ERRORLN("Wrong type marker found in persistence block.");
return false;
}