Files
Seele/src/Engine/Window/GameView.cpp
T

106 lines
3.8 KiB
C++
Raw Normal View History

2023-02-24 22:09:07 +01:00
#include "GameView.h"
#include "Actor/CameraActor.h"
#include "Asset/AssetRegistry.h"
2024-06-09 12:20:04 +02:00
#include "Component/KeyboardInput.h"
#include "Graphics/Graphics.h"
2024-06-15 21:47:20 +02:00
#include "Graphics/Query.h"
2024-06-11 14:15:29 +02:00
#include "Graphics/RenderPass/BasePass.h"
2024-06-15 21:47:20 +02:00
#include "Graphics/RenderPass/CachedDepthPass.h"
#include "Graphics/RenderPass/DepthCullingPass.h"
#include "Graphics/RenderPass/LightCullingPass.h"
2024-12-25 14:59:08 +01:00
#include "Graphics/RenderPass/RayTracingPass.h"
2024-06-15 21:47:20 +02:00
#include "Graphics/RenderPass/RenderGraphResources.h"
#include "Graphics/RenderPass/VisibilityPass.h"
2025-03-10 18:35:35 +01:00
#include "Graphics/RenderPass/ToneMappingPass.h"
2024-06-09 12:20:04 +02:00
#include "System/CameraUpdater.h"
2023-11-08 23:27:21 +01:00
#include "System/LightGather.h"
#include "System/MeshUpdater.h"
2024-06-09 12:20:04 +02:00
#include "Window/Window.h"
2023-02-24 22:09:07 +01:00
using namespace Seele;
2025-04-11 13:49:37 +02:00
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath)
: View(graphics, window, createInfo, "Game"), graphics(graphics), scene(new Scene(graphics)), gameInterface(dllPath) {
2023-04-09 16:39:53 +02:00
reloadGame();
2024-07-18 11:45:56 +02:00
renderGraph.addPass(new CachedDepthPass(graphics, scene));
renderGraph.addPass(new DepthCullingPass(graphics, scene));
2025-01-08 19:15:12 +01:00
renderGraph.addPass(new VisibilityPass(graphics));
2024-07-18 11:45:56 +02:00
renderGraph.addPass(new LightCullingPass(graphics, scene));
renderGraph.addPass(new BasePass(graphics, scene));
2025-03-10 18:35:35 +01:00
renderGraph.addPass(new ToneMappingPass(graphics));
2024-04-05 10:41:59 +02:00
renderGraph.setViewport(viewport);
renderGraph.createRenderPass();
2025-01-08 19:15:12 +01:00
if (graphics->supportRayTracing()) {
rayTracingGraph.addPass(new RayTracingPass(graphics, scene));
2025-03-26 13:38:48 +01:00
rayTracingGraph.addPass(new ToneMappingPass(graphics));
2025-01-08 19:15:12 +01:00
rayTracingGraph.setViewport(viewport);
rayTracingGraph.createRenderPass();
}
2025-01-30 23:25:41 +01:00
2023-02-24 22:09:07 +01:00
}
2024-06-09 12:20:04 +02:00
GameView::~GameView() {}
2023-02-24 22:09:07 +01:00
2024-06-09 12:20:04 +02:00
void GameView::beginUpdate() {}
2023-02-24 22:09:07 +01:00
2024-06-09 12:20:04 +02:00
void GameView::update() {
2023-02-24 22:09:07 +01:00
static auto startTime = std::chrono::high_resolution_clock::now();
2024-06-09 12:20:04 +02:00
for (VertexData* vd : VertexData::getList()) {
2023-10-24 15:01:09 +02:00
vd->resetMeshData();
}
2024-05-01 19:05:48 +02:00
systemGraph->run(updateTime);
2023-02-24 22:09:07 +01:00
scene->update(updateTime);
2024-06-09 12:20:04 +02:00
for (VertexData* vd : VertexData::getList()) {
2023-10-24 15:01:09 +02:00
vd->createDescriptors();
}
2023-11-05 10:36:01 +01:00
scene->getLightEnvironment()->commit();
2023-02-24 22:09:07 +01:00
auto endTime = std::chrono::high_resolution_clock::now();
std::chrono::duration<float> duration = (endTime - startTime);
updateTime = duration.count();
startTime = endTime;
}
2024-06-09 12:20:04 +02:00
void GameView::commitUpdate() {}
2023-02-24 22:09:07 +01:00
2024-06-09 12:20:04 +02:00
void GameView::prepareRender() {}
2023-02-24 22:09:07 +01:00
2024-06-09 12:20:04 +02:00
void GameView::render() {
2023-11-17 22:31:26 +01:00
Component::Camera cam;
scene->view<Component::Camera>([&cam](Component::Camera& c) {
2024-06-09 12:20:04 +02:00
if (c.mainCamera)
2023-12-28 21:42:18 +01:00
cam = c;
2023-11-17 22:31:26 +01:00
});
2025-01-08 19:15:12 +01:00
if (getGlobals().useRayTracing && graphics->supportRayTracing()) {
2024-12-25 14:59:08 +01:00
rayTracingGraph.render(cam);
} else {
renderGraph.render(cam);
}
2023-02-24 22:09:07 +01:00
}
2024-06-09 12:20:04 +02:00
void GameView::applyArea(URect) { renderGraph.setViewport(viewport); }
2023-11-18 11:04:30 +01:00
2024-06-09 12:20:04 +02:00
void GameView::reloadGame() {
2024-01-11 21:40:46 +01:00
gameInterface.reload();
2024-06-09 12:20:04 +02:00
2023-04-09 16:39:53 +02:00
systemGraph = new SystemGraph();
gameInterface.getGame()->setupScene(scene, systemGraph);
2023-11-17 22:31:26 +01:00
System::OKeyboardInput keyInput = new System::KeyboardInput(scene);
keyboardSystem = keyInput;
systemGraph->addSystem(std::move(keyInput));
2023-11-08 23:27:21 +01:00
systemGraph->addSystem(new System::LightGather(scene));
systemGraph->addSystem(new System::MeshUpdater(scene));
2023-11-10 19:18:09 +01:00
systemGraph->addSystem(new System::CameraUpdater(scene));
2023-04-09 16:39:53 +02:00
}
2024-12-25 14:59:08 +01:00
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier) { keyboardSystem->keyCallback(code, action, modifier); }
2023-02-24 22:09:07 +01:00
2024-06-09 12:20:04 +02:00
void GameView::mouseMoveCallback(double xPos, double yPos) { keyboardSystem->mouseCallback(xPos, yPos); }
2023-02-24 22:09:07 +01:00
2024-06-09 12:20:04 +02:00
void GameView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) {
2023-11-17 22:31:26 +01:00
keyboardSystem->mouseButtonCallback(button, action, modifier);
2023-02-24 22:09:07 +01:00
}
2024-06-09 12:20:04 +02:00
void GameView::scrollCallback(double xScroll, double yScroll) { keyboardSystem->scrollCallback(xScroll, yScroll); }
2023-02-24 22:09:07 +01:00
2024-06-09 12:20:04 +02:00
void GameView::fileCallback(int, const char**) {}