added project loader
This commit is contained in:
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -20,3 +20,9 @@
|
|||||||
[submodule "_ThirdParty/fmt"]
|
[submodule "_ThirdParty/fmt"]
|
||||||
path = _ThirdParty/fmt
|
path = _ThirdParty/fmt
|
||||||
url = https://github.com/fmtlib/fmt.git
|
url = https://github.com/fmtlib/fmt.git
|
||||||
|
[submodule "_ThirdParty/json"]
|
||||||
|
path = _ThirdParty/json
|
||||||
|
url = https://github.com/nlohmann/json.git
|
||||||
|
[submodule "_ThirdParty/nfd"]
|
||||||
|
path = _ThirdParty/nfd
|
||||||
|
url = https://github.com/btzy/nativefiledialog-extended.git
|
||||||
|
|||||||
@@ -12,8 +12,23 @@ set (GLFW_BUILD_TESTS OFF)
|
|||||||
set (GLFW_BUILD_DOCS OFF)
|
set (GLFW_BUILD_DOCS OFF)
|
||||||
add_subdirectory(_ThirdParty/glfw)
|
add_subdirectory(_ThirdParty/glfw)
|
||||||
|
|
||||||
|
add_subdirectory(_ThirdParty/glm)
|
||||||
|
|
||||||
|
include_directories(src/imgui)
|
||||||
|
file(GLOB_RECURSE IMGUI_SOURCES src/imgui/*.cpp)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp)
|
||||||
|
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/src/*.h)
|
||||||
|
|
||||||
|
add_subdirectory(_ThirdParty/entt)
|
||||||
|
add_subdirectory(_ThirdParty/fmt)
|
||||||
add_subdirectory(_ThirdParty/spdlog)
|
add_subdirectory(_ThirdParty/spdlog)
|
||||||
|
|
||||||
|
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||||
|
add_subdirectory(_ThirdParty/json)
|
||||||
|
|
||||||
|
add_subdirectory(_ThirdParty/nfd)
|
||||||
|
|
||||||
set (ASSIMP_INSTALL OFF)
|
set (ASSIMP_INSTALL OFF)
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
find_path(UNZIP_PATH unzip.h PATHS
|
find_path(UNZIP_PATH unzip.h PATHS
|
||||||
@@ -26,26 +41,16 @@ if(UNIX)
|
|||||||
endif()
|
endif()
|
||||||
add_subdirectory(_ThirdParty/assimp)
|
add_subdirectory(_ThirdParty/assimp)
|
||||||
target_compile_options(assimp PRIVATE
|
target_compile_options(assimp PRIVATE
|
||||||
-Wno-unused-but-set-variable
|
-Wno-unused-but-set-variable
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(_ThirdParty/glm)
|
|
||||||
|
|
||||||
add_subdirectory(_ThirdParty/entt)
|
|
||||||
|
|
||||||
add_subdirectory(_ThirdParty/fmt)
|
|
||||||
|
|
||||||
include_directories(src/imgui)
|
|
||||||
file(GLOB_RECURSE IMGUI_SOURCES src/imgui/*.cpp)
|
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp)
|
|
||||||
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/src/*.h)
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
${IMGUI_SOURCES}
|
${IMGUI_SOURCES}
|
||||||
${GLAD_SOURCE_DIR}/gl.c
|
${GLAD_SOURCE_DIR}/gl.c
|
||||||
${SOURCES}
|
${SOURCES}
|
||||||
${HEADERS})
|
${HEADERS}
|
||||||
|
src/ProjectManifestFile.cpp
|
||||||
|
src/ProjectManifestFile.h)
|
||||||
|
|
||||||
add_custom_target(copy_resources
|
add_custom_target(copy_resources
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
@@ -54,6 +59,7 @@ add_custom_target(copy_resources
|
|||||||
COMMENT "Copying resources..."
|
COMMENT "Copying resources..."
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} glfw spdlog assimp glm EnTT fmt)
|
target_link_libraries(${PROJECT_NAME} glfw spdlog assimp glm EnTT fmt nfd)
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${ASSIMP_INCLUDE_INSTALL_DIR})
|
target_include_directories(${PROJECT_NAME} PRIVATE ${ASSIMP_INCLUDE_INSTALL_DIR})
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE src)
|
target_include_directories(${PROJECT_NAME} PRIVATE src)
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE _ThirdParty/json/single_include)
|
||||||
|
|||||||
1
_ThirdParty/json
vendored
Submodule
1
_ThirdParty/json
vendored
Submodule
Submodule _ThirdParty/json added at 630beaeb05
1
_ThirdParty/nfd
vendored
Submodule
1
_ThirdParty/nfd
vendored
Submodule
Submodule _ThirdParty/nfd added at c9cc7baf28
@@ -5,9 +5,12 @@
|
|||||||
#ifndef B_ENGINE_PROJECTMANIFEST_H
|
#ifndef B_ENGINE_PROJECTMANIFEST_H
|
||||||
#define B_ENGINE_PROJECTMANIFEST_H
|
#define B_ENGINE_PROJECTMANIFEST_H
|
||||||
|
|
||||||
struct ProjectManifest
|
#include <string>
|
||||||
{
|
|
||||||
|
|
||||||
};
|
typedef struct
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
std::string assetFolder;
|
||||||
|
} ProjectManifest;
|
||||||
|
|
||||||
#endif //B_ENGINE_PROJECTMANIFEST_H
|
#endif //B_ENGINE_PROJECTMANIFEST_H
|
||||||
|
|||||||
38
src/ProjectManifestFile.cpp
Normal file
38
src/ProjectManifestFile.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// Created by slinky on 5/14/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ProjectManifestFile.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
std::unique_ptr<ProjectManifest> ProjectManifestFile::load(std::string_view _path) {
|
||||||
|
std::ifstream file;
|
||||||
|
file.open(_path.data(), std::ios::in);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
spdlog::error("failed to open project file {}", _path);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << file.rdbuf();
|
||||||
|
|
||||||
|
std::string fileData = ss.str();
|
||||||
|
|
||||||
|
auto data = json::parse(fileData);
|
||||||
|
|
||||||
|
ProjectManifest manifest;
|
||||||
|
manifest.name = data.at("name").get<std::string>();
|
||||||
|
manifest.assetFolder = data.at("assetFolder").get<std::string>();
|
||||||
|
|
||||||
|
return std::make_unique<ProjectManifest>(manifest);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProjectManifestFile::save(std::string_view _path, ProjectManifest *_project) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
19
src/ProjectManifestFile.h
Normal file
19
src/ProjectManifestFile.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by slinky on 5/14/26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef B_ENGINE_PROJECTMANIFESTFILE_H
|
||||||
|
#define B_ENGINE_PROJECTMANIFESTFILE_H
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "ProjectManifest.h"
|
||||||
|
|
||||||
|
class ProjectManifestFile {
|
||||||
|
public:
|
||||||
|
static std::unique_ptr<ProjectManifest> load(std::string_view _path);
|
||||||
|
static bool save(std::string_view _path, ProjectManifest* _project);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //B_ENGINE_PROJECTMANIFESTFILE_H
|
||||||
29
src/main.cpp
29
src/main.cpp
@@ -15,6 +15,8 @@
|
|||||||
#include "FreeCameraController.h"
|
#include "FreeCameraController.h"
|
||||||
#include "InputManager.h"
|
#include "InputManager.h"
|
||||||
#include "ModelManager.h"
|
#include "ModelManager.h"
|
||||||
|
#include "ProjectManifest.h"
|
||||||
|
#include "ProjectManifestFile.h"
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include "ShaderManager.h"
|
#include "ShaderManager.h"
|
||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
@@ -26,6 +28,8 @@
|
|||||||
#include "ui/UISceneGraph.h"
|
#include "ui/UISceneGraph.h"
|
||||||
#include "ui/UISceneViewer.h"
|
#include "ui/UISceneViewer.h"
|
||||||
|
|
||||||
|
const char* B_ENGINE_VERSION = "v0.0.3";
|
||||||
|
|
||||||
GLFWwindow* gWindow = nullptr;
|
GLFWwindow* gWindow = nullptr;
|
||||||
int gWindowWidth = 1920;
|
int gWindowWidth = 1920;
|
||||||
int gWindowHeight = 1080;
|
int gWindowHeight = 1080;
|
||||||
@@ -37,6 +41,8 @@ float gAspectRatio = 0.f;
|
|||||||
|
|
||||||
float gMouseSensitivity = 0.1f;
|
float gMouseSensitivity = 0.1f;
|
||||||
|
|
||||||
|
std::unique_ptr<ProjectManifest> gCurrentProject {nullptr};
|
||||||
|
|
||||||
Camera gCamera {};
|
Camera gCamera {};
|
||||||
Scene gScene{};
|
Scene gScene{};
|
||||||
EditorContext gEditorCtx{};
|
EditorContext gEditorCtx{};
|
||||||
@@ -58,13 +64,14 @@ void load_default_models();
|
|||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
void create_entity(entt::entity parent);
|
void create_entity(entt::entity parent);
|
||||||
|
void open_project(std::string_view _path);
|
||||||
|
|
||||||
auto xAxis = glm::vec3{1.f, 0.f, 0.f};
|
auto xAxis = glm::vec3{1.f, 0.f, 0.f};
|
||||||
auto yAxis = glm::vec3{0.f, 1.f, 0.f};
|
auto yAxis = glm::vec3{0.f, 1.f, 0.f};
|
||||||
auto zAxis = glm::vec3{0.f, 0.f, 1.f};
|
auto zAxis = glm::vec3{0.f, 0.f, 1.f};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
spdlog::info("b_engine v0.0.3 start");
|
spdlog::info("b_engine {} start", B_ENGINE_VERSION);
|
||||||
|
|
||||||
init_glfw();
|
init_glfw();
|
||||||
|
|
||||||
@@ -83,8 +90,9 @@ int main() {
|
|||||||
load_default_models();
|
load_default_models();
|
||||||
|
|
||||||
UIManager::init(gWindow);
|
UIManager::init(gWindow);
|
||||||
UIMenuBar* menuBar = UIManager::add_ui_panel<UIMenuBar>("menu_bar");
|
auto* menuBar = UIManager::add_ui_panel<UIMenuBar>("menu_bar");
|
||||||
menuBar->create_entity = create_entity;
|
menuBar->create_entity = create_entity;
|
||||||
|
menuBar->open_project = open_project;
|
||||||
UIManager::add_ui_panel<UISceneViewer>("scene_viewer");
|
UIManager::add_ui_panel<UISceneViewer>("scene_viewer");
|
||||||
UIManager::add_ui_panel<UISceneGraph>("scene_graph");
|
UIManager::add_ui_panel<UISceneGraph>("scene_graph");
|
||||||
UIManager::add_ui_panel<UIEntityInspector>("entity_inspector");
|
UIManager::add_ui_panel<UIEntityInspector>("entity_inspector");
|
||||||
@@ -142,7 +150,8 @@ void init_glfw()
|
|||||||
|
|
||||||
void create_main_window()
|
void create_main_window()
|
||||||
{
|
{
|
||||||
gWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, "b_engine v0.0.3", nullptr, nullptr);
|
std::string title = fmt::format("b_engine {}", B_ENGINE_VERSION);
|
||||||
|
gWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, title.c_str(), nullptr, nullptr);
|
||||||
if (!gWindow) {
|
if (!gWindow) {
|
||||||
spdlog::error("failed to create glfw window");
|
spdlog::error("failed to create glfw window");
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
@@ -272,10 +281,12 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void create_entity(entt::entity parent) {
|
void create_entity(entt::entity parent) {
|
||||||
auto entity = gScene.create_game_object(parent);
|
gScene.create_game_object(parent);
|
||||||
auto& drawable = gScene.attach_component<Components::Drawable>(entity);
|
}
|
||||||
drawable.model = ModelManager::models["vette"];
|
|
||||||
auto& transform = gScene.fetch_component<Components::Transform>(entity);
|
void open_project(std::string_view _path) {
|
||||||
transform.scale = {0.1, 0.1, 0.1};
|
gCurrentProject = ProjectManifestFile::load(_path);
|
||||||
transform.dirty = true;
|
|
||||||
|
const std::string title = fmt::format("project \"{}\" | b_engine {}", gCurrentProject->name, B_ENGINE_VERSION);
|
||||||
|
glfwSetWindowTitle(gWindow, title.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,34 @@
|
|||||||
|
|
||||||
#include "UIMenuBar.h"
|
#include "UIMenuBar.h"
|
||||||
#include "UIManager.h"
|
#include "UIManager.h"
|
||||||
|
#include "UISceneGraph.h"
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "UISceneGraph.h"
|
|
||||||
|
#include "nfd.h"
|
||||||
|
|
||||||
void UIMenuBar::update(EditorContext &context) {
|
void UIMenuBar::update(EditorContext &context) {
|
||||||
if (ImGui::BeginMainMenuBar()) {
|
if (ImGui::BeginMainMenuBar()) {
|
||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
if (ImGui::MenuItem("New Scene")) {
|
if (ImGui::MenuItem("New Project")) {
|
||||||
}
|
}
|
||||||
if (ImGui::MenuItem("Open Scene")) {
|
if (ImGui::MenuItem("Open Project")) {
|
||||||
|
NFD_Init();
|
||||||
|
|
||||||
|
nfdu8char_t *outPath;
|
||||||
|
nfdu8filteritem_t filters[1] = { { "b_engine project files", "json" } };
|
||||||
|
nfdopendialogu8args_t args = {0};
|
||||||
|
args.filterList = filters;
|
||||||
|
args.filterCount = 1;
|
||||||
|
nfdresult_t result = NFD_OpenDialogU8_With(&outPath, &args);
|
||||||
|
|
||||||
|
if (result == NFD_OKAY && open_project)
|
||||||
|
{
|
||||||
|
open_project(outPath);
|
||||||
|
NFD_FreePathU8(outPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
NFD_Quit();
|
||||||
}
|
}
|
||||||
ImGui::Separator(); // Adds a visual line between sections
|
ImGui::Separator(); // Adds a visual line between sections
|
||||||
if (ImGui::MenuItem("Save", "Ctrl+S")) {
|
if (ImGui::MenuItem("Save", "Ctrl+S")) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public:
|
|||||||
void update(EditorContext &context) override;
|
void update(EditorContext &context) override;
|
||||||
|
|
||||||
std::function<void(entt::entity)> create_entity;
|
std::function<void(entt::entity)> create_entity;
|
||||||
|
std::function<void(std::string_view path)> open_project;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user