Skip to content

Commit

Permalink
Added some profile markers, fix data race in file changer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mormert committed Aug 14, 2023
1 parent 2a9e689 commit 359c1b2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 48 deletions.
58 changes: 30 additions & 28 deletions engine/editor/jleEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright (c) 2023. Johan Lind

#include "jleEditor.h"
#include "editor/jleEditorImGuiWindowInterface.h"
#include "editor/jleConsoleEditorWindow.h"
#include "editor/jleEditorContentBrowser.h"
#include "editor/jleEditorFrameGraphWindow.h"
#include "editor/jleEditorGizmos.h"
#include "editor/jleEditorImGuiWindowInterface.h"
#include "editor/jleEditorNotifications.h"
#include "editor/jleEditorProfilerWindow.h"
#include "editor/jleEditorResourceViewer.h"
#include "editor/jleEditorSaveState.h"
#include "editor/jleEditorSceneObjectsWindow.h"
#include "editor/jleEditorWindowsPanel.h"
#include "editor/jleEditorSaveState.h"
#include "editor/jleEditorGizmos.h"
#include "editor/jleEditorFrameGraphWindow.h"

#include "jle3DRenderer.h"
#include "jleEditor3DImportWindow.h"
Expand All @@ -37,11 +37,11 @@
#include <ImGui/imgui.h>
#include <ImGui/imgui_impl_glfw.h>
#include <ImGui/imgui_impl_opengl3.h>
#include <implot/implot.h>
#include <Remotery/Remotery.h>
#include <implot/implot.h>
#include <plog/Log.h>

