Component changes
This commit is contained in:
@@ -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 ()
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
21
src/engine/gameobjects/components/ComponentIDS.hpp
Normal file
21
src/engine/gameobjects/components/ComponentIDS.hpp
Normal 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
|
||||
@@ -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 > );
|
||||
|
||||
31
src/engine/gameobjects/components/PointLightComponent.hpp
Normal file
31
src/engine/gameobjects/components/PointLightComponent.hpp
Normal 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
|
||||
@@ -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
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user