First commit.
This commit is contained in:
commit
1a4a1ecd9c
82
.gitea/workflows/Build_Release.yaml
Normal file
82
.gitea/workflows/Build_Release.yaml
Normal file
@ -0,0 +1,82 @@
|
||||
name: Build & Release
|
||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
Linux-x86_64-Build:
|
||||
runs-on: linux-x86_64
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Installing Dependencies
|
||||
run: |
|
||||
sudo pacman -S --noconfirm zip alsa-lib libxcb xcb-util-cursor
|
||||
|
||||
- name: Building/Compiling Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug -DLINUX_WINDOW_SYSTEM:STRING=XCB .
|
||||
cmake --build . --config Debug
|
||||
|
||||
- name: Creating Appropriate Directories
|
||||
run: |
|
||||
mkdir bin
|
||||
mv StrToHash bin
|
||||
mkdir lib
|
||||
mv libEHS.a lib
|
||||
|
||||
- name: Zipping Binaries
|
||||
run: zip -r ehs-linux-amd64.zip include bin lib
|
||||
|
||||
- uses: https://github.com/actions/setup-go@v4
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
|
||||
- name: Use Go Action
|
||||
id: use-go-action
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
with:
|
||||
files: |-
|
||||
ehs-linux-amd64.zip
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
||||
|
||||
Linux-AARCH64-Build:
|
||||
runs-on: linux-aarch64
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Installing Dependencies
|
||||
run: sudo apt install -y zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev
|
||||
|
||||
- name: Building/Compiling Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug -DLINUX_WINDOW_SYSTEM:STRING=XCB .
|
||||
cmake --build . --config Debug
|
||||
|
||||
- name: Creating Appropriate Directories
|
||||
run: |
|
||||
mkdir bin
|
||||
mv StrToHash bin
|
||||
mkdir lib
|
||||
mv libEHS.a lib
|
||||
|
||||
- name: Zipping Binaries
|
||||
run: zip -r ehs-linux-aarch64.zip include bin lib
|
||||
|
||||
- uses: https://github.com/actions/setup-go@v4
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
|
||||
- name: Use Go Action
|
||||
id: use-go-action
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
with:
|
||||
files: |-
|
||||
ehs-linux-aarch64.zip
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
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/
|
257
CMakeLists.txt
Normal file
257
CMakeLists.txt
Normal file
@ -0,0 +1,257 @@
|
||||
cmake_minimum_required(VERSION 3.25.1)
|
||||
|
||||
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/EHS.h
|
||||
src/Type.cpp include/ehs/Type.h
|
||||
src/BaseObj.cpp include/ehs/BaseObj.h
|
||||
src/GarbageCollector.cpp include/ehs/GarbageCollector.h
|
||||
src/Log.cpp include/ehs/Log.h
|
||||
src/URI.cpp include/ehs/URI.h
|
||||
src/Math.cpp include/ehs/Math.h
|
||||
src/Color4.cpp include/ehs/Color4.h
|
||||
src/Color3.cpp include/ehs/Color3.h
|
||||
src/Version.cpp include/ehs/Version.h
|
||||
src/Base64.cpp include/ehs/Base64.h
|
||||
src/Data.cpp include/ehs/Data.h
|
||||
src/Range.cpp include/ehs/Range.h
|
||||
src/Util.cpp include/ehs/Util.h
|
||||
src/Task.cpp include/ehs/Task.h
|
||||
src/DataType.cpp include/ehs/DataType.h
|
||||
include/ehs/Anchor.h
|
||||
include/ehs/Dock.h
|
||||
include/ehs/HashMap.h
|
||||
include/ehs/HRNG.h
|
||||
include/ehs/Link.h
|
||||
include/ehs/LinkedList.h
|
||||
include/ehs/Mat2.h
|
||||
include/ehs/Mat3.h
|
||||
include/ehs/Mat4.h
|
||||
include/ehs/PRNG.h
|
||||
include/ehs/Quat.h
|
||||
include/ehs/Rect.h
|
||||
include/ehs/Str.h
|
||||
include/ehs/Types.h
|
||||
include/ehs/UTF.h
|
||||
include/ehs/Vec2.h
|
||||
include/ehs/Vec3.h
|
||||
include/ehs/Vec4.h
|
||||
include/ehs/Serializer.h
|
||||
include/ehs/Array.h
|
||||
include/ehs/Vector.h
|
||||
include/ehs/SArray.h
|
||||
src/PtrData.cpp include/ehs/PtrData.h
|
||||
include/ehs/UniPtr.h
|
||||
include/ehs/ShdPtr.h
|
||||
include/ehs/WkPtr.h
|
||||
|
||||
src/database/DVar.cpp include/ehs/database/DVar.h
|
||||
|
||||
src/system/CPU.cpp include/ehs/system/CPU.h
|
||||
src/system/Thread.cpp include/ehs/system/Thread.h
|
||||
src/system/BaseMutex.cpp include/ehs/system/BaseMutex.h
|
||||
src/system/BaseSemaphore.cpp include/ehs/system/BaseSemaphore.h
|
||||
src/system/BaseSystem.cpp include/ehs/system/BaseSystem.h
|
||||
src/system/BaseOpen.cpp include/ehs/system/BaseOpen.h
|
||||
include/ehs/system/Architecture.h
|
||||
include/ehs/system/Mutex.h
|
||||
include/ehs/system/Open.h
|
||||
include/ehs/system/OS.h
|
||||
include/ehs/system/Semaphore.h
|
||||
include/ehs/system/System.h
|
||||
|
||||
src/json/Json.cpp include/ehs/json/Json.h
|
||||
src/json/JsonBase.cpp include/ehs/json/JsonBase.h
|
||||
src/json/JsonNum.cpp include/ehs/json/JsonNum.h
|
||||
src/json/JsonBool.cpp include/ehs/json/JsonBool.h
|
||||
src/json/JsonStr.cpp include/ehs/json/JsonStr.h
|
||||
src/json/JsonObj.cpp include/ehs/json/JsonObj.h
|
||||
src/json/JsonArray.cpp include/ehs/json/JsonArray.h
|
||||
src/json/JsonVar.cpp include/ehs/json/JsonVar.h
|
||||
|
||||
src/io/Resource.cpp include/ehs/io/Resource.h
|
||||
src/io/Console.cpp include/ehs/io/Console.h
|
||||
src/io/RIFF_Chunk.cpp include/ehs/io/RIFF_Chunk.h
|
||||
src/io/RIFF.cpp include/ehs/io/RIFF.h
|
||||
src/io/BaseWindow.cpp include/ehs/io/BaseWindow.h
|
||||
src/io/BaseFile.cpp include/ehs/io/BaseFile.h
|
||||
src/io/Glyph.cpp include/ehs/io/Glyph.h
|
||||
src/io/FontAtlas.cpp include/ehs/io/FontAtlas.h
|
||||
src/io/BaseFileMonitor.cpp include/ehs/io/BaseFileMonitor.h
|
||||
include/ehs/io/COM.h
|
||||
include/ehs/io/File.h
|
||||
include/ehs/io/FileMonitor.h
|
||||
include/ehs/io/Window.h
|
||||
|
||||
src/io/socket/Request.cpp include/ehs/io/socket/Request.h
|
||||
src/io/socket/Response.cpp include/ehs/io/socket/Response.h
|
||||
src/io/socket/DNS.cpp include/ehs/io/socket/DNS.h
|
||||
src/io/socket/BaseUDP.cpp include/ehs/io/socket/BaseUDP.h
|
||||
src/io/socket/BaseTCP.cpp include/ehs/io/socket/BaseTCP.h
|
||||
src/io/socket/SSL.cpp include/ehs/io/socket/SSL.h
|
||||
|
||||
src/io/socket/rest/Twitch.cpp include/ehs/io/socket/rest/Twitch.h
|
||||
src/io/socket/rest/TwitchChat.cpp include/ehs/io/socket/rest/TwitchChat.h
|
||||
src/io/socket/rest/Spotify.cpp include/ehs/io/socket/rest/Spotify.h
|
||||
include/ehs/io/socket/Socket.h
|
||||
include/ehs/io/socket/TCP.h
|
||||
include/ehs/io/socket/UDP.h
|
||||
|
||||
src/io/audio/Audio.cpp include/ehs/io/audio/Audio.h
|
||||
src/io/audio/BaseAudioDevice.cpp include/ehs/io/audio/BaseAudioDevice.h
|
||||
src/io/audio/AudioCodec.cpp include/ehs/io/audio/AudioCodec.h
|
||||
include/ehs/io/audio/AudioDevice.h
|
||||
|
||||
src/io/img/PNG.cpp include/ehs/io/img/PNG.h
|
||||
src/io/img/Img.cpp include/ehs/io/img/Img.h
|
||||
src/io/img/PNG_Chunk.cpp include/ehs/io/img/PNG_Chunk.h
|
||||
src/io/img/ImgCodec.cpp include/ehs/io/img/ImgCodec.h
|
||||
|
||||
include/ehs/io/model/Vertex.h
|
||||
src/io/model/Mesh.cpp include/ehs/io/model/Mesh.h
|
||||
src/io/model/Bone.cpp include/ehs/io/model/Bone.h
|
||||
src/io/model/Model.cpp include/ehs/io/model/Model.h
|
||||
src/io/model/Animation.cpp include/ehs/io/model/Animation.h
|
||||
src/io/model/AnimBone.cpp include/ehs/io/model/AnimBone.h
|
||||
src/io/model/KeyFrame.cpp include/ehs/io/model/KeyFrame.h
|
||||
src/io/model/PropertyChange.cpp include/ehs/io/model/PropertyChange.h
|
||||
|
||||
src/io/hid/ButtonState.cpp include/ehs/io/hid/ButtonState.h
|
||||
src/io/hid/Button.cpp include/ehs/io/hid/Button.h
|
||||
src/io/hid/Mouse.cpp include/ehs/io/hid/Mouse.h
|
||||
src/io/hid/Keyboard.cpp include/ehs/io/hid/Keyboard.h
|
||||
src/io/hid/HID.cpp include/ehs/io/hid/HID.h
|
||||
src/io/hid/InputHandler.cpp include/ehs/io/hid/InputHandler.h
|
||||
src/io/hid/Input.cpp include/ehs/io/hid/Input.h
|
||||
)
|
||||
|
||||
if (IS_OS_WINDOWS)
|
||||
list(APPEND EHS_SOURCES
|
||||
src/io/socket/UDP_W32.cpp include/ehs/io/socket/UDP_W32.h
|
||||
src/io/socket/TCP_W32.cpp include/ehs/io/socket/TCP_W32.h
|
||||
src/system/Semaphore_W32.cpp include/ehs/system/Semaphore_W32.h
|
||||
src/system/System_W32.cpp include/ehs/system/System_W32.h
|
||||
src/system/Mutex_W32.cpp include/ehs/system/Mutex_W32.h
|
||||
src/system/Open_W32.cpp include/ehs/system/Open_W32.h
|
||||
src/io/audio/audioDevice_W32.cpp include/ehs/io/audio/audioDevice_W32.h
|
||||
src/io/MsgBox.cpp include/ehs/io/MsgBox.h
|
||||
src/io/File_W32.cpp include/ehs/io/File_W32.h
|
||||
src/io/FileMonitor_W32.cpp include/ehs/io/FileMonitor_W32.h
|
||||
src/io/Window_W32.cpp include/ehs/io/Window_W32.h
|
||||
src/io/COM.cpp include/ehs/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/ehs/io/socket/UDP_BSD.h
|
||||
src/io/socket/TCP_BSD.cpp include/ehs/io/socket/TCP_BSD.h
|
||||
src/system/Semaphore_P.cpp include/ehs/system/Semaphore_P.h
|
||||
src/system/System_LNX.cpp include/ehs/system/System_LNX.h
|
||||
src/system/Open_UNX.cpp include/ehs/system/Open_UNX.h
|
||||
src/io/File_UNX.cpp include/ehs/io/File_UNX.h
|
||||
src/io/FileMonitor_UNX.cpp include/ehs/io/FileMonitor_UNX.h
|
||||
src/system/Mutex_PT.cpp include/ehs/system/Mutex_PT.h
|
||||
src/io/audio/AudioDevice_ALSA.cpp include/ehs/io/audio/AudioDevice_ALSA.h
|
||||
src/system/FileSystem.cpp include/ehs/system/FileSystem.h
|
||||
src/system/User.cpp include/ehs/system/User.h
|
||||
)
|
||||
|
||||
set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System")
|
||||
|
||||
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")
|
||||
add_compile_definitions(EHS_WS_WAYLAND)
|
||||
list(APPEND EHS_SOURCES src/io/xdg-shell-protocol.c include/ehs/io/xdg-shell-client-protocol.h src/io/Window_Way.cpp include/ehs/io/Window_Way.h)
|
||||
message("Building for Wayland.")
|
||||
elseif (LINUX_WINDOW_SYSTEM STREQUAL "XCB")
|
||||
add_compile_definitions(EHS_WS_XCB)
|
||||
list(APPEND EHS_SOURCES src/io/Window_XCB.cpp include/ehs/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)
|
||||
|
||||
target_include_directories(EHS PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
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)
|
||||
|
||||
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 EHS)
|
||||
elseif (IS_OS_LINUX)
|
||||
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")
|
||||
target_link_libraries(StrToHash wayland-client)
|
||||
elseif (LINUX_WINDOW_SYSTEM STREQUAL "XCB")
|
||||
target_link_libraries(StrToHash xcb xcb-cursor xcb-xfixes xcb-xinput)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(StrToHash z asound EHS)
|
||||
endif ()
|
19
include/ehs/Anchor.h
Normal file
19
include/ehs/Anchor.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class Anchor : UInt_8
|
||||
{
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
TOP_CENTER,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT,
|
||||
BOTTOM_CENTER,
|
||||
CENTER_LEFT,
|
||||
CENTER_RIGHT,
|
||||
CENTER
|
||||
};
|
||||
}
|
426
include/ehs/Array.h
Normal file
426
include/ehs/Array.h
Normal file
@ -0,0 +1,426 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "BaseObj.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
/// 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 : public BaseObj
|
||||
{
|
||||
protected:
|
||||
T* data;
|
||||
N size;
|
||||
|
||||
public:
|
||||
/// Frees any data created on the heap.
|
||||
~Array() override
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
/// Default members initialization.
|
||||
Array()
|
||||
: data(nullptr), size(0)
|
||||
{
|
||||
AddType("Array");
|
||||
}
|
||||
|
||||
/// 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)
|
||||
{
|
||||
AddType("Array");
|
||||
}
|
||||
|
||||
/// 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())
|
||||
{
|
||||
AddType("Array");
|
||||
|
||||
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)
|
||||
{
|
||||
AddType("Array");
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
this->data[i] = data[i];
|
||||
}
|
||||
|
||||
Array(Array&& array) noexcept
|
||||
: BaseObj(array), 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.
|
||||
Array(const Array& array)
|
||||
: BaseObj((BaseObj&&)array), data(new T[array.size]), size(array.size)
|
||||
{
|
||||
for (N i = 0; i < size; ++i)
|
||||
data[i] = array.data[i];
|
||||
}
|
||||
|
||||
Array<T, N>& operator=(Array&& array) noexcept
|
||||
{
|
||||
if (this == &array)
|
||||
return *this;
|
||||
|
||||
BaseObj::operator=((BaseObj&&)array);
|
||||
|
||||
delete[] data;
|
||||
data = array.data;
|
||||
size = array.size;
|
||||
|
||||
array.data = nullptr;
|
||||
array.size = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// 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;
|
||||
|
||||
BaseObj::operator=(array);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// 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::Compare(data, in.data, size);
|
||||
}
|
||||
|
||||
bool operator!=(const Array& in) const
|
||||
{
|
||||
if (size != in.size)
|
||||
return true;
|
||||
|
||||
return !Util::Compare(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 popped = (T&&)data[size];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = (T&&)data[i];
|
||||
|
||||
delete[] data;
|
||||
|
||||
data = result;
|
||||
|
||||
return popped;
|
||||
}
|
||||
|
||||
/// Will swap the value at the given index with the value at the end of the array and pops it.
|
||||
/// @param [in] index The index of the value to swap with.
|
||||
/// @returns The removed value.
|
||||
T Pop(const N index)
|
||||
{
|
||||
if (!size)
|
||||
return {};
|
||||
|
||||
N lastIndex = size - 1;
|
||||
|
||||
if (index < lastIndex)
|
||||
Swap(index, lastIndex);
|
||||
|
||||
return Pop();
|
||||
}
|
||||
|
||||
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/ehs/Base64.h
Normal file
24
include/ehs/Base64.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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);
|
||||
|
||||
};
|
||||
}
|
52
include/ehs/BaseObj.h
Normal file
52
include/ehs/BaseObj.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "Type.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class BaseObj
|
||||
{
|
||||
private:
|
||||
Type* hierarchy;
|
||||
UInt_64 hierarchySize;
|
||||
|
||||
public:
|
||||
virtual ~BaseObj();
|
||||
|
||||
BaseObj();
|
||||
|
||||
BaseObj(BaseObj&& base) noexcept;
|
||||
|
||||
BaseObj(const BaseObj& base);
|
||||
|
||||
BaseObj& operator=(BaseObj&& base) noexcept;
|
||||
|
||||
BaseObj& operator=(const BaseObj& base);
|
||||
|
||||
bool operator==(const BaseObj& base) const;
|
||||
|
||||
bool operator!=(const BaseObj& base) const;
|
||||
|
||||
const Type* GetHierarchy() const;
|
||||
|
||||
UInt_64 GetHierarchySize() const;
|
||||
|
||||
bool HasType(UInt_64 typeHashId) const;
|
||||
|
||||
bool HasType(const Char_8* typeId) const;
|
||||
|
||||
Type GetType() const;
|
||||
|
||||
UInt_64 GetTypeIdSize() const;
|
||||
|
||||
const Char_8* GetTypeId() const;
|
||||
|
||||
UInt_64 GetTypeHashId() const;
|
||||
|
||||
virtual BaseObj* Clone() const;
|
||||
|
||||
protected:
|
||||
void AddType(const Char_8* id);
|
||||
};
|
||||
}
|
38
include/ehs/Color3.h
Normal file
38
include/ehs/Color3.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/Color4.h
Normal file
44
include/ehs/Color4.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "Color3.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/Data.h
Normal file
45
include/ehs/Data.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/DataType.h
Normal file
29
include/ehs/DataType.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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);
|
||||
}
|
10
include/ehs/Dock.h
Normal file
10
include/ehs/Dock.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class Dock
|
||||
{
|
||||
NONE,
|
||||
FILL
|
||||
};
|
||||
}
|
63
include/ehs/EHS.h
Normal file
63
include/ehs/EHS.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(NDEBUG)
|
||||
#define EHS_RELEASE
|
||||
#else
|
||||
#define EHS_DEBUG
|
||||
#endif
|
||||
|
||||
#include "Types.h"
|
||||
#include "ehs/system/OS.h"
|
||||
#include "Version.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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 ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer);
|
63
include/ehs/GarbageCollector.h
Normal file
63
include/ehs/GarbageCollector.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Vector.h"
|
||||
#include "BaseObj.h"
|
||||
#include "ehs/system/Mutex.h"
|
||||
#include "ehs/system/Thread.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
typedef bool (*GcLogic)(BaseObj*);
|
||||
|
||||
class GarbageCollector
|
||||
{
|
||||
private:
|
||||
static Vector<GcLogic>* logic;
|
||||
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/ehs/HRNG.h
Normal file
59
include/ehs/HRNG.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Types.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/HashMap.h
Normal file
146
include/ehs/HashMap.h
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
70
include/ehs/Link.h
Normal file
70
include/ehs/Link.h
Normal file
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
/// 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/ehs/LinkedList.h
Normal file
240
include/ehs/LinkedList.h
Normal file
@ -0,0 +1,240 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Log.h"
|
||||
#include "Link.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/Log.h
Normal file
116
include/ehs/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 ehs
|
||||
{
|
||||
/// 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 EHS_LOG_INT
|
||||
#ifdef EHS_DEBUG
|
||||
#define EHS_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), EHS_FILE, EHS_FUNC, Str_8::FromNum((UInt_32)EHS_LINE)}, code, msg})
|
||||
#else
|
||||
#define EHS_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), EHS_FUNC}, code, msg})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EHS_LOG
|
||||
#ifdef EHS_DEBUG
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise({{type, ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
|
||||
#else
|
||||
#define EHS_LOG(type, code, msg) ehs::Log::Raise({{type, ehs::GetAppName_8(), EHS_FUNC}, code, msg})
|
||||
#endif
|
||||
#endif
|
217
include/ehs/Mat2.h
Normal file
217
include/ehs/Mat2.h
Normal file
@ -0,0 +1,217 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Vec2.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/Mat3.h
Normal file
322
include/ehs/Mat3.h
Normal file
@ -0,0 +1,322 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Vec3.h"
|
||||
#include "Mat2.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/Mat4.h
Normal file
426
include/ehs/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 ehs
|
||||
{
|
||||
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/ehs/Math.h
Normal file
316
include/ehs/Math.h
Normal file
@ -0,0 +1,316 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/system/CPU.h"
|
||||
|
||||
#define EHS_LOW_WORD(x) *((int*)&x) + 1
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/PRNG.h
Normal file
60
include/ehs/PRNG.h
Normal file
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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;
|
||||
}
|
18
include/ehs/PtrData.h
Normal file
18
include/ehs/PtrData.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "DataType.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
struct PtrData
|
||||
{
|
||||
UInt_64 references;
|
||||
void* data;
|
||||
};
|
||||
|
||||
bool HasPtrData(void* data);
|
||||
|
||||
void AddPtrData(void* data);
|
||||
|
||||
bool RemovePtrData(void* data);
|
||||
}
|
396
include/ehs/Quat.h
Normal file
396
include/ehs/Quat.h
Normal file
@ -0,0 +1,396 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Math.h"
|
||||
#include "Mat4.h"
|
||||
#include "Vec3.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T>
|
||||
class Quat
|
||||
{
|
||||
public:
|
||||
T w;
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
Quat()
|
||||
: w(0), x(0), y(0), z(0)
|
||||
{
|
||||
}
|
||||
|
||||
Quat(const T w, const T x, const T y, const T z)
|
||||
: w(w), x(x), y(y), z(z)
|
||||
{
|
||||
}
|
||||
|
||||
Quat(const T yaw, const T pitch, const T roll)
|
||||
: w(0), x(0), y(0), z(0)
|
||||
{
|
||||
T c1 = cos(yaw / 2);
|
||||
T c2 = cos(pitch / 2);
|
||||
T c3 = cos(roll / 2);
|
||||
T s1 = sin(yaw / 2);
|
||||
T s2 = sin(pitch / 2);
|
||||
T s3 = sin(roll / 2);
|
||||
|
||||
w = c1 * c2 * c3 - s1 * s2 * s3;
|
||||
x = s1 * s2 * c3 + c1 * c2 * s3;
|
||||
y = s1 * c2 * c3 + c1 * s2 * s3;
|
||||
z = c1 * s2 * c3 - s1 * c2 * s3;
|
||||
}
|
||||
|
||||
explicit Quat(const Vec3<T>& euler)
|
||||
: w(0), x(0), y(0), z(0)
|
||||
{
|
||||
T c1 = cos(euler.x / 2);
|
||||
T c2 = cos(euler.y / 2);
|
||||
T c3 = cos(euler.z / 2);
|
||||
T s1 = sin(euler.x / 2);
|
||||
T s2 = sin(euler.y / 2);
|
||||
T s3 = sin(euler.z / 2);
|
||||
|
||||
w = c1 * c2 * c3 - s1 * s2 * s3;
|
||||
x = s1 * s2 * c3 + c1 * c2 * s3;
|
||||
y = s1 * c2 * c3 + c1 * s2 * s3;
|
||||
z = c1 * s2 * c3 - s1 * c2 * s3;
|
||||
}
|
||||
|
||||
Quat(const Vec3<T>& n, const T a)
|
||||
: w(cosf(a / 2)), x(n.x * sinf(a / 2)), y(n.y * sinf(a / 2)), z(n.z * sinf(a / 2))
|
||||
{
|
||||
}
|
||||
|
||||
explicit Quat(const Mat4<T>& rotMatrix)
|
||||
: w(0), x(0), y(0), z(0)
|
||||
{
|
||||
ToQuaternion(rotMatrix);
|
||||
}
|
||||
|
||||
Quat(const Quat& quat)
|
||||
: w(quat.w), x(quat.x), y(quat.y), z(quat.z)
|
||||
{
|
||||
}
|
||||
|
||||
explicit Quat(const T scalar)
|
||||
: w(scalar), x(scalar), y(scalar), z(scalar)
|
||||
{
|
||||
}
|
||||
|
||||
Quat& operator=(const Quat& quat)
|
||||
{
|
||||
if (this == &quat)
|
||||
return *this;
|
||||
|
||||
w = quat.w;
|
||||
x = quat.x;
|
||||
y = quat.y;
|
||||
z = quat.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quat& operator=(const Mat4<T>& rotMatrix)
|
||||
{
|
||||
ToQuaternion(rotMatrix);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quat operator+(const Quat& other) const
|
||||
{
|
||||
return {w + other.w, x + other.x, y + other.y, z + other.z};
|
||||
}
|
||||
|
||||
Quat operator-() const
|
||||
{
|
||||
return {-w, -x, -y, -z};
|
||||
}
|
||||
|
||||
Quat operator-(const Quat& other) const
|
||||
{
|
||||
return {w - other.w, x - other.x, y - other.y, z - other.z};
|
||||
}
|
||||
|
||||
Quat operator*(const T scalar)
|
||||
{
|
||||
return {w * scalar, x * scalar, x * scalar, x * scalar};
|
||||
}
|
||||
|
||||
Quat operator*(const Quat& other)
|
||||
{
|
||||
return Quat
|
||||
(
|
||||
w * other.w - x * other.x - y * other.y - z * other.z,
|
||||
w * other.x + x * other.w + y * other.z - z * other.y,
|
||||
w * other.y - x * other.z + y * other.w + z * other.x,
|
||||
w * other.z + x * other.y - y * other.x + z * other.w
|
||||
);
|
||||
}
|
||||
|
||||
Vec3<T> operator*(const Vec3<T>& vect)
|
||||
{
|
||||
Quat tmp(0, vect[0], vect[1], vect[2]);
|
||||
Vec3<T> tmpVect(x, y, z);
|
||||
|
||||
Vec3<T> vcV = tmpVect.CrossProduct(vect);
|
||||
return vect + vcV * (2 * w) + tmpVect.CrossProduct(vcV) * 2;
|
||||
}
|
||||
|
||||
Quat operator^(const T t)
|
||||
{
|
||||
Vec3<T> n;
|
||||
T a;
|
||||
|
||||
ToAxisAngle(&n, &a);
|
||||
|
||||
float at = a * t;
|
||||
|
||||
return Quat<T>(n, at);
|
||||
}
|
||||
|
||||
bool operator==(const Quat& quat) const
|
||||
{
|
||||
return w == quat.w && x == quat.x && y == quat.y && z == quat.z;
|
||||
}
|
||||
|
||||
bool operator!=(const Quat& quat) const
|
||||
{
|
||||
return w != quat.w || x != quat.x || y != quat.y || z == quat.z;
|
||||
}
|
||||
|
||||
T operator[](const UInt_64 index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return w;
|
||||
case 1:
|
||||
return x;
|
||||
case 2:
|
||||
return y;
|
||||
case 3:
|
||||
return z;
|
||||
default:
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
T& operator[](const UInt_64 index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return w;
|
||||
case 1:
|
||||
return x;
|
||||
case 2:
|
||||
return y;
|
||||
case 3:
|
||||
return z;
|
||||
default:
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
void ToAxisAngle(Vec3<T>* vectAxis, T* flAngle)
|
||||
{
|
||||
Vec3<T> tmp(x, y, z);
|
||||
|
||||
if (tmp.GetDis2() < 0.0001f)
|
||||
*vectAxis = Vec3<T>(1, 0, 0);
|
||||
else
|
||||
*vectAxis = tmp.GetNorm();
|
||||
|
||||
*flAngle = acosf(w) * 2;
|
||||
*flAngle = Math::Degr<T>(*flAngle);
|
||||
}
|
||||
|
||||
void ToQuaternion(const Mat4<T>& rotMatrix)
|
||||
{
|
||||
T trace = rotMatrix[0][0] + rotMatrix[1][1] + rotMatrix[2][2];
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
T s = 0.5f / Math::Sqrt<T>(trace + 1.0f);
|
||||
w = 0.25f / s;
|
||||
|
||||
x = (rotMatrix[2][1] - rotMatrix[1][2]) * s;
|
||||
y = (rotMatrix[0][2] - rotMatrix[2][0]) * s;
|
||||
z = (rotMatrix[1][0] - rotMatrix[0][1]) * s;
|
||||
} else
|
||||
{
|
||||
if ((rotMatrix[0][0] > rotMatrix[1][1]) && (rotMatrix[0][0] > rotMatrix[2][2]))
|
||||
{
|
||||
T s = 2.0f * Math::Sqrt(1.0f + rotMatrix[0][0] - rotMatrix[1][1] - rotMatrix[2][2]);
|
||||
w = (rotMatrix[2][1] - rotMatrix[1][2]) / s;
|
||||
x = 0.25f * s;
|
||||
y = (rotMatrix[0][1] + rotMatrix[1][0]) / s;
|
||||
z = (rotMatrix[0][2] + rotMatrix[2][0]) / s;
|
||||
} else if (rotMatrix[1][1] > rotMatrix[2][2])
|
||||
{
|
||||
T s = 2.0f * sqrtf(1.0f + rotMatrix[1][1] - rotMatrix[0][0] - rotMatrix[2][2]);
|
||||
w = (rotMatrix[0][2] - rotMatrix[2][0]) / s;
|
||||
x = (rotMatrix[0][1] + rotMatrix[1][0]) / s;
|
||||
y = 0.25f * s;
|
||||
z = (rotMatrix[1][2] + rotMatrix[2][1]) / s;
|
||||
} else
|
||||
{
|
||||
T s = 2.0f * sqrtf(1.0f + rotMatrix[2][2] - rotMatrix[0][0] - rotMatrix[1][1]);
|
||||
w = (rotMatrix[1][0] - rotMatrix[0][1]) / s;
|
||||
x = (rotMatrix[0][2] + rotMatrix[2][0]) / s;
|
||||
y = (rotMatrix[1][2] + rotMatrix[2][1]) / s;
|
||||
z = 0.25f * s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Vec3<T> ToEulerAngle() const
|
||||
{
|
||||
Vec3<T> euler;
|
||||
|
||||
float ysqr = y * y;
|
||||
|
||||
float t0 = 2 * (w * x + y * z);
|
||||
float t1 = 1 - 2 * (x * x + ysqr);
|
||||
euler.z = std::atan2(t0, t1);
|
||||
|
||||
float t2 = 2 * (w * y - z * x);
|
||||
t2 = t2 > 1 ? 1 : t2;
|
||||
t2 = t2 < -1 ? -1 : t2;
|
||||
euler.y = std::asin(t2);
|
||||
|
||||
float t3 = 2 * (w * z + x * y);
|
||||
float t4 = 1 - 2 * (ysqr + z * z);
|
||||
euler.x = std::atan2(t3, t4);
|
||||
|
||||
return euler;
|
||||
}
|
||||
*/
|
||||
|
||||
Mat4<T> ToMatrix() const
|
||||
{
|
||||
Mat4<T> result;
|
||||
|
||||
T x2 = x + x;
|
||||
T y2 = y + y;
|
||||
T z2 = z + z;
|
||||
T x2w = x2 * w;
|
||||
T y2w = y2 * w;
|
||||
T z2w = z2 * w;
|
||||
T x2x = x2 * x;
|
||||
T y2x = y2 * x;
|
||||
T z2x = z2 * x;
|
||||
T y2y = y2 * y;
|
||||
T z2y = z2 * y;
|
||||
T z2z = z2 * y;
|
||||
|
||||
result[0] = T(1) - (y2y + z2z);
|
||||
result[1] = y2x - z2w;
|
||||
result[2] = z2x + y2w;
|
||||
result[3] = T(0);
|
||||
|
||||
result[4] = y2x + z2w;
|
||||
result[5] = T(1) - (x2x + z2z);
|
||||
result[6] = z2y - x2w;
|
||||
result[7] = T(0);
|
||||
|
||||
result[8] = z2x - y2w;
|
||||
result[9] = z2y + x2w;
|
||||
result[10] = T(1) - (x2x + y2y);
|
||||
result[11] = T(0);
|
||||
|
||||
result[12] = T(0);
|
||||
result[13] = T(0);
|
||||
result[14] = T(0);
|
||||
result[15] = T(1);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float GetMagnitude()
|
||||
{
|
||||
return Math::Sqrt<T>(Math::Pow<T>(w, 2) + Math::Pow<T>(x, 2) + Math::Pow<T>(y, 2) + Math::Pow<T>(z, 2));
|
||||
}
|
||||
|
||||
Quat<T> GetNormalized()
|
||||
{
|
||||
T mag = GetMagnitude();
|
||||
|
||||
return Quat<T>(w / mag, x / mag, y / mag, z / mag);
|
||||
}
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
T mag = GetMagnitude();
|
||||
|
||||
w = w / mag;
|
||||
x = x / mag;
|
||||
y = y / mag;
|
||||
z = z / mag;
|
||||
}
|
||||
|
||||
T Dot(const Quat& other) const
|
||||
{
|
||||
return w * other.w + x * other.x + y * other.y + z * other.z;
|
||||
}
|
||||
|
||||
Quat<T> GetConjugate()
|
||||
{
|
||||
return Quat<T>(w, -x, -y, -z);
|
||||
}
|
||||
|
||||
void Conjugate()
|
||||
{
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
Quat<T> GetInverse()
|
||||
{
|
||||
return Quat<T>(w, -x, -y, -z);
|
||||
}
|
||||
|
||||
void Inverse()
|
||||
{
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
static Quat<T> Slerp(Quat<T> start, Quat<T> finish, const T t)
|
||||
{
|
||||
T cosHalfTheta = start.Dot(finish);
|
||||
if (Math::Abs(cosHalfTheta) >= 1.0f)
|
||||
return start;
|
||||
|
||||
float halfTheta = Math::ACos(cosHalfTheta);
|
||||
float sinHalfTheta = Math::Sqrt(1.0f - cosHalfTheta * cosHalfTheta);
|
||||
if (Math::Abs(sinHalfTheta) < 0.001f)
|
||||
{
|
||||
return {
|
||||
start.w * 0.5f + finish.w * 0.5f,
|
||||
start.x * 0.5f + finish.x * 0.5f,
|
||||
start.y * 0.5f + finish.y * 0.5f,
|
||||
start.z * 0.5f + finish.z * 0.5f
|
||||
};
|
||||
}
|
||||
|
||||
float ratioA = Math::Sin((1 - t) * halfTheta) / sinHalfTheta;
|
||||
float ratioB = Math::Sin(t * halfTheta) / sinHalfTheta;
|
||||
|
||||
return {
|
||||
start.w * ratioA + finish.w * ratioB,
|
||||
start.x * ratioA + finish.x * ratioB,
|
||||
start.y * ratioA + finish.y * ratioB,
|
||||
start.z * ratioA + finish.z * ratioB
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
typedef Quat<float> Quat_f;
|
||||
}
|
27
include/ehs/Range.h
Normal file
27
include/ehs/Range.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename N>
|
||||
class Range
|
||||
{
|
||||
public:
|
||||
N min;
|
||||
N max;
|
||||
|
||||
Range()
|
||||
: min(0), max(0)
|
||||
{
|
||||
}
|
||||
|
||||
Range(const N min, const N max)
|
||||
: min(min), max(max)
|
||||
{
|
||||
}
|
||||
|
||||
Range(const Range& range)
|
||||
: min(range.min), max(range.max)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
186
include/ehs/Rect.h
Normal file
186
include/ehs/Rect.h
Normal file
@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Vec2.h"
|
||||
#include "Vec3.h"
|
||||
#include "Vec4.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T>
|
||||
class Rect
|
||||
{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T w;
|
||||
T h;
|
||||
|
||||
Rect(const T scalar = 0)
|
||||
: x(scalar), y(scalar), w(scalar), h(scalar)
|
||||
{
|
||||
}
|
||||
|
||||
Rect(const T x, const T y, const T w, const T h)
|
||||
: x(x), y(y), w(w), h(h)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect(const Vec2<C>& vec, const T w = 0, const T h = 0)
|
||||
: x((T)vec.x), y((T)vec.y), w(w), h(h)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect(const Vec3<C>& vec, const T h = 0)
|
||||
: x((T)vec.x), y((T)vec.y), w((T)vec.z), h(h)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect(const Vec4<C>& vec)
|
||||
: x((T)vec.x), y((T)vec.y), w((T)vec.z), h((T)vec.w)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect(const Rect<C>& rect)
|
||||
: x((T)rect.x), y((T)rect.y), w((T)rect.w), h((T)rect.h)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect<T>& operator=(const Vec2<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
w = 0;
|
||||
h = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect<T>& operator=(const Vec3<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
w = (T)vec.z;
|
||||
h = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect<T>& operator=(const Vec4<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
w = (T)vec.z;
|
||||
h = (T)vec.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Rect<T>& operator=(const Rect<C>& rect)
|
||||
{
|
||||
if (this == &rect)
|
||||
return *this;
|
||||
|
||||
x = (T)rect.x;
|
||||
y = (T)rect.y;
|
||||
w = (T)rect.w;
|
||||
h = (T)rect.h;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Vec4<T>& vec)
|
||||
{
|
||||
return x == vec.x && y == vec.y && w == vec.z && h == vec.w;
|
||||
}
|
||||
|
||||
bool operator!=(const Vec4<T>& vec)
|
||||
{
|
||||
return x != vec.x || y != vec.y || w != vec.z || h != vec.w;
|
||||
}
|
||||
|
||||
bool operator==(const Rect<T>& rect)
|
||||
{
|
||||
return x == rect.x && y == rect.y && w == rect.w && h == rect.h;
|
||||
}
|
||||
|
||||
bool operator!=(const Rect<T>& rect)
|
||||
{
|
||||
return x != rect.x || y != rect.y || w != rect.w || h != rect.h;
|
||||
}
|
||||
|
||||
T operator[](const UInt_64 index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return w;
|
||||
case 3:
|
||||
return h;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
T& operator[](const UInt_64 index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return w;
|
||||
case 3:
|
||||
return h;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
operator Vec4<T>()
|
||||
{
|
||||
return Vec4<T>(x, y, w, h);
|
||||
}
|
||||
|
||||
Vec2<T> GetPos() const
|
||||
{
|
||||
return {x, y};
|
||||
}
|
||||
|
||||
Vec2<T> GetScale() const
|
||||
{
|
||||
return {w, h};
|
||||
}
|
||||
};
|
||||
|
||||
typedef Rect<UInt_64> Rect_u64;
|
||||
typedef Rect<SInt_64> Rect_s64;
|
||||
typedef Rect<Int_64> Rect_64;
|
||||
typedef Rect<UInt_32> Rect_u32;
|
||||
typedef Rect<SInt_32> Rect_s32;
|
||||
typedef Rect<Int_32> Rect_32;
|
||||
typedef Rect<UInt_16> Rect_u16;
|
||||
typedef Rect<SInt_16> Rect_s16;
|
||||
typedef Rect<Int_16> Rect_16;
|
||||
typedef Rect<UInt_8> Rect_u8;
|
||||
typedef Rect<SInt_8> Rect_s8;
|
||||
typedef Rect<Int_8> Rect_8;
|
||||
typedef Rect<float> Rect_f;
|
||||
typedef Rect<double> Rect_d;
|
||||
}
|
110
include/ehs/SArray.h
Normal file
110
include/ehs/SArray.h
Normal file
@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
/// This container is useful for sorting arrays efficiently.
|
||||
template<typename T, typename N = UInt_64>
|
||||
class SArray
|
||||
{
|
||||
private:
|
||||
T* data;
|
||||
N size;
|
||||
|
||||
public:
|
||||
~SArray()
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
SArray()
|
||||
: data(nullptr), size(0)
|
||||
{
|
||||
}
|
||||
|
||||
SArray(const N size)
|
||||
: data(new T[size]), size(size)
|
||||
{
|
||||
}
|
||||
|
||||
SArray(const SArray& sArray)
|
||||
: data(new T[sArray.size]), size(sArray.size)
|
||||
{
|
||||
for (N i = 0; i < size; ++i)
|
||||
data[i] = sArray.data[i];
|
||||
}
|
||||
|
||||
SArray(SArray&& sArray) noexcept
|
||||
: data(sArray.data), size(sArray.size)
|
||||
{
|
||||
sArray.data = nullptr;
|
||||
sArray.size = 0;
|
||||
}
|
||||
|
||||
SArray& operator=(const SArray& pArray)
|
||||
{
|
||||
if (this == &pArray)
|
||||
return *this;
|
||||
|
||||
delete[] data;
|
||||
data = new T[pArray.size];
|
||||
for (N i = 0; i < pArray.size; ++i)
|
||||
data[i] = pArray.data[i];
|
||||
|
||||
size = pArray.size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
SArray& operator=(SArray&& pArray) noexcept
|
||||
{
|
||||
if (this == &pArray)
|
||||
return *this;
|
||||
|
||||
delete[] data;
|
||||
data = pArray.data;
|
||||
size = pArray.size;
|
||||
|
||||
pArray.data = nullptr;
|
||||
pArray.size = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator const T* () const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
operator T* ()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void Insert(const N index, T value)
|
||||
{
|
||||
if (index >= size)
|
||||
{
|
||||
EHS_LOG_INT("Warning", 0, "Cannot insert value at " + Str_8::FromNum(index) + " because it is outside of array range of " + size + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
for (N i = size; i > index + 1; --i)
|
||||
data[i - 1] = std::move(data[i - 2]);
|
||||
|
||||
data[index] = std::move(value);
|
||||
}
|
||||
|
||||
void SetSize(const N newSize)
|
||||
{
|
||||
size = newSize;
|
||||
}
|
||||
|
||||
N Size() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
};
|
||||
}
|
1153
include/ehs/Serializer.h
Normal file
1153
include/ehs/Serializer.h
Normal file
File diff suppressed because it is too large
Load Diff
121
include/ehs/ShdPtr.h
Normal file
121
include/ehs/ShdPtr.h
Normal file
@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include "PtrData.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T>
|
||||
class ShdPtr
|
||||
{
|
||||
private:
|
||||
T* data;
|
||||
|
||||
public:
|
||||
~ShdPtr()
|
||||
{
|
||||
if (RemovePtrData(data))
|
||||
delete data;
|
||||
}
|
||||
|
||||
ShdPtr()
|
||||
: data(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ShdPtr(T* data)
|
||||
: data(data)
|
||||
{
|
||||
AddPtrData(data);
|
||||
}
|
||||
|
||||
ShdPtr(ShdPtr&& shdPtr) noexcept
|
||||
: data(shdPtr.data)
|
||||
{
|
||||
shdPtr.data = nullptr;
|
||||
}
|
||||
|
||||
ShdPtr(const ShdPtr& shdPtr)
|
||||
: data(shdPtr.data)
|
||||
{
|
||||
AddPtrData(data);
|
||||
}
|
||||
|
||||
ShdPtr& operator=(ShdPtr&& shdPtr) noexcept
|
||||
{
|
||||
if (this == &shdPtr)
|
||||
return *this;
|
||||
|
||||
if (RemovePtrData(data))
|
||||
delete data;
|
||||
|
||||
data = shdPtr.data;
|
||||
|
||||
shdPtr.data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ShdPtr& operator=(const ShdPtr& shdPtr) noexcept
|
||||
{
|
||||
if (this == &shdPtr)
|
||||
return *this;
|
||||
|
||||
if (RemovePtrData(data))
|
||||
delete data;
|
||||
|
||||
data = shdPtr.data;
|
||||
|
||||
AddPtrData(data);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const ShdPtr& shdPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data == shdPtr.data;
|
||||
}
|
||||
|
||||
bool operator==(T* inPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data == inPtr;
|
||||
}
|
||||
|
||||
bool operator!=(const ShdPtr& shdPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data != shdPtr.data;
|
||||
}
|
||||
|
||||
bool operator!=(T* inPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data != inPtr;
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
if (RemovePtrData(data))
|
||||
delete data;
|
||||
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
T* GetData()
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data;
|
||||
}
|
||||
};
|
||||
}
|
1875
include/ehs/Str.h
Normal file
1875
include/ehs/Str.h
Normal file
File diff suppressed because it is too large
Load Diff
50
include/ehs/Task.h
Normal file
50
include/ehs/Task.h
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "BaseObj.h"
|
||||
#include "ehs/system/Thread.h"
|
||||
#include "ehs/system/Semaphore.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
typedef void (*TaskCb)(Serializer<UInt_64>*);
|
||||
|
||||
class Task
|
||||
{
|
||||
private:
|
||||
bool working;
|
||||
Semaphore* available;
|
||||
Semaphore* done;
|
||||
Serializer<UInt_64>** cbArgs;
|
||||
TaskCb* callback;
|
||||
Serializer<UInt_64>* threadArgs;
|
||||
Thread thread;
|
||||
|
||||
public:
|
||||
~Task();
|
||||
|
||||
Task();
|
||||
|
||||
Task(Task&& task) noexcept;
|
||||
|
||||
Task(const Task& task);
|
||||
|
||||
Task& operator=(Task&& task) noexcept;
|
||||
|
||||
Task& operator=(const Task& task);
|
||||
|
||||
void Revalidate();
|
||||
|
||||
void Initialize();
|
||||
|
||||
void Release();
|
||||
|
||||
bool IsWorking() const;
|
||||
|
||||
void GiveWork(Serializer<UInt_64> args, TaskCb cb);
|
||||
|
||||
void WaitUntilDone();
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
}
|
55
include/ehs/Type.h
Normal file
55
include/ehs/Type.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "Util.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Type
|
||||
{
|
||||
private:
|
||||
friend class BaseObj;
|
||||
|
||||
UInt_64 size;
|
||||
const Char_8* id;
|
||||
UInt_64 hashId;
|
||||
|
||||
public:
|
||||
Type();
|
||||
|
||||
explicit Type(const Char_8* id);
|
||||
|
||||
Type(Type&& type) noexcept;
|
||||
|
||||
Type(const Type& type);
|
||||
|
||||
Type& operator=(Type&& type) noexcept;
|
||||
|
||||
Type& operator=(const Type& type);
|
||||
|
||||
bool operator==(const Type& type) const;
|
||||
|
||||
bool operator!=(const Type& type) const;
|
||||
|
||||
bool operator==(UInt_64 inHashId) const;
|
||||
|
||||
bool operator!=(UInt_64 inHashId) const;
|
||||
|
||||
bool operator==(const Char_8* inStr) const;
|
||||
|
||||
bool operator!=(const Char_8* inStr) const;
|
||||
|
||||
UInt_64 GetSize() const;
|
||||
|
||||
const Char_8* GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
static UInt_64 CalcSize(const Char_8* id);
|
||||
|
||||
static UInt_64 GenHash(const Char_8* id, UInt_64 size);
|
||||
};
|
||||
}
|
55
include/ehs/Types.h
Normal file
55
include/ehs/Types.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/system/OS.h"
|
||||
|
||||
#define EHS_MAX_PATH 0x104
|
||||
#define EHS_UINT_8_MAX 0xFF
|
||||
#define EHS_SINT_8_MAX 0x7F
|
||||
#define EHS_SINT_8_MIN 0x80
|
||||
#define EHS_UINT_16_MAX 0xFFFF
|
||||
#define EHS_SINT_16_MAX 0x7FFF
|
||||
#define EHS_SINT_16_MIN 0x8000
|
||||
#define EHS_UINT_24_MAX 0xFFFFFF
|
||||
#define EHS_SINT_24_MAX 0x7FFFFF
|
||||
#define EHS_SINT_24_MIN 0x800000
|
||||
#define EHS_UINT_32_MAX 0xFFFFFFFF
|
||||
#define EHS_SINT_32_MAX 0x7FFFFFFF
|
||||
#define EHS_SINT_32_MIN 0x80000000
|
||||
#define EHS_UINT_64_MAX 0xFFFFFFFFFFFFFFFF
|
||||
#define EHS_SINT_64_MAX 0x7FFFFFFFFFFFFFFF
|
||||
#define EHS_SINT_64_MIN 0x8000000000000000
|
||||
#define EHS_FLOAT_MAX 3.40282e+038f
|
||||
#define EHS_FLOAT_MIN 1.17549e-038f
|
||||
#define EHS_DOUBLE_MAX 1.79769e+308
|
||||
#define EHS_DOUBLE_MIN 2.22507e-308
|
||||
#define EHS_LDOUBLE_MAX 1.79769e+308
|
||||
#define EHS_LDOUBLE_MIN 2.22507e-308
|
||||
|
||||
#define EHS_INFINITE EHS_UINT_32_MAX
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
typedef unsigned char Byte;
|
||||
typedef char Char_8;
|
||||
typedef wchar_t Char_16;
|
||||
typedef char32_t Char_32;
|
||||
typedef unsigned char UInt_8;
|
||||
typedef signed char SInt_8;
|
||||
typedef char Int_8;
|
||||
typedef unsigned short UInt_16;
|
||||
typedef signed short SInt_16;
|
||||
typedef short Int_16;
|
||||
typedef unsigned int UInt_32;
|
||||
typedef signed int SInt_32;
|
||||
typedef int Int_32;
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
typedef unsigned long long UInt_64;
|
||||
typedef signed long long SInt_64;
|
||||
typedef long long Int_64;
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
typedef unsigned long UInt_64;
|
||||
typedef signed long SInt_64;
|
||||
typedef long Int_64;
|
||||
#endif
|
||||
}
|
15
include/ehs/URI.h
Normal file
15
include/ehs/URI.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class URI
|
||||
{
|
||||
public:
|
||||
static Str_8 Encode(const Str_8& in);
|
||||
|
||||
static Str_8 Decode(const Str_8& in);
|
||||
};
|
||||
}
|
455
include/ehs/UTF.h
Normal file
455
include/ehs/UTF.h
Normal file
@ -0,0 +1,455 @@
|
||||
#pragma once
|
||||
|
||||
#include "EHS.h"
|
||||
#include "Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class CharEncoding
|
||||
{
|
||||
UTF_32,
|
||||
UTF_16,
|
||||
UTF_8
|
||||
};
|
||||
|
||||
/// A helper class for converting between UTF8, 16 and 32.
|
||||
class UTF
|
||||
{
|
||||
public:
|
||||
/// Converts the given UTF16 C-style string into UTF32.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given C-style UTF16 string.
|
||||
/// @param [in] size The size of the given C-style UTF16 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_32, N> To_32(const Char_16* const from, const N size = 0)
|
||||
{
|
||||
Str<Char_32, N> result((size) ? size : Str<Char_16, N>::Len(from));
|
||||
|
||||
N index = 0;
|
||||
|
||||
for (N i = 0; i < result.Size(); ++i)
|
||||
{
|
||||
if (i != result.Size() - 1)
|
||||
{
|
||||
if ((from[i] & 0xDC00) == 0xDC00 && (from[i + 1] & 0xD800) == 0xD800)
|
||||
{
|
||||
result[index++] = (((from[i] - 0xD800) * 0x400) | (from[i] - 0xDC00)) + 0x10000;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
result[index++] = (Char_32)from[i];
|
||||
}
|
||||
|
||||
result.Resize(index);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Converts the given UTF16 string object into UTF32.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF16 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_32, N> To_32(const Str<Char_16, N>& from)
|
||||
{
|
||||
Str<Char_32, N> result(from.Size());
|
||||
|
||||
N index = 0;
|
||||
|
||||
for (N i = 0; i < from.Size(); ++i)
|
||||
{
|
||||
if (i != from.Size() - 1)
|
||||
{
|
||||
if ((from[i] & 0xDC00) == 0xDC00 && (from[i + 1] & 0xD800) == 0xD800)
|
||||
{
|
||||
result[index++] = (((from[i] - 0xD800) * 0x400) | (from[i] - 0xDC00)) + 0x10000;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
result[index++] = (Char_32)from[i];
|
||||
}
|
||||
|
||||
result.Resize(index);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Converts the given UTF8 C-style string into UTF32.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given C-style UTF8 string.
|
||||
/// @param [in] size The size of the given C-style UTF8 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_32, N> To_32(const Char_8* from, const N size = 0)
|
||||
{
|
||||
N rSize = size ? size : Str<Char_8, N>::Len(from);
|
||||
|
||||
Str<Char_32, N> r(rSize);
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < rSize; ++i)
|
||||
{
|
||||
if (from[i] <= 0b11110111 && i + 3 < rSize && from[i + 1] <= 0b10111111 && from[i + 2] <= 0b10111111 && from[i + 3] <= 0b10111111)
|
||||
r[c++] = (Char_32)(from[i++] & 0b00000111) << 18 | (Char_32)(from[i++] & 0b00111111) << 12 | (Char_32)(from[i++] & 0b00111111) << 6 | (Char_32)(from[i] & 0b00111111);
|
||||
else if (from[i] <= 0b11101111 && i + 2 < rSize && from[i + 1] <= 0b10111111 && from[i + 2] <= 0b10111111)
|
||||
r[c++] = (Char_32)(from[i++] & 0b00001111) << 12 | (Char_32)(from[i++] & 0b00111111) << 6 | ((Char_32)from[i] & 0b00111111);
|
||||
else if (from[i] <= 0b11011111 && i + 1 < rSize && from[i + 1] <= 0b10111111)
|
||||
r[c++] = (Char_32)(from[i++] & 0b00011111) << 6 | (Char_32)(from[i] & 0b00111111);
|
||||
else
|
||||
r[c++] = (Char_32)from[i];
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Converts the given UTF8 string object into UTF32.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF8 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_32, N> To_32(const Str<Char_8, N>& from)
|
||||
{
|
||||
Str<Char_32, N> r(from.Size());
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < from.Size(); ++i)
|
||||
{
|
||||
if (from[i] <= 0b11110111 && i + 3 < from.Size() && from[i + 1] <= 0b10111111 && from[i + 2] <= 0b10111111 && from[i + 3] <= 0b10111111)
|
||||
r[c++] = (Char_32)(from[i++] & 0b00000111) << 18 | (Char_32)(from[i++] & 0b00111111) << 12 | (Char_32)(from[i++] & 0b00111111) << 6 | (Char_32)(from[i] & 0b00111111);
|
||||
else if (from[i] <= 0b11101111 && i + 2 < from.Size() && from[i + 1] <= 0b10111111 && from[i + 2] <= 0b10111111)
|
||||
r[c++] = (Char_32)(from[i++] & 0b00001111) << 12 | (Char_32)(from[i++] & 0b00111111) << 6 | ((Char_32)from[i] & 0b00111111);
|
||||
else if (from[i] <= 0b11011111 && i + 1 < from.Size() && from[i + 1] <= 0b10111111)
|
||||
r[c++] = (Char_32)(from[i++] & 0b00011111) << 6 | (Char_32)(from[i] & 0b00111111);
|
||||
else
|
||||
r[c++] = (Char_32)from[i];
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Converts the given UTF32 C-style string object into UTF16.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF32 string.
|
||||
/// @param [in] size The size of the give C-style UTF32 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_16, N> To_16(const Char_32* const from, const N size = 0)
|
||||
{
|
||||
N rSize = size ? size : Str<Char_32, N>::Len(from);
|
||||
|
||||
Str<Char_16, N> result(rSize * sizeof(Char_16));
|
||||
|
||||
N index = 0;
|
||||
|
||||
for (N i = 0; i < rSize; ++i)
|
||||
{
|
||||
if (from[i] <= 0xFFFF)
|
||||
{
|
||||
result[index++] = (Char_16)from[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
Char_32 t = from[i] - 0x10000;
|
||||
|
||||
result[index++] |= (t >> 10) + 0xD800;
|
||||
result[index++] |= t + 0xDC00;
|
||||
}
|
||||
}
|
||||
|
||||
result.Resize(index);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Converts the given UTF32 string object into UTF16.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF32 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_16, N> To_16(const Str<Char_32, N>& from)
|
||||
{
|
||||
Str<Char_16, N> result(from.Size() * sizeof(Char_16));
|
||||
|
||||
N index = 0;
|
||||
|
||||
for (N i = 0; i < from.Size(); ++i)
|
||||
{
|
||||
if (from[i] <= 0xFFFF)
|
||||
{
|
||||
result[index++] = (Char_16)from[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
Char_32 t = from[i] - 0x10000;
|
||||
|
||||
result[index++] |= (t >> 10) + 0xD800;
|
||||
result[index++] |= t + 0xDC00;
|
||||
}
|
||||
}
|
||||
|
||||
result.Resize(index);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Converts the given UTF8 C-style string into UTF16.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF8 C-style string.
|
||||
/// @param [in] size The size of the given C-style UTF8 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_16, N> To_16(const Char_8* const from, const N size = 0)
|
||||
{
|
||||
N rSize = size ? size : Str<Char_8, N>::Len(from);
|
||||
|
||||
const Byte* const data = (const Byte* const)from;
|
||||
|
||||
Str<Char_16, N> r(rSize);
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < rSize; ++i)
|
||||
{
|
||||
if (data[i] >= 0b11110000 && i + 3 < rSize && data[i + 1] <= 0b10111111 && data[i + 2] <= 0b10111111 && data[i + 3] <= 0b10111111)
|
||||
r[c++] = (0b00000011111111110000001111111111 &
|
||||
((Char_16)(data[i++] & 0b00000111) << 23) |
|
||||
((Char_16)(data[i++] & 0b00111111) << 18) |
|
||||
((Char_16)(data[i++] & 0b00111111) << 12) |
|
||||
((Char_16)(data[i++] & 0b00111111) << 6) |
|
||||
(Char_16)(data[i] & 0b00111111)) |
|
||||
0b11011000000000001101110000000000;
|
||||
else if (data[i] >= 0b11100000 && i + 2 < rSize && data[i + 1] <= 0b10111111 && data[i + 2] <= 0b10111111)
|
||||
r[c++] = ((Char_16)(data[i++] & 0b00001111) << 12) | ((Char_16)(data[i++] & 0b00111111) << 6) | (Char_16)(data[i] & 0b00111111);
|
||||
else if (data[i] >= 0b11000000 && i + 1 < rSize && data[i + 1] <= 0b10111111)
|
||||
r[c++] = (Char_16)(data[i++] & 0b00011111) << 6 | (Char_16 )(data[i] & 0b00111111);
|
||||
else
|
||||
r[c++] = (Char_16 )data[i];
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Converts the given UTF8 string object into UTF16.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF8 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_16, N> To_16(const Str<Char_8, N>& from)
|
||||
{
|
||||
const Byte* const data = from.ToBytes();
|
||||
|
||||
Str<Char_16, N> r(from.Size());
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < from.Size(); ++i)
|
||||
{
|
||||
if (data[i] >= 0b11110000 && i + 3 < from.Size() && data[i + 1] <= 0b10111111 && data[i + 2] <= 0b10111111 && data[i + 3] <= 0b10111111)
|
||||
r[c++] = (0b00000011111111110000001111111111 &
|
||||
((Char_16)(data[i++] & 0b00000111) << 23) |
|
||||
((Char_16)(data[i++] & 0b00111111) << 18) |
|
||||
((Char_16)(data[i++] & 0b00111111) << 12) |
|
||||
((Char_16)(data[i++] & 0b00111111) << 6) |
|
||||
(Char_16)(data[i] & 0b00111111)) |
|
||||
0b11011000000000001101110000000000;
|
||||
else if (data[i] >= 0b11100000 && i + 2 < from.Size() && data[i + 1] <= 0b10111111 && data[i + 2] <= 0b10111111)
|
||||
r[c++] = ((Char_16)(data[i++] & 0b00001111) << 12) | ((Char_16)(data[i++] & 0b00111111) << 6) | (Char_16)(data[i] & 0b00111111);
|
||||
else if (data[i] >= 0b11000000 && i + 1 < from.Size() && data[i + 1] <= 0b10111111)
|
||||
r[c++] = (Char_16)(data[i++] & 0b00011111) << 6 | (Char_16 )(data[i] & 0b00111111);
|
||||
else
|
||||
r[c++] = (Char_16 )data[i];
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Converts the given UTF16 C-style string into UTF8.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF16 string.
|
||||
/// @param [in] size The size of the given C-style UTF8 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_8, N> To_8(const Char_16* const from, const N size = 0)
|
||||
{
|
||||
N rSize = size ? size : Str<Char_16, N>::Len(from);
|
||||
|
||||
Str<Char_8, N> r(rSize * sizeof(Char_16));
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < rSize; ++i)
|
||||
{
|
||||
if (from[i] & 0b1101100000000000 && i + 1 < rSize && from[i] & 0b1101110000000000)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] & 00000111 | 0b11110000;
|
||||
r[c++] = ((Byte*)&from[i])[0] >> 2 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] << 4 | (((Byte*)&from[i + 1])[1] & 0b00000011) << 2 | ((Byte*)&from[i + 1])[0] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[++i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] <= 0b11111111)
|
||||
{
|
||||
r[c++] = (Byte)from[i];
|
||||
}
|
||||
else if (from[i] > 0b11111111 && from[i] <= 0b0000011111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 | 0b11000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] > 0b0000011111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] >> 4 | 0b11100000;
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Converts the given UTF16 string object into UTF8.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF16 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_8, N> To_8(const Str<Char_16, N>& from)
|
||||
{
|
||||
Str<Char_8, N> r(from.Size(true) * sizeof(Char_16));
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < from.Size(); ++i)
|
||||
{
|
||||
if (from[i] & 0b1101100000000000 && i + 1 < from.Size() && from[i] & 0b1101110000000000)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] & 00000111 | 0b11110000;
|
||||
r[c++] = ((Byte*)&from[i])[0] >> 2 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] << 4 | (((Byte*)&from[i + 1])[1] & 0b00000011) << 2 | ((Byte*)&from[i + 1])[0] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[++i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] <= 0b11111111)
|
||||
{
|
||||
r[c++] = (Byte)from[i];
|
||||
}
|
||||
else if (from[i] > 0b11111111 && from[i] <= 0b0000011111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 | 0b11000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] > 0b0000011111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] >> 4 | 0b11100000;
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Converts the given UTF32 C-style string into UTF8.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF32 string.
|
||||
/// @param [in] size The size of the give C-style UTF32 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_8, N> To_8(const Char_32* const from, const N size = 0)
|
||||
{
|
||||
N rSize = size ? size : Str<Char_32, N>::Len(from);
|
||||
|
||||
Str<Char_8, N> r(rSize * sizeof(Char_32));
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < rSize; ++i)
|
||||
{
|
||||
if (from[i] <= 0b11111111)
|
||||
{
|
||||
r[c++] = (Char_8)from[i];
|
||||
}
|
||||
else if (from[i] > 0b11111111 && from[i] <= 0b0000011111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 | 0b11000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] > 0b0000011111111111 && from[i] <= 0b1111111111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[2] << 2 | ((Byte*)&from[i])[1] >> 6 | 0b11100000;
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] > 0b1111111111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[3] << 2 | ((Byte*)&from[i])[3] >> 2 & 0b00000111 | 0b11110000;
|
||||
r[c++] = ((Byte*)&from[i])[2] << 2 | ((Byte*)&from[i])[2] >> 6 & 0b00111111 | 0b11100000;
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[1] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Converts the given UTF32 string object into UTF8.
|
||||
/// @tparam N The number data type to use.
|
||||
/// @param [in] from The given UTF32 string.
|
||||
/// @returns The result.
|
||||
template<typename N = UInt_64>
|
||||
static Str<Char_8, N> To_8(const Str<Char_32, N>& from)
|
||||
{
|
||||
Str<Char_8, N> r(from.Size() * sizeof(Char_32));
|
||||
|
||||
N c = 0;
|
||||
|
||||
for (N i = 0; i < from.Size(); ++i)
|
||||
{
|
||||
if (from[i] <= 0b11111111)
|
||||
{
|
||||
r[c++] = (Char_8)from[i];
|
||||
}
|
||||
else if (from[i] > 0b11111111 && from[i] <= 0b0000011111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 | 0b11000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] > 0b0000011111111111 && from[i] <= 0b1111111111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[2] << 2 | ((Byte*)&from[i])[1] >> 6 | 0b11100000;
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[0] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
else if (from[i] > 0b1111111111111111)
|
||||
{
|
||||
r[c++] = ((Byte*)&from[i])[3] << 2 | ((Byte*)&from[i])[3] >> 2 & 0b00000111 | 0b11110000;
|
||||
r[c++] = ((Byte*)&from[i])[2] << 2 | ((Byte*)&from[i])[2] >> 6 & 0b00111111 | 0b11100000;
|
||||
r[c++] = ((Byte*)&from[i])[1] << 2 | ((Byte*)&from[i])[1] >> 6 & 0b00111111 | 0b10000000;
|
||||
r[c++] = ((Byte*)&from[i])[0] & 0b00111111 | 0b10000000;
|
||||
}
|
||||
}
|
||||
|
||||
r.Resize(c);
|
||||
|
||||
return r;
|
||||
}
|
||||
};
|
||||
}
|
85
include/ehs/UniPtr.h
Normal file
85
include/ehs/UniPtr.h
Normal file
@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T>
|
||||
class UniPtr
|
||||
{
|
||||
private:
|
||||
T* data;
|
||||
|
||||
public:
|
||||
~UniPtr()
|
||||
{
|
||||
delete data;
|
||||
}
|
||||
|
||||
UniPtr()
|
||||
: data(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
UniPtr(T* data)
|
||||
: data(data)
|
||||
{
|
||||
}
|
||||
|
||||
UniPtr(UniPtr&& uniPtr) noexcept
|
||||
: data(uniPtr.data)
|
||||
{
|
||||
uniPtr.data = nullptr;
|
||||
}
|
||||
|
||||
UniPtr(const UniPtr& uniPtr)
|
||||
: data(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
UniPtr& operator=(UniPtr&& uniPtr) noexcept
|
||||
{
|
||||
if (this == &uniPtr)
|
||||
return *this;
|
||||
|
||||
delete data;
|
||||
|
||||
data = uniPtr.data;
|
||||
|
||||
uniPtr.data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
UniPtr& operator=(const UniPtr& uniPtr) noexcept
|
||||
{
|
||||
if (this == &uniPtr)
|
||||
return *this;
|
||||
|
||||
delete data;
|
||||
|
||||
data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(T* inPtr) const
|
||||
{
|
||||
return data == inPtr;
|
||||
}
|
||||
|
||||
bool operator!=(T* inPtr) const
|
||||
{
|
||||
return data != inPtr;
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
delete data;
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
T* GetData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
};
|
||||
}
|
18
include/ehs/Util.h
Normal file
18
include/ehs/Util.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Util
|
||||
{
|
||||
public:
|
||||
static bool Compare(const void* a, const void* b, UInt_64 size);
|
||||
|
||||
static void Copy(void* out, const void* in, UInt_64 size);
|
||||
|
||||
static void Fill(void* out, UInt_64 outSize, const void* in, UInt_64 inSize);
|
||||
|
||||
static void Zero(void* in, UInt_64 size);
|
||||
};
|
||||
}
|
386
include/ehs/Vec2.h
Normal file
386
include/ehs/Vec2.h
Normal file
@ -0,0 +1,386 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "UTF.h"
|
||||
#include "Str.h"
|
||||
#include "Math.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T = float>
|
||||
class Vec2
|
||||
{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
|
||||
Vec2(const T x, const T y)
|
||||
: x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec2(const Vec2<C>& vec)
|
||||
: x((T)vec.x), y((T)vec.y)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2(const T scalar = 0)
|
||||
: x(scalar), y(scalar)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec2<T>& operator=(const Vec2<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Vec2<T>& vec) const
|
||||
{
|
||||
return x == vec.x && y == vec.y;
|
||||
}
|
||||
|
||||
bool operator!=(const Vec2<T>& vec) const
|
||||
{
|
||||
return x != vec.x || y != vec.y;
|
||||
}
|
||||
|
||||
Vec2<T>& operator+=(const Vec2<T>& vec)
|
||||
{
|
||||
x += vec.x;
|
||||
y += vec.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator+(const Vec2<T>& vec) const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x + vec.x;
|
||||
tmp.y = y + vec.y;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec2<T>& operator+=(const T scalar)
|
||||
{
|
||||
x += scalar;
|
||||
y += scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator+(const T scalar) const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x + scalar;
|
||||
tmp.y = y + scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec2<T>& operator-=(const Vec2<T>& vec)
|
||||
{
|
||||
x -= vec.x;
|
||||
y -= vec.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator-(const Vec2<T>& vec) const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x - vec.x;
|
||||
tmp.y = y - vec.y;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec2<T>& operator-=(const T scalar)
|
||||
{
|
||||
x -= scalar;
|
||||
y -= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator-(const T scalar) const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x - scalar;
|
||||
tmp.y = y - scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec2<T>& operator/=(const Vec2<T>& vec)
|
||||
{
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator/(const Vec2<T>& vec) const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x / vec.x;
|
||||
tmp.y = y / vec.y;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec2<T>& operator/=(const T scalar)
|
||||
{
|
||||
x /= scalar;
|
||||
y /= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator/(const T scalar) const
|
||||
{
|
||||
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x / scalar;
|
||||
tmp.y = y / scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec2<T>& operator*=(const Vec2<T>& vec)
|
||||
{
|
||||
x *= vec.x;
|
||||
y *= vec.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator*(const Vec2<T>& vec) const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x * vec.x;
|
||||
tmp.y = y * vec.y;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec2<T>& operator*=(const T scalar)
|
||||
{
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator*(const T scalar) const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = x * scalar;
|
||||
tmp.y = y * scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator<=(const Vec2<T>& other) const
|
||||
{
|
||||
return x <= other.x && y <= other.y;
|
||||
}
|
||||
|
||||
bool operator<(const Vec2<T>& other) const
|
||||
{
|
||||
return x < other.x && y < other.y;
|
||||
}
|
||||
|
||||
bool operator>=(const Vec2<T>& other) const
|
||||
{
|
||||
return x >= other.x && y >= other.y;
|
||||
}
|
||||
|
||||
bool operator>(const Vec2<T>& other) const
|
||||
{
|
||||
return x > other.x && y > other.y;
|
||||
}
|
||||
|
||||
Vec2 operator-()
|
||||
{
|
||||
return {-x, -y};
|
||||
}
|
||||
|
||||
T operator[](const UInt_64 index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
T& operator[](const UInt_64 index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
Vec2<T> GetAbs() const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = Math::Abs(x);
|
||||
tmp.y = Math::Abs(y);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void Abs()
|
||||
{
|
||||
x = Math::Abs(x);
|
||||
y = Math::Abs(y);
|
||||
}
|
||||
|
||||
/// If positive, the vectors are pointing in the same direction. If negative, the vectors are pointing in opposing directions.
|
||||
/// If zero, the vectors are perpendicular.
|
||||
T GetDot(const Vec2<T>& vec) const
|
||||
{
|
||||
return x * vec.x + y * vec.y;
|
||||
}
|
||||
|
||||
T GetAngle(const Vec2<T>& vec) const
|
||||
{
|
||||
return Math::ACos(GetDot(vec) / Math::Sqrt(GetMagnitude2() * vec.GetMagnitude2()));
|
||||
}
|
||||
|
||||
Vec2<T> GetProjection(const Vec2<T>& length) const
|
||||
{
|
||||
return operator*(length.GetDot(*this) / GetMagnitude2());
|
||||
}
|
||||
|
||||
Vec2<T> GetPerpendicular(const Vec2<T>& length) const
|
||||
{
|
||||
return length - GetProjection(length);
|
||||
}
|
||||
|
||||
Vec2<T> GetReflection(const Vec2<T>& normal) const
|
||||
{
|
||||
return operator-(normal * (GetDot(normal) * 2));
|
||||
}
|
||||
|
||||
T GetMagnitude() const
|
||||
{
|
||||
return Math::Sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
T GetMagnitude2() const
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
T GetDistance(const Vec2<T>& vec) const
|
||||
{
|
||||
return Math::Sqrt(Math::Pow(vec.x - x, 2) + Math::Pow(vec.y - y, 2));
|
||||
}
|
||||
|
||||
T GetDistance2(const Vec2<T>& vec) const
|
||||
{
|
||||
return Math::Pow(vec.x - x, 2) + Math::Pow(vec.y - y, 2);
|
||||
}
|
||||
|
||||
Vec2<T> GetNorm() const
|
||||
{
|
||||
Vec2<T> norm;
|
||||
|
||||
T dis = GetMagnitude();
|
||||
|
||||
norm.x = x / dis;
|
||||
norm.y = y / dis;
|
||||
|
||||
return norm;
|
||||
}
|
||||
|
||||
void Norm()
|
||||
{
|
||||
T dis = GetMagnitude();
|
||||
|
||||
x /= dis;
|
||||
y /= dis;
|
||||
}
|
||||
|
||||
Vec2<T> GetRads() const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = Math::Rads(x);
|
||||
tmp.y = Math::Rads(y);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void ToRads()
|
||||
{
|
||||
x = Math::Rads(x);
|
||||
y = Math::Rads(y);
|
||||
}
|
||||
|
||||
Vec2<T> GetDegr() const
|
||||
{
|
||||
Vec2<T> tmp;
|
||||
|
||||
tmp.x = Math::Degr(x);
|
||||
tmp.y = Math::Degr(y);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void ToDegr()
|
||||
{
|
||||
x = Math::Degr(x);
|
||||
y = Math::Degr(y);
|
||||
}
|
||||
|
||||
static Vec2 Lerp(const Vec2& start, const Vec2& finish, const T t)
|
||||
{
|
||||
return start + (finish - start) * t;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec2<UInt_64> Vec2_u64;
|
||||
typedef Vec2<SInt_64> Vec2_s64;
|
||||
typedef Vec2<Int_64> Vec2_64;
|
||||
typedef Vec2<UInt_32> Vec2_u32;
|
||||
typedef Vec2<SInt_32> Vec2_s32;
|
||||
typedef Vec2<Int_32> Vec2_32;
|
||||
typedef Vec2<UInt_16> Vec2_u16;
|
||||
typedef Vec2<SInt_16> Vec2_s16;
|
||||
typedef Vec2<Int_16> Vec2_16;
|
||||
typedef Vec2<UInt_8> Vec2_u8;
|
||||
typedef Vec2<SInt_8> Vec2_s8;
|
||||
typedef Vec2<Int_8> Vec2_8;
|
||||
typedef Vec2<float> Vec2_f;
|
||||
typedef Vec2<double> Vec2_d;
|
||||
}
|
445
include/ehs/Vec3.h
Normal file
445
include/ehs/Vec3.h
Normal file
@ -0,0 +1,445 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "UTF.h"
|
||||
#include "Str.h"
|
||||
#include "Math.h"
|
||||
#include "Vec2.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T>
|
||||
class Vec3
|
||||
{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
Vec3(const T scalar = 0)
|
||||
: x(scalar), y(scalar), z(scalar)
|
||||
{
|
||||
}
|
||||
|
||||
Vec3(const T x, const T y, const T z)
|
||||
: x(x), y(y), z(z)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec3(const Vec2<C>& vec, const T z = 0)
|
||||
: x((T)vec.x), y((T)vec.y), z(z)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec3(const Vec3<C>& vec)
|
||||
: x((T)vec.x), y((T)vec.y), z((T)vec.z)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec3<T>& operator=(const Vec2<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
z = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec3<T>& operator=(const Vec3<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
z = (T)vec.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Vec3<T>& vec) const
|
||||
{
|
||||
return Math::ComCmp(x, vec.x) && Math::ComCmp(y, vec.y) && Math::ComCmp(z, vec.z);
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(const Vec3<T>& vec) const
|
||||
{
|
||||
return !Math::ComCmp(z, vec.z) || !Math::ComCmp(y, vec.y) || !Math::ComCmp(z, vec.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator+(const Vec3<T>& vec) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x + vec.x;
|
||||
tmp.y = y + vec.y;
|
||||
tmp.z = z + vec.z;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator+=(const Vec3<T>& vec)
|
||||
{
|
||||
x += vec.x;
|
||||
y += vec.y;
|
||||
z += vec.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator+(const T scalar) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x + scalar;
|
||||
tmp.y = y + scalar;
|
||||
tmp.z = z + scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator+=(const T scalar)
|
||||
{
|
||||
x += scalar;
|
||||
y += scalar;
|
||||
z += scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator-(const Vec3<T>& vec) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x - vec.x;
|
||||
tmp.y = y - vec.y;
|
||||
tmp.z = z - vec.z;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator-=(const Vec3<T>& vec)
|
||||
{
|
||||
x -= vec.x;
|
||||
y -= vec.y;
|
||||
z -= vec.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator-(const T scalar) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x - scalar;
|
||||
tmp.y = y - scalar;
|
||||
tmp.z = z - scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator-=(const T scalar)
|
||||
{
|
||||
x -= scalar;
|
||||
y -= scalar;
|
||||
z -= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator*(const Vec3<T>& vec) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x * vec.x;
|
||||
tmp.y = y * vec.y;
|
||||
tmp.z = z * vec.z;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator*=(const Vec3<T>& vec)
|
||||
{
|
||||
x *= vec.x;
|
||||
y *= vec.y;
|
||||
z *= vec.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator*(const T scalar) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x * scalar;
|
||||
tmp.y = y * scalar;
|
||||
tmp.z = z * scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator*=(const T scalar)
|
||||
{
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
z *= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator/(const Vec3<T>& vec) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x / vec.x;
|
||||
tmp.y = y / vec.y;
|
||||
tmp.z = z / vec.z;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator/=(const Vec3<T>& vec)
|
||||
{
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
z /= vec.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator/(const T scalar) const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = x / scalar;
|
||||
tmp.y = y / scalar;
|
||||
tmp.z = z / scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec3<T>& operator/=(const T scalar)
|
||||
{
|
||||
x /= scalar;
|
||||
y /= scalar;
|
||||
z /= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator<=(const Vec3<T>& other) const
|
||||
{
|
||||
return x <= other.x && y <= other.y && z <= other.z;
|
||||
}
|
||||
|
||||
bool operator<(const Vec3<T>& other) const
|
||||
{
|
||||
return x < other.x && y < other.y && z < other.z;
|
||||
}
|
||||
|
||||
bool operator>=(const Vec3<T>& other) const
|
||||
{
|
||||
return x >= other.x && y >= other.y && z >= other.z;
|
||||
}
|
||||
|
||||
bool operator>(const Vec3<T>& other) const
|
||||
{
|
||||
return x > other.x && y > other.y && z > other.z;
|
||||
}
|
||||
|
||||
Vec3 operator-()
|
||||
{
|
||||
return {-x, -y, -z};
|
||||
}
|
||||
|
||||
T operator[](const UInt_64 index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
T& operator[](const UInt_64 index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 3.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
operator Vec2<T>()
|
||||
{
|
||||
return Vec2<T>(x, y);
|
||||
}
|
||||
|
||||
Vec3<T> GetAbs() const
|
||||
{
|
||||
Vec3<T> absolute;
|
||||
|
||||
absolute.x = Math::Abs(x);
|
||||
absolute.y = Math::Abs(y);
|
||||
absolute.z = Math::Abs(z);
|
||||
|
||||
return absolute;
|
||||
}
|
||||
|
||||
void Abs()
|
||||
{
|
||||
x = Math::Abs(x);
|
||||
y = Math::Abs(y);
|
||||
z = Math::Abs(z);
|
||||
}
|
||||
|
||||
Vec3<T> GetNorm() const
|
||||
{
|
||||
Vec3<T> norm;
|
||||
|
||||
T dis = GetMagnitude();
|
||||
|
||||
norm.x = x / dis;
|
||||
norm.y = y / dis;
|
||||
norm.z = z / dis;
|
||||
|
||||
return norm;
|
||||
}
|
||||
|
||||
void Norm()
|
||||
{
|
||||
T dis = GetMagnitude();
|
||||
|
||||
x /= dis;
|
||||
y /= dis;
|
||||
z /= dis;
|
||||
}
|
||||
|
||||
Vec3<T> GetCross(const Vec3<T>& vec) const
|
||||
{
|
||||
return Vec3<T>(
|
||||
y * vec.z - z * vec.y,
|
||||
z * vec.x - x * vec.z,
|
||||
x * vec.y - y * vec.x
|
||||
);
|
||||
}
|
||||
|
||||
T GetDot(const Vec3<T>& vec) const
|
||||
{
|
||||
return x * vec.x + y * vec.y + z * vec.z;
|
||||
}
|
||||
|
||||
T GetAngle(const Vec2<T>& vec) const
|
||||
{
|
||||
return Math::ACos(GetDot(vec) / Math::Sqrt(GetMagnitude2() * vec.GetMagnitude2()));
|
||||
}
|
||||
|
||||
Vec2<T> GetProjection(const Vec2<T>& length) const
|
||||
{
|
||||
return operator*(length.GetDot(*this) / GetMagnitude2());
|
||||
}
|
||||
|
||||
Vec2<T> GetPerpendicular(const Vec2<T>& length) const
|
||||
{
|
||||
return length - GetProjection(length);
|
||||
}
|
||||
|
||||
Vec2<T> GetReflection(const Vec2<T>& normal) const
|
||||
{
|
||||
return operator-(normal * (GetDot(normal) * 2));
|
||||
}
|
||||
|
||||
T GetMagnitude() const
|
||||
{
|
||||
return Math::Sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
T GetMagnitude2() const
|
||||
{
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
T GetDistance(const Vec3<T>& vec) const
|
||||
{
|
||||
return (T)Math::Sqrt(Math::Pow<T>(vec.x - x, 2) + Math::Pow<T>(vec.y - y, 2) + Math::Pow<T>(vec.z - z, 2));
|
||||
}
|
||||
|
||||
T GetDistance2(const Vec3<T>& vec) const
|
||||
{
|
||||
return static_cast<T>(Math::Pow<T>(vec.x - x, 2) + Math::Pow<T>(vec.y - y, 2) + Math::Pow<T>(vec.z - z, 2));
|
||||
}
|
||||
|
||||
Vec3<T> GetRads() const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = Math::Rads(x);
|
||||
tmp.y = Math::Rads(y);
|
||||
tmp.z = Math::Rads(z);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void ToRads()
|
||||
{
|
||||
x = Math::Rads(x);
|
||||
y = Math::Rads(y);
|
||||
z = Math::Rads(z);
|
||||
}
|
||||
|
||||
Vec3<T> GetDegr() const
|
||||
{
|
||||
Vec3<T> tmp;
|
||||
|
||||
tmp.x = Math::Degr(x);
|
||||
tmp.y = Math::Degr(y);
|
||||
tmp.z = Math::Degr(z);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void ToDegr()
|
||||
{
|
||||
x = Math::Degr(x);
|
||||
y = Math::Degr(y);
|
||||
z = Math::Degr(z);
|
||||
}
|
||||
|
||||
static Vec3 Lerp(const Vec3& start, const Vec3& finish, const T t)
|
||||
{
|
||||
return start + (finish - start) * t;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec3<UInt_64> Vec3_u64;
|
||||
typedef Vec3<SInt_64> Vec3_s64;
|
||||
typedef Vec3<Int_64> Vec3_64;
|
||||
typedef Vec3<UInt_32> Vec3_u32;
|
||||
typedef Vec3<SInt_32> Vec3_s32;
|
||||
typedef Vec3<Int_32> Vec3_32;
|
||||
typedef Vec3<UInt_16> Vec3_u16;
|
||||
typedef Vec3<SInt_16> Vec3_s16;
|
||||
typedef Vec3<Int_16> Vec3_16;
|
||||
typedef Vec3<UInt_8> Vec3_u8;
|
||||
typedef Vec3<SInt_8> Vec3_s8;
|
||||
typedef Vec3<Int_8> Vec3_8;
|
||||
typedef Vec3<float> Vec3_f;
|
||||
typedef Vec3<double> Vec3_d;
|
||||
}
|
345
include/ehs/Vec4.h
Normal file
345
include/ehs/Vec4.h
Normal file
@ -0,0 +1,345 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "UTF.h"
|
||||
#include "Str.h"
|
||||
#include "Math.h"
|
||||
#include "Vec2.h"
|
||||
#include "Vec3.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T>
|
||||
class Vec4
|
||||
{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T w;
|
||||
|
||||
Vec4(const T scalar = 0)
|
||||
: x(scalar), y(scalar), z(scalar), w(scalar)
|
||||
{
|
||||
}
|
||||
|
||||
Vec4(const T x, const T y, const T z, const T w)
|
||||
: x(x), y(y), z(z), w(w)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec4(const Vec2<C>& vec, const T z = 0, const T w = 0)
|
||||
: x((T)vec.x), y((T)vec.y), z(z), w(w)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec4(const Vec3<C>& vec, const T w = 1)
|
||||
: x((T)vec.x), y((T)vec.y), z((T)vec.z), w(w)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec4(const Vec4<C>& vec)
|
||||
: x((T)vec.x), y((T)vec.y), z((T)vec.z), w((T)vec.w)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec4<T>& operator=(const Vec2<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
z = (T)0;
|
||||
w = (T)0;
|
||||
|
||||
return*this;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec4<T>& operator=(const Vec3<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
z = (T)vec.z;
|
||||
w = (T)0;
|
||||
|
||||
return*this;
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
Vec4<T>& operator=(const Vec4<C>& vec)
|
||||
{
|
||||
x = (T)vec.x;
|
||||
y = (T)vec.y;
|
||||
z = (T)vec.z;
|
||||
w = (T)vec.w;
|
||||
|
||||
return*this;
|
||||
}
|
||||
|
||||
bool operator==(const Vec4<T>& vec)
|
||||
{
|
||||
return Math::ComCmp(x, vec.x) && Math::ComCmp(y, vec.y) && Math::ComCmp(z, vec.z) && Math::ComCmp(w, vec.w);
|
||||
}
|
||||
|
||||
bool operator!=(const Vec4<T>& vec)
|
||||
{
|
||||
return !Math::ComCmp(z, vec.z) || !Math::ComCmp(y, vec.y) || !Math::ComCmp(z, vec.z) || !Math::ComCmp(w, vec.w);
|
||||
}
|
||||
|
||||
Vec4<T>& operator+=(const Vec4<T>& vec)
|
||||
{
|
||||
x += vec.x;
|
||||
y += vec.y;
|
||||
z += vec.z;
|
||||
w += vec.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator+(const Vec4<T>& vec)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x + vec.x;
|
||||
tmp.y = y + vec.y;
|
||||
tmp.z = z + vec.z;
|
||||
tmp.w = w + vec.w;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec4<T>& operator+=(const T scalar)
|
||||
{
|
||||
x += scalar;
|
||||
y += scalar;
|
||||
z += scalar;
|
||||
w += scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator+(const T scalar)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x + scalar;
|
||||
tmp.y = y + scalar;
|
||||
tmp.z = z + scalar;
|
||||
tmp.w = w + scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec4<T>& operator-=(const Vec4<T>& vec)
|
||||
{
|
||||
x -= vec.x;
|
||||
y -= vec.y;
|
||||
z -= vec.z;
|
||||
w -= vec.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator-(const Vec4<T>& vec)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x - vec.x;
|
||||
tmp.y = y - vec.y;
|
||||
tmp.z = z - vec.z;
|
||||
tmp.w = w - vec.w;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec4<T>& operator-=(const T scalar)
|
||||
{
|
||||
x -= scalar;
|
||||
y -= scalar;
|
||||
z -= scalar;
|
||||
w -= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator-(const T scalar)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x - scalar;
|
||||
tmp.y = y - scalar;
|
||||
tmp.z = z - scalar;
|
||||
tmp.w = w - scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec4<T>& operator*=(const Vec4<T>& vec)
|
||||
{
|
||||
x *= vec.x;
|
||||
y *= vec.y;
|
||||
z *= vec.z;
|
||||
w *= vec.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator*(const Vec4<T>& vec)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x * vec.x;
|
||||
tmp.y = y * vec.y;
|
||||
tmp.z = z * vec.z;
|
||||
tmp.w = w * vec.w;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec4<T>& operator*=(const T scalar)
|
||||
{
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
z *= scalar;
|
||||
w *= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator*(const T scalar)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x * scalar;
|
||||
tmp.y = y * scalar;
|
||||
tmp.z = z * scalar;
|
||||
tmp.w = w * scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec4<T>& operator/=(const Vec4<T>& vec)
|
||||
{
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
z /= vec.z;
|
||||
w /= vec.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator/(const Vec4<T>& vec)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x / vec.x;
|
||||
tmp.y = y / vec.y;
|
||||
tmp.z = z / vec.z;
|
||||
tmp.w = w / vec.w;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Vec4<T>& operator/=(const T scalar)
|
||||
{
|
||||
x /= scalar;
|
||||
y /= scalar;
|
||||
z /= scalar;
|
||||
w /= scalar;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator/(const T scalar)
|
||||
{
|
||||
Vec4<T> tmp;
|
||||
|
||||
tmp.x = x / scalar;
|
||||
tmp.y = y / scalar;
|
||||
tmp.z = z / scalar;
|
||||
tmp.w = w / scalar;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
T operator[](const UInt_64 index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
case 3:
|
||||
return w;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
T& operator[](const UInt_64 index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
case 3:
|
||||
return w;
|
||||
default:
|
||||
EHS_LOG_INT("Error", 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Vector 4.");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
operator Vec3<T>()
|
||||
{
|
||||
return Vec3<T>(x, y, z);
|
||||
}
|
||||
|
||||
operator Vec2<T>()
|
||||
{
|
||||
return Vec2<T>(x, y);
|
||||
}
|
||||
|
||||
T GetDotProduct(const Vec4<T>& vec) const
|
||||
{
|
||||
return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
|
||||
}
|
||||
|
||||
T GetMagnitude() const
|
||||
{
|
||||
return Math::Sqrt(x * x + y * y + z * z + w * w);
|
||||
}
|
||||
|
||||
T GetMagnitude2() const
|
||||
{
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec4<UInt_64> Vec4_u64;
|
||||
typedef Vec4<SInt_64> Vec4_s64;
|
||||
typedef Vec4<Int_64> Vec4_64;
|
||||
typedef Vec4<UInt_32> Vec4_u32;
|
||||
typedef Vec4<SInt_32> Vec4_s32;
|
||||
typedef Vec4<Int_32> Vec4_32;
|
||||
typedef Vec4<UInt_16> Vec4_u16;
|
||||
typedef Vec4<SInt_16> Vec4_s16;
|
||||
typedef Vec4<Int_16> Vec4_16;
|
||||
typedef Vec4<UInt_8> Vec4_u8;
|
||||
typedef Vec4<SInt_8> Vec4_s8;
|
||||
typedef Vec4<Int_8> Vec4_8;
|
||||
typedef Vec4<float> Vec4_f;
|
||||
typedef Vec4<double> Vec4_d;
|
||||
}
|
637
include/ehs/Vector.h
Normal file
637
include/ehs/Vector.h
Normal file
@ -0,0 +1,637 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseObj.h"
|
||||
#include "Types.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
/// An array with extra memory pre-allocated for fast pushes.
|
||||
/// @tparam T Array data type to use.
|
||||
/// @tparam N Number data type to use.
|
||||
/// @note If extra memory is set to five then each time that memory is filled it will add five extra.
|
||||
template<typename T, typename N = UInt_64>
|
||||
class Vector : public BaseObj
|
||||
{
|
||||
protected:
|
||||
N rawSize;
|
||||
N size;
|
||||
N stride;
|
||||
T* data;
|
||||
|
||||
public:
|
||||
/// Frees any data created on the heap.
|
||||
~Vector() override
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
/// Default members initialization.
|
||||
Vector()
|
||||
: rawSize(0), size(0), stride(5), data(nullptr)
|
||||
{
|
||||
AddType("Vector");
|
||||
}
|
||||
|
||||
/// Initializes members for pre-allocated memory to write to later.
|
||||
/// @param [in] size The size of memory to pre-allocate.
|
||||
/// @param [in] stride The stride size of memory to pre-allocate.
|
||||
Vector(const N size, const N stride)
|
||||
: rawSize(size + stride), size(size), stride(stride), data(new T[rawSize])
|
||||
{
|
||||
AddType("Vector");
|
||||
}
|
||||
|
||||
/// Initializes this vector with an initializer list object.
|
||||
/// @param [in] list The given initializer list.
|
||||
/// @param [in] stride The extra amount of memory to allocate.
|
||||
Vector(std::initializer_list<T> list, const N stride = 5)
|
||||
: rawSize(0), size(list.size()), stride(stride), data(nullptr)
|
||||
{
|
||||
AddType("Vector");
|
||||
|
||||
if (stride)
|
||||
{
|
||||
rawSize = list.size() / stride * stride;
|
||||
if (list.size() % stride)
|
||||
rawSize += stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = list.size();
|
||||
}
|
||||
|
||||
data = new T[rawSize];
|
||||
|
||||
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.
|
||||
/// @param [in] stride The size of the extra memory allocated.
|
||||
Vector(const T* data, const N size, const N stride)
|
||||
: rawSize(0), size(size), stride(stride), data(nullptr)
|
||||
{
|
||||
AddType("Vector");
|
||||
|
||||
if (stride)
|
||||
{
|
||||
rawSize = size / stride * stride;
|
||||
if (size % stride)
|
||||
rawSize += stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = size;
|
||||
}
|
||||
|
||||
data = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
this->data[i] = data[i];
|
||||
}
|
||||
|
||||
/// Copies all members from the given vector object.
|
||||
/// @param [in] vec The vector object to copy from.
|
||||
Vector(const Vector& vec)
|
||||
: BaseObj(vec), rawSize(vec.rawSize), size(vec.size), stride(vec.stride), data(new T[rawSize])
|
||||
{
|
||||
for (N i = 0; i < size; ++i)
|
||||
data[i] = vec.data[i];
|
||||
}
|
||||
|
||||
Vector(Vector&& vec) noexcept
|
||||
: BaseObj((BaseObj&&)vec), rawSize(vec.rawSize), size(vec.size), stride(vec.stride), data(vec.data)
|
||||
{
|
||||
vec.rawSize = 0;
|
||||
vec.size = 0;
|
||||
vec.stride = 0;
|
||||
vec.data = nullptr;
|
||||
}
|
||||
|
||||
/// Copies all members from the given vector object.
|
||||
/// @param [in] vec The vector object to copy from.
|
||||
/// @returns The vector that has been assigned to.
|
||||
Vector& operator=(const Vector& vec)
|
||||
{
|
||||
if (this == &vec)
|
||||
return *this;
|
||||
|
||||
BaseObj::operator=(vec);
|
||||
|
||||
rawSize = vec.rawSize;
|
||||
size = vec.size;
|
||||
stride = vec.stride;
|
||||
|
||||
delete[] data;
|
||||
data = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
data[i] = vec.data[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector& operator=(Vector&& vec) noexcept
|
||||
{
|
||||
if (this == &vec)
|
||||
return *this;
|
||||
|
||||
BaseObj::operator=((BaseObj&&)vec);
|
||||
|
||||
rawSize = vec.rawSize;
|
||||
size = vec.size;
|
||||
stride = vec.stride;
|
||||
delete[] data;
|
||||
data = vec.data;
|
||||
|
||||
vec.rawSize = 0;
|
||||
vec.size = 0;
|
||||
vec.stride = 0;
|
||||
vec.data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Vector& in) const
|
||||
{
|
||||
if (size != in.size)
|
||||
return false;
|
||||
|
||||
return Util::Compare(data, in.data, size);
|
||||
}
|
||||
|
||||
bool operator!=(const Vector& in) const
|
||||
{
|
||||
if (size != in.size)
|
||||
return true;
|
||||
|
||||
return !Util::Compare(data, in.data, size);
|
||||
}
|
||||
|
||||
/// Adds a given initializer list at the end of the vector.
|
||||
/// @param [in] value The given initializer list to push to the end of the vector.
|
||||
Vector& operator+=(std::initializer_list<T> value)
|
||||
{
|
||||
if (size + value.size() >= rawSize)
|
||||
{
|
||||
if (stride)
|
||||
{
|
||||
rawSize = (size + value.size()) / stride * stride;
|
||||
if ((size + value.size()) % stride)
|
||||
rawSize += stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = size + value.size();
|
||||
}
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(std::move(data[i]));
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
|
||||
for (auto v = value.begin(); v != value.end(); ++v)
|
||||
data[size++] = std::move(*v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Adds a given value at the end of the vector.
|
||||
/// @param [in] value The given value to push to the end of the vector.
|
||||
Vector& operator+=(const T value)
|
||||
{
|
||||
if (size + 1 >= rawSize)
|
||||
{
|
||||
if (stride)
|
||||
rawSize = size + stride;
|
||||
else
|
||||
rawSize = size + 1;
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
|
||||
data[size++] = std::move(value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Retrieves the raw C-style array from casting an array object.
|
||||
operator T* () const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
/// Retrieves the size of the vector object including the extra memory allocated.
|
||||
/// @returns The raw size.
|
||||
N RawSize() const
|
||||
{
|
||||
return rawSize;
|
||||
}
|
||||
|
||||
/// Retrieves the size of the array not including the extra memory allocated.
|
||||
/// @returns The size.
|
||||
N Size() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
/// Retrieves the size of the extra memory allocated.
|
||||
/// @returns The extra size.
|
||||
N Stride() const
|
||||
{
|
||||
return stride;
|
||||
}
|
||||
|
||||
N End() const
|
||||
{
|
||||
return size ? size - 1 : size;
|
||||
}
|
||||
|
||||
/// Copies a vector object with offsets.
|
||||
/// @param [in] dstOffset The offset index to copy the given vector object to.
|
||||
/// @param [in] src The given vector object.
|
||||
/// @param [in] srcOffset The offset index from the given vector object to copy from.
|
||||
void Copy(const N dstOffset, Vector<T, N> src, const N srcOffset = 0)
|
||||
{
|
||||
for (N i = 0; i < src.Size() - srcOffset; ++i)
|
||||
data[i + dstOffset] = std::move(src[i + srcOffset]);
|
||||
}
|
||||
|
||||
/// Copies a C-style array with offsets.
|
||||
/// @param [in] dstOffset The offset index to copy the given C-style array to.
|
||||
/// @param [in] src The given C-style array.
|
||||
/// @param [in] size The size from the given C-style array to copy.
|
||||
void Copy(const N dstOffset, const T* src, const N inSize)
|
||||
{
|
||||
if (dstOffset + inSize > size)
|
||||
return;
|
||||
|
||||
for (N i = 0; i < inSize; ++i)
|
||||
data[i + dstOffset] = src[i];
|
||||
}
|
||||
|
||||
/// Swaps two values in the vector.
|
||||
/// @param [in] a The first index to swap with.
|
||||
/// @param [in] b The second index to swap with.
|
||||
void Swap(N a, N b)
|
||||
{
|
||||
T tmp = std::move(data[a]);
|
||||
|
||||
data[a] = std::move(data[b]);
|
||||
data[b] = std::move(tmp);
|
||||
}
|
||||
|
||||
/// Inserts a value at a specified index that is available.
|
||||
/// @param [in] index The index to insert the value at.
|
||||
/// @param [in] value The given value to insert.
|
||||
void Insert(const N index, const T value)
|
||||
{
|
||||
N newSize = 0;
|
||||
if (index > size - 1)
|
||||
newSize = size + ((index + 1) - size);
|
||||
else
|
||||
newSize = size + 1;
|
||||
|
||||
if (newSize >= rawSize)
|
||||
{
|
||||
if (stride)
|
||||
rawSize += newSize + stride;
|
||||
else
|
||||
rawSize = newSize;
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (N i = index; i < size; ++i)
|
||||
data[i + 1] = std::move(data[i]);
|
||||
|
||||
data[index] = std::move(value);
|
||||
}
|
||||
|
||||
size = newSize;
|
||||
}
|
||||
|
||||
/// Removes a value at a specified index.
|
||||
/// @param [in] index The index to remove the value at.
|
||||
/// @returns The removed data.
|
||||
T Remove(const N index)
|
||||
{
|
||||
T popped = {};
|
||||
|
||||
if (!size || index >= size)
|
||||
return popped;
|
||||
|
||||
popped = std::move(data[index]);
|
||||
|
||||
if (!stride)
|
||||
{
|
||||
rawSize = size - 1;
|
||||
T* result = new T[rawSize];
|
||||
|
||||
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;
|
||||
}
|
||||
else if (rawSize - stride && size - 1 <= rawSize - stride)
|
||||
{
|
||||
rawSize -= stride;
|
||||
T* result = new T[rawSize];
|
||||
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (N i = index + 1; i < size; ++i)
|
||||
data[i - 1] = std::move(data[i]);
|
||||
}
|
||||
|
||||
--size;
|
||||
|
||||
return popped;
|
||||
}
|
||||
|
||||
/// Adds a given C-style array at the end of the vector.
|
||||
/// @param [in] value The given C-style array to push to the end of the vector.
|
||||
/// @param [in] size The size of the given C-style array.
|
||||
void Push(const T* const value, const N size)
|
||||
{
|
||||
if (this->size + size >= rawSize)
|
||||
{
|
||||
if (stride)
|
||||
{
|
||||
rawSize = (this->size + size()) / stride * stride;
|
||||
if ((this->size + size) % stride)
|
||||
rawSize += stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = this->size + size;
|
||||
}
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
data[this->size + i] = value[i];
|
||||
|
||||
this->size += size;
|
||||
}
|
||||
|
||||
/// Adds a given vector object at the end of the vector.
|
||||
/// @param [in] value The given vector object to push to the end of the vector.
|
||||
void Push(Vector<T> value)
|
||||
{
|
||||
if (size + value.size >= rawSize)
|
||||
{
|
||||
if (stride)
|
||||
{
|
||||
rawSize = (size + value.size) / stride * stride;
|
||||
if ((size + value.size) % stride)
|
||||
rawSize += stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = size + value.size;
|
||||
}
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
|
||||
for (N i = 0; i < value.size; ++i)
|
||||
data[size + i] = std::move(value.data[i]);
|
||||
|
||||
size += value.size;
|
||||
}
|
||||
|
||||
/// Adds a given initializer at the end of the vector.
|
||||
/// @param [in] value The given initializer list to push to the end of the vector.
|
||||
void Push(std::initializer_list<T> value)
|
||||
{
|
||||
if (size + value.size() >= rawSize)
|
||||
{
|
||||
if (stride)
|
||||
{
|
||||
rawSize = (size + value.size()) / stride * stride;
|
||||
if ((size + value.size()) % stride)
|
||||
rawSize += stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = size + value.size();
|
||||
}
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
|
||||
for (auto v = value.begin(); v != value.end(); ++v)
|
||||
data[size++] = std::move(*v);
|
||||
}
|
||||
|
||||
/// Adds a given value at the end of the vector.
|
||||
/// @param [in] value The given value to push to the end of the vector.
|
||||
void Push(T value)
|
||||
{
|
||||
if (size + 1 >= rawSize)
|
||||
{
|
||||
if (stride)
|
||||
rawSize += stride;
|
||||
else
|
||||
rawSize = size + 1;
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
|
||||
data[size++] = std::move(value);
|
||||
}
|
||||
|
||||
/// Much like the stack it pops a value at the end of the vector.
|
||||
/// @returns The removed value.
|
||||
T Pop()
|
||||
{
|
||||
T popped = {};
|
||||
|
||||
if (!size)
|
||||
return popped;
|
||||
|
||||
popped = std::move(data[--size]);
|
||||
|
||||
if (!stride)
|
||||
{
|
||||
rawSize = size;
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
else if (rawSize - stride && size < rawSize - stride)
|
||||
{
|
||||
rawSize -= stride;
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
|
||||
return popped;
|
||||
}
|
||||
|
||||
/// Will swap the value at the given index with the value at the end of the vector and pops it.
|
||||
/// @param [in] index The index of the value to swap with.
|
||||
/// @returns The removed value.
|
||||
T Pop(const N index)
|
||||
{
|
||||
if (!size)
|
||||
return {};
|
||||
|
||||
N lastIndex = size - 1;
|
||||
|
||||
if (index < lastIndex)
|
||||
Swap(index, lastIndex);
|
||||
|
||||
return Pop();
|
||||
}
|
||||
|
||||
/// Resizes the vector while keeping its alignment.
|
||||
/// @param [in] newSize The size to change to.
|
||||
void Resize(const N newSize)
|
||||
{
|
||||
if (newSize == size)
|
||||
return;
|
||||
|
||||
if (stride)
|
||||
{
|
||||
rawSize = newSize / stride * stride;
|
||||
if (newSize % stride)
|
||||
rawSize += stride;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = newSize;
|
||||
}
|
||||
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size && i < newSize; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
size = newSize;
|
||||
}
|
||||
|
||||
/// Removes any extra allocated memory.
|
||||
void ExactSize()
|
||||
{
|
||||
if (!stride)
|
||||
return;
|
||||
|
||||
stride = 0;
|
||||
|
||||
if (size)
|
||||
{
|
||||
rawSize = size;
|
||||
T* result = new T[rawSize];
|
||||
|
||||
for (N i = 0; i < size; ++i)
|
||||
result[i] = std::move(data[i]);
|
||||
|
||||
delete[] data;
|
||||
data = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
rawSize = 0;
|
||||
delete[] data;
|
||||
data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears all values in the vector object.
|
||||
void Clear()
|
||||
{
|
||||
if (!size)
|
||||
return;
|
||||
|
||||
rawSize = stride;
|
||||
size = 0;
|
||||
|
||||
delete[] data;
|
||||
|
||||
if (rawSize)
|
||||
data = new T[rawSize];
|
||||
else
|
||||
data = nullptr;
|
||||
}
|
||||
};
|
||||
}
|
41
include/ehs/Version.h
Normal file
41
include/ehs/Version.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
/// A helper class for storing version major, minor and patch.
|
||||
class Version
|
||||
{
|
||||
public:
|
||||
UInt_32 major;
|
||||
UInt_32 minor;
|
||||
UInt_32 patch;
|
||||
|
||||
/// Default members initialization.
|
||||
Version();
|
||||
|
||||
/// Initializes members with given major, minor and patch.
|
||||
/// @param [in] major The major version.
|
||||
/// @param [in] minor The minor version.
|
||||
/// @param [in] patch The patch version.
|
||||
Version(const UInt_32 major, const UInt_32 minor, const UInt_32 patch);
|
||||
|
||||
/// Copies all members from the given version object.
|
||||
/// @param [in] version The version object to copy from.
|
||||
Version(const Version& version);
|
||||
|
||||
/// Copies all members from the given version object.
|
||||
/// @param [in] version The version object to copy from.
|
||||
/// @returns The version object that has been assigned to.
|
||||
Version& operator=(const Version& version);
|
||||
|
||||
bool operator==(const Version& version) const;
|
||||
|
||||
bool operator!=(const Version& version) const;
|
||||
|
||||
unsigned int operator[](const UInt_32 i) const;
|
||||
|
||||
unsigned int& operator[](const UInt_32 i);
|
||||
};
|
||||
}
|
134
include/ehs/WkPtr.h
Normal file
134
include/ehs/WkPtr.h
Normal file
@ -0,0 +1,134 @@
|
||||
#pragma once
|
||||
|
||||
#include "ShdPtr.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T>
|
||||
class WkPtr
|
||||
{
|
||||
private:
|
||||
T* data;
|
||||
|
||||
public:
|
||||
~WkPtr()
|
||||
{
|
||||
}
|
||||
|
||||
WkPtr()
|
||||
: data(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
WkPtr(T* data)
|
||||
: data(data)
|
||||
{
|
||||
}
|
||||
|
||||
WkPtr(ShdPtr<T>& shdPtr)
|
||||
: data(shdPtr.GetData())
|
||||
{
|
||||
}
|
||||
|
||||
WkPtr(WkPtr&& wkPtr) noexcept
|
||||
: data(wkPtr.data)
|
||||
{
|
||||
wkPtr.data = nullptr;
|
||||
}
|
||||
|
||||
WkPtr(const WkPtr& wkPtr)
|
||||
: data(wkPtr.data)
|
||||
{
|
||||
}
|
||||
|
||||
WkPtr& operator=(const ShdPtr<T>& shdPtr)
|
||||
{
|
||||
data = shdPtr.GetData();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
WkPtr& operator=(WkPtr&& wkPtr) noexcept
|
||||
{
|
||||
if (this == &wkPtr)
|
||||
return *this;
|
||||
|
||||
data = wkPtr.data;
|
||||
|
||||
wkPtr.data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
WkPtr& operator=(const WkPtr& wkPtr) noexcept
|
||||
{
|
||||
if (this == &wkPtr)
|
||||
return *this;
|
||||
|
||||
data = wkPtr.data;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(ShdPtr<T>& shdPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data == shdPtr.GetData();
|
||||
}
|
||||
|
||||
bool operator==(const WkPtr& wkPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data == wkPtr.data;
|
||||
}
|
||||
|
||||
bool operator==(T* inPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data == inPtr;
|
||||
}
|
||||
|
||||
bool operator!=(ShdPtr<T>& shdPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data != shdPtr.GetData();
|
||||
}
|
||||
|
||||
bool operator!=(const WkPtr& wkPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data != wkPtr.data;
|
||||
}
|
||||
|
||||
bool operator!=(T* inPtr)
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data != inPtr;
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
T* GetData()
|
||||
{
|
||||
if (!HasPtrData(data))
|
||||
data = nullptr;
|
||||
|
||||
return data;
|
||||
}
|
||||
};
|
||||
}
|
20
include/ehs/database/DVar.h
Normal file
20
include/ehs/database/DVar.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class DType : UInt_8
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class DVar : public BaseObj
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
};
|
||||
}
|
260
include/ehs/io/BaseFile.h
Normal file
260
include/ehs/io/BaseFile.h
Normal file
@ -0,0 +1,260 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class Mode
|
||||
{
|
||||
READ,
|
||||
WRITE,
|
||||
READ_WRITE
|
||||
};
|
||||
|
||||
enum class Disposition
|
||||
{
|
||||
CREATE_PERSISTENT,
|
||||
CREATE,
|
||||
OPEN_PERSISTENT,
|
||||
OPEN,
|
||||
TRUNCATE
|
||||
};
|
||||
|
||||
/// A cross-platform wrapper class that handles native file input/output.
|
||||
class BaseFile
|
||||
{
|
||||
protected:
|
||||
Str_8 path;
|
||||
Str_8 fullName;
|
||||
Str_8 name;
|
||||
Str_8 extension;
|
||||
Mode mode;
|
||||
Disposition disposition;
|
||||
|
||||
public:
|
||||
/// Frees all native handles.
|
||||
virtual ~BaseFile() = default;
|
||||
|
||||
/// Default members initialization.
|
||||
BaseFile();
|
||||
|
||||
/// Initializes members with the given data.
|
||||
/// @param [in] filePath The file path to read or write to.
|
||||
/// @param [in] mode The mode when accessing the file.
|
||||
/// @param [in] disposition How to handle the file.
|
||||
BaseFile(const Str_8& filePath, const Mode mode, const Disposition disposition);
|
||||
|
||||
BaseFile(BaseFile&& file) noexcept;
|
||||
|
||||
/// Copy constructor.
|
||||
/// @param [in] file The file object to copy from.
|
||||
BaseFile(const BaseFile& file) = default;
|
||||
|
||||
BaseFile& operator=(BaseFile&& file) noexcept;
|
||||
|
||||
/// Copy operator.
|
||||
/// @param [in] file The file object to copy from.
|
||||
BaseFile& operator=(const BaseFile& file) = default;
|
||||
|
||||
virtual operator const Byte*() const = 0;
|
||||
|
||||
virtual operator Byte*() = 0;
|
||||
|
||||
/// Uninitializes the native handle.
|
||||
/// @param [in] raiseLog Whether or not to raise a log if already uninitialized. Mostly for deconstructor.
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual bool IsMapped() const = 0;
|
||||
|
||||
virtual UInt_64 MapSize() const = 0;
|
||||
|
||||
virtual void Map(const UInt_64 offset, const UInt_64 size) = 0;
|
||||
|
||||
virtual void Unmap() = 0;
|
||||
|
||||
virtual void FlushMap() = 0;
|
||||
|
||||
/// Writes a C-style byte array to the file.
|
||||
/// @param [in] data The C-style byte array to write to the file.
|
||||
/// @param [in] size The size of the given C-style byte array.
|
||||
virtual UInt_64 Write(const Byte* const data, const UInt_64 size) = 0;
|
||||
|
||||
/// Writes a C-style string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [in] str The C-style string to write to the file.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
void WriteStr_32(const Char_32* const str, const UInt_64 size);
|
||||
|
||||
/// Writes a string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] str The string to write to the file.
|
||||
void WriteStr_32(const Str_32& str);
|
||||
|
||||
/// Writes a C-style string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [in] str The C-style string to write to the file.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
void WriteStr_16(const Char_16* const str, const UInt_64 size);
|
||||
|
||||
/// Writes a string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] str The string to write to the file.
|
||||
void WriteStr_16(const Str_16& str);
|
||||
|
||||
/// Writes a C-style string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [in] str The C-style string to write to the file.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
void WriteStr_8(const Char_8* const str, const UInt_64 size);
|
||||
|
||||
/// Writes a string to the file.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] str The string to write to the file.
|
||||
void WriteStr_8(const Str_8& str);
|
||||
|
||||
/// Writes a vector to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] vec The vector to write to the file.
|
||||
void WriteVector(const Vector<Byte, UInt_64>& vec);
|
||||
|
||||
/// Writes an array to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] arr The array to write to the file.
|
||||
void WriteArray(const Array<Byte, UInt_64>& arr);
|
||||
|
||||
/// Writes a serializer to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] ser The serializer to write to the file.
|
||||
void WriteSerializer_64(const Serializer<UInt_64>& ser);
|
||||
|
||||
/// Writes a serializer to the file.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] ser The serializer to write to the file.
|
||||
void WriteSerializer_32(const Serializer<UInt_32>& ser);
|
||||
|
||||
/// Reads data from the file as a C-style byte array.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
virtual UInt_64 Read(Byte* const buffer, const UInt_64 size) = 0;
|
||||
|
||||
/// Reads data from the file as a C-style string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
void ReadStr_32(Char_32* const buffer, UInt_64& size);
|
||||
|
||||
/// Reads data from the file as a string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting string.
|
||||
Str_32 ReadStr_32(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a C-style string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
void ReadStr_16(Char_16* const buffer, UInt_64& size);
|
||||
|
||||
/// Reads data from the file as a string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting string.
|
||||
Str_16 ReadStr_16(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a C-style string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @param [out] buffer The buffer to store the data read from the file.
|
||||
/// @param [in] size The size of the given buffer and how much data to read.
|
||||
void ReadStr_8(Char_8* const buffer, UInt_64& size);
|
||||
|
||||
/// Reads data from the file as a string.
|
||||
/// @tparam T The character data type to use.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting string.
|
||||
Str_8 ReadStr_8(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a vector.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting vector.
|
||||
Vector<Byte, UInt_64> ReadVector(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as an array.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param [in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting array.
|
||||
Array<Byte, UInt_64> ReadArray(const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a serializer.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param[in] end The Endianness of the data in the file.
|
||||
/// @param[in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting serializer.
|
||||
Serializer<UInt_64> ReadSerializer_64(const Endianness end, const UInt_64 size);
|
||||
|
||||
/// Reads data from the file as a serializer.
|
||||
/// @tparam N The data type to use for numbers.
|
||||
/// @param[in] end The Endianness of the data in the file.
|
||||
/// @param[in] size The size of the buffer and how much data to read.
|
||||
/// @returns The resulting serializer.
|
||||
Serializer<UInt_32> ReadSerializer_32(const Endianness end, const UInt_32 size);
|
||||
|
||||
virtual void Seek(UInt_64 index) = 0;
|
||||
|
||||
virtual void SeekBeginning() = 0;
|
||||
|
||||
virtual void SeekEnd() = 0;
|
||||
|
||||
virtual void Truncate(const UInt_64 size) = 0;
|
||||
|
||||
/// Retrieves the size of the file.
|
||||
/// @returns The result.
|
||||
virtual UInt_64 Size() const = 0;
|
||||
|
||||
Str_8 GetPath() const;
|
||||
|
||||
Str_8 GetFullName() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
Str_8 GetExtension() const;
|
||||
|
||||
/// Retrieves whether or not this object is valid.
|
||||
/// @returns The result.
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
static void Rename_32(const Str_32& filePath, const Str_32& newName);
|
||||
|
||||
static void Rename_16(const Str_16& filePath, const Str_16& newName);
|
||||
|
||||
static void Rename_8(const Str_8& filePath, const Str_8& newName);
|
||||
|
||||
static Str_32 ParseFullName_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ParseFullName_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ParseFullName_8(const Str_8& filePath);
|
||||
|
||||
static Str_32 ParseName_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ParseName_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ParseName_8(const Str_8& filePath);
|
||||
|
||||
static Str_32 ParseExt_32(const Str_32& filePath);
|
||||
|
||||
static Str_16 ParseExt_16(const Str_16& filePath);
|
||||
|
||||
static Str_8 ParseExt_8(const Str_8& filePath);
|
||||
};
|
||||
}
|
46
include/ehs/io/BaseFileMonitor.h
Normal file
46
include/ehs/io/BaseFileMonitor.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
|
||||
#define EHS_FE_NONE 0x00
|
||||
#define EHS_FE_MODIFIED 0x01
|
||||
#define EHS_FE_DELETED 0x02
|
||||
#define EHS_FE_MOVED 0x04
|
||||
#define EHS_FE_OPENED 0x08
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class BaseFileMonitor
|
||||
{
|
||||
protected:
|
||||
Str_8 filePath;
|
||||
|
||||
public:
|
||||
virtual ~BaseFileMonitor() = default;
|
||||
|
||||
BaseFileMonitor() = default;
|
||||
|
||||
BaseFileMonitor(Str_8 filePath);
|
||||
|
||||
BaseFileMonitor(BaseFileMonitor&& fm) noexcept;
|
||||
|
||||
BaseFileMonitor(const BaseFileMonitor& fm);
|
||||
|
||||
BaseFileMonitor& operator=(BaseFileMonitor&& fm) noexcept;
|
||||
|
||||
BaseFileMonitor& operator=(const BaseFileMonitor& fm);
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual UInt_8 Poll() = 0;
|
||||
|
||||
Str_8 GetFilePath() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
virtual bool IsInitialized() const = 0;
|
||||
};
|
||||
}
|
114
include/ehs/io/BaseWindow.h
Normal file
114
include/ehs/io/BaseWindow.h
Normal file
@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Vec2.h"
|
||||
#include "ehs/Rect.h"
|
||||
#include "ehs/io/hid/Input.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class WindowState : UInt_8
|
||||
{
|
||||
NONE,
|
||||
FULLSCREEN
|
||||
};
|
||||
|
||||
enum class CursorImg : UInt_8
|
||||
{
|
||||
DEFAULT,
|
||||
I_BEAM
|
||||
};
|
||||
|
||||
class BaseWindow
|
||||
{
|
||||
protected:
|
||||
bool created;
|
||||
bool focused;
|
||||
Vec2_s32 cursorPos;
|
||||
bool cursorVisible;
|
||||
bool cursorConstrained;
|
||||
WindowState state;
|
||||
InputHandler ih;
|
||||
|
||||
public:
|
||||
virtual ~BaseWindow() = default;
|
||||
|
||||
BaseWindow();
|
||||
|
||||
BaseWindow(const BaseWindow& win);
|
||||
|
||||
BaseWindow& operator=(const BaseWindow& win);
|
||||
|
||||
virtual void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
|
||||
|
||||
virtual void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
|
||||
|
||||
virtual void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) = 0;
|
||||
|
||||
virtual void OnCreated() = 0;
|
||||
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual void Show() = 0;
|
||||
|
||||
virtual void Hide() = 0;
|
||||
|
||||
bool IsCreated() const;
|
||||
|
||||
virtual bool Poll();
|
||||
|
||||
bool HasFocus() const;
|
||||
|
||||
void EnableResizing(const bool enable);
|
||||
|
||||
bool IsResizable() const;
|
||||
|
||||
/// Gets the cursors position on the desktop in pixels.
|
||||
/// @param [in] relative Whether the position should be relative to the windows client.
|
||||
/// @returns The current value.
|
||||
Vec2_s32 GetCursorPos() const;
|
||||
|
||||
/// Shows the cursor on the window.
|
||||
/// @param [in] toggle The new status.
|
||||
virtual void ShowCursor(bool toggle) = 0;
|
||||
|
||||
/// Checks whether the cursor is shown.
|
||||
/// @returns The current status.
|
||||
bool IsCursorVisible() const;
|
||||
|
||||
virtual void ConstrainCursor(const bool constrain) = 0;
|
||||
|
||||
bool IsCursorConstrained() const;
|
||||
|
||||
WindowState GetState() const;
|
||||
|
||||
const InputHandler* GetInputHandler() const;
|
||||
|
||||
virtual void SetTitle_32(const Str_32& newTitle) = 0;
|
||||
|
||||
virtual Str_32 GetTitle_32() const = 0;
|
||||
|
||||
virtual void SetTitle_16(const Str_16& newTitle) = 0;
|
||||
|
||||
virtual Str_16 GetTitle_16() const = 0;
|
||||
|
||||
virtual void SetTitle_8(const Str_8& newTitle) = 0;
|
||||
|
||||
virtual Str_8 GetTitle_8() const = 0;
|
||||
|
||||
virtual void SetPos(const Vec2_s32& newPos) = 0;
|
||||
|
||||
virtual Vec2_s32 GetPos() const = 0;
|
||||
|
||||
virtual void SetScale(const Vec2_u32& newScale) = 0;
|
||||
|
||||
virtual Vec2_u32 GetScale() const = 0;
|
||||
|
||||
virtual Serializer<UInt_64> GetClipboard() = 0;
|
||||
|
||||
virtual void SetClipboard(Serializer<UInt_64> data) = 0;
|
||||
|
||||
virtual void SetCursorImg(const CursorImg img) = 0;
|
||||
};
|
||||
}
|
55
include/ehs/io/COM.h
Normal file
55
include/ehs/io/COM.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class Parity : UInt_8
|
||||
{
|
||||
NONE,
|
||||
ODD,
|
||||
EVEN,
|
||||
MARK,
|
||||
SPACE
|
||||
};
|
||||
|
||||
enum class StopBits : UInt_8
|
||||
{
|
||||
ONE,
|
||||
ONE_POINT_FIVE,
|
||||
TWO
|
||||
};
|
||||
|
||||
class COM
|
||||
{
|
||||
private:
|
||||
UInt_8 port;
|
||||
UInt_32 baudRate;
|
||||
UInt_8 byteSize;
|
||||
Parity parity;
|
||||
StopBits stopBits;
|
||||
void* hdl;
|
||||
bool initialized;
|
||||
|
||||
public:
|
||||
COM();
|
||||
|
||||
COM(const UInt_8 port, const UInt_32 baudRate, const UInt_8 byteSize, const Parity parity, const StopBits stopBits);
|
||||
|
||||
COM(const COM& com) = default;
|
||||
|
||||
void Initialize();
|
||||
|
||||
void UnInitialize();
|
||||
|
||||
UInt_32 Wait();
|
||||
|
||||
void Transmit(const Char_8 data);
|
||||
|
||||
UInt_32 Send(const Char_8* data, const UInt_32 size);
|
||||
|
||||
UInt_32 Receive(const Char_8* data, const UInt_32 size);
|
||||
|
||||
void Flush();
|
||||
};
|
||||
}
|
115
include/ehs/io/Console.h
Normal file
115
include/ehs/io/Console.h
Normal file
@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/UTF.h"
|
||||
#include "ehs/Array.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
typedef void* ConsoleHdl;
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
typedef int ConsoleHdl;
|
||||
#endif
|
||||
|
||||
class Console
|
||||
{
|
||||
private:
|
||||
static ConsoleHdl hdlOut;
|
||||
static ConsoleHdl hdlIn;
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
static bool isConsole;
|
||||
#endif
|
||||
|
||||
public:
|
||||
static void Attach();
|
||||
|
||||
/// Creates a console using standard input and output.
|
||||
/// @param [in] inputRequired Whether or not input is required from the console.
|
||||
static bool Create();
|
||||
|
||||
/// Frees the current console being used.
|
||||
static void Free();
|
||||
|
||||
static bool CanRead();
|
||||
|
||||
static bool CanWrite();
|
||||
|
||||
/// Writes to console using UTF32.
|
||||
/// @param [in] str The text to write to the console.
|
||||
/// @param [in] newLine To make a new line after the given text.
|
||||
/// @warning Has to convert from UTF32 to UTF16 for the Windows API.
|
||||
static void Write_32(const Str_32& str, const bool newLine = true);
|
||||
|
||||
/// Writes to console using UTF16.
|
||||
/// @param [in] str The text to write to the console.
|
||||
/// @param [in] newLine To make a new line after the given text.
|
||||
static void Write_16(const Str_16& str, const bool newLine = true);
|
||||
|
||||
/// Writes to console using UTF8.
|
||||
/// @param [in] str The text to write to the console.
|
||||
/// @param [in] newLine To make a new line after the given text.
|
||||
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
|
||||
static void Write_8(const Str_8& str, const bool newLine = true);
|
||||
|
||||
/// Reads from the console using UTF32.
|
||||
/// @returns The text the user wrote to the console.
|
||||
/// @warning Has to convert from UTF16 to UTF32 for the Windows API.
|
||||
static Str_32 Read_32(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Reads from the console using UTF16.
|
||||
/// @returns The text the user wrote to the console.
|
||||
static Str_16 Read_16(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Reads from the console using UTF8.
|
||||
/// @returns The text the user wrote to the console.
|
||||
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
|
||||
static Str_8 Read_8(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Clears the console.
|
||||
static void Clear();
|
||||
|
||||
/// Changes the console's title.
|
||||
/// @param [in] title The text to change the title to.
|
||||
/// @warning Has to convert from UTF32 to UTF16 for the Windows API.
|
||||
static void SetTitle_32(const Str_32& title);
|
||||
|
||||
/// Changes the console's title.
|
||||
/// @param [in] title The text to change the title to.
|
||||
static void SetTitle_16(const Str_16& title);
|
||||
|
||||
/// Changes the console's title.
|
||||
/// @param [in] title The text to change the title to.
|
||||
/// @warning Has to convert from UTF8 to UTF16 for the Windows API.
|
||||
static void SetTitle_8(const Str_8& title);
|
||||
|
||||
/// Retrieves the console's title in UTF32.
|
||||
/// @returns The console's title.
|
||||
/// @warning Has to convert from UTF16 to UTF32 for the Windows API.
|
||||
static Str_32 GetTitle_32();
|
||||
|
||||
/// Retrieves the console's title in UTF16.
|
||||
/// @returns The console's title.
|
||||
static Str_16 GetTitle_16();
|
||||
|
||||
/// Retrieves the console's title in UTF8.
|
||||
/// @returns The console's title.
|
||||
/// @warning Has to convert from UTF16 to UTF8 for the Windows API.
|
||||
static Str_8 GetTitle_8();
|
||||
|
||||
/// Retrieves the string used when executing the end application through a command line interface in UTF32.
|
||||
/// @returns The result.
|
||||
static Vector<Str_32> GetArgs_32(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Retrieves the string used when executing the end application through a command line interface in UTF16.
|
||||
/// @returns The result.
|
||||
static Vector<Str_16> GetArgs_16(const UInt_64 bufferSize = 1024);
|
||||
|
||||
/// Retrieves the string used when executing the end application through a command line interface in UTF8.
|
||||
/// @returns The result.
|
||||
static Vector<Str_8> GetArgs_8(const UInt_64 bufferSize = 1024);
|
||||
|
||||
//static void* GetHandle();
|
||||
};
|
||||
}
|
9
include/ehs/io/File.h
Normal file
9
include/ehs/io/File.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#include "File_W32.h"
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
#include "File_UNX.h"
|
||||
#endif
|
7
include/ehs/io/FileMonitor.h
Normal file
7
include/ehs/io/FileMonitor.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#include "FileMonitor_W32.h"
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
#include "FileMonitor_UNX.h"
|
||||
#endif
|
37
include/ehs/io/FileMonitor_UNX.h
Normal file
37
include/ehs/io/FileMonitor_UNX.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "BaseFileMonitor.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class FileMonitor : public BaseFileMonitor
|
||||
{
|
||||
private:
|
||||
int hdl;
|
||||
int wd;
|
||||
|
||||
public:
|
||||
~FileMonitor();
|
||||
|
||||
FileMonitor();
|
||||
|
||||
FileMonitor(Str_8 filePath);
|
||||
|
||||
FileMonitor(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor(const FileMonitor& fm);
|
||||
|
||||
FileMonitor& operator=(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor& operator=(const FileMonitor& fm);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
UInt_8 Poll() override;
|
||||
|
||||
bool IsInitialized() const override;
|
||||
};
|
||||
}
|
37
include/ehs/io/FileMonitor_W32.h
Normal file
37
include/ehs/io/FileMonitor_W32.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "BaseFileMonitor.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class FileMonitor final : public BaseFileMonitor
|
||||
{
|
||||
private:
|
||||
Handle hdl;
|
||||
FILETIME time;
|
||||
|
||||
public:
|
||||
~FileMonitor() override;
|
||||
|
||||
FileMonitor();
|
||||
|
||||
FileMonitor(Str_8 filePath);
|
||||
|
||||
FileMonitor(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor(const FileMonitor& fm);
|
||||
|
||||
FileMonitor& operator=(FileMonitor&& fm) noexcept;
|
||||
|
||||
FileMonitor& operator=(const FileMonitor& fm);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
UInt_8 Poll() override;
|
||||
|
||||
bool IsInitialized() const override;
|
||||
};
|
||||
}
|
73
include/ehs/io/File_UNX.h
Normal file
73
include/ehs/io/File_UNX.h
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/UTF.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "BaseFile.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class File : public BaseFile
|
||||
{
|
||||
private:
|
||||
int hdl;
|
||||
void* map;
|
||||
UInt_64 mapSize;
|
||||
|
||||
public:
|
||||
~File() override;
|
||||
|
||||
File();
|
||||
|
||||
File(const Str_8& filePath, const Mode mode, const Disposition disposition);
|
||||
|
||||
File(File&& file) noexcept;
|
||||
|
||||
File(const File& file);
|
||||
|
||||
File& operator=(File&& file) noexcept;
|
||||
|
||||
File& operator=(const File& file);
|
||||
|
||||
operator const Byte*() const override;
|
||||
|
||||
operator Byte*() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
bool IsMapped() const override;
|
||||
|
||||
UInt_64 MapSize() const override;
|
||||
|
||||
void Map(const UInt_64 offset, const UInt_64 size) override;
|
||||
|
||||
void Unmap() override;
|
||||
|
||||
void FlushMap() override;
|
||||
|
||||
UInt_64 Write(const Byte* const data, const UInt_64 size) override;
|
||||
|
||||
UInt_64 Read(Byte* const buffer, const UInt_64 size) override;
|
||||
|
||||
void Seek(UInt_64 index) override;
|
||||
|
||||
void SeekBeginning() override;
|
||||
|
||||
void SeekEnd() override;
|
||||
|
||||
void Truncate(const UInt_64 size) override;
|
||||
|
||||
UInt_64 Size() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static void Rename_32(const Str_32& filePath, const Str_32& newName);
|
||||
|
||||
static void Rename_16(const Str_16& filePath, const Str_16& newName);
|
||||
|
||||
static void Rename_8(const Str_8& filePath, const Str_8& newName);
|
||||
};
|
||||
}
|
74
include/ehs/io/File_W32.h
Normal file
74
include/ehs/io/File_W32.h
Normal file
@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/UTF.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "BaseFile.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class File : public BaseFile
|
||||
{
|
||||
private:
|
||||
HANDLE hdl;
|
||||
HANDLE map;
|
||||
Byte* view;
|
||||
UInt_64 viewSize;
|
||||
|
||||
public:
|
||||
~File() override;
|
||||
|
||||
File();
|
||||
|
||||
File(const Str_8& filePath, const Mode mode, const Disposition disposition);
|
||||
|
||||
File(File&& file) noexcept;
|
||||
|
||||
File(const File& file);
|
||||
|
||||
File& operator=(File&& file) noexcept;
|
||||
|
||||
File& operator=(const File& file);
|
||||
|
||||
operator const Byte*() const override;
|
||||
|
||||
operator Byte*() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
bool IsMapped() const override;
|
||||
|
||||
UInt_64 MapSize() const override;
|
||||
|
||||
void Map(const UInt_64 offset, const UInt_64 size) override;
|
||||
|
||||
void Unmap() override;
|
||||
|
||||
void FlushMap() override;
|
||||
|
||||
UInt_64 Write(const Byte* const data, const UInt_64 size) override;
|
||||
|
||||
UInt_64 Read(Byte* const buffer, const UInt_64 size) override;
|
||||
|
||||
void Seek(UInt_64 index) override;
|
||||
|
||||
void SeekBeginning() override;
|
||||
|
||||
void SeekEnd() override;
|
||||
|
||||
void Truncate(const UInt_64 size) override;
|
||||
|
||||
UInt_64 Size() const override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static void Rename_32(const Str_32& filePath, const Str_32& newName);
|
||||
|
||||
static void Rename_16(const Str_16& filePath, const Str_16& newName);
|
||||
|
||||
static void Rename_8(const Str_8& filePath, const Str_8& newName);
|
||||
};
|
||||
}
|
69
include/ehs/io/FontAtlas.h
Normal file
69
include/ehs/io/FontAtlas.h
Normal file
@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Array.h"
|
||||
|
||||
#include "Glyph.h"
|
||||
#include "ehs/Anchor.h"
|
||||
#include "ehs/io/img/Img.h"
|
||||
#include "ehs/io/model/Mesh.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class FontAtlas : public BaseObj
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
UInt_64 glyphScale;
|
||||
Array<Glyph> glyphs;
|
||||
Vec2_u64 resolution;
|
||||
UInt_64 size;
|
||||
Byte* atlas;
|
||||
|
||||
public:
|
||||
~FontAtlas() override;
|
||||
|
||||
FontAtlas();
|
||||
|
||||
FontAtlas(const Str_8& filePath);
|
||||
|
||||
FontAtlas(FontAtlas&& fa) noexcept;
|
||||
|
||||
FontAtlas(const FontAtlas& fa);
|
||||
|
||||
FontAtlas& operator=(FontAtlas&& fa) noexcept;
|
||||
|
||||
FontAtlas& operator=(const FontAtlas& fa);
|
||||
|
||||
operator Byte*() const;
|
||||
|
||||
void Release();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetGlyphScale() const;
|
||||
|
||||
const Array<Glyph>& GetGlyphs() const;
|
||||
|
||||
Glyph GetGlyph(Char_32 code) const;
|
||||
|
||||
Vec2_u64 GetResolution() const;
|
||||
|
||||
UInt_64 GetSize() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
Vec2_f CalculateSize(const Str_8& text) const;
|
||||
|
||||
float CalculateWidth(const Str_8& text) const;
|
||||
|
||||
float CalculateHeight(const Str_8& text) const;
|
||||
|
||||
UInt_64 CalculateIndexAtPoint(const Str_8& text, const Vec2_f& point) const;
|
||||
|
||||
Mesh Generate(Anchor anchor, const Str_8& text) const;
|
||||
};
|
||||
}
|
59
include/ehs/io/Glyph.h
Normal file
59
include/ehs/io/Glyph.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Vec2.h"
|
||||
#include "ehs/Rect.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Glyph
|
||||
{
|
||||
private:
|
||||
Char_32 code;
|
||||
Vec2_u64 pos;
|
||||
Vec2_u64 scale;
|
||||
Rect_f uv;
|
||||
Vec2_64 bearing;
|
||||
Vec2_64 advance;
|
||||
|
||||
public:
|
||||
Glyph();
|
||||
|
||||
Glyph(Serializer<>& ser);
|
||||
|
||||
Glyph(const Char_32 code);
|
||||
|
||||
Glyph(const Glyph& glyph);
|
||||
|
||||
Glyph& operator=(const Glyph& glyph);
|
||||
|
||||
bool operator==(const Glyph& glyph) const;
|
||||
|
||||
bool operator!=(const Glyph& glyph) const;
|
||||
|
||||
Char_32 GetCode() const;
|
||||
|
||||
void SetPos(const Vec2_u64& newPos);
|
||||
|
||||
Vec2_u64 GetPos() const;
|
||||
|
||||
void SetScale(const Vec2_u64& newScale);
|
||||
|
||||
Vec2_u64 GetScale() const;
|
||||
|
||||
void SetUV(const Rect_f& newUV);
|
||||
|
||||
Rect_f GetUV() const;
|
||||
|
||||
void SetBearing(const Vec2_64& newBearing);
|
||||
|
||||
Vec2_32 GetBearing() const;
|
||||
|
||||
void SetAdvance(const Vec2_64& newAdvance);
|
||||
|
||||
Vec2_32 GetAdvance() const;
|
||||
|
||||
void Serialize(Serializer<>& ser) const;
|
||||
};
|
||||
}
|
38
include/ehs/io/RIFF.h
Normal file
38
include/ehs/io/RIFF.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "RIFF_Chunk.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class RIFF
|
||||
{
|
||||
private:
|
||||
Str_8 type;
|
||||
Vector<RIFF_Chunk> chunks;
|
||||
|
||||
public:
|
||||
RIFF() = default;
|
||||
|
||||
RIFF(const Str_8& filePath);
|
||||
|
||||
RIFF(Serializer<>& data);
|
||||
|
||||
RIFF(const RIFF& riff) = default;
|
||||
|
||||
operator const RIFF_Chunk*() const;
|
||||
|
||||
Str_8 GetType() const;
|
||||
|
||||
bool HasChunk(const UInt_64 hashId) const;
|
||||
|
||||
bool HasChunk(const Str_8& id) const;
|
||||
|
||||
RIFF_Chunk GetChunk(const UInt_64 hashId) const;
|
||||
|
||||
RIFF_Chunk GetChunk(const Str_8& id) const;
|
||||
};
|
||||
}
|
33
include/ehs/io/RIFF_Chunk.h
Normal file
33
include/ehs/io/RIFF_Chunk.h
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class RIFF_Chunk
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Serializer<> data;
|
||||
|
||||
public:
|
||||
RIFF_Chunk();
|
||||
|
||||
RIFF_Chunk(const Str_8& id, const Serializer<>& data);
|
||||
|
||||
RIFF_Chunk(const RIFF_Chunk& chunk);
|
||||
|
||||
RIFF_Chunk& operator=(const RIFF_Chunk& chunk);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Serializer<> GetData() const;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
}
|
45
include/ehs/io/Resource.h
Normal file
45
include/ehs/io/Resource.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Vec2.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Resource : public BaseObj
|
||||
{
|
||||
private:
|
||||
ehs::UInt_64 hashId;
|
||||
ehs::Str_8 id;
|
||||
|
||||
public:
|
||||
Resource();
|
||||
|
||||
Resource(ehs::Str_8 id);
|
||||
|
||||
Resource(Resource&& rsrc) noexcept;
|
||||
|
||||
Resource(const Resource& rsrc);
|
||||
|
||||
Resource& operator=(Resource&& rsrc) noexcept;
|
||||
|
||||
Resource& operator=(const Resource& rsrc);
|
||||
|
||||
bool operator==(ehs::UInt_64 otherHashId) const;
|
||||
|
||||
bool operator!=(ehs::UInt_64 otherHashId) const;
|
||||
|
||||
virtual void Release();
|
||||
|
||||
void SetId(ehs::Str_8 newId);
|
||||
|
||||
ehs::UInt_64 GetHashId() const;
|
||||
|
||||
ehs::Str_8 GetId() const;
|
||||
|
||||
virtual bool IsValid() const;
|
||||
|
||||
Resource* Clone() const override;
|
||||
};
|
||||
}
|
13
include/ehs/io/Window.h
Normal file
13
include/ehs/io/Window.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/system/OS.h"
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#include "Window_W32.h"
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
#if defined(EHS_WS_XCB)
|
||||
#include "Window_XCB.h"
|
||||
#elif defined(EHS_WS_WAYLAND)
|
||||
#include "Window_Way.h"
|
||||
#endif
|
||||
#endif
|
127
include/ehs/io/Window_W32.h
Normal file
127
include/ehs/io/Window_W32.h
Normal file
@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Vec4.h"
|
||||
#include "BaseWindow.h"
|
||||
#include "HID/InputHandler.h"
|
||||
|
||||
#define WM_HIDE (WM_APP + 1)
|
||||
#define WM_SHOW (WM_APP + 2)
|
||||
#define WM_HIDE_CURSOR (WM_APP + 3)
|
||||
#define WM_SHOW_CURSOR (WM_APP + 4)
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Window : public BaseWindow
|
||||
{
|
||||
private:
|
||||
UInt_32 owner;
|
||||
HINSTANCE instance;
|
||||
HWND hdl;
|
||||
|
||||
static Array<Window*> windows;
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
public:
|
||||
virtual ~Window() override;
|
||||
|
||||
Window();
|
||||
|
||||
Window(const Window &win);
|
||||
|
||||
Window& operator=(const Window &win);
|
||||
|
||||
virtual bool Poll() override;
|
||||
|
||||
///Creates the native window.
|
||||
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
///Creates the native window.
|
||||
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
///Creates the native window.
|
||||
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
///Uses an already existing window to render an overlay.
|
||||
void Use(HWND windowHdl);
|
||||
|
||||
///Closes the window.
|
||||
virtual void Close() override;
|
||||
|
||||
///Shows the window.
|
||||
void Show() override;
|
||||
|
||||
///Hides the window.
|
||||
void Hide() override;
|
||||
|
||||
void SetTitle_32(const Str_32& title) override;
|
||||
|
||||
Str_32 GetTitle_32();
|
||||
|
||||
void SetTitle_16(const Str_16& title) override;
|
||||
|
||||
Str_16 GetTitle_16();
|
||||
|
||||
void SetTitle_8(const Str_8& title) override;
|
||||
|
||||
Str_8 GetTitle_8();
|
||||
|
||||
void SetIcon(const Str_8& filePath);
|
||||
|
||||
/// Sets the windows client scale.
|
||||
/// @param [in] w The width in pixels.
|
||||
/// @param [in] h The height in pixels.
|
||||
void SetClientSize(const Vec2<UInt_32>& size);
|
||||
|
||||
Vec2<UInt_32> GetClientSize();
|
||||
|
||||
/// Gets the windows native handle for the operating system or other native tasks.
|
||||
/// @returns The window's native handle.
|
||||
HWND GetHdl() const;
|
||||
|
||||
/// Retrieves the first window handle that has been created using this library.
|
||||
/// @returns The window's native handle.
|
||||
static HWND GetAvailableHdl();
|
||||
|
||||
HINSTANCE GetInst() const;
|
||||
|
||||
/// Toggles whether the window updates and renders.
|
||||
/// @param [in] toggle The new status.
|
||||
void ToggleEnabled(bool toggle);
|
||||
|
||||
/// Checks whether the window updates and renders.
|
||||
/// @returns The current status.
|
||||
bool IsEnabled();
|
||||
|
||||
/// Sets the windows position on the desktop.
|
||||
/// @param [in] x The x axis in pixels.
|
||||
/// @param [in] y The y axis in pixels.
|
||||
void SetPos(int x, int y);
|
||||
|
||||
/// Gets the windows current position on the desktop.
|
||||
/// @returns The current value.
|
||||
Vec2<Int_32> GetPos();
|
||||
|
||||
virtual void OnResized(const Vec2<UInt_32>& newSize);
|
||||
|
||||
/// Sets the windows scale which includes the border.
|
||||
/// @param [in] w The width in pixels.
|
||||
/// @param [in] h The height in pixels.
|
||||
void SetSize(int w, int h);
|
||||
|
||||
/// Gets the windows current scale.
|
||||
/// @returns The current value.
|
||||
Vec2<Int_32> GetSize();
|
||||
|
||||
void ShowCursor(bool toggle) override;
|
||||
|
||||
void ConstrainCursor(const bool toggle) override;
|
||||
|
||||
protected:
|
||||
void SendMsg(const UINT msg, const WPARAM wParam, const LPARAM lParam);
|
||||
|
||||
};
|
||||
}
|
80
include/ehs/io/Window_Way.h
Normal file
80
include/ehs/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 ehs
|
||||
{
|
||||
class Window : public BaseWindow
|
||||
{
|
||||
private:
|
||||
wl_display* display;
|
||||
wl_registry *registry;
|
||||
wl_compositor* compositor;
|
||||
wl_surface* surface;
|
||||
xdg_wm_base *xdgShell;
|
||||
xdg_surface *xdgSurface;
|
||||
xdg_toplevel *xdgToplevel;
|
||||
|
||||
static void SurfaceConfigure(void *data, xdg_surface *xdg_surface, UInt_32 serial);
|
||||
|
||||
static void ShellPing(void *data, xdg_wm_base *shell, UInt_32 serial);
|
||||
|
||||
static void RegistryHandler(void *data, wl_registry *registry, UInt_32 id, const char *interface, UInt_32 version);
|
||||
|
||||
static void RegistryRemoved(void *data, wl_registry *registry, UInt_32 id);
|
||||
|
||||
public:
|
||||
~Window() override;
|
||||
|
||||
Window();
|
||||
|
||||
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override;
|
||||
|
||||
void OnCreated() override;
|
||||
|
||||
void Close() override;
|
||||
|
||||
void Show() override;
|
||||
|
||||
void Hide() override;
|
||||
|
||||
bool Poll() override;
|
||||
|
||||
void ShowCursor(bool toggle) override;
|
||||
|
||||
void ConstrainCursor(const bool constrain) override;
|
||||
|
||||
void SetTitle_32(const Str_32& newTitle) override;
|
||||
|
||||
Str_32 GetTitle_32() const override;
|
||||
|
||||
void SetTitle_16(const Str_16& newTitle) override;
|
||||
|
||||
Str_16 GetTitle_16() const override;
|
||||
|
||||
void SetTitle_8(const Str_8& newTitle) override;
|
||||
|
||||
Str_8 GetTitle_8() const override;
|
||||
|
||||
void SetPos(const Vec2_s32& newPos) override;
|
||||
|
||||
Vec2_s32 GetPos() const override;
|
||||
|
||||
void SetScale(const Vec2_u32& newScale) override;
|
||||
|
||||
Vec2_u32 GetScale() const override;
|
||||
|
||||
Serializer<UInt_64> GetClipboard() override;
|
||||
|
||||
void SetClipboard(Serializer<UInt_64> data) override;
|
||||
|
||||
void SetCursorImg(const CursorImg img) override;
|
||||
};
|
||||
}
|
94
include/ehs/io/Window_XCB.h
Normal file
94
include/ehs/io/Window_XCB.h
Normal file
@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseWindow.h"
|
||||
#include "File.h"
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xinput.h>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Window : public BaseWindow
|
||||
{
|
||||
protected:
|
||||
friend class Input;
|
||||
|
||||
xcb_connection_t* server;
|
||||
xcb_screen_t* screen;
|
||||
xcb_window_t hdl;
|
||||
xcb_atom_t masks[2];
|
||||
UInt_8 extOpCode;
|
||||
Vector<xcb_generic_event_t*> events;
|
||||
Serializer<UInt_64> clipboard;
|
||||
|
||||
public:
|
||||
~Window() override;
|
||||
|
||||
Window();
|
||||
|
||||
Window(Window&& win) noexcept;
|
||||
|
||||
Window(const Window& win);
|
||||
|
||||
Window& operator=(Window&& win) noexcept;
|
||||
|
||||
Window& operator=(const Window& win);
|
||||
|
||||
void Create_32(const Str_32& title, const Vec2_s32& pos, Vec2_u32 scale) override;
|
||||
|
||||
void Create_16(const Str_16& title, const Vec2_s32& pos, Vec2_u32 scale) override;
|
||||
|
||||
void Create_8(const Str_8& title, const Vec2_s32& pos, Vec2_u32 scale) override;
|
||||
|
||||
void Close() override;
|
||||
|
||||
void Show() override;
|
||||
|
||||
void Hide() override;
|
||||
|
||||
bool Poll() override;
|
||||
|
||||
void ShowCursor(bool toggle) override;
|
||||
|
||||
void ConstrainCursor(bool constrain) override;
|
||||
|
||||
void SetTitle_32(const Str_32& newTitle) override;
|
||||
|
||||
Str_32 GetTitle_32() const override;
|
||||
|
||||
void SetTitle_16(const Str_16& newTitle) override;
|
||||
|
||||
Str_16 GetTitle_16() const override;
|
||||
|
||||
void SetTitle_8(const Str_8& newTitle) override;
|
||||
|
||||
Str_8 GetTitle_8() const override;
|
||||
|
||||
void SetPos(const Vec2_s32& newPos) override;
|
||||
|
||||
Vec2_s32 GetPos() const override;
|
||||
|
||||
void SetScale(const Vec2_u32& newScale) override;
|
||||
|
||||
Vec2_u32 GetScale() const override;
|
||||
|
||||
Serializer<UInt_64> GetClipboard() override;
|
||||
|
||||
void SetClipboard(Serializer<UInt_64> data) override;
|
||||
|
||||
void SetCursorImg(CursorImg img) override;
|
||||
|
||||
xcb_connection_t* GetServer();
|
||||
|
||||
private:
|
||||
xcb_generic_event_t* RetrieveEvent();
|
||||
|
||||
xcb_atom_t RetrieveAtom(bool create, const Str_8& name) const;
|
||||
|
||||
xcb_get_property_reply_t* RetrieveProp(xcb_atom_t prop, xcb_atom_t type) const;
|
||||
|
||||
void QueryPrimaryDevices();
|
||||
|
||||
Str_8 QueryDeviceName(UInt_16 id);
|
||||
};
|
||||
}
|
204
include/ehs/io/audio/Audio.h
Normal file
204
include/ehs/io/audio/Audio.h
Normal file
@ -0,0 +1,204 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
#include "ehs/DataType.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/io/Resource.h"
|
||||
#include "AudioCodec.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Audio : public Resource
|
||||
{
|
||||
private:
|
||||
static Array<AudioCodec> codecs;
|
||||
UInt_64 sampleRate;
|
||||
DataType dataType;
|
||||
UInt_8 byteDepth;
|
||||
UInt_8 channels;
|
||||
UInt_64 frames;
|
||||
float length;
|
||||
Byte* data;
|
||||
Byte* peak;
|
||||
|
||||
public:
|
||||
static bool HasCodec(UInt_64 hashExt);
|
||||
|
||||
static bool HasCodec(const Str_8& ext);
|
||||
|
||||
static bool AddCodec(AudioCodec codec);
|
||||
|
||||
static const AudioCodec* GetCodec(UInt_64 hashExt);
|
||||
|
||||
static const AudioCodec* GetCodec(const Str_8& ext);
|
||||
|
||||
~Audio() override;
|
||||
|
||||
Audio();
|
||||
|
||||
Audio(Str_8 id);
|
||||
|
||||
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames, const Byte* data);
|
||||
|
||||
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Serializer<UInt_64>& data);
|
||||
|
||||
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Vector<Byte>& data);
|
||||
|
||||
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Array<Byte>& data);
|
||||
|
||||
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames);
|
||||
|
||||
Audio(Audio&& audio) noexcept;
|
||||
|
||||
Audio(const Audio& audio);
|
||||
|
||||
Audio& operator=(Audio&& audio) noexcept;
|
||||
|
||||
Audio& operator=(const Audio& audio);
|
||||
|
||||
operator const Byte*() const;
|
||||
|
||||
operator Byte*();
|
||||
|
||||
void Release() override;
|
||||
|
||||
UInt_64 GetSampleRate() const;
|
||||
|
||||
DataType GetDataType() const;
|
||||
|
||||
UInt_8 GetByteDepth() const;
|
||||
|
||||
UInt_8 GetBitDepth() const;
|
||||
|
||||
UInt_8 GetChannels() const;
|
||||
|
||||
UInt_64 GetFrameCount() const;
|
||||
|
||||
UInt_64 GetSampleCount() const;
|
||||
|
||||
UInt_64 GetSize() const;
|
||||
|
||||
float GetLength() const;
|
||||
|
||||
Array<Byte> FrameAsMono(UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsStereo(UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsFive_One(UInt_64 frameIndex) const;
|
||||
|
||||
Array<Byte> FrameAsSeven_One(UInt_64 frameIndex) const;
|
||||
|
||||
SInt_8 SampleAsSInt_8(UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_16 SampleAsSInt_16(UInt_64 sampleIndex) const;
|
||||
|
||||
float SampleAsFloat(UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_32 SampleAsSInt_32(UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_64 SampleAsSInt_64(UInt_64 sampleIndex) const;
|
||||
|
||||
SInt_8 PeakAsSInt_8() const;
|
||||
|
||||
SInt_16 PeakAsSInt_16() const;
|
||||
|
||||
float PeakAsFloat() const;
|
||||
|
||||
SInt_32 PeakAsSInt_32() const;
|
||||
|
||||
SInt_64 PeakAsSInt_64() const;
|
||||
|
||||
void SetPeak(UInt_64 size, const Byte* newPeak);
|
||||
|
||||
const Byte* GetPeak() const;
|
||||
|
||||
void ToDataType(DataType newDataType);
|
||||
|
||||
Audio GetAsDataType(DataType newDataType) const;
|
||||
|
||||
void ToChannels(UInt_8 newChannels);
|
||||
|
||||
Audio GetAsChannels(UInt_8 newChannels) const;
|
||||
|
||||
bool ToFile(const Str_8& filePath) const;
|
||||
|
||||
static Audio FromFile(const Str_8& filePath);
|
||||
|
||||
static Audio* FromFile_Heap(const Str_8& filePath);
|
||||
|
||||
static Audio FromFile(const Str_8& filePath, DataType required);
|
||||
|
||||
static Audio* FromFile_Heap(const Str_8& filePath, DataType required);
|
||||
|
||||
static Audio FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data);
|
||||
|
||||
private:
|
||||
void ToMono(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Five_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Seven_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Stereo_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Seven_One_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Mono_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Stereo_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
void Five_One_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
||||
|
||||
// To SInt_8
|
||||
void SInt_16_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To SInt_16
|
||||
void SInt_8_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To Float
|
||||
void SInt_8_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_16_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_Float(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To SInt_32
|
||||
void SInt_8_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_16_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_64_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
// To SInt_64
|
||||
void SInt_8_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_16_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void Float_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
|
||||
void SInt_32_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||||
};
|
||||
}
|
48
include/ehs/io/audio/AudioCodec.h
Normal file
48
include/ehs/io/audio/AudioCodec.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/io/File.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Audio;
|
||||
|
||||
class AudioCodec
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashExt;
|
||||
Str_8 ext;
|
||||
Endianness endianness;
|
||||
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*);
|
||||
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*);
|
||||
|
||||
public:
|
||||
AudioCodec();
|
||||
|
||||
AudioCodec(Str_8 id, Str_8 ext, const Endianness end,
|
||||
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*),
|
||||
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*));
|
||||
|
||||
AudioCodec(AudioCodec&& codec) noexcept;
|
||||
|
||||
AudioCodec(const AudioCodec& codec);
|
||||
|
||||
AudioCodec& operator=(AudioCodec&& codec) noexcept;
|
||||
|
||||
AudioCodec& operator=(const AudioCodec& codec);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashExt() const;
|
||||
|
||||
Str_8 GetExt() const;
|
||||
|
||||
Endianness GetEndianness() const;
|
||||
|
||||
bool Encode(Serializer<UInt_64>& out, const Audio* in) const;
|
||||
|
||||
bool Decode(Serializer<UInt_64>& in, Audio* out) const;
|
||||
};
|
||||
}
|
9
include/ehs/io/audio/AudioDevice.h
Normal file
9
include/ehs/io/audio/AudioDevice.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#include "AudioDevice_W32.h"
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
#include "AudioDevice_ALSA.h"
|
||||
#endif
|
46
include/ehs/io/audio/AudioDevice_ALSA.h
Normal file
46
include/ehs/io/audio/AudioDevice_ALSA.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "BaseAudioDevice.h"
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class AudioDevice : public BaseAudioDevice
|
||||
{
|
||||
private:
|
||||
snd_pcm_t* hdl;
|
||||
|
||||
public:
|
||||
~AudioDevice() override;
|
||||
|
||||
AudioDevice();
|
||||
|
||||
AudioDevice(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice(const AudioDevice& device);
|
||||
|
||||
AudioDevice& operator=(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice& operator=(const AudioDevice& device);
|
||||
|
||||
void Release() override;
|
||||
|
||||
void OpenStream() override;
|
||||
|
||||
void CloseStream() override;
|
||||
|
||||
UInt_64 GetAvailFrames() const override;
|
||||
|
||||
Byte* Map(UInt_64* offset, UInt_64* frames) override;
|
||||
|
||||
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static AudioDevice GetDefault(const AudioDeviceType type);
|
||||
|
||||
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
|
||||
};
|
||||
}
|
66
include/ehs/io/audio/AudioDevice_W32.h
Normal file
66
include/ehs/io/audio/AudioDevice_W32.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "BaseAudioDevice.h"
|
||||
|
||||
#include <initguid.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <functiondiscoverykeys_devpkey.h>
|
||||
#include <Audioclient.h>
|
||||
|
||||
struct IMMDevice;
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class AudioDevice : public BaseAudioDevice
|
||||
{
|
||||
private:
|
||||
IMMDevice* hdl;
|
||||
IAudioClient* client;
|
||||
IAudioRenderClient* playbackClient;
|
||||
IAudioCaptureClient* captureClient;
|
||||
|
||||
public:
|
||||
~AudioDevice() override;
|
||||
|
||||
AudioDevice();
|
||||
|
||||
AudioDevice(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice(const AudioDevice& device);
|
||||
|
||||
AudioDevice& operator=(AudioDevice&& device) noexcept;
|
||||
|
||||
AudioDevice& operator=(const AudioDevice& device);
|
||||
|
||||
void Release() override;
|
||||
|
||||
void OpenStream() override;
|
||||
|
||||
void CloseStream() override;
|
||||
|
||||
UInt_64 GetAvailFrames() const override;
|
||||
|
||||
Byte* Map(UInt_64* offset, UInt_64* frames) override;
|
||||
|
||||
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
|
||||
|
||||
Str_32 GetInterfaceName_32() const;
|
||||
|
||||
Str_16 GetInterfaceName_16() const;
|
||||
|
||||
Str_8 GetInterfaceName_8() const;
|
||||
|
||||
Str_32 GetName_32() const;
|
||||
|
||||
Str_16 GetName_16() const;
|
||||
|
||||
Str_8 GetName_8() const;
|
||||
|
||||
bool IsValid() const override;
|
||||
|
||||
static AudioDevice GetDefault(const AudioDeviceType type);
|
||||
|
||||
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
|
||||
};
|
||||
}
|
105
include/ehs/io/audio/BaseAudioDevice.h
Normal file
105
include/ehs/io/audio/BaseAudioDevice.h
Normal file
@ -0,0 +1,105 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/DataType.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class AudioDeviceType
|
||||
{
|
||||
OUTPUT = 0x0,
|
||||
INPUT = 0x1,
|
||||
ALL = 0x2
|
||||
};
|
||||
|
||||
enum class AudioDeviceState
|
||||
{
|
||||
ACTIVE = 0x1,
|
||||
DISABLED = 0x2,
|
||||
NOT_PRESENT = 0x4,
|
||||
UNPLUGGED = 0x8
|
||||
};
|
||||
|
||||
class BaseAudioDevice
|
||||
{
|
||||
protected:
|
||||
AudioDeviceType type;
|
||||
DataType dataType;
|
||||
UInt_16 bitDepth;
|
||||
UInt_32 sampleRate;
|
||||
UInt_32 channels;
|
||||
UInt_32 period;
|
||||
UInt_32 latency;
|
||||
UInt_64 maxFrames;
|
||||
bool streaming;
|
||||
|
||||
public:
|
||||
virtual ~BaseAudioDevice() = default;
|
||||
|
||||
BaseAudioDevice();
|
||||
|
||||
BaseAudioDevice(const BaseAudioDevice& device);
|
||||
|
||||
BaseAudioDevice& operator=(const BaseAudioDevice& device);
|
||||
|
||||
virtual void Release();
|
||||
|
||||
virtual void OpenStream();
|
||||
|
||||
virtual void CloseStream();
|
||||
|
||||
virtual UInt_64 GetAvailFrames() const;
|
||||
|
||||
virtual Byte* Map(UInt_64* offset, UInt_64* frames);
|
||||
|
||||
virtual void UnMap(const UInt_64 offset, const UInt_64 frames);
|
||||
|
||||
AudioDeviceType GetType() const;
|
||||
|
||||
void SetDataType(const DataType newDataType);
|
||||
|
||||
DataType GetDataType() const;
|
||||
|
||||
UInt_8 GetByteDepth() const;
|
||||
|
||||
UInt_16 GetBitDepth() const;
|
||||
|
||||
void SetSampleRate(const UInt_32 newSampleRate);
|
||||
|
||||
UInt_32 GetSampleRate() const;
|
||||
|
||||
void SetChannels(const UInt_32 newChannels);
|
||||
|
||||
UInt_16 GetChannels() const;
|
||||
|
||||
UInt_32 GetFrameSize() const;
|
||||
|
||||
void SetPeriod(const UInt_32 newPeriod);
|
||||
|
||||
UInt_32 GetPeriod() const;
|
||||
|
||||
void SetLatency(const UInt_32 newLatency);
|
||||
|
||||
UInt_32 GetLatency() const;
|
||||
|
||||
UInt_64 GetMaxFrames() const;
|
||||
|
||||
bool IsStreaming() const;
|
||||
|
||||
virtual bool IsValid() const;
|
||||
|
||||
/// Retrieves the default audio input/output device.
|
||||
/// @param [in] type The audio device type to retrieve.
|
||||
/// @param [out] device The default audio device.
|
||||
static BaseAudioDevice GetDefault(const AudioDeviceType type);
|
||||
|
||||
/// Retrieves a list of audio input/output devices.
|
||||
/// @param [in] type The audio device type to retrieve.
|
||||
/// @param [in] state The audio device state to retrieve.
|
||||
/// @param [out] devices The list of audio devices.
|
||||
static Array<BaseAudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
|
||||
};
|
||||
}
|
31
include/ehs/io/hid/Button.h
Normal file
31
include/ehs/io/hid/Button.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Button
|
||||
{
|
||||
private:
|
||||
Str_8 name;
|
||||
UInt_32 hash;
|
||||
|
||||
public:
|
||||
Button();
|
||||
|
||||
Button(const Str_8& name);
|
||||
|
||||
Button(const Button& key);
|
||||
|
||||
Button& operator=(const Button& key);
|
||||
|
||||
bool operator==(const Button& key) const;
|
||||
|
||||
bool operator!=(const Button& key) const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_32 GetHash() const;
|
||||
};
|
||||
}
|
55
include/ehs/io/hid/ButtonState.h
Normal file
55
include/ehs/io/hid/ButtonState.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "Button.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class State
|
||||
{
|
||||
JUST_RELEASED,
|
||||
RELEASED,
|
||||
PRESSED,
|
||||
TOUCHED
|
||||
};
|
||||
|
||||
class ButtonState
|
||||
{
|
||||
private:
|
||||
Button button;
|
||||
State state;
|
||||
bool pressed;
|
||||
float threshold;
|
||||
|
||||
public:
|
||||
ButtonState();
|
||||
|
||||
ButtonState(const Button& button, const State state);
|
||||
|
||||
ButtonState(const ButtonState& bs);
|
||||
|
||||
ButtonState& operator=(const ButtonState& bs);
|
||||
|
||||
bool operator==(const Button& other) const;
|
||||
|
||||
bool operator!=(const Button& other) const;
|
||||
|
||||
bool operator==(const State otherState) const;
|
||||
|
||||
bool operator!=(const State otherState) const;
|
||||
|
||||
Button GetButton() const;
|
||||
|
||||
void SetState(State newState);
|
||||
|
||||
State GetState() const;
|
||||
|
||||
void SetPressed(bool value);
|
||||
|
||||
bool IsPressed() const;
|
||||
|
||||
void SetThreshold(const float newThreshold);
|
||||
|
||||
float GetThreshold() const;
|
||||
};
|
||||
}
|
91
include/ehs/io/hid/HID.h
Normal file
91
include/ehs/io/hid/HID.h
Normal file
@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Array.h"
|
||||
#include "ButtonState.h"
|
||||
|
||||
#define EHS_HID_UNKNOWN 0
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class HID
|
||||
{
|
||||
protected:
|
||||
UInt_8 type;
|
||||
UInt_64 hashName;
|
||||
Str_8 name;
|
||||
UInt_64 id;
|
||||
Array<ButtonState> states;
|
||||
|
||||
public:
|
||||
HID();
|
||||
|
||||
HID(const UInt_8 type, Str_8 name, const UInt_64 id);
|
||||
|
||||
HID(HID&& hid) noexcept;
|
||||
|
||||
HID(const HID& hid);
|
||||
|
||||
HID& operator=(HID&& hid) noexcept;
|
||||
|
||||
HID& operator=(const HID& hid);
|
||||
|
||||
bool operator==(const HID& other) const;
|
||||
|
||||
bool operator!=(const HID& other) const;
|
||||
|
||||
bool operator==(const UInt_64 otherId) const;
|
||||
|
||||
bool operator!=(const UInt_64 otherId) const;
|
||||
|
||||
virtual void Poll();
|
||||
|
||||
UInt_8 GetType() const;
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_64 GetId() const;
|
||||
|
||||
void ReleaseAll();
|
||||
|
||||
Vector<const ButtonState*> GetAllTouched() const;
|
||||
|
||||
const ButtonState* IsTouched(const Button& button) const;
|
||||
|
||||
const ButtonState* IsTouched() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllDown() const;
|
||||
|
||||
const ButtonState* IsDown(const Button& button) const;
|
||||
|
||||
const ButtonState* IsDown() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllJustReleased() const;
|
||||
|
||||
const ButtonState* IsJustReleased(const Button& button) const;
|
||||
|
||||
const ButtonState* IsJustReleased() const;
|
||||
|
||||
Vector<const ButtonState*> GetAllUp() const;
|
||||
|
||||
const ButtonState* IsUp(const Button& button) const;
|
||||
|
||||
const ButtonState* IsUp() const;
|
||||
|
||||
void ButtonDown(const Button& button);
|
||||
|
||||
void ButtonUp(const Button& button);
|
||||
|
||||
const ButtonState* GetState(const Button& button) const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
virtual HID* Clone() const;
|
||||
|
||||
private:
|
||||
bool HasState(const Button& button) const;
|
||||
|
||||
bool AddState(const ButtonState& state);
|
||||
|
||||
ButtonState* GetState(const Button& button);
|
||||
};
|
||||
}
|
46
include/ehs/io/hid/Input.h
Normal file
46
include/ehs/io/hid/Input.h
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "InputHandler.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Input
|
||||
{
|
||||
private:
|
||||
Array<InputHandler*> handlers;
|
||||
bool initalized;
|
||||
|
||||
public:
|
||||
~Input();
|
||||
|
||||
Input();
|
||||
|
||||
Input(Input&& input) noexcept;
|
||||
|
||||
Input(const Input& input);
|
||||
|
||||
Input& operator=(Input&& input) noexcept;
|
||||
|
||||
Input& operator=(const Input& input);
|
||||
|
||||
void Initialize();
|
||||
|
||||
void Release();
|
||||
|
||||
void Poll();
|
||||
|
||||
bool HasHandler(const UInt_64 hashId) const;
|
||||
|
||||
bool HasHandler(const Str_8& id) const;
|
||||
|
||||
bool AddHandler(InputHandler* handler);
|
||||
|
||||
const InputHandler* GetHandler(const UInt_64 hashId) const;
|
||||
|
||||
const InputHandler* GetHandler(const Str_8& id) const;
|
||||
|
||||
bool IsInitialized() const;
|
||||
};
|
||||
}
|
58
include/ehs/io/hid/InputHandler.h
Normal file
58
include/ehs/io/hid/InputHandler.h
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Array.h"
|
||||
#include "HID.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class InputHandler
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
|
||||
protected:
|
||||
Array<HID*> devices;
|
||||
|
||||
public:
|
||||
virtual ~InputHandler();
|
||||
|
||||
InputHandler();
|
||||
|
||||
InputHandler(Str_8 id);
|
||||
|
||||
InputHandler(InputHandler&& ih) noexcept;
|
||||
|
||||
InputHandler(const InputHandler& ih);
|
||||
|
||||
InputHandler& operator=(InputHandler&& ih) noexcept;
|
||||
|
||||
InputHandler& operator=(const InputHandler& ih);
|
||||
|
||||
bool operator==(const UInt_64 otherHashId);
|
||||
|
||||
bool operator!=(const UInt_64 otherHashId);
|
||||
|
||||
virtual bool Initialize();
|
||||
|
||||
virtual bool Release();
|
||||
|
||||
virtual void Poll();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
void ResetAllStates();
|
||||
|
||||
bool HasDevice(const UInt_64 id) const;
|
||||
|
||||
bool AddDevice(HID* device);
|
||||
|
||||
HID* GetDevice(const UInt_64 id) const;
|
||||
|
||||
HID* GetDeviceByType(const UInt_8 type) const;
|
||||
|
||||
virtual bool IsInitialized() const;
|
||||
};
|
||||
}
|
121
include/ehs/io/hid/Keyboard.h
Normal file
121
include/ehs/io/hid/Keyboard.h
Normal file
@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define EHS_HID_KEYBOARD 0x02
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Keyboard : public HID
|
||||
{
|
||||
public:
|
||||
Keyboard();
|
||||
|
||||
Keyboard(Str_8 name, 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/ehs/io/hid/Mouse.h
Normal file
55
include/ehs/io/hid/Mouse.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
#include "ehs/Vec2.h"
|
||||
#include "Button.h"
|
||||
#include "HID.h"
|
||||
|
||||
#define EHS_HID_MOUSE 0x01
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Mouse : public HID
|
||||
{
|
||||
private:
|
||||
friend class Input;
|
||||
|
||||
Vec2_s32 delta;
|
||||
|
||||
public:
|
||||
Mouse();
|
||||
|
||||
Mouse(Str_8 name, const UInt_64 id);
|
||||
|
||||
Mouse(Mouse&& hid) noexcept = default;
|
||||
|
||||
Mouse(const Mouse& hid);
|
||||
|
||||
Mouse& operator=(Mouse&& hid) noexcept = default;
|
||||
|
||||
Mouse& operator=(const Mouse& hid);
|
||||
|
||||
void Poll() override;
|
||||
|
||||
void SetDelta(const Vec2_s32& newDelta);
|
||||
|
||||
Vec2_s32 GetDelta() const;
|
||||
|
||||
Mouse* Clone() const override;
|
||||
|
||||
static const Button Unknown;
|
||||
static const Button LMB;
|
||||
static const Button MMB;
|
||||
static const Button RMB;
|
||||
static const Button Four;
|
||||
static const Button Five;
|
||||
static const Button ScrollUp;
|
||||
static const Button ScrollDown;
|
||||
static const Button ScrollLeft;
|
||||
static const Button ScrollRight;
|
||||
static const Button Back;
|
||||
static const Button Forward;
|
||||
|
||||
static Button TranslateXCB(const UInt_32 code);
|
||||
};
|
||||
}
|
188
include/ehs/io/img/Img.h
Normal file
188
include/ehs/io/img/Img.h
Normal file
@ -0,0 +1,188 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ImgCodec.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class Resampling : UInt_8
|
||||
{
|
||||
NONE,
|
||||
NEAREST_NEIGHBOR
|
||||
};
|
||||
|
||||
class Img : public BaseObj
|
||||
{
|
||||
private:
|
||||
static Array<ImgCodec> codecs;
|
||||
|
||||
protected:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
UInt_8 byteDepth;
|
||||
UInt_8 channels;
|
||||
Vec2_u64 resolution;
|
||||
UInt_64 size;
|
||||
Byte* data;
|
||||
|
||||
public:
|
||||
static bool HasCodec(UInt_64 hashExt);
|
||||
|
||||
static bool HasCodec(const Str_8& ext);
|
||||
|
||||
static bool AddCodec(ImgCodec codec);
|
||||
|
||||
static const ImgCodec* GetCodec(UInt_64 hashExt);
|
||||
|
||||
static const ImgCodec* GetCodec(const Str_8& ext);
|
||||
|
||||
~Img() override;
|
||||
|
||||
Img();
|
||||
|
||||
Img(Str_8 id);
|
||||
|
||||
Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution, const Byte* data);
|
||||
|
||||
Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution);
|
||||
|
||||
Img(Img&& img) noexcept;
|
||||
|
||||
Img(const Img& img);
|
||||
|
||||
Img& operator=(Img&& img) noexcept;
|
||||
|
||||
Img& operator=(const Img& img);
|
||||
|
||||
operator const Byte* () const;
|
||||
|
||||
operator Byte* ();
|
||||
|
||||
void Release();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_8 GetByteDepth() const;
|
||||
|
||||
UInt_8 GetBitDepth() const;
|
||||
|
||||
UInt_8 GetChannels() const;
|
||||
|
||||
Vec2_u64 GetResolution() const;
|
||||
|
||||
UInt_64 GetSize() const;
|
||||
|
||||
void SetPixel(UInt_64 index, const Byte* pixel);
|
||||
|
||||
void GetPixel(UInt_64 index, Byte* pixel) const;
|
||||
|
||||
void SetPixel(UInt_64 x, UInt_64 y, const Byte* pixel);
|
||||
|
||||
void GetPixel(UInt_64 x, UInt_64 y, Byte* pixel) const;
|
||||
|
||||
void Resize(Resampling method, const Vec2_u64& newResolution);
|
||||
|
||||
Img GetResized(Resampling method, const Vec2_u64& newResolution) const;
|
||||
|
||||
void ToRGBA();
|
||||
|
||||
Img GetAsRGBA() const;
|
||||
|
||||
void ToRGB();
|
||||
|
||||
Img GetAsRGB() const;
|
||||
|
||||
void ToMonoA();
|
||||
|
||||
Img GetAsMonoA() const;
|
||||
|
||||
void ToMono();
|
||||
|
||||
Img GetAsMono() const;
|
||||
|
||||
void To32();
|
||||
|
||||
Img GetAs32() const;
|
||||
|
||||
void To24();
|
||||
|
||||
Img GetAs24() const;
|
||||
|
||||
void To16();
|
||||
|
||||
Img GetAs16() const;
|
||||
|
||||
void To8();
|
||||
|
||||
Img GetAs8() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool ToFile(const Str_8& filePath) const;
|
||||
|
||||
static Img FromFile(const Str_8& filePath);
|
||||
|
||||
static Img* FromFile_Heap(const Str_8& filePath);
|
||||
|
||||
static Img FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data);
|
||||
|
||||
private:
|
||||
Img GetNearestNeighbor(const Vec2_u64& newResolution) const;
|
||||
|
||||
void NearestNeighbor(const Vec2_u64& newResolution);
|
||||
|
||||
void RGB_To_RGBA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void MonoA_To_RGBA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void Mono_To_RGBA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGBA_To_RGB(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void MonoA_To_RGB(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void Mono_To_RGB(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGBA_To_MonoA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGB_To_MonoA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void Mono_To_MonoA(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGBA_To_Mono(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void RGB_To_Mono(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void MonoA_To_Mono(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD24_to_BD32(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD16_to_BD32(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD8_to_BD32(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD32_to_BD24(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD16_to_BD24(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD8_to_BD24(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD32_to_BD16(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD24_to_BD16(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD8_to_BD16(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD32_to_BD8(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD24_to_BD8(UInt_64 newSize, Byte* buffer) const;
|
||||
|
||||
void BD16_to_BD8(UInt_64 newSize, Byte* buffer) const;
|
||||
};
|
||||
}
|
48
include/ehs/io/img/ImgCodec.h
Normal file
48
include/ehs/io/img/ImgCodec.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/io/File.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Img;
|
||||
|
||||
class ImgCodec
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashExt;
|
||||
Str_8 ext;
|
||||
Endianness endianness;
|
||||
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*);
|
||||
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*);
|
||||
|
||||
public:
|
||||
ImgCodec();
|
||||
|
||||
ImgCodec(Str_8 id, Str_8 ext, const Endianness end,
|
||||
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*),
|
||||
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*));
|
||||
|
||||
ImgCodec(ImgCodec&& codec) noexcept;
|
||||
|
||||
ImgCodec(const ImgCodec& codec);
|
||||
|
||||
ImgCodec& operator=(ImgCodec&& codec) noexcept;
|
||||
|
||||
ImgCodec& operator=(const ImgCodec& codec);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashExt() const;
|
||||
|
||||
Str_8 GetExt() const;
|
||||
|
||||
Endianness GetEndianness() const;
|
||||
|
||||
bool Encode(Serializer<UInt_64>& out, const Img* in) const;
|
||||
|
||||
bool Decode(Serializer<UInt_64>& in, Img* out) const;
|
||||
};
|
||||
}
|
51
include/ehs/io/img/PNG.h
Normal file
51
include/ehs/io/img/PNG.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "PNG_Chunk.h"
|
||||
#include "Img.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class PNG
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Array<PNG_Chunk> chunks;
|
||||
|
||||
public:
|
||||
PNG();
|
||||
|
||||
PNG(const Str_8& filePath);
|
||||
|
||||
PNG(const Str_8& id, Serializer<UInt_64>& data);
|
||||
|
||||
PNG(const PNG& png);
|
||||
|
||||
PNG& operator=(const PNG& png);
|
||||
|
||||
bool HasChunk(const UInt_64 hashId) const;
|
||||
|
||||
bool HasChunk(const Str_8& id) const;
|
||||
|
||||
PNG_Chunk* GetChunk(const UInt_64 hashId);
|
||||
|
||||
PNG_Chunk* GetChunk(const Str_8& id);
|
||||
|
||||
static bool IsPNG(Serializer<UInt_32>& data);
|
||||
|
||||
static void FilterNone(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterSub(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterUp(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterAverage(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
static void FilterPaeth(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
|
||||
|
||||
private:
|
||||
static Byte PaethPredictor(const Byte a, const Byte b, const Byte c);
|
||||
};
|
||||
}
|
34
include/ehs/io/img/PNG_Chunk.h
Normal file
34
include/ehs/io/img/PNG_Chunk.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class PNG_Chunk
|
||||
{
|
||||
private:
|
||||
Str_8 id;
|
||||
UInt_64 hashId;
|
||||
Serializer<UInt_64> data;
|
||||
Byte crc[4];
|
||||
|
||||
public:
|
||||
PNG_Chunk();
|
||||
|
||||
PNG_Chunk(const Str_8& id, const Serializer<UInt_64>& data, const Byte crc[4]);
|
||||
|
||||
PNG_Chunk(const PNG_Chunk& chunk);
|
||||
|
||||
PNG_Chunk& operator=(const PNG_Chunk& chunk);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
Serializer<UInt_64>* GetData();
|
||||
|
||||
const unsigned char* GetCRC() const;
|
||||
};
|
||||
}
|
40
include/ehs/io/model/AnimBone.h
Normal file
40
include/ehs/io/model/AnimBone.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "KeyFrame.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class AnimBone
|
||||
{
|
||||
private:
|
||||
UInt_8 boneId;
|
||||
Array<KeyFrame> keyFrames;
|
||||
|
||||
public:
|
||||
AnimBone();
|
||||
|
||||
AnimBone(const UInt_8 boneId);
|
||||
|
||||
AnimBone(const UInt_8 boneId, const UInt_64 size);
|
||||
|
||||
AnimBone(const UInt_8 boneId, Array<KeyFrame> keyFrames);
|
||||
|
||||
AnimBone(AnimBone&& anim) noexcept;
|
||||
|
||||
AnimBone(const AnimBone& anim);
|
||||
|
||||
AnimBone& operator=(AnimBone&& anim) noexcept;
|
||||
|
||||
AnimBone& operator=(const AnimBone& anim);
|
||||
|
||||
UInt_8 GetBoneId() const;
|
||||
|
||||
Array<KeyFrame> GetKeyFrames() const;
|
||||
|
||||
Array<KeyFrame>& GetKeyFrames();
|
||||
|
||||
float GetPrevAndNext(KeyFrame& prev, KeyFrame& next, const float elapsed) const;
|
||||
};
|
||||
}
|
49
include/ehs/io/model/Animation.h
Normal file
49
include/ehs/io/model/Animation.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "AnimBone.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Animation
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
float duration;
|
||||
Array<AnimBone> animated;
|
||||
|
||||
public:
|
||||
Animation();
|
||||
|
||||
Animation(Str_8 id, const float duration);
|
||||
|
||||
Animation(Str_8 id, const float duration, UInt_64 size);
|
||||
|
||||
Animation(Str_8 id, const float duration, Array<AnimBone> animated);
|
||||
|
||||
Animation(Animation&& anim) noexcept;
|
||||
|
||||
Animation(const Animation& anim);
|
||||
|
||||
Animation& operator=(Animation&& anim) noexcept;
|
||||
|
||||
Animation& operator=(const Animation& anim);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
float GetDuration() const;
|
||||
|
||||
Array<AnimBone> GetAnimated() const;
|
||||
|
||||
Array<AnimBone>& GetAnimated();
|
||||
|
||||
Array<Mat4_f> Interpolate(const UInt_64 boneCount, const float elapsed) const;
|
||||
};
|
||||
}
|
73
include/ehs/io/model/Bone.h
Normal file
73
include/ehs/io/model/Bone.h
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Quat.h"
|
||||
#include "ehs/Mat4.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Bone
|
||||
{
|
||||
private:
|
||||
UInt_64 hashName;
|
||||
Str_8 name;
|
||||
UInt_8 id;
|
||||
Mat4_f animTrans;
|
||||
Mat4_f localBindTrans;
|
||||
Mat4_f invBindTrans;
|
||||
Array<Bone> children;
|
||||
|
||||
public:
|
||||
Bone();
|
||||
|
||||
Bone(Str_8 name, UInt_8 id, const Mat4_f& localBindTrans, const Mat4_f& invBindTrans);
|
||||
|
||||
Bone(Bone&& bone) noexcept;
|
||||
|
||||
Bone(const Bone& bone);
|
||||
|
||||
Bone& operator=(Bone&& bone) noexcept;
|
||||
|
||||
Bone& operator=(const Bone& bone);
|
||||
|
||||
UInt_64 GetHashName() const;
|
||||
|
||||
void SetName(Str_8 newId);
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_8 GetId() const;
|
||||
|
||||
void SetAnimTrans(const Mat4_f& newTrans);
|
||||
|
||||
Mat4_f GetAnimTrans() const;
|
||||
|
||||
void GetAnimTransRec(Array<Mat4_f>& output) const;
|
||||
|
||||
Mat4_f GetLocalBindTrans() const;
|
||||
|
||||
Mat4_f GetInvBindTrans() const;
|
||||
|
||||
UInt_8 GetBoneCount() const;
|
||||
|
||||
bool HasBone(UInt_64 hashName, UInt_8 id) const;
|
||||
|
||||
bool HasBone(UInt_64 hashName) const;
|
||||
|
||||
bool HasBone(UInt_8 id) const;
|
||||
|
||||
bool AddBone(Bone child);
|
||||
|
||||
const Bone* GetBone(UInt_64 hashName) const;
|
||||
|
||||
Bone* GetBone(UInt_64 hashName);
|
||||
|
||||
const Bone* GetBone(UInt_8 id) const;
|
||||
|
||||
Bone* GetBone(UInt_8 id);
|
||||
|
||||
const Array<Bone>& GetChildren() const;
|
||||
|
||||
Array<Bone>& GetChildren();
|
||||
};
|
||||
}
|
55
include/ehs/io/model/KeyFrame.h
Normal file
55
include/ehs/io/model/KeyFrame.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/Vec3.h"
|
||||
#include "ehs/Quat.h"
|
||||
#include "ehs/Mat4.h"
|
||||
#include "PropertyChange.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class KeyFrame
|
||||
{
|
||||
private:
|
||||
float num;
|
||||
float timeStamp;
|
||||
Vec3_f pos;
|
||||
Quat_f rot;
|
||||
Vec3_f scale;
|
||||
Mat4_f trans;
|
||||
|
||||
public:
|
||||
KeyFrame();
|
||||
|
||||
KeyFrame(const float num, const float timeStamp, const Vec3_f& pos, const Quat_f& rot, const Vec3_f& scale);
|
||||
|
||||
KeyFrame(const float num, const float timeStamp);
|
||||
|
||||
KeyFrame(const KeyFrame& kf);
|
||||
|
||||
KeyFrame& operator=(const KeyFrame& kf);
|
||||
|
||||
float GetNum() const;
|
||||
|
||||
float GetTimeStamp() const;
|
||||
|
||||
void SetPos(const Vec3_f& newPos);
|
||||
|
||||
Vec3_f GetPos() const;
|
||||
|
||||
void SetRot(const Quat_f& newRot);
|
||||
|
||||
Quat_f GetRot() const;
|
||||
|
||||
void SetScale(const Vec3_f& newScale);
|
||||
|
||||
Vec3_f GetScale() const;
|
||||
|
||||
void CalculateTransform();
|
||||
|
||||
Mat4_f GetTrans() const;
|
||||
|
||||
static Mat4_f Interpolate(const KeyFrame& prev, const KeyFrame& next, const float percentage);
|
||||
};
|
||||
}
|
80
include/ehs/io/model/Mesh.h
Normal file
80
include/ehs/io/model/Mesh.h
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "Vertex.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Mesh final : public BaseObj
|
||||
{
|
||||
protected:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
Array<Vertex_f> vertices;
|
||||
Array<UInt_32> indices;
|
||||
|
||||
public:
|
||||
Mesh();
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices, Array<UInt_32> indices);
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices);
|
||||
|
||||
Mesh(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh(const Mesh& mesh);
|
||||
|
||||
Mesh& operator=(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh& operator=(const Mesh& mesh);
|
||||
|
||||
void Release();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
void SetVertices(const Array<Vertex_f>& newVertices);
|
||||
|
||||
const Array<Vertex_f>& GetVertices() const;
|
||||
|
||||
Array<Vertex_f>& GetVertices();
|
||||
|
||||
void SetIndices(const Array<UInt_32>& newIndices);
|
||||
|
||||
bool HasIndices() const;
|
||||
|
||||
const Array<UInt_32>& GetIndices() const;
|
||||
|
||||
Array<UInt_32>& GetIndices();
|
||||
|
||||
void Calculate();
|
||||
|
||||
private:
|
||||
static void Calculate(Vertex_f& vert1, Vertex_f& vert2, Vertex_f& vert3);
|
||||
};
|
||||
|
||||
const Mesh portraitGui("PortraitGui",
|
||||
{
|
||||
{{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
|
||||
{{0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
|
||||
{{1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
|
||||
{{1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
|
||||
},
|
||||
{0, 1, 2, 3, 2, 1}
|
||||
);
|
||||
|
||||
const Mesh portrait("Portrait",
|
||||
{
|
||||
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
|
||||
{{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
|
||||
},
|
||||
{0, 1, 2, 3, 2, 1}
|
||||
);
|
||||
}
|
80
include/ehs/io/model/Model.h
Normal file
80
include/ehs/io/model/Model.h
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Array.h"
|
||||
#include "ehs/io/File.h"
|
||||
#include "Mesh.h"
|
||||
#include "Bone.h"
|
||||
#include "Animation.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class ModelEncoding : UInt_8
|
||||
{
|
||||
EHM
|
||||
};
|
||||
|
||||
class Model : public BaseObj
|
||||
{
|
||||
protected:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
Array<Mesh> meshes;
|
||||
Bone skeleton;
|
||||
Array<Animation> animations;
|
||||
|
||||
public:
|
||||
Model();
|
||||
|
||||
Model(const Str_8& filePath);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton, Array<Animation> animations);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes);
|
||||
|
||||
Model(Model&& model) noexcept;
|
||||
|
||||
Model(const Model& model) = default;
|
||||
|
||||
Model& operator=(Model&& model) noexcept;
|
||||
|
||||
Model& operator=(const Model& model) = default;
|
||||
|
||||
void Release();
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
const Array<Mesh>& GetMeshes() const;
|
||||
|
||||
Array<Mesh>& GetMeshes();
|
||||
|
||||
Mesh* GetMesh(UInt_64 inHashId);
|
||||
|
||||
Mesh* GetMesh(const Str_8& inId);
|
||||
|
||||
const Bone& GetSkeleton() const;
|
||||
|
||||
Bone& GetSkeleton();
|
||||
|
||||
Animation* GetAnimation(UInt_64 inHashId);
|
||||
|
||||
const Array<Animation>& GetAnimations() const;
|
||||
|
||||
Array<Animation>& GetAnimations();
|
||||
|
||||
void Calculate();
|
||||
|
||||
void Export(const Str_8& filePath, ModelEncoding encoding);
|
||||
|
||||
private:
|
||||
void ToEHM(File& file);
|
||||
|
||||
void FromEHM(File& file);
|
||||
};
|
||||
}
|
32
include/ehs/io/model/PropertyChange.h
Normal file
32
include/ehs/io/model/PropertyChange.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class ChangeType : UInt_8
|
||||
{
|
||||
X_AXIS_POS,
|
||||
Y_AXIS_POS,
|
||||
Z_AXIS_POS,
|
||||
X_AXIS_SCALE,
|
||||
Y_AXIS_SCALE,
|
||||
Z_AXIS_SCALE,
|
||||
X_AXIS_ROT,
|
||||
Y_AXIS_ROT,
|
||||
Z_AXIS_ROT,
|
||||
W_AXIS_ROT,
|
||||
INVALID
|
||||
};
|
||||
|
||||
class PropertyChange
|
||||
{
|
||||
public:
|
||||
ChangeType type;
|
||||
float value;
|
||||
|
||||
PropertyChange();
|
||||
|
||||
PropertyChange(const ChangeType type, const float value);
|
||||
};
|
||||
}
|
50
include/ehs/io/model/Vertex.h
Normal file
50
include/ehs/io/model/Vertex.h
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Vec4.h"
|
||||
#include "ehs/Vec3.h"
|
||||
#include "ehs/Vec2.h"
|
||||
#include "ehs/Color4.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
template<typename T = float>
|
||||
class Vertex
|
||||
{
|
||||
public:
|
||||
Vec3<T> pos;
|
||||
Vec3<T> normal;
|
||||
Vec2<T> uv;
|
||||
Vec3<T> tan;
|
||||
Vec3<T> bTan;
|
||||
Vec4<UInt_8> bones;
|
||||
Vec4<float> weights;
|
||||
|
||||
Vertex() = default;
|
||||
|
||||
Vertex(const Vec3<T>& pos)
|
||||
: pos(pos), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vec3<T>& pos, const Vec3<T>& normal)
|
||||
: pos(pos), normal(normal), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vec3<T>& pos, const Vec3<T>& normal, const Vec2<T>& uv)
|
||||
: pos(pos), normal(normal), uv(uv), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vertex& vert)
|
||||
: pos(vert.pos), normal(vert.normal), uv(vert.uv), bones(vert.bones), weights(vert.weights)
|
||||
{
|
||||
}
|
||||
|
||||
Vertex& operator=(const Vertex& vert) = default;
|
||||
};
|
||||
|
||||
typedef Vertex<double> Vertex_d;
|
||||
typedef Vertex<float> Vertex_f;
|
||||
}
|
112
include/ehs/io/socket/BaseTCP.h
Normal file
112
include/ehs/io/socket/BaseTCP.h
Normal file
@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "Request.h"
|
||||
#include "Response.h"
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class BaseTCP
|
||||
{
|
||||
protected:
|
||||
AddrType addrType;
|
||||
Str_8 localAddr;
|
||||
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/ehs/io/socket/BaseUDP.h
Normal file
54
include/ehs/io/socket/BaseUDP.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class BaseUDP
|
||||
{
|
||||
protected:
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
bool bound;
|
||||
|
||||
public:
|
||||
virtual ~BaseUDP() = default;
|
||||
|
||||
BaseUDP();
|
||||
|
||||
BaseUDP(AddrType type);
|
||||
|
||||
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(AddrType type, const Str_8& address, UInt_16 port) = 0;
|
||||
|
||||
virtual UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) = 0;
|
||||
|
||||
virtual UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) = 0;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
virtual void SetBlocking(bool blocking) = 0;
|
||||
|
||||
virtual bool IsBlocking() const = 0;
|
||||
|
||||
AddrType GetLocalAddressType() const;
|
||||
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
UInt_16 GetLocalPort() const;
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
};
|
||||
}
|
14
include/ehs/io/socket/DNS.h
Normal file
14
include/ehs/io/socket/DNS.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class DNS
|
||||
{
|
||||
public:
|
||||
static Str_8 Resolve(const AddrType addrType, const Str_8& hostName);
|
||||
};
|
||||
}
|
164
include/ehs/io/socket/Request.h
Normal file
164
include/ehs/io/socket/Request.h
Normal file
@ -0,0 +1,164 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/json/Json.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class Verb
|
||||
{
|
||||
POST,
|
||||
GET,
|
||||
PUT,
|
||||
DEL
|
||||
};
|
||||
|
||||
class Request
|
||||
{
|
||||
private:
|
||||
Verb verb;
|
||||
Str_8 rsrc;
|
||||
Vector<Str_8> queries;
|
||||
Vector<Str_8> header;
|
||||
ContentType cType;
|
||||
Str_8 body;
|
||||
|
||||
public:
|
||||
/// Default member initialization.
|
||||
Request();
|
||||
|
||||
/// Initializes this request with a given verb and URI resource.
|
||||
/// @param [in] verb The type of request to make.
|
||||
/// @param [in] rsrc The URI endpoint to make the request at.
|
||||
Request(const Verb verb, const Str_8& rsrc);
|
||||
|
||||
/// Initializes this request with the raw request data.
|
||||
/// @param [in] data The C-style string of the request.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
Request(const char* data, const UInt_64 size);
|
||||
|
||||
/// Initializes this request with the raw request data.
|
||||
/// @param [in] data The string of the request.
|
||||
Request(const Str_8& data);
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] req The object to copy from.
|
||||
Request(const Request& req) = default;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] req The object to copy from.
|
||||
/// @returns The request that has been assigned to.
|
||||
Request& operator=(const Request& req);
|
||||
|
||||
/// Retrieves the verb for the request.
|
||||
/// @returns The result.
|
||||
Verb GetVerb() const;
|
||||
|
||||
/// Sets the content type for the body.
|
||||
/// @param [in] cType The content type to use.
|
||||
void SetContentType(const ContentType cType);
|
||||
|
||||
/// Retrieves the content type for the body.
|
||||
/// @returns The result.
|
||||
ContentType GetContentType() const;
|
||||
|
||||
/// Sets the URI resource.
|
||||
/// @param [in] rsrc The resource.
|
||||
void SetResource(const Str_8& rsrc);
|
||||
|
||||
/// Retrieves the URI resource.
|
||||
/// @returns The result.
|
||||
Str_8 GetResource() const;
|
||||
|
||||
/// Adds a query variable to the URI.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddQuery(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Retrieves a query variable from the URI.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the query variable. Empty if it was not found.
|
||||
Str_8 GetQuery(const Str_8& var);
|
||||
|
||||
/// Retrieves all the query variables from the URI in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetQueries() const;
|
||||
|
||||
/// A helper method to automatically add the required header variables for basic authentication.
|
||||
/// @param [in] id The username or id.
|
||||
/// @param [in] secret The secret given by an API.
|
||||
void BasicAuth(const Str_8& id, const Str_8& secret);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bearer authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
void BearerAuth(const Str_8& token);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bearer authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
/// @param [in] clientId The client id given by an API.
|
||||
void BearerAuth(const Str_8& token, const Str_8& clientId);
|
||||
|
||||
/// A helper method to automatically add the required header variables for bot authentication.
|
||||
/// @param [in] token The token given by an API.
|
||||
void BotAuth(const Str_8& token);
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToHeader(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Retrieves a header variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the header variable. Empty if it was not found.
|
||||
Str_8 GetHeader(const Str_8& var) const;
|
||||
|
||||
/// Retrieves all the header variables in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetHeader() const;
|
||||
|
||||
/// Adds a body variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToBody(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Adds a value to the body.
|
||||
/// @param [in] data The value to add.
|
||||
void AddToBody(const Str_8& data);
|
||||
|
||||
/// Sets the entire body.
|
||||
/// @param [in] body The body to use.
|
||||
void SetBody(const Str_8& body);
|
||||
|
||||
/// Retrieves a body variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the body variable. Empty if it was not found.
|
||||
Str_8 GetVar(const Str_8& var) const;
|
||||
|
||||
/// Retrieves the entire body.
|
||||
/// @returns The result.
|
||||
Str_8 GetBody() const;
|
||||
|
||||
/// Retrieves the entire body as a Json.
|
||||
/// @returns The result.
|
||||
Json GetJson() const;
|
||||
|
||||
/// Forms the raw result of the request to be sent.
|
||||
/// @returns The result.
|
||||
Str_8 FormResult() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
static Str_8 VerbToStr(const Verb verb);
|
||||
|
||||
static Str_8 ContentTypeToStr(const ContentType cType);
|
||||
|
||||
static ContentType StrToContentType(const Str_8& value);
|
||||
|
||||
void ReadData(const Str_8& data);
|
||||
|
||||
};
|
||||
}
|
127
include/ehs/io/socket/Response.h
Normal file
127
include/ehs/io/socket/Response.h
Normal file
@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Vector.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/json/Json.h"
|
||||
#include "Socket.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class Response
|
||||
{
|
||||
private:
|
||||
UInt_32 code;
|
||||
Str_8 server;
|
||||
ContentType cType;
|
||||
Vector<Str_8> header;
|
||||
Str_8 body;
|
||||
|
||||
public:
|
||||
/// Default member initialization.
|
||||
Response();
|
||||
|
||||
/// Initializes this response with a given code and server identifier.
|
||||
/// @param [in] code The code to give.
|
||||
/// @param [in] server The server identifier.
|
||||
Response(const UInt_32 code, const Str_8& server);
|
||||
|
||||
/// Initializes this response with the raw response data.
|
||||
/// @param [in] data The C-style string of the response.
|
||||
/// @param [in] size The size of the given C-style string.
|
||||
Response(const char* data, const UInt_64 size);
|
||||
|
||||
/// Initializes this response with the raw response data.
|
||||
/// @param [in] data The string of the response.
|
||||
Response(const Str_8& data);
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] res The object to copy from.
|
||||
Response(const Response& res) = default;
|
||||
|
||||
/// Copies members from another object of the same type.
|
||||
/// @param [in] res The object to copy from.
|
||||
/// @returns The response that has been assigned to.
|
||||
Response& operator=(const Response& res);
|
||||
|
||||
/// Sets the response code to send to the endpoint.
|
||||
/// @param [in] code The code for success, error or info.
|
||||
void SetCode(const UInt_32 code);
|
||||
|
||||
/// Retrieves the response code.
|
||||
/// @returns The result.
|
||||
UInt_32 GetCode() const;
|
||||
|
||||
/// Sets the server identifier.
|
||||
/// @param [in] server The server identifier to use.
|
||||
void SetServer(const Str_8& server);
|
||||
|
||||
/// Retrieves the server identifier.
|
||||
/// @returns The result.
|
||||
Str_8 GetServer() const;
|
||||
|
||||
/// Sets the content type for the body.
|
||||
/// @param [in] cType The content type to use.
|
||||
void SetContentType(const ContentType cType);
|
||||
|
||||
/// Retrieves the content type for the body.
|
||||
/// @returns The result.
|
||||
ContentType GetContentType() const;
|
||||
|
||||
/// Adds a header variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToHeader(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Retrieves a header variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the header variable. Empty if it was not found.
|
||||
Str_8 GetHeader(const Str_8& var) const;
|
||||
|
||||
/// Retrieves all the header variables in a vector object.
|
||||
/// @returns The result.
|
||||
Vector<Str_8> GetHeader() const;
|
||||
|
||||
/// Adds a body variable.
|
||||
/// @param [in] var The variable identifier.
|
||||
/// @param [in] value The value of the variable.
|
||||
void AddToBody(const Str_8& var, const Str_8& value);
|
||||
|
||||
/// Adds a value to the body.
|
||||
/// @param [in] data The value to add.
|
||||
void AddToBody(const Str_8& data);
|
||||
|
||||
/// Sets the entire body.
|
||||
/// @param [in] body The body to use.
|
||||
void SetBody(const Str_8& body);
|
||||
|
||||
/// Retrieves a body variable.
|
||||
/// @param [in] var The variable identifier to look for.
|
||||
/// @returns The value of the body variable. Empty if it was not found.
|
||||
Str_8 GetVar(const Str_8& var) const;
|
||||
|
||||
/// Retrieves the entire body.
|
||||
/// @returns The result.
|
||||
Str_8 GetBody() const;
|
||||
|
||||
/// Retrieves the entire body as a Json.
|
||||
/// @returns The result.
|
||||
Json GetJson() const;
|
||||
|
||||
/// Forms the raw result of the response to be sent.
|
||||
/// @returns The result.
|
||||
Str_8 FormResult() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
static Str_8 CodeToStr(const UInt_32 code);
|
||||
|
||||
static Str_8 ContentTypeToStr(const ContentType cType);
|
||||
|
||||
static ContentType StrToContentType(const Str_8& value);
|
||||
|
||||
void ReadData(const Str_8& data);
|
||||
|
||||
};
|
||||
}
|
56
include/ehs/io/socket/SSL.h
Normal file
56
include/ehs/io/socket/SSL.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "TCP.h"
|
||||
#include "Request.h"
|
||||
#include "Response.h"
|
||||
|
||||
typedef struct ssl_ctx_st SSL_CTX;
|
||||
typedef struct ssl_st SSL;
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
/// A class for handling the HTTP(S) TCP socket layer.
|
||||
class SSL : public TCP
|
||||
{
|
||||
private:
|
||||
SSL_CTX* ctx;
|
||||
::SSL* sslHdl;
|
||||
|
||||
public:
|
||||
~SSL() override;
|
||||
|
||||
SSL();
|
||||
|
||||
SSL(const AddrType type);
|
||||
|
||||
SSL(TCP&& tcp) noexcept;
|
||||
|
||||
SSL(const TCP& tcp);
|
||||
|
||||
SSL(const SSL& ssl);
|
||||
|
||||
SSL& operator=(const SSL& ssl);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void Release() override;
|
||||
|
||||
void Bind(const Str_8& address, unsigned short port) override;
|
||||
|
||||
SSL* Accept() override;
|
||||
|
||||
void Connect(const Str_8& address, const UInt_16 port) override;
|
||||
|
||||
UInt_64 Send(const Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
UInt_64 Receive(Byte* const buffer, const UInt_32 size) override;
|
||||
|
||||
void UseCertificate(const Byte* data, const UInt_64 size);
|
||||
|
||||
void UsePrivateKey(const Byte* data, const UInt_64 size);
|
||||
|
||||
bool IsValid();
|
||||
};
|
||||
}
|
51
include/ehs/io/socket/Socket.h
Normal file
51
include/ehs/io/socket/Socket.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef EHS_IPV4_HEADER
|
||||
#define EHS_IPV4_HEADER 60
|
||||
#endif
|
||||
|
||||
#ifndef EHS_IPV6_HEADER
|
||||
#define EHS_IPV6_HEADER 40
|
||||
#endif
|
||||
|
||||
#ifndef EHS_UDP_HEADER
|
||||
#define EHS_UDP_HEADER 8
|
||||
#endif
|
||||
|
||||
#ifndef EHS_IPV4_UDP_PAYLOAD
|
||||
#define EHS_IPV4_UDP_PAYLOAD (EHS_UINT_16_MAX - EHS_IPV4_HEADER - EHS_UDP_HEADER)
|
||||
#endif
|
||||
|
||||
#ifndef EHS_IPV6_UDP_PAYLOAD
|
||||
#define EHS_IPV6_UDP_PAYLOAD (EHS_UINT_16_MAX - EHS_IPV6_HEADER - EHS_UDP_HEADER)
|
||||
#endif
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class AddrType
|
||||
{
|
||||
IPV6,
|
||||
IPV4
|
||||
};
|
||||
|
||||
enum class ContentType
|
||||
{
|
||||
APP_MULTIPART_FORMDATA,
|
||||
APP_FORMURLENCODED,
|
||||
APP_JAVASCRIPT,
|
||||
APP_JSON,
|
||||
APP_XML,
|
||||
TEXT_PLAIN,
|
||||
TEXT_HTML,
|
||||
TEXT_XML,
|
||||
NONE
|
||||
};
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
typedef UInt_64 Socket;
|
||||
#define EHS_INVALID_SOCKET EHS_UINT_64_MAX
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
typedef SInt_32 Socket;
|
||||
#define EHS_INVALID_SOCKET (SInt_32)0xffffffff
|
||||
#endif
|
||||
}
|
7
include/ehs/io/socket/TCP.h
Normal file
7
include/ehs/io/socket/TCP.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef EHS_OS_WINDOWS
|
||||
#include "TCP_W32.h"
|
||||
#else
|
||||
#include "TCP_BSD.h"
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user