Component changes

This commit is contained in:
2024-08-09 07:59:11 -04:00
parent 61e22684af
commit 35663e6fd4
12 changed files with 132 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ file(GLOB_RECURSE CPP_SOURCES
add_library(FGLEngine STATIC ${CPP_SOURCES} ${HPP_SOURCES})
set(CMAKE_CXX_STANDARD 23)
if (DEFINED FGL_ENABLE_PCH)
if (DEFINED FGL_ENABLE_PCH AND FGL_ENABLE_PCH)
target_precompile_headers(FGLEngine PRIVATE
@@ -54,11 +54,7 @@ else ()
target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI_DRAWERS=0)
endif ()
if (NOT DEFINED FGL_ENABLE_TESTS)
set(FGL_ENABLE_TESTS 0)
endif ()
if (FGL_ENABLE_TESTS)
if (DEFINED FGL_ENABLE_TESTS AND FGL_ENABLE_TESTS)
target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=1)
target_link_libraries(FGLEngine PUBLIC Catch2)
else ()
@@ -69,7 +65,12 @@ endif ()
# with the game itself
target_compile_definitions(FGLEngine PUBLIC TRACK_BUFFERS)
#GLM settings
# GLM_FORCE_NO_CTOR_INIT
target_compile_definitions(FGLEngine PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_FORCE_LEFT_HANDED)
if (DEFINED FGL_ENABLE_CALIBRATED_PROFILING AND FGL_ENABLE_CALIBRATED_PROFILING)
target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=1)
else ()
target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=0)
endif ()

View File

@@ -189,7 +189,7 @@ namespace fgl::engine
renderFrame();
using namespace std::chrono_literals;
std::this_thread::sleep_for( 13ms );
// std::this_thread::sleep_for( 13ms );
}
Device::getInstance().device().waitIdle();

View File

@@ -7,8 +7,8 @@
#include <unordered_map>
#include <vector>
#include "components/GameObjectComponent.hpp"
#include "components/ModelComponent.hpp"
#include "engine/gameobjects/components/interface/GameObjectComponent.hpp"
#include "engine/primitives/TransformComponent.hpp"
namespace fgl::engine

View File

@@ -5,20 +5,20 @@
#pragma once
#include <memory>
#include "GameObjectComponent.hpp"
#include "engine/gameobjects/components/interface/GameObjectComponent.hpp"
namespace fgl::engine
{
class Camera;
class CameraComponent final : public GameObjectComponent< 2 >
COMPONENT_CLASS( CameraComponent, CameraComponentID )
{
std::shared_ptr< Camera > m_camera;
public:
CameraComponent() = delete;
CameraComponent( std::shared_ptr< Camera >& camera );
CameraComponent( std::shared_ptr< Camera > & camera );
~CameraComponent();
};

View File

@@ -0,0 +1,21 @@
//
// Created by kj16609 on 8/8/24.
//
#pragma once
#define ASSIGN_COMPONENT_ID( name, id ) constexpr ComponentID name { id };
#include <cstdint>
namespace fgl::engine
{
using ComponentID = std::uint32_t;
ASSIGN_COMPONENT_ID( ModelComponentID, 1 );
ASSIGN_COMPONENT_ID( CameraComponentID, 2 );
ASSIGN_COMPONENT_ID( PointLightComponentID, 10 );
ASSIGN_COMPONENT_ID( DirectionalLightComponentID, 11 );
} // namespace fgl::engine

View File

@@ -6,19 +6,21 @@
#include <filesystem>
#include <memory>
#include "GameObjectComponent.hpp"
#include "ComponentIDS.hpp"
#include "engine/gameobjects/components/interface/GameObjectComponent.hpp"
namespace fgl::engine
{
class Model;
class ModelComponent final : public GameObjectComponent< 1 >
COMPONENT_CLASS( ModelComponent, ModelComponentID )
{
std::shared_ptr< Model > m_model;
public:
ModelComponent( std::shared_ptr< Model >&& model ) : m_model( std::forward< decltype( m_model ) >( model ) ) {}
ModelComponent( std::shared_ptr< Model > && model ) : m_model( std::forward< decltype( m_model ) >( model ) )
{}
#ifdef TITOR_EDITOR
void drawImGui() override;
@@ -30,11 +32,18 @@ namespace fgl::engine
}
#endif
virtual ~ModelComponent() override {}
virtual ~ModelComponent() override
{}
Model* operator->() { return m_model.get(); }
Model* operator->()
{
return m_model.get();
}
const Model* operator->() const { return m_model.get(); }
const Model* operator->() const
{
return m_model.get();
}
};
static_assert( is_component< ModelComponent > );

View File

@@ -0,0 +1,31 @@
//
// Created by kj16609 on 8/8/24.
//
#pragma once
#include "interface/GameObjectComponent.hpp"
namespace fgl::engine
{
using LightMask = uint32_t;
COMPONENT_CLASS( PointLightComponent, PointLightComponentID )
{
glm::vec3 m_color;
float m_brightness;
//! Objects that fit this mask should be lit by this light
LightMask m_lighting_mask;
//! Objects that fit this mask should not block this light.
LightMask m_block_mask;
//! Objects that fit this mask should not be shadowed by this light
LightMask m_shadowed_mask;
public:
};
} // namespace fgl::engine

View File

@@ -5,17 +5,34 @@
#pragma once
#include "ComponentEngineInterface.hpp"
#include "engine/gameobjects/components/ComponentIDS.hpp"
#include "engine/primitives/TransformComponent.hpp"
#define COMPONENT_CLASS( class_name, id_name ) class class_name final : public GameObjectComponent< id_name >
namespace fgl::engine
{
using ComponentTransform = TransformComponent;
struct ComponentTransform final : public TransformComponent
{
enum Mode
{
//! Object is non moving,
Static,
//! Object moves in relation to it's parent
Local,
//! Object moves in relation to the world
Global
} m_mode;
};
struct GameObjectComponentBase : public ComponentEditorInterface, public ComponentEngineInterface
{};
using GameObjectComponentPtr = GameObjectComponentBase*;
//TODO: Add way to add components to an object in the editor.
template < ComponentEngineInterface::ComponentID T_ID >
struct GameObjectComponent : public GameObjectComponentBase
{
@@ -28,9 +45,7 @@ namespace fgl::engine
template < typename T >
concept is_component = requires( T t ) {
std::is_base_of_v< T, ComponentEngineInterface >;
{
t.ID
} -> std::same_as< const ComponentEngineInterface::ComponentID& >;
{ t.ID } -> std::same_as< const ComponentEngineInterface::ComponentID& >;
};
} // namespace fgl::engine

View File

@@ -77,7 +77,11 @@ namespace fgl::engine
}
const static std::vector< const char* > required_device_extensions { VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME };
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
#if ENABLE_CALIBRATED_PROFILING
VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME
#endif
};
bool PhysicalDevice::supportsRequiredExtensions()
{

View File

@@ -58,7 +58,35 @@ namespace fgl::engine
TracyVkCtx createContext( PhysicalDevice& physical_device, Device& device, vk::raii::CommandBuffer& cmd_buffer )
{
#if ENABLE_CALIBRATED_PROFILING
// The calibrated context wants the calibration extention and two function pointers.
auto getPhysicalDeviceClibrateableTimeDomains {
reinterpret_cast< PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT >(
device->getProcAddr( "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR" ) )
};
auto getCalibratedTimestamps {
reinterpret_cast< PFN_vkGetCalibratedTimestampsEXT >( device
->getProcAddr( "vkGetCalibratedTimestampsKHR" ) )
};
if ( getPhysicalDeviceClibrateableTimeDomains == nullptr )
throw std::runtime_error( "Failed to get vkGetPhysicalDeviceCalibratableTimeDomainsEXT" );
if ( getCalibratedTimestamps == nullptr )
throw std::runtime_error( "Failed to get vkGetCalibratedTimestampsEXT" );
return TracyVkContextCalibrated(
*physical_device,
*device,
*device.graphicsQueue(),
*cmd_buffer,
getPhysicalDeviceClibrateableTimeDomains,
getCalibratedTimestamps );
#else
return TracyVkContext( *physical_device, *device, *device.graphicsQueue(), *cmd_buffer );
#endif
}
void Renderer::createCommandBuffers()