Compare commits
No commits in common. "main" and "feat/universal_pch" have entirely different histories.
main
...
feat/unive
180 changed files with 902 additions and 19963 deletions
|
|
@ -25,7 +25,6 @@ readability-avoid-const-params-in-decls,
|
||||||
readability-avoid-nested-conditional-operator,
|
readability-avoid-nested-conditional-operator,
|
||||||
readability-avoid-return-with-void-value,
|
readability-avoid-return-with-void-value,
|
||||||
readability-avoid-unconditional-preprocessor-if,
|
readability-avoid-unconditional-preprocessor-if,
|
||||||
readability-braces-around-statements,
|
|
||||||
readability-const-return-type,
|
readability-const-return-type,
|
||||||
readability-container-contains,
|
readability-container-contains,
|
||||||
readability-container-data-pointdr,
|
readability-container-data-pointdr,
|
||||||
|
|
@ -129,6 +128,7 @@ cppcoreguidelines-pro-type-cstyle-cast,
|
||||||
cppcoreguidelines-pro-type-member-init,
|
cppcoreguidelines-pro-type-member-init,
|
||||||
cppcoreguidelines-pro-type-reinterpret-cast,
|
cppcoreguidelines-pro-type-reinterpret-cast,
|
||||||
cppcoreguidelines-pro-type-static-cast-downcast,
|
cppcoreguidelines-pro-type-static-cast-downcast,
|
||||||
|
cppcoreguidelines-pro-type-union-access,
|
||||||
cppcoreguidelines-pro-type-vararg,
|
cppcoreguidelines-pro-type-vararg,
|
||||||
cppcoreguidelines-rvalue-reference-param-not-moved,
|
cppcoreguidelines-rvalue-reference-param-not-moved,
|
||||||
cppcoreguidelines-slicing,
|
cppcoreguidelines-slicing,
|
||||||
|
|
@ -235,10 +235,12 @@ misc-new-delete-overloads,
|
||||||
misc-misplaced-const,
|
misc-misplaced-const,
|
||||||
misc-misleading-identifier,
|
misc-misleading-identifier,
|
||||||
misc-misleading-bidirectional,
|
misc-misleading-bidirectional,
|
||||||
|
misc-include-cleaner,
|
||||||
misc-header-include-cycle,
|
misc-header-include-cycle,
|
||||||
misc-definitions-in-headers,
|
misc-definitions-in-headers,
|
||||||
misc-coroutine-hostile-raii,
|
misc-coroutine-hostile-raii,
|
||||||
misc-const-correctness,
|
misc-const-correctness,
|
||||||
|
misc-confusable-identifiers,
|
||||||
|
|
||||||
hicpp-signed-bitwise,
|
hicpp-signed-bitwise,
|
||||||
hicpp-no-assembler,
|
hicpp-no-assembler,
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
# How wide to allow formatted cmake files
|
|
||||||
line_width: 80
|
|
||||||
|
|
||||||
# How many spaces to tab for indent
|
|
||||||
tab_size: 4
|
|
||||||
|
|
||||||
dangle_parens: true
|
|
||||||
|
|
||||||
# Additional FLAGS and KWARGS for custom commands
|
|
||||||
additional_commands:
|
|
||||||
foo:
|
|
||||||
flags: [BAR, BAZ]
|
|
||||||
kwargs:
|
|
||||||
HEADERS : '*'
|
|
||||||
SOURCES : '*'
|
|
||||||
DEPENDS : '*'
|
|
||||||
|
|
||||||
7
.cmake-format.yaml
Normal file
7
.cmake-format.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
dangle_parens: true
|
||||||
|
line_ending: unix
|
||||||
|
line_width: 120
|
||||||
|
max_pargs_hwrap: 3
|
||||||
|
separate_ctrl_name_with_space: true
|
||||||
|
separate_fn_name_with_space: false
|
||||||
|
tab_size: 4
|
||||||
155
.drone.yml
155
.drone.yml
|
|
@ -1,156 +1,13 @@
|
||||||
---
|
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: exec
|
type: docker
|
||||||
name: amd64 — msvc
|
name: linux_amd64
|
||||||
node:
|
|
||||||
environment: lina
|
|
||||||
trigger:
|
|
||||||
branch:
|
|
||||||
- main
|
|
||||||
platform:
|
platform:
|
||||||
os: windows
|
os: linux
|
||||||
arch: amd64
|
arch: amd64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: unit tests
|
|
||||||
shell: powershell
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/amd64/msvc/unit_tests.ps1
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: amd64 — gcc
|
|
||||||
trigger:
|
|
||||||
branch:
|
|
||||||
- main
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: unit tests
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/amd64/gcc/unit_tests.sh
|
|
||||||
|
|
||||||
- name: valgrind
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/amd64/gcc/valgrind.sh
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: amd64 — clang
|
|
||||||
trigger:
|
|
||||||
branch:
|
|
||||||
- main
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: code coverage
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
environment:
|
|
||||||
CODECOV_TOKEN:
|
|
||||||
from_secret: CODECOV_TOKEN
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/amd64/clang/coverage.sh
|
|
||||||
|
|
||||||
- name: leak sanitizer
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/amd64/clang/lsan.sh
|
|
||||||
|
|
||||||
- name: memory sanitizer
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/amd64/clang/msan.sh
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: static analysis
|
|
||||||
trigger:
|
|
||||||
branch:
|
|
||||||
- main
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: clang tidy
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
privileged: true
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/static_analysis/clang_tidy.sh
|
|
||||||
|
|
||||||
- name: shell check
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/static_analysis/shell_check.sh
|
|
||||||
|
|
||||||
- name: clang format
|
- name: clang format
|
||||||
image: ci:latest
|
image: alpine_amd64__clang_format
|
||||||
pull: if-not-exists
|
pull: if-not-exists
|
||||||
commands:
|
commands: $(git rev-parse --show-toplevel)/tools/ci/alpine_amd64/script.sh
|
||||||
- ./tools/ci/static_analysis/clang_format.sh
|
|
||||||
|
|
||||||
- name: cmake format
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/static_analysis/cmake_format.sh
|
|
||||||
|
|
||||||
- name: shell format
|
|
||||||
image: ci:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- ./tools/ci/static_analysis/shell_format.sh
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: documentation — development
|
|
||||||
node:
|
|
||||||
environment: ryali
|
|
||||||
trigger:
|
|
||||||
branch:
|
|
||||||
- main
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build and deploy
|
|
||||||
image: documentation:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- cd docs
|
|
||||||
- sphinx-build -M html . .
|
|
||||||
|
|
||||||
- rm -rf /light_docs_dev/*
|
|
||||||
- mv ./html/* /light_docs_dev/
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: documentation — production
|
|
||||||
node:
|
|
||||||
environment: ryali
|
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
- tag
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: build and deploy
|
|
||||||
image: documentation:latest
|
|
||||||
pull: if-not-exists
|
|
||||||
commands:
|
|
||||||
- cd docs
|
|
||||||
- mkdir generated
|
|
||||||
- touch generated/changelogs.rst
|
|
||||||
- touch generated/api.rst
|
|
||||||
- sphinx-build -M html . .
|
|
||||||
|
|
||||||
- rm -rf /light_docs/*
|
|
||||||
- mv ./html/* /light_docs/
|
|
||||||
|
|
||||||
|
|
|
||||||
88
.gitignore
vendored
88
.gitignore
vendored
|
|
@ -1,37 +1,65 @@
|
||||||
# Temp directories
|
|
||||||
.vs/
|
|
||||||
bin/
|
|
||||||
bin-obj/
|
|
||||||
build/
|
build/
|
||||||
.cache/
|
.cache/
|
||||||
|
|
||||||
# VS Files
|
# ---> C++
|
||||||
**.vcxproj**
|
# Prerequisites
|
||||||
**.sln
|
*.d
|
||||||
|
|
||||||
.codelite/
|
# Compiled Object files
|
||||||
.build-debug/
|
*.slo
|
||||||
.vimspector.json
|
*.lo
|
||||||
**.workspace
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Compiled Dynamic libraries
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Fortran module files
|
||||||
|
*.mod
|
||||||
|
*.smod
|
||||||
|
|
||||||
|
# Compiled Static libraries
|
||||||
|
*.lai
|
||||||
|
*.la
|
||||||
|
*.a
|
||||||
|
*.lib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
|
||||||
|
# ---> Rust
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# ---> CMake
|
||||||
|
CMakeLists.txt.user
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
CMakeScripts
|
||||||
|
Testing
|
||||||
Makefile
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
**/**.mk
|
install_manifest.txt
|
||||||
|
|
||||||
**/**.project
|
|
||||||
|
|
||||||
**/Engine.txt
|
|
||||||
**/GLAD.txt
|
|
||||||
**/Sandbox.txt
|
|
||||||
|
|
||||||
**/Logs/**
|
|
||||||
**/logs/**
|
|
||||||
**.ini
|
|
||||||
!**/default_gui_layout.ini
|
|
||||||
|
|
||||||
CMake/
|
|
||||||
CMakeUserPresets.json
|
|
||||||
|
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
CTestTestfile.cmake
|
||||||
|
_deps
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,21 @@
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
|
||||||
set(CMAKE_EPXORT_COMPILE_COMMANDS TRUE)
|
project("light" LANGUAGES CXX)
|
||||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
|
||||||
set(CMAKE_CXX_MODULE_STD 1)
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 4.1)
|
include(tools/cmake/preliminary.cmake)
|
||||||
project(Light)
|
include(tools/cmake/module_macros.cmake)
|
||||||
|
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/functions.cmake)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/options.cmake)
|
|
||||||
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules)
|
add_option(ENABLE_SANITIZERS "Enables fsan sanitizers")
|
||||||
|
add_option(ENABLE_STATIC_ANALYSIS "Enables clang-tidy static analysis")
|
||||||
|
|
||||||
|
find_package(benchmark REQUIRED)
|
||||||
|
find_package(GTest REQUIRED)
|
||||||
|
|
||||||
|
if(ENABLE_STATIC_ANALYSIS)
|
||||||
|
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(docs)
|
||||||
|
add_subdirectory(modules)
|
||||||
|
|
|
||||||
9
CMakeUserPresets.json
Normal file
9
CMakeUserPresets.json
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"version": 4,
|
||||||
|
"vendor": {
|
||||||
|
"conan": {}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"build/Debug/generators/CMakePresets.json"
|
||||||
|
]
|
||||||
|
}
|
||||||
367
LICENSE
367
LICENSE
|
|
@ -1,201 +1,232 @@
|
||||||
Apache License
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2.0, January 2004
|
Version 3, 29 June 2007
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
|
||||||
1. Definitions.
|
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
Preamble
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
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.
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
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.
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
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.
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
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.
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
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.
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
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.
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
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.
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
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.
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
The precise terms and conditions for copying, distribution and modification follow.
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
TERMS AND CONDITIONS
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
0. Definitions.
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
“This License” refers to version 3 of the GNU General Public License.
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
“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.
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
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.
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
A “covered work” means either the unmodified Program or a work based on the Program.
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
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.
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
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.
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
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.
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
1. Source Code.
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
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.
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
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 Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
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.
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
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.
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
The Corresponding Source for a work in source code form is that same work.
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
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
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
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.
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
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.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
light
|
||||||
you may not use this file except in compliance with the License.
|
Copyright (C) 2024 light7734
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
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.
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
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.
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
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:
|
||||||
|
|
||||||
|
light Copyright (C) 2024 light7734
|
||||||
|
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>.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Light
|
# light
|
||||||
See docs.light7734.com for a comprehensive project documentation
|
|
||||||
|
|
||||||
###### “No great thing comes into being all at once, any more than a cluster of grapes or a fig. If you tell me, 'I want a fig,' I will answer that it needs time. Let it flower first, then put forth its fruit and then ripen. I say then, if the fig tree's fruit is not brought to perfection suddenly in a single hour, would you expect to gather the fruit of a person’s mind so soon and so easily? I tell you, you must not expect it.” —Epictetus, Discourses 1.15.7-8
|
Monorepo for a cross-platform, cross-graphics-api, high-performance, modular, and modern game-engine.
|
||||||
|
|
|
||||||
58
conanfile.py
Normal file
58
conanfile.py
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
from conan import ConanFile
|
||||||
|
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
|
class LightRecipe(ConanFile):
|
||||||
|
name = "light"
|
||||||
|
|
||||||
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
|
generators = "CMakeDeps"
|
||||||
|
|
||||||
|
requires = [
|
||||||
|
"benchmark/1.8.4",
|
||||||
|
"gtest/1.14.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
tool_requires = [
|
||||||
|
"cmake/3.30.0"
|
||||||
|
]
|
||||||
|
|
||||||
|
options = {
|
||||||
|
"enable_static_analysis": [True, False],
|
||||||
|
"enable_sanitizers": [True, False],
|
||||||
|
}
|
||||||
|
|
||||||
|
default_options = {
|
||||||
|
"enable_static_analysis": True,
|
||||||
|
"enable_sanitizers": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
def layout(self):
|
||||||
|
cmake_layout(self)
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
tc = CMakeToolchain(self)
|
||||||
|
|
||||||
|
tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
|
||||||
|
tc.cache_variables["ENABLE_SANITIZERS"] = self.options.enable_sanitizers
|
||||||
|
tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis
|
||||||
|
|
||||||
|
tc.generate()
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
cmake = CMake(self)
|
||||||
|
cmake.configure()
|
||||||
|
cmake.build()
|
||||||
|
self.copy_compile_commands()
|
||||||
|
|
||||||
|
def copy_compile_commands(self):
|
||||||
|
build_folder = self.build_folder
|
||||||
|
source_file = os.path.join(build_folder, "compile_commands.json")
|
||||||
|
destination_file = os.path.join(self.source_folder, "compile_commands.json")
|
||||||
|
|
||||||
|
if os.path.isfile(source_file):
|
||||||
|
shutil.copy(source_file, destination_file)
|
||||||
|
self.output.info(f"Copied compile_commands.json to {destination_file}")
|
||||||
|
else:
|
||||||
|
self.output.warn("compile_commands.json not found!")
|
||||||
Binary file not shown.
|
|
@ -1,202 +0,0 @@
|
||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 79 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 8.5 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
|
|
@ -1 +0,0 @@
|
||||||
The quick brown fox jumps over the lazy dog
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
#version 450 core
|
|
||||||
|
|
||||||
layout(push_constant) uniform pc
|
|
||||||
{
|
|
||||||
mat4 view_projection;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct VertexData
|
|
||||||
{
|
|
||||||
vec3 position;
|
|
||||||
vec3 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
// readonly SSBO containing the vertex data
|
|
||||||
layout(set = 0, binding = 0, std430) readonly buffer vertex_data {
|
|
||||||
VertexData data[];
|
|
||||||
};
|
|
||||||
|
|
||||||
vec3 position(int idx)
|
|
||||||
{
|
|
||||||
return data[idx].position;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 color(int idx)
|
|
||||||
{
|
|
||||||
return data[idx].color;
|
|
||||||
}
|
|
||||||
|
|
||||||
layout(location = 0) out vec3 out_frag_color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = view_projection * vec4(position(gl_VertexIndex), 1.0);
|
|
||||||
out_frag_color = color(gl_VertexIndex);
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
|
@ -1,10 +0,0 @@
|
||||||
#version 450 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 in_frag_color;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 out_frag_color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
out_frag_color = vec4(in_frag_color, 1.0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
|
@ -1,26 +0,0 @@
|
||||||
#version 450 core
|
|
||||||
|
|
||||||
layout(push_constant) uniform pc {
|
|
||||||
mat4 view_projection;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VertexData
|
|
||||||
{
|
|
||||||
vec3 position;
|
|
||||||
vec3 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140, set = 0, binding = 0) readonly buffer Vertices {
|
|
||||||
|
|
||||||
VertexData vertices[];
|
|
||||||
} ssbo_vertices;
|
|
||||||
|
|
||||||
layout(location = 0) out vec3 out_frag_color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
VertexData vertex = ssbo_vertices.vertices[gl_VertexIndex];
|
|
||||||
|
|
||||||
gl_Position = view_projection * vec4(vertex.position, 1.0);
|
|
||||||
out_frag_color = vertex.color;
|
|
||||||
}
|
|
||||||
Binary file not shown.
4
docs/.gitignore
vendored
4
docs/.gitignore
vendored
|
|
@ -1,4 +0,0 @@
|
||||||
_build/
|
|
||||||
generated/
|
|
||||||
html/
|
|
||||||
xml/
|
|
||||||
1
docs/CMakeLists.txt
Normal file
1
docs/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
message("TODO: implement doc generation")
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
TARGET = ./
|
|
||||||
INPUT = "../modules"
|
|
||||||
RECURSIVE = YES
|
|
||||||
|
|
||||||
PROJECT_NAME = "Light"
|
|
||||||
JAVADOC_AUTOBRIEF = YES
|
|
||||||
JAVADOC_BANNER = YES
|
|
||||||
GENERATE_XML = YES
|
|
||||||
|
|
||||||
EXTRACT_PRIVATE = NO
|
|
||||||
EXTRACT_STATIC = NO
|
|
||||||
EXTRACT_LOCAL_CLASSES = NO
|
|
||||||
HIDE_UNDOC_RELATIONS = YES
|
|
||||||
HAVE_DOT = NO
|
|
||||||
|
|
||||||
GENERATE_TODOLIST = NO
|
|
||||||
GENERATE_HTML = NO
|
|
||||||
GENERATE_DOCSET = NO
|
|
||||||
GENERATE_HTMLHELP = NO
|
|
||||||
GENERATE_CHI = NO
|
|
||||||
GENERATE_QHP = NO
|
|
||||||
GENERATE_ECLIPSEHELP = NO
|
|
||||||
GENERATE_TREEVIEW = NO
|
|
||||||
GENERATE_LATEX = NO
|
|
||||||
GENERATE_RTF = NO
|
|
||||||
GENERATE_MAN = NO
|
|
||||||
GENERATE_DOCBOOK = NO
|
|
||||||
GENERATE_AUTOGEN_DEF = NO
|
|
||||||
GENERATE_SQLITE3 = NO
|
|
||||||
GENERATE_PERLMOD = NO
|
|
||||||
GENERATE_TAGFILE = NO
|
|
||||||
GENERATE_LEGEND = NO
|
|
||||||
GENERATE_TESTLIST = NO
|
|
||||||
GENERATE_BUGLIST = NO
|
|
||||||
GENERATE_DEPRECATEDLIST= NO
|
|
||||||
|
|
||||||
FILE_PATTERNS = *.c \
|
|
||||||
*.cc \
|
|
||||||
*.cxx \
|
|
||||||
*.cxxm \
|
|
||||||
*.cpp \
|
|
||||||
*.cppm \
|
|
||||||
*.ccm \
|
|
||||||
*.c++ \
|
|
||||||
*.c++m \
|
|
||||||
*.java \
|
|
||||||
*.ii \
|
|
||||||
*.ixx \
|
|
||||||
*.ipp \
|
|
||||||
*.i++ \
|
|
||||||
*.inl \
|
|
||||||
*.idl \
|
|
||||||
*.ddl \
|
|
||||||
*.odl \
|
|
||||||
*.h \
|
|
||||||
*.hh \
|
|
||||||
*.hxx \
|
|
||||||
*.hpp \
|
|
||||||
*.h++ \
|
|
||||||
*.l \
|
|
||||||
*.cs \
|
|
||||||
*.d \
|
|
||||||
*.php \
|
|
||||||
*.php4 \
|
|
||||||
*.php5 \
|
|
||||||
*.phtml \
|
|
||||||
*.inc \
|
|
||||||
*.m \
|
|
||||||
*.markdown \
|
|
||||||
*.md \
|
|
||||||
*.mm \
|
|
||||||
*.dox \
|
|
||||||
*.py \
|
|
||||||
*.pyw \
|
|
||||||
*.f90 \
|
|
||||||
*.f95 \
|
|
||||||
*.f03 \
|
|
||||||
*.f08 \
|
|
||||||
*.f18 \
|
|
||||||
*.f \
|
|
||||||
*.for \
|
|
||||||
*.vhd \
|
|
||||||
*.vhdl \
|
|
||||||
*.ucf \
|
|
||||||
*.qsf \
|
|
||||||
*.ice
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
Application
|
|
||||||
===================================================================================================
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 3
|
|
||||||
:caption: App
|
|
||||||
|
|
||||||
Functions
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
.. doxygenfunction:: main
|
|
||||||
|
|
||||||
Classes
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
.. doxygenclass:: lt::app::ISystem
|
|
||||||
|
|
||||||
.. doxygenstruct:: lt::app::TickInfo
|
|
||||||
|
|
||||||
.. doxygenstruct:: lt::app::TickResult
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
Renderer
|
|
||||||
===================================================================================================
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 3
|
|
||||||
:caption: App
|
|
||||||
|
|
||||||
Classes
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
.. doxygenenum:: lt::renderer::Api
|
|
||||||
|
|
||||||
.. doxygenclass:: lt::renderer::System
|
|
||||||
|
|
||||||
.. doxygenstruct:: lt::renderer::components::Sprite
|
|
||||||
198
docs/architecture.rst
Normal file
198
docs/architecture.rst
Normal file
|
|
@ -0,0 +1,198 @@
|
||||||
|
Architecture
|
||||||
|
=========================
|
||||||
|
**Light** is a **modular** and feature rich engine with emphasis on the **entity component system** architectural design.
|
||||||
|
It is composed of numerous **modules** and prefers **composition over inheritance**.
|
||||||
|
|
||||||
|
Building Blocks
|
||||||
|
------------------------
|
||||||
|
Modules are the **building blocks** of Light.
|
||||||
|
Each module can provide one, and only one of the following:
|
||||||
|
|
||||||
|
- Library
|
||||||
|
These modules provide some form of functionality.
|
||||||
|
They may depend on library modules.
|
||||||
|
|
||||||
|
For instance, they may provide: asset parsing, logging, string functions,
|
||||||
|
math functions, containers, etc.
|
||||||
|
|
||||||
|
Library modules may also **wrap** a third-party library and provide an interface following Light's coding guidelines.
|
||||||
|
|
||||||
|
This way:
|
||||||
|
|
||||||
|
* Unsafe libraries, often native C libraries, can be made safer (without sacrificing performance).
|
||||||
|
* Coding conventions can be consistent across all lines of code in other modules.
|
||||||
|
* Deprecated and confusing conventions (eg. out parameters) can be wrapped away and replaced by simpler interfaces.
|
||||||
|
* It may be possible to provide only the required symbols from a library.
|
||||||
|
|
||||||
|
- Tool
|
||||||
|
These modules compile as executables that provide tooling.
|
||||||
|
They may depend on any other module type.
|
||||||
|
|
||||||
|
An example of a **tool** module is the "AssetBaker" that relieves other modules
|
||||||
|
from linking to large third-party asset readers (and optimizers) and bakes assets' content
|
||||||
|
in a common, and often optimized, format.
|
||||||
|
|
||||||
|
- Component
|
||||||
|
These modules specify POD structures to be used as components of one or more systems.
|
||||||
|
They shall not depend on any other module. This separation (of components and system modules) is for 2 reasons:
|
||||||
|
|
||||||
|
First, for simple re-usability of **components** between multiple **systems** as it is quite likely
|
||||||
|
for more than 1 **system** to depend on a component.
|
||||||
|
For instance, **physics simulation** and **rendering** both depend on the **TransformationComponent**
|
||||||
|
|
||||||
|
Second, even if a component is used solely by **1 system**, decoupling the **component** from the
|
||||||
|
**system's implementation** allows us to provide alternative implementations for
|
||||||
|
a system. For instance, we can have a **polygon-renderer** and a **raytracer** for our
|
||||||
|
rendering system.
|
||||||
|
|
||||||
|
- System
|
||||||
|
System modules may depend on any number of modules but must depend on at least one component module.
|
||||||
|
|
||||||
|
These modules implement an aspect of the engine, e.g. physics system, rendering system,
|
||||||
|
audio system, networking system, script system, etc.
|
||||||
|
They implement a common **system interface** and may periodically **tick** to execute their logic
|
||||||
|
and **mutate** different components while doing so.
|
||||||
|
|
||||||
|
- Main
|
||||||
|
**Light** is the stock implementation of the **main** module. It's basically our engine.
|
||||||
|
You may design and use an alternative implementation.
|
||||||
|
|
||||||
|
The main module acts as the **aggregator** and **synchronizer** of a required module list.
|
||||||
|
It synchronizes between multiple modules using a concept called **tick dependencies**.
|
||||||
|
|
||||||
|
Since we want to maximally utilize our hardware, we need to have as much concurrency as possible.
|
||||||
|
One obvious way to increase concurrency is to make multiple systems tick (execute their logic)
|
||||||
|
in parallel.
|
||||||
|
|
||||||
|
But we can't just tick haphazardly, we need proper **synchronization**.
|
||||||
|
Let's break down how synchronization works with **tick dependencies** by briefly going
|
||||||
|
through different module types:
|
||||||
|
|
||||||
|
**Tool** modules are executables (eg. AssetBaker). They don't need any external synchronization.
|
||||||
|
|
||||||
|
**Library** modules simply provide reusable functionality for **tool** and **system** modules.
|
||||||
|
|
||||||
|
**Component** modules, even more simply, provide a set of POD structures.
|
||||||
|
|
||||||
|
**System** modules, however, bring about a bit of complexity.
|
||||||
|
They need to execute a piece of code periodically, which may cause **mutations**.
|
||||||
|
|
||||||
|
For instance, a **physics simulation system** needs to tick every frame (or multiple times
|
||||||
|
a frame at fixed intervals) to simulate physics, this simulation may **mutate** one
|
||||||
|
or more components, such as the **TransformationComponents**.
|
||||||
|
|
||||||
|
Meanwhile, the **rendering system** might use the **TransformationComponent** for vertex shader operations
|
||||||
|
to determine where things should end up on the screen.
|
||||||
|
We can't be **mutating** a component in one thread while **reading** it in another, this causes all sorts
|
||||||
|
of nasty problems. Hence why we need synchronization.
|
||||||
|
|
||||||
|
Systems can think of synchronization of their logic to be done in one of 3 ways:
|
||||||
|
**external**, **internal**, and **unsynchronized**.
|
||||||
|
|
||||||
|
- **Unsynchronized**:
|
||||||
|
As evident from the name, no syncing needs to be done for these parts of a system.
|
||||||
|
|
||||||
|
- **Internal**:
|
||||||
|
This type of synchronization is handled internally by the module and does
|
||||||
|
not concern other systems.
|
||||||
|
|
||||||
|
- **External**:
|
||||||
|
This is the synchronization done by the main module (Light). And can be achieved
|
||||||
|
by specifying a list of tick dependencies.
|
||||||
|
|
||||||
|
The system interface provides 3 tick functions:
|
||||||
|
|
||||||
|
- **tick_pre_unsync**:
|
||||||
|
This gets called for all **active systems** at the same time before the frame starts.
|
||||||
|
Light waits for the execution of all **tick_pre_unsync** functions to finish before proceeding to **tick_sync**.
|
||||||
|
This is usually for systems to handle internally synchronized pre-frame logic.
|
||||||
|
|
||||||
|
- **tick_sync**:
|
||||||
|
This relies on the tick dependencies of a system.
|
||||||
|
A tick dependency simply marks a **type of component** as a **mutable** or **immutable** dependency for
|
||||||
|
a particular **system**. If system **A** shares only **immutable** dependencies with system **B**, or
|
||||||
|
if system **A** shares no dependencies with system **B**, they can tick together.
|
||||||
|
|
||||||
|
If system **A** has a **mutable** dependency with a component, then all systems that have either
|
||||||
|
**mutable** or **immutable** dependency with that component need to tick before or after system **A's**
|
||||||
|
tick.
|
||||||
|
|
||||||
|
- **tick_post_unsync**:
|
||||||
|
Same as **tick_pre_unsync**, but happens after all **tick_sync** calls
|
||||||
|
have been executed.
|
||||||
|
|
||||||
|
You might be wondering why we're bothering with specifying tick dependencies between
|
||||||
|
such high-level concepts as **systems** where we could manually do the external synchronization
|
||||||
|
between them.
|
||||||
|
|
||||||
|
There may be truth in that claim, but our intention here is to free **Light** from knowing
|
||||||
|
about the implementation details of our systems and instead make it simply provide a framework for setting up
|
||||||
|
and running multiple systems together.
|
||||||
|
|
||||||
|
Furthermore, now our **systems** don't need to know anything about the existence of other systems either
|
||||||
|
and their logic is completely isolated.
|
||||||
|
|
||||||
|
Performance
|
||||||
|
----------------
|
||||||
|
**Light** engine aims to keep a high-performant design on all levels of the engine, from the grand architecture to the low-level implementations.
|
||||||
|
It also tries to ensure a consistent performance across platforms and APIs.
|
||||||
|
We achieve this by not thinking of performance as a concern for later times and put it as one
|
||||||
|
of our first priorities.
|
||||||
|
|
||||||
|
Some of the main techniques **Light** utilizes to ensure optimal code performance:
|
||||||
|
|
||||||
|
- Hardware Friendly Architecture
|
||||||
|
|
||||||
|
- Native Support
|
||||||
|
Light provides native support for the supported platforms and architectures.
|
||||||
|
It also provides native graphics API support for all the supported operating systems:
|
||||||
|
Metal for MacOS, DirectX12 for Windows and Vulkan for the rest.
|
||||||
|
|
||||||
|
- Baking
|
||||||
|
Light bakes and optimizes anything that can be baked as soon as it can.
|
||||||
|
|
||||||
|
For assets, this will significantly decrease our load times because optimized (and specialized) data can be directly
|
||||||
|
streamed to RAM/VRAM without intermediate processing.
|
||||||
|
|
||||||
|
We don't only bake assets like models, images and audio. We also bake anything about the scene
|
||||||
|
that's bake-able in any sense.
|
||||||
|
|
||||||
|
- Low Memory Footprint
|
||||||
|
Memory is sacred! That's my personal philosophy. I always use low memory-footprint applications.
|
||||||
|
I value and respect memory. I worship memory. I pray to the memory gods, so that I may never run
|
||||||
|
out of memory.
|
||||||
|
|
||||||
|
Games and simulations naturally have high memory consumption. But that fact should not give us
|
||||||
|
a free pass for ignoring our memory footprint. Light engine respects its user's hardware by
|
||||||
|
not being wasteful and always optimizing its memory consumption (alongside its performance).
|
||||||
|
|
||||||
|
Every byte matters!
|
||||||
|
|
||||||
|
- Minimal Indirection
|
||||||
|
Light minimizes unnecessary indirections and makes friends with the compilers by
|
||||||
|
providing them as much context as possible. It uses compile-time paradigms and principles before
|
||||||
|
considering (necessary) indirections.
|
||||||
|
|
||||||
|
All problems in programming can be solved by another level of indirection. But perhaps not performance
|
||||||
|
problems.
|
||||||
|
|
||||||
|
- Rigorous Testing
|
||||||
|
|
||||||
|
State
|
||||||
|
----------------
|
||||||
|
The data in Light engine can be coarsely divided into 4 types:
|
||||||
|
|
||||||
|
- Shared
|
||||||
|
Components are the only way for our systems to have data shared between themselves.
|
||||||
|
They are laid out in the most reasonably efficient way possible by our ECS implementation.
|
||||||
|
Currently we use **EnTT**, however we **may** roll our own implementation in the future if needs be.
|
||||||
|
|
||||||
|
- Internal
|
||||||
|
Systems can hold any amount of internal state as they wish. Light however won't go over-board
|
||||||
|
and respects the hardware's cache locality when it's iterating over a set of components.
|
||||||
|
|
||||||
|
- Transient
|
||||||
|
Mostly just the stack.
|
||||||
|
|
||||||
|
- Cold
|
||||||
|
Cold state is everything that lives on the disk, saved game-state, baked assets, etc.
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
Asset Management
|
|
||||||
===================================================================================================
|
|
||||||
|
|
||||||
On Disk (file) Layout
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.. code-block:: md
|
|
||||||
|
|
||||||
{version} | 4 bytes, ie. uint32_t
|
|
||||||
{general metadata} | sizeof(AssetMetadata)
|
|
||||||
{specialized metadata} | sizeof(XXXAssetMetadata), eg. TextureAssetMetadata
|
|
||||||
{n} | 4 bytes, ie. uint32_t
|
|
||||||
{blob_0...n metadata} | n * sizeof(BlobMetadata)
|
|
||||||
{blob_0...n data} | variable size based on actual data
|
|
||||||
{end marker} | 8 byte, ie size_t for marking the END
|
|
||||||
|
|
||||||
Sections
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
.. code-block:: md
|
|
||||||
|
|
||||||
version -> The version of the asset for forward compatibility
|
|
||||||
general metadata -> Common asset metadata such as file-path, asset-type, creator, etc.
|
|
||||||
specialized metadata -> Metadata specific to the asset, eg. texture dimensions for Textures.
|
|
||||||
n -> The number of blobs.
|
|
||||||
blob_0...n metadata -> Metadata specifying how the actual data is packed, required for unpacking.
|
|
||||||
blob_0...n data -> The actual data, packed and compressed to be reacdy for direct engine consumption.
|
|
||||||
|
|
||||||
Loading
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
Loading pre-baked asset files (like .png files) for baking:
|
|
||||||
|
|
||||||
|
|
||||||
Each **Loader** has ONE OR MORE supported input file types (detected via the file extension): eg. StbLoader -> Can read in .jpg, .png, .bmp, etc.... files
|
|
||||||
|
|
||||||
Each **Loader** has ONLY ONE supported output asset type:
|
|
||||||
eg. StbLoader -> outputs TextureAsset
|
|
||||||
|
|
||||||
Multiple **Loader**\s MAY have as output the same asset type:
|
|
||||||
eg. StbLoader -> outputs TextureAsset
|
|
||||||
eg. SomeOtherImgLoader -> outputs TextureAsset
|
|
||||||
|
|
||||||
Multiple **Loader**\s SHOULD NOT have as input same extension types
|
|
||||||
eg. .jpg, .png -> if supported, should only be supported by 1 **Loader** class
|
|
||||||
|
|
||||||
Each **Loader** SHOULD read and turn the data from a file (eg. .png for textures) into something
|
|
||||||
understandable by a **Packer** (not the engine itself).
|
|
||||||
|
|
||||||
A **Loader** SHOULD NOT be responsible for packing the parsed file data into asset data,
|
|
||||||
as that implies direct understanding of the layout required by the engine.
|
|
||||||
|
|
||||||
And if that layout changes, ALL **Loader**s should change accordingly;
|
|
||||||
which makes a class that's responsible for reading files dependant on the engine's (potentially frequent) internal changes.
|
|
||||||
The logic is to reduce many-to-one dependency into a one-to-one dependency by redirecting the packing process to **Packer** classes
|
|
||||||
|
|
||||||
Packing
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
Each **Packer** is responsible for packing ONLY ONE asset type:
|
|
||||||
eg. TexturePacker for packing texture assets from parsed image files.
|
|
||||||
eg. ModelPacker for packing model assets from parsed model files.
|
|
||||||
|
|
||||||
Each **Packer** will output ONE OR MORE blobs of data,
|
|
||||||
and for EACH blob of data, it'll write a BlobMetadata, AFTER the specialized metadata (eg. TextureAssetMetadata)
|
|
||||||
|
|
||||||
A **Packer** will make use of the **Compressor** classes to compress the data,
|
|
||||||
and lay it out in a way that is suitable for the engine's consumption.
|
|
||||||
|
|
||||||
Unpacking
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
A **Parser** is responsible for parsing ONLY ONE asset type:
|
|
||||||
eg. TextureParser for parsing texture assets for direct engine consumption.
|
|
||||||
eg. ModelParser for parsing model assets for direct engine consumption.
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
.. architecture/resources
|
|
||||||
|
|
||||||
Resource Management
|
|
||||||
===================================================================================================
|
|
||||||
|
|
||||||
46
docs/conf.py
46
docs/conf.py
|
|
@ -1,35 +1,25 @@
|
||||||
# Configuration file for the Sphinx documentation builder.
|
# Project information
|
||||||
#
|
project = 'Light'
|
||||||
# For the full list of built-in configuration values, see the documentation:
|
copyright = '2024, Light7734'
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
author = 'Light7734'
|
||||||
|
release = '1'
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# General configuration
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
extensions = [
|
||||||
|
"sphinx.ext.intersphinx",
|
||||||
|
"sphinx_copybutton",
|
||||||
|
"sphinx_design"
|
||||||
|
]
|
||||||
|
|
||||||
project = 'light'
|
source_suffix = '.rst'
|
||||||
copyright = '2025, light7734'
|
default_role = 'cpp:any'
|
||||||
author = 'light7734'
|
pygments_style = 'sphinx'
|
||||||
|
highlight_language = 'c++'
|
||||||
# -- General configuration ---------------------------------------------------
|
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
||||||
|
|
||||||
extensions = ['breathe']
|
|
||||||
|
|
||||||
breathe_projects = {"Light": "./xml"}
|
|
||||||
breathe_default_project = "Light"
|
|
||||||
breathe_default_members = ()
|
|
||||||
|
|
||||||
# Tell sphinx what the primary language being documented is.
|
|
||||||
primary_domain = 'cpp'
|
primary_domain = 'cpp'
|
||||||
|
|
||||||
# Tell sphinx what the pygments highlight language should be.
|
|
||||||
highlight_language = 'cpp'
|
|
||||||
|
|
||||||
templates_path = ['_templates']
|
|
||||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||||
|
|
||||||
# -- Options for HTML output -------------------------------------------------
|
templates_path = ["_templates"]
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
||||||
|
|
||||||
|
# Theme configuration
|
||||||
html_theme = 'sphinx_rtd_theme'
|
html_theme = 'sphinx_rtd_theme'
|
||||||
html_static_path = ['_static']
|
# html_favicon = ''
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
.. guidelines/conventions
|
|
||||||
|
|
||||||
Coding Conventions
|
|
||||||
===================================================================================================
|
|
||||||
Any line of code added to the engine, must abide by following conventions.
|
|
||||||
They may seem arbitrary, and sometimes they are. But to achieve **consistency**, which is not an arbitrary goal, is to
|
|
||||||
follow these guidelines.
|
|
||||||
|
|
||||||
AAA
|
|
||||||
--------------------
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
.. guidelines/development
|
|
||||||
|
|
||||||
Development Strategy
|
|
||||||
===================================================================================================
|
|
||||||
Defines:
|
|
||||||
|
|
||||||
- A **unit of work**.
|
|
||||||
- A **pipeline** for making changes ---should **minimize ambiguity**.
|
|
||||||
- A way for **distributing work** and **tracking productivity**.
|
|
||||||
|
|
||||||
An **unpragmatic strategy** is utterly useless. It should pull our minds out from the **engineering dreamland**, and make us focus on the **product delivery**.
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
**Forgejo issues** is used as the project-management tool.
|
|
||||||
No need for fancy boards or 3rd party apps. Simple tags, titles, milestones, etc... should suffice.
|
|
||||||
|
|
||||||
Cycle
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
A cycle is one **step** in development, 1 cycle == 1 issue, and it consists of 4 stages:
|
|
||||||
|
|
||||||
1 - Make it known
|
|
||||||
- Write the commit title.
|
|
||||||
- This limits the **scope of changes** and gives you a very specific **goal** to work towards.
|
|
||||||
- The message should follow the project's **commit message specifications**.
|
|
||||||
|
|
||||||
- Make an issue.
|
|
||||||
- Git is a **version-control** tool, not a **project-management** tool.
|
|
||||||
- Preferably, provide a very brief description ---This may be used in the commit message's body.
|
|
||||||
|
|
||||||
2 - Make it work
|
|
||||||
- Write high-level tests that confirms the cycle's requirements are met.
|
|
||||||
- That is, specify requirements in a programming language instead of English.
|
|
||||||
- You're done when all the tests pass.
|
|
||||||
- Preferably write the tests first, but it's okay to start with the interface.
|
|
||||||
- Tests **may** not be necessary depending on the requirements and commit type.
|
|
||||||
|
|
||||||
- **Make it work** doesn't mean liberally producing substandard code, you should:
|
|
||||||
- Follow project's **conventions**.
|
|
||||||
- Follow **best practices** and **proven swe principles**.
|
|
||||||
- Enable **warnings as errors**.
|
|
||||||
- Enable **static analysis**.
|
|
||||||
- Don't break existing tests.
|
|
||||||
- Have the overall picture in mind.
|
|
||||||
|
|
||||||
3 - Make it right
|
|
||||||
- Test driven refactoring
|
|
||||||
- Now you have a better picture of how things relate and work.
|
|
||||||
- Switch to a TDD-style development to do the refactoring while following swe best-practices and proven-principles.
|
|
||||||
|
|
||||||
4 - Make it fast
|
|
||||||
- This is an engine, at the end of the day, **performance** is king.
|
|
||||||
- Get a performance and/or memory profile and try to alleviate the bottlenecks.
|
|
||||||
- Avoid premature optimizations, be certain what you change has performance benefits.
|
|
||||||
|
|
||||||
Sprint
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
A sprint is the collection of all the finished cycles in **one week**.
|
|
||||||
They start from **Monday mornings**, and end on **Sunday nights**,
|
|
||||||
where we'll do a **12hr coding marathon** (streamed on Discord) to wrap everything up.
|
|
||||||
|
|
||||||
Sprints begin by **defining** what cycles/issues are expected to be done.
|
|
||||||
And end by **reflecting** on the results, which may **affect** our future approach.
|
|
||||||
|
|
||||||
Commit Message Specification
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
The project follows the `Conventional Commits Specification <https://www.conventionalcommits.org/en/v1.0.0-beta.4>`_.
|
|
||||||
|
|
||||||
.. code-block:: md
|
|
||||||
|
|
||||||
<type>[optional scope]: <description>
|
|
||||||
|
|
||||||
[optional body]
|
|
||||||
|
|
||||||
[optional footer]
|
|
||||||
|
|
||||||
With the following commit types:
|
|
||||||
|
|
||||||
- feat
|
|
||||||
- For adding a new feature.
|
|
||||||
- Causes a **minor** bump in version.
|
|
||||||
|
|
||||||
- fix
|
|
||||||
- For changes that fix one or more bug.
|
|
||||||
- Causes a **patch** bump in version.
|
|
||||||
|
|
||||||
- refactor
|
|
||||||
- For non feat/fix changes that improve the implementation and/or the interface.
|
|
||||||
- Causes a **patch** bump in version.
|
|
||||||
|
|
||||||
- perf
|
|
||||||
- For changes that (hopefully) improve the performance.
|
|
||||||
- Causes a **patch** bump in version.
|
|
||||||
|
|
||||||
- build
|
|
||||||
- For changes that affect the build system or external dependencies.
|
|
||||||
- Causes a **patch** bump in version.
|
|
||||||
|
|
||||||
- asset
|
|
||||||
- For changes to the files under the ``/data`` directory.
|
|
||||||
- Causes a **patch** bump in version.
|
|
||||||
|
|
||||||
- test
|
|
||||||
- For adding missing tests or correcting the existing tests.
|
|
||||||
- Does not affect the version.
|
|
||||||
|
|
||||||
- chore
|
|
||||||
- For releases, .gitignore changes, deleting unused files, etc.
|
|
||||||
- Does not affect the version.
|
|
||||||
|
|
||||||
- ci
|
|
||||||
- For changes to our CI configuration files and scripts, including files under ``/tools/ci``.
|
|
||||||
- Does not affect the version.
|
|
||||||
|
|
||||||
- docs
|
|
||||||
- For changes to the documentations.
|
|
||||||
- Does not affect the version.
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
Since we're in beta, any commit might change the api, no need for ! (breaking) tags.
|
|
||||||
|
|
||||||
Semantic Versioning
|
|
||||||
---------------------------------------------------------------------------------------------------
|
|
||||||
Coupled with conventional commit style messages, we can automajically version the project following
|
|
||||||
the **Semantic Versioning 2.0.0** specifications.
|
|
||||||
|
|
||||||
The full version identifier consits of a version core (major.minor.patch) + label + hexsha of the commit.
|
|
||||||
Using the following format:
|
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: md
|
|
||||||
|
|
||||||
<major>.<minor>.<patch>-<label>+<short_hexsha>
|
|
||||||
|
|
||||||
eg.
|
|
||||||
0.8.1-kitten+ea898
|
|
||||||
0.5.0-kitten+01d85
|
|
||||||
1.5.0-akasha+7de53
|
|
||||||
|
|
||||||
kitten refers to all pre-release (1.0.0) versions
|
|
||||||
|
|
||||||
|
|
||||||
The shortened hexsha of a commit is obtained by:
|
|
||||||
``git rev-parse --short=5 <commit_hexsha>``
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
.. guidelines/philosophy
|
|
||||||
|
|
||||||
Philosophy
|
|
||||||
===================================================================================================
|
|
||||||
|
|
||||||
| **A theory or attitude that acts as a guiding principle for behaviour.**
|
|
||||||
| --- Oxford Languages
|
|
||||||
|
|
@ -1,32 +1,4 @@
|
||||||
.. light documentation
|
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
./architecture.rst
|
||||||
:caption: Light Engine
|
./philosophy.rst
|
||||||
|
|
||||||
light/showcase.rst
|
|
||||||
light/features.rst
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 2
|
|
||||||
:caption: Software Architecture
|
|
||||||
|
|
||||||
architecture/assets.rst
|
|
||||||
architecture/resource.rst
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 2
|
|
||||||
:caption: Development Guidelines
|
|
||||||
|
|
||||||
guidelines/philosophy.rst
|
|
||||||
guidelines/development.rst
|
|
||||||
guidelines/conventions.rst
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 3
|
|
||||||
:caption: API
|
|
||||||
|
|
||||||
api/app.rst
|
|
||||||
api/renderer.rst
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
.. light/features
|
|
||||||
|
|
||||||
Features
|
|
||||||
===================================================================================================
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
.. light/demos
|
|
||||||
|
|
||||||
Showcase
|
|
||||||
===================================================================================================
|
|
||||||
6
docs/philosophy.rst
Normal file
6
docs/philosophy.rst
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
Philosophy
|
||||||
|
=========================
|
||||||
|
|
||||||
|
|
||||||
|
Code is documentation
|
||||||
|
------------------------
|
||||||
|
|
@ -1,262 +1,3 @@
|
||||||
add_module(NAME preliminary INTERFACES module.cppm fundumental_types.cppm assertions.cppm build_constants.cppm)
|
add_subdirectory(pch)
|
||||||
add_module(NAME logger INTERFACES logger.cppm TESTS logger.test.cpp DEPENDENCIES preliminary)
|
|
||||||
add_module(NAME tracer INTERFACES tracer.cppm DEPENDENCIES preliminary logger)
|
|
||||||
|
|
||||||
add_module(NAME bitwise INTERFACES operations.cppm DEPENDENCIES preliminary)
|
add_subdirectory(engine)
|
||||||
add_module(NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
logger
|
|
||||||
)
|
|
||||||
add_module(NAME time INTERFACES timer.cppm TESTS timer.test.cpp DEPENDENCIES preliminary)
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
test
|
|
||||||
INTERFACES
|
|
||||||
module.cppm
|
|
||||||
test.cppm
|
|
||||||
expects.cppm
|
|
||||||
registry.cppm
|
|
||||||
SOURCES
|
|
||||||
entrypoint.cpp
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
logger
|
|
||||||
TESTS
|
|
||||||
test.test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
math
|
|
||||||
INTERFACES
|
|
||||||
algebra.cppm
|
|
||||||
trig.cppm
|
|
||||||
vec2.cppm
|
|
||||||
vec3.cppm
|
|
||||||
vec4.cppm
|
|
||||||
mat4.cppm
|
|
||||||
components.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
TESTS
|
|
||||||
trig.test.cpp
|
|
||||||
vec2.test.cpp
|
|
||||||
vec3.test.cpp
|
|
||||||
vec4.test.cpp
|
|
||||||
mat4.test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
assets
|
|
||||||
INTERFACES
|
|
||||||
shader.cppm
|
|
||||||
metadata.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
logger
|
|
||||||
TESTS
|
|
||||||
shader.test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
asset_baker
|
|
||||||
ROOT_DIR
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/asset_baker
|
|
||||||
INTERFACES
|
|
||||||
bakers.cppm
|
|
||||||
ENTRYPOINT
|
|
||||||
entrypoint.cpp
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
assets
|
|
||||||
logger
|
|
||||||
)
|
|
||||||
|
|
||||||
# add_executable(asset_baker entrypoint.cpp) target_link_libraries(asset_baker
|
|
||||||
# PRIVATE libasset_baker)
|
|
||||||
|
|
||||||
add_module(NAME camera INTERFACES components.cppm DEPENDENCIES preliminary math)
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
app
|
|
||||||
INTERFACES
|
|
||||||
application.cppm
|
|
||||||
system.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
memory
|
|
||||||
PRIVATE_DEPENDENCIES
|
|
||||||
)
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
ecs
|
|
||||||
INTERFACES
|
|
||||||
sparse_set.cppm
|
|
||||||
registry.cppm
|
|
||||||
entity.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
logger
|
|
||||||
memory
|
|
||||||
TESTS
|
|
||||||
registry.test.cpp
|
|
||||||
sparse_set.test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_module(NAME input_codes INTERFACES input_codes.cppm DEPENDENCIES preliminary)
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
surface
|
|
||||||
INTERFACES
|
|
||||||
constants.cppm
|
|
||||||
system.cppm
|
|
||||||
requests.cppm
|
|
||||||
events.cppm
|
|
||||||
components.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
ecs
|
|
||||||
app
|
|
||||||
math
|
|
||||||
memory
|
|
||||||
input_codes
|
|
||||||
PRIVATE_DEPENDENCIES
|
|
||||||
logger
|
|
||||||
time
|
|
||||||
TESTS
|
|
||||||
system.test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
elseif(UNIX)
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
surface
|
|
||||||
INTERFACES
|
|
||||||
constants.cppm
|
|
||||||
system.cppm
|
|
||||||
requests.cppm
|
|
||||||
events.cppm
|
|
||||||
components.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
ecs
|
|
||||||
app
|
|
||||||
math
|
|
||||||
memory
|
|
||||||
input_codes
|
|
||||||
wayland-client
|
|
||||||
PRIVATE_DEPENDENCIES
|
|
||||||
X11
|
|
||||||
logger
|
|
||||||
time
|
|
||||||
TESTS
|
|
||||||
system.test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
function(add_wayland_protocol_target TARGET_NAME SPEC NAME)
|
|
||||||
add_custom_target(wayland_${TARGET_NAME}_header COMMAND wayland-scanner client-header /usr/share/wayland-protocols${SPEC} ${CMAKE_CURRENT_SOURCE_DIR}/surface/wayland-protocols/${NAME}.h)
|
|
||||||
add_dependencies(surface wayland_${TARGET_NAME}_header)
|
|
||||||
add_custom_target(wayland_${TARGET_NAME}_source COMMAND wayland-scanner private-code /usr/share/wayland-protocols${SPEC} ${CMAKE_CURRENT_SOURCE_DIR}/surface/wayland-protocols/${NAME}.c)
|
|
||||||
add_dependencies(surface wayland_${TARGET_NAME}_source)
|
|
||||||
|
|
||||||
target_sources(surface PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/surface/wayland-protocols/${NAME}.c)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
target_include_directories(surface PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/surface/wayland-protocols/)
|
|
||||||
add_wayland_protocol_target(xdg_shell "/stable/xdg-shell/xdg-shell.xml" xdg-shell)
|
|
||||||
|
|
||||||
else()
|
|
||||||
message(FATAL "Failed to generate cmake: unsupported platform")
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
input
|
|
||||||
INTERFACES
|
|
||||||
system.cppm
|
|
||||||
components.cppm
|
|
||||||
events.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
input_codes
|
|
||||||
surface
|
|
||||||
math
|
|
||||||
logger
|
|
||||||
TESTS
|
|
||||||
system.test.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
find_package(Vulkan REQUIRED)
|
|
||||||
message("Vulkan Libraries are: ${Vulkan_LIBRARIES}")
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
renderer
|
|
||||||
INTERFACES
|
|
||||||
data.cppm
|
|
||||||
system.cppm
|
|
||||||
frontends.cppm
|
|
||||||
components.cppm
|
|
||||||
factory.cppm
|
|
||||||
vk/api_wrapper.cppm
|
|
||||||
vk/device.cppm
|
|
||||||
vk/gpu.cppm
|
|
||||||
vk/instance.cppm
|
|
||||||
vk/surface.cppm
|
|
||||||
vk/swapchain.cppm
|
|
||||||
vk/buffer.cppm
|
|
||||||
vk/pass.cppm
|
|
||||||
vk/renderer.cppm
|
|
||||||
vk/debugger.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
preliminary
|
|
||||||
app
|
|
||||||
ecs
|
|
||||||
memory
|
|
||||||
assets
|
|
||||||
time
|
|
||||||
bitwise
|
|
||||||
camera
|
|
||||||
${Vulkan_LIBRARIES}
|
|
||||||
Vulkan::Vulkan
|
|
||||||
PRIVATE_DEPENDENCIES
|
|
||||||
surface
|
|
||||||
TESTS
|
|
||||||
_tests/buffer.cpp
|
|
||||||
_tests/debugger.cpp
|
|
||||||
_tests/device.cpp
|
|
||||||
_tests/pass.cpp
|
|
||||||
_tests/renderer.cpp
|
|
||||||
_tests/surface.cpp
|
|
||||||
_tests/system.cpp
|
|
||||||
TEST_INTERFACES
|
|
||||||
_tests/utils.cppm
|
|
||||||
)
|
|
||||||
|
|
||||||
add_module(
|
|
||||||
NAME
|
|
||||||
mirror
|
|
||||||
ROOT_DIR
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mirror
|
|
||||||
INTERFACES
|
|
||||||
system.cppm
|
|
||||||
DEPENDENCIES
|
|
||||||
memory
|
|
||||||
app
|
|
||||||
time
|
|
||||||
input
|
|
||||||
surface
|
|
||||||
renderer
|
|
||||||
camera
|
|
||||||
)
|
|
||||||
|
|
||||||
if(ENABLE_SANDBOX)
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sandbox/)
|
|
||||||
endif()
|
|
||||||
|
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
export module app;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import app.system;
|
|
||||||
import memory.reference;
|
|
||||||
import memory.scope;
|
|
||||||
|
|
||||||
export namespace lt::app {
|
|
||||||
|
|
||||||
/** The main application class.
|
|
||||||
* Think of this like an aggregate of systems, you register systems through this interface.
|
|
||||||
* Then they'll tick every "application frame".
|
|
||||||
*/
|
|
||||||
class Application
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Application(const Application &) = delete;
|
|
||||||
|
|
||||||
Application(Application &&) = delete;
|
|
||||||
|
|
||||||
auto operator=(const Application &) -> Application & = delete;
|
|
||||||
|
|
||||||
auto operator=(Application &&) -> Application & = delete;
|
|
||||||
|
|
||||||
virtual ~Application() = default;
|
|
||||||
|
|
||||||
void game_loop();
|
|
||||||
|
|
||||||
void register_system(memory::Ref<app::ISystem> system);
|
|
||||||
|
|
||||||
void unregister_system(memory::Ref<app::ISystem> system);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Application() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<memory::Ref<app::ISystem>> m_systems;
|
|
||||||
|
|
||||||
std::vector<memory::Ref<app::ISystem>> m_systems_to_be_unregistered;
|
|
||||||
|
|
||||||
std::vector<memory::Ref<app::ISystem>> m_systems_to_be_registered;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::app
|
|
||||||
|
|
||||||
module :private;
|
|
||||||
namespace lt::app {
|
|
||||||
|
|
||||||
void Application::game_loop()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
for (auto &system : m_systems)
|
|
||||||
{
|
|
||||||
const auto &last_tick = system->get_last_tick_result();
|
|
||||||
const auto now = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
system->tick(
|
|
||||||
TickInfo {
|
|
||||||
.delta_time = now - last_tick.end_time,
|
|
||||||
.budget = std::chrono::milliseconds { 10 },
|
|
||||||
.start_time = now,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &system : m_systems_to_be_registered)
|
|
||||||
{
|
|
||||||
m_systems.emplace_back(system)->on_register();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &system : m_systems_to_be_unregistered)
|
|
||||||
{
|
|
||||||
m_systems.erase(
|
|
||||||
std::remove(m_systems.begin(), m_systems.end(), system),
|
|
||||||
m_systems.end()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_systems.empty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::register_system(memory::Ref<app::ISystem> system)
|
|
||||||
{
|
|
||||||
m_systems.emplace_back(std::move(system));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::unregister_system(memory::Ref<app::ISystem> system)
|
|
||||||
{
|
|
||||||
m_systems_to_be_unregistered.emplace_back(std::move(system));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::app
|
|
||||||
|
|
@ -1,111 +0,0 @@
|
||||||
export module app.system;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import logger;
|
|
||||||
|
|
||||||
export namespace lt::app {
|
|
||||||
|
|
||||||
/** Information required to tick a system.
|
|
||||||
* @note May be used across an entire application-frame (consisting of multiple systems ticking)
|
|
||||||
*/
|
|
||||||
struct TickInfo
|
|
||||||
{
|
|
||||||
using Timepoint_T = std::chrono::time_point<std::chrono::steady_clock>;
|
|
||||||
|
|
||||||
using Duration_T = std::chrono::duration<f64>;
|
|
||||||
|
|
||||||
/** Duration since previous tick's end_time to current tick's start_time. */
|
|
||||||
Duration_T delta_time {};
|
|
||||||
|
|
||||||
/** Maximum duration the system is expected to finish ticking in.
|
|
||||||
*
|
|
||||||
* if end_time - start_time > budget -> the system exceeded its ticking budget.
|
|
||||||
* else end_time - start_time < budget -> the system ticked properly.
|
|
||||||
*
|
|
||||||
* In other words, end_time is expected to be less than start_time + budget.
|
|
||||||
*/
|
|
||||||
Duration_T budget {};
|
|
||||||
|
|
||||||
/** Exact time which ticking started. */
|
|
||||||
Timepoint_T start_time;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Information about how a system's tick performed */
|
|
||||||
struct TickResult
|
|
||||||
{
|
|
||||||
using Timepoint_T = std::chrono::time_point<std::chrono::steady_clock>;
|
|
||||||
|
|
||||||
using Duration_T = std::chrono::duration<f64>;
|
|
||||||
|
|
||||||
/** The info supplied to the system for ticking. */
|
|
||||||
TickInfo info;
|
|
||||||
|
|
||||||
/** Equivalent to end_time - info.start_time. */
|
|
||||||
Duration_T duration {};
|
|
||||||
|
|
||||||
/** Exact time which ticking ended. */
|
|
||||||
Timepoint_T end_time;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SystemDiagnosis
|
|
||||||
{
|
|
||||||
enum class Severity : u8
|
|
||||||
{
|
|
||||||
verbose,
|
|
||||||
info,
|
|
||||||
warning,
|
|
||||||
error,
|
|
||||||
fatal,
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string message;
|
|
||||||
|
|
||||||
std::string code;
|
|
||||||
|
|
||||||
Severity severity;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SystemStats
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void push_diagnosis(SystemDiagnosis &&diagnosis)
|
|
||||||
{
|
|
||||||
auto &diag = m_diagnosis.emplace_back(std::move(diagnosis));
|
|
||||||
|
|
||||||
log::info("message: {}", std::string { diag.message });
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto empty_diagnosis() const -> bool
|
|
||||||
{
|
|
||||||
return m_diagnosis.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<SystemDiagnosis> m_diagnosis;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ISystem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ISystem() = default;
|
|
||||||
|
|
||||||
virtual ~ISystem() = default;
|
|
||||||
|
|
||||||
ISystem(ISystem &&) = default;
|
|
||||||
|
|
||||||
ISystem(const ISystem &) = delete;
|
|
||||||
|
|
||||||
auto operator=(ISystem &&) -> ISystem & = default;
|
|
||||||
|
|
||||||
auto operator=(const ISystem &) -> ISystem & = delete;
|
|
||||||
|
|
||||||
virtual void on_register() = 0;
|
|
||||||
|
|
||||||
virtual void on_unregister() = 0;
|
|
||||||
|
|
||||||
virtual void tick(TickInfo tick) = 0;
|
|
||||||
|
|
||||||
[[nodiscard]] virtual auto get_last_tick_result() const -> const TickResult & = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::app
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
export module bakers;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import assets.metadata;
|
|
||||||
import assets.shader;
|
|
||||||
import logger;
|
|
||||||
|
|
||||||
export void bake_shader(
|
|
||||||
const std::filesystem::path &in_path,
|
|
||||||
const std::filesystem::path &out_path,
|
|
||||||
lt::assets::ShaderAsset::Type type
|
|
||||||
)
|
|
||||||
{
|
|
||||||
using lt::assets::ShaderAsset;
|
|
||||||
using enum lt::assets::ShaderAsset::Type;
|
|
||||||
|
|
||||||
auto glsl_path = std::string { in_path.string() };
|
|
||||||
auto spv_path = std::format("{}.spv", glsl_path);
|
|
||||||
lt::log::trace(
|
|
||||||
"Compiling {} shader {} -> {}",
|
|
||||||
type == vertex ? "vertex" : "fragment",
|
|
||||||
std::string { glsl_path },
|
|
||||||
std::string { spv_path }
|
|
||||||
);
|
|
||||||
|
|
||||||
// Don't bother linking to shaderc, just invoke the command with a system call.
|
|
||||||
// NOLINTNEXTLINE(concurrency-mt-unsafe)
|
|
||||||
std::system(
|
|
||||||
std::format(
|
|
||||||
"glslc --target-env=vulkan1.4 -std=450core -fshader-stage={} {} -o {}",
|
|
||||||
type == vertex ? "vert" : "frag",
|
|
||||||
glsl_path,
|
|
||||||
spv_path
|
|
||||||
)
|
|
||||||
.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
auto stream = std::ifstream(spv_path, std::ios::binary);
|
|
||||||
ensure(
|
|
||||||
stream.is_open(),
|
|
||||||
"Failed to open compiled {} shader at: {}",
|
|
||||||
type == vertex ? "vert" : "frag",
|
|
||||||
spv_path
|
|
||||||
);
|
|
||||||
|
|
||||||
stream.seekg(0, std::ios::end);
|
|
||||||
const auto size = stream.tellg();
|
|
||||||
|
|
||||||
auto bytes = std::vector<byte>(size);
|
|
||||||
stream.seekg(0, std::ios::beg);
|
|
||||||
stream.read((char *)bytes.data(), size); // NOLINT
|
|
||||||
stream.close();
|
|
||||||
std::filesystem::remove(spv_path);
|
|
||||||
|
|
||||||
ShaderAsset::pack(
|
|
||||||
out_path,
|
|
||||||
lt::assets::AssetMetadata {
|
|
||||||
.version = lt::assets::current_version,
|
|
||||||
.type = ShaderAsset::asset_type_identifier,
|
|
||||||
},
|
|
||||||
ShaderAsset::Metadata {
|
|
||||||
.type = type,
|
|
||||||
},
|
|
||||||
std::move(bytes)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
import preliminary;
|
|
||||||
import assets.shader;
|
|
||||||
import logger;
|
|
||||||
import bakers;
|
|
||||||
|
|
||||||
auto main(i32 argc, char *argv[]) -> i32
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (argc != 2)
|
|
||||||
{
|
|
||||||
throw std::logic_error("Argc should be 2 -- exe dir (implicit) and target dir");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &directory_iterator :
|
|
||||||
std::filesystem::recursive_directory_iterator(argv[1])) // NOLINT
|
|
||||||
{
|
|
||||||
if (directory_iterator.is_directory())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &in_path = directory_iterator.path();
|
|
||||||
const std::string in_path_str = in_path.generic_string();
|
|
||||||
const auto out_path = std::format("{}.asset", in_path_str);
|
|
||||||
|
|
||||||
if (in_path.extension() == ".vert")
|
|
||||||
{
|
|
||||||
bake_shader(in_path, out_path, lt::assets::ShaderAsset::Type::vertex);
|
|
||||||
}
|
|
||||||
else if (in_path.extension() == ".frag")
|
|
||||||
{
|
|
||||||
bake_shader(in_path, out_path, lt::assets::ShaderAsset::Type::fragment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
catch (const std::exception &exp)
|
|
||||||
{
|
|
||||||
lt::log::critical("Terminating due to uncaught exception:");
|
|
||||||
lt::log::critical("\texception.what: {}:", exp.what());
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
export module assets.metadata;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
export namespace lt::assets {
|
|
||||||
|
|
||||||
using Type_T = std::array<const char, 16>;
|
|
||||||
|
|
||||||
using Tag_T = u8;
|
|
||||||
|
|
||||||
using Version = u8;
|
|
||||||
|
|
||||||
using Blob = std::vector<byte>;
|
|
||||||
|
|
||||||
constexpr auto current_version = Version { 1u };
|
|
||||||
|
|
||||||
enum class CompressionType : u8
|
|
||||||
{
|
|
||||||
none,
|
|
||||||
lz4,
|
|
||||||
lz4_hc,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AssetMetadata
|
|
||||||
{
|
|
||||||
Version version;
|
|
||||||
|
|
||||||
Type_T type;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BlobMetadata
|
|
||||||
{
|
|
||||||
Tag_T tag;
|
|
||||||
|
|
||||||
size_t offset;
|
|
||||||
|
|
||||||
CompressionType compression_type;
|
|
||||||
|
|
||||||
size_t compressed_size;
|
|
||||||
|
|
||||||
size_t uncompressed_size;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::assets
|
|
||||||
|
|
@ -1,226 +0,0 @@
|
||||||
export module assets.shader;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import assets.metadata;
|
|
||||||
import logger;
|
|
||||||
|
|
||||||
export namespace lt::assets {
|
|
||||||
|
|
||||||
class ShaderAsset
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static constexpr auto asset_type_identifier = Type_T { "SHADER_________" };
|
|
||||||
|
|
||||||
enum class BlobTag : Tag_T
|
|
||||||
{
|
|
||||||
code,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class Type : u8
|
|
||||||
{
|
|
||||||
vertex,
|
|
||||||
fragment,
|
|
||||||
geometry,
|
|
||||||
compute,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Metadata
|
|
||||||
{
|
|
||||||
Type type;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void pack(
|
|
||||||
const std::filesystem::path &destination,
|
|
||||||
AssetMetadata asset_metadata,
|
|
||||||
Metadata metadata,
|
|
||||||
Blob code_blob
|
|
||||||
);
|
|
||||||
|
|
||||||
ShaderAsset(const std::filesystem::path &path);
|
|
||||||
|
|
||||||
void unpack_to(BlobTag tag, std::span<byte> destination) const;
|
|
||||||
|
|
||||||
[[nodiscard]] auto unpack(BlobTag tag) const -> Blob;
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_asset_metadata() const -> const AssetMetadata &
|
|
||||||
{
|
|
||||||
return m_asset_metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_metadata() const -> const Metadata &
|
|
||||||
{
|
|
||||||
return m_metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_blob_metadata(BlobTag tag) const -> const BlobMetadata &
|
|
||||||
{
|
|
||||||
ensure(
|
|
||||||
tag == BlobTag::code,
|
|
||||||
"Invalid blob tag for shader asset: {}",
|
|
||||||
std::to_underlying(tag)
|
|
||||||
);
|
|
||||||
|
|
||||||
return m_code_blob_metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
AssetMetadata m_asset_metadata {};
|
|
||||||
|
|
||||||
Metadata m_metadata {};
|
|
||||||
|
|
||||||
BlobMetadata m_code_blob_metadata {};
|
|
||||||
|
|
||||||
mutable std::ifstream m_stream;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::assets
|
|
||||||
|
|
||||||
|
|
||||||
namespace lt::assets {
|
|
||||||
|
|
||||||
constexpr auto total_metadata_size = //
|
|
||||||
sizeof(AssetMetadata::type) //
|
|
||||||
+ sizeof(AssetMetadata::version) //
|
|
||||||
+ sizeof(ShaderAsset::Metadata::type) //
|
|
||||||
+ sizeof(BlobMetadata::tag) //
|
|
||||||
+ sizeof(BlobMetadata::offset) //
|
|
||||||
+ sizeof(BlobMetadata::compression_type) //
|
|
||||||
+ sizeof(BlobMetadata::compressed_size) //
|
|
||||||
+ sizeof(BlobMetadata::uncompressed_size);
|
|
||||||
|
|
||||||
ShaderAsset::ShaderAsset(const std::filesystem::path &path)
|
|
||||||
: m_stream(path, std::ios::beg | std::ios::binary)
|
|
||||||
{
|
|
||||||
ensure(m_stream.is_open(), "Failed to open shader asset at: {}", path.string());
|
|
||||||
const auto read = [this](auto &field) {
|
|
||||||
m_stream.read(std::bit_cast<char *>(&field), sizeof(field));
|
|
||||||
};
|
|
||||||
|
|
||||||
m_stream.seekg(0, std::ifstream::end);
|
|
||||||
const auto file_size = static_cast<size_t>(m_stream.tellg());
|
|
||||||
ensure(
|
|
||||||
file_size > total_metadata_size,
|
|
||||||
"Failed to open shader asset at: {}, file smaller than metadata: {} < {}",
|
|
||||||
path.string(),
|
|
||||||
total_metadata_size,
|
|
||||||
file_size
|
|
||||||
);
|
|
||||||
|
|
||||||
m_stream.seekg(0, std::ifstream::beg);
|
|
||||||
read(m_asset_metadata.type);
|
|
||||||
read(m_asset_metadata.version);
|
|
||||||
read(m_metadata.type);
|
|
||||||
|
|
||||||
read(m_code_blob_metadata.tag);
|
|
||||||
read(m_code_blob_metadata.offset);
|
|
||||||
read(m_code_blob_metadata.compression_type);
|
|
||||||
read(m_code_blob_metadata.compressed_size);
|
|
||||||
read(m_code_blob_metadata.uncompressed_size);
|
|
||||||
|
|
||||||
ensure(
|
|
||||||
m_asset_metadata.type == asset_type_identifier,
|
|
||||||
"Failed to open shader asset at: {}, incorrect asset type: {} != {}",
|
|
||||||
path.string(),
|
|
||||||
m_asset_metadata.type,
|
|
||||||
asset_type_identifier
|
|
||||||
);
|
|
||||||
|
|
||||||
ensure(
|
|
||||||
m_asset_metadata.version == current_version,
|
|
||||||
"Failed to open shader asset at: {}, version mismatch: {} != {}",
|
|
||||||
path.string(),
|
|
||||||
m_asset_metadata.version,
|
|
||||||
current_version
|
|
||||||
);
|
|
||||||
|
|
||||||
ensure(
|
|
||||||
std::to_underlying(m_metadata.type) <= std::to_underlying(Type::compute),
|
|
||||||
"Failed to open shader asset at: {}, invalid shader type: {}",
|
|
||||||
path.string(),
|
|
||||||
std::to_underlying(m_metadata.type)
|
|
||||||
);
|
|
||||||
|
|
||||||
ensure(
|
|
||||||
m_code_blob_metadata.tag == std::to_underlying(BlobTag::code),
|
|
||||||
"Failed to open shader asset at: {}, invalid blob tag: {}",
|
|
||||||
path.string(),
|
|
||||||
m_code_blob_metadata.tag
|
|
||||||
);
|
|
||||||
|
|
||||||
ensure(
|
|
||||||
m_code_blob_metadata.offset + m_code_blob_metadata.compressed_size <= file_size,
|
|
||||||
"Failed to open shader asset at: {}, file smaller than blob: {} > {} + {}",
|
|
||||||
path.string(),
|
|
||||||
file_size,
|
|
||||||
m_code_blob_metadata.offset,
|
|
||||||
m_code_blob_metadata.compressed_size
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */ void ShaderAsset::pack(
|
|
||||||
const std::filesystem::path &destination,
|
|
||||||
AssetMetadata asset_metadata,
|
|
||||||
Metadata metadata,
|
|
||||||
Blob code_blob
|
|
||||||
)
|
|
||||||
{
|
|
||||||
auto stream = std::ofstream {
|
|
||||||
destination,
|
|
||||||
std::ios::binary | std::ios::trunc,
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto code_blob_metadata = BlobMetadata {
|
|
||||||
.tag = std::to_underlying(BlobTag::code),
|
|
||||||
.offset = total_metadata_size,
|
|
||||||
.compression_type = CompressionType::none,
|
|
||||||
.compressed_size = code_blob.size(),
|
|
||||||
.uncompressed_size = code_blob.size(),
|
|
||||||
};
|
|
||||||
|
|
||||||
ensure(stream.is_open(), "Failed to pack shader asset to {}", destination.string());
|
|
||||||
const auto write = [&stream](auto &field) {
|
|
||||||
stream.write(std::bit_cast<char *>(&field), sizeof(field));
|
|
||||||
};
|
|
||||||
write(asset_metadata.type);
|
|
||||||
write(asset_metadata.version);
|
|
||||||
write(metadata.type);
|
|
||||||
write(code_blob_metadata.tag);
|
|
||||||
write(code_blob_metadata.offset);
|
|
||||||
write(code_blob_metadata.compression_type);
|
|
||||||
write(code_blob_metadata.compressed_size);
|
|
||||||
write(code_blob_metadata.uncompressed_size);
|
|
||||||
stream.write(std::bit_cast<char *>(code_blob.data()), static_cast<long long>(code_blob.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderAsset::unpack_to(BlobTag tag, std::span<byte> destination) const
|
|
||||||
{
|
|
||||||
ensure(tag == BlobTag::code, "Invalid blob tag for shader asset: {}", std::to_underlying(tag));
|
|
||||||
|
|
||||||
ensure(
|
|
||||||
destination.size() >= m_code_blob_metadata.uncompressed_size,
|
|
||||||
"Failed to unpack shader blob {} to destination ({}) of size {} since it's smaller "
|
|
||||||
"than the blobl's uncompressed size: {}",
|
|
||||||
std::to_underlying(tag),
|
|
||||||
std::bit_cast<size_t>(destination.data()),
|
|
||||||
destination.size(),
|
|
||||||
m_code_blob_metadata.uncompressed_size
|
|
||||||
);
|
|
||||||
|
|
||||||
m_stream.seekg(static_cast<long long>(m_code_blob_metadata.offset), std::ifstream::beg);
|
|
||||||
m_stream.read(
|
|
||||||
std::bit_cast<char *>(destination.data()),
|
|
||||||
m_code_blob_metadata.uncompressed_size
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto ShaderAsset::unpack(BlobTag tag) const -> Blob
|
|
||||||
{
|
|
||||||
ensure(tag == BlobTag::code, "Invalid blob tag for shader asset: {}", std::to_underlying(tag));
|
|
||||||
|
|
||||||
auto blob = Blob(m_code_blob_metadata.uncompressed_size);
|
|
||||||
unpack_to(tag, blob);
|
|
||||||
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::assets
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
||||||
import test;
|
|
||||||
import assets.metadata;
|
|
||||||
import assets.shader;
|
|
||||||
|
|
||||||
using ::lt::assets::AssetMetadata;
|
|
||||||
using ::lt::assets::Blob;
|
|
||||||
using ::lt::assets::BlobMetadata;
|
|
||||||
using ::lt::assets::ShaderAsset;
|
|
||||||
|
|
||||||
const auto test_data_path = std::filesystem::path { "./data/test_assets" };
|
|
||||||
const auto tmp_path = std::filesystem::path { "/tmp/lt_assets_tests/" };
|
|
||||||
|
|
||||||
[[nodiscard]] auto generate_blob(size_t size) -> Blob
|
|
||||||
{
|
|
||||||
auto blob = Blob {};
|
|
||||||
for (auto idx : std::views::iota(0u, size))
|
|
||||||
{
|
|
||||||
blob.emplace_back(static_cast<byte>(idx));
|
|
||||||
}
|
|
||||||
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
Suite raii = "shader_raii"_suite = [] {
|
|
||||||
std::filesystem::current_path(test_data_path);
|
|
||||||
std::filesystem::create_directories(tmp_path);
|
|
||||||
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
auto shader_asset = ShaderAsset { "triangle.frag.asset" };
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
// non-existent file
|
|
||||||
expect_throw([] { ShaderAsset { "path" }; });
|
|
||||||
|
|
||||||
// incompatible type
|
|
||||||
expect_throw([] { ShaderAsset { "dummytext" }; });
|
|
||||||
|
|
||||||
// some random stressing
|
|
||||||
expect_throw([] {
|
|
||||||
for (auto idx : std::views::iota(0u, 1'000u))
|
|
||||||
{
|
|
||||||
auto shader_asset = ShaderAsset { std::to_string(idx) };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
for (auto idx : std::views::iota(0u, 1'000u))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
auto shader_asset = ShaderAsset { "triangle.frag.asset" };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite packing = "shader_pack"_suite = [] {
|
|
||||||
Case { "Unpacking packed data returns the same data" } = [] {
|
|
||||||
const auto out_path = tmp_path / "shader_packing";
|
|
||||||
constexpr auto blob_size = size_t { 255u };
|
|
||||||
|
|
||||||
auto blob = generate_blob(blob_size);
|
|
||||||
|
|
||||||
const auto expected_size = //
|
|
||||||
sizeof(AssetMetadata::type) //
|
|
||||||
+ sizeof(AssetMetadata::version) //
|
|
||||||
+ sizeof(ShaderAsset::Metadata::type) //
|
|
||||||
+ sizeof(BlobMetadata::tag) //
|
|
||||||
+ sizeof(BlobMetadata::offset) //
|
|
||||||
+ sizeof(BlobMetadata::compression_type) //
|
|
||||||
+ sizeof(BlobMetadata::compressed_size) //
|
|
||||||
+ sizeof(BlobMetadata::uncompressed_size) //
|
|
||||||
+ blob.size();
|
|
||||||
|
|
||||||
ShaderAsset::pack(
|
|
||||||
out_path,
|
|
||||||
lt::assets::AssetMetadata {
|
|
||||||
.version = lt::assets::current_version,
|
|
||||||
.type = ShaderAsset::asset_type_identifier,
|
|
||||||
},
|
|
||||||
ShaderAsset::Metadata {
|
|
||||||
.type = ShaderAsset::Type::vertex,
|
|
||||||
},
|
|
||||||
std::move(blob)
|
|
||||||
);
|
|
||||||
|
|
||||||
auto stream = std::ifstream {
|
|
||||||
out_path,
|
|
||||||
std::ios::binary,
|
|
||||||
};
|
|
||||||
expect_true(stream.is_open());
|
|
||||||
|
|
||||||
stream.seekg(0u, std::ios::end);
|
|
||||||
const auto file_size = static_cast<size_t>(stream.tellg());
|
|
||||||
expect_eq(file_size, expected_size);
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
auto shader_asset = ShaderAsset { out_path };
|
|
||||||
|
|
||||||
const auto &asset_metadata = shader_asset.get_asset_metadata();
|
|
||||||
expect_eq(asset_metadata.type, ShaderAsset::asset_type_identifier);
|
|
||||||
expect_eq(asset_metadata.version, lt::assets::current_version);
|
|
||||||
|
|
||||||
const auto &metadata = shader_asset.get_metadata();
|
|
||||||
expect_eq(metadata.type, ShaderAsset::Type::vertex);
|
|
||||||
|
|
||||||
auto unpakced_blob = shader_asset.unpack(ShaderAsset::BlobTag::code);
|
|
||||||
expect_eq(unpakced_blob.size(), blob_size);
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0u, blob_size))
|
|
||||||
{
|
|
||||||
expect_eq(unpakced_blob[idx], static_cast<byte>(idx));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
export module bitwise;
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
namespace lt::bitwise {
|
|
||||||
|
|
||||||
/* bit-wise */
|
|
||||||
export constexpr auto bit(u32 x) -> u32
|
|
||||||
{
|
|
||||||
return u32 { 1u } << x;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::bitwise
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
export module camera.components;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import math.vec4;
|
|
||||||
|
|
||||||
export namespace lt::camera::components {
|
|
||||||
|
|
||||||
struct PerspectiveCamera
|
|
||||||
{
|
|
||||||
f32 vertical_fov {};
|
|
||||||
|
|
||||||
f32 near_plane {};
|
|
||||||
|
|
||||||
f32 far_plane {};
|
|
||||||
|
|
||||||
f32 aspect_ratio {};
|
|
||||||
|
|
||||||
math::vec4 background_color;
|
|
||||||
|
|
||||||
bool is_primary {};
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::camera::components
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
export module ecs.entity;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import memory.reference;
|
|
||||||
import ecs.registry;
|
|
||||||
|
|
||||||
export namespace lt::ecs {
|
|
||||||
|
|
||||||
/** High-level entity convenience wrapper */
|
|
||||||
class Entity
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Entity(memory::Ref<Registry> registry, EntityId identifier)
|
|
||||||
: m_registry(std::move(registry))
|
|
||||||
, m_identifier(identifier)
|
|
||||||
{
|
|
||||||
ensure(m_registry, "Failed to create Entity ({}): null registry", m_identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
auto add(Component_T component) -> Component_T &
|
|
||||||
{
|
|
||||||
return m_registry->add(m_identifier, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
auto get() -> Component_T &
|
|
||||||
{
|
|
||||||
return m_registry->get<Component_T>(m_identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
auto get() const -> const Component_T &
|
|
||||||
{
|
|
||||||
return m_registry->get<Component_T>(m_identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto get_registry() -> memory::Ref<Registry>
|
|
||||||
{
|
|
||||||
return m_registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto id() const -> EntityId
|
|
||||||
{
|
|
||||||
return m_identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
memory::Ref<Registry> m_registry;
|
|
||||||
|
|
||||||
EntityId m_identifier;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::ecs
|
|
||||||
6
modules/ecs/private/sparse_set.hpp
Normal file
6
modules/ecs/private/sparse_set.hpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace lt::ecs {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,266 +0,0 @@
|
||||||
export module ecs.registry;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import ecs.sparse_set;
|
|
||||||
import memory.scope;
|
|
||||||
|
|
||||||
export namespace lt::ecs {
|
|
||||||
|
|
||||||
using EntityId = u32;
|
|
||||||
|
|
||||||
constexpr auto null_entity = std::numeric_limits<EntityId>::max();
|
|
||||||
|
|
||||||
/** A registry of components, the heart of an ECS architecture.
|
|
||||||
*
|
|
||||||
* @todo(Light): Implement grouping
|
|
||||||
* @todo(Light): Implement identifier recycling
|
|
||||||
* @todo(Light): Optimize views/each
|
|
||||||
* @todo(Light): Support >2 component views
|
|
||||||
* @todo(Light): Handle more edge cases or specify the undefined behaviors
|
|
||||||
*
|
|
||||||
* @ref https://skypjack.github.io/
|
|
||||||
* @ref https://github.com/alecthomas/entityx
|
|
||||||
* @ref https://github.com/skypjack/entt
|
|
||||||
* @ref https://github.com/SanderMertens/flecs
|
|
||||||
*/
|
|
||||||
class Registry
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
using UnderlyingSparseSet_T = TypeErasedSparseSet<EntityId>;
|
|
||||||
|
|
||||||
using Callback_T = std::function<void(Registry &, EntityId)>;
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
void connect_on_construct(Callback_T callback)
|
|
||||||
{
|
|
||||||
m_on_construct_hooks[get_type_id<Component_T>()] = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
void connect_on_destruct(Callback_T callback)
|
|
||||||
{
|
|
||||||
m_on_destruct_hooks[get_type_id<Component_T>()] = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
void disconnect_on_construct()
|
|
||||||
{
|
|
||||||
m_on_construct_hooks.erase(get_type_id<Component_T>());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
void disconnect_on_destruct()
|
|
||||||
{
|
|
||||||
m_on_destruct_hooks.erase(get_type_id<Component_T>());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto create_entity() -> EntityId
|
|
||||||
{
|
|
||||||
++m_entity_count;
|
|
||||||
return m_current++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy_entity(EntityId entity)
|
|
||||||
{
|
|
||||||
for (const auto &[key, set] : m_sparsed_sets)
|
|
||||||
{
|
|
||||||
set->remove(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
--m_entity_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
auto get(EntityId entity) const -> const Component_T &
|
|
||||||
{
|
|
||||||
auto &derived_set = get_derived_set<Component_T>();
|
|
||||||
return derived_set.at(entity).second;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
auto get(EntityId entity) -> Component_T &
|
|
||||||
{
|
|
||||||
auto &derived_set = get_derived_set<Component_T>();
|
|
||||||
return derived_set.at(entity).second;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
auto add(EntityId entity, Component_T component) -> Component_T &
|
|
||||||
{
|
|
||||||
auto &derived_set = get_derived_set<Component_T>();
|
|
||||||
auto &added_component = derived_set.insert(entity, std::move(component)).second;
|
|
||||||
|
|
||||||
if (m_on_construct_hooks.contains(get_type_id<Component_T>()))
|
|
||||||
{
|
|
||||||
m_on_construct_hooks[get_type_id<Component_T>()](*this, entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
return added_component;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
void remove(EntityId entity)
|
|
||||||
{
|
|
||||||
if (m_on_destruct_hooks.contains(get_type_id<Component_T>()))
|
|
||||||
{
|
|
||||||
m_on_destruct_hooks[get_type_id<Component_T>()](*this, entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto &derived_set = get_derived_set<Component_T>();
|
|
||||||
derived_set.remove(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
auto view() -> SparseSet<Component_T, EntityId> &
|
|
||||||
{
|
|
||||||
return get_derived_set<Component_T>();
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename ComponentA_T, typename ComponentB_T>
|
|
||||||
requires(!std::is_same_v<ComponentA_T, ComponentB_T>)
|
|
||||||
auto view() -> std::vector<std::tuple<EntityId, ComponentA_T &, ComponentB_T &>>
|
|
||||||
{
|
|
||||||
auto &set_a = get_derived_set<ComponentA_T>();
|
|
||||||
auto &set_b = get_derived_set<ComponentB_T>();
|
|
||||||
auto view = std::vector<std::tuple<EntityId, ComponentA_T &, ComponentB_T &>> {};
|
|
||||||
|
|
||||||
/* iterate over the "smaller" component-set, and check if its entities have the other
|
|
||||||
* component */
|
|
||||||
if (set_a.get_size() > set_b.get_size())
|
|
||||||
{
|
|
||||||
for (auto &[entity, component_b] : set_b)
|
|
||||||
{
|
|
||||||
if (set_a.contains(entity))
|
|
||||||
{
|
|
||||||
view.emplace_back(std::tie(entity, set_a.at(entity).second, component_b));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto &[entity, component_a] : set_a)
|
|
||||||
{
|
|
||||||
if (set_b.contains(entity))
|
|
||||||
{
|
|
||||||
view.emplace_back(std::tie(entity, component_a, set_b.at(entity).second));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Component_T>
|
|
||||||
void each(std::function<void(EntityId, Component_T &)> functor)
|
|
||||||
{
|
|
||||||
for (auto &[entity, component] : get_derived_set<Component_T>())
|
|
||||||
{
|
|
||||||
functor(entity, component);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename ComponentA_T, typename ComponentB_T>
|
|
||||||
requires(!std::is_same_v<ComponentA_T, ComponentB_T>)
|
|
||||||
void each(std::function<void(EntityId, ComponentA_T &, ComponentB_T &)> functor)
|
|
||||||
{
|
|
||||||
auto &set_a = get_derived_set<ComponentA_T>();
|
|
||||||
auto &set_b = get_derived_set<ComponentB_T>();
|
|
||||||
|
|
||||||
/* iterate over the "smaller" component-set, and check if its entities have the other
|
|
||||||
* component */
|
|
||||||
if (set_a.get_size() > set_b.get_size())
|
|
||||||
{
|
|
||||||
for (auto &[entity, component_b] : set_b)
|
|
||||||
{
|
|
||||||
if (set_a.contains(entity))
|
|
||||||
{
|
|
||||||
functor(entity, set_a.at(entity).second, component_b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &[entity, component_a] : set_a)
|
|
||||||
{
|
|
||||||
if (set_b.contains(entity))
|
|
||||||
{
|
|
||||||
functor(entity, component_a, set_b.at(entity).second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_entity_count() const -> size_t
|
|
||||||
{
|
|
||||||
return static_cast<size_t>(m_entity_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
using TypeId = size_t;
|
|
||||||
|
|
||||||
static consteval auto hash_cstr(const char *str) -> TypeId
|
|
||||||
{
|
|
||||||
constexpr auto fnv_offset_basis = size_t { 14695981039346656037ull };
|
|
||||||
constexpr auto fnv_prime = size_t { 1099511628211ull };
|
|
||||||
|
|
||||||
auto hash = fnv_offset_basis;
|
|
||||||
|
|
||||||
for (const auto &ch : std::string_view { str })
|
|
||||||
{
|
|
||||||
hash *= fnv_prime;
|
|
||||||
hash ^= static_cast<u8>(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static consteval auto get_type_id() -> TypeId
|
|
||||||
{
|
|
||||||
#if defined _MSC_VER
|
|
||||||
#define GENERATOR_PRETTY_FUNCTION __FUNCSIG__
|
|
||||||
#elif defined __clang__ || (defined __GNUC__)
|
|
||||||
#define GENERATOR_PRETTY_FUNCTION __PRETTY_FUNCTION__
|
|
||||||
#else
|
|
||||||
#error "Compiler not supported"
|
|
||||||
#endif
|
|
||||||
constexpr auto value = hash_cstr(GENERATOR_PRETTY_FUNCTION);
|
|
||||||
|
|
||||||
#undef GENERATOR_PRETTY_FUNCTION
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
auto get_derived_set() -> SparseSet<T, EntityId> &
|
|
||||||
{
|
|
||||||
constexpr auto type_id = get_type_id<T>();
|
|
||||||
if (!m_sparsed_sets.contains(type_id))
|
|
||||||
{
|
|
||||||
m_sparsed_sets[type_id] = memory::create_scope<SparseSet<T, EntityId>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *base_set = m_sparsed_sets[type_id].get();
|
|
||||||
auto *derived_set = dynamic_cast<SparseSet<T, EntityId> *>(base_set);
|
|
||||||
ensure(derived_set, "Failed to downcast to derived set");
|
|
||||||
|
|
||||||
return *derived_set;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityId m_current;
|
|
||||||
|
|
||||||
TypeId m_entity_count;
|
|
||||||
|
|
||||||
/** MSVC DOES NOT SUPPORT FLAT MAP!!
|
|
||||||
* IT"S YEAR ~2026, great...
|
|
||||||
* using ::std::map for the time being.
|
|
||||||
*/
|
|
||||||
|
|
||||||
std::map<TypeId, memory::Scope<UnderlyingSparseSet_T>> m_sparsed_sets;
|
|
||||||
|
|
||||||
std::map<TypeId, Callback_T> m_on_construct_hooks;
|
|
||||||
|
|
||||||
std::map<TypeId, Callback_T> m_on_destruct_hooks;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::ecs
|
|
||||||
|
|
@ -1,345 +0,0 @@
|
||||||
import test;
|
|
||||||
import ecs.registry;
|
|
||||||
|
|
||||||
using ::lt::ecs::EntityId;
|
|
||||||
using ::lt::ecs::Registry;
|
|
||||||
|
|
||||||
struct Component
|
|
||||||
{
|
|
||||||
i32 m_int {};
|
|
||||||
std::string m_string;
|
|
||||||
|
|
||||||
[[nodiscard]] friend auto operator==(const Component &lhs, const Component &rhs) -> bool
|
|
||||||
{
|
|
||||||
return lhs.m_int == rhs.m_int && lhs.m_string == rhs.m_string;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct std::formatter<Component>
|
|
||||||
{
|
|
||||||
constexpr auto parse(std::format_parse_context &context)
|
|
||||||
{
|
|
||||||
return context.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto format(const Component &val, std::format_context &context) const
|
|
||||||
{
|
|
||||||
return std::format_to(context.out(), "{}, {}", val.m_int, val.m_string);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Component_B
|
|
||||||
{
|
|
||||||
f32 m_float {};
|
|
||||||
|
|
||||||
[[nodiscard]] friend auto operator==(const Component_B lhs, const Component_B &rhs) -> bool
|
|
||||||
{
|
|
||||||
return lhs.m_float == rhs.m_float;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct std::formatter<Component_B>
|
|
||||||
{
|
|
||||||
constexpr auto parse(std::format_parse_context &context)
|
|
||||||
{
|
|
||||||
return context.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto format(const Component_B &val, std::format_context &context) const
|
|
||||||
{
|
|
||||||
return std::format_to(context.out(), "{}", val.m_float);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite raii = "raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
ignore = Registry {};
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
for (auto idx : std::views::iota(0, 100'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
ignore = Registry {};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct has correct state" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
expect_eq(registry.get_entity_count(), 0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite entity_raii = "entity_raii"_suite = [] {
|
|
||||||
Case { "create_entity returns unique values" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
auto set = std::unordered_set<EntityId> {};
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
auto entity = registry.create_entity();
|
|
||||||
expect_false(set.contains(entity));
|
|
||||||
|
|
||||||
set.insert(entity);
|
|
||||||
expect_eq(set.size(), idx + 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post create/destroy_entity has correct state" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
|
|
||||||
auto entities = std::vector<EntityId> {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
entities.emplace_back(registry.create_entity());
|
|
||||||
expect_eq(registry.get_entity_count(), idx + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
auto entity = entities.back();
|
|
||||||
registry.destroy_entity(entity);
|
|
||||||
|
|
||||||
entities.pop_back();
|
|
||||||
expect_eq(registry.get_entity_count(), 10'000 - (idx + 1));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite component_raii = "component_raii"_suite = [] {
|
|
||||||
Case { "add has correct state" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
for (auto idx : std::views::iota(0, 100'000))
|
|
||||||
{
|
|
||||||
auto entity = registry.create_entity();
|
|
||||||
auto &component = registry.add<Component>(
|
|
||||||
entity,
|
|
||||||
{ .m_int = idx, .m_string = std::to_string(idx) }
|
|
||||||
);
|
|
||||||
|
|
||||||
expect_eq(component.m_int, idx);
|
|
||||||
expect_eq(component.m_string, std::to_string(idx));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "remove has correct state" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
for (auto idx : std::views::iota(0, 100'000))
|
|
||||||
{
|
|
||||||
auto entity = registry.create_entity();
|
|
||||||
auto &component = registry.add<Component>(
|
|
||||||
entity,
|
|
||||||
{ .m_int = idx, .m_string = std::to_string(idx) }
|
|
||||||
);
|
|
||||||
|
|
||||||
expect_eq(component.m_int, idx);
|
|
||||||
expect_eq(component.m_string, std::to_string(idx));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite callbacks = "callbacks"_suite = [] {
|
|
||||||
Case { "connecting on_construct/on_destruct won't throw" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
registry.connect_on_construct<Component>([&](Registry &, EntityId) {});
|
|
||||||
registry.connect_on_destruct<Component>([&](Registry &, EntityId) {});
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "on_construct/on_destruct won't get called on unrelated component" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
|
|
||||||
registry.connect_on_construct<Component>([&](Registry &, EntityId) {
|
|
||||||
expect_unreachable();
|
|
||||||
});
|
|
||||||
registry.connect_on_destruct<Component>([&](Registry &, EntityId) {
|
|
||||||
expect_unreachable();
|
|
||||||
});
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 100'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
registry.add<Component_B>(registry.create_entity(), {});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "on_construct/on_destruct gets called" } = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
auto all_entities = std::vector<EntityId> {};
|
|
||||||
auto on_construct_called = std::vector<EntityId> {};
|
|
||||||
auto on_destruct_called = std::vector<EntityId> {};
|
|
||||||
|
|
||||||
registry.connect_on_construct<Component>([&](Registry &, EntityId entity) {
|
|
||||||
on_construct_called.emplace_back(entity);
|
|
||||||
});
|
|
||||||
registry.connect_on_destruct<Component>([&](Registry &, EntityId entity) {
|
|
||||||
on_destruct_called.emplace_back(entity);
|
|
||||||
});
|
|
||||||
|
|
||||||
expect_true(on_construct_called.empty());
|
|
||||||
expect_true(on_destruct_called.empty());
|
|
||||||
for (auto idx : std::views::iota(0, 100'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
|
|
||||||
auto entity = all_entities.emplace_back(registry.create_entity());
|
|
||||||
registry.add<Component>(entity, {});
|
|
||||||
}
|
|
||||||
expect_eq(on_construct_called, all_entities);
|
|
||||||
expect_true(on_destruct_called.empty());
|
|
||||||
|
|
||||||
for (auto &entity : all_entities)
|
|
||||||
{
|
|
||||||
registry.remove<Component>(entity);
|
|
||||||
}
|
|
||||||
expect_eq(on_construct_called, all_entities);
|
|
||||||
expect_eq(on_destruct_called, all_entities);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite each = "each"_suite = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
|
|
||||||
auto shared_entity_counter = 0u;
|
|
||||||
|
|
||||||
auto component_map_a = std::unordered_map<EntityId, Component> {};
|
|
||||||
auto entities_a = std::vector<EntityId> {};
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
auto entity = entities_a.emplace_back(registry.create_entity());
|
|
||||||
auto &component = registry.add<Component>(
|
|
||||||
entity,
|
|
||||||
{ .m_int = idx, .m_string = std::to_string(idx) }
|
|
||||||
);
|
|
||||||
|
|
||||||
component_map_a[entity] = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto component_map_b = std::unordered_map<EntityId, Component_B> {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
auto entity = EntityId {};
|
|
||||||
if (idx % 3 == 0)
|
|
||||||
{
|
|
||||||
entity = entities_a[idx];
|
|
||||||
++shared_entity_counter;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entity = registry.create_entity();
|
|
||||||
}
|
|
||||||
auto &component = registry.add<Component_B>(
|
|
||||||
entity,
|
|
||||||
{ .m_float = static_cast<f32>(idx) / 2.0f }
|
|
||||||
);
|
|
||||||
|
|
||||||
component_map_b[entity] = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
Case { "each one element" } = [&] {
|
|
||||||
auto counter = 0u;
|
|
||||||
registry.each<Component>([&](EntityId entity, Component &component) {
|
|
||||||
++counter;
|
|
||||||
expect_eq(component_map_a[entity], component);
|
|
||||||
});
|
|
||||||
|
|
||||||
expect_eq(component_map_a.size(), counter);
|
|
||||||
|
|
||||||
counter = 0u;
|
|
||||||
registry.each<Component_B>([&](EntityId entity, Component_B &component) {
|
|
||||||
++counter;
|
|
||||||
expect_eq(component_map_b[entity], component);
|
|
||||||
});
|
|
||||||
expect_eq(component_map_b.size(), counter);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "each two element" } = [&] {
|
|
||||||
auto counter = 0u;
|
|
||||||
registry.each<Component, Component_B>(
|
|
||||||
[&](EntityId entity, Component &component_a, Component_B &component_b) {
|
|
||||||
expect_eq(component_map_a[entity], component_a);
|
|
||||||
expect_eq(component_map_b[entity], component_b);
|
|
||||||
++counter;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
expect_eq(counter, shared_entity_counter);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite views = "views"_suite = [] {
|
|
||||||
auto registry = Registry {};
|
|
||||||
|
|
||||||
auto shared_entity_counter = 0u;
|
|
||||||
|
|
||||||
auto component_map_a = std::unordered_map<EntityId, Component> {};
|
|
||||||
auto entities_a = std::vector<EntityId> {};
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
auto entity = entities_a.emplace_back(registry.create_entity());
|
|
||||||
auto &component = registry.add<Component>(
|
|
||||||
entity,
|
|
||||||
{ .m_int = idx, .m_string = std::to_string(idx) }
|
|
||||||
);
|
|
||||||
|
|
||||||
component_map_a[entity] = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto component_map_b = std::unordered_map<EntityId, Component_B> {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
auto entity = EntityId {};
|
|
||||||
if (idx % 3 == 0)
|
|
||||||
{
|
|
||||||
entity = entities_a[idx];
|
|
||||||
++shared_entity_counter;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entity = registry.create_entity();
|
|
||||||
}
|
|
||||||
auto &component = registry.add<Component_B>(
|
|
||||||
entity,
|
|
||||||
{ .m_float = static_cast<f32>(idx) / 2.0f }
|
|
||||||
);
|
|
||||||
|
|
||||||
component_map_b[entity] = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Case { "view one component" } = [&] {
|
|
||||||
for (const auto &[entity, component] : registry.view<Component>())
|
|
||||||
{
|
|
||||||
expect_eq(component_map_a[entity], component);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &[entity, component] : registry.view<Component_B>())
|
|
||||||
{
|
|
||||||
expect_eq(component_map_b[entity], component);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "view two component" } = [&] {
|
|
||||||
auto counter = 0u;
|
|
||||||
for (const auto &[entity, component, component_b] : registry.view<Component, Component_B>())
|
|
||||||
{
|
|
||||||
expect_eq(component_map_a[entity], component);
|
|
||||||
expect_eq(component_map_b[entity], component_b);
|
|
||||||
++counter;
|
|
||||||
}
|
|
||||||
expect_eq(counter, shared_entity_counter);
|
|
||||||
|
|
||||||
counter = 0u;
|
|
||||||
for (const auto &[entity, component_b, component] : registry.view<Component_B, Component>())
|
|
||||||
{
|
|
||||||
expect_eq(component_map_b[entity], component_b);
|
|
||||||
expect_eq(component_map_a[entity], component);
|
|
||||||
++counter;
|
|
||||||
}
|
|
||||||
expect_eq(counter, shared_entity_counter);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,191 +0,0 @@
|
||||||
export module ecs.sparse_set;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
export namespace lt::ecs {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ref https://programmingpraxis.com/2012/03/09/sparse-sets/
|
|
||||||
*/
|
|
||||||
template<typename Identifier_T = u32>
|
|
||||||
class TypeErasedSparseSet
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TypeErasedSparseSet() = default;
|
|
||||||
|
|
||||||
TypeErasedSparseSet(TypeErasedSparseSet &&) = default;
|
|
||||||
|
|
||||||
TypeErasedSparseSet(const TypeErasedSparseSet &) = default;
|
|
||||||
|
|
||||||
auto operator=(TypeErasedSparseSet &&) -> TypeErasedSparseSet & = default;
|
|
||||||
|
|
||||||
auto operator=(const TypeErasedSparseSet &) -> TypeErasedSparseSet & = default;
|
|
||||||
|
|
||||||
virtual ~TypeErasedSparseSet() = default;
|
|
||||||
|
|
||||||
virtual void remove(Identifier_T identifier) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Value_T, typename Identifier_T = u32>
|
|
||||||
class SparseSet: public TypeErasedSparseSet<Identifier_T>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
using Dense_T = std::pair<Identifier_T, Value_T>;
|
|
||||||
|
|
||||||
static constexpr auto max_capacity = size_t { 1'000'000 };
|
|
||||||
|
|
||||||
static constexpr auto null_identifier = std::numeric_limits<Identifier_T>().max();
|
|
||||||
|
|
||||||
explicit SparseSet(size_t initial_capacity = 1)
|
|
||||||
{
|
|
||||||
ensure(
|
|
||||||
initial_capacity <= max_capacity,
|
|
||||||
"Failed to create SparseSet: capacity too large ({} > {})",
|
|
||||||
initial_capacity,
|
|
||||||
max_capacity
|
|
||||||
);
|
|
||||||
|
|
||||||
m_dense.reserve(initial_capacity);
|
|
||||||
m_sparse.resize(initial_capacity, null_identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto insert(Identifier_T identifier, Value_T value) -> Dense_T &
|
|
||||||
{
|
|
||||||
ensure(identifier < max_capacity, "SparseSet::insert: identifier < max_capacity");
|
|
||||||
|
|
||||||
if (m_sparse.size() < identifier + 1)
|
|
||||||
{
|
|
||||||
auto new_capacity = std::max(static_cast<size_t>(identifier + 1), m_sparse.size() * 2);
|
|
||||||
new_capacity = std::min(new_capacity, max_capacity);
|
|
||||||
|
|
||||||
m_sparse.resize(new_capacity, null_identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
++m_alive_count;
|
|
||||||
m_sparse[identifier] = static_cast<Identifier_T>(m_dense.size());
|
|
||||||
return m_dense.emplace_back(identifier, std::move(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @warn invalidates begin/end iterators
|
|
||||||
*
|
|
||||||
* @todo(Light): make it not invalidate the iterators >:c
|
|
||||||
*/
|
|
||||||
void remove(Identifier_T identifier) override
|
|
||||||
{
|
|
||||||
ensure(
|
|
||||||
identifier < m_sparse.size(),
|
|
||||||
"Failed to ensure: identifier < m_sparse.size() [{} < {}]",
|
|
||||||
identifier,
|
|
||||||
m_sparse.size()
|
|
||||||
);
|
|
||||||
|
|
||||||
auto &idx = m_sparse[identifier];
|
|
||||||
ensure(
|
|
||||||
idx != null_identifier,
|
|
||||||
"Failed to ensure: idx != null_identifier [{} != {}]",
|
|
||||||
idx,
|
|
||||||
null_identifier
|
|
||||||
);
|
|
||||||
ensure(
|
|
||||||
idx < m_dense.size(),
|
|
||||||
"Failed to ensure: idx < m_dense.size() [{} < {}]",
|
|
||||||
idx,
|
|
||||||
m_dense.size()
|
|
||||||
);
|
|
||||||
|
|
||||||
auto &[entity, component] = m_dense[idx];
|
|
||||||
|
|
||||||
auto &[last_entity, last_component] = m_dense.back();
|
|
||||||
auto &last_idx = m_sparse[last_entity];
|
|
||||||
|
|
||||||
// removed entity is in dense's back, just pop and invalidate sparse[identifier]
|
|
||||||
if (entity == last_entity)
|
|
||||||
{
|
|
||||||
idx = null_identifier;
|
|
||||||
m_dense.pop_back();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// swap dense's 'back' to 'removed'
|
|
||||||
std::swap(component, last_component);
|
|
||||||
entity = last_entity;
|
|
||||||
|
|
||||||
// make sparse point to new idx
|
|
||||||
last_idx = idx;
|
|
||||||
|
|
||||||
// pop dense and invalidate sparse[identifier]
|
|
||||||
idx = null_identifier;
|
|
||||||
m_dense.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
++m_dead_count;
|
|
||||||
--m_alive_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear()
|
|
||||||
{
|
|
||||||
m_dense.clear();
|
|
||||||
m_sparse.clear();
|
|
||||||
m_alive_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto contains(Identifier_T identifier) const -> bool
|
|
||||||
{
|
|
||||||
return m_sparse.size() > identifier //
|
|
||||||
&& m_sparse[identifier] != null_identifier //
|
|
||||||
&& m_dense[m_sparse[identifier]].first == identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto begin() -> std::vector<Dense_T>::iterator
|
|
||||||
{
|
|
||||||
return m_dense.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto end() -> std::vector<Dense_T>::iterator
|
|
||||||
{
|
|
||||||
return m_dense.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto at(Identifier_T identifier) const -> const Dense_T &
|
|
||||||
{
|
|
||||||
return m_dense.at(m_sparse.at(identifier));
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto at(Identifier_T identifier) -> Dense_T &
|
|
||||||
{
|
|
||||||
return m_dense.at(m_sparse.at(identifier));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @warn unsafe, for bound-checked access: use `.at` */
|
|
||||||
[[nodiscard]] auto &&operator[](this auto &&self, Identifier_T identifier)
|
|
||||||
{
|
|
||||||
using Self_T = decltype(self);
|
|
||||||
return std::forward<Self_T>(self).m_dense[std::forward<Self_T>(self).m_sparse[identifier]];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_size() const noexcept -> size_t
|
|
||||||
{
|
|
||||||
return m_alive_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_capacity() const noexcept -> size_t
|
|
||||||
{
|
|
||||||
return m_sparse.capacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto is_empty() const noexcept -> bool
|
|
||||||
{
|
|
||||||
return m_dense.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<Dense_T> m_dense;
|
|
||||||
|
|
||||||
std::vector<Identifier_T> m_sparse;
|
|
||||||
|
|
||||||
size_t m_alive_count {};
|
|
||||||
|
|
||||||
size_t m_dead_count {};
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::ecs
|
|
||||||
|
|
@ -1,188 +0,0 @@
|
||||||
import test;
|
|
||||||
import ecs.sparse_set;
|
|
||||||
|
|
||||||
using Value_T = i32;
|
|
||||||
using Set = lt::ecs::SparseSet<Value_T>;
|
|
||||||
|
|
||||||
constexpr auto capacity = 100;
|
|
||||||
|
|
||||||
Suite raii = "raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
ignore = Set {};
|
|
||||||
ignore = Set { Set::max_capacity };
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
expect_throw([] { ignore = Set { Set::max_capacity + 1 }; });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
for (auto idx : std::views::iota(0, 1'000))
|
|
||||||
{
|
|
||||||
ignore = Set { static_cast<size_t>(idx) };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct has correct state" } = [&] {
|
|
||||||
auto set = Set { capacity };
|
|
||||||
expect_eq(set.get_size(), 0);
|
|
||||||
expect_eq(set.get_capacity(), capacity);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite element_raii = "element_raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
auto set = Set { capacity };
|
|
||||||
set.insert(0, {});
|
|
||||||
set.remove(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
expect_throw([] {
|
|
||||||
auto set = Set { capacity };
|
|
||||||
set.insert(Set::max_capacity + 1, {});
|
|
||||||
});
|
|
||||||
|
|
||||||
expect_throw([] {
|
|
||||||
auto set = Set { capacity };
|
|
||||||
set.insert(0, {});
|
|
||||||
set.insert(1, {});
|
|
||||||
set.insert(2, {});
|
|
||||||
|
|
||||||
set.remove(3);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
auto set = Set {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
set.insert(idx, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
set.remove(idx);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "insert returns reference to inserted value" } = [] {
|
|
||||||
auto set = Set {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
const auto val = Set::Dense_T { idx, {} };
|
|
||||||
expect_eq(set.insert(val.first, val.second), val);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post insert/remove has correct state" } = [] {
|
|
||||||
auto set = Set {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
set.insert(idx, idx * 2);
|
|
||||||
expect_eq(set.get_size(), idx + 1);
|
|
||||||
expect_eq(set.at(idx), Set::Dense_T { idx, idx * 2 });
|
|
||||||
expect_true(set.contains(idx));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
expect_eq(set.at(idx), Set::Dense_T { idx, idx * 2 });
|
|
||||||
expect_true(set.contains(idx));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
set.remove(idx);
|
|
||||||
|
|
||||||
expect_eq(set.get_size(), 10'000 - (idx + 1));
|
|
||||||
expect_false(set.contains(idx));
|
|
||||||
expect_throw([&] { ignore = set.at(idx); });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "removed elements won't be iterated again" } = [] {
|
|
||||||
auto set = Set {};
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
set.insert(idx, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
set.remove(0);
|
|
||||||
set.remove(32);
|
|
||||||
set.remove(69);
|
|
||||||
set.remove(420);
|
|
||||||
set.remove(9'999);
|
|
||||||
|
|
||||||
for (auto &[identifier, value] : set)
|
|
||||||
{
|
|
||||||
expect_eq(static_cast<Value_T>(identifier), value);
|
|
||||||
expect_ne(value, 0);
|
|
||||||
expect_ne(value, 32);
|
|
||||||
expect_ne(value, 69);
|
|
||||||
expect_ne(value, 420);
|
|
||||||
expect_ne(value, 9'999);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite getters = "getters"_suite = [] {
|
|
||||||
Case { "get_size returns correct values" } = [] {
|
|
||||||
auto set = Set {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
expect_eq(set.get_size(), idx);
|
|
||||||
set.insert(idx, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
expect_eq(set.get_size(), 10'000);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "get_capacity returns correct values" } = [] {
|
|
||||||
auto set = Set { 10'000 };
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
expect_eq(set.get_capacity(), 10'000); // are we testing std::vector's implementation?
|
|
||||||
set.insert(idx, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
expect_eq(set.get_capacity(), 10'000);
|
|
||||||
|
|
||||||
set.insert(static_cast<Value_T>(set.get_size()), {});
|
|
||||||
expect_ne(set.get_capacity(), 10'000);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "at throws with out of bound access" } = [] {
|
|
||||||
auto set = Set {};
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 50))
|
|
||||||
{
|
|
||||||
expect_throw([&] {
|
|
||||||
set.insert(idx, {});
|
|
||||||
ignore = set.at(50);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
set.insert(50, {});
|
|
||||||
ignore = set.at(50); // should not throw
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite clear = "clear"_suite = [] {
|
|
||||||
Case { "post clear has correct state" } = [] {
|
|
||||||
auto set = Set { 0 };
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
set.insert(idx, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
set.clear();
|
|
||||||
expect_eq(set.get_size(), 0);
|
|
||||||
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
expect_throw([&] { ignore = set.at(idx); });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
2
modules/engine/CMakeLists.txt
Normal file
2
modules/engine/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
add_executable(engine ${CMAKE_CURRENT_SOURCE_DIR}/private/entrypoint.cpp)
|
||||||
|
target_link_libraries(engine PRIVATE pch)
|
||||||
17
modules/engine/private/entrypoint.cpp
Normal file
17
modules/engine/private/entrypoint.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
auto main() -> int32_t
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::cout << "Light built and ran fine...";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (const std::exception &exp)
|
||||||
|
{
|
||||||
|
std::cout << "\n\nUnhandled std exception: " << exp.what() << std::endl; // NOLINT
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cout << "\n\nUnhandled exception" << std::endl; // NOLINT
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
export module input.system:components;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import input.codes;
|
|
||||||
|
|
||||||
export namespace lt::input {
|
|
||||||
|
|
||||||
struct Trigger
|
|
||||||
{
|
|
||||||
Key mapped_keycode;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct InputAction
|
|
||||||
{
|
|
||||||
enum class State : u8
|
|
||||||
{
|
|
||||||
inactive,
|
|
||||||
active,
|
|
||||||
triggered,
|
|
||||||
cancelled,
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
|
|
||||||
State state;
|
|
||||||
|
|
||||||
Trigger trigger;
|
|
||||||
};
|
|
||||||
|
|
||||||
class InputComponent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
InputComponent() = default;
|
|
||||||
|
|
||||||
auto add_action(InputAction action) -> size_t
|
|
||||||
{
|
|
||||||
m_actions.emplace_back(std::move(action));
|
|
||||||
return m_actions.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto get_action(size_t idx) -> const InputAction &
|
|
||||||
{
|
|
||||||
return m_actions[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class System;
|
|
||||||
|
|
||||||
void push_event()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<InputAction> m_actions;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::input
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
export module input.events;
|
|
||||||
|
|
||||||
import input.codes;
|
|
||||||
import math.vec2;
|
|
||||||
|
|
||||||
import std;
|
|
||||||
|
|
||||||
namespace lt::input {
|
|
||||||
|
|
||||||
export class AnalogEvent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AnalogEvent(Key key, math::vec2_u32 pointer_position)
|
|
||||||
: m_key(key)
|
|
||||||
, m_pointer_position(pointer_position)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_key() const -> Key
|
|
||||||
{
|
|
||||||
return m_key;
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_pointer_position() const -> math::vec2_u32
|
|
||||||
{
|
|
||||||
return m_pointer_position;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto to_string() const -> std::string
|
|
||||||
{
|
|
||||||
const auto &[x, y] = m_pointer_position;
|
|
||||||
return std::format("input::AnalogEvent: {} @ {}, {}", std::to_underlying(m_key), x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Key m_key;
|
|
||||||
|
|
||||||
math::vec2_u32 m_pointer_position;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::input
|
|
||||||
|
|
@ -1,201 +0,0 @@
|
||||||
export module input.system;
|
|
||||||
export import :components;
|
|
||||||
import logger;
|
|
||||||
import app.system;
|
|
||||||
import ecs.registry;
|
|
||||||
import memory.reference;
|
|
||||||
import surface.system;
|
|
||||||
import surface.events;
|
|
||||||
import math.vec2;
|
|
||||||
import std;
|
|
||||||
|
|
||||||
namespace lt::input {
|
|
||||||
|
|
||||||
export class System: public app::ISystem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
System(memory::Ref<ecs::Registry> registry);
|
|
||||||
|
|
||||||
void tick(app::TickInfo tick) override;
|
|
||||||
|
|
||||||
void on_register() override;
|
|
||||||
|
|
||||||
void on_unregister() override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_last_tick_result() const -> const app::TickResult & override
|
|
||||||
{
|
|
||||||
return m_last_tick_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void handle_event(const surface::SurfaceComponent::Event &event);
|
|
||||||
|
|
||||||
void on_surface_lost_focus();
|
|
||||||
|
|
||||||
void on_key_press(const lt::surface::KeyPressedEvent &event);
|
|
||||||
|
|
||||||
void on_key_release(const lt::surface::KeyReleasedEvent &event);
|
|
||||||
|
|
||||||
void on_pointer_move(const lt::surface::MouseMovedEvent &event);
|
|
||||||
|
|
||||||
void on_button_press(const lt::surface::ButtonPressedEvent &event);
|
|
||||||
|
|
||||||
void on_button_release(const lt::surface::ButtonReleasedEvent &event);
|
|
||||||
|
|
||||||
memory::Ref<ecs::Registry> m_registry;
|
|
||||||
|
|
||||||
std::array<bool, 512> m_keys {};
|
|
||||||
|
|
||||||
std::array<bool, 512> m_buttons {};
|
|
||||||
|
|
||||||
math::vec2 m_pointer_position;
|
|
||||||
|
|
||||||
app::TickResult m_last_tick_result {};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace lt::input
|
|
||||||
|
|
||||||
|
|
||||||
module :private;
|
|
||||||
namespace lt::input {
|
|
||||||
|
|
||||||
template<class... Ts>
|
|
||||||
struct overloads: Ts...
|
|
||||||
{
|
|
||||||
using Ts::operator()...;
|
|
||||||
};
|
|
||||||
|
|
||||||
System::System(memory::Ref<ecs::Registry> registry): m_registry(std::move(registry))
|
|
||||||
{
|
|
||||||
ensure(m_registry, "Failed to initialize input system: null registry");
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::tick(app::TickInfo tick)
|
|
||||||
{
|
|
||||||
for (auto &[entity, surface] : m_registry->view<surface::SurfaceComponent>())
|
|
||||||
{
|
|
||||||
for (const auto &event : surface.peek_events())
|
|
||||||
{
|
|
||||||
handle_event(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &[entity, input] : m_registry->view<InputComponent>())
|
|
||||||
{
|
|
||||||
// TODO(Light): instead of iterating over all actions each frame,
|
|
||||||
// make a list of "dirty" actions to reset
|
|
||||||
// and a surface_input->input_action mapping to get to action through input
|
|
||||||
// instead of brute-force checking all of them.
|
|
||||||
for (auto &action : input.m_actions)
|
|
||||||
{
|
|
||||||
auto code = std::to_underlying(action.trigger.mapped_keycode);
|
|
||||||
if (code < m_keys.size() && m_keys[code])
|
|
||||||
{
|
|
||||||
if (action.state == InputAction::State::triggered)
|
|
||||||
{
|
|
||||||
action.state = InputAction::State::active;
|
|
||||||
}
|
|
||||||
else if (action.state == InputAction::State::inactive)
|
|
||||||
{
|
|
||||||
action.state = InputAction::State::triggered;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
action.state = InputAction::State::inactive;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto now = std::chrono::steady_clock::now();
|
|
||||||
m_last_tick_result = app::TickResult {
|
|
||||||
.info = tick,
|
|
||||||
.duration = now - tick.start_time,
|
|
||||||
.end_time = now,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_register()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_unregister()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::handle_event(const surface::SurfaceComponent::Event &event)
|
|
||||||
{
|
|
||||||
const auto visitor = overloads {
|
|
||||||
[this](const surface::ClosedEvent &) { on_surface_lost_focus(); },
|
|
||||||
[this](const surface::LostFocusEvent &) { on_surface_lost_focus(); },
|
|
||||||
[this](const surface::KeyPressedEvent &event) { on_key_press(event); },
|
|
||||||
[this](const surface::KeyReleasedEvent &event) { on_key_release(event); },
|
|
||||||
[this](const surface::MouseMovedEvent &event) { on_pointer_move(event); },
|
|
||||||
[this](const surface::ButtonPressedEvent &event) { on_button_press(event); },
|
|
||||||
[this](const surface::ButtonReleasedEvent &event) { on_button_release(event); },
|
|
||||||
[this](auto) {},
|
|
||||||
};
|
|
||||||
|
|
||||||
std::visit(visitor, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_surface_lost_focus()
|
|
||||||
{
|
|
||||||
for (auto &key : m_keys)
|
|
||||||
{
|
|
||||||
key = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &button : m_buttons)
|
|
||||||
{
|
|
||||||
button = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_key_press(const lt::surface::KeyPressedEvent &event)
|
|
||||||
{
|
|
||||||
if (std::to_underlying(event.get_key()) > m_keys.size())
|
|
||||||
{
|
|
||||||
log::warn(
|
|
||||||
"Key code larger than key container size, implement platform-dependant "
|
|
||||||
"key-code-mapping!"
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_keys[std::to_underlying(event.get_key())] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_key_release(const lt::surface::KeyReleasedEvent &event)
|
|
||||||
{
|
|
||||||
if (std::to_underlying(event.get_key()) > m_keys.size())
|
|
||||||
{
|
|
||||||
log::warn(
|
|
||||||
"Key code larger than key container size, implement platform-dependant "
|
|
||||||
"key-code-mapping!"
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_keys[std::to_underlying(event.get_key())] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_pointer_move(const lt::surface::MouseMovedEvent &event)
|
|
||||||
{
|
|
||||||
m_pointer_position = event.get_position();
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_button_press(const lt::surface::ButtonPressedEvent &event)
|
|
||||||
{
|
|
||||||
m_buttons[std::to_underlying(event.get_button())] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void System::on_button_release(const lt::surface::ButtonReleasedEvent &event)
|
|
||||||
{
|
|
||||||
m_buttons[std::to_underlying(event.get_button())] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::input
|
|
||||||
|
|
@ -1,175 +0,0 @@
|
||||||
import test;
|
|
||||||
import input.system;
|
|
||||||
import input.codes;
|
|
||||||
import surface.events;
|
|
||||||
import memory.scope;
|
|
||||||
import memory.reference;
|
|
||||||
import app.system;
|
|
||||||
import ecs.entity;
|
|
||||||
import ecs.registry;
|
|
||||||
import surface.system;
|
|
||||||
|
|
||||||
using ::lt::input::InputComponent;
|
|
||||||
using ::lt::input::System;
|
|
||||||
|
|
||||||
[[nodiscard]] auto tick_info() -> lt::app::TickInfo
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
.delta_time = std::chrono::milliseconds { 16 },
|
|
||||||
.budget = std::chrono::milliseconds { 10 },
|
|
||||||
.start_time = std::chrono::steady_clock::now(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class Fixture
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
[[nodiscard]] auto registry() -> lt::memory::Ref<lt::ecs::Registry>
|
|
||||||
{
|
|
||||||
return m_registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto add_input_component() -> lt::ecs::EntityId
|
|
||||||
{
|
|
||||||
auto entity = m_registry->create_entity();
|
|
||||||
m_registry->add<InputComponent>(entity, {});
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto add_surface_component() -> lt::ecs::EntityId
|
|
||||||
{
|
|
||||||
auto entity = m_registry->create_entity();
|
|
||||||
m_surface_system.create_surface_component(
|
|
||||||
entity,
|
|
||||||
{ .title = "", .resolution = { 20u, 20u } }
|
|
||||||
);
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
lt::memory::Ref<lt::ecs::Registry> m_registry = lt::memory::create_ref<lt::ecs::Registry>();
|
|
||||||
|
|
||||||
lt::surface::System m_surface_system = lt::surface::System { m_registry };
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite raii = "raii"_suite = "raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [&] {
|
|
||||||
System { Fixture {}.registry() };
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
expect_throw([] { ignore = System { {} }; });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [&] {
|
|
||||||
auto fixture = Fixture {};
|
|
||||||
for (auto idx : std::views::iota(0, 10'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
ignore = System { fixture.registry() };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite system_events = "system_events"_suite = [] {
|
|
||||||
Case { "on_register won't throw" } = [] {
|
|
||||||
auto fixture = Fixture {};
|
|
||||||
auto registry = fixture.registry();
|
|
||||||
auto system = System { registry };
|
|
||||||
|
|
||||||
system.on_register();
|
|
||||||
expect_eq(registry->view<InputComponent>().get_size(), 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "on_unregister won't throw" } = [] {
|
|
||||||
auto fixture = Fixture {};
|
|
||||||
auto registry = fixture.registry();
|
|
||||||
auto system = System { registry };
|
|
||||||
|
|
||||||
system.on_register();
|
|
||||||
system.on_unregister();
|
|
||||||
expect_eq(registry->view<InputComponent>().get_size(), 0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite registry_events = "registry_events"_suite = [] {
|
|
||||||
Case { "on_construct<InputComnent>" } = [] {
|
|
||||||
auto fixture = Fixture {};
|
|
||||||
auto registry = fixture.registry();
|
|
||||||
auto system = System { registry };
|
|
||||||
|
|
||||||
fixture.add_input_component();
|
|
||||||
expect_eq(registry->view<InputComponent>().get_size(), 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "on_destrroy<InputComponent>" } = [] {
|
|
||||||
auto fixture = Fixture {};
|
|
||||||
auto registry = fixture.registry();
|
|
||||||
auto system = lt::memory::create_scope<System>(registry);
|
|
||||||
|
|
||||||
auto entity_a = fixture.add_input_component();
|
|
||||||
auto entity_b = fixture.add_input_component();
|
|
||||||
expect_eq(registry->view<InputComponent>().get_size(), 2);
|
|
||||||
|
|
||||||
registry->remove<InputComponent>(entity_a);
|
|
||||||
expect_eq(registry->view<InputComponent>().get_size(), 1);
|
|
||||||
|
|
||||||
system.reset();
|
|
||||||
expect_eq(registry->view<InputComponent>().get_size(), 1);
|
|
||||||
|
|
||||||
registry->remove<InputComponent>(entity_b);
|
|
||||||
expect_eq(registry->view<InputComponent>().get_size(), 0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite tick = "tick"_suite = [] {
|
|
||||||
Case { "Empty tick won't throw" } = [] {
|
|
||||||
auto fixture = Fixture {};
|
|
||||||
auto registry = fixture.registry();
|
|
||||||
auto system = System { fixture.registry() };
|
|
||||||
|
|
||||||
system.tick(tick_info());
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "Tick triggers input action" } = [] {
|
|
||||||
auto fixture = Fixture {};
|
|
||||||
auto registry = fixture.registry();
|
|
||||||
auto system = System { fixture.registry() };
|
|
||||||
|
|
||||||
auto surface_entity = fixture.add_surface_component();
|
|
||||||
auto &surface = registry->get<lt::surface::SurfaceComponent>(surface_entity);
|
|
||||||
|
|
||||||
auto input_entity = fixture.add_input_component();
|
|
||||||
auto &input = registry->get<InputComponent>(input_entity);
|
|
||||||
|
|
||||||
auto action_key = input.add_action(
|
|
||||||
{
|
|
||||||
.name { "test" },
|
|
||||||
.trigger = { .mapped_keycode = Key::a },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
using enum ::lt::input::InputAction::State;
|
|
||||||
expect_eq(input.get_action(action_key).state, inactive);
|
|
||||||
system.tick(tick_info());
|
|
||||||
expect_eq(input.get_action(action_key).state, inactive);
|
|
||||||
|
|
||||||
surface.push_event(lt::surface::KeyPressedEvent(Key::a));
|
|
||||||
system.tick(tick_info());
|
|
||||||
expect_eq(input.get_action(action_key).state, triggered);
|
|
||||||
|
|
||||||
system.tick(tick_info());
|
|
||||||
expect_eq(input.get_action(action_key).state, active);
|
|
||||||
|
|
||||||
system.tick(tick_info());
|
|
||||||
system.tick(tick_info());
|
|
||||||
system.tick(tick_info());
|
|
||||||
expect_eq(input.get_action(action_key).state, active);
|
|
||||||
|
|
||||||
surface.push_event(lt::surface::KeyReleasedEvent(Key::a));
|
|
||||||
system.tick(tick_info());
|
|
||||||
expect_eq(input.get_action(action_key).state, inactive);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,292 +0,0 @@
|
||||||
/**
|
|
||||||
* @note: The reason this is a separate module, rather than being in the `Input` module is that
|
|
||||||
* the input is received from the hardware through the `Surface` module, and it is further parsed
|
|
||||||
* inside the `Input` module, USING the `Surface` module's events.
|
|
||||||
*
|
|
||||||
* Hence, both `Surface` and `Input` needs to agree to the same input codes, while `Input` depends
|
|
||||||
* on `Surface`. The simplest solution is to keep the codes in a 3rd module and make both depend on
|
|
||||||
* it. (I did not want to give `Surface` the responsibility of defining input codes...)
|
|
||||||
*/
|
|
||||||
export module input.codes;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
export enum class Key: u16 {
|
|
||||||
none = 0,
|
|
||||||
|
|
||||||
left_button,
|
|
||||||
l_button = left_button,
|
|
||||||
|
|
||||||
right_button,
|
|
||||||
r_button = right_button,
|
|
||||||
|
|
||||||
middle_button,
|
|
||||||
m_button = middle_button,
|
|
||||||
|
|
||||||
// the buttons on the sidse of some mouses
|
|
||||||
x_button_1,
|
|
||||||
x_button_2,
|
|
||||||
|
|
||||||
backspace,
|
|
||||||
tab,
|
|
||||||
capslock,
|
|
||||||
enter,
|
|
||||||
space,
|
|
||||||
delete_,
|
|
||||||
|
|
||||||
shift,
|
|
||||||
left_shit = shift,
|
|
||||||
l_shift = shift,
|
|
||||||
|
|
||||||
right_shift,
|
|
||||||
r_shift = right_shift,
|
|
||||||
|
|
||||||
control,
|
|
||||||
left_control = control,
|
|
||||||
l_control = control,
|
|
||||||
ctrl = control,
|
|
||||||
left_ctrl = control,
|
|
||||||
l_ctrl = control,
|
|
||||||
|
|
||||||
right_control,
|
|
||||||
r_control = right_control,
|
|
||||||
right_ctrl = right_control,
|
|
||||||
r_ctrl = right_control,
|
|
||||||
|
|
||||||
alt,
|
|
||||||
left_alt = alt,
|
|
||||||
l_alt = alt,
|
|
||||||
|
|
||||||
right_alt,
|
|
||||||
r_alt = right_alt,
|
|
||||||
|
|
||||||
pageup,
|
|
||||||
pagedown,
|
|
||||||
home,
|
|
||||||
end,
|
|
||||||
|
|
||||||
left_arrow,
|
|
||||||
l_arrow = left_arrow,
|
|
||||||
|
|
||||||
up_arrow,
|
|
||||||
u_arrow = up_arrow,
|
|
||||||
|
|
||||||
right_arrow,
|
|
||||||
r_arrow = right_arrow,
|
|
||||||
|
|
||||||
down_arrow,
|
|
||||||
d_arrow = down_arrow,
|
|
||||||
|
|
||||||
cancel,
|
|
||||||
pause,
|
|
||||||
select,
|
|
||||||
print,
|
|
||||||
snapshot, // aka. print-screen
|
|
||||||
insert,
|
|
||||||
help,
|
|
||||||
sleep,
|
|
||||||
eep = sleep,
|
|
||||||
|
|
||||||
digit_0,
|
|
||||||
digit_1,
|
|
||||||
digit_2,
|
|
||||||
digit_3,
|
|
||||||
digit_4,
|
|
||||||
digit_5,
|
|
||||||
digit_6,
|
|
||||||
digit_7,
|
|
||||||
digit_8,
|
|
||||||
digit_9,
|
|
||||||
|
|
||||||
a,
|
|
||||||
b,
|
|
||||||
c,
|
|
||||||
d,
|
|
||||||
e,
|
|
||||||
f,
|
|
||||||
g,
|
|
||||||
h,
|
|
||||||
i,
|
|
||||||
j,
|
|
||||||
k,
|
|
||||||
l,
|
|
||||||
m,
|
|
||||||
n,
|
|
||||||
o,
|
|
||||||
p,
|
|
||||||
q,
|
|
||||||
r,
|
|
||||||
s,
|
|
||||||
t,
|
|
||||||
u,
|
|
||||||
v,
|
|
||||||
w,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
z,
|
|
||||||
|
|
||||||
super,
|
|
||||||
left_super = super,
|
|
||||||
l_super = super,
|
|
||||||
|
|
||||||
right_super,
|
|
||||||
r_super = right_super,
|
|
||||||
|
|
||||||
kp_0,
|
|
||||||
kp_1,
|
|
||||||
kp_2,
|
|
||||||
kp_3,
|
|
||||||
kp_4,
|
|
||||||
kp_5,
|
|
||||||
kp_6,
|
|
||||||
kp_7,
|
|
||||||
kp_8,
|
|
||||||
kp_9,
|
|
||||||
kp_decimal,
|
|
||||||
kp_divide,
|
|
||||||
kp_multiply,
|
|
||||||
kp_subtract,
|
|
||||||
kp_add,
|
|
||||||
kp_enter,
|
|
||||||
kp_equal,
|
|
||||||
|
|
||||||
f1,
|
|
||||||
f2,
|
|
||||||
f3,
|
|
||||||
f4,
|
|
||||||
f5,
|
|
||||||
f6,
|
|
||||||
f7,
|
|
||||||
f8,
|
|
||||||
f9,
|
|
||||||
f10,
|
|
||||||
f11,
|
|
||||||
f12,
|
|
||||||
|
|
||||||
/** Input was received but was none of the above. */
|
|
||||||
unknown,
|
|
||||||
};
|
|
||||||
|
|
||||||
export [[nodiscard]] constexpr auto to_string(Key key) -> std::string
|
|
||||||
{
|
|
||||||
using enum Key;
|
|
||||||
switch (key)
|
|
||||||
{
|
|
||||||
case none: return "<none>";
|
|
||||||
|
|
||||||
case left_button: return "left_button";
|
|
||||||
case right_button: return "right_button";
|
|
||||||
case middle_button: return "middle_button";
|
|
||||||
|
|
||||||
case x_button_1: return "x_button_1";
|
|
||||||
case x_button_2: return "x_button_2";
|
|
||||||
|
|
||||||
case backspace: return "backspace";
|
|
||||||
case tab: return "tab";
|
|
||||||
case capslock: return "capslock";
|
|
||||||
case enter: return "enter";
|
|
||||||
case space: return "space";
|
|
||||||
case delete_: return "delete";
|
|
||||||
|
|
||||||
case shift: return "shift";
|
|
||||||
case control: return "control";
|
|
||||||
case right_control: return "right_control";
|
|
||||||
case alt: return "alt";
|
|
||||||
case right_alt: return "right_alt";
|
|
||||||
|
|
||||||
case pageup: return "pageup";
|
|
||||||
case pagedown: return "pagedown";
|
|
||||||
case home: return "home";
|
|
||||||
case end: return "end";
|
|
||||||
|
|
||||||
case left_arrow: return "left_arrow";
|
|
||||||
case up_arrow: return "up_arrow";
|
|
||||||
case right_arrow: return "right_arrow";
|
|
||||||
case down_arrow: return "down_arrow";
|
|
||||||
|
|
||||||
case cancel: return "cancel";
|
|
||||||
case pause: return "pause";
|
|
||||||
case select: return "select";
|
|
||||||
case print: return "print";
|
|
||||||
case snapshot: return "snapshot";
|
|
||||||
case insert: return "insert";
|
|
||||||
case help: return "help";
|
|
||||||
case sleep: return "sleep";
|
|
||||||
|
|
||||||
case digit_0: return "0";
|
|
||||||
case digit_1: return "1";
|
|
||||||
case digit_2: return "2";
|
|
||||||
case digit_3: return "3";
|
|
||||||
case digit_4: return "4";
|
|
||||||
case digit_5: return "5";
|
|
||||||
case digit_6: return "6";
|
|
||||||
case digit_7: return "7";
|
|
||||||
case digit_8: return "8";
|
|
||||||
case digit_9: return "9";
|
|
||||||
|
|
||||||
case a: return "a";
|
|
||||||
case b: return "b";
|
|
||||||
case c: return "c";
|
|
||||||
case d: return "d";
|
|
||||||
case e: return "e";
|
|
||||||
case f: return "f";
|
|
||||||
case g: return "g";
|
|
||||||
case h: return "h";
|
|
||||||
case i: return "i";
|
|
||||||
case j: return "j";
|
|
||||||
case k: return "k";
|
|
||||||
case l: return "l";
|
|
||||||
case m: return "m";
|
|
||||||
case n: return "n";
|
|
||||||
case o: return "o";
|
|
||||||
case p: return "p";
|
|
||||||
case q: return "q";
|
|
||||||
case r: return "r";
|
|
||||||
case s: return "s";
|
|
||||||
case t: return "t";
|
|
||||||
case u: return "u";
|
|
||||||
case v: return "v";
|
|
||||||
case w: return "w";
|
|
||||||
case x: return "x";
|
|
||||||
case y: return "y";
|
|
||||||
case z: return "z";
|
|
||||||
|
|
||||||
case super: return "super";
|
|
||||||
case right_super: return "right_super";
|
|
||||||
|
|
||||||
case kp_0: return "kp_0";
|
|
||||||
case kp_1: return "kp_1";
|
|
||||||
case kp_2: return "kp_2";
|
|
||||||
case kp_3: return "kp_3";
|
|
||||||
case kp_4: return "kp_4";
|
|
||||||
case kp_5: return "kp_5";
|
|
||||||
case kp_6: return "kp_6";
|
|
||||||
case kp_7: return "kp_7";
|
|
||||||
case kp_8: return "kp_8";
|
|
||||||
case kp_9: return "kp_9";
|
|
||||||
case kp_decimal: return "kp_decimal";
|
|
||||||
case kp_divide: return "kp_divide";
|
|
||||||
case kp_multiply: return "kp_multiply";
|
|
||||||
case kp_subtract: return "kp_subtract";
|
|
||||||
case kp_add: return "kp_add";
|
|
||||||
case kp_enter: return "kp_enter";
|
|
||||||
case kp_equal: return "kp_equal";
|
|
||||||
|
|
||||||
case f1: return "f1";
|
|
||||||
case f2: return "f2";
|
|
||||||
case f3: return "f3";
|
|
||||||
case f4: return "f4";
|
|
||||||
case f5: return "f5";
|
|
||||||
case f6: return "f6";
|
|
||||||
case f7: return "f7";
|
|
||||||
case f8: return "f8";
|
|
||||||
case f9: return "f9";
|
|
||||||
case f10: return "f10";
|
|
||||||
case f11: return "f11";
|
|
||||||
case f12: return "f12";
|
|
||||||
|
|
||||||
case unknown: return "<unknown>";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "<invalid>";
|
|
||||||
}
|
|
||||||
|
|
@ -1,230 +0,0 @@
|
||||||
export module logger;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
export namespace lt::log {
|
|
||||||
|
|
||||||
/** Severity of a log message. */
|
|
||||||
enum class Level : u8
|
|
||||||
{
|
|
||||||
/** Lowest and most vebose log level, for tracing execution paths and events */
|
|
||||||
trace = 0,
|
|
||||||
|
|
||||||
/** Vebose log level, for enabling temporarily to debug */
|
|
||||||
debug = 1,
|
|
||||||
|
|
||||||
/** General information */
|
|
||||||
info = 2,
|
|
||||||
|
|
||||||
/** Things we should to be aware of and edge cases */
|
|
||||||
warn = 3,
|
|
||||||
|
|
||||||
/** Defects, bugs and undesired behaviour */
|
|
||||||
error = 4,
|
|
||||||
|
|
||||||
/** Unrecoverable errors */
|
|
||||||
critical = 5,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs from the testing-framework.
|
|
||||||
* Highest so we still get them while turning off all logs from the code under test.
|
|
||||||
*
|
|
||||||
* @note: log::test does NOT include source_location
|
|
||||||
*/
|
|
||||||
test = 6,
|
|
||||||
|
|
||||||
/** No logging */
|
|
||||||
off = 7,
|
|
||||||
};
|
|
||||||
|
|
||||||
auto min_severity = Level::trace;
|
|
||||||
|
|
||||||
auto set_min_severity(Level severity)
|
|
||||||
{
|
|
||||||
min_severity = severity;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct [[maybe_unused]] print
|
|
||||||
{
|
|
||||||
[[maybe_unused]] print(
|
|
||||||
Level level,
|
|
||||||
const std::source_location &location,
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
if (std::to_underlying(level) < std::to_underlying(min_severity))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr auto to_string = [](Level level) {
|
|
||||||
// clang-format off
|
|
||||||
switch (level)
|
|
||||||
{
|
|
||||||
using enum ::lt::log::Level;
|
|
||||||
case trace : return "\033[1;37m| trc |\033[0m";
|
|
||||||
case debug : return "\033[1;36m| dbg |\033[0m";
|
|
||||||
case info : return "\033[1;32m| inf |\033[0m";
|
|
||||||
case warn : return "\033[1;33m| wrn |\033[0m";
|
|
||||||
case error : return "\033[1;31m| err |\033[0m";
|
|
||||||
case critical: return "\033[1;41m| crt |\033[0m";
|
|
||||||
case off: return "off";
|
|
||||||
}
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
std::unreachable();
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto path = std::filesystem::path { location.file_name() };
|
|
||||||
|
|
||||||
std::println(
|
|
||||||
"{} {} ==> {}",
|
|
||||||
to_string(level),
|
|
||||||
std::format("{}:{}", path.filename().string(), location.line()),
|
|
||||||
std::format(format, std::forward<Args>(arguments)...)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[maybe_unused]] print(
|
|
||||||
Level level,
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
constexpr auto to_string = [](Level level) {
|
|
||||||
// clang-format off
|
|
||||||
switch (level)
|
|
||||||
{
|
|
||||||
using enum ::lt::log::Level;
|
|
||||||
case trace : return "\033[1;37m| trc |\033[0m";
|
|
||||||
case debug : return "\033[1;36m| dbg |\033[0m";
|
|
||||||
case info : return "\033[1;32m| inf |\033[0m";
|
|
||||||
case warn : return "\033[1;33m| wrn |\033[0m";
|
|
||||||
case error : return "\033[1;31m| err |\033[0m";
|
|
||||||
case critical: return "\033[1;41m| crt |\033[0m";
|
|
||||||
case test : return "\033[1;33m| test |\033[0m";
|
|
||||||
case off : return "";
|
|
||||||
}
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
std::unreachable();
|
|
||||||
};
|
|
||||||
|
|
||||||
std::println(
|
|
||||||
"{} {}",
|
|
||||||
to_string(level),
|
|
||||||
std::format(format, std::forward<Args>(arguments)...)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
print(Level, const std::source_location &, std::format_string<Args...>, Args &&...) noexcept
|
|
||||||
-> print<Args...>;
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct [[maybe_unused]] trace
|
|
||||||
{
|
|
||||||
[[maybe_unused]] trace(
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments,
|
|
||||||
const std::source_location &location = std::source_location::current()
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
print(Level::trace, location, format, std::forward<Args>(arguments)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
trace(std::format_string<Args...>, Args &&...) noexcept -> trace<Args...>;
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct [[maybe_unused]] debug
|
|
||||||
{
|
|
||||||
[[maybe_unused]] debug(
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments,
|
|
||||||
const std::source_location &location = std::source_location::current()
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
print(Level::debug, location, format, std::forward<Args>(arguments)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
debug(std::format_string<Args...>, Args &&...) noexcept -> debug<Args...>;
|
|
||||||
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct [[maybe_unused]] info
|
|
||||||
{
|
|
||||||
[[maybe_unused]] info(
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments,
|
|
||||||
const std::source_location &location = std::source_location::current()
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
print(Level::info, location, format, std::forward<Args>(arguments)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
info(std::format_string<Args...>, Args &&...) noexcept -> info<Args...>;
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct [[maybe_unused]] warn
|
|
||||||
{
|
|
||||||
[[maybe_unused]] warn(
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments,
|
|
||||||
const std::source_location &location = std::source_location::current()
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
print(Level::warn, location, format, std::forward<Args>(arguments)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
warn(std::format_string<Args...>, Args &&...) noexcept -> warn<Args...>;
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct [[maybe_unused]] error
|
|
||||||
{
|
|
||||||
[[maybe_unused]] error(
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments,
|
|
||||||
const std::source_location &location = std::source_location::current()
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
print(Level::error, location, format, std::forward<Args>(arguments)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
error(std::format_string<Args...>, Args &&...) noexcept -> error<Args...>;
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct [[maybe_unused]] critical
|
|
||||||
{
|
|
||||||
[[maybe_unused]] critical(
|
|
||||||
std::format_string<Args...> format,
|
|
||||||
Args &&...arguments,
|
|
||||||
const std::source_location &location = std::source_location::current()
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
print(Level::critical, location, format, std::forward<Args>(arguments)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
critical(std::format_string<Args...>, Args &&...) noexcept -> critical<Args...>;
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void test(std::format_string<Args...> format, Args &&...arguments) noexcept
|
|
||||||
{
|
|
||||||
print(Level::test, format, std::forward<Args>(arguments)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::log
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
import test;
|
|
||||||
|
|
||||||
Suite suite = [] {
|
|
||||||
Case { "formatless" } = [] {
|
|
||||||
lt::log::trace("trace");
|
|
||||||
lt::log::debug("debug");
|
|
||||||
lt::log::info("info");
|
|
||||||
lt::log::warn("warn");
|
|
||||||
lt::log::error("error");
|
|
||||||
lt::log::critical("critical");
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "formatted" } = [] {
|
|
||||||
lt::log::trace("trace {}", 69);
|
|
||||||
lt::log::debug("debug {}", 69);
|
|
||||||
lt::log::info("info {}", 69);
|
|
||||||
lt::log::warn("warn {}", 69);
|
|
||||||
lt::log::error("error {}", 69);
|
|
||||||
lt::log::critical("critical {}", 69);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
export module math.algebra;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import math.mat4;
|
|
||||||
|
|
||||||
export namespace lt::math {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* let...
|
|
||||||
* a = h / w ==> for aspect ratio adjustment
|
|
||||||
* f = 1 / tan(fov / 2) ==> for field of view
|
|
||||||
*
|
|
||||||
* zdiff = zfar-znear
|
|
||||||
* A = (zfar / zdiff) - (zfar / zdiff * znear) ==> for normalization
|
|
||||||
*
|
|
||||||
* given a 3d position vector xyz, we need to do the following operations to achieve
|
|
||||||
* perspective projection:
|
|
||||||
* x afx
|
|
||||||
* y --> fy
|
|
||||||
* z Az - Aznear
|
|
||||||
*
|
|
||||||
* such calculation can be embdedded in a matrix as:
|
|
||||||
* [x] [y] [z] [w]
|
|
||||||
*
|
|
||||||
* | af | 0 | 0 | 0 |
|
|
||||||
* ----------------------------------
|
|
||||||
* | 0 | f | 0 | 0 |
|
|
||||||
* ----------------------------------
|
|
||||||
* | 0 | 0 | A | A*znear|
|
|
||||||
* ----------------------------------
|
|
||||||
* | 0 | 0 | 1 | 0 |
|
|
||||||
*
|
|
||||||
* the 1 at [z][3] is to save the Z axis into the resulting W for perspective division.
|
|
||||||
*
|
|
||||||
* @ref Thanks to @pikuma for explaining the math behind this:
|
|
||||||
* https://www.youtube.com/watch?v=EqNcqBdrNyI
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
requires(std::is_arithmetic_v<T>)
|
|
||||||
constexpr auto perspective(T field_of_view, T aspect_ratio, T z_near, T z_far) -> mat4_impl<T>
|
|
||||||
{
|
|
||||||
const T half_fov_tan = std::tan(field_of_view / static_cast<T>(2));
|
|
||||||
|
|
||||||
auto result = mat4_impl<T>::identity();
|
|
||||||
|
|
||||||
result[0][0] = T { 1 } / (aspect_ratio * half_fov_tan);
|
|
||||||
//
|
|
||||||
result[1][1] = T { 1 } / (half_fov_tan);
|
|
||||||
//
|
|
||||||
// result[2][2] = -(z_far + z_near) / (z_far - z_near);
|
|
||||||
//
|
|
||||||
result[2][2] = z_far / (z_far - z_near);
|
|
||||||
//
|
|
||||||
result[2][3] = -T { 1 };
|
|
||||||
//
|
|
||||||
// result[3][2] = -(T { 2 } * z_far * z_near) / (z_far - z_near);
|
|
||||||
result[3][2] = -(z_far * z_near) / (z_far - z_near);
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::math
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
export module math.components;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import math.vec3;
|
|
||||||
|
|
||||||
namespace lt::math::components {
|
|
||||||
|
|
||||||
export struct Transform
|
|
||||||
{
|
|
||||||
math::vec3 translation;
|
|
||||||
|
|
||||||
math::vec3 scale;
|
|
||||||
|
|
||||||
math::vec3 rotation;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::math::components
|
|
||||||
|
|
@ -1,185 +0,0 @@
|
||||||
export module math.mat4;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import math.vec2;
|
|
||||||
import math.vec3;
|
|
||||||
import math.vec4;
|
|
||||||
|
|
||||||
export namespace lt::math {
|
|
||||||
|
|
||||||
/** A 4 by 4 matrix, column major order
|
|
||||||
*
|
|
||||||
* @todo(Light): Use std::simd when it's implemented. */
|
|
||||||
template<typename T = f32>
|
|
||||||
requires(std::is_arithmetic_v<T>)
|
|
||||||
struct mat4_impl
|
|
||||||
{
|
|
||||||
using Column_T = vec4_impl<T>;
|
|
||||||
|
|
||||||
using Underlying_T = Column_T::Underlying_T;
|
|
||||||
|
|
||||||
static constexpr auto num_elements = 4u * 4u;
|
|
||||||
|
|
||||||
constexpr explicit mat4_impl(T scalar = T {})
|
|
||||||
: values(
|
|
||||||
{
|
|
||||||
Column_T { scalar },
|
|
||||||
Column_T { scalar },
|
|
||||||
Column_T { scalar },
|
|
||||||
Column_T { scalar },
|
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr mat4_impl(
|
|
||||||
// clang-format off
|
|
||||||
const T& x0, const T& x1, const T& x2, const T& x3,
|
|
||||||
const T& y0, const T& y1, const T& y2, const T& y3,
|
|
||||||
const T& z0, const T& z1, const T& z2, const T& z3,
|
|
||||||
const T& w0, const T& w1, const T& w2, const T& w3)
|
|
||||||
// clang-format on
|
|
||||||
: values({ { x0, x1, x2, x3 }, { y0, y1, y2, y3 }, { z0, z1, z2, z3 }, { w0, w1, w2, w3 } })
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr mat4_impl(
|
|
||||||
const Column_T &column_x,
|
|
||||||
const Column_T &column_y,
|
|
||||||
const Column_T &column_z,
|
|
||||||
const Column_T &column_w
|
|
||||||
)
|
|
||||||
: values({ column_x, column_y, column_z, column_w })
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static constexpr auto identity() -> mat4_impl<T>
|
|
||||||
{
|
|
||||||
return mat4_impl<T> {
|
|
||||||
{ 1 }, {}, {}, {}, //
|
|
||||||
{}, { 1 }, {}, {}, //
|
|
||||||
{}, {}, { 1 }, {}, //
|
|
||||||
{}, {}, {}, { 1 }, //
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator*(const mat4_impl<T> &other) const -> mat4_impl<T>
|
|
||||||
{
|
|
||||||
const auto &[a_x, a_y, a_z, a_w] = values;
|
|
||||||
const auto &[b_x, b_y, b_z, b_w] = other.values;
|
|
||||||
|
|
||||||
return mat4_impl<T>(
|
|
||||||
// X column
|
|
||||||
a_x.x * b_x.x + a_y.x * b_x.y + a_z.x * b_x.z + a_w.x * b_x.w,
|
|
||||||
a_x.y * b_x.x + a_y.y * b_x.y + a_z.y * b_x.z + a_w.y * b_x.w,
|
|
||||||
a_x.z * b_x.x + a_y.z * b_x.y + a_z.z * b_x.z + a_w.z * b_x.w,
|
|
||||||
a_x.w * b_x.x + a_y.w * b_x.y + a_z.w * b_x.z + a_w.w * b_x.w,
|
|
||||||
|
|
||||||
// Y column
|
|
||||||
a_x.x * b_y.x + a_y.x * b_y.y + a_z.x * b_y.z + a_w.x * b_y.w,
|
|
||||||
a_x.y * b_y.x + a_y.y * b_y.y + a_z.y * b_y.z + a_w.y * b_y.w,
|
|
||||||
a_x.z * b_y.x + a_y.z * b_y.y + a_z.z * b_y.z + a_w.z * b_y.w,
|
|
||||||
a_x.w * b_y.x + a_y.w * b_y.y + a_z.w * b_y.z + a_w.w * b_y.w,
|
|
||||||
|
|
||||||
// Z column
|
|
||||||
a_x.x * b_z.x + a_y.x * b_z.y + a_z.x * b_z.z + a_w.x * b_z.w,
|
|
||||||
a_x.y * b_z.x + a_y.y * b_z.y + a_z.y * b_z.z + a_w.y * b_z.w,
|
|
||||||
a_x.z * b_z.x + a_y.z * b_z.y + a_z.z * b_z.z + a_w.z * b_z.w,
|
|
||||||
a_x.w * b_z.x + a_y.w * b_z.y + a_z.w * b_z.z + a_w.w * b_z.w,
|
|
||||||
|
|
||||||
// W column
|
|
||||||
a_x.x * b_w.x + a_y.x * b_w.y + a_z.x * b_w.z + a_w.x * b_w.w,
|
|
||||||
a_x.y * b_w.x + a_y.y * b_w.y + a_z.y * b_w.z + a_w.y * b_w.w,
|
|
||||||
a_x.z * b_w.x + a_y.z * b_w.y + a_z.z * b_w.z + a_w.z * b_w.w,
|
|
||||||
a_x.w * b_w.x + a_y.w * b_w.y + a_z.w * b_w.z + a_w.w * b_w.w
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](size_t idx) -> Column_T &
|
|
||||||
{
|
|
||||||
debug_check(idx < num_elements, "mat4 out of bound access: {}", idx);
|
|
||||||
return values[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](size_t idx) const -> const Column_T &
|
|
||||||
{
|
|
||||||
return values[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static constexpr auto transpose(const mat4_impl<T> &mat) -> mat4_impl<T>
|
|
||||||
{
|
|
||||||
const auto &[x, y, z, w] = mat.values;
|
|
||||||
return mat4_impl<T> {
|
|
||||||
x.x, y.x, z.x, w.x, x.y, y.y, z.y, w.y, x.z, y.z, z.z, w.z, x.w, y.w, z.w, w.w,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static constexpr auto translate(const vec3_impl<T> &vec) -> mat4_impl<T>
|
|
||||||
{
|
|
||||||
return mat4_impl<T>(
|
|
||||||
T { 1 },
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
|
|
||||||
T { 0 },
|
|
||||||
T { 1 },
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
T { 1 },
|
|
||||||
T { 0 },
|
|
||||||
|
|
||||||
vec.x,
|
|
||||||
vec.y,
|
|
||||||
vec.z,
|
|
||||||
T { 1 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static constexpr auto scale(const vec3_impl<T> &vec) -> mat4_impl<T>
|
|
||||||
{
|
|
||||||
return mat4_impl<T>(
|
|
||||||
vec.x,
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
|
|
||||||
T { 0 },
|
|
||||||
vec.y,
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
vec.z,
|
|
||||||
T { 0 },
|
|
||||||
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
T { 0 },
|
|
||||||
T { 1 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::array<Column_T, 4u> values;
|
|
||||||
};
|
|
||||||
|
|
||||||
using mat4 = mat4_impl<f32>;
|
|
||||||
|
|
||||||
using mat4_f32 = mat4;
|
|
||||||
using mat4_f64 = mat4_impl<f64>;
|
|
||||||
|
|
||||||
using mat4_i8 = mat4_impl<i8>;
|
|
||||||
using mat4_i16 = mat4_impl<i16>;
|
|
||||||
using mat4_i32 = mat4_impl<i32>;
|
|
||||||
using mat4_i64 = mat4_impl<i64>;
|
|
||||||
|
|
||||||
using mat4_u8 = mat4_impl<u8>;
|
|
||||||
using mat4_u16 = mat4_impl<u16>;
|
|
||||||
using mat4_u32 = mat4_impl<u32>;
|
|
||||||
using mat4_u64 = mat4_impl<u64>;
|
|
||||||
|
|
||||||
} // namespace lt::math
|
|
||||||
|
|
@ -1,413 +0,0 @@
|
||||||
import test;
|
|
||||||
import math.vec3;
|
|
||||||
import math.mat4;
|
|
||||||
|
|
||||||
using vec3 = ::lt::math::vec3;
|
|
||||||
using mat4 = ::lt::math::mat4;
|
|
||||||
|
|
||||||
Suite static_tests = "mat4_static_checks"_suite = [] {
|
|
||||||
constexpr auto num_elements = lt::math::mat4::num_elements;
|
|
||||||
|
|
||||||
static_assert(num_elements == 4u * 4u);
|
|
||||||
static_assert(std::is_same_v<lt::math::mat4, lt::math::mat4_f32>);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::mat4_f32) == sizeof(f32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::mat4_f64) == sizeof(f64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::mat4_i8) == sizeof(i8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::mat4_i16) == sizeof(i16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::mat4_i32) == sizeof(i32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::mat4_i64) == sizeof(i64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::mat4_u8) == sizeof(u8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::mat4_u16) == sizeof(u16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::mat4_u32) == sizeof(u32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::mat4_u64) == sizeof(u64) * num_elements);
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite raii = "mat4_raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
ignore = mat4 {};
|
|
||||||
ignore = mat4 { 1.0 };
|
|
||||||
ignore = mat4 {
|
|
||||||
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
|
|
||||||
};
|
|
||||||
ignore = mat4 {
|
|
||||||
mat4::Column_T { 1.0, 2.0, 3.0, 4.0 },
|
|
||||||
mat4::Column_T { 5.0, 6.0, 7.0, 8.0 },
|
|
||||||
mat4::Column_T { 9.0, 10.0, 11.0, 12.0 },
|
|
||||||
mat4::Column_T { 13.0, 14.0, 15.0, 16.0 },
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
for (auto idx : std::views::iota(0, 1'000'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
ignore = mat4 {};
|
|
||||||
ignore = mat4 { 1.0 };
|
|
||||||
ignore = mat4 {
|
|
||||||
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
|
|
||||||
9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
|
|
||||||
};
|
|
||||||
ignore = mat4 {
|
|
||||||
mat4::Column_T { 1.0, 2.0, 3.0, 4.0 },
|
|
||||||
mat4::Column_T { 5.0, 6.0, 7.0, 8.0 },
|
|
||||||
mat4::Column_T { 9.0, 10.0, 11.0, 12.0 },
|
|
||||||
mat4::Column_T { 13.0, 14.0, 15.0, 16.0 },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post default construct has correct state" } = [] {
|
|
||||||
const auto [x, y, z, w] = mat4 {}.values;
|
|
||||||
|
|
||||||
expect_eq(x[0], mat4::Underlying_T {});
|
|
||||||
expect_eq(x[1], mat4::Underlying_T {});
|
|
||||||
expect_eq(x[2], mat4::Underlying_T {});
|
|
||||||
expect_eq(x[3], mat4::Underlying_T {});
|
|
||||||
|
|
||||||
expect_eq(y[0], mat4::Underlying_T {});
|
|
||||||
expect_eq(y[1], mat4::Underlying_T {});
|
|
||||||
expect_eq(y[2], mat4::Underlying_T {});
|
|
||||||
expect_eq(y[3], mat4::Underlying_T {});
|
|
||||||
|
|
||||||
expect_eq(z[0], mat4::Underlying_T {});
|
|
||||||
expect_eq(z[1], mat4::Underlying_T {});
|
|
||||||
expect_eq(z[2], mat4::Underlying_T {});
|
|
||||||
expect_eq(z[3], mat4::Underlying_T {});
|
|
||||||
|
|
||||||
expect_eq(w[0], mat4::Underlying_T {});
|
|
||||||
expect_eq(w[1], mat4::Underlying_T {});
|
|
||||||
expect_eq(w[2], mat4::Underlying_T {});
|
|
||||||
expect_eq(w[3], mat4::Underlying_T {});
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post scalar construct has correct state" } = [] {
|
|
||||||
const auto [x, y, z, w] = mat4 { 69.0 }.values;
|
|
||||||
|
|
||||||
expect_eq(x[0], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(x[1], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(x[2], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(x[3], mat4::Underlying_T { 69.0 });
|
|
||||||
|
|
||||||
expect_eq(y[0], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(y[1], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(y[2], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(y[3], mat4::Underlying_T { 69.0 });
|
|
||||||
|
|
||||||
expect_eq(z[0], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(z[1], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(z[2], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(z[3], mat4::Underlying_T { 69.0 });
|
|
||||||
|
|
||||||
expect_eq(w[0], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(w[1], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(w[2], mat4::Underlying_T { 69.0 });
|
|
||||||
expect_eq(w[3], mat4::Underlying_T { 69.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with all values has correct state" } = [] {
|
|
||||||
const auto [x, y, z, w] = mat4 {
|
|
||||||
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
|
|
||||||
}.values;
|
|
||||||
|
|
||||||
expect_eq(x[0], mat4::Underlying_T { 1.0 });
|
|
||||||
expect_eq(x[1], mat4::Underlying_T { 2.0 });
|
|
||||||
expect_eq(x[2], mat4::Underlying_T { 3.0 });
|
|
||||||
expect_eq(x[3], mat4::Underlying_T { 4.0 });
|
|
||||||
|
|
||||||
expect_eq(y[0], mat4::Underlying_T { 5.0 });
|
|
||||||
expect_eq(y[1], mat4::Underlying_T { 6.0 });
|
|
||||||
expect_eq(y[2], mat4::Underlying_T { 7.0 });
|
|
||||||
expect_eq(y[3], mat4::Underlying_T { 8.0 });
|
|
||||||
|
|
||||||
expect_eq(z[0], mat4::Underlying_T { 9.0 });
|
|
||||||
expect_eq(z[1], mat4::Underlying_T { 10.0 });
|
|
||||||
expect_eq(z[2], mat4::Underlying_T { 11.0 });
|
|
||||||
expect_eq(z[3], mat4::Underlying_T { 12.0 });
|
|
||||||
|
|
||||||
expect_eq(w[0], mat4::Underlying_T { 13.0 });
|
|
||||||
expect_eq(w[1], mat4::Underlying_T { 14.0 });
|
|
||||||
expect_eq(w[2], mat4::Underlying_T { 15.0 });
|
|
||||||
expect_eq(w[3], mat4::Underlying_T { 16.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with columns has correct state" } = [] {
|
|
||||||
const auto [x, y, z, w] = mat4 {
|
|
||||||
mat4::Column_T { 1.0, 2.0, 3.0, 4.0 },
|
|
||||||
mat4::Column_T { 5.0, 6.0, 7.0, 8.0 },
|
|
||||||
mat4::Column_T { 9.0, 10.0, 11.0, 12.0 },
|
|
||||||
mat4::Column_T { 13.0, 14.0, 15.0, 16.0 },
|
|
||||||
}.values;
|
|
||||||
|
|
||||||
expect_eq(x[0], mat4::Underlying_T { 1.0 });
|
|
||||||
expect_eq(x[1], mat4::Underlying_T { 2.0 });
|
|
||||||
expect_eq(x[2], mat4::Underlying_T { 3.0 });
|
|
||||||
expect_eq(x[3], mat4::Underlying_T { 4.0 });
|
|
||||||
|
|
||||||
expect_eq(y[0], mat4::Underlying_T { 5.0 });
|
|
||||||
expect_eq(y[1], mat4::Underlying_T { 6.0 });
|
|
||||||
expect_eq(y[2], mat4::Underlying_T { 7.0 });
|
|
||||||
expect_eq(y[3], mat4::Underlying_T { 8.0 });
|
|
||||||
|
|
||||||
expect_eq(z[0], mat4::Underlying_T { 9.0 });
|
|
||||||
expect_eq(z[1], mat4::Underlying_T { 10.0 });
|
|
||||||
expect_eq(z[2], mat4::Underlying_T { 11.0 });
|
|
||||||
expect_eq(z[3], mat4::Underlying_T { 12.0 });
|
|
||||||
|
|
||||||
expect_eq(w[0], mat4::Underlying_T { 13.0 });
|
|
||||||
expect_eq(w[1], mat4::Underlying_T { 14.0 });
|
|
||||||
expect_eq(w[2], mat4::Underlying_T { 15.0 });
|
|
||||||
expect_eq(w[3], mat4::Underlying_T { 16.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct identity matrix has correct state" } = [] {
|
|
||||||
const auto [x, y, z, w] = mat4::identity().values;
|
|
||||||
|
|
||||||
expect_eq(x[0], mat4::Underlying_T { 1 });
|
|
||||||
expect_eq(x[1], mat4::Underlying_T {});
|
|
||||||
expect_eq(x[2], mat4::Underlying_T {});
|
|
||||||
expect_eq(x[3], mat4::Underlying_T {});
|
|
||||||
|
|
||||||
expect_eq(y[0], mat4::Underlying_T {});
|
|
||||||
expect_eq(y[1], mat4::Underlying_T { 1 });
|
|
||||||
expect_eq(y[2], mat4::Underlying_T {});
|
|
||||||
expect_eq(y[3], mat4::Underlying_T {});
|
|
||||||
|
|
||||||
expect_eq(z[0], mat4::Underlying_T {});
|
|
||||||
expect_eq(z[1], mat4::Underlying_T {});
|
|
||||||
expect_eq(z[2], mat4::Underlying_T { 1 });
|
|
||||||
expect_eq(z[3], mat4::Underlying_T {});
|
|
||||||
|
|
||||||
expect_eq(w[0], mat4::Underlying_T {});
|
|
||||||
expect_eq(w[1], mat4::Underlying_T {});
|
|
||||||
expect_eq(w[2], mat4::Underlying_T {});
|
|
||||||
expect_eq(w[3], mat4::Underlying_T { 1 });
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite arithmetic_operators = "mat4_arithmetic_operators"_suite = [] {
|
|
||||||
Case { "operator *" } = [] {
|
|
||||||
const auto lhs = mat4 {
|
|
||||||
mat4::Column_T { 1.0, 2.0, 3.0, 4.0 },
|
|
||||||
mat4::Column_T { 5.0, 6.0, 7.0, 8.0 },
|
|
||||||
mat4::Column_T { 9.0, 10.0, 11.0, 12.0 },
|
|
||||||
mat4::Column_T { 13.0, 14.0, 15.0, 16.0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto rhs = mat4 {
|
|
||||||
mat4::Column_T { 17.0, 18.0, 19.0, 20.0 },
|
|
||||||
mat4::Column_T { 21.0, 22.0, 23.0, 24.0 },
|
|
||||||
mat4::Column_T { 25.0, 26.0, 27.0, 28.0 },
|
|
||||||
mat4::Column_T { 29.0, 30.0, 31.0, 32.0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto [x, y, z, w] = (lhs * rhs).values;
|
|
||||||
|
|
||||||
expect_eq(x[0], 538.0);
|
|
||||||
expect_eq(x[1], 612.0);
|
|
||||||
expect_eq(x[2], 686.0);
|
|
||||||
expect_eq(x[3], 760.0);
|
|
||||||
|
|
||||||
expect_eq(y[0], 650.0);
|
|
||||||
expect_eq(y[1], 740.0);
|
|
||||||
expect_eq(y[2], 830.0);
|
|
||||||
expect_eq(y[3], 920.0);
|
|
||||||
|
|
||||||
expect_eq(z[0], 762.0);
|
|
||||||
expect_eq(z[1], 868.0);
|
|
||||||
expect_eq(z[2], 974.0);
|
|
||||||
expect_eq(z[3], 1080.0);
|
|
||||||
|
|
||||||
expect_eq(w[0], 874.0);
|
|
||||||
expect_eq(w[1], 996.0);
|
|
||||||
expect_eq(w[2], 1118.0);
|
|
||||||
expect_eq(w[3], 1240.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite access_operators = "mat4_access_operators"_suite = [] {
|
|
||||||
Case { "operator []" } = [] {
|
|
||||||
auto mat = mat4 {
|
|
||||||
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect_eq(mat[0][0], 1.0);
|
|
||||||
expect_eq(mat[0][1], 2.0);
|
|
||||||
expect_eq(mat[0][2], 3.0);
|
|
||||||
expect_eq(mat[0][3], 4.0);
|
|
||||||
|
|
||||||
expect_eq(mat[1][0], 5.0);
|
|
||||||
expect_eq(mat[1][1], 6.0);
|
|
||||||
expect_eq(mat[1][2], 7.0);
|
|
||||||
expect_eq(mat[1][3], 8.0);
|
|
||||||
|
|
||||||
expect_eq(mat[2][0], 9.0);
|
|
||||||
expect_eq(mat[2][1], 10.0);
|
|
||||||
expect_eq(mat[2][2], 11.0);
|
|
||||||
expect_eq(mat[2][3], 12.0);
|
|
||||||
|
|
||||||
expect_eq(mat[3][0], 13.0);
|
|
||||||
expect_eq(mat[3][1], 14.0);
|
|
||||||
expect_eq(mat[3][2], 15.0);
|
|
||||||
expect_eq(mat[3][3], 16.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator [] const" } = [] {
|
|
||||||
const auto mat = mat4 {
|
|
||||||
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect_eq(mat[0][0], 1.0);
|
|
||||||
expect_eq(mat[0][1], 2.0);
|
|
||||||
expect_eq(mat[0][2], 3.0);
|
|
||||||
expect_eq(mat[0][3], 4.0);
|
|
||||||
|
|
||||||
expect_eq(mat[1][0], 5.0);
|
|
||||||
expect_eq(mat[1][1], 6.0);
|
|
||||||
expect_eq(mat[1][2], 7.0);
|
|
||||||
expect_eq(mat[1][3], 8.0);
|
|
||||||
|
|
||||||
expect_eq(mat[2][0], 9.0);
|
|
||||||
expect_eq(mat[2][1], 10.0);
|
|
||||||
expect_eq(mat[2][2], 11.0);
|
|
||||||
expect_eq(mat[2][3], 12.0);
|
|
||||||
|
|
||||||
expect_eq(mat[3][0], 13.0);
|
|
||||||
expect_eq(mat[3][1], 14.0);
|
|
||||||
expect_eq(mat[3][2], 15.0);
|
|
||||||
expect_eq(mat[3][3], 16.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite transformations = "mat4_transformations"_suite = [] {
|
|
||||||
Case { "translate" } = [] {
|
|
||||||
const auto &[x, y, z, w] = mat4::translate(vec3 { 1, 2, 3 }).values;
|
|
||||||
|
|
||||||
// identity basis
|
|
||||||
expect_eq(x[0], 1);
|
|
||||||
expect_eq(x[1], 0);
|
|
||||||
expect_eq(x[2], 0);
|
|
||||||
expect_eq(x[3], 0);
|
|
||||||
expect_eq(y[0], 0);
|
|
||||||
expect_eq(y[1], 1);
|
|
||||||
expect_eq(y[2], 0);
|
|
||||||
expect_eq(y[3], 0);
|
|
||||||
expect_eq(z[0], 0);
|
|
||||||
expect_eq(z[1], 0);
|
|
||||||
expect_eq(z[2], 1);
|
|
||||||
expect_eq(z[3], 0);
|
|
||||||
|
|
||||||
// translation column
|
|
||||||
expect_eq(w[0], 1);
|
|
||||||
expect_eq(w[1], 2);
|
|
||||||
expect_eq(w[2], 3);
|
|
||||||
expect_eq(w[3], 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "scale" } = [] {
|
|
||||||
const auto [x, y, z, w] = mat4::scale(vec3 { 2, 3, 4 }).values;
|
|
||||||
|
|
||||||
expect_eq(x[0], 2);
|
|
||||||
expect_eq(x[1], 0);
|
|
||||||
expect_eq(x[2], 0);
|
|
||||||
expect_eq(x[3], 0);
|
|
||||||
expect_eq(y[0], 0);
|
|
||||||
expect_eq(y[1], 3);
|
|
||||||
expect_eq(y[2], 0);
|
|
||||||
expect_eq(y[3], 0);
|
|
||||||
expect_eq(z[0], 0);
|
|
||||||
expect_eq(z[1], 0);
|
|
||||||
expect_eq(z[2], 4);
|
|
||||||
expect_eq(z[3], 0);
|
|
||||||
expect_eq(w[0], 0);
|
|
||||||
expect_eq(w[1], 0);
|
|
||||||
expect_eq(w[2], 0);
|
|
||||||
expect_eq(w[3], 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "scale -> translate" } = [] {
|
|
||||||
const auto scale = mat4::scale(vec3 { 2, 2, 2 });
|
|
||||||
const auto translate = mat4::translate(vec3 { 1, 2, 3 });
|
|
||||||
const auto [x, y, z, w] = (scale * translate).values;
|
|
||||||
|
|
||||||
// scaled basis
|
|
||||||
expect_eq(x[0], 2);
|
|
||||||
expect_eq(x[1], 0);
|
|
||||||
expect_eq(x[2], 0);
|
|
||||||
expect_eq(x[3], 0);
|
|
||||||
expect_eq(y[0], 0);
|
|
||||||
expect_eq(y[1], 2);
|
|
||||||
expect_eq(y[2], 0);
|
|
||||||
expect_eq(y[3], 0);
|
|
||||||
expect_eq(z[0], 0);
|
|
||||||
expect_eq(z[1], 0);
|
|
||||||
expect_eq(z[2], 2);
|
|
||||||
expect_eq(z[3], 0);
|
|
||||||
|
|
||||||
// translation is scaled (local-space translation)
|
|
||||||
expect_eq(w[0], 2); // 1 * 2
|
|
||||||
expect_eq(w[1], 4); // 2 * 2
|
|
||||||
expect_eq(w[2], 6); // 3 * 2
|
|
||||||
expect_eq(w[3], 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "transpose" } = [] {
|
|
||||||
const auto mat = mat4 {
|
|
||||||
mat4::Column_T { 1, 2, 3, 4 },
|
|
||||||
mat4::Column_T { 5, 6, 7, 8 },
|
|
||||||
mat4::Column_T { 9, 10, 11, 12 },
|
|
||||||
mat4::Column_T { 13, 14, 15, 16 },
|
|
||||||
};
|
|
||||||
const auto [x, y, z, w] = mat4::transpose(mat).values;
|
|
||||||
|
|
||||||
// rows become columns
|
|
||||||
expect_eq(x[0], 1);
|
|
||||||
expect_eq(x[1], 5);
|
|
||||||
expect_eq(x[2], 9);
|
|
||||||
expect_eq(x[3], 13);
|
|
||||||
expect_eq(y[0], 2);
|
|
||||||
expect_eq(y[1], 6);
|
|
||||||
expect_eq(y[2], 10);
|
|
||||||
expect_eq(y[3], 14);
|
|
||||||
expect_eq(z[0], 3);
|
|
||||||
expect_eq(z[1], 7);
|
|
||||||
expect_eq(z[2], 11);
|
|
||||||
expect_eq(z[3], 15);
|
|
||||||
expect_eq(w[0], 4);
|
|
||||||
expect_eq(w[1], 8);
|
|
||||||
expect_eq(w[2], 12);
|
|
||||||
expect_eq(w[3], 16);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "transpose twice" } = [] {
|
|
||||||
const auto mat = mat4 {
|
|
||||||
mat4::Column_T { 1, 2, 3, 4 },
|
|
||||||
mat4::Column_T { 5, 6, 7, 8 },
|
|
||||||
mat4::Column_T { 9, 10, 11, 12 },
|
|
||||||
mat4::Column_T { 13, 14, 15, 16 },
|
|
||||||
};
|
|
||||||
const auto [x, y, z, w] = mat4::transpose(mat4::transpose(mat)).values;
|
|
||||||
|
|
||||||
expect_eq(x[0], 1);
|
|
||||||
expect_eq(x[1], 2);
|
|
||||||
expect_eq(x[2], 3);
|
|
||||||
expect_eq(x[3], 4);
|
|
||||||
expect_eq(y[0], 5);
|
|
||||||
expect_eq(y[1], 6);
|
|
||||||
expect_eq(y[2], 7);
|
|
||||||
expect_eq(y[3], 8);
|
|
||||||
expect_eq(z[0], 9);
|
|
||||||
expect_eq(z[1], 10);
|
|
||||||
expect_eq(z[2], 11);
|
|
||||||
expect_eq(z[3], 12);
|
|
||||||
expect_eq(w[0], 13);
|
|
||||||
expect_eq(w[1], 14);
|
|
||||||
expect_eq(w[2], 15);
|
|
||||||
expect_eq(w[3], 16);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
export module math.trig;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
export namespace lt::math {
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto to_radians(f32 degrees) -> f32
|
|
||||||
{
|
|
||||||
return degrees * 0.01745329251994329576923690768489f;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto to_radians(f64 degrees) -> f64
|
|
||||||
{
|
|
||||||
return degrees * 0.01745329251994329576923690768489;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto to_degrees(f32 radians) -> f32
|
|
||||||
{
|
|
||||||
return radians * 57.295779513082320876798154814105f;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto to_degrees(f64 radians) -> f64
|
|
||||||
{
|
|
||||||
return radians * 57.295779513082320876798154814105;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::math
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
import test;
|
|
||||||
import math.trig;
|
|
||||||
|
|
||||||
Suite conversions = "trig_conversions"_suite = [] {
|
|
||||||
using ::lt::math::to_degrees;
|
|
||||||
using ::lt::math::to_radians;
|
|
||||||
|
|
||||||
Case { "to_radians <f32>" } = [] {
|
|
||||||
expect_eq(to_radians(f32 { 0.0f }), f32 { 0.0f });
|
|
||||||
expect_eq(to_radians(f32 { 90.0f }), f32 { 1.5707963267948966f });
|
|
||||||
expect_eq(to_radians(f32 { 180.0f }), f32 { 3.1415926535897932f });
|
|
||||||
expect_eq(to_radians(f32 { 360.0f }), f32 { 6.2831853071795864f });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "to_radians <f64>" } = [] {
|
|
||||||
expect_eq(to_radians(f64 { 0.0 }), f64 { 0.0 });
|
|
||||||
expect_eq(to_radians(f64 { 90.0 }), f64 { 1.5707963267948966 });
|
|
||||||
expect_eq(to_radians(f64 { 180.0 }), f64 { 3.1415926535897932 });
|
|
||||||
expect_eq(to_radians(f64 { 360.0 }), f64 { 6.2831853071795864 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "to_degrees <f32>" } = [] {
|
|
||||||
expect_eq(to_degrees(f32 { 0.0f }), f32 { 0.0f });
|
|
||||||
expect_eq(to_degrees(f32 { 1.5707963267948966f }), f32 { 90.0f });
|
|
||||||
expect_eq(to_degrees(f32 { 3.1415926535897932f }), f32 { 180.0f });
|
|
||||||
expect_eq(to_degrees(f32 { 6.2831853071795864f }), f32 { 360.0f });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "to_degrees <f64>" } = [] {
|
|
||||||
expect_eq(to_degrees(f64 { 0.0 }), f64 { 0.0 });
|
|
||||||
expect_eq(to_degrees(f64 { 1.5707963267948966 }), f64 { 90.0 });
|
|
||||||
expect_eq(to_degrees(f64 { 3.1415926535897932 }), f64 { 180.0 });
|
|
||||||
expect_eq(to_degrees(f64 { 6.2831853071795864 }), f64 { 360.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "to_degrees -> to_radians -> to_degrees <f32>" } = [] {
|
|
||||||
expect_eq(to_degrees(to_radians(f32 { 45.0f })), f32 { 45.0f });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "to_degrees -> to_radians -> to_degrees <f64>" } = [] {
|
|
||||||
expect_eq(to_degrees(to_radians(f64 { 45.0 })), f64 { 45.0 });
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
||||||
export module math.vec2;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
export namespace lt::math {
|
|
||||||
|
|
||||||
template<typename T = f32>
|
|
||||||
requires(std::is_arithmetic_v<T>)
|
|
||||||
struct vec2_impl
|
|
||||||
{
|
|
||||||
using Underlying_T = T;
|
|
||||||
|
|
||||||
static constexpr auto num_elements = 2u;
|
|
||||||
|
|
||||||
constexpr vec2_impl(): x(), y()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr explicit vec2_impl(T scalar): x(scalar), y(scalar)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec2_impl(T x, T y): x(x), y(y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator==(const vec2_impl<T> &other) const -> bool
|
|
||||||
{
|
|
||||||
return x == other.x && y == other.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator!=(const vec2_impl<T> &other) const -> bool
|
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator+(const vec2_impl<T> &other) const -> vec2_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x + other.x,
|
|
||||||
y + other.y,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator-(const vec2_impl<T> &other) const -> vec2_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x - other.x,
|
|
||||||
y - other.y,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator*(const vec2_impl<T> &other) const -> vec2_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x * other.x,
|
|
||||||
y * other.y,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator/(const vec2_impl<T> &other) const -> vec2_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x / other.x,
|
|
||||||
y / other.y,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](u8 idx) -> T &
|
|
||||||
{
|
|
||||||
debug_check(idx < num_elements, "vec2 out of bound access: {}", idx);
|
|
||||||
return ((T *)this)[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](u8 idx) const -> const T &
|
|
||||||
{
|
|
||||||
debug_check(idx < num_elements, "vec2 out of bound access: {}", idx);
|
|
||||||
return ((T *)this)[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
T x;
|
|
||||||
|
|
||||||
T y;
|
|
||||||
};
|
|
||||||
|
|
||||||
using vec2 = vec2_impl<f32>;
|
|
||||||
|
|
||||||
using vec2_f32 = vec2;
|
|
||||||
using vec2_f64 = vec2_impl<f64>;
|
|
||||||
|
|
||||||
using vec2_i8 = vec2_impl<i8>;
|
|
||||||
using vec2_i16 = vec2_impl<i16>;
|
|
||||||
using vec2_i32 = vec2_impl<i32>;
|
|
||||||
using vec2_i64 = vec2_impl<i64>;
|
|
||||||
|
|
||||||
using vec2_u8 = vec2_impl<u8>;
|
|
||||||
using vec2_u16 = vec2_impl<u16>;
|
|
||||||
using vec2_u32 = vec2_impl<u32>;
|
|
||||||
using vec2_u64 = vec2_impl<u64>;
|
|
||||||
|
|
||||||
} // namespace lt::math
|
|
||||||
|
|
||||||
export template<typename T>
|
|
||||||
struct std::formatter<lt::math::vec2_impl<T>>
|
|
||||||
{
|
|
||||||
constexpr auto parse(std::format_parse_context &context)
|
|
||||||
{
|
|
||||||
return context.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto format(const lt::math::vec2_impl<T> &val, std::format_context &context) const
|
|
||||||
{
|
|
||||||
return std::format_to(context.out(), "{}, {}", val.x, val.y);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,130 +0,0 @@
|
||||||
import test;
|
|
||||||
import math.vec2;
|
|
||||||
|
|
||||||
using vec2 = ::lt::math::vec2;
|
|
||||||
using ivec2 = ::lt::math::vec2_i32;
|
|
||||||
|
|
||||||
Suite static_tests = "vec3_static_checks"_suite = [] {
|
|
||||||
constexpr auto num_elements = lt::math::vec2::num_elements;
|
|
||||||
|
|
||||||
static_assert(num_elements == 2u);
|
|
||||||
static_assert(std::is_same_v<lt::math::vec2, lt::math::vec2_f32>);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec2_f32) == sizeof(f32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec2_f64) == sizeof(f64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec2_i8) == sizeof(i8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec2_i16) == sizeof(i16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec2_i32) == sizeof(i32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec2_i64) == sizeof(i64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec2_u8) == sizeof(u8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec2_u16) == sizeof(u16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec2_u32) == sizeof(u32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec2_u64) == sizeof(u64) * num_elements);
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite raii = "vec2_raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
ignore = vec2 {};
|
|
||||||
ignore = vec2 { 2.0 };
|
|
||||||
ignore = vec2 { 2.0, 4.0 };
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
for (auto idx : std::views::iota(0, 1'000'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
ignore = vec2 {};
|
|
||||||
ignore = vec2 { 2.0 };
|
|
||||||
ignore = vec2 { 2.0, 4.0 };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post default construct has correct state" } = [] {
|
|
||||||
const auto vec = vec2 {};
|
|
||||||
expect_eq(vec.x, 0.0);
|
|
||||||
expect_eq(vec.y, 0.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post scalar construct has correct state" } = [] {
|
|
||||||
const auto vec = vec2 { 2.0 };
|
|
||||||
expect_eq(vec.x, 2.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,y has correct state" } = [] {
|
|
||||||
const auto vec = vec2 { 2.0, 3.0 };
|
|
||||||
expect_eq(vec.x, 2.0);
|
|
||||||
expect_eq(vec.y, 3.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite arithmetic_operators = "vec2_operators"_suite = [] {
|
|
||||||
Case { "operator ==" } = [] {
|
|
||||||
const auto lhs = vec2 { 1.0, 2.0 };
|
|
||||||
|
|
||||||
expect_false(lhs == vec2 { {}, 2.0 });
|
|
||||||
expect_false(lhs == vec2 { 1.0, {} });
|
|
||||||
expect_true(lhs == vec2 { 1.0, 2.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator !=" } = [] {
|
|
||||||
const auto lhs = vec2 { 1.0, 2.0 };
|
|
||||||
|
|
||||||
expect_true(lhs != vec2 { {}, 2.0 });
|
|
||||||
expect_true(lhs != vec2 { 1.0, {} });
|
|
||||||
expect_false(lhs != vec2 { 1.0, 2.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator +" } = [] {
|
|
||||||
const auto lhs = vec2 { 2.0, 3.0 };
|
|
||||||
const auto rhs = vec2 { 4.0, 5.0 };
|
|
||||||
expect_eq(lhs + rhs, vec2 { 6.0, 8.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator -" } = [] {
|
|
||||||
const auto lhs = vec2 { 2.0, 3.0 };
|
|
||||||
const auto rhs = vec2 { 4.0, 6.0 };
|
|
||||||
expect_eq(lhs - rhs, vec2 { -2.0, -3.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator *" } = [] {
|
|
||||||
const auto lhs = vec2 { 2.0, 3.0 };
|
|
||||||
const auto rhs = vec2 { 10.0, 20.0 };
|
|
||||||
expect_eq(lhs * rhs, vec2 { 20.0, 60.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator /" } = [] {
|
|
||||||
const auto lhs = vec2 { 10.0, 20.0 };
|
|
||||||
const auto rhs = vec2 { 2.0, 20.0 };
|
|
||||||
expect_eq(lhs / rhs, vec2 { 5.0, 1.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator []" } = [] {
|
|
||||||
auto vec = vec2 { 0.0, 1.0 };
|
|
||||||
expect_eq(vec[0], 0.0);
|
|
||||||
expect_eq(vec[1], 1.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator [] const" } = [] {
|
|
||||||
const auto vec = vec2 { 0.0, 1.0 };
|
|
||||||
expect_eq(vec[0], 0.0);
|
|
||||||
expect_eq(vec[1], 1.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite utilities = "vec2_utilities"_suite = [] {
|
|
||||||
Case { "std::format float" } = [] {
|
|
||||||
auto str = std::format("{}", vec2 { 10.0000f, 30.0005f });
|
|
||||||
expect_eq(str, "10, 30.0005");
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "std::format int" } = [] {
|
|
||||||
auto str = std::format("{}", ivec2 { 10, 30 });
|
|
||||||
expect_eq(str, "10, 30");
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,136 +0,0 @@
|
||||||
export module math.vec3;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import math.vec2;
|
|
||||||
|
|
||||||
export namespace lt::math {
|
|
||||||
|
|
||||||
template<typename T = f32>
|
|
||||||
requires(std::is_arithmetic_v<T>)
|
|
||||||
struct vec3_impl
|
|
||||||
{
|
|
||||||
using Underlying_T = T;
|
|
||||||
|
|
||||||
static constexpr auto num_elements = 3u;
|
|
||||||
|
|
||||||
constexpr vec3_impl(): x(), y(), z()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr explicit vec3_impl(T scalar): x(scalar), y(scalar), z(scalar)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec3_impl(T x, T y, T z): x(x), y(y), z(z)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec3_impl(vec2_impl<T> xy, T z): x(xy.x), y(xy.y), z(z)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec3_impl(T x, vec2_impl<T> yz): x(x), y(yz.x), z(yz.y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator==(const vec3_impl<T> &other) const -> bool
|
|
||||||
{
|
|
||||||
return x == other.x && y == other.y && z == other.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator!=(const vec3_impl<T> &other) const -> bool
|
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator+(const vec3_impl<T> &other) const -> vec3_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x + other.x,
|
|
||||||
y + other.y,
|
|
||||||
z + other.z,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator-(const vec3_impl<T> &other) const -> vec3_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x - other.x,
|
|
||||||
y - other.y,
|
|
||||||
z - other.z,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator*(const vec3_impl<T> &other) const -> vec3_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x * other.x,
|
|
||||||
y * other.y,
|
|
||||||
z * other.z,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator/(const vec3_impl<T> &other) const -> vec3_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x / other.x,
|
|
||||||
y / other.y,
|
|
||||||
z / other.z,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](u8 idx) -> T &
|
|
||||||
{
|
|
||||||
debug_check(idx < num_elements, "vec3 out of bound access: {}", idx);
|
|
||||||
return ((T *)this)[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](u8 idx) const -> const T &
|
|
||||||
{
|
|
||||||
debug_check(idx < num_elements, "vec3 out of bound access: {}", idx);
|
|
||||||
return ((T *)this)[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
friend auto operator<<(std::ostream &stream, vec3_impl<T> value) -> std::ostream &
|
|
||||||
{
|
|
||||||
stream << value.x << ", " << value.y << ", " << value.z;
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
T x;
|
|
||||||
|
|
||||||
T y;
|
|
||||||
|
|
||||||
T z;
|
|
||||||
};
|
|
||||||
|
|
||||||
using vec3 = vec3_impl<f32>;
|
|
||||||
|
|
||||||
using vec3_f32 = vec3;
|
|
||||||
using vec3_f64 = vec3_impl<f64>;
|
|
||||||
|
|
||||||
using vec3_i8 = vec3_impl<i8>;
|
|
||||||
using vec3_i16 = vec3_impl<i16>;
|
|
||||||
using vec3_i32 = vec3_impl<i32>;
|
|
||||||
using vec3_i64 = vec3_impl<i64>;
|
|
||||||
|
|
||||||
using vec3_u8 = vec3_impl<u8>;
|
|
||||||
using vec3_u16 = vec3_impl<u16>;
|
|
||||||
using vec3_u32 = vec3_impl<u32>;
|
|
||||||
using vec3_u64 = vec3_impl<u64>;
|
|
||||||
|
|
||||||
} // namespace lt::math
|
|
||||||
|
|
||||||
export template<typename T>
|
|
||||||
struct std::formatter<lt::math::vec3_impl<T>>
|
|
||||||
{
|
|
||||||
constexpr auto parse(std::format_parse_context &context)
|
|
||||||
{
|
|
||||||
return context.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto format(const lt::math::vec3_impl<T> &val, std::format_context &context) const
|
|
||||||
{
|
|
||||||
return std::format_to(context.out(), "{}, {}, {}", val.x, val.y, val.z);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
import test;
|
|
||||||
import math.vec2;
|
|
||||||
import math.vec3;
|
|
||||||
|
|
||||||
using vec2 = ::lt::math::vec2;
|
|
||||||
using vec3 = ::lt::math::vec3;
|
|
||||||
using ivec3 = ::lt::math::vec3_i32;
|
|
||||||
|
|
||||||
Suite static_tests = "vec3_static_checks"_suite = [] {
|
|
||||||
constexpr auto num_elements = lt::math::vec3::num_elements;
|
|
||||||
|
|
||||||
static_assert(num_elements == 3u);
|
|
||||||
static_assert(std::is_same_v<lt::math::vec3, lt::math::vec3_f32>);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec3_f32) == sizeof(f32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec3_f64) == sizeof(f64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec3_i8) == sizeof(i8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec3_i16) == sizeof(i16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec3_i32) == sizeof(i32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec3_i64) == sizeof(i64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec3_u8) == sizeof(u8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec3_u16) == sizeof(u16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec3_u32) == sizeof(u32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec3_u64) == sizeof(u64) * num_elements);
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite raii = "vec3_raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
ignore = vec3 {};
|
|
||||||
ignore = vec3 { 2.0 };
|
|
||||||
ignore = vec3 { 2.0, 4.0, 6.0 };
|
|
||||||
ignore = vec3 { vec2 { 2.0, 4.0 }, 6.0 };
|
|
||||||
ignore = vec3 { 2.0, vec2 { 4.0, 6.0 } };
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
for (auto idx : std::views::iota(0, 1'000'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
ignore = vec3 {};
|
|
||||||
ignore = vec3 { 2.0 };
|
|
||||||
ignore = vec3 { 2.0, 4.0, 6.0 };
|
|
||||||
ignore = vec3 { vec2 { 2.0, 4.0 }, 6.0 };
|
|
||||||
ignore = vec3 { 2.0, vec2 { 4.0, 6.0 } };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post default construct has correct state" } = [] {
|
|
||||||
const auto vec = vec3 {};
|
|
||||||
expect_eq(vec.x, 0.0);
|
|
||||||
expect_eq(vec.y, 0.0);
|
|
||||||
expect_eq(vec.z, 0.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post scalar construct has correct state" } = [] {
|
|
||||||
const auto vec = vec3 { 2.0 };
|
|
||||||
expect_eq(vec.x, 2.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 2.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,y,z has correct state" } = [] {
|
|
||||||
const auto vec = vec3 { 1.0, 2.0, 3.0 };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.y, 3.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with xy,z has correct state" } = [] {
|
|
||||||
const auto vec = vec3 { vec2 { 1.0, 2.0 }, 3.0 };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,yz has correct state" } = [] {
|
|
||||||
const auto vec = vec3 { 1.0, vec2 { 2.0, 3.0 } };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite arithmetic_operators = "vec3_operators"_suite = [] {
|
|
||||||
Case { "operator ==" } = [] {
|
|
||||||
const auto lhs = vec3 { 1.0, 2.0, 3.0 };
|
|
||||||
|
|
||||||
expect_false(lhs == vec3 { {}, 2.0, 3.0 });
|
|
||||||
expect_false(lhs == vec3 { 1.0, {}, 3.0 });
|
|
||||||
expect_false(lhs == vec3 { 1.0, 2.0, {} });
|
|
||||||
expect_true(lhs == vec3 { 1.0, 2.0, 3.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator !=" } = [] {
|
|
||||||
const auto lhs = vec3 { 1.0, 2.0, 3.0 };
|
|
||||||
|
|
||||||
expect_true(lhs != vec3 { {}, 2.0, 3.0 });
|
|
||||||
expect_true(lhs != vec3 { 1.0, {}, 3.0 });
|
|
||||||
expect_true(lhs != vec3 { 1.0, 2.0, {} });
|
|
||||||
expect_false(lhs != vec3 { 1.0, 2.0, 3.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator +" } = [] {
|
|
||||||
const auto lhs = vec3 { 1.0, 2.0, 3.0 };
|
|
||||||
const auto rhs = vec3 { 4.0, 5.0, 6.0 };
|
|
||||||
expect_eq(lhs + rhs, vec3 { 5.0, 7.0, 9.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator -" } = [] {
|
|
||||||
const auto lhs = vec3 { 1.0, 2.0, 3.0 };
|
|
||||||
const auto rhs = vec3 { 4.0, 5.0, 7.0 };
|
|
||||||
expect_eq(lhs - rhs, vec3 { -2.0, -3.0, -4.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator *" } = [] {
|
|
||||||
const auto lhs = vec3 { 1.0, 2.0, 3.0 };
|
|
||||||
const auto rhs = vec3 { 4.0, 5.0, 6.0 };
|
|
||||||
expect_eq(lhs * rhs, vec3 { 4.0, 10.0, 18.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator /" } = [] {
|
|
||||||
const auto lhs = vec3 { 4.0, 10.0, 30.0 };
|
|
||||||
const auto rhs = vec3 { 1.0, 2.0, 5.0 };
|
|
||||||
expect_eq(lhs / rhs, vec3 { 4.0, 5.0, 6.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator []" } = [] {
|
|
||||||
auto vec = vec3 { 0.0, 1.0, 2.0 };
|
|
||||||
expect_eq(vec[0], 0.0);
|
|
||||||
expect_eq(vec[1], 1.0);
|
|
||||||
expect_eq(vec[2], 2.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator [] const" } = [] {
|
|
||||||
const auto vec = vec3 { 0.0, 1.0, 2.0 };
|
|
||||||
expect_eq(vec[0], 0.0);
|
|
||||||
expect_eq(vec[1], 1.0);
|
|
||||||
expect_eq(vec[2], 2.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite utilities = "vec3_utilities"_suite = [] {
|
|
||||||
Case { "std::format float" } = [] {
|
|
||||||
auto str = std::format("{}", vec3 { 10.0000f, 30.0005f, 40.00005f });
|
|
||||||
expect_eq(str, "10, 30.0005, 40.00005");
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "std::format int" } = [] {
|
|
||||||
auto str = std::format("{}", ivec3 { 10, 30, 3'000'000 });
|
|
||||||
expect_eq(str, "10, 30, 3000000");
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,159 +0,0 @@
|
||||||
export module math.vec4;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import math.vec2;
|
|
||||||
import math.vec3;
|
|
||||||
|
|
||||||
export namespace lt::math {
|
|
||||||
|
|
||||||
template<typename T = f32>
|
|
||||||
requires(std::is_arithmetic_v<T>)
|
|
||||||
struct vec4_impl
|
|
||||||
{
|
|
||||||
using Underlying_T = T;
|
|
||||||
|
|
||||||
static constexpr auto num_elements = 4u;
|
|
||||||
|
|
||||||
constexpr vec4_impl(): x(), y(), z(), w()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr explicit vec4_impl(T scalar): x(scalar), y(scalar), z(scalar), w(scalar)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec4_impl(T x, T y, T z, T w): x(x), y(y), z(z), w(w)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec4_impl(vec2_impl<T> xy, T z, T w): x(xy.x), y(xy.y), z(z), w(w)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec4_impl(T x, vec2_impl<T> yz, T w): x(x), y(yz.x), z(yz.y), w(w)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec4_impl(T x, T y, vec2_impl<T> zw): x(x), y(y), z(zw.x), w(zw.y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec4_impl(vec2_impl<T> xy, vec2_impl<T> zw): x(xy.x), y(xy.y), z(zw.x), w(zw.y)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec4_impl(vec3_impl<T> xyz, T w): x(xyz.x), y(xyz.y), z(xyz.z), w(w)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr vec4_impl(T x, vec3_impl<T> yzw): x(x), y(yzw.x), z(yzw.y), w(yzw.z)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator==(const vec4_impl<T> &other) const -> bool
|
|
||||||
{
|
|
||||||
return x == other.x && y == other.y && z == other.z && w == other.w;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator!=(const vec4_impl<T> &other) const -> bool
|
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator+(const vec4_impl<T> &other) const -> vec4_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x + other.x,
|
|
||||||
y + other.y,
|
|
||||||
z + other.z,
|
|
||||||
w + other.w,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator-(const vec4_impl<T> &other) const -> vec4_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x - other.x,
|
|
||||||
y - other.y,
|
|
||||||
z - other.z,
|
|
||||||
w - other.w,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator*(const vec4_impl<T> &other) const -> vec4_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x * other.x,
|
|
||||||
y * other.y,
|
|
||||||
z * other.z,
|
|
||||||
w * other.w,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator/(const vec4_impl<T> &other) const -> vec4_impl
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
x / other.x,
|
|
||||||
y / other.y,
|
|
||||||
z / other.z,
|
|
||||||
w / other.w,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](u8 idx) -> T &
|
|
||||||
{
|
|
||||||
debug_check(idx < num_elements, "vec4 out of bound access: {}", idx);
|
|
||||||
return ((T *)this)[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr auto operator[](u8 idx) const -> const T &
|
|
||||||
{
|
|
||||||
debug_check(idx < num_elements, "vec4 out of bound access: {}", idx);
|
|
||||||
return ((T *)this)[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
friend auto operator<<(std::ostream &stream, vec4_impl<T> value) -> std::ostream &
|
|
||||||
{
|
|
||||||
stream << value.x << ", " << value.y << ", " << value.z << ", " << value.w;
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
T x;
|
|
||||||
|
|
||||||
T y;
|
|
||||||
|
|
||||||
T z;
|
|
||||||
|
|
||||||
T w;
|
|
||||||
};
|
|
||||||
|
|
||||||
using vec4 = vec4_impl<f32>;
|
|
||||||
|
|
||||||
using vec4_f32 = vec4;
|
|
||||||
using vec4_f64 = vec4_impl<f64>;
|
|
||||||
|
|
||||||
using vec4_i8 = vec4_impl<i8>;
|
|
||||||
using vec4_i16 = vec4_impl<i16>;
|
|
||||||
using vec4_i32 = vec4_impl<i32>;
|
|
||||||
using vec4_i64 = vec4_impl<i64>;
|
|
||||||
|
|
||||||
using vec4_u8 = vec4_impl<u8>;
|
|
||||||
using vec4_u16 = vec4_impl<u16>;
|
|
||||||
using vec4_u32 = vec4_impl<u32>;
|
|
||||||
using vec4_u64 = vec4_impl<u64>;
|
|
||||||
|
|
||||||
} // namespace lt::math
|
|
||||||
|
|
||||||
export template<typename T>
|
|
||||||
struct std::formatter<lt::math::vec4_impl<T>>
|
|
||||||
{
|
|
||||||
constexpr auto parse(std::format_parse_context &context)
|
|
||||||
{
|
|
||||||
return context.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto format(const lt::math::vec4_impl<T> &val, std::format_context &context) const
|
|
||||||
{
|
|
||||||
return std::format_to(context.out(), "{}, {}, {}, {}", val.x, val.y, val.z, val.w);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,215 +0,0 @@
|
||||||
import test;
|
|
||||||
import math.vec2;
|
|
||||||
import math.vec3;
|
|
||||||
import math.vec4;
|
|
||||||
import logger;
|
|
||||||
|
|
||||||
using vec2 = ::lt::math::vec2;
|
|
||||||
using vec3 = ::lt::math::vec3;
|
|
||||||
using vec4 = ::lt::math::vec4;
|
|
||||||
using ivec4 = ::lt::math::vec4_i32;
|
|
||||||
|
|
||||||
Suite static_tests = "vec4_static_checks"_suite = [] {
|
|
||||||
constexpr auto num_elements = lt::math::vec4::num_elements;
|
|
||||||
|
|
||||||
static_assert(num_elements == 4u);
|
|
||||||
static_assert(std::is_same_v<lt::math::vec4, lt::math::vec4_f32>);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec4_f32) == sizeof(f32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec4_f64) == sizeof(f64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec4_i8) == sizeof(i8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec4_i16) == sizeof(i16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec4_i32) == sizeof(i32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec4_i64) == sizeof(i64) * num_elements);
|
|
||||||
|
|
||||||
static_assert(sizeof(lt::math::vec4_u8) == sizeof(u8) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec4_u16) == sizeof(u16) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec4_u32) == sizeof(u32) * num_elements);
|
|
||||||
static_assert(sizeof(lt::math::vec4_u64) == sizeof(u64) * num_elements);
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite raii = "vec4_raii"_suite = [] {
|
|
||||||
Case { "happy paths" } = [] {
|
|
||||||
ignore = vec4 {};
|
|
||||||
ignore = vec4 { 2.0 };
|
|
||||||
ignore = vec4 { 2.0, 4.0, 6.0, 8.0 };
|
|
||||||
ignore = vec4 { vec2 { 2.0, 4.0 }, 6.0, 8.0 };
|
|
||||||
ignore = vec4 { 2.0, 4.0, vec2 { 6.0, 8.0 } };
|
|
||||||
ignore = vec4 { vec2 { 2.0, 4.0 }, vec2 { 6.0, 8.0 } };
|
|
||||||
ignore = vec4 { vec3 { 2.0, 4.0, 6.0 }, 8.0 };
|
|
||||||
ignore = vec4 { 2.0, vec3 { 4.0, 6.0, 8.0 } };
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "unhappy paths" } = [] {
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "many" } = [] {
|
|
||||||
for (auto idx : std::views::iota(0, 1'000'000))
|
|
||||||
{
|
|
||||||
ignore = idx;
|
|
||||||
ignore = vec4 {};
|
|
||||||
ignore = vec4 { 2.0 };
|
|
||||||
ignore = vec4 { 2.0, 4.0, 6.0, 8.0 };
|
|
||||||
ignore = vec4 { vec2 { 2.0, 4.0 }, 6.0, 8.0 };
|
|
||||||
ignore = vec4 { 2.0, 4.0, vec2 { 6.0, 8.0 } };
|
|
||||||
ignore = vec4 { vec2 { 2.0, 4.0 }, vec2 { 6.0, 8.0 } };
|
|
||||||
ignore = vec4 { vec3 { 2.0, 4.0, 6.0 }, 8.0 };
|
|
||||||
ignore = vec4 { 2.0, vec3 { 4.0, 6.0, 8.0 } };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post default construct has correct state" } = [] {
|
|
||||||
const auto vec = vec4 {};
|
|
||||||
expect_eq(vec.x, 0.0);
|
|
||||||
expect_eq(vec.y, 0.0);
|
|
||||||
expect_eq(vec.z, 0.0);
|
|
||||||
expect_eq(vec.w, 0.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post scalar construct has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { 2.0 };
|
|
||||||
expect_eq(vec.x, 2.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 2.0);
|
|
||||||
expect_eq(vec.w, 2.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,y,z,w has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { 1.0, 2.0, 3.0, 4.0 };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.y, 3.0);
|
|
||||||
expect_eq(vec.z, 4.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with xy,z,w has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { vec2 { 1.0, 2.0 }, 3.0, 4.0 };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
expect_eq(vec.w, 4.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,y,zw has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { 1.0, 2.0, vec2 { 3.0, 4.0 } };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
expect_eq(vec.w, 4.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,yz,w has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { 1.0, vec2 { 2.0, 3.0 }, 4.0 };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
expect_eq(vec.w, 4.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,y,zw has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { 1.0, 2.0, vec2 { 3.0, 4.0 } };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
expect_eq(vec.w, 4.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with xy,zw has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { vec2 { 1.0, 2.0 }, vec2 { 3.0, 4.0 } };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
expect_eq(vec.w, 4.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with xyz,w has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { vec3 { 1.0, 2.0, 3.0 }, 4.0 };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
expect_eq(vec.w, 4.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "post construct with x,yzw has correct state" } = [] {
|
|
||||||
const auto vec = vec4 { 1.0, vec3 { 2.0, 3.0, 4.0 } };
|
|
||||||
expect_eq(vec.x, 1.0);
|
|
||||||
expect_eq(vec.y, 2.0);
|
|
||||||
expect_eq(vec.z, 3.0);
|
|
||||||
expect_eq(vec.w, 4.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite arithmetic_operators = "vec4_operators"_suite = [] {
|
|
||||||
Case { "operator ==" } = [] {
|
|
||||||
const auto lhs = vec4 { 1.0, 2.0, 3.0, 4.0 };
|
|
||||||
|
|
||||||
expect_false(lhs == vec4 { {}, 2.0, 3.0, 4.0 });
|
|
||||||
expect_false(lhs == vec4 { 1.0, {}, 3.0, 4.0 });
|
|
||||||
expect_false(lhs == vec4 { 1.0, 2.0, {}, 4.0 });
|
|
||||||
expect_false(lhs == vec4 { 1.0, 2.0, 3.0, {} });
|
|
||||||
expect_true(lhs == vec4 { 1.0, 2.0, 3.0, 4.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator !=" } = [] {
|
|
||||||
const auto lhs = vec4 { 1.0, 2.0, 3.0, 4.0 };
|
|
||||||
|
|
||||||
expect_true(lhs != vec4 { {}, 2.0, 3.0, 4.0 });
|
|
||||||
expect_true(lhs != vec4 { 1.0, {}, 3.0, 4.0 });
|
|
||||||
expect_true(lhs != vec4 { 1.0, 2.0, {}, 4.0 });
|
|
||||||
expect_true(lhs != vec4 { 1.0, 2.0, 3.0, {} });
|
|
||||||
expect_false(lhs != vec4 { 1.0, 2.0, 3.0, 4.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator +" } = [] {
|
|
||||||
const auto lhs = vec4 { 1.0, 2.0, 3.0, 4.0 };
|
|
||||||
const auto rhs = vec4 { 5.0, 6.0, 7.0, 8.0 };
|
|
||||||
expect_eq(lhs + rhs, vec4 { 6.0, 8.0, 10.0, 12.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator -" } = [] {
|
|
||||||
const auto lhs = vec4 { 1.0, 2.0, 3.0, 4.0 };
|
|
||||||
const auto rhs = vec4 { 5.0, 10.0, 15.0, 20.0 };
|
|
||||||
expect_eq(lhs - rhs, vec4 { -4.0, -8.0, -12.0, -16.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator *" } = [] {
|
|
||||||
const auto lhs = vec4 { 1.0, 2.0, 3.0, 4.0 };
|
|
||||||
const auto rhs = vec4 { 5.0, 6.0, 7.0, 8.0 };
|
|
||||||
expect_eq(lhs * rhs, vec4 { 5.0, 12.0, 21.0, 32.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator /" } = [] {
|
|
||||||
const auto lhs = vec4 { 5.0, 6.0, 30.0, 8.0 };
|
|
||||||
const auto rhs = vec4 { 1.0, 2.0, 3.0, 4.0 };
|
|
||||||
expect_eq(lhs / rhs, vec4 { 5.0, 3.0, 10.0, 2.0 });
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator []" } = [] {
|
|
||||||
auto vec = vec4 { 0.0, 1.0, 2.0, 3.0 };
|
|
||||||
expect_eq(vec[0], 0.0);
|
|
||||||
expect_eq(vec[1], 1.0);
|
|
||||||
expect_eq(vec[2], 2.0);
|
|
||||||
expect_eq(vec[3], 3.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "operator [] const" } = [] {
|
|
||||||
const auto vec = vec4 { 0.0, 1.0, 2.0, 3.0 };
|
|
||||||
expect_eq(vec[0], 0.0);
|
|
||||||
expect_eq(vec[1], 1.0);
|
|
||||||
expect_eq(vec[2], 2.0);
|
|
||||||
expect_eq(vec[3], 3.0);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Suite utilities = "vec4_utilities"_suite = [] {
|
|
||||||
Case { "std::format float" } = [] {
|
|
||||||
auto str = std::format("{}", vec4 { 10.0000f, 30.0005f, 40.00005f, 0.0 });
|
|
||||||
expect_eq(str, "10, 30.0005, 40.00005, 0");
|
|
||||||
};
|
|
||||||
|
|
||||||
Case { "std::format int" } = [] {
|
|
||||||
auto str = std::format("{}", ivec4 { 10, 30, 3'000'000, 13 });
|
|
||||||
expect_eq(str, "10, 30, 3000000, 13");
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
export module memory.null_on_move;
|
|
||||||
|
|
||||||
import logger;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
namespace lt::memory {
|
|
||||||
|
|
||||||
/** Holds an `Underlying_T`, assigns it to `null_value` when this object is moved.
|
|
||||||
*
|
|
||||||
* @note For avoiding the need to explicitly implement the move constructor for objects that hold
|
|
||||||
* non-raii-handles (eg. Vulkan, Wayland).
|
|
||||||
*/
|
|
||||||
export template<typename Underlying_T, Underlying_T null_value = nullptr>
|
|
||||||
class NullOnMove
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NullOnMove() = default;
|
|
||||||
|
|
||||||
NullOnMove(Underlying_T value): m_value(value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~NullOnMove() = default;
|
|
||||||
|
|
||||||
NullOnMove(const NullOnMove &) = delete;
|
|
||||||
|
|
||||||
auto operator=(const NullOnMove &) -> NullOnMove & = delete;
|
|
||||||
|
|
||||||
NullOnMove(NullOnMove &&other) noexcept
|
|
||||||
{
|
|
||||||
*this = std::move(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto operator=(NullOnMove &&other) noexcept -> NullOnMove &
|
|
||||||
{
|
|
||||||
if (this == std::addressof(other))
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_value = other.m_value;
|
|
||||||
other.m_value = null_value;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto operator->() -> Underlying_T
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOLINTNEXTLINE
|
|
||||||
auto operator->() const -> const Underlying_T
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto operator&() const -> const Underlying_T *
|
|
||||||
{
|
|
||||||
return &m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto operator&() -> Underlying_T *
|
|
||||||
{
|
|
||||||
return &m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator bool() const
|
|
||||||
{
|
|
||||||
return m_value != null_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator Underlying_T() const
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator Underlying_T()
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get() -> Underlying_T &
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get() const -> const Underlying_T &
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Underlying_T m_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::memory
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
export module memory.reference;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
namespace lt::memory {
|
|
||||||
|
|
||||||
/** Wrapper around std::shared_ptr.
|
|
||||||
*
|
|
||||||
* @note Currently just an alias, might turn into an implementation later.
|
|
||||||
* @ref https://en.cppreference.com/w/cpp/memory/shared_ptr.html
|
|
||||||
*/
|
|
||||||
export template<typename T>
|
|
||||||
using Ref = std::shared_ptr<T>;
|
|
||||||
|
|
||||||
/** Allocates memory for an `Underlying_T` and directly constructs it there.
|
|
||||||
*
|
|
||||||
* @return A Ref<Underlying_T> to the constructed object.
|
|
||||||
*/
|
|
||||||
export template<typename Underlying_T, typename... Args>
|
|
||||||
constexpr Ref<Underlying_T> create_ref(Args &&...args)
|
|
||||||
{
|
|
||||||
return std::make_shared<Underlying_T>(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Converts c-style pointer of type `Underlying_T` to a `Ref<Underlying_T>`. */
|
|
||||||
export template<typename Underlying_T>
|
|
||||||
constexpr Ref<Underlying_T> make_ref(Underlying_T *raw_pointer)
|
|
||||||
{
|
|
||||||
return Ref<Underlying_T>(raw_pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::memory
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
export module memory.scope;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
|
|
||||||
namespace lt::memory {
|
|
||||||
|
|
||||||
/** @brief Wrapper around std::unique_ptr.
|
|
||||||
*
|
|
||||||
* @note Currently just an alias, might turn into an implementation later.
|
|
||||||
* @ref https://en.cppreference.com/w/cpp/memory/unique_ptr.html
|
|
||||||
*/
|
|
||||||
export template<typename t>
|
|
||||||
using Scope = std::unique_ptr<t>;
|
|
||||||
|
|
||||||
/** Allocates memory for an `Underlying_T` and directly constructs it there.
|
|
||||||
*
|
|
||||||
* @return A Scope<Underlying_T> to the constructed object.
|
|
||||||
*/
|
|
||||||
export template<typename Underlying_T, typename... Args>
|
|
||||||
constexpr Scope<Underlying_T> create_scope(Args &&...args)
|
|
||||||
{
|
|
||||||
return std::make_unique<Underlying_T>(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Converts c-style pointer of type `Underlying_T` to a `Scope<Underlying_T>`. */
|
|
||||||
export template<typename Underlying_T>
|
|
||||||
constexpr Scope<Underlying_T> make_scope(Underlying_T *raw_pointer)
|
|
||||||
{
|
|
||||||
return Scope<Underlying_T>(raw_pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::memory
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
import app;
|
|
||||||
import app.system;
|
|
||||||
import std;
|
|
||||||
import logger;
|
|
||||||
import memory.scope;
|
|
||||||
import mirror.system;
|
|
||||||
import renderer.factory;
|
|
||||||
|
|
||||||
/** The ultimate entrypoint. */
|
|
||||||
auto main(i32 argc, char *argv[]) -> i32
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ignore = argc;
|
|
||||||
ignore = argv;
|
|
||||||
|
|
||||||
auto application = lt::memory::create_scope<lt::Mirror>();
|
|
||||||
if (!application)
|
|
||||||
{
|
|
||||||
throw std::runtime_error { "Failed to create application\n" };
|
|
||||||
}
|
|
||||||
|
|
||||||
application->game_loop();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
catch (const std::exception &exp)
|
|
||||||
{
|
|
||||||
lt::log::critical("Terminating due to uncaught exception:");
|
|
||||||
lt::log::critical("\texception.what(): {}", exp.what());
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,298 +0,0 @@
|
||||||
export module mirror.system;
|
|
||||||
|
|
||||||
import preliminary;
|
|
||||||
import math.vec3;
|
|
||||||
import camera.components;
|
|
||||||
import surface.requests;
|
|
||||||
import logger;
|
|
||||||
import surface.system;
|
|
||||||
import math.vec2;
|
|
||||||
import math.vec4;
|
|
||||||
import math.trig;
|
|
||||||
import input.codes;
|
|
||||||
import input.events;
|
|
||||||
import input.system;
|
|
||||||
import math.components;
|
|
||||||
import memory.reference;
|
|
||||||
import memory.scope;
|
|
||||||
import renderer.components;
|
|
||||||
import renderer.system;
|
|
||||||
import renderer.frontend;
|
|
||||||
import surface.events;
|
|
||||||
import time;
|
|
||||||
import app;
|
|
||||||
import app.system;
|
|
||||||
import ecs.entity;
|
|
||||||
import ecs.registry;
|
|
||||||
|
|
||||||
namespace lt {
|
|
||||||
|
|
||||||
void renderer_callback(
|
|
||||||
renderer::IDebugger::MessageSeverity message_severity,
|
|
||||||
renderer::IDebugger::MessageType message_type,
|
|
||||||
renderer::IDebugger::MessageData data,
|
|
||||||
std::any &user_data
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ignore = message_severity;
|
|
||||||
ignore = message_type;
|
|
||||||
ignore = user_data;
|
|
||||||
|
|
||||||
log::trace("< Renderer > ==> {}", std::string { data.message });
|
|
||||||
}
|
|
||||||
|
|
||||||
class MirrorSystem: public lt::app::ISystem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MirrorSystem(
|
|
||||||
memory::Ref<ecs::Registry> registry,
|
|
||||||
size_t quit_action_key,
|
|
||||||
std::array<size_t, 4ul> debug_action_keys
|
|
||||||
)
|
|
||||||
: m_registry(std::move(registry))
|
|
||||||
, m_quit_action_key(quit_action_key)
|
|
||||||
, m_debug_action_keys(debug_action_keys)
|
|
||||||
{
|
|
||||||
using Surface = lt::surface::SurfaceComponent;
|
|
||||||
|
|
||||||
|
|
||||||
using Input = lt::input::InputComponent;
|
|
||||||
|
|
||||||
for (auto &[entity, surface, input] : m_registry->view<Surface, Input>())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tick(app::TickInfo tick) override
|
|
||||||
{
|
|
||||||
using Surface = lt::surface::SurfaceComponent;
|
|
||||||
using Input = lt::input::InputComponent;
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds { 10 });
|
|
||||||
auto should_quit = false;
|
|
||||||
for (auto &[entity, surface, input] : m_registry->view<Surface, Input>())
|
|
||||||
{
|
|
||||||
using State = lt::input::InputAction::State;
|
|
||||||
const auto &[x, y] = surface.get_position();
|
|
||||||
const auto &[width, height] = surface.get_resolution();
|
|
||||||
|
|
||||||
if (input.get_action(m_quit_action_key).state == State::active)
|
|
||||||
{
|
|
||||||
should_quit = true;
|
|
||||||
}
|
|
||||||
if (input.get_action(m_debug_action_keys[0]).state == State::active)
|
|
||||||
{
|
|
||||||
for (auto &[id, camera] :
|
|
||||||
m_registry->view<lt::camera::components::PerspectiveCamera>())
|
|
||||||
{
|
|
||||||
camera.vertical_fov += (static_cast<f32>(tick.delta_time.count()) * 40.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.get_action(m_debug_action_keys[1]).state == State::active)
|
|
||||||
{
|
|
||||||
surface.push_request(surface::ModifyPositionRequest({ x - 5, y - 5 }));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.get_action(m_debug_action_keys[2]).state == State::active)
|
|
||||||
{
|
|
||||||
surface.push_request(surface::ModifyResolutionRequest({ width + 5, height + 5 }));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.get_action(m_debug_action_keys[3]).state == State::active)
|
|
||||||
{
|
|
||||||
surface.push_request(surface::ModifyResolutionRequest({ width - 5, height - 5 }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto now = std::chrono::steady_clock::now();
|
|
||||||
m_last_tick_result = app::TickResult {
|
|
||||||
.info = tick,
|
|
||||||
.duration = now - tick.start_time,
|
|
||||||
.end_time = now,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_register() override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_unregister() override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_last_tick_result() const -> const app::TickResult & override
|
|
||||||
{
|
|
||||||
return m_last_tick_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
memory::Ref<ecs::Registry> m_registry;
|
|
||||||
|
|
||||||
size_t m_quit_action_key;
|
|
||||||
|
|
||||||
std::array<size_t, 4ul> m_debug_action_keys {};
|
|
||||||
|
|
||||||
app::TickResult m_last_tick_result {};
|
|
||||||
};
|
|
||||||
|
|
||||||
export class Mirror: public app::Application
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Mirror()
|
|
||||||
{
|
|
||||||
m_editor_registry = memory::create_ref<ecs::Registry>();
|
|
||||||
|
|
||||||
setup_window_system();
|
|
||||||
setup_input_system();
|
|
||||||
|
|
||||||
register_systems();
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_window_close()
|
|
||||||
{
|
|
||||||
log::info("Window close requested...");
|
|
||||||
|
|
||||||
unregister_system(m_input_system);
|
|
||||||
unregister_system(m_surface_system);
|
|
||||||
unregister_system(m_renderer_system);
|
|
||||||
unregister_system(m_mirror_system);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup_window_system()
|
|
||||||
{
|
|
||||||
using lt::input::InputComponent;
|
|
||||||
using lt::surface::SurfaceComponent;
|
|
||||||
m_surface_system = memory::create_ref<lt::surface::System>(m_editor_registry);
|
|
||||||
|
|
||||||
m_window = m_editor_registry->create_entity();
|
|
||||||
m_surface_system->create_surface_component(
|
|
||||||
m_window,
|
|
||||||
SurfaceComponent::CreateInfo {
|
|
||||||
.title = "Editor Window",
|
|
||||||
.resolution = { 400u, 400u },
|
|
||||||
.vsync = true,
|
|
||||||
.visible = true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
auto &input = m_editor_registry->add<InputComponent>(m_window, {});
|
|
||||||
auto quit_action_key = input.add_action(
|
|
||||||
input::InputAction {
|
|
||||||
.name = "quit",
|
|
||||||
.trigger = input::Trigger { .mapped_keycode = Key::q },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
auto debug_action_keys = std::array<size_t, 4ul> {};
|
|
||||||
debug_action_keys[0] = input.add_action(
|
|
||||||
input::InputAction {
|
|
||||||
.name = "debug_1",
|
|
||||||
.trigger = input::Trigger { .mapped_keycode = Key::digit_1 },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
debug_action_keys[1] = input.add_action(
|
|
||||||
input::InputAction {
|
|
||||||
.name = "debug_2",
|
|
||||||
.trigger = input::Trigger { .mapped_keycode = Key::digit_2 },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
debug_action_keys[2] = input.add_action(
|
|
||||||
input::InputAction {
|
|
||||||
.name = "debug_3",
|
|
||||||
.trigger = input::Trigger { .mapped_keycode = Key::digit_3 },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
debug_action_keys[3] = input.add_action(
|
|
||||||
input::InputAction {
|
|
||||||
.name = "debug_4",
|
|
||||||
.trigger = input::Trigger { .mapped_keycode = Key::digit_4 },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
m_input_system = memory::create_ref<input::System>(m_editor_registry);
|
|
||||||
m_mirror_system = memory::create_ref<MirrorSystem>(
|
|
||||||
m_editor_registry,
|
|
||||||
quit_action_key,
|
|
||||||
debug_action_keys
|
|
||||||
);
|
|
||||||
|
|
||||||
auto entity = ecs::Entity { m_editor_registry, m_window };
|
|
||||||
|
|
||||||
m_renderer_system = std::make_shared<renderer::System>(renderer::System::CreateInfo {
|
|
||||||
.config = { .target_api = renderer::Api::vulkan, .max_frames_in_flight = 3u },
|
|
||||||
.registry = m_editor_registry,
|
|
||||||
.surface_entity = entity,
|
|
||||||
.debug_callback_info = renderer::IDebugger::CreateInfo {
|
|
||||||
.severities = renderer::IDebugger::MessageSeverity::all,
|
|
||||||
.types = renderer::IDebugger::MessageType::all,
|
|
||||||
.callback = &renderer_callback,
|
|
||||||
.user_data = this,
|
|
||||||
} });
|
|
||||||
|
|
||||||
m_sprite_id = m_editor_registry->create_entity();
|
|
||||||
|
|
||||||
m_editor_registry->add(
|
|
||||||
m_sprite_id,
|
|
||||||
renderer::components::Sprite {
|
|
||||||
.color = lt::math::vec3 { 1.0f, 0.0f, 0.0f },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
m_editor_registry->add(
|
|
||||||
m_sprite_id,
|
|
||||||
math::components::Transform {
|
|
||||||
.translation = { -5.0, -5.0, 0.5 },
|
|
||||||
.scale = { 5.0, 5.0, 1.0 },
|
|
||||||
.rotation = {},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
m_camera_id = m_editor_registry->create_entity();
|
|
||||||
|
|
||||||
m_editor_registry->add(
|
|
||||||
m_camera_id,
|
|
||||||
camera::components::PerspectiveCamera {
|
|
||||||
.vertical_fov = math::to_radians(90.0f),
|
|
||||||
.near_plane = 0.1f,
|
|
||||||
.far_plane = 30.0,
|
|
||||||
.aspect_ratio = 1.0f,
|
|
||||||
.background_color = math::vec4(1.0, 0.0, 0.0, 1.0),
|
|
||||||
.is_primary = true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup_input_system()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void register_systems()
|
|
||||||
{
|
|
||||||
register_system(m_surface_system);
|
|
||||||
register_system(m_input_system);
|
|
||||||
register_system(m_renderer_system);
|
|
||||||
register_system(m_mirror_system);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
memory::Ref<ecs::Registry> m_editor_registry;
|
|
||||||
|
|
||||||
memory::Ref<lt::surface::System> m_surface_system;
|
|
||||||
|
|
||||||
memory::Ref<lt::input::System> m_input_system;
|
|
||||||
|
|
||||||
memory::Ref<lt::renderer::System> m_renderer_system;
|
|
||||||
|
|
||||||
memory::Ref<MirrorSystem> m_mirror_system;
|
|
||||||
|
|
||||||
lt::ecs::EntityId m_window = lt::ecs::null_entity;
|
|
||||||
|
|
||||||
lt::ecs::EntityId m_camera_id = lt::ecs::null_entity;
|
|
||||||
|
|
||||||
lt::ecs::EntityId m_sprite_id = lt::ecs::null_entity;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt
|
|
||||||
2
modules/pch/CMakeLists.txt
Normal file
2
modules/pch/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
add_library_module(universal_pch)
|
||||||
|
target_precompile_headers(universal_pch INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/public/pch/pch.hpp)
|
||||||
55
modules/pch/public/pch/error_handling/checks.hpp
Normal file
55
modules/pch/public/pch/error_handling/checks.hpp
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pch/error_handling/types.hpp>
|
||||||
|
#include <pch/module_configs.hpp>
|
||||||
|
|
||||||
|
namespace lt {
|
||||||
|
|
||||||
|
namespace details {
|
||||||
|
|
||||||
|
inline void throw_if_false(bool condition, std::source_location location)
|
||||||
|
{
|
||||||
|
if (!condition)
|
||||||
|
{
|
||||||
|
throw Error { "Failed runtime assertion", location };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace details
|
||||||
|
|
||||||
|
/** Throws lt::Error if \a condition is false, otherwise returns without side-effects.
|
||||||
|
*
|
||||||
|
* @throws lt::Error
|
||||||
|
*
|
||||||
|
* @note Only runs when LIGHT_ENABLE_CHECK is enabled, which is enabled by default on debug builds.
|
||||||
|
*
|
||||||
|
* @warn The successful execution of the contract of the using code should NOT depend on the
|
||||||
|
* execution of this function as it may or may NOT be executed--based on project configuration.
|
||||||
|
*/
|
||||||
|
inline void check(bool condition, std::source_location location = std::source_location::current())
|
||||||
|
{
|
||||||
|
if constexpr (light_enabled_check)
|
||||||
|
{
|
||||||
|
details::throw_if_false(condition, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Throws lt::Error if \a condition is false, otherwise returns without side-effects.
|
||||||
|
*
|
||||||
|
* @throws lt::Error
|
||||||
|
*
|
||||||
|
* @note Only runs when LIGHT_ENABLE_ENSURE is enabled, which is enabled by default on debug and
|
||||||
|
* release builds.
|
||||||
|
*
|
||||||
|
* @warn The successful execution of the contract of the using code should NOT depend on the
|
||||||
|
* execution of this function as it may or may NOT be executed--based on project configuration.
|
||||||
|
*/
|
||||||
|
inline void ensure(bool condition, std::source_location location = std::source_location::current())
|
||||||
|
{
|
||||||
|
if constexpr (light_enabled_ensure)
|
||||||
|
{
|
||||||
|
details::throw_if_false(condition, location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace lt
|
||||||
32
modules/pch/public/pch/error_handling/types.hpp
Normal file
32
modules/pch/public/pch/error_handling/types.hpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace lt {
|
||||||
|
|
||||||
|
class Error: public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Error(std::string_view reason, std::source_location location): m_reason(reason)
|
||||||
|
{
|
||||||
|
std::ignore = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error(const Error &prev, std::string_view reason, std::source_location location)
|
||||||
|
: m_reason(reason)
|
||||||
|
{
|
||||||
|
std::ignore = location;
|
||||||
|
std::ignore = prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto what() const noexcept -> const char * override
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_reason;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using Expected = std::expected<T, Error>;
|
||||||
|
|
||||||
|
} // namespace lt
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue