forked from LeenkxTeam/LNXSDK
HaxeJolt
This commit is contained in:
694
lib/haxejolt/Sources/jolt/Jt.hx
Normal file
694
lib/haxejolt/Sources/jolt/Jt.hx
Normal file
@ -0,0 +1,694 @@
|
||||
// Jolt Physics bindings for Haxe
|
||||
|
||||
package jolt;
|
||||
|
||||
enum abstract EMotionType(Int) from Int to Int {
|
||||
var Static = 0;
|
||||
var Kinematic = 1;
|
||||
var Dynamic = 2;
|
||||
}
|
||||
|
||||
enum abstract EActivation(Int) from Int to Int {
|
||||
var Activate = 0;
|
||||
var DontActivate = 1;
|
||||
}
|
||||
|
||||
enum abstract EShapeType(Int) from Int to Int {
|
||||
var Convex = 0;
|
||||
var Compound = 1;
|
||||
var Decorated = 2;
|
||||
var Mesh = 3;
|
||||
var HeightField = 4;
|
||||
var Plane = 5;
|
||||
var Empty = 6;
|
||||
}
|
||||
|
||||
enum abstract EShapeSubType(Int) from Int to Int {
|
||||
var Sphere = 0;
|
||||
var Box = 1;
|
||||
var Capsule = 2;
|
||||
var TaperedCapsule = 3;
|
||||
var Cylinder = 4;
|
||||
var TaperedCylinder = 5;
|
||||
var ConvexHull = 6;
|
||||
var StaticCompound = 7;
|
||||
var MutableCompound = 8;
|
||||
var RotatedTranslated = 9;
|
||||
var Scaled = 10;
|
||||
var OffsetCenterOfMass = 11;
|
||||
var MeshShape = 12;
|
||||
var HeightFieldShape = 13;
|
||||
var PlaneShape = 14;
|
||||
var EmptyShape = 15;
|
||||
}
|
||||
|
||||
#if hl
|
||||
|
||||
typedef Jt = haxe.macro.MacroType<[webidl.Module.build({
|
||||
idlFile: "Sources/jolt/jolt.idl",
|
||||
chopPrefix: "",
|
||||
autoGC: false,
|
||||
nativeLib: "jolt"
|
||||
})]>;
|
||||
|
||||
#else
|
||||
|
||||
@:native('Jolt.Vec3')
|
||||
extern class Vec3 {
|
||||
public function new(?x:Float, ?y:Float, ?z:Float):Void;
|
||||
public static function sZero():Vec3;
|
||||
public static function sOne():Vec3;
|
||||
public static function sAxisX():Vec3;
|
||||
public static function sAxisY():Vec3;
|
||||
public static function sAxisZ():Vec3;
|
||||
public function GetX():Float;
|
||||
public function GetY():Float;
|
||||
public function GetZ():Float;
|
||||
public function SetX(x:Float):Void;
|
||||
public function SetY(y:Float):Void;
|
||||
public function SetZ(z:Float):Void;
|
||||
public function Set(x:Float, y:Float, z:Float):Void;
|
||||
public function Length():Float;
|
||||
public function LengthSq():Float;
|
||||
public function Normalized():Vec3;
|
||||
public function Cross(v:Vec3):Vec3;
|
||||
public function Dot(v:Vec3):Float;
|
||||
public function Add(v:Vec3):Vec3;
|
||||
public function Sub(v:Vec3):Vec3;
|
||||
public function Mul(f:Float):Vec3;
|
||||
public function Div(f:Float):Vec3;
|
||||
}
|
||||
|
||||
@:native('Jolt.RVec3')
|
||||
extern class RVec3 {
|
||||
public function new(?x:Float, ?y:Float, ?z:Float):Void;
|
||||
public static function sZero():RVec3;
|
||||
public function GetX():Float;
|
||||
public function GetY():Float;
|
||||
public function GetZ():Float;
|
||||
public function SetX(x:Float):Void;
|
||||
public function SetY(y:Float):Void;
|
||||
public function SetZ(z:Float):Void;
|
||||
public function Set(x:Float, y:Float, z:Float):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.Quat')
|
||||
extern class Quat {
|
||||
public function new(?x:Float, ?y:Float, ?z:Float, ?w:Float):Void;
|
||||
public static function sIdentity():Quat;
|
||||
public static function sRotation(axis:Vec3, angle:Float):Quat;
|
||||
public static function sEulerAngles(angles:Vec3):Quat;
|
||||
public function GetX():Float;
|
||||
public function GetY():Float;
|
||||
public function GetZ():Float;
|
||||
public function GetW():Float;
|
||||
public function SetX(x:Float):Void;
|
||||
public function SetY(y:Float):Void;
|
||||
public function SetZ(z:Float):Void;
|
||||
public function SetW(w:Float):Void;
|
||||
public function Set(x:Float, y:Float, z:Float, w:Float):Void;
|
||||
public function Length():Float;
|
||||
public function Normalized():Quat;
|
||||
public function GetEulerAngles():Vec3;
|
||||
public function Conjugated():Quat;
|
||||
public function Inversed():Quat;
|
||||
public function MulQuat(q:Quat):Quat;
|
||||
public function MulVec3(v:Vec3):Vec3;
|
||||
public function SLERP(dest:Quat, fraction:Float):Quat;
|
||||
}
|
||||
|
||||
@:native('Jolt.Mat44')
|
||||
extern class Mat44 {
|
||||
public function new():Void;
|
||||
public static function sIdentity():Mat44;
|
||||
public static function sZero():Mat44;
|
||||
public static function sRotation(q:Quat):Mat44;
|
||||
public static function sTranslation(v:Vec3):Mat44;
|
||||
public static function sRotationTranslation(q:Quat, v:Vec3):Mat44;
|
||||
public static function sScale(s:Float):Mat44;
|
||||
public function GetAxisX():Vec3;
|
||||
public function GetAxisY():Vec3;
|
||||
public function GetAxisZ():Vec3;
|
||||
public function GetTranslation():Vec3;
|
||||
public function GetQuaternion():Quat;
|
||||
public function GetRotation():Mat44;
|
||||
public function MulMat44(m:Mat44):Mat44;
|
||||
public function MulVec3(v:Vec3):Vec3;
|
||||
public function Inversed():Mat44;
|
||||
}
|
||||
|
||||
@:native('Jolt.BodyID')
|
||||
extern class BodyID {
|
||||
public function new():Void;
|
||||
public function GetIndex():Int;
|
||||
public function GetSequenceNumber():Int;
|
||||
public function IsInvalid():Bool;
|
||||
}
|
||||
|
||||
@:native('Jolt.Body')
|
||||
extern class Body {
|
||||
public function GetID():BodyID;
|
||||
public function GetBodyType():Int;
|
||||
public function GetMotionType():Int;
|
||||
public function SetMotionType(type:Int):Void;
|
||||
public function IsActive():Bool;
|
||||
public function IsStatic():Bool;
|
||||
public function IsKinematic():Bool;
|
||||
public function IsDynamic():Bool;
|
||||
public function IsSensor():Bool;
|
||||
public function SetIsSensor(sensor:Bool):Void;
|
||||
public function GetPosition():RVec3;
|
||||
public function GetRotation():Quat;
|
||||
public function GetWorldTransform():Mat44;
|
||||
public function GetCenterOfMassPosition():RVec3;
|
||||
public function GetCenterOfMassTransform():Mat44;
|
||||
public function GetLinearVelocity():Vec3;
|
||||
public function GetAngularVelocity():Vec3;
|
||||
public function SetLinearVelocity(v:Vec3):Void;
|
||||
public function SetAngularVelocity(v:Vec3):Void;
|
||||
public function SetLinearVelocityClamped(v:Vec3):Void;
|
||||
public function SetAngularVelocityClamped(v:Vec3):Void;
|
||||
public function GetPointVelocity(point:RVec3):Vec3;
|
||||
public function AddForce(force:Vec3):Void;
|
||||
public function AddForceAtPosition(force:Vec3, position:RVec3):Void;
|
||||
public function AddTorque(torque:Vec3):Void;
|
||||
public function AddImpulse(impulse:Vec3):Void;
|
||||
public function AddImpulseAtPosition(impulse:Vec3, position:RVec3):Void;
|
||||
public function AddAngularImpulse(impulse:Vec3):Void;
|
||||
public function MoveKinematic(targetPosition:RVec3, targetRotation:Quat, deltaTime:Float):Void;
|
||||
public function GetAccumulatedForce():Vec3;
|
||||
public function GetAccumulatedTorque():Vec3;
|
||||
public function ResetForce():Void;
|
||||
public function ResetTorque():Void;
|
||||
public function ResetMotion():Void;
|
||||
public function GetInverseInertia():Mat44;
|
||||
public function GetWorldSpaceBounds():Dynamic;
|
||||
public function GetShape():Shape;
|
||||
public function GetFriction():Float;
|
||||
public function SetFriction(friction:Float):Void;
|
||||
public function GetRestitution():Float;
|
||||
public function SetRestitution(restitution:Float):Void;
|
||||
public function GetUserData():Int;
|
||||
public function SetUserData(data:Int):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.Shape')
|
||||
extern class Shape {
|
||||
public function GetType():Int;
|
||||
public function GetSubType():Int;
|
||||
public function GetUserData():Int;
|
||||
public function SetUserData(data:Int):Void;
|
||||
public function MustBeStatic():Bool;
|
||||
public function GetCenterOfMass():Vec3;
|
||||
public function GetLocalBounds():Dynamic;
|
||||
public function GetInnerRadius():Float;
|
||||
public function GetVolume():Float;
|
||||
public function GetMassProperties():Dynamic;
|
||||
}
|
||||
|
||||
@:native('Jolt.BoxShapeSettings')
|
||||
extern class BoxShapeSettings {
|
||||
public function new(halfExtent:Vec3):Void;
|
||||
public function Create():ShapeResult;
|
||||
}
|
||||
|
||||
@:native('Jolt.BoxShape')
|
||||
extern class BoxShape extends Shape {
|
||||
public function new(halfExtent:Vec3):Void;
|
||||
public function GetHalfExtent():Vec3;
|
||||
}
|
||||
|
||||
@:native('Jolt.SphereShapeSettings')
|
||||
extern class SphereShapeSettings {
|
||||
public function new(radius:Float):Void;
|
||||
public function Create():ShapeResult;
|
||||
}
|
||||
|
||||
@:native('Jolt.SphereShape')
|
||||
extern class SphereShape extends Shape {
|
||||
public function new(radius:Float):Void;
|
||||
public function GetRadius():Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.CapsuleShapeSettings')
|
||||
extern class CapsuleShapeSettings {
|
||||
public function new(halfHeight:Float, radius:Float):Void;
|
||||
public function Create():ShapeResult;
|
||||
}
|
||||
|
||||
@:native('Jolt.CapsuleShape')
|
||||
extern class CapsuleShape extends Shape {
|
||||
public function new(halfHeight:Float, radius:Float):Void;
|
||||
public function GetHalfHeightOfCylinder():Float;
|
||||
public function GetRadius():Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.CylinderShapeSettings')
|
||||
extern class CylinderShapeSettings {
|
||||
public function new(halfHeight:Float, radius:Float):Void;
|
||||
public function Create():ShapeResult;
|
||||
}
|
||||
|
||||
@:native('Jolt.CylinderShape')
|
||||
extern class CylinderShape extends Shape {
|
||||
public function new(halfHeight:Float, radius:Float):Void;
|
||||
public function GetHalfHeight():Float;
|
||||
public function GetRadius():Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.ConvexHullShapeSettings')
|
||||
extern class ConvexHullShapeSettings {
|
||||
public function new():Void;
|
||||
public function Create():ShapeResult;
|
||||
}
|
||||
|
||||
@:native('Jolt.MeshShapeSettings')
|
||||
extern class MeshShapeSettings {
|
||||
public function new():Void;
|
||||
public function Create():ShapeResult;
|
||||
}
|
||||
|
||||
@:native('Jolt.HeightFieldShapeSettings')
|
||||
extern class HeightFieldShapeSettings {
|
||||
public function new():Void;
|
||||
public function Create():ShapeResult;
|
||||
}
|
||||
|
||||
@:native('Jolt.ShapeResult')
|
||||
extern class ShapeResult {
|
||||
public function IsValid():Bool;
|
||||
public function HasError():Bool;
|
||||
public function Get():Shape;
|
||||
}
|
||||
|
||||
@:native('Jolt.MassProperties')
|
||||
extern class MassProperties {
|
||||
public function new():Void;
|
||||
public var mMass:Float;
|
||||
public function ScaleToMass(mass:Float):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.BodyCreationSettings')
|
||||
extern class BodyCreationSettings {
|
||||
public function new(shape:Shape, position:RVec3, rotation:Quat, motionType:Int, objectLayer:Int):Void;
|
||||
public var mFriction:Float;
|
||||
public var mRestitution:Float;
|
||||
public var mLinearDamping:Float;
|
||||
public var mAngularDamping:Float;
|
||||
public var mMaxLinearVelocity:Float;
|
||||
public var mMaxAngularVelocity:Float;
|
||||
public var mGravityFactor:Float;
|
||||
public var mAllowSleeping:Bool;
|
||||
public var mIsSensor:Bool;
|
||||
public var mMotionQuality:Int;
|
||||
public var mAllowedDOFs:Int;
|
||||
public var mOverrideMassProperties:Int;
|
||||
public var mMassPropertiesOverride:MassProperties;
|
||||
public var mNumVelocityStepsOverride:Int;
|
||||
public var mNumPositionStepsOverride:Int;
|
||||
}
|
||||
|
||||
@:native('Jolt.BodyInterface')
|
||||
extern class BodyInterface {
|
||||
public function CreateBody(settings:BodyCreationSettings):Body;
|
||||
public function CreateBodyWithID(bodyId:BodyID, settings:BodyCreationSettings):Body;
|
||||
public function DestroyBody(bodyId:BodyID):Void;
|
||||
public function AddBody(bodyId:BodyID, activation:Int):Void;
|
||||
public function RemoveBody(bodyId:BodyID):Void;
|
||||
public function IsAdded(bodyId:BodyID):Bool;
|
||||
public function ActivateBody(bodyId:BodyID):Void;
|
||||
public function DeactivateBody(bodyId:BodyID):Void;
|
||||
public function IsActive(bodyId:BodyID):Bool;
|
||||
public function SetMotionType(bodyId:BodyID, motionType:Int, activation:Int):Void;
|
||||
public function GetMotionType(bodyId:BodyID):Int;
|
||||
public function SetPosition(bodyId:BodyID, position:RVec3, activation:Int):Void;
|
||||
public function GetPosition(bodyId:BodyID):RVec3;
|
||||
public function GetCenterOfMassPosition(bodyId:BodyID):RVec3;
|
||||
public function SetRotation(bodyId:BodyID, rotation:Quat, activation:Int):Void;
|
||||
public function GetRotation(bodyId:BodyID):Quat;
|
||||
public function SetPositionAndRotation(bodyId:BodyID, position:RVec3, rotation:Quat, activation:Int):Void;
|
||||
public function SetPositionAndRotationWhenChanged(bodyId:BodyID, position:RVec3, rotation:Quat, activation:Int):Void;
|
||||
public function SetLinearVelocity(bodyId:BodyID, velocity:Vec3):Void;
|
||||
public function GetLinearVelocity(bodyId:BodyID):Vec3;
|
||||
public function SetAngularVelocity(bodyId:BodyID, velocity:Vec3):Void;
|
||||
public function GetAngularVelocity(bodyId:BodyID):Vec3;
|
||||
public function AddLinearVelocity(bodyId:BodyID, velocity:Vec3):Void;
|
||||
public function AddLinearAndAngularVelocity(bodyId:BodyID, linear:Vec3, angular:Vec3):Void;
|
||||
public function GetPointVelocity(bodyId:BodyID, point:RVec3):Vec3;
|
||||
public function AddForce(bodyId:BodyID, force:Vec3, activation:Int = 0):Void;
|
||||
public function AddForceAtPosition(bodyId:BodyID, force:Vec3, position:RVec3, activation:Int = 0):Void;
|
||||
public function AddTorque(bodyId:BodyID, torque:Vec3, activation:Int = 0):Void;
|
||||
public function AddImpulse(bodyId:BodyID, impulse:Vec3):Void;
|
||||
public function AddImpulseAtPosition(bodyId:BodyID, impulse:Vec3, position:RVec3):Void;
|
||||
public function AddAngularImpulse(bodyId:BodyID, impulse:Vec3):Void;
|
||||
public function MoveKinematic(bodyId:BodyID, targetPosition:RVec3, targetRotation:Quat, deltaTime:Float):Void;
|
||||
public function SetShape(bodyId:BodyID, shape:Shape, updateMassProperties:Bool, activation:Int):Void;
|
||||
public function GetShape(bodyId:BodyID):Shape;
|
||||
public function SetFriction(bodyId:BodyID, friction:Float):Void;
|
||||
public function GetFriction(bodyId:BodyID):Float;
|
||||
public function SetRestitution(bodyId:BodyID, restitution:Float):Void;
|
||||
public function GetRestitution(bodyId:BodyID):Float;
|
||||
public function SetGravityFactor(bodyId:BodyID, factor:Float):Void;
|
||||
public function GetGravityFactor(bodyId:BodyID):Float;
|
||||
public function SetUserData(bodyId:BodyID, data:Int):Void;
|
||||
public function GetUserData(bodyId:BodyID):Int;
|
||||
public function GetWorldTransform(bodyId:BodyID):Mat44;
|
||||
public function GetCenterOfMassTransform(bodyId:BodyID):Mat44;
|
||||
}
|
||||
|
||||
@:native('Jolt.RRayCast')
|
||||
extern class RRayCast {
|
||||
public function new(origin:RVec3, direction:Vec3):Void;
|
||||
public var mOrigin:RVec3;
|
||||
public var mDirection:Vec3;
|
||||
}
|
||||
|
||||
@:native('Jolt.RayCastResult')
|
||||
extern class RayCastResult {
|
||||
public function new():Void;
|
||||
public var mBodyID:BodyID;
|
||||
public var mFraction:Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.BroadPhaseLayer')
|
||||
extern class BroadPhaseLayer {
|
||||
public function new(layer:Int):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.BroadPhaseLayerInterfaceTable')
|
||||
extern class BroadPhaseLayerInterfaceTable extends BroadPhaseLayerInterface {
|
||||
public function new(numObjectLayers:Int, numBroadPhaseLayers:Int):Void;
|
||||
public function MapObjectToBroadPhaseLayer(objectLayer:Int, broadPhaseLayer:BroadPhaseLayer):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.ObjectLayerPairFilterTable')
|
||||
extern class ObjectLayerPairFilterTable extends ObjectLayerPairFilter {
|
||||
public function new(numObjectLayers:Int):Void;
|
||||
public function EnableCollision(layer1:Int, layer2:Int):Void;
|
||||
public function DisableCollision(layer1:Int, layer2:Int):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.ObjectVsBroadPhaseLayerFilterTable')
|
||||
extern class ObjectVsBroadPhaseLayerFilterTable extends ObjectVsBroadPhaseLayerFilter {
|
||||
public function new(broadPhaseLayerInterface:BroadPhaseLayerInterfaceTable, numBroadPhaseLayers:Int,
|
||||
objectLayerPairFilter:ObjectLayerPairFilterTable, numObjectLayers:Int):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.BroadPhaseLayerInterfaceJS')
|
||||
extern class BroadPhaseLayerInterface {
|
||||
public function new():Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.ObjectVsBroadPhaseLayerFilterJS')
|
||||
extern class ObjectVsBroadPhaseLayerFilter {
|
||||
public function new():Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.ObjectLayerPairFilterJS')
|
||||
extern class ObjectLayerPairFilter {
|
||||
public function new():Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.NarrowPhaseQuery')
|
||||
extern class NarrowPhaseQuery {
|
||||
public function CastRay(ray:RRayCast, result:RayCastResult):Bool;
|
||||
}
|
||||
|
||||
@:native('Jolt.ContactListenerJS')
|
||||
extern class ContactListener {
|
||||
public function new():Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.BodyActivationListenerJS')
|
||||
extern class BodyActivationListener {
|
||||
public function new():Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.PhysicsSystem')
|
||||
extern class PhysicsSystem {
|
||||
public function new():Void;
|
||||
public function Init(maxBodies:Int, numBodyMutexes:Int, maxBodyPairs:Int, maxContactConstraints:Int):Void;
|
||||
public function Update(deltaTime:Float, collisionSteps:Int):Void;
|
||||
public function OptimizeBroadPhase():Void;
|
||||
public function GetBodyInterface():BodyInterface;
|
||||
public function GetBodyInterfaceNoLock():BodyInterface;
|
||||
public function GetNumBodies():Int;
|
||||
public function GetNumActiveBodies(bodyType:Int):Int;
|
||||
public function GetMaxBodies():Int;
|
||||
public function SetGravity(gravity:Vec3):Void;
|
||||
public function GetGravity():Vec3;
|
||||
public function SetContactListener(listener:ContactListener):Void;
|
||||
public function SetBodyActivationListener(listener:BodyActivationListener):Void;
|
||||
public function GetNarrowPhaseQuery():NarrowPhaseQuery;
|
||||
public function AddConstraint(constraint:Constraint):Void;
|
||||
public function RemoveConstraint(constraint:Constraint):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.JoltSettings')
|
||||
extern class JoltSettings {
|
||||
public function new():Void;
|
||||
public var mMaxBodies:Int;
|
||||
public var mMaxBodyPairs:Int;
|
||||
public var mMaxContactConstraints:Int;
|
||||
public var mBroadPhaseLayerInterface:BroadPhaseLayerInterface;
|
||||
public var mObjectVsBroadPhaseLayerFilter:ObjectVsBroadPhaseLayerFilter;
|
||||
public var mObjectLayerPairFilter:ObjectLayerPairFilter;
|
||||
}
|
||||
|
||||
@:native('Jolt.JoltInterface')
|
||||
extern class JoltInterface {
|
||||
public function new(settings:JoltSettings):Void;
|
||||
public function Step(deltaTime:Float, collisionSteps:Int):Void;
|
||||
public function GetPhysicsSystem():PhysicsSystem;
|
||||
public function GetTempAllocator():Dynamic;
|
||||
}
|
||||
|
||||
@:native('Jolt.Constraint')
|
||||
extern class Constraint {
|
||||
public function GetType():Int;
|
||||
public function GetSubType():Int;
|
||||
public function GetRefCount():Int;
|
||||
public function SetEnabled(enabled:Bool):Void;
|
||||
public function GetEnabled():Bool;
|
||||
}
|
||||
|
||||
@:native('Jolt.TwoBodyConstraint')
|
||||
extern class TwoBodyConstraint extends Constraint {
|
||||
public function GetBody1():Body;
|
||||
public function GetBody2():Body;
|
||||
}
|
||||
|
||||
@:native('Jolt.FixedConstraintSettings')
|
||||
extern class FixedConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mSpace:Int;
|
||||
public var mAutoDetectPoint:Bool;
|
||||
public var mPoint1:RVec3;
|
||||
public var mPoint2:RVec3;
|
||||
public var mAxisX1:Vec3;
|
||||
public var mAxisY1:Vec3;
|
||||
public var mAxisX2:Vec3;
|
||||
public var mAxisY2:Vec3;
|
||||
public function Create(body1:Body, body2:Body):TwoBodyConstraint;
|
||||
}
|
||||
|
||||
@:native('Jolt.PointConstraintSettings')
|
||||
extern class PointConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mSpace:Int;
|
||||
public var mPoint1:RVec3;
|
||||
public var mPoint2:RVec3;
|
||||
public function Create(body1:Body, body2:Body):TwoBodyConstraint;
|
||||
}
|
||||
|
||||
@:native('Jolt.HingeConstraintSettings')
|
||||
extern class HingeConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mSpace:Int;
|
||||
public var mPoint1:RVec3;
|
||||
public var mPoint2:RVec3;
|
||||
public var mHingeAxis1:Vec3;
|
||||
public var mHingeAxis2:Vec3;
|
||||
public var mNormalAxis1:Vec3;
|
||||
public var mNormalAxis2:Vec3;
|
||||
public var mLimitsMin:Float;
|
||||
public var mLimitsMax:Float;
|
||||
public var mMaxFrictionTorque:Float;
|
||||
public function Create(body1:Body, body2:Body):TwoBodyConstraint;
|
||||
}
|
||||
|
||||
@:native('Jolt.SliderConstraintSettings')
|
||||
extern class SliderConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mSpace:Int;
|
||||
public var mAutoDetectPoint:Bool;
|
||||
public var mPoint1:RVec3;
|
||||
public var mPoint2:RVec3;
|
||||
public var mSliderAxis1:Vec3;
|
||||
public var mSliderAxis2:Vec3;
|
||||
public var mNormalAxis1:Vec3;
|
||||
public var mNormalAxis2:Vec3;
|
||||
public var mLimitsMin:Float;
|
||||
public var mLimitsMax:Float;
|
||||
public var mMaxFrictionForce:Float;
|
||||
public function Create(body1:Body, body2:Body):TwoBodyConstraint;
|
||||
}
|
||||
|
||||
@:native('Jolt.DistanceConstraintSettings')
|
||||
extern class DistanceConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mSpace:Int;
|
||||
public var mPoint1:RVec3;
|
||||
public var mPoint2:RVec3;
|
||||
public var mMinDistance:Float;
|
||||
public var mMaxDistance:Float;
|
||||
public function Create(body1:Body, body2:Body):TwoBodyConstraint;
|
||||
}
|
||||
|
||||
@:native('Jolt.ConeConstraintSettings')
|
||||
extern class ConeConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mSpace:Int;
|
||||
public var mPoint1:RVec3;
|
||||
public var mPoint2:RVec3;
|
||||
public var mTwistAxis1:Vec3;
|
||||
public var mTwistAxis2:Vec3;
|
||||
public var mHalfConeAngle:Float;
|
||||
public function Create(body1:Body, body2:Body):TwoBodyConstraint;
|
||||
}
|
||||
|
||||
@:native('Jolt.SixDOFConstraintSettings')
|
||||
extern class SixDOFConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mSpace:Int;
|
||||
public var mPosition1:RVec3;
|
||||
public var mPosition2:RVec3;
|
||||
public var mAxisX1:Vec3;
|
||||
public var mAxisY1:Vec3;
|
||||
public var mAxisX2:Vec3;
|
||||
public var mAxisY2:Vec3;
|
||||
public function MakeFreeAxis(axis:Int):Void;
|
||||
public function MakeFixedAxis(axis:Int):Void;
|
||||
public function SetLimitedAxis(axis:Int, min:Float, max:Float):Void;
|
||||
public function Create(body1:Body, body2:Body):TwoBodyConstraint;
|
||||
}
|
||||
|
||||
@:native('Jolt.SixDOFConstraintSettings.EAxis')
|
||||
extern class SixDOFConstraintSettingsEAxis {
|
||||
public static var TranslationX:Int;
|
||||
public static var TranslationY:Int;
|
||||
public static var TranslationZ:Int;
|
||||
public static var RotationX:Int;
|
||||
public static var RotationY:Int;
|
||||
public static var RotationZ:Int;
|
||||
}
|
||||
|
||||
@:native('Jolt.Float3')
|
||||
extern class Float3 {
|
||||
public function new(x:Float, y:Float, z:Float):Void;
|
||||
public var x:Float;
|
||||
public var y:Float;
|
||||
public var z:Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.IndexedTriangle')
|
||||
extern class IndexedTriangle {
|
||||
public function new():Void;
|
||||
public var mIdx:Array<Int>;
|
||||
public var mMaterialIndex:Int;
|
||||
}
|
||||
|
||||
@:native('Jolt.ConvexHullShapeSettings')
|
||||
extern class ConvexHullShapeSettingsExt extends ConvexHullShapeSettings {
|
||||
public var mPoints:Dynamic; // std::vector<Vec3>
|
||||
public var mMaxConvexRadius:Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.MeshShapeSettings')
|
||||
extern class MeshShapeSettingsExt extends MeshShapeSettings {
|
||||
public var mTriangleVertices:Dynamic; // std::vector<Float3>
|
||||
public var mIndexedTriangles:Dynamic; // std::vector<IndexedTriangle>
|
||||
}
|
||||
|
||||
@:native('Jolt.HeightFieldShapeSettings')
|
||||
extern class HeightFieldShapeSettingsExt extends HeightFieldShapeSettings {
|
||||
public var mOffset:Vec3;
|
||||
public var mScale:Vec3;
|
||||
public var mSampleCount:Int;
|
||||
public var mHeightSamples:Dynamic; // float array
|
||||
}
|
||||
|
||||
@:native('Jolt.VehicleConstraintSettings')
|
||||
extern class VehicleConstraintSettings {
|
||||
public function new():Void;
|
||||
public var mMaxPitchRollAngle:Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.WheelSettings')
|
||||
extern class WheelSettings {
|
||||
public function new():Void;
|
||||
public var mPosition:Vec3;
|
||||
public var mSuspensionDirection:Vec3;
|
||||
public var mSteeringAxis:Vec3;
|
||||
public var mWheelUp:Vec3;
|
||||
public var mWheelForward:Vec3;
|
||||
public var mSuspensionMinLength:Float;
|
||||
public var mSuspensionMaxLength:Float;
|
||||
public var mSuspensionPreloadLength:Float;
|
||||
public var mRadius:Float;
|
||||
public var mWidth:Float;
|
||||
}
|
||||
|
||||
@:native('Jolt.CharacterVirtualSettings')
|
||||
extern class CharacterVirtualSettings {
|
||||
public function new():Void;
|
||||
public var mShape:Shape;
|
||||
public var mMaxSlopeAngle:Float;
|
||||
public var mMass:Float;
|
||||
public var mMaxStrength:Float;
|
||||
public var mPredictiveContactDistance:Float;
|
||||
public var mEnhancedInternalEdgeRemoval:Bool;
|
||||
}
|
||||
|
||||
@:native('Jolt.CharacterVirtual')
|
||||
extern class CharacterVirtual {
|
||||
public function new(settings:CharacterVirtualSettings, position:RVec3, rotation:Quat, physicsSystem:PhysicsSystem):Void;
|
||||
public function SetLinearVelocity(velocity:Vec3):Void;
|
||||
public function GetLinearVelocity():Vec3;
|
||||
public function GetPosition():RVec3;
|
||||
public function SetPosition(position:RVec3):Void;
|
||||
public function GetRotation():Quat;
|
||||
public function SetRotation(rotation:Quat):Void;
|
||||
public function GetGroundState():Int;
|
||||
public function IsSupported():Bool;
|
||||
public function GetGroundNormal():Vec3;
|
||||
public function GetGroundVelocity():Vec3;
|
||||
public function Update(deltaTime:Float, gravity:Vec3, broadPhaseLayerFilter:Dynamic, objectLayerFilter:Dynamic, bodyFilter:Dynamic, allocator:Dynamic):Void;
|
||||
}
|
||||
|
||||
enum abstract EGroundState(Int) from Int to Int {
|
||||
var OnGround = 0;
|
||||
var OnSteepGround = 1;
|
||||
var NotSupported = 2;
|
||||
var InAir = 3;
|
||||
}
|
||||
|
||||
@:native('Jolt.SoftBodySharedSettings')
|
||||
extern class SoftBodySharedSettings {
|
||||
public function new():Void;
|
||||
public function AddFace(f:Dynamic):Void;
|
||||
public function CreateConstraints(settings:Dynamic):Void;
|
||||
public function Optimize():Void;
|
||||
}
|
||||
|
||||
@:native('Jolt.SoftBodyCreationSettings')
|
||||
extern class SoftBodyCreationSettings {
|
||||
public function new(settings:SoftBodySharedSettings, position:RVec3, rotation:Quat, objectLayer:Int):Void;
|
||||
}
|
||||
|
||||
@:native('Jolt')
|
||||
extern class Jolt {
|
||||
public static function destroy(obj:Dynamic):Void;
|
||||
}
|
||||
|
||||
#end
|
||||
407
lib/haxejolt/Sources/jolt/jolt.idl
Normal file
407
lib/haxejolt/Sources/jolt/jolt.idl
Normal file
@ -0,0 +1,407 @@
|
||||
// Jolt Physics IDL for HashLink bindings
|
||||
// Based on JoltPhysics.js IDL
|
||||
// NOTE: Enums are defined in Jt.hx to avoid redefinition conflicts
|
||||
|
||||
// Vec3
|
||||
interface Vec3 {
|
||||
void Vec3();
|
||||
void Vec3(float inX, float inY, float inZ);
|
||||
[Value] Vec3 sZero();
|
||||
[Value] Vec3 sOne();
|
||||
[Value] Vec3 sAxisX();
|
||||
[Value] Vec3 sAxisY();
|
||||
[Value] Vec3 sAxisZ();
|
||||
float GetX();
|
||||
float GetY();
|
||||
float GetZ();
|
||||
void SetX(float inX);
|
||||
void SetY(float inY);
|
||||
void SetZ(float inZ);
|
||||
void Set(float inX, float inY, float inZ);
|
||||
float Length();
|
||||
float LengthSq();
|
||||
[Value] Vec3 Normalized();
|
||||
[Value] Vec3 Cross([Const, Ref] Vec3 inRHS);
|
||||
float Dot([Const, Ref] Vec3 inRHS);
|
||||
[Operator="+=", Ref] Vec3 Add([Const, Ref] Vec3 inV);
|
||||
[Operator="-=", Ref] Vec3 Sub([Const, Ref] Vec3 inV);
|
||||
[Operator="*=", Ref] Vec3 Mul(float inV);
|
||||
[Operator="/=", Ref] Vec3 Div(float inV);
|
||||
};
|
||||
|
||||
// RVec3 (real/double precision)
|
||||
interface RVec3 {
|
||||
void RVec3();
|
||||
void RVec3(double inX, double inY, double inZ);
|
||||
[Value] RVec3 sZeroR();
|
||||
double GetX();
|
||||
double GetY();
|
||||
double GetZ();
|
||||
void SetX(double inX);
|
||||
void SetY(double inY);
|
||||
void SetZ(double inZ);
|
||||
void Set(double inX, double inY, double inZ);
|
||||
double Length();
|
||||
double LengthSq();
|
||||
[Value] RVec3 Normalized();
|
||||
};
|
||||
|
||||
// Quat
|
||||
interface Quat {
|
||||
void Quat();
|
||||
void Quat(float inX, float inY, float inZ, float inW);
|
||||
[Value] Quat sIdentity();
|
||||
[Value] Quat sRotation([Const, Ref] Vec3 inAxis, float inAngle);
|
||||
[Value] Quat sEulerAngles([Const, Ref] Vec3 inInput);
|
||||
float GetX();
|
||||
float GetY();
|
||||
float GetZ();
|
||||
float GetW();
|
||||
void SetX(float inX);
|
||||
void SetY(float inY);
|
||||
void SetZ(float inZ);
|
||||
void SetW(float inW);
|
||||
void Set(float inX, float inY, float inZ, float inW);
|
||||
float Length();
|
||||
[Value] Quat Normalized();
|
||||
[Value] Vec3 GetEulerAngles();
|
||||
[Value] Quat Conjugated();
|
||||
[Value] Quat Inversed();
|
||||
[Value] Quat MulQuat([Const, Ref] Quat inQ);
|
||||
[Value] Vec3 MulVec3([Const, Ref] Vec3 inV);
|
||||
[Value] Quat SLERP([Const, Ref] Quat inDestination, float inFraction);
|
||||
};
|
||||
|
||||
// Mat44
|
||||
interface Mat44 {
|
||||
void Mat44();
|
||||
[Value] Mat44 sIdentity();
|
||||
[Value] Mat44 sZeroM();
|
||||
[Value] Mat44 sRotation([Const, Ref] Quat inQ);
|
||||
[Value] Mat44 sTranslation([Const, Ref] Vec3 inTranslation);
|
||||
[Value] Mat44 sRotationTranslation([Const, Ref] Quat inRotation, [Const, Ref] Vec3 inTranslation);
|
||||
[Value] Mat44 sScale(float inScale);
|
||||
[Value] Vec3 GetAxisX();
|
||||
[Value] Vec3 GetAxisY();
|
||||
[Value] Vec3 GetAxisZ();
|
||||
[Value] Vec3 GetTranslation();
|
||||
[Value] Quat GetQuaternion();
|
||||
[Value] Mat44 GetRotation();
|
||||
[Value] Mat44 MulMat44([Const, Ref] Mat44 inM);
|
||||
[Value] Vec3 MulVec3([Const, Ref] Vec3 inV);
|
||||
[Value] Mat44 Inversed();
|
||||
};
|
||||
|
||||
// BodyID
|
||||
interface BodyID {
|
||||
void BodyID();
|
||||
long GetIndex();
|
||||
long GetSequenceNumber();
|
||||
boolean IsInvalid();
|
||||
};
|
||||
|
||||
// Shape (base)
|
||||
interface Shape {
|
||||
long GetRefCount();
|
||||
void AddRef();
|
||||
void Release();
|
||||
int GetType();
|
||||
int GetSubType();
|
||||
boolean MustBeStatic();
|
||||
[Value] Vec3 GetCenterOfMass();
|
||||
float GetInnerRadius();
|
||||
long GetUserData();
|
||||
void SetUserData(long inUserData);
|
||||
};
|
||||
|
||||
// BoxShape
|
||||
interface BoxShape {
|
||||
void BoxShape([Const, Ref] Vec3 inHalfExtent);
|
||||
[Value] Vec3 GetHalfExtent();
|
||||
};
|
||||
BoxShape implements Shape;
|
||||
|
||||
// SphereShape
|
||||
interface SphereShape {
|
||||
void SphereShape(float inRadius);
|
||||
float GetRadius();
|
||||
};
|
||||
SphereShape implements Shape;
|
||||
|
||||
// CapsuleShape
|
||||
interface CapsuleShape {
|
||||
void CapsuleShape(float inHalfHeightOfCylinder, float inRadius);
|
||||
float GetHalfHeightOfCylinder();
|
||||
float GetRadius();
|
||||
};
|
||||
CapsuleShape implements Shape;
|
||||
|
||||
// CylinderShape
|
||||
interface CylinderShape {
|
||||
void CylinderShape(float inHalfHeight, float inRadius);
|
||||
float GetHalfHeight();
|
||||
float GetRadius();
|
||||
};
|
||||
CylinderShape implements Shape;
|
||||
|
||||
// Body
|
||||
interface Body {
|
||||
[Const, Value] BodyID GetID();
|
||||
boolean IsActive();
|
||||
boolean IsStatic();
|
||||
boolean IsKinematic();
|
||||
boolean IsDynamic();
|
||||
boolean IsSensor();
|
||||
void SetIsSensor(boolean inIsSensor);
|
||||
int GetMotionType();
|
||||
void SetMotionType(int inMotionType);
|
||||
[Value] RVec3 GetPosition();
|
||||
[Value] Quat GetRotation();
|
||||
[Value] Mat44 GetWorldTransform();
|
||||
[Value] RVec3 GetCenterOfMassPosition();
|
||||
[Value] Mat44 GetCenterOfMassTransform();
|
||||
[Value] Vec3 GetLinearVelocity();
|
||||
[Value] Vec3 GetAngularVelocity();
|
||||
void SetLinearVelocity([Const, Ref] Vec3 inLinearVelocity);
|
||||
void SetAngularVelocity([Const, Ref] Vec3 inAngularVelocity);
|
||||
void SetLinearVelocityClamped([Const, Ref] Vec3 inLinearVelocity);
|
||||
void SetAngularVelocityClamped([Const, Ref] Vec3 inAngularVelocity);
|
||||
[Value] Vec3 GetPointVelocity([Const, Ref] RVec3 inPoint);
|
||||
void AddForce([Const, Ref] Vec3 inForce);
|
||||
void AddForceAtPosition([Const, Ref] Vec3 inForce, [Const, Ref] RVec3 inPosition);
|
||||
void AddTorque([Const, Ref] Vec3 inTorque);
|
||||
void AddImpulse([Const, Ref] Vec3 inImpulse);
|
||||
void AddImpulseAtPosition([Const, Ref] Vec3 inImpulse, [Const, Ref] RVec3 inPosition);
|
||||
void AddAngularImpulse([Const, Ref] Vec3 inAngularImpulse);
|
||||
void MoveKinematic([Const, Ref] RVec3 inTargetPosition, [Const, Ref] Quat inTargetRotation, float inDeltaTime);
|
||||
[Value] Vec3 GetAccumulatedForce();
|
||||
[Value] Vec3 GetAccumulatedTorque();
|
||||
void ResetForce();
|
||||
void ResetTorque();
|
||||
void ResetMotion();
|
||||
[Const] Shape GetShape();
|
||||
float GetFriction();
|
||||
void SetFriction(float inFriction);
|
||||
float GetRestitution();
|
||||
void SetRestitution(float inRestitution);
|
||||
long GetUserData();
|
||||
void SetUserData(long inUserData);
|
||||
};
|
||||
|
||||
// MassProperties
|
||||
interface MassProperties {
|
||||
void MassProperties();
|
||||
attribute float mMass;
|
||||
void ScaleToMass(float inMass);
|
||||
};
|
||||
|
||||
// BodyCreationSettings
|
||||
interface BodyCreationSettings {
|
||||
void BodyCreationSettings([Const] Shape inShape, [Const, Ref] RVec3 inPosition, [Const, Ref] Quat inRotation, int inMotionType, short inObjectLayer);
|
||||
attribute float mFriction;
|
||||
attribute float mRestitution;
|
||||
attribute float mLinearDamping;
|
||||
attribute float mAngularDamping;
|
||||
attribute float mMaxLinearVelocity;
|
||||
attribute float mMaxAngularVelocity;
|
||||
attribute float mGravityFactor;
|
||||
attribute boolean mAllowSleeping;
|
||||
attribute boolean mIsSensor;
|
||||
attribute int mMotionQuality;
|
||||
attribute int mAllowedDOFs;
|
||||
attribute int mOverrideMassProperties;
|
||||
[Value] attribute MassProperties mMassPropertiesOverride;
|
||||
attribute int mNumVelocityStepsOverride;
|
||||
attribute int mNumPositionStepsOverride;
|
||||
};
|
||||
|
||||
// BodyInterface
|
||||
interface BodyInterface {
|
||||
Body CreateBody([Const, Ref] BodyCreationSettings inSettings);
|
||||
void DestroyBody([Const, Ref] BodyID inBodyID);
|
||||
void AddBody([Const, Ref] BodyID inBodyID, int inActivationMode);
|
||||
void RemoveBody([Const, Ref] BodyID inBodyID);
|
||||
boolean IsAdded([Const, Ref] BodyID inBodyID);
|
||||
void ActivateBody([Const, Ref] BodyID inBodyID);
|
||||
void DeactivateBody([Const, Ref] BodyID inBodyID);
|
||||
boolean IsActive([Const, Ref] BodyID inBodyID);
|
||||
void SetMotionType([Const, Ref] BodyID inBodyID, int inMotionType, int inActivationMode);
|
||||
int GetMotionType([Const, Ref] BodyID inBodyID);
|
||||
void SetPosition([Const, Ref] BodyID inBodyID, [Const, Ref] RVec3 inPosition, int inActivationMode);
|
||||
[Value] RVec3 GetPosition([Const, Ref] BodyID inBodyID);
|
||||
[Value] RVec3 GetCenterOfMassPosition([Const, Ref] BodyID inBodyID);
|
||||
void SetRotation([Const, Ref] BodyID inBodyID, [Const, Ref] Quat inRotation, int inActivationMode);
|
||||
[Value] Quat GetRotation([Const, Ref] BodyID inBodyID);
|
||||
void SetPositionAndRotation([Const, Ref] BodyID inBodyID, [Const, Ref] RVec3 inPosition, [Const, Ref] Quat inRotation, int inActivationMode);
|
||||
void SetLinearVelocity([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inLinearVelocity);
|
||||
[Value] Vec3 GetLinearVelocity([Const, Ref] BodyID inBodyID);
|
||||
void SetAngularVelocity([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inAngularVelocity);
|
||||
[Value] Vec3 GetAngularVelocity([Const, Ref] BodyID inBodyID);
|
||||
void AddLinearVelocity([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inLinearVelocity);
|
||||
void AddLinearAndAngularVelocity([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inLinearVelocity, [Const, Ref] Vec3 inAngularVelocity);
|
||||
void AddForce([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inForce);
|
||||
void AddForceAtPosition([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inForce, [Const, Ref] RVec3 inPosition);
|
||||
void AddTorque([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inTorque);
|
||||
void AddImpulse([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inImpulse);
|
||||
void AddImpulseAtPosition([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inImpulse, [Const, Ref] RVec3 inPosition);
|
||||
void AddAngularImpulse([Const, Ref] BodyID inBodyID, [Const, Ref] Vec3 inAngularImpulse);
|
||||
void MoveKinematic([Const, Ref] BodyID inBodyID, [Const, Ref] RVec3 inTargetPosition, [Const, Ref] Quat inTargetRotation, float inDeltaTime);
|
||||
void SetShape([Const, Ref] BodyID inBodyID, [Const] Shape inShape, boolean inUpdateMassProperties, int inActivationMode);
|
||||
[Const] Shape GetShape([Const, Ref] BodyID inBodyID);
|
||||
void SetFriction([Const, Ref] BodyID inBodyID, float inFriction);
|
||||
float GetFriction([Const, Ref] BodyID inBodyID);
|
||||
void SetRestitution([Const, Ref] BodyID inBodyID, float inRestitution);
|
||||
float GetRestitution([Const, Ref] BodyID inBodyID);
|
||||
void SetGravityFactor([Const, Ref] BodyID inBodyID, float inGravityFactor);
|
||||
float GetGravityFactor([Const, Ref] BodyID inBodyID);
|
||||
void SetUserData([Const, Ref] BodyID inBodyID, long inUserData);
|
||||
long GetUserData([Const, Ref] BodyID inBodyID);
|
||||
[Value] Mat44 GetWorldTransform([Const, Ref] BodyID inBodyID);
|
||||
[Value] Mat44 GetCenterOfMassTransform([Const, Ref] BodyID inBodyID);
|
||||
};
|
||||
|
||||
// RayCast
|
||||
interface RRayCast {
|
||||
void RRayCast([Const, Ref] RVec3 inOrigin, [Const, Ref] Vec3 inDirection);
|
||||
[Value] attribute RVec3 mOrigin;
|
||||
[Value] attribute Vec3 mDirection;
|
||||
};
|
||||
|
||||
interface RayCastResult {
|
||||
void RayCastResult();
|
||||
[Value] attribute BodyID mBodyID;
|
||||
attribute float mFraction;
|
||||
};
|
||||
|
||||
// NarrowPhaseQuery
|
||||
interface NarrowPhaseQuery {
|
||||
boolean CastRay([Const, Ref] RRayCast inRay, [Ref] RayCastResult ioHit);
|
||||
};
|
||||
|
||||
// PhysicsSystem
|
||||
interface PhysicsSystem {
|
||||
void PhysicsSystem();
|
||||
void Init(long inMaxBodies, long inNumBodyMutexes, long inMaxBodyPairs, long inMaxContactConstraints);
|
||||
void OptimizeBroadPhase();
|
||||
long Update(float inDeltaTime, long inCollisionSteps);
|
||||
BodyInterface GetBodyInterface();
|
||||
BodyInterface GetBodyInterfaceNoLock();
|
||||
long GetNumBodies();
|
||||
long GetNumActiveBodies();
|
||||
long GetMaxBodies();
|
||||
void SetGravity([Const, Ref] Vec3 inGravity);
|
||||
[Value] Vec3 GetGravity();
|
||||
[Const, Ref] NarrowPhaseQuery GetNarrowPhaseQuery();
|
||||
void AddConstraint(Constraint inConstraint);
|
||||
void RemoveConstraint(Constraint inConstraint);
|
||||
};
|
||||
|
||||
// Constraint base
|
||||
interface Constraint {
|
||||
long GetRefCount();
|
||||
void AddRef();
|
||||
void Release();
|
||||
void SetEnabled(boolean inEnabled);
|
||||
boolean GetEnabled();
|
||||
};
|
||||
|
||||
interface TwoBodyConstraint {
|
||||
Body GetBody1();
|
||||
Body GetBody2();
|
||||
};
|
||||
TwoBodyConstraint implements Constraint;
|
||||
|
||||
// FixedConstraintSettings
|
||||
interface FixedConstraintSettings {
|
||||
void FixedConstraintSettings();
|
||||
attribute int mSpace;
|
||||
attribute boolean mAutoDetectPoint;
|
||||
[Value] attribute RVec3 mPoint1;
|
||||
[Value] attribute RVec3 mPoint2;
|
||||
[Value] attribute Vec3 mAxisX1;
|
||||
[Value] attribute Vec3 mAxisY1;
|
||||
[Value] attribute Vec3 mAxisX2;
|
||||
[Value] attribute Vec3 mAxisY2;
|
||||
TwoBodyConstraint Create(Body inBody1, Body inBody2);
|
||||
};
|
||||
|
||||
// PointConstraintSettings
|
||||
interface PointConstraintSettings {
|
||||
void PointConstraintSettings();
|
||||
attribute int mSpace;
|
||||
[Value] attribute RVec3 mPoint1;
|
||||
[Value] attribute RVec3 mPoint2;
|
||||
TwoBodyConstraint Create(Body inBody1, Body inBody2);
|
||||
};
|
||||
|
||||
// HingeConstraintSettings
|
||||
interface HingeConstraintSettings {
|
||||
void HingeConstraintSettings();
|
||||
attribute int mSpace;
|
||||
[Value] attribute RVec3 mPoint1;
|
||||
[Value] attribute RVec3 mPoint2;
|
||||
[Value] attribute Vec3 mHingeAxis1;
|
||||
[Value] attribute Vec3 mHingeAxis2;
|
||||
[Value] attribute Vec3 mNormalAxis1;
|
||||
[Value] attribute Vec3 mNormalAxis2;
|
||||
attribute float mLimitsMin;
|
||||
attribute float mLimitsMax;
|
||||
attribute float mMaxFrictionTorque;
|
||||
TwoBodyConstraint Create(Body inBody1, Body inBody2);
|
||||
};
|
||||
|
||||
// SliderConstraintSettings
|
||||
interface SliderConstraintSettings {
|
||||
void SliderConstraintSettings();
|
||||
attribute int mSpace;
|
||||
attribute boolean mAutoDetectPoint;
|
||||
[Value] attribute RVec3 mPoint1;
|
||||
[Value] attribute RVec3 mPoint2;
|
||||
[Value] attribute Vec3 mSliderAxis1;
|
||||
[Value] attribute Vec3 mSliderAxis2;
|
||||
[Value] attribute Vec3 mNormalAxis1;
|
||||
[Value] attribute Vec3 mNormalAxis2;
|
||||
attribute float mLimitsMin;
|
||||
attribute float mLimitsMax;
|
||||
attribute float mMaxFrictionForce;
|
||||
TwoBodyConstraint Create(Body inBody1, Body inBody2);
|
||||
};
|
||||
|
||||
// DistanceConstraintSettings
|
||||
interface DistanceConstraintSettings {
|
||||
void DistanceConstraintSettings();
|
||||
attribute int mSpace;
|
||||
[Value] attribute RVec3 mPoint1;
|
||||
[Value] attribute RVec3 mPoint2;
|
||||
attribute float mMinDistance;
|
||||
attribute float mMaxDistance;
|
||||
TwoBodyConstraint Create(Body inBody1, Body inBody2);
|
||||
};
|
||||
|
||||
// SixDOFConstraintSettings
|
||||
interface SixDOFConstraintSettings {
|
||||
void SixDOFConstraintSettings();
|
||||
attribute int mSpace;
|
||||
[Value] attribute RVec3 mPosition1;
|
||||
[Value] attribute RVec3 mPosition2;
|
||||
[Value] attribute Vec3 mAxisX1;
|
||||
[Value] attribute Vec3 mAxisY1;
|
||||
[Value] attribute Vec3 mAxisX2;
|
||||
[Value] attribute Vec3 mAxisY2;
|
||||
void MakeFreeAxis(int inAxis);
|
||||
void MakeFixedAxis(int inAxis);
|
||||
void SetLimitedAxis(int inAxis, float inMin, float inMax);
|
||||
TwoBodyConstraint Create(Body inBody1, Body inBody2);
|
||||
};
|
||||
|
||||
// ConeConstraintSettings
|
||||
interface ConeConstraintSettings {
|
||||
void ConeConstraintSettings();
|
||||
attribute int mSpace;
|
||||
[Value] attribute RVec3 mPoint1;
|
||||
[Value] attribute RVec3 mPoint2;
|
||||
[Value] attribute Vec3 mTwistAxis1;
|
||||
[Value] attribute Vec3 mTwistAxis2;
|
||||
attribute float mHalfConeAngle;
|
||||
TwoBodyConstraint Create(Body inBody1, Body inBody2);
|
||||
};
|
||||
60
lib/haxejolt/Sources/webidl/Data.hx
Normal file
60
lib/haxejolt/Sources/webidl/Data.hx
Normal file
@ -0,0 +1,60 @@
|
||||
package webidl;
|
||||
|
||||
typedef Data = Array<Definition>;
|
||||
|
||||
typedef Position = {
|
||||
var file : String;
|
||||
var line : Int;
|
||||
var pos : Int;
|
||||
}
|
||||
|
||||
typedef Definition = {
|
||||
var pos : Position;
|
||||
var kind : DefinitionKind;
|
||||
}
|
||||
|
||||
enum DefinitionKind {
|
||||
DInterface( name : String, attrs : Array<Attrib>, fields : Array<Field> );
|
||||
DImplements( type : String, interfaceName : String );
|
||||
DEnum( name : String, values : Array<String> );
|
||||
}
|
||||
|
||||
typedef Field = {
|
||||
var name : String;
|
||||
var kind : FieldKind;
|
||||
var pos : Position;
|
||||
}
|
||||
|
||||
enum FieldKind {
|
||||
FMethod( args : Array<FArg>, ret : TypeAttr );
|
||||
FAttribute( t : TypeAttr );
|
||||
DConst( name : String, type : Type, value : String );
|
||||
}
|
||||
|
||||
typedef FArg = { name : String, opt : Bool, t : TypeAttr };
|
||||
typedef TypeAttr = { var t : Type; var attr : Array<Attrib>; };
|
||||
|
||||
enum Type {
|
||||
TVoid;
|
||||
TInt;
|
||||
TShort;
|
||||
TFloat;
|
||||
TDouble;
|
||||
TBool;
|
||||
TAny;
|
||||
TVoidPtr;
|
||||
TCustom( id : String );
|
||||
TArray( t : Type );
|
||||
}
|
||||
|
||||
enum Attrib {
|
||||
// fields
|
||||
AValue;
|
||||
ARef;
|
||||
AConst;
|
||||
AOperator( op : String );
|
||||
// interfaces
|
||||
ANoDelete;
|
||||
APrefix( prefix : String );
|
||||
AJSImplementation( name : String );
|
||||
}
|
||||
452
lib/haxejolt/Sources/webidl/Generate.hx
Normal file
452
lib/haxejolt/Sources/webidl/Generate.hx
Normal file
@ -0,0 +1,452 @@
|
||||
package webidl;
|
||||
import webidl.Data;
|
||||
|
||||
class Generate {
|
||||
|
||||
static var HEADER_EMSCRIPTEN = "
|
||||
|
||||
#include <emscripten.h>
|
||||
#define HL_PRIM
|
||||
#define HL_NAME(n) EMSCRIPTEN_KEEPALIVE eb_##n
|
||||
#define DEFINE_PRIM(ret, name, args)
|
||||
#define _OPT(t) t*
|
||||
#define _GET_OPT(value,t) *value
|
||||
|
||||
|
||||
";
|
||||
|
||||
static var HEADER_HL = "
|
||||
|
||||
#include <hl.h>
|
||||
#define _IDL _BYTES
|
||||
#define _OPT(t) vdynamic *
|
||||
#define _GET_OPT(value,t) (value)->v.t
|
||||
|
||||
|
||||
";
|
||||
|
||||
static var HEADER_NO_GC = "
|
||||
|
||||
#define alloc_ref(r, _) r
|
||||
#define alloc_ref_const(r,_) r
|
||||
#define _ref(t) t
|
||||
#define _unref(v) v
|
||||
#define free_ref(v) delete (v)
|
||||
#define HL_CONST const
|
||||
|
||||
";
|
||||
|
||||
static var HEADER_GC = "
|
||||
|
||||
template <typename T> struct pref {
|
||||
void *finalize;
|
||||
T *value;
|
||||
};
|
||||
|
||||
#define _ref(t) pref<t>
|
||||
#define _unref(v) v->value
|
||||
#define alloc_ref(r,t) _alloc_ref(r,finalize_##t)
|
||||
#define alloc_ref_const(r, _) _alloc_const(r)
|
||||
#define HL_CONST
|
||||
|
||||
template<typename T> void free_ref( pref<T> *r ) {
|
||||
if( !r->finalize ) hl_error(\"delete() is not allowed on const value.\");
|
||||
delete r->value;
|
||||
r->value = NULL;
|
||||
r->finalize = NULL;
|
||||
}
|
||||
|
||||
template<typename T> pref<T> *_alloc_ref( T *value, void (*finalize)( pref<T> * ) ) {
|
||||
pref<T> *r = (pref<T>*)hl_gc_alloc_finalizer(sizeof(pref<T>));
|
||||
r->finalize = finalize;
|
||||
r->value = value;
|
||||
return r;
|
||||
}
|
||||
|
||||
template<typename T> pref<T> *_alloc_const( const T *value ) {
|
||||
pref<T> *r = (pref<T>*)hl_gc_alloc_noptr(sizeof(pref<T>));
|
||||
r->finalize = NULL;
|
||||
r->value = (T*)value;
|
||||
return r;
|
||||
}
|
||||
|
||||
";
|
||||
|
||||
static function initOpts( opts : Options ) {
|
||||
if( opts.outputDir == null )
|
||||
opts.outputDir = "";
|
||||
else if( !StringTools.endsWith(opts.outputDir,"/") )
|
||||
opts.outputDir += "/";
|
||||
}
|
||||
|
||||
public static function generateCpp( opts : Options ) {
|
||||
|
||||
initOpts(opts);
|
||||
|
||||
var file = opts.idlFile;
|
||||
var content = sys.io.File.getBytes(file);
|
||||
var parse = new webidl.Parser();
|
||||
var decls = null;
|
||||
var gc = opts.autoGC;
|
||||
try {
|
||||
decls = parse.parseFile(file, new haxe.io.BytesInput(content));
|
||||
} catch( msg : String ) {
|
||||
throw msg + "(" + file+" line " + parse.line+")";
|
||||
}
|
||||
var output = new StringBuf();
|
||||
function add(str:String) {
|
||||
output.add(str.split("\r\n").join("\n") + "\n");
|
||||
}
|
||||
add("#ifdef EMSCRIPTEN");
|
||||
add("");
|
||||
add(StringTools.trim(HEADER_EMSCRIPTEN));
|
||||
add(StringTools.trim(HEADER_NO_GC));
|
||||
add("");
|
||||
add("#else");
|
||||
add("");
|
||||
add('#define HL_NAME(x) ${opts.nativeLib}_##x');
|
||||
add(StringTools.trim(HEADER_HL));
|
||||
add(StringTools.trim(gc ? HEADER_GC : HEADER_NO_GC));
|
||||
add("");
|
||||
add("#endif");
|
||||
if( opts.includeCode != null ) {
|
||||
add("");
|
||||
add(StringTools.trim(opts.includeCode));
|
||||
}
|
||||
add("");
|
||||
add('extern "C" {');
|
||||
add("");
|
||||
|
||||
var typeNames = new Map();
|
||||
var enumNames = new Map();
|
||||
|
||||
// ignore "JSImplementation" interfaces (?)
|
||||
for( d in decls.copy() )
|
||||
switch( d.kind ) {
|
||||
case DInterface(_, attrs, _):
|
||||
for( a in attrs )
|
||||
switch( a ) {
|
||||
case AJSImplementation(_):
|
||||
decls.remove(d);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
for( d in decls ) {
|
||||
switch( d.kind ) {
|
||||
case DInterface(name, attrs, _):
|
||||
var prefix = "";
|
||||
for( a in attrs )
|
||||
switch( a ) {
|
||||
case APrefix(name): prefix = name;
|
||||
default:
|
||||
}
|
||||
var fullName = "_ref(" + prefix + name+")*";
|
||||
typeNames.set(name, { full : fullName, constructor : prefix + name });
|
||||
if( attrs.indexOf(ANoDelete) >= 0 )
|
||||
continue;
|
||||
add('static void finalize_$name( $fullName _this ) { free_ref(_this); }');
|
||||
add('HL_PRIM void HL_NAME(${name}_delete)( $fullName _this ) {\n\tfree_ref(_this);\n}');
|
||||
add('DEFINE_PRIM(_VOID, ${name}_delete, _IDL);');
|
||||
case DEnum(name, values):
|
||||
enumNames.set(name, true);
|
||||
typeNames.set(name, { full : "int", constructor : null });
|
||||
add('static $name ${name}__values[] = { ${values.join(",")} };');
|
||||
case DImplements(_):
|
||||
}
|
||||
}
|
||||
|
||||
function getEnumName( t : webidl.Data.Type ) {
|
||||
return switch( t ) {
|
||||
case TCustom(id): enumNames.exists(id) ? id : null;
|
||||
default: null;
|
||||
}
|
||||
}
|
||||
|
||||
function makeType( t : webidl.Data.Type ) {
|
||||
return switch( t ) {
|
||||
case TFloat: "float";
|
||||
case TDouble: "double";
|
||||
case TShort: "short";
|
||||
case TInt: "int";
|
||||
case TVoid: "void";
|
||||
case TAny, TVoidPtr: "void*";
|
||||
case TArray(t): makeType(t) + "[]";
|
||||
case TBool: "bool";
|
||||
case TCustom(id): typeNames.get(id).full;
|
||||
}
|
||||
}
|
||||
|
||||
function defType( t ) {
|
||||
return switch( t ) {
|
||||
case TFloat: "_F32";
|
||||
case TDouble: "_F64";
|
||||
case TShort: "_I16";
|
||||
case TInt: "_I32";
|
||||
case TVoid: "_VOID";
|
||||
case TAny, TVoidPtr: "_BYTES";
|
||||
case TArray(t): "_BYTES";
|
||||
case TBool: "_BOOL";
|
||||
case TCustom(name): enumNames.exists(name) ? "_I32" : "_IDL";
|
||||
}
|
||||
}
|
||||
|
||||
function dynamicAccess(t) {
|
||||
return switch( t ) {
|
||||
case TFloat: "f";
|
||||
case TDouble: "d";
|
||||
case TShort: "ui16";
|
||||
case TInt: "i";
|
||||
case TBool: "b";
|
||||
default: throw "assert";
|
||||
}
|
||||
}
|
||||
|
||||
function makeTypeDecl( td : TypeAttr ) {
|
||||
var prefix = "";
|
||||
for( a in td.attr ) {
|
||||
switch( a ) {
|
||||
case AConst: prefix += "HL_CONST ";
|
||||
default:
|
||||
}
|
||||
}
|
||||
return prefix + makeType(td.t);
|
||||
}
|
||||
|
||||
function isDyn( arg : { opt : Bool, t : TypeAttr } ) {
|
||||
return arg.opt && !arg.t.t.match(TCustom(_));
|
||||
}
|
||||
|
||||
for( d in decls ) {
|
||||
switch( d.kind ) {
|
||||
case DInterface(name, attrs, fields):
|
||||
for( f in fields ) {
|
||||
switch( f.kind ) {
|
||||
case FMethod(margs, ret):
|
||||
var isConstr = f.name == name;
|
||||
var args = isConstr ? margs : [{ name : "_this", t : { t : TCustom(name), attr : [] }, opt : false }].concat(margs);
|
||||
var tret = isConstr ? { t : TCustom(name), attr : [] } : ret;
|
||||
var funName = name + "_" + (isConstr ? "new" + args.length : f.name + (args.length - 1));
|
||||
output.add('HL_PRIM ${makeTypeDecl(tret)} HL_NAME($funName)(');
|
||||
var first = true;
|
||||
for( a in args ) {
|
||||
if( first ) first = false else output.add(", ");
|
||||
switch( a.t.t ) {
|
||||
case TArray(t):
|
||||
output.add(makeType(t) + "*");
|
||||
default:
|
||||
if( isDyn(a) )
|
||||
output.add("_OPT("+makeType(a.t.t)+")");
|
||||
else
|
||||
output.add(makeType(a.t.t));
|
||||
}
|
||||
output.add(" " + a.name);
|
||||
}
|
||||
add(') {');
|
||||
|
||||
|
||||
function addCall(margs : Array<{ name : String, opt : Bool, t : TypeAttr }> ) {
|
||||
var refRet = null;
|
||||
var enumName = getEnumName(tret.t);
|
||||
if( isConstr ) {
|
||||
refRet = name;
|
||||
output.add('return alloc_ref((new ${typeNames.get(refRet).constructor}(');
|
||||
} else {
|
||||
if( tret.t != TVoid ) output.add("return ");
|
||||
for( a in ret.attr ) {
|
||||
switch( a ) {
|
||||
case ARef, AValue:
|
||||
refRet = switch(tret.t) {
|
||||
case TCustom(id): id;
|
||||
default: throw "assert";
|
||||
}
|
||||
if( a == ARef && tret.attr.indexOf(AConst) >= 0 )
|
||||
output.add('alloc_ref_const(&('); // we shouldn't call delete() on this one !
|
||||
else
|
||||
output.add('alloc_ref(new ${typeNames.get(refRet).constructor}(');
|
||||
default:
|
||||
}
|
||||
}
|
||||
if( enumName != null )
|
||||
output.add('make__$enumName(');
|
||||
else if( refRet == null && ret.t.match(TCustom(_)) ) {
|
||||
refRet = switch(tret.t) {
|
||||
case TCustom(id): id;
|
||||
default: throw "assert";
|
||||
}
|
||||
if( tret.attr.indexOf(AConst) >= 0 )
|
||||
output.add('alloc_ref_const((');
|
||||
else
|
||||
output.add('alloc_ref((');
|
||||
}
|
||||
|
||||
switch( f.name ) {
|
||||
case "op_mul":
|
||||
output.add("*_unref(_this) * (");
|
||||
case "op_add":
|
||||
output.add("*_unref(_this) + (");
|
||||
case "op_sub":
|
||||
output.add("*_unref(_this) - (");
|
||||
case "op_div":
|
||||
output.add("*_unref(_this) / (");
|
||||
case "op_mulq":
|
||||
output.add("*_unref(_this) *= (");
|
||||
default:
|
||||
output.add("_unref(_this)->" + f.name+"(");
|
||||
}
|
||||
}
|
||||
|
||||
var first = true;
|
||||
for( a in margs ) {
|
||||
if( first ) first = false else output.add(", ");
|
||||
for( a in a.t.attr ) {
|
||||
switch( a ) {
|
||||
case ARef: output.add("*"); // unref
|
||||
default:
|
||||
}
|
||||
}
|
||||
var e = getEnumName(a.t.t);
|
||||
if( e != null )
|
||||
output.add('${e}__values[${a.name}]');
|
||||
else switch( a.t.t ) {
|
||||
case TCustom(_):
|
||||
output.add('_unref(${a.name})');
|
||||
default:
|
||||
if( isDyn(a) ) {
|
||||
output.add("_GET_OPT("+a.name+","+dynamicAccess(a.t.t)+")");
|
||||
} else
|
||||
output.add(a.name);
|
||||
}
|
||||
}
|
||||
|
||||
if( enumName != null ) output.add(')');
|
||||
if( refRet != null ) output.add(')),$refRet');
|
||||
add(");");
|
||||
}
|
||||
|
||||
var hasOpt = false;
|
||||
for( i in 0...margs.length )
|
||||
if( margs[i].opt ) {
|
||||
hasOpt = true;
|
||||
break;
|
||||
}
|
||||
if( hasOpt ) {
|
||||
|
||||
for( i in 0...margs.length )
|
||||
if( margs[i].opt ) {
|
||||
add("\tif( !" + margs[i].name+" )");
|
||||
output.add("\t\t");
|
||||
addCall(margs.slice(0, i));
|
||||
add("\telse");
|
||||
}
|
||||
output.add("\t\t");
|
||||
addCall(margs);
|
||||
|
||||
} else {
|
||||
output.add("\t");
|
||||
addCall(margs);
|
||||
}
|
||||
add('}');
|
||||
output.add('DEFINE_PRIM(${defType(tret.t)}, $funName,');
|
||||
for( a in args )
|
||||
output.add(' ' + (isDyn(a) ? "_NULL(" + defType(a.t.t)+")" : defType(a.t.t)));
|
||||
add(');');
|
||||
add('');
|
||||
|
||||
|
||||
case FAttribute(t):
|
||||
var isVal = t.attr.indexOf(AValue) >= 0;
|
||||
var tname = switch( t.t ) { case TCustom(id): id; default: null; };
|
||||
var isRef = tname != null;
|
||||
var enumName = getEnumName(t.t);
|
||||
var isConst = t.attr.indexOf(AConst) >= 0;
|
||||
|
||||
if( enumName != null ) throw "TODO : enum attribute";
|
||||
|
||||
add('HL_PRIM ${makeTypeDecl(t)} HL_NAME(${name}_get_${f.name})( ${typeNames.get(name).full} _this ) {');
|
||||
if( isVal ) {
|
||||
var fname = typeNames.get(tname).constructor;
|
||||
add('\treturn alloc_ref(new $fname(_unref(_this)->${f.name}),$tname);');
|
||||
} else if( isRef )
|
||||
add('\treturn alloc_ref${isConst?'_const':''}(_unref(_this)->${f.name},$tname);');
|
||||
else
|
||||
add('\treturn _unref(_this)->${f.name};');
|
||||
add('}');
|
||||
|
||||
add('HL_PRIM ${makeTypeDecl(t)} HL_NAME(${name}_set_${f.name})( ${typeNames.get(name).full} _this, ${makeTypeDecl(t)} value ) {');
|
||||
add('\t_unref(_this)->${f.name} = ${isVal?"*":""}${isRef?"_unref":""}(value);');
|
||||
add('\treturn value;');
|
||||
add('}');
|
||||
|
||||
var td = defType(t.t);
|
||||
add('DEFINE_PRIM($td,${name}_get_${f.name},_IDL);');
|
||||
add('DEFINE_PRIM($td,${name}_set_${f.name},_IDL $td);');
|
||||
add('');
|
||||
case DConst(_, _, _):
|
||||
}
|
||||
}
|
||||
|
||||
case DEnum(_), DImplements(_):
|
||||
}
|
||||
}
|
||||
|
||||
add("}"); // extern C
|
||||
|
||||
sys.io.File.saveContent(opts.outputDir + opts.nativeLib+".cpp", output.toString());
|
||||
}
|
||||
|
||||
static function command( cmd, args : Array<String> ) {
|
||||
Sys.println("> " + cmd + " " + args.join(" "));
|
||||
var ret = Sys.command(cmd, args);
|
||||
if( ret != 0 ) throw "Command '" + cmd + "' has exit with error code " + ret;
|
||||
}
|
||||
|
||||
public static function generateJs( opts : Options, sources : Array<String>, ?params : Array<String> ) {
|
||||
if( params == null )
|
||||
params = [];
|
||||
|
||||
initOpts(opts);
|
||||
|
||||
var hasOpt = false;
|
||||
for( p in params )
|
||||
if( p.substr(0, 2) == "-O" )
|
||||
hasOpt = true;
|
||||
if( !hasOpt )
|
||||
params.push("-O2");
|
||||
|
||||
var lib = opts.nativeLib;
|
||||
|
||||
var emSdk = Sys.getEnv("EMSCRIPTEN");
|
||||
if( emSdk == null )
|
||||
throw "Missing EMSCRIPTEN environment variable. Install emscripten";
|
||||
var emcc = emSdk + "/emcc";
|
||||
|
||||
// build sources BC files
|
||||
var outFiles = [];
|
||||
sources.push(lib+".cpp");
|
||||
for( cfile in sources ) {
|
||||
var out = opts.outputDir + cfile.substr(0, -4) + ".bc";
|
||||
var args = params.concat(["-c", cfile, "-o", out]);
|
||||
command( emcc, args);
|
||||
outFiles.push(out);
|
||||
}
|
||||
|
||||
// link : because too many files, generate Makefile
|
||||
var tmp = opts.outputDir + "Makefile.tmp";
|
||||
var args = params.concat([
|
||||
"-s", 'EXPORT_NAME="\'$lib\'"', "-s", "MODULARIZE=1",
|
||||
"--memory-init-file", "0",
|
||||
"-o", '$lib.js'
|
||||
]);
|
||||
var output = "SOURCES = " + outFiles.join(" ") + "\n";
|
||||
output += "all:\n";
|
||||
output += "\t"+emcc+" $(SOURCES) " + args.join(" ");
|
||||
sys.io.File.saveContent(tmp, output);
|
||||
command("make", ["-f", tmp]);
|
||||
sys.FileSystem.deleteFile(tmp);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
459
lib/haxejolt/Sources/webidl/Module.hx
Normal file
459
lib/haxejolt/Sources/webidl/Module.hx
Normal file
@ -0,0 +1,459 @@
|
||||
package webidl;
|
||||
|
||||
#if macro
|
||||
import webidl.Data;
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
|
||||
class Module {
|
||||
var p : Position;
|
||||
var hl : Bool;
|
||||
var pack : Array<String>;
|
||||
var opts : Options;
|
||||
var types : Array<TypeDefinition> = [];
|
||||
|
||||
function new(p, pack, hl, opts) {
|
||||
this.p = p;
|
||||
this.pack = pack;
|
||||
this.hl = hl;
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
function makeName( name : String ) {
|
||||
if( opts.chopPrefix != null && StringTools.startsWith(name, opts.chopPrefix) ) name = name.substr(opts.chopPrefix.length);
|
||||
return capitalize(name);
|
||||
}
|
||||
|
||||
function buildModule( decls : Array<Definition> ) {
|
||||
for( d in decls )
|
||||
buildDecl(d);
|
||||
return types;
|
||||
}
|
||||
|
||||
function makeType( t : TypeAttr ) : ComplexType {
|
||||
return switch( t.t ) {
|
||||
case TVoid: macro : Void;
|
||||
case TInt: macro : Int;
|
||||
case TShort: hl ? macro : hl.UI16 : macro : Int;
|
||||
case TFloat: hl ? macro : Single : macro : Float;
|
||||
case TDouble: macro : Float;
|
||||
case TBool: macro : Bool;
|
||||
case TAny: macro : webidl.Types.Any;
|
||||
case TArray(t):
|
||||
var tt = makeType({ t : t, attr : [] });
|
||||
macro : webidl.Types.NativePtr<$tt>;
|
||||
case TVoidPtr: macro : webidl.Types.VoidPtr;
|
||||
case TCustom(id): TPath({ pack : [], name : makeName(id) });
|
||||
}
|
||||
}
|
||||
|
||||
function defVal( t : TypeAttr ) : Expr {
|
||||
return switch( t.t ) {
|
||||
case TVoid: throw "assert";
|
||||
case TInt, TShort: { expr : EConst(CInt("0")), pos : p };
|
||||
case TFloat, TDouble: { expr : EConst(CFloat("0.")), pos : p };
|
||||
case TBool: { expr : EConst(CIdent("false")), pos : p };
|
||||
default: { expr : EConst(CIdent("null")), pos : p };
|
||||
}
|
||||
}
|
||||
|
||||
function makeNative( name : String ) : MetadataEntry {
|
||||
return { name : ":hlNative", params : [{ expr : EConst(CString(opts.nativeLib)), pos : p },{ expr : EConst(CString(name)), pos : p }], pos : p };
|
||||
}
|
||||
|
||||
function makeEither( arr : Array<ComplexType> ) {
|
||||
var i = 0;
|
||||
var t = arr[i++];
|
||||
while( i < arr.length ) {
|
||||
var t2 = arr[i++];
|
||||
t = TPath({ pack : ["haxe", "extern"], name : "EitherType", params : [TPType(t), TPType(t2)] });
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
function makePosition( pos : webidl.Data.Position ) {
|
||||
if( pos == null )
|
||||
return p;
|
||||
return Context.makePosition({ min : pos.pos, max : pos.pos + 1, file : pos.file });
|
||||
}
|
||||
|
||||
function makeNativeField( iname : String, f : webidl.Data.Field, args : Array<FArg>, ret : TypeAttr, pub : Bool ) : Field {
|
||||
var name = f.name;
|
||||
var isConstr = name == iname;
|
||||
if( isConstr ) {
|
||||
name = "new";
|
||||
ret = { t : TCustom(iname), attr : [] };
|
||||
}
|
||||
|
||||
var expr = if( ret.t == TVoid )
|
||||
{ expr : EBlock([]), pos : p };
|
||||
else
|
||||
{ expr : EReturn(defVal(ret)), pos : p };
|
||||
|
||||
var access : Array<Access> = [];
|
||||
if( !hl ) access.push(AInline);
|
||||
if( pub ) access.push(APublic);
|
||||
if( isConstr ) access.push(AStatic);
|
||||
|
||||
return {
|
||||
pos : makePosition(f.pos),
|
||||
name : pub ? name : name + args.length,
|
||||
meta : [makeNative(iname+"_" + name + (name == "delete" ? "" : ""+args.length))],
|
||||
access : access,
|
||||
kind : FFun({
|
||||
ret : makeType(ret),
|
||||
expr : expr,
|
||||
args : [for( a in args ) { name : a.name, opt : a.opt, type : makeType(a.t) }],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function buildDecl( d : Definition ) {
|
||||
var p = makePosition(d.pos);
|
||||
switch( d.kind ) {
|
||||
case DInterface(iname, attrs, fields):
|
||||
var dfields : Array<Field> = [];
|
||||
|
||||
var variants = new Map();
|
||||
function getVariants( name : String ) {
|
||||
if( variants.exists(name) )
|
||||
return null;
|
||||
variants.set(name, true);
|
||||
var fl = [];
|
||||
for( f in fields )
|
||||
if( f.name == name )
|
||||
switch( f.kind ) {
|
||||
case FMethod(args, ret):
|
||||
fl.push({args:args, ret:ret,pos:f.pos});
|
||||
default:
|
||||
}
|
||||
return fl;
|
||||
}
|
||||
|
||||
|
||||
for( f in fields ) {
|
||||
switch( f.kind ) {
|
||||
case FMethod(_):
|
||||
|
||||
var vars = getVariants(f.name);
|
||||
if( vars == null ) continue;
|
||||
|
||||
var isConstr = f.name == iname;
|
||||
|
||||
if( vars.length == 1 && !isConstr ) {
|
||||
|
||||
var f = makeNativeField(iname, f, vars[0].args, vars[0].ret, true);
|
||||
dfields.push(f);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// create dispatching code
|
||||
var maxArgs = 0;
|
||||
for( v in vars ) if( v.args.length > maxArgs ) maxArgs = v.args.length;
|
||||
|
||||
if( vars.length > 1 && maxArgs == 0 )
|
||||
Context.error("Duplicate method declaration", makePosition(vars.pop().pos));
|
||||
|
||||
var targs : Array<FunctionArg> = [];
|
||||
var argsTypes = [];
|
||||
for( i in 0...maxArgs ) {
|
||||
var types : Array<{t:TypeAttr,sign:String}>= [];
|
||||
var names = [];
|
||||
var opt = false;
|
||||
for( v in vars ) {
|
||||
var a = v.args[i];
|
||||
if( a == null ) {
|
||||
opt = true;
|
||||
continue;
|
||||
}
|
||||
var sign = haxe.Serializer.run(a.t);
|
||||
var found = false;
|
||||
for( t in types )
|
||||
if( t.sign == sign ) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if( !found ) types.push({ t : a.t, sign : sign });
|
||||
if( names.indexOf(a.name) < 0 )
|
||||
names.push(a.name);
|
||||
if( a.opt )
|
||||
opt = true;
|
||||
}
|
||||
argsTypes.push(types);
|
||||
targs.push({
|
||||
name : names.join("_"),
|
||||
opt : opt,
|
||||
type : makeEither([for( t in types ) makeType(t.t)]),
|
||||
});
|
||||
}
|
||||
|
||||
// native impls
|
||||
var retTypes : Array<{t:TypeAttr,sign:String}> = [];
|
||||
for( v in vars ) {
|
||||
var f = makeNativeField(iname, f, v.args, v.ret, false );
|
||||
|
||||
var sign = haxe.Serializer.run(v.ret);
|
||||
var found = false;
|
||||
for( t in retTypes )
|
||||
if( t.sign == sign ) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if( !found ) retTypes.push({ t : v.ret, sign : sign });
|
||||
|
||||
dfields.push(f);
|
||||
}
|
||||
|
||||
vars.sort(function(v1, v2) return v1.args.length - v2.args.length);
|
||||
|
||||
// dispatch only on args count
|
||||
function makeCall( v : { args : Array<FArg>, ret : TypeAttr } ) : Expr {
|
||||
var ident = { expr : EConst(CIdent( (f.name == iname ? "new" : f.name) + v.args.length )), pos : p};
|
||||
var e : Expr = { expr : ECall(ident, [for( i in 0...v.args.length ) { expr : ECast({ expr : EConst(CIdent(targs[i].name)), pos : p }, null), pos : p }]), pos : p };
|
||||
if( v.ret.t != TVoid )
|
||||
e = { expr : EReturn(e), pos : p };
|
||||
else if( isConstr )
|
||||
e = macro this = $e;
|
||||
return e;
|
||||
}
|
||||
|
||||
var expr = makeCall(vars[vars.length - 1]);
|
||||
for( i in 1...vars.length ) {
|
||||
var v = vars[vars.length - 1 - i];
|
||||
var aname = targs[v.args.length].name;
|
||||
var call = makeCall(v);
|
||||
expr = macro if( $i{aname} == null ) $call else $expr;
|
||||
}
|
||||
|
||||
dfields.push({
|
||||
name : isConstr ? "new" : f.name,
|
||||
pos : makePosition(f.pos),
|
||||
access : [APublic, AInline],
|
||||
kind : FFun({
|
||||
expr : expr,
|
||||
args : targs,
|
||||
ret : makeEither([for( t in retTypes ) makeType(t.t)]),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
case FAttribute(t):
|
||||
var tt = makeType(t);
|
||||
dfields.push({
|
||||
pos : p,
|
||||
name : f.name,
|
||||
kind : FProp("get", "set", tt),
|
||||
access : [APublic],
|
||||
});
|
||||
dfields.push({
|
||||
pos : p,
|
||||
name : "get_" + f.name,
|
||||
meta : [makeNative(iname+"_get_" + f.name)],
|
||||
kind : FFun({
|
||||
ret : tt,
|
||||
expr : macro return ${defVal(t)},
|
||||
args : [],
|
||||
}),
|
||||
});
|
||||
dfields.push({
|
||||
pos : p,
|
||||
name : "set_" + f.name,
|
||||
meta : [makeNative(iname+"_set_" + f.name)],
|
||||
kind : FFun({
|
||||
ret : tt,
|
||||
expr : macro return ${defVal(t)},
|
||||
args : [{ name : "_v", type : tt }],
|
||||
}),
|
||||
});
|
||||
case DConst(name, type, value):
|
||||
dfields.push({
|
||||
pos : p,
|
||||
name : name,
|
||||
access : [APublic, AStatic, AInline],
|
||||
kind : FVar(
|
||||
makeType({t : type, attr : []}),
|
||||
macro $i{value}
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
var td : TypeDefinition = {
|
||||
pos : p,
|
||||
pack : pack,
|
||||
name : makeName(iname),
|
||||
meta : [],
|
||||
kind : TDAbstract(macro : webidl.Types.Ref, [], [macro : webidl.Types.Ref]),
|
||||
fields : dfields,
|
||||
};
|
||||
|
||||
if( attrs.indexOf(ANoDelete) < 0 )
|
||||
dfields.push(makeNativeField(iname, { name : "delete", pos : null, kind : null }, [], { t : TVoid, attr : [] }, true));
|
||||
|
||||
if( !hl ) {
|
||||
for( f in dfields )
|
||||
if( f.meta != null )
|
||||
for( m in f.meta )
|
||||
if( m.name == ":hlNative" ) {
|
||||
if( f.access == null ) f.access = [];
|
||||
switch( f.kind ) {
|
||||
case FFun(df):
|
||||
var call = opts.nativeLib + "._eb_" + switch( m.params[1].expr ) { case EConst(CString(name)): name; default: throw "!"; };
|
||||
var args : Array<Expr> = [for( a in df.args ) { expr : EConst(CIdent(a.name)), pos : p }];
|
||||
if( f.access.indexOf(AStatic) < 0 )
|
||||
args.unshift(macro this);
|
||||
df.expr = macro return untyped $i{call}($a{args});
|
||||
default: throw "assert";
|
||||
}
|
||||
if (f.access.indexOf(AInline) == -1) f.access.push(AInline);
|
||||
f.meta.remove(m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
types.push(td);
|
||||
case DImplements(name,intf):
|
||||
var name = makeName(name);
|
||||
var intf = makeName(intf);
|
||||
var found = false;
|
||||
for( t in types )
|
||||
if( t.name == name ) {
|
||||
found = true;
|
||||
switch( t.kind ) {
|
||||
case TDAbstract(a, _):
|
||||
t.fields.push({
|
||||
pos : p,
|
||||
name : "_to" + intf,
|
||||
meta : [{ name : ":to", pos : p }],
|
||||
access : [AInline],
|
||||
kind : FFun({
|
||||
args : [],
|
||||
expr : macro return cast this,
|
||||
ret : TPath({ pack : [], name : intf }),
|
||||
}),
|
||||
});
|
||||
|
||||
var toImpl = [intf];
|
||||
while( toImpl.length > 0 ) {
|
||||
var intf = toImpl.pop();
|
||||
var td = null;
|
||||
for( t2 in types ) {
|
||||
if( t2.name == intf )
|
||||
switch( t2.kind ) {
|
||||
case TDAbstract(a2, _, to):
|
||||
for ( inheritedField in t2.fields ) {
|
||||
// Search for existing field
|
||||
var fieldExists = false;
|
||||
for ( existingField in t.fields ) {
|
||||
if ( inheritedField.name == existingField.name ) {
|
||||
fieldExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !fieldExists ) {
|
||||
t.fields.push(inheritedField);
|
||||
}
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
Context.warning("Cannot have " + name+" extends " + intf, p);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if( !found )
|
||||
Context.warning("Class " + name+" not found for implements " + intf, p);
|
||||
case DEnum(name, values):
|
||||
var index = 0;
|
||||
types.push({
|
||||
pos : p,
|
||||
pack : pack,
|
||||
name : makeName(name),
|
||||
meta : [{ name : ":enum", pos : p }],
|
||||
kind : TDAbstract(macro : Int),
|
||||
fields : [for( v in values ) { pos : p, name : v, kind : FVar(null,{ expr : EConst(CInt(""+(index++))), pos : p }) }],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static function buildTypes( opts : Options, hl : Bool = false ):Array<TypeDefinition> {
|
||||
var p = Context.currentPos();
|
||||
if( opts.nativeLib == null ) {
|
||||
Context.error("Missing nativeLib option for HL", p);
|
||||
return null;
|
||||
}
|
||||
// load IDL
|
||||
var file = opts.idlFile;
|
||||
var content = try {
|
||||
file = Context.resolvePath(file);
|
||||
sys.io.File.getBytes(file);
|
||||
} catch( e : Dynamic ) {
|
||||
Context.error("" + e, p);
|
||||
return null;
|
||||
}
|
||||
|
||||
// parse IDL
|
||||
var parse = new webidl.Parser();
|
||||
var decls = null;
|
||||
try {
|
||||
decls = parse.parseFile(file,new haxe.io.BytesInput(content));
|
||||
} catch( msg : String ) {
|
||||
var lines = content.toString().split("\n");
|
||||
var start = lines.slice(0, parse.line-1).join("\n").length + 1;
|
||||
Context.error(msg, Context.makePosition({ min : start, max : start + lines[parse.line-1].length, file : file }));
|
||||
return null;
|
||||
}
|
||||
|
||||
var module = Context.getLocalModule();
|
||||
var pack = module.split(".");
|
||||
pack.pop();
|
||||
return new Module(p, pack, hl, opts).buildModule(decls);
|
||||
}
|
||||
|
||||
public static function build( opts : Options ) {
|
||||
var file = opts.idlFile;
|
||||
var module = Context.getLocalModule();
|
||||
var types = buildTypes(opts, Context.defined("hl"));
|
||||
if (types == null) return macro : Void;
|
||||
|
||||
// Add an init function for initializing the JS module
|
||||
if (Context.defined("js")) {
|
||||
types.push(macro class Init {
|
||||
public static function init(onReady:Void->Void) {
|
||||
untyped __js__('${opts.nativeLib} = ${opts.nativeLib}().then(onReady)');
|
||||
}
|
||||
});
|
||||
|
||||
// For HL no initialization is required so execute the callback immediately
|
||||
} else if (Context.defined("hl")) {
|
||||
types.push(macro class Init {
|
||||
public static function init(onReady:Void->Void) {
|
||||
onReady();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Context.defineModule(module, types);
|
||||
Context.registerModuleDependency(module, file);
|
||||
|
||||
return macro : Void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capitalize the first letter of a string
|
||||
* @param text The string to capitalize
|
||||
*/
|
||||
private static function capitalize(text:String) {
|
||||
return text.charAt(0).toUpperCase() + text.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
||||
10
lib/haxejolt/Sources/webidl/Options.hx
Normal file
10
lib/haxejolt/Sources/webidl/Options.hx
Normal file
@ -0,0 +1,10 @@
|
||||
package webidl;
|
||||
|
||||
typedef Options = {
|
||||
var idlFile : String;
|
||||
var nativeLib : String;
|
||||
@:optional var outputDir : String;
|
||||
@:optional var includeCode : String;
|
||||
@:optional var chopPrefix : String;
|
||||
@:optional var autoGC : Bool;
|
||||
}
|
||||
509
lib/haxejolt/Sources/webidl/Parser.hx
Normal file
509
lib/haxejolt/Sources/webidl/Parser.hx
Normal file
@ -0,0 +1,509 @@
|
||||
package webidl;
|
||||
import webidl.Data;
|
||||
|
||||
private enum Token {
|
||||
TEof;
|
||||
TId( s : String );
|
||||
TPOpen;
|
||||
TPClose;
|
||||
TBrOpen;
|
||||
TBrClose;
|
||||
TBkOpen;
|
||||
TBkClose;
|
||||
TSemicolon;
|
||||
TComma;
|
||||
TOp( op : String );
|
||||
TString( str : String );
|
||||
}
|
||||
|
||||
|
||||
class Parser {
|
||||
|
||||
public var line : Int;
|
||||
var input : haxe.io.Input;
|
||||
var char : Int;
|
||||
var ops : Array<Bool>;
|
||||
var idents : Array<Bool>;
|
||||
var tokens : Array<Token>;
|
||||
var pos = 0;
|
||||
var fileName : String;
|
||||
|
||||
public function new() {
|
||||
var opChars = "+*/-=!><&|^%~";
|
||||
var identChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
||||
idents = new Array();
|
||||
ops = new Array();
|
||||
for( i in 0...identChars.length )
|
||||
idents[identChars.charCodeAt(i)] = true;
|
||||
for( i in 0...opChars.length )
|
||||
ops[opChars.charCodeAt(i)] = true;
|
||||
}
|
||||
|
||||
public function parseFile( fileName : String, input : haxe.io.Input ) {
|
||||
this.fileName = fileName;
|
||||
pos = 0;
|
||||
line = 1;
|
||||
char = -1;
|
||||
tokens = [];
|
||||
this.input = input;
|
||||
var out = [];
|
||||
while( true ) {
|
||||
var tk = token();
|
||||
if( tk == TEof ) break;
|
||||
push(tk);
|
||||
out.push(parseDecl());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function parseDecl() {
|
||||
var attr = attributes();
|
||||
var pmin = this.pos;
|
||||
switch( token() ) {
|
||||
case TId("interface"):
|
||||
var name = ident();
|
||||
ensure(TBrOpen);
|
||||
var fields = [];
|
||||
while( true ) {
|
||||
var tk = token();
|
||||
if( tk == TBrClose ) break;
|
||||
push(tk);
|
||||
fields.push(parseField());
|
||||
}
|
||||
ensure(TSemicolon);
|
||||
return { pos : makePos(pmin), kind : DInterface(name, attr, fields) };
|
||||
case TId("enum"):
|
||||
var name = ident();
|
||||
ensure(TBrOpen);
|
||||
var values = [];
|
||||
if( !maybe(TBrClose) )
|
||||
while( true ) {
|
||||
switch( token() ) {
|
||||
case TString(str): values.push(str);
|
||||
case var tk: unexpected(tk);
|
||||
}
|
||||
switch( token() ) {
|
||||
case TBrClose: break;
|
||||
case TComma: continue;
|
||||
case var tk: unexpected(tk);
|
||||
}
|
||||
}
|
||||
ensure(TSemicolon);
|
||||
return { pos : makePos(pmin), kind : DEnum(name, values) };
|
||||
case TId(name):
|
||||
if( attr.length > 0 )
|
||||
throw "assert";
|
||||
ensure(TId("implements"));
|
||||
var intf = ident();
|
||||
ensure(TSemicolon);
|
||||
return { pos : makePos(pmin), kind : DImplements(name, intf) };
|
||||
|
||||
case var tk:
|
||||
return unexpected(tk);
|
||||
}
|
||||
}
|
||||
|
||||
function attributes() {
|
||||
if( !maybe(TBkOpen) )
|
||||
return [];
|
||||
var attrs = [];
|
||||
while( true ) {
|
||||
var attr = switch( ident() ) {
|
||||
case "Value": AValue;
|
||||
case "Ref": ARef;
|
||||
case "Const": AConst;
|
||||
case "NoDelete": ANoDelete;
|
||||
case "Prefix":
|
||||
ensure(TOp("="));
|
||||
APrefix(switch( token() ) { case TString(s): s; case var tk: unexpected(tk); });
|
||||
case "JSImplementation":
|
||||
ensure(TOp("="));
|
||||
AJSImplementation(switch( token() ) { case TString(s): s; case var tk: unexpected(tk); });
|
||||
case "Operator":
|
||||
ensure(TOp("="));
|
||||
AOperator(switch( token() ) { case TString(s): s; case var tk: unexpected(tk); });
|
||||
case var attr:
|
||||
error("Unsupported attribute " + attr);
|
||||
null;
|
||||
}
|
||||
attrs.push(attr);
|
||||
if( !maybe(TComma) ) break;
|
||||
}
|
||||
ensure(TBkClose);
|
||||
return attrs;
|
||||
}
|
||||
|
||||
function type() : Type {
|
||||
var id = ident();
|
||||
var t = switch( id ) {
|
||||
case "void": TVoid;
|
||||
case "float": TFloat;
|
||||
case "double": TDouble;
|
||||
case "long", "int": TInt; // long ensures 32 bits
|
||||
case "short": TShort;
|
||||
case "boolean", "bool": TBool;
|
||||
case "any": TAny;
|
||||
case "VoidPtr": TVoidPtr;
|
||||
default: TCustom(id);
|
||||
};
|
||||
if( maybe(TBkOpen) ) {
|
||||
ensure(TBkClose);
|
||||
t = TArray(t);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
function makePos( pmin : Int ) {
|
||||
return { file : fileName, line : line, pos : pmin };
|
||||
}
|
||||
|
||||
function parseField() : Field {
|
||||
var attr = attributes();
|
||||
var pmin = this.pos;
|
||||
|
||||
if( maybe(TId("attribute")) ) {
|
||||
var t = type();
|
||||
var name = ident();
|
||||
ensure(TSemicolon);
|
||||
return { name : name, kind : FAttribute({ t : t, attr : attr }), pos : makePos(pmin) };
|
||||
}
|
||||
|
||||
if( maybe(TId("const")) ) {
|
||||
var type = type();
|
||||
var name = ident();
|
||||
ensure(TOp("="));
|
||||
var value = tokenString(token());
|
||||
ensure(TSemicolon);
|
||||
return { name: name, kind : DConst(name, type, value), pos : makePos(pmin) };
|
||||
}
|
||||
|
||||
var tret = type();
|
||||
var name = ident();
|
||||
ensure(TPOpen);
|
||||
var args = [];
|
||||
if( !maybe(TPClose) ) {
|
||||
while( true ) {
|
||||
var attr = attributes();
|
||||
var opt = maybe(TId("optional"));
|
||||
var t = type();
|
||||
var name = ident();
|
||||
args.push({ name : name, t : { t : t, attr : attr }, opt : opt });
|
||||
switch( token() ) {
|
||||
case TPClose:
|
||||
break;
|
||||
case TComma:
|
||||
continue;
|
||||
case var tk:
|
||||
unexpected(tk);
|
||||
}
|
||||
}
|
||||
}
|
||||
ensure(TSemicolon);
|
||||
return { name : name, kind : FMethod(args, { attr : attr, t : tret }), pos : makePos(pmin) };
|
||||
}
|
||||
|
||||
// --- Lexing
|
||||
|
||||
function invalidChar(c:Int) {
|
||||
error("Invalid char "+c+"("+String.fromCharCode(c)+")");
|
||||
}
|
||||
|
||||
function error( msg : String ) {
|
||||
throw msg+" line "+line;
|
||||
}
|
||||
|
||||
function unexpected( tk ) : Dynamic {
|
||||
error("Unexpected " + tokenString(tk));
|
||||
return null;
|
||||
}
|
||||
|
||||
function tokenString( tk ) {
|
||||
return switch( tk ) {
|
||||
case TEof: "<eof>";
|
||||
case TId(id): id;
|
||||
case TPOpen: "(";
|
||||
case TPClose: ")";
|
||||
case TBkOpen: "[";
|
||||
case TBkClose: "]";
|
||||
case TBrOpen: "{";
|
||||
case TBrClose: "}";
|
||||
case TComma: ",";
|
||||
case TSemicolon: ";";
|
||||
case TOp(op): op;
|
||||
case TString(str): '"' + str + '"';
|
||||
}
|
||||
}
|
||||
|
||||
inline function push(tk) {
|
||||
tokens.push(tk);
|
||||
}
|
||||
|
||||
function ensure(tk) {
|
||||
var t = token();
|
||||
if( t != tk && !std.Type.enumEq(t,tk) ) unexpected(t);
|
||||
}
|
||||
|
||||
function maybe(tk) {
|
||||
var t = token();
|
||||
if( t == tk || std.Type.enumEq(t,tk) )
|
||||
return true;
|
||||
push(t);
|
||||
return false;
|
||||
}
|
||||
|
||||
function ident() {
|
||||
var tk = token();
|
||||
switch( tk ) {
|
||||
case TId(id): return id;
|
||||
default:
|
||||
unexpected(tk);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function readChar() {
|
||||
pos++;
|
||||
return try input.readByte() catch( e : Dynamic ) 0;
|
||||
}
|
||||
|
||||
function token() : Token {
|
||||
if( tokens.length > 0 )
|
||||
return tokens.shift();
|
||||
var char;
|
||||
if( this.char < 0 )
|
||||
char = readChar();
|
||||
else {
|
||||
char = this.char;
|
||||
this.char = -1;
|
||||
}
|
||||
while( true ) {
|
||||
switch( char ) {
|
||||
case 0: return TEof;
|
||||
case 32,9,13: // space, tab, CR
|
||||
case 10: line++; // LF
|
||||
/* case 48,49,50,51,52,53,54,55,56,57: // 0...9
|
||||
var n = (char - 48) * 1.0;
|
||||
var exp = 0.;
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
exp *= 10;
|
||||
switch( char ) {
|
||||
case 48,49,50,51,52,53,54,55,56,57:
|
||||
n = n * 10 + (char - 48);
|
||||
case 46:
|
||||
if( exp > 0 ) {
|
||||
// in case of '...'
|
||||
if( exp == 10 && readChar() == 46 ) {
|
||||
push(TOp("..."));
|
||||
var i = Std.int(n);
|
||||
return TConst( (i == n) ? CInt(i) : CFloat(n) );
|
||||
}
|
||||
invalidChar(char);
|
||||
}
|
||||
exp = 1.;
|
||||
case 120: // x
|
||||
if( n > 0 || exp > 0 )
|
||||
invalidChar(char);
|
||||
// read hexa
|
||||
#if haxe3
|
||||
var n = 0;
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
switch( char ) {
|
||||
case 48,49,50,51,52,53,54,55,56,57: // 0-9
|
||||
n = (n << 4) + char - 48;
|
||||
case 65,66,67,68,69,70: // A-F
|
||||
n = (n << 4) + (char - 55);
|
||||
case 97,98,99,100,101,102: // a-f
|
||||
n = (n << 4) + (char - 87);
|
||||
default:
|
||||
this.char = char;
|
||||
return TConst(CInt(n));
|
||||
}
|
||||
}
|
||||
#else
|
||||
var n = haxe.Int32.ofInt(0);
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
switch( char ) {
|
||||
case 48,49,50,51,52,53,54,55,56,57: // 0-9
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 48));
|
||||
case 65,66,67,68,69,70: // A-F
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 55));
|
||||
case 97,98,99,100,101,102: // a-f
|
||||
n = haxe.Int32.add(haxe.Int32.shl(n,4), cast (char - 87));
|
||||
default:
|
||||
this.char = char;
|
||||
// we allow to parse hexadecimal Int32 in Neko, but when the value will be
|
||||
// evaluated by Interpreter, a failure will occur if no Int32 operation is
|
||||
// performed
|
||||
var v = try CInt(haxe.Int32.toInt(n)) catch( e : Dynamic ) CInt32(n);
|
||||
return TConst(v);
|
||||
}
|
||||
}
|
||||
#end
|
||||
default:
|
||||
this.char = char;
|
||||
var i = Std.int(n);
|
||||
return TConst( (exp > 0) ? CFloat(n * 10 / exp) : ((i == n) ? CInt(i) : CFloat(n)) );
|
||||
}
|
||||
}*/
|
||||
case 59: return TSemicolon;
|
||||
case 40: return TPOpen;
|
||||
case 41: return TPClose;
|
||||
case 44: return TComma;
|
||||
/* case 46:
|
||||
char = readChar();
|
||||
switch( char ) {
|
||||
case 48,49,50,51,52,53,54,55,56,57:
|
||||
var n = char - 48;
|
||||
var exp = 1;
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
exp *= 10;
|
||||
switch( char ) {
|
||||
case 48,49,50,51,52,53,54,55,56,57:
|
||||
n = n * 10 + (char - 48);
|
||||
default:
|
||||
this.char = char;
|
||||
return TConst( CFloat(n/exp) );
|
||||
}
|
||||
}
|
||||
case 46:
|
||||
char = readChar();
|
||||
if( char != 46 )
|
||||
invalidChar(char);
|
||||
return TOp("...");
|
||||
default:
|
||||
this.char = char;
|
||||
return TDot;
|
||||
}*/
|
||||
case 123: return TBrOpen;
|
||||
case 125: return TBrClose;
|
||||
case 91: return TBkOpen;
|
||||
case 93: return TBkClose;
|
||||
case 39: return TString(readString(39));
|
||||
case 34: return TString(readString(34));
|
||||
// case 63: return TQuestion;
|
||||
// case 58: return TDoubleDot;
|
||||
case '='.code:
|
||||
char = readChar();
|
||||
if( char == '='.code )
|
||||
return TOp("==");
|
||||
else if ( char == '>'.code )
|
||||
return TOp("=>");
|
||||
this.char = char;
|
||||
return TOp("=");
|
||||
default:
|
||||
if( ops[char] ) {
|
||||
var op = String.fromCharCode(char);
|
||||
var prev = -1;
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
if( !ops[char] || prev == '='.code ) {
|
||||
if( op.charCodeAt(0) == '/'.code )
|
||||
return tokenComment(op,char);
|
||||
this.char = char;
|
||||
return TOp(op);
|
||||
}
|
||||
prev = char;
|
||||
op += String.fromCharCode(char);
|
||||
}
|
||||
}
|
||||
if( idents[char] ) {
|
||||
var id = String.fromCharCode(char);
|
||||
while( true ) {
|
||||
char = readChar();
|
||||
if( !idents[char] ) {
|
||||
this.char = char;
|
||||
return TId(id);
|
||||
}
|
||||
id += String.fromCharCode(char);
|
||||
}
|
||||
}
|
||||
invalidChar(char);
|
||||
}
|
||||
char = readChar();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function tokenComment( op : String, char : Int ) {
|
||||
var c = op.charCodeAt(1);
|
||||
var s = input;
|
||||
if( c == '/'.code ) { // comment
|
||||
try {
|
||||
while( char != '\r'.code && char != '\n'.code ) {
|
||||
pos++;
|
||||
char = s.readByte();
|
||||
}
|
||||
this.char = char;
|
||||
} catch( e : Dynamic ) {
|
||||
}
|
||||
return token();
|
||||
}
|
||||
if( c == '*'.code ) { /* comment */
|
||||
var old = line;
|
||||
if( op == "/**/" ) {
|
||||
this.char = char;
|
||||
return token();
|
||||
}
|
||||
try {
|
||||
while( true ) {
|
||||
while( char != '*'.code ) {
|
||||
if( char == '\n'.code ) line++;
|
||||
pos++;
|
||||
char = s.readByte();
|
||||
}
|
||||
pos++;
|
||||
char = s.readByte();
|
||||
if( char == '/'.code )
|
||||
break;
|
||||
}
|
||||
} catch( e : Dynamic ) {
|
||||
line = old;
|
||||
error("Unterminated comment");
|
||||
}
|
||||
return token();
|
||||
}
|
||||
this.char = char;
|
||||
return TOp(op);
|
||||
}
|
||||
|
||||
function readString( until ) {
|
||||
var c = 0;
|
||||
var b = new haxe.io.BytesOutput();
|
||||
var esc = false;
|
||||
var old = line;
|
||||
var s = input;
|
||||
while( true ) {
|
||||
try {
|
||||
pos++;
|
||||
c = s.readByte();
|
||||
} catch( e : Dynamic ) {
|
||||
line = old;
|
||||
error("Unterminated string");
|
||||
}
|
||||
if( esc ) {
|
||||
esc = false;
|
||||
switch( c ) {
|
||||
case 'n'.code: b.writeByte(10);
|
||||
case 'r'.code: b.writeByte(13);
|
||||
case 't'.code: b.writeByte(9);
|
||||
case "'".code, '"'.code, '\\'.code: b.writeByte(c);
|
||||
case '/'.code: b.writeByte(c);
|
||||
default: invalidChar(c);
|
||||
}
|
||||
} else if( c == 92 )
|
||||
esc = true;
|
||||
else if( c == until )
|
||||
break;
|
||||
else {
|
||||
if( c == 10 ) line++;
|
||||
b.writeByte(c);
|
||||
}
|
||||
}
|
||||
return b.getBytes().toString();
|
||||
}
|
||||
|
||||
}
|
||||
13
lib/haxejolt/Sources/webidl/Types.hx
Normal file
13
lib/haxejolt/Sources/webidl/Types.hx
Normal file
@ -0,0 +1,13 @@
|
||||
package webidl;
|
||||
|
||||
abstract Ref(#if hl hl.Bytes #else Dynamic #end) {
|
||||
}
|
||||
|
||||
abstract Any(#if hl hl.Bytes #else Dynamic #end) {
|
||||
}
|
||||
|
||||
abstract VoidPtr(#if hl hl.Bytes #else Dynamic #end) {
|
||||
}
|
||||
|
||||
abstract NativePtr<T>(#if hl hl.BytesAccess<T> #else Dynamic #end) {
|
||||
}
|
||||
Reference in New Issue
Block a user