Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative root path #262

Merged
merged 4 commits into from
Jun 13, 2022
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
3 changes: 3 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set(ENGINE_ROOT_DIR "${PILOT_ROOT_DIR}/engine")
set(THIRD_PARTY_DIR "${ENGINE_ROOT_DIR}/3rdparty")
set(ENGINE_ASSET_DIR "/asset")

set(DEPLOY_CONFIG_DIR "configs/deployment")
set(DEVELOP_CONFIG_DIR "configs/development")

option(ENABLE_PHYSICS_DEBUG_RENDERER "Enable Physics Debug Renderer" OFF)

# only support physics debug render at windows platform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BinaryRootFolder=.
AssetFolder=asset
SchemaFolder=schema
BigIconFile=resource/PilotEditorBigIcon.png
Expand Down
9 changes: 9 additions & 0 deletions engine/configs/development/PilotEditor.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BinaryRootFolder=../../../../../bin
AssetFolder=asset
SchemaFolder=schema
BigIconFile=resource/PilotEditorBigIcon.png
SmallIconFile=resource/PilotEditorSmallIcon.png
FontFile=resource/PilotEditorFont.TTF
DefaultWorld=asset/world/hello.world.json
GlobalRenderingRes=asset/global/rendering.global.json
JoltAssetFolder=jolt-asset
31 changes: 15 additions & 16 deletions engine/source/editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,23 @@ target_compile_options(${TARGET_NAME} PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:

target_link_libraries(${TARGET_NAME} PilotRuntime)

if(NOT ENABLE_PHYSICS_DEBUG_RENDERER)
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${TARGET_NAME}.ini" "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resource" "${BINARY_ROOT_DIR}/resource"
COMMAND ${CMAKE_COMMAND} -E copy_directory "$<TARGET_FILE_DIR:${TARGET_NAME}>/" "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ENGINE_ROOT_DIR}/${ENGINE_ASSET_DIR}" "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}"
set(POST_BUILD_COMMANDS
COMMAND ${CMAKE_COMMAND} -E make_directory "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resource" "${BINARY_ROOT_DIR}/resource"
COMMAND ${CMAKE_COMMAND} -E copy_directory "$<TARGET_FILE_DIR:${TARGET_NAME}>/" "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${DEPLOY_CONFIG_DIR}/${TARGET_NAME}.ini" "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${DEVELOP_CONFIG_DIR}/${TARGET_NAME}.ini" "$<TARGET_FILE_DIR:${TARGET_NAME}>/"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ENGINE_ROOT_DIR}/${ENGINE_ASSET_DIR}" "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}"
)
else()
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${TARGET_NAME}.ini" "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resource" "${BINARY_ROOT_DIR}/resource"
COMMAND ${CMAKE_COMMAND} -E copy_directory "$<TARGET_FILE_DIR:${TARGET_NAME}>/" "${BINARY_ROOT_DIR}"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ENGINE_ROOT_DIR}/${ENGINE_ASSET_DIR}" "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}"



if(ENABLE_PHYSICS_DEBUG_RENDERER)
set(POST_BUILD_COMMANDS ${POST_BUILD_COMMANDS}
COMMAND ${CMAKE_COMMAND} -E remove_directory "${BINARY_ROOT_DIR}/${JOLT_ASSET_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ENGINE_ROOT_DIR}/${JOLT_ASSET_DIR}" "${BINARY_ROOT_DIR}/${JOLT_ASSET_DIR}"
)
endif()

add_custom_command(TARGET ${TARGET_NAME} ${POST_BUILD_COMMANDS})
10 changes: 4 additions & 6 deletions engine/source/editor/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <filesystem>
#include <iostream>
#include <string>
#include <thread>
Expand All @@ -13,15 +14,12 @@

