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

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

View File

@ -0,0 +1,135 @@
name: Build & Release
run-name: ${{ gitea.actor }} is testing out Gitea Actions
on:
push:
tags:
- "v*"
jobs:
Windows-AMD64-Build:
runs-on: windows-x86_64
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Generating Documentation
run: |
doxygen ehs-docs-config.doxyfile
- name: Building/Compiling/Installing Project
run: |
cd ${{ gitea.workspace }}
cmake -A x64 -DCMAKE_BUILD_TYPE=Release --preset=default .
cd build
cmake --build . --config Release
- name: Creating Appropriate Directories
run: |
cd ${{ gitea.workspace }}
mkdir bin
mv build/Release/StrToHash.exe bin
mv build/Release/zlib1.dll bin
mkdir lib
mv build/Release/EHS.lib lib
- name: Zipping Binaries
run: |
cd ${{ gitea.workspace }}
tar -a -c -f ehs-windows-amd64.zip include bin lib docs LICENSE README.md
- 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-windows-amd64.zip
api_key: '${{secrets.RELEASE_TOKEN}}'
Linux-AMD64-Build:
runs-on: linux-x86_64
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Installing Dependencies
run: |
sudo pacman -S --noconfirm doxygen zip alsa-lib libxcb xcb-util-cursor
- name: Generating Documentation
run: |
doxygen ehs-docs-config.doxyfile
- name: Building/Compiling/Installing Project
run: |
cd ${{ gitea.workspace }}
cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
cmake --build . --config Release
cmake --install .
- 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 docs LICENSE RADME.md
- 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 doxygen zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev
- name: Generating Documentation
run: |
doxygen ehs-docs-config.doxyfile
- name: Building/Compiling/Installing Project
run: |
cd ${{ gitea.workspace }}
cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB .
cmake --build . --config Release
cmake --install .
- 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 docs LICENSE README.md
- 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
View 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/

256
CMakeLists.txt Normal file
View File

@ -0,0 +1,256 @@
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/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}/.local")
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 ()

12
CMakePresets.json Normal file
View File

@ -0,0 +1,12 @@
{
"version": 3,
"configurePresets": [
{
"name": "default",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}

232
LICENSE Normal file
View File

@ -0,0 +1,232 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS
0. Definitions.
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on the Program.
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
7. Additional Terms.
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
Event Horizon Suite
Copyright (C) 2024 EventHorizonStudio
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
Event Horizon Suite Copyright (C) 2024 EventHorizonStudio
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/philosophy/why-not-lgpl.html>.

102
README.md Normal file
View File

@ -0,0 +1,102 @@
# About
Much like boost.io this library is a replacement of the standard C/C++ libraries. It provides most features needed when
designing applications in a cross-platform manner. The goal for this project is for it to be compiled and run on
anything which means embedded hardware support.
This project does not fully follow the C++ standard.
### Features
- Audio IO/Processing/Manipulation
- Image Processing/Manipulation
- 3D Model & Mesh Processing/Manipulation
- File IO
- Basic File Monitoring
- Console IO
- 2/3/4D Vectors
- 2x2/3x3/4x4 Matrices
- Hardware/Software Level Math Functions
- Smart Pointers
- Threads
- Mutexes
- Semaphores
- CPU information and features at runtime
- HTTP(S) Sockets
- TCP Socket
- UDP Socket
- COM (Serial) IO
- UTF_8/16/32 Character Encoding
- Spotify Integration
- Twitch Integration
- Json Parsing/Writing
- User Friendly HID Input
- Basic Garbage Collector
- Linked List
- Array
- Vector
- Asynchronous Task System
- URI Parsing
### Supported Architectures
- AMD64
- AARCH64
### Supported Operating Systems
- Windows
- Linux
# Compiling
## Prerequisites
### Windows
- [Visual Studio Community](https://visualstudio.microsoft.com/vs/community/)
- [Netwide Assembler](https://www.nasm.us/)
- [CMake](https://cmake.org/)
- [vcpkg](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-cmd)
### Linux
- **Arch Linux**: `sudo pacman -S gcc nasm cmake alsa-lib libxcb xcb-util-cursor`
- **Debian Linux**: `sudo apt install gcc nasm cmake libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev`
For building on the Raspberry Pi instead of the Netwide Assembler (NASM), GCC's Assembler is used.
## Building
### Linux
1. `cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB /path/to/source`
2. `cmake --build /path/to/build --config Release`
The `LINUX_WINDOW_SYSTEM` variable in the first step can be either `XCB` for the X Window System or `Wayland` for the
Wayland Window System. Wayland support is currently not fully supported yet, use only `XCB`.
### Windows
1. `cmake -A x64 -DCMAKE_BUILD_TYPE=Release --preset=default .`
2. `cmake --build build --config Release`
# Simple Example
```cpp
#include <ehs/EHS.h>
#include <ehs/io/Console.h>
ehs::Int_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
{
// Simple identifying meta-data for the logger.
*appName = "Simple Example App"; // The application's name
*appVerId = "Release"; // The app's version prefix; i.e. Alpha, Beta or Release as an example.
*appVer = {1, 0, 0}; // The app's version major, minor and patch number.
ehs::Console::Write_8("How old are you?"); // Write to the console in UTF_8 character encoding.
ehs::Str_8 response = ehs::Console::Read_8(); // Read from the console in UTF_8 character encoding.
if (!response.IsNum())
{
ehs::Console::Clear(); // Clear the console's buffer.
return Main(appName, appVerId, appVer); // Repeat process if given response is not a number.
}
ehs::UInt_8 age = response.ToDecimal<ehs::UInt_8>(); // Converts the string number into a number based primitive.
ehs::Console::Write("Your age is " + ehs::Str_8::FromNum(age) + "."); // Write the console with the age converted back to string.
return 0;
}
```

2854
ehs-docs-config.doxyfile Normal file

File diff suppressed because it is too large Load Diff

19
include/ehs/Anchor.h Normal file
View 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
};
}

435
include/ehs/Array.h Normal file
View File

@ -0,0 +1,435 @@
#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);
}
/// Inserts a value at the specified index.
/// @param [in] index The index to insert the value at.
/// @param [in] value The value to add.
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;
}
/// Removes a value at the specified index.
/// @param [in] index The index to remove a value.
/// @returns The value that was removed.
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();
}
/// Releases the resources of the array.
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;
}
/// Retrieves the index at the end of the array.
/// @returns The index.
N End() const
{
return size - 1;
}
};
}

