Skip to content

Commit 73e6415

Browse files
authored
Remove usingnamespace usage (#8)
Closes #7
1 parent 092c2ab commit 73e6415

File tree

1 file changed

+189
-47
lines changed

1 file changed

+189
-47
lines changed

src/zbullet.zig

Lines changed: 189 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// zbullet v0.2
21
// Zig bindings for Bullet Physics SDK
32

43
const builtin = @import("builtin");
@@ -381,7 +380,7 @@ const ShapeImpl = opaque {
381380
}
382381
};
383382

384-
fn ShapeFunctions(comptime T: type) type {
383+
fn ShapeInterface(comptime T: type) type {
385384
return struct {
386385
pub fn asShape(shape: T) Shape {
387386
return @as(Shape, @ptrCast(shape));
@@ -426,8 +425,8 @@ fn ShapeFunctions(comptime T: type) type {
426425
pub fn isCompound(shape: T) bool {
427426
return shape.asShape().isCompound();
428427
}
429-
pub fn calculateLocalInertia(shape: Shape, mass: f32, inertia: *[3]f32) void {
430-
shape.asShape().calculateLocalInertia(shape, mass, inertia);
428+
pub fn calculateLocalInertia(shape: T, mass: f32, inertia: *[3]f32) void {
429+
shape.asShape().calculateLocalInertia(mass, inertia);
431430
}
432431
pub fn setUserPointer(shape: T, ptr: ?*anyopaque) void {
433432
shape.asShape().setUserPointer(ptr);
@@ -444,14 +443,68 @@ fn ShapeFunctions(comptime T: type) type {
444443
};
445444
}
446445

446+
fn ConstraintInterface(comptime T: type) type {
447+
return struct {
448+
pub fn asConstraint(con: T) Constraint {
449+
return @as(Constraint, @ptrCast(con));
450+
}
451+
pub fn dealloc(con: T) void {
452+
con.asConstraint().dealloc();
453+
}
454+
pub fn destroy(con: T) void {
455+
con.asConstraint().destroy();
456+
}
457+
pub fn getType(con: T) ConstraintType {
458+
return con.asConstraint().getType();
459+
}
460+
pub fn isCreated(con: T) bool {
461+
return con.asConstraint().isCreated();
462+
}
463+
pub fn setEnabled(con: T, enabled: bool) void {
464+
con.asConstraint().setEnabled(enabled);
465+
}
466+
pub fn isEnabled(con: T) bool {
467+
return con.asConstraint().isEnabled();
468+
}
469+
pub fn getBodyA(con: T) Body {
470+
return con.asConstraint().getBodyA();
471+
}
472+
pub fn getBodyB(con: T) Body {
473+
return con.asConstraint().getBodyB();
474+
}
475+
pub fn setDebugDrawSize(con: T, size: f32) void {
476+
con.asConstraint().setDebugDrawSize(size);
477+
}
478+
};
479+
}
480+
447481
pub fn initBoxShape(half_extents: *const [3]f32) BoxShape {
448482
const box = BoxShapeImpl.alloc();
449483
box.create(half_extents);
450484
return box;
451485
}
452486

453487
const BoxShapeImpl = opaque {
454-
pub usingnamespace ShapeFunctions(BoxShape);
488+
const Interface = ShapeInterface(BoxShape);
489+
pub const asShape = Interface.asShape;
490+
pub const dealloc = Interface.dealloc;
491+
pub const destroy = Interface.destroy;
492+
pub const deinit = Interface.deinit;
493+
pub const isCreated = Interface.isCreated;
494+
pub const getType = Interface.getType;
495+
pub const setMargin = Interface.setMargin;
496+
pub const getMargin = Interface.getMargin;
497+
pub const isPolyhedral = Interface.isPolyhedral;
498+
pub const isConvex2d = Interface.isConvex2d;
499+
pub const isConvex = Interface.isConvex;
500+
pub const isNonMoving = Interface.isNonMoving;
501+
pub const isConcave = Interface.isConcave;
502+
pub const isCompound = Interface.isCompound;
503+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
504+
pub const setUserPointer = Interface.setUserPointer;
505+
pub const getUserPointer = Interface.getUserPointer;
506+
pub const setUserIndex = Interface.setUserIndex;
507+
pub const getUserIndex = Interface.getUserIndex;
455508

456509
fn alloc() BoxShape {
457510
return @as(BoxShape, @ptrCast(ShapeImpl.alloc(.box)));
@@ -474,7 +527,26 @@ pub fn initSphereShape(radius: f32) SphereShape {
474527
}
475528

476529
const SphereShapeImpl = opaque {
477-
pub usingnamespace ShapeFunctions(SphereShape);
530+
const Interface = ShapeInterface(SphereShape);
531+
pub const asShape = Interface.asShape;
532+
pub const dealloc = Interface.dealloc;
533+
pub const destroy = Interface.destroy;
534+
pub const deinit = Interface.deinit;
535+
pub const isCreated = Interface.isCreated;
536+
pub const getType = Interface.getType;
537+
pub const setMargin = Interface.setMargin;
538+
pub const getMargin = Interface.getMargin;
539+
pub const isPolyhedral = Interface.isPolyhedral;
540+
pub const isConvex2d = Interface.isConvex2d;
541+
pub const isConvex = Interface.isConvex;
542+
pub const isNonMoving = Interface.isNonMoving;
543+
pub const isConcave = Interface.isConcave;
544+
pub const isCompound = Interface.isCompound;
545+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
546+
pub const setUserPointer = Interface.setUserPointer;
547+
pub const getUserPointer = Interface.getUserPointer;
548+
pub const setUserIndex = Interface.setUserIndex;
549+
pub const getUserIndex = Interface.getUserIndex;
478550

479551
fn alloc() SphereShape {
480552
return @as(SphereShape, @ptrCast(ShapeImpl.alloc(.sphere)));
@@ -497,7 +569,26 @@ pub fn initCapsuleShape(radius: f32, height: f32, upaxis: Axis) CapsuleShape {
497569
}
498570

499571
const CapsuleShapeImpl = opaque {
500-
pub usingnamespace ShapeFunctions(CapsuleShape);
572+
const Interface = ShapeInterface(CapsuleShape);
573+
pub const asShape = Interface.asShape;
574+
pub const dealloc = Interface.dealloc;
575+
pub const destroy = Interface.destroy;
576+
pub const deinit = Interface.deinit;
577+
pub const isCreated = Interface.isCreated;
578+
pub const getType = Interface.getType;
579+
pub const setMargin = Interface.setMargin;
580+
pub const getMargin = Interface.getMargin;
581+
pub const isPolyhedral = Interface.isPolyhedral;
582+
pub const isConvex2d = Interface.isConvex2d;
583+
pub const isConvex = Interface.isConvex;
584+
pub const isNonMoving = Interface.isNonMoving;
585+
pub const isConcave = Interface.isConcave;
586+
pub const isCompound = Interface.isCompound;
587+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
588+
pub const setUserPointer = Interface.setUserPointer;
589+
pub const getUserPointer = Interface.getUserPointer;
590+
pub const setUserIndex = Interface.setUserIndex;
591+
pub const getUserIndex = Interface.getUserIndex;
501592

502593
fn alloc() CapsuleShape {
503594
return @as(CapsuleShape, @ptrCast(ShapeImpl.alloc(.capsule)));
@@ -531,7 +622,26 @@ pub fn initCylinderShape(
531622
}
532623

533624
const CylinderShapeImpl = opaque {
534-
pub usingnamespace ShapeFunctions(CylinderShape);
625+
const Interface = ShapeInterface(CylinderShape);
626+
pub const asShape = Interface.asShape;
627+
pub const dealloc = Interface.dealloc;
628+
pub const destroy = Interface.destroy;
629+
pub const deinit = Interface.deinit;
630+
pub const isCreated = Interface.isCreated;
631+
pub const getType = Interface.getType;
632+
pub const setMargin = Interface.setMargin;
633+
pub const getMargin = Interface.getMargin;
634+
pub const isPolyhedral = Interface.isPolyhedral;
635+
pub const isConvex2d = Interface.isConvex2d;
636+
pub const isConvex = Interface.isConvex;
637+
pub const isNonMoving = Interface.isNonMoving;
638+
pub const isConcave = Interface.isConcave;
639+
pub const isCompound = Interface.isCompound;
640+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
641+
pub const setUserPointer = Interface.setUserPointer;
642+
pub const getUserPointer = Interface.getUserPointer;
643+
pub const setUserIndex = Interface.setUserIndex;
644+
pub const getUserIndex = Interface.getUserIndex;
535645

536646
fn alloc() CylinderShape {
537647
return @as(CylinderShape, @ptrCast(ShapeImpl.alloc(.cylinder)));
@@ -561,7 +671,26 @@ const CylinderShapeImpl = opaque {
561671
};
562672

563673
const ConvexHullShapeImpl = opaque {
564-
pub usingnamespace ShapeFunctions(ConvexHullShape);
674+
const Interface = ShapeInterface(ConvexHullShape);
675+
pub const asShape = Interface.asShape;
676+
pub const dealloc = Interface.dealloc;
677+
pub const destroy = Interface.destroy;
678+
pub const deinit = Interface.deinit;
679+
pub const isCreated = Interface.isCreated;
680+
pub const getType = Interface.getType;
681+
pub const setMargin = Interface.setMargin;
682+
pub const getMargin = Interface.getMargin;
683+
pub const isPolyhedral = Interface.isPolyhedral;
684+
pub const isConvex2d = Interface.isConvex2d;
685+
pub const isConvex = Interface.isConvex;
686+
pub const isNonMoving = Interface.isNonMoving;
687+
pub const isConcave = Interface.isConcave;
688+
pub const isCompound = Interface.isCompound;
689+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
690+
pub const setUserPointer = Interface.setUserPointer;
691+
pub const getUserPointer = Interface.getUserPointer;
692+
pub const setUserIndex = Interface.setUserIndex;
693+
pub const getUserIndex = Interface.getUserIndex;
565694

566695
fn alloc() ConvexHullShape {
567696
return @as(ConvexHullShape, @ptrCast(ShapeImpl.alloc(.convex_hull)));
@@ -606,7 +735,26 @@ pub fn initCompoundShape(
606735
}
607736

608737
const CompoundShapeImpl = opaque {
609-
pub usingnamespace ShapeFunctions(CompoundShape);
738+
const Interface = ShapeInterface(CompoundShape);
739+
pub const asShape = Interface.asShape;
740+
pub const dealloc = Interface.dealloc;
741+
pub const destroy = Interface.destroy;
742+
pub const deinit = Interface.deinit;
743+
pub const isCreated = Interface.isCreated;
744+
pub const getType = Interface.getType;
745+
pub const setMargin = Interface.setMargin;
746+
pub const getMargin = Interface.getMargin;
747+
pub const isPolyhedral = Interface.isPolyhedral;
748+
pub const isConvex2d = Interface.isConvex2d;
749+
pub const isConvex = Interface.isConvex;
750+
pub const isNonMoving = Interface.isNonMoving;
751+
pub const isConcave = Interface.isConcave;
752+
pub const isCompound = Interface.isCompound;
753+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
754+
pub const setUserPointer = Interface.setUserPointer;
755+
pub const getUserPointer = Interface.getUserPointer;
756+
pub const setUserIndex = Interface.setUserIndex;
757+
pub const getUserIndex = Interface.getUserIndex;
610758

611759
fn alloc() CompoundShape {
612760
return @as(CompoundShape, @ptrCast(ShapeImpl.alloc(.compound)));
@@ -653,7 +801,26 @@ pub fn initTriangleMeshShape() TriangleMeshShape {
653801
}
654802

655803
const TriangleMeshShapeImpl = opaque {
656-
pub usingnamespace ShapeFunctions(TriangleMeshShape);
804+
const Interface = ShapeInterface(TriangleMeshShape);
805+
pub const asShape = Interface.asShape;
806+
pub const dealloc = Interface.dealloc;
807+
pub const destroy = Interface.destroy;
808+
pub const deinit = Interface.deinit;
809+
pub const isCreated = Interface.isCreated;
810+
pub const getType = Interface.getType;
811+
pub const setMargin = Interface.setMargin;
812+
pub const getMargin = Interface.getMargin;
813+
pub const isPolyhedral = Interface.isPolyhedral;
814+
pub const isConvex2d = Interface.isConvex2d;
815+
pub const isConvex = Interface.isConvex;
816+
pub const isNonMoving = Interface.isNonMoving;
817+
pub const isConcave = Interface.isConcave;
818+
pub const isCompound = Interface.isCompound;
819+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
820+
pub const setUserPointer = Interface.setUserPointer;
821+
pub const getUserPointer = Interface.getUserPointer;
822+
pub const setUserIndex = Interface.setUserIndex;
823+
pub const getUserIndex = Interface.getUserIndex;
657824

658825
pub fn finish(trimesh: TriangleMeshShape) void {
659826
trimesh.createEnd();
@@ -909,47 +1076,22 @@ const ConstraintImpl = opaque {
9091076
extern fn cbtConSetDebugDrawSize(con: Constraint, size: f32) void;
9101077
};
9111078

912-
fn ConstraintFunctions(comptime T: type) type {
913-
return struct {
914-
pub fn asConstraint(con: T) Constraint {
915-
return @as(Constraint, @ptrCast(con));
916-
}
917-
pub fn dealloc(con: T) void {
918-
con.asConstraint().dealloc();
919-
}
920-
pub fn destroy(con: T) void {
921-
con.asConstraint().destroy();
922-
}
923-
pub fn getType(con: T) ConstraintType {
924-
return con.asConstraint().getType();
925-
}
926-
pub fn isCreated(con: T) bool {
927-
return con.asConstraint().isCreated();
928-
}
929-
pub fn setEnabled(con: T, enabled: bool) void {
930-
con.asConstraint().setEnabled(enabled);
931-
}
932-
pub fn isEnabled(con: T) bool {
933-
return con.asConstraint().isEnabled();
934-
}
935-
pub fn getBodyA(con: T) Body {
936-
return con.asConstraint().getBodyA();
937-
}
938-
pub fn getBodyB(con: T) Body {
939-
return con.asConstraint().getBodyB();
940-
}
941-
pub fn setDebugDrawSize(con: T, size: f32) void {
942-
con.asConstraint().setDebugDrawSize(size);
943-
}
944-
};
945-
}
946-
9471079
pub fn allocPoint2PointConstraint() Point2PointConstraint {
9481080
return Point2PointConstraintImpl.alloc();
9491081
}
9501082

9511083
const Point2PointConstraintImpl = opaque {
952-
pub usingnamespace ConstraintFunctions(Point2PointConstraint);
1084+
const Interface = ConstraintInterface(Point2PointConstraint);
1085+
pub const asConstraint = Interface.asConstraint;
1086+
pub const dealloc = Interface.dealloc;
1087+
pub const destroy = Interface.destroy;
1088+
pub const getType = Interface.getType;
1089+
pub const isCreated = Interface.isCreated;
1090+
pub const setEnabled = Interface.setEnabled;
1091+
pub const isEnabled = Interface.isEnabled;
1092+
pub const getBodyA = Interface.getBodyA;
1093+
pub const getBodyB = Interface.getBodyB;
1094+
pub const setDebugDrawSize = Interface.setDebugDrawSize;
9531095

9541096
fn alloc() Point2PointConstraint {
9551097
return @as(Point2PointConstraint, @ptrCast(ConstraintImpl.alloc(.point2point)));

0 commit comments

Comments
 (0)