6 Commits

Author SHA1 Message Date
96c55ad30d Add flag to say if pvd is supported 2022-12-07 06:38:33 +04:00
dd5a42c760 Support both checked and release modes 2022-12-07 06:34:13 +04:00
ceabe5d59b Flag to disable pvd 2022-12-07 06:06:49 +04:00
7e63090cb1 Move to go 1.18 2022-12-07 03:24:25 +04:00
8e358fb31f Correct DefaultCpuDispatcherCreate 2022-12-07 01:45:28 +04:00
6880bac72a Add PvdSceneClient.Release 2022-12-07 00:53:27 +04:00
10 changed files with 64 additions and 22 deletions

4
go.mod
View File

@ -1,5 +1,5 @@
module github.com/bloeys/physx-go
go 1.17
go 1.18
require github.com/bloeys/gglm v0.3.1
require github.com/bloeys/gglm v0.43.0

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/bloeys/gglm v0.3.1 h1:Sy9upW7SBsBfDXrSmEhid3aQ+7J7itej+upwcxOnPMQ=
github.com/bloeys/gglm v0.3.1/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk=
github.com/bloeys/gglm v0.43.0 h1:ZpOghR3PHfpkigTDh+FqxLsF0gN8CD6s/bWoei6LyxI=
github.com/bloeys/gglm v0.43.0/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk=

33
main.go
View File

@ -20,15 +20,19 @@ func contactHandler(cph pgo.ContactPairHeader) {
}
func main() {
f := pgo.CreateFoundation()
println("foundation:", f)
pvdTr := pgo.DefaultPvdSocketTransportCreate("127.0.0.1", 5425, 100000)
println("Pvd transport:", pvdTr)
var pvd *pgo.Pvd
if pgo.PvdSupported {
pvdTr := pgo.DefaultPvdSocketTransportCreate("127.0.0.1", 5425, 100000)
println("Pvd transport:", pvdTr)
pvd := pgo.CreatePvd(f)
println("Pvd:", pvd)
println("connected to PVD:", pvd.Connect(pvdTr, pgo.PvdInstrumentationFlag_eALL))
pvd = pgo.CreatePvd(f)
println("Pvd:", pvd)
println("connected to PVD:", pvd.Connect(pvdTr, pgo.PvdInstrumentationFlag_eALL))
}
ts := pgo.NewTolerancesScale(1, 9.81)
p := pgo.CreatePhysics(f, ts, false, pvd)
@ -36,18 +40,21 @@ func main() {
sd := pgo.NewSceneDesc(ts)
sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, nil).ToCpuDispatcher())
sd.SetOnContactCallback(contactHandler)
scene := p.CreateScene(sd)
println("Scene:", scene)
scenePvdClient := scene.GetScenePvdClient()
println("ScenePvdClient:", scenePvdClient)
if pgo.PvdSupported {
scenePvdClient := scene.GetScenePvdClient()
println("ScenePvdClient:", scenePvdClient)
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONSTRAINTS, true)
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONTACTS, true)
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_SCENEQUERIES, true)
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONSTRAINTS, true)
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONTACTS, true)
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_SCENEQUERIES, true)
scenePvdClient.Release()
}
//Add plane
pMat := p.CreateMaterial(0.5, 0.5, 0.6)
@ -148,8 +155,4 @@ func main() {
// println("Press enter...")
// r.ReadBytes('\n')
}
// p.Release()
// pvd.Release()
// pvdTr.Release()
}

5
pgo/consts_checked.go Executable file
View File

@ -0,0 +1,5 @@
//go:build !physx_release
package pgo
const PvdSupported = true

5
pgo/consts_release.go Executable file
View File

@ -0,0 +1,5 @@
//go:build physx_release
package pgo
const PvdSupported = false

Binary file not shown.

View File

@ -2,7 +2,11 @@ package pgo
/*
#cgo CFLAGS: -I physx-c
#cgo LDFLAGS: -L ./libs -l physx-c
#cgo LDFLAGS: -L ./libs
// NOTE: If you change this update rigiddynamic.go as well
#cgo windows,amd64 LDFLAGS: -l physxc_checked_windows_amd64
#cgo windows,amd64,physx_release LDFLAGS: -l physxc_release_windows_amd64
#include <wrap.c>
#include <stdlib.h> //Needed for C.free
@ -362,9 +366,24 @@ func (d *DefaultCpuDispatcher) ToCpuDispatcher() *CpuDispatcher {
return &CpuDispatcher{cCpuDisp: (*C.struct_CPxCpuDispatcher)(d.cDefCpuDisp)}
}
func DefaultCpuDispatcherCreate(numThreads, affinityMasks uint32) *DefaultCpuDispatcher {
// DefaultCpuDispatcherCreate sets the number of threads used by physX.
// If affinityMasksPerThread is nil/zero then default masks are used, otherwise the size of the array
// must match the number of threads
func DefaultCpuDispatcherCreate(numThreads uint32, affinityMasksPerThread []uint32) *DefaultCpuDispatcher {
if len(affinityMasksPerThread) == 0 {
return &DefaultCpuDispatcher{
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), nil),
}
}
arr := make([]C.uint, len(affinityMasksPerThread))
for i := 0; i < len(arr); i++ {
arr[i] = C.uint(affinityMasksPerThread[i])
}
return &DefaultCpuDispatcher{
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), C.uint(affinityMasks)),
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), &arr[0]),
}
}
@ -510,6 +529,10 @@ func (p *PvdSceneClient) SetScenePvdFlag(flag PvdSceneFlag, value bool) {
C.CPxPvdSceneClient_setScenePvdFlag(p.cPvdSceneClient, uint32(flag), C._Bool(value))
}
func (p *PvdSceneClient) Release() {
C.CPxPvdSceneClient_release(p.cPvdSceneClient)
}
type Material struct {
cM *C.struct_CPxMaterial
}

View File

@ -11,7 +11,7 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32 affinityMasks);
CPxAPI CSTRUCT CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32* affinityMasks);
CPxAPI CSTRUCT CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(CSTRUCT CPxDefaultCpuDispatcher* cdcd);
CPxAPI void CPxDefaultCpuDispatcher_release(CSTRUCT CPxDefaultCpuDispatcher* cdcd);

View File

@ -2,7 +2,11 @@ package pgo
/*
#cgo CFLAGS: -I physx-c
#cgo LDFLAGS: -L ./libs -l physx-c
#cgo LDFLAGS: -L ./libs
// NOTE: If you change this update pgo.go as well
#cgo windows,amd64 LDFLAGS: -l physxc_checked_windows_amd64
#cgo windows,amd64,physx_release LDFLAGS: -l physxc_release_windows_amd64
#include <wrap.c>
#include <stdlib.h> //Needed for C.free