Skip to content

Commit

Permalink
Update Wa binding. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Jan 1, 2025
1 parent 3c0aa4b commit f2b8d40
Show file tree
Hide file tree
Showing 61 changed files with 161 additions and 88 deletions.
5 changes: 3 additions & 2 deletions Tools/WasmGen/gen.yue
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ getWaType = (dataType, waName): t ->
convertTo: (name)-> "#{name}.GetRaw()"
argType: waName
returnType: waName and "#{waName}" or ""
creturn: (name, fnArgId)-> "#{name} := *#{waName}From(stack#{fnArgId}.PopObject().GetRaw())"
creturn: (name, fnArgId)-> "#{name}_obj := stack#{fnArgId}.PopObject()
ObjectRetain(#{name}_obj.GetRaw())
#{name} := *#{waName}From(#{name}_obj.GetRaw())"
cpass: (name, fnArgId)-> "stack#{fnArgId}.Push(#{name}.Object)"
}

Expand Down Expand Up @@ -1156,7 +1158,6 @@ func #{waNewName}From(raw: i64) => *#{waNewName} {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := #{waNewName}{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
4 changes: 2 additions & 2 deletions Tools/dora-wa/src/body.wa
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func test_body() {
body_d.SetAngularRate(90.0)
world.AddChild(body_d.Node)

windows_flags := dora.ImGuiWindowFlags(
window_flags := dora.ImGuiWindowFlags(
dora.ImGuiWindowNoSavedSettings,
dora.ImGuiWindowAlwaysAutoResize,
dora.ImGuiWindowNoFocusOnAppearing,
Expand All @@ -69,7 +69,7 @@ func test_body() {
dora.Vec2{X: 240.0, Y: 0.0},
dora.ImGuiCondFirstUseEver,
)
dora.ImGui.BeginOpts("Body", windows_flags, func() {
dora.ImGui.BeginOpts("Body", window_flags, func() {
dora.ImGui.Text("Body (Wa)")
dora.ImGui.Separator()
dora.ImGui.TextWrapped("Basic usage to create physics bodies!")
Expand Down
86 changes: 86 additions & 0 deletions Tools/dora-wa/src/contact.wa
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import "dora"
import "math"
import "strconv"

func test_contact() {
gravity := dora.Vec2{X: 0.0, Y: -10.0}
world := dora.NewPhysicsWorld()
world.SetShouldContact(0, 0, true)
world.SetShowDebug(true)

label := dora.NewLabel("sarasa-mono-sc-regular", 30, false)
label.AddTo(world.Node)

terrain_def := dora.NewBodyDef()
count := 50
radius: f32 = 300.0
vertices := []dora.Vec2{}
for i := 0; i <= count; i++ {
angle := 2.0 * math.Pi * f32(i) / f32(count)
vertices = append(vertices, dora.Vec2{X: radius * math.Cos(angle), Y: radius * math.Sin(angle)})
}
terrain_def.AttachChain(&vertices, 0.4, 0.0)
terrain_def.AttachDiskWithCenter(dora.Vec2{X: 0.0, Y: -270.0}, 30.0, 1.0, 0.0, 1.0)
terrain := dora.NewBody(terrain_def, world, dora.Vec2{X: 0.0, Y: 0.0}, 0.0)
terrain.AddTo(world.Node)

platform_def := dora.NewBodyDef()
platform_def.AttachPolygonWithCenter(dora.Vec2{X: 0.0, Y: -80.0}, 120.0, 30.0, 0.0, 1.0, 0.0, 1.0)
platform := dora.NewBody(platform_def, world, dora.Vec2{X: 0.0, Y: 0.0}, 0.0)
platform.OnContactFilter(func(other: dora.Body) => bool {
return other.GetVelocityY() < 0.0
})
platform.AddTo(world.Node)

draw_node := dora.NewLineWithVecColor(&[]dora.Vec2{
dora.Vec2{X: -20.0, Y: 0.0},
dora.Vec2{X: 20.0, Y: 0.0},
dora.Vec2Zero,
dora.Vec2{X: 0.0, Y: -20.0},
dora.Vec2{X: 0.0, Y: 20.0},
}, dora.App.GetThemeColor())
draw_node.AddTo(world.Node)

disk_def := dora.NewBodyDef()
disk_def.SetType(dora.BodyTypeDynamic)
disk_def.SetLinearAcceleration(gravity)
disk_def.AttachDisk(20.0, 5.0, 0.8, 1.0)
disk := dora.NewBody(disk_def, world, dora.Vec2{X: 100.0, Y: 200.0}, 0.0)
disk.AddTo(world.Node)
disk.SetAngularRate(-1800.0)
disk.OnContactStart(func(other: dora.Body, point: dora.Vec2, normal: dora.Vec2, enabled: bool) {
if enabled {
draw_node.SetPosition(point)
label.SetText("Contact: [" + strconv.FormatFloat(f64(point.X), 'f', 2, 32) + "," + strconv.FormatFloat(f64(point.Y), 'f', 2, 32) + "]")
}
})

window_flags := dora.ImGuiWindowFlags(
dora.ImGuiWindowNoDecoration,
dora.ImGuiWindowAlwaysAutoResize,
dora.ImGuiWindowNoSavedSettings,
dora.ImGuiWindowNoFocusOnAppearing,
dora.ImGuiWindowNoNav,
dora.ImGuiWindowNoMove,
)
imgui_node := dora.NewNode()
imgui_node.Schedule(func(delta_time: f64) => bool {
width := dora.App.GetVisualSize().Width
dora.ImGui.SetNextWindowBgAlpha(0.35)
dora.ImGui.SetNextWindowPosOpts(
dora.Vec2{X: width - 10.0, Y: 10.0},
dora.ImGuiCondAlways,
dora.Vec2{X: 1.0, Y: 0.0},
)
dora.ImGui.SetNextWindowSizeOpts(
dora.Vec2{X: 240.0, Y: 0.0},
dora.ImGuiCondFirstUseEver,
)
dora.ImGui.BeginOpts("Contact", window_flags, func() {
dora.ImGui.Text("Contact (Wa)")
dora.ImGui.Separator()
dora.ImGui.TextWrapped("Receive events when physics bodies contact.")
})
return false
})
}
7 changes: 4 additions & 3 deletions Tools/dora-wa/src/main.wa
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ func init {
all_clear()
test_body()
}
if dora.ImGui.Button("Contact", button_size) {
all_clear()
test_contact()
}
/*
if dora.ImGui.Button("Entity Move", button_size) {
all_clear()
}
if dora.ImGui.Button("SQLite", button_size) {
all_clear()
}
if dora.ImGui.Button("Contact", button_size) {
all_clear()
}
if dora.ImGui.Button("Sprite", button_size) {
all_clear()
}
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/action.wa
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func ActionFrom(raw: i64) => *Action {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Action{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/align_node.wa
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func AlignNodeFrom(raw: i64) => *AlignNode {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := AlignNode{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/array.wa
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func ArrayFrom(raw: i64) => *Array {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Array{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
5 changes: 3 additions & 2 deletions Tools/dora-wa/vendor/dora/body.wa
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func BodyFrom(raw: i64) => *Body {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Body{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down Expand Up @@ -261,7 +260,9 @@ func Body.AttachSensor(tag: i32, fixture_def: FixtureDef) => Sensor {
func Body.OnContactFilter(filter: func(body: Body) => bool) {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
body := *BodyFrom(stack0.PopObject().GetRaw())
body_obj := stack0.PopObject()
ObjectRetain(body_obj.GetRaw())
body := *BodyFrom(body_obj.GetRaw())
result_ := filter(body)
stack0.Push(result_)
})
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/body_def.wa
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func BodyDefFrom(raw: i64) => *BodyDef {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := BodyDef{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/buffer.wa
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func BufferFrom(raw: i64) => *Buffer {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Buffer{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/camera.wa
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func CameraFrom(raw: i64) => *Camera {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Camera{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/camera_2d.wa
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func Camera2DFrom(raw: i64) => *Camera2D {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Camera2D{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/camera_otho.wa
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func CameraOthoFrom(raw: i64) => *CameraOtho {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := CameraOtho{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/clip_node.wa
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func ClipNodeFrom(raw: i64) => *ClipNode {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := ClipNode{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/dictionary.wa
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func DictionaryFrom(raw: i64) => *Dictionary {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Dictionary{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
36 changes: 24 additions & 12 deletions Tools/dora-wa/vendor/dora/dora.wa
Original file line number Diff line number Diff line change
Expand Up @@ -321,45 +321,57 @@ func createObject(raw: i64) => Object {
}

func ObjectCastToNode(object: Object) => *Node {
if object_to_node(*object.raw) == 0 {
raw := object_to_node(*object.raw)
if raw == 0 {
return nil
}
return NodeFrom(object_to_node(*object.raw))
ObjectRetain(raw)
return NodeFrom(raw)
}

func ObjectCastToCamera(object: Object) => *Camera {
if object_to_camera(*object.raw) == 0 {
raw := object_to_camera(*object.raw)
if raw == 0 {
return nil
}
return CameraFrom(object_to_camera(*object.raw))
ObjectRetain(raw)
return CameraFrom(raw)
}

func ObjectCastToPlayable(object: Object) => *Playable {
if object_to_playable(*object.raw) == 0 {
raw := object_to_playable(*object.raw)
if raw == 0 {
return nil
}
return PlayableFrom(object_to_playable(*object.raw))
ObjectRetain(raw)
return PlayableFrom(raw)
}

func ObjectCastToBody(object: Object) => *Body {
if object_to_body(*object.raw) == 0 {
raw := object_to_body(*object.raw)
if raw == 0 {
return nil
}
return BodyFrom(object_to_body(*object.raw))
ObjectRetain(raw)
return BodyFrom(raw)
}

func ObjectCastToJoint(object: Object) => *Joint {
if object_to_joint(*object.raw) == 0 {
raw := object_to_joint(*object.raw)
if raw == 0 {
return nil
}
return JointFrom(object_to_joint(*object.raw))
ObjectRetain(raw)
return JointFrom(raw)
}

func ObjectCastToPhysicsWorld(object: Object) => *PhysicsWorld {
if object_to_physics_world(*object.raw) == 0 {
raw := object_to_physics_world(*object.raw)
if raw == 0 {
return nil
}
return PhysicsWorldFrom(object_to_physics_world(*object.raw))
ObjectRetain(raw)
return PhysicsWorldFrom(raw)
}

/* Value */
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/dragon_bone.wa
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func DragonBoneFrom(raw: i64) => *DragonBone {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := DragonBone{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/draw_node.wa
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func DrawNodeFrom(raw: i64) => *DrawNode {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := DrawNode{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/effect.wa
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func EffectFrom(raw: i64) => *Effect {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Effect{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/effek_node.wa
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func EffekNodeFrom(raw: i64) => *EffekNode {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := EffekNode{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/entity.wa
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func EntityFrom(raw: i64) => *Entity {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Entity{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/fixture_def.wa
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func FixtureDefFrom(raw: i64) => *FixtureDef {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := FixtureDef{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/grabber.wa
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func GrabberFrom(raw: i64) => *Grabber {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Grabber{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
1 change: 0 additions & 1 deletion Tools/dora-wa/vendor/dora/grid.wa
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func GridFrom(raw: i64) => *Grid {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Grid{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down
5 changes: 3 additions & 2 deletions Tools/dora-wa/vendor/dora/group.wa
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func GroupFrom(raw: i64) => *Group {
if raw == 0 {
return nil
}
ObjectRetain(raw)
object := Group{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
Expand Down Expand Up @@ -62,7 +61,9 @@ func Group.GetFirst() => *Entity {
func Group.Find(predicate: func(e: Entity) => bool) => *Entity {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
e := *EntityFrom(stack0.PopObject().GetRaw())
e_obj := stack0.PopObject()
ObjectRetain(e_obj.GetRaw())
e := *EntityFrom(e_obj.GetRaw())
result_ := predicate(e)
stack0.Push(result_)
})
Expand Down
Loading

0 comments on commit f2b8d40

Please sign in to comment.