struct jleEditor::jleEditorInternal{
struct jleEditor::jleEditorInternal {
jleResourceRef<jleEditorSaveState> editorSaveState;
};

Expand Down Expand Up @@ -181,6 +181,8 @@ jleEditor::render()
void
jleEditor::renderGameView()
{
JLE_SCOPE_PROFILE_CPU(RenderGameView);

if (!gameHalted && game) {
// Render to game view
static jleFramebufferMultisample msaa{mainScreenFramebuffer->width(), mainScreenFramebuffer->height(), 4};
Expand All @@ -199,6 +201,8 @@ jleEditor::renderGameView()
void
jleEditor::renderEditorSceneView()
{
JLE_SCOPE_PROFILE_CPU(RenderEditorSceneView);

if (!isGameKilled()) {
physics().renderDebug();
}
Expand Down Expand Up @@ -229,6 +233,8 @@ jleEditor::renderEditorSceneView()
void
jleEditor::renderEditorUI()
{
JLE_SCOPE_PROFILE_CPU(RenderEditorUI);

glBindFramebuffer(GL_FRAMEBUFFER, 0);

glClearColor(0.f, 0.f, 0.f, 1.f);
Expand All @@ -237,31 +243,27 @@ jleEditor::renderEditorUI()
// Set viewport to cover the entire screen
glViewport(0, 0, window().width(), window().height());

{
JLE_SCOPE_PROFILE_GPU(ImGuiRender);

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

ImGuizmo::BeginFrame();
ImGuizmo::BeginFrame();

// Update loop for all ImGui windows
for (const auto &window : _imGuiWindows) {
window->update(*this);
}
// Update loop for all ImGui windows
for (const auto &window : _imGuiWindows) {
window->update(*this);
}

ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glCheckError("ImGui");
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glCheckError("ImGui");

auto &&io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
GLFWwindow *backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
auto &&io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
GLFWwindow *backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}

glCheckError("Render Editor UI");
Expand Down Expand Up @@ -464,7 +466,7 @@ jleEditor::exiting()
}
saveState().cameraYaw = _sceneWindow->fpvCamController.yaw;
saveState().cameraPitch = _sceneWindow->fpvCamController.pitch;
//saveState().orthographicCamera = !static_cast<bool>(projectionType);
// saveState().orthographicCamera = !static_cast<bool>(projectionType);
saveState().saveToFile();

jleGameEngine::exiting();
Expand Down
28 changes: 12 additions & 16 deletions engine/jleFileChangeNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ jleFileChangeNotifier::periodicSweep()
static std::vector<jlePath> erased;
static std::vector<jlePath> added;
static std::vector<jlePath> modified;
static std::future<void> sortTranslucentAsync;
static std::future<void> sortTranslucentAsync{};

if (sortTranslucentAsync.valid() && sortTranslucentAsync.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
if (sortTranslucentAsync.valid() &&
sortTranslucentAsync.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
for (auto &path : erased) {
notifyErase(path);
}
Expand All @@ -48,11 +49,13 @@ jleFileChangeNotifier::periodicSweep()
void
jleFileChangeNotifier::sweep(std::vector<jlePath> &erased, std::vector<jlePath> &added, std::vector<jlePath> &modified)
{
auto it = _pathsMonitored.begin();
while (it != _pathsMonitored.end()) {
static std::unordered_map<std::string, std::filesystem::file_time_type> pathsMonitored;

auto it = pathsMonitored.begin();
while (it != pathsMonitored.end()) {
if (!std::filesystem::exists(it->first)) {
erased.push_back(jlePath{it->first, false});
it = _pathsMonitored.erase(it);
it = pathsMonitored.erase(it);
} else {
it++;
}
Expand All @@ -63,12 +66,12 @@ jleFileChangeNotifier::sweep(std::vector<jlePath> &erased, std::vector<jlePath>
for (auto &file : std::filesystem::recursive_directory_iterator(dir)) {
auto current_file_last_write_time = std::filesystem::last_write_time(file);

if (!contains(file.path().string())) {
_pathsMonitored[file.path().string()] = current_file_last_write_time;
if ((pathsMonitored.find(file.path().string()) == pathsMonitored.end())) {
pathsMonitored[file.path().string()] = current_file_last_write_time;
added.push_back(jlePath{file.path().string(), false});
} else {
if (_pathsMonitored[file.path().string()] != current_file_last_write_time) {
_pathsMonitored[file.path().string()] = current_file_last_write_time;
if (pathsMonitored[file.path().string()] != current_file_last_write_time) {
pathsMonitored[file.path().string()] = current_file_last_write_time;
if (file.is_regular_file()) {
modified.push_back(jlePath{file.path().string(), false});
}
Expand Down Expand Up @@ -104,10 +107,3 @@ jleFileChangeNotifier::notifyErase(const jlePath &path)
{
LOGI << "File erased: " << path.getVirtualPath();
}

bool
jleFileChangeNotifier::contains(const std::string &key)
{
auto el = _pathsMonitored.find(key);
return el != _pathsMonitored.end();
}
3 changes: 0 additions & 3 deletions engine/jleFileChangeNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ class jleFileChangeNotifier

void notifyErase(const jlePath &path);

std::unordered_map<std::string, std::filesystem::file_time_type> _pathsMonitored;
std::vector<std::string> _directories;

bool contains(const std::string &key);

long long lastSweep = 0;
};

Expand Down
1 change: 1 addition & 0 deletions engine/jleGameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ jleGameEngine::renderer()
void
jleGameEngine::resetRenderGraphForNewFrame()
{
JLE_SCOPE_PROFILE_CPU(ResetRenderGraph);
_3dRenderGraph = std::make_unique<jle3DGraph>();
}
float
Expand Down
2 changes: 2 additions & 0 deletions engine/jleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ jleMesh::loadAssimp(const jlePath &path)

makeMesh(out_vertices, out_normals, out_uvs, out_tangents, out_bitangents, out_indices);

LOGV << "Loaded mesh " << path.getVirtualPath() << " with " << out_vertices.size() << " vertices";

return true;
}

Expand Down
3 changes: 2 additions & 1 deletion engine/jleMouseInput.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2023. Johan Lind

#include "jleMouseInput.h"
#include "jleProfiler.h"
#include "jleWindow.h"


jleMouseInput::jleMouseInput(std::shared_ptr<jleWindow> window) {
this->_window = std::move(window);
}
Expand Down Expand Up @@ -80,6 +80,7 @@ jleMouseInput::isFpsMode() const
void
jleMouseInput::updateDeltas()
{
JLE_SCOPE_PROFILE_CPU(jleMouseInput_updateDeltas)
auto c = _window->cursor();
_deltaX = c.first - _lastMouseX;
_deltaY = c.second - _lastMouseY;
Expand Down
4 changes: 4 additions & 0 deletions engine/jleWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023. Johan Lind

#include "jleWindow.h"
#include "jleProfiler.h"

#include <iostream>

Expand Down Expand Up @@ -186,6 +187,8 @@ jleWindow::initWindow()
void
jleWindow::updateWindow()
{
JLE_SCOPE_PROFILE_CPU(WindowUpdate);

_activeWindow->currentScrollX = 0.f;
_activeWindow->currentScrollY = 0.f;

Expand All @@ -198,6 +201,7 @@ jleWindow::updateWindow()
bool
jleWindow::windowShouldClose()
{
JLE_SCOPE_PROFILE_CPU(WindowCloseCheck);
return glfwWindowShouldClose(_glfwWindow);
}

Expand Down

0 comments on commit 359c1b2

Please sign in to comment.