From 6b0095dadf41fb981f5d6b40608ddef9d8e4d553 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 16 Sep 2022 20:11:56 +0200 Subject: [PATCH] CMake: Move source directory to project root --- CMakeLists.txt | 6 +- example/CMakeLists.txt | 2 +- {inferno => src}/CMakeLists.txt | 4 +- {inferno/src => src}/inferno.h | 0 {inferno/src => src}/inferno/application.cpp | 0 {inferno/src => src}/inferno/application.h | 0 {inferno/src => src}/inferno/assert.h | 0 .../inferno/component/cameracomponent.h | 0 .../inferno/component/luascriptcomponent.h | 0 .../inferno/component/nativescriptcomponent.h | 0 .../inferno/component/spritecomponent.h | 0 .../inferno/component/tagcomponent.h | 0 src/inferno/component/textareacomponent.h | 32 +++++ .../inferno/component/transformcomponent.cpp | 0 .../inferno/component/transformcomponent.h | 0 {inferno/src => src}/inferno/core.h | 0 {inferno/src => src}/inferno/entrypoint.h | 0 .../inferno/event/applicationevent.h | 0 {inferno/src => src}/inferno/event/event.h | 0 .../src => src}/inferno/event/joystickevent.h | 0 {inferno/src => src}/inferno/event/keyevent.h | 0 .../src => src}/inferno/event/mouseevent.h | 0 {inferno/src => src}/inferno/io/file.cpp | 0 {inferno/src => src}/inferno/io/file.h | 0 {inferno/src => src}/inferno/io/gltffile.cpp | 0 {inferno/src => src}/inferno/io/gltffile.h | 0 {inferno/src => src}/inferno/io/input.cpp | 0 {inferno/src => src}/inferno/io/input.h | 0 {inferno/src => src}/inferno/io/log.cpp | 0 {inferno/src => src}/inferno/io/log.h | 0 {inferno/src => src}/inferno/keycodes.cpp | 0 {inferno/src => src}/inferno/keycodes.h | 0 .../src => src}/inferno/render/buffer.cpp | 0 {inferno/src => src}/inferno/render/buffer.h | 0 .../src => src}/inferno/render/context.cpp | 0 {inferno/src => src}/inferno/render/context.h | 0 {inferno/src => src}/inferno/render/font.cpp | 0 {inferno/src => src}/inferno/render/font.h | 0 src/inferno/render/framebuffer.cpp | 15 +++ src/inferno/render/framebuffer.h | 14 +++ {inferno/src => src}/inferno/render/gltf.cpp | 0 {inferno/src => src}/inferno/render/gltf.h | 0 .../src => src}/inferno/render/renderer.cpp | 0 .../src => src}/inferno/render/renderer.h | 0 src/inferno/render/renderer3d.cpp | 7 ++ src/inferno/render/renderer3d.h | 40 ++++++ .../src => src}/inferno/render/shader.cpp | 0 {inferno/src => src}/inferno/render/shader.h | 0 .../src => src}/inferno/render/texture.cpp | 0 {inferno/src => src}/inferno/render/texture.h | 0 {inferno/src => src}/inferno/scene/scene.cpp | 0 {inferno/src => src}/inferno/scene/scene.h | 0 .../inferno/script/cameracontroller.cpp | 0 .../inferno/script/cameracontroller.h | 0 .../src => src}/inferno/script/luascript.cpp | 0 .../src => src}/inferno/script/luascript.h | 0 .../src => src}/inferno/script/nativescript.h | 0 .../inferno/script/registration.cpp | 0 .../src => src}/inferno/script/registration.h | 0 {inferno/src => src}/inferno/settings.cpp | 0 {inferno/src => src}/inferno/settings.h | 0 {inferno/src => src}/inferno/singleton.h | 0 .../inferno/system/camerasystem.cpp | 0 .../src => src}/inferno/system/camerasystem.h | 0 .../inferno/system/rendersystem.cpp | 0 .../src => src}/inferno/system/rendersystem.h | 0 .../inferno/system/scriptsystem.cpp | 0 .../src => src}/inferno/system/scriptsystem.h | 0 src/inferno/system/textareasystem.cpp | 117 ++++++++++++++++++ src/inferno/system/textareasystem.h | 39 ++++++ .../inferno/system/transformsystem.cpp | 0 .../inferno/system/transformsystem.h | 0 {inferno/src => src}/inferno/time.cpp | 0 {inferno/src => src}/inferno/time.h | 0 {inferno/src => src}/inferno/util/integer.h | 0 {inferno/src => src}/inferno/util/json.h | 0 {inferno/src => src}/inferno/util/string.h | 0 {inferno/src => src}/inferno/window.cpp | 0 {inferno/src => src}/inferno/window.h | 0 79 files changed, 270 insertions(+), 6 deletions(-) rename {inferno => src}/CMakeLists.txt (94%) rename {inferno/src => src}/inferno.h (100%) rename {inferno/src => src}/inferno/application.cpp (100%) rename {inferno/src => src}/inferno/application.h (100%) rename {inferno/src => src}/inferno/assert.h (100%) rename {inferno/src => src}/inferno/component/cameracomponent.h (100%) rename {inferno/src => src}/inferno/component/luascriptcomponent.h (100%) rename {inferno/src => src}/inferno/component/nativescriptcomponent.h (100%) rename {inferno/src => src}/inferno/component/spritecomponent.h (100%) rename {inferno/src => src}/inferno/component/tagcomponent.h (100%) create mode 100644 src/inferno/component/textareacomponent.h rename {inferno/src => src}/inferno/component/transformcomponent.cpp (100%) rename {inferno/src => src}/inferno/component/transformcomponent.h (100%) rename {inferno/src => src}/inferno/core.h (100%) rename {inferno/src => src}/inferno/entrypoint.h (100%) rename {inferno/src => src}/inferno/event/applicationevent.h (100%) rename {inferno/src => src}/inferno/event/event.h (100%) rename {inferno/src => src}/inferno/event/joystickevent.h (100%) rename {inferno/src => src}/inferno/event/keyevent.h (100%) rename {inferno/src => src}/inferno/event/mouseevent.h (100%) rename {inferno/src => src}/inferno/io/file.cpp (100%) rename {inferno/src => src}/inferno/io/file.h (100%) rename {inferno/src => src}/inferno/io/gltffile.cpp (100%) rename {inferno/src => src}/inferno/io/gltffile.h (100%) rename {inferno/src => src}/inferno/io/input.cpp (100%) rename {inferno/src => src}/inferno/io/input.h (100%) rename {inferno/src => src}/inferno/io/log.cpp (100%) rename {inferno/src => src}/inferno/io/log.h (100%) rename {inferno/src => src}/inferno/keycodes.cpp (100%) rename {inferno/src => src}/inferno/keycodes.h (100%) rename {inferno/src => src}/inferno/render/buffer.cpp (100%) rename {inferno/src => src}/inferno/render/buffer.h (100%) rename {inferno/src => src}/inferno/render/context.cpp (100%) rename {inferno/src => src}/inferno/render/context.h (100%) rename {inferno/src => src}/inferno/render/font.cpp (100%) rename {inferno/src => src}/inferno/render/font.h (100%) create mode 100644 src/inferno/render/framebuffer.cpp create mode 100644 src/inferno/render/framebuffer.h rename {inferno/src => src}/inferno/render/gltf.cpp (100%) rename {inferno/src => src}/inferno/render/gltf.h (100%) rename {inferno/src => src}/inferno/render/renderer.cpp (100%) rename {inferno/src => src}/inferno/render/renderer.h (100%) create mode 100644 src/inferno/render/renderer3d.cpp create mode 100644 src/inferno/render/renderer3d.h rename {inferno/src => src}/inferno/render/shader.cpp (100%) rename {inferno/src => src}/inferno/render/shader.h (100%) rename {inferno/src => src}/inferno/render/texture.cpp (100%) rename {inferno/src => src}/inferno/render/texture.h (100%) rename {inferno/src => src}/inferno/scene/scene.cpp (100%) rename {inferno/src => src}/inferno/scene/scene.h (100%) rename {inferno/src => src}/inferno/script/cameracontroller.cpp (100%) rename {inferno/src => src}/inferno/script/cameracontroller.h (100%) rename {inferno/src => src}/inferno/script/luascript.cpp (100%) rename {inferno/src => src}/inferno/script/luascript.h (100%) rename {inferno/src => src}/inferno/script/nativescript.h (100%) rename {inferno/src => src}/inferno/script/registration.cpp (100%) rename {inferno/src => src}/inferno/script/registration.h (100%) rename {inferno/src => src}/inferno/settings.cpp (100%) rename {inferno/src => src}/inferno/settings.h (100%) rename {inferno/src => src}/inferno/singleton.h (100%) rename {inferno/src => src}/inferno/system/camerasystem.cpp (100%) rename {inferno/src => src}/inferno/system/camerasystem.h (100%) rename {inferno/src => src}/inferno/system/rendersystem.cpp (100%) rename {inferno/src => src}/inferno/system/rendersystem.h (100%) rename {inferno/src => src}/inferno/system/scriptsystem.cpp (100%) rename {inferno/src => src}/inferno/system/scriptsystem.h (100%) create mode 100644 src/inferno/system/textareasystem.cpp create mode 100644 src/inferno/system/textareasystem.h rename {inferno/src => src}/inferno/system/transformsystem.cpp (100%) rename {inferno/src => src}/inferno/system/transformsystem.h (100%) rename {inferno/src => src}/inferno/time.cpp (100%) rename {inferno/src => src}/inferno/time.h (100%) rename {inferno/src => src}/inferno/util/integer.h (100%) rename {inferno/src => src}/inferno/util/json.h (100%) rename {inferno/src => src}/inferno/util/string.h (100%) rename {inferno/src => src}/inferno/window.cpp (100%) rename {inferno/src => src}/inferno/window.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d94fcf8..0018794 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,18 +58,18 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Engine dependencies target # Add engine target to project -add_subdirectory("${CMAKE_SOURCE_DIR}/vendor") +add_subdirectory("vendor") # ------------------------------------------ # Engine target # Add engine target to project -add_subdirectory("${CMAKE_SOURCE_DIR}/${ENGINE}") +add_subdirectory("src") # ------------------------------------------ # Examples target if (INFERNO_BUILD_EXAMPLES) # Add examples target to project - add_subdirectory("${CMAKE_SOURCE_DIR}/example") + add_subdirectory("example") endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 62fb4ad..94e5e73 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -14,7 +14,7 @@ file(GLOB_RECURSE GAME_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") add_executable(${GAME} ${GAME_SOURCES}) target_include_directories(${GAME} PRIVATE "src" - "${CMAKE_SOURCE_DIR}/${ENGINE}/src") + "${CMAKE_SOURCE_DIR}/src") target_link_libraries(${GAME} ${ENGINE}) target_precompile_headers(${GAME} REUSE_FROM ${ENGINE}) diff --git a/inferno/CMakeLists.txt b/src/CMakeLists.txt similarity index 94% rename from inferno/CMakeLists.txt rename to src/CMakeLists.txt index 973d2df..102b8a9 100644 --- a/inferno/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,8 @@ -file(GLOB_RECURSE ENGINE_SOURCES "src/*.cpp") +file(GLOB_RECURSE ENGINE_SOURCES "${ENGINE}/*.cpp") add_library(${ENGINE} ${ENGINE_SOURCES}) target_include_directories(${ENGINE} PRIVATE - "src" + "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/vendor/entt/src" "${CMAKE_SOURCE_DIR}/vendor/glad/include" "${CMAKE_SOURCE_DIR}/vendor/glfw/include" diff --git a/inferno/src/inferno.h b/src/inferno.h similarity index 100% rename from inferno/src/inferno.h rename to src/inferno.h diff --git a/inferno/src/inferno/application.cpp b/src/inferno/application.cpp similarity index 100% rename from inferno/src/inferno/application.cpp rename to src/inferno/application.cpp diff --git a/inferno/src/inferno/application.h b/src/inferno/application.h similarity index 100% rename from inferno/src/inferno/application.h rename to src/inferno/application.h diff --git a/inferno/src/inferno/assert.h b/src/inferno/assert.h similarity index 100% rename from inferno/src/inferno/assert.h rename to src/inferno/assert.h diff --git a/inferno/src/inferno/component/cameracomponent.h b/src/inferno/component/cameracomponent.h similarity index 100% rename from inferno/src/inferno/component/cameracomponent.h rename to src/inferno/component/cameracomponent.h diff --git a/inferno/src/inferno/component/luascriptcomponent.h b/src/inferno/component/luascriptcomponent.h similarity index 100% rename from inferno/src/inferno/component/luascriptcomponent.h rename to src/inferno/component/luascriptcomponent.h diff --git a/inferno/src/inferno/component/nativescriptcomponent.h b/src/inferno/component/nativescriptcomponent.h similarity index 100% rename from inferno/src/inferno/component/nativescriptcomponent.h rename to src/inferno/component/nativescriptcomponent.h diff --git a/inferno/src/inferno/component/spritecomponent.h b/src/inferno/component/spritecomponent.h similarity index 100% rename from inferno/src/inferno/component/spritecomponent.h rename to src/inferno/component/spritecomponent.h diff --git a/inferno/src/inferno/component/tagcomponent.h b/src/inferno/component/tagcomponent.h similarity index 100% rename from inferno/src/inferno/component/tagcomponent.h rename to src/inferno/component/tagcomponent.h diff --git a/src/inferno/component/textareacomponent.h b/src/inferno/component/textareacomponent.h new file mode 100644 index 0000000..fe3b41f --- /dev/null +++ b/src/inferno/component/textareacomponent.h @@ -0,0 +1,32 @@ +#ifndef TEXTAREA_COMPONENT_H +#define TEXTAREA_COMPONENT_H + +#include // uint32_t +#include // std::string +#include // std::move + +#include "glm/ext/vector_float4.hpp" // glm::vec4 + +namespace Inferno { + + struct TextAreaComponent { + std::string content { "" }; + std::string font { "" }; + uint32_t fontSize { 0 }; + uint32_t width { 0 }; + uint32_t lines { 0 }; + + TextAreaComponent() {} + TextAreaComponent(const std::string& content, const std::string& font, + uint32_t fontSize, uint32_t width, uint32_t lines) + : content(std::move(content)), font(std::move(font)), fontSize(fontSize), width(width), lines(lines) {} + + // booleans? + // glm::vec4 outlineColor { 1.0f, 1.0f, 1.0f, 1.0f }; + // glow? + // float dropShadow { 0.0f }; + }; + +} + +#endif // TEXTAREA_COMPONENT_H diff --git a/inferno/src/inferno/component/transformcomponent.cpp b/src/inferno/component/transformcomponent.cpp similarity index 100% rename from inferno/src/inferno/component/transformcomponent.cpp rename to src/inferno/component/transformcomponent.cpp diff --git a/inferno/src/inferno/component/transformcomponent.h b/src/inferno/component/transformcomponent.h similarity index 100% rename from inferno/src/inferno/component/transformcomponent.h rename to src/inferno/component/transformcomponent.h diff --git a/inferno/src/inferno/core.h b/src/inferno/core.h similarity index 100% rename from inferno/src/inferno/core.h rename to src/inferno/core.h diff --git a/inferno/src/inferno/entrypoint.h b/src/inferno/entrypoint.h similarity index 100% rename from inferno/src/inferno/entrypoint.h rename to src/inferno/entrypoint.h diff --git a/inferno/src/inferno/event/applicationevent.h b/src/inferno/event/applicationevent.h similarity index 100% rename from inferno/src/inferno/event/applicationevent.h rename to src/inferno/event/applicationevent.h diff --git a/inferno/src/inferno/event/event.h b/src/inferno/event/event.h similarity index 100% rename from inferno/src/inferno/event/event.h rename to src/inferno/event/event.h diff --git a/inferno/src/inferno/event/joystickevent.h b/src/inferno/event/joystickevent.h similarity index 100% rename from inferno/src/inferno/event/joystickevent.h rename to src/inferno/event/joystickevent.h diff --git a/inferno/src/inferno/event/keyevent.h b/src/inferno/event/keyevent.h similarity index 100% rename from inferno/src/inferno/event/keyevent.h rename to src/inferno/event/keyevent.h diff --git a/inferno/src/inferno/event/mouseevent.h b/src/inferno/event/mouseevent.h similarity index 100% rename from inferno/src/inferno/event/mouseevent.h rename to src/inferno/event/mouseevent.h diff --git a/inferno/src/inferno/io/file.cpp b/src/inferno/io/file.cpp similarity index 100% rename from inferno/src/inferno/io/file.cpp rename to src/inferno/io/file.cpp diff --git a/inferno/src/inferno/io/file.h b/src/inferno/io/file.h similarity index 100% rename from inferno/src/inferno/io/file.h rename to src/inferno/io/file.h diff --git a/inferno/src/inferno/io/gltffile.cpp b/src/inferno/io/gltffile.cpp similarity index 100% rename from inferno/src/inferno/io/gltffile.cpp rename to src/inferno/io/gltffile.cpp diff --git a/inferno/src/inferno/io/gltffile.h b/src/inferno/io/gltffile.h similarity index 100% rename from inferno/src/inferno/io/gltffile.h rename to src/inferno/io/gltffile.h diff --git a/inferno/src/inferno/io/input.cpp b/src/inferno/io/input.cpp similarity index 100% rename from inferno/src/inferno/io/input.cpp rename to src/inferno/io/input.cpp diff --git a/inferno/src/inferno/io/input.h b/src/inferno/io/input.h similarity index 100% rename from inferno/src/inferno/io/input.h rename to src/inferno/io/input.h diff --git a/inferno/src/inferno/io/log.cpp b/src/inferno/io/log.cpp similarity index 100% rename from inferno/src/inferno/io/log.cpp rename to src/inferno/io/log.cpp diff --git a/inferno/src/inferno/io/log.h b/src/inferno/io/log.h similarity index 100% rename from inferno/src/inferno/io/log.h rename to src/inferno/io/log.h diff --git a/inferno/src/inferno/keycodes.cpp b/src/inferno/keycodes.cpp similarity index 100% rename from inferno/src/inferno/keycodes.cpp rename to src/inferno/keycodes.cpp diff --git a/inferno/src/inferno/keycodes.h b/src/inferno/keycodes.h similarity index 100% rename from inferno/src/inferno/keycodes.h rename to src/inferno/keycodes.h diff --git a/inferno/src/inferno/render/buffer.cpp b/src/inferno/render/buffer.cpp similarity index 100% rename from inferno/src/inferno/render/buffer.cpp rename to src/inferno/render/buffer.cpp diff --git a/inferno/src/inferno/render/buffer.h b/src/inferno/render/buffer.h similarity index 100% rename from inferno/src/inferno/render/buffer.h rename to src/inferno/render/buffer.h diff --git a/inferno/src/inferno/render/context.cpp b/src/inferno/render/context.cpp similarity index 100% rename from inferno/src/inferno/render/context.cpp rename to src/inferno/render/context.cpp diff --git a/inferno/src/inferno/render/context.h b/src/inferno/render/context.h similarity index 100% rename from inferno/src/inferno/render/context.h rename to src/inferno/render/context.h diff --git a/inferno/src/inferno/render/font.cpp b/src/inferno/render/font.cpp similarity index 100% rename from inferno/src/inferno/render/font.cpp rename to src/inferno/render/font.cpp diff --git a/inferno/src/inferno/render/font.h b/src/inferno/render/font.h similarity index 100% rename from inferno/src/inferno/render/font.h rename to src/inferno/render/font.h diff --git a/src/inferno/render/framebuffer.cpp b/src/inferno/render/framebuffer.cpp new file mode 100644 index 0000000..c40e935 --- /dev/null +++ b/src/inferno/render/framebuffer.cpp @@ -0,0 +1,15 @@ +#include "inferno/render/framebuffer.h" + +namespace Inferno { + +Framebuffer::Framebuffer() +{ +} + +Framebuffer::~Framebuffer() +{ +} + +// ----------------------------------------- + +} // namespace Inferno diff --git a/src/inferno/render/framebuffer.h b/src/inferno/render/framebuffer.h new file mode 100644 index 0000000..f830183 --- /dev/null +++ b/src/inferno/render/framebuffer.h @@ -0,0 +1,14 @@ +#ifndef FRAMEBUFFER_H +#define FRAMEBUFFER_H + +namespace Inferno { + +class Framebuffer { +public: + Framebuffer(); + virtual ~Framebuffer(); +}; + +} // namespace Inferno + +#endif // FRAMEBUFFER_H diff --git a/inferno/src/inferno/render/gltf.cpp b/src/inferno/render/gltf.cpp similarity index 100% rename from inferno/src/inferno/render/gltf.cpp rename to src/inferno/render/gltf.cpp diff --git a/inferno/src/inferno/render/gltf.h b/src/inferno/render/gltf.h similarity index 100% rename from inferno/src/inferno/render/gltf.h rename to src/inferno/render/gltf.h diff --git a/inferno/src/inferno/render/renderer.cpp b/src/inferno/render/renderer.cpp similarity index 100% rename from inferno/src/inferno/render/renderer.cpp rename to src/inferno/render/renderer.cpp diff --git a/inferno/src/inferno/render/renderer.h b/src/inferno/render/renderer.h similarity index 100% rename from inferno/src/inferno/render/renderer.h rename to src/inferno/render/renderer.h diff --git a/src/inferno/render/renderer3d.cpp b/src/inferno/render/renderer3d.cpp new file mode 100644 index 0000000..947ba6a --- /dev/null +++ b/src/inferno/render/renderer3d.cpp @@ -0,0 +1,7 @@ +#include "inferno/render/renderer3d.h" + +namespace Inferno { + +//.. + +} // namespace Inferno diff --git a/src/inferno/render/renderer3d.h b/src/inferno/render/renderer3d.h new file mode 100644 index 0000000..be94ab7 --- /dev/null +++ b/src/inferno/render/renderer3d.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2021 Riyyi + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef RENDERER_3D_H +#define RENDERER_3D_H + +namespace Inferno { + +class Renderer3D { +public: + Renderer3D(); + virtual ~Renderer3D(); +}; + +} // namespace Inferno + +#endif // RENDERER_3D_H + +// - what data do you need? +// - gltf +// - how are we going to batch +// - mesh (gltf) -> material -> shader rendering diff --git a/inferno/src/inferno/render/shader.cpp b/src/inferno/render/shader.cpp similarity index 100% rename from inferno/src/inferno/render/shader.cpp rename to src/inferno/render/shader.cpp diff --git a/inferno/src/inferno/render/shader.h b/src/inferno/render/shader.h similarity index 100% rename from inferno/src/inferno/render/shader.h rename to src/inferno/render/shader.h diff --git a/inferno/src/inferno/render/texture.cpp b/src/inferno/render/texture.cpp similarity index 100% rename from inferno/src/inferno/render/texture.cpp rename to src/inferno/render/texture.cpp diff --git a/inferno/src/inferno/render/texture.h b/src/inferno/render/texture.h similarity index 100% rename from inferno/src/inferno/render/texture.h rename to src/inferno/render/texture.h diff --git a/inferno/src/inferno/scene/scene.cpp b/src/inferno/scene/scene.cpp similarity index 100% rename from inferno/src/inferno/scene/scene.cpp rename to src/inferno/scene/scene.cpp diff --git a/inferno/src/inferno/scene/scene.h b/src/inferno/scene/scene.h similarity index 100% rename from inferno/src/inferno/scene/scene.h rename to src/inferno/scene/scene.h diff --git a/inferno/src/inferno/script/cameracontroller.cpp b/src/inferno/script/cameracontroller.cpp similarity index 100% rename from inferno/src/inferno/script/cameracontroller.cpp rename to src/inferno/script/cameracontroller.cpp diff --git a/inferno/src/inferno/script/cameracontroller.h b/src/inferno/script/cameracontroller.h similarity index 100% rename from inferno/src/inferno/script/cameracontroller.h rename to src/inferno/script/cameracontroller.h diff --git a/inferno/src/inferno/script/luascript.cpp b/src/inferno/script/luascript.cpp similarity index 100% rename from inferno/src/inferno/script/luascript.cpp rename to src/inferno/script/luascript.cpp diff --git a/inferno/src/inferno/script/luascript.h b/src/inferno/script/luascript.h similarity index 100% rename from inferno/src/inferno/script/luascript.h rename to src/inferno/script/luascript.h diff --git a/inferno/src/inferno/script/nativescript.h b/src/inferno/script/nativescript.h similarity index 100% rename from inferno/src/inferno/script/nativescript.h rename to src/inferno/script/nativescript.h diff --git a/inferno/src/inferno/script/registration.cpp b/src/inferno/script/registration.cpp similarity index 100% rename from inferno/src/inferno/script/registration.cpp rename to src/inferno/script/registration.cpp diff --git a/inferno/src/inferno/script/registration.h b/src/inferno/script/registration.h similarity index 100% rename from inferno/src/inferno/script/registration.h rename to src/inferno/script/registration.h diff --git a/inferno/src/inferno/settings.cpp b/src/inferno/settings.cpp similarity index 100% rename from inferno/src/inferno/settings.cpp rename to src/inferno/settings.cpp diff --git a/inferno/src/inferno/settings.h b/src/inferno/settings.h similarity index 100% rename from inferno/src/inferno/settings.h rename to src/inferno/settings.h diff --git a/inferno/src/inferno/singleton.h b/src/inferno/singleton.h similarity index 100% rename from inferno/src/inferno/singleton.h rename to src/inferno/singleton.h diff --git a/inferno/src/inferno/system/camerasystem.cpp b/src/inferno/system/camerasystem.cpp similarity index 100% rename from inferno/src/inferno/system/camerasystem.cpp rename to src/inferno/system/camerasystem.cpp diff --git a/inferno/src/inferno/system/camerasystem.h b/src/inferno/system/camerasystem.h similarity index 100% rename from inferno/src/inferno/system/camerasystem.h rename to src/inferno/system/camerasystem.h diff --git a/inferno/src/inferno/system/rendersystem.cpp b/src/inferno/system/rendersystem.cpp similarity index 100% rename from inferno/src/inferno/system/rendersystem.cpp rename to src/inferno/system/rendersystem.cpp diff --git a/inferno/src/inferno/system/rendersystem.h b/src/inferno/system/rendersystem.h similarity index 100% rename from inferno/src/inferno/system/rendersystem.h rename to src/inferno/system/rendersystem.h diff --git a/inferno/src/inferno/system/scriptsystem.cpp b/src/inferno/system/scriptsystem.cpp similarity index 100% rename from inferno/src/inferno/system/scriptsystem.cpp rename to src/inferno/system/scriptsystem.cpp diff --git a/inferno/src/inferno/system/scriptsystem.h b/src/inferno/system/scriptsystem.h similarity index 100% rename from inferno/src/inferno/system/scriptsystem.h rename to src/inferno/system/scriptsystem.h diff --git a/src/inferno/system/textareasystem.cpp b/src/inferno/system/textareasystem.cpp new file mode 100644 index 0000000..61db0bd --- /dev/null +++ b/src/inferno/system/textareasystem.cpp @@ -0,0 +1,117 @@ +#include "inferno/application.h" +#include "inferno/assert.h" +#include "inferno/component/textareacomponent.h" +#include "inferno/render/font.h" +#include "inferno/render/renderer.h" +#include "inferno/render/texture.h" +#include "inferno/scene/scene.h" +#include "inferno/system/textareasystem.h" +#include "inferno/window.h" + +namespace Inferno { + + TextAreaSystem::TextAreaSystem(s) + { + info() << "TextAreaSystem initialized"; + } + + TextAreaSystem::~TextAreaSystem() + { + } + + void TextAreaSystem::render() + { + auto view = m_scene->registry()->view(); + + glm::ivec2 viewport = { + Application::the().getWindow().getWidth(), + Application::the().getWindow().getHeight(), + }; + + for (auto [entity, transform, textarea] : view.each()) { + // Loop through textareas content + // Linebreak if width reached + // Break if lines AND width reached + // Calculate character quad + // Submit character quad for rendering + + std::shared_ptr font = FontManager::the().load(textarea.font); + // glm::mat4 translate = transform.translate; + + float advance = 0.0f; + for (auto character : textarea.content) { + std::optional quad = calculateCharacterQuad(character, font, advance); + + if (quad) { + RendererCharacter::the().drawCharacter(quad.value(), font->texture()); + } + } + } + } + + std::optional TextAreaSystem::calculateCharacterQuad(unsigned char character, std::shared_ptr font, float& advance) + { + CharacterQuad characterQuad; + + auto c = font->get(character); + + // Texture + // --------------------------------- + + float textureWidth = static_cast(font->texture()->width()); + float textureHeight = static_cast(font->texture()->height()); + ASSERT(textureWidth == textureHeight, "TextAreaSystem read invalid font texture"); + + // Skip empty characters + if (c->size.x == 0 || c->size.y == 0) { + // Jump to the next glyph + advance += c->advance / textureWidth; + return {}; + } + + // Position + // --------------------------------- + + float quadWidth = c->size.x / textureWidth; + float quadHeight = c->size.y / textureHeight; + characterQuad.at(0).quad.position = { -quadWidth, -quadHeight, 0.0f }; // bottom left + characterQuad.at(1).quad.position = { quadWidth, -quadHeight, 0.0f }; // bottom right + characterQuad.at(2).quad.position = { quadWidth, quadHeight, 0.0f }; // top right + characterQuad.at(3).quad.position = { -quadWidth, quadHeight, 0.0f }; // top left + + for (auto& quad : characterQuad) { + quad.quad.position.x -= 0.5f; + + quad.quad.position.x += c->offset.x / (float)textureWidth; + quad.quad.position.y -= c->offset.y / (float)textureHeight; + + quad.quad.position.x += advance; + } + + // dbgln("character: {} ({}) width: {} height: {} advance: {} x: {}", + // character, (int)character, quadWidth, quadHeight, advance, characterQuad.at(0).quad.position.x); + + // Jump to the next glyph + advance += c->advance / textureWidth; + + // Texture coordinates + // --------------------------------- + + glm::vec2 x { + 1 - (textureWidth - c->position.x) / textureWidth, + 1 - (textureWidth - c->position.x - c->size.x) / textureWidth + }; + glm::vec2 y { + (textureHeight - c->position.y - c->size.y) / textureHeight, + (textureHeight - c->position.y) / textureHeight + }; + + characterQuad.at(0).quad.textureCoordinates = { x.x, y.x }; + characterQuad.at(1).quad.textureCoordinates = { x.y, y.x }; + characterQuad.at(2).quad.textureCoordinates = { x.y, y.y }; + characterQuad.at(3).quad.textureCoordinates = { x.x, y.y }; + + return characterQuad; + } + +} // namespace Inferno diff --git a/src/inferno/system/textareasystem.h b/src/inferno/system/textareasystem.h new file mode 100644 index 0000000..d5e40c8 --- /dev/null +++ b/src/inferno/system/textareasystem.h @@ -0,0 +1,39 @@ +#ifndef TEXTAREA_H +#define TEXTAREA_H + +#include // std::uint32_t +#include // std::shared_ptr +#include // std::optional +#include // std::vector + +#include "glm/ext/vector_float3.hpp" // glm::vec3 + +#include "inferno/render/renderer.h" +#include "inferno/singleton.h" + +namespace Inferno { + + using CharacterQuad = std::array; + + class Font; + class Scene; + + class TextAreaSystem final : public Singleton { + public: + TextAreaSystem(s); + virtual ~TextAreaSystem(); + + void render(); + + void setScene(Scene* scene) { m_scene = scene; } + + private: + std::optional calculateCharacterQuad(unsigned char character, std::shared_ptr font, float& advance); + + Scene* m_scene { nullptr }; + }; + +} // namespace Inferno + + +#endif // TEXTAREA_H diff --git a/inferno/src/inferno/system/transformsystem.cpp b/src/inferno/system/transformsystem.cpp similarity index 100% rename from inferno/src/inferno/system/transformsystem.cpp rename to src/inferno/system/transformsystem.cpp diff --git a/inferno/src/inferno/system/transformsystem.h b/src/inferno/system/transformsystem.h similarity index 100% rename from inferno/src/inferno/system/transformsystem.h rename to src/inferno/system/transformsystem.h diff --git a/inferno/src/inferno/time.cpp b/src/inferno/time.cpp similarity index 100% rename from inferno/src/inferno/time.cpp rename to src/inferno/time.cpp diff --git a/inferno/src/inferno/time.h b/src/inferno/time.h similarity index 100% rename from inferno/src/inferno/time.h rename to src/inferno/time.h diff --git a/inferno/src/inferno/util/integer.h b/src/inferno/util/integer.h similarity index 100% rename from inferno/src/inferno/util/integer.h rename to src/inferno/util/integer.h diff --git a/inferno/src/inferno/util/json.h b/src/inferno/util/json.h similarity index 100% rename from inferno/src/inferno/util/json.h rename to src/inferno/util/json.h diff --git a/inferno/src/inferno/util/string.h b/src/inferno/util/string.h similarity index 100% rename from inferno/src/inferno/util/string.h rename to src/inferno/util/string.h diff --git a/inferno/src/inferno/window.cpp b/src/inferno/window.cpp similarity index 100% rename from inferno/src/inferno/window.cpp rename to src/inferno/window.cpp diff --git a/inferno/src/inferno/window.h b/src/inferno/window.h similarity index 100% rename from inferno/src/inferno/window.h rename to src/inferno/window.h