Godot 4 源码分析 - 获取属性信息

在管道通信基础上,可进行宿主程序与Godot的双向通信。

先拿属性信息试试手。

DrGraph端

cpp 复制代码
static UnicodeString command = "Book.position";
if (InputQuery("输入窗口", "请输入待获取的属性信息", command)) {
	TDrStream_Get drGet(THelper::String::GetStringAt(command, L".", 0).Trim(),
						THelper::String::GetStringAt(command, L".", 1).Trim());
	TDllStream ds;
	ds << drGet;
	PipeStreamServer->WritePipe(ds, 1000);
}

Godot端(源码完善)

cpp 复制代码
List<PropertyInfo> *p_list = new List<PropertyInfo>;
bool p_reversed = true;
destObject->get_property_list(p_list, p_reversed);
cofs << "OK";
for (List<PropertyInfo>::Iterator it = p_list->begin(); it != p_list->end(); ++it) {
	String content = it->name.ptr();
	if (it->class_name.operator String().is_empty() == false)
		content += str_format(U"[%s]", it->class_name.operator String().utf8().get_data());
	Variant value = destObject->get(it->name);
	content += str_format(U" = %s", value.operator String().utf8().get_data());
	cofs << content;
}
delete p_list;

运行结果

XML 复制代码
132. 13:20:29:829 > 【主线程】 > [Pipe.发送] > 发送数据中内容[DrGraph.28: Request - wait 1000 ms]: 
	[int]类型 > 值 = 2
	[UnicodeString]类型 > 值 = root
	[UnicodeString]类型 > 值 = propertyNames
