First commit.
This commit is contained in:
commit
09ced8e899
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
*.obj
|
||||
*.cpp.obj
|
||||
*.lib
|
||||
*.exe
|
||||
*.a
|
||||
*.ninja_deps
|
||||
*.ninja_log
|
||||
*.ninja
|
||||
*.cmake
|
||||
*.log
|
||||
/.idea/
|
||||
/cmake-build-release/
|
||||
/cmake-build-debug/
|
266
CMakeLists.txt
Normal file
266
CMakeLists.txt
Normal file
@ -0,0 +1,266 @@
|
||||
cmake_minimum_required(VERSION 3.18.4)
|
||||
|
||||
set(IS_OS_WINDOWS FALSE)
|
||||
set(IS_OS_LINUX FALSE)
|
||||
set(IS_OS_MAC FALSE)
|
||||
|
||||
set(IS_ARCH_AMD64 FALSE)
|
||||
set(IS_ARCH_X86 FALSE)
|
||||
set(IS_ARCH_ARM64 FALSE)
|
||||
set(IS_ARCH_ARM FALSE)
|
||||
|
||||
project(EHS CXX C)
|
||||
|
||||
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
|
||||
set(IS_OS_WINDOWS TRUE)
|
||||
set(USER_HOME_DIRECTORY $ENV{USERPROFILE})
|
||||
message("Building for the Windows operating system.")
|
||||
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set(IS_OS_LINUX TRUE)
|
||||
set(USER_HOME_DIRECTORY $ENV{HOME})
|
||||
add_compile_options(-Wno-stringop-overflow)
|
||||
message("Building for the Linux operating system.")
|
||||
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
set(IS_OS_MAC TRUE)
|
||||
set(USER_HOME_DIRECTORY $ENV{HOME})
|
||||
message("Building for the Mac operating system.")
|
||||
endif ()
|
||||
|
||||
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
|
||||
set(IS_ARCH_AMD64 TRUE)
|
||||
enable_language(ASM_NASM)
|
||||
message("Building for the AMD64 architecture.")
|
||||
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
|
||||
set(IS_ARCH_ARM64 TRUE)
|
||||
enable_language(ASM)
|
||||
message("Building for the ARM64 architecture.")
|
||||
endif ()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
set(EHS_SOURCES
|
||||
src/EHS.cpp include/EHS.h
|
||||
src/Type.cpp include/Type.h
|
||||
src/BaseObj.cpp include/BaseObj.h
|
||||
src/GarbageCollector.cpp include/GarbageCollector.h
|
||||
src/Log.cpp include/Log.h
|
||||
src/URI.cpp include/URI.h
|
||||
src/Math.cpp include/Math.h
|
||||
src/Color4.cpp include/Color4.h
|
||||
src/Color3.cpp include/Color3.h
|
||||
src/Version.cpp include/Version.h
|
||||
src/Base64.cpp include/Base64.h
|
||||
src/Data.cpp include/Data.h
|
||||
src/Range.cpp include/Range.h
|
||||
src/Util.cpp include/Util.h
|
||||
src/Task.cpp include/Task.h
|
||||
src/DataType.cpp include/DataType.h
|
||||
src/Encryption.cpp include/Encryption.h
|
||||
include/Anchor.h
|
||||
include/Dock.h
|
||||
include/HashMap.h
|
||||
include/HRNG.h
|
||||
include/Link.h
|
||||
include/LinkedList.h
|
||||
include/Mat2.h
|
||||
include/Mat3.h
|
||||
include/Mat4.h
|
||||
include/PRNG.h
|
||||
include/Quat.h
|
||||
include/Rect.h
|
||||
include/Str.h
|
||||
include/Types.h
|
||||
include/UTF.h
|
||||
include/Vec2.h
|
||||
include/Vec3.h
|
||||
include/Vec4.h
|
||||
include/Serializer.h
|
||||
include/Array.h
|
||||
include/Vector.h
|
||||
include/SArray.h
|
||||
src/PtrData.cpp include/PtrData.h
|
||||
include/UniPtr.h
|
||||
include/ShdPtr.h
|
||||
include/WkPtr.h
|
||||
|
||||
src/Database/DVar.cpp include/Database/DVar.h
|
||||
|
||||
src/System/CPU.cpp include/System/CPU.h
|
||||
src/System/Thread.cpp include/System/Thread.h
|
||||
src/System/BaseMutex.cpp include/System/BaseMutex.h
|
||||
src/System/BaseSemaphore.cpp include/System/BaseSemaphore.h
|
||||
src/System/BaseSystem.cpp include/System/BaseSystem.h
|
||||
src/System/BaseOpen.cpp include/System/BaseOpen.h
|
||||
include/System/Architecture.h
|
||||
include/System/Mutex.h
|
||||
include/System/Open.h
|
||||
include/System/OS.h
|
||||
include/System/Semaphore.h
|
||||
include/System/System.h
|
||||
|
||||
src/Json/Json.cpp include/Json/Json.h
|
||||
src/Json/JsonBase.cpp include/Json/JsonBase.h
|
||||
src/Json/JsonNum.cpp include/Json/JsonNum.h
|
||||
src/Json/JsonBool.cpp include/Json/JsonBool.h
|
||||
src/Json/JsonStr.cpp include/Json/JsonStr.h
|
||||
src/Json/JsonObj.cpp include/Json/JsonObj.h
|
||||
src/Json/JsonArray.cpp include/Json/JsonArray.h
|
||||
src/Json/JsonVar.cpp include/Json/JsonVar.h
|
||||
|
||||
src/IO/Console.cpp include/IO/Console.h
|
||||
src/IO/RIFF_Chunk.cpp include/IO/RIFF_Chunk.h
|
||||
src/IO/RIFF.cpp include/IO/RIFF.h
|
||||
src/IO/BaseWindow.cpp include/IO/BaseWindow.h
|
||||
src/IO/BaseFile.cpp include/IO/BaseFile.h
|
||||
src/IO/Glyph.cpp include/IO/Glyph.h
|
||||
src/IO/FontAtlas.cpp include/IO/FontAtlas.h
|
||||
src/IO/BaseFileMonitor.cpp include/IO/BaseFileMonitor.h
|
||||
include/IO/COM.h
|
||||
include/IO/File.h
|
||||
include/IO/FileMonitor.h
|
||||
include/IO/Window.h
|
||||
|
||||
src/IO/Socket/Request.cpp include/IO/Socket/Request.h
|
||||
src/IO/Socket/Response.cpp include/IO/Socket/Response.h
|
||||
src/IO/Socket/DNS.cpp include/IO/Socket/DNS.h
|
||||
src/IO/Socket/BaseUDP.cpp include/IO/Socket/BaseUDP.h
|
||||
src/IO/Socket/BaseTCP.cpp include/IO/Socket/BaseTCP.h
|
||||
src/IO/Socket/Comms.cpp include/IO/Socket/Comms.h
|
||||
src/IO/Socket/CommsSystem.cpp include/IO/Socket/CommsSystem.h
|
||||
src/IO/Socket/Operation.cpp include/IO/Socket/Operation.h
|
||||
src/IO/Socket/Fragments.cpp include/IO/Socket/Fragments.h
|
||||
src/IO/Socket/Endpoint.cpp include/IO/Socket/Endpoint.h
|
||||
src/IO/Socket/SSL.cpp include/IO/Socket/SSL.h
|
||||
|
||||
src/IO/Socket/RestAPIs/Twitch.cpp include/IO/Socket/RestAPIs/Twitch.h
|
||||
src/IO/Socket/RestAPIs/TwitchChat.cpp include/IO/Socket/RestAPIs/TwitchChat.h
|
||||
src/IO/Socket/RestAPIs/Spotify.cpp include/IO/Socket/RestAPIs/Spotify.h
|
||||
include/IO/Socket/Socket.h
|
||||
include/IO/Socket/TCP.h
|
||||
include/IO/Socket/UDP.h
|
||||
include/IO/Socket/Utils.h
|
||||
|
||||
src/IO/Audio/Audio.cpp include/IO/Audio/Audio.h
|
||||
src/IO/Audio/BaseAudioDevice.cpp include/IO/Audio/BaseAudioDevice.h
|
||||
src/IO/Audio/AudioCodec.cpp include/IO/Audio/AudioCodec.h
|
||||
include/IO/Audio/AudioDevice.h
|
||||
|
||||
src/IO/Img/PNG.cpp include/IO/Img/PNG.h
|
||||
src/IO/Img/Img.cpp include/IO/Img/Img.h
|
||||
src/IO/Img/PNG_Chunk.cpp include/IO/Img/PNG_Chunk.h
|
||||
src/IO/Img/ImgCodec.cpp include/IO/Img/ImgCodec.h
|
||||
|
||||
include/IO/Model/Vertex.h
|
||||
src/IO/Model/Mesh.cpp include/IO/Model/Mesh.h
|
||||
src/IO/Model/Bone.cpp include/IO/Model/Bone.h
|
||||
src/IO/Model/Model.cpp include/IO/Model/Model.h
|
||||
src/IO/Model/Animation.cpp include/IO/Model/Animation.h
|
||||
src/IO/Model/AnimBone.cpp include/IO/Model/AnimBone.h
|
||||
src/IO/Model/KeyFrame.cpp include/IO/Model/KeyFrame.h
|
||||
src/IO/Model/PropertyChange.cpp include/IO/Model/PropertyChange.h
|
||||
|
||||
src/IO/HID/ButtonState.cpp include/IO/HID/ButtonState.h
|
||||
src/IO/HID/Button.cpp include/IO/HID/Button.h
|
||||
src/IO/HID/Mouse.cpp include/IO/HID/Mouse.h
|
||||
src/IO/HID/Keyboard.cpp include/IO/HID/Keyboard.h
|
||||
src/IO/HID/HID.cpp include/IO/HID/HID.h
|
||||
src/IO/HID/InputHandler.cpp include/IO/HID/InputHandler.h
|
||||
src/IO/HID/Input.cpp include/IO/HID/Input.h
|
||||
)
|
||||
|
||||
if (IS_OS_WINDOWS)
|
||||
list(APPEND EHS_SOURCES
|
||||
src/IO/Socket/UDP_W32.cpp include/IO/Socket/UDP_W32.h
|
||||
src/IO/Socket/TCP_W32.cpp include/IO/Socket/TCP_W32.h
|
||||
src/System/Semaphore_W32.cpp include/System/Semaphore_W32.h
|
||||
src/System/System_W32.cpp include/System/System_W32.h
|
||||
src/System/Mutex_W32.cpp include/System/Mutex_W32.h
|
||||
src/System/Open_W32.cpp include/System/Open_W32.h
|
||||
src/IO/Audio/AudioDevice_W32.cpp include/IO/Audio/AudioDevice_W32.h
|
||||
src/IO/MsgBox.cpp include/IO/MsgBox.h
|
||||
src/IO/File_W32.cpp include/IO/File_W32.h
|
||||
src/IO/FileMonitor_W32.cpp include/IO/FileMonitor_W32.h
|
||||
src/IO/Window_W32.cpp include/IO/Window_W32.h
|
||||
src/IO/COM.cpp include/IO/COM.h
|
||||
src/System/CPU_MSVC_AMD64.asm src/HRNG_MSVC.asm src/Math_MSVC_AMD64.asm
|
||||
)
|
||||
elseif (IS_OS_LINUX)
|
||||
list(APPEND EHS_SOURCES
|
||||
src/IO/Socket/UDP_BSD.cpp include/IO/Socket/UDP_BSD.h
|
||||
src/IO/Socket/TCP_BSD.cpp include/IO/Socket/TCP_BSD.h
|
||||
src/System/Semaphore_P.cpp include/System/Semaphore_P.h
|
||||
src/System/System_LNX.cpp include/System/System_LNX.h
|
||||
src/System/Open_UNX.cpp include/System/Open_UNX.h
|
||||
src/IO/File_UNX.cpp include/IO/File_UNX.h
|
||||
src/IO/FileMonitor_UNX.cpp include/IO/FileMonitor_UNX.h
|
||||
src/System/Mutex_PT.cpp include/System/Mutex_PT.h
|
||||
src/IO/Audio/AudioDevice_ALSA.cpp include/IO/Audio/AudioDevice_ALSA.h
|
||||
src/System/FileSystem.cpp include/System/FileSystem.h
|
||||
src/System/User.cpp include/System/User.h
|
||||
)
|
||||
|
||||
set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System")
|
||||
|
||||
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")
|
||||
add_compile_definitions(LWE_WS_WAYLAND)
|
||||
list(APPEND EHS_SOURCES src/IO/xdg-shell-protocol.c include/IO/xdg-shell-client-protocol.h src/IO/Window_Way.cpp include/IO/Window_Way.h)
|
||||
message("Building for Wayland.")
|
||||
elseif (LINUX_WINDOW_SYSTEM STREQUAL "XCB")
|
||||
add_compile_definitions(LWE_WS_XCB)
|
||||
list(APPEND EHS_SOURCES src/IO/Window_XCB.cpp include/IO/Window_XCB.h)
|
||||
message("Building for XCB.")
|
||||
endif ()
|
||||
|
||||
if (IS_ARCH_AMD64)
|
||||
list(APPEND EHS_SOURCES src/System/CPU_GCC_AMD64.asm src/HRNG_GCC.asm src/Math_GCC_AMD64.asm)
|
||||
elseif (IS_ARCH_ARM64)
|
||||
list(APPEND EHS_SOURCES src/System/CPU_ARM64.cpp src/HRNG_ARM64.cpp src/Math_GCC_ARM64.s)
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
#message("${CMAKE_CXX_FLAGS}")
|
||||
|
||||
add_library(EHS ${EHS_SOURCES})
|
||||
|
||||
add_executable(StrToHash src/StrToHash.cpp)
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX "${USER_HOME_DIRECTORY}/Libraries/EHS")
|
||||
install(TARGETS EHS DESTINATION lib)
|
||||
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include)
|
||||
|
||||
install(TARGETS StrToHash DESTINATION bin)
|
||||
|
||||
if (IS_ARCH_AMD64)
|
||||
target_include_directories(EHS PUBLIC "${PROJECT_SOURCE_DIR}/../Libraries/include")
|
||||
target_include_directories(EHS PUBLIC "${PROJECT_SOURCE_DIR}/../Libraries/include/zlib")
|
||||
|
||||
target_link_directories(StrToHash PUBLIC "${PROJECT_SOURCE_DIR}/../Libraries/x64")
|
||||
|
||||
find_package(ZLIB REQUIRED)
|
||||
if (ZLIB_FOUND)
|
||||
message(STATUS "ZLIB was found.")
|
||||
else ()
|
||||
message(STATUS "ZLIB was not found.")
|
||||
endif ()
|
||||
|
||||
find_package(OpenSSL REQUIRED)
|
||||
if (OpenSSL_FOUND)
|
||||
message(STATUS "OpenSSL was found.")
|
||||
else ()
|
||||
message(STATUS "OpenSSL was not found.")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(EHS OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
|
||||
|
||||
if (IS_OS_WINDOWS)
|
||||
target_link_libraries(StrToHash ws2_32 avrt LWE)
|
||||
elseif (IS_OS_LINUX)
|
||||
#add_compile_definitions(LWE_WOOTING)
|
||||
|
||||
target_link_libraries(StrToHash z xcb xcb-cursor xcb-xfixes xcb-xinput wayland-client z asound EHS)
|
||||
endif ()
|
||||
elseif (IS_ARCH_ARM64)
|
||||
target_include_directories(LWE PRIVATE "~/vulkan/1.3.261.1/aarch64/include")
|
||||
endif ()
|
19
include/Anchor.h
Normal file
19
include/Anchor.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class Anchor : UInt_8
|
||||
{
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
TOP_CENTER,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT,
|
||||
BOTTOM_CENTER,
|
||||
CENTER_LEFT,
|
||||
CENTER_RIGHT,
|
||||
CENTER
|
||||
};
|
||||
}
|
399
include/Array.h
Normal file
399
include/Array.h
Normal file
@ -0,0 +1,399 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <algorithm>
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// A helper class for C-style arrays.
|
||||
/// @tparam T Array data type to use.
|
||||
/// @tparam N Number data type to use.
|
||||
template<typename T, typename N = UInt_64>
|
||||
class Array
|
||||
{
|
||||
protected:
|
||||
T* data;
|
||||
N size;
|
||||
|
||||
public:
|
||||
/// Frees any data created on the heap.
|
||||
~Array()
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
/// Default members initialization.
|
||||
Array()
|
||||
: data(nullptr), size(0)
|
||||
{
|
||||
}
|
||||
|
||||
/// Initializes an empty array with the given size.
|
||||
/// @note Data must be assigned manually using an index.
|
||||
explicit Array(const N size)
|
||||
: data(new T[size]), size(size)
|
||||
{
|
||||
}
|
||||
|
||||
/// Initializes this array with an initializer list object.
|
||||
/// @param [in] list The given initializer list.
|
||||
Array(std::initializer_list<T> list)
|
||||
: data(new T[list.size()]), size(list.size())
|
||||
{
|
||||
N i = 0;
|
||||
for (auto v = list.begin(); v != list.end(); ++v)
|
||||
data[i++] = std::move(*v);
|
||||
}
|
||||
|
||||
/// Initializes members with given C-style array.
|
||||
/// @param [in] data The C-style array.
|
||||
/// @param [in] size The size of the given C-style array.
|
||||
Array(const T* const data, const N size)
|
||||
: data(new T[size]), size(size)
|
||||
{
|
||||
for (N i = 0; i < size; ++i)
|
||||
this->data[i] = data[i];
|
||||
}
|
||||
|
||||
/// Copies all members from the given array object.
|
||||
/// @param [in] array The array object to copy from.
|
||||
Array(const Array& array)
|
||||
: data(new T[array.size]), size(array.size)
|
||||
{
|
||||
for (N i = 0; i < size; ++i)
|
||||
data[i] = array.data[i];
|
||||
}
|
||||
|
||||
Array(Array&& array) noexcept
|
||||
: data(array.data), size(array.size)
|
||||
{
|
||||
array.data = nullptr;
|
||||
array.size = 0;
|
||||
}
|
||||
|
||||
/// Copies all members from the given array object.
|
||||
/// @param [in] array The array object to copy from.
|
||||
/// @returns The array that has been assigned to.
|
||||
Array<T, N>& operator=(const Array& array)
|
||||
{
|
||||
if (this == &array)
|
||||
return *this;
|
||||
|
||||
delete[] data;
|
||||
data = new T[array.size];
|
||||
for (N i = 0; i < array.size; ++i)
|
||||
data[i] = array.data[i];
|
||||
|
||||
size = array.size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Array<T, N>& operator=(Array&& array) noexcept
|
||||
{
|
||||
if (this == &array)
|
||||
return *this;
|
||||
|
||||
delete[] data;
|
||||
data = array.data;
|
||||
size = array.size;
|
||||
|
||||
array.data = nullptr;
|
||||
array.size = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Copies all members from the given initializer list object.
|
||||
/// @param [in] list The initializer list object to copy from.
|
||||
/// @returns The array that has been assigned to.
|
||||
Array& operator=(std::initializer_list<T> list)
|
||||
{
|
||||
delete[] data;
|
||||
data = new T[list.size];
|
||||
|
||||
N i = 0;
|
||||
for (auto v = list.begin(); v != list.end(); ++v)
|
||||
data[i++] = std::move(*v);
|
||||
|
||||
size = list.size();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Adds a given array object at the end of the array.
|
||||
/// @param [in] value The given array object to push to the end of the array.
|
||||
Array& operator+=(Array value)
|
||||
{
|
||||
T* result = new T[size + value.size];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
for (N i = 0; i < value.size; ++i)
|
||||
result[size + i] = std::move(value[i]);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
size += value.size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Array& in) const
|
||||
{
|
||||
if (size != in.size)
|
||||
return false;
|
||||
|
||||
return Util::IsEqual(data, in.data, size);
|
||||
}
|
||||
|
||||
bool operator!=(const Array& in) const
|
||||
{
|
||||
if (size != in.size)
|
||||
return true;
|
||||
|
||||
return !Util::IsEqual(data, in.data, size);
|
||||
}
|
||||
|
||||
/// Adds a given array object at the end of the array.
|
||||
/// @param [in] value The given initializer list to push to the end of the array.
|
||||
Array& operator+=(std::initializer_list<T> value)
|
||||
{
|
||||
T* result = new T[size + value.size()];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
N i = 0;
|
||||
for (auto v = value.begin(); v != value.end(); ++v)
|
||||
result[size + i++] = std::move(*v);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
size += value.size();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Adds a given value at the end of the array.
|
||||
/// @param [in] value The given value to push to the end of the array.
|
||||
Array& operator+=(const T value)
|
||||
{
|
||||
T* result = new T[size + 1];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
result[size] = std::move(value);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
++size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Retrieves the raw C-style array from casting an array object.
|
||||
operator T* () const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
/// Swaps two values in the array.
|
||||
/// @param a The first index to swap with.
|
||||
/// @param b The second index to swap with.
|
||||
void Swap(N a, N b) const
|
||||
{
|
||||
T tmp = std::move(data[a]);
|
||||
|
||||
data[a] = std::move(data[b]);
|
||||
data[b] = std::move(tmp);
|
||||
}
|
||||
|
||||
void Insert(const N index, const T value)
|
||||
{
|
||||
N newSize = 0;
|
||||
if (index > size - 1)
|
||||
newSize = size + ((index + 1) - size);
|
||||
else
|
||||
newSize = size + 1;
|
||||
|
||||
T* result = new T[newSize];
|
||||
|
||||
for (N i = 0; i < index; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
result[index] = std::move(value);
|
||||
|
||||
for (N i = index; i < size; ++i)
|
||||
result[i + 1] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
|
||||
size = newSize;
|
||||
}
|
||||
|
||||
T Remove(const N index)
|
||||
{
|
||||
T popped = {};
|
||||
|
||||
if (!size || index >= size)
|
||||
return popped;
|
||||
|
||||
popped = std::move(data[index]);
|
||||
|
||||
N newSize = size - 1;
|
||||
T* result = new T[newSize];
|
||||
|
||||
for (N i = 0; i < index; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
for (N i = index + 1; i < size; ++i)
|
||||
result[i - 1] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
size = newSize;
|
||||
|
||||
return popped;
|
||||
}
|
||||
|
||||
/// Adds a given C-style array at the end of the array.
|
||||
/// @param [in] value The given C-style array to push to the end of the array.
|
||||
/// @param [in] size The size of the given C-style array.
|
||||
void Push(const T* const value, const N size)
|
||||
{
|
||||
T* result = new T[this->size + size];
|
||||
|
||||
for (N i = 0; i < this->size; ++i)
|
||||
result[i] = std::move(this->data[i]);
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[this->size + i] = value[i];
|
||||
|
||||
delete[] data;
|
||||
|
||||
this->data = result;
|
||||
this->size += size;
|
||||
}
|
||||
|
||||
/// Adds a given array object at the end of the array.
|
||||
/// @param [in] value The given array object to push to the end of the array.
|
||||
void Push(Array value)
|
||||
{
|
||||
T* result = new T[size + value.size];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
for (N i = 0; i < value.size; ++i)
|
||||
result[size + i] = std::move(value[i]);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
size += value.size;
|
||||
}
|
||||
|
||||
/// Adds a given array object at the end of the array.
|
||||
/// @param [in] value The given initializer list to push to the end of the array.
|
||||
void Push(std::initializer_list<T> value)
|
||||
{
|
||||
T* result = new T[size + value.size()];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
N i = 0;
|
||||
for (auto v = value.begin(); v != value.end(); ++v)
|
||||
result[size + i++] = std::move(*v);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
size += value.size();
|
||||
}
|
||||
|
||||
/// Adds a given value at the end of the array.
|
||||
/// @param [in] value The given value to push to the end of the array.
|
||||
void Push(T value)
|
||||
{
|
||||
T* result = new T[size + 1];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
result[size] = std::move(value);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
++size;
|
||||
}
|
||||
|
||||
/// Removes a value at the end of the array.
|
||||
/// @returns The value that was popped.
|
||||
T Pop()
|
||||
{
|
||||
T* result = new T[--size];
|
||||
|
||||
T value = std::move(data[size]);
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
delete[] data;
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
/// Resizes the array.
|
||||
/// @param [in] newSize The size to change to.
|
||||
void Resize(const N newSize)
|
||||
{
|
||||
if (size == newSize)
|
||||
return;
|
||||
|
||||
T* result = new T[newSize];
|
||||
|
||||
for (N i = 0; i < newSize && i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
size = newSize;
|
||||
}
|
||||
|
||||
/// Retrieves the size of the array.
|
||||
/// @returns The resulting size.
|
||||
N Size() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
N End() const
|
||||
{
|
||||
return size - 1;
|
||||
}
|
||||
};
|
||||
}
|
24
include/Base64.h
Normal file
24
include/Base64.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Base64
|
||||
{
|
||||
private:
|
||||
static const char ascii[];
|
||||
|
||||
public:
|
||||
static Str_8 Encode(const Str_8 input);
|
||||
|
||||
static Str_8 Decode(const Str_8 input);
|
||||
|
||||
private:
|
||||
static char Find(const char c);
|
||||
|
||||
static bool IsBase64(const char c);
|
||||
|
||||
};
|
||||
}
|
95
include/BaseObj.h
Normal file
95
include/BaseObj.h
Normal file
@ -0,0 +1,95 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Type.h"
|
||||
#include "Array.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class BaseObj
|
||||
{
|
||||
private:
|
||||
Array<Type> hierarchy;
|
||||
BaseObj* parent;
|
||||
|
||||
public:
|
||||
virtual ~BaseObj();
|
||||
|
||||
BaseObj();
|
||||
|
||||
BaseObj(const BaseObj& base);
|
||||
|
||||
BaseObj(BaseObj&& base) noexcept;
|
||||
|
||||
BaseObj& operator=(const BaseObj& base);
|
||||
|
||||
BaseObj& operator=(BaseObj&& base) noexcept;
|
||||
|
||||
bool operator!() const;
|
||||
|
||||
bool operator==(const BaseObj& base) const;
|
||||
|
||||
bool operator!=(const BaseObj& base) const;
|
||||
|
||||
bool HasType(const UInt_64 hashType) const;
|
||||
|
||||
bool HasType(const Str_8& type) const;
|
||||
|
||||
protected:
|
||||
bool AddType(Str_8 type);
|
||||
|
||||
public:
|
||||
Type GetType() const;
|
||||
|
||||
Type GetType(const UInt_64 hashType) const;
|
||||
|
||||
Type GetType(const Str_8& type) const;
|
||||
|
||||
const Char_8* GetTypeId() const;
|
||||
|
||||
UInt_64 GetTypeHashId() const;
|
||||
|
||||
const Array<Type>& GetHierarchy() const;
|
||||
|
||||
void SetParent(BaseObj* newParent);
|
||||
|
||||
BaseObj* GetParent();
|
||||
|
||||
BaseObj* GetParent(const UInt_64 hashType);
|
||||
|
||||
BaseObj* GetParent(const Str_8& type);
|
||||
|
||||
virtual BaseObj* Clone() const;
|
||||
|
||||
virtual bool IsValid() const;
|
||||
};
|
||||
|
||||
inline bool BaseObj::HasType(const UInt_64 hashType) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < hierarchy.Size(); ++i)
|
||||
if (hashType == hierarchy[i].GetHashId())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline Type BaseObj::GetType(const UInt_64 hashType) const
|
||||
{
|
||||
for (UInt_64 i = 0; i < hierarchy.Size(); ++i)
|
||||
if (hashType == hierarchy[i].GetHashId())
|
||||
return hierarchy[i];
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
inline BaseObj* BaseObj::GetParent(const UInt_64 hashType)
|
||||
{
|
||||
BaseObj* result = GetParent();
|
||||
|
||||
while (result && !result->HasType(hashType))
|
||||
result = result->GetParent();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
38
include/Color3.h
Normal file
38
include/Color3.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Color3
|
||||
{
|
||||
public:
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
|
||||
Color3();
|
||||
|
||||
Color3(const float scalar);
|
||||
|
||||
Color3(const float r, const float g, const float b);
|
||||
|
||||
Color3(const Color3& color);
|
||||
|
||||
Color3& operator=(const float scalar);
|
||||
|
||||
Color3& operator=(const Color3& color);
|
||||
|
||||
bool operator==(const Color3& color) const;
|
||||
|
||||
bool operator!=(const Color3& color) const;
|
||||
|
||||
float operator[](const UInt_64 i) const;
|
||||
|
||||
float& operator[](const UInt_64 i);
|
||||
|
||||
Color3& operator*=(const Color3& color);
|
||||
|
||||
Color3 operator*(const Color3& color) const;
|
||||
};
|
||||
}
|
44
include/Color4.h
Normal file
44
include/Color4.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "Color3.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Color4
|
||||
{
|
||||
public:
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
|
||||
Color4();
|
||||
|
||||
Color4(const float scalar);
|
||||
|
||||
explicit Color4(const Color3& color);
|
||||
|
||||
Color4(const float r, const float g, const float b, const float a = 1.0f);
|
||||
|
||||
Color4(const Color4& color);
|
||||
|
||||
Color4& operator=(const float scalar);
|
||||
|
||||
Color4& operator=(const Color3& color);
|
||||
|
||||
Color4& operator=(const Color4& color);
|
||||
|
||||
bool operator==(const Color4& color) const;
|
||||
|
||||
bool operator!=(const Color4& color) const;
|
||||
|
||||
float operator[](const UInt_64 i) const;
|
||||
|
||||
float& operator[](const UInt_64 i);
|
||||
|
||||
Color4& operator*=(const Color4& color);
|
||||
|
||||
Color4 operator*(const Color4& color) const;
|
||||
};
|
||||
}
|
45
include/Data.h
Normal file
45
include/Data.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static void SwapEndianness(T* value)
|
||||
{
|
||||
Byte tmp = 0;
|
||||
for (UInt_64 i = 0; i < sizeof(T) / 2; ++i)
|
||||
{
|
||||
tmp = ((Byte*)value)[i];
|
||||
((Byte*)value)[i] = ((Byte*)value)[sizeof(T) - i - 1];
|
||||
((Byte*)value)[sizeof(T) - i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static Array<T> SwapEndianness(const T* const array, const UInt_64 size)
|
||||
{
|
||||
Array<T> result(size);
|
||||
|
||||
for (UInt_64 i = size; i; --i)
|
||||
result[size - i] = array[i - 1];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename N>
|
||||
static Serializer<N> SwapEndianness(const Serializer<N>& data)
|
||||
{
|
||||
Serializer<N> result(data.Size());
|
||||
|
||||
for (N i = 0; i < data.Size(); ++i)
|
||||
result[i] = data[data.Size() - i - 1];
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
29
include/DataType.h
Normal file
29
include/DataType.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class DataType : UInt_8
|
||||
{
|
||||
LDOUBLE,
|
||||
DOUBLE,
|
||||
SINT_64,
|
||||
UINT_64,
|
||||
FLOAT,
|
||||
SINT_32,
|
||||
UINT_32,
|
||||
SINT_24,
|
||||
UINT_24,
|
||||
SINT_16,
|
||||
UINT_16,
|
||||
SINT_8,
|
||||
UINT_8
|
||||
};
|
||||
|
||||
DataType FromAudioBitDepth(const UInt_16 bitDepth);
|
||||
|
||||
UInt_8 ToByteDepth(const DataType type);
|
||||
|
||||
UInt_8 ToBitDepth(const DataType type);
|
||||
}
|
20
include/Database/DVar.h
Normal file
20
include/Database/DVar.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../BaseObj.h"
|
||||
#include "../Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class DType : UInt_8
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class DVar : public BaseObj
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
};
|
||||
}
|
7
include/Dock.h
Normal file
7
include/Dock.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
enum class Dock
|
||||
{
|
||||
NONE,
|
||||
FILL
|
||||
};
|
63
include/EHS.h
Normal file
63
include/EHS.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NDEBUG)
|
||||
#define LWE_RELEASE
|
||||
#else
|
||||
#define LWE_DEBUG
|
||||
#endif
|
||||
|
||||
#include "Types.h"
|
||||
#include "System/OS.h"
|
||||
#include "Version.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class MemoryPattern
|
||||
{
|
||||
SPEED,
|
||||
SIZE
|
||||
};
|
||||
|
||||
/// Retrieves the UTF32 C-style string as "Event Horizon Standard"
|
||||
/// @returns The result.
|
||||
const Char_32* GetName_32();
|
||||
|
||||
/// Retrieves the UTF16 C-style string as "Event Horizon Standard"
|
||||
/// @returns The result.
|
||||
const Char_16* GetName_16();
|
||||
|
||||
/// Retrieves the UTF8 C-style string as "Event Horizon Standard"
|
||||
/// @returns The result.
|
||||
const Char_8* GetName_8();
|
||||
|
||||
Str_8 GetAppName_8();
|
||||
|
||||
const Char_32* GetAcronym_32();
|
||||
|
||||
const Char_16* GetAcronym_16();
|
||||
|
||||
const Char_8* GetAcronym_8();
|
||||
|
||||
/// Retrieves the version identifier in UTF32.
|
||||
/// @returns The result.
|
||||
const Char_32* GetVersionId_32();
|
||||
|
||||
/// Retrieves the version identifier in UTF16.
|
||||
/// @returns The result.
|
||||
const Char_16* GetVersionId_16();
|
||||
|
||||
/// Retrieves the version identifier in UTF8.
|
||||
/// @returns The result.
|
||||
const Char_8* GetVersionId_8();
|
||||
|
||||
Str_8 GetAppVersionId_8();
|
||||
|
||||
/// Retrieves the current Event Horizon Standard version.
|
||||
/// @returns The result.
|
||||
Version GetVersion();
|
||||
|
||||
Version GetAppVersion();
|
||||
};
|
||||
|
||||
extern lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVer);
|
48
include/Encryption.h
Normal file
48
include/Encryption.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Array.h"
|
||||
#include "Vector.h"
|
||||
#include "Serializer.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Encryption
|
||||
{
|
||||
public:
|
||||
static void Encrypt_64(const UInt_64 key, const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_64(const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_64(Array<Byte>& data);
|
||||
|
||||
static void Encrypt_64(Vector<Byte>& data);
|
||||
|
||||
static void Encrypt_64(Serializer<UInt_64>& data);
|
||||
|
||||
static void Encrypt_32(const UInt_64 key, const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_32(const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_32(Array<Byte>& data);
|
||||
|
||||
static void Encrypt_32(Vector<Byte>& data);
|
||||
|
||||
static void Encrypt_16(const UInt_64 key, const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_16(const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_16(Array<Byte>& data);
|
||||
|
||||
static void Encrypt_16(Vector<Byte>& data);
|
||||
|
||||
static void Encrypt_8(const UInt_64 key, const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_8(const UInt_64 size, Byte* const data);
|
||||
|
||||
static void Encrypt_8(Array<Byte>& data);
|
||||
|
||||
static void Encrypt_8(Vector<Byte>& data);
|
||||
};
|
||||
}
|
60
include/GarbageCollector.h
Normal file
60
include/GarbageCollector.h
Normal file
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Vector.h"
|
||||
#include "BaseObj.h"
|
||||
#include "System/Mutex.h"
|
||||
#include "System/Thread.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class GarbageCollector
|
||||
{
|
||||
private:
|
||||
static Vector<BaseObj*> garbage;
|
||||
static UInt_64 max;
|
||||
static Thread thread;
|
||||
static Mutex mutex;
|
||||
static bool running;
|
||||
|
||||
static bool Has(const BaseObj* obj);
|
||||
|
||||
public:
|
||||
static void Start();
|
||||
|
||||
static void Stop();
|
||||
|
||||
/// Adds an object to the garbage pile to be deleted.
|
||||
/// @param[in] obj The object to be deleted.
|
||||
static void Add(BaseObj* obj);
|
||||
|
||||
/// Sets the maximum amount of garbage to delete per poll.
|
||||
/// @param[in] newMax The new maximum.
|
||||
static void SetMax(const UInt_64 newMax);
|
||||
|
||||
/// Gets the maximum amount of garbage to delete per poll.
|
||||
/// @returns The maximum.
|
||||
static UInt_64 GetMax();
|
||||
|
||||
/// Sets a new amount for memory pre-allocation to save on memory operations.
|
||||
/// @param[in] newStride The stride to pre-allocate.
|
||||
static void SetStride(const UInt_64 newStride);
|
||||
|
||||
/// The amount of data pre-allocated to save on memory operations.
|
||||
/// @returns The stride.
|
||||
static UInt_64 GetStride();
|
||||
|
||||
/// Gets the garbage count.
|
||||
/// @returns Garbage count.
|
||||
static UInt_64 Size();
|
||||
|
||||
/// Used to delete objects over time.
|
||||
static void Poll();
|
||||
|
||||
/// Deletes all of the data at once.
|
||||
/// @warning Use Poll instead to prevent stutter.
|
||||
static void Dump();
|
||||
|
||||
static bool IsRunning();
|
||||
};
|
||||
}
|
59
include/HRNG.h
Normal file
59
include/HRNG.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Types.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class HRNG
|
||||
{
|
||||
public:
|
||||
static UInt_64 GenerateSeed_u64();
|
||||
|
||||
static UInt_64 Generate_u64(const UInt_64 min, const UInt_64 max);
|
||||
|
||||
static UInt_64 Generate_u64();
|
||||
|
||||
static SInt_64 GenerateSeed_s64();
|
||||
|
||||
static SInt_64 Generate_s64(const SInt_64 min, const SInt_64 max);
|
||||
|
||||
static SInt_64 Generate_s64();
|
||||
|
||||
static UInt_32 GenerateSeed_u32();
|
||||
|
||||
static UInt_32 Generate_u32(const UInt_32 min, const UInt_32 max);
|
||||
|
||||
static UInt_32 Generate_u32();
|
||||
|
||||
static SInt_32 GenerateSeed_s32();
|
||||
|
||||
static SInt_32 Generate_s32(const SInt_32 min, const SInt_32 max);
|
||||
|
||||
static SInt_32 Generate_s32();
|
||||
|
||||
static UInt_32 GenerateSeed_u16();
|
||||
|
||||
static UInt_16 Generate_u16(const UInt_16 min, const UInt_16 max);
|
||||
|
||||
static UInt_16 Generate_u16();
|
||||
|
||||
static SInt_16 GenerateSeed_s16();
|
||||
|
||||
static SInt_16 Generate_s16(const SInt_16 min, const SInt_16 max);
|
||||
|
||||
static SInt_16 Generate_s16();
|
||||
|
||||
static UInt_8 GenerateSeed_u8();
|
||||
|
||||
static UInt_8 Generate_u8(const UInt_8 min, const UInt_8 max);
|
||||
|
||||
static UInt_8 Generate_u8();
|
||||
|
||||
static SInt_8 GenerateSeed_s8();
|
||||
|
||||
static SInt_8 Generate_s8(const SInt_8 min, const SInt_8 max);
|
||||
|
||||
static SInt_8 Generate_s8();
|
||||
};
|
||||
}
|
146
include/HashMap.h
Normal file
146
include/HashMap.h
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template<typename V>
|
||||
class HashNode
|
||||
{
|
||||
private:
|
||||
V value;
|
||||
HashNode child;
|
||||
|
||||
public:
|
||||
HashNode()
|
||||
{
|
||||
}
|
||||
|
||||
HashNode(const V value)
|
||||
: value(value)
|
||||
{
|
||||
}
|
||||
|
||||
HashNode(const HashNode& node)
|
||||
: value(node.value), child(node.child)
|
||||
{
|
||||
}
|
||||
|
||||
HashNode& operator==(const HashNode& node)
|
||||
{
|
||||
value = node.value;
|
||||
child = node.child;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void SetValue(const V value)
|
||||
{
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
V GetValue() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void SetChild(const HashNode child)
|
||||
{
|
||||
this->child = child;
|
||||
}
|
||||
|
||||
HashNode* GetChild()
|
||||
{
|
||||
return &child;
|
||||
}
|
||||
};
|
||||
|
||||
/// 1000
|
||||
template<typename V, typename N = USize>
|
||||
class HashMap
|
||||
{
|
||||
private:
|
||||
HashNode<V>** data;
|
||||
N size;
|
||||
|
||||
public:
|
||||
~HashMap()
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
delete[] data;
|
||||
data = nullptr;
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
HashMap()
|
||||
: data(nullptr), size(0)
|
||||
{
|
||||
}
|
||||
|
||||
HashMap(const N size)
|
||||
: data(new HashNode<V>(size)), size(size)
|
||||
{
|
||||
}
|
||||
|
||||
HashMap(const HashMap& map)
|
||||
: data(new HashNode<V>*(map.size)), size(map.size)
|
||||
{
|
||||
for (N i = 0; i < map.size; ++i)
|
||||
data[i] = map.data[i];
|
||||
}
|
||||
|
||||
HashMap& operator=(const HashMap& map)
|
||||
{
|
||||
if (this == &map)
|
||||
return *this;
|
||||
|
||||
data = new HashNode<V>*(map.size);
|
||||
size = map.size;
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
data[i] = map.data[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename K>
|
||||
void Insert(const K key, const V value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
void Insert(const Str_8& key, const V value)
|
||||
{
|
||||
N hash = 0;
|
||||
|
||||
for (N i = 0; i < key.Size(); ++i)
|
||||
hash += key[i];
|
||||
|
||||
hash %= size;
|
||||
|
||||
if (data[hash])
|
||||
{
|
||||
HashNode<V> child = data[hash]->GetChild();
|
||||
if (child)
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
data[hash] = new HashNode<V>(value);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SetChildRecursive()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
199
include/IO/Audio/Audio.h
Normal file
199
include/IO/Audio/Audio.h
Normal file
@ -0,0 +1,199 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../DataType.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Array.h"
|
||||
#include "AudioCodec.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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(const UInt_64 hashExt);
|
||||
|
||||
static bool HasCodec(const Str_8& ext);
|
||||
|
||||
static bool AddCodec(AudioCodec codec);
|
||||
|
||||
static const AudioCodec* GetCodec(const UInt_64 hashExt);
|
||||
|
||||
static const AudioCodec* GetCodec(const Str_8& ext);
|
||||
|
||||
~Audio() override;
|
||||
|
||||
Audio();
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames, const Byte* const data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Serializer<UInt_64>& data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Vector<Byte>& data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Array<Byte>& data);
|
||||
|
||||
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const 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*();
|
||||
|
||||
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(const UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsStereo(const UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsFive_One(const UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsSeven_One(const UInt_64 frameIndex) const;
|
||||
|
||||
SInt_8 SampleAsSInt_8(const UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_16 SampleAsSInt_16(const UInt_64 sampleIndex) const;
|
||||
|
||||
float SampleAsFloat(const UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_32 SampleAsSInt_32(const UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_64 SampleAsSInt_64(const 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(const UInt_64 size, const Byte* newPeak);
|
||||
|
||||
const Byte* GetPeak() const;
|
||||
|
||||
void ToDataType(const DataType newDataType);
|
||||
|
||||
Audio GetAsDataType(const DataType newDataType) const;
|
||||
|
||||
void ToChannels(const UInt_8 newChannels);
|
||||
|
||||
Audio GetAsChannels(const 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, const DataType required);
|
||||
|
||||
static Audio* FromFile_Heap(const Str_8& filePath, const DataType required);
|
||||
|
||||
static Audio FromData(const Str_8& ext, const Str_8& id, Serializer<UInt_64>& data);
|
||||
|
||||
private:
|
||||
void ToMono(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Five_One_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Seven_One_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Stereo_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Seven_One_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Stereo_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||||
|
||||
void Five_One_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const 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;
|
||||
};
|
||||
}
|
48
include/IO/Audio/AudioCodec.h
Normal file
48
include/IO/Audio/AudioCodec.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../File.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
9
include/IO/Audio/AudioDevice.h
Normal file
9
include/IO/Audio/AudioDevice.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "AudioDevice_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#include "AudioDevice_ALSA.h"
|
||||
#endif
|
46
include/IO/Audio/AudioDevice_ALSA.h
Normal file
46
include/IO/Audio/AudioDevice_ALSA.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "BaseAudioDevice.h"
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
66
include/IO/Audio/AudioDevice_W32.h
Normal file
66
include/IO/Audio/AudioDevice_W32.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "BaseAudioDevice.h"
|
||||
|
||||
#include <initguid.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <functiondiscoverykeys_devpkey.h>
|
||||
#include <Audioclient.h>
|
||||
|
||||
struct IMMDevice;
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
105
include/IO/Audio/BaseAudioDevice.h
Normal file
105
include/IO/Audio/BaseAudioDevice.h
Normal file
@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Array.h"
|
||||
#include "../../DataType.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
260
include/IO/BaseFile.h
Normal file
260
include/IO/BaseFile.h
Normal file
@ -0,0 +1,260 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Array.h"
|
||||
#include "../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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 ProcessFullName_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ProcessFullName_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ProcessFullName_8(const Str_8& filePath);
|
||||
|
||||
static Str_32 ProcessName_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ProcessName_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ProcessName_8(const Str_8& filePath);
|
||||
|
||||
static Str_32 ProcessExt_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ProcessExt_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ProcessExt_8(const Str_8& filePath);
|
||||
};
|
||||
}
|
46
include/IO/BaseFileMonitor.h
Normal file
46
include/IO/BaseFileMonitor.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
#define LWE_FE_NONE 0x00
|
||||
#define LWE_FE_MODIFIED 0x01
|
||||
#define LWE_FE_DELETED 0x02
|
||||
#define LWE_FE_MOVED 0x04
|
||||
#define LWE_FE_OPENED 0x08
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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/IO/BaseWindow.h
Normal file
114
include/IO/BaseWindow.h
Normal file
@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vec2.h"
|
||||
#include "../Rect.h"
|
||||
#include "HID/Input.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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/IO/COM.h
Normal file
55
include/IO/COM.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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/IO/Console.h
Normal file
115
include/IO/Console.h
Normal file
@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Str.h"
|
||||
#include "../UTF.h"
|
||||
#include "../Array.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
typedef void* ConsoleHdl;
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
typedef int ConsoleHdl;
|
||||
#endif
|
||||
|
||||
class Console
|
||||
{
|
||||
private:
|
||||
static ConsoleHdl hdlOut;
|
||||
static ConsoleHdl hdlIn;
|
||||
|
||||
#if defined(LWE_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/IO/File.h
Normal file
9
include/IO/File.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "File_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#include "File_UNX.h"
|
||||
#endif
|
7
include/IO/FileMonitor.h
Normal file
7
include/IO/FileMonitor.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "FileMonitor_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#include "FileMonitor_UNX.h"
|
||||
#endif
|
37
include/IO/FileMonitor_UNX.h
Normal file
37
include/IO/FileMonitor_UNX.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "BaseFileMonitor.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
37
include/IO/FileMonitor_W32.h
Normal file
37
include/IO/FileMonitor_W32.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "BaseFileMonitor.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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/IO/File_UNX.h
Normal file
73
include/IO/File_UNX.h
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../UTF.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Array.h"
|
||||
#include "../Serializer.h"
|
||||
#include "BaseFile.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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/IO/File_W32.h
Normal file
74
include/IO/File_W32.h
Normal file
@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../UTF.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Array.h"
|
||||
#include "../Serializer.h"
|
||||
#include "BaseFile.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
48
include/IO/FontAtlas.h
Normal file
48
include/IO/FontAtlas.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Array.h"
|
||||
|
||||
#include "Glyph.h"
|
||||
#include "../Anchor.h"
|
||||
#include "Img/Img.h"
|
||||
#include "Model/Mesh.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class FontAtlas : public Img
|
||||
{
|
||||
private:
|
||||
UInt_64 glyphScale;
|
||||
Array<Glyph> glyphs;
|
||||
|
||||
public:
|
||||
FontAtlas();
|
||||
|
||||
FontAtlas(const Str_8& filePath);
|
||||
|
||||
FontAtlas(FontAtlas&& fa) noexcept;
|
||||
|
||||
FontAtlas(const FontAtlas& fa);
|
||||
|
||||
FontAtlas& operator=(FontAtlas&& fa) noexcept;
|
||||
|
||||
FontAtlas& operator=(const FontAtlas& fa);
|
||||
|
||||
UInt_64 GetGlyphScale() const;
|
||||
|
||||
Glyph GetGlyph(const Char_32 code) 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(const Anchor anchor, const Str_8& text) const;
|
||||
|
||||
FontAtlas* Clone() const override;
|
||||
};
|
||||
}
|
59
include/IO/Glyph.h
Normal file
59
include/IO/Glyph.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Vec2.h"
|
||||
#include "../Rect.h"
|
||||
#include "../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
31
include/IO/HID/Button.h
Normal file
31
include/IO/HID/Button.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
55
include/IO/HID/ButtonState.h
Normal file
55
include/IO/HID/ButtonState.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "Button.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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/IO/HID/HID.h
Normal file
91
include/IO/HID/HID.h
Normal file
@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Array.h"
|
||||
#include "ButtonState.h"
|
||||
|
||||
#define LWE_HID_UNKNOWN 0
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
46
include/IO/HID/Input.h
Normal file
46
include/IO/HID/Input.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Array.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "InputHandler.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
58
include/IO/HID/InputHandler.h
Normal file
58
include/IO/HID/InputHandler.h
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Array.h"
|
||||
#include "HID.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
121
include/IO/HID/Keyboard.h
Normal file
121
include/IO/HID/Keyboard.h
Normal file
@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Types.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define LWE_HID_KEYBOARD 0x02
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Keyboard : public HID
|
||||
{
|
||||
public:
|
||||
Keyboard();
|
||||
|
||||
Keyboard(Str_8 name, const 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(const UInt_32 code);
|
||||
|
||||
static Char_8 TranslateToEnglish_8(const bool shifted, const Button& button);
|
||||
};
|
||||
}
|
55
include/IO/HID/Mouse.h
Normal file
55
include/IO/HID/Mouse.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Types.h"
|
||||
#include "../../Vec2.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define LWE_HID_MOUSE 0x01
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
178
include/IO/Img/Img.h
Normal file
178
include/IO/Img/Img.h
Normal file
@ -0,0 +1,178 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "ImgCodec.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class Resampling : UInt_8
|
||||
{
|
||||
NONE,
|
||||
NEAREST_NEIGHBOR
|
||||
};
|
||||
|
||||
class Img
|
||||
{
|
||||
private:
|
||||
static Array<ImgCodec> codecs;
|
||||
|
||||
protected:
|
||||
UInt_8 bitDepth;
|
||||
UInt_8 channels;
|
||||
UInt_64 width;
|
||||
UInt_64 height;
|
||||
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();
|
||||
|
||||
Img();
|
||||
|
||||
Img(UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height, const Byte* data);
|
||||
|
||||
Img(UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height);
|
||||
|
||||
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_8 BitDepth() const;
|
||||
|
||||
UInt_8 Channels() const;
|
||||
|
||||
UInt_64 Width() const;
|
||||
|
||||
UInt_64 Height() const;
|
||||
|
||||
UInt_64 Size() 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, UInt_64 newWidth, UInt_64 newHeight);
|
||||
|
||||
Img GetResized(Resampling method, UInt_64 newWidth, UInt_64 newHeight) 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(const Str_8& ext, Serializer<UInt_64>& data);
|
||||
|
||||
private:
|
||||
Img GetNearestNeighbor(UInt_64 newWidth, UInt_64 newHeight) const;
|
||||
|
||||
void NearestNeighbor(UInt_64 newWidth, UInt_64 newHeight);
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
48
include/IO/Img/ImgCodec.h
Normal file
48
include/IO/Img/ImgCodec.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../File.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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/IO/Img/PNG.h
Normal file
51
include/IO/Img/PNG.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "PNG_Chunk.h"
|
||||
#include "Img.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
34
include/IO/Img/PNG_Chunk.h
Normal file
34
include/IO/Img/PNG_Chunk.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
40
include/IO/Model/AnimBone.h
Normal file
40
include/IO/Model/AnimBone.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "KeyFrame.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
49
include/IO/Model/Animation.h
Normal file
49
include/IO/Model/Animation.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Array.h"
|
||||
#include "AnimBone.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
73
include/IO/Model/Bone.h
Normal file
73
include/IO/Model/Bone.h
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Quat.h"
|
||||
#include "../../Mat4.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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, const 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(const UInt_64 hashName, const UInt_8 id) const;
|
||||
|
||||
bool HasBone(const UInt_64 hashName) const;
|
||||
|
||||
bool HasBone(const UInt_8 id) const;
|
||||
|
||||
bool AddBone(Bone child);
|
||||
|
||||
const Bone* GetBone(const UInt_64 hashName) const;
|
||||
|
||||
Bone* GetBone(const UInt_64 hashName);
|
||||
|
||||
const Bone* GetBone(const UInt_8 id) const;
|
||||
|
||||
Bone* GetBone(const UInt_8 id);
|
||||
|
||||
const Array<Bone>& GetChildren() const;
|
||||
|
||||
Array<Bone>& GetChildren();
|
||||
};
|
||||
}
|
55
include/IO/Model/KeyFrame.h
Normal file
55
include/IO/Model/KeyFrame.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "../../Vec3.h"
|
||||
#include "../../Quat.h"
|
||||
#include "../../Mat4.h"
|
||||
#include "PropertyChange.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
101
include/IO/Model/Mesh.h
Normal file
101
include/IO/Model/Mesh.h
Normal file
@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
const Array<Vertex_f> portraitGuiVerts({
|
||||
{{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}}
|
||||
});
|
||||
|
||||
const Array<UInt_32> portraitGuiIndices({
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
1
|
||||
});
|
||||
|
||||
const Array<Vertex_f> portraitVerts({
|
||||
{{-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}}
|
||||
});
|
||||
|
||||
const Array<UInt_32> portraitIndices({
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
1
|
||||
});
|
||||
|
||||
class Mesh : public Resource
|
||||
{
|
||||
protected:
|
||||
Array<Vertex_f> vertices;
|
||||
Array<UInt_32> indices;
|
||||
GpuBuffer srcVertBuffer;
|
||||
GpuBuffer dstVertBuffer;
|
||||
GpuBuffer srcIndBuffer;
|
||||
GpuBuffer dstIndBuffer;
|
||||
|
||||
public:
|
||||
Mesh();
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices, Array<UInt_32> indices);
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices);
|
||||
|
||||
Mesh(Str_8 id);
|
||||
|
||||
Mesh(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh(const Mesh& mesh);
|
||||
|
||||
Mesh& operator=(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh& operator=(const Mesh& mesh);
|
||||
|
||||
bool UploadToGpu(GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
bool PostGpuUpload() override;
|
||||
|
||||
bool HasPostGpuUploaded() const override;
|
||||
|
||||
bool ReleaseFromGpu() override;
|
||||
|
||||
bool IsUploaded() const override;
|
||||
|
||||
void Bind(GpuCmdBuffer* cmdBuffer);
|
||||
|
||||
void Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances = 1);
|
||||
|
||||
void SetVertices(const Array<Vertex_f>& newVertices);
|
||||
|
||||
Array<Vertex_f> GetVertices() const;
|
||||
|
||||
Array<Vertex_f>& GetVertices();
|
||||
|
||||
void SetIndices(const Array<UInt_32>& newIndices);
|
||||
|
||||
bool HasIndices() 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);
|
||||
};
|
||||
}
|
80
include/IO/Model/Model.h
Normal file
80
include/IO/Model/Model.h
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "../File.h"
|
||||
#include "Mesh.h"
|
||||
#include "Bone.h"
|
||||
#include "Animation.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class ModelEncoding : UInt_8
|
||||
{
|
||||
EHM
|
||||
};
|
||||
|
||||
class Model : public Resource
|
||||
{
|
||||
protected:
|
||||
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;
|
||||
|
||||
bool UploadToGpu(GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
bool PostGpuUpload() override;
|
||||
|
||||
bool ReleaseFromGpu() override;
|
||||
|
||||
bool IsUploaded() const override;
|
||||
|
||||
void Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances = 1);
|
||||
|
||||
Array<Mesh> GetMeshes() const;
|
||||
|
||||
Array<Mesh>& GetMeshes();
|
||||
|
||||
Mesh* GetMesh(const UInt_64 hashId);
|
||||
|
||||
Mesh* GetMesh(const Str_8& id);
|
||||
|
||||
Bone GetSkeleton() const;
|
||||
|
||||
Bone& GetSkeleton();
|
||||
|
||||
Animation* GetAnimation(const UInt_64 hashId);
|
||||
|
||||
Array<Animation> GetAnimations() const;
|
||||
|
||||
Array<Animation>& GetAnimations();
|
||||
|
||||
void Calculate();
|
||||
|
||||
void Export(const Str_8& filePath, const ModelEncoding encoding);
|
||||
|
||||
private:
|
||||
void ToEHM(File& file);
|
||||
|
||||
void FromEHM(File& file);
|
||||
};
|
||||
}
|
32
include/IO/Model/PropertyChange.h
Normal file
32
include/IO/Model/PropertyChange.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
49
include/IO/Model/Vertex.h
Normal file
49
include/IO/Model/Vertex.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Vec3.h"
|
||||
#include "../../Vec2.h"
|
||||
#include "../../Color4.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
}
|
38
include/IO/RIFF.h
Normal file
38
include/IO/RIFF.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vector.h"
|
||||
#include "../Serializer.h"
|
||||
#include "RIFF_Chunk.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
33
include/IO/RIFF_Chunk.h
Normal file
33
include/IO/RIFF_Chunk.h
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
112
include/IO/Socket/BaseTCP.h
Normal file
112
include/IO/Socket/BaseTCP.h
Normal file
@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "Request.h"
|
||||
#include "Response.h"
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class BaseTCP
|
||||
{
|
||||
protected:
|
||||
AddrType addrType;
|
||||
Str_8 localAddr;
|
||||
unsigned short localPort;
|
||||
Str_8 remoteHostName;
|
||||
Str_8 remoteAddr;
|
||||
unsigned short 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;
|
||||
|
||||
BaseTCP();
|
||||
|
||||
BaseTCP(const AddrType addrType);
|
||||
|
||||
BaseTCP(BaseTCP&& tcp) noexcept;
|
||||
|
||||
BaseTCP(const BaseTCP& tcp);
|
||||
|
||||
BaseTCP& operator=(BaseTCP&& tcp) noexcept;
|
||||
|
||||
BaseTCP& operator=(const BaseTCP& tcp);
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual void Bind(const Str_8& address, unsigned short port) = 0;
|
||||
|
||||
virtual void Listen() = 0;
|
||||
|
||||
virtual BaseTCP* Accept() = 0;
|
||||
|
||||
virtual void Connect(const Str_8& address, const unsigned short port) = 0;
|
||||
|
||||
virtual UInt_64 Send(const Byte* const buffer, const UInt_32 size) = 0;
|
||||
|
||||
virtual UInt_64 Receive(Byte* const buffer, const UInt_32 size) = 0;
|
||||
|
||||
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();
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
unsigned short GetLocalPort() const;
|
||||
|
||||
Str_8 GetRemoteAddress() const;
|
||||
|
||||
unsigned short GetRemotePort() const;
|
||||
|
||||
bool IsConnection() const;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
bool IsListening() const;
|
||||
|
||||
bool IsConnected() const;
|
||||
|
||||
virtual void SetBlocking(const bool blocking) = 0;
|
||||
|
||||
virtual bool IsBlocking() const = 0;
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
private:
|
||||
Str_8 RecvHeader();
|
||||
|
||||
Str_8 RecvBody(const UInt_64 contentLength);
|
||||
|
||||
UInt_64 RecvChunkSize();
|
||||
|
||||
Str_8 RecvChunk(const UInt_64 chunkSize);
|
||||
};
|
||||
}
|
54
include/IO/Socket/BaseUDP.h
Normal file
54
include/IO/Socket/BaseUDP.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class BaseUDP
|
||||
{
|
||||
protected:
|
||||
AddrType addrType;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
bool bound;
|
||||
|
||||
public:
|
||||
virtual ~BaseUDP() = default;
|
||||
|
||||
BaseUDP();
|
||||
|
||||
BaseUDP(const AddrType addrType);
|
||||
|
||||
BaseUDP(BaseUDP&& udp) noexcept;
|
||||
|
||||
BaseUDP(const BaseUDP& udp);
|
||||
|
||||
BaseUDP& operator=(BaseUDP&& udp) noexcept;
|
||||
|
||||
BaseUDP& operator=(const BaseUDP& udp);
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual void Bind(const Str_8& address, const UInt_16 port) = 0;
|
||||
|
||||
virtual UInt_64 Send(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size) = 0;
|
||||
|
||||
virtual UInt_64 Receive(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) = 0;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
virtual void SetBlocking(const bool blocking) = 0;
|
||||
|
||||
virtual bool IsBlocking() const = 0;
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
UInt_16 GetLocalPort() const;
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
};
|
||||
}
|
194
include/IO/Socket/Comms.h
Normal file
194
include/IO/Socket/Comms.h
Normal file
@ -0,0 +1,194 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Log.h"
|
||||
#include "../../BaseObj.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Array.h"
|
||||
#include "Socket.h"
|
||||
#include "UDP.h"
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class CommsSystem;
|
||||
class Endpoint;
|
||||
|
||||
class Comms : public BaseObj
|
||||
{
|
||||
private:
|
||||
static const Version ver;
|
||||
static const UInt_64 internalSys;
|
||||
static const UInt_64 connectOp;
|
||||
static const UInt_64 connectedOp;
|
||||
static const UInt_64 rejectedOp;
|
||||
static const UInt_64 disconnectOp;
|
||||
static const UInt_64 disconnectedOp;
|
||||
static const UInt_64 statusUpdateOp;
|
||||
static const UInt_64 pingOp;
|
||||
static const UInt_64 pongOp;
|
||||
static const UInt_64 latencyOp;
|
||||
static const UInt_64 receivedOp;
|
||||
|
||||
Socket hdl;
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
bool bound;
|
||||
Version appVer;
|
||||
EndDisp disposition;
|
||||
bool dropPackets;
|
||||
Str_8 id;
|
||||
UInt_32 hashId;
|
||||
Byte* buffer;
|
||||
UInt_32 bufferSize;
|
||||
Array<CommsSystem*> systems;
|
||||
Vector<Endpoint*> endpoints;
|
||||
UInt_32 maxEndpoints;
|
||||
UInt_64 lastTSC;
|
||||
float delta;
|
||||
float maxTimeout;
|
||||
float resendRate;
|
||||
bool (*connectedCb)(Comms*, Endpoint*);
|
||||
void (*activeCb)(Comms*, Endpoint*);
|
||||
void (*disconnectedCb)(Comms*, Endpoint*);
|
||||
|
||||
public:
|
||||
~Comms() override;
|
||||
|
||||
Comms();
|
||||
|
||||
Comms(const Version& ver, const EndDisp disposition, const Str_8& id, const UInt_64 maxEndpoints);
|
||||
|
||||
Comms(const Comms& sock);
|
||||
|
||||
Comms& operator=(const Comms& sock);
|
||||
|
||||
void Initialize();
|
||||
|
||||
void UnInitialize();
|
||||
|
||||
void Bind(const Str_8& newAddress, const UInt_16 newPort);
|
||||
|
||||
void Connect(const Str_8& address, const UInt_16 port);
|
||||
|
||||
bool Disconnect(const EndDisp disposition, const UInt_64 hashId, const Str_8& msg);
|
||||
|
||||
bool Disconnect(const EndDisp disposition, const Str_8& id, const Str_8& msg);
|
||||
|
||||
void Broadcast(const EndDisp disposition, const Status status, const bool deltaLocked, const bool encrypted,
|
||||
const bool ensure, const UInt_64 sysHashId, const UInt_64 opHashId,
|
||||
const Serializer<>& payload);
|
||||
|
||||
void Broadcast(const EndDisp disposition, const Status status, const bool deltaLocked, const bool encrypted,
|
||||
const bool ensure, const Str_8& sysId, const Str_8& opId,
|
||||
const Serializer<>& payload);
|
||||
|
||||
void Poll();
|
||||
|
||||
bool IsInitialized() const;
|
||||
|
||||
void SetAddressType(const AddrType newType);
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
|
||||
Str_8 GetAddress() const;
|
||||
|
||||
UInt_16 GetPort() const;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
Version GetVersion() const;
|
||||
|
||||
Version GetAppVersion() const;
|
||||
|
||||
EndDisp GetDisposition() const;
|
||||
|
||||
void EnableDropPackets(const bool enable);
|
||||
|
||||
bool IsDropPacketsEnabled() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
bool HasSystem(const UInt_64 hashId) const;
|
||||
|
||||
bool HasSystem(const Str_8& id) const;
|
||||
|
||||
bool AddSystem(CommsSystem* sys);
|
||||
|
||||
CommsSystem* GetSystem(const UInt_64 hashId);
|
||||
|
||||
CommsSystem* GetSystem(const Str_8& id);
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Status status, const UInt_64 hashId) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Status status, const Str_8& id) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const UInt_64 hashId) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Str_8& id) const;
|
||||
|
||||
bool HasEndpoint(const Str_8& address, const UInt_16 port) const;
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Status status, const UInt_64 hashId);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Status status, const Str_8& id);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const UInt_64 hashId);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Str_8& id);
|
||||
|
||||
Endpoint* GetEndpoint(const Str_8& address, const UInt_16 port);
|
||||
|
||||
Array<Endpoint*> GetEndpoints(const EndDisp disposition, const Status status);
|
||||
|
||||
Array<Endpoint*> GetEndpoints(const EndDisp disposition);
|
||||
|
||||
UInt_64 GetEndpointsCount(const EndDisp disposition, const Status status);
|
||||
|
||||
UInt_64 GetEndpointsCount(const EndDisp disposition);
|
||||
|
||||
UInt_64 GetMaxEndpoints() const;
|
||||
|
||||
void SetBlocking(const bool blocking);
|
||||
|
||||
bool IsBlocking() const;
|
||||
|
||||
void SetMaxTimeout(const float seconds);
|
||||
|
||||
float GetMaxTimeout() const;
|
||||
|
||||
void SetResendRate(const float seconds);
|
||||
|
||||
float GetResendRate() const;
|
||||
|
||||
void SetConnectedCb(bool (*newCb)(Comms*, Endpoint*));
|
||||
|
||||
void SetActiveCb(void (*newCb)(Comms*, Endpoint*));
|
||||
|
||||
void SetDisconnectedCb(void (*newCb)(Comms*, Endpoint*));
|
||||
|
||||
private:
|
||||
void UpdateQueue(UInt_64 active);
|
||||
|
||||
void UpdateQueue();
|
||||
|
||||
bool RemoveEndpoint(const EndDisp disposition, const UInt_64 hashId);
|
||||
|
||||
bool RemoveEndpoint(const Str_8& address, const UInt_16 port);
|
||||
|
||||
bool RemoveEndpoint(const Endpoint* const end);
|
||||
|
||||
void PollEndpoints(Vector<Endpoint*>& endpoints);
|
||||
|
||||
void Bind_v6(const Str_8& address, const UInt_16 port);
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
|
||||
UInt_16 Receive(Str_8* address, UInt_16* port, Byte* const data, const UInt_16 size);
|
||||
};
|
||||
}
|
42
include/IO/Socket/CommsSystem.h
Normal file
42
include/IO/Socket/CommsSystem.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Array.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Endpoint;
|
||||
class Operation;
|
||||
class Comms;
|
||||
|
||||
class CommsSystem
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Array<Operation*> ops;
|
||||
|
||||
public:
|
||||
~CommsSystem();
|
||||
|
||||
CommsSystem();
|
||||
|
||||
CommsSystem(const Str_8& id);
|
||||
|
||||
CommsSystem(const CommsSystem& sys);
|
||||
|
||||
CommsSystem& operator=(const CommsSystem& sys);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
bool HasOperation(const UInt_64 hashId);
|
||||
|
||||
bool AddOperation(Operation* op);
|
||||
|
||||
void Execute(Comms* comms, Endpoint* endpoint, const UInt_64 hashId, Serializer<>& payload);
|
||||
};
|
||||
}
|
14
include/IO/Socket/DNS.h
Normal file
14
include/IO/Socket/DNS.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class DNS
|
||||
{
|
||||
public:
|
||||
static Str_8 Resolve(const AddrType addrType, const Str_8& hostName);
|
||||
};
|
||||
}
|
137
include/IO/Socket/Endpoint.h
Normal file
137
include/IO/Socket/Endpoint.h
Normal file
@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../BaseObj.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Serializer.h"
|
||||
#include "../../IO/Socket/Socket.h"
|
||||
|
||||
#include "Utils.h"
|
||||
#include "Fragments.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Comms;
|
||||
|
||||
class Endpoint : public BaseObj
|
||||
{
|
||||
private:
|
||||
Socket hdl;
|
||||
EndDisp disposition;
|
||||
Status status;
|
||||
Architecture arch;
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
UInt_64 nextSendId;
|
||||
Vector<Insurance> sent;
|
||||
UInt_64 nextRecvId;
|
||||
Vector<Fragments> received;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
float deltaDuration;
|
||||
float deltaRate;
|
||||
float timeout;
|
||||
float lastPing;
|
||||
float oldLatency;
|
||||
float latency;
|
||||
UInt_64 queueSlot;
|
||||
|
||||
public:
|
||||
Endpoint();
|
||||
|
||||
Endpoint(const Socket hdl, const EndDisp disposition, const Architecture arch, const Str_8& id,
|
||||
const AddrType& type, const Str_8& address, const UInt_16 port);
|
||||
|
||||
Endpoint(const Socket hdl, const AddrType& type, const Str_8& address, const UInt_16 port);
|
||||
|
||||
Endpoint(const Endpoint& end);
|
||||
|
||||
Endpoint& operator=(const Endpoint& end);
|
||||
|
||||
void Poll(const float delta);
|
||||
|
||||
EndDisp GetDisposition() const;
|
||||
|
||||
void SetStatus(const Status newStatus);
|
||||
|
||||
Status GetStatus() const;
|
||||
|
||||
Architecture GetArchitecture() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
UInt_64 GetNextSendId() const;
|
||||
|
||||
/// Sends data to the remote endpoint.
|
||||
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
|
||||
/// @param [in] encrypted Whether or not to encrypt this data before sending to the remote endpoint.
|
||||
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
|
||||
/// @param [in] sys The system hash id to execute an operation from.
|
||||
/// @param [in] op The operation hash id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(const bool deltaLocked, const bool encrypted, const bool ensure, const UInt_64 sys,
|
||||
const UInt_64 op, const Serializer<>& payload);
|
||||
|
||||
/// Sends data to the remote endpoint.
|
||||
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
|
||||
/// @param [in] encrypted Whether or not to encrypt this data before sending to the remote endpoint.
|
||||
/// @param [in] ensure Whether or not to ensure the data was received by the remote endpoint.
|
||||
/// @param [in] sys The system string id to execute an operation from.
|
||||
/// @param [in] op The operation string id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(const bool deltaLocked, const bool encrypted, const bool ensure, const Str_8& sys,
|
||||
const Str_8& op, const Serializer<>& payload);
|
||||
|
||||
void RemoveInsurance(const UInt_64 msgId, const UInt_64 fragment);
|
||||
|
||||
UInt_64 GetNextRecvId() const;
|
||||
|
||||
void AddReceived(const Header& header, const Serializer<>& payload);
|
||||
|
||||
Vector<Fragments> GetReceived() const;
|
||||
|
||||
Vector<Fragments>* GetReceived();
|
||||
|
||||
Str_8 GetAddress() const;
|
||||
|
||||
UInt_16 GetPort() const;
|
||||
|
||||
void SetDeltaRate(const float newDeltaRate);
|
||||
|
||||
float GetDeltaRate() const;
|
||||
|
||||
float GetTimeout() const;
|
||||
|
||||
float GetLastPing() const;
|
||||
|
||||
void Ping(const float delta);
|
||||
|
||||
void Pong(const float delta);
|
||||
|
||||
void SendLatency();
|
||||
|
||||
void SetLatency(const float newLatency);
|
||||
|
||||
float GetLatency() const;
|
||||
|
||||
void SetQueueSlot(const UInt_64 slot);
|
||||
|
||||
UInt_64 GetQueueSlot() const;
|
||||
|
||||
private:
|
||||
Fragments FragmentData(const Header& header, const Serializer<>& data);
|
||||
|
||||
void Send(const Header& header, const Serializer<>& payload);
|
||||
|
||||
bool SortingNeeded() const;
|
||||
|
||||
void SortReceived();
|
||||
|
||||
UInt_16 Send_v6(const Serializer<>& payload);
|
||||
|
||||
UInt_16 Send_v4(const Serializer<>& payload);
|
||||
};
|
||||
}
|
42
include/IO/Socket/Fragments.h
Normal file
42
include/IO/Socket/Fragments.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Fragments
|
||||
{
|
||||
private:
|
||||
Header header;
|
||||
Serializer<>* data;
|
||||
UInt_64 size;
|
||||
|
||||
public:
|
||||
~Fragments();
|
||||
|
||||
Fragments();
|
||||
|
||||
Fragments(const Header& header, const Serializer<>& payload);
|
||||
|
||||
Fragments(const Header& header, const UInt_64 size);
|
||||
|
||||
Fragments(const Fragments& frags);
|
||||
|
||||
Fragments& operator=(const Fragments& frags);
|
||||
|
||||
operator const Serializer<>* () const;
|
||||
|
||||
operator Serializer<>* ();
|
||||
|
||||
Header GetHeader() const;
|
||||
|
||||
UInt_64 Size() const;
|
||||
|
||||
bool IsComplete() const;
|
||||
|
||||
Packet Combine() const;
|
||||
};
|
||||
}
|
36
include/IO/Socket/Operation.h
Normal file
36
include/IO/Socket/Operation.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class CommsSystem;
|
||||
class Comms;
|
||||
class Endpoint;
|
||||
|
||||
class Operation
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
|
||||
public:
|
||||
virtual ~Operation() = default;
|
||||
|
||||
Operation();
|
||||
|
||||
Operation(const Str_8& id);
|
||||
|
||||
Operation(const Operation& cmd);
|
||||
|
||||
Operation& operator=(const Operation& cmd);
|
||||
|
||||
virtual void Process(Comms* comms, Endpoint* endpoint, CommsSystem* sys, Serializer<>& payload);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
};
|
||||
}
|
164
include/IO/Socket/Request.h
Normal file
164
include/IO/Socket/Request.h
Normal file
@ -0,0 +1,164 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Json/Json.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
|
||||
};
|
||||
}
|
127
include/IO/Socket/Response.h
Normal file
127
include/IO/Socket/Response.h
Normal file
@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Vector.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Json/Json.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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);
|
||||
|
||||
};
|
||||
}
|
113
include/IO/Socket/RestAPIs/Spotify.h
Normal file
113
include/IO/Socket/RestAPIs/Spotify.h
Normal file
@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../EHS.h"
|
||||
#include "../../../Str.h"
|
||||
#include "../../../Array.h"
|
||||
#include "../SSL.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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();
|
||||
};
|
||||
}
|
39
include/IO/Socket/RestAPIs/Twitch.h
Normal file
39
include/IO/Socket/RestAPIs/Twitch.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../EHS.h"
|
||||
#include "../../../Str.h"
|
||||
#include "../SSL.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
53
include/IO/Socket/RestAPIs/TwitchChat.h
Normal file
53
include/IO/Socket/RestAPIs/TwitchChat.h
Normal file
@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../EHS.h"
|
||||
#include "../../../Str.h"
|
||||
#include "../TCP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
56
include/IO/Socket/SSL.h
Normal file
56
include/IO/Socket/SSL.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "TCP.h"
|
||||
#include "Request.h"
|
||||
#include "Response.h"
|
||||
|
||||
typedef struct ssl_ctx_st SSL_CTX;
|
||||
typedef struct ssl_st SSL;
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// 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();
|
||||
};
|
||||
}
|
51
include/IO/Socket/Socket.h
Normal file
51
include/IO/Socket/Socket.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef LWE_IPV4_HEADER
|
||||
#define LWE_IPV4_HEADER 60
|
||||
#endif
|
||||
|
||||
#ifndef LWE_IPV6_HEADER
|
||||
#define LWE_IPV6_HEADER 40
|
||||
#endif
|
||||
|
||||
#ifndef LWE_UDP_HEADER
|
||||
#define LWE_UDP_HEADER 8
|
||||
#endif
|
||||
|
||||
#ifndef LWE_IPV4_UDP_PAYLOAD
|
||||
#define LWE_IPV4_UDP_PAYLOAD (LWE_UINT_16_MAX - LWE_IPV4_HEADER - LWE_UDP_HEADER)
|
||||
#endif
|
||||
|
||||
#ifndef LWE_IPV6_UDP_PAYLOAD
|
||||
#define LWE_IPV6_UDP_PAYLOAD (LWE_UINT_16_MAX - LWE_IPV6_HEADER - LWE_UDP_HEADER)
|
||||
#endif
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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(LWE_OS_WINDOWS)
|
||||
typedef UInt_64 Socket;
|
||||
#define LWE_INVALID_SOCKET LWE_UINT_64_MAX
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
typedef SInt_32 Socket;
|
||||
#define LWE_INVALID_SOCKET (SInt_32)0xffffffff
|
||||
#endif
|
||||
}
|
7
include/IO/Socket/TCP.h
Normal file
7
include/IO/Socket/TCP.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef LWE_OS_WINDOWS
|
||||
#include "TCP_W32.h"
|
||||
#else
|
||||
#include "TCP_BSD.h"
|
||||
#endif
|
94
include/IO/Socket/TCP_BSD.h
Normal file
94
include/IO/Socket/TCP_BSD.h
Normal file
@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Log.h"
|
||||
|
||||
#include "Socket.h"
|
||||
#include "BaseTCP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// 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(const 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, unsigned short 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, const unsigned short 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* const buffer, const 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* const buffer, const UInt_32 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const 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, unsigned short port);
|
||||
|
||||
void Bind_v4(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v6(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v4(const Str_8& address, unsigned short port);
|
||||
};
|
||||
}
|
94
include/IO/Socket/TCP_W32.h
Normal file
94
include/IO/Socket/TCP_W32.h
Normal file
@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Log.h"
|
||||
|
||||
#include "Socket.h"
|
||||
#include "BaseTCP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// 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(const 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, unsigned short 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, const unsigned short 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* const buffer, const 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* const buffer, const UInt_32 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const 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, unsigned short port);
|
||||
|
||||
void Bind_v4(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v6(const Str_8& address, unsigned short port);
|
||||
|
||||
void Connect_v4(const Str_8& address, unsigned short port);
|
||||
};
|
||||
}
|
7
include/IO/Socket/UDP.h
Normal file
7
include/IO/Socket/UDP.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef LWE_OS_WINDOWS
|
||||
#include "UDP_W32.h"
|
||||
#else
|
||||
#include "UDP_BSD.h"
|
||||
#endif
|
82
include/IO/Socket/UDP_BSD.h
Normal file
82
include/IO/Socket/UDP_BSD.h
Normal file
@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "BaseUDP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// 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(const Str_8& address, const 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(const Str_8& addr, const UInt_16 port, const Byte* const data, const 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(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const 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, const UInt_16 port);
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
|
||||
UInt_64 Send_v6(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
|
||||
UInt_64 Send_v4(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
};
|
||||
}
|
82
include/IO/Socket/UDP_W32.h
Normal file
82
include/IO/Socket/UDP_W32.h
Normal file
@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "BaseUDP.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// 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(const Str_8& address, const 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(const Str_8& addr, const UInt_16 port, const Byte* const data, const 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(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const 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, const UInt_16 port);
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
|
||||
UInt_64 Send_v6(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
|
||||
UInt_64 Send_v4(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
};
|
||||
}
|
56
include/IO/Socket/Utils.h
Normal file
56
include/IO/Socket/Utils.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Serializer.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class EndDisp : UInt_8
|
||||
{
|
||||
UNKNOWN,
|
||||
SERVICE,
|
||||
ENDPOINT
|
||||
};
|
||||
|
||||
enum class Status : UInt_8
|
||||
{
|
||||
ACTIVE,
|
||||
PENDING,
|
||||
IN_LOCAL_QUEUE,
|
||||
IN_REMOTE_QUEUE,
|
||||
};
|
||||
|
||||
struct Header
|
||||
{
|
||||
bool encrypted = true;
|
||||
UInt_64 id = 0;
|
||||
UInt_64 fragments = 0;
|
||||
UInt_64 fragment = 0;
|
||||
bool ensure = false;
|
||||
EndDisp disposition = EndDisp::UNKNOWN;
|
||||
UInt_64 endpointId = 0;
|
||||
UInt_64 system = 0;
|
||||
UInt_64 op = 0;
|
||||
};
|
||||
|
||||
struct Packet
|
||||
{
|
||||
Header header;
|
||||
Serializer<> payload;
|
||||
};
|
||||
|
||||
struct Insurance
|
||||
{
|
||||
Header header;
|
||||
Serializer<> payload;
|
||||
float lastResend;
|
||||
};
|
||||
}
|
||||
|
||||
#ifndef COMMS_IPV4_PAYLOAD
|
||||
#define COMMS_IPV4_PAYLOAD (LWE_IPV4_UDP_PAYLOAD - (UInt_16)sizeof(Header))
|
||||
#endif
|
||||
|
||||
#ifndef COMMS_IPV6_PAYLOAD
|
||||
#define COMMS_IPV6_PAYLOAD (LWE_IPV6_UDP_PAYLOAD - (UInt_16)sizeof(Header))
|
||||
#endif
|
13
include/IO/Window.h
Normal file
13
include/IO/Window.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
#include "Window_W32.h"
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
#if defined(LWE_WS_XCB)
|
||||
#include "Window_XCB.h"
|
||||
#elif defined(LWE_WS_WAYLAND)
|
||||
#include "Window_Way.h"
|
||||
#endif
|
||||
#endif
|
127
include/IO/Window_W32.h
Normal file
127
include/IO/Window_W32.h
Normal file
@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Array.h"
|
||||
#include "../Str.h"
|
||||
#include "../Vec4.h"
|
||||
#include "BaseWindow.h"
|
||||
#include "HID/InputHandler_RI.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 lwe
|
||||
{
|
||||
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);
|
||||
|
||||
};
|
||||
}
|
80
include/IO/Window_Way.h
Normal file
80
include/IO/Window_Way.h
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseWindow.h"
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include "xdg-shell-client-protocol.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
84
include/IO/Window_XCB.h
Normal file
84
include/IO/Window_XCB.h
Normal file
@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseWindow.h"
|
||||
#include "File.h"
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xinput.h>
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
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();
|
||||
|
||||
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 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;
|
||||
|
||||
xcb_connection_t* GetServer();
|
||||
|
||||
private:
|
||||
xcb_generic_event_t* RetrieveEvent();
|
||||
|
||||
xcb_atom_t RetrieveAtom(const bool create, const Str_8& name) const;
|
||||
|
||||
xcb_get_property_reply_t* RetrieveProp(const xcb_atom_t prop, const xcb_atom_t type) const;
|
||||
|
||||
void QueryPrimaryDevices();
|
||||
|
||||
Str_8 QueryDeviceName(const UInt_16 id);
|
||||
};
|
||||
}
|
2307
include/IO/xdg-shell-client-protocol.h
Normal file
2307
include/IO/xdg-shell-client-protocol.h
Normal file
File diff suppressed because it is too large
Load Diff
68
include/Json/Json.h
Normal file
68
include/Json/Json.h
Normal file
@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
#include "JsonBase.h"
|
||||
#include "JsonObj.h"
|
||||
#include "JsonArray.h"
|
||||
#include "JsonBool.h"
|
||||
#include "JsonNum.h"
|
||||
#include "JsonStr.h"
|
||||
#include "JsonVar.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Json
|
||||
{
|
||||
private:
|
||||
JsonBase* value;
|
||||
|
||||
public:
|
||||
virtual ~Json();
|
||||
|
||||
Json();
|
||||
|
||||
Json(const JsonBase& value);
|
||||
|
||||
Json(const JsonObj& value);
|
||||
|
||||
Json(const JsonArray& value);
|
||||
|
||||
Json(const JsonBool& value);
|
||||
|
||||
Json(const JsonNum& value);
|
||||
|
||||
Json(const JsonStr& value);
|
||||
|
||||
Json(const char* data, const UInt_64 size, const UInt_64 extra);
|
||||
|
||||
Json(const Str_8& data, const UInt_64 extra);
|
||||
|
||||
Json(Json&& json) noexcept;
|
||||
|
||||
Json(const Json &json);
|
||||
|
||||
Json& operator=(Json&& json) noexcept;
|
||||
|
||||
Json& operator=(const Json& json);
|
||||
|
||||
JsonBase* GetValue();
|
||||
|
||||
JsonBase* RetrieveValue(const Str_8& access);
|
||||
|
||||
Str_8 ToStr(const bool compact) const;
|
||||
|
||||
private:
|
||||
static Vector<Str_8> ParseAccess(const Str_8& access);
|
||||
|
||||
void ParseValue(JsonVar* var, const Char_8** begin, const Char_8* end, const UInt_64 extra);
|
||||
|
||||
JsonVar ParseVar(const Char_8** begin, const Char_8* end, const UInt_64 extra);
|
||||
|
||||
void ParseObject(JsonObj* obj, const Char_8** begin, const Char_8* end, const UInt_64 extra);
|
||||
|
||||
void ParseArray(JsonArray* arr, const Char_8** begin, const Char_8* end, const UInt_64 extra);
|
||||
|
||||
void Parse(const Str_8& data, const UInt_64 extra);
|
||||
};
|
||||
}
|
78
include/Json/JsonArray.h
Normal file
78
include/Json/JsonArray.h
Normal file
@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
#include "JsonBase.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class JsonObj;
|
||||
class JsonBool;
|
||||
class JsonNum;
|
||||
class JsonStr;
|
||||
|
||||
class JsonArray : public JsonBase
|
||||
{
|
||||
private:
|
||||
UInt_64 size;
|
||||
UInt_64 extra;
|
||||
UInt_64 rawSize;
|
||||
JsonBase** data;
|
||||
|
||||
public:
|
||||
virtual ~JsonArray();
|
||||
|
||||
JsonArray();
|
||||
|
||||
JsonArray(const UInt_64 extra);
|
||||
|
||||
JsonArray(const UInt_64 size, const UInt_64 extra);
|
||||
|
||||
JsonArray(JsonArray&& ja) noexcept;
|
||||
|
||||
JsonArray(const JsonArray& ja);
|
||||
|
||||
JsonArray& operator=(JsonArray&& ja) noexcept;
|
||||
|
||||
JsonArray& operator=(const JsonArray& ja);
|
||||
|
||||
operator JsonBase* const *() const;
|
||||
|
||||
operator JsonBase**();
|
||||
|
||||
UInt_64 RawSize() const;
|
||||
|
||||
UInt_64 Extra() const;
|
||||
|
||||
UInt_64 Size() const;
|
||||
|
||||
void Insert(const UInt_64 index, const JsonBase* const value);
|
||||
|
||||
void Push(const JsonBase* const value);
|
||||
|
||||
void Push(const JsonBase& value);
|
||||
|
||||
void Push(const JsonObj& value);
|
||||
|
||||
void Push(const JsonArray& value);
|
||||
|
||||
void Push(const JsonBool& value);
|
||||
|
||||
void Push(const bool value);
|
||||
|
||||
void Push(const JsonNum& value);
|
||||
|
||||
void Push(const float value);
|
||||
|
||||
void Push(const JsonStr& value);
|
||||
|
||||
void Push(const Char_8* value, const UInt_64 size = 0);
|
||||
|
||||
void Push(const Str_8& value);
|
||||
|
||||
void Pop();
|
||||
|
||||
Str_8 ToStr(const UInt_64 level, const bool compact) const;
|
||||
};
|
||||
}
|
34
include/Json/JsonBase.h
Normal file
34
include/Json/JsonBase.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class JsonType
|
||||
{
|
||||
NULLOBJ,
|
||||
OBJ,
|
||||
ARRAY,
|
||||
BOOL,
|
||||
NUM,
|
||||
STR
|
||||
};
|
||||
|
||||
class JsonBase
|
||||
{
|
||||
private:
|
||||
JsonType type;
|
||||
|
||||
public:
|
||||
JsonBase();
|
||||
|
||||
JsonBase(const JsonType type);
|
||||
|
||||
JsonBase(const JsonBase& base) = default;
|
||||
|
||||
JsonType GetType() const;
|
||||
|
||||
virtual Str_8 ToStr(const UInt_64 level, const bool compact) const;
|
||||
};
|
||||
}
|
27
include/Json/JsonBool.h
Normal file
27
include/Json/JsonBool.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
#include "JsonBase.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class JsonBool : public JsonBase
|
||||
{
|
||||
public:
|
||||
bool value;
|
||||
|
||||
JsonBool();
|
||||
|
||||
JsonBool(const bool value);
|
||||
|
||||
JsonBool(const JsonBool& jb) = default;
|
||||
|
||||
operator bool() const;
|
||||
|
||||
operator bool&();
|
||||
|
||||
Str_8 ToStr(const UInt_64 level, const bool compact) const;
|
||||
};
|
||||
}
|
45
include/Json/JsonNum.h
Normal file
45
include/Json/JsonNum.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
#include "JsonBase.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class JsonNum : public JsonBase
|
||||
{
|
||||
public:
|
||||
float value;
|
||||
|
||||
JsonNum();
|
||||
|
||||
JsonNum(const SInt_64 value);
|
||||
|
||||
JsonNum(const UInt_64 value);
|
||||
|
||||
JsonNum(const SInt_32 value);
|
||||
|
||||
JsonNum(const UInt_32 value);
|
||||
|
||||
JsonNum(const SInt_16 value);
|
||||
|
||||
JsonNum(const UInt_16 value);
|
||||
|
||||
JsonNum(const SInt_8 value);
|
||||
|
||||
JsonNum(const UInt_8 value);
|
||||
|
||||
JsonNum(const double value);
|
||||
|
||||
JsonNum(const float value);
|
||||
|
||||
JsonNum(const JsonNum& jn) = default;
|
||||
|
||||
operator float() const;
|
||||
|
||||
operator float&();
|
||||
|
||||
Str_8 ToStr(const UInt_64 level, const bool compact) const;
|
||||
};
|
||||
}
|
63
include/Json/JsonObj.h
Normal file
63
include/Json/JsonObj.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
#include "JsonBase.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class JsonVar;
|
||||
|
||||
class JsonObj : public JsonBase
|
||||
{
|
||||
protected:
|
||||
UInt_64 size;
|
||||
UInt_64 extra;
|
||||
UInt_64 rawSize;
|
||||
JsonVar* vars;
|
||||
|
||||
public:
|
||||
virtual ~JsonObj();
|
||||
|
||||
JsonObj();
|
||||
|
||||
JsonObj(const UInt_64 size, const UInt_64 extra);
|
||||
|
||||
JsonObj(const UInt_64 extra);
|
||||
|
||||
JsonObj(JsonObj&& value) noexcept;
|
||||
|
||||
JsonObj(const JsonObj& value);
|
||||
|
||||
JsonObj& operator=(JsonObj&& value) noexcept;
|
||||
|
||||
JsonObj& operator=(const JsonObj& value);
|
||||
|
||||
operator const JsonVar*() const;
|
||||
|
||||
operator JsonVar*();
|
||||
|
||||
UInt_64 Size() const;
|
||||
|
||||
UInt_64 Extra() const;
|
||||
|
||||
UInt_64 RawSize() const;
|
||||
|
||||
bool HasVar(const UInt_64 hashId) const;
|
||||
|
||||
bool HasVar(const Str_8& identifier) const;
|
||||
|
||||
bool AddVar(const JsonVar& var);
|
||||
|
||||
const JsonVar* GetVar(const UInt_64 hashId) const;
|
||||
|
||||
const JsonVar* GetVar(const Str_8& identifier) const;
|
||||
|
||||
JsonVar* GetVar(const UInt_64 hashId);
|
||||
|
||||
JsonVar* GetVar(const Str_8& identifier);
|
||||
|
||||
Str_8 ToStr(const UInt_64 level, const bool compact) const;
|
||||
};
|
||||
}
|
33
include/Json/JsonStr.h
Normal file
33
include/Json/JsonStr.h
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
#include "JsonBase.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class JsonStr : public JsonBase
|
||||
{
|
||||
public:
|
||||
Str_8 value;
|
||||
|
||||
JsonStr();
|
||||
|
||||
JsonStr(Str_8 value);
|
||||
|
||||
JsonStr(const Char_8* value, const UInt_64 size = 0);
|
||||
|
||||
JsonStr(JsonStr&& js) noexcept;
|
||||
|
||||
JsonStr(const JsonStr& js) = default;
|
||||
|
||||
JsonStr& operator=(JsonStr&& js) noexcept;
|
||||
|
||||
operator Str_8() const;
|
||||
|
||||
operator Str_8&();
|
||||
|
||||
Str_8 ToStr(const UInt_64 level, const bool compact) const;
|
||||
};
|
||||
}
|
109
include/Json/JsonVar.h
Normal file
109
include/Json/JsonVar.h
Normal file
@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
#include "../EHS.h"
|
||||
#include "../Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class JsonBase;
|
||||
class JsonObj;
|
||||
class JsonArray;
|
||||
class JsonBool;
|
||||
class JsonNum;
|
||||
class JsonStr;
|
||||
|
||||
class JsonVar
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
JsonBase* value;
|
||||
|
||||
public:
|
||||
virtual ~JsonVar();
|
||||
|
||||
JsonVar();
|
||||
|
||||
JsonVar(Str_8 id);
|
||||
|
||||
JsonVar(Str_8 id, const JsonBase* const value);
|
||||
|
||||
JsonVar(Str_8 id, const JsonBase& value);
|
||||
|
||||
JsonVar(Str_8 id, const JsonObj& value);
|
||||
|
||||
JsonVar(Str_8 id, const JsonArray& value);
|
||||
|
||||
JsonVar(Str_8 id, const JsonBool& value);
|
||||
|
||||
JsonVar(Str_8 id, const bool boolean);
|
||||
|
||||
JsonVar(Str_8 id, const JsonNum& value);
|
||||
|
||||
JsonVar(Str_8 id, const SInt_64 num);
|
||||
|
||||
JsonVar(Str_8 id, const UInt_64 num);
|
||||
|
||||
JsonVar(Str_8 id, const SInt_32 num);
|
||||
|
||||
JsonVar(Str_8 id, const UInt_32 num);
|
||||
|
||||
JsonVar(Str_8 id, const SInt_16 num);
|
||||
|
||||
JsonVar(Str_8 id, const UInt_16 num);
|
||||
|
||||
JsonVar(Str_8 id, const SInt_8 num);
|
||||
|
||||
JsonVar(Str_8 id, const UInt_8 num);
|
||||
|
||||
JsonVar(Str_8 id, const double num);
|
||||
|
||||
JsonVar(Str_8 id, const float num);
|
||||
|
||||
JsonVar(Str_8 id, const JsonStr& value);
|
||||
|
||||
JsonVar(Str_8 id, const Char_8* str, const UInt_64 size = 0);
|
||||
|
||||
JsonVar(Str_8 id, Str_8 str);
|
||||
|
||||
JsonVar(JsonVar&& var) noexcept;
|
||||
|
||||
JsonVar(const JsonVar& var);
|
||||
|
||||
JsonVar& operator=(JsonVar&& var) noexcept;
|
||||
|
||||
JsonVar& operator=(const JsonVar& var);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
void SetValue(const JsonBase* const newValue);
|
||||
|
||||
void SetValue(const JsonBase& newValue);
|
||||
|
||||
void SetValue(const JsonObj& newValue);
|
||||
|
||||
void SetValue(const JsonArray& newValue);
|
||||
|
||||
void SetValue(const JsonBool& newValue);
|
||||
|
||||
void SetValue(const bool newValue);
|
||||
|
||||
void SetValue(const JsonNum& newValue);
|
||||
|
||||
void SetValue(const float newValue);
|
||||
|
||||
void SetValue(const JsonStr& newValue);
|
||||
|
||||
void SetValue(const Char_8* newValue, const UInt_64 size = 0);
|
||||
|
||||
void SetValue(const Str_8& newValue);
|
||||
|
||||
const JsonBase* GetValue() const;
|
||||
|
||||
JsonBase* GetValue();
|
||||
|
||||
Str_8 ToStr(const UInt_64 level, const bool compact) const;
|
||||
};
|
||||
}
|
70
include/Link.h
Normal file
70
include/Link.h
Normal file
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// Test
|
||||
template<typename T>
|
||||
class Link
|
||||
{
|
||||
public:
|
||||
T value;
|
||||
Link<T> *child;
|
||||
|
||||
~Link()
|
||||
{
|
||||
delete child;
|
||||
}
|
||||
|
||||
Link()
|
||||
: value(), child(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Link(const T value, Link* child)
|
||||
: value(value), child(child)
|
||||
{
|
||||
}
|
||||
|
||||
Link(const T value)
|
||||
: value(value), child(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Link(const Link& link)
|
||||
: value(link.value), child(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Link(Link&& link) noexcept
|
||||
: value(link.value), child(link.child)
|
||||
{
|
||||
link.value = 0;
|
||||
link.child = nullptr;
|
||||
}
|
||||
|
||||
Link& operator=(const Link& link)
|
||||
{
|
||||
if (this == &link)
|
||||
return *this;
|
||||
|
||||
value = link.value;
|
||||
child = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Link& operator=(Link&& link) noexcept
|
||||
{
|
||||
if (this == &link)
|
||||
return *this;
|
||||
|
||||
value = link.value;
|
||||
child = link.child;
|
||||
|
||||
link.value = 0;
|
||||
link.child = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
240
include/LinkedList.h
Normal file
240
include/LinkedList.h
Normal file
@ -0,0 +1,240 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Log.h"
|
||||
#include "Link.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template<typename T, typename N = UInt_64>
|
||||
class LinkedList
|
||||
{
|
||||
private:
|
||||
Link<T>* start;
|
||||
Link<T>* end;
|
||||
N size;
|
||||
|
||||
public:
|
||||
~LinkedList()
|
||||
{
|
||||
delete start;
|
||||
}
|
||||
|
||||
LinkedList()
|
||||
: size(0), start(nullptr), end(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
LinkedList(const LinkedList& list)
|
||||
: start(nullptr), end(nullptr), size(list.size)
|
||||
{
|
||||
const Link<T>* rLast = list.start;
|
||||
Link<T>* last = new Link<T>(rLast->value);
|
||||
start = last;
|
||||
|
||||
while (rLast->child)
|
||||
{
|
||||
last->child = new Link<T>(rLast->child->value);
|
||||
last = last->child;
|
||||
rLast = rLast->child;
|
||||
}
|
||||
|
||||
end = last;
|
||||
}
|
||||
|
||||
LinkedList(LinkedList&& list) noexcept
|
||||
: start(list.start), end(list.end), size(list.size)
|
||||
{
|
||||
list.start = nullptr;
|
||||
list.end = nullptr;
|
||||
list.size = {};
|
||||
}
|
||||
|
||||
LinkedList& operator=(const LinkedList& list)
|
||||
{
|
||||
if (this == &list)
|
||||
return *this;
|
||||
|
||||
const Link<T>* rLast = list.start;
|
||||
Link<T>* last = new Link<T>(rLast->value);
|
||||
start = last;
|
||||
|
||||
while (rLast->child)
|
||||
{
|
||||
last->child = new Link<T>(rLast->child->value);
|
||||
last = last->child;
|
||||
rLast = rLast->child;
|
||||
}
|
||||
|
||||
end = last;
|
||||
size = list.size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
LinkedList& operator=(LinkedList&& list) noexcept
|
||||
{
|
||||
if (this == &list)
|
||||
return *this;
|
||||
|
||||
start = list.start;
|
||||
end = list.end;
|
||||
size = list.size;
|
||||
|
||||
list.start = nullptr;
|
||||
list.end = nullptr;
|
||||
list.size = {};
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const Link<T>* operator[](const N index) const
|
||||
{
|
||||
const Link<T>* result = start;
|
||||
|
||||
for (N i = 0; i != index; ++i)
|
||||
result = result->child;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Link<T>* operator[](const N index)
|
||||
{
|
||||
Link<T>* result = start;
|
||||
|
||||
for (N i = 0; i != index; ++i)
|
||||
result = result->child;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
T& Insert(const N index, const T value)
|
||||
{
|
||||
if (index && index == size - 1)
|
||||
{
|
||||
end->child = new Link<T>(value);
|
||||
end = end->child;
|
||||
++size;
|
||||
return end->value;
|
||||
}
|
||||
else if (index)
|
||||
{
|
||||
Link<T>* hierarchy = start;
|
||||
for (N i = 0; i != index - 1; ++i)
|
||||
hierarchy = hierarchy->child;
|
||||
|
||||
hierarchy->child = new Link<T>(value, hierarchy->child);
|
||||
++size;
|
||||
return hierarchy->child->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = new Link<T>(value, start);
|
||||
++size;
|
||||
return start->value;
|
||||
}
|
||||
}
|
||||
|
||||
T Remove(const N index)
|
||||
{
|
||||
if (index && index == size - 1)
|
||||
{
|
||||
Link<T>* hierarchy = start;
|
||||
while (hierarchy->child->child)
|
||||
hierarchy = hierarchy->child;
|
||||
|
||||
T result = end->value;
|
||||
delete end;
|
||||
end = hierarchy;
|
||||
--size;
|
||||
return result;
|
||||
}
|
||||
else if (index)
|
||||
{
|
||||
Link<T>* hierarchy = start;
|
||||
for (N i = 0; i != index - 1; ++i)
|
||||
hierarchy = hierarchy->child;
|
||||
|
||||
Link<T>* tmp = hierarchy->child;
|
||||
T result = tmp->value;
|
||||
hierarchy->child = hierarchy->child->child;
|
||||
tmp->child = nullptr;
|
||||
delete tmp;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
Link<T>* tmp = start;
|
||||
T result = tmp->value;
|
||||
start = start->child;
|
||||
|
||||
if (--size)
|
||||
tmp->child = nullptr;
|
||||
else
|
||||
end = nullptr;
|
||||
|
||||
delete tmp;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
T& Push(const T value)
|
||||
{
|
||||
if (size)
|
||||
{
|
||||
end->child = new Link<T>(value);
|
||||
end = end->child;
|
||||
++size;
|
||||
return end->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = new Link<T>(value);
|
||||
end = start;
|
||||
size = 1;
|
||||
return start->value;
|
||||
}
|
||||
}
|
||||
|
||||
T Pop()
|
||||
{
|
||||
if (size == 1)
|
||||
{
|
||||
T result = start->value;
|
||||
delete start;
|
||||
start = nullptr;
|
||||
end = nullptr;
|
||||
size = 0;
|
||||
return result;
|
||||
}
|
||||
if (size > 1)
|
||||
{
|
||||
Link<T>* hierarchy = start;
|
||||
while (hierarchy->child->child)
|
||||
hierarchy = hierarchy->child;
|
||||
|
||||
T result = hierarchy->child->value;
|
||||
delete hierarchy->child;
|
||||
hierarchy->child = nullptr;
|
||||
end = hierarchy;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
delete start;
|
||||
start = nullptr;
|
||||
end = nullptr;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
N Size() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
};
|
||||
}
|
116
include/Log.h
Normal file
116
include/Log.h
Normal file
@ -0,0 +1,116 @@
|
||||
#pragma once
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
#include "Types.h"
|
||||
#include "Array.h"
|
||||
#include "UTF.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
/// A helper class for holding error information and handling them.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The number data type to use.
|
||||
class Log
|
||||
{
|
||||
private:
|
||||
static void (*logCb)(const Log&);
|
||||
static Log lastLog;
|
||||
Array<Str_8> tags;
|
||||
UInt_64 code;
|
||||
Str_8 msg;
|
||||
|
||||
public:
|
||||
static void SetCallback(void (*newLogCb)(const Log&));
|
||||
|
||||
static void Raise(const Log& log);
|
||||
|
||||
/// Retrieves the last log raised.
|
||||
static Log GetLastLog();
|
||||
|
||||
/// Default members initialization.
|
||||
Log();
|
||||
|
||||
/// Initializes members with the given information.
|
||||
/// @param [in] tags The tags to associate this log with.
|
||||
/// @param [in] code The unique code to use.
|
||||
/// @param [in] msg Detailed information about what happened.
|
||||
Log(std::initializer_list<Str_8> tags, const UInt_64 code, const Str_8& msg);
|
||||
|
||||
/// Initializes members with the given information.
|
||||
/// @param [in] tags The tags to associate this log with.
|
||||
/// @param [in] code The unique code to use.
|
||||
/// @param [in] msg Detailed information about what happened.
|
||||
Log(Array<Str_8>& tags, const UInt_64 code, const Str_8& msg);
|
||||
|
||||
/// Copies all members from the given log.
|
||||
/// @param [in] log The log to copy from.
|
||||
Log(const Log& log);
|
||||
|
||||
/// Copies all members from the given log.
|
||||
/// @param [in] log The log to copy from.
|
||||
/// @returns The log that has been assigned to.
|
||||
Log& operator=(const Log& log);
|
||||
|
||||
/*
|
||||
/// Compares with another given log.
|
||||
/// @param [in] log The log to compare with.
|
||||
/// @returns Whether or not they are equal.
|
||||
bool operator==(const Log log);
|
||||
|
||||
/// Compares with another given log.
|
||||
/// @param [in] log The log to compare with.
|
||||
/// @returns Whether or not they are equal.
|
||||
bool operator!=(const Log log);
|
||||
*/
|
||||
|
||||
/// Checks whether or not this log has the given tags.
|
||||
/// @param [in] tags The tags to look for.
|
||||
/// @returns True if all tags were found, otherwise false.
|
||||
bool HasTags(const std::initializer_list<Str_8> tags) const;
|
||||
|
||||
/// Checks whether or not this log has the given tags.
|
||||
/// @param [in] tags The tags to look for.
|
||||
/// @returns True if all tags were found, otherwise false.
|
||||
bool HasTags(const Array<Str_8>& tags) const;
|
||||
|
||||
/// Checks whether or not this log has the given tag.
|
||||
/// @param [in] tag The tag to look for.
|
||||
/// @returns True if tag was found, otherwise false.
|
||||
bool HasTag(const Str_8& tag) const;
|
||||
|
||||
/// Retrieves all the tags.
|
||||
/// @returns The result.
|
||||
Array<Str_8> GetTags() const;
|
||||
|
||||
UInt_64 GetCode() const;
|
||||
|
||||
/// Retrieves the detailed error message string.
|
||||
/// @returns The error message.
|
||||
Str_8 GetMsg() const;
|
||||
|
||||
Str_8 ToStr() const;
|
||||
|
||||
/// Retrieves whether or not this is a valid object.
|
||||
/// @returns The result.
|
||||
/// @note To be a valid object it must have one or more tags and a message size greater than zero.
|
||||
bool IsValid() const;
|
||||
};
|
||||
}
|
||||
|
||||
#ifndef LWE_LOG_INT
|
||||
#ifdef LWE_DEBUG
|
||||
#define LWE_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), LWE_FILE, LWE_FUNC, Str_8::FromNum((UInt_32)LWE_LINE)}, code, msg})
|
||||
#else
|
||||
#define LWE_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), LWE_FUNC}, code, msg})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LWE_LOG
|
||||
#ifdef LWE_DEBUG
|
||||
#define LWE_LOG(type, code, msg) lwe::Log::Raise({{type, lwe::GetAppName_8(), LWE_FILE, LWE_FUNC, lwe::Str_8::FromNum((lwe::UInt_32)LWE_LINE)}, code, msg})
|
||||
#else
|
||||
#define LWE_LOG(type, code, msg) lwe::Log::Raise({{type, lwe::GetAppName_8(), LWE_FUNC}, code, msg})
|
||||
#endif
|
||||
#endif
|
217
include/Mat2.h
Normal file
217
include/Mat2.h
Normal file
@ -0,0 +1,217 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Vec2.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template<typename T = float>
|
||||
class Mat2
|
||||
{
|
||||
private:
|
||||
T data[4];
|
||||
|
||||
public:
|
||||
Mat2()
|
||||
{
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
data[i] = 0;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat2(const Mat2<C>& mat)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
data[i] = mat.data[i];
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat2<T>& operator=(const Mat2<C>& mat)
|
||||
{
|
||||
if (this == &mat)
|
||||
return *this;
|
||||
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
data[i] = mat.data[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator const T*() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
Vec2<T> operator*(Vec2<T> vec) const
|
||||
{
|
||||
Vec2<T> result;
|
||||
result.x = vec.x * data[0] + vec.y * data[2];
|
||||
result.y = vec.x * data[1] + vec.y * data[3];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat2<T>& operator*=(const T scalar)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
data[i] *= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat2<T> operator*(const T scalar) const
|
||||
{
|
||||
Mat2<T> result;
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
result.data[i] = data[i] * scalar;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat2<T>& operator*=(const Mat2<T>& mat)
|
||||
{
|
||||
Mat2<T> old = *this;
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
{
|
||||
UInt_8 row = i / 2;
|
||||
UInt_8 column = i % 2;
|
||||
data[i] = 0;
|
||||
data[i] += old.data[0 * 2 + column] * mat.data[row * 2 + 0];
|
||||
data[i] += old.data[1 * 2 + column] * mat.data[row * 2 + 1];
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat2<T> operator*(const Mat2<T>& mat) const
|
||||
{
|
||||
Mat2<T> result;
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
{
|
||||
UInt_8 row = i / 2;
|
||||
UInt_8 column = i % 2;
|
||||
result.data[i] += data[0 * 2 + column] * mat.data[row * 2 + 0];
|
||||
result.data[i] += data[1 * 2 + column] * mat.data[row * 2 + 1];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat2<T> GetTranspose() const
|
||||
{
|
||||
Mat2<T> result;
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
result.data[i] = data[2 * (i % 2) + i / 2];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Transpose()
|
||||
{
|
||||
Mat2<T> old = *this;
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
data[i] = old.data[2 * (i % 2) + i / 2];
|
||||
}
|
||||
|
||||
Mat2<T> GetMinor() const
|
||||
{
|
||||
Mat2<T> result(0);
|
||||
result.data[0] = data[3];
|
||||
result.data[1] = data[2];
|
||||
result.data[2] = data[1];
|
||||
result.data[3] = data[0];
|
||||
return result;
|
||||
}
|
||||
|
||||
void Minor()
|
||||
{
|
||||
Mat2<T> old = *this;
|
||||
data[0] = old.data[3];
|
||||
data[1] = old.data[2];
|
||||
data[2] = old.data[1];
|
||||
data[3] = old.data[0];
|
||||
}
|
||||
|
||||
T GetDeterminant() const
|
||||
{
|
||||
return data[0] * data[3] - data[1] * data[2];
|
||||
}
|
||||
|
||||
Mat2<T> GetCofactor() const
|
||||
{
|
||||
Mat2<T> minor = GetMinor();
|
||||
Mat2<T> result;
|
||||
|
||||
for (UInt_8 r = 0; r < 2; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 2; ++c)
|
||||
{
|
||||
UInt_8 i = 2 * c + r;
|
||||
result.data[i] = minor.data[i] * Math::Pow<T>(-1, r + c);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Cofactor()
|
||||
{
|
||||
Mat2<T> minor = GetMinor();
|
||||
|
||||
for (UInt_8 r = 0; r < 2; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 2; ++c)
|
||||
{
|
||||
UInt_8 i = 2 * c + r;
|
||||
data[i] = minor.data[i] * Math::Pow<T>(-1, r + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mat2<T> GetAdjugate() const
|
||||
{
|
||||
return GetCofactor().GetTranspose();
|
||||
}
|
||||
|
||||
void Adjugate()
|
||||
{
|
||||
Cofactor();
|
||||
Transpose();
|
||||
}
|
||||
|
||||
Mat2<T> GetInverse() const
|
||||
{
|
||||
T det = GetDeterminant();
|
||||
if (Math::ComCmp(det, 0.0f))
|
||||
return {};
|
||||
|
||||
return GetAdjugate() * (1 / det);
|
||||
}
|
||||
|
||||
void Inverse()
|
||||
{
|
||||
T det = GetDeterminant();
|
||||
if (Math::ComCmp(det, 0.0f))
|
||||
return;
|
||||
|
||||
Adjugate();
|
||||
operator*=(1 / det);
|
||||
}
|
||||
|
||||
static Mat2<T> Identity()
|
||||
{
|
||||
Mat2<T> result;
|
||||
result[0] = 1;
|
||||
result[3] = 1;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Mat2<float> Mat2_f;
|
||||
typedef Mat2<double> Mat2_d;
|
||||
}
|
322
include/Mat3.h
Normal file
322
include/Mat3.h
Normal file
@ -0,0 +1,322 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Vec3.h"
|
||||
#include "Mat2.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template<typename T = float>
|
||||
class Mat3
|
||||
{
|
||||
private:
|
||||
T data[9];
|
||||
|
||||
public:
|
||||
Mat3()
|
||||
{
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
data[i] = 0;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat3(const Mat2<C>& mat)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
data[i / 2 * 4 + i % 2] = mat.data[i];
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat3(const Mat3<C>& mat)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
data[i] = mat.data[i];
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat3<T>& operator=(const Mat3<C>& mat)
|
||||
{
|
||||
if (this == &mat)
|
||||
return *this;
|
||||
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
data[i] = mat.data[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator Mat2<T>() const
|
||||
{
|
||||
Mat2<T> result;
|
||||
|
||||
for (UInt_8 i = 0; i < 4; ++i)
|
||||
result.data[i] = data[i / 2 * 4 + i % 2];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
operator const T*() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
Vec3<T> operator*(Vec3<T> vec) const
|
||||
{
|
||||
Vec3<T> result;
|
||||
result.x = vec.x * data[0] + vec.y * data[3] + vec.z * data[6];
|
||||
result.y = vec.x * data[1] + vec.y * data[4] + vec.z * data[7];
|
||||
result.z = vec.x * data[2] + vec.y * data[5] + vec.z * data[8];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat3<T>& operator*=(const T scalar)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
data[i] *= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat3<T> operator*(const T scalar) const
|
||||
{
|
||||
Mat3<T> result;
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
result.data[i] = data[i] * scalar;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat3<T>& operator*=(const Mat3<T>& mat)
|
||||
{
|
||||
Mat3<T> old = *this;
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
{
|
||||
UInt_8 row = i / 3;
|
||||
UInt_8 column = i % 3;
|
||||
data[i] = 0;
|
||||
data[i] += old.data[0 * 3 + column] * mat.data[row * 3 + 0];
|
||||
data[i] += old.data[1 * 3 + column] * mat.data[row * 3 + 1];
|
||||
data[i] += old.data[2 * 3 + column] * mat.data[row * 3 + 2];
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat3<T> operator*(const Mat3<T>& mat) const
|
||||
{
|
||||
Mat3<T> result;
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
{
|
||||
UInt_8 row = i / 3;
|
||||
UInt_8 column = i % 3;
|
||||
result.data[i] += data[0 * 3 + column] * mat.data[row * 3 + 0];
|
||||
result.data[i] += data[1 * 3 + column] * mat.data[row * 3 + 1];
|
||||
result.data[i] += data[2 * 3 + column] * mat.data[row * 3 + 2];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat3<T> GetTranspose() const
|
||||
{
|
||||
Mat3<T> result;
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
result.data[i] = data[3 * (i % 3) + i / 3];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Transpose()
|
||||
{
|
||||
Mat3<T> old = *this;
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
data[i] = old.data[3 * (i % 3) + i / 3];
|
||||
}
|
||||
|
||||
Mat3<T> GetMinor() const
|
||||
{
|
||||
Mat3<T> result;
|
||||
|
||||
for (UInt_8 r = 0; r < 3; ++r)
|
||||
for (UInt_8 c = 0; c < 3; ++c)
|
||||
result[3 * r + c] = Cut(r, c).GetDeterminant();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Minor()
|
||||
{
|
||||
Mat3<T> old = *this;
|
||||
|
||||
for (UInt_8 r = 0; r < 3; ++r)
|
||||
for (UInt_8 c = 0; c < 3; ++c)
|
||||
data[3 * r + c] = old.Cut(r, c).GetDeterminant();
|
||||
}
|
||||
|
||||
Mat2<T> Cut(const UInt_8 row, const UInt_8 column) const
|
||||
{
|
||||
Mat2<T> result;
|
||||
UInt_8 index = 0;
|
||||
|
||||
for (UInt_8 r = 0; r < 3; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 3; ++c)
|
||||
{
|
||||
if (r == row || c == column)
|
||||
continue;
|
||||
|
||||
result[index++] = data[3 * r + c];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
T GetDeterminant() const
|
||||
{
|
||||
Mat3<T> cofactor = GetCofactor();
|
||||
T result = 0;
|
||||
|
||||
for (UInt_8 c = 0; c < 3; ++c)
|
||||
result += data[c] * cofactor[c];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat3<T> GetCofactor() const
|
||||
{
|
||||
Mat3<T> minor = GetMinor();
|
||||
Mat3<T> result;
|
||||
|
||||
for (UInt_8 r = 0; r < 3; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 3; ++c)
|
||||
{
|
||||
UInt_8 i = 3 * c + r;
|
||||
result.data[i] = minor.data[i] * Math::Pow<T>(-1, r + c);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Cofactor()
|
||||
{
|
||||
Mat3<T> minor = GetMinor();
|
||||
|
||||
for (UInt_8 r = 0; r < 3; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 3; ++c)
|
||||
{
|
||||
UInt_8 i = 3 * c + r;
|
||||
data[i] = minor.data[i] * Math::Pow<T>(-1, r + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mat3<T> GetAdjugate() const
|
||||
{
|
||||
return GetCofactor().GetTranspose();
|
||||
}
|
||||
|
||||
void Adjugate()
|
||||
{
|
||||
Cofactor();
|
||||
Transpose();
|
||||
}
|
||||
|
||||
Mat3<T> GetInverse() const
|
||||
{
|
||||
T det = GetDeterminant();
|
||||
if (Math::ComCmp(det, 0.0f))
|
||||
return {};
|
||||
|
||||
return GetAdjugate() * (1 / det);
|
||||
}
|
||||
|
||||
void Inverse()
|
||||
{
|
||||
T det = GetDeterminant();
|
||||
if (Math::ComCmp(det, 0.0f))
|
||||
return;
|
||||
|
||||
Adjugate();
|
||||
operator*=(1 / det);
|
||||
}
|
||||
|
||||
static Mat3<T> Identity()
|
||||
{
|
||||
Mat3<T> result;
|
||||
result.data[0] = 1;
|
||||
result.data[4] = 1;
|
||||
result.data[8] = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat3<T> Scale(const Vec3<T>& scale)
|
||||
{
|
||||
Mat3<T> result;
|
||||
result.data[0] = scale.x;
|
||||
result.data[4] = scale.y;
|
||||
result.data[8] = scale.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat3<T> PitchRotate(const T angle)
|
||||
{
|
||||
T radians = Math::Rads(angle);
|
||||
|
||||
Mat3<T> result;
|
||||
result.data[0] = 1;
|
||||
result.data[4] = Math::Cos(radians);
|
||||
result.data[5] = Math::Sin(radians);
|
||||
result.data[7] = -Math::Sin(radians);
|
||||
result.data[8] = Math::Cos(radians);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat3<T> YawRotate(const T angle)
|
||||
{
|
||||
T radians = Math::Rads(angle);
|
||||
|
||||
Mat3<T> result;
|
||||
result.data[0] = Math::Cos(radians);
|
||||
result.data[2] = -Math::Sin(radians);
|
||||
result.data[4] = 1;
|
||||
result.data[6] = Math::Sin(radians);
|
||||
result.data[8] = Math::Cos(radians);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat3<T> RollRotate(const T angle)
|
||||
{
|
||||
T radians = Math::Rads(angle);
|
||||
|
||||
Mat3<T> result;
|
||||
result.data[0] = Math::Cos(radians);
|
||||
result.data[1] = Math::Sin(radians);
|
||||
result.data[3] = -Math::Sin(radians);
|
||||
result.data[4] = Math::Cos(radians);
|
||||
result.data[8] = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat3<T> Rotate(const Vec3<T>& vec)
|
||||
{
|
||||
return YawRotate(vec.y) * RollRotate(vec.z) * PitchRotate(vec.x);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Mat3<float> Mat3_f;
|
||||
typedef Mat3<double> Mat3_d;
|
||||
}
|
426
include/Mat4.h
Normal file
426
include/Mat4.h
Normal file
@ -0,0 +1,426 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Math.h"
|
||||
#include "Mat3.h"
|
||||
#include "Vec4.h"
|
||||
#include "Vec3.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template <typename T = float>
|
||||
class Mat4
|
||||
{
|
||||
private:
|
||||
friend class GpuUniform;
|
||||
|
||||
T data[16];
|
||||
|
||||
public:
|
||||
Mat4()
|
||||
{
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
data[i] = 0;
|
||||
}
|
||||
|
||||
explicit Mat4(const T* data)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
this->data[i] = data[i];
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat4(const Mat3<C>& mat)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 9; ++i)
|
||||
{
|
||||
UInt_8 row = i / 3;
|
||||
UInt_8 column = i % 3;
|
||||
UInt_8 dst = row * 4 + column;
|
||||
|
||||
data[dst] = (T)mat[i];
|
||||
}
|
||||
|
||||
data[3] = 0;
|
||||
data[7] = 0;
|
||||
data[11] = 0;
|
||||
data[12] = 0;
|
||||
data[13] = 0;
|
||||
data[14] = 0;
|
||||
data[15] = 1;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat4(const Mat4<C>& mat)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
data[i] = (T)mat.data[i];
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Mat4<T>& operator=(const Mat4<C>& mat)
|
||||
{
|
||||
if (this == &mat)
|
||||
return *this;
|
||||
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
data[i] = (T)mat.data[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator*(Vec4<T> vec) const
|
||||
{
|
||||
Vec4<T> result;
|
||||
result.x = vec.x * data[0] + vec.y * data[4] + vec.z * data[8] + vec.w * data[12];
|
||||
result.y = vec.x * data[1] + vec.y * data[5] + vec.z * data[9] + vec.w * data[13];
|
||||
result.z = vec.x * data[2] + vec.y * data[6] + vec.z * data[10] + vec.w * data[14];
|
||||
result.w = vec.x * data[3] + vec.y * data[7] + vec.z * data[11] + vec.w * data[15];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat4<T>& operator*=(const T scalar)
|
||||
{
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
data[i] *= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat4<T> operator*(const T scalar) const
|
||||
{
|
||||
Mat4<T> result;
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
result.data[i] = data[i] * scalar;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat4<T>& operator*=(const Mat4<T>& mat)
|
||||
{
|
||||
Mat4 transposed = GetTranspose();
|
||||
|
||||
for (UInt_8 i = 0; i < 16; i++)
|
||||
{
|
||||
UInt_8 row = i / 4 * 4;
|
||||
UInt_8 column = i % 4 * 4;
|
||||
data[i] += transposed.data[column] * mat.data[row];
|
||||
data[i] += transposed.data[column + 1] * mat.data[row + 1];
|
||||
data[i] += transposed.data[column + 2] * mat.data[row + 2];
|
||||
data[i] += transposed.data[column + 3] * mat.data[row + 3];
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat4<T> operator*(const Mat4<T>& mat) const
|
||||
{
|
||||
Mat4 transposed = GetTranspose();
|
||||
|
||||
Mat4<T> result;
|
||||
for (UInt_8 i = 0; i < 16; i++)
|
||||
{
|
||||
UInt_8 row = i / 4 * 4;
|
||||
UInt_8 column = i % 4 * 4;
|
||||
result.data[i] += transposed.data[column] * mat.data[row];
|
||||
result.data[i] += transposed.data[column + 1] * mat.data[row + 1];
|
||||
result.data[i] += transposed.data[column + 2] * mat.data[row + 2];
|
||||
result.data[i] += transposed.data[column + 3] * mat.data[row + 3];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
operator const T*() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
operator T*()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
Vec3<T> GetRight() const
|
||||
{
|
||||
return Vec3<T>(data[0], data[4], data[8]);
|
||||
}
|
||||
|
||||
Vec3<T> GetUp() const
|
||||
{
|
||||
return Vec3<T>(data[1], data[5], data[9]);
|
||||
}
|
||||
|
||||
Vec3<T> GetForward() const
|
||||
{
|
||||
return Vec3<T>(data[2], data[6], data[10]);
|
||||
}
|
||||
|
||||
Mat4<T> GetTranspose() const
|
||||
{
|
||||
Mat4<T> result;
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
result.data[i] = data[i % 4 * 4 + i / 4];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Transpose()
|
||||
{
|
||||
Mat4<T> old = *this;
|
||||
for (UInt_8 i = 0; i < 16; ++i)
|
||||
data[i] = old.data[4 * (i % 4) + i / 4];
|
||||
}
|
||||
|
||||
Mat3<T> Cut(const UInt_8 row, const UInt_8 column) const
|
||||
{
|
||||
Mat3<T> result;
|
||||
UInt_8 index = 0;
|
||||
|
||||
for (UInt_8 r = 0; r < 4; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 4; ++c)
|
||||
{
|
||||
if (r == row || c == column)
|
||||
continue;
|
||||
|
||||
result[index++] = data[4 * r + c];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat4<T> GetMinor() const
|
||||
{
|
||||
Mat4<T> result;
|
||||
|
||||
for (UInt_8 r = 0; r < 4; ++r)
|
||||
for (UInt_8 c = 0; c < 4; ++c)
|
||||
result.data[4 * r + c] = Cut(r, c).GetDeterminant();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Minor()
|
||||
{
|
||||
Mat4<T> old = *this;
|
||||
|
||||
for (UInt_8 r = 0; r < 4; ++r)
|
||||
for (UInt_8 c = 0; c < 4; ++c)
|
||||
data[4 * r + c] = old.Cut(r, c).GetDeterminant();
|
||||
}
|
||||
|
||||
Mat4<T> GetCofactor() const
|
||||
{
|
||||
Mat4<T> minor = GetMinor();
|
||||
Mat4<T> result;
|
||||
|
||||
for (UInt_8 r = 0; r < 4; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 4; ++c)
|
||||
{
|
||||
UInt_8 i = 4 * c + r;
|
||||
result.data[i] = minor.data[i] * Math::Pow<T>(-1, r + c);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Cofactor()
|
||||
{
|
||||
Mat4<T> minor = GetMinor();
|
||||
|
||||
for (UInt_8 r = 0; r < 4; ++r)
|
||||
{
|
||||
for (UInt_8 c = 0; c < 4; ++c)
|
||||
{
|
||||
UInt_8 i = 4 * c + r;
|
||||
data[i] = minor.data[i] * Math::Pow<T>(-1, r + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T GetDeterminant() const
|
||||
{
|
||||
Mat4<T> cofactor = GetCofactor();
|
||||
T result = 0;
|
||||
|
||||
for (UInt_8 c = 0; c < 4; ++c)
|
||||
result += data[c] * cofactor[c];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Mat4<T> GetAdjugate() const
|
||||
{
|
||||
return GetCofactor().GetTranspose();
|
||||
}
|
||||
|
||||
void Adjugate()
|
||||
{
|
||||
Cofactor();
|
||||
Transpose();
|
||||
}
|
||||
|
||||
Mat4<T> GetInverse() const
|
||||
{
|
||||
T det = GetDeterminant();
|
||||
if (Math::ComCmp(det, 0.0f))
|
||||
return {};
|
||||
|
||||
return GetAdjugate() * (1 / det);
|
||||
}
|
||||
|
||||
void Inverse()
|
||||
{
|
||||
T det = GetDeterminant();
|
||||
if (Math::ComCmp(det, 0.0f))
|
||||
return;
|
||||
|
||||
Adjugate();
|
||||
operator*=(1 / det);
|
||||
}
|
||||
|
||||
static Mat4<T> Identity()
|
||||
{
|
||||
Mat4<T> result;
|
||||
result.data[0] = 1;
|
||||
result.data[5] = 1;
|
||||
result.data[10] = 1;
|
||||
result.data[15] = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> Scale(const Vec3<T>& scale)
|
||||
{
|
||||
Mat4<T> result;
|
||||
result.data[0] = scale.x;
|
||||
result.data[5] = scale.y;
|
||||
result.data[10] = scale.z;
|
||||
result.data[15] = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> Translate(const Vec3<T>& pos)
|
||||
{
|
||||
Mat4<T> result = Identity();
|
||||
result.data[12] = pos.x;
|
||||
result.data[13] = pos.y;
|
||||
result.data[14] = pos.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> PitchRotate(const T angle)
|
||||
{
|
||||
T radians = Math::Rads(angle);
|
||||
|
||||
Mat4<T> result;
|
||||
result.data[0] = 1;
|
||||
result.data[5] = Math::Cos(radians);
|
||||
result.data[6] = Math::Sin(radians);
|
||||
result.data[9] = -Math::Sin(radians);
|
||||
result.data[10] = Math::Cos(radians);
|
||||
result.data[15] = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> YawRotate(const T angle)
|
||||
{
|
||||
T radians = Math::Rads(angle);
|
||||
|
||||
Mat4<T> result;
|
||||
result.data[0] = Math::Cos(radians);
|
||||
result.data[2] = -Math::Sin(radians);
|
||||
result.data[5] = 1;
|
||||
result.data[8] = Math::Sin(radians);
|
||||
result.data[10] = Math::Cos(radians);
|
||||
result.data[15] = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> RollRotate(const T angle)
|
||||
{
|
||||
T radians = Math::Rads(angle);
|
||||
|
||||
Mat4<T> result;
|
||||
result.data[0] = Math::Cos(radians);
|
||||
result.data[1] = Math::Sin(radians);
|
||||
result.data[4] = -Math::Sin(radians);
|
||||
result.data[5] = Math::Cos(radians);
|
||||
result.data[10] = 1;
|
||||
result.data[15] = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> Rotate(const Vec3<T>& vec)
|
||||
{
|
||||
return YawRotate(vec.y) * RollRotate(vec.z) * PitchRotate(vec.x);
|
||||
}
|
||||
|
||||
static Mat4<T> RH_Perspective(const T fov, const T aspect, const T zNear, const T zFar)
|
||||
{
|
||||
const float tanHalfFovy = tan(Math::Rads(fov) / 2.0f);
|
||||
|
||||
Mat4<T> result;
|
||||
result[0] = 1.0f / (aspect * tanHalfFovy);
|
||||
result[5] = -1.0f / tanHalfFovy;
|
||||
result[10] = zFar / (zFar - zNear);
|
||||
result[14] = -(zFar * zNear) / (zFar - zNear);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> LH_Perspective(const T fov, const T aspect, const T zNear, const T zFar)
|
||||
{
|
||||
const float tanHalfFovy = Math::Tan(Math::Rads(fov) / 2.0f);
|
||||
|
||||
Mat4<T> result;
|
||||
result[0] = 1.0f / (aspect * tanHalfFovy);
|
||||
result[5] = -1.0f / tanHalfFovy;
|
||||
result[10] = zFar / (zFar - zNear);
|
||||
result[11] = 1.0f;
|
||||
result[14] = -(zFar * zNear) / (zFar - zNear);
|
||||
result[15] = 0.0f;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Mat4<T> LH_Orthographic(const T left, const T right, const T top, const T bottom, const T zNear, const T zFar)
|
||||
{
|
||||
Mat4<T> result;
|
||||
result[0] = 2.0f / (right - left); // 0,0 entry
|
||||
result[5] = 2.0f / (bottom - top); // 1,1 entry
|
||||
result[10] = 1.0f / (zFar - zNear); // 2,2 entry
|
||||
result[12] = -(right + left) / (right - left); // 3,0 entry
|
||||
result[13] = -(bottom + top) / (bottom - top); // 3,1 entry
|
||||
result[14] = -zNear / (zFar - zNear); // 3,2 entry
|
||||
result[15] = 1.0f; // 3,3 entry
|
||||
|
||||
return result;
|
||||
|
||||
/*
|
||||
Mat4<T> result;
|
||||
result.data[0] = 2 / (right - left);
|
||||
result.data[5] = 2 / (top - bottom);
|
||||
result.data[10] = 1 / (zFar - zNear);
|
||||
result.data[12] = (left + right) / (left - right);
|
||||
result.data[13] = (top + bottom) / (bottom - top);
|
||||
result.data[14] = zNear / (zNear - zFar);
|
||||
result.data[15] = 1;
|
||||
|
||||
return result;
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
typedef Mat4<float> Mat4_f;
|
||||
typedef Mat4<double> Mat4_d;
|
||||
}
|
316
include/Math.h
Normal file
316
include/Math.h
Normal file
@ -0,0 +1,316 @@
|
||||
#pragma once
|
||||
|
||||
#include "System/CPU.h"
|
||||
|
||||
#define LWE_LOW_WORD(x) *((int*)&x) + 1
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Math
|
||||
{
|
||||
private:
|
||||
static float Sqrt_AVX(const float from);
|
||||
|
||||
static double Sqrt_AVX(const double from);
|
||||
|
||||
static float Sqrt_SSE(const float from);
|
||||
|
||||
static double Sqrt_SSE2(const double from);
|
||||
|
||||
static float Sqrt_VFP4(const float from);
|
||||
|
||||
static double Sqrt_VFP4(const double from);
|
||||
|
||||
public:
|
||||
constexpr static float fltEpsilon = 1e-7f;
|
||||
constexpr static double dblEpsilon = 1e-16;
|
||||
|
||||
/// Absolute tolerance comparison for single precision floats.
|
||||
static bool AbsCmp(const float a, const float b);
|
||||
|
||||
/// Absolute tolerance comparison for double precision floats.
|
||||
static bool AbsCmp(const double a, const double b);
|
||||
|
||||
/// Relative tolerance comparison for single precision floats.
|
||||
static bool RelCmp(const float a, const float b);
|
||||
|
||||
/// Relative tolerance comparison for double precision floats.
|
||||
static bool RelCmp(const double a, const double b);
|
||||
|
||||
/// Combined absolute and relative tolerance comparison for single precision floats.
|
||||
static bool ComCmp(const float a, const float b);
|
||||
|
||||
/// Combined absolute and relative tolerance comparison for double precision floats.
|
||||
static bool ComCmp(const double a, const double b);
|
||||
|
||||
template<typename T = float>
|
||||
static T Max(const T a, const T b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T = float>
|
||||
static T Min(const T a, const T b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T = float>
|
||||
static T Clamp(const T value, const T min, const T max)
|
||||
{
|
||||
if (value < min)
|
||||
return min;
|
||||
else if (value > max)
|
||||
return max;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T = float>
|
||||
static T Abs(const T from)
|
||||
{
|
||||
return from < 0 ? -from : from;
|
||||
}
|
||||
|
||||
/// Retrieves a very accurate version of Pi as a long double and converts it.
|
||||
/// @tparam T The data type to return Pi as.
|
||||
/// @returns The result.
|
||||
template<typename T = float>
|
||||
static constexpr T Pi()
|
||||
{
|
||||
return (T)3.141592653589793238462643383279502884L;
|
||||
}
|
||||
|
||||
/// Converts degrees into radians.
|
||||
/// @tparam T The data type to return;
|
||||
/// @param [in] from The value to convert to radians.
|
||||
/// @returns The value in radians.
|
||||
template<typename T = float>
|
||||
static T Rads(const T from)
|
||||
{
|
||||
return from * 0.01745329251994329576923690768489;
|
||||
}
|
||||
|
||||
/// Converts radians into degrees.
|
||||
/// @tparam T The data type to return;
|
||||
/// @param [in] from The value to convert to degrees.
|
||||
/// @returns The value in degrees.
|
||||
template<typename T = float>
|
||||
static T Degr(const T from)
|
||||
{
|
||||
return from * 57.295779513082320876798154814105;
|
||||
}
|
||||
|
||||
/// A method for use of exponents.
|
||||
/// @tparam T The data type to return;
|
||||
/// @tparam I The data type to use as the exponent.
|
||||
/// @param [in] from The value to use the exponent on.
|
||||
/// @param [in] of The exponent.
|
||||
/// @returns The result.
|
||||
template<typename T = float, typename I = UInt_64>
|
||||
static T Pow(const T from, const I of)
|
||||
{
|
||||
if (of < 0)
|
||||
{
|
||||
if (from == 0)
|
||||
return -0;
|
||||
|
||||
return 1 / (from * Pow<T>(from, (-of) - 1));
|
||||
}
|
||||
|
||||
if (of == 0)
|
||||
return 1;
|
||||
else if (of == 1)
|
||||
return from;
|
||||
|
||||
return from * Pow<T>(from, of - 1);
|
||||
}
|
||||
|
||||
static float Near(const float from);
|
||||
|
||||
static double Near(const double from);
|
||||
|
||||
static float Floor(const float from);
|
||||
|
||||
static double Floor(const double from);
|
||||
|
||||
static float Ceil(const float from);
|
||||
|
||||
static double Ceil(const double from);
|
||||
|
||||
static float Trunc(const float from);
|
||||
|
||||
static double Trunc(const double from);
|
||||
|
||||
static float Mod(const float from, const float divisor);
|
||||
|
||||
static double Mod(const double from, const double divisor);
|
||||
|
||||
/// A method for retrieving the square root of a value.
|
||||
/// @tparam T The data type to use.
|
||||
/// @param [in] from The value to retrieve to square root of.
|
||||
/// @returns The result.
|
||||
template<typename T = float>
|
||||
static T Sqrt(const T from)
|
||||
{
|
||||
T temp = 0;
|
||||
T result = from / 2;
|
||||
|
||||
while (result != temp)
|
||||
{
|
||||
temp = result;
|
||||
result = (from / temp + temp) / 2;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static double Sqrt(const double from);
|
||||
|
||||
static float Sqrt(const float from);
|
||||
|
||||
template<typename R = float>
|
||||
static R Sin(const R angle, const R precision = 0.001)
|
||||
{
|
||||
R sum = angle;
|
||||
R term = angle;
|
||||
|
||||
for (UInt_64 i = 1; Abs<R>(term) >= precision; ++i)
|
||||
{
|
||||
term *= -angle * angle / (R)((2 * i + 1) * (2 * i));
|
||||
sum += term;
|
||||
}
|
||||
|
||||
return sum;
|
||||
|
||||
/*
|
||||
R sum = 0;
|
||||
|
||||
for (USize n = 0; n < precision; ++n)
|
||||
sum += Pow<R>(-1, n) / (R)Fact<T>(2 * n + 1) * Pow<R>(angle, 2 * n + 1);
|
||||
|
||||
return sum;
|
||||
*/
|
||||
}
|
||||
|
||||
template<typename R = float, typename T = UInt_64>
|
||||
static R ASin(const R yPos, const T precision = 10)
|
||||
{
|
||||
R sum = 0;
|
||||
|
||||
for (T n = 0; n < precision; ++n)
|
||||
sum += (R)Fact<T>(2 * n) / (Pow<R>(4, n) * Pow<R>((R)Fact<T>(n), 2) * (2 * n + 1)) * Pow<R>(yPos, 2 * n + 1);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
/// A trigonometry Cosine function for finding the X-Axis position from the Z-Axis angle.
|
||||
/// @tparam R BaseInput and result data type.
|
||||
/// @tparam T Precision data type.
|
||||
/// @param[in] angle The angle in radians from the Z-Axis.
|
||||
/// @param [in] precision Sigma max.
|
||||
/// @returns The X-Axis position.
|
||||
template<typename R = float>
|
||||
static R Cos(const R angle, const R precision = 0.001)
|
||||
{
|
||||
R sum = 1.0;
|
||||
R term = 1.0;
|
||||
|
||||
for (UInt_64 i = 2; Abs<R>(term) >= precision; i += 2)
|
||||
{
|
||||
term *= -angle * angle / (R)(i * (i - 1));
|
||||
sum += term;
|
||||
}
|
||||
|
||||
return sum;
|
||||
|
||||
/*
|
||||
R sum = 0;
|
||||
|
||||
for (T n = 0; n < precision; ++n)
|
||||
sum += Pow<R>(-1, n) / (R)Fact<T>(2 * n) * Pow<R>(angle, 2 * n);
|
||||
|
||||
return sum;
|
||||
*/
|
||||
}
|
||||
|
||||
/// A trigonometry Arc Cosine function for finding the Z-Axis angle form the X-Axis position.
|
||||
/// @tparam R BaseInput and result data type.
|
||||
/// @tparam T Precision data type.
|
||||
/// @param [in] xPos The position from the X-Axis.
|
||||
/// @param [in] precision Sigma max.
|
||||
/// @returns The Z-Axis angle.
|
||||
template<typename R = float, typename T = UInt_64>
|
||||
static R ACos(const R xPos, const T precision = 10)
|
||||
{
|
||||
return Pi<R>() / 2 - ASin<R, T>(xPos, precision);
|
||||
}
|
||||
|
||||
template<typename R = float>
|
||||
static R Tan(const R angle, const R precision = 0.001)
|
||||
{
|
||||
/*
|
||||
R sum = 0;
|
||||
|
||||
for (T n = 1; n < precision + 1; ++n)
|
||||
sum += B<R>(2 * n) * Pow<R>(-4, n) * (1 - Pow<R>(4, n)) / (R)Fact<T>(2 * n) * Pow<R>(angle, 2 * n - 1);
|
||||
|
||||
return sum;
|
||||
*/
|
||||
return Sin<R>(angle) / Cos<R>(angle);
|
||||
}
|
||||
|
||||
template<typename R = float, typename T = UInt_64>
|
||||
static R ATan(const R x, const T precision = 1)
|
||||
{
|
||||
R sum = 0;
|
||||
|
||||
for (T n = 0; n < precision; ++n)
|
||||
sum += Pow<R>(-1, n) / (2 * n + 1) * Pow<R>(x, 2 * n + 1);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
template<typename R = float>
|
||||
static R Cot(const R x, const R precision = 0.001)
|
||||
{
|
||||
return 1 / Tan<R>(x, precision);
|
||||
}
|
||||
|
||||
template<typename T = UInt_64>
|
||||
static T Fact(const T n)
|
||||
{
|
||||
if (n <= 1)
|
||||
return 1;
|
||||
|
||||
return n * Fact<T>(n - 1);
|
||||
}
|
||||
|
||||
template<typename R = float, typename T = UInt_64>
|
||||
static R Combination(const T n, const T k)
|
||||
{
|
||||
if (k <= n)
|
||||
return (R)Fact<T>(n) / (R)(Fact<T>(n - k) * Fact<T>(k));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename R = float, typename T = UInt_64>
|
||||
static R B(const T n)
|
||||
{
|
||||
R innerSum = 0;
|
||||
R outerSum = 0;
|
||||
|
||||
for (T k = 0; k <= n; ++k)
|
||||
{
|
||||
for (T r = 0; r <= k; ++r)
|
||||
innerSum += Pow<R, T>(-1, r) * Combination<R, T>(k, r) * Pow<R, T>(r, n);
|
||||
|
||||
outerSum += 1 / ((R)k + 1) * innerSum;
|
||||
innerSum = 0;
|
||||
}
|
||||
|
||||
return outerSum;
|
||||
}
|
||||
};
|
||||
}
|
60
include/PRNG.h
Normal file
60
include/PRNG.h
Normal file
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template<typename T>
|
||||
class PRNG
|
||||
{
|
||||
private:
|
||||
T seed;
|
||||
T last;
|
||||
|
||||
public:
|
||||
PRNG()
|
||||
: seed(0), last(0)
|
||||
{
|
||||
}
|
||||
|
||||
PRNG(const T seed)
|
||||
: seed(seed), last(seed)
|
||||
{
|
||||
}
|
||||
|
||||
PRNG(const PRNG& prng)
|
||||
: seed(prng.seed), last(prng.last)
|
||||
{
|
||||
}
|
||||
|
||||
PRNG& operator=(const PRNG& prng)
|
||||
{
|
||||
if (this == &prng)
|
||||
return *this;
|
||||
|
||||
seed = prng.seed;
|
||||
last = prng.last;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
T Generate(const T min, const T max)
|
||||
{
|
||||
return Generate() % (max - min) + min;
|
||||
}
|
||||
|
||||
T Generate()
|
||||
{
|
||||
return ((last = last * (T)214013 + (T)2531011) >> 16) & (T)0x7fff;
|
||||
}
|
||||
};
|
||||
|
||||
typedef PRNG<SInt_64> PRNG_s64;
|
||||
typedef PRNG<UInt_64> PRNG_u64;
|
||||
typedef PRNG<SInt_32> PRNG_s32;
|
||||
typedef PRNG<UInt_32> PRNG_u32;
|
||||
typedef PRNG<SInt_16> PRNG_s16;
|
||||
typedef PRNG<UInt_16> PRNG_u16;
|
||||
typedef PRNG<SInt_8> PRNG_s8;
|
||||
typedef PRNG<UInt_8> PRNG_u8;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user