Skip to content

Commit

Permalink
Compile fix, jobified file watcher and translucency sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mormert committed Sep 12, 2023
1 parent 4ccdd20 commit a8c1803
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 45 deletions.
2 changes: 1 addition & 1 deletion engine/editor/jleEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ jleEditor::updateEditorLoadedScenes(float dt)
void
jleEditor::update(float dt)
{
//_fileChangeNotifier->periodicSweep();
_fileChangeNotifier->periodicSweep();
jleGameEngine::update(dt);
if (isGameKilled()) {
JLE_SCOPE_PROFILE_CPU(updateEditorLoadedScenes)
Expand Down
17 changes: 14 additions & 3 deletions engine/jle3DRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <random>

#include <WickedEngine/wiJobSystem.h>

#define JLE_LINE_DRAW_BATCH_SIZE 32768

struct jle3DRenderer::jle3DRendererShaders {
Expand Down Expand Up @@ -106,8 +108,14 @@ jle3DRenderer::render(jleFramebufferInterface &framebufferOut,
glEnable(GL_DEPTH_TEST);

// Sort translucency early on another thread, sync before rendering translucency
std::future<void> sortTranslucentAsync =
std::async(std::launch::async, [&] { sortTranslucentMeshes(camera, graph._translucentMeshes); });
wi::jobsystem::context sortCtx;
if(!graph._translucentMeshes.empty())
{
wi::jobsystem::Execute(sortCtx, [&](wi::jobsystem::JobArgs args){
sortTranslucentMeshes(camera, graph._translucentMeshes);
});
}


// Directional light renders to the shadow mapping framebuffer
renderDirectionalLight(camera, graph._meshes, settings);
Expand Down Expand Up @@ -151,7 +159,9 @@ jle3DRenderer::render(jleFramebufferInterface &framebufferOut,

{
JLE_SCOPE_PROFILE_CPU(jle3DRenderer_renderMeshes_Translucent)
sortTranslucentAsync.wait();
if(!graph._translucentMeshes.empty()){
wi::jobsystem::Wait(sortCtx);
}

renderMeshes(camera, graph._translucentMeshes, graph._lights, settings);
glCheckError("3D Render - Translucent Meshes");
Expand Down Expand Up @@ -235,6 +245,7 @@ jle3DRenderer::renderSkinnedMeshes(const jleCamera &camera,
void
jle3DRenderer::sortTranslucentMeshes(const jleCamera &camera, std::vector<jle3DQueuedMesh> &translucentMeshes)
{
ZoneScoped;
glm::vec3 camPosition = camera.getPosition();

std::sort(translucentMeshes.begin(),
Expand Down
46 changes: 22 additions & 24 deletions engine/jleFileChangeNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include "jleResource.h"

#include <Tracy.hpp>
#include <WickedEngine/wiJobSystem.h>

jleFileChangeNotifier::jleFileChangeNotifier(const std::vector<std::string> &directories)
{
_directories = directories;
Expand All @@ -16,39 +19,34 @@ jleFileChangeNotifier::periodicSweep()
{
using namespace std::chrono;

long long now = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();

if (now > lastSweep + 250ll) {
static std::vector<jlePath> erased;
static std::vector<jlePath> added;
static std::vector<jlePath> modified;
static std::future<void> sortTranslucentAsync{};
static std::vector<jlePath> erased;
static std::vector<jlePath> added;
static std::vector<jlePath> modified;
static wi::jobsystem::context sweepingCtx;

if (sortTranslucentAsync.valid() &&
sortTranslucentAsync.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
for (auto &path : erased) {
notifyErase(path);
}
for (auto &path : added) {
notifyAdded(path);
}
for (auto &path : modified) {
notifyModification(path);
}
erased.clear();
added.clear();
modified.clear();
if (!IsBusy(sweepingCtx)) {
for (auto &path : erased) {
notifyErase(path);
}
for (auto &path : added) {
notifyAdded(path);
}
for (auto &path : modified) {
notifyModification(path);
}
erased.clear();
added.clear();
modified.clear();

sortTranslucentAsync = std::async(std::launch::async, [&] { sweep(erased, added, modified); });

lastSweep = now;
wi::jobsystem::Execute(sweepingCtx, [&](wi::jobsystem::JobArgs args) { sweep(erased, added, modified); });
}
}

void
jleFileChangeNotifier::sweep(std::vector<jlePath> &erased, std::vector<jlePath> &added, std::vector<jlePath> &modified)
{
ZoneScopedNC("FileChangeWatcher", 0xe57395);

static std::unordered_map<std::string, std::filesystem::file_time_type> pathsMonitored;

auto it = pathsMonitored.begin();
Expand Down
2 changes: 0 additions & 2 deletions engine/jleFileChangeNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class jleFileChangeNotifier
void notifyErase(const jlePath &path);

std::vector<std::string> _directories;

long long lastSweep = 0;
};

#endif // JLE_FILECHANGENOTIFIER_H
14 changes: 0 additions & 14 deletions engine/jleGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ jleGame::activeScenesRef()
return _activeScenes;
}

template <typename T>
std::shared_ptr<T>
jleGame::createScene()
{
static_assert(std::is_base_of<jleScene, T>::value, "T must derive from jleScene");

std::shared_ptr<T> newScene = std::make_shared<T>();
_activeScenes.push_back(newScene);

newScene->onSceneCreation();

return newScene;
}

std::shared_ptr<jleScene>
jleGame::loadScene(const jlePath &scenePath)
{
Expand Down
13 changes: 12 additions & 1 deletion engine/jleGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ class jleGame
void updateActiveScenes(float dt);

template <typename T>
std::shared_ptr<T> createScene();
std::shared_ptr<T>
createScene()
{
static_assert(std::is_base_of<jleScene, T>::value, "T must derive from jleScene");

std::shared_ptr<T> newScene = std::make_shared<T>();
_activeScenes.push_back(newScene);

newScene->onSceneCreation();

return newScene;
}

std::shared_ptr<jleScene> loadScene(const jlePath &scenePath);

Expand Down

0 comments on commit a8c1803

Please sign in to comment.