Browse Source

CMake: Move source directory to project root

master
Riyyi 2 years ago
parent
commit
6b0095dadf
  1. 6
      CMakeLists.txt
  2. 2
      example/CMakeLists.txt
  3. 4
      src/CMakeLists.txt
  4. 0
      src/inferno.h
  5. 0
      src/inferno/application.cpp
  6. 0
      src/inferno/application.h
  7. 0
      src/inferno/assert.h
  8. 0
      src/inferno/component/cameracomponent.h
  9. 0
      src/inferno/component/luascriptcomponent.h
  10. 0
      src/inferno/component/nativescriptcomponent.h
  11. 0
      src/inferno/component/spritecomponent.h
  12. 0
      src/inferno/component/tagcomponent.h
  13. 32
      src/inferno/component/textareacomponent.h
  14. 0
      src/inferno/component/transformcomponent.cpp
  15. 0
      src/inferno/component/transformcomponent.h
  16. 0
      src/inferno/core.h
  17. 0
      src/inferno/entrypoint.h
  18. 0
      src/inferno/event/applicationevent.h
  19. 0
      src/inferno/event/event.h
  20. 0
      src/inferno/event/joystickevent.h
  21. 0
      src/inferno/event/keyevent.h
  22. 0
      src/inferno/event/mouseevent.h
  23. 0
      src/inferno/io/file.cpp
  24. 0
      src/inferno/io/file.h
  25. 0
      src/inferno/io/gltffile.cpp
  26. 0
      src/inferno/io/gltffile.h
  27. 0
      src/inferno/io/input.cpp
  28. 0
      src/inferno/io/input.h
  29. 0
      src/inferno/io/log.cpp
  30. 0
      src/inferno/io/log.h
  31. 0
      src/inferno/keycodes.cpp
  32. 0
      src/inferno/keycodes.h
  33. 0
      src/inferno/render/buffer.cpp
  34. 0
      src/inferno/render/buffer.h
  35. 0
      src/inferno/render/context.cpp
  36. 0
      src/inferno/render/context.h
  37. 0
      src/inferno/render/font.cpp
  38. 0
      src/inferno/render/font.h
  39. 15
      src/inferno/render/framebuffer.cpp
  40. 14
      src/inferno/render/framebuffer.h
  41. 0
      src/inferno/render/gltf.cpp
  42. 0
      src/inferno/render/gltf.h
  43. 0
      src/inferno/render/renderer.cpp
  44. 0
      src/inferno/render/renderer.h
  45. 7
      src/inferno/render/renderer3d.cpp
  46. 40
      src/inferno/render/renderer3d.h
  47. 0
      src/inferno/render/shader.cpp
  48. 0
      src/inferno/render/shader.h
  49. 0
      src/inferno/render/texture.cpp
  50. 0
      src/inferno/render/texture.h
  51. 0
      src/inferno/scene/scene.cpp
  52. 0
      src/inferno/scene/scene.h
  53. 0
      src/inferno/script/cameracontroller.cpp
  54. 0
      src/inferno/script/cameracontroller.h
  55. 0
      src/inferno/script/luascript.cpp
  56. 0
      src/inferno/script/luascript.h
  57. 0
      src/inferno/script/nativescript.h
  58. 0
      src/inferno/script/registration.cpp
  59. 0
      src/inferno/script/registration.h
  60. 0
      src/inferno/settings.cpp
  61. 0
      src/inferno/settings.h
  62. 0
      src/inferno/singleton.h
  63. 0
      src/inferno/system/camerasystem.cpp
  64. 0
      src/inferno/system/camerasystem.h
  65. 0
      src/inferno/system/rendersystem.cpp
  66. 0
      src/inferno/system/rendersystem.h
  67. 0
      src/inferno/system/scriptsystem.cpp
  68. 0
      src/inferno/system/scriptsystem.h
  69. 117
      src/inferno/system/textareasystem.cpp
  70. 39
      src/inferno/system/textareasystem.h
  71. 0
      src/inferno/system/transformsystem.cpp
  72. 0
      src/inferno/system/transformsystem.h
  73. 0
      src/inferno/time.cpp
  74. 0
      src/inferno/time.h
  75. 0
      src/inferno/util/integer.h
  76. 0
      src/inferno/util/json.h
  77. 0
      src/inferno/util/string.h
  78. 0
      src/inferno/window.cpp
  79. 0
      src/inferno/window.h

6
CMakeLists.txt

@ -58,18 +58,18 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Engine dependencies target # Engine dependencies target
# Add engine target to project # Add engine target to project
add_subdirectory("${CMAKE_SOURCE_DIR}/vendor") add_subdirectory("vendor")
# ------------------------------------------ # ------------------------------------------
# Engine target # Engine target
# Add engine target to project # Add engine target to project
add_subdirectory("${CMAKE_SOURCE_DIR}/${ENGINE}") add_subdirectory("src")
# ------------------------------------------ # ------------------------------------------
# Examples target # Examples target
if (INFERNO_BUILD_EXAMPLES) if (INFERNO_BUILD_EXAMPLES)
# Add examples target to project # Add examples target to project
add_subdirectory("${CMAKE_SOURCE_DIR}/example") add_subdirectory("example")
endif() endif()

