Skip to content

Commit ed8016c

Browse files
committed
Remove usingnamespace usage
1 parent 092c2ab commit ed8016c

File tree

1 file changed

+173
-47
lines changed

1 file changed

+173
-47
lines changed

src/zbullet.zig

Lines changed: 173 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);
@@ -451,7 +450,26 @@ pub fn initBoxShape(half_extents: *const [3]f32) BoxShape {
451450
}
452451

453452
const BoxShapeImpl = opaque {
454-
pub usingnamespace ShapeFunctions(BoxShape);
453+
const Interface = ShapeInterface(BoxShape);
454+
pub const asShape = Interface.asShape;
455+
pub const dealloc = Interface.dealloc;
456+
pub const destroy = Interface.destroy;
457+
pub const deinit = Interface.deinit;
458+
pub const isCreated = Interface.isCreated;
459+
pub const getType = Interface.getType;
460+
pub const setMargin = Interface.setMargin;
461+
pub const getMargin = Interface.getMargin;
462+
pub const isPolyhedral = Interface.isPolyhedral;
463+
pub const isConvex2d = Interface.isConvex2d;
464+
pub const isConvex = Interface.isConvex;
465+
pub const isNonMoving = Interface.isNonMoving;
466+
pub const isConcave = Interface.isConcave;
467+
pub const isCompound = Interface.isCompound;
468+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
469+
pub const setUserPointer = Interface.setUserPointer;
470+
pub const getUserPointer = Interface.getUserPointer;
471+
pub const setUserIndex = Interface.setUserIndex;
472+
pub const getUserIndex = Interface.getUserIndex;
455473

456474
fn alloc() BoxShape {
457475
return @as(BoxShape, @ptrCast(ShapeImpl.alloc(.box)));
@@ -474,7 +492,26 @@ pub fn initSphereShape(radius: f32) SphereShape {
474492
}
475493

476494
const SphereShapeImpl = opaque {
477-
pub usingnamespace ShapeFunctions(SphereShape);
495+
const Interface = ShapeInterface(SphereShape);
496+
pub const asShape = Interface.asShape;
497+
pub const dealloc = Interface.dealloc;
498+
pub const destroy = Interface.destroy;
499+
pub const deinit = Interface.deinit;
500+
pub const isCreated = Interface.isCreated;
501+
pub const getType = Interface.getType;
502+
pub const setMargin = Interface.setMargin;
503+
pub const getMargin = Interface.getMargin;
504+
pub const isPolyhedral = Interface.isPolyhedral;
505+
pub const isConvex2d = Interface.isConvex2d;
506+
pub const isConvex = Interface.isConvex;
507+
pub const isNonMoving = Interface.isNonMoving;
508+
pub const isConcave = Interface.isConcave;
509+
pub const isCompound = Interface.isCompound;
510+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
511+
pub const setUserPointer = Interface.setUserPointer;
512+
pub const getUserPointer = Interface.getUserPointer;
513+
pub const setUserIndex = Interface.setUserIndex;
514+
pub const getUserIndex = Interface.getUserIndex;
478515

479516
fn alloc() SphereShape {
480517
return @as(SphereShape, @ptrCast(ShapeImpl.alloc(.sphere)));
@@ -497,7 +534,26 @@ pub fn initCapsuleShape(radius: f32, height: f32, upaxis: Axis) CapsuleShape {
497534
}
498535

499536
const CapsuleShapeImpl = opaque {
500-
pub usingnamespace ShapeFunctions(CapsuleShape);
537+
const Interface = ShapeInterface(CapsuleShape);
538+
pub const asShape = Interface.asShape;
539+
pub const dealloc = Interface.dealloc;
540+
pub const destroy = Interface.destroy;
541+
pub const deinit = Interface.deinit;
542+
pub const isCreated = Interface.isCreated;
543+
pub const getType = Interface.getType;
544+
pub const setMargin = Interface.setMargin;
545+
pub const getMargin = Interface.getMargin;
546+
pub const isPolyhedral = Interface.isPolyhedral;
547+
pub const isConvex2d = Interface.isConvex2d;
548+
pub const isConvex = Interface.isConvex;
549+
pub const isNonMoving = Interface.isNonMoving;
550+
pub const isConcave = Interface.isConcave;
551+
pub const isCompound = Interface.isCompound;
552+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
553+
pub const setUserPointer = Interface.setUserPointer;
554+
pub const getUserPointer = Interface.getUserPointer;
555+
pub const setUserIndex = Interface.setUserIndex;
556+
pub const getUserIndex = Interface.getUserIndex;
501557

502558
fn alloc() CapsuleShape {
503559
return @as(CapsuleShape, @ptrCast(ShapeImpl.alloc(.capsule)));
@@ -531,7 +587,26 @@ pub fn initCylinderShape(
531587
}
532588

533589
const CylinderShapeImpl = opaque {
534-
pub usingnamespace ShapeFunctions(CylinderShape);
590+
const Interface = ShapeInterface(CylinderShape);
591+
pub const asShape = Interface.asShape;
592+
pub const dealloc = Interface.dealloc;
593+
pub const destroy = Interface.destroy;
594+
pub const deinit = Interface.deinit;
595+
pub const isCreated = Interface.isCreated;
596+
pub const getType = Interface.getType;
597+
pub const setMargin = Interface.setMargin;
598+
pub const getMargin = Interface.getMargin;
599+
pub const isPolyhedral = Interface.isPolyhedral;
600+
pub const isConvex2d = Interface.isConvex2d;
601+
pub const isConvex = Interface.isConvex;
602+
pub const isNonMoving = Interface.isNonMoving;
603+
pub const isConcave = Interface.isConcave;
604+
pub const isCompound = Interface.isCompound;
605+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
606+
pub const setUserPointer = Interface.setUserPointer;
607+
pub const getUserPointer = Interface.getUserPointer;
608+
pub const setUserIndex = Interface.setUserIndex;
609+
pub const getUserIndex = Interface.getUserIndex;
535610

536611
fn alloc() CylinderShape {
537612
return @as(CylinderShape, @ptrCast(ShapeImpl.alloc(.cylinder)));
@@ -561,7 +636,26 @@ const CylinderShapeImpl = opaque {
561636
};
562637

563638
const ConvexHullShapeImpl = opaque {
564-
pub usingnamespace ShapeFunctions(ConvexHullShape);
639+
const Interface = ShapeInterface(ConvexHullShape);
640+
pub const asShape = Interface.asShape;
641+
pub const dealloc = Interface.dealloc;
642+
pub const destroy = Interface.destroy;
643+
pub const deinit = Interface.deinit;
644+
pub const isCreated = Interface.isCreated;
645+
pub const getType = Interface.getType;
646+
pub const setMargin = Interface.setMargin;
647+
pub const getMargin = Interface.getMargin;
648+
pub const isPolyhedral = Interface.isPolyhedral;
649+
pub const isConvex2d = Interface.isConvex2d;
650+
pub const isConvex = Interface.isConvex;
651+
pub const isNonMoving = Interface.isNonMoving;
652+
pub const isConcave = Interface.isConcave;
653+
pub const isCompound = Interface.isCompound;
654+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
655+
pub const setUserPointer = Interface.setUserPointer;
656+
pub const getUserPointer = Interface.getUserPointer;
657+
pub const setUserIndex = Interface.setUserIndex;
658+
pub const getUserIndex = Interface.getUserIndex;
565659

566660
fn alloc() ConvexHullShape {
567661
return @as(ConvexHullShape, @ptrCast(ShapeImpl.alloc(.convex_hull)));
@@ -606,7 +700,26 @@ pub fn initCompoundShape(
606700
}
607701

608702
const CompoundShapeImpl = opaque {
609-
pub usingnamespace ShapeFunctions(CompoundShape);
703+
const Interface = ShapeInterface(CompoundShape);
704+
pub const asShape = Interface.asShape;
705+
pub const dealloc = Interface.dealloc;
706+
pub const destroy = Interface.destroy;
707+
pub const deinit = Interface.deinit;
708+
pub const isCreated = Interface.isCreated;
709+
pub const getType = Interface.getType;
710+
pub const setMargin = Interface.setMargin;
711+
pub const getMargin = Interface.getMargin;
712+
pub const isPolyhedral = Interface.isPolyhedral;
713+
pub const isConvex2d = Interface.isConvex2d;
714+
pub const isConvex = Interface.isConvex;
715+
pub const isNonMoving = Interface.isNonMoving;
716+
pub const isConcave = Interface.isConcave;
717+
pub const isCompound = Interface.isCompound;
718+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
719+
pub const setUserPointer = Interface.setUserPointer;
720+
pub const getUserPointer = Interface.getUserPointer;
721+
pub const setUserIndex = Interface.setUserIndex;
722+
pub const getUserIndex = Interface.getUserIndex;
610723

611724
fn alloc() CompoundShape {
612725
return @as(CompoundShape, @ptrCast(ShapeImpl.alloc(.compound)));
@@ -653,7 +766,26 @@ pub fn initTriangleMeshShape() TriangleMeshShape {
653766
}
654767

655768
const TriangleMeshShapeImpl = opaque {
656-
pub usingnamespace ShapeFunctions(TriangleMeshShape);
769+
const Interface = ShapeInterface(TriangleMeshShape);
770+
pub const asShape = Interface.asShape;
771+
pub const dealloc = Interface.dealloc;
772+
pub const destroy = Interface.destroy;
773+
pub const deinit = Interface.deinit;
774+
pub const isCreated = Interface.isCreated;
775+
pub const getType = Interface.getType;
776+
pub const setMargin = Interface.setMargin;
777+
pub const getMargin = Interface.getMargin;
778+
pub const isPolyhedral = Interface.isPolyhedral;
779+
pub const isConvex2d = Interface.isConvex2d;
780+
pub const isConvex = Interface.isConvex;
781+
pub const isNonMoving = Interface.isNonMoving;
782+
pub const isConcave = Interface.isConcave;
783+
pub const isCompound = Interface.isCompound;
784+
pub const calculateLocalInertia = Interface.calculateLocalInertia;
785+
pub const setUserPointer = Interface.setUserPointer;
786+
pub const getUserPointer = Interface.getUserPointer;
787+
pub const setUserIndex = Interface.setUserIndex;
788+
pub const getUserIndex = Interface.getUserIndex;
657789

658790
pub fn finish(trimesh: TriangleMeshShape) void {
659791
trimesh.createEnd();
@@ -909,47 +1041,41 @@ const ConstraintImpl = opaque {
9091041
extern fn cbtConSetDebugDrawSize(con: Constraint, size: f32) void;
9101042
};
9111043

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-
9471044
pub fn allocPoint2PointConstraint() Point2PointConstraint {
9481045
return Point2PointConstraintImpl.alloc();
9491046
}
9501047

9511048
const Point2PointConstraintImpl = opaque {
952-
pub usingnamespace ConstraintFunctions(Point2PointConstraint);
1049+
pub fn asConstraint(con: Point2PointConstraint) Constraint {
1050+
return @as(Constraint, @ptrCast(con));
1051+
}
1052+
pub fn dealloc(con: Point2PointConstraint) void {
1053+
con.asConstraint().dealloc();
1054+
}
1055+
pub fn destroy(con: Point2PointConstraint) void {
1056+
con.asConstraint().destroy();
1057+
}
1058+
pub fn getType(con: Point2PointConstraint) ConstraintType {
1059+
return con.asConstraint().getType();
1060+
}
1061+
pub fn isCreated(con: Point2PointConstraint) bool {
1062+
return con.asConstraint().isCreated();
1063+
}
1064+
pub fn setEnabled(con: Point2PointConstraint, enabled: bool) void {
1065+
con.asConstraint().setEnabled(enabled);
1066+
}
1067+
pub fn isEnabled(con: Point2PointConstraint) bool {
1068+
return con.asConstraint().isEnabled();
1069+
}
1070+
pub fn getBodyA(con: Point2PointConstraint) Body {
1071+
return con.asConstraint().getBodyA();
1072+
}
1073+
pub fn getBodyB(con: Point2PointConstraint) Body {
1074+
return con.asConstraint().getBodyB();
1075+
}
1076+
pub fn setDebugDrawSize(con: Point2PointConstraint, size: f32) void {
1077+
con.asConstraint().setDebugDrawSize(size);
1078+
}
9531079

9541080
fn alloc() Point2PointConstraint {
9551081
return @as(Point2PointConstraint, @ptrCast(ConstraintImpl.alloc(.point2point)));

0 commit comments

Comments
 (0)