-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.cpp
186 lines (155 loc) · 5.28 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <stdlib.h>
// imgui headers
#include <imgui.h>
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl2.h"
// RCC++ headers
#include "RuntimeObjectSystem.h"
// headers from our example
#include "StdioLogSystem.h"
#include "SystemTable.h"
#include "RCCppMainLoop.h"
#include <GLFW/glfw3.h>
// RCC++ Data
static StdioLogSystem g_Logger;
static SystemTable g_SystemTable;
bool RCCppInit();
void RCCppCleanup();
void RCCppUpdate();
// Power save
const int POWERSAVEDRAWNUM = 3;
int powerSaveCountDown = POWERSAVEDRAWNUM;
void ResetPowerSaveCountDown(){ powerSaveCountDown = 3; }
void WindowResizeCallback( GLFWwindow* window, int width, int height ){ ResetPowerSaveCountDown(); }
void WindowPosCallback( GLFWwindow* window, int xpos, int ypos ){ ResetPowerSaveCountDown(); }
void KeyCallback( GLFWwindow* window, int key, int scancode, int action, int mods )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_KeyCallback( window, key, scancode, action, mods );
}
void CharCallback( GLFWwindow* window, unsigned int character )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_CharCallback( window, character );
}
void MouseButtonCallback( GLFWwindow* window, int button, int action, int mods )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_MouseButtonCallback( window, button, action, mods );
}
void MousePosCallback( GLFWwindow* window, double x, double y ){ ResetPowerSaveCountDown(); }
void MouseWheelCallback( GLFWwindow* window, double x, double y )
{
ResetPowerSaveCountDown();
ImGui_ImplGlfw_ScrollCallback( window, x, y );
}
int main( int argc, const char * argv[] )
{
if (!glfwInit())
exit(1);
GLFWwindow* window = glfwCreateWindow(1280, 720, "RCC++ Dear ImGui GLFW example", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
// Power save - ensure callbacks point to the correct place
glfwSetWindowSizeCallback( window, WindowResizeCallback );
glfwSetWindowPosCallback( window, WindowPosCallback );
glfwSetKeyCallback( window, KeyCallback );
glfwSetCharCallback( window, CharCallback );
glfwSetMouseButtonCallback( window, MouseButtonCallback );
glfwSetCursorPosCallback( window, MousePosCallback );
glfwSetScrollCallback( window, MouseWheelCallback );
// Setup Dear ImGui binding
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui_ImplGlfw_InitForOpenGL(window, false);
ImGui_ImplOpenGL2_Init();
// Initialize RCC++
RCCppInit();
// Setup style
ImGui::StyleColorsDark();
ImVec4 clear_color = ImColor(114, 144, 154);
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
// Update RCC++
RCCppUpdate();
// Start the Dear ImGui frame
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Call the function in our RCC++ class
g_SystemTable.pRCCppMainLoopI->MainLoop();
// Rendering
{
glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui::Render();
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
// Power save
if( g_pSys->power_save )
{
if( powerSaveCountDown )
{
--powerSaveCountDown;
glfwPollEvents();
}
else
{
ResetPowerSaveCountDown();
glfwWaitEvents();
}
}
}
// Cleanup
RCCppCleanup();
ImGui_ImplOpenGL2_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwTerminate();
return 0;
}
bool RCCppInit()
{
g_SystemTable.pImContext = ImGui::GetCurrentContext();
g_SystemTable.pRuntimeObjectSystem = new RuntimeObjectSystem;
if( !g_SystemTable.pRuntimeObjectSystem->Initialise(&g_Logger, &g_SystemTable) )
{
delete g_SystemTable.pRuntimeObjectSystem;
g_SystemTable.pRuntimeObjectSystem = 0;
return false;
}
g_SystemTable.pRuntimeObjectSystem->CleanObjectFiles();
#ifndef _WIN32
g_SystemTable.pRuntimeObjectSystem->SetAdditionalCompileOptions( "-std=c++11" );
#endif
// ensure include directories are set - use location of this file as starting point
FileSystemUtils::Path basePath = g_SystemTable.pRuntimeObjectSystem->FindFile( __FILE__ ).ParentPath();
FileSystemUtils::Path imguiIncludeDir = basePath / "imgui";
g_SystemTable.pRuntimeObjectSystem->AddIncludeDir( imguiIncludeDir.c_str() );
return true;
}
void RCCppCleanup()
{
delete g_SystemTable.pRuntimeObjectSystem;
}
void RCCppUpdate()
{
//check status of any compile
if( g_SystemTable.pRuntimeObjectSystem->GetIsCompiledComplete() )
{
// load module when compile complete
g_SystemTable.pRuntimeObjectSystem->LoadCompiledModule();
}
if( !g_SystemTable.pRuntimeObjectSystem->GetIsCompiling() )
{
float deltaTime = 1.0f / ImGui::GetIO().Framerate;
g_SystemTable.pRuntimeObjectSystem->GetFileChangeNotifier()->Update( deltaTime );
}
else
{
ResetPowerSaveCountDown();
}
}