rebuild zengine
This commit is contained in:
parent
96c78ab1df
commit
fc043a0a8d
3
engine/3rdparty/zlib/include/refl/macro.h
vendored
3
engine/3rdparty/zlib/include/refl/macro.h
vendored
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#if !defined(__cppast)
|
#if !defined(__cppast)
|
||||||
#define __cppast(...)
|
#define __cppast(...)
|
||||||
|
#else
|
||||||
|
class string_view;
|
||||||
|
class string;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define __Meta(...) __cppast(Meta,__VA_ARGS__)
|
#define __Meta(...) __cppast(Meta,__VA_ARGS__)
|
||||||
|
|||||||
@ -3,15 +3,18 @@
|
|||||||
#include "render/window.h"
|
#include "render/window.h"
|
||||||
#include "object/mesh/actor.h"
|
#include "object/mesh/actor.h"
|
||||||
#include "data/property/actor_property.h"
|
#include "data/property/actor_property.h"
|
||||||
|
#include "asset/file_manager.h"
|
||||||
#include "asset/asset_manager.h"
|
#include "asset/asset_manager.h"
|
||||||
#include "object/scene/scene_manager.h"
|
#include "object/scene/scene_manager.h"
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
App::App(const string& path)
|
App::App(const string& path)
|
||||||
{
|
{
|
||||||
const char* name = "zengine";
|
const char* name = "zengine";
|
||||||
|
SystemList.push_back(new FileManager());
|
||||||
SystemList.push_back(new AssetManager());
|
SystemList.push_back(new AssetManager());
|
||||||
SystemList.push_back(RenderAPI::MakeInstance());
|
SystemList.push_back(RenderAPI::MakeInstance());
|
||||||
SystemList.push_back(Window::MakeInstance(3, 640, 720, name));
|
SystemList.push_back(Window::MakeInstance(3, 640, 720, name));
|
||||||
|
SystemList.push_back(new SceneManager());
|
||||||
}
|
}
|
||||||
App::~App()
|
App::~App()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "guid.h"
|
||||||
|
#include "package_path.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "package_path.h"
|
|
||||||
namespace engineapi
|
namespace engineapi
|
||||||
{
|
{
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|||||||
@ -46,5 +46,6 @@ namespace engineapi
|
|||||||
AssetManager() = default;
|
AssetManager() = default;
|
||||||
private:
|
private:
|
||||||
inline static table<string_view, AssetWrap> AssetMap;
|
inline static table<string_view, AssetWrap> AssetMap;
|
||||||
|
inline static table<Guid, AssetWrap> AssetNext;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,12 @@ using namespace std;
|
|||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
void FileManager::Init()
|
void FileManager::Init()
|
||||||
{
|
{
|
||||||
|
std::filesystem::path path = std::filesystem::current_path();
|
||||||
|
Mount(string_view("engine"), path.string());
|
||||||
}
|
}
|
||||||
void FileManager::Shutdown()
|
void FileManager::Shutdown()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
string FileManager::LoadTextFile(const string& path)
|
string FileManager::LoadTextFile(const string& path)
|
||||||
{
|
{
|
||||||
@ -32,18 +35,18 @@ namespace engineapi {
|
|||||||
}
|
}
|
||||||
vector<char> FileManager::LoadBinaryFile(const string& path)
|
vector<char> FileManager::LoadBinaryFile(const string& path)
|
||||||
{
|
{
|
||||||
// ate:在文件末尾开始读取,从文件末尾开始读取的优点是我们可以使用读取位置来确定文件的大小并分配缓冲区
|
// ate:在文件末尾开始读取,从文件末尾开始读取的优点是我们可以使用读取位置来确定文件的大小并分配缓冲区
|
||||||
ifstream file(path, std::ios::ate | std::ios::binary);
|
ifstream file(path, std::ios::ate | std::ios::binary);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
zlog::info("Failed to load binary file: {}", path);
|
zlog::info("Failed to load binary file: {}", path);
|
||||||
return vector<char>();
|
return vector<char>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用读取位置来确定文件的大小并分配缓冲区
|
// 使用读取位置来确定文件的大小并分配缓冲区
|
||||||
size_t fileSize = (size_t)file.tellg();
|
size_t fileSize = (size_t)file.tellg();
|
||||||
vector<char> data(fileSize);
|
vector<char> data(fileSize);
|
||||||
|
|
||||||
// 返回文件开头,真正读取内容
|
// 返回文件开头,真正读取内容
|
||||||
file.seekg(0);
|
file.seekg(0);
|
||||||
file.read(data.data(), fileSize);
|
file.read(data.data(), fileSize);
|
||||||
file.close();
|
file.close();
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "package_path.h".
|
#include "asset.h"
|
||||||
#include "singleton.h"
|
#include "singleton.h"
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
namespace engineapi
|
namespace engineapi
|
||||||
@ -11,9 +11,12 @@ namespace engineapi
|
|||||||
void Init() override;
|
void Init() override;
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
public:
|
public:
|
||||||
|
static void Mount(NameID id, const string& path) {
|
||||||
|
MountMap.emplace(id, path);
|
||||||
|
}
|
||||||
static string FindMount(NameID id) {
|
static string FindMount(NameID id) {
|
||||||
auto it = MountMap.find(id);
|
auto it = MountMap.find(id);
|
||||||
if (it == MountMap.end()) {
|
if (it != MountMap.end()) {
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
79
engine/src/engine/asset/guid.h
Normal file
79
engine/src/engine/asset/guid.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "refl/refl.h"
|
||||||
|
#include <objbase.h>
|
||||||
|
#include <string>
|
||||||
|
namespace engineapi
|
||||||
|
{
|
||||||
|
using std::string;
|
||||||
|
using std::string_view;
|
||||||
|
struct Guid
|
||||||
|
{
|
||||||
|
using MyMeta = class Guid_Meta;
|
||||||
|
UPROPERTY({})
|
||||||
|
unsigned int Data1;
|
||||||
|
UPROPERTY({})
|
||||||
|
unsigned short Data2;
|
||||||
|
UPROPERTY({})
|
||||||
|
unsigned short Data3;
|
||||||
|
UPROPERTY({})
|
||||||
|
unsigned char Data4[8];
|
||||||
|
constexpr Guid() noexcept
|
||||||
|
: Data1{ 0 }, Data2{ 0 }, Data3{ 0 }, Data4{ 0,0,0,0,0,0,0,0 }
|
||||||
|
{}
|
||||||
|
UFUNCTION({})
|
||||||
|
Guid(const string_view& str) noexcept
|
||||||
|
: Guid{}
|
||||||
|
{
|
||||||
|
sscanf_s(str.data(),
|
||||||
|
"%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
||||||
|
&Data1, &Data2, &Data3,
|
||||||
|
&Data4[0], &Data4[1], &Data4[2], &Data4[3],
|
||||||
|
&Data4[4], &Data4[5], &Data4[6], &Data4[7]);
|
||||||
|
|
||||||
|
}
|
||||||
|
constexpr Guid(unsigned int a, unsigned short b, unsigned short c, unsigned long long d)
|
||||||
|
: Data1{ a }
|
||||||
|
, Data2{ b }
|
||||||
|
, Data3{ c }
|
||||||
|
, Data4{
|
||||||
|
(unsigned char)(d >> 56 & 0xFF)
|
||||||
|
, (unsigned char)(d >> 48 & 0xFF)
|
||||||
|
, (unsigned char)(d >> 40 & 0xFF)
|
||||||
|
, (unsigned char)(d >> 32 & 0xFF)
|
||||||
|
, (unsigned char)(d >> 24 & 0xFF)
|
||||||
|
, (unsigned char)(d >> 16 & 0xFF)
|
||||||
|
, (unsigned char)(d >> 8 & 0xFF)
|
||||||
|
, (unsigned char)(d >> 0 & 0xFF)
|
||||||
|
}
|
||||||
|
{};
|
||||||
|
UFUNCTION({})
|
||||||
|
string ToString()const {
|
||||||
|
char guid_cstr[39];
|
||||||
|
snprintf(guid_cstr, sizeof(guid_cstr),
|
||||||
|
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||||
|
Data1, Data2, Data3,
|
||||||
|
Data4[0], Data4[1], Data4[2], Data4[3],
|
||||||
|
Data4[4], Data4[5], Data4[6], Data4[7]);
|
||||||
|
return string{ guid_cstr };
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
auto operator<=>(const Guid&) const noexcept = default;
|
||||||
|
operator bool() const noexcept
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<const GUID*>(this) != GUID_NULL;
|
||||||
|
}
|
||||||
|
operator string() const
|
||||||
|
{
|
||||||
|
return ToString();
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
UFUNCTION({})
|
||||||
|
static Guid Make()
|
||||||
|
{
|
||||||
|
Guid guid;
|
||||||
|
const auto res = CoCreateGuid((GUID*)&guid);
|
||||||
|
return guid;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#include "guid_gen.inl"
|
||||||
@ -16,7 +16,7 @@ namespace engineapi
|
|||||||
PackagePath(const string& path) : path(StringView(path)) {};
|
PackagePath(const string& path) : path(StringView(path)) {};
|
||||||
PackagePath(const string&& path) : path(path) {}
|
PackagePath(const string&& path) : path(path) {}
|
||||||
bool CheckPackage() {
|
bool CheckPackage() {
|
||||||
if (name.empty()) {
|
if (!name.empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (path[0] == '/') {
|
if (path[0] == '/') {
|
||||||
|
|||||||
25
engine/src/engine/asset/resource_config.h
Normal file
25
engine/src/engine/asset/resource_config.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <tuple>
|
||||||
|
namespace engineapi {
|
||||||
|
template <typename T, typename Tuple>
|
||||||
|
constexpr uint8_t index_in_tuple() {
|
||||||
|
constexpr std::size_t N = std::tuple_size_v<Tuple>;
|
||||||
|
for (std::size_t i = 0; i < N; ++i) {
|
||||||
|
if constexpr (is_same<T, std::tuple_element_t<i, Tuple>>::value) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename FindMe, typename Tuple>
|
||||||
|
constexpr uint8_t index_in_tuple_v = index_in_tuple<FindMe, Tuple>();
|
||||||
|
|
||||||
|
using Resources = std::tuple<
|
||||||
|
class Scene
|
||||||
|
, class Shader
|
||||||
|
>;
|
||||||
|
template<typename Resource>
|
||||||
|
constexpr auto ResourceID = index_in_tuple_v<Resource, Resources>;
|
||||||
|
constexpr auto ResourceCount = std::tuple_size_v<Resources>;
|
||||||
|
}
|
||||||
0
engine/src/engine/asset/resource_manager.cpp
Normal file
0
engine/src/engine/asset/resource_manager.cpp
Normal file
4
engine/src/engine/asset/resource_manager.h
Normal file
4
engine/src/engine/asset/resource_manager.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
namespace engineapi {
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,12 +8,12 @@ namespace engineapi {
|
|||||||
{
|
{
|
||||||
mCamera = new Camera();
|
mCamera = new Camera();
|
||||||
auto flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
auto flags = Asset::ASSET_SHARED_FLAG | Asset::ASSET_ASYNC_FLAG;
|
||||||
Material* material = new Material("assets/shader/simple", flags);
|
Material* material = new Material("/engine/assets/shader/simple", flags);
|
||||||
{
|
{
|
||||||
ActorProperty property;
|
ActorProperty property;
|
||||||
property.id = 1;
|
property.id = 1;
|
||||||
property.flags = flags;
|
property.flags = flags;
|
||||||
property.path = "assets/models/cube.obj";
|
property.path = "/engine/assets/models/cube.obj";
|
||||||
actor1 = ActorMesh::New(property);
|
actor1 = ActorMesh::New(property);
|
||||||
actor1->Ptr().SetMaterial(material);
|
actor1->Ptr().SetMaterial(material);
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ namespace engineapi {
|
|||||||
ActorProperty property;
|
ActorProperty property;
|
||||||
property.id = 1;
|
property.id = 1;
|
||||||
property.flags = flags;
|
property.flags = flags;
|
||||||
property.path = "assets/models/box.ply";
|
property.path = "/engine/assets/models/box.ply";
|
||||||
actor2 = ActorMesh::New(property);
|
actor2 = ActorMesh::New(property);
|
||||||
actor2->Ptr().SetMaterial(material);
|
actor2->Ptr().SetMaterial(material);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,13 @@
|
|||||||
#include "scene_manager.h"
|
#include "scene_manager.h"
|
||||||
#include "zlog.h"
|
#include "zlog.h"
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
|
void SceneManager::Init()
|
||||||
|
{
|
||||||
|
LoadScene("hello", true);
|
||||||
|
}
|
||||||
|
void SceneManager::Shutdown()
|
||||||
|
{
|
||||||
|
}
|
||||||
Scene* SceneManager::GetScene(const Name& name)
|
Scene* SceneManager::GetScene(const Name& name)
|
||||||
{
|
{
|
||||||
auto sceneInfo = GetSceneInfo(name);
|
auto sceneInfo = GetSceneInfo(name);
|
||||||
|
|||||||
@ -12,6 +12,9 @@ namespace engineapi {
|
|||||||
protected:
|
protected:
|
||||||
SceneInfo* curScene = nullptr;
|
SceneInfo* curScene = nullptr;
|
||||||
table<Name, SceneInfo*> scenes;
|
table<Name, SceneInfo*> scenes;
|
||||||
|
public:
|
||||||
|
void Init() override;
|
||||||
|
void Shutdown() override;
|
||||||
public:
|
public:
|
||||||
Scene* GetScene(const Name& name);
|
Scene* GetScene(const Name& name);
|
||||||
void LoadScene(const Name& path, bool switchNow = true);
|
void LoadScene(const Name& path, bool switchNow = true);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "asset/asset_manager.h"
|
#include "asset/file_manager.h"
|
||||||
#include "../renderapi.h"
|
#include "../renderapi.h"
|
||||||
namespace engineapi {
|
namespace engineapi {
|
||||||
Shader::Shader(string_view name, uint32_t flags)
|
Shader::Shader(string_view name, uint32_t flags)
|
||||||
@ -12,17 +12,17 @@ namespace engineapi {
|
|||||||
}
|
}
|
||||||
void Shader::BeginLoad()
|
void Shader::BeginLoad()
|
||||||
{
|
{
|
||||||
json data = AssetManager::LoadJsonFile(string(mName) + ".json");
|
json data = FileManager::LoadJsonFile(PackagePath::AbsolutePath(mName) + ".json");
|
||||||
RenderAPI::GetSingletonPtr()->LoadShader(this);
|
RenderAPI::GetSingletonPtr()->LoadShader(this);
|
||||||
//ShaderProperty
|
//ShaderProperty
|
||||||
//mInfo.vertProperties.baseProperties.push_back
|
//mInfo.vertProperties.baseProperties.push_back
|
||||||
}
|
}
|
||||||
vector<char> Shader::GetVertData()
|
vector<char> Shader::GetVertData()
|
||||||
{
|
{
|
||||||
return AssetManager::LoadBinaryFile(string(mName) + ".vert.spv");
|
return FileManager::LoadBinaryFile(PackagePath::AbsolutePath(mName) + ".vert.spv");
|
||||||
}
|
}
|
||||||
vector<char> Shader::GetFragData()
|
vector<char> Shader::GetFragData()
|
||||||
{
|
{
|
||||||
return AssetManager::LoadBinaryFile(string(mName) + ".frag.spv");
|
return FileManager::LoadBinaryFile(PackagePath::AbsolutePath(mName) + ".frag.spv");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,14 +7,14 @@ target("zengine")
|
|||||||
set_rundir(".")
|
set_rundir(".")
|
||||||
add_rules("volk.env", "glsl.env")
|
add_rules("volk.env", "glsl.env")
|
||||||
add_rules("c++.codegen",{
|
add_rules("c++.codegen",{
|
||||||
files = {"src/engine/render/meta/*.h"}
|
files = {"src/engine/render/meta/*.h", "src/engine/asset/guid.h"}
|
||||||
})
|
})
|
||||||
add_deps("zlib","zlog")
|
add_deps("zlib","zlog")
|
||||||
add_defines("VULKAN_API")
|
add_defines("VULKAN_API")
|
||||||
add_packages("vulkansdk","tinyobjloader","assimp","nlohmann_json")
|
add_packages("vulkansdk","tinyobjloader","assimp","nlohmann_json")
|
||||||
add_includedirs("src/engine")
|
add_includedirs("src/engine")
|
||||||
add_includedirs("src/3rdparty/volk", "src/3rdparty/vulkan-memory-allocator", "src/3rdparty/template")
|
add_includedirs("src/3rdparty/volk", "src/3rdparty/vulkan-memory-allocator", "src/3rdparty/template")
|
||||||
add_syslinks("user32")
|
add_syslinks("user32", "Ole32")
|
||||||
add_files("src/*.cpp", "src/**.cpp")
|
add_files("src/*.cpp", "src/**.cpp")
|
||||||
add_files("src/3rdparty/**.c")
|
add_files("src/3rdparty/**.c")
|
||||||
add_headerfiles("src/**.h")
|
add_headerfiles("src/**.h")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user