This commit is contained in:
ouczbs 2024-08-03 17:56:38 +08:00
parent f5e2424f0f
commit a552c5d8e4
23 changed files with 74 additions and 58 deletions

7
.vscode/emmyrc.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"diagnostics": {
"disable": [
"undefined-global"
]
}
}

5
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"recommendations": [
"tangzx.emmylua"
]
}

7
.vscode/launch.json vendored
View File

@ -17,5 +17,10 @@
],
"ideConnectDebugger": true
}
]
],
"diagnostics": {
"disable": [
"undefined-global"
]
},
}

View File

@ -5,4 +5,4 @@ static_component("asset","engine")
add_includedirs("include/asset")
add_headerfiles("include/**.h","include/**.inl")
add_files("src/**.cpp")
add_deps("core", {public = true})
add_deps("core", "zlib")

View File

@ -20,7 +20,7 @@ namespace zlog {
m_logger->flush();
}
};
extern zloger zlog;
CORE_API inline zloger zlog;
template <typename... Args>
void info(format_with_location fmt, Args &&...args) {
zlog.log(level_enum::info, fmt, std::forward<Args>(args)...);
@ -43,5 +43,7 @@ namespace zlog {
const std::string format_str = fmt::format(std::forward<Args>(args)...);
throw std::runtime_error(format_str);
};
void flush();
inline void flush() {
zlog.flush();
}
};

View File

