diff --git a/main.go b/main.go index bd7b680..b10ebaa 100755 --- a/main.go +++ b/main.go @@ -1,8 +1,23 @@ package main -import "github.com/bloeys/physx-go/pgo" +import ( + "github.com/bloeys/physx-go/pgo" +) func main() { - pgo.Test() - println("Hey!!") + f := pgo.CreateFoundation() + defer f.Release() + println("foundation:", f) + + pvd := pgo.CreatePvd(f) + // defer pvd.Release() + println("Pvd:", pvd) + + pvdTr := pgo.DefaultPvdSocketTransportCreate("127.0.0.1", 9876, 500) + // defer pvdTr.Release() + println("Pvd transport:", pvdTr) + + // for { + // time.Sleep(1 / 60 * time.Second) + // } } diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index d55024c..823f088 100755 Binary files a/pgo/libs/libphysx-c.a and b/pgo/libs/libphysx-c.a differ diff --git a/pgo/pgo.go b/pgo/pgo.go index a271753..1247910 100755 --- a/pgo/pgo.go +++ b/pgo/pgo.go @@ -8,13 +8,65 @@ package pgo #include //Needed for C.free //Functions -struct CPxFoundation* NewCPxFoundation(); -void FreeCPxFoundation(struct CPxFoundation*); +struct CPxFoundation* CPxCreateFoundation(); +void CPxFoundation_release(struct CPxFoundation*); + +struct CPxPvd* CPxCreatePvd(struct CPxFoundation*); +void CPxPvd_release(struct CPxPvd*); + +struct CPxPvdTransport* CPxDefaultPvdSocketTransportCreate(const char* address, int port, int timeoutMillis); +void CPxPvdTransport_release(struct CPxPvdTransport* cppt); */ import "C" +import "unsafe" -func Test() { - x := C.NewCPxFoundation() - println("Result:", x) - C.FreeCPxFoundation(x) +type Foundation struct { + cFoundation *C.struct_CPxFoundation +} + +func (f *Foundation) Release() { + C.CPxFoundation_release(f.cFoundation) +} + +func CreateFoundation() *Foundation { + + f := &Foundation{} + f.cFoundation = C.CPxCreateFoundation() + + return f +} + +type Pvd struct { + cPvd *C.struct_CPxPvd +} + +func (p *Pvd) Release() { + C.CPxPvd_release(p.cPvd) +} + +func CreatePvd(f *Foundation) *Pvd { + + p := &Pvd{} + p.cPvd = C.CPxCreatePvd(f.cFoundation) + + return p +} + +type PvdTransport struct { + cPvdTr *C.struct_CPxPvdTransport +} + +func (p *PvdTransport) Release() { + C.CPxPvdTransport_release(p.cPvdTr) +} + +func DefaultPvdSocketTransportCreate(host string, port, timeoutMillis int) *PvdTransport { + + hostCStr := C.CString(host) + defer C.free(unsafe.Pointer(hostCStr)) + + p := &PvdTransport{} + p.cPvdTr = C.CPxDefaultPvdSocketTransportCreate(hostCStr, C.int(port), C.int(timeoutMillis)) + + return p } diff --git a/pgo/physx-c/CPxFoundation.h b/pgo/physx-c/CPxFoundation.h index 6622b70..4edbd82 100755 --- a/pgo/physx-c/CPxFoundation.h +++ b/pgo/physx-c/CPxFoundation.h @@ -9,8 +9,8 @@ extern "C" { void* obj; }; - CPxAPI CSTRUCT CPxFoundation* NewCPxFoundation(); - CPxAPI void FreeCPxFoundation(CSTRUCT CPxFoundation* cpf); + CPxAPI CSTRUCT CPxFoundation* CPxCreateFoundation(); + CPxAPI void CPxFoundation_release(CSTRUCT CPxFoundation* cpf); #ifdef __cplusplus } #endif diff --git a/pgo/physx-c/CPxPvd.h b/pgo/physx-c/CPxPvd.h new file mode 100755 index 0000000..8053702 --- /dev/null +++ b/pgo/physx-c/CPxPvd.h @@ -0,0 +1,20 @@ +#ifndef __CPxPvd_H__ +#define __CPxPvd_H__ + +#include "CPxFoundation.h" + +#ifdef __cplusplus +extern "C" { +#endif + struct CPxPvd + { + void* obj; + }; + + CPxAPI CSTRUCT CPxPvd* CPxCreatePvd(CSTRUCT CPxFoundation*); + CPxAPI void CPxPvd_release(CSTRUCT CPxPvd* cpp); +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/pgo/physx-c/CPxPvdTransport.h b/pgo/physx-c/CPxPvdTransport.h new file mode 100755 index 0000000..fdaf709 --- /dev/null +++ b/pgo/physx-c/CPxPvdTransport.h @@ -0,0 +1,18 @@ +#ifndef __CPxPvdTransport_H__ +#define __CPxPvdTransport_H__ + +#ifdef __cplusplus +extern "C" { +#endif + struct CPxPvdTransport + { + void* obj; + }; + + CPxAPI CSTRUCT CPxPvdTransport* CPxDefaultPvdSocketTransportCreate(const char* address, int port, int timeoutMillis); + CPxAPI void CPxPvdTransport_release(CSTRUCT CPxPvdTransport* cppt); +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/pgo/wrap.cxx b/pgo/wrap.cxx index 4f669a2..b120050 100755 --- a/pgo/wrap.cxx +++ b/pgo/wrap.cxx @@ -1,3 +1,4 @@ #define CPxAPI #define CSTRUCT struct #include +#include