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

121 lines
3.2 KiB
C++
Raw Normal View History

2023-02-24 22:09:07 +01:00
#include "GameView.h"
#include "Graphics/Graphics.h"
#include "Window/Window.h"
#include "Component/KeyboardInput.h"
#include "Actor/CameraActor.h"
#include "Asset/AssetRegistry.h"
2023-11-08 23:27:21 +01:00
#include "System/LightGather.h"
#include "System/MeshUpdater.h"
2023-11-10 19:18:09 +01:00
#include "System/CameraUpdater.h"
2023-12-15 11:57:13 +01:00
#include "Graphics/Vulkan/Graphics.h"
#include "Graphics/Vulkan/Allocator.h"
2023-02-24 22:09:07 +01:00
using namespace Seele;
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string dllPath)
: View(graphics, window, createInfo, "Game")
2023-11-06 14:47:21 +01:00
, scene(new Scene(graphics))
2023-02-24 22:09:07 +01:00
, gameInterface(dllPath)
{
2023-04-09 16:39:53 +02:00
reloadGame();
2024-05-12 19:36:32 +02:00
//renderGraph.addPass(new StaticDepthPrepass(graphics, scene));
2024-04-05 10:41:59 +02:00
renderGraph.addPass(new DepthPrepass(graphics, scene));
renderGraph.addPass(new LightCullingPass(graphics, scene));
2024-05-12 19:36:32 +02:00
//renderGraph.addPass(new StaticBasePass(graphics, scene));
2024-04-05 10:41:59 +02:00
renderGraph.addPass(new BasePass(graphics, scene));
2024-05-15 15:27:13 +02:00
renderGraph.addPass(new DebugPass(graphics, scene));
2024-04-05 10:41:59 +02:00
//renderGraph.addPass(new SkyboxRenderPass(graphics, scene));
renderGraph.setViewport(viewport);
renderGraph.createRenderPass();
2023-02-24 22:09:07 +01:00
}
GameView::~GameView()
{
}
void GameView::beginUpdate()
{
}
void GameView::update()
{
static auto startTime = std::chrono::high_resolution_clock::now();
2023-10-24 15:01:09 +02:00
for (VertexData* vd : VertexData::getList())
{
vd->resetMeshData();
}
2024-05-01 19:05:48 +02:00
systemGraph->run(updateTime);
2023-02-24 22:09:07 +01:00
scene->update(updateTime);
2023-10-24 15:01:09 +02:00
for (VertexData* vd : VertexData::getList())
{
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;
}
void GameView::commitUpdate()
{
}
void GameView::prepareRender()
{
}
void GameView::render()
{
2023-11-17 22:31:26 +01:00
Component::Camera cam;
scene->view<Component::Camera>([&cam](Component::Camera& c) {
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-01-16 21:11:57 +01:00
void GameView::applyArea(URect)
2023-11-18 11:04:30 +01:00
{
2024-04-05 10:41:59 +02:00
renderGraph.setViewport(viewport);
2023-11-18 11:04:30 +01:00
}
2023-04-09 16:39:53 +02:00
void GameView::reloadGame()
{
2024-01-11 21:40:46 +01:00
gameInterface.reload();
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
}
2023-11-17 22:31:26 +01:00
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
2023-02-24 22:09:07 +01:00
{
2023-11-17 22:31:26 +01:00
keyboardSystem->keyCallback(code, action, modifier);
2023-02-24 22:09:07 +01:00
}
void GameView::mouseMoveCallback(double xPos, double yPos)
{
2023-11-17 22:31:26 +01:00
keyboardSystem->mouseCallback(xPos, yPos);
2023-02-24 22:09:07 +01:00
}
2023-11-17 22:31:26 +01:00
void GameView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
2023-02-24 22:09:07 +01:00
{
2023-11-17 22:31:26 +01:00
keyboardSystem->mouseButtonCallback(button, action, modifier);
2023-02-24 22:09:07 +01:00
}
void GameView::scrollCallback(double xScroll, double yScroll)
2023-02-24 22:09:07 +01:00
{
keyboardSystem->scrollCallback(xScroll, yScroll);
2023-02-24 22:09:07 +01:00
}
void GameView::fileCallback(int, const char**)
{
}