Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/common/fileManager/fileWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ void FileWatcher::scanForChanges(bool callbacks)

void FileWatcher::loadCache(std::filesystem::path changeCache)
{
SerializedData cacheData;
_changeCache = std::move(changeCache);
if(!FileManager::readFile(_changeCache, cacheData.vector()))

SerializedData cacheData;
if (!FileManager::readFile(_changeCache, cacheData.vector()))
return;

InputSerializer s(cacheData);
uint32_t count = 0;
s >> count;
Expand All @@ -53,8 +55,10 @@ void FileWatcher::loadCache(std::filesystem::path changeCache)
std::string path;
std::filesystem::file_time_type lastUpdate;
s >> path >> lastUpdate;

if(!std::filesystem::exists(path))
continue;

_lastUpdate.insert({path, lastUpdate});
}
}
Expand All @@ -63,10 +67,13 @@ void FileWatcher::saveCache()
{
if(_changeCache.empty())
return;

SerializedData cacheData;
OutputSerializer s(cacheData);

uint32_t count = _lastUpdate.size();
s << count;

for(auto& u : _lastUpdate)
s << u.first << u.second;
FileManager::writeFile(_changeCache, cacheData.vector());
Expand Down
1 change: 1 addition & 0 deletions src/common/utility/threadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <atomic>
#include <cassert>
#include <chrono>
#include <functional>
#include <memory>
#include <mutex>
Expand Down
3 changes: 3 additions & 0 deletions src/editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ install(TARGETS BraneEditor
if(MSVC)
install(FILES $<TARGET_PDB_FILE:BraneEditor> DESTINATION . OPTIONAL COMPONENT Editor)
endif()

install(TARGETS BraneEditor
DESTINATION .)
install(FILES config.json ${PROJECT_SOURCE_DIR}/media/branelogo.png
DESTINATION .
COMPONENT Editor)
Expand Down
8 changes: 6 additions & 2 deletions src/editor/assets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
find_package(jsoncpp CONFIG REQUIRED)

set(CMAKE_FOLDER ${CMAKE_FOLDER}/Assets)
add_library(editorAssets STATIC
gltfLoader.cpp
assemblyBuilder.cpp
editorAsset.cpp
types/editorShaderAsset.cpp
types/editorAssemblyAsset.cpp
jsonVirtualType.cpp assetCache.cpp assetCache.h types/editorMaterialAsset.cpp types/editorMaterialAsset.h types/editorChunkAsset.cpp types/editorChunkAsset.h assemblyReloadManager.cpp assemblyReloadManager.h types/editorImageAsset.cpp types/editorImageAsset.h)
jsonVirtualType.cpp
assetCache.cpp
types/editorMaterialAsset.cpp
types/editorChunkAsset.cpp
assemblyReloadManager.cpp
types/editorImageAsset.cpp)
target_link_libraries(editorAssets PUBLIC assets_client ecs JsonCpp::JsonCpp)
27 changes: 18 additions & 9 deletions src/editor/braneProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ void BraneProject::initLoaded()
{
refreshAssets();

Json::Value& assets = _file.data()["assets"];
// Create required project data directories.
const auto projectRootDirectory = projectDirectory();
std::filesystem::create_directories(projectDirectory() / "assets");
std::filesystem::create_directories(projectDirectory() / "cache");

if(!_file.data().isMember("assetIdCounter"))
_file.data()["assetIdCounter"] = 0;

_fileWatcher = std::make_unique<FileWatcher>();
_fileWatcher->loadCache(projectDirectory() / "cache" / "changeCache");
_fileWatcher->loadCache(projectDirectory() / "cache" / "changeCache.bin");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break existing caches but it's clearer that this is a binary cache file, would you like to keep this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not worried about breaking changes at all until we release a LTS version. I prefer the more descriptive name

_fileWatcher->watchDirectory(projectDirectory() / "assets");
_fileWatcher->addFileWatcher(".gltf", [this](const std::filesystem::path& path) {
Runtime::log("loading gltf: " + path.string());
Expand Down Expand Up @@ -303,26 +307,31 @@ void BraneProject::refreshAssets()
assets.removeMember(id);
}

std::unordered_set<std::string> assetTypes = {".shader", ".material", ".assembly", ".image"};
for(auto& file : std::filesystem::recursive_directory_iterator{projectDirectory() / "assets"})
if (assets.empty())
return;

const std::unordered_set<std::string> assetFileTypes = {".shader", ".material", ".assembly", ".image"};

for (const auto& assetFile : std::filesystem::recursive_directory_iterator{projectDirectory() / "assets"})
{
if(!file.is_regular_file())
if(!assetFile.is_regular_file())
continue;
if(!assetTypes.count(file.path().extension().string()))
if(!assetFileTypes.contains(assetFile.path().extension().string()))
continue;

EditorAsset* asset = nullptr;
try
{
asset = EditorAsset::openUnknownAsset(file, *this);
asset = EditorAsset::openUnknownAsset(assetFile, *this);
}
catch(const std::exception& e)
{
Runtime::error("Could not open asset " + file.path().string() + " error: " + e.what());
Runtime::error("Could not open asset " + assetFile.path().string() + " error: " + e.what());
continue;
}
if(!asset)
{
Runtime::error("Could not automatically open asset with extension " + file.path().extension().string());
Runtime::error("Could not automatically open asset with extension " + assetFile.path().extension().string());
continue;
}
registerAssetLocation(asset);
Expand Down
49 changes: 25 additions & 24 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"dependencies": [
"openssl",
"asio",
"cpp-httplib",
"gtest",
"jsoncpp",
"sqlite3",
"shaderc",
"spirv-cross",
"glm",
"vulkan",
"glfw3",
{
"name": "imgui",
"features": [
"docking-experimental",
"glfw-binding",
"vulkan-binding"
]
},
"imguizmo",
"tinyfiledialogs",
"stb"
]
"dependencies": [
"openssl",
"asio",
"cpp-httplib",
"gtest",
"jsoncpp",
"sqlite3",
"shaderc",
"spirv-cross",
"glm",
"vulkan",
"glfw3",
{
"name": "imgui",
"features": [
"docking-experimental",
"glfw-binding",
"vulkan-binding"
]
},
"imguizmo",
"tinyfiledialogs",
"stb"
],
"builtin-baseline": "5a5662402382b1aa72f64440717b75258992eba0"
}