Adjusted workflow.
All checks were successful
Build & Release / Windows-AMD64-Build (push) Successful in 1m8s
Build & Release / Linux-AMD64-Build (push) Successful in 1m30s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m21s

This commit is contained in:
2024-02-05 22:25:30 -08:00
commit bcd71cf2b5
251 changed files with 45909 additions and 0 deletions

260
include/ehs/io/BaseFile.h Normal file
View File

@@ -0,0 +1,260 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Vector.h"
#include "ehs/Array.h"
#include "ehs/Serializer.h"
namespace ehs
{
enum class Mode
{
READ,
WRITE,
READ_WRITE
};
enum class Disposition
{
CREATE_PERSISTENT,
CREATE,
OPEN_PERSISTENT,
OPEN,
TRUNCATE
};
/// A cross-platform wrapper class that handles native file input/output.
class BaseFile
{
protected:
Str_8 path;
Str_8 fullName;
Str_8 name;
Str_8 extension;
Mode mode;
Disposition disposition;
public:
/// Frees all native handles.
virtual ~BaseFile() = default;
/// Default members initialization.
BaseFile();
/// Initializes members with the given data.
/// @param [in] filePath The file path to read or write to.
/// @param [in] mode The mode when accessing the file.
/// @param [in] disposition How to handle the file.
BaseFile(const Str_8& filePath, const Mode mode, const Disposition disposition);
BaseFile(BaseFile&& file) noexcept;
/// Copy constructor.
/// @param [in] file The file object to copy from.
BaseFile(const BaseFile& file) = default;
BaseFile& operator=(BaseFile&& file) noexcept;
/// Copy operator.
/// @param [in] file The file object to copy from.
BaseFile& operator=(const BaseFile& file) = default;
virtual operator const Byte*() const = 0;
virtual operator Byte*() = 0;
/// Uninitializes the native handle.
/// @param [in] raiseLog Whether or not to raise a log if already uninitialized. Mostly for deconstructor.
virtual void Release() = 0;
virtual bool IsMapped() const = 0;
virtual UInt_64 MapSize() const = 0;
virtual void Map(const UInt_64 offset, const UInt_64 size) = 0;
virtual void Unmap() = 0;
virtual void FlushMap() = 0;
/// Writes a C-style byte array to the file.
/// @param [in] data The C-style byte array to write to the file.
/// @param [in] size The size of the given C-style byte array.
virtual UInt_64 Write(const Byte* const data, const UInt_64 size) = 0;
/// Writes a C-style string to the file.
/// @tparam T The character data type to use.
/// @param [in] str The C-style string to write to the file.
/// @param [in] size The size of the given C-style string.
void WriteStr_32(const Char_32* const str, const UInt_64 size);
/// Writes a string to the file.
/// @tparam T The character data type to use.
/// @tparam N The data type to use for numbers.
/// @param [in] str The string to write to the file.
void WriteStr_32(const Str_32& str);
/// Writes a C-style string to the file.
/// @tparam T The character data type to use.
/// @param [in] str The C-style string to write to the file.
/// @param [in] size The size of the given C-style string.
void WriteStr_16(const Char_16* const str, const UInt_64 size);
/// Writes a string to the file.
/// @tparam T The character data type to use.
/// @tparam N The data type to use for numbers.
/// @param [in] str The string to write to the file.
void WriteStr_16(const Str_16& str);
/// Writes a C-style string to the file.
/// @tparam T The character data type to use.
/// @param [in] str The C-style string to write to the file.
/// @param [in] size The size of the given C-style string.
void WriteStr_8(const Char_8* const str, const UInt_64 size);
/// Writes a string to the file.
/// @tparam T The character data type to use.
/// @tparam N The data type to use for numbers.
/// @param [in] str The string to write to the file.
void WriteStr_8(const Str_8& str);
/// Writes a vector to the file.
/// @tparam N The data type to use for numbers.
/// @param [in] vec The vector to write to the file.
void WriteVector(const Vector<Byte, UInt_64>& vec);
/// Writes an array to the file.
/// @tparam N The data type to use for numbers.
/// @param [in] arr The array to write to the file.
void WriteArray(const Array<Byte, UInt_64>& arr);
/// Writes a serializer to the file.
/// @tparam N The data type to use for numbers.
/// @param [in] ser The serializer to write to the file.
void WriteSerializer_64(const Serializer<UInt_64>& ser);
/// Writes a serializer to the file.
/// @tparam N The data type to use for numbers.
/// @param [in] ser The serializer to write to the file.
void WriteSerializer_32(const Serializer<UInt_32>& ser);
/// Reads data from the file as a C-style byte array.
/// @param [out] buffer The buffer to store the data read from the file.
/// @param [in] size The size of the given buffer and how much data to read.
virtual UInt_64 Read(Byte* const buffer, const UInt_64 size) = 0;
/// Reads data from the file as a C-style string.
/// @tparam T The character data type to use.
/// @param [out] buffer The buffer to store the data read from the file.
/// @param [in] size The size of the given buffer and how much data to read.
void ReadStr_32(Char_32* const buffer, UInt_64& size);
/// Reads data from the file as a string.
/// @tparam T The character data type to use.
/// @tparam N The data type to use for numbers.
/// @param [in] size The size of the buffer and how much data to read.
/// @returns The resulting string.
Str_32 ReadStr_32(const UInt_64 size);
/// Reads data from the file as a C-style string.
/// @tparam T The character data type to use.
/// @param [out] buffer The buffer to store the data read from the file.
/// @param [in] size The size of the given buffer and how much data to read.
void ReadStr_16(Char_16* const buffer, UInt_64& size);
/// Reads data from the file as a string.
/// @tparam T The character data type to use.
/// @tparam N The data type to use for numbers.
/// @param [in] size The size of the buffer and how much data to read.
/// @returns The resulting string.
Str_16 ReadStr_16(const UInt_64 size);
/// Reads data from the file as a C-style string.
/// @tparam T The character data type to use.
/// @param [out] buffer The buffer to store the data read from the file.
/// @param [in] size The size of the given buffer and how much data to read.
void ReadStr_8(Char_8* const buffer, UInt_64& size);
/// Reads data from the file as a string.
/// @tparam T The character data type to use.
/// @tparam N The data type to use for numbers.
/// @param [in] size The size of the buffer and how much data to read.
/// @returns The resulting string.
Str_8 ReadStr_8(const UInt_64 size);
/// Reads data from the file as a vector.
/// @tparam N The data type to use for numbers.
/// @param [in] size The size of the buffer and how much data to read.
/// @returns The resulting vector.
Vector<Byte, UInt_64> ReadVector(const UInt_64 size);
/// Reads data from the file as an array.
/// @tparam N The data type to use for numbers.
/// @param [in] size The size of the buffer and how much data to read.
/// @returns The resulting array.
Array<Byte, UInt_64> ReadArray(const UInt_64 size);
/// Reads data from the file as a serializer.
/// @tparam N The data type to use for numbers.
/// @param[in] end The Endianness of the data in the file.
/// @param[in] size The size of the buffer and how much data to read.
/// @returns The resulting serializer.
Serializer<UInt_64> ReadSerializer_64(const Endianness end, const UInt_64 size);
/// Reads data from the file as a serializer.
/// @tparam N The data type to use for numbers.
/// @param[in] end The Endianness of the data in the file.
/// @param[in] size The size of the buffer and how much data to read.
/// @returns The resulting serializer.
Serializer<UInt_32> ReadSerializer_32(const Endianness end, const UInt_32 size);
virtual void Seek(UInt_64 index) = 0;
virtual void SeekBeginning() = 0;
virtual void SeekEnd() = 0;
virtual void Truncate(const UInt_64 size) = 0;
/// Retrieves the size of the file.
/// @returns The result.
virtual UInt_64 Size() const = 0;
Str_8 GetPath() const;
Str_8 GetFullName() const;
Str_8 GetName() const;
Str_8 GetExtension() const;
/// Retrieves whether or not this object is valid.
/// @returns The result.
virtual bool IsValid() const = 0;
static void Rename_32(const Str_32& filePath, const Str_32& newName);
static void Rename_16(const Str_16& filePath, const Str_16& newName);
static void Rename_8(const Str_8& filePath, const Str_8& newName);
static Str_32 ParseFullName_32(const Str_32& filePath);
static Str_16 ParseFullName_16(const Str_16& filePath);
static Str_8 ParseFullName_8(const Str_8& filePath);
static Str_32 ParseName_32(const Str_32& filePath);
static Str_16 ParseName_16(const Str_16& filePath);
static Str_8 ParseName_8(const Str_8& filePath);
static Str_32 ParseExt_32(const Str_32& filePath);
static Str_16 ParseExt_16(const Str_16& filePath);
static Str_8 ParseExt_8(const Str_8& filePath);
};
}

View File

@@ -0,0 +1,46 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#define EHS_FE_NONE 0x00
#define EHS_FE_MODIFIED 0x01
#define EHS_FE_DELETED 0x02
#define EHS_FE_MOVED 0x04
#define EHS_FE_OPENED 0x08
namespace ehs
{
class BaseFileMonitor
{
protected:
Str_8 filePath;
public:
virtual ~BaseFileMonitor() = default;
BaseFileMonitor() = default;
BaseFileMonitor(Str_8 filePath);
BaseFileMonitor(BaseFileMonitor&& fm) noexcept;
BaseFileMonitor(const BaseFileMonitor& fm);
BaseFileMonitor& operator=(BaseFileMonitor&& fm) noexcept;
BaseFileMonitor& operator=(const BaseFileMonitor& fm);
virtual void Initialize() = 0;
virtual void Release() = 0;
virtual UInt_8 Poll() = 0;
Str_8 GetFilePath() const;
bool IsValid() const;
virtual bool IsInitialized() const = 0;
};
}

114
include/ehs/io/BaseWindow.h Normal file
View File

@@ -0,0 +1,114 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Vec2.h"
#include "ehs/Rect.h"
#include "ehs/io/hid/Input.h"
namespace ehs
{
enum class WindowState : UInt_8
{
NONE,
FULLSCREEN
};
enum class CursorImg : UInt_8
{
DEFAULT,
I_BEAM
};
class BaseWindow
{
protected:
bool created;
bool focused;
Vec2_s32 cursorPos;
bool cursorVisible;
bool cursorConstrained;
WindowState state;
InputHandler ih;
public:
virtual ~BaseWindow() = default;
BaseWindow();
BaseWindow(const BaseWindow& win);
BaseWindow& operator=(const BaseWindow& win);
virtual void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
virtual void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
virtual void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
virtual void OnCreated() = 0;
virtual void Close() = 0;
virtual void Show() = 0;
virtual void Hide() = 0;
bool IsCreated() const;
virtual bool Poll();
bool HasFocus() const;
void EnableResizing(const bool enable);
bool IsResizable() const;
/// Gets the cursors position on the desktop in pixels.
/// @param [in] relative Whether the position should be relative to the windows client.
/// @returns The current value.
Vec2_s32 GetCursorPos() const;
/// Shows the cursor on the window.
/// @param [in] toggle The new status.
virtual void ShowCursor(bool toggle) = 0;
/// Checks whether the cursor is shown.
/// @returns The current status.
bool IsCursorVisible() const;
virtual void ConstrainCursor(const bool constrain) = 0;
bool IsCursorConstrained() const;
WindowState GetState() const;
const InputHandler* GetInputHandler() const;
virtual void SetTitle_32(const Str_32& newTitle) = 0;
virtual Str_32 GetTitle_32() const = 0;
virtual void SetTitle_16(const Str_16& newTitle) = 0;
virtual Str_16 GetTitle_16() const = 0;
virtual void SetTitle_8(const Str_8& newTitle) = 0;
virtual Str_8 GetTitle_8() const = 0;
virtual void SetPos(const Vec2_s32& newPos) = 0;
virtual Vec2_s32 GetPos() const = 0;
virtual void SetScale(const Vec2_u32& newScale) = 0;
virtual Vec2_u32 GetScale() const = 0;
virtual Serializer<UInt_64> GetClipboard() = 0;
virtual void SetClipboard(Serializer<UInt_64> data) = 0;
virtual void SetCursorImg(const CursorImg img) = 0;
};
}

55
include/ehs/io/COM.h Normal file
View File

