ProtoGraph(代码编程式Protoflux)
ProtoGraph
ProtoGraph 是一个社区制作的声明式编程语言,旨在与 ProtoFlux 在 Resonite 生态系统中协同工作。它允许创作者以简洁、可读的文本格式编写逻辑,并直接编译为 ProtoFlux 节点——从而更轻松地构建、测试和维护复杂系统。
概述 (Overview)
- 范式:数据流
- 家族:ML: Caml: OCaml: F#
- 设计者:Papaltine, Kittysquirrel
- 开发者:Papaltine, Kittysquirrel
- 稳定版本:1.5.0
- 许可证:AGPLv3
- 目标平台:Resonite(通过 ProtoFlux)
- 文件扩展名:
.pg - 编译器工具:
flux-sdk - 仓库:Flux SDK
- VSCode 扩展:ProtoGraph
- Nuget 工具:Papaltine.FluxSDK
- 编译后格式:
.brson(Resonite 记录) - 受以下语言影响:F#, Elm, Python, Haskell, VHDL, Odin, Go
- 公共文件夹:resrec:///U-1O4IcGhlKSm/R-131E69459864F98728F5423884957F2E677BFC75894306493CCADBDAF7E7F154
- 展示世界:https://go.resonite.com/world/U-1O4IcGhlKSm/R-2045c574-dda6-4a7e-9955-56d2ca002d78
- 文档
谁应该考虑 ProtoGraph?
- 希望超越可视化脚本的创作者
- 构建模块化、可重用系统的开发者
- 在大型项目上协作的团队
优势 (Benefits)
- 可读性强:简洁的语法,与 ProtoFlux 一一对应
- 模块化:使用模块(嵌套节点)实现可重用且易于重构的代码
- 版本控制:使用行业标准工具存储、比较、分享和版本控制源代码
- 可靠性高:编译器检查有助于及早捕获错误,甚至可以构建不完整的程序
- 易于上手:即使作为第一门编程语言,对熟悉 ProtoFlux 的人也很友好
- 兼容性好:底层仍是 ProtoFlux,能与 Resonite 的其他部分无缝协作,无需模组或插件
什么时候 ProtoGraph 不是好选择?
- 快速原型:对于小型测试和一次性示例,ProtoFlux 设置起来更快、更容易。
- 高性能要求:请等待 WASM 集成。ProtoGraph 的速度仅与 ProtoFlux 虚拟机相当。
- 纯可视化创作者:ProtoGraph 是 ProtoFlux 的文本版本,需要打字。
在 Resonite 中构建与使用 (Building and Using in Resonite)
- 编写您的
.pg文件。 - 编译它:
flux-sdk build MyModule.pg - 将
.brson文件导入 Resonite。 - 在对应槽位下检查生成的 ProtoFlux。
Flux UI
可以在 Resonite 中使用 Flux UI 来连接生成的 ProtoFlux 中的源和驱动。
示例 (Examples)
叉积模块 (Cross Product Module)
这是一个简单的纯模块,将输入数据转换为输出。
/// Multiplies two 3D vectors using a cross product module CrossProduct
/// The first vector
in A: float3
/// The second vector
in B: float3
/// The result of (A X B)
out this: float3
where {
// Inputs
Ax, Ay, Az = A->unpack;
Bx, By, Bz = B->unpack;
// Computations
Cx = (Ay * Bz) - (Az * By);
Cy = (Az * Bx) - (Ax * Bz);
Cz = (Ax * By) - (Ay * Bx);
// Final result
pack(Cx, Cy, Cz);
}
计数器对象 (Counter Object)
展示了如何编写一个维护内部状态并公开可调用方法的对象。
/// A simple object state machine that can count up and down module Counter
/// The current value of the counter
out this: int
/// Public method to count up
out Increment: Impulse
/// Public method to count down
out Decrement: Impulse
/// Public method that sets counter to 0
out Reset: Impulse
where {
// Variables are not shared with other nodes, they are private
sync CounterVar: int;
// out impulses are methods on the object that send it messages
// to do different actions
Reset = CounterVar <- 0;
Increment = CounterVar <- ValueInc(CounterVar);
Decrement = CounterVar <- ValueDec(CounterVar);
// We can also expose normal data. This is like a getter.
CounterVar;
}
弹跳球 (Bouncing Ball)
一个抛体运动的物理模拟,每次撞击地面时能量会损耗。
No comments to display
No comments to display