133. 13:20:30:015 > 【主线程】 > [Pipe.Read] > 发送数据[DrGraph.28: Request - wait 1000 ms]成功返回 1837 字节... > PIPE响应中内容[godot -> DrGraph.28: Response - no return]: 
	[int]类型 > 值 = 3
	[UnicodeString]类型 > 值 = OK
	[UnicodeString]类型 > 值 = book.gd = <null>
	[UnicodeString]类型 > 值 = singlePage = false
	[UnicodeString]类型 > 值 = middleBarWidth = 0
	[UnicodeString]类型 > 值 = shader_rect[ColorRect] = ShaderRect:<ColorRect#26944209673>
	[UnicodeString]类型 > 值 = currentPageMode = false
	[UnicodeString]类型 > 值 = currentAreaType = -2
	[UnicodeString]类型 > 值 = triggleAreaMoment = 484887
	[UnicodeString]类型 > 值 = currentPageIndex = 30
	[UnicodeString]类型 > 值 = pageCount = 100
	[UnicodeString]类型 > 值 = pageImgPath = res://Pages/
	[UnicodeString]类型 > 值 = leftMouseDownMoment = 0
	[UnicodeString]类型 > 值 = underAutoTurnPage = false
	[UnicodeString]类型 > 值 = leftMouseDownPos = (0, 0)
	[UnicodeString]类型 > 值 = dllStream[DllStream] = <DllStream#67024979098>
	[UnicodeString]类型 > 值 = AutoTurnObject = <RefCounted#-9223372009692462322>
	[UnicodeString]类型 > 值 = Node2D = <null>
	[UnicodeString]类型 > 值 = Transform = <null>
	[UnicodeString]类型 > 值 = position = (0, 0)
	[UnicodeString]类型 > 值 = rotation = 0
	[UnicodeString]类型 > 值 = rotation_degrees = 0
	[UnicodeString]类型 > 值 = scale = (1, 1)
	[UnicodeString]类型 > 值 = skew = 0
	[UnicodeString]类型 > 值 = transform = [X: (1, 0), Y: (0, 1), O: (0, 0)]
	[UnicodeString]类型 > 值 = global_position = (0, 0)
	[UnicodeString]类型 > 值 = global_rotation = 0
	[UnicodeString]类型 > 值 = global_rotation_degrees = 0
	[UnicodeString]类型 > 值 = global_scale = (1, 1)
	[UnicodeString]类型 > 值 = global_skew = 0
	[UnicodeString]类型 > 值 = global_transform = [X: (1, 0), Y: (0, 1), O: (0, 0)]
	[UnicodeString]类型 > 值 = CanvasItem = <null>
	[UnicodeString]类型 > 值 = Visibility = <null>
	[UnicodeString]类型 > 值 = visible = true
	[UnicodeString]类型 > 值 = modulate = (1, 1, 1, 1)
	[UnicodeString]类型 > 值 = self_modulate = (1, 1, 1, 1)
	[UnicodeString]类型 > 值 = show_behind_parent = false
	[UnicodeString]类型 > 值 = top_level = false
	[UnicodeString]类型 > 值 = clip_children = 0
	[UnicodeString]类型 > 值 = light_mask = 1
	[UnicodeString]类型 > 值 = visibility_layer = 1
	[UnicodeString]类型 > 值 = Ordering = <null>
	[UnicodeString]类型 > 值 = z_index = 0
	[UnicodeString]类型 > 值 = z_as_relative = true
	[UnicodeString]类型 > 值 = y_sort_enabled = false
	[UnicodeString]类型 > 值 = Texture = <null>
	[UnicodeString]类型 > 值 = texture_filter = 0
	[UnicodeString]类型 > 值 = texture_repeat = 0
	[UnicodeString]类型 > 值 = Material = <null>
	[UnicodeString]类型 > 值 = material[CanvasItemMaterial,ShaderMaterial] = <Object#null>
	[UnicodeString]类型 > 值 = use_parent_material = false
	[UnicodeString]类型 > 值 = Node = <null>
	[UnicodeString]类型 > 值 = _import_path = 
	[UnicodeString]类型 > 值 = name = Book
	[UnicodeString]类型 > 值 = unique_name_in_owner = false
	[UnicodeString]类型 > 值 = scene_file_path = res://book.tscn
	[UnicodeString]类型 > 值 = owner[Node] = <Object#null>
	[UnicodeString]类型 > 值 = multiplayer[MultiplayerAPI] = <SceneMultiplayer#-9223372011168857310>
	[UnicodeString]类型 > 值 = Process = <null>
	[UnicodeString]类型 > 值 = process_mode = 0
	[UnicodeString]类型 > 值 = process_priority = 0
	[UnicodeString]类型 > 值 = Editor Description = <null>
	[UnicodeString]类型 > 值 = editor_description = 
	[UnicodeString]类型 > 值 = script[Script] = <GDScript#-9223372010984307965>

这已具备RTTI的雏形。

相关推荐
wowocpp15 分钟前
ubuntu 22.04 server 格式化 磁盘 为 ext4 并 自动挂载 LTS
服务器·数据库·ubuntu
九圣残炎15 分钟前
【从零开始的LeetCode-算法】1456. 定长子串中元音的最大数目
java·算法·leetcode
wclass-zhengge17 分钟前
Netty篇(入门编程)
java·linux·服务器
方方怪23 分钟前
与IP网络规划相关的知识点
服务器·网络·tcp/ip
Re.不晚1 小时前
Java入门15——抽象类
java·开发语言·学习·算法·intellij-idea
雷神乐乐1 小时前
Maven学习——创建Maven的Java和Web工程,并运行在Tomcat上
java·maven
码农派大星。1 小时前
Spring Boot 配置文件
java·spring boot·后端
顾北川_野1 小时前
Android 手机设备的OEM-unlock解锁 和 adb push文件
android·java
江深竹静,一苇以航1 小时前
springboot3项目整合Mybatis-plus启动项目报错:Invalid bean definition with name ‘xxxMapper‘
java·spring boot
weixin_442643421 小时前
推荐FileLink数据跨网摆渡系统 — 安全、高效的数据传输解决方案
服务器·网络·安全·filelink数据摆渡系统