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

125 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)
, renderGraph(RenderGraphBuilder::build(
2023-11-10 22:26:47 +01:00
DepthPrepass(graphics, scene),
LightCullingPass(graphics, scene),
BasePass(graphics, scene),
SkyboxRenderPass(graphics, scene)
2023-02-24 22:09:07 +01:00
))
{
2023-04-09 16:39:53 +02:00
reloadGame();
2023-02-24 22:09:07 +01:00
renderGraph.updateViewport(viewport);
}
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();
}
2023-02-24 22:09:07 +01:00
systemGraph->run(threadPool, updateTime);
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)
cam = c;
});
renderGraph.render(cam);
2023-02-24 22:09:07 +01:00
}
2023-11-18 11:04:30 +01:00
void GameView::applyArea(URect rect)
{
viewport = graphics->createViewport(owner->getGfxHandle(), ViewportCreateInfo{
.dimensions = rect,
});
renderGraph.updateViewport(viewport);
}
2023-04-09 16:39:53 +02:00
void GameView::reloadGame()
{
2023-08-26 15:19:12 +02:00
gameInterface.reload(AssetRegistry::getInstance());
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-12-15 11:57:13 +01:00
if (code == KeyCode::KEY_P && action == InputAction::PRESS)
{
((Vulkan::Graphics*)graphics.getHandle())->getAllocator()->print();
}
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, double)
{
}
void GameView::fileCallback(int, const char**)
{
}