From a25e3551440ca47fe3268eb6d39a2bd036b8d84d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 18 Feb 2025 22:37:53 +0300 Subject: [PATCH] assets compiler and input splitting --- .255.cache.bin | Bin 0 -> 28 bytes CMakeLists.txt | 1 + apps/assets_compiler/CMakeLists.txt | 12 ++ apps/assets_compiler/src/compiler/main.cpp | 90 +++++++++++ apps/editor/CMakeLists.txt | 4 + apps/editor/src/editor/editor_init_system.cpp | 68 +++++++++ apps/editor/src/editor/editor_init_system.h | 18 +++ .../src/game/game_init_system.cpp | 31 ++-- apps/example_game/src/game/game_init_system.h | 2 +- .../game/movement/private/movement_system.cpp | 4 +- .../game/movement/private/movement_system.h | 6 - modules/core/src/asset/bin.cpp | 4 +- modules/core/src/asset/bin.h | 14 ++ modules/core/src/asset/fbx.cpp | 3 +- modules/core/src/asset/image.cpp | 2 +- modules/core/src/asset/image.h | 2 +- modules/core/src/asset/model_asset.cpp | 8 +- modules/core/src/asset/model_asset.h | 2 +- modules/core/src/asset/obj.cpp | 3 +- .../src/core/ecs/camera_holder_component.h | 2 - .../src/core/ecs/input_reciever_component.h | 1 + ...t_component.h => input_sender_component.h} | 17 ++- .../src/core/ecs/private/camera_system.cpp | 27 ++-- .../core/src/core/ecs/private/camera_system.h | 2 - .../core/ecs/private/input_root_component.cpp | 40 ----- .../ecs/private/input_sender_component.cpp | 65 ++++++++ .../src/core/ecs/private/input_system.cpp | 144 ++++++++---------- .../core/src/core/ecs/private/input_system.h | 2 - modules/core/src/core/fps_limiter.cpp | 52 +++++++ modules/core/src/core/fps_limiter.h | 33 ++++ modules/core/src/core/string.h | 9 ++ modules/core/src/dx/dx_texture.cpp | 28 ++-- modules/core/src/dx/dx_texture.h | 15 +- .../core/src/ecs/rendering/mesh_component.h | 3 +- modules/core/src/engine/private/engine.cpp | 5 +- modules/core/src/geometry/mesh.cpp | 20 ++- modules/core/src/geometry/mesh.h | 16 +- modules/core/src/geometry/mesh_builder.h | 30 ++-- .../rendering/ecs/private/render_system.cpp | 91 +---------- .../src/rendering/ecs/private/render_system.h | 2 - .../ecs/renderer_holder_root_component.h | 4 + modules/core/src/rendering/pbr_material.cpp | 10 +- modules/core/src/rendering/pbr_material.h | 7 +- modules/physics/CMakeLists.txt | 5 + tools/assets_compiler/assets_compiler.py | 17 +++ tools/python_requirements.txt | 3 +- 46 files changed, 598 insertions(+), 326 deletions(-) create mode 100644 .255.cache.bin create mode 100644 apps/assets_compiler/CMakeLists.txt create mode 100644 apps/assets_compiler/src/compiler/main.cpp create mode 100644 apps/editor/src/editor/editor_init_system.cpp create mode 100644 apps/editor/src/editor/editor_init_system.h create mode 100644 modules/core/src/asset/bin.h rename modules/core/src/core/ecs/{input_root_component.h => input_sender_component.h} (51%) delete mode 100644 modules/core/src/core/ecs/private/input_root_component.cpp create mode 100644 modules/core/src/core/ecs/private/input_sender_component.cpp create mode 100644 modules/core/src/core/fps_limiter.cpp create mode 100644 modules/core/src/core/fps_limiter.h diff --git a/.255.cache.bin b/.255.cache.bin new file mode 100644 index 0000000000000000000000000000000000000000..43721a4a68a5a7fdd893103a60c142f9497f077a GIT binary patch literal 28 VcmY%J^K@clU|=`{1V9P}0030N1S
+#include + +#include + +#include +#include + +#include +#include + +int main(int argc, char** argv) +{ + using namespace era_engine; + using namespace clara; + + try + { + fs::path path; + bool verbose = false; + + Parser cli; + cli += Opt(verbose, "verbose")["-v"]["--verbose"]("Enable verbose logging"); + cli += Opt(path, "path")["-p"]["--path"]("Path to asset"); + + auto result = cli.parse(Args(argc, argv)); + if (!result) + { + std::cerr << "Error in command line: " << result.errorMessage() << std::endl; + } + + path = get_full_path(path); + + if (!fs::exists(path)) + { + std::cerr << "Could not find file '" << path << "'.\n"; + return EXIT_FAILURE; + } + + std::string extension = path.extension().string(); + + fs::path cached_filename = path; + cached_filename.replace_extension("." + std::to_string(mesh_flag_default) + ".cache.bin"); + fs::path cache_filepath = L"asset_cache" / cached_filename; + + if (fs::exists(cache_filepath)) + { + auto last_cache_write_time = fs::last_write_time(cache_filepath); + auto last_original_write_time = fs::last_write_time(path); + + if (last_cache_write_time > last_original_write_time) + { + std::cout << "Asset is already compiled! \n"; + return EXIT_SUCCESS; + } + } + + std::cout << "Preprocessing asset '" << path << "' for faster loading next time.\n"; + + ModelAsset result_mesh; + + std::transform(extension.begin(), extension.end(), extension.begin(), + [](char c) { return std::tolower(c); }); + if (extension == ".fbx") + { + result_mesh = loadFBX(path, mesh_flag_default); + } + else if (extension == ".obj") + { + result_mesh = loadOBJ(path, mesh_flag_default); + } + + fs::create_directories(cache_filepath.parent_path()); + writeBIN(result_mesh, cache_filepath); + } + catch (const std::exception& ex) + { + std::cerr << ex.what() << "\n"; + + std::ofstream output("logs/compiler_error_log.txt"); + output << "Runtime Error>" << ex.what() << std::endl; + output.close(); + + std::this_thread::sleep_for(std::chrono::duration(5000.0f)); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/apps/editor/CMakeLists.txt b/apps/editor/CMakeLists.txt index 00158832e..d2ad66fb7 100644 --- a/apps/editor/CMakeLists.txt +++ b/apps/editor/CMakeLists.txt @@ -1,6 +1,10 @@ include(${CMAKE_SOURCE_DIR}/cmake/common.cmake) era_begin(editor "APP") + require_thirdparty_module(editor EnTT) + require_thirdparty_module(editor yaml-cpp) + require_thirdparty_module(editor rttr_core) + require_thirdparty_module(editor DirectXTex) require_module(editor base) require_module(editor core) require_module(editor physics) diff --git a/apps/editor/src/editor/editor_init_system.cpp b/apps/editor/src/editor/editor_init_system.cpp new file mode 100644 index 000000000..0fdbd38ab --- /dev/null +++ b/apps/editor/src/editor/editor_init_system.cpp @@ -0,0 +1,68 @@ +#include "editor/editor_init_system.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include