int main(int argc, char** argv)
{
std::filesystem::path pilot_root_folder = std::filesystem::path(PILOT_XSTR(PILOT_ROOT_DIR));

Pilot::EngineInitParams params;
params.m_root_folder = pilot_root_folder;
params.m_config_file_path = pilot_root_folder / "PilotEditor.ini";
std::filesystem::path executable_path(argv[0]);
std::filesystem::path config_file_path = executable_path.parent_path() / "PilotEditor.ini";

Pilot::PilotEngine* engine = new Pilot::PilotEngine();

engine->startEngine(params);
engine->startEngine(config_file_path.generic_string());
engine->initialize();

Pilot::PilotEditor* editor = new Pilot::PilotEditor();
Expand Down
6 changes: 2 additions & 4 deletions engine/source/runtime/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ namespace Pilot
bool g_is_editor_mode {false};
std::unordered_set<std::string> g_editor_tick_component_types {};

void PilotEngine::startEngine(const EngineInitParams& param)
void PilotEngine::startEngine(const std::string& config_file_path)
{
m_init_params = param;

Reflection::TypeMetaRegister::Register();

g_runtime_global_context.startSystems(param);
g_runtime_global_context.startSystems(config_file_path);

LOG_INFO("engine start");
}
Expand Down
11 changes: 2 additions & 9 deletions engine/source/runtime/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
#include <atomic>
#include <chrono>
#include <filesystem>
#include <string>
#include <unordered_set>

namespace Pilot
{
extern bool g_is_editor_mode;
extern std::unordered_set<std::string> g_editor_tick_component_types;

struct EngineInitParams
{
std::filesystem::path m_root_folder;
std::filesystem::path m_config_file_path;
};

class PilotEngine
{
friend class PilotEditor;

static const float k_fps_alpha;

public:
void startEngine(const EngineInitParams& param);
void startEngine(const std::string& config_file_path);
void shutdownEngine();

void initialize();
Expand All @@ -47,8 +42,6 @@ namespace Pilot
float calculateDeltaTime();

protected:
EngineInitParams m_init_params;

bool m_is_quit {false};

std::chrono::steady_clock::time_point m_last_tick_time_point {std::chrono::steady_clock::now()};
Expand Down
4 changes: 2 additions & 2 deletions engine/source/runtime/function/global/global_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace Pilot
{
RuntimeGlobalContext g_runtime_global_context;

void RuntimeGlobalContext::startSystems(const EngineInitParams& init_params)
void RuntimeGlobalContext::startSystems(const std::string& config_file_path)
{
m_config_manager = std::make_shared<ConfigManager>();
m_config_manager->initialize(init_params);
m_config_manager->initialize(config_file_path);

m_file_system = std::make_shared<FileSystem>();

Expand Down
3 changes: 2 additions & 1 deletion engine/source/runtime/function/global/global_context.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <memory>
#include <string>

namespace Pilot
{
Expand All @@ -22,7 +23,7 @@ namespace Pilot
{
public:
// create all global systems and initialize these systems
void startSystems(const EngineInitParams& init_params);
void startSystems(const std::string& config_file_path);
// destroy all global systems
void shutdownSystems();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

#include "runtime/function/global/global_context.h"

#include <filesystem>

namespace Pilot
{
std::filesystem::path AssetManager::getFullPath(const std::string& relative_path) const
{
return g_runtime_global_context.m_config_manager->getRootFolder() / relative_path;
return std::filesystem::absolute(g_runtime_global_context.m_config_manager->getRootFolder() / relative_path);
}
} // namespace Pilot
5 changes: 3 additions & 2 deletions engine/source/runtime/resource/asset_manager/asset_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ namespace Pilot
bool loadAsset(const std::string& asset_url, AssetType& out_asset) const
{
// read json file to string
std::ifstream asset_json_file(getFullPath(asset_url));
std::filesystem::path asset_path = getFullPath(asset_url);
std::ifstream asset_json_file(asset_path);
if (!asset_json_file)
{
LOG_ERROR("open file: {} failed!", asset_url);
LOG_ERROR("open file: {} failed!", asset_path.generic_string());
return false;
}

Expand Down
12 changes: 8 additions & 4 deletions engine/source/runtime/resource/config_manager/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

#include "runtime/engine.h"

#include <filesystem>
#include <fstream>
#include <string>

namespace Pilot
{
void ConfigManager::initialize(const EngineInitParams& init_param)
void ConfigManager::initialize(const std::filesystem::path& config_file_path)
{
m_root_folder = init_param.m_root_folder;
// read configs
std::ifstream config_file(init_param.m_config_file_path);
std::ifstream config_file(config_file_path);
std::string config_line;
while (std::getline(config_file, config_line))
{
Expand All @@ -20,7 +20,11 @@ namespace Pilot
{
std::string name = config_line.substr(0, seperate_pos);
std::string value = config_line.substr(seperate_pos + 1, config_line.length() - seperate_pos - 1);
if (name == "AssetFolder")
if (name == "BinaryRootFolder")
{
m_root_folder = config_file_path.parent_path() / value;
}
else if (name == "AssetFolder")
{
m_asset_folder = m_root_folder / value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Pilot
class ConfigManager
{
public:
void initialize(const EngineInitParams& init_param);
void initialize(const std::filesystem::path& config_file_path);

const std::filesystem::path& getRootFolder() const;
const std::filesystem::path& getAssetFolder() const;
Expand Down