@ -11,9 +11,8 @@ namespace api {
using Write = yyjson_mut_val*(*)(yyjson_mut_doc*, const void*);
};
struct JsonArchive {
private:
static bool InitJsonSerde();
inline static bool HasInit = InitJsonSerde();
public:
static void InitJsonSerde();
public:
template<typename T>
static void Register();

View File

@ -27,13 +27,12 @@ namespace api {
alc.ctx = mr;
return alc;
}
inline bool JsonArchive::InitJsonSerde()
inline void JsonArchive::InitJsonSerde()
{
using std::string_view;
#define RegisterAny(T) Register<T>();
#include "../register.inl"
#undef RegisterAny
return true;
}
constexpr size_t VJsonSerdeRead() {
return string_hash("JsonSerdeRead");

View File

@ -3,8 +3,6 @@
#include "enum_macro.h"
#include "os/shared_library.h"
#include "refl/pch.h"
//可变生命周期,回收内存
inline thread_local pmr::unsynchronized_pool_resource MemPool;
// 默认对齐方式 new
void* operator new(std::size_t size);
// 默认对齐方式 delete

View File

@ -1,7 +1,7 @@
#pragma once
#include "module.h"
namespace api {
class DLL_API ModuleManager
class CORE_API ModuleManager
{
friend struct IModule;
private:

View File

@ -4,7 +4,6 @@
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
namespace zlog {
zloger zlog;
zloger::zloger()
{
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
@ -33,7 +32,4 @@ namespace zlog {
m_logger->flush();
spdlog::drop_all();
}
void flush(){
zlog.flush();
}
}

View File

@ -5,6 +5,7 @@ struct MemDetail {
int new_count{ 0 };
int del_count{ 0 };
};
thread_local pmr::unsynchronized_pool_resource MemPool;
thread_local MemDetail detail;
void* operator new(std::size_t size) {
std::size_t alignment = alignof(std::max_align_t);

View File

@ -5,5 +5,5 @@ static_component("core","engine")
add_includedirs("include", "include/3rdparty", {public = true})
add_headerfiles("include/**.h","include/**.inl")
add_files("src/**.cpp")
add_deps("zlib", {public = true})
add_deps("zlib")
add_packages("spdlog", {public = true})

View File

@ -48,18 +48,10 @@ inline void* operator new(size_t size, pmr::FrameAllocatorPool* pool, size_t ali
return pool->allocate(size, alignment);
}
#include "frame_allocator.inl"
#ifdef DLL_API_VALUE
//全局生命周期,不回收内存
extern DLL_API inline pmr::FrameAllocatorPool* GlobalPool;
ZLIB_API inline pmr::FrameAllocatorPool* GlobalPool;
//局部生命周期,每帧回收内存
extern DLL_API inline pmr::FrameAllocatorPool* FramePool;
DLL_API pmr::FrameAllocatorPool* GetGlobalPool();
DLL_API pmr::FrameAllocatorPool* GetFramePool();
#else
//全局生命周期,不回收内存
inline pmr::FrameAllocatorPool* GlobalPool;
//局部生命周期,每帧回收内存
inline pmr::FrameAllocatorPool* FramePool;
ZLIB_API inline pmr::FrameAllocatorPool* FramePool;
inline pmr::FrameAllocatorPool* GetGlobalPool() {
if (!GlobalPool) {
GlobalPool = new pmr::FrameAllocatorPool();
@ -71,5 +63,4 @@ inline pmr::FrameAllocatorPool* GetFramePool() {
FramePool = new(GetGlobalPool()) pmr::FrameAllocatorPool();
}
return FramePool;
}
#endif // DLL_API
}

View File

@ -1,7 +1,6 @@
#include "name.h"
namespace pmr {
using NameTable_t = table<size_t,const string>;
struct NameTable {
struct ZLIB_API NameTable {
static const string& Find(size_t id);
template<typename T>
static std::string_view MakePair(size_t id, T&& str);

View File

@ -1,6 +1,5 @@
#pragma once
#include "module/module.h"
#include "asset/asset.h"
class VULKAN_API VulkanModule : public api::IDynamicModule
{
public:

View File

@ -1,24 +1,22 @@
function header_component(name, owner, opt)
target(owner)
add_deps(name, { public = opt and opt.public or true })
add_deps(name)
target_end()
target(name)
set_kind("headeronly")
set_group("Engine/"..owner.."__comp")
add_rules("engine.api")
add_includedirs("include", {public = true})
end
function static_component(name, owner, opt)
target(owner)
add_deps(name)
add_defines("DLL_API_VALUE", {public = true})
add_includedirs("include", {public = true})
target_end()
target(name)
set_kind("static")
set_kind("moduleonly")
set_group("Engine/"..owner.."__comp")
add_rules("engine.api")
add_defines("DLL_API=")
add_includedirs("include")
add_includedirs("include", {public = true})
end
function shared_module(name, owner, opt)
target(name)

View File

@ -1,4 +1,6 @@
#include "api.h"
#include "pmr/frame_allocator.h"
#include "pmr/name.h"
class ENGINE_API EngineModule : public api::IDynamicModule
{
public:

View File

@ -1,7 +1,7 @@
target("editor")
set_kind("shared")
set_group("Engine")
add_rules("engine.api", {targets = {"dll", "editor"}})
add_rules("engine.api")
add_headerfiles("include/editor/*.h")
add_includedirs("include/editor")
add_files("src/editor/*.cpp")
@ -9,7 +9,7 @@ target("engine")
add_includedirs("include", {public = true})
set_kind("shared")
set_group("Engine")
add_rules("engine.api", {targets = {"dll", "engine"}})
add_rules("engine.api")
add_headerfiles("include/engine/*.h")
add_includedirs("include/engine")
add_files("src/engine/*.cpp")

View File

@ -0,0 +1,26 @@
import("core.project.project")
function add_define(target, name, is_static)
local api = string.upper(name) .. "_API"
if is_static then
target:add("defines", api .. "=", api .. "_VAL", {public = false})
else
target:add("defines", api.."=__declspec(dllimport)", {interface=true})
target:add("defines", api.."=__declspec(dllexport)", api .. "_VAL", {public=false})
end
end
function is_static_f(kind)
return kind == "static" or kind == "headeronly" or kind == "moduleonly"
end
function main(target)
local name = target:name()
local is_static = is_static_f(target:kind())
add_define(target, name, is_static)
local deps = target:get("deps")
if not deps then return end
for _,dep in ipairs(deps) do
local deptarget = project.target(dep)
if is_static_f(deptarget:kind()) then
add_define(target, dep, is_static)
end
end
end

View File

@ -0,0 +1,5 @@
rule("engine.api")
on_config(function (target)
import("rule_api")
rule_api(target)
end)

View File

@ -1,13 +1,7 @@
import("core.project.depend")
local loadTable = {}
function cmd_compile(target, genfile, file)
local name = target:name()
if loadTable[name] then
return
end
loadTable[name] = true
import("core.project.project")
target:data_set("compile", true)
local name = target:name()
local pub_deps = target:values("module.public_dependencies")
local cpp_content = "inline void __" .. name .. "__module::InitMetaData(void){\n"
cpp_content = cpp_content.."\tmInfo.name = \"" .. name.."\";\n"

View File

@ -1,6 +1,6 @@
rule("engine.plugin")
set_extensions(".h")
on_load(function (target)
on_config(function (target)
import("make_plugin")
local file = target:extraconf("rules", "engine.plugin", "file")
make_plugin(target, file or "module.h")

View File

@ -6,14 +6,4 @@ rule("engine.tool")
end
local exefile = target:targetfile()
os.cp(exefile, path.join(tooldir, path.filename(exefile)))
end)
rule("engine.api")
on_load(function (target)
local deps = target:extraconf("rules", "engine.api", "targets")
deps = deps or {target:name()}
for k,v in ipairs(deps) do
local api = string.upper(v) .. "_API"
target:add("defines", api.."=__declspec(dllimport)", {interface=true})
target:add("defines", api.."=__declspec(dllexport)", {public=false})
end
end)