Everywhere: Update work in progress
This commit is contained in:
+5
-1
@@ -14,14 +14,17 @@ AlignTrailingComments: true
|
|||||||
AllowAllArgumentsOnNextLine: false
|
AllowAllArgumentsOnNextLine: false
|
||||||
AllowAllConstructorInitializersOnNextLine: true
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
|
||||||
AlwaysBreakTemplateDeclarations: Yes
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
IndentPPDirectives: BeforeHash
|
||||||
|
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
AfterEnum: false
|
AfterEnum: false
|
||||||
AfterFunction: true
|
AfterFunction: true
|
||||||
BeforeCatch: true
|
BeforeCatch: true
|
||||||
BeforeElse: true
|
BeforeElse: true
|
||||||
|
BeforeLambdaBody: false
|
||||||
SplitEmptyRecord: false
|
SplitEmptyRecord: false
|
||||||
BreakBeforeBraces: Custom
|
BreakBeforeBraces: Custom
|
||||||
BreakInheritanceList: BeforeComma
|
BreakInheritanceList: BeforeComma
|
||||||
@@ -29,7 +32,8 @@ BreakInheritanceList: BeforeComma
|
|||||||
SpaceAfterTemplateKeyword: false
|
SpaceAfterTemplateKeyword: false
|
||||||
SpaceInEmptyBlock: false
|
SpaceInEmptyBlock: false
|
||||||
NamespaceIndentation: None
|
NamespaceIndentation: None
|
||||||
Standard: c++11
|
FixNamespaceComments: true
|
||||||
|
Standard: c++17
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
UseTab: AlignWithSpaces
|
UseTab: AlignWithSpaces
|
||||||
...
|
...
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
@@ -27,6 +27,7 @@ void main()
|
|||||||
vec4 textureColor = v_color;
|
vec4 textureColor = v_color;
|
||||||
switch(int(v_textureIndex)) {
|
switch(int(v_textureIndex)) {
|
||||||
case 0: break; // Texture unit 0 is reserved for no texture
|
case 0: break; // Texture unit 0 is reserved for no texture
|
||||||
|
// case 1: textureColor.a = 1; break;
|
||||||
case 1: textureColor.a = alpha(texture(u_textures[1], v_textureCoordinates).a); break;
|
case 1: textureColor.a = alpha(texture(u_textures[1], v_textureCoordinates).a); break;
|
||||||
// case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
// case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
||||||
case 2: textureColor.a = alpha(texture(u_textures[2], v_textureCoordinates).a); break;
|
case 2: textureColor.a = alpha(texture(u_textures[2], v_textureCoordinates).a); break;
|
||||||
|
|||||||
@@ -33,4 +33,7 @@ void main()
|
|||||||
v_borderColor = a_borderColor;
|
v_borderColor = a_borderColor;
|
||||||
v_offset = a_offset;
|
v_offset = a_offset;
|
||||||
gl_Position = vec4(a_position, 1.0f);
|
gl_Position = vec4(a_position, 1.0f);
|
||||||
|
|
||||||
|
// Vclip = Camera projection * Camera view * Model transform * Vlocal
|
||||||
|
// gl_Position = u_projectionView * vec4(a_position, 1.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -9,9 +9,12 @@
|
|||||||
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
|
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
|
||||||
cd "$scriptPath/.." || exit 1
|
cd "$scriptPath/.." || exit 1
|
||||||
|
|
||||||
green=$(tput setf 2)
|
# Get all files staged for commit
|
||||||
red=$(tput setf 4)
|
files="$(git --no-pager diff --cached --name-only)"
|
||||||
nc=$(tput sgr0)
|
|
||||||
|
green="$(tput setf 2)"
|
||||||
|
red="$(tput setf 4)"
|
||||||
|
nc="$(tput sgr0)"
|
||||||
|
|
||||||
failures=0
|
failures=0
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ lint-shell-script.sh
|
|||||||
|
|
||||||
for linter in $linters; do
|
for linter in $linters; do
|
||||||
echo "Running script/$linter"
|
echo "Running script/$linter"
|
||||||
if "script/$linter"; then
|
if "script/$linter" "$files"; then
|
||||||
echo "[${green}PASS${nc}]: script/$linter"
|
echo "[${green}PASS${nc}]: script/$linter"
|
||||||
else
|
else
|
||||||
echo "[${red}FAIL${nc}]: script/$linter"
|
echo "[${red}FAIL${nc}]: script/$linter"
|
||||||
@@ -29,12 +32,9 @@ for linter in $linters; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Get all files staged for commit
|
|
||||||
files="$(git diff --cached --name-only)"
|
|
||||||
|
|
||||||
echo "Running script/lint-clang-format.sh"
|
echo "Running script/lint-clang-format.sh"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if script/lint-clang-format.sh && git diff --exit-code $files; then
|
if script/lint-clang-format.sh "$files" && git diff --exit-code $files; then
|
||||||
echo "[${green}PASS${nc}]: script/lint-clang-format.sh"
|
echo "[${green}PASS${nc}]: script/lint-clang-format.sh"
|
||||||
else
|
else
|
||||||
echo "[${red}FAIL${nc}]: script/lint-clang-format.sh"
|
echo "[${red}FAIL${nc}]: script/lint-clang-format.sh"
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
files=$(git ls-files -- '*.cpp' '*.h' ':!:inferno/vendor')
|
files="${1:-$(git --no-pager diff --cached --name-only)}"
|
||||||
|
files="$(echo "$files" | grep -E '\.(cpp|h)$')"
|
||||||
|
|
||||||
if [ -z "$files" ]; then
|
if [ -z "$files" ]; then
|
||||||
echo "No .cpp or .h files to check."
|
echo "No .cpp or .h files to check."
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ if ! command -v shellcheck > /dev/null 2>&1; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
files=$(git ls-files -- '*.sh' ':!:inferno/vendor')
|
files="${1:-$(git --no-pager diff --cached --name-only)}"
|
||||||
|
files="$(echo "$files" | grep -E '\.sh$')"
|
||||||
|
|
||||||
if [ -z "$files" ]; then
|
if [ -z "$files" ]; then
|
||||||
echo "No .sh files to check."
|
echo "No .sh files to check."
|
||||||
|
|||||||
+24
-13
@@ -7,23 +7,24 @@
|
|||||||
|
|
||||||
scriptName="$(basename "$0")"
|
scriptName="$(basename "$0")"
|
||||||
|
|
||||||
help() {
|
b="$(tput bold)"
|
||||||
b=$(tput bold)
|
u="$(tput smul)"
|
||||||
u=$(tput smul)
|
red="$(tput setf 4)"
|
||||||
nc=$(tput sgr0)
|
n="$(tput sgr0)"
|
||||||
|
|
||||||
|
help() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
${b}NAME${nc}
|
${b}NAME${n}
|
||||||
${scriptName} - manage pre-commit hooks
|
${scriptName} - manage pre-commit hooks
|
||||||
|
|
||||||
${b}SYNOPSIS${nc}
|
${b}SYNOPSIS${n}
|
||||||
${b}${scriptName}${nc} ${u}COMMAND${nc}
|
${b}${scriptName}${n} ${u}COMMAND${n}
|
||||||
|
|
||||||
${b}COMMANDS${nc}
|
${b}COMMANDS${n}
|
||||||
${b}install${nc}
|
${b}install${n}
|
||||||
Install all pre-commit hooks.
|
Install all pre-commit hooks.
|
||||||
|
|
||||||
${b}remove${nc}
|
${b}remove${n}
|
||||||
Remove all pre-commit hooks.
|
Remove all pre-commit hooks.
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@@ -31,8 +32,18 @@ EOF
|
|||||||
# Exit if no option is provided
|
# Exit if no option is provided
|
||||||
[ "$#" -eq 0 ] && help && exit 1
|
[ "$#" -eq 0 ] && help && exit 1
|
||||||
|
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
echo "${b}${red}Error:${n} please run this script from the project root." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
currentDir="$(pwd -P)"
|
||||||
|
|
||||||
|
# Get the path from the project root to the script
|
||||||
|
subDir="$(dirname -- "$0")"
|
||||||
|
|
||||||
# Get the full path to this script while handling spaces and symlinks correctly
|
# Get the full path to this script while handling spaces and symlinks correctly
|
||||||
scriptPath="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
|
scriptPath="$(cd -P -- "$subDir" && pwd -P)"
|
||||||
cd "$scriptPath/.." || exit 1
|
cd "$scriptPath/.." || exit 1
|
||||||
|
|
||||||
hooks="
|
hooks="
|
||||||
@@ -42,7 +53,7 @@ lint-ci.sh
|
|||||||
install() {
|
install() {
|
||||||
echo "Installing pre-commit hooks"
|
echo "Installing pre-commit hooks"
|
||||||
|
|
||||||
preCommit=".git/hooks/pre-commit"
|
preCommit="$currentDir/.git/hooks/pre-commit"
|
||||||
if ! test -f "$preCommit"; then
|
if ! test -f "$preCommit"; then
|
||||||
touch "$preCommit"
|
touch "$preCommit"
|
||||||
chmod +x "$preCommit"
|
chmod +x "$preCommit"
|
||||||
@@ -51,7 +62,7 @@ install() {
|
|||||||
|
|
||||||
for hook in $hooks; do
|
for hook in $hooks; do
|
||||||
sed -Ei "/$hook/d" "$preCommit"
|
sed -Ei "/$hook/d" "$preCommit"
|
||||||
sed -Ei "\$ a script/$hook" "$preCommit"
|
sed -Ei "\$ a $subDir/$hook" "$preCommit"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "glm/gtc/type_ptr.hpp" // glm::make_mat4
|
||||||
|
|
||||||
#include "inferno/application.h"
|
#include "inferno/application.h"
|
||||||
#include "inferno/assert.h"
|
#include "inferno/assert.h"
|
||||||
#include "inferno/core.h"
|
#include "inferno/core.h"
|
||||||
@@ -5,12 +7,14 @@
|
|||||||
#include "inferno/event/event.h"
|
#include "inferno/event/event.h"
|
||||||
#include "inferno/event/keyevent.h"
|
#include "inferno/event/keyevent.h"
|
||||||
#include "inferno/event/mouseevent.h"
|
#include "inferno/event/mouseevent.h"
|
||||||
#include "inferno/keycodes.h"
|
#include "inferno/io/gltffile.h"
|
||||||
#include "inferno/io/input.h"
|
#include "inferno/io/input.h"
|
||||||
#include "inferno/io/log.h"
|
#include "inferno/io/log.h"
|
||||||
|
#include "inferno/keycodes.h"
|
||||||
#include "inferno/render/buffer.h"
|
#include "inferno/render/buffer.h"
|
||||||
#include "inferno/render/context.h"
|
#include "inferno/render/context.h"
|
||||||
#include "inferno/render/font.h"
|
#include "inferno/render/font.h"
|
||||||
|
#include "inferno/render/gltf.h"
|
||||||
#include "inferno/render/renderer.h"
|
#include "inferno/render/renderer.h"
|
||||||
#include "inferno/render/shader.h"
|
#include "inferno/render/shader.h"
|
||||||
#include "inferno/render/texture.h"
|
#include "inferno/render/texture.h"
|
||||||
@@ -18,6 +22,7 @@
|
|||||||
#include "inferno/settings.h"
|
#include "inferno/settings.h"
|
||||||
#include "inferno/time.h"
|
#include "inferno/time.h"
|
||||||
#include "inferno/window.h"
|
#include "inferno/window.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
@@ -47,6 +52,20 @@ namespace Inferno {
|
|||||||
// Load assets
|
// Load assets
|
||||||
|
|
||||||
m_font = FontManager::the().load("assets/fnt/dejavu-sans");
|
m_font = FontManager::the().load("assets/fnt/dejavu-sans");
|
||||||
|
|
||||||
|
// auto bla = GlTFFile::read("assets/gltf/box.glb");
|
||||||
|
// success() << "@" << bla.first.get() << "@";
|
||||||
|
// auto bla2 = GlTFFile::read("assets/gltf/boxtextured.glb");
|
||||||
|
// info() << "@" << bla2.first.get() << "@";
|
||||||
|
// auto bla3 = GlTFFile::read("assets/gltf/guinea-pig-cage-fleece.glb");
|
||||||
|
// warn() << "@" << bla3.first.get() << "@";
|
||||||
|
|
||||||
|
// Gltf model = Gltf("assets/gltf/box.glb");
|
||||||
|
|
||||||
|
// Gltf model = Gltf("assets/gltf/animatedmorphcube.glb");
|
||||||
|
// Gltf model = Gltf("assets/gltf/reciprocatingsaw.glb");
|
||||||
|
|
||||||
|
Gltf model = Gltf("assets/gltf/triangle-without-indices.gltf");
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
@@ -138,7 +157,7 @@ namespace Inferno {
|
|||||||
RendererCharacter::the().beginScene();
|
RendererCharacter::the().beginScene();
|
||||||
|
|
||||||
m_scene->render();
|
m_scene->render();
|
||||||
RendererCharacter::the().drawCharacter(character, f->texture());
|
// RendererCharacter::the().drawCharacter(character, f->texture());
|
||||||
|
|
||||||
Renderer2D::the().endScene();
|
Renderer2D::the().endScene();
|
||||||
RendererCharacter::the().endScene();
|
RendererCharacter::the().endScene();
|
||||||
@@ -167,6 +186,7 @@ namespace Inferno {
|
|||||||
(void)e;
|
(void)e;
|
||||||
|
|
||||||
info() << "WindowCloseEvent triggered";
|
info() << "WindowCloseEvent triggered";
|
||||||
|
infoln("{}Event triggered", e.toString());
|
||||||
|
|
||||||
m_window->setShouldClose(true);
|
m_window->setShouldClose(true);
|
||||||
|
|
||||||
|
|||||||
+27
-16
@@ -53,37 +53,48 @@ namespace Inferno {
|
|||||||
#endif // APPLICATION_H
|
#endif // APPLICATION_H
|
||||||
|
|
||||||
// C++17 features used:
|
// C++17 features used:
|
||||||
// - std::string:view, log.h
|
// - std::string_view -> log.h
|
||||||
// - std::shared_ptr array management, renderer.h
|
// - std::shared_ptr array management -> renderer.h
|
||||||
|
// - EnTT library
|
||||||
|
// - structured binding -> render.cpp, camera.cpp
|
||||||
|
// - std::optional -> textareasystem.cpp
|
||||||
|
|
||||||
// OpenGL 4.5 features used:
|
// OpenGL 4.5 features used:
|
||||||
// -
|
// -
|
||||||
|
|
||||||
|
// Cmake 3.16 features used:
|
||||||
|
// - Precompiled headers
|
||||||
|
|
||||||
// Gameplan
|
// Gameplan
|
||||||
// v Entrypoint
|
|
||||||
// v Logging
|
|
||||||
// v Events
|
|
||||||
// v Window
|
|
||||||
// v Settings loader (json)
|
|
||||||
// v Input polling
|
|
||||||
// v OpenGL context
|
|
||||||
// - GPUDriver (?)
|
// - GPUDriver (?)
|
||||||
// v Renderer
|
// v Renderer
|
||||||
// v Buffers
|
// v Buffers
|
||||||
// ~ Shader
|
// ~ Shader
|
||||||
// - Schene (camera, lights, environment)
|
// - Schene (camera, lights, environment)
|
||||||
// - Texture loading
|
|
||||||
// - Model loading
|
// - Model loading
|
||||||
// - Entity Component System
|
|
||||||
// - Serialization
|
// - Serialization
|
||||||
// - Level format
|
// - Level format
|
||||||
// - Tools (Tiled?)
|
// - Tools (Tiled?)
|
||||||
// - Scripting (Lua)
|
|
||||||
|
|
||||||
// - Global object access can be done in 3 ways:
|
// - Global object access can be done in 4 ways:
|
||||||
// - Singleton, static, extern
|
// - Singleton, static class, extern, regular global
|
||||||
|
|
||||||
// @Todo
|
// @Todo
|
||||||
// - Settings should contain all file paths (ex: shaders)
|
|
||||||
// - RefPtr<>
|
// - RefPtr<>
|
||||||
// - Rename Application::get() to Application::the() for singleton
|
// - keycodes.h stringify helper in code.h (util/types.h, util/defines.h)
|
||||||
|
// https://github.com/SerenityOS/serenity/blob/master/Kernel/Assertions.h#L29
|
||||||
|
// - Call delete on pointers that make the singletons, so valgrind will say "All heap blocks were freed -- no leaks are possible", in "HEAP SUMMARY"
|
||||||
|
// - TagComponent, string -> char[]
|
||||||
|
// - Move Gltf parsing and json helper to /parser directory
|
||||||
|
|
||||||
|
// - Initialize primitive types, raw pointers are uninitialized, so need to be explicitly initialized to nullptr
|
||||||
|
// - Run clang-format on every file
|
||||||
|
|
||||||
|
// profiling: 1:33:08 - JS bytecode VM part 7
|
||||||
|
// $ valgrind --tool=callgrind <executable>
|
||||||
|
// $ kcachegrind callgrind.out.<number>
|
||||||
|
|
||||||
|
// GUI
|
||||||
|
// Framebuffer on entire screen, manage every individual pixel
|
||||||
|
// - classes: Window, Button, Label
|
||||||
|
// - event loop: select based
|
||||||
|
|||||||
+65
-13
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
#include <csignal> // raise
|
#include <csignal> // raise
|
||||||
#include <cstdint> // uint32_t
|
#include <cstdint> // uint32_t
|
||||||
|
#include <cstdio> // fflush
|
||||||
|
#include <cstring> // strlen
|
||||||
|
#include <fstream> // ifstream
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "inferno/core.h"
|
#include "inferno/core.h"
|
||||||
#include "inferno/io/log.h"
|
#include "inferno/io/log.h"
|
||||||
@@ -15,50 +19,98 @@
|
|||||||
#ifdef NF_ENABLE_ASSERTS
|
#ifdef NF_ENABLE_ASSERTS
|
||||||
// Check if SIGTRAP is available
|
// Check if SIGTRAP is available
|
||||||
#ifdef SIGTRAP
|
#ifdef SIGTRAP
|
||||||
#define ABORT_SIGNAL SIGTRAP
|
#define ABORT_SIGNAL SIGTRAP // POSIX
|
||||||
#else
|
#else
|
||||||
#define ABORT_SIGNAL SIGABRT
|
#define ABORT_SIGNAL SIGABRT // C99
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Non-standard function macro
|
// Non-standard function macro
|
||||||
#ifdef GCC
|
#ifdef GCC
|
||||||
#define FUNCTION_MACRO __PRETTY_FUNCTION__
|
#define FUNCTION_MACRO __PRETTY_FUNCTION__ // GCC extension
|
||||||
#elif MSVC
|
#elif MSVC
|
||||||
#define FUNCTION_MACRO __FUNCSIG__
|
#define FUNCTION_MACRO __FUNCSIG__
|
||||||
#else
|
#else
|
||||||
#define FUNCTION_MACRO __func__
|
#define FUNCTION_MACRO __func__ // C99
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ##__VA_ARGS__ is a non-standard GCC extension, C++20 introduces __VA_OPT__
|
// ##__VA_ARGS__ is a non-standard GCC extension, C++20 introduces __VA_OPT__
|
||||||
// https://stackoverflow.com/questions/52891546/what-does-va-args-mean
|
// https://stackoverflow.com/questions/52891546/what-does-va-args-mean
|
||||||
#define ASSERT(expr, ...) static_cast<bool>(expr) ? (void)0 : Inferno::__assert_fail(#expr, __FILE__, __LINE__, FUNCTION_MACRO, ##__VA_ARGS__)
|
#define ASSERT(expr, ...) (static_cast<bool>(expr) ? (void)0 : Inferno::__assert_fail(#expr, __FILE__, __LINE__, FUNCTION_MACRO, ##__VA_ARGS__))
|
||||||
#define ASSERT_NOT_REACHED() ASSERT(false)
|
#define ASSERT_NOT_REACHED() ASSERT(false)
|
||||||
#else
|
#else
|
||||||
#define ASSERT(expr, ...)
|
#define ASSERT(expr, ...) (static_cast<void>(0))
|
||||||
#define ASSERT_NOT_REACHED() CRASH()
|
#define ASSERT_NOT_REACHED() CRASH()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CRASH() raise(SIGABRT)
|
#define CRASH() Inferno::__crash();
|
||||||
|
// https://stackoverflow.com/questions/1440570/likely-unlikely-equivalent-for-msvc
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
|
inline void __crash()
|
||||||
|
{
|
||||||
|
asm volatile("int $0x03");
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Doesnt print to stderr
|
||||||
#ifdef NF_ENABLE_ASSERTS
|
#ifdef NF_ENABLE_ASSERTS
|
||||||
template<typename... P>
|
template<typename... P>
|
||||||
inline void __assert_fail(const char* assertion, const char* file, uint32_t line, const char* function, P&&... parameters)
|
inline void __assert_fail(const char* assertion, const char* file, uint32_t line, const char* function, P&&... parameters)
|
||||||
{
|
{
|
||||||
dangerln(false, "ASSERTION `{}' FAILED.", assertion);
|
(void)function;
|
||||||
|
|
||||||
if (sizeof...(P) > 0) {
|
// Get the line that caused the error
|
||||||
dbg(false) << " ";
|
std::ifstream source(file);
|
||||||
dbgln(Log::Danger, false, std::forward<P>(parameters)...);
|
std::string content;
|
||||||
|
if (source.is_open()) {
|
||||||
|
for (uint32_t i = 0; std::getline(source, content); ++i) {
|
||||||
|
if (i == line - 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Replace tab indentation with spaces
|
||||||
|
size_t tabs = content.find_first_not_of('\t');
|
||||||
|
if (tabs > 0 && tabs < content.size()) {
|
||||||
|
content = std::string(tabs * 4, ' ') + content.substr(tabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
danger() << "\n " << file << ":" << line << " in " << function;
|
// Find the assertion in the line
|
||||||
|
size_t column = content.find_first_of(assertion);
|
||||||
|
size_t assertionLength = strlen(assertion);
|
||||||
|
if (column == std::string::npos) {
|
||||||
|
column = content.find_first_not_of(' ');
|
||||||
|
assertionLength = content.length() - column;
|
||||||
|
}
|
||||||
|
|
||||||
raise(ABORT_SIGNAL);
|
// Error message
|
||||||
|
dbgln(false, "\033[0;1m{}:{}:{}: ", file, line, column + 1);
|
||||||
|
dangerln(false, "error: ");
|
||||||
|
dbgln(false, "assertion failed");
|
||||||
|
if (sizeof...(P) > 0) {
|
||||||
|
dbgln(false, ": ");
|
||||||
|
dbgln(Log::None, false, std::forward<P>(parameters)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Code line
|
||||||
|
dbgln("\n {} | {}\033[31;1m{}\033[0m{}", line,
|
||||||
|
content.substr(0, column), // Whitespace at front
|
||||||
|
content.substr(column, assertionLength), // Error portion
|
||||||
|
content.substr(column + assertionLength)); // Rest of the line
|
||||||
|
|
||||||
|
// Arrow pointer
|
||||||
|
dbgln(" {} | {}\033[31;1m^{}\033[0m",
|
||||||
|
std::string(std::to_string(line).length(), ' '), // Line number spacing
|
||||||
|
std::string(column, ' '), // Content spacing
|
||||||
|
std::string(assertionLength - 1, '~')); // Arrow pointer
|
||||||
|
|
||||||
|
fflush(stdout); // FIXME: stdout is buffered, strerr is not so wouldnt need this
|
||||||
|
CRASH();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ASSERT_H
|
#endif // ASSERT_H
|
||||||
|
|
||||||
|
// https://github.com/scottt/debugbreak
|
||||||
|
|||||||
+4
-1
@@ -1,10 +1,13 @@
|
|||||||
#ifndef CORE_H
|
#ifndef CORE_H
|
||||||
#define CORE_H
|
#define CORE_H
|
||||||
|
|
||||||
#include <functional> // std::bind
|
#include <functional> // std::bind, std::placeholders
|
||||||
|
|
||||||
#define BIT(x) (1 << x)
|
#define BIT(x) (1 << x)
|
||||||
|
|
||||||
|
// @Todo figure out lambda's and replace std::bind
|
||||||
|
// https://github.com/TheCherno/Hazel/pull/277
|
||||||
|
// variadic args in lambdas were added in C++17
|
||||||
#define NF_BIND_EVENT(f) std::bind(&f, this, std::placeholders::_1)
|
#define NF_BIND_EVENT(f) std::bind(&f, this, std::placeholders::_1)
|
||||||
|
|
||||||
// Compiler
|
// Compiler
|
||||||
|
|||||||
+79
-76
@@ -7,105 +7,108 @@
|
|||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
enum class EventType {
|
enum class EventType {
|
||||||
None = 0,
|
None = 0,
|
||||||
|
|
||||||
WindowClose,
|
WindowClose,
|
||||||
WindowResize,
|
WindowResize,
|
||||||
|
|
||||||
KeyPress,
|
KeyPress,
|
||||||
KeyRelease,
|
KeyRelease,
|
||||||
KeyRepeat,
|
KeyRepeat,
|
||||||
|
|
||||||
MouseButtonPress,
|
MouseButtonPress,
|
||||||
MouseButtonRelease,
|
MouseButtonRelease,
|
||||||
MousePosition,
|
MousePosition,
|
||||||
MouseScroll,
|
MouseScroll,
|
||||||
|
|
||||||
JoystickConnected,
|
JoystickConnected,
|
||||||
JoystickDisconnected,
|
JoystickDisconnected,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EventCategory {
|
enum EventCategory {
|
||||||
None = 0,
|
None = 0,
|
||||||
ApplicationEventCategory = BIT(0),
|
ApplicationEventCategory = BIT(0),
|
||||||
|
|
||||||
InputEventCategory = BIT(1),
|
InputEventCategory = BIT(1),
|
||||||
|
|
||||||
KeyEventCategory = BIT(2),
|
KeyEventCategory = BIT(2),
|
||||||
|
|
||||||
MouseEventCategory = BIT(3),
|
MouseEventCategory = BIT(3),
|
||||||
MouseButtonEventCategory = BIT(4),
|
MouseButtonEventCategory = BIT(4),
|
||||||
|
|
||||||
JoystickEventCatergory = BIT(5),
|
JoystickEventCatergory = BIT(5),
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event {
|
class Event {
|
||||||
// EventDispatcher is allowed to access Event private/protected members
|
// EventDispatcher is allowed to access Event private/protected members
|
||||||
friend class EventDispatcher;
|
friend class EventDispatcher;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Event() {}
|
virtual ~Event() {}
|
||||||
|
|
||||||
virtual std::string toString() const { return getName(); }
|
virtual std::string toString() const { return getName(); }
|
||||||
|
|
||||||
inline bool inCategory(EventCategory category)
|
inline bool inCategory(EventCategory category)
|
||||||
{
|
{
|
||||||
return getCategoryFlags() & category;
|
return getCategoryFlags() & category;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
|
// Getter function templates
|
||||||
|
virtual char getCategoryFlags() const = 0;
|
||||||
|
virtual const char* getName() const = 0;
|
||||||
|
virtual EventType getType() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool handled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EventDispatcher {
|
||||||
|
public:
|
||||||
|
EventDispatcher(Event& e)
|
||||||
|
: m_event(e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Easily dispatch all type of Events, call with:
|
||||||
|
// dispatch<T>(std::bind(&F, this, std::placeholders::_1));
|
||||||
|
// T is the type of Event
|
||||||
|
// F is the function to call, signature: bool name(T& e);
|
||||||
|
template<typename T, typename F>
|
||||||
|
bool dispatch(const F& function)
|
||||||
|
{
|
||||||
|
// If <constructed> type is same as member variable type
|
||||||
|
if (T::getTypeStatic() == m_event.getType()) {
|
||||||
|
// Call the function
|
||||||
|
m_event.handled = function(static_cast<T&>(m_event));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Getter function templates
|
private:
|
||||||
virtual char getCategoryFlags() const = 0;
|
Event& m_event;
|
||||||
virtual const char* getName() const = 0;
|
};
|
||||||
virtual EventType getType() const = 0;
|
|
||||||
|
|
||||||
private:
|
// Add class type functions macro
|
||||||
bool handled = false;
|
#define EVENT_CLASS_TYPE(type) \
|
||||||
};
|
virtual const char* getName() const override { return #type; } \
|
||||||
|
|
||||||
class EventDispatcher {
|
|
||||||
public:
|
|
||||||
EventDispatcher(Event& e) : m_event(e) {}
|
|
||||||
|
|
||||||
// Easily dispatch all type of Events, call with:
|
|
||||||
// dispatch<T>(std::bind(&F, this, std::placeholders::_1));
|
|
||||||
// T is the type of Event
|
|
||||||
// F is the function to call, signature: bool name(T& e);
|
|
||||||
template<typename T, typename F>
|
|
||||||
bool dispatch(const F& function)
|
|
||||||
{
|
|
||||||
// If <constructed> type is same as member variable type
|
|
||||||
if (T::getTypeStatic() == m_event.getType()) {
|
|
||||||
// Call the function
|
|
||||||
m_event.handled = function(static_cast<T& >(m_event));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Event& m_event;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add class type functions macro
|
|
||||||
#define EVENT_CLASS_TYPE(type) \
|
|
||||||
virtual const char* getName() const override { return #type; } \
|
|
||||||
virtual EventType getType() const override { return getTypeStatic(); } \
|
virtual EventType getType() const override { return getTypeStatic(); } \
|
||||||
static inline EventType getTypeStatic() { return EventType::type; }
|
static inline EventType getTypeStatic() { return EventType::type; }
|
||||||
|
|
||||||
// Add class catergory function macro
|
// Add class category function macro
|
||||||
#define EVENT_CLASS_CATEGORY(category) \
|
#define EVENT_CLASS_CATEGORY(category) \
|
||||||
virtual char getCategoryFlags() const override { return category; }
|
virtual char getCategoryFlags() const override { return category; }
|
||||||
|
|
||||||
// Make Events easily printable
|
// Make Events easily printable
|
||||||
inline std::ostream& operator<<(std::ostream& os, const Event& e)
|
inline std::ostream& operator<<(std::ostream& os, const Event& e)
|
||||||
{
|
{
|
||||||
return os << e.toString();
|
return os << e.toString();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Inferno
|
||||||
|
|
||||||
#endif // EVENT_H
|
#endif // EVENT_H
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ namespace Inferno {
|
|||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
template<typename... P> void dbgln(const char* format, P&&... parameters) { dbgln(Log::None, true, format, std::forward<P>(parameters)...); }
|
template<typename... P> void dbgln(const char* format, P&&... parameters) { dbgln(Log::None, true, format, std::forward<P>(parameters)...); }
|
||||||
template<typename... P> void infoln(const char* format, P&&... parameters) { dbgln(Log::Info, true, format, std::forward<P>(parameters)...); }
|
template<typename... P> void infoln(const char* format, P&&... parameters) { dbgln(Log::Info, true, format, std::forward<P>(parameters)...); }
|
||||||
template<typename... P> void warnln(const char* format, P&&... parameters) { dbgln(Log::Warn, true, format, std::forward<P>(parameters)...); }
|
template<typename... P> void warnln(const char* format, P&&... parameters) { dbgln(Log::Warn, true, format, std::forward<P>(parameters)...); }
|
||||||
@@ -193,6 +194,7 @@ namespace Inferno {
|
|||||||
template<typename... P> void dangerln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Danger, newline, format.data(), std::forward<P>(parameters)...); }
|
template<typename... P> void dangerln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Danger, newline, format.data(), std::forward<P>(parameters)...); }
|
||||||
template<typename... P> void successln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Success, newline, format.data(), std::forward<P>(parameters)...); }
|
template<typename... P> void successln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Success, newline, format.data(), std::forward<P>(parameters)...); }
|
||||||
template<typename... P> void commentln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Comment, newline, format.data(), std::forward<P>(parameters)...); }
|
template<typename... P> void commentln(bool newline, const std::string_view& format, P&&... parameters) { dbgln(Log::Comment, newline, format.data(), std::forward<P>(parameters)...); }
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
@@ -214,6 +216,7 @@ namespace Inferno {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// possible c++17 improvent https://riptutorial.com/cplusplus/example/3208/iterating-over-a-parameter-pack
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,25 @@
|
|||||||
#include "inferno/singleton.h"
|
#include "inferno/singleton.h"
|
||||||
#include "inferno/util/json.h"
|
#include "inferno/util/json.h"
|
||||||
|
|
||||||
|
#define GLTF_TYPE_SCALAR 1
|
||||||
|
#define GLTF_TYPE_VEC2 2
|
||||||
|
#define GLTF_TYPE_VEC3 3
|
||||||
|
#define GLTF_TYPE_VEC4 4
|
||||||
|
#define GLTF_TYPE_MAT2 8
|
||||||
|
#define GLTF_TYPE_MAT3 12
|
||||||
|
#define GLTF_TYPE_MAT4 16
|
||||||
|
|
||||||
|
#define GLTF_COMPONENT_TYPE_BYTE 5120
|
||||||
|
#define GLTF_COMPONENT_TYPE_UNSIGNED_BYTE 5121
|
||||||
|
#define GLTF_COMPONENT_TYPE_SHORT 5122
|
||||||
|
#define GLTF_COMPONENT_TYPE_UNSIGNED_SHORT 5123
|
||||||
|
#define GLTF_COMPONENT_TYPE_INT 5124
|
||||||
|
#define GLTF_COMPONENT_TYPE_UNSIGNED_INT 5125
|
||||||
|
#define GLTF_COMPONENT_TYPE_FLOAT 5126
|
||||||
|
|
||||||
|
#define GLTF_TARGET_ARRAY_BUFFER 34962
|
||||||
|
#define GLTF_TARGET_ELEMENT_ARRAY_BUFFER 34963
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
namespace glTF {
|
namespace glTF {
|
||||||
|
|||||||
@@ -4,12 +4,14 @@
|
|||||||
#include "inferno/component/nativescriptcomponent.h"
|
#include "inferno/component/nativescriptcomponent.h"
|
||||||
#include "inferno/component/spritecomponent.h"
|
#include "inferno/component/spritecomponent.h"
|
||||||
#include "inferno/component/tagcomponent.h"
|
#include "inferno/component/tagcomponent.h"
|
||||||
|
#include "inferno/component/textareacomponent.h"
|
||||||
#include "inferno/scene/scene.h"
|
#include "inferno/scene/scene.h"
|
||||||
#include "inferno/script/cameracontroller.h"
|
#include "inferno/script/cameracontroller.h"
|
||||||
#include "inferno/script/nativescript.h"
|
#include "inferno/script/nativescript.h"
|
||||||
#include "inferno/system/camerasystem.h"
|
#include "inferno/system/camerasystem.h"
|
||||||
#include "inferno/system/rendersystem.h"
|
#include "inferno/system/rendersystem.h"
|
||||||
#include "inferno/system/scriptsystem.h"
|
#include "inferno/system/scriptsystem.h"
|
||||||
|
#include "inferno/system/textareasystem.h"
|
||||||
#include "inferno/system/transformsystem.h"
|
#include "inferno/system/transformsystem.h"
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
@@ -33,6 +35,9 @@ namespace Inferno {
|
|||||||
ScriptSystem::initialize();
|
ScriptSystem::initialize();
|
||||||
ScriptSystem::the().setScene(this);
|
ScriptSystem::the().setScene(this);
|
||||||
|
|
||||||
|
TextAreaSystem::initialize();
|
||||||
|
TextAreaSystem::the().setScene(this);
|
||||||
|
|
||||||
// Load assets
|
// Load assets
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
|
||||||
@@ -44,6 +49,9 @@ namespace Inferno {
|
|||||||
|
|
||||||
uint32_t camera = createEntity("Camera Entity");
|
uint32_t camera = createEntity("Camera Entity");
|
||||||
auto& cameraTransform = getComponent<TransformComponent>(camera);
|
auto& cameraTransform = getComponent<TransformComponent>(camera);
|
||||||
|
// cameraTransform.rotate.z = 0.0f;
|
||||||
|
// cameraTransform.translate.z = -1.0f;
|
||||||
|
// addComponent<CameraComponent>(camera, CameraType::Orthographic);
|
||||||
cameraTransform.rotate.z = -1.0f;
|
cameraTransform.rotate.z = -1.0f;
|
||||||
cameraTransform.translate.z = 1.0f;
|
cameraTransform.translate.z = 1.0f;
|
||||||
addComponent<CameraComponent>(camera, CameraType::Perspective);
|
addComponent<CameraComponent>(camera, CameraType::Perspective);
|
||||||
@@ -63,6 +71,10 @@ namespace Inferno {
|
|||||||
quad3Transform.translate.x = 2.2f;
|
quad3Transform.translate.x = 2.2f;
|
||||||
addComponent<SpriteComponent>(quad3, glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
|
addComponent<SpriteComponent>(quad3, glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
|
||||||
|
|
||||||
|
uint32_t text = createEntity("Text");
|
||||||
|
addComponent<TextAreaComponent>(text, "HelloWorld!", "assets/fnt/dejavu-sans", 0, 150, 3);
|
||||||
|
// addComponent<TextAreaComponent>(text, "@#$%^&*()qygij!", "assets/fnt/dejavu-sans-test", 0, 150, 3);
|
||||||
|
|
||||||
info() << "Scene initialized";
|
info() << "Scene initialized";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +89,7 @@ namespace Inferno {
|
|||||||
void Scene::render()
|
void Scene::render()
|
||||||
{
|
{
|
||||||
RenderSystem::the().render();
|
RenderSystem::the().render();
|
||||||
|
TextAreaSystem::the().render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::destroy()
|
void Scene::destroy()
|
||||||
|
|||||||
@@ -82,3 +82,7 @@ namespace Inferno {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // SCENE_H
|
#endif // SCENE_H
|
||||||
|
|
||||||
|
// @Todo
|
||||||
|
// - Convert registry to stack variable
|
||||||
|
// - Convert registry to scene pointer in systems
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef CAMERA_CONTROLLER_H
|
#ifndef CAMERA_CONTROLLER_H
|
||||||
#define CAMERA_CONTROLLER_H
|
#define CAMERA_CONTROLLER_H
|
||||||
|
|
||||||
|
#include "inferno/component/cameracomponent.h"
|
||||||
#include "inferno/script/nativescript.h"
|
#include "inferno/script/nativescript.h"
|
||||||
|
|
||||||
#define TRANSLATE_SPEED 2.5f
|
#define TRANSLATE_SPEED 2.5f
|
||||||
|
|||||||
@@ -13,20 +13,20 @@ namespace Inferno {
|
|||||||
public:
|
public:
|
||||||
static inline void initialize()
|
static inline void initialize()
|
||||||
{
|
{
|
||||||
ASSERT(!s_instance, "Singleton already exists!");
|
ASSERT(!s_instance, "singleton already exists");
|
||||||
s_instance = new T { s {} };
|
s_instance = new T { s {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void destroy()
|
static inline void destroy()
|
||||||
{
|
{
|
||||||
ASSERT(s_instance, "Singleton does not exist!");
|
ASSERT(s_instance, "singleton does not exist");
|
||||||
delete s_instance;
|
delete s_instance;
|
||||||
s_instance = nullptr;
|
s_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline T& the()
|
static inline T& the()
|
||||||
{
|
{
|
||||||
ASSERT(s_instance, "Singleton does not exist!");
|
ASSERT(s_instance, "singleton does not exist");
|
||||||
return *s_instance;
|
return *s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user