Skip to content

Commit

Permalink
Updated Wa bindings with tests. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 31, 2024
1 parent d077f7b commit 64c4fbc
Show file tree
Hide file tree
Showing 90 changed files with 3,076 additions and 465 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,3 @@ Projects/Linux/3rdParty/
# Ignore rust files
Source/Rust/lib/*
Source/Rust/target/*

# Ignore files build by Wa
Tools/dora-wa/output
2 changes: 1 addition & 1 deletion Source/Rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Source/Wasm/Dora/DrawNodeWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ void drawnode_set_depth_write(int64_t self, int32_t val) {
int32_t drawnode_is_depth_write(int64_t self) {
return r_cast<DrawNode*>(self)->isDepthWrite() ? 1 : 0;
}
void drawnode__set_blend_func(int64_t self, int64_t blend_func) {
r_cast<DrawNode*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(blend_func)));
void drawnode_set_blend_func(int64_t self, int64_t val) {
r_cast<DrawNode*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(val)));
}
int64_t drawnode__get_blend_func(int64_t self) {
int64_t drawnode_get_blend_func(int64_t self) {
return s_cast<int64_t>(r_cast<DrawNode*>(self)->getBlendFunc().toValue());
}
void drawnode_draw_dot(int64_t self, int64_t pos, float radius, int32_t color) {
Expand All @@ -47,8 +47,8 @@ static void linkDrawNode(wasm3::module3& mod) {
mod.link_optional("*", "drawnode_type", drawnode_type);
mod.link_optional("*", "drawnode_set_depth_write", drawnode_set_depth_write);
mod.link_optional("*", "drawnode_is_depth_write", drawnode_is_depth_write);
mod.link_optional("*", "drawnode__set_blend_func", drawnode__set_blend_func);
mod.link_optional("*", "drawnode__get_blend_func", drawnode__get_blend_func);
mod.link_optional("*", "drawnode_set_blend_func", drawnode_set_blend_func);
mod.link_optional("*", "drawnode_get_blend_func", drawnode_get_blend_func);
mod.link_optional("*", "drawnode_draw_dot", drawnode_draw_dot);
mod.link_optional("*", "drawnode_draw_segment", drawnode_draw_segment);
mod.link_optional("*", "drawnode_draw_polygon", drawnode_draw_polygon);
Expand Down
10 changes: 5 additions & 5 deletions Source/Wasm/Dora/GrabberWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ void grabber_set_effect(int64_t self, int64_t val) {
int64_t grabber_get_effect(int64_t self) {
return Object_From(r_cast<Grabber*>(self)->getEffect());
}
void grabber__set_blend_func(int64_t self, int64_t blend_func) {
r_cast<Grabber*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(blend_func)));
void grabber_set_blend_func(int64_t self, int64_t val) {
r_cast<Grabber*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(val)));
}
int64_t grabber__get_blend_func(int64_t self) {
int64_t grabber_get_blend_func(int64_t self) {
return s_cast<int64_t>(r_cast<Grabber*>(self)->getBlendFunc().toValue());
}
void grabber_set_clear_color(int64_t self, int32_t val) {
Expand Down Expand Up @@ -58,8 +58,8 @@ static void linkGrabber(wasm3::module3& mod) {
mod.link_optional("*", "grabber_get_camera", grabber_get_camera);
mod.link_optional("*", "grabber_set_effect", grabber_set_effect);
mod.link_optional("*", "grabber_get_effect", grabber_get_effect);
mod.link_optional("*", "grabber__set_blend_func", grabber__set_blend_func);
mod.link_optional("*", "grabber__get_blend_func", grabber__get_blend_func);
mod.link_optional("*", "grabber_set_blend_func", grabber_set_blend_func);
mod.link_optional("*", "grabber_get_blend_func", grabber_get_blend_func);
mod.link_optional("*", "grabber_set_clear_color", grabber_set_clear_color);
mod.link_optional("*", "grabber_get_clear_color", grabber_get_clear_color);
mod.link_optional("*", "grabber_set_pos", grabber_set_pos);
Expand Down
10 changes: 5 additions & 5 deletions Source/Wasm/Dora/GridWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ void grid_set_depth_write(int64_t self, int32_t val) {
int32_t grid_is_depth_write(int64_t self) {
return r_cast<Grid*>(self)->isDepthWrite() ? 1 : 0;
}
void grid__set_blend_func(int64_t self, int64_t blend_func) {
r_cast<Grid*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(blend_func)));
void grid_set_blend_func(int64_t self, int64_t val) {
r_cast<Grid*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(val)));
}
int64_t grid__get_blend_func(int64_t self) {
int64_t grid_get_blend_func(int64_t self) {
return s_cast<int64_t>(r_cast<Grid*>(self)->getBlendFunc().toValue());
}
void grid_set_effect(int64_t self, int64_t val) {
Expand Down Expand Up @@ -82,8 +82,8 @@ static void linkGrid(wasm3::module3& mod) {
mod.link_optional("*", "grid_get_grid_y", grid_get_grid_y);
mod.link_optional("*", "grid_set_depth_write", grid_set_depth_write);
mod.link_optional("*", "grid_is_depth_write", grid_is_depth_write);
mod.link_optional("*", "grid__set_blend_func", grid__set_blend_func);
mod.link_optional("*", "grid__get_blend_func", grid__get_blend_func);
mod.link_optional("*", "grid_set_blend_func", grid_set_blend_func);
mod.link_optional("*", "grid_get_blend_func", grid_get_blend_func);
mod.link_optional("*", "grid_set_effect", grid_set_effect);
mod.link_optional("*", "grid_get_effect", grid_get_effect);
mod.link_optional("*", "grid_set_texture_rect", grid_set_texture_rect);
Expand Down
10 changes: 5 additions & 5 deletions Source/Wasm/Dora/LabelWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ void label_set_text(int64_t self, int64_t val) {
int64_t label_get_text(int64_t self) {
return Str_Retain(r_cast<Label*>(self)->getText());
}
void label__set_blend_func(int64_t self, int64_t blend_func) {
r_cast<Label*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(blend_func)));
void label_set_blend_func(int64_t self, int64_t val) {
r_cast<Label*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(val)));
}
int64_t label__get_blend_func(int64_t self) {
int64_t label_get_blend_func(int64_t self) {
return s_cast<int64_t>(r_cast<Label*>(self)->getBlendFunc().toValue());
}
void label_set_depth_write(int64_t self, int32_t val) {
Expand Down Expand Up @@ -126,8 +126,8 @@ static void linkLabel(wasm3::module3& mod) {
mod.link_optional("*", "label_get_smooth", label_get_smooth);
mod.link_optional("*", "label_set_text", label_set_text);
mod.link_optional("*", "label_get_text", label_get_text);
mod.link_optional("*", "label__set_blend_func", label__set_blend_func);
mod.link_optional("*", "label__get_blend_func", label__get_blend_func);
mod.link_optional("*", "label_set_blend_func", label_set_blend_func);
mod.link_optional("*", "label_get_blend_func", label_get_blend_func);
mod.link_optional("*", "label_set_depth_write", label_set_depth_write);
mod.link_optional("*", "label_is_depth_write", label_is_depth_write);
mod.link_optional("*", "label_set_batched", label_set_batched);
Expand Down
10 changes: 5 additions & 5 deletions Source/Wasm/Dora/LineWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ void line_set_depth_write(int64_t self, int32_t val) {
int32_t line_is_depth_write(int64_t self) {
return r_cast<Line*>(self)->isDepthWrite() ? 1 : 0;
}
void line__set_blend_func(int64_t self, int64_t blend_func) {
r_cast<Line*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(blend_func)));
void line_set_blend_func(int64_t self, int64_t val) {
r_cast<Line*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(val)));
}
int64_t line__get_blend_func(int64_t self) {
int64_t line_get_blend_func(int64_t self) {
return s_cast<int64_t>(r_cast<Line*>(self)->getBlendFunc().toValue());
}
void line_add(int64_t self, int64_t verts, int32_t color) {
Expand All @@ -44,8 +44,8 @@ static void linkLine(wasm3::module3& mod) {
mod.link_optional("*", "line_type", line_type);
mod.link_optional("*", "line_set_depth_write", line_set_depth_write);
mod.link_optional("*", "line_is_depth_write", line_is_depth_write);
mod.link_optional("*", "line__set_blend_func", line__set_blend_func);
mod.link_optional("*", "line__get_blend_func", line__get_blend_func);
mod.link_optional("*", "line_set_blend_func", line_set_blend_func);
mod.link_optional("*", "line_get_blend_func", line_get_blend_func);
mod.link_optional("*", "line_add", line_add);
mod.link_optional("*", "line_set", line_set);
mod.link_optional("*", "line_clear", line_clear);
Expand Down
10 changes: 5 additions & 5 deletions Source/Wasm/Dora/SpriteWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ int64_t sprite_get_texture_rect(int64_t self) {
int64_t sprite_get_texture(int64_t self) {
return Object_From(r_cast<Sprite*>(self)->getTexture());
}
void sprite__set_blend_func(int64_t self, int64_t blend_func) {
r_cast<Sprite*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(blend_func)));
void sprite_set_blend_func(int64_t self, int64_t val) {
r_cast<Sprite*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(val)));
}
int64_t sprite__get_blend_func(int64_t self) {
int64_t sprite_get_blend_func(int64_t self) {
return s_cast<int64_t>(r_cast<Sprite*>(self)->getBlendFunc().toValue());
}
void sprite_set_effect(int64_t self, int64_t val) {
Expand Down Expand Up @@ -88,8 +88,8 @@ static void linkSprite(wasm3::module3& mod) {
mod.link_optional("*", "sprite_set_texture_rect", sprite_set_texture_rect);
mod.link_optional("*", "sprite_get_texture_rect", sprite_get_texture_rect);
mod.link_optional("*", "sprite_get_texture", sprite_get_texture);
mod.link_optional("*", "sprite__set_blend_func", sprite__set_blend_func);
mod.link_optional("*", "sprite__get_blend_func", sprite__get_blend_func);
mod.link_optional("*", "sprite_set_blend_func", sprite_set_blend_func);
mod.link_optional("*", "sprite_get_blend_func", sprite_get_blend_func);
mod.link_optional("*", "sprite_set_effect", sprite_set_effect);
mod.link_optional("*", "sprite_get_effect", sprite_get_effect);
mod.link_optional("*", "sprite_set_uwrap", sprite_set_uwrap);
Expand Down
10 changes: 5 additions & 5 deletions Source/Wasm/Dora/TileNodeWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ void tilenode_set_depth_write(int64_t self, int32_t val) {
int32_t tilenode_is_depth_write(int64_t self) {
return r_cast<TileNode*>(self)->isDepthWrite() ? 1 : 0;
}
void tilenode__set_blend_func(int64_t self, int64_t blend_func) {
r_cast<TileNode*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(blend_func)));
void tilenode_set_blend_func(int64_t self, int64_t val) {
r_cast<TileNode*>(self)->setBlendFunc(BlendFunc(s_cast<uint64_t>(val)));
}
int64_t tilenode__get_blend_func(int64_t self) {
int64_t tilenode_get_blend_func(int64_t self) {
return s_cast<int64_t>(r_cast<TileNode*>(self)->getBlendFunc().toValue());
}
void tilenode_set_effect(int64_t self, int64_t val) {
Expand Down Expand Up @@ -53,8 +53,8 @@ static void linkTileNode(wasm3::module3& mod) {
mod.link_optional("*", "tilenode_type", tilenode_type);
mod.link_optional("*", "tilenode_set_depth_write", tilenode_set_depth_write);
mod.link_optional("*", "tilenode_is_depth_write", tilenode_is_depth_write);
mod.link_optional("*", "tilenode__set_blend_func", tilenode__set_blend_func);
mod.link_optional("*", "tilenode__get_blend_func", tilenode__get_blend_func);
mod.link_optional("*", "tilenode_set_blend_func", tilenode_set_blend_func);
mod.link_optional("*", "tilenode_get_blend_func", tilenode_get_blend_func);
mod.link_optional("*", "tilenode_set_effect", tilenode_set_effect);
mod.link_optional("*", "tilenode_get_effect", tilenode_get_effect);
mod.link_optional("*", "tilenode_set_filter", tilenode_set_filter);
Expand Down
15 changes: 1 addition & 14 deletions Source/Wasm/WasmRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NS_DORA_BEGIN

#define DoraVersion(major, minor, patch) ((major) << 16 | (minor) << 8 | (patch))

static const int doraWASMVersion = DoraVersion(0, 4, 17);
static const int doraWASMVersion = DoraVersion(0, 4, 18);

static std::string VersionToStr(int version) {
return std::to_string((version & 0x00ff0000) >> 16) + '.' + std::to_string((version & 0x0000ff00) >> 8) + '.' + std::to_string(version & 0x000000ff);
Expand Down Expand Up @@ -1400,18 +1400,6 @@ void group_watch(int64_t group, int32_t func, int64_t stack) {
return std::get<bool>(args->pop());
});
}
int64_t group_find(int64_t group, int32_t func, int64_t stack) {
std::shared_ptr<void> deref(nullptr, [func](auto) {
SharedWasmRuntime.deref(func);
});
auto args = r_cast<CallStack*>(stack);
return Object_From(r_cast<EntityGroup*>(group)->find([func, args, deref](Entity* e) {
args->clear();
args->push(e);
SharedWasmRuntime.invoke(func);
return std::get<bool>(args->pop());
}));
}

// EntityObserver

Expand Down Expand Up @@ -1765,7 +1753,6 @@ static void linkDoraModule(wasm3::module3& mod) {
mod.link_optional("*", "entity_get_old", entity_get_old);

mod.link_optional("*", "group_watch", group_watch);
mod.link_optional("*", "group_find", group_find);

mod.link_optional("*", "observer_watch", observer_watch);

Expand Down
28 changes: 14 additions & 14 deletions Tools/WasmGen/Dora.h
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,8 @@ object class Grabber
optional common Camera* camera;
/// the sprite effect applied to the texture.
optional common SpriteEffect* effect;
void setBlendFunc @ _setBlendFunc(BlendFunc blendFunc);
BlendFunc getBlendFunc @ _getBlendFunc() const;
/// the blend function for the grabber.
common BlendFunc blendFunc;
/// the clear color used to clear the texture.
common Color clearColor;
/// Sets the position of a vertex in the grabber grid.
Expand Down Expand Up @@ -1586,8 +1586,8 @@ object class Sprite : public INode
common Rect textureRect;
/// the texture for the sprite.
optional readonly common Texture2D* texture;
void setBlendFunc @ _setBlendFunc(BlendFunc blendFunc);
BlendFunc getBlendFunc @ _getBlendFunc() const;
/// the blend function for the sprite.
common BlendFunc blendFunc;
/// the sprite shader effect.
common SpriteEffect* effect;
/// the texture wrapping mode for the U (horizontal) axis.
Expand Down Expand Up @@ -1646,8 +1646,8 @@ object class Grid : public INode
readonly common uint32_t gridY;
/// whether depth writes are enabled.
boolean bool depthWrite;
void setBlendFunc @ _setBlendFunc(BlendFunc blendFunc);
BlendFunc getBlendFunc @ _getBlendFunc() const;
/// the blend function for the grid.
common BlendFunc blendFunc;
/// the sprite effect applied to the grid.
/// Default is `SpriteEffect::new("builtin:vs_sprite", "builtin:fs_sprite")`.
common SpriteEffect* effect;
Expand Down Expand Up @@ -1811,8 +1811,8 @@ object class Label : public INode
common Vec2 smooth;
/// the text to be rendered.
common string text;
void setBlendFunc @ _setBlendFunc(BlendFunc blendFunc);
BlendFunc getBlendFunc @ _getBlendFunc() const;
/// the blend function for the label.
common BlendFunc blendFunc;
/// whether depth writing is enabled. (Default is false)
boolean bool depthWrite;
/// whether the label is using batched rendering.
Expand Down Expand Up @@ -1935,8 +1935,8 @@ object class DrawNode : public INode
{
/// whether to write to the depth buffer when drawing (default is false).
boolean bool depthWrite;
void setBlendFunc @ _setBlendFunc(BlendFunc blendFunc);
BlendFunc getBlendFunc @ _getBlendFunc() const;
/// the blend function for the draw node.
common BlendFunc blendFunc;
/// Draws a dot at a specified position with a specified radius and color.
///
/// # Arguments
Expand Down Expand Up @@ -1984,8 +1984,8 @@ object class Line : public INode
{
/// whether the depth should be written. (Default is false)
boolean bool depthWrite;
void setBlendFunc @ _setBlendFunc(BlendFunc blendFunc);
BlendFunc getBlendFunc @ _getBlendFunc() const;
/// the blend function for the line node.
common BlendFunc blendFunc;
/// Adds vertices to the line.
///
/// # Arguments
Expand Down Expand Up @@ -2454,8 +2454,8 @@ object class TileNode : public INode
{
/// whether the depth buffer should be written to when rendering the tilemap.
boolean bool depthWrite;
void setBlendFunc @ _setBlendFunc(BlendFunc blendFunc);
BlendFunc getBlendFunc @ _getBlendFunc() const;
/// the blend function for the tilemap.
common BlendFunc blendFunc;
/// the tilemap shader effect.
common SpriteEffect* effect;
/// the texture filtering mode for the tilemap.
Expand Down
18 changes: 13 additions & 5 deletions Tools/WasmGen/gen.yue
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,10 @@ basicTypes =
* "i64"
* (name)-> "BlendFunc(s_cast<uint64_t>(#{name}))"
* (name)-> "s_cast<int64_t>(#{name}.toValue())"
* "u64"
* "u64"
* (name)-> "#{name} as i64"
* (name)-> "#{name} as u64"
* "crate::dora::BlendFunc"
* "crate::dora::BlendFunc"
* (name)-> "#{name}.to_value()"
* (name)-> "crate::dora::BlendFunc::from(#{name})"
* -> error "unsupported"
* -> error "unsupported"
* --[[10: wa type]] {
Expand Down Expand Up @@ -908,7 +908,8 @@ basicTypes =
toSnakeCase = (name)-> table.concat [sub\lower! for sub in (name\sub(1, 1)\lower! .. name\sub(2))\gsub("%d", "_%1")\gsub("%u", "_%1")\gsub("(%d)_", "%1")\gmatch "[^_]*"], "_"

snakeToPascal = (snakeStr)->
snakeStr
prefix = if "_" == snakeStr\sub 1,1 then "_" else ""
prefix .. snakeStr
\gsub "_(%a)", (letter) -> letter\upper!
\gsub "^%l", (first) -> first\upper!

Expand Down Expand Up @@ -1155,6 +1156,7 @@ func #{waNewName}From(raw: i64) => *#{waNewName} {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := #{waNewName}{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand All @@ -1163,6 +1165,12 @@ func #{waNewName}From(raw: i64) => *#{waNewName} {
}
func #{waNewName}.GetTypeId() => i32 {
return #{namespace}#{clsNewNameL}_type()
}
func ObjectAs#{waNewName}(object: Object) => *#{waNewName} {
if object.GetTypeId() == #{namespace}#{clsNewNameL}_type() {
return #{waNewName}From(object.GetRaw())
}
return nil
}"
else
if isStatic or isSingleton
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-rust/dora-test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tools/dora-rust/dora-test/src/tests/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn test() {
ImGui::begin_opts("Hello World", windows_flags, || {
ImGui::text("Hello World (Rust)");
ImGui::separator();
ImGui::text_wrapped("Basic Dora schedule and signal function usage. Written in Yuescript. View outputs in log window!");
ImGui::text_wrapped("Basic Dora schedule and signal function usage. View outputs in log window!");
});
false
}));
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-rust/dora/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tools/dora-rust/dora/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dora-ssr"
version = "0.4.17"
version = "0.4.18"
authors = ["Li Jin <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
Loading

0 comments on commit 64c4fbc

Please sign in to comment.