Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87dbfd0

Browse files
authored
Merge pull request#16 from kcbanner/writer_fixup
New writer API, batch body adding bindings
2 parents1b4717b +9106492 commit87dbfd0

File tree

4 files changed

+112
-31
lines changed

4 files changed

+112
-31
lines changed

‎build.zig.zon‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name=.zphysics,
33
.fingerprint=0x1def6aac00c4909d,
44
.version="0.2.0-dev",
5-
.minimum_zig_version="0.14.0",
5+
.minimum_zig_version="0.15.1",
66
.paths= .{
77
"build.zig",
88
"build.zig.zon",

‎libs/JoltC/JoltPhysicsC.cpp‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ FN(toJpc)(JPH::CollisionGroup *in) { assert(in); return reinterpret_cast<JPC_Col
302302

303303
FN(toJph)(const JPC_SubShapeID *in) {assert(in);returnreinterpret_cast<const JPH::SubShapeID *>(in); }
304304
FN(toJph)(const JPC_BodyID *in) {assert(in);returnreinterpret_cast<const JPH::BodyID *>(in); }
305+
FN(toJph)(JPC_BodyID *in) {assert(in);returnreinterpret_cast<JPH::BodyID *>(in); }
305306

306307
FN(toJpc)(const JPH::SubShapeIDCreator *in) {assert(in);returnreinterpret_cast<const JPC_SubShapeIDCreator *>(in); }
307308
FN(toJph)(const JPC_SubShapeIDCreator *in) {assert(in);returnreinterpret_cast<const JPH::SubShapeIDCreator *>(in); }
@@ -353,6 +354,9 @@ FN(toJph)(const JPC_BodyInterface *in) { assert(in); return reinterpret_cast<con
353354
FN(toJpc)(JPH::BodyInterface *in) {assert(in);returnreinterpret_cast<JPC_BodyInterface *>(in); }
354355
FN(toJph)(JPC_BodyInterface *in) {assert(in);returnreinterpret_cast<JPH::BodyInterface *>(in); }
355356

357+
FN(toJpc)(JPH::BodyInterface::AddState in) {assert(in);returnreinterpret_cast<JPC_BodyInterface_AddState* >(in); }
358+
FN(toJph)(JPC_BodyInterface_AddState* in) {assert(in);returnreinterpret_cast<JPH::BodyInterface::AddState >(in); }
359+
356360
FN(toJpc)(const JPH::TransformedShape *in) {assert(in);returnreinterpret_cast<const JPC_TransformedShape *>(in); }
357361

358362
FN(toJph)(const JPC_MassProperties *in) {assert(in);returnreinterpret_cast<const JPH::MassProperties *>(in); }
@@ -2356,6 +2360,31 @@ JPC_BodyInterface_DestroyBody(JPC_BodyInterface *in_iface, JPC_BodyID in_body_id
23562360
}
23572361
//--------------------------------------------------------------------------------------------------
23582362
JPC_APIvoid
2363+
JPC_BodyInterface_AddBodiesAbort(JPC_BodyInterface *in_iface,
2364+
JPC_BodyID* in_body_ids,
2365+
int in_num_bodies,
2366+
JPC_BodyInterface_AddState* add_state)
2367+
{
2368+
returntoJph(in_iface)->AddBodiesAbort(toJph(in_body_ids), in_num_bodies,toJph(add_state));
2369+
}
2370+
//--------------------------------------------------------------------------------------------------
2371+
JPC_APIvoid
2372+
JPC_BodyInterface_AddBodiesFinalize(JPC_BodyInterface *in_iface,
2373+
JPC_BodyID* in_body_ids,
2374+
int in_num_bodies,
2375+
JPC_BodyInterface_AddState* add_state,
2376+
JPC_Activation in_mode)
2377+
{
2378+
returntoJph(in_iface)->AddBodiesFinalize(toJph(in_body_ids), in_num_bodies,toJph(add_state),static_cast<JPH::EActivation>(in_mode));
2379+
}
2380+
//--------------------------------------------------------------------------------------------------
2381+
JPC_API JPC_BodyInterface_AddState*
2382+
JPC_BodyInterface_AddBodiesPrepare(JPC_BodyInterface *in_iface, JPC_BodyID* in_body_ids,int in_num_bodies)
2383+
{
2384+
returntoJpc(toJph(in_iface)->AddBodiesPrepare(toJph(in_body_ids), in_num_bodies));
2385+
}
2386+
//--------------------------------------------------------------------------------------------------
2387+
JPC_APIvoid
23592388
JPC_BodyInterface_AddBody(JPC_BodyInterface *in_iface, JPC_BodyID in_body_id, JPC_Activation in_mode)
23602389
{
23612390
toJph(in_iface)->AddBody(toJph(in_body_id),static_cast<JPH::EActivation>(in_mode));

‎libs/JoltC/JoltPhysicsC.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ typedef bool (*JPC_AssertFailedFunction)(
330330
typedefstructJPC_TempAllocator JPC_TempAllocator;
331331
typedefstructJPC_JobSystem JPC_JobSystem;
332332
typedefstructJPC_BodyInterface JPC_BodyInterface;
333+
typedefstructJPC_BodyInterface_AddState JPC_BodyInterface_AddState;
333334
typedefstructJPC_BodyLockInterface JPC_BodyLockInterface;
334335
typedefstructJPC_NarrowPhaseQuery JPC_NarrowPhaseQuery;
335336

@@ -2026,6 +2027,22 @@ JPC_BodyInterface_CreateBodyWithID(JPC_BodyInterface *in_iface,
20262027
JPC_APIvoid
20272028
JPC_BodyInterface_DestroyBody(JPC_BodyInterface *in_iface, JPC_BodyID in_body_id);
20282029

2030+
JPC_APIvoid
2031+
JPC_BodyInterface_AddBodiesAbort(JPC_BodyInterface *in_iface,
2032+
JPC_BodyID* in_body_ids,
2033+
int in_num_bodies,
2034+
JPC_BodyInterface_AddState* add_state);
2035+
2036+
JPC_APIvoid
2037+
JPC_BodyInterface_AddBodiesFinalize(JPC_BodyInterface *in_iface,
2038+
JPC_BodyID* in_body_ids,
2039+
int in_num_bodies,
2040+
JPC_BodyInterface_AddState* add_state,
2041+
JPC_Activation in_mode);
2042+
2043+
JPC_API JPC_BodyInterface_AddState*
2044+
JPC_BodyInterface_AddBodiesPrepare(JPC_BodyInterface *in_iface, JPC_BodyID* in_body_ids,int in_num_bodies);
2045+
20292046
JPC_APIvoid
20302047
JPC_BodyInterface_AddBody(JPC_BodyInterface *in_iface, JPC_BodyID in_body_id, JPC_Activation in_mode);
20312048

‎src/zphysics.zig‎

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn initInterface(comptime T: type, comptime VTableT: type) *const VTableT {
148148
}
149149
}else {
150150
if (field.default_value_ptr)|default_value_ptr| {
151-
@field(vtable,field.name)=@as(*constfield.type,@alignCast(@ptrCast(default_value_ptr))).*;
151+
@field(vtable,field.name)=@as(*constfield.type,@ptrCast(@alignCast(default_value_ptr))).*;
152152
}else@compileError("non-pointer vtable field "++field.name++" must have a default value");
153153
}
154154
}
@@ -184,24 +184,24 @@ pub const StreamOut = extern struct {
184184
}
185185
};
186186

187-
pubconstAnyWriterStreamOut=externstruct {
187+
pubconstWriterStreamOut=externstruct {
188188
stream_out:StreamOut= .init(@This()),
189-
writer:*conststd.io.AnyWriter,
189+
writer:*std.Io.Writer,
190190
failed:bool=false,
191191

192-
pubfninit(writer:*conststd.io.AnyWriter)AnyWriterStreamOut {
192+
pubfninit(writer:*std.Io.Writer)WriterStreamOut {
193193
return .{ .writer=writer };
194194
}
195195

196196
pubfnwriteBytes(stream_out:*StreamOut,data: [*]constu8,num_bytes:usize)callconv(.c)void {
197-
constself:*AnyWriterStreamOut=@alignCast(@fieldParentPtr("stream_out",stream_out));
197+
constself:*WriterStreamOut=@alignCast(@fieldParentPtr("stream_out",stream_out));
198198
self.writer.writeAll(data[0..num_bytes])catch {
199199
self.failed=true;
200200
};
201201
}
202202

203203
pubfnisFailed(stream_out:*StreamOut)callconv(.c)bool {
204-
constself:*AnyWriterStreamOut=@alignCast(@fieldParentPtr("stream_out",stream_out));
204+
constself:*WriterStreamOut=@alignCast(@fieldParentPtr("stream_out",stream_out));
205205
returnself.failed;
206206
}
207207
};
@@ -225,19 +225,19 @@ pub const StreamIn = extern struct {
225225
}
226226
};
227227

228-
pubconstAnyReaderStreamIn=externstruct {
228+
pubconstReaderStreamIn=externstruct {
229229
stream_in:StreamIn= .init(@This()),
230-
reader:*conststd.io.AnyReader,
230+
reader:*std.Io.Reader,
231231
failed:bool=false,
232232
eof:bool=false,
233233

234-
pubfninit(reader:*conststd.io.AnyReader)AnyReaderStreamIn {
234+
pubfninit(reader:*std.Io.Reader)ReaderStreamIn {
235235
return .{ .reader=reader };
236236
}
237237

238238
pubfnreadBytes(stream_in:*StreamIn,data: [*]u8,num_bytes:usize)callconv(.c)void {
239239
constself:*@This()=@alignCast(@fieldParentPtr("stream_in",stream_in));
240-
self.reader.readNoEof(data[0..num_bytes])catch|err|switch (err) {
240+
self.reader.readSliceAll(data[0..num_bytes])catch|err|switch (err) {
241241
error.EndOfStream=>self.eof=true,
242242
else=>self.failed=true,
243243
};
@@ -1509,8 +1509,12 @@ pub const PhysicsSystem = opaque {
15091509
c.JPC_PhysicsSystem_DrawConstraintReferenceFrame(@ptrCast(physics_system));
15101510
}
15111511

1512-
pubfngetBodyIds(physics_system:*constPhysicsSystem,body_ids:*std.ArrayList(BodyId))!void {
1513-
trybody_ids.ensureTotalCapacityPrecise(physics_system.getMaxBodies());
1512+
pubfngetBodyIds(
1513+
physics_system:*constPhysicsSystem,
1514+
allocator:std.mem.Allocator,
1515+
body_ids:*std.ArrayList(BodyId),
1516+
)!void {
1517+
trybody_ids.ensureTotalCapacityPrecise(allocator,physics_system.getMaxBodies());
15141518
varnum_body_ids:u32=0;
15151519
c.JPC_PhysicsSystem_GetBodyIDs(
15161520
@as(*constc.JPC_PhysicsSystem,@ptrCast(physics_system)),
@@ -1521,8 +1525,12 @@ pub const PhysicsSystem = opaque {
15211525
body_ids.items.len=num_body_ids;
15221526
}
15231527

1524-
pubfngetActiveBodyIds(physics_system:*constPhysicsSystem,body_ids:*std.ArrayList(BodyId))!void {
1525-
trybody_ids.ensureTotalCapacityPrecise(physics_system.getMaxBodies());
1528+
pubfngetActiveBodyIds(
1529+
physics_system:*constPhysicsSystem,
1530+
allocator:std.mem.Allocator,
1531+
body_ids:*std.ArrayList(BodyId),
1532+
)!void {
1533+
trybody_ids.ensureTotalCapacityPrecise(allocator,physics_system.getMaxBodies());
15261534
varnum_body_ids:u32=0;
15271535
c.JPC_PhysicsSystem_GetActiveBodyIDs(
15281536
@as(*constc.JPC_PhysicsSystem,@ptrCast(physics_system)),
@@ -1618,6 +1626,8 @@ pub const BodyLockWrite = extern struct {
16181626
//
16191627
//--------------------------------------------------------------------------------------------------
16201628
pubconstBodyInterface=opaque {
1629+
pubconstAddState=*opaque {};
1630+
16211631
pubfncreateBody(body_iface:*BodyInterface,settings:BodyCreationSettings)!*Body {
16221632
constbody=c.JPC_BodyInterface_CreateBody(
16231633
@as(*c.JPC_BodyInterface,@ptrCast(body_iface)),
@@ -1646,6 +1656,33 @@ pub const BodyInterface = opaque {
16461656
);
16471657
}
16481658

1659+
pubfnaddBodiesAbort(body_iface:*BodyInterface,body_ids: []BodyId,add_state:AddState)void {
1660+
c.JPC_BodyInterface_AddBodiesAbort(
1661+
@as(*c.JPC_BodyInterface,@ptrCast(body_iface)),
1662+
@ptrCast(body_ids.ptr),
1663+
@intCast(body_ids.len),
1664+
@ptrCast(add_state),
1665+
);
1666+
}
1667+
1668+
pubfnaddBodiesFinalize(body_iface:*BodyInterface,body_ids: []BodyId,add_state:AddState,mode:Activation)void {
1669+
c.JPC_BodyInterface_AddBodiesFinalize(
1670+
@as(*c.JPC_BodyInterface,@ptrCast(body_iface)),
1671+
@ptrCast(body_ids.ptr),
1672+
@intCast(body_ids.len),
1673+
@ptrCast(add_state),
1674+
@intFromEnum(mode),
1675+
);
1676+
}
1677+
1678+
pubfnaddBodiesPrepare(body_iface:*BodyInterface,body_ids: []BodyId)AddState {
1679+
return@ptrCast(c.JPC_BodyInterface_AddBodiesPrepare(
1680+
@as(*c.JPC_BodyInterface,@ptrCast(body_iface)),
1681+
@ptrCast(body_ids.ptr),
1682+
@intCast(body_ids.len),
1683+
));
1684+
}
1685+
16491686
pubfnaddBody(body_iface:*BodyInterface,body_id:BodyId,mode:Activation)void {
16501687
c.JPC_BodyInterface_AddBody(
16511688
@as(*c.JPC_BodyInterface,@ptrCast(body_iface)),
@@ -3390,7 +3427,7 @@ pub const Shape = opaque {
33903427

33913428
pubfngetLocalBounds(shape:*constShape)AABox {
33923429
constaabox=c.JPC_Shape_GetLocalBounds(@ptrCast(shape));
3393-
return@as(*AABox,@constCast(@ptrCast(&aabox))).*;
3430+
return@as(*AABox,@ptrCast(@constCast(&aabox))).*;
33943431
}
33953432

33963433
pubfngetSurfaceNormal(shape:*constShape,sub_shape_id:SubShapeId,local_pos: [3]f32) [3]f32 {
@@ -4356,18 +4393,18 @@ test "zphysics.body.basic" {
43564393
}
43574394

43584395
{
4359-
varbody_ids=std.ArrayList(BodyId).init(std.testing.allocator);
4360-
deferbody_ids.deinit();
4361-
tryphysics_system.getBodyIds(&body_ids);
4396+
varbody_ids:std.ArrayList(BodyId)=.empty;
4397+
deferbody_ids.deinit(std.testing.allocator);
4398+
tryphysics_system.getBodyIds(std.testing.allocator,&body_ids);
43624399
tryexpect(body_ids.items.len==1);
43634400
tryexpect(body_ids.capacity>=physics_system.getMaxBodies());
43644401
tryexpect(body_ids.items[0]==body_id);
43654402
}
43664403

43674404
{
4368-
varbody_ids=std.ArrayList(BodyId).init(std.testing.allocator);
4369-
deferbody_ids.deinit();
4370-
tryphysics_system.getActiveBodyIds(&body_ids);
4405+
varbody_ids:std.ArrayList(BodyId)=.empty;
4406+
deferbody_ids.deinit(std.testing.allocator);
4407+
tryphysics_system.getActiveBodyIds(std.testing.allocator,&body_ids);
43714408
tryexpect(body_ids.items.len==0);
43724409
tryexpect(body_ids.capacity>=physics_system.getMaxBodies());
43734410
}
@@ -4599,20 +4636,18 @@ test "zphysics.serialization" {
45994636
constshape=tryshape_settings.asShapeSettings().createShape();
46004637
defershape.release();
46014638

4602-
varbuf:std.ArrayListUnmanaged(u8)= .{};
4603-
deferbuf.deinit(std.testing.allocator);
4639+
varbuf:std.Io.Writer.Allocating= .init(std.testing.allocator);
4640+
deferbuf.deinit();
46044641

46054642
{
4606-
constwriter=buf.writer(std.testing.allocator).any();
4607-
varstream_out=AnyWriterStreamOut.init(&writer);
4643+
varstream_out=WriterStreamOut.init(&buf.writer);
46084644
shape.saveBinaryState(@ptrCast(&stream_out));
4609-
trystd.testing.expectEqual(1+8+4+12+4,buf.items.len);
4645+
trystd.testing.expectEqual(1+8+4+12+4,buf.written().len);
46104646
}
46114647

46124648
{
4613-
varstream=std.io.fixedBufferStream(buf.items);
4614-
constreader=stream.reader().any();
4615-
varstream_in=AnyReaderStreamIn.init(&reader);
4649+
varreader:std.Io.Reader= .fixed(buf.written());
4650+
varstream_in=ReaderStreamIn.init(&reader);
46164651
constshape_restored=tryShape.restoreFromBinaryState(@ptrCast(&stream_in));
46174652
defershape_restored.release();
46184653

@@ -4795,7 +4830,7 @@ const test_cb1 = struct {
47954830
batch:*anyopaque,
47964831
)callconv(.c)void {
47974832
_=self;
4798-
constprimitive:*MyRenderPrimitive=@alignCast(@ptrCast(batch));
4833+
constprimitive:*MyRenderPrimitive=@ptrCast(@alignCast(batch));
47994834
primitive.allocated=false;
48004835
}
48014836
fndrawGeometry(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp