Compare commits
No commits in common. "feat/universal_pch" and "main" have entirely different histories.
feat/unive
...
main
184 changed files with 19295 additions and 935 deletions
|
|
@ -25,6 +25,7 @@ readability-avoid-const-params-in-decls,
|
|||
readability-avoid-nested-conditional-operator,
|
||||
readability-avoid-return-with-void-value,
|
||||
readability-avoid-unconditional-preprocessor-if,
|
||||
readability-braces-around-statements,
|
||||
readability-const-return-type,
|
||||
readability-container-contains,
|
||||
readability-container-data-pointdr,
|
||||
|
|
@ -128,7 +129,6 @@ cppcoreguidelines-pro-type-cstyle-cast,
|
|||
cppcoreguidelines-pro-type-member-init,
|
||||
cppcoreguidelines-pro-type-reinterpret-cast,
|
||||
cppcoreguidelines-pro-type-static-cast-downcast,
|
||||
cppcoreguidelines-pro-type-union-access,
|
||||
cppcoreguidelines-pro-type-vararg,
|
||||
cppcoreguidelines-rvalue-reference-param-not-moved,
|
||||
cppcoreguidelines-slicing,
|
||||
|
|
@ -235,12 +235,10 @@ misc-new-delete-overloads,
|
|||
misc-misplaced-const,
|
||||
misc-misleading-identifier,
|
||||
misc-misleading-bidirectional,
|
||||
misc-include-cleaner,
|
||||
misc-header-include-cycle,
|
||||
misc-definitions-in-headers,
|
||||
misc-coroutine-hostile-raii,
|
||||
misc-const-correctness,
|
||||
misc-confusable-identifiers,
|
||||
|
||||
hicpp-signed-bitwise,
|
||||
hicpp-no-assembler,
|
||||
|
|
|
|||
17
.cmake-format
Normal file
17
.cmake-format
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# 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 : '*'
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
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
|
||||
157
.drone.yml
157
.drone.yml
|
|
@ -1,13 +1,154 @@
|
|||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: linux_amd64
|
||||
|
||||
type: exec
|
||||
name: amd64 — msvc
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
platform:
|
||||
os: linux
|
||||
os: windows
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: clang format
|
||||
image: alpine_amd64__clang_format
|
||||
pull: if-not-exists
|
||||
commands: $(git rev-parse --show-toplevel)/tools/ci/alpine_amd64/script.sh
|
||||
- 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
|
||||
image: ci:latest
|
||||
pull: if-not-exists
|
||||
commands:
|
||||
- ./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,65 +1,37 @@
|
|||
# Temp directories
|
||||
.vs/
|
||||
bin/
|
||||
bin-obj/
|
||||
build/
|
||||
.cache/
|
||||
|
||||
# ---> C++
|
||||
# Prerequisites
|
||||
*.d
|
||||
# VS Files
|
||||
**.vcxproj**
|
||||
**.sln
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
.codelite/
|
||||
.build-debug/
|
||||
.vimspector.json
|
||||
**.workspace
|
||||
|
||||
# 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
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
|
||||
**/**.mk
|
||||
|
||||
**/**.project
|
||||
|
||||
**/Engine.txt
|
||||
**/GLAD.txt
|
||||
**/Sandbox.txt
|
||||
|
||||
**/Logs/**
|
||||
**/logs/**
|
||||
**.ini
|
||||
!**/default_gui_layout.ini
|
||||
|
||||
CMake/
|
||||
CMakeUserPresets.json
|
||||
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
|
||||
project("light" LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_EPXORT_COMPILE_COMMANDS TRUE)
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
set(CMAKE_CXX_MODULE_STD 1)
|
||||
|
||||
include(tools/cmake/preliminary.cmake)
|
||||
include(tools/cmake/module_macros.cmake)
|
||||
cmake_minimum_required(VERSION 4.1)
|
||||
project(Light)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/functions.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/options.cmake)
|
||||
|
||||
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)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules)
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"version": 4,
|
||||
"vendor": {
|
||||
"conan": {}
|
||||
},
|
||||
"include": [
|
||||
"build/Debug/generators/CMakePresets.json"
|
||||
]
|
||||
}
|
||||
433
LICENSE
433
LICENSE
|
|
@ -1,232 +1,201 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
“This License” refers to version 3 of the GNU General Public License.
|
||||
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
||||
|
||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
||||
|
||||
A “covered work” means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
||||
|
||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
||||
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
||||
|
||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||
|
||||
light
|
||||
Copyright (C) 2024 light7734
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
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>.
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# light
|
||||
# Light
|
||||
See docs.light7734.com for a comprehensive project documentation
|
||||
|
||||
Monorepo for a cross-platform, cross-graphics-api, high-performance, modular, and modern game-engine.
|
||||
###### “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
|
||||
|
|
|
|||
58
conanfile.py
58
conanfile.py
|
|
@ -1,58 +0,0 @@
|
|||
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!")
|
||||
BIN
data/assets/fonts/open_sans/LICENSE.asset
Normal file
BIN
data/assets/fonts/open_sans/LICENSE.asset
Normal file
Binary file not shown.
202
data/assets/fonts/open_sans/LICENSE.txt
Normal file
202
data/assets/fonts/open_sans/LICENSE.txt
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
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.
|
||||
BIN
data/assets/fonts/open_sans/OpenSans-Bold.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-Bold.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-BoldItalic.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-BoldItalic.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-ExtraBold.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-ExtraBold.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-ExtraBoldItalic.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-ExtraBoldItalic.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-Italic.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-Italic.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-Light.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-Light.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-LightItalic.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-LightItalic.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-Regular.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-Regular.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-SemiBold.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-SemiBold.ttf
Normal file
Binary file not shown.
BIN
data/assets/fonts/open_sans/OpenSans-SemiBoldItalic.ttf
Normal file
BIN
data/assets/fonts/open_sans/OpenSans-SemiBoldItalic.ttf
Normal file
Binary file not shown.
BIN
data/assets/textures/awesomeface.asset
Normal file
BIN
data/assets/textures/awesomeface.asset
Normal file
Binary file not shown.
BIN
data/assets/textures/awesomeface.png
Normal file
BIN
data/assets/textures/awesomeface.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 79 KiB |
BIN
data/engine/icons/asset/dir.asset
Normal file
BIN
data/engine/icons/asset/dir.asset
Normal file
Binary file not shown.
BIN
data/engine/icons/asset/dir.png
Normal file
BIN
data/engine/icons/asset/dir.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
data/engine/icons/asset/img.asset
Normal file
BIN
data/engine/icons/asset/img.asset
Normal file
Binary file not shown.
BIN
data/engine/icons/asset/img.png
Normal file
BIN
data/engine/icons/asset/img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
BIN
data/engine/icons/asset/scene.asset
Normal file
BIN
data/engine/icons/asset/scene.asset
Normal file
Binary file not shown.
BIN
data/engine/icons/asset/scene.png
Normal file
BIN
data/engine/icons/asset/scene.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
BIN
data/engine/icons/asset/txt.asset
Normal file
BIN
data/engine/icons/asset/txt.asset
Normal file
Binary file not shown.
BIN
data/engine/icons/asset/txt.png
Normal file
BIN
data/engine/icons/asset/txt.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
1
data/test_assets/dummytext
Normal file
1
data/test_assets/dummytext
Normal file
|
|
@ -0,0 +1 @@
|
|||
The quick brown fox jumps over the lazy dog
|
||||
36
data/test_assets/sprite.vert
Normal file
36
data/test_assets/sprite.vert
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#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);
|
||||
}
|
||||
BIN
data/test_assets/sprite.vert.asset
Normal file
BIN
data/test_assets/sprite.vert.asset
Normal file
Binary file not shown.
10
data/test_assets/triangle.frag
Normal file
10
data/test_assets/triangle.frag
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#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);
|
||||
}
|
||||
BIN
data/test_assets/triangle.frag.asset
Normal file
BIN
data/test_assets/triangle.frag.asset
Normal file
Binary file not shown.
25
data/test_assets/triangle.vert
Normal file
25
data/test_assets/triangle.vert
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#version 450 core
|
||||
|
||||
layout(push_constant ) uniform pc {
|
||||
mat4 view_projection;
|
||||
};
|
||||
|
||||
vec3 positions[3] = vec3[](
|
||||
vec3(0.0, -0.5, 0.5),
|
||||
vec3(0.5, 0.5, 0.5),
|
||||
vec3(-0.5, 0.5, 0.5)
|
||||
);
|
||||
|
||||
vec3 colors[3] = vec3[](
|
||||
vec3(0.0, 0.0, 0.0),
|
||||
vec3(0.0, 0.0, 0.0),
|
||||
vec3(0.0, 0.0, 0.0)
|
||||
);
|
||||
|
||||
layout(location = 0) out vec3 out_frag_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = view_projection * vec4(positions[gl_VertexIndex], 1.0);
|
||||
out_frag_color = colors[gl_VertexIndex];
|
||||
}
|
||||
BIN
data/test_assets/triangle.vert.asset
Normal file
BIN
data/test_assets/triangle.vert.asset
Normal file
Binary file not shown.
4
docs/.gitignore
vendored
Normal file
4
docs/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
_build/
|
||||
generated/
|
||||
html/
|
||||
xml/
|
||||
|
|
@ -1 +0,0 @@
|
|||
message("TODO: implement doc generation")
|
||||
86
docs/Doxyfile
Normal file
86
docs/Doxyfile
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
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
|
||||
17
docs/api/app.rst
Normal file
17
docs/api/app.rst
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Application
|
||||
===================================================================================================
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
:caption: App
|
||||
|
||||
Functions
|
||||
---------------------------------------------------------------------------------------------------
|
||||
.. doxygenfunction:: main
|
||||
|
||||
Classes
|
||||
---------------------------------------------------------------------------------------------------
|
||||
.. doxygenclass:: lt::app::ISystem
|
||||
|
||||
.. doxygenstruct:: lt::app::TickInfo
|
||||
|
||||
.. doxygenstruct:: lt::app::TickResult
|
||||
13
docs/api/renderer.rst
Normal file
13
docs/api/renderer.rst
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Renderer
|
||||
===================================================================================================
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
:caption: App
|
||||
|
||||
Classes
|
||||
---------------------------------------------------------------------------------------------------
|
||||
.. doxygenenum:: lt::renderer::Api
|
||||
|
||||
.. doxygenclass:: lt::renderer::System
|
||||
|
||||
.. doxygenstruct:: lt::renderer::components::Sprite
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
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.
|
||||
72
docs/architecture/assets.rst
Normal file
72
docs/architecture/assets.rst
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
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.
|
||||
5
docs/architecture/resource.rst
Normal file
5
docs/architecture/resource.rst
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.. architecture/resources
|
||||
|
||||
Resource Management
|
||||
===================================================================================================
|
||||
|
||||
46
docs/conf.py
46
docs/conf.py
|
|
@ -1,25 +1,35 @@
|
|||
# Project information
|
||||
project = 'Light'
|
||||
copyright = '2024, Light7734'
|
||||
author = 'Light7734'
|
||||
release = '1'
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# For the full list of built-in configuration values, see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# General configuration
|
||||
extensions = [
|
||||
"sphinx.ext.intersphinx",
|
||||
"sphinx_copybutton",
|
||||
"sphinx_design"
|
||||
]
|
||||
# -- Project information -----------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||
|
||||
source_suffix = '.rst'
|
||||
default_role = 'cpp:any'
|
||||
pygments_style = 'sphinx'
|
||||
highlight_language = 'c++'
|
||||
project = 'light'
|
||||
copyright = '2025, light7734'
|
||||
author = 'light7734'
|
||||
|
||||
# -- 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'
|
||||
|
||||
# Tell sphinx what the pygments highlight language should be.
|
||||
highlight_language = 'cpp'
|
||||
|
||||
templates_path = ['_templates']
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
templates_path = ["_templates"]
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
|
||||
# Theme configuration
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
# html_favicon = ''
|
||||
html_static_path = ['_static']
|
||||
|
|
|
|||
10
docs/guidelines/conventions.rst
Normal file
10
docs/guidelines/conventions.rst
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
.. 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
|
||||
--------------------
|
||||
144
docs/guidelines/development.rst
Normal file
144
docs/guidelines/development.rst
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
.. 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>``
|
||||
7
docs/guidelines/philosophy.rst
Normal file
7
docs/guidelines/philosophy.rst
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
.. guidelines/philosophy
|
||||
|
||||
Philosophy
|
||||
===================================================================================================
|
||||
|
||||
| **A theory or attitude that acts as a guiding principle for behaviour.**
|
||||
| --- Oxford Languages
|
||||
|
|
@ -1,4 +1,32 @@
|
|||
.. toctree::
|
||||
./architecture.rst
|
||||
./philosophy.rst
|
||||
.. light documentation
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Light Engine
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
|
|
|||
4
docs/light/features.rst
Normal file
4
docs/light/features.rst
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.. light/features
|
||||
|
||||
Features
|
||||
===================================================================================================
|
||||
4
docs/light/showcase.rst
Normal file
4
docs/light/showcase.rst
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.. light/demos
|
||||
|
||||
Showcase
|
||||
===================================================================================================
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
Philosophy
|
||||
=========================
|
||||
|
||||
|
||||
Code is documentation
|
||||
------------------------
|
||||
|
|
@ -1,3 +1,259 @@
|
|||
add_subdirectory(pch)
|
||||
add_module(NAME logger INTERFACES logger.cppm TESTS logger.test.cpp)
|
||||
add_module(NAME bitwise INTERFACES operations.cppm)
|
||||
add_module(NAME env INTERFACES constants.cppm)
|
||||
add_module(NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm)
|
||||
add_module(NAME time INTERFACES timer.cppm TESTS timer.test.cpp)
|
||||
|
||||
add_subdirectory(engine)
|
||||
add_module(
|
||||
NAME
|
||||
test
|
||||
INTERFACES
|
||||
test.cppm
|
||||
expects.cppm
|
||||
registry.cppm
|
||||
SOURCES
|
||||
entrypoint.cpp
|
||||
DEPENDENCIES
|
||||
logger
|
||||
TESTS
|
||||
test.test.cpp
|
||||
)
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
lt_debug
|
||||
ROOT_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug
|
||||
INTERFACES
|
||||
instrumentor.cppm
|
||||
assertions.cppm
|
||||
DEPENDENCIES
|
||||
logger
|
||||
)
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
math
|
||||
INTERFACES
|
||||
algebra.cppm
|
||||
mat4.cppm
|
||||
trig.cppm
|
||||
vec2.cppm
|
||||
vec3.cppm
|
||||
vec4.cppm
|
||||
components.cppm
|
||||
)
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
assets
|
||||
INTERFACES
|
||||
shader.cppm
|
||||
metadata.cppm
|
||||
DEPENDENCIES
|
||||
logger
|
||||
lt_debug
|
||||
TESTS
|
||||
shader.test.cpp
|
||||
)
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
asset_baker
|
||||
ROOT_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/asset_baker
|
||||
INTERFACES
|
||||
bakers.cppm
|
||||
ENTRYPOINT
|
||||
entrypoint.cpp
|
||||
DEPENDENCIES
|
||||
assets
|
||||
logger
|
||||
lt_debug
|
||||
TESTS
|
||||
bakers.test.cpp
|
||||
)
|
||||
|
||||
# add_executable(asset_baker entrypoint.cpp) target_link_libraries(asset_baker
|
||||
# PRIVATE libasset_baker)
|
||||
|
||||
add_module(NAME camera INTERFACES components.cppm DEPENDENCIES math)
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
app
|
||||
INTERFACES
|
||||
application.cppm
|
||||
system.cppm
|
||||
DEPENDENCIES
|
||||
memory
|
||||
PRIVATE_DEPENDENCIES
|
||||
lt_debug
|
||||
)
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
ecs
|
||||
INTERFACES
|
||||
sparse_set.cppm
|
||||
registry.cppm
|
||||
entity.cppm
|
||||
DEPENDENCIES
|
||||
logger
|
||||
lt_debug
|
||||
memory
|
||||
TESTS
|
||||
registry.test.cpp
|
||||
sparse_set.test.cpp
|
||||
)
|
||||
|
||||
add_module(NAME input_codes INTERFACES input_codes.cppm)
|
||||
|
||||
if(WIN32)
|
||||
add_module(
|
||||
NAME
|
||||
surface
|
||||
INTERFACES
|
||||
constants.cppm
|
||||
system.cppm
|
||||
requests.cppm
|
||||
events.cppm
|
||||
components.cppm
|
||||
SOURCES
|
||||
platform_windows.cpp
|
||||
DEPENDENCIES
|
||||
ecs
|
||||
app
|
||||
math
|
||||
memory
|
||||
input_codes
|
||||
PRIVATE_DEPENDENCIES
|
||||
logger
|
||||
lt_debug
|
||||
time
|
||||
)
|
||||
|
||||
elseif(UNIX)
|
||||
add_module(
|
||||
NAME
|
||||
surface
|
||||
INTERFACES
|
||||
constants.cppm
|
||||
system.cppm
|
||||
requests.cppm
|
||||
events.cppm
|
||||
components.cppm
|
||||
SOURCES
|
||||
platform_linux.cpp
|
||||
DEPENDENCIES
|
||||
ecs
|
||||
app
|
||||
math
|
||||
memory
|
||||
input_codes
|
||||
PRIVATE_DEPENDENCIES
|
||||
X11
|
||||
logger
|
||||
lt_debug
|
||||
time
|
||||
TESTS
|
||||
system.test.cpp
|
||||
)
|
||||
|
||||
else()
|
||||
message(FATAL "Failed to generate cmake: unsupported platform")
|
||||
|
||||
endif()
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
input
|
||||
INTERFACES
|
||||
system.cppm
|
||||
components.cppm
|
||||
events.cppm
|
||||
DEPENDENCIES
|
||||
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
|
||||
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
|
||||
TEST_INTERFACES
|
||||
_tests/utils.cppm
|
||||
# _tests/renderer.cpp _tests/surface.cpp _tests/system.cpp
|
||||
)
|
||||
|
||||
add_module(
|
||||
NAME
|
||||
mirror
|
||||
ROOT_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mirror
|
||||
INTERFACES
|
||||
system.cppm
|
||||
DEPENDENCIES
|
||||
memory
|
||||
app
|
||||
time
|
||||
input
|
||||
surface
|
||||
renderer
|
||||
camera
|
||||
# TESTS system.test.cpp
|
||||
)
|
||||
|
||||
add_executable(exectest ${CMAKE_CURRENT_SOURCE_DIR}/mirror/entrypoint.cpp)
|
||||
|
||||
target_link_libraries(
|
||||
exectest
|
||||
PRIVATE mirror
|
||||
app
|
||||
time
|
||||
input
|
||||
surface
|
||||
renderer
|
||||
camera
|
||||
)
|
||||
|
||||
# add_executable_module(mirror entrypoint/mirror.cpp)
|
||||
# target_link_libraries(mirror PRIVATE libmirror input)
|
||||
|
|
|
|||
94
modules/app/application.cppm
Normal file
94
modules/app/application.cppm
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
export module app;
|
||||
import app.system;
|
||||
import memory.reference;
|
||||
import memory.scope;
|
||||
import std;
|
||||
|
||||
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".
|
||||
*/
|
||||
export 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
|
||||
110
modules/app/system.cppm
Normal file
110
modules/app/system.cppm
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
export module app.system;
|
||||
import logger;
|
||||
import std;
|
||||
|
||||
namespace lt::app {
|
||||
|
||||
/** Information required to tick a system.
|
||||
* @note May be used across an entire application-frame (consisting of multiple systems ticking)
|
||||
*/
|
||||
export struct TickInfo
|
||||
{
|
||||
using Timepoint_T = std::chrono::time_point<std::chrono::steady_clock>;
|
||||
|
||||
using Duration_T = std::chrono::duration<double>;
|
||||
|
||||
/** 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 */
|
||||
export struct TickResult
|
||||
{
|
||||
using Timepoint_T = std::chrono::time_point<std::chrono::steady_clock>;
|
||||
|
||||
using Duration_T = std::chrono::duration<double>;
|
||||
|
||||
/** 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;
|
||||
};
|
||||
|
||||
export struct SystemDiagnosis
|
||||
{
|
||||
enum class Severity : std::uint8_t
|
||||
{
|
||||
verbose,
|
||||
info,
|
||||
warning,
|
||||
error,
|
||||
fatal,
|
||||
};
|
||||
|
||||
std::string message;
|
||||
|
||||
std::string code;
|
||||
|
||||
Severity severity;
|
||||
};
|
||||
|
||||
export 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;
|
||||
};
|
||||
|
||||
export 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
|
||||
66
modules/asset_baker/bakers.cppm
Normal file
66
modules/asset_baker/bakers.cppm
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
export module bakers;
|
||||
|
||||
import debug.assertions;
|
||||
import assets.metadata;
|
||||
import assets.shader;
|
||||
import logger;
|
||||
import std;
|
||||
|
||||
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);
|
||||
lt::debug::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<std::byte>(size);
|
||||
stream.seekg(0, std::ios::beg);
|
||||
stream.read((char *)bytes.data(), size); // NOLINT
|
||||
lt::log::debug("BYTES: {}", bytes.size());
|
||||
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)
|
||||
);
|
||||
}
|
||||
44
modules/asset_baker/entrypoint.cpp
Normal file
44
modules/asset_baker/entrypoint.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import assets.shader;
|
||||
import logger;
|
||||
import bakers;
|
||||
import std;
|
||||
|
||||
|
||||
auto main(int argc, char *argv[]) -> std::int32_t
|
||||
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 auto out_path = std::format("{}.asset", in_path.c_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;
|
||||
}
|
||||
43
modules/assets/metadata.cppm
Normal file
43
modules/assets/metadata.cppm
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
export module assets.metadata;
|
||||
import std;
|
||||
|
||||
export namespace lt::assets {
|
||||
|
||||
using Type_T = std::array<const char, 16>;
|
||||
|
||||
using Tag_T = std::uint8_t;
|
||||
|
||||
using Version = std::uint8_t;
|
||||
|
||||
using Blob = std::vector<std::byte>;
|
||||
|
||||
constexpr auto current_version = Version { 1u };
|
||||
|
||||
enum class CompressionType : std::uint8_t
|
||||
{
|
||||
none,
|
||||
lz4,
|
||||
lz4_hc,
|
||||
};
|
||||
|
||||
struct AssetMetadata
|
||||
{
|
||||
Version version;
|
||||
|
||||
Type_T type;
|
||||
};
|
||||
|
||||
struct BlobMetadata
|
||||
{
|
||||
Tag_T tag;
|
||||
|
||||
std::size_t offset;
|
||||
|
||||
CompressionType compression_type;
|
||||
|
||||
std::size_t compressed_size;
|
||||
|
||||
std::size_t uncompressed_size;
|
||||
};
|
||||
|
||||
} // namespace lt::assets
|
||||
232
modules/assets/shader.cppm
Normal file
232
modules/assets/shader.cppm
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
export module assets.shader;
|
||||
import assets.metadata;
|
||||
import debug.assertions;
|
||||
|
||||
import std;
|
||||
|
||||
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 : std::uint8_t
|
||||
{
|
||||
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<std::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 &
|
||||
{
|
||||
debug::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)
|
||||
{
|
||||
debug::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<std::size_t>(m_stream.tellg());
|
||||
debug::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);
|
||||
|
||||
debug::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
|
||||
);
|
||||
|
||||
debug::ensure(
|
||||
m_asset_metadata.version == current_version,
|
||||
"Failed to open shader asset at: {}, version mismatch: {} != {}",
|
||||
path.string(),
|
||||
m_asset_metadata.version,
|
||||
current_version
|
||||
);
|
||||
|
||||
debug::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)
|
||||
);
|
||||
|
||||
debug::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
|
||||
);
|
||||
|
||||
debug::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(),
|
||||
};
|
||||
|
||||
debug::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<std::byte> destination) const
|
||||
{
|
||||
debug::ensure(
|
||||
tag == BlobTag::code,
|
||||
"Invalid blob tag for shader asset: {}",
|
||||
std::to_underlying(tag)
|
||||
);
|
||||
|
||||
debug::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<std::size_t>(destination.data()),
|
||||
destination.size(),
|
||||
m_code_blob_metadata.uncompressed_size
|
||||
);
|
||||
|
||||
m_stream.seekg(static_cast<long long>(m_code_blob_metadata.offset));
|
||||
m_stream.read(
|
||||
std::bit_cast<char *>(destination.data()),
|
||||
static_cast<long long>(m_code_blob_metadata.uncompressed_size)
|
||||
);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto ShaderAsset::unpack(BlobTag tag) const -> Blob
|
||||
{
|
||||
debug::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
|
||||
97
modules/assets/shader.test.cpp
Normal file
97
modules/assets/shader.test.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
import assets.metadata;
|
||||
import assets.shader;
|
||||
import test.test;
|
||||
import test.expects;
|
||||
import std;
|
||||
|
||||
using ::lt::assets::AssetMetadata;
|
||||
using ::lt::assets::BlobMetadata;
|
||||
using ::lt::assets::ShaderAsset;
|
||||
using ::lt::test::Case;
|
||||
using ::lt::test::expect_eq;
|
||||
using ::lt::test::expect_throw;
|
||||
using ::lt::test::expect_true;
|
||||
using ::lt::test::Suite;
|
||||
using ::lt::test::operator""_suite;
|
||||
|
||||
const auto test_data_path = std::filesystem::path { "./data/test_assets" };
|
||||
const auto tmp_path = std::filesystem::path { "/tmp/lt_assets_tests/" };
|
||||
|
||||
Suite raii = "shader_raii"_suite = [] {
|
||||
std::filesystem::current_path(test_data_path);
|
||||
std::filesystem::create_directories(tmp_path);
|
||||
|
||||
Case { "happy path won't throw" } = [] {
|
||||
|
||||
};
|
||||
|
||||
Case { "many won't freeze/throw" } = [] {
|
||||
};
|
||||
|
||||
Case { "unhappy path throws" } = [] {
|
||||
expect_throw([] { ShaderAsset { "random_path" }; });
|
||||
};
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-interfaces-global-init)
|
||||
Suite packing = "shader_pack"_suite = [] {
|
||||
Case { "" } = [] {
|
||||
const auto out_path = tmp_path / "shader_packing";
|
||||
auto dummy_blob = lt::assets::Blob {};
|
||||
for (auto idx : std::views::iota(0, 255))
|
||||
{
|
||||
dummy_blob.emplace_back(static_cast<std::byte>(idx));
|
||||
}
|
||||
|
||||
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) //
|
||||
+ dummy_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(dummy_blob)
|
||||
);
|
||||
|
||||
auto stream = std::ifstream {
|
||||
out_path,
|
||||
std::ios::binary,
|
||||
};
|
||||
expect_true(stream.is_open());
|
||||
|
||||
stream.seekg(0, std::ios::end);
|
||||
const auto file_size = static_cast<std::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 blob = shader_asset.unpack(ShaderAsset::BlobTag::code);
|
||||
expect_eq(blob.size(), 255);
|
||||
|
||||
for (auto idx : std::views::iota(0, 255))
|
||||
{
|
||||
expect_eq(blob[idx], static_cast<std::byte>(idx));
|
||||
}
|
||||
};
|
||||
};
|
||||
12
modules/bitwise/operations.cppm
Normal file
12
modules/bitwise/operations.cppm
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export module bitwise;
|
||||
import std;
|
||||
|
||||
namespace lt::bitwise {
|
||||
|
||||
/* bit-wise */
|
||||
export constexpr auto bit(std::uint32_t x) -> std::uint32_t
|
||||
{
|
||||
return 1u << x;
|
||||
}
|
||||
|
||||
} // namespace lt::bitwise
|
||||
21
modules/camera/components.cppm
Normal file
21
modules/camera/components.cppm
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
export module camera.components;
|
||||
import math.vec4;
|
||||
|
||||
namespace lt::camera::components {
|
||||
|
||||
export struct PerspectiveCamera
|
||||
{
|
||||
float vertical_fov {};
|
||||
|
||||
float near_plane {};
|
||||
|
||||
float far_plane {};
|
||||
|
||||
float aspect_ratio {};
|
||||
|
||||
math::vec4 background_color;
|
||||
|
||||
bool is_primary {};
|
||||
};
|
||||
|
||||
} // namespace lt::camera::components
|
||||
47
modules/debug/assertions.cppm
Normal file
47
modules/debug/assertions.cppm
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
export module debug.assertions;
|
||||
|
||||
import std;
|
||||
|
||||
namespace lt::debug {
|
||||
|
||||
///////////////////////////////////////
|
||||
// ----------* INTERFACE *--------- //
|
||||
/////////////////////////////////////
|
||||
export template<typename Expression_T, typename... Args_T>
|
||||
struct ensure
|
||||
{
|
||||
ensure(
|
||||
const Expression_T &expression,
|
||||
std::format_string<Args_T...> fmt,
|
||||
Args_T &&...args,
|
||||
const std::source_location &location = std::source_location::current()
|
||||
);
|
||||
};
|
||||
|
||||
export template<typename Expression_T, typename... Args_T>
|
||||
ensure(Expression_T, std::format_string<Args_T...>, Args_T &&...)
|
||||
-> ensure<Expression_T, Args_T...>;
|
||||
|
||||
///////////////////////////////////////
|
||||
// * IMPLEMENTATION -- TEMPLATES * //
|
||||
/////////////////////////////////////
|
||||
template<typename Expression_T, typename... Args_T>
|
||||
ensure<Expression_T, Args_T...>::ensure(
|
||||
const Expression_T &expression,
|
||||
std::format_string<Args_T...> fmt,
|
||||
Args_T &&...args,
|
||||
const std::source_location &location
|
||||
)
|
||||
{
|
||||
if (!static_cast<bool>(expression))
|
||||
{
|
||||
throw std::runtime_error { std::format(
|
||||
"exception: {}\nlocation: {}:{}",
|
||||
std::format(fmt, std::forward<Args_T>(args)...),
|
||||
location.file_name(),
|
||||
location.line()
|
||||
) };
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace lt::debug
|
||||
146
modules/debug/instrumentor.cppm
Normal file
146
modules/debug/instrumentor.cppm
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
export module debug.instrumentor;
|
||||
|
||||
import std;
|
||||
import logger;
|
||||
|
||||
namespace lt::debug {
|
||||
|
||||
struct ScopeProfileResult
|
||||
{
|
||||
std::string name;
|
||||
long long start, duration;
|
||||
std::uint32_t threadID;
|
||||
};
|
||||
|
||||
class Instrumentor
|
||||
{
|
||||
public:
|
||||
static auto instance() -> Instrumentor &
|
||||
{
|
||||
static auto instance = Instrumentor {};
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void begin_session(const std::string &outputPath)
|
||||
{
|
||||
instance().begin_session_impl(outputPath);
|
||||
}
|
||||
static void end_session()
|
||||
{
|
||||
instance().end_session_impl();
|
||||
}
|
||||
|
||||
static void submit_scope_profile(const ScopeProfileResult &profileResult)
|
||||
{
|
||||
instance().submit_scope_profile_impl(profileResult);
|
||||
}
|
||||
|
||||
private:
|
||||
std::ofstream m_output_file_stream;
|
||||
|
||||
unsigned int m_current_session_count { 0u };
|
||||
|
||||
Instrumentor() = default;
|
||||
|
||||
void begin_session_impl(const std::string &outputPath);
|
||||
|
||||
void end_session_impl();
|
||||
|
||||
void submit_scope_profile_impl(const ScopeProfileResult &profileResult);
|
||||
};
|
||||
|
||||
class InstrumentorTimer
|
||||
{
|
||||
public:
|
||||
InstrumentorTimer(const std::string &scopeName);
|
||||
|
||||
~InstrumentorTimer();
|
||||
|
||||
private:
|
||||
ScopeProfileResult m_result;
|
||||
|
||||
std::chrono::time_point<std::chrono::steady_clock> m_start;
|
||||
};
|
||||
|
||||
} // namespace lt::debug
|
||||
|
||||
/* scope */
|
||||
#define lt_profile_scope(name) lt_profile_scope_no_redifinition(name, __LINE__)
|
||||
#define lt_profile_scope_no_redifinition(name, line) lt_profile_scope_no_redifinition2(name, line)
|
||||
#define lt_profile_scope_no_redifinition2(name, line) InstrumentorTimer timer##line(name)
|
||||
|
||||
/* function */
|
||||
#define LT_PROFILE_FUNCTION lt_profile_scope(__FUNCSIG__)
|
||||
|
||||
/* session */
|
||||
#define lt_profile_begin_session(outputPath) ::lt::Instrumentor::begin_session(outputPath)
|
||||
#define lt_profile_end_session() ::lt::Instrumentor::end_session()
|
||||
|
||||
module :private;
|
||||
namespace lt::debug {
|
||||
|
||||
void Instrumentor::begin_session_impl(const std::string &outputPath)
|
||||
{
|
||||
std::filesystem::create_directory(outputPath.substr(0, outputPath.find_last_of('/') + 1));
|
||||
|
||||
m_output_file_stream.open(outputPath);
|
||||
m_output_file_stream << "{\"traceEvents\":[";
|
||||
}
|
||||
|
||||
void Instrumentor::end_session_impl()
|
||||
{
|
||||
if (m_current_session_count == 0u)
|
||||
{
|
||||
log::warn("0 profiling for the ended session");
|
||||
}
|
||||
|
||||
m_current_session_count = 0u;
|
||||
|
||||
m_output_file_stream << "]}";
|
||||
m_output_file_stream.flush();
|
||||
m_output_file_stream.close();
|
||||
}
|
||||
|
||||
void Instrumentor::submit_scope_profile_impl(const ScopeProfileResult &profileResult)
|
||||
{
|
||||
if (m_current_session_count++ == 0u)
|
||||
{
|
||||
m_output_file_stream << "{";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_output_file_stream << ",{";
|
||||
}
|
||||
|
||||
m_output_file_stream << R"("name":")" << profileResult.name << "\",";
|
||||
m_output_file_stream << R"("cat": "scope",)";
|
||||
m_output_file_stream << R"("ph": "X",)";
|
||||
m_output_file_stream << "\"ts\":" << profileResult.start << ",";
|
||||
m_output_file_stream << "\"dur\":" << profileResult.duration << ",";
|
||||
m_output_file_stream << "\"pid\":0,";
|
||||
m_output_file_stream << "\"tid\":" << profileResult.threadID << "";
|
||||
m_output_file_stream << "}";
|
||||
}
|
||||
|
||||
InstrumentorTimer::InstrumentorTimer(const std::string &scopeName)
|
||||
: m_result({ .name = scopeName, .start = 0, .duration = 0, .threadID = 0 })
|
||||
, m_start(std::chrono::steady_clock::now())
|
||||
{
|
||||
}
|
||||
|
||||
InstrumentorTimer::~InstrumentorTimer()
|
||||
{
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
|
||||
m_result.start = std::chrono::time_point_cast<std::chrono::microseconds>(m_start)
|
||||
.time_since_epoch()
|
||||
.count();
|
||||
|
||||
m_result.duration = std::chrono::time_point_cast<std::chrono::microseconds>(end)
|
||||
.time_since_epoch()
|
||||
.count()
|
||||
- m_result.start;
|
||||
|
||||
Instrumentor::submit_scope_profile(m_result);
|
||||
}
|
||||
} // namespace lt::debug
|
||||
55
modules/ecs/entity.cppm
Normal file
55
modules/ecs/entity.cppm
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
export module ecs.entity;
|
||||
import debug.assertions;
|
||||
import memory.reference;
|
||||
import ecs.registry;
|
||||
import std;
|
||||
|
||||
namespace lt::ecs {
|
||||
|
||||
/** High-level entity convenience wrapper */
|
||||
export class Entity
|
||||
{
|
||||
public:
|
||||
Entity(memory::Ref<Registry> registry, EntityId identifier)
|
||||
: m_registry(std::move(registry))
|
||||
, m_identifier(identifier)
|
||||
{
|
||||
debug::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
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace lt::ecs {
|
||||
|
||||
|
||||
}
|
||||
266
modules/ecs/registry.cppm
Normal file
266
modules/ecs/registry.cppm
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
export module ecs.registry;
|
||||
import debug.assertions;
|
||||
import ecs.sparse_set;
|
||||
import memory.scope;
|
||||
import std;
|
||||
|
||||
namespace lt::ecs {
|
||||
|
||||
export using EntityId = std::uint32_t;
|
||||
|
||||
export 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
|
||||
*/
|
||||
export 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 -> std::size_t
|
||||
{
|
||||
return static_cast<std::size_t>(m_entity_count);
|
||||
}
|
||||
|
||||
private:
|
||||
using TypeId = std::size_t;
|
||||
|
||||
static consteval auto hash_cstr(const char *str) -> TypeId
|
||||
{
|
||||
constexpr auto fnv_offset_basis = std::size_t { 14695981039346656037ull };
|
||||
constexpr auto fnv_prime = std::size_t { 1099511628211ull };
|
||||
|
||||
auto hash = fnv_offset_basis;
|
||||
|
||||
for (const auto &ch : std::string_view { str })
|
||||
{
|
||||
hash *= fnv_prime;
|
||||
hash ^= static_cast<std::uint8_t>(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);
|
||||
debug::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
|
||||
349
modules/ecs/registry.test.cpp
Normal file
349
modules/ecs/registry.test.cpp
Normal file
|
|
@ -0,0 +1,349 @@
|
|||
import ecs.registry;
|
||||
import test.test;
|
||||
import test.expects;
|
||||
import std;
|
||||
|
||||
using ::lt::ecs::EntityId;
|
||||
using ::lt::ecs::Registry;
|
||||
using ::lt::test::Case;
|
||||
using ::lt::test::expect_eq;
|
||||
using ::lt::test::expect_false;
|
||||
using ::lt::test::expect_true;
|
||||
using ::lt::test::expect_unreachable;
|
||||
using ::lt::test::Suite;
|
||||
using ::lt::test::operator""_suite;
|
||||
|
||||
struct Component
|
||||
{
|
||||
int 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
|
||||
{
|
||||
float 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 path won't throw" } = [] {
|
||||
std::ignore = Registry {};
|
||||
};
|
||||
|
||||
Case { "many won't freeze/throw" } = [] {
|
||||
for (auto idx : std::views::iota(0, 100'000))
|
||||
{
|
||||
std::ignore = Registry {};
|
||||
}
|
||||
};
|
||||
|
||||
Case { "unhappy path throws" } = [] {
|
||||
};
|
||||
|
||||
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))
|
||||
{
|
||||
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))
|
||||
{
|
||||
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<lt::ecs::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<float>(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<float>(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);
|
||||
};
|
||||
};
|
||||
177
modules/ecs/sparse_set.cppm
Normal file
177
modules/ecs/sparse_set.cppm
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
export module ecs.sparse_set;
|
||||
import debug.assertions;
|
||||
import std;
|
||||
|
||||
namespace lt::ecs {
|
||||
|
||||
/**
|
||||
* @ref https://programmingpraxis.com/2012/03/09/sparse-sets/
|
||||
*/
|
||||
export template<typename Identifier_T = std::uint32_t>
|
||||
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;
|
||||
};
|
||||
|
||||
export template<typename Value_T, typename Identifier_T = std::uint32_t>
|
||||
class SparseSet: public TypeErasedSparseSet<Identifier_T>
|
||||
{
|
||||
public:
|
||||
using Dense_T = std::pair<Identifier_T, Value_T>;
|
||||
|
||||
static constexpr auto max_capacity = std::size_t { 1'000'000 };
|
||||
|
||||
static constexpr auto null_identifier = std::numeric_limits<Identifier_T>().max();
|
||||
|
||||
explicit SparseSet(std::size_t initial_capacity = 1)
|
||||
{
|
||||
debug::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 &
|
||||
{
|
||||
if (m_sparse.size() < identifier + 1)
|
||||
{
|
||||
auto new_capacity = std::max(
|
||||
static_cast<std::size_t>(identifier + 1),
|
||||
m_sparse.size() * 2
|
||||
);
|
||||
new_capacity = std::min(new_capacity, max_capacity);
|
||||
|
||||
// log::debug("Increasing sparse vector size:", m_dead_count);
|
||||
// log::debug("\tdead_count: {}", m_dead_count);
|
||||
// log::debug("\talive_count: {}", m_alive_count);
|
||||
// log::debug("\tsparse.size: {} -> {}", m_sparse.size(), new_capacity);
|
||||
|
||||
m_sparse.resize(new_capacity, null_identifier);
|
||||
}
|
||||
|
||||
++m_alive_count;
|
||||
m_sparse[identifier] = 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
|
||||
{
|
||||
auto &idx = m_sparse[identifier];
|
||||
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 -> std::size_t
|
||||
{
|
||||
return m_alive_count;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_capacity() const noexcept -> std::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;
|
||||
|
||||
std::size_t m_alive_count {};
|
||||
|
||||
std::size_t m_dead_count {};
|
||||
};
|
||||
|
||||
} // namespace lt::ecs
|
||||
163
modules/ecs/sparse_set.test.cpp
Normal file
163
modules/ecs/sparse_set.test.cpp
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
import ecs.sparse_set;
|
||||
import test.test;
|
||||
import test.expects;
|
||||
import std;
|
||||
|
||||
using ::lt::test::Case;
|
||||
using ::lt::test::expect_eq;
|
||||
using ::lt::test::expect_false;
|
||||
using ::lt::test::expect_ne;
|
||||
using ::lt::test::expect_throw;
|
||||
using ::lt::test::expect_true;
|
||||
using ::lt::test::Suite;
|
||||
using ::lt::test::operator""_suite;
|
||||
|
||||
using Set = lt::ecs::SparseSet<int>;
|
||||
constexpr auto capacity = 100;
|
||||
|
||||
Suite raii = "raii"_suite = [] {
|
||||
Case { "happy path won't throw" } = [] {
|
||||
std::ignore = Set {};
|
||||
std::ignore = Set { Set::max_capacity };
|
||||
};
|
||||
|
||||
Case { "unhappy path throws" } = [] {
|
||||
expect_throw([] { std::ignore = Set { Set::max_capacity + 1 }; });
|
||||
};
|
||||
|
||||
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 { "many inserts/removes won't freeze/throw" } = [] {
|
||||
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([&] { std::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(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(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, {});
|
||||
std::ignore = set.at(50);
|
||||
});
|
||||
}
|
||||
|
||||
set.insert(50, {});
|
||||
std::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);
|
||||
};
|
||||
};
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
add_executable(engine ${CMAKE_CURRENT_SOURCE_DIR}/private/entrypoint.cpp)
|
||||
target_link_libraries(engine PRIVATE pch)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
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;
|
||||
}
|
||||
70
modules/env/constants.cppm
vendored
Normal file
70
modules/env/constants.cppm
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
export module env;
|
||||
|
||||
import std;
|
||||
|
||||
namespace lt {
|
||||
|
||||
enum class Platform : std::uint8_t
|
||||
{
|
||||
/** The GNU/Linux platform.
|
||||
* Tested on the following distros: arch-x86_64
|
||||
* @note: Named like so because `linux` is a built-in identifier.
|
||||
* */
|
||||
gnu_linux,
|
||||
|
||||
/**
|
||||
* The Microsoft Windows(tm) platform.
|
||||
* Tested on the following architectures: x86_64
|
||||
*/
|
||||
windows,
|
||||
|
||||
/**
|
||||
* The apple's macOS platform.
|
||||
* Currently not supported.
|
||||
*/
|
||||
mac,
|
||||
};
|
||||
|
||||
/** The compiler that was used for compiling the project. */
|
||||
enum class Compiler : std::uint8_t
|
||||
{
|
||||
clang,
|
||||
gcc,
|
||||
msvc,
|
||||
apple_clang,
|
||||
};
|
||||
|
||||
namespace constants {
|
||||
|
||||
#if defined(LIGHT_PLATFORM_WINDOWS)
|
||||
#define lt_win(x)
|
||||
constexpr auto platform = Platform::windows;
|
||||
constexpr auto platform_name = "windows";
|
||||
|
||||
#undef LIGHT_PLATFORM_WINDOWS
|
||||
|
||||
#elif defined(LIGHT_PLATFORM_LINUX)
|
||||
constexpr auto platform = Platform::gnu_linux;
|
||||
constexpr auto platform_name = "gnu_linux";
|
||||
|
||||
#elif defined(LIGHT_PLATFORM_MAC)
|
||||
#define lt_mac(x) x
|
||||
constexpr auto platform = Platform::mac;
|
||||
constexpr auto platform_name = "mac";
|
||||
|
||||
#else
|
||||
#error "Unsupported platform: Unknown"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
constexpr auto compiler = Compiler::clang;
|
||||
constexpr auto compiler_name = "clang";
|
||||
|
||||
/** @todo(Light): insert the full identifier, including version information and such */
|
||||
constexpr auto full_compiler_identifier = "clang";
|
||||
#endif
|
||||
|
||||
} // namespace constants
|
||||
|
||||
} // namespace lt
|
||||
55
modules/input/components.cppm
Normal file
55
modules/input/components.cppm
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
export module input.system:components;
|
||||
import input.codes;
|
||||
import std;
|
||||
|
||||
namespace lt::input {
|
||||
|
||||
export struct Trigger
|
||||
{
|
||||
Key mapped_keycode;
|
||||
};
|
||||
|
||||
export struct InputAction
|
||||
{
|
||||
enum class State : std::uint8_t
|
||||
{
|
||||
inactive,
|
||||
active,
|
||||
triggered,
|
||||
cancelled,
|
||||
};
|
||||
|
||||
std::string name;
|
||||
|
||||
State state;
|
||||
|
||||
Trigger trigger;
|
||||
};
|
||||
|
||||
export class InputComponent
|
||||
{
|
||||
public:
|
||||
InputComponent() = default;
|
||||
|
||||
auto add_action(InputAction action) -> std::size_t
|
||||
{
|
||||
m_actions.emplace_back(std::move(action));
|
||||
return m_actions.size() - 1;
|
||||
}
|
||||
|
||||
auto get_action(std::size_t idx) -> const InputAction &
|
||||
{
|
||||
return m_actions[idx];
|
||||
}
|
||||
|
||||
private:
|
||||
friend class System;
|
||||
|
||||
void push_event()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<InputAction> m_actions;
|
||||
};
|
||||
|
||||
} // namespace lt::input
|
||||
41
modules/input/events.cppm
Normal file
41
modules/input/events.cppm
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
export module input.events;
|
||||
|
||||
import input.codes;
|
||||
import math.vec2;
|
||||
|
||||
import std;
|
||||
|
||||
namespace lt::input {
|
||||
|
||||
export class AnalogEvent
|
||||
{
|
||||
public:
|
||||
AnalogEvent(Key key, math::uvec2 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::uvec2
|
||||
{
|
||||
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::uvec2 m_pointer_position;
|
||||
};
|
||||
|
||||
} // namespace lt::input
|
||||
198
modules/input/system.cppm
Normal file
198
modules/input/system.cppm
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
export module input.system;
|
||||
export import :components;
|
||||
import logger;
|
||||
import app.system;
|
||||
import debug.assertions;
|
||||
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))
|
||||
{
|
||||
debug::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::debug("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::debug("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
|
||||
209
modules/input/system.test.cpp
Normal file
209
modules/input/system.test.cpp
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
import std;
|
||||
import input.system;
|
||||
import input.codes;
|
||||
import std;
|
||||
import test.test;
|
||||
import test.expects;
|
||||
import surface.events;
|
||||
import memory.scope;
|
||||
import memory.reference;
|
||||
import app.system;
|
||||
import ecs.entity;
|
||||
import ecs.registry;
|
||||
import surface.system;
|
||||
|
||||
|
||||
// NOLINTBEGIN
|
||||
using namespace lt;
|
||||
using input::InputComponent;
|
||||
using input::System;
|
||||
using std::ignore;
|
||||
using test::Case;
|
||||
using test::expect_eq;
|
||||
using test::expect_false;
|
||||
using test::expect_ne;
|
||||
using test::expect_not_nullptr;
|
||||
using test::operator""_suite;
|
||||
using test::expect_throw;
|
||||
using test::Suite;
|
||||
// NOLINTEND
|
||||
|
||||
[[nodiscard]] auto tick_info() -> 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() -> memory::Ref<ecs::Registry>
|
||||
{
|
||||
return m_registry;
|
||||
}
|
||||
|
||||
auto add_input_component() -> ecs::EntityId
|
||||
{
|
||||
auto entity = m_registry->create_entity();
|
||||
m_registry->add<InputComponent>(entity, {});
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
auto add_surface_component() -> ecs::EntityId
|
||||
{
|
||||
auto entity = m_registry->create_entity();
|
||||
m_surface_system.create_surface_component(
|
||||
entity,
|
||||
{ .title = "", .resolution = { 20u, 20u } }
|
||||
);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private:
|
||||
memory::Ref<ecs::Registry> m_registry = memory::create_ref<ecs::Registry>();
|
||||
|
||||
surface::System m_surface_system = surface::System { m_registry };
|
||||
};
|
||||
|
||||
Suite raii = "raii"_suite = "raii"_suite = [] {
|
||||
Case { "happy path won't throw" } = [&] {
|
||||
System { Fixture {}.registry() };
|
||||
};
|
||||
|
||||
Case { "many won't freeze/throw" } = [&] {
|
||||
auto fixture = Fixture {};
|
||||
for (auto idx : std::views::iota(0, 10'000))
|
||||
{
|
||||
ignore = System { fixture.registry() };
|
||||
}
|
||||
};
|
||||
|
||||
Case { "unhappy path throws" } = [] {
|
||||
expect_throw([] { ignore = System { {} }; });
|
||||
};
|
||||
};
|
||||
|
||||
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 };
|
||||
|
||||
const auto &entity = 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 = 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<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 },
|
||||
}
|
||||
);
|
||||
|
||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
||||
system.tick(tick_info());
|
||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
||||
|
||||
surface.push_event(surface::KeyPressedEvent(Key::A));
|
||||
system.tick(tick_info());
|
||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::triggered);
|
||||
|
||||
system.tick(tick_info());
|
||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::active);
|
||||
|
||||
system.tick(tick_info());
|
||||
system.tick(tick_info());
|
||||
system.tick(tick_info());
|
||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::active);
|
||||
|
||||
surface.push_event(surface::KeyReleasedEvent(Key::A));
|
||||
system.tick(tick_info());
|
||||
expect_eq(input.get_action(action_key).state, input::InputAction::State::inactive);
|
||||
};
|
||||
|
||||
Case { "Tick triggers" } = [] {
|
||||
auto fixture = Fixture {};
|
||||
auto registry = fixture.registry();
|
||||
auto system = System { fixture.registry() };
|
||||
|
||||
auto surface_entity = fixture.add_surface_component();
|
||||
auto &surface = registry->get<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 },
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
173
modules/input_codes/input_codes.cppm
Normal file
173
modules/input_codes/input_codes.cppm
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
export module input.codes;
|
||||
import std;
|
||||
|
||||
export enum class Key: std::uint16_t {
|
||||
/* digits */
|
||||
D0 = 48,
|
||||
D1 = 49,
|
||||
D2 = 50,
|
||||
D3 = 51,
|
||||
D4 = 52,
|
||||
D5 = 53,
|
||||
D6 = 54,
|
||||
D7 = 55,
|
||||
D8 = 56,
|
||||
D9 = 57,
|
||||
Semicolon = 59, // ;
|
||||
Equal = 61, // =
|
||||
|
||||
/* letters */
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
t = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90,
|
||||
|
||||
/* brackets */
|
||||
LeftBracket = 91, // [
|
||||
LBracket = LeftBracket, // [
|
||||
RightBracket = 93, // ]
|
||||
RBracket = RightBracket, // ]
|
||||
|
||||
/* arrow */
|
||||
Right = 262,
|
||||
RightArrow = Right,
|
||||
RArrow = Right,
|
||||
Left = 263,
|
||||
LeftArrow = Left,
|
||||
LArrow = Left,
|
||||
Down = 264,
|
||||
DownArrow = Down,
|
||||
DArrow = Down,
|
||||
Up = 265,
|
||||
UpArrow = Up,
|
||||
UArrow = Up,
|
||||
|
||||
/* page */
|
||||
PageUp = 266,
|
||||
PageDown = 267,
|
||||
|
||||
/* home/end */
|
||||
Home = 268,
|
||||
end = 269,
|
||||
|
||||
/* toggles */
|
||||
CapsLock = 280,
|
||||
ScrollLock = 281,
|
||||
NumLock = 282,
|
||||
NumberLock = NumLock,
|
||||
|
||||
/* function */
|
||||
F1 = 290,
|
||||
F2 = 291,
|
||||
F3 = 292,
|
||||
F4 = 293,
|
||||
F5 = 294,
|
||||
F6 = 295,
|
||||
F7 = 296,
|
||||
F8 = 297,
|
||||
F9 = 298,
|
||||
F10 = 299,
|
||||
F11 = 300,
|
||||
F12 = 301,
|
||||
F13 = 302,
|
||||
F14 = 303,
|
||||
F15 = 304,
|
||||
F16 = 305,
|
||||
F17 = 306,
|
||||
F18 = 307,
|
||||
F19 = 308,
|
||||
F20 = 309,
|
||||
F21 = 310,
|
||||
F22 = 311,
|
||||
F23 = 312,
|
||||
F24 = 313,
|
||||
F25 = 314,
|
||||
|
||||
/* keypad */
|
||||
Kp0 = 320,
|
||||
Kp1 = 321,
|
||||
Kp2 = 322,
|
||||
Kp3 = 323,
|
||||
Kp4 = 324,
|
||||
Kp5 = 325,
|
||||
Kp6 = 326,
|
||||
Kp7 = 327,
|
||||
Kp8 = 328,
|
||||
Kp9 = 329,
|
||||
KpDecimal = 330,
|
||||
KpDivide = 331,
|
||||
KpMultiply = 332,
|
||||
KpSubstract = 333,
|
||||
KpAdd = 334,
|
||||
KpEnter = 335,
|
||||
KpEqual = 336,
|
||||
|
||||
/* modifiers */
|
||||
LeftShift = 340,
|
||||
LShift = LeftShift,
|
||||
LeftControl = 341,
|
||||
LControl = LeftControl,
|
||||
LeftAlt = 342,
|
||||
LAlt = LeftAlt,
|
||||
LeftSuper = 343,
|
||||
LSuper = LeftSuper,
|
||||
RightShift = 344,
|
||||
RShift = 344,
|
||||
RightControl = 345,
|
||||
RControl = 345,
|
||||
RightAlt = 346,
|
||||
RAlt = 346,
|
||||
RightSuper = 347,
|
||||
RSuper = 347,
|
||||
|
||||
/* misc */
|
||||
Space = 32,
|
||||
Apostrophe = 39, // '
|
||||
Quote = Apostrophe,
|
||||
|
||||
Comma = 44, // ,
|
||||
Minus = 45, // -
|
||||
Period = 46, // .
|
||||
Slash = 47, // /
|
||||
ForwardSlash = Slash, // /
|
||||
BackSlash = 92, // \
|
||||
|
||||
GraveAccent = 96, // `
|
||||
Console = GraveAccent,
|
||||
World1 = 161, // non-US #1
|
||||
World2 = 162, // non-US #2
|
||||
Escape = 256,
|
||||
Esc = Escape,
|
||||
Enter = 257,
|
||||
Tab = 258,
|
||||
BackSpace = 259,
|
||||
Insert = 260,
|
||||
Delete = 261,
|
||||
|
||||
PrintScreen = 283,
|
||||
Pause = 284,
|
||||
|
||||
Menu = 348,
|
||||
};
|
||||
180
modules/logger/logger.cppm
Normal file
180
modules/logger/logger.cppm
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
export module logger;
|
||||
|
||||
import std;
|
||||
|
||||
namespace lt::log {
|
||||
|
||||
/** Severity of a log message. */
|
||||
enum class Level : std::uint8_t
|
||||
{
|
||||
/** 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,
|
||||
|
||||
/** No logging */
|
||||
off = 6,
|
||||
};
|
||||
|
||||
namespace details {
|
||||
|
||||
inline auto thread_hash_id() noexcept -> std::uint64_t
|
||||
{
|
||||
return static_cast<std::uint64_t>(std::hash<std::thread::id> {}(std::this_thread::get_id()));
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
|
||||
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
|
||||
{
|
||||
constexpr auto to_string = [](Level level, auto location) {
|
||||
// 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, location),
|
||||
std::format("{}:{}", path.filename().string(), location.line()),
|
||||
std::format(format, std::forward<Args>(arguments)...)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
print(Level, const std::source_location &, std::format_string<Args...>, Args &&...) noexcept
|
||||
-> print<Args...>;
|
||||
|
||||
export 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)...);
|
||||
}
|
||||
};
|
||||
|
||||
export template<typename... Args>
|
||||
trace(std::format_string<Args...>, Args &&...) noexcept -> trace<Args...>;
|
||||
|
||||
export 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)...);
|
||||
}
|
||||
};
|
||||
|
||||
export template<typename... Args>
|
||||
debug(std::format_string<Args...>, Args &&...) noexcept -> debug<Args...>;
|
||||
|
||||
export 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)...);
|
||||
}
|
||||
};
|
||||
|
||||
export template<typename... Args>
|
||||
info(std::format_string<Args...>, Args &&...) noexcept -> info<Args...>;
|
||||
|
||||
export 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)...);
|
||||
}
|
||||
};
|
||||
|
||||
export template<typename... Args>
|
||||
warn(std::format_string<Args...>, Args &&...) noexcept -> warn<Args...>;
|
||||
|
||||
export 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)...);
|
||||
}
|
||||
};
|
||||
|
||||
export template<typename... Args>
|
||||
error(std::format_string<Args...>, Args &&...) noexcept -> error<Args...>;
|
||||
|
||||
export 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)...);
|
||||
}
|
||||
};
|
||||
|
||||
export template<typename... Args>
|
||||
critical(std::format_string<Args...>, Args &&...) noexcept -> critical<Args...>;
|
||||
|
||||
} // namespace lt::log
|
||||
25
modules/logger/logger.test.cpp
Normal file
25
modules/logger/logger.test.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import logger;
|
||||
import test.test;
|
||||
|
||||
using ::lt::test::Case;
|
||||
using ::lt::test::Suite;
|
||||
|
||||
Suite suite = [] {
|
||||
Case { "no format" } = [] {
|
||||
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);
|
||||
};
|
||||
};
|
||||
60
modules/math/algebra.cppm
Normal file
60
modules/math/algebra.cppm
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
export module math.algebra;
|
||||
import math.mat4;
|
||||
import std;
|
||||
|
||||
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>
|
||||
constexpr auto perspective(T field_of_view, T aspect_ratio, T z_near, T z_far)
|
||||
{
|
||||
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
|
||||
16
modules/math/components.cppm
Normal file
16
modules/math/components.cppm
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
export module math.components;
|
||||
|
||||
import math.vec3;
|
||||
|
||||
namespace lt::math::components {
|
||||
|
||||
export struct Transform
|
||||
{
|
||||
math::vec3 translation;
|
||||
|
||||
math::vec3 scale;
|
||||
|
||||
math::vec3 rotation;
|
||||
};
|
||||
|
||||
} // namespace lt::math::components
|
||||
110
modules/math/mat4.cppm
Normal file
110
modules/math/mat4.cppm
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
export module math.mat4;
|
||||
import math.vec3;
|
||||
import math.vec4;
|
||||
import std;
|
||||
|
||||
namespace lt::math {
|
||||
|
||||
export template<typename T = float>
|
||||
struct mat4_impl
|
||||
{
|
||||
using Column_T = vec4_impl<T>;
|
||||
|
||||
constexpr explicit mat4_impl(T scalar = 0)
|
||||
: values(
|
||||
{
|
||||
Column_T { scalar },
|
||||
Column_T { scalar },
|
||||
Column_T { scalar },
|
||||
Column_T { scalar },
|
||||
}
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
constexpr mat4_impl(
|
||||
const T& x0, const T& y0, const T& z0, const T& w0,
|
||||
const T& x1, const T& y1, const T& z1, const T& w1,
|
||||
const T& x2, const T& y2, const T& z2, const T& w2,
|
||||
const T& x3, const T& y3, const T& z3, 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[](std::size_t idx) -> Column_T &
|
||||
{
|
||||
return values[idx];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto operator[](std::size_t idx) const -> const Column_T &
|
||||
{
|
||||
return values[idx];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto operator*(const mat4_impl<T> &other) const -> mat4_impl<T>
|
||||
{
|
||||
return mat4_impl<T> {};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto operator*(const vec4_impl<T> &other) const -> vec4_impl<T>
|
||||
{
|
||||
return vec4_impl<T> {};
|
||||
}
|
||||
|
||||
std::array<Column_T, 4> values; // NOLINT
|
||||
};
|
||||
|
||||
export template<typename T>
|
||||
[[nodiscard]] auto translate(const vec3_impl<T> &value) -> mat4_impl<T>
|
||||
{
|
||||
return mat4_impl<T> {};
|
||||
}
|
||||
|
||||
export template<typename T>
|
||||
[[nodiscard]] auto rotate(float value, const vec3_impl<T> &xyz) -> mat4_impl<T>
|
||||
{
|
||||
return mat4_impl<T> {};
|
||||
}
|
||||
|
||||
export template<typename T>
|
||||
[[nodiscard]] auto scale(const vec3_impl<T> &value) -> mat4_impl<T>
|
||||
{
|
||||
return mat4_impl<T> {};
|
||||
}
|
||||
|
||||
export template<typename T>
|
||||
[[nodiscard]] auto inverse(const mat4_impl<T> &value) -> mat4_impl<T>
|
||||
{
|
||||
return mat4_impl<T> {};
|
||||
}
|
||||
|
||||
export using mat4 = mat4_impl<float>;
|
||||
|
||||
export using imat4 = mat4_impl<std::int32_t>;
|
||||
|
||||
export using umat4 = mat4_impl<std::uint32_t>;
|
||||
|
||||
} // namespace lt::math
|
||||
26
modules/math/trig.cppm
Normal file
26
modules/math/trig.cppm
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
export module math.trig;
|
||||
|
||||
export namespace lt::math {
|
||||
|
||||
[[nodiscard]] constexpr auto radians(float degrees) -> float
|
||||
{
|
||||
return degrees * 0.01745329251994329576923690768489f;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto radians(double degrees) -> double
|
||||
{
|
||||
return degrees * 0.01745329251994329576923690768489;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto degrees(float radians) -> float
|
||||
{
|
||||
return radians * 57.295779513082320876798154814105f;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto degrees(double radians) -> double
|
||||
{
|
||||
return radians * 57.295779513082320876798154814105;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lt::math
|
||||
82
modules/math/vec2.cppm
Normal file
82
modules/math/vec2.cppm
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
export module math.vec2;
|
||||
|
||||
import std;
|
||||
|
||||
namespace lt::math {
|
||||
|
||||
export template<typename T = float>
|
||||
struct vec2_impl
|
||||
{
|
||||
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]] auto operator*(const vec2_impl<T> &other) const -> vec2_impl
|
||||
{
|
||||
return {
|
||||
x * other.x,
|
||||
y * other.y,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator-(const vec2_impl<T> &other) const -> vec2_impl
|
||||
{
|
||||
return {
|
||||
x - other.x,
|
||||
y - other.y,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] auto operator*(float scalar) const -> vec2_impl
|
||||
{
|
||||
return {
|
||||
x * scalar,
|
||||
y * scalar,
|
||||
};
|
||||
}
|
||||
|
||||
T x; // NOLINT
|
||||
|
||||
T y; // NOLINT
|
||||
};
|
||||
|
||||
|
||||
export using vec2 = vec2_impl<float>;
|
||||
|
||||
export using ivec2 = vec2_impl<std::int32_t>;
|
||||
|
||||
export using uvec2 = vec2_impl<std::uint32_t>;
|
||||
|
||||
} // 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);
|
||||
}
|
||||
};
|
||||
84
modules/math/vec3.cppm
Normal file
84
modules/math/vec3.cppm
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
export module math.vec3;
|
||||
|
||||
import math.vec2;
|
||||
import std;
|
||||
|
||||
namespace lt::math {
|
||||
|
||||
export template<typename T = float>
|
||||
struct vec3_impl
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
[[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,
|
||||
};
|
||||
}
|
||||
|
||||
friend auto operator<<(std::ostream &stream, vec3_impl<T> value) -> std::ostream &
|
||||
{
|
||||
stream << value.x << ", " << value.y << ", " << value.z;
|
||||
return stream;
|
||||
}
|
||||
|
||||
T x; // NOLINT
|
||||
|
||||
T y; // NOLINT
|
||||
|
||||
T z; // NOLINT
|
||||
};
|
||||
|
||||
export using vec3 = vec3_impl<float>;
|
||||
|
||||
export using ivec3 = vec3_impl<std::int32_t>;
|
||||
|
||||
export using uvec3 = vec3_impl<std::uint32_t>;
|
||||
|
||||
} // namespace lt::math
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
109
modules/math/vec4.cppm
Normal file
109
modules/math/vec4.cppm
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
export module math.vec4;
|
||||
import math.vec2;
|
||||
import math.vec3;
|
||||
import std;
|
||||
|
||||
namespace lt::math {
|
||||
|
||||
export template<typename T = float>
|
||||
struct vec4_impl
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
[[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[](std::size_t idx) -> T &
|
||||
{
|
||||
return values[idx];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto operator[](std::size_t idx) const -> const T &
|
||||
{
|
||||
return values[idx];
|
||||
}
|
||||
|
||||
friend auto operator<<(std::ostream &stream, vec4_impl<T> value) -> std::ostream &
|
||||
{
|
||||
stream << value.x << ", " << value.y << ", " << value.z << ", " << value.w;
|
||||
return stream;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
T x;
|
||||
|
||||
T y;
|
||||
|
||||
T z;
|
||||
|
||||
T w;
|
||||
};
|
||||
struct
|
||||
{
|
||||
T r;
|
||||
|
||||
T g;
|
||||
|
||||
T b;
|
||||
|
||||
T a;
|
||||
};
|
||||
struct
|
||||
{
|
||||
std::array<T, 4> values;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export using vec4 = vec4_impl<float>;
|
||||
|
||||
export using ivec4 = vec4_impl<std::int32_t>;
|
||||
|
||||
export using uvec4 = vec4_impl<std::uint32_t>;
|
||||
|
||||
} // 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);
|
||||
}
|
||||
};
|
||||
101
modules/memory/null_on_move.cppm
Normal file
101
modules/memory/null_on_move.cppm
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
export module memory.null_on_move;
|
||||
|
||||
import std;
|
||||
|
||||
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
|
||||
* Vulkan handles. But may serve other purposes, hence why I kept the implementation generic.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
operator std::uint64_t() const
|
||||
{
|
||||
return (std::uint64_t)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
|
||||
32
modules/memory/reference.cppm
Normal file
32
modules/memory/reference.cppm
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
export module memory.reference;
|
||||
|
||||
import std;
|
||||
|
||||
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
|
||||
32
modules/memory/scope.cppm
Normal file
32
modules/memory/scope.cppm
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
export module memory.scope;
|
||||
|
||||
import std;
|
||||
|
||||
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
|
||||
33
modules/mirror/entrypoint.cpp
Normal file
33
modules/mirror/entrypoint.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import app;
|
||||
import app.system;
|
||||
import std;
|
||||
import logger;
|
||||
import memory.scope;
|
||||
import mirror.system;
|
||||
import renderer.factory;
|
||||
|
||||
/** The ultimate entrypoint. */
|
||||
auto main(int argc, char *argv[]) -> std::int32_t
|
||||
{
|
||||
try
|
||||
{
|
||||
std::ignore = argc;
|
||||
std::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;
|
||||
}
|
||||
}
|
||||
227
modules/mirror/layers/editor_layer.cppm
Normal file
227
modules/mirror/layers/editor_layer.cppm
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
#pragma once
|
||||
|
||||
#include <app/layer.hpp>
|
||||
#include <imgui.h>
|
||||
#include <math/vec2.hpp>
|
||||
#include <memory/reference.hpp>
|
||||
#include <mirror/panels/asset_browser.hpp>
|
||||
#include <mirror/panels/properties.hpp>
|
||||
#include <mirror/panels/scene_hierarchy.hpp>
|
||||
#include <renderer/texture.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
class Scene;
|
||||
|
||||
class EditorLayer: public Layer
|
||||
{
|
||||
public:
|
||||
EditorLayer(const std::string &name);
|
||||
|
||||
~EditorLayer() override;
|
||||
|
||||
EditorLayer(EditorLayer &&) = delete;
|
||||
|
||||
EditorLayer(const EditorLayer &) = delete;
|
||||
|
||||
auto operator=(EditorLayer &&) const -> EditorLayer & = delete;
|
||||
|
||||
auto operator=(const EditorLayer &) const -> EditorLayer & = delete;
|
||||
|
||||
void on_update(float delta_time) override;
|
||||
|
||||
void on_render() override;
|
||||
|
||||
void on_user_interface_update() override;
|
||||
|
||||
private:
|
||||
std::string m_scene_dir;
|
||||
|
||||
math::vec2 m_direction;
|
||||
|
||||
float m_speed = 1000.0f;
|
||||
|
||||
memory::Ref<Scene> m_scene;
|
||||
|
||||
memory::Ref<SceneHierarchyPanel> m_sceneHierarchyPanel;
|
||||
|
||||
memory::Ref<PropertiesPanel> m_properties_panel;
|
||||
|
||||
memory::Ref<AssetBrowserPanel> m_content_browser_panel;
|
||||
|
||||
memory::Ref<Framebuffer> m_framebuffer;
|
||||
|
||||
Entity m_camera_entity;
|
||||
|
||||
ImVec2 m_available_content_region_prev;
|
||||
};
|
||||
|
||||
} // namespace lt
|
||||
|
||||
|
||||
#include <app/application.hpp>
|
||||
#include <asset_manager/asset_manager.hpp>
|
||||
#include <camera/component.hpp>
|
||||
#include <ecs/components.hpp>
|
||||
#include <ecs/registry.hpp>
|
||||
#include <ecs/serializer.hpp>
|
||||
#include <input/input.hpp>
|
||||
#include <input/key_codes.hpp>
|
||||
#include <math/vec4.hpp>
|
||||
#include <memory/reference.hpp>
|
||||
#include <mirror/layers/editor_layer.hpp>
|
||||
#include <renderer/framebuffer.hpp>
|
||||
#include <renderer/texture.hpp>
|
||||
#include <ui/ui.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
EditorLayer::EditorLayer(const std::string &name)
|
||||
: Layer(name)
|
||||
, m_scene_dir("")
|
||||
, m_direction { 0.0, 0.0 }
|
||||
{
|
||||
m_scene = memory::create_ref<Scene>();
|
||||
|
||||
m_properties_panel = memory::create_ref<PropertiesPanel>();
|
||||
m_sceneHierarchyPanel = memory::create_ref<SceneHierarchyPanel>(m_scene, m_properties_panel);
|
||||
m_content_browser_panel = memory::create_ref<AssetBrowserPanel>(m_scene);
|
||||
|
||||
m_framebuffer = Framebuffer::create(
|
||||
{
|
||||
.width = 1,
|
||||
.height = 1,
|
||||
.samples = 1,
|
||||
},
|
||||
GraphicsContext::get_shared_context()
|
||||
);
|
||||
|
||||
if (m_scene_dir.empty())
|
||||
{
|
||||
m_camera_entity = m_scene->create_entity("Camera");
|
||||
m_camera_entity.add_component<CameraComponent>(SceneCamera(), true);
|
||||
|
||||
AssetManager::load_texture("Awesomeface", "data/assets/textures/awesomeface.asset");
|
||||
|
||||
auto entity = Entity { m_scene->create_entity("Awesomeface", {}) };
|
||||
entity.add_component<SpriteRendererComponent>(
|
||||
AssetManager::get_texture("Awesomeface"),
|
||||
math::vec4 { 0.0f, 1.0f, 1.0f, 1.0f }
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto serializer = SceneSerializer { m_scene };
|
||||
ensure(serializer.deserialize(m_scene_dir), "Failed to de-serialize: {}", m_scene_dir);
|
||||
|
||||
// m_camera_entity = m_scene->GetEntityByTag("Game Camera");
|
||||
}
|
||||
}
|
||||
|
||||
EditorLayer::~EditorLayer()
|
||||
{
|
||||
if (!m_scene_dir.empty())
|
||||
{
|
||||
auto serializer = SceneSerializer { m_scene };
|
||||
serializer.serialize(m_scene_dir);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::on_update(float delta_time)
|
||||
{
|
||||
m_scene->on_update(delta_time);
|
||||
|
||||
if (Input::get_keyboard_key(Key::A))
|
||||
{
|
||||
m_direction.x = -1.0;
|
||||
}
|
||||
else if (Input::get_keyboard_key(Key::D))
|
||||
{
|
||||
m_direction.x = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_direction.x = 0.0;
|
||||
}
|
||||
|
||||
if (Input::get_keyboard_key(Key::S))
|
||||
{
|
||||
m_direction.y = -1.0;
|
||||
}
|
||||
else if (Input::get_keyboard_key(Key::W))
|
||||
{
|
||||
m_direction.y = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_direction.y = 0.0;
|
||||
}
|
||||
|
||||
auto &translation = m_camera_entity.get_component<TransformComponent>().translation;
|
||||
auto velocity = m_direction * m_speed * delta_time;
|
||||
translation = translation * math::vec3 { velocity.x, velocity.y, 0.0f };
|
||||
|
||||
if (Input::get_keyboard_key(Key::Escape))
|
||||
{
|
||||
Application::quit();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::on_render()
|
||||
{
|
||||
m_scene->on_render(m_framebuffer);
|
||||
}
|
||||
|
||||
void EditorLayer::on_user_interface_update()
|
||||
{
|
||||
UserInterface::dockspace_begin();
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
if (ImGui::Begin("Game"))
|
||||
{
|
||||
Input::receive_game_events(ImGui::IsWindowFocused());
|
||||
auto available_region = ImGui::GetContentRegionAvail();
|
||||
|
||||
if (m_available_content_region_prev.x != available_region.x
|
||||
|| m_available_content_region_prev.y != available_region.y)
|
||||
{
|
||||
m_framebuffer->resize(
|
||||
math::uvec2 {
|
||||
static_cast<uint32_t>(available_region.x),
|
||||
static_cast<uint32_t>(available_region.y),
|
||||
}
|
||||
);
|
||||
auto &camera = m_camera_entity.get_component<CameraComponent>().camera;
|
||||
camera.set_viewport_size(
|
||||
static_cast<uint32_t>(available_region.x),
|
||||
static_cast<uint32_t>(available_region.y)
|
||||
);
|
||||
|
||||
m_available_content_region_prev = available_region;
|
||||
}
|
||||
|
||||
if (GraphicsContext::get_graphics_api() == GraphicsAPI::DirectX)
|
||||
{
|
||||
ImGui::Image(m_framebuffer->get_color_attachment(), available_region);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Image(
|
||||
m_framebuffer->get_color_attachment(),
|
||||
available_region,
|
||||
ImVec2(0, 1),
|
||||
ImVec2(1, 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
// Panels
|
||||
m_sceneHierarchyPanel->on_user_interface_update();
|
||||
m_properties_panel->on_user_interface_update();
|
||||
m_content_browser_panel->on_user_interface_update();
|
||||
|
||||
UserInterface::dockspace_end();
|
||||
}
|
||||
|
||||
} // namespace lt
|
||||
0
modules/mirror/layers/editor_layer.test.cpp
Normal file
0
modules/mirror/layers/editor_layer.test.cpp
Normal file
200
modules/mirror/panels/asset_browser.cppm
Normal file
200
modules/mirror/panels/asset_browser.cppm
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory/reference.hpp>
|
||||
#include <mirror/panels/panel.hpp>
|
||||
#include <renderer/texture.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
class Scene;
|
||||
|
||||
class AssetBrowserPanel: public Panel
|
||||
{
|
||||
public:
|
||||
AssetBrowserPanel(memory::Ref<Scene> active_scene);
|
||||
|
||||
void on_user_interface_update();
|
||||
|
||||
private:
|
||||
enum class AssetType
|
||||
{
|
||||
none = 0,
|
||||
scene,
|
||||
directory,
|
||||
text,
|
||||
image,
|
||||
};
|
||||
|
||||
std::filesystem::path m_current_directory;
|
||||
|
||||
const std::filesystem::path m_assets_path;
|
||||
|
||||
float m_file_size = 128.0f;
|
||||
|
||||
float m_file_padding = 8.0f;
|
||||
|
||||
memory::Ref<Scene> m_active_scene;
|
||||
|
||||
memory::Ref<Texture> m_directory_texture;
|
||||
|
||||
memory::Ref<Texture> m_scene_texture;
|
||||
|
||||
memory::Ref<Texture> m_image_texture;
|
||||
|
||||
memory::Ref<Texture> m_text_texture;
|
||||
};
|
||||
|
||||
} // namespace lt
|
||||
#include <asset_manager/asset_manager.hpp>
|
||||
#include <ecs/registry.hpp>
|
||||
#include <ecs/serializer.hpp>
|
||||
#include <imgui.h>
|
||||
#include <memory/reference.hpp>
|
||||
#include <mirror/panels/asset_browser.hpp>
|
||||
#include <renderer/texture.hpp>
|
||||
|
||||
namespace lt {
|
||||
|
||||
AssetBrowserPanel::AssetBrowserPanel(memory::Ref<Scene> active_scene)
|
||||
: m_current_directory("./data/assets")
|
||||
, m_assets_path("./data/assets")
|
||||
, m_active_scene(std::move(active_scene))
|
||||
{
|
||||
AssetManager::load_texture("_Assets_Directory", "data/engine/icons/asset/dir.asset");
|
||||
AssetManager::load_texture("_Assets_Scene", "data/engine/icons/asset/scene.asset");
|
||||
AssetManager::load_texture("_Assets_Image", "data/engine/icons/asset/img.asset");
|
||||
AssetManager::load_texture("_Assets_Text", "data/engine/icons/asset/txt.asset");
|
||||
|
||||
m_directory_texture = AssetManager::get_texture("_Assets_Directory");
|
||||
m_scene_texture = AssetManager::get_texture("_Assets_Scene");
|
||||
m_image_texture = AssetManager::get_texture("_Assets_Image");
|
||||
m_text_texture = AssetManager::get_texture("_Assets_Text");
|
||||
}
|
||||
|
||||
void AssetBrowserPanel::on_user_interface_update()
|
||||
{
|
||||
ImGui::Begin("Content Browser");
|
||||
|
||||
// Parent directory button
|
||||
if (m_current_directory != std::filesystem::path("data/assets"))
|
||||
{
|
||||
if (ImGui::Button(" <-- "))
|
||||
{
|
||||
m_current_directory = m_current_directory.parent_path();
|
||||
}
|
||||
}
|
||||
|
||||
const auto available_region = ImGui::GetContentRegionAvail();
|
||||
const auto cell_size = m_file_size + m_file_padding;
|
||||
const auto column_count = std::clamp(
|
||||
static_cast<uint32_t>(std::floor(available_region.x / cell_size)),
|
||||
1u,
|
||||
64u
|
||||
);
|
||||
|
||||
if (ImGui::BeginTable("ContentBrowser", static_cast<int>(column_count)))
|
||||
{
|
||||
m_directory_texture->bind(0u);
|
||||
for (const auto &directory_entry : std::filesystem::directory_iterator(m_current_directory))
|
||||
{
|
||||
const auto &path = directory_entry.path();
|
||||
auto extension = directory_entry.path().extension().string();
|
||||
|
||||
auto asset_type = AssetType {};
|
||||
|
||||
if (extension.empty())
|
||||
{
|
||||
asset_type = AssetType::directory;
|
||||
}
|
||||
else if (extension == ".txt" || extension == ".glsl")
|
||||
{
|
||||
asset_type = AssetType::text;
|
||||
}
|
||||
else if (extension == ".png")
|
||||
{
|
||||
asset_type = AssetType::image;
|
||||
}
|
||||
else if (extension == ".scene")
|
||||
{
|
||||
asset_type = AssetType::scene;
|
||||
}
|
||||
else
|
||||
{
|
||||
asset_type = AssetType::none;
|
||||
}
|
||||
|
||||
// Extension not supported
|
||||
if (asset_type == AssetType::none)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Button
|
||||
const auto path_str = path.string();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::PushID(path_str.c_str());
|
||||
switch (asset_type)
|
||||
{
|
||||
// Directory
|
||||
case AssetType::directory:
|
||||
if (ImGui::ImageButton(
|
||||
path_str.c_str(),
|
||||
m_directory_texture->get_texture(),
|
||||
ImVec2(m_file_size, m_file_size)
|
||||
))
|
||||
{
|
||||
m_current_directory /= path.filename();
|
||||
}
|
||||
break;
|
||||
|
||||
// Scene
|
||||
case AssetType::scene:
|
||||
if (ImGui::ImageButton(
|
||||
path_str.c_str(),
|
||||
m_scene_texture->get_texture(),
|
||||
ImVec2(m_file_size, m_file_size)
|
||||
))
|
||||
{
|
||||
auto serializer = SceneSerializer { m_active_scene };
|
||||
log::info("Attempting to deserialize: {}", path.string());
|
||||
serializer.deserialize(path.string());
|
||||
}
|
||||
break;
|
||||
|
||||
// Image
|
||||
case AssetType::image:
|
||||
if (ImGui::ImageButton(
|
||||
path_str.c_str(),
|
||||
m_image_texture->get_texture(),
|
||||
ImVec2(m_file_size, m_file_size)
|
||||
))
|
||||
{
|
||||
}
|
||||
break;
|
||||
|
||||
// Text
|
||||
case AssetType::text:
|
||||
if (ImGui::ImageButton(
|
||||
path_str.c_str(),
|
||||
m_text_texture->get_texture(),
|
||||
ImVec2(m_file_size, m_file_size)
|
||||
))
|
||||
{
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default: break;
|
||||
}
|
||||
// Label
|
||||
ImGui::TextUnformatted(std::format("{}", path.filename().string()).c_str());
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // 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