@@ -0,0 +1,55 @@
#pragma once
#include "ehs/EHS.h"
namespace ehs
{
enum class Parity : UInt_8
{
NONE,
ODD,
EVEN,
MARK,
SPACE
};
enum class StopBits : UInt_8
{
ONE,
ONE_POINT_FIVE,
TWO
};
class COM
{
private:
UInt_8 port;
UInt_32 baudRate;
UInt_8 byteSize;
Parity parity;
StopBits stopBits;
void* hdl;
bool initialized;
public:
COM();
COM(const UInt_8 port, const UInt_32 baudRate, const UInt_8 byteSize, const Parity parity, const StopBits stopBits);
COM(const COM& com) = default;
void Initialize();
void UnInitialize();
UInt_32 Wait();
void Transmit(const Char_8 data);
UInt_32 Send(const Char_8* data, const UInt_32 size);
UInt_32 Receive(const Char_8* data, const UInt_32 size);
void Flush();
};
}

115
include/ehs/io/Console.h Normal file
View File

@@ -0,0 +1,115 @@
#pragma once
#include "ehs/Str.h"
#include "ehs/UTF.h"
#include "ehs/Array.h"
namespace ehs
{
#if defined(EHS_OS_WINDOWS)
typedef void* ConsoleHdl;
#elif defined(EHS_OS_LINUX)
typedef int ConsoleHdl;
#endif
class Console
{
private:
static ConsoleHdl hdlOut;
static ConsoleHdl hdlIn;
#if defined(EHS_OS_WINDOWS)
static bool isConsole;
#endif
public:
static void Attach();
/// Creates a console using standard input and output.
/// @param [in] inputRequired Whether or not input is required from the console.
static bool Create();
/// Frees the current console being used.
static void Free();
static bool CanRead();
static bool CanWrite();
/// Writes to console using UTF32.
/// @param [in] str The text to write to the console.
/// @param [in] newLine To make a new line after the given text.
/// @warning Has to convert from UTF32 to UTF16 for the Windows API.
static void Write_32(const Str_32& str, const bool newLine = true);
/// Writes to console using UTF16.
/// @param [in] str The text to write to the console.
/// @param [in] newLine To make a new line after the given text.
static void Write_16(const Str_16& str, const bool newLine = true);
/// Writes to console using UTF8.
/// @param [in] str The text to write to the console.
/// @param [in] newLine To make a new line after the given text.
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
static void Write_8(const Str_8& str, const bool newLine = true);
/// Reads from the console using UTF32.
/// @returns The text the user wrote to the console.
/// @warning Has to convert from UTF16 to UTF32 for the Windows API.
static Str_32 Read_32(const UInt_64 bufferSize = 1024);
/// Reads from the console using UTF16.
/// @returns The text the user wrote to the console.
static Str_16 Read_16(const UInt_64 bufferSize = 1024);
/// Reads from the console using UTF8.
/// @returns The text the user wrote to the console.
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
static Str_8 Read_8(const UInt_64 bufferSize = 1024);
/// Clears the console.
static void Clear();
/// Changes the console's title.
/// @param [in] title The text to change the title to.
/// @warning Has to convert from UTF32 to UTF16 for the Windows API.
static void SetTitle_32(const Str_32& title);
/// Changes the console's title.
/// @param [in] title The text to change the title to.
static void SetTitle_16(const Str_16& title);
/// Changes the console's title.
/// @param [in] title The text to change the title to.
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
static void SetTitle_8(const Str_8& title);
/// Retrieves the console's title in UTF32.
/// @returns The console's title.
/// @warning Has to convert from UTF16 to UTF32 for the Windows API.
static Str_32 GetTitle_32();
/// Retrieves the console's title in UTF16.
/// @returns The console's title.
static Str_16 GetTitle_16();
/// Retrieves the console's title in UTF8.
/// @returns The console's title.
/// @warning Has to convert from UTF16 to UTF8 for the Windows API.
static Str_8 GetTitle_8();
/// Retrieves the string used when executing the end application through a command line interface in UTF32.
/// @returns The result.
static Vector<Str_32> GetArgs_32(const UInt_64 bufferSize = 1024);
/// Retrieves the string used when executing the end application through a command line interface in UTF16.
/// @returns The result.
static Vector<Str_16> GetArgs_16(const UInt_64 bufferSize = 1024);
/// Retrieves the string used when executing the end application through a command line interface in UTF8.
/// @returns The result.
static Vector<Str_8> GetArgs_8(const UInt_64 bufferSize = 1024);
//static void* GetHandle();
};
}

9
include/ehs/io/File.h Normal file
View File

@@ -0,0 +1,9 @@
#pragma once
#include "ehs/EHS.h"
#if defined(EHS_OS_WINDOWS)
#include "File_W32.h"
#elif defined(EHS_OS_LINUX)
#include "File_UNX.h"
#endif

View File

@@ -0,0 +1,7 @@
#pragma once
#if defined(EHS_OS_WINDOWS)
#include "FileMonitor_W32.h"
#elif defined(EHS_OS_LINUX)
#include "FileMonitor_UNX.h"
#endif

View File

@@ -0,0 +1,37 @@
#pragma once
#include "ehs/EHS.h"
#include "BaseFileMonitor.h"
namespace ehs
{
class FileMonitor : public BaseFileMonitor
{
private:
int hdl;
int wd;
public:
~FileMonitor();
FileMonitor();
FileMonitor(Str_8 filePath);
FileMonitor(FileMonitor&& fm) noexcept;
FileMonitor(const FileMonitor& fm);
FileMonitor& operator=(FileMonitor&& fm) noexcept;
FileMonitor& operator=(const FileMonitor& fm);
void Initialize() override;
void Release() override;
UInt_8 Poll() override;
bool IsInitialized() const override;
};
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include "ehs/EHS.h"
#include "BaseFileMonitor.h"
namespace ehs
{
class FileMonitor final : public BaseFileMonitor
{
private:
Handle hdl;
FILETIME time;
public:
~FileMonitor() override;
FileMonitor();
FileMonitor(Str_8 filePath);
FileMonitor(FileMonitor&& fm) noexcept;
FileMonitor(const FileMonitor& fm);
FileMonitor& operator=(FileMonitor&& fm) noexcept;
FileMonitor& operator=(const FileMonitor& fm);
void Initialize() override;
void Release() override;
UInt_8 Poll() override;
bool IsInitialized() const override;
};
}

73
include/ehs/io/File_UNX.h Normal file
View File

@@ -0,0 +1,73 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/UTF.h"
#include "ehs/Vector.h"
#include "ehs/Array.h"
#include "ehs/Serializer.h"
#include "BaseFile.h"
namespace ehs
{
class File : public BaseFile
{
private:
int hdl;
void* map;
UInt_64 mapSize;
public:
~File() override;
File();
File(const Str_8& filePath, const Mode mode, const Disposition disposition);
File(File&& file) noexcept;
File(const File& file);
File& operator=(File&& file) noexcept;
File& operator=(const File& file);
operator const Byte*() const override;
operator Byte*() override;
void Release() override;
bool IsMapped() const override;
UInt_64 MapSize() const override;
void Map(const UInt_64 offset, const UInt_64 size) override;
void Unmap() override;
void FlushMap() override;
UInt_64 Write(const Byte* const data, const UInt_64 size) override;
UInt_64 Read(Byte* const buffer, const UInt_64 size) override;
void Seek(UInt_64 index) override;
void SeekBeginning() override;
void SeekEnd() override;
void Truncate(const UInt_64 size) override;
UInt_64 Size() const override;
bool IsValid() const override;
static void Rename_32(const Str_32& filePath, const Str_32& newName);
static void Rename_16(const Str_16& filePath, const Str_16& newName);
static void Rename_8(const Str_8& filePath, const Str_8& newName);
};
}

74
include/ehs/io/File_W32.h Normal file
View File

@@ -0,0 +1,74 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/UTF.h"
#include "ehs/Vector.h"
#include "ehs/Array.h"
#include "ehs/Serializer.h"
#include "BaseFile.h"
namespace ehs
{
class File : public BaseFile
{
private:
HANDLE hdl;
HANDLE map;
Byte* view;
UInt_64 viewSize;
public:
~File() override;
File();
File(const Str_8& filePath, const Mode mode, const Disposition disposition);
File(File&& file) noexcept;
File(const File& file);
File& operator=(File&& file) noexcept;
File& operator=(const File& file);
operator const Byte*() const override;
operator Byte*() override;
void Release() override;
bool IsMapped() const override;
UInt_64 MapSize() const override;
void Map(const UInt_64 offset, const UInt_64 size) override;
void Unmap() override;
void FlushMap() override;
UInt_64 Write(const Byte* const data, const UInt_64 size) override;
UInt_64 Read(Byte* const buffer, const UInt_64 size) override;
void Seek(UInt_64 index) override;
void SeekBeginning() override;
void SeekEnd() override;
void Truncate(const UInt_64 size) override;
UInt_64 Size() const override;
bool IsValid() const override;
static void Rename_32(const Str_32& filePath, const Str_32& newName);
static void Rename_16(const Str_16& filePath, const Str_16& newName);
static void Rename_8(const Str_8& filePath, const Str_8& newName);
};
}

View File

@@ -0,0 +1,69 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Array.h"
#include "Glyph.h"
#include "ehs/Anchor.h"
#include "ehs/io/img/Img.h"
#include "ehs/io/model/Mesh.h"
namespace ehs
{
class FontAtlas : public BaseObj
{
private:
UInt_64 hashId;
Str_8 id;
UInt_64 glyphScale;
Array<Glyph> glyphs;
Vec2_u64 resolution;
UInt_64 size;
Byte* atlas;
public:
~FontAtlas() override;
FontAtlas();
FontAtlas(const Str_8& filePath);
FontAtlas(FontAtlas&& fa) noexcept;
FontAtlas(const FontAtlas& fa);
FontAtlas& operator=(FontAtlas&& fa) noexcept;
FontAtlas& operator=(const FontAtlas& fa);
operator Byte*() const;
void Release();
UInt_64 GetHashId() const;
Str_8 GetId() const;
UInt_64 GetGlyphScale() const;
const Array<Glyph>& GetGlyphs() const;
Glyph GetGlyph(Char_32 code) const;
Vec2_u64 GetResolution() const;
UInt_64 GetSize() const;
bool IsValid() const;
Vec2_f CalculateSize(const Str_8& text) const;
float CalculateWidth(const Str_8& text) const;
float CalculateHeight(const Str_8& text) const;
UInt_64 CalculateIndexAtPoint(const Str_8& text, const Vec2_f& point) const;
Mesh Generate(Anchor anchor, const Str_8& text) const;
};
}

59
include/ehs/io/Glyph.h Normal file
View File

@@ -0,0 +1,59 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Vec2.h"
#include "ehs/Rect.h"
#include "ehs/Serializer.h"
namespace ehs
{
class Glyph
{
private:
Char_32 code;
Vec2_u64 pos;
Vec2_u64 scale;
Rect_f uv;
Vec2_64 bearing;
Vec2_64 advance;
public:
Glyph();
Glyph(Serializer<>& ser);
Glyph(const Char_32 code);
Glyph(const Glyph& glyph);
Glyph& operator=(const Glyph& glyph);
bool operator==(const Glyph& glyph) const;
bool operator!=(const Glyph& glyph) const;
Char_32 GetCode() const;
void SetPos(const Vec2_u64& newPos);
Vec2_u64 GetPos() const;
void SetScale(const Vec2_u64& newScale);
Vec2_u64 GetScale() const;
void SetUV(const Rect_f& newUV);
Rect_f GetUV() const;
void SetBearing(const Vec2_64& newBearing);
Vec2_32 GetBearing() const;
void SetAdvance(const Vec2_64& newAdvance);
Vec2_32 GetAdvance() const;
void Serialize(Serializer<>& ser) const;
};
}

38
include/ehs/io/RIFF.h Normal file
View File

@@ -0,0 +1,38 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Vector.h"
#include "ehs/Serializer.h"
#include "RIFF_Chunk.h"
namespace ehs
{
class RIFF
{
private:
Str_8 type;
Vector<RIFF_Chunk> chunks;
public:
RIFF() = default;
RIFF(const Str_8& filePath);
RIFF(Serializer<>& data);
RIFF(const RIFF& riff) = default;
operator const RIFF_Chunk*() const;
Str_8 GetType() const;
bool HasChunk(const UInt_64 hashId) const;
bool HasChunk(const Str_8& id) const;
RIFF_Chunk GetChunk(const UInt_64 hashId) const;
RIFF_Chunk GetChunk(const Str_8& id) const;
};
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Serializer.h"
namespace ehs
{
class RIFF_Chunk
{
private:
Str_8 id;
UInt_64 hashId;
Serializer<> data;
public:
RIFF_Chunk();
RIFF_Chunk(const Str_8& id, const Serializer<>& data);
RIFF_Chunk(const RIFF_Chunk& chunk);
RIFF_Chunk& operator=(const RIFF_Chunk& chunk);
Str_8 GetId() const;
UInt_64 GetHashId() const;
Serializer<> GetData() const;
bool IsValid() const;
};
}

45
include/ehs/io/Resource.h Normal file
View File

@@ -0,0 +1,45 @@
#pragma once
#include "ehs/Types.h"
#include "ehs/Str.h"
#include "ehs/Vec2.h"
#include "ehs/BaseObj.h"
namespace ehs
{
class Resource : public BaseObj
{
private:
ehs::UInt_64 hashId;
ehs::Str_8 id;
public:
Resource();
Resource(ehs::Str_8 id);
Resource(Resource&& rsrc) noexcept;
Resource(const Resource& rsrc);
Resource& operator=(Resource&& rsrc) noexcept;
Resource& operator=(const Resource& rsrc);
bool operator==(ehs::UInt_64 otherHashId) const;
bool operator!=(ehs::UInt_64 otherHashId) const;
virtual void Release();
void SetId(ehs::Str_8 newId);
ehs::UInt_64 GetHashId() const;
ehs::Str_8 GetId() const;
virtual bool IsValid() const;
Resource* Clone() const override;
};
}

13
include/ehs/io/Window.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include "ehs/system/OS.h"
#if defined(EHS_OS_WINDOWS)
#include "Window_W32.h"
#elif defined(EHS_OS_LINUX)
#if defined(EHS_WS_XCB)
#include "Window_XCB.h"
#elif defined(EHS_WS_WAYLAND)
#include "Window_Way.h"
#endif
#endif

127
include/ehs/io/Window_W32.h Normal file
View File

@@ -0,0 +1,127 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Array.h"
#include "ehs/Str.h"
#include "ehs/Vec4.h"
#include "BaseWindow.h"
#include "HID/InputHandler.h"
#define WM_HIDE (WM_APP + 1)
#define WM_SHOW (WM_APP + 2)
#define WM_HIDE_CURSOR (WM_APP + 3)
#define WM_SHOW_CURSOR (WM_APP + 4)
namespace ehs
{
class Window : public BaseWindow
{
private:
UInt_32 owner;
HINSTANCE instance;
HWND hdl;
static Array<Window*> windows;
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
virtual ~Window() override;
Window();
Window(const Window &win);
Window& operator=(const Window &win);
virtual bool Poll() override;
///Creates the native window.
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
///Creates the native window.
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
///Creates the native window.
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
///Uses an already existing window to render an overlay.
void Use(HWND windowHdl);
///Closes the window.
virtual void Close() override;
///Shows the window.
void Show() override;
///Hides the window.
void Hide() override;
void SetTitle_32(const Str_32& title) override;
Str_32 GetTitle_32();
void SetTitle_16(const Str_16& title) override;
Str_16 GetTitle_16();
void SetTitle_8(const Str_8& title) override;
Str_8 GetTitle_8();
void SetIcon(const Str_8& filePath);
/// Sets the windows client scale.
/// @param [in] w The width in pixels.
/// @param [in] h The height in pixels.
void SetClientSize(const Vec2<UInt_32>& size);
Vec2<UInt_32> GetClientSize();
/// Gets the windows native handle for the operating system or other native tasks.
/// @returns The window's native handle.
HWND GetHdl() const;
/// Retrieves the first window handle that has been created using this library.
/// @returns The window's native handle.
static HWND GetAvailableHdl();
HINSTANCE GetInst() const;
/// Toggles whether the window updates and renders.
/// @param [in] toggle The new status.
void ToggleEnabled(bool toggle);
/// Checks whether the window updates and renders.
/// @returns The current status.
bool IsEnabled();
/// Sets the windows position on the desktop.
/// @param [in] x The x axis in pixels.
/// @param [in] y The y axis in pixels.
void SetPos(int x, int y);
/// Gets the windows current position on the desktop.
/// @returns The current value.
Vec2<Int_32> GetPos();
virtual void OnResized(const Vec2<UInt_32>& newSize);
/// Sets the windows scale which includes the border.
/// @param [in] w The width in pixels.
/// @param [in] h The height in pixels.
void SetSize(int w, int h);
/// Gets the windows current scale.
/// @returns The current value.
Vec2<Int_32> GetSize();
void ShowCursor(bool toggle) override;
void ConstrainCursor(const bool toggle) override;
protected:
void SendMsg(const UINT msg, const WPARAM wParam, const LPARAM lParam);
};
}

View File

@@ -0,0 +1,80 @@
#pragma once
#include "BaseWindow.h"
#include <wayland-client.h>
#include "xdg-shell-client-protocol.h"
namespace ehs
{
class Window : public BaseWindow
{
private:
wl_display* display;
wl_registry *registry;
wl_compositor* compositor;
wl_surface* surface;
xdg_wm_base *xdgShell;
xdg_surface *xdgSurface;
xdg_toplevel *xdgToplevel;
static void SurfaceConfigure(void *data, xdg_surface *xdg_surface, UInt_32 serial);
static void ShellPing(void *data, xdg_wm_base *shell, UInt_32 serial);
static void RegistryHandler(void *data, wl_registry *registry, UInt_32 id, const char *interface, UInt_32 version);
static void RegistryRemoved(void *data, wl_registry *registry, UInt_32 id);
public:
~Window() override;
Window();
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
void OnCreated() override;
void Close() override;
void Show() override;
void Hide() override;
bool Poll() override;
void ShowCursor(bool toggle) override;
void ConstrainCursor(const bool constrain) override;
void SetTitle_32(const Str_32& newTitle) override;
Str_32 GetTitle_32() const override;
void SetTitle_16(const Str_16& newTitle) override;
Str_16 GetTitle_16() const override;
void SetTitle_8(const Str_8& newTitle) override;
Str_8 GetTitle_8() const override;
void SetPos(const Vec2_s32& newPos) override;
Vec2_s32 GetPos() const override;
void SetScale(const Vec2_u32& newScale) override;
Vec2_u32 GetScale() const override;
Serializer<UInt_64> GetClipboard() override;
void SetClipboard(Serializer<UInt_64> data) override;
void SetCursorImg(const CursorImg img) override;
};
}

View File

@@ -0,0 +1,94 @@
#pragma once
#include "BaseWindow.h"
#include "File.h"
#include <xcb/xcb.h>
#include <xcb/xinput.h>
namespace ehs
{
class Window : public BaseWindow
{
protected:
friend class Input;
xcb_connection_t* server;
xcb_screen_t* screen;
xcb_window_t hdl;
xcb_atom_t masks[2];
UInt_8 extOpCode;
Vector<xcb_generic_event_t*> events;
Serializer<UInt_64> clipboard;
public:
~Window() override;
Window();
Window(Window&& win) noexcept;
Window(const Window& win);
Window& operator=(Window&& win) noexcept;
Window& operator=(const Window& win);
void Create_32(const Str_32& title, const Vec2_s32& pos, Vec2_u32 scale) override;
void Create_16(const Str_16& title, const Vec2_s32& pos, Vec2_u32 scale) override;
void Create_8(const Str_8& title, const Vec2_s32& pos, Vec2_u32 scale) override;
void Close() override;
void Show() override;
void Hide() override;
bool Poll() override;
void ShowCursor(bool toggle) override;
void ConstrainCursor(bool constrain) override;
void SetTitle_32(const Str_32& newTitle) override;
Str_32 GetTitle_32() const override;
void SetTitle_16(const Str_16& newTitle) override;
Str_16 GetTitle_16() const override;
void SetTitle_8(const Str_8& newTitle) override;
Str_8 GetTitle_8() const override;
void SetPos(const Vec2_s32& newPos) override;
Vec2_s32 GetPos() const override;
void SetScale(const Vec2_u32& newScale) override;
Vec2_u32 GetScale() const override;
Serializer<UInt_64> GetClipboard() override;
void SetClipboard(Serializer<UInt_64> data) override;
void SetCursorImg(CursorImg img) override;
xcb_connection_t* GetServer();
private:
xcb_generic_event_t* RetrieveEvent();
xcb_atom_t RetrieveAtom(bool create, const Str_8& name) const;
xcb_get_property_reply_t* RetrieveProp(xcb_atom_t prop, xcb_atom_t type) const;
void QueryPrimaryDevices();
Str_8 QueryDeviceName(UInt_16 id);
};
}

View File

@@ -0,0 +1,204 @@
#pragma once
#include "ehs/Types.h"
#include "ehs/DataType.h"
#include "ehs/Str.h"
#include "ehs/Serializer.h"
#include "ehs/Vector.h"
#include "ehs/Array.h"
#include "ehs/io/Resource.h"
#include "AudioCodec.h"
namespace ehs
{
class Audio : public Resource
{
private:
static Array<AudioCodec> codecs;
UInt_64 sampleRate;
DataType dataType;
UInt_8 byteDepth;
UInt_8 channels;
UInt_64 frames;
float length;
Byte* data;
Byte* peak;
public:
static bool HasCodec(UInt_64 hashExt);
static bool HasCodec(const Str_8& ext);
static bool AddCodec(AudioCodec codec);
static const AudioCodec* GetCodec(UInt_64 hashExt);
static const AudioCodec* GetCodec(const Str_8& ext);
~Audio() override;
Audio();
Audio(Str_8 id);
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames, const Byte* data);
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Serializer<UInt_64>& data);
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Vector<Byte>& data);
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Array<Byte>& data);
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames);
Audio(Audio&& audio) noexcept;
Audio(const Audio& audio);
Audio& operator=(Audio&& audio) noexcept;
Audio& operator=(const Audio& audio);
operator const Byte*() const;
operator Byte*();
void Release() override;
UInt_64 GetSampleRate() const;
DataType GetDataType() const;
UInt_8 GetByteDepth() const;
UInt_8 GetBitDepth() const;
UInt_8 GetChannels() const;
UInt_64 GetFrameCount() const;
UInt_64 GetSampleCount() const;
UInt_64 GetSize() const;
float GetLength() const;
Array<Byte> FrameAsMono(UInt_64 frameIndex) const;
Array<Byte> FrameAsStereo(UInt_64 frameIndex) const;
Array<Byte> FrameAsFive_One(UInt_64 frameIndex) const;
Array<Byte> FrameAsSeven_One(UInt_64 frameIndex) const;
SInt_8 SampleAsSInt_8(UInt_64 sampleIndex) const;
SInt_16 SampleAsSInt_16(UInt_64 sampleIndex) const;
float SampleAsFloat(UInt_64 sampleIndex) const;
SInt_32 SampleAsSInt_32(UInt_64 sampleIndex) const;
SInt_64 SampleAsSInt_64(UInt_64 sampleIndex) const;
SInt_8 PeakAsSInt_8() const;
SInt_16 PeakAsSInt_16() const;
float PeakAsFloat() const;
SInt_32 PeakAsSInt_32() const;
SInt_64 PeakAsSInt_64() const;
void SetPeak(UInt_64 size, const Byte* newPeak);
const Byte* GetPeak() const;
void ToDataType(DataType newDataType);
Audio GetAsDataType(DataType newDataType) const;
void ToChannels(UInt_8 newChannels);
Audio GetAsChannels(UInt_8 newChannels) const;
bool ToFile(const Str_8& filePath) const;
static Audio FromFile(const Str_8& filePath);
static Audio* FromFile_Heap(const Str_8& filePath);
static Audio FromFile(const Str_8& filePath, DataType required);
static Audio* FromFile_Heap(const Str_8& filePath, DataType required);
static Audio FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data);
private:
void ToMono(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Mono_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Five_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Seven_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Mono_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Stereo_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Seven_One_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Mono_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Stereo_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
void Five_One_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
// To SInt_8
void SInt_16_to_SInt_8(Byte* newData, Byte* newPeak) const;
void Float_to_SInt_8(Byte* newData, Byte* newPeak) const;
void SInt_32_to_SInt_8(Byte* newData, Byte* newPeak) const;
void SInt_64_to_SInt_8(Byte* newData, Byte* newPeak) const;
// To SInt_16
void SInt_8_to_SInt_16(Byte* newData, Byte* newPeak) const;
void Float_to_SInt_16(Byte* newData, Byte* newPeak) const;
void SInt_32_to_SInt_16(Byte* newData, Byte* newPeak) const;
void SInt_64_to_SInt_16(Byte* newData, Byte* newPeak) const;
// To Float
void SInt_8_to_Float(Byte* newData, Byte* newPeak) const;
void SInt_16_to_Float(Byte* newData, Byte* newPeak) const;
void SInt_32_to_Float(Byte* newData, Byte* newPeak) const;
void SInt_64_to_Float(Byte* newData, Byte* newPeak) const;
// To SInt_32
void SInt_8_to_SInt_32(Byte* newData, Byte* newPeak) const;
void SInt_16_to_SInt_32(Byte* newData, Byte* newPeak) const;
void Float_to_SInt_32(Byte* newData, Byte* newPeak) const;
void SInt_64_to_SInt_32(Byte* newData, Byte* newPeak) const;
// To SInt_64
void SInt_8_to_SInt_64(Byte* newData, Byte* newPeak) const;
void SInt_16_to_SInt_64(Byte* newData, Byte* newPeak) const;
void Float_to_SInt_64(Byte* newData, Byte* newPeak) const;
void SInt_32_to_SInt_64(Byte* newData, Byte* newPeak) const;
};
}

