Skip to content

[WIP] A rust/wasm component that parses Phigros level files and outputs structured drawing commands for web rendering

Notifications You must be signed in to change notification settings

phasetida/phasetida-wasm-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phasetida-wasm-core


一个简单的 Rust → WebAssembly 组件,将 Phigros 官方铺面文件渲染为紧凑的结构体。

安装

这里有两种安装方式:

1. 使用Github Action的构建分支

这个仓库具有Github Action的自动构建分支,运行

npm install phasetida/phasetida-wasm-core#dist

2. 手动编译

欸欸欸?这么信不过咱吗?

  1. 安装Cargo(如果已经安装了,请跳过这一步;如果没有的话,可以参考这个教程
  2. 安装wasm-pack:
    cargo install wasm-pack
  3. 克隆这个仓库
    git clone https://github.com/phasetida/phasetida-wasm-core
  4. 进入仓库目录,然后执行wasm构建:
    wasm-pack build --target web
  5. 最后,在package.json文件里引用仓库里的pkg目录就可以啦

使用

这个WASM组件会读取window.inputBufferwindow.inputBufferLengthwindow.outputBufferwindow.outputBufferLength,所以请准备好这些缓冲区和缓冲区长度。
以下为示例代码

import init, { pre_draw, load_level } from "phasetida_wasm_core.js";

const OUTPUT_BUFFER_LENGTH = 65536;
const outputBufferRaw = new ArrayBuffer(
  OUTPUT_BUFFER_LENGTH * Uint8Array.BYTES_PER_ELEMENT
);
const outputBuffer = new Uint8Array(outputBufferRaw);
const outputBufferLength = outputBuffer.length;
window.outputBuffer = outputBuffer;
window.outputBufferLength = outputBufferLength;

const INPUT_BUFFER_LENGTH = 1024;
const inputBufferRaw = new ArrayBuffer(
  INPUT_BUFFER_LENGTH * Uint8Array.BYTES_PER_ELEMENT
);
const inputBuffer = new Uint8Array(inputBufferRaw);
const inputBufferLength = inputBuffer.length;
window.inputBuffer = inputBuffer;
window.inputBufferLength = inputBufferLength;

await init();
//...

调用load_level时,WASM会接受参数的JSON字符串,并载入铺面文件。
调用pre_draw时,WASM会从window.inputBuffer读取输入数据,并将绘制结构化数据写入window.outputBuffer,具体结构化数据格式,请见src/renders.rs以及src/input.rs

注意

本仓库为实验性玩具项目,所以文档十分潦草。
由于Android WebView对共享缓冲区的限制,本仓库不使用共享缓冲区作为数据交换的方式!

About

[WIP] A rust/wasm component that parses Phigros level files and outputs structured drawing commands for web rendering

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages