-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
134 lines (122 loc) · 4.62 KB
/
Copy pathmain.cpp
File metadata and controls
134 lines (122 loc) · 4.62 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Conway's Game of Life in 3D
// by Chad Dore'
// chaduke@gmail.com | youtube.com/chaddore | github.com/chaduke
// made with LibSGD - support it and get it at patreon.com/libsgd
// materials from ambientcg.com
// if you have questions, comments, requests, or do anything cool //
// with this let me know, comment on youtube or the blitzworld forums, email me etc..
// Blitz World forums - https://skirmish-dev.net/forum/
// thanks for checking this out
// TODO : add ImGUI
// TODO : improve edit mode
// TODO : improve lighting / shadows
// TODO : improve mouselook
#include <fstream>
#include <iostream>
#include <string>
#include "globals.h"
// #include "rules.h"
#include "grid2D.h"
#include "grid3D.h"
#include "states.h"
#include "init.h"
#include "input.h"
#include "imgui.h"
#define IMGUI_IMPL_SGD_IMPLEMENTATION 1
#include "sgd/imgui_impl_sgd.h"
int main(int, char**) {
sgd_Init();
// sgd_CreateWindow(1280, 720, "Conway's Game of Life in 3D", 0); // 16 : 9 Window
// sgd_CreateWindow(3840,2160, "", 1); // UHD Fullscreen
sgd_CreateWindow(1920, 1080, "", 256); // HD Fullscreen
// imgui init
IMGUI_CHECKVERSION();
ImGui::CreateContext();
auto& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
ImGui_ImplSGD_Init();
init();
// start main loop
while (loop) {
processInput();
if (!paused) {
if (mode2D) updateNextGrid(); else updateNextGrid3D();
}
sgd_RenderScene();
// imgui
ImGui_ImplSGD_NewFrame();
ImGui::NewFrame();
if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window);
if (show_help) {
ImGui::Begin("Welcome to Conway's Game of Life in 3D!\n");
ImGui::BulletText("To minimize this window you can double click\nthe title bar\n");
ImGui::BulletText("When it's not in focus you can use the F1 key\nto toggle its visiblity.\n");
if (ImGui::CollapsingHeader("Options")) {
ImGui::Text("These can be toggled with the keyboard shortcuts\nonly when the window is not in focus");
ImGui::Checkbox("Mouselook (Keyboard F)", &mouselook);
ImGui::Checkbox("Pause (Keyboard SPACE)", &paused);
ImGui::Checkbox("Edit Mode (Keyboard G)", &editmode);
ImGui::Checkbox("2D Mode (Keyboard T)", &mode2D);
if (ImGui::Button("Clear Grid", ImVec2(100, 20))) {
if (mode2D) clearGrid(); else clearGrid3D();
}
ImGui::Text("(Keyboard C)");
if (ImGui::Button("Reset / Randomize Grid", ImVec2(200, 20))) {
if (mode2D) {
randomizeGrid();
arrangeGrid();
}
else {
randomizeGrid3D();
arrangeGrid3D();
}
}
ImGui::Text("(Keyboard R)");
if (ImGui::Button("Next Grid Step", ImVec2(150, 20))) {
if (paused) if (mode2D) updateNextGrid(); else updateNextGrid3D();
}
ImGui::Text("(Keyboard N)");
}
if (ImGui::CollapsingHeader("Cellular Automata Rules")) {
ImGui::Text("Ruleset 1- Conway's standard");
ImGui::SeparatorText("Rule 1 - Loneliness");
ImGui::Text("IF Currently Alive");
ImGui::Text("AND Neighbors less than 2");
ImGui::Text("THEN After Dead");
ImGui::SeparatorText("Rule 2 - Survival");
ImGui::Text("IF Currently Alive");
ImGui::Text("AND Neighbors greater than 2");
ImGui::Text("AND Neighbors less than 4");
ImGui::Text("THEN After Alive");
ImGui::SeparatorText("Rule 3 - Rebirth");
ImGui::Text("IF Currently Dead");
ImGui::Text("AND Neighbors equal to 3");
ImGui::Text("THEN After Alive");
ImGui::SeparatorText("Rule 4 - Overpopulation");
ImGui::Text("IF Currently Alive");
ImGui::Text("AND Neighbors greater than 3");
ImGui::Text("THEN After Dead");
}
if (ImGui::CollapsingHeader("Info and Stats")) {
ImGui::Text("Pivot Position X %.2f Y %.2f Z %.2f", sgd_GetEntityX(pivot), sgd_GetEntityY(pivot), sgd_GetEntityZ(pivot));
ImGui::Text("Pivot Rotation X %.2f Y %.2f Z %.2f", sgd_GetEntityRX(pivot), sgd_GetEntityRY(pivot), sgd_GetEntityRZ(pivot));
ImGui::Text("Camera Position X %.2f Y %.2f Z %.2f", sgd_GetEntityX(cam), sgd_GetEntityY(cam), sgd_GetEntityZ(cam));
ImGui::Text("Camera Rotation X %.2f Y %.2f Z %.2f", sgd_GetEntityRX(cam), sgd_GetEntityRY(cam), sgd_GetEntityRZ(cam));
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
}
ImGui::End();
}
ImGui::Render();
ImGui_ImplSGD_RenderDrawData(ImGui::GetDrawData());
sgd_Present();
}
// Cleanup
ImGui_ImplSGD_Shutdown();
ImGui::DestroyContext();
sgd_Terminate();
return 0;
}