chore(build): 搭建并验证 C# / C++(GDExtension) 原生构建环境(4.7.1 Mono)
为「GDScript→C#→C++」性能逃生梯备好可随时启用的工具链,运行时仍 100% GDScript。
C#:新增根 Rogue.csproj(Godot.NET.Sdk/4.7.1,net8.0,程序集名 Rogue);
csharp/ 下既有 3 个骨架 .cs 现可编译,dotnet build 与编辑器 --build-solutions 均 0 错通过。
C++:gdextension/ 下加 godot-cpp 子模块(master,因无 4.6/4.7 分支,配合本工程 dump 的
4.7.1 extension_api.json + gdextension_interface.h 经 custom_api_file 精确匹配 ABI);
SConstruct + 示例扩展 SpellforgeNative(含 PackedFloat32Array 零拷贝热路径写法);
SCons 自动探测 MSVC 构建出 debug .dll,headless 冒烟验证类注册/调用通过
(CLASS_EXISTS=true / multiply=42 / scale_inplace 正确)。
配套:.gitignore 忽略编译中间产物、保留 debug .dll 开箱即用;gdextension/README.md 记录构建/激活/升级流程;
CLAUDE.md 修正引擎版本 4.6→4.7.1 并更新「环境已就绪但休眠」现状。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// register_types.cpp — GDExtension 模块注册入口
|
||||
// 新增 C++ 类:在 initialize 里 GDREGISTER_CLASS(YourClass); 并包含其头文件。
|
||||
#include "register_types.h"
|
||||
|
||||
#include "spellforge_native.h"
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void initialize_spellforge_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
GDREGISTER_CLASS(SpellforgeNative);
|
||||
}
|
||||
|
||||
void uninitialize_spellforge_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
// 入口符号,须与 .gdextension 的 entry_symbol 一致。
|
||||
GDExtensionBool GDE_EXPORT spellforge_library_init(
|
||||
GDExtensionInterfaceGetProcAddress p_get_proc_address,
|
||||
GDExtensionClassLibraryPtr p_library,
|
||||
GDExtensionInitialization *r_initialization) {
|
||||
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
|
||||
|
||||
init_obj.register_initializer(initialize_spellforge_module);
|
||||
init_obj.register_terminator(uninitialize_spellforge_module);
|
||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||
|
||||
return init_obj.init();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// register_types.h — GDExtension 模块注册入口声明
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void initialize_spellforge_module(ModuleInitializationLevel p_level);
|
||||
void uninitialize_spellforge_module(ModuleInitializationLevel p_level);
|
||||
@@ -0,0 +1,34 @@
|
||||
// spellforge_native.cpp — 见头文件说明。
|
||||
#include "spellforge_native.h"
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void SpellforgeNative::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("multiply", "a", "b"), &SpellforgeNative::multiply);
|
||||
ClassDB::bind_method(D_METHOD("native_info"), &SpellforgeNative::native_info);
|
||||
ClassDB::bind_method(D_METHOD("scale_inplace", "data", "factor"), &SpellforgeNative::scale_inplace);
|
||||
}
|
||||
|
||||
SpellforgeNative::SpellforgeNative() {}
|
||||
SpellforgeNative::~SpellforgeNative() {}
|
||||
|
||||
double SpellforgeNative::multiply(double a, double b) const {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
String SpellforgeNative::native_info() const {
|
||||
return String("Spellforge C++ GDExtension OK — built against Godot 4.7.1 API");
|
||||
}
|
||||
|
||||
PackedFloat32Array SpellforgeNative::scale_inplace(PackedFloat32Array data, float factor) const {
|
||||
// 边界纪律(ADR-L1):热循环全程在 C++ 内完成,仅在边界批量进出 PackedArray。
|
||||
// ptrw() 拿到原生连续内存指针,内循环零 GodotObject 调用。
|
||||
const int n = data.size();
|
||||
float *w = data.ptrw();
|
||||
for (int i = 0; i < n; i++) {
|
||||
w[i] *= factor;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// spellforge_native.h — C++ GDExtension 冒烟示例类
|
||||
// 用途:证明 C++(GDExtension)环境可用。真实极限内核见 CLAUDE.md「编程语言规范」。
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/classes/ref_counted.hpp>
|
||||
#include <godot_cpp/variant/packed_float32_array.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class SpellforgeNative : public RefCounted {
|
||||
GDCLASS(SpellforgeNative, RefCounted)
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
SpellforgeNative();
|
||||
~SpellforgeNative();
|
||||
|
||||
// 冒烟:标量运算
|
||||
double multiply(double a, double b) const;
|
||||
// 冒烟:返回原生构建信息字符串
|
||||
String native_info() const;
|
||||
// 冒烟:原地就地缩放 PackedFloat32Array(演示零拷贝热路径写法:AsSpan 等价的 ptrw 直写)
|
||||
PackedFloat32Array scale_inplace(PackedFloat32Array data, float factor) const;
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
Reference in New Issue
Block a user