24
include/ehs/Base64.h Normal file
View 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);
};
}

74
include/ehs/BaseObj.h Normal file
View File

@ -0,0 +1,74 @@
#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;
/// Retrieves the class hierarchy.
/// @returns The hierarchy array.
const Type* GetHierarchy() const;
/// Retrieves the class hierarchy size.
/// @returns The hierarchy size.
UInt_64 GetHierarchySize() const;
/// Checks if this class derives from another.
/// @param [in] typeHashId The type hash id to look for.
/// @returns True if found.
bool HasType(UInt_64 typeHashId) const;
/// Checks if this class derives from another.
/// @param [in] typeId The type id to look for.
/// @returns True if found.
bool HasType(const Char_8* typeId) const;
/// Retrieves the top class' information.
/// @returns The Type object containing the class information.
Type GetType() const;
/// Retrieves the top class' string name, size.
/// @returns The name size.
UInt_64 GetTypeIdSize() const;
/// Retrieves the top class' string name.
/// @returns The name.
const Char_8* GetTypeId() const;
/// Retrieves the top class' hashed name.
/// @returns The hashed name.
UInt_64 GetTypeHashId() const;
/// Clones the object onto the heap.
/// @returns The cloned object.
virtual BaseObj* Clone() const;
protected:
/// Adds the class name to the class hierarchy.
/// @param [in] id The name of the class to add.
void AddType(const Char_8* id);
};
}

38
include/ehs/Color3.h Normal file
View 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
View 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
View 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
View 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(UInt_16 bitDepth);
UInt_8 ToByteDepth(DataType type);
UInt_8 ToBitDepth(DataType type);
}

10
include/ehs/Dock.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
namespace ehs
{
enum class Dock
{
NONE,
FILL
};
}

63
include/ehs/EHS.h Normal file
View 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);

View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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

File diff suppressed because it is too large Load Diff

121
include/ehs/ShdPtr.h Normal file
View 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;
}
};
}

1941
include/ehs/Str.h Normal file

File diff suppressed because it is too large Load Diff

50
include/ehs/Task.h Normal file
View 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;
};
}

65
include/ehs/Type.h Normal file
View File

@ -0,0 +1,65 @@
#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();
/// Constructs the object with the given class name.
/// @param [in] id The class name.
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;
/// Retrieves the name size.
/// @returns The size.
UInt_64 GetSize() const;
/// Retrieves the name.
/// @returns The name.
const Char_8* GetId() const;
/// Retrieves the hashed name.
/// @returns The hashed name.
UInt_64 GetHashId() const;
/// Whether or not this object was properly constructed.
/// @returns The result.
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
View 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
}

21
include/ehs/URI.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include "EHS.h"
#include "Str.h"
namespace ehs
{
class URI
{
public:
/// Encodes specialized characters in the URI.
/// @param [in] in The URI to encode.
/// @returns The encoded URI.
static Str_8 Encode(const Str_8& in);
/// Decodes specialized characters back into their readable format.
/// @param [in] in The URI to decode.
/// @returns The decoded URI.
static Str_8 Decode(const Str_8& in);
};
}

455
include/ehs/UTF.h Normal file
View 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
View 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
View 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
View 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
View 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
View 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;
}

639
include/ehs/Vector.h Normal file
View File

@ -0,0 +1,639 @@
#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;
}
/// Retrieves the index at the end of the array.
/// @returns The index.
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;
}
}
/// Releases the resources of the vector.
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
View 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
View 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;
}
};
}

View 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
View File

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

View File

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

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

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

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

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

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

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

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

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

View File

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

View File

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

View File

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

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

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

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

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

View File

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

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

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

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

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

View File

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

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

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

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

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

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

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

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More