moved stats to window
This commit is contained in:
@@ -70,6 +70,12 @@ std::vector<double> renderFrameTimes;
|
|||||||
int frameHistoryIndex = 0;
|
int frameHistoryIndex = 0;
|
||||||
bool firstFrameMeasured = false;
|
bool firstFrameMeasured = false;
|
||||||
|
|
||||||
|
// Stats update timer
|
||||||
|
std::chrono::steady_clock::time_point lastStatsUpdate;
|
||||||
|
const std::chrono::seconds STATS_UPDATE_INTERVAL(60); // Update stats once per minute
|
||||||
|
std::string cachedStats;
|
||||||
|
bool statsNeedUpdate = true;
|
||||||
|
|
||||||
void createSphere(const defaults& config, const spheredefaults& sconfig, Octree<int>& grid) {
|
void createSphere(const defaults& config, const spheredefaults& sconfig, Octree<int>& grid) {
|
||||||
if (!grid.empty()) grid.clear();
|
if (!grid.empty()) grid.clear();
|
||||||
|
|
||||||
@@ -163,6 +169,14 @@ void addStar(const defaults& config, const stardefaults& starconf, Octree<int>&
|
|||||||
grid.set(2, pos, true, colorVec, starconf.size, true, 2, true, starconf.emittance, 0.0f, 0.0f);
|
grid.set(2, pos, true, colorVec, starconf.size, true, 2, true, starconf.emittance, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateStatsCache(Octree<int>& grid) {
|
||||||
|
std::stringstream gridstats;
|
||||||
|
grid.printStats(gridstats);
|
||||||
|
cachedStats = gridstats.str();
|
||||||
|
lastStatsUpdate = std::chrono::steady_clock::now();
|
||||||
|
statsNeedUpdate = false;
|
||||||
|
}
|
||||||
|
|
||||||
void livePreview(Octree<int>& grid, defaults& config, const Camera& cam) {
|
void livePreview(Octree<int>& grid, defaults& config, const Camera& cam) {
|
||||||
std::lock_guard<std::mutex> lock(PreviewMutex);
|
std::lock_guard<std::mutex> lock(PreviewMutex);
|
||||||
updatePreview = true;
|
updatePreview = true;
|
||||||
@@ -198,6 +212,11 @@ void livePreview(Octree<int>& grid, defaults& config, const Camera& cam) {
|
|||||||
renderFPS = 1.0 / avgRenderFrameTime;
|
renderFPS = 1.0 / avgRenderFrameTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto now = std::chrono::steady_clock::now();
|
||||||
|
if (statsNeedUpdate || (now - lastStatsUpdate) > STATS_UPDATE_INTERVAL) {
|
||||||
|
updateStatsCache(grid);
|
||||||
|
}
|
||||||
|
|
||||||
// Update texture
|
// Update texture
|
||||||
if (textu == 0) {
|
if (textu == 0) {
|
||||||
glGenTextures(1, &textu);
|
glGenTextures(1, &textu);
|
||||||
@@ -333,9 +352,12 @@ int main() {
|
|||||||
// Initialize render frame times vector
|
// Initialize render frame times vector
|
||||||
renderFrameTimes.resize(FRAME_HISTORY_SIZE, 0.0);
|
renderFrameTimes.resize(FRAME_HISTORY_SIZE, 0.0);
|
||||||
|
|
||||||
|
lastStatsUpdate = std::chrono::steady_clock::now();
|
||||||
|
statsNeedUpdate = true;
|
||||||
|
|
||||||
if (grid.load("output/Treegrid.yggs")) {
|
if (grid.load("output/Treegrid.yggs")) {
|
||||||
gridInitialized = true;
|
gridInitialized = true;
|
||||||
grid.printStats();
|
updateStatsCache(grid);
|
||||||
resetView(cam, config.gridSizecube);
|
resetView(cam, config.gridSizecube);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,9 +479,9 @@ int main() {
|
|||||||
|
|
||||||
if (ImGui::Button("Create Sphere & Render")) {
|
if (ImGui::Button("Create Sphere & Render")) {
|
||||||
createSphere(config, sphereConf, grid);
|
createSphere(config, sphereConf, grid);
|
||||||
grid.printStats();
|
|
||||||
addStar(config, starConf, grid);
|
addStar(config, starConf, grid);
|
||||||
gridInitialized = true;
|
gridInitialized = true;
|
||||||
|
statsNeedUpdate = true;
|
||||||
|
|
||||||
resetView(cam, config.gridSizecube);
|
resetView(cam, config.gridSizecube);
|
||||||
|
|
||||||
@@ -473,8 +495,16 @@ int main() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
ImGui::Begin("Preview");
|
ImGui::Begin("Preview");
|
||||||
|
if (gridInitialized && textureInitialized) {
|
||||||
|
ImGui::Image((void*)(intptr_t)textu, ImVec2(config.outWidth, config.outHeight));
|
||||||
|
} else if (gridInitialized) {
|
||||||
|
ImGui::Text("Preview not generated yet");
|
||||||
|
} else {
|
||||||
|
ImGui::Text("No grid generated");
|
||||||
|
}
|
||||||
|
|
||||||
// Display render FPS information
|
ImGui::Separator();
|
||||||
|
|
||||||
ImGui::Text("Render Performance:");
|
ImGui::Text("Render Performance:");
|
||||||
if (renderFPS > 0) {
|
if (renderFPS > 0) {
|
||||||
// Color code based on FPS
|
// Color code based on FPS
|
||||||
@@ -498,15 +528,18 @@ int main() {
|
|||||||
} else {
|
} else {
|
||||||
ImGui::Text("No render data yet");
|
ImGui::Text("No render data yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
if (gridInitialized) {
|
||||||
|
// Show time since last update
|
||||||
if (gridInitialized && textureInitialized) {
|
auto now = std::chrono::steady_clock::now();
|
||||||
ImGui::Image((void*)(intptr_t)textu, ImVec2(config.outWidth, config.outHeight));
|
auto timeSinceUpdate = std::chrono::duration_cast<std::chrono::seconds>(now - lastStatsUpdate);
|
||||||
} else if (gridInitialized) {
|
|
||||||
ImGui::Text("Preview not generated yet");
|
if (!(timeSinceUpdate < STATS_UPDATE_INTERVAL)) {
|
||||||
} else {
|
updateStatsCache(grid);
|
||||||
ImGui::Text("No grid generated");
|
}
|
||||||
|
|
||||||
|
// Display cached stats
|
||||||
|
ImGui::TextUnformatted(cachedStats.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
Reference in New Issue
Block a user