2020-05-05 01:51:13 +02:00
|
|
|
#pragma once
|
2022-11-15 12:19:11 +01:00
|
|
|
#include <entt/entt.hpp>
|
2020-04-15 02:03:56 +02:00
|
|
|
#include "MinimalEngine.h"
|
2023-01-29 18:58:59 +01:00
|
|
|
#include "Graphics/Graphics.h"
|
2020-06-02 11:46:18 +02:00
|
|
|
#include "Graphics/MeshBatch.h"
|
2023-01-21 18:43:21 +01:00
|
|
|
#include "Physics/PhysicsSystem.h"
|
2023-02-01 22:13:04 +01:00
|
|
|
#include "Component/Skybox.h"
|
2020-04-15 02:03:56 +02:00
|
|
|
|
|
|
|
|
namespace Seele
|
|
|
|
|
{
|
2021-04-01 16:40:14 +02:00
|
|
|
DECLARE_REF(Material)
|
2022-11-15 12:19:11 +01:00
|
|
|
DECLARE_REF(Entity)
|
2020-05-05 01:51:13 +02:00
|
|
|
|
2020-09-30 13:48:41 +02:00
|
|
|
struct DirectionalLight
|
|
|
|
|
{
|
2023-01-21 18:43:21 +01:00
|
|
|
Vector4 color;
|
|
|
|
|
Vector4 direction;
|
|
|
|
|
Vector4 intensity;
|
2020-09-30 13:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PointLight
|
|
|
|
|
{
|
2023-01-21 18:43:21 +01:00
|
|
|
Vector4 positionWS;
|
2022-03-19 22:45:30 +01:00
|
|
|
//Vector4 positionVS;
|
2023-01-21 18:43:21 +01:00
|
|
|
Vector4 colorRange;
|
2020-09-30 13:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define MAX_DIRECTIONAL_LIGHTS 4
|
|
|
|
|
#define MAX_POINT_LIGHTS 256
|
|
|
|
|
struct LightEnv
|
|
|
|
|
{
|
|
|
|
|
DirectionalLight directionalLights[MAX_DIRECTIONAL_LIGHTS];
|
|
|
|
|
PointLight pointLights[MAX_POINT_LIGHTS];
|
2021-01-19 15:30:00 +01:00
|
|
|
uint32 numDirectionalLights;
|
2020-09-30 13:48:41 +02:00
|
|
|
uint32 numPointLights;
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-15 02:03:56 +02:00
|
|
|
class Scene
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
Scene(Gfx::PGraphics graphics);
|
2020-04-15 02:03:56 +02:00
|
|
|
~Scene();
|
2023-01-21 18:43:21 +01:00
|
|
|
void update(float deltaTime);
|
2022-11-15 12:19:11 +01:00
|
|
|
entt::entity createEntity()
|
|
|
|
|
{
|
|
|
|
|
return registry.create();
|
|
|
|
|
}
|
2023-01-21 18:43:21 +01:00
|
|
|
void destroyEntity(entt::entity identifier)
|
2022-11-15 12:19:11 +01:00
|
|
|
{
|
2023-01-21 18:43:21 +01:00
|
|
|
registry.destroy(identifier);
|
|
|
|
|
}
|
|
|
|
|
template<typename Component, typename... Args>
|
|
|
|
|
Component& attachComponent(entt::entity entity, Args&&... args)
|
|
|
|
|
{
|
|
|
|
|
return registry.emplace<Component>(entity, std::forward<Args>(args)...);
|
2022-11-15 12:19:11 +01:00
|
|
|
}
|
|
|
|
|
template<typename Component>
|
|
|
|
|
Component& accessComponent(entt::entity entity)
|
|
|
|
|
{
|
|
|
|
|
return registry.get<Component>(entity);
|
|
|
|
|
}
|
|
|
|
|
template<typename Component>
|
|
|
|
|
const Component& accessComponent(entt::entity entity) const
|
|
|
|
|
{
|
|
|
|
|
return registry.get<Component>(entity);
|
|
|
|
|
}
|
2023-01-29 18:58:59 +01:00
|
|
|
template<typename Component, typename Func>
|
|
|
|
|
void view(Func func) requires std::is_invocable_v<Func, Component&>
|
|
|
|
|
{
|
|
|
|
|
registry.view<Component>().each(func);
|
|
|
|
|
}
|
2022-11-15 12:19:11 +01:00
|
|
|
Array<StaticMeshBatch> getStaticMeshes();
|
|
|
|
|
LightEnv getLightBuffer() const;
|
2023-02-01 22:13:04 +01:00
|
|
|
Component::Skybox getSkybox();
|
2023-01-21 18:43:21 +01:00
|
|
|
Gfx::PStructuredBuffer getSceneDataBuffer() const { return sceneDataBuffer; }
|
2023-01-29 18:58:59 +01:00
|
|
|
Gfx::PGraphics getGraphics() const { return graphics; }
|
2022-11-15 12:19:11 +01:00
|
|
|
entt::registry registry;
|
2020-04-15 02:03:56 +02:00
|
|
|
private:
|
2023-01-21 18:43:21 +01:00
|
|
|
struct PrimitiveSceneData
|
|
|
|
|
{
|
|
|
|
|
Matrix4 localToWorld;
|
|
|
|
|
Matrix4 worldToLocal;
|
|
|
|
|
Vector4 actorLocation;
|
|
|
|
|
};
|
|
|
|
|
Array<PrimitiveSceneData> sceneData;
|
|
|
|
|
Gfx::PStructuredBuffer sceneDataBuffer;
|
|
|
|
|
PhysicsSystem physics;
|
2020-09-19 14:36:50 +02:00
|
|
|
Gfx::PGraphics graphics;
|
2020-04-15 02:03:56 +02:00
|
|
|
};
|
2022-11-15 12:19:11 +01:00
|
|
|
DEFINE_REF(Scene)
|
2020-05-05 01:51:13 +02:00
|
|
|
} // namespace Seele
|