Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (59 loc) · 2.39 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (59 loc) · 2.39 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <algorithm>
#include <filesystem>
#include "renderer.h"
#include "imgui_layer.h"
#include "free_camera.h"
#include <imgui.h>
#include <ImGuizmo.h>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include "Scene.h"
#include "file_dialog.h"
// scene.nsc in folder, or scene-2.nsc, scene-3.nsc, ... if taken: a new scene never overwrites a saved one.
static std::string freeScenePath(std::string_view folder) {
std::filesystem::path path = std::filesystem::path(folder) / "scene.nsc";
std::error_code ec;
for (int n = 2; std::filesystem::exists(path, ec); n++)
path = std::filesystem::path(folder) / ("scene-" + std::to_string(n) + ".nsc");
return path.string();
}
int main() {
(void) NRE::setRenderConfig({
NRE::RenderMode::Render_3D, NRE::ApiMode::SceneMode, NRE::RenderErrorPolicy::Return, false,
{1280, 720, "NSC", true}});
if (auto r = NRE::init(); !r) {
std::cerr << r.error() << '\n';
return 1;
}
auto vertex = NRE::createShader(SHADER_DIR "/vertex.vert.spv", NRE::ShaderType::VERTEX_SHADER).value();
auto fragment = NRE::createShader(SHADER_DIR "/fragment.frag.spv", NRE::ShaderType::FRAGMENT_SHADER).value();
auto pipeline = createPipeline(vertex, fragment).value();
(void)bindPipeline(pipeline);
Scene scene;
scene.createScene(ASSET_DIR); // starts on the Create scene screen, with the built-in assets folder filled in
(void) NRE::setCameraPosition({0.0f, 1.0f, 3.0f});
(void) NRE::cameraLookAt({0.0f, 0.0f, 0.0f});
FreeCamera camera;
ImGuiLayer::init();
FileDialog::init();
while (!NRE::windowShouldClose().value()) {
(void) NRE::pollEvents();
ImGuiLayer::beginFrame();
ImGuizmo::BeginFrame();
camera.update();
scene.renderUIForScene();
ImGuiLayer::endFrame();
(void) NRE::renderFrame();
}
// A scene never saved goes into its assets folder; nothing is saved while still on the Create scene screen.
if (!scene.inSetup()) {
std::string path = scene.getPath().empty() ? freeScenePath(scene.getAssetsPath())
: std::string(scene.getPath());
if (!scene.saveScene(path)) std::cerr << "Can't write " << path << '\n';
}
scene.destroyScene();
FileDialog::shutdown();
ImGuiLayer::shutdown();
(void) NRE::shutdown();
return 0;
}