diff --git a/CMakeLists.txt b/CMakeLists.txt index 685a151..f069b95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ set(EHS_SOURCES include/ehs/ShdPtr.h include/ehs/WkPtr.h - src/database/DVar.cpp include/ehs/database/DVar.h + src/db/DbVarTmpl.cpp include/ehs/db/DbVarTmpl.h src/system/CPU.cpp include/ehs/system/CPU.h src/system/Thread.cpp include/ehs/system/Thread.h @@ -162,6 +162,18 @@ set(EHS_SOURCES src/io/hid/Input.cpp include/ehs/io/hid/Input.h src/io/model/MdlCodec.cpp include/ehs/io/mdl/MdlCodec.h + include/ehs/io/UsbBase.h + src/io/UsbBase.cpp + include/ehs/io/Usb_LNX.h + src/io/Usb_LNX.cpp + include/ehs/db/DbType.h + src/db/DbType.cpp + include/ehs/db/DbTable.h + include/ehs/db/DbObject.h + include/ehs/db/DbVar.h + src/db/DbVar.cpp + include/ehs/db/Database.h + src/db/DbObject.cpp ) if (IS_OS_WINDOWS) diff --git a/include/ehs/Math.h b/include/ehs/Math.h index 2f7bbbb..9184a94 100644 --- a/include/ehs/Math.h +++ b/include/ehs/Math.h @@ -101,29 +101,73 @@ namespace ehs return from * 57.295779513082320876798154814105; } + template + static T Exp(const T x) + { + T sum = 1; + T term = 1; + + for (int n = 1; n <= 20; ++n) + { + term *= x / n; + sum += term; + } + + return sum; + } + + template + static T Ln(T x) + { + if (x <= 0) + return -1; + + T result = 0; + + x = (x - 1) / (x + 1); + + for (int i = 1; i <= 19; i += 2) + result += (1 / i) * Exp(x * i); + + return 2 * result; + } + /// A method for use of exponents. /// @tparam T The data type to return; /// @tparam I The data type to use as the exponent. /// @param [in] from The value to use the exponent on. /// @param [in] of The exponent. /// @returns The result. - template - static T Pow(const T from, const I of) + template + static T Pow(const T base, const I exponent) { - if (of < 0) - { - if (from == 0) - return -0; + if (base == 0) + return 0; - return 1 / (from * Pow(from, (-of) - 1)); - } + if (exponent == 0) + return 1; - if (of == 0) - return 1; - else if (of == 1) - return from; + UInt_32 exponentIsInteger = exponent == (UInt_32)exponent; + UInt_32 baseIsNegative = base < 0; - return from * Pow(from, of - 1); + if (baseIsNegative && exponentIsInteger) + { + T result = Exp(exponent * Ln(-base)); + if (Mod((float)exponent, 2.0f) != 0) + result = -result; + + return result; + } + else if (!baseIsNegative) + return Exp(exponent * Ln(base)); + + return 0; + } + + template + static T Log10(const T x) + { + return Ln(x) / Ln(10); } static float Near(const float from); diff --git a/include/ehs/Serializer.h b/include/ehs/Serializer.h index d832308..8b08255 100644 --- a/include/ehs/Serializer.h +++ b/include/ehs/Serializer.h @@ -1078,8 +1078,8 @@ namespace ehs bool sizeKnown = size; if (!sizeKnown) - while (&data[offset + sizeof(T) * size]) - size++; + while (((T*)&data[offset])[size]) + ++size; Str result(size); @@ -1090,14 +1090,14 @@ namespace ehs else for (N i = 0; i < size; ++i) for (N b = 0; b < sizeof(T); ++b) - ((Byte*)&result[i])[sizeof(T) - i - 1] = data[offset + sizeof(T) * i + b]; + ((Byte*)&result[i])[b] = data[offset + sizeof(T) * i + b]; } else { if (endianness == Endianness::LE) for (N i = 0; i < size; ++i) for (N b = 0; b < sizeof(T); ++b) - ((Byte*)&result[i])[sizeof(T) - i - 1] = data[offset + sizeof(T) * i + b]; + ((Byte*)&result[i])[b] = data[offset + sizeof(T) * i + b]; else Util::Copy(&result[0], &data[offset], result.Size(true)); } diff --git a/include/ehs/Types.h b/include/ehs/Types.h index 0371795..9ebc69b 100644 --- a/include/ehs/Types.h +++ b/include/ehs/Types.h @@ -1,6 +1,7 @@ #pragma once #include "ehs/system/OS.h" +#include "ehs/system/Architecture.h" #define EHS_MAX_PATH 0x104 #define EHS_UINT_8_MAX 0xFF @@ -25,6 +26,12 @@ #define EHS_LDOUBLE_MAX 1.79769e+308 #define EHS_LDOUBLE_MIN 2.22507e-308 +#if defined(EHS_64_BIT) + #define EHS_SIZE_MAX 0xFFFFFFFFFFFFFFFF +#elif defined(EHS_32_BIT) + #define EHS_SIZE_MAX 0xFFFFFFFF +#endif + #define EHS_INFINITE EHS_UINT_32_MAX namespace ehs @@ -52,4 +59,10 @@ namespace ehs typedef signed long SInt_64; typedef long Int_64; #endif + + #if defined(EHS_64_BIT) + typedef UInt_64 Size; + #elif defined(EHS_32_BIT) + typedef UInt_32 Size; + #endif } \ No newline at end of file diff --git a/include/ehs/database/DVar.h b/include/ehs/database/DVar.h deleted file mode 100644 index 40551cd..0000000 --- a/include/ehs/database/DVar.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "ehs/EHS.h" -#include "ehs/BaseObj.h" -#include "ehs/Str.h" - -namespace ehs -{ - enum class DType : UInt_8 - { - - }; - - class DVar : public BaseObj - { - private: - Str_8 id; - UInt_64 hashId; - }; -} diff --git a/include/ehs/db/Database.h b/include/ehs/db/Database.h new file mode 100644 index 0000000..3e1958c --- /dev/null +++ b/include/ehs/db/Database.h @@ -0,0 +1,36 @@ +#pragma once + +#include "ehs/Array.h" +#include "DbTable.h" + +namespace ehs +{ + class Database + { + private: + UInt_64 hashId; + Str_8 id; + Array tables; + + public: + Database(); + + Database(const Str_8& filePath); + + UInt_64 GetHashId() const; + + Str_8 GetId() const; + + bool HasTable(UInt_64 hashId) const; + + bool HasTable(Str_8& id) const; + + bool CreateTable(Str_8 id); + + DbTable* GetTable(UInt_64 hashId) const; + + DbTable* GetTable(Str_8& id) const; + + void Save(); + }; +} \ No newline at end of file diff --git a/include/ehs/db/DbObject.h b/include/ehs/db/DbObject.h new file mode 100644 index 0000000..5d0c84a --- /dev/null +++ b/include/ehs/db/DbObject.h @@ -0,0 +1,47 @@ +#pragma once + +#include "ehs/Array.h" +#include "DbVar.h" + +namespace ehs +{ + class DbTable; + + class DbObject + { + private: + friend class DbTable; + + UInt_64 id; + Array vars; + bool loaded; + DbTable* parent; + + public: + DbObject(); + + DbObject(DbObject&& obj) noexcept; + + DbObject(const DbObject& obj); + + DbObject& operator=(DbObject&& obj) noexcept; + + DbObject& operator=(const DbObject& obj); + + UInt_64 GetId(); + + bool HasVariable(UInt_64 hashId); + + DbVar* GetVariable(UInt_64 hashId) const; + + void Save(); + + void Load(); + + bool IsLoaded() const; + + void Free(); + + DbTable* GetParent() const; + }; +} \ No newline at end of file diff --git a/include/ehs/db/DbTable.h b/include/ehs/db/DbTable.h new file mode 100644 index 0000000..e5696af --- /dev/null +++ b/include/ehs/db/DbTable.h @@ -0,0 +1,36 @@ +#pragma once + +#include "ehs/Version.h" +#include "ehs/Array.h" +#include "DbVarTmpl.h" +#include "DbObject.h" + +namespace ehs +{ + class DbTable + { + private: + UInt_64 hashId; + Str_8 id; + Version version; + Array varTmpls; + Array objects; + + public: + DbTable(); + + DbTable(); + + UInt_64 GetHashId() const; + + Str_8 GetId() const; + + Version GetVersion() const; + + bool CreateVariable(Str_8 id, DbType type); + + bool CreateVariable(Str_8 id, DbType type, UInt_64 size); + + void Save(); + }; +} diff --git a/include/ehs/db/DbType.h b/include/ehs/db/DbType.h new file mode 100644 index 0000000..76096cd --- /dev/null +++ b/include/ehs/db/DbType.h @@ -0,0 +1,26 @@ +#pragma once + +#include "ehs/Types.h" + +namespace ehs +{ + enum class DbType : UInt_8 + { + SINT_64, + UINT_64, + SINT_32, + UINT_32, + SINT_16, + UINT_16, + SINT_8, + UINT_8, + FLOAT, + DOUBLE, + BOOLEAN, + CHAR_32, + CHAR_16, + CHAR_8 + }; + + constexpr UInt_8 DbTypeToSize(DbType type); +} diff --git a/include/ehs/db/DbVar.h b/include/ehs/db/DbVar.h new file mode 100644 index 0000000..eb0e57d --- /dev/null +++ b/include/ehs/db/DbVar.h @@ -0,0 +1,37 @@ +#pragma once + +#include "ehs/Types.h" + +namespace ehs +{ + class DbVar + { + private: + UInt_64 hashId; + UInt_64 size; + Byte* data; + + public: + ~DbVar(); + + DbVar(); + + DbVar(UInt_64 hashId, UInt_64 size, Byte* data); + + DbVar(DbVar&& var) noexcept; + + DbVar(const DbVar& var); + + DbVar& operator=(DbVar&& var) noexcept; + + DbVar& operator=(const DbVar& var); + + explicit operator Byte*() const; + + UInt_64 GetHashId() const; + + UInt_64 GetSize() const; + + Byte* GetData() const; + }; +} \ No newline at end of file diff --git a/include/ehs/db/DbVarTmpl.h b/include/ehs/db/DbVarTmpl.h new file mode 100644 index 0000000..ab92b0a --- /dev/null +++ b/include/ehs/db/DbVarTmpl.h @@ -0,0 +1,45 @@ +#pragma once + +#include "DbType.h" +#include "ehs/EHS.h" +#include "ehs/BaseObj.h" +#include "ehs/Str.h" + +namespace ehs +{ + class DbVarTmpl : public BaseObj + { + private: + UInt_64 hashId; + Str_8 id; + DbType type; + bool array; + + public: + DbVarTmpl(); + + DbVarTmpl(Str_8 id, DbType type, bool array); + + DbVarTmpl(DbVarTmpl&& varTmpl) noexcept; + + DbVarTmpl(const DbVarTmpl& varTmpl); + + DbVarTmpl& operator=(DbVarTmpl&& varTmpl) noexcept; + + DbVarTmpl& operator=(const DbVarTmpl& varTmpl); + + UInt_64 GetHashId() const; + + void SetId(Str_8 newId); + + Str_8 GetId() const; + + void SetType(DbType newType); + + DbType GetType() const; + + void SetIsArray(bool value); + + bool IsArray() const; + }; +} diff --git a/include/ehs/io/UsbBase.h b/include/ehs/io/UsbBase.h new file mode 100644 index 0000000..9994cf5 --- /dev/null +++ b/include/ehs/io/UsbBase.h @@ -0,0 +1,48 @@ +#pragma once + +#include "ehs/Types.h" + +namespace ehs +{ + class UsbBase + { + private: + UInt_32 bus; + UInt_32 address; + + public: + virtual ~UsbBase() = default; + + UsbBase(); + + UsbBase(UInt_32 bus, UInt_32 address); + + UsbBase(UsbBase&& usb) noexcept; + + UsbBase(const UsbBase& usb); + + UsbBase& operator=(UsbBase&& usb) noexcept; + + UsbBase& operator=(const UsbBase& usb); + + virtual void Initialize() = 0; + + virtual void Release() = 0; + + virtual bool IsInitialized() const = 0; + + virtual Size Send(const Byte* data, Size size) = 0; + + void BulkSend(const Byte* data, Size size); + + virtual Size Receive(Byte* data, Size size) = 0; + + void BulkReceive(Byte** data, Size* size); + + UInt_32 GetBus() const; + + UInt_32 GetAddress() const; + + bool IsValid() const; + }; +} \ No newline at end of file diff --git a/include/ehs/io/Usb_LNX.h b/include/ehs/io/Usb_LNX.h new file mode 100644 index 0000000..ea60e04 --- /dev/null +++ b/include/ehs/io/Usb_LNX.h @@ -0,0 +1,34 @@ +#pragma once + +#include "UsbBase.h" +#include "File.h" + +namespace ehs +{ + class Usb final : public UsbBase + { + private: + int hdl; + + public: + ~Usb() override; + + Usb(); + + Usb(UInt_32 bus, UInt_32 address); + + Usb(Usb&& usb) noexcept; + + Usb(const Usb& usb); + + Usb& operator=(Usb&& usb) noexcept; + + Usb& operator=(const Usb& usb); + + void Initialize() override; + + void Release() override; + + bool IsInitialized() const override; + }; +} \ No newline at end of file diff --git a/include/ehs/system/Architecture.h b/include/ehs/system/Architecture.h index f854eb1..da29911 100644 --- a/include/ehs/system/Architecture.h +++ b/include/ehs/system/Architecture.h @@ -3,9 +3,11 @@ #if defined(_M_AMD64) || defined(_M_X64) || defined(__x86_64__) #define EHS_LITTLE_ENDIAN #define EHS_ARCH_X64 + #define EHS_64_BIT #elif defined(_M_ARM64) || defined(__aarch64__) -#define EHS_LITTLE_ENDIAN + #define EHS_LITTLE_ENDIAN #define EHS_ARCH_ARM64 + #define EHS_64_BIT #else #error Unsupported architecture. #endif \ No newline at end of file diff --git a/src/database/DVar.cpp b/src/database/DVar.cpp deleted file mode 100644 index ae53a17..0000000 --- a/src/database/DVar.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "ehs/database/DVar.h" - -namespace ehs -{ -} \ No newline at end of file diff --git a/src/db/DbObject.cpp b/src/db/DbObject.cpp new file mode 100644 index 0000000..f923bba --- /dev/null +++ b/src/db/DbObject.cpp @@ -0,0 +1,98 @@ +#include "ehs/db/DbObject.h" + +namespace ehs +{ + DbObject::DbObject() + : id(0), loaded(false), parent(nullptr) + { + } + + DbObject::DbObject(DbObject&& obj) noexcept + : id(obj.id), vars((Array&&)obj.vars), loaded(obj.loaded), parent(obj.parent) + { + obj.id = 0; + obj.loaded = false; + obj.parent = nullptr; + } + + DbObject::DbObject(const DbObject& obj) + : id(obj.id), vars(obj.vars), loaded(obj.loaded), parent(obj.parent) + { + } + + DbObject& DbObject::operator=(DbObject&& obj) noexcept + { + if (this == &obj) + return *this; + + id = obj.id; + vars = (Array&&)obj.vars; + loaded = obj.loaded; + parent = obj.parent; + + obj.id = 0; + obj.loaded = false; + obj.parent = nullptr; + + return *this; + } + + DbObject& DbObject::operator=(const DbObject& obj) + { + if (this == &obj) + return *this; + + id = obj.id; + vars = obj.vars; + loaded = obj.loaded; + parent = obj.parent; + + return *this; + } + + UInt_64 DbObject::GetId() + { + return id; + } + + bool DbObject::HasVariable(UInt_64 hashId) + { + for (UInt_64 i = 0; i < vars.Size(); ++i) + if (vars[i].GetHashId() == hashId) + return true; + + return false; + } + + DbVar* DbObject::GetVariable(UInt_64 hashId) const + { + for (UInt_64 i = 0; i < vars.Size(); ++i) + if (vars[i].GetHashId() == hashId) + return &vars[i]; + + return nullptr; + } + + void DbObject::Save() + { + } + + void DbObject::Load() + { + } + + bool DbObject::IsLoaded() const + { + return loaded; + } + + void DbObject::Free() + { + vars.Clear(); + } + + DbTable* DbObject::GetParent() const + { + return parent; + } +} diff --git a/src/db/DbType.cpp b/src/db/DbType.cpp new file mode 100644 index 0000000..5f83f28 --- /dev/null +++ b/src/db/DbType.cpp @@ -0,0 +1,39 @@ +#include "ehs/db/DbType.h" + +namespace ehs +{ + constexpr UInt_8 DbTypeToSize(const DbType type) + { + switch (type) + { + case DbType::SINT_64: + return 8; + case DbType::UINT_64: + return 8; + case DbType::SINT_32: + return 4; + case DbType::UINT_32: + return 4; + case DbType::SINT_16: + return 2; + case DbType::UINT_16: + return 2; + case DbType::SINT_8: + return 1; + case DbType::UINT_8: + return 1; + case DbType::FLOAT: + return 4; + case DbType::DOUBLE: + return 8; + case DbType::BOOLEAN: + return 1; + case DbType::CHAR_32: + return 4; + case DbType::CHAR_16: + return 2; + case DbType::CHAR_8: + return 1; + } + } +} \ No newline at end of file diff --git a/src/db/DbVar.cpp b/src/db/DbVar.cpp new file mode 100644 index 0000000..2ce0930 --- /dev/null +++ b/src/db/DbVar.cpp @@ -0,0 +1,84 @@ +#include "ehs/db/DbVar.h" + +namespace ehs +{ + DbVar::~DbVar() + { + delete[] data; + } + + DbVar::DbVar() + : hashId(0), size(0), data(nullptr) + { + } + + DbVar::DbVar(UInt_64 hashId, UInt_64 size, Byte* data) + : hashId(hashId), size(size), data(data) + { + } + + DbVar::DbVar(DbVar&& var) noexcept + : hashId(var.hashId), size(var.size), data(var.data) + { + var.hashId = 0; + var.size = 0; + var.data = nullptr; + } + + DbVar::DbVar(const DbVar& var) + : hashId(0), size(0), data(nullptr) + { + } + + DbVar& DbVar::operator=(DbVar&& var) noexcept + { + if (this == &var) + return *this; + + delete[] data; + + hashId = var.hashId; + size = var.size; + data = var.data; + + var.hashId = 0; + var.size = 0; + var.data = nullptr; + + return *this; + } + + DbVar& DbVar::operator=(const DbVar& var) + { + if (this == &var) + return *this; + + delete[] data; + + hashId = 0; + size = 0; + data = nullptr; + + return *this; + } + + DbVar::operator Byte*() const + { + return data; + } + + UInt_64 DbVar::GetHashId() const + { + return hashId; + } + + UInt_64 DbVar::GetSize() const + { + return size; + } + + Byte* DbVar::GetData() const + { + return data; + } +} diff --git a/src/db/DbVarTmpl.cpp b/src/db/DbVarTmpl.cpp new file mode 100644 index 0000000..df1c0c9 --- /dev/null +++ b/src/db/DbVarTmpl.cpp @@ -0,0 +1,93 @@ +#include "ehs/db/DbVarTmpl.h" + +namespace ehs +{ + DbVarTmpl::DbVarTmpl() + : hashId(0), type(DbType::SINT_64), array(false) + { + } + + DbVarTmpl::DbVarTmpl(Str_8 id, DbType type, bool array) + : hashId(id.Hash_64()), id((Str_8&&)id), type(type), array(array) + { + } + + DbVarTmpl::DbVarTmpl(DbVarTmpl&& varTmpl) noexcept + : hashId(varTmpl.hashId), id((Str_8&&)varTmpl.id), type(varTmpl.type), array(varTmpl.array) + { + varTmpl.hashId = 0; + varTmpl.type = DbType::SINT_64; + varTmpl.array = false; + } + + DbVarTmpl::DbVarTmpl(const DbVarTmpl& varTmpl) + : hashId(varTmpl.hashId), id(varTmpl.id), type(varTmpl.type), array(varTmpl.array) + { + } + + DbVarTmpl& DbVarTmpl::operator=(DbVarTmpl&& varTmpl) noexcept + { + if (this == &varTmpl) + return *this; + + hashId = varTmpl.hashId; + id = (Str_8&&)varTmpl.id; + type = varTmpl.type; + array = varTmpl.array; + + varTmpl.hashId = 0; + varTmpl.type = DbType::SINT_64; + varTmpl.array = false; + + return *this; + } + + DbVarTmpl& DbVarTmpl::operator=(const DbVarTmpl& varTmpl) + { + if (this == &varTmpl) + return *this; + + hashId = varTmpl.hashId; + id = varTmpl.id; + type = varTmpl.type; + array = varTmpl.array; + + return *this; + } + + UInt_64 DbVarTmpl::GetHashId() const + { + return hashId; + } + + void DbVarTmpl::SetId(Str_8 newId) + { + hashId = newId.Hash_64(); + id = (Str_8&&)newId; + } + + Str_8 DbVarTmpl::GetId() const + { + return id; + } + + void DbVarTmpl::SetType(DbType newType) + { + type = newType; + } + + DbType DbVarTmpl::GetType() const + { + return type; + } + + void DbVarTmpl::SetIsArray(bool value) + { + array = value; + } + + bool DbVarTmpl::IsArray() const + { + return array; + } +} diff --git a/src/io/UsbBase.cpp b/src/io/UsbBase.cpp new file mode 100644 index 0000000..4eb5576 --- /dev/null +++ b/src/io/UsbBase.cpp @@ -0,0 +1,97 @@ +#include "ehs/io/UsbBase.h" +#include "ehs/Util.h" + +#include + +namespace ehs +{ + UsbBase::UsbBase() + : bus(0), address(0) + { + } + + UsbBase::UsbBase(const UInt_32 bus, const UInt_32 address) + : bus(bus), address(address) + { + } + + UsbBase::UsbBase(UsbBase&& usb) noexcept + : bus(usb.bus), address(usb.address) + { + usb.bus = 0; + usb.address = 0; + } + + UsbBase::UsbBase(const UsbBase& usb) + : bus(usb.bus), address(usb.address) + { + } + + UsbBase& UsbBase::operator=(UsbBase&& usb) noexcept + { + if (this == &usb) + return *this; + + bus = usb.bus; + address = usb.address; + + usb.bus = 0; + usb.address = 0; + + return *this; + } + + UsbBase& UsbBase::operator=(const UsbBase& usb) + { + if (this == &usb) + return *this; + + bus = usb.bus; + address = usb.address; + + return *this; + } + + void UsbBase::BulkSend(const Byte* const data, const Size size) + { + Size out = 0; + while (out < size) + out = Send(&data[out], size); + } + + void UsbBase::BulkReceive(Byte** data, Size* size) + { + Byte *result = nullptr; + Size total = 0; + Size in; + do + { + Byte *resize = new Byte[(total + *size) / *size]; + Util::Copy(resize, result, total); + + in = Receive(&resize[total], *size); + total += in; + + delete[] result; + result = resize; + } + while (in); + + *size = total; + } + + UInt_32 UsbBase::GetBus() const + { + return bus; + } + + UInt_32 UsbBase::GetAddress() const + { + return address; + } + + bool UsbBase::IsValid() const + { + return bus && address; + } +} diff --git a/src/io/Usb_LNX.cpp b/src/io/Usb_LNX.cpp new file mode 100644 index 0000000..96b0af0 --- /dev/null +++ b/src/io/Usb_LNX.cpp @@ -0,0 +1,106 @@ +#include "ehs/io/Usb_LNX.h" + +#include +#include + +namespace ehs +{ + Usb::~Usb() + { + + } + + Usb::Usb() + : hdl(-1) + { + } + + Usb::Usb(const UInt_32 bus, const UInt_32 address) + : UsbBase(bus, address), hdl(-1) + { + Initialize(); + } + + Usb::Usb(Usb&& usb) noexcept + : UsbBase((UsbBase&&)usb), hdl(usb.hdl) + { + usb.hdl = -1; + } + + Usb::Usb(const Usb& usb) + : UsbBase(usb), hdl(-1) + { + Initialize(); + } + + Usb& Usb::operator=(Usb&& usb) noexcept + { + if (this == &usb) + return *this; + + UsbBase::operator=((UsbBase&&)usb); + + hdl = usb.hdl; + + usb.hdl = -1; + + return *this; + } + + Usb& Usb::operator=(const Usb& usb) + { + if (this == &usb) + return *this; + + UsbBase::operator=(usb); + + hdl = -1; + + Initialize(); + + return *this; + } + + void Usb::Initialize() + { + if (!IsValid()) + { + EHS_LOG_INT("Error", 0, "Cannot initialize with an invalid object."); + return; + } + + if (IsInitialized()) + { + EHS_LOG_INT("Warning", 1, "Object is already initialized."); + return; + } + + hdl = open("/dev/bus/usb/" + Str_8::FromNum(GetBus()) + "/" + Str_8::FromNum(GetAddress()), O_RDWR); + if (hdl == -1) + EHS_LOG_INT("Error", 2, "Failed to connect to USB device."); + } + + void Usb::Release() + { + if (!IsValid()) + { + EHS_LOG_INT("Error", 0, "Cannot release with an invalid object."); + return; + } + + if (!IsInitialized()) + { + EHS_LOG_INT("Warning", 1, "Object is already released."); + return; + } + + close(hdl); + + hdl = -1; + } + + bool Usb::IsInitialized() const + { + return hdl != -1; + } +} diff --git a/src/io/model/Mdl.cpp b/src/io/model/Mdl.cpp index 3bc7007..7ab0b97 100644 --- a/src/io/model/Mdl.cpp +++ b/src/io/model/Mdl.cpp @@ -275,6 +275,7 @@ namespace ehs meshes[i].SetIndices(data.ReadArray()); + /* Bone& skeleton = mdl->GetSkeleton(); UInt_8 boneCount = data.Read(); for (UInt_8 b = 0; b < boneCount; ++b) @@ -328,6 +329,7 @@ namespace ehs } } } + */ } return true;