2
example/CMakeLists.txt

@ -14,7 +14,7 @@ file(GLOB_RECURSE GAME_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
add_executable(${GAME} ${GAME_SOURCES}) add_executable(${GAME} ${GAME_SOURCES})
target_include_directories(${GAME} PRIVATE target_include_directories(${GAME} PRIVATE
"src" "src"
"${CMAKE_SOURCE_DIR}/${ENGINE}/src") "${CMAKE_SOURCE_DIR}/src")
target_link_libraries(${GAME} ${ENGINE}) target_link_libraries(${GAME} ${ENGINE})
target_precompile_headers(${GAME} REUSE_FROM ${ENGINE}) target_precompile_headers(${GAME} REUSE_FROM ${ENGINE})

4
inferno/CMakeLists.txt → 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}) add_library(${ENGINE} ${ENGINE_SOURCES})
target_include_directories(${ENGINE} PRIVATE target_include_directories(${ENGINE} PRIVATE
"src" "${CMAKE_SOURCE_DIR}/src"
"${CMAKE_SOURCE_DIR}/vendor/entt/src" "${CMAKE_SOURCE_DIR}/vendor/entt/src"
"${CMAKE_SOURCE_DIR}/vendor/glad/include" "${CMAKE_SOURCE_DIR}/vendor/glad/include"
"${CMAKE_SOURCE_DIR}/vendor/glfw/include" "${CMAKE_SOURCE_DIR}/vendor/glfw/include"

0
inferno/src/inferno.h → src/inferno.h

0
inferno/src/inferno/application.cpp → src/inferno/application.cpp

0
inferno/src/inferno/application.h → src/inferno/application.h

0
inferno/src/inferno/assert.h → src/inferno/assert.h

0
inferno/src/inferno/component/cameracomponent.h → src/inferno/component/cameracomponent.h

0
inferno/src/inferno/component/luascriptcomponent.h → src/inferno/component/luascriptcomponent.h

0
inferno/src/inferno/component/nativescriptcomponent.h → src/inferno/component/nativescriptcomponent.h

0
inferno/src/inferno/component/spritecomponent.h → src/inferno/component/spritecomponent.h

0
inferno/src/inferno/component/tagcomponent.h → src/inferno/component/tagcomponent.h

32
src/inferno/component/textareacomponent.h

@ -0,0 +1,32 @@
#ifndef TEXTAREA_COMPONENT_H
#define TEXTAREA_COMPONENT_H
#include <cstdint> // uint32_t
#include <string> // std::string
#include <utility> // 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

0
inferno/src/inferno/component/transformcomponent.cpp → src/inferno/component/transformcomponent.cpp

0
inferno/src/inferno/component/transformcomponent.h → src/inferno/component/transformcomponent.h

0
inferno/src/inferno/core.h → src/inferno/core.h

0
inferno/src/inferno/entrypoint.h → src/inferno/entrypoint.h

0
inferno/src/inferno/event/applicationevent.h → src/inferno/event/applicationevent.h

0
inferno/src/inferno/event/event.h → src/inferno/event/event.h

0
inferno/src/inferno/event/joystickevent.h → src/inferno/event/joystickevent.h

0
inferno/src/inferno/event/keyevent.h → src/inferno/event/keyevent.h

0
inferno/src/inferno/event/mouseevent.h → src/inferno/event/mouseevent.h

0
inferno/src/inferno/io/file.cpp → src/inferno/io/file.cpp

0
inferno/src/inferno/io/file.h → src/inferno/io/file.h

0
inferno/src/inferno/io/gltffile.cpp → src/inferno/io/gltffile.cpp

0
inferno/src/inferno/io/gltffile.h → src/inferno/io/gltffile.h

0
inferno/src/inferno/io/input.cpp → src/inferno/io/input.cpp

0
inferno/src/inferno/io/input.h → src/inferno/io/input.h

0
inferno/src/inferno/io/log.cpp → src/inferno/io/log.cpp

0
inferno/src/inferno/io/log.h → src/inferno/io/log.h

0
inferno/src/inferno/keycodes.cpp → src/inferno/keycodes.cpp

0
inferno/src/inferno/keycodes.h → src/inferno/keycodes.h

0
inferno/src/inferno/render/buffer.cpp → src/inferno/render/buffer.cpp

0
inferno/src/inferno/render/buffer.h → src/inferno/render/buffer.h

0
inferno/src/inferno/render/context.cpp → src/inferno/render/context.cpp

0
inferno/src/inferno/render/context.h → src/inferno/render/context.h

0
inferno/src/inferno/render/font.cpp → src/inferno/render/font.cpp

0
inferno/src/inferno/render/font.h → src/inferno/render/font.h

15
src/inferno/render/framebuffer.cpp

@ -0,0 +1,15 @@
#include "inferno/render/framebuffer.h"
namespace Inferno {
Framebuffer::Framebuffer()
{
}
Framebuffer::~Framebuffer()
{
}
// -----------------------------------------
} // namespace Inferno

14
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

0
inferno/src/inferno/render/gltf.cpp → src/inferno/render/gltf.cpp

0
inferno/src/inferno/render/gltf.h → src/inferno/render/gltf.h

0
inferno/src/inferno/render/renderer.cpp → src/inferno/render/renderer.cpp

0
inferno/src/inferno/render/renderer.h → src/inferno/render/renderer.h

7
src/inferno/render/renderer3d.cpp

@ -0,0 +1,7 @@
#include "inferno/render/renderer3d.h"
namespace Inferno {
//..
} // namespace Inferno

40
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

0
inferno/src/inferno/render/shader.cpp → src/inferno/render/shader.cpp

0
inferno/src/inferno/render/shader.h → src/inferno/render/shader.h

0
inferno/src/inferno/render/texture.cpp → src/inferno/render/texture.cpp

0
inferno/src/inferno/render/texture.h → src/inferno/render/texture.h

0
inferno/src/inferno/scene/scene.cpp → src/inferno/scene/scene.cpp

0
inferno/src/inferno/scene/scene.h → src/inferno/scene/scene.h

0
inferno/src/inferno/script/cameracontroller.cpp → src/inferno/script/cameracontroller.cpp

0
inferno/src/inferno/script/cameracontroller.h → src/inferno/script/cameracontroller.h

0
inferno/src/inferno/script/luascript.cpp → src/inferno/script/luascript.cpp

0
inferno/src/inferno/script/luascript.h → src/inferno/script/luascript.h

0
inferno/src/inferno/script/nativescript.h → src/inferno/script/nativescript.h

0
inferno/src/inferno/script/registration.cpp → src/inferno/script/registration.cpp

0
inferno/src/inferno/script/registration.h → src/inferno/script/registration.h

0
inferno/src/inferno/settings.cpp → src/inferno/settings.cpp

0
inferno/src/inferno/settings.h → src/inferno/settings.h

0
inferno/src/inferno/singleton.h → src/inferno/singleton.h

0
inferno/src/inferno/system/camerasystem.cpp → src/inferno/system/camerasystem.cpp

0
inferno/src/inferno/system/camerasystem.h → src/inferno/system/camerasystem.h

0
inferno/src/inferno/system/rendersystem.cpp → src/inferno/system/rendersystem.cpp

0
inferno/src/inferno/system/rendersystem.h → src/inferno/system/rendersystem.h

0
inferno/src/inferno/system/scriptsystem.cpp → src/inferno/system/scriptsystem.cpp

0
inferno/src/inferno/system/scriptsystem.h → src/inferno/system/scriptsystem.h

117
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<TransformComponent, TextAreaComponent>();
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> font = FontManager::the().load(textarea.font);
// glm::mat4 translate = transform.translate;
float advance = 0.0f;
for (auto character : textarea.content) {
std::optional<CharacterQuad> quad = calculateCharacterQuad(character, font, advance);
if (quad) {
RendererCharacter::the().drawCharacter(quad.value(), font->texture());
}
}
}
}
std::optional<CharacterQuad> TextAreaSystem::calculateCharacterQuad(unsigned char character, std::shared_ptr<Font> font, float& advance)
{
CharacterQuad characterQuad;
auto c = font->get(character);
// Texture
// ---------------------------------
float textureWidth = static_cast<float>(font->texture()->width());
float textureHeight = static_cast<float>(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

39
src/inferno/system/textareasystem.h

@ -0,0 +1,39 @@
#ifndef TEXTAREA_H
#define TEXTAREA_H
#include <cstdint> // std::uint32_t
#include <memory> // std::shared_ptr
#include <optional> // std::optional
#include <vector> // 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<CharacterVertex, Renderer::vertexPerQuad>;
class Font;
class Scene;
class TextAreaSystem final : public Singleton<TextAreaSystem> {
public:
TextAreaSystem(s);
virtual ~TextAreaSystem();
void render();
void setScene(Scene* scene) { m_scene = scene; }
private:
std::optional<CharacterQuad> calculateCharacterQuad(unsigned char character, std::shared_ptr<Font> font, float& advance);
Scene* m_scene { nullptr };
};
} // namespace Inferno
#endif // TEXTAREA_H

0
inferno/src/inferno/system/transformsystem.cpp → src/inferno/system/transformsystem.cpp

0
inferno/src/inferno/system/transformsystem.h → src/inferno/system/transformsystem.h

0
inferno/src/inferno/time.cpp → src/inferno/time.cpp

0
inferno/src/inferno/time.h → src/inferno/time.h

0
inferno/src/inferno/util/integer.h → src/inferno/util/integer.h

0
inferno/src/inferno/util/json.h → src/inferno/util/json.h

0
inferno/src/inferno/util/string.h → src/inferno/util/string.h

0
inferno/src/inferno/window.cpp → src/inferno/window.cpp

0
inferno/src/inferno/window.h → src/inferno/window.h

Loading…
Cancel
Save