Skip to content

Commit

Permalink
Added more WA bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 29, 2024
1 parent 3b05b28 commit 76f0e03
Show file tree
Hide file tree
Showing 28 changed files with 615 additions and 95 deletions.
10 changes: 5 additions & 5 deletions Source/Wasm/Dora/BodyDefWasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ using namespace Dora;
int32_t bodydef_type() {
return DoraType<BodyDef>();
}
void bodydef__set_type(int64_t self, int32_t val) {
BodyDef_SetTypeEnum(r_cast<BodyDef*>(self), s_cast<int>(val));
void bodydef_set_type(int64_t self, int32_t body_type) {
BodyDef_SetTypeEnum(r_cast<BodyDef*>(self), body_type);
}
int32_t bodydef__get_type(int64_t self) {
int32_t bodydef_get_type(int64_t self) {
return BodyDef_GetTypeEnum(r_cast<BodyDef*>(self));
}
void bodydef_set_position(int64_t self, int64_t val) {
Expand Down Expand Up @@ -135,8 +135,8 @@ int64_t bodydef_new() {

static void linkBodyDef(wasm3::module3& mod) {
mod.link_optional("*", "bodydef_type", bodydef_type);
mod.link_optional("*", "bodydef__set_type", bodydef__set_type);
mod.link_optional("*", "bodydef__get_type", bodydef__get_type);
mod.link_optional("*", "bodydef_set_type", bodydef_set_type);
mod.link_optional("*", "bodydef_get_type", bodydef_get_type);
mod.link_optional("*", "bodydef_set_position", bodydef_set_position);
mod.link_optional("*", "bodydef_get_position", bodydef_get_position);
mod.link_optional("*", "bodydef_set_angle", bodydef_set_angle);
Expand Down
14 changes: 12 additions & 2 deletions Tools/RustWasmGen/Dora.h → Tools/WasmGen/Dora.h
Original file line number Diff line number Diff line change
Expand Up @@ -2576,8 +2576,18 @@ object class FixtureDef { };
/// A struct to describe the properties of a physics body.
object class BodyDef
{
outside void BodyDef_SetTypeEnum @ _set_type(int val);
outside int32_t BodyDef_GetTypeEnum @ _get_type() const;
/// Sets the define for the type of the body.
///
/// # Arguments
///
/// * `body_type` - The type of the body.
outside void BodyDef_SetTypeEnum @ set_type(BodyType body_type);
/// Gets the define for the type of the body.
///
/// # Returns
///
/// * `BodyType` - The type of the body.
outside BodyType BodyDef_GetTypeEnum @ get_type() const;
/// define for the position of the body.
Vec2 offset @ position;
/// define for the angle of the body.
Expand Down
File renamed without changes.
55 changes: 52 additions & 3 deletions Tools/RustWasmGen/gen.yue → Tools/WasmGen/gen.yue
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ basicTypes =
* --[[10: wa type]] {
convertFrom: (name)-> name
convertTo: (name)-> name
argType: "DBRecord"
returnType: "DBRecord"
creturn: (name, fnArgId)-> "#{name}, _ := DBRecordFrom(stack#{fnArgId}.PopI64())"
cpass: -> error "unsupported"
}
DBQuery:
* "i64"
Expand All @@ -425,6 +429,10 @@ basicTypes =
* --[[10: wa type]] {
convertFrom: (name)-> name
convertTo: (name)-> name
argType: "DBQuery"
returnType: "DBQuery"
creturn: -> error "unsupported"
cpass: -> error "unsupported"
}
WorkBook:
* "i64"
Expand Down Expand Up @@ -657,6 +665,10 @@ basicTypes =
* --[[10: wa type]] {
convertFrom: (name)-> name
convertTo: (name)-> name
argType: "i64"
returnType: "i64"
creturn: (name, fnArgId)-> "#{name}, _ := stack#{fnArgId}.PopI64()"
cpass: -> error "unsupported"
}
MLQAction:
* "i32"
Expand All @@ -671,6 +683,10 @@ basicTypes =
* --[[10: wa type]] {
convertFrom: (name)-> name
convertTo: (name)-> name
argType: "i32"
returnType: "i32"
creturn: (name, fnArgId)-> "#{name}, _ := stack#{fnArgId}.PopI32()"
cpass: -> error "unsupported"
}
"Platformer::TargetAllow":
* "i64"
Expand Down Expand Up @@ -782,6 +798,22 @@ basicTypes =
convertFrom: (name)-> name
convertTo: (name)-> name
}
BodyType:
* "i32"
* (name)-> name
* (name)-> name
* "crate::dora::BodyType"
* "crate::dora::BodyType"
* (name)-> "#{name} as i32"
* (name)-> "core::mem::transmute(#{name})"
* -> error "unsupported"
* -> error "unsupported"
* --[[10: wa type]] {
convertFrom: (name)-> "BodyType{value: #{name}}"
convertTo: (name)-> "#{name}.ToValue()"
argType: "BodyType"
returnType: "BodyType"
}
"Platformer::Relation":
* "i32"
* (name)-> "s_cast<Platformer::Relation>(#{name})"
Expand All @@ -807,8 +839,12 @@ basicTypes =
* (fnArgId)-> "&crate::dora::platformer::behavior::Blackboard::from(stack#{fnArgId}.pop_i64().unwrap()).unwrap()"
* -> error "unsupported"
* --[[10: wa type]] {
convertFrom: (name)-> name
convertTo: (name)-> name
convertFrom: (name)-> "*BlackboardFrom(#{name})"
convertTo: (name)-> "#{name}.GetRaw()"
argType: "Blackboard"
returnType: "Blackboard"
creturn: (name, fnArgId)-> "#{name}, _ := stack#{fnArgId}.PopI64()"
cpass: -> error "unsupported"
}
"Platformer::UnitAction":
* "i64"
Expand Down Expand Up @@ -1077,7 +1113,7 @@ func #{clsNewName}From(raw: i64) => *#{clsNewName} {
result := &object
return result
}
func #{clsNewName}.GetType() => i32 {
func #{clsNewName}.GetTypeId() => i32 {
return #{namespace}#{clsNewNameL}_type()
}"
else
Expand Down Expand Up @@ -1228,6 +1264,8 @@ func #{clsNewName}From(raw: i64) => *#{clsNewName} {
waType = getWaType dataType, rustName
waBinding[] = if isSingleton
"func _#{clsNewName}.#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(#{waType.convertTo 'val'})\n}"
elseif isStatic
"func #{clsNewName}#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(#{waType.convertTo 'val'})\n}"
else
"func #{clsNewName}.#{waSetterName}(val: #{waType.argType}) {\n\t#{cppSetterName}(*this.raw, #{waType.convertTo 'val'})\n}"
docText = if #docs > 0
Expand Down Expand Up @@ -1290,6 +1328,9 @@ func #{clsNewName}From(raw: i64) => *#{clsNewName} {
waBinding[] = if isSingleton
item = "#{cppGetterName}()"
"func _#{clsNewName}.#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
elseif isStatic
item = "#{cppGetterName}()"
"func #{clsNewName}#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
else
item = "#{cppGetterName}(*this.raw)"
"func #{clsNewName}.#{waGetterName}() => #{waReturnType} {\n#{waReturn item}\n}"
Expand Down Expand Up @@ -1728,6 +1769,14 @@ func #{clsNewName}From(raw: i64) => *#{clsNewName} {
"content"
"work_book"
"work_sheet"
"body_def"
"body"
"physics_world"
"sensor"
"fixture_def"
"buffer"
"c_45"
"cache"
]
\write "\n"
\write table.concat waBinding, "\n"
Expand Down
File renamed without changes.
25 changes: 1 addition & 24 deletions Tools/dora-rust/dora/src/dora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3280,37 +3280,14 @@ pub enum TextAlign {

// BodyDef

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum BodyType {
Dynamic = 0,
Static = 1,
Kinematic = 2,
}

impl BodyDef {
/// Sets the define for the type of the body.
///
/// # Arguments
///
/// * `body_type` - The type of the body.
pub fn set_type(&mut self, body_type: BodyType) {
self._set_type(body_type as i32);
}
/// Gets the define for the type of the body.
///
/// # Returns
///
/// * `BodyType` - The type of the body.
pub fn get_type(&self) -> BodyType {
match self._get_type() {
0 => BodyType::Dynamic,
1 => BodyType::Static,
2 => BodyType::Kinematic,
_ => panic!("Invalid body type.")
}
}
}

// Keyboard

#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down
22 changes: 16 additions & 6 deletions Tools/dora-rust/dora/src/dora/body_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

extern "C" {
fn bodydef_type() -> i32;
fn bodydef__set_type(slf: i64, val: i32);
fn bodydef__get_type(slf: i64) -> i32;
fn bodydef_set_type(slf: i64, body_type: i32);
fn bodydef_get_type(slf: i64) -> i32;
fn bodydef_set_position(slf: i64, val: i64);
fn bodydef_get_position(slf: i64) -> i64;
fn bodydef_set_angle(slf: i64, val: f32);
Expand Down Expand Up @@ -62,11 +62,21 @@ impl BodyDef {
}
})
}
pub(crate) fn _set_type(&mut self, val: i32) {
unsafe { bodydef__set_type(self.raw(), val); }
/// Sets the define for the type of the body.
///
/// # Arguments
///
/// * `body_type` - The type of the body.
pub fn set_type(&mut self, body_type: crate::dora::BodyType) {
unsafe { bodydef_set_type(self.raw(), body_type as i32); }
}
pub(crate) fn _get_type(&self) -> i32 {
unsafe { return bodydef__get_type(self.raw()); }
/// Gets the define for the type of the body.
///
/// # Returns
///
/// * `BodyType` - The type of the body.
pub fn get_type(&self) -> crate::dora::BodyType {
unsafe { return core::mem::transmute(bodydef_get_type(self.raw())); }
}
/// Sets define for the position of the body.
pub fn set_position(&mut self, val: &crate::dora::Vec2) {
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-wa/vendor/dora/action.wa
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ActionFrom(raw: i64) => *Action {
result := &object
return result
}
func Action.GetType() => i32 {
func Action.GetTypeId() => i32 {
return action_type()
}
func Action.GetDuration() => f32 {
Expand Down
2 changes: 1 addition & 1 deletion Tools/dora-wa/vendor/dora/array.wa
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ArrayFrom(raw: i64) => *Array {
result := &object
return result
}
func Array.GetType() => i32 {
func Array.GetTypeId() => i32 {
return array_type()
}
func Array.GetCount() => i64 {
Expand Down
119 changes: 118 additions & 1 deletion Tools/dora-wa/vendor/dora/body.wa
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,121 @@ func body_attach_sensor(slf: i64, tag: i32, fixture_def: i64) => i64
#wa:import dora body_on_contact_filter
func body_on_contact_filter(slf: i64, func0: i32, stack0: i64)
#wa:import dora body_new
func body_new(def: i64, world: i64, pos: i64, rot: f32) => i64
func body_new(def: i64, world: i64, pos: i64, rot: f32) => i64
type Body struct { Node }
func BodyFrom(raw: i64) => *Body {
if raw == 0 {
return nil
}
object := Body{}
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
result := &object
return result
}
func Body.GetTypeId() => i32 {
return body_type()
}
func Body.GetWorld() => PhysicsWorld {
return *PhysicsWorldFrom(body_get_world(*this.raw))
}
func Body.GetBodyDef() => BodyDef {
return *BodyDefFrom(body_get_body_def(*this.raw))
}
func Body.GetMass() => f32 {
return body_get_mass(*this.raw)
}
func Body.IsSensor() => bool {
return body_is_sensor(*this.raw) != 0
}
func Body.SetVelocityX(val: f32) {
body_set_velocity_x(*this.raw, val)
}
func Body.GetVelocityX() => f32 {
return body_get_velocity_x(*this.raw)
}
func Body.SetVelocityY(val: f32) {
body_set_velocity_y(*this.raw, val)
}
func Body.GetVelocityY() => f32 {
return body_get_velocity_y(*this.raw)
}
func Body.SetVelocity(val: Vec2) {
body_set_velocity(*this.raw, val.ToValue())
}
func Body.GetVelocity() => Vec2 {
return Vec2FromValue(body_get_velocity(*this.raw))
}
func Body.SetAngularRate(val: f32) {
body_set_angular_rate(*this.raw, val)
}
func Body.GetAngularRate() => f32 {
return body_get_angular_rate(*this.raw)
}
func Body.SetGroup(val: i32) {
body_set_group(*this.raw, val)
}
func Body.GetGroup() => i32 {
return body_get_group(*this.raw)
}
func Body.SetLinearDamping(val: f32) {
body_set_linear_damping(*this.raw, val)
}
func Body.GetLinearDamping() => f32 {
return body_get_linear_damping(*this.raw)
}
func Body.SetAngularDamping(val: f32) {
body_set_angular_damping(*this.raw, val)
}
func Body.GetAngularDamping() => f32 {
return body_get_angular_damping(*this.raw)
}
func Body.SetOwner(val: Object) {
body_set_owner(*this.raw, val.GetRaw())
}
func Body.GetOwner() => Object {
return *ObjectFrom(body_get_owner(*this.raw))
}
func Body.SetReceivingContact(val: bool) {
body_set_receiving_contact(*this.raw, ToDoraBool(val))
}
func Body.IsReceivingContact() => bool {
return body_is_receiving_contact(*this.raw) != 0
}
func Body.ApplyLinearImpulse(impulse: Vec2, pos: Vec2) {
body_apply_linear_impulse(*this.raw, impulse.ToValue(), pos.ToValue())
}
func Body.ApplyAngularImpulse(impulse: f32) {
body_apply_angular_impulse(*this.raw, impulse)
}
func Body.GetSensorByTag(tag: i32) => Sensor {
return *SensorFrom(body_get_sensor_by_tag(*this.raw, tag))
}
func Body.RemoveSensorByTag(tag: i32) => bool {
return body_remove_sensor_by_tag(*this.raw, tag) != 0
}
func Body.RemoveSensor(sensor: Sensor) => bool {
return body_remove_sensor(*this.raw, sensor.GetRaw()) != 0
}
func Body.Attach(fixture_def: FixtureDef) {
body_attach(*this.raw, fixture_def.GetRaw())
}
func Body.AttachSensor(tag: i32, fixture_def: FixtureDef) => Sensor {
return *SensorFrom(body_attach_sensor(*this.raw, tag, fixture_def.GetRaw()))
}
func Body.OnContactFilter(filter: func(body: Body) => bool) {
stack0 := NewCallStack()
func_id0 := PushFunction(func() {
body := *BodyFrom(stack0.PopObject().GetRaw())
result_ := filter(body)
stack0.Push(result_)
})
body_on_contact_filter(*this.raw, func_id0, *stack0.raw)
}
func NewBody(def: BodyDef, world: PhysicsWorld, pos: Vec2, rot: f32) => Body {
object := Body{}
raw := body_new(def.GetRaw(), world.GetRaw(), pos.ToValue(), rot)
object.raw = &raw
setFinalizer(object.raw, ObjectFinalizer)
return object
}
Loading

0 comments on commit 76f0e03

Please sign in to comment.