-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (46 loc) · 1.48 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <emscripten/html5.h>
#include <emscripten/fetch.h>
#include <imgui/imgui_impl_wgpu.h>
#include "logstorm/logstorm.h"
#include "gui/gui_renderer.h"
#include "render/webgpu_renderer.h"
class game_manager {
logstorm::manager logger{logstorm::manager::build_with_sink<logstorm::sink::emscripten_out>()}; // logging system
render::webgpu_renderer renderer{logger}; // WebGPU rendering system
gui::gui_renderer gui{logger}; // GUI top level
void loop_main();
public:
game_manager();
};
game_manager::game_manager() {
/// Run the game
renderer.init(
[&](render::webgpu_renderer::webgpu_data const& webgpu){
ImGui_ImplWGPU_InitInfo imgui_wgpu_info;
imgui_wgpu_info.Device = webgpu.device.Get();
imgui_wgpu_info.RenderTargetFormat = static_cast<WGPUTextureFormat>(webgpu.surface_preferred_format);
//imgui_wgpu_info.DepthStencilFormat = static_cast<WGPUTextureFormat>(webgpu.depth_texture_format);
gui.init(imgui_wgpu_info);
},
[&]{
loop_main();
}
);
std::unreachable();
}
void game_manager::loop_main() {
/// Main pseudo-loop
gui.draw();
renderer.draw();
}
auto main()->int {
try {
game_manager game;
std::unreachable();
} catch (std::exception const &e) {
std::cerr << "Exception: " << e.what() << std::endl;
EM_ASM(alert("Error: Press F12 to see console for details."));
}
return EXIT_SUCCESS;
}