zengine/game/zworld/src/zworld.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2024-09-01 22:32:29 +08:00
#include "zlog.h"
2024-07-20 18:04:19 +08:00
#include "zworld.h"
2024-12-07 18:10:01 +08:00
#include "data/global.h"
2024-12-13 11:32:34 +08:00
#include "event/event_system.h"
2024-08-17 18:01:21 +08:00
#include "vkn/vulkan_window.h"
#include "vkn/vulkan_api.h"
2024-12-12 22:20:56 +08:00
#ifdef WITH_EDITOR
#include "imgui/imgui_impl_sdl2.h"
#endif
2024-09-01 22:32:29 +08:00
#include "render/pass/demo_pass.h"
2024-08-17 18:01:21 +08:00
#include <iostream>
using namespace api;
2024-09-21 17:19:22 +08:00
RenderAPI* API;
2024-07-31 10:48:28 +08:00
void ZWorldModule::OnLoad(int argc, char** argv)
{
2024-08-17 18:01:21 +08:00
// 创建窗口
2024-12-07 18:10:01 +08:00
gEngineConfig.API = GraphicsAPI::Vulkan;
2024-09-01 22:32:29 +08:00
auto window = new vkn::VulkanWindow(&SDL_CreateWindow, { "zengine" , SDL_WINDOW_VULKAN }, 1080, 720);
2024-09-21 17:19:22 +08:00
API = new vkn::VulkanAPI();
2024-09-01 22:32:29 +08:00
auto args = vkn::VulkanWindowArgs::Default();
args.frames = 3;
if (!window->CreateRender(&SDL_Vulkan_CreateSurface, args)) {
zlog::errorf("SDL_Vulkan_CreateSurface failed {}", SDL_GetError());
}
2024-10-21 16:31:02 +08:00
API->Init();
2024-09-01 22:32:29 +08:00
API->context.views.push_back({});
2024-12-12 22:20:56 +08:00
#ifdef WITH_EDITOR //绑定窗口交互
ImGui_ImplSDL2_InitForVulkan(window->GetPtr());
#endif
2024-12-13 11:32:34 +08:00
EventSystem::Ptr()->BeginRenderFrame.Subscribe("zworld", []() {
API->graph.AddRenderPass<DemoPass>();
});
2024-12-12 22:20:56 +08:00
}
void ZWorldModule::Initialize()
{
2024-07-31 10:48:28 +08:00
}
void ZWorldModule::OnUnload()
{
2024-08-17 18:01:21 +08:00
}
void ZWorldModule::MainLoop()
{
bool running = true;
SDL_Event event_;
while (running) {
// 处理事件
while (SDL_PollEvent(&event_)) {
if (event_.type == SDL_QUIT) {
running = false;
}
2024-12-07 18:10:01 +08:00
}
2024-09-01 22:32:29 +08:00
API->BeginFrame();
API->Render();
API->EndFrame();
2024-10-30 15:15:25 +08:00
FramePool()->reset();
2024-08-17 18:01:21 +08:00
}
2024-07-31 10:48:28 +08:00
}
2024-12-12 22:20:56 +08:00