View File

@@ -0,0 +1,48 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/io/File.h"
namespace ehs
{
class Audio;
class AudioCodec
{
private:
Str_8 id;
UInt_64 hashExt;
Str_8 ext;
Endianness endianness;
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*);
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*);
public:
AudioCodec();
AudioCodec(Str_8 id, Str_8 ext, const Endianness end,
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*),
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*));
AudioCodec(AudioCodec&& codec) noexcept;
AudioCodec(const AudioCodec& codec);
AudioCodec& operator=(AudioCodec&& codec) noexcept;
AudioCodec& operator=(const AudioCodec& codec);
Str_8 GetId() const;
UInt_64 GetHashExt() const;
Str_8 GetExt() const;
Endianness GetEndianness() const;
bool Encode(Serializer<UInt_64>& out, const Audio* in) const;
bool Decode(Serializer<UInt_64>& in, Audio* out) const;
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "ehs/EHS.h"
#if defined(EHS_OS_WINDOWS)
#include "AudioDevice_W32.h"
#elif defined(EHS_OS_LINUX)
#include "AudioDevice_ALSA.h"
#endif

View File

@@ -0,0 +1,46 @@
#pragma once
#include "ehs/EHS.h"
#include "BaseAudioDevice.h"
#include <alsa/asoundlib.h>
namespace ehs
{
class AudioDevice : public BaseAudioDevice
{
private:
snd_pcm_t* hdl;
public:
~AudioDevice() override;
AudioDevice();
AudioDevice(AudioDevice&& device) noexcept;
AudioDevice(const AudioDevice& device);
AudioDevice& operator=(AudioDevice&& device) noexcept;
AudioDevice& operator=(const AudioDevice& device);
void Release() override;
void OpenStream() override;
void CloseStream() override;
UInt_64 GetAvailFrames() const override;
Byte* Map(UInt_64* offset, UInt_64* frames) override;
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
bool IsValid() const override;
static AudioDevice GetDefault(const AudioDeviceType type);
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
};
}

View File

@@ -0,0 +1,66 @@
#pragma once
#include "ehs/EHS.h"
#include "BaseAudioDevice.h"
#include <initguid.h>
#include <mmdeviceapi.h>
#include <functiondiscoverykeys_devpkey.h>
#include <Audioclient.h>
struct IMMDevice;
namespace ehs
{
class AudioDevice : public BaseAudioDevice
{
private:
IMMDevice* hdl;
IAudioClient* client;
IAudioRenderClient* playbackClient;
IAudioCaptureClient* captureClient;
public:
~AudioDevice() override;
AudioDevice();
AudioDevice(AudioDevice&& device) noexcept;
AudioDevice(const AudioDevice& device);
AudioDevice& operator=(AudioDevice&& device) noexcept;
AudioDevice& operator=(const AudioDevice& device);
void Release() override;
void OpenStream() override;
void CloseStream() override;
UInt_64 GetAvailFrames() const override;
Byte* Map(UInt_64* offset, UInt_64* frames) override;
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
Str_32 GetInterfaceName_32() const;
Str_16 GetInterfaceName_16() const;
Str_8 GetInterfaceName_8() const;
Str_32 GetName_32() const;
Str_16 GetName_16() const;
Str_8 GetName_8() const;
bool IsValid() const override;
static AudioDevice GetDefault(const AudioDeviceType type);
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
};
}

View File

@@ -0,0 +1,105 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Vector.h"
#include "ehs/Array.h"
#include "ehs/DataType.h"
namespace ehs
{
enum class AudioDeviceType
{
OUTPUT = 0x0,
INPUT = 0x1,
ALL = 0x2
};
enum class AudioDeviceState
{
ACTIVE = 0x1,
DISABLED = 0x2,
NOT_PRESENT = 0x4,
UNPLUGGED = 0x8
};
class BaseAudioDevice
{
protected:
AudioDeviceType type;
DataType dataType;
UInt_16 bitDepth;
UInt_32 sampleRate;
UInt_32 channels;
UInt_32 period;
UInt_32 latency;
UInt_64 maxFrames;
bool streaming;
public:
virtual ~BaseAudioDevice() = default;
BaseAudioDevice();
BaseAudioDevice(const BaseAudioDevice& device);
BaseAudioDevice& operator=(const BaseAudioDevice& device);
virtual void Release();
virtual void OpenStream();
virtual void CloseStream();
virtual UInt_64 GetAvailFrames() const;
virtual Byte* Map(UInt_64* offset, UInt_64* frames);
virtual void UnMap(const UInt_64 offset, const UInt_64 frames);
AudioDeviceType GetType() const;
void SetDataType(const DataType newDataType);
DataType GetDataType() const;
UInt_8 GetByteDepth() const;
UInt_16 GetBitDepth() const;
void SetSampleRate(const UInt_32 newSampleRate);
UInt_32 GetSampleRate() const;
void SetChannels(const UInt_32 newChannels);
UInt_16 GetChannels() const;
UInt_32 GetFrameSize() const;
void SetPeriod(const UInt_32 newPeriod);
UInt_32 GetPeriod() const;
void SetLatency(const UInt_32 newLatency);
UInt_32 GetLatency() const;
UInt_64 GetMaxFrames() const;
bool IsStreaming() const;
virtual bool IsValid() const;
/// Retrieves the default audio input/output device.
/// @param [in] type The audio device type to retrieve.
/// @param [out] device The default audio device.
static BaseAudioDevice GetDefault(const AudioDeviceType type);
/// Retrieves a list of audio input/output devices.
/// @param [in] type The audio device type to retrieve.
/// @param [in] state The audio device state to retrieve.
/// @param [out] devices The list of audio devices.
static Array<BaseAudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
};
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
namespace ehs
{
class Button
{
private:
Str_8 name;
UInt_32 hash;
public:
Button();
Button(const Str_8& name);
Button(const Button& key);
Button& operator=(const Button& key);
bool operator==(const Button& key) const;
bool operator!=(const Button& key) const;
Str_8 GetName() const;
UInt_32 GetHash() const;
};
}

View File

@@ -0,0 +1,55 @@
#pragma once
#include "ehs/EHS.h"
#include "Button.h"
namespace ehs
{
enum class State
{
JUST_RELEASED,
RELEASED,
PRESSED,
TOUCHED
};
class ButtonState
{
private:
Button button;
State state;
bool pressed;
float threshold;
public:
ButtonState();
ButtonState(const Button& button, const State state);
ButtonState(const ButtonState& bs);
ButtonState& operator=(const ButtonState& bs);
bool operator==(const Button& other) const;
bool operator!=(const Button& other) const;
bool operator==(const State otherState) const;
bool operator!=(const State otherState) const;
Button GetButton() const;
void SetState(State newState);
State GetState() const;
void SetPressed(bool value);
bool IsPressed() const;
void SetThreshold(const float newThreshold);
float GetThreshold() const;
};
}

91
include/ehs/io/hid/HID.h Normal file
View File

@@ -0,0 +1,91 @@
#pragma once
#include "ehs/Array.h"
#include "ButtonState.h"
#define EHS_HID_UNKNOWN 0
namespace ehs
{
class HID
{
protected:
UInt_8 type;
UInt_64 hashName;
Str_8 name;
UInt_64 id;
Array<ButtonState> states;
public:
HID();
HID(const UInt_8 type, Str_8 name, const UInt_64 id);
HID(HID&& hid) noexcept;
HID(const HID& hid);
HID& operator=(HID&& hid) noexcept;
HID& operator=(const HID& hid);
bool operator==(const HID& other) const;
bool operator!=(const HID& other) const;
bool operator==(const UInt_64 otherId) const;
bool operator!=(const UInt_64 otherId) const;
virtual void Poll();
UInt_8 GetType() const;
Str_8 GetName() const;
UInt_64 GetId() const;
void ReleaseAll();
Vector<const ButtonState*> GetAllTouched() const;
const ButtonState* IsTouched(const Button& button) const;
const ButtonState* IsTouched() const;
Vector<const ButtonState*> GetAllDown() const;
const ButtonState* IsDown(const Button& button) const;
const ButtonState* IsDown() const;
Vector<const ButtonState*> GetAllJustReleased() const;
const ButtonState* IsJustReleased(const Button& button) const;
const ButtonState* IsJustReleased() const;
Vector<const ButtonState*> GetAllUp() const;
const ButtonState* IsUp(const Button& button) const;
const ButtonState* IsUp() const;
void ButtonDown(const Button& button);
void ButtonUp(const Button& button);
const ButtonState* GetState(const Button& button) const;
bool IsValid() const;
virtual HID* Clone() const;
private:
bool HasState(const Button& button) const;
bool AddState(const ButtonState& state);
ButtonState* GetState(const Button& button);
};
}

View File

@@ -0,0 +1,46 @@
#pragma once
#include "ehs/Array.h"
#include "ehs/Serializer.h"
#include "InputHandler.h"
namespace ehs
{
class Input
{
private:
Array<InputHandler*> handlers;
bool initalized;
public:
~Input();
Input();
Input(Input&& input) noexcept;
Input(const Input& input);
Input& operator=(Input&& input) noexcept;
Input& operator=(const Input& input);
void Initialize();
void Release();
void Poll();
bool HasHandler(const UInt_64 hashId) const;
bool HasHandler(const Str_8& id) const;
bool AddHandler(InputHandler* handler);
const InputHandler* GetHandler(const UInt_64 hashId) const;
const InputHandler* GetHandler(const Str_8& id) const;
bool IsInitialized() const;
};
}

View File

@@ -0,0 +1,58 @@
#pragma once
#include "ehs/Array.h"
#include "HID.h"
namespace ehs
{
class InputHandler
{
private:
UInt_64 hashId;
Str_8 id;
protected:
Array<HID*> devices;
public:
virtual ~InputHandler();
InputHandler();
InputHandler(Str_8 id);
InputHandler(InputHandler&& ih) noexcept;
InputHandler(const InputHandler& ih);
InputHandler& operator=(InputHandler&& ih) noexcept;
InputHandler& operator=(const InputHandler& ih);
bool operator==(const UInt_64 otherHashId);
bool operator!=(const UInt_64 otherHashId);
virtual bool Initialize();
virtual bool Release();
virtual void Poll();
UInt_64 GetHashId() const;
Str_8 GetId() const;
void ResetAllStates();
bool HasDevice(const UInt_64 id) const;
bool AddDevice(HID* device);
HID* GetDevice(const UInt_64 id) const;
HID* GetDeviceByType(const UInt_8 type) const;
virtual bool IsInitialized() const;
};
}

View File

@@ -0,0 +1,121 @@
#pragma once
#include "ehs/Types.h"
#include "Button.h"
#include "HID.h"
#define EHS_HID_KEYBOARD 0x02
namespace ehs
{
class Keyboard : public HID
{
public:
Keyboard();
Keyboard(Str_8 name, UInt_64 id);
Keyboard(Keyboard&& hid) noexcept = default;
Keyboard(const Keyboard& hid);
Keyboard& operator=(Keyboard&& hid) noexcept = default;
Keyboard& operator=(const Keyboard& hid);
void Poll() override;
Keyboard* Clone() const override;
static const Button Unknown;
static const Button Escape;
static const Button Backspace;
static const Button Enter;
static const Button LShift;
static const Button RShift;
static const Button LAlt;
static const Button RAlt;
static const Button LCtrl;
static const Button RCtrl;
static const Button Space;
static const Button A;
static const Button B;
static const Button C;
static const Button D;
static const Button E;
static const Button F;
static const Button G;
static const Button H;
static const Button I;
static const Button J;
static const Button K;
static const Button L;
static const Button M;
static const Button N;
static const Button O;
static const Button P;
static const Button Q;
static const Button R;
static const Button S;
static const Button T;
static const Button U;
static const Button V;
static const Button W;
static const Button X;
static const Button Y;
static const Button Z;
static const Button One;
static const Button Two;
static const Button Three;
static const Button Four;
static const Button Five;
static const Button Six;
static const Button Seven;
static const Button Eight;
static const Button Nine;
static const Button Zero;
static const Button Minus;
static const Button Equals;
static const Button Tilde;
static const Button BackSlash;
static const Button LeftSquareBracket;
static const Button RightSquareBracket;
static const Button SemiColon;
static const Button Apostrophe;
static const Button Comma;
static const Button Period;
static const Button ForwardSlash;
static const Button F1;
static const Button F2;
static const Button F3;
static const Button F4;
static const Button F5;
static const Button F6;
static const Button F7;
static const Button F8;
static const Button F9;
static const Button F10;
static const Button F11;
static const Button F12;
static const Button F13;
static const Button F14;
static const Button F15;
static const Button F16;
static const Button F17;
static const Button F18;
static const Button F19;
static const Button F20;
static const Button F21;
static const Button F22;
static const Button F23;
static const Button F24;
static const Button Left;
static const Button Right;
static const Button Up;
static const Button Down;
static Button TranslateScanCode(UInt_32 code);
static Char_8 TranslateToEnglish_8(bool shifted, const Button& button);
};
}

View File

@@ -0,0 +1,55 @@
#pragma once
#include "ehs/Types.h"
#include "ehs/Vec2.h"
#include "Button.h"
#include "HID.h"
#define EHS_HID_MOUSE 0x01
namespace ehs
{
class Mouse : public HID
{
private:
friend class Input;
Vec2_s32 delta;
public:
Mouse();
Mouse(Str_8 name, const UInt_64 id);
Mouse(Mouse&& hid) noexcept = default;
Mouse(const Mouse& hid);
Mouse& operator=(Mouse&& hid) noexcept = default;
Mouse& operator=(const Mouse& hid);
void Poll() override;
void SetDelta(const Vec2_s32& newDelta);
Vec2_s32 GetDelta() const;
Mouse* Clone() const override;
static const Button Unknown;
static const Button LMB;
static const Button MMB;
static const Button RMB;
static const Button Four;
static const Button Five;
static const Button ScrollUp;
static const Button ScrollDown;
static const Button ScrollLeft;
static const Button ScrollRight;
static const Button Back;
static const Button Forward;
static Button TranslateXCB(const UInt_32 code);
};
}

188
include/ehs/io/img/Img.h Normal file
View File

@@ -0,0 +1,188 @@
#pragma once
#include "ehs/Types.h"
#include "ehs/BaseObj.h"
#include "ehs/Str.h"
#include "ImgCodec.h"
namespace ehs
{
enum class Resampling : UInt_8
{
NONE,
NEAREST_NEIGHBOR
};
class Img : public BaseObj
{
private:
static Array<ImgCodec> codecs;
protected:
UInt_64 hashId;
Str_8 id;
UInt_8 byteDepth;
UInt_8 channels;
Vec2_u64 resolution;
UInt_64 size;
Byte* data;
public:
static bool HasCodec(UInt_64 hashExt);
static bool HasCodec(const Str_8& ext);
static bool AddCodec(ImgCodec codec);
static const ImgCodec* GetCodec(UInt_64 hashExt);
static const ImgCodec* GetCodec(const Str_8& ext);
~Img() override;
Img();
Img(Str_8 id);
Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution, const Byte* data);
Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution);
Img(Img&& img) noexcept;
Img(const Img& img);
Img& operator=(Img&& img) noexcept;
Img& operator=(const Img& img);
operator const Byte* () const;
operator Byte* ();
void Release();
UInt_64 GetHashId() const;
void SetId(Str_8 newId);
Str_8 GetId() const;
UInt_8 GetByteDepth() const;
UInt_8 GetBitDepth() const;
UInt_8 GetChannels() const;
Vec2_u64 GetResolution() const;
UInt_64 GetSize() const;
void SetPixel(UInt_64 index, const Byte* pixel);
void GetPixel(UInt_64 index, Byte* pixel) const;
void SetPixel(UInt_64 x, UInt_64 y, const Byte* pixel);
void GetPixel(UInt_64 x, UInt_64 y, Byte* pixel) const;
void Resize(Resampling method, const Vec2_u64& newResolution);
Img GetResized(Resampling method, const Vec2_u64& newResolution) const;
void ToRGBA();
Img GetAsRGBA() const;
void ToRGB();
Img GetAsRGB() const;
void ToMonoA();
Img GetAsMonoA() const;
void ToMono();
Img GetAsMono() const;
void To32();
Img GetAs32() const;
void To24();
Img GetAs24() const;
void To16();
Img GetAs16() const;
void To8();
Img GetAs8() const;
bool IsValid() const;
bool ToFile(const Str_8& filePath) const;
static Img FromFile(const Str_8& filePath);
static Img* FromFile_Heap(const Str_8& filePath);
static Img FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data);
private:
Img GetNearestNeighbor(const Vec2_u64& newResolution) const;
void NearestNeighbor(const Vec2_u64& newResolution);
void RGB_To_RGBA(UInt_64 newSize, Byte* buffer) const;
void MonoA_To_RGBA(UInt_64 newSize, Byte* buffer) const;
void Mono_To_RGBA(UInt_64 newSize, Byte* buffer) const;
void RGBA_To_RGB(UInt_64 newSize, Byte* buffer) const;
void MonoA_To_RGB(UInt_64 newSize, Byte* buffer) const;
void Mono_To_RGB(UInt_64 newSize, Byte* buffer) const;
void RGBA_To_MonoA(UInt_64 newSize, Byte* buffer) const;
void RGB_To_MonoA(UInt_64 newSize, Byte* buffer) const;
void Mono_To_MonoA(UInt_64 newSize, Byte* buffer) const;
void RGBA_To_Mono(UInt_64 newSize, Byte* buffer) const;
void RGB_To_Mono(UInt_64 newSize, Byte* buffer) const;
void MonoA_To_Mono(UInt_64 newSize, Byte* buffer) const;
void BD24_to_BD32(UInt_64 newSize, Byte* buffer) const;
void BD16_to_BD32(UInt_64 newSize, Byte* buffer) const;
void BD8_to_BD32(UInt_64 newSize, Byte* buffer) const;
void BD32_to_BD24(UInt_64 newSize, Byte* buffer) const;
void BD16_to_BD24(UInt_64 newSize, Byte* buffer) const;
void BD8_to_BD24(UInt_64 newSize, Byte* buffer) const;
void BD32_to_BD16(UInt_64 newSize, Byte* buffer) const;
void BD24_to_BD16(UInt_64 newSize, Byte* buffer) const;
void BD8_to_BD16(UInt_64 newSize, Byte* buffer) const;
void BD32_to_BD8(UInt_64 newSize, Byte* buffer) const;
void BD24_to_BD8(UInt_64 newSize, Byte* buffer) const;
void BD16_to_BD8(UInt_64 newSize, Byte* buffer) const;
};
}

