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"
|
2024-06-11 14:15:29 +02:00
|
|
|
#include "Graphics/RenderPass/DebugPass.h"
|
2024-06-15 21:47:20 +02:00
|
|
|
#include "Graphics/RenderPass/DepthCullingPass.h"
|
|
|
|
|
#include "Graphics/RenderPass/LightCullingPass.h"
|
|
|
|
|
#include "Graphics/RenderPass/RenderGraphResources.h"
|
|
|
|
|
#include "Graphics/RenderPass/SkyboxRenderPass.h"
|
|
|
|
|
#include "Graphics/RenderPass/VisibilityPass.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"
|
2024-07-01 12:17:04 +02:00
|
|
|
#include <fstream>
|
2023-02-24 22:09:07 +01:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2024-05-23 14:58:14 +02:00
|
|
|
bool usePositionOnly = false;
|
2024-06-11 16:55:20 +02:00
|
|
|
bool useDepthCulling = false;
|
2024-05-29 10:40:35 +02:00
|
|
|
bool useLightCulling = false;
|
2024-06-07 18:43:10 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath)
|
|
|
|
|
: View(graphics, window, createInfo, "Game"), scene(new Scene(graphics)), gameInterface(dllPath) {
|
2023-04-09 16:39:53 +02:00
|
|
|
reloadGame();
|
2024-05-30 16:56:22 +02:00
|
|
|
renderGraph.addPass(new CachedDepthPass(graphics, scene));
|
2024-06-11 14:15:29 +02:00
|
|
|
renderGraph.addPass(new DepthCullingPass(graphics, scene));
|
2024-06-07 09:19:47 +02:00
|
|
|
renderGraph.addPass(new VisibilityPass(graphics, scene));
|
2024-04-05 10:41:59 +02:00
|
|
|
renderGraph.addPass(new LightCullingPass(graphics, scene));
|
|
|
|
|
renderGraph.addPass(new BasePass(graphics, scene));
|
2024-05-15 15:27:13 +02:00
|
|
|
renderGraph.addPass(new DebugPass(graphics, scene));
|
2024-06-15 21:47:20 +02:00
|
|
|
// renderGraph.addPass(new SkyboxRenderPass(graphics, scene));
|
2024-04-05 10:41:59 +02:00
|
|
|
renderGraph.setViewport(viewport);
|
|
|
|
|
renderGraph.createRenderPass();
|
2024-06-15 21:47:20 +02:00
|
|
|
queryThread = std::thread([&]() {
|
|
|
|
|
PRenderGraphResources res = renderGraph.getResources();
|
|
|
|
|
Gfx::PPipelineStatisticsQuery cachedQuery = res->requestQuery("CACHED_QUERY");
|
|
|
|
|
Gfx::PPipelineStatisticsQuery depthQuery = res->requestQuery("DEPTH_QUERY");
|
|
|
|
|
Gfx::PPipelineStatisticsQuery baseQuery = res->requestQuery("BASEPASS_QUERY");
|
|
|
|
|
Gfx::PPipelineStatisticsQuery lightCullQuery = res->requestQuery("LIGHTCULL_QUERY");
|
|
|
|
|
Gfx::PPipelineStatisticsQuery visibilityQuery = res->requestQuery("VISIBILITY_QUERY");
|
2024-07-01 12:17:04 +02:00
|
|
|
Gfx::PTimestampQuery timeQuery = res->requestTimestampQuery("TIMESTAMP");
|
|
|
|
|
std::ofstream stats("stats.csv");
|
|
|
|
|
stats << "RelTime,"
|
|
|
|
|
<< "CachedIAV,CachedIAP,CachedVS,CachedClipInv,CachedClipPrim,CachedFS,CachedCS,CachedTS,CachedMS,"
|
|
|
|
|
<< "DepthIAV,DepthIAP,DepthVS,DepthClipInv,DepthClipPrim,DepthFS,DepthCS,DepthTS,DepthMS,"
|
|
|
|
|
<< "BaseIAV,BaseIAP,BaseVS,BaseClipInv,BaseClipPrim,BaseFS,BaseCS,BaseTS,BaseMS,"
|
|
|
|
|
<< "LightCullIAV,LightCullIAP,LightCullVS,LightCullClipInv,LightCullClipPrim,LightCullFS,LightCullCS,LightCullTS,LightCullMS,"
|
|
|
|
|
<< "VisibilityIAV,VisibilityIAP,VisibilityVS,VisibilityClipInv,VisibilityClipPrim,VisibilityFS,VisibilityCS,VisibilityTS,"
|
|
|
|
|
"VisibilityMS,"
|
|
|
|
|
<< "CACHED,MIPGEN,DEPTHCULL,VISIBILITY,LIGHTCULL,BASE" << std::endl;
|
|
|
|
|
std::chrono::nanoseconds start = std::chrono::nanoseconds(0);
|
2024-06-15 21:47:20 +02:00
|
|
|
while (true) {
|
2024-07-01 12:17:04 +02:00
|
|
|
auto timestamps = timeQuery->getResults();
|
2024-06-15 21:47:20 +02:00
|
|
|
auto cachedResults = cachedQuery->getResults();
|
|
|
|
|
auto depthResults = depthQuery->getResults();
|
|
|
|
|
auto baseResults = baseQuery->getResults();
|
|
|
|
|
auto lightCullResults = lightCullQuery->getResults();
|
|
|
|
|
auto visiblityResults = visibilityQuery->getResults();
|
2024-07-01 12:17:04 +02:00
|
|
|
if (start.count() == 0) {
|
|
|
|
|
start = timestamps[0].time;
|
|
|
|
|
}
|
|
|
|
|
stats << (timestamps[0].time - start).count() << "," << cachedResults << depthResults << baseResults << lightCullResults
|
|
|
|
|
<< visiblityResults;
|
|
|
|
|
stats << fmt::format("{},{},{},{},{},{}", (timestamps[1].time - timestamps[0].time).count(),
|
|
|
|
|
(timestamps[2].time - timestamps[1].time).count(), (timestamps[3].time - timestamps[2].time).count(),
|
|
|
|
|
(timestamps[4].time - timestamps[3].time).count(), (timestamps[5].time - timestamps[4].time).count(),
|
|
|
|
|
(timestamps[6].time - timestamps[5].time).count())
|
|
|
|
|
<< std::endl;
|
|
|
|
|
stats.flush();
|
2024-06-15 21:47:20 +02: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
|
|
|
});
|
|
|
|
|
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-06-09 12:20:04 +02:00
|
|
|
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier) {
|
2023-11-17 22:31:26 +01:00
|
|
|
keyboardSystem->keyCallback(code, action, modifier);
|
2024-06-09 12:20:04 +02:00
|
|
|
if (code == KeyCode::KEY_P && action == InputAction::RELEASE) {
|
2024-05-29 10:40:35 +02:00
|
|
|
usePositionOnly = !usePositionOnly;
|
|
|
|
|
std::cout << "Use Pos only " << usePositionOnly << std::endl;
|
2024-05-23 14:58:14 +02:00
|
|
|
}
|
2024-06-09 12:20:04 +02:00
|
|
|
if (code == KeyCode::KEY_O && action == InputAction::RELEASE) {
|
2024-06-11 16:55:20 +02:00
|
|
|
useDepthCulling = !useDepthCulling;
|
|
|
|
|
std::cout << "Use Depth Culling " << useDepthCulling << std::endl;
|
2024-05-23 14:58:14 +02:00
|
|
|
}
|
2024-06-09 12:20:04 +02:00
|
|
|
if (code == KeyCode::KEY_L && action == InputAction::RELEASE) {
|
2024-05-29 10:40:35 +02:00
|
|
|
useLightCulling = !useLightCulling;
|
|
|
|
|
std::cout << "Use Light Culling " << useLightCulling << std::endl;
|
2024-05-23 14:58:14 +02:00
|
|
|
}
|
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**) {}
|