Merge pull request #5 from Jiga228/main #1
+32
-7
@@ -4,23 +4,48 @@ find_package(Vulkan REQUIRED)
|
|||||||
|
|
||||||
file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.h" "*.hpp")
|
file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.h" "*.hpp")
|
||||||
|
|
||||||
add_library(${CORE_NAME} STATIC ${SRC})
|
add_library(Core STATIC ${SRC})
|
||||||
target_compile_features(${CORE_NAME} PRIVATE cxx_std_17)
|
target_compile_features(Core PRIVATE cxx_std_17)
|
||||||
target_include_directories(${CORE_NAME} PUBLIC
|
target_include_directories(Core PUBLIC
|
||||||
${PROJECT_SOURCE_DIR}/FastRTTI
|
${PROJECT_SOURCE_DIR}/FastRTTI
|
||||||
${PROJECT_SOURCE_DIR}/Delegate
|
|
||||||
)
|
)
|
||||||
target_include_directories(${CORE_NAME}
|
target_include_directories(Core
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${PROJECT_SOURCE_DIR}/glfw/Include
|
${PROJECT_SOURCE_DIR}/glfw/Include
|
||||||
${PROJECT_SOURCE_DIR}/RenderEngineSDK
|
${PROJECT_SOURCE_DIR}/RenderEngineSDK
|
||||||
${Vulkan_INCLUDE_DIRS}
|
${Vulkan_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${CORE_NAME} PRIVATE
|
target_link_libraries(Core PRIVATE
|
||||||
${CMAKE_DL_LIBS} # For linux
|
${CMAKE_DL_LIBS} # For linux
|
||||||
FastRTTI
|
FastRTTI
|
||||||
glfw
|
glfw
|
||||||
Vulkan::Vulkan
|
Vulkan::Vulkan
|
||||||
)
|
)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE HEADERS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.hpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach (HEADER ${HEADERS})
|
||||||
|
file(RELATIVE_PATH R_PATH
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
"${HEADER}"
|
||||||
|
)
|
||||||
|
|
||||||
|
get_filename_component(HEADER_DIR ${R_PATH} DIRECTORY)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
TARGET Core
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||||
|
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/include/${HEADER_DIR}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${HEADER}"
|
||||||
|
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/include/${R_PATH}"
|
||||||
|
|
||||||
|
COMMENT "Copy Core headers"
|
||||||
|
)
|
||||||
|
endforeach ()
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
#include "ModelManager.hpp"
|
|
||||||
|
|
||||||
#include "Log/Log.hpp"
|
|
||||||
|
|
||||||
ModelManager::owner_counter::owner_counter(const owner_counter& other) : counter(other.counter.load()), model(other.model)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int ModelManager::FNV1aHash(const char* buf)
|
|
||||||
{
|
|
||||||
unsigned int h_val = 0x811c9dc5;
|
|
||||||
|
|
||||||
while (*buf)
|
|
||||||
{
|
|
||||||
h_val ^= static_cast<unsigned int>(*buf++);
|
|
||||||
h_val *= 0x01000193;
|
|
||||||
}
|
|
||||||
|
|
||||||
return h_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
ModelManager::~ModelManager()
|
|
||||||
{
|
|
||||||
models.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
ModelManager::StaticModel* ModelManager::LoadModel(const std::string& name)
|
|
||||||
{
|
|
||||||
if (name.empty())
|
|
||||||
return nullptr;
|
|
||||||
unsigned int hash = FNV1aHash(name.c_str());
|
|
||||||
auto counter = models.find(hash);
|
|
||||||
if (counter != models.cend())
|
|
||||||
{
|
|
||||||
++counter->second.counter;
|
|
||||||
return counter->second.model;
|
|
||||||
}
|
|
||||||
|
|
||||||
Loging::Log("Load new model: " + name);
|
|
||||||
|
|
||||||
// Load model_data
|
|
||||||
owner_counter new_counter;
|
|
||||||
new_counter.counter.store(1);
|
|
||||||
new_counter.model = new StaticModel();
|
|
||||||
models.try_emplace(hash, new_counter);
|
|
||||||
return new_counter.model;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelManager::FreeModel(const std::string& name)
|
|
||||||
{
|
|
||||||
if (name.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
unsigned int hash = FNV1aHash(name.c_str());
|
|
||||||
auto counter = models.find(hash);
|
|
||||||
--counter->second.counter;
|
|
||||||
|
|
||||||
StaticModel* model = counter->second.model;
|
|
||||||
if (counter->second.counter.load() == 0)
|
|
||||||
{
|
|
||||||
models.erase(hash);
|
|
||||||
delete model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <string>
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
class ModelManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class StaticModel
|
|
||||||
{
|
|
||||||
//DATA
|
|
||||||
};
|
|
||||||
|
|
||||||
struct owner_counter
|
|
||||||
{
|
|
||||||
std::atomic_ullong counter;
|
|
||||||
StaticModel* model;
|
|
||||||
|
|
||||||
owner_counter() = default;
|
|
||||||
owner_counter(const owner_counter& other);
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::unordered_map<unsigned int, owner_counter> models;
|
|
||||||
|
|
||||||
static unsigned int FNV1aHash (const char *buf);
|
|
||||||
|
|
||||||
public:
|
|
||||||
~ModelManager();
|
|
||||||
|
|
||||||
StaticModel* LoadModel(const std::string& name);
|
|
||||||
void FreeModel(const std::string& name);
|
|
||||||
};
|
|
||||||
@@ -5,3 +5,29 @@ target_include_directories(UwURenderEngine PUBLIC ${PROJECT_SOURCE_DIR}/RenderEn
|
|||||||
target_link_libraries(UwURenderEngine PUBLIC RenderEngineSDK)
|
target_link_libraries(UwURenderEngine PUBLIC RenderEngineSDK)
|
||||||
|
|
||||||
target_compile_features(UwURenderEngine PRIVATE cxx_std_17)
|
target_compile_features(UwURenderEngine PRIVATE cxx_std_17)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE HEADERS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/*.hpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach (HEADER ${HEADERS})
|
||||||
|
file(RELATIVE_PATH R_PATH
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/"
|
||||||
|
"${HEADER}"
|
||||||
|
)
|
||||||
|
|
||||||
|
get_filename_component(HEADER_DIR "${R_PATH}" DIRECTORY)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
TARGET UwURenderEngine
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||||
|
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/include/${HEADER_DIR}"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${HEADER}"
|
||||||
|
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/include/${R_PATH}"
|
||||||
|
|
||||||
|
COMMENT "Copy UwURenderEngine headers"
|
||||||
|
)
|
||||||
|
endforeach ()
|
||||||
@@ -3,9 +3,4 @@ mkdir .\build
|
|||||||
cd build
|
cd build
|
||||||
cmake -DBUILD_MODE=Engine ..
|
cmake -DBUILD_MODE=Engine ..
|
||||||
cmake --build . --config Release
|
cmake --build . --config Release
|
||||||
cd ..
|
|
||||||
mkdir ".\build\bin\include"
|
|
||||||
robocopy ".\Core" ".\build\bin\include\Core" *.h *.hpp /S
|
|
||||||
robocopy ".\Delegate" ".\build\bin\include\Delegate" *.h *.hpp /S
|
|
||||||
robocopy ".\FastRTTI" ".\build\bin\include\FastRTTI" *.h *.hpp /S
|
|
||||||
pause
|
pause
|
||||||
Reference in New Issue
Block a user