View File

@@ -0,0 +1,48 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/io/File.h"
namespace ehs
{
class Img;
class ImgCodec
{
private:
Str_8 id;
UInt_64 hashExt;
Str_8 ext;
Endianness endianness;
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*);
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*);
public:
ImgCodec();
ImgCodec(Str_8 id, Str_8 ext, const Endianness end,
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*),
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*));
ImgCodec(ImgCodec&& codec) noexcept;
ImgCodec(const ImgCodec& codec);
ImgCodec& operator=(ImgCodec&& codec) noexcept;
ImgCodec& operator=(const ImgCodec& codec);
Str_8 GetId() const;
UInt_64 GetHashExt() const;
Str_8 GetExt() const;
Endianness GetEndianness() const;
bool Encode(Serializer<UInt_64>& out, const Img* in) const;
bool Decode(Serializer<UInt_64>& in, Img* out) const;
};
}

51
include/ehs/io/img/PNG.h Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Serializer.h"
#include "PNG_Chunk.h"
#include "Img.h"
namespace ehs
{
class PNG
{
private:
Str_8 id;
UInt_64 hashId;
Array<PNG_Chunk> chunks;
public:
PNG();
PNG(const Str_8& filePath);
PNG(const Str_8& id, Serializer<UInt_64>& data);
PNG(const PNG& png);
PNG& operator=(const PNG& png);
bool HasChunk(const UInt_64 hashId) const;
bool HasChunk(const Str_8& id) const;
PNG_Chunk* GetChunk(const UInt_64 hashId);
PNG_Chunk* GetChunk(const Str_8& id);
static bool IsPNG(Serializer<UInt_32>& data);
static void FilterNone(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterSub(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterUp(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterAverage(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterPaeth(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
private:
static Byte PaethPredictor(const Byte a, const Byte b, const Byte c);
};
}

View File

@@ -0,0 +1,34 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Serializer.h"
namespace ehs
{
class PNG_Chunk
{
private:
Str_8 id;
UInt_64 hashId;
Serializer<UInt_64> data;
Byte crc[4];
public:
PNG_Chunk();
PNG_Chunk(const Str_8& id, const Serializer<UInt_64>& data, const Byte crc[4]);
PNG_Chunk(const PNG_Chunk& chunk);
PNG_Chunk& operator=(const PNG_Chunk& chunk);
Str_8 GetId() const;
UInt_64 GetHashId() const;
Serializer<UInt_64>* GetData();
const unsigned char* GetCRC() const;
};
}

View File

@@ -0,0 +1,40 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Array.h"
#include "KeyFrame.h"
namespace ehs
{
class AnimBone
{
private:
UInt_8 boneId;
Array<KeyFrame> keyFrames;
public:
AnimBone();
AnimBone(const UInt_8 boneId);
AnimBone(const UInt_8 boneId, const UInt_64 size);
AnimBone(const UInt_8 boneId, Array<KeyFrame> keyFrames);
AnimBone(AnimBone&& anim) noexcept;
AnimBone(const AnimBone& anim);
AnimBone& operator=(AnimBone&& anim) noexcept;
AnimBone& operator=(const AnimBone& anim);
UInt_8 GetBoneId() const;
Array<KeyFrame> GetKeyFrames() const;
Array<KeyFrame>& GetKeyFrames();
float GetPrevAndNext(KeyFrame& prev, KeyFrame& next, const float elapsed) const;
};
}

View File

@@ -0,0 +1,49 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Array.h"
#include "AnimBone.h"
namespace ehs
{
class Animation
{
private:
UInt_64 hashId;
Str_8 id;
float duration;
Array<AnimBone> animated;
public:
Animation();
Animation(Str_8 id, const float duration);
Animation(Str_8 id, const float duration, UInt_64 size);
Animation(Str_8 id, const float duration, Array<AnimBone> animated);
Animation(Animation&& anim) noexcept;
Animation(const Animation& anim);
Animation& operator=(Animation&& anim) noexcept;
Animation& operator=(const Animation& anim);
UInt_64 GetHashId() const;
void SetId(Str_8 newId);
Str_8 GetId() const;
float GetDuration() const;
Array<AnimBone> GetAnimated() const;
Array<AnimBone>& GetAnimated();
Array<Mat4_f> Interpolate(const UInt_64 boneCount, const float elapsed) const;
};
}

View File

@@ -0,0 +1,73 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Quat.h"
#include "ehs/Mat4.h"
namespace ehs
{
class Bone
{
private:
UInt_64 hashName;
Str_8 name;
UInt_8 id;
Mat4_f animTrans;
Mat4_f localBindTrans;
Mat4_f invBindTrans;
Array<Bone> children;
public:
Bone();
Bone(Str_8 name, UInt_8 id, const Mat4_f& localBindTrans, const Mat4_f& invBindTrans);
Bone(Bone&& bone) noexcept;
Bone(const Bone& bone);
Bone& operator=(Bone&& bone) noexcept;
Bone& operator=(const Bone& bone);
UInt_64 GetHashName() const;
void SetName(Str_8 newId);
Str_8 GetName() const;
UInt_8 GetId() const;
void SetAnimTrans(const Mat4_f& newTrans);
Mat4_f GetAnimTrans() const;
void GetAnimTransRec(Array<Mat4_f>& output) const;
Mat4_f GetLocalBindTrans() const;
Mat4_f GetInvBindTrans() const;
UInt_8 GetBoneCount() const;
bool HasBone(UInt_64 hashName, UInt_8 id) const;
bool HasBone(UInt_64 hashName) const;
bool HasBone(UInt_8 id) const;
bool AddBone(Bone child);
const Bone* GetBone(UInt_64 hashName) const;
Bone* GetBone(UInt_64 hashName);
const Bone* GetBone(UInt_8 id) const;
Bone* GetBone(UInt_8 id);
const Array<Bone>& GetChildren() const;
Array<Bone>& GetChildren();
};
}

View File

@@ -0,0 +1,55 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Array.h"
#include "ehs/Vec3.h"
#include "ehs/Quat.h"
#include "ehs/Mat4.h"
#include "PropertyChange.h"
namespace ehs
{
class KeyFrame
{
private:
float num;
float timeStamp;
Vec3_f pos;
Quat_f rot;
Vec3_f scale;
Mat4_f trans;
public:
KeyFrame();
KeyFrame(const float num, const float timeStamp, const Vec3_f& pos, const Quat_f& rot, const Vec3_f& scale);
KeyFrame(const float num, const float timeStamp);
KeyFrame(const KeyFrame& kf);
KeyFrame& operator=(const KeyFrame& kf);
float GetNum() const;
float GetTimeStamp() const;
void SetPos(const Vec3_f& newPos);
Vec3_f GetPos() const;
void SetRot(const Quat_f& newRot);
Quat_f GetRot() const;
void SetScale(const Vec3_f& newScale);
Vec3_f GetScale() const;
void CalculateTransform();
Mat4_f GetTrans() const;
static Mat4_f Interpolate(const KeyFrame& prev, const KeyFrame& next, const float percentage);
};
}

View File

@@ -0,0 +1,80 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Array.h"
#include "Vertex.h"
#include "ehs/BaseObj.h"
namespace ehs
{
class Mesh final : public BaseObj
{
protected:
UInt_64 hashId;
Str_8 id;
Array<Vertex_f> vertices;
Array<UInt_32> indices;
public:
Mesh();
Mesh(Str_8 id, Array<Vertex_f> vertices, Array<UInt_32> indices);
Mesh(Str_8 id, Array<Vertex_f> vertices);
Mesh(Mesh&& mesh) noexcept;
Mesh(const Mesh& mesh);
Mesh& operator=(Mesh&& mesh) noexcept;
Mesh& operator=(const Mesh& mesh);
void Release();
UInt_64 GetHashId() const;
void SetId(Str_8 newId);
Str_8 GetId() const;
void SetVertices(const Array<Vertex_f>& newVertices);
const Array<Vertex_f>& GetVertices() const;
Array<Vertex_f>& GetVertices();
void SetIndices(const Array<UInt_32>& newIndices);
bool HasIndices() const;
const Array<UInt_32>& GetIndices() const;
Array<UInt_32>& GetIndices();
void Calculate();
private:
static void Calculate(Vertex_f& vert1, Vertex_f& vert2, Vertex_f& vert3);
};
const Mesh portraitGui("PortraitGui",
{
{{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
{{0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
{{1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
{{1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
},
{0, 1, 2, 3, 2, 1}
);
const Mesh portrait("Portrait",
{
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
{{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
},
{0, 1, 2, 3, 2, 1}
);
}

View File

@@ -0,0 +1,80 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Array.h"
#include "ehs/io/File.h"
#include "Mesh.h"
#include "Bone.h"
#include "Animation.h"
namespace ehs
{
enum class ModelEncoding : UInt_8
{
EHM
};
class Model : public BaseObj
{
protected:
UInt_64 hashId;
Str_8 id;
Array<Mesh> meshes;
Bone skeleton;
Array<Animation> animations;
public:
Model();
Model(const Str_8& filePath);
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton, Array<Animation> animations);
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton);
Model(Str_8 id, Array<Mesh> meshes);
Model(Model&& model) noexcept;
Model(const Model& model) = default;
Model& operator=(Model&& model) noexcept;
Model& operator=(const Model& model) = default;
void Release();
UInt_64 GetHashId() const;
void SetId(Str_8 newId);
Str_8 GetId() const;
const Array<Mesh>& GetMeshes() const;
Array<Mesh>& GetMeshes();
Mesh* GetMesh(UInt_64 inHashId);
Mesh* GetMesh(const Str_8& inId);
const Bone& GetSkeleton() const;
Bone& GetSkeleton();
Animation* GetAnimation(UInt_64 inHashId);
const Array<Animation>& GetAnimations() const;
Array<Animation>& GetAnimations();
void Calculate();
void Export(const Str_8& filePath, ModelEncoding encoding);
private:
void ToEHM(File& file);
void FromEHM(File& file);
};
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include "ehs/EHS.h"
namespace ehs
{
enum class ChangeType : UInt_8
{
X_AXIS_POS,
Y_AXIS_POS,
Z_AXIS_POS,
X_AXIS_SCALE,
Y_AXIS_SCALE,
Z_AXIS_SCALE,
X_AXIS_ROT,
Y_AXIS_ROT,
Z_AXIS_ROT,
W_AXIS_ROT,
INVALID
};
class PropertyChange
{
public:
ChangeType type;
float value;
PropertyChange();
PropertyChange(const ChangeType type, const float value);
};
}

View File

@@ -0,0 +1,50 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Vec4.h"
#include "ehs/Vec3.h"
#include "ehs/Vec2.h"
#include "ehs/Color4.h"
namespace ehs
{
template<typename T = float>
class Vertex
{
public:
Vec3<T> pos;
Vec3<T> normal;
Vec2<T> uv;
Vec3<T> tan;
Vec3<T> bTan;
Vec4<UInt_8> bones;
Vec4<float> weights;
Vertex() = default;
Vertex(const Vec3<T>& pos)
: pos(pos), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
{
}
Vertex(const Vec3<T>& pos, const Vec3<T>& normal)
: pos(pos), normal(normal), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
{
}
Vertex(const Vec3<T>& pos, const Vec3<T>& normal, const Vec2<T>& uv)
: pos(pos), normal(normal), uv(uv), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
{
}
Vertex(const Vertex& vert)
: pos(vert.pos), normal(vert.normal), uv(vert.uv), bones(vert.bones), weights(vert.weights)
{
}
Vertex& operator=(const Vertex& vert) = default;
};
typedef Vertex<double> Vertex_d;
typedef Vertex<float> Vertex_f;
}

View File

@@ -0,0 +1,162 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "Request.h"
#include "Response.h"
#include "Socket.h"
namespace ehs
{
class BaseTCP
{
protected:
AddrType addrType;
Str_8 localAddr;
UInt_16 localPort;
Str_8 remoteHostName;
Str_8 remoteAddr;
UInt_16 remotePort;
bool connection;
bool bound;
bool listening;
bool connected;
public:
static const UInt_16 HTTPS_Port = 443;
static const UInt_16 HTTP_Port = 80;
static const UInt_16 MaxHeaderSize = 8192;
virtual ~BaseTCP() = default;
/// Initializes the socket with the defaults.
BaseTCP();
/// Properly initializes the socket.
/// @param [in] type The ip version to initialize the socket with.
BaseTCP(AddrType addrType);
BaseTCP(BaseTCP&& tcp) noexcept;
BaseTCP(const BaseTCP& tcp);
BaseTCP& operator=(BaseTCP&& tcp) noexcept;
BaseTCP& operator=(const BaseTCP& tcp);
/// Explicitly initialize the socket.
virtual void Initialize() = 0;
/// Explicitly release resources before it falls off the stack.
virtual void Release() = 0;
/// Binds to socket to a specified address and port.
/// @param [in] address The ip address to bind to.
/// @param [in] port The port to bind to.
/// @note Used for servers.
virtual void Bind(const Str_8& address, UInt_16 port) = 0;
/// Listens for new incoming connections.
/// @note Used for servers.
virtual void Listen() = 0;
/// Accepts the new incoming connection.
/// @note Used for servers.
virtual BaseTCP* Accept() = 0;
/// Connects to a server at the specified address and port.
/// @param [in] address The ip address to connect to.
/// @param [in] port The port to connect to.
/// @note Used for clients.
virtual void Connect(const Str_8& address, UInt_16 port) = 0;
/// Sends data to the connected endpoint.
/// @param [in] buffer The data to send to the endpoint.
/// @param [in] size The size in bytes of data being sent.
virtual UInt_64 Send(const Byte* buffer, UInt_32 size) = 0;
/// Receives data from the connected endpoint.
/// @param [out] buffer The incoming data from the endpoint.
/// @param [in] size The max size of the buffer in bytes to store the data.
/// @returns The size of the incoming data in bytes.
virtual UInt_64 Receive(Byte* buffer, UInt_32 size) = 0;
/// Sends a string to the connected endpoint.
/// @param [in] str The string to send to the endpoint.
void SendStr(const Str_8& str);
/// Sends a HTTP response to the connected endpoint.
/// @param [in] res The response to send.
void SendRes(const Response& res);
/// Sends a HTTP request to the connected endpoint.
/// @param [in] req The request to send.
void SendReq(Request& req);
/// Receives a HTTP response from the connected endpoint.
/// @returns The response received.
Response RecvRes();
/// Receives a HTTP request from the connected endpoint.
/// @returns The request received.
Request RecvReq();
/// Retrieves the sockets ip version.
/// @returns The ip version.
AddrType GetAddressType() const;
/// Retrieves the bound ip address.
/// @returns The ip address.
Str_8 GetLocalAddress() const;
/// Retrieves the bound port.
/// @returns The port.
unsigned short GetLocalPort() const;
/// Retrieves the ip address of the connected endpoint.
/// @returns The ip address.
Str_8 GetRemoteAddress() const;
/// Retrieves the port of the connected endpoint.
/// @returns The port.
UInt_16 GetRemotePort() const;
/// Retrieves whether or not this socket is connected to a client endpoint.
/// @returns The result.
bool IsConnection() const;
/// Retrieves whether of not this socket is bound to an ip address and port.
/// @returns The result.
bool IsBound() const;
/// Retrieves whether or not this socket is listening for incoming connections.
/// @returns The result.
bool IsListening() const;
/// Retrieves whether or not this socket is connected to an endpoint.
/// @returns The result.
bool IsConnected() const;
/// Sets whether or not the socket blocks the thread when receiving data.
/// @param [in] blocking Whether or not to block.
virtual void SetBlocking(bool blocking) = 0;
/// Retrieves whether or not when receiving data blocks the thread.
/// @returns The result.
virtual bool IsBlocking() const = 0;
/// Retrieves whether or not this socket was initialized.
/// @returns The result.
virtual bool IsValid() const = 0;
private:
Str_8 RecvHeader();
Str_8 RecvBody(UInt_64 contentLength);
UInt_64 RecvChunkSize();
Str_8 RecvChunk(UInt_64 chunkSize);
};
}

View File

@@ -0,0 +1,88 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "Socket.h"
namespace ehs
{
class BaseUDP
{
protected:
AddrType type;
Str_8 address;
UInt_16 port;
bool bound;
public:
virtual ~BaseUDP() = default;
/// Initializes the socket with the defaults.
BaseUDP();
/// Properly initializes the socket.
/// @param [in] type The ip version to initialize the socket with.
BaseUDP(AddrType type);
BaseUDP(BaseUDP&& udp) noexcept;
BaseUDP(const BaseUDP& udp);
BaseUDP& operator=(BaseUDP&& udp) noexcept;
BaseUDP& operator=(const BaseUDP& udp);
/// Explicitly release resources before it falls off the stack.
virtual void Release() = 0;
/// Binds to socket to a specified address and port.
/// @param [in] type The ip version to use.
/// @param [in] address The ip address to bind to.
/// @param [in] port The port to bind to.
/// @note Used for servers.
virtual void Bind(AddrType type, const Str_8& address, UInt_16 port) = 0;
/// Sends data to the endpoint.
/// @param [in] type The ip version of the endpoint.
/// @param [in] address The ip address of the endpoint.
/// @param [in] port The port of the endpoint is bound to.
virtual UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) = 0;
/// Receives data from the endpoint.
/// @param [out] type The ip version of the endpoint.
/// @param [out] address The ip address of the endpoint.
/// @param [out] port The port of the endpoint.
/// @param [out] data The incoming data from the endpoint.
/// @param [in] size The max size of the buffer in bytes to store the data.
/// @returns The size of the incoming data in bytes.
virtual UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) = 0;
/// Retrieves whether or not this socket is bound to an ip address and port.
/// @returns The result.
bool IsBound() const;
/// Sets whether or not the socket blocks the thread when receiving data.
/// @param [in] blocking Whether or not to block.
virtual void SetBlocking(bool blocking) = 0;
/// Retrieves whether or not when receiving data blocks the thread.
/// @returns The result.
virtual bool IsBlocking() const = 0;
/// Retrieves the bound ip version.
/// @returns The result.
AddrType GetLocalAddressType() const;
/// Retrieves the bound ip address.
/// @returns The bound ip address.
Str_8 GetLocalAddress() const;
/// Retrieves the bound port.
/// @returns The bound port.
UInt_16 GetLocalPort() const;
/// Retrieves whether or not this socket was initialized.
/// @returns The result.
virtual bool IsValid() const = 0;
};
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "Socket.h"
namespace ehs
{
class DNS
{
public:
/// Resolves a hostname to an ip address.
/// @param [in] hostname The given hostname to resolve.
/// @returns The resulting ip address.
static Str_8 Resolve(const Str_8& hostname);
};
}

View File

@@ -0,0 +1,164 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Vector.h"
#include "ehs/Str.h"
#include "ehs/json/Json.h"
#include "Socket.h"
namespace ehs
{
enum class Verb
{
POST,
GET,
PUT,
DEL
};
class Request
{
private:
Verb verb;
Str_8 rsrc;
Vector<Str_8> queries;
Vector<Str_8> header;
ContentType cType;
Str_8 body;
public:
/// Default member initialization.
Request();
/// Initializes this request with a given verb and URI resource.
/// @param [in] verb The type of request to make.
/// @param [in] rsrc The URI endpoint to make the request at.
Request(const Verb verb, const Str_8& rsrc);
/// Initializes this request with the raw request data.
/// @param [in] data The C-style string of the request.
/// @param [in] size The size of the given C-style string.
Request(const char* data, const UInt_64 size);
/// Initializes this request with the raw request data.
/// @param [in] data The string of the request.
Request(const Str_8& data);
/// Copies members from another object of the same type.
/// @param [in] req The object to copy from.
Request(const Request& req) = default;
/// Copies members from another object of the same type.
/// @param [in] req The object to copy from.
/// @returns The request that has been assigned to.
Request& operator=(const Request& req);
/// Retrieves the verb for the request.
/// @returns The result.
Verb GetVerb() const;
/// Sets the content type for the body.
/// @param [in] cType The content type to use.
void SetContentType(const ContentType cType);
/// Retrieves the content type for the body.
/// @returns The result.
ContentType GetContentType() const;
/// Sets the URI resource.
/// @param [in] rsrc The resource.
void SetResource(const Str_8& rsrc);
/// Retrieves the URI resource.
/// @returns The result.
Str_8 GetResource() const;
/// Adds a query variable to the URI.
/// @param [in] var The variable identifier.
/// @param [in] value The value of the variable.
void AddQuery(const Str_8& var, const Str_8& value);
/// Retrieves a query variable from the URI.
/// @param [in] var The variable identifier to look for.
/// @returns The value of the query variable. Empty if it was not found.
Str_8 GetQuery(const Str_8& var);
/// Retrieves all the query variables from the URI in a vector object.
/// @returns The result.
Vector<Str_8> GetQueries() const;
/// A helper method to automatically add the required header variables for basic authentication.
/// @param [in] id The username or id.
/// @param [in] secret The secret given by an API.
void BasicAuth(const Str_8& id, const Str_8& secret);
/// A helper method to automatically add the required header variables for bearer authentication.
/// @param [in] token The token given by an API.
void BearerAuth(const Str_8& token);
/// A helper method to automatically add the required header variables for bearer authentication.
/// @param [in] token The token given by an API.
/// @param [in] clientId The client id given by an API.
void BearerAuth(const Str_8& token, const Str_8& clientId);
/// A helper method to automatically add the required header variables for bot authentication.
/// @param [in] token The token given by an API.
void BotAuth(const Str_8& token);
/// Adds a header variable.
/// @param [in] var The variable identifier.
/// @param [in] value The value of the variable.
void AddToHeader(const Str_8& var, const Str_8& value);
/// Retrieves a header variable.
/// @param [in] var The variable identifier to look for.
/// @returns The value of the header variable. Empty if it was not found.
Str_8 GetHeader(const Str_8& var) const;
/// Retrieves all the header variables in a vector object.
/// @returns The result.
Vector<Str_8> GetHeader() const;
/// Adds a body variable.
/// @param [in] var The variable identifier.
/// @param [in] value The value of the variable.
void AddToBody(const Str_8& var, const Str_8& value);
/// Adds a value to the body.
/// @param [in] data The value to add.
void AddToBody(const Str_8& data);
/// Sets the entire body.
/// @param [in] body The body to use.
void SetBody(const Str_8& body);
/// Retrieves a body variable.
/// @param [in] var The variable identifier to look for.
/// @returns The value of the body variable. Empty if it was not found.
Str_8 GetVar(const Str_8& var) const;
/// Retrieves the entire body.
/// @returns The result.
Str_8 GetBody() const;
/// Retrieves the entire body as a Json.
/// @returns The result.
Json GetJson() const;
/// Forms the raw result of the request to be sent.
/// @returns The result.
Str_8 FormResult() const;
bool IsValid() const;
private:
static Str_8 VerbToStr(const Verb verb);
static Str_8 ContentTypeToStr(const ContentType cType);
static ContentType StrToContentType(const Str_8& value);
void ReadData(const Str_8& data);
};
}

View File

@@ -0,0 +1,127 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Vector.h"
#include "ehs/Str.h"
#include "ehs/json/Json.h"
#include "Socket.h"
namespace ehs
{
class Response
{
private:
UInt_32 code;
Str_8 server;
ContentType cType;
Vector<Str_8> header;
Str_8 body;
public:
/// Default member initialization.
Response();
/// Initializes this response with a given code and server identifier.
/// @param [in] code The code to give.
/// @param [in] server The server identifier.
Response(const UInt_32 code, const Str_8& server);
/// Initializes this response with the raw response data.
/// @param [in] data The C-style string of the response.
/// @param [in] size The size of the given C-style string.
Response(const char* data, const UInt_64 size);
/// Initializes this response with the raw response data.
/// @param [in] data The string of the response.
Response(const Str_8& data);
/// Copies members from another object of the same type.
/// @param [in] res The object to copy from.
Response(const Response& res) = default;
/// Copies members from another object of the same type.
/// @param [in] res The object to copy from.
/// @returns The response that has been assigned to.
Response& operator=(const Response& res);
/// Sets the response code to send to the endpoint.
/// @param [in] code The code for success, error or info.
void SetCode(const UInt_32 code);
/// Retrieves the response code.
/// @returns The result.
UInt_32 GetCode() const;
/// Sets the server identifier.
/// @param [in] server The server identifier to use.
void SetServer(const Str_8& server);
/// Retrieves the server identifier.
/// @returns The result.
Str_8 GetServer() const;
/// Sets the content type for the body.
/// @param [in] cType The content type to use.
void SetContentType(const ContentType cType);
/// Retrieves the content type for the body.
/// @returns The result.
ContentType GetContentType() const;
/// Adds a header variable.
/// @param [in] var The variable identifier.
/// @param [in] value The value of the variable.
void AddToHeader(const Str_8& var, const Str_8& value);
/// Retrieves a header variable.
/// @param [in] var The variable identifier to look for.
/// @returns The value of the header variable. Empty if it was not found.
Str_8 GetHeader(const Str_8& var) const;
/// Retrieves all the header variables in a vector object.
/// @returns The result.
Vector<Str_8> GetHeader() const;
/// Adds a body variable.
/// @param [in] var The variable identifier.
/// @param [in] value The value of the variable.
void AddToBody(const Str_8& var, const Str_8& value);
/// Adds a value to the body.
/// @param [in] data The value to add.
void AddToBody(const Str_8& data);
/// Sets the entire body.
/// @param [in] body The body to use.
void SetBody(const Str_8& body);
/// Retrieves a body variable.
/// @param [in] var The variable identifier to look for.
/// @returns The value of the body variable. Empty if it was not found.
Str_8 GetVar(const Str_8& var) const;
/// Retrieves the entire body.
/// @returns The result.
Str_8 GetBody() const;
/// Retrieves the entire body as a Json.
/// @returns The result.
Json GetJson() const;
/// Forms the raw result of the response to be sent.
/// @returns The result.
Str_8 FormResult() const;
bool IsValid() const;
private:
static Str_8 CodeToStr(const UInt_32 code);
static Str_8 ContentTypeToStr(const ContentType cType);
static ContentType StrToContentType(const Str_8& value);
void ReadData(const Str_8& data);
};
}

View File

@@ -0,0 +1,56 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "TCP.h"
#include "Request.h"
#include "Response.h"
typedef struct ssl_ctx_st SSL_CTX;
typedef struct ssl_st SSL;
namespace ehs
{
/// A class for handling the HTTP(S) TCP socket layer.
class SSL : public TCP
{
private:
SSL_CTX* ctx;
::SSL* sslHdl;
public:
~SSL() override;
SSL();
SSL(const AddrType type);
SSL(TCP&& tcp) noexcept;
SSL(const TCP& tcp);
SSL(const SSL& ssl);
SSL& operator=(const SSL& ssl);
void Initialize() override;
void Release() override;
void Bind(const Str_8& address, unsigned short port) override;
SSL* Accept() override;
void Connect(const Str_8& address, const UInt_16 port) override;
UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
void UseCertificate(const Byte* data, const UInt_64 size);
void UsePrivateKey(const Byte* data, const UInt_64 size);
bool IsValid();
};
}

View File

@@ -0,0 +1,51 @@
#pragma once
#ifndef EHS_IPV4_HEADER
#define EHS_IPV4_HEADER 60
#endif
#ifndef EHS_IPV6_HEADER
#define EHS_IPV6_HEADER 40
#endif
#ifndef EHS_UDP_HEADER
#define EHS_UDP_HEADER 8
#endif
#ifndef EHS_IPV4_UDP_PAYLOAD
#define EHS_IPV4_UDP_PAYLOAD (EHS_UINT_16_MAX - EHS_IPV4_HEADER - EHS_UDP_HEADER)
#endif
#ifndef EHS_IPV6_UDP_PAYLOAD
#define EHS_IPV6_UDP_PAYLOAD (EHS_UINT_16_MAX - EHS_IPV6_HEADER - EHS_UDP_HEADER)
#endif
namespace ehs
{
enum class AddrType
{
IPV6,
IPV4
};
enum class ContentType
{
APP_MULTIPART_FORMDATA,
APP_FORMURLENCODED,
APP_JAVASCRIPT,
APP_JSON,
APP_XML,
TEXT_PLAIN,
TEXT_HTML,
TEXT_XML,
NONE
};
#if defined(EHS_OS_WINDOWS)
typedef UInt_64 Socket;
#define EHS_INVALID_SOCKET EHS_UINT_64_MAX
#elif defined(EHS_OS_LINUX)
typedef SInt_32 Socket;
#define EHS_INVALID_SOCKET (SInt_32)0xffffffff
#endif
}

View File

@@ -0,0 +1,7 @@
#pragma once
#ifdef EHS_OS_WINDOWS
#include "TCP_W32.h"
#else
#include "TCP_BSD.h"
#endif

View File

@@ -0,0 +1,94 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Log.h"
#include "Socket.h"
#include "BaseTCP.h"
namespace ehs
{
/// A wrapper class for the transmission control protocol socket.
class TCP : public BaseTCP
{
protected:
Socket hdl;
public:
/// Frees any native handles.
~TCP() override;
/// Default members initialization.
TCP();
TCP(AddrType addrType);
TCP(TCP&& tcp) noexcept;
/// Copies some members from the given TCP object.
/// @param [in] tcp The TCP object to copy from.
TCP(const TCP& tcp);
TCP& operator=(TCP&& tcp) noexcept;
/// Copies some members from the given TCP object.
/// @param [in] tcp The TCP object to copy from.
/// @returns The TCP object that has been assigned to.
TCP& operator=(const TCP& tcp);
void Initialize() override;
/// Frees native handles and uninitializes them.
void Release() override;
/// Binds the UDP socket to a local address and port.
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called.
void Bind(const Str_8& address, UInt_16 port) override;
/// Listens for incoming connections. Used for servers or PtP.
void Listen() override;
/// Accepts an incoming connection. Used for servers or PtP.
/// @returns The accepted client object.
TCP* Accept() override;
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param port The port of the listening TCP socket.
void Connect(const Str_8& address, UInt_16 port) override;
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [in] buffer The C-style array to send.
/// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually sent in bytes.
UInt_64 Send(const Byte* buffer, UInt_32 size) override;
/// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [out] buffer The C-style array to receive with.
/// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually received in bytes.
UInt_64 Receive(Byte* buffer, UInt_32 size) override;
/// Sets whether or not receiving data blocks the next task.
/// @param [in] blocking Whether or not to block.
void SetBlocking(bool blocking) override;
/// Retrieves whether or not this socket will block when receiving data.
/// @returns The result.
bool IsBlocking() const override;
bool IsValid() const override;
private:
void Bind_v6(const Str_8& address, UInt_16 port);
void Bind_v4(const Str_8& address, UInt_16 port);
void Connect_v6(const Str_8& address, UInt_16 port);
void Connect_v4(const Str_8& address, UInt_16 port);
};
}

View File

@@ -0,0 +1,94 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Log.h"
#include "Socket.h"
#include "BaseTCP.h"
namespace ehs
{
/// A wrapper class for the transmission control protocol socket.
class TCP : public BaseTCP
{
protected:
Socket hdl;
public:
/// Frees any native handles.
~TCP() override;
/// Default members initialization.
TCP();
TCP(AddrType addrType);
TCP(TCP&& tcp) noexcept;
/// Copies some members from the given TCP object.
/// @param [in] tcp The TCP object to copy from.
TCP(const TCP& tcp);
TCP& operator=(TCP&& tcp) noexcept;
/// Copies some members from the given TCP object.
/// @param [in] tcp The TCP object to copy from.
/// @returns The TCP object that has been assigned to.
TCP& operator=(const TCP& tcp);
void Initialize() override;
/// Frees native handles and uninitializes them.
void Release() override;
/// Binds the UDP socket to a local address and port.
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called.
void Bind(const Str_8& address, UInt_16 port) override;
/// Listens for incoming connections. Used for servers or PtP.
void Listen() override;
/// Accepts an incoming connection. Used for servers or PtP.
/// @returns The accepted client object.
TCP* Accept() override;
/// Connects to a TCP Socket that listens for incoming connections. Used for clients or PtP.
/// @param address The address of the listening TCP socket. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param port The port of the listening TCP socket.
void Connect(const Str_8& address, UInt_16 port) override;
/// Sends data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [in] buffer The C-style array to send.
/// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually sent in bytes.
UInt_64 Send(const Byte* buffer, UInt_32 size) override;
/// Receives data in a C-style array with raw functionality. Meaning no internal help outside of native functions besides error checking.
/// @param [out] buffer The C-style array to receive with.
/// @param [in] size The size of the given C-style array.
/// @returns The size of the data actually received in bytes.
UInt_64 Receive(Byte* buffer, UInt_32 size) override;
/// Sets whether or not receiving data blocks the next task.
/// @param [in] blocking Whether or not to block.
void SetBlocking(bool blocking) override;
/// Retrieves whether or not this socket will block when receiving data.
/// @returns The result.
bool IsBlocking() const override;
bool IsValid() const override;
private:
void Bind_v6(const Str_8& address, UInt_16 port);
void Bind_v4(const Str_8& address, UInt_16 port);
void Connect_v6(const Str_8& address, UInt_16 port);
void Connect_v4(const Str_8& address, UInt_16 port);
};
}

View File

@@ -0,0 +1,7 @@
#pragma once
#ifdef EHS_OS_WINDOWS
#include "UDP_W32.h"
#else
#include "UDP_BSD.h"
#endif

View File

@@ -0,0 +1,82 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "BaseUDP.h"
namespace ehs
{
/// A wrapper class for the user datagram protocol socket.
class UDP : public BaseUDP
{
private:
Socket hdl;
public:
/// Frees any native handles.
~UDP() override;
UDP();
/// Default members initialization.
UDP(AddrType type);
UDP(UDP&& udp) noexcept;
/// Copies some members from the given UDP object.
/// @param [in] udp The UDP object to copy from.
UDP(const UDP& udp);
UDP& operator=(UDP&& udp) noexcept;
/// Copies some members from the given UDP object.
/// @param [in] udp The UDP object to copy from.
/// @returns The UDP object that has been assigned to.
UDP& operator=(const UDP& udp);
/// Frees native handles and uninitializes them.
void Release() override;
/// Binds the UDP socket to a local address and port.
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called.
void Bind(AddrType type, const Str_8& address, UInt_16 port) override;
/// Sends data using a C-style byte array.
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The remote port to send to.
/// @param [in] data The C-style byte array to send.
/// @param [in] size The size of the C-style byte array.
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) override;
/// Receives data using the packet helper class.
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
/// @param [out] port The port of the sender.
/// @param [out] data The C-style byte array received.
/// @param [in] size The size of the pre-allocated C-style byte array.
/// @returns The size of the data received.
/// @warning The provided C-style byte array must be freed when finished using.
UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) override;
/// Sets whether or not receiving data blocks the next task.
/// @param [in] blocking Whether or not to block.
void SetBlocking(bool blocking) override;
/// Retrieves whether or not this socket will block when receiving data.
/// @returns The result.
bool IsBlocking() const override;
bool IsValid() const override;
private:
void Bind_v6(const Str_8& address, UInt_16 port) const;
void Bind_v4(const Str_8& address, UInt_16 port) const;
UInt_64 Send_v6(const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size);
UInt_64 Send_v4(const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size);
};
}

View File

@@ -0,0 +1,82 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "BaseUDP.h"
namespace ehs
{
/// A wrapper class for the user datagram protocol socket.
class UDP : public BaseUDP
{
private:
Socket hdl;
public:
/// Frees any native handles.
~UDP() override;
UDP();
/// Default members initialization.
UDP(const AddrType addrType);
UDP(UDP&& udp) noexcept;
/// Copies some members from the given UDP object.
/// @param [in] udp The UDP object to copy from.
UDP(const UDP& udp);
UDP& operator=(UDP&& udp) noexcept;
/// Copies some members from the given UDP object.
/// @param [in] udp The UDP object to copy from.
/// @returns The UDP object that has been assigned to.
UDP& operator=(const UDP& udp);
/// Frees native handles and uninitializes them.
void Release() override;
/// Binds the UDP socket to a local address and port.
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The port to bind to.
/// @note Requires the port given to be forwarded if this is called.
void Bind(AddrType type, const Str_8& address, UInt_16 port) override;
/// Sends data using a C-style byte array.
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
/// @param [in] port The remote port to send to.
/// @param [in] data The C-style byte array to send.
/// @param [in] size The size of the C-style byte array.
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
UInt_64 Send(AddrType type, const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size) override;
/// Receives data using the packet helper class.
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
/// @param [out] port The port of the sender.
/// @param [out] data The C-style byte array received.
/// @param [in] size The size of the pre-allocated C-style byte array.
/// @returns The size of the data received.
/// @warning The provided C-style byte array must be freed when finished using.
UInt_64 Receive(AddrType* type, Str_8* addr, UInt_16* port, Byte* data, UInt_64 size) override;
/// Sets whether or not receiving data blocks the next task.
/// @param [in] blocking Whether or not to block.
void SetBlocking(bool blocking) override;
/// Retrieves whether or not this socket will block when receiving data.
/// @returns The result.
bool IsBlocking() const override;
bool IsValid() const override;
private:
void Bind_v6(const Str_8& address, UInt_16 port);
void Bind_v4(const Str_8& address, UInt_16 port);
UInt_64 Send_v6(const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size);
UInt_64 Send_v4(const Str_8& addr, UInt_16 port, const Byte* data, UInt_64 size);
};
}

View File

@@ -0,0 +1,113 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/Array.h"
#include "ehs/io/socket/SSL.h"
namespace ehs
{
enum class SpotifyState
{
TRACK,
CONTEXT,
OFF
};
struct Track
{
Array<Str_8> artists;
Str_8 name;
Str_8 id;
};
class Spotify
{
private:
SSL client;
Str_8 clientId;
Str_8 secret;
Str_8 redURI;
Array<Str_8> scopes;
bool forceVerify;
Str_8 token;
Str_8 rToken;
public:
static const Str_8 trackUriPrefix;
virtual ~Spotify();
Spotify();
Spotify(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify);
bool Authorize();
/// Sets the volume for a device.
/// @param [in] level The percentage to set the volume to.
/// @returns The response code.
UInt_32 SetVolume(const UInt_8 level);
/// Resume playback for a device.
/// @returns The response code.
UInt_32 Play();
/// Pauses playback for a device.
/// @returns The response code.
UInt_32 Pause();
/// Repeats playback for a device.
/// @param [in] status The status to set it to.
/// @returns The response code.
UInt_32 SetRepeat(const SpotifyState state);
/// Shuffles playback for a device.
/// @param [in] state The state to set shuffle to.
/// @returns The response code.
UInt_32 SetShuffle(const bool state);
UInt_32 SearchTrack(Vector<Str_8>& artists, Str_8& id, Str_8& name);
UInt_32 GetPlayingTrack(Vector<Str_8>& artists, Str_8& id, Str_8& name);
UInt_32 GetQueue(Array<Track>& tracks);
/// Adds a track to the queue for a device.
/// @param [in] uri The track id to add.
/// @returns The response code.
UInt_32 QueueTrack(const Str_8& id);
UInt_32 AddTracks(const Str_8& playlistId, const Array<Str_8>& trackIds, const UInt_32 pos = 0);
UInt_32 AddTrack(const Str_8& playlistId, const Str_8& trackId, const UInt_32 pos = 0);
/// Skips to the next track.
/// @returns The response code.
UInt_32 Skip();
/// Skips to the previous track.
/// @returns The response code.
UInt_32 Previous();
/// Seeks to a position of the currently playing track in milliseconds.
/// @param [in] pos The position in milliseconds to seek to.
/// @returns The response code.
UInt_32 Seek(const UInt_32 pos);
Str_8 GetClientId() const;
Str_8 GetSecret() const;
Str_8 GetRedURI() const;
bool IsVerificationForced() const;
bool IsActive() const;
private:
void StartConnection();
bool ReAuthorize();
};
}

View File

@@ -0,0 +1,39 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/io/socket/SSL.h"
namespace ehs
{
class Twitch
{
private:
SSL client;
Str_8 clientId;
Str_8 secret;
Str_8 redURI;
Array<Str_8> scopes;
bool forceVerify;
Str_8 token;
public:
virtual ~Twitch();
Twitch();
Twitch(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify);
bool Authorize();
Str_8 GetClientId() const;
Str_8 GetSecret() const;
Str_8 GetRedURI() const;
bool IsVerificationForced() const;
Str_8 GetToken() const;
};
}

View File

@@ -0,0 +1,53 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "ehs/io/socket/TCP.h"
namespace ehs
{
class TwitchChat
{
private:
TCP client;
Str_8 username;
Str_8 token;
Str_8 channel;
bool initialized;
public:
~TwitchChat();
TwitchChat();
TwitchChat(const Str_8& username);
TwitchChat(const Str_8& username, const Str_8& token);
TwitchChat(const TwitchChat& chat);
TwitchChat& operator=(const TwitchChat& chat);
void SetToken(const Str_8& newToken);
void Initialize();
void UnInitialize();
void JoinChannel(const Str_8& newChannel);
void LeaveChannel();
void SendPong();
void SendMsg(const Str_8& msg);
void WhisperMsg(const Str_8& user, const Str_8& msg);
Str_8 RecvMsg();
Str_8 GetUsername() const;
Str_8 GetChannel() const;
};
}

File diff suppressed because it is too large Load Diff