Towards an mvp

This commit is contained in:
bloeys
2022-01-17 04:36:56 +04:00
parent 845b0612dc
commit eb8eea6c44
15 changed files with 389 additions and 15 deletions

32
main.go
View File

@ -9,15 +9,29 @@ func main() {
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()
pvdTr := pgo.DefaultPvdSocketTransportCreate("0.0.0.0", 5426, 100000)
println("Pvd transport:", pvdTr)
// for {
// time.Sleep(1 / 60 * time.Second)
// }
pvd := pgo.CreatePvd(f)
println("Pvd:", pvd)
println("connect:", pvd.Connect(pvdTr, pgo.PvdInstrumentationFlag_eALL))
ts := pgo.NewTolerancesScale(1, 9.81)
p := pgo.CreatePhysics(f, ts, false, pvd)
println("Physics:", p)
sd := pgo.NewSceneDesc(ts)
sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
s := p.CreateScene(sd)
println("Scene:", s)
for {
}
p.Release()
pvd.Release()
pvdTr.Release()
}

Binary file not shown.

View File

@ -12,14 +12,39 @@ struct CPxFoundation* CPxCreateFoundation();
void CPxFoundation_release(struct CPxFoundation*);
struct CPxPvd* CPxCreatePvd(struct CPxFoundation*);
bool CPxPvd_connect(struct CPxPvd*, struct CPxPvdTransport*, enum CPxPvdInstrumentationFlag);
void CPxPvd_release(struct CPxPvd*);
struct CPxPvdTransport* CPxDefaultPvdSocketTransportCreate(const char* address, int port, int timeoutMillis);
void CPxPvdTransport_release(struct CPxPvdTransport* cppt);
struct CPxTolerancesScale NewCPxTolerancesScale(CPxReal length, CPxReal speed);
struct CPxPhysics* CPxCreatePhysics(struct CPxFoundation* cfoundation, struct CPxTolerancesScale cscale, bool trackOutstandingAllocations, struct CPxPvd* cpvd);
struct CPxScene* CPxPhysics_createScene(struct CPxPhysics*, struct CPxSceneDesc*);
void CPxPhysics_release(struct CPxPhysics*);
struct CPxVec3 NewCPxVec3(float x, float y, float z);
struct CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32 affinityMasks);
struct CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(struct CPxDefaultCpuDispatcher* cdcd);
struct CPxSceneDesc* NewCPxSceneDesc(struct CPxTolerancesScale);
void CPxSceneDesc_set_gravity(struct CPxSceneDesc*, struct CPxVec3);
void CPxSceneDesc_set_cpuDispatcher(struct CPxSceneDesc*, struct CPxCpuDispatcher*);
*/
import "C"
import "unsafe"
type PvdInstrumentationFlag uint32
const (
PvdInstrumentationFlag_eDEBUG PvdInstrumentationFlag = 1 << 0
PvdInstrumentationFlag_ePROFILE PvdInstrumentationFlag = 1 << 1
PvdInstrumentationFlag_eMEMORY PvdInstrumentationFlag = 1 << 2
PvdInstrumentationFlag_eALL PvdInstrumentationFlag = (PvdInstrumentationFlag_eDEBUG | PvdInstrumentationFlag_ePROFILE | PvdInstrumentationFlag_eMEMORY)
)
type Foundation struct {
cFoundation *C.struct_CPxFoundation
}
@ -40,6 +65,10 @@ type Pvd struct {
cPvd *C.struct_CPxPvd
}
func (p *Pvd) Connect(pvdTr *PvdTransport, instFlag PvdInstrumentationFlag) bool {
return bool(C.CPxPvd_connect(p.cPvd, pvdTr.cPvdTr, uint32(instFlag)))
}
func (p *Pvd) Release() {
C.CPxPvd_release(p.cPvd)
}
@ -67,6 +96,91 @@ func DefaultPvdSocketTransportCreate(host string, port, timeoutMillis int) *PvdT
p := &PvdTransport{}
p.cPvdTr = C.CPxDefaultPvdSocketTransportCreate(hostCStr, C.int(port), C.int(timeoutMillis))
return p
}
type TolerancesScale struct {
cTolScale C.struct_CPxTolerancesScale
}
func NewTolerancesScale(length, speed float32) *TolerancesScale {
ts := &TolerancesScale{}
ts.cTolScale = C.NewCPxTolerancesScale(C.float(length), C.float(speed))
return ts
}
type Scene struct {
cS *C.struct_CPxScene
}
type Physics struct {
cPhysics *C.struct_CPxPhysics
}
// struct CPxScene* CPxPhysics_createScene(struct CPxPhysics*, struct CPxSceneDesc*);
func (p *Physics) CreateScene(sd *SceneDesc) *Scene {
return &Scene{
cS: C.CPxPhysics_createScene(p.cPhysics, sd.cSD),
}
}
func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocations bool, pvd *Pvd) *Physics {
p := &Physics{}
p.cPhysics = C.CPxCreatePhysics(f.cFoundation, ts.cTolScale, C._Bool(trackOutstandingAllocations), pvd.cPvd)
return p
}
func (p *Physics) Release() {
C.CPxPhysics_release(p.cPhysics)
}
type Vec3 struct {
cV C.struct_CPxVec3
}
func NewVec3(x, y, z float32) *Vec3 {
return &Vec3{
cV: C.NewCPxVec3(C.float(x), C.float(y), C.float(z)),
}
}
type CpuDispatcher struct {
cCpuDisp *C.struct_CPxCpuDispatcher
}
type DefaultCpuDispatcher struct {
cDefCpuDisp *C.struct_CPxDefaultCpuDispatcher
}
// struct CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(struct CPxDefaultCpuDispatcher* cdcd);
func (d *DefaultCpuDispatcher) ToCpuDispatcher() *CpuDispatcher {
return &CpuDispatcher{cCpuDisp: (*C.struct_CPxCpuDispatcher)(d.cDefCpuDisp)}
}
func DefaultCpuDispatcherCreate(numThreads, affinityMasks uint32) *DefaultCpuDispatcher {
return &DefaultCpuDispatcher{
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), C.uint(affinityMasks)),
}
}
type SceneDesc struct {
cSD *C.struct_CPxSceneDesc
}
func (sd *SceneDesc) SetGravity(v *Vec3) {
C.CPxSceneDesc_set_gravity(sd.cSD, v.cV)
}
func (sd *SceneDesc) SetCpuDispatcher(cd *CpuDispatcher) {
C.CPxSceneDesc_set_cpuDispatcher(sd.cSD, cd.cCpuDisp)
}
//struct CPxSceneDesc* NewCPxSceneDesc(struct CPxTolerancesScale);
func NewSceneDesc(ts *TolerancesScale) *SceneDesc {
return &SceneDesc{
cSD: C.NewCPxSceneDesc(ts.cTolScale),
}
}

25
pgo/physx-c/CPxCpuDispatcher.h Executable file
View File

@ -0,0 +1,25 @@
#ifndef CPxCpuDispatcher_H
#define CPxCpuDispatcher_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxCpuDispatcher
{
void* obj;
};
/// <summary>
/// This only frees C representation of the base class (the CPxCpuDispatcher struct). obj is NOT freed.
/// To release the PhysX resources release must be called on the actual C implementation (e.g. CPxDefaultCpuDispatcher_release)
/// </summary>
/// <param name="CPxCpuDispatcher"></param>
/// <returns></returns>
CPxAPI void CPxCpuDispatcher_release(CSTRUCT CPxCpuDispatcher*);
#ifdef __cplusplus
}
#endif
#endif // !PxCpuDispatcher_H

View File

@ -0,0 +1,22 @@
#ifndef CPxDefaultCpuDispatcher_H
#define CPxDefaultCpuDispatcher_H
#include "CPxCpuDispatcher.h"
#ifdef __cplusplus
extern "C" {
#endif
struct CPxDefaultCpuDispatcher {
void* obj;
};
CPxAPI CSTRUCT CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32 affinityMasks);
CPxAPI CSTRUCT CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(CSTRUCT CPxDefaultCpuDispatcher* cdcd);
CPxAPI void CPxDefaultCpuDispatcher_release(CSTRUCT CPxDefaultCpuDispatcher* cdcd);
#ifdef __cplusplus
}
#endif
#endif // !CPxDefaultCpuDispatcher_H

View File

@ -0,0 +1,20 @@
#ifndef CPxDefaultSimulationFilterShader_H
#define CPxDefaultSimulationFilterShader_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxDefaultSimulationFilterShader
{
void* obj;
};
//CPxAPI CSTRUCT CPxDefaultSimulationFilterShader* NewCPxDefaultSimulationFilterShader();
//CPxAPI void FreeCPxDefaultSimulationFilterShader(CSTRUCT CPxDefaultSimulationFilterShader*);
#ifdef __cplusplus
}
#endif
#endif // !CPxDefaultSimulationFilterShader_H

View File

@ -1,5 +1,5 @@
#ifndef __CPxFoundation_H__
#define __CPxFoundation_H__
#ifndef CPxFoundation_H
#define CPxFoundation_H
#ifdef __cplusplus
extern "C" {

26
pgo/physx-c/CPxPhysics.h Executable file
View File

@ -0,0 +1,26 @@
#ifndef CPxPhysics_H
#define CPxPhysics_H
#include "CPxPvd.h"
#include "CPxFoundation.h"
#include "CPxScene.h"
#include "CPxSceneDesc.h"
#include "CPxTolerancesScale.h"
#ifdef __cplusplus
extern "C" {
#endif
struct CPxPhysics {
void* obj;
};
CPxAPI CSTRUCT CPxPhysics* CPxCreatePhysics(CSTRUCT CPxFoundation* cfoundation, CSTRUCT CPxTolerancesScale cscale, bool trackOutstandingAllocations, CSTRUCT CPxPvd* cpvd);
CPxAPI CSTRUCT CPxScene* CPxPhysics_createScene(CSTRUCT CPxPhysics*, CSTRUCT CPxSceneDesc*);
CPxAPI void CPxPhysics_release(CSTRUCT CPxPhysics*);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,17 +1,69 @@
#ifndef __CPxPvd_H__
#define __CPxPvd_H__
#ifndef CPxPvd_H
#define CPxPvd_H
#include "CPxFoundation.h"
#include "CPxPvdTransport.h"
#ifdef __cplusplus
extern "C" {
#endif
enum CPxPvdInstrumentationFlag
{
/**
\brief Send debugging information to PVD.
This information is the actual object data of the rigid statics, shapes,
articulations, etc. Sending this information has a noticeable impact on
performance and thus this flag should not be set if you want an accurate
performance profile.
*/
CPxPvdInstrumentationFlag_eDEBUG = 1 << 0,
/**
\brief Send profile information to PVD.
This information populates PVD's profile view. It has (at this time) negligible
cost compared to Debug information and makes PVD *much* more useful so it is quite
highly recommended.
This flag works together with a PxCreatePhysics parameter.
Using it allows the SDK to send profile events to PVD.
*/
CPxPvdInstrumentationFlag_ePROFILE = 1 << 1,
/**
\brief Send memory information to PVD.
The PVD sdk side hooks into the Foundation memory controller and listens to
allocation/deallocation events. This has a noticable hit on the first frame,
however, this data is somewhat compressed and the PhysX SDK doesn't allocate much
once it hits a steady state. This information also has a fairly negligible
impact and thus is also highly recommended.
This flag works together with a PxCreatePhysics parameter,
trackOutstandingAllocations. Using both of them together allows users to have
an accurate view of the overall memory usage of the simulation at the cost of
a hashtable lookup per allocation/deallocation. Again, PhysX makes a best effort
attempt not to allocate or deallocate during simulation so this hashtable lookup
tends to have no effect past the first frame.
Sending memory information without tracking outstanding allocations means that
PVD will accurate information about the state of the memory system before the
actual connection happened.
*/
CPxPvdInstrumentationFlag_eMEMORY = 1 << 2,
eALL = (CPxPvdInstrumentationFlag_eDEBUG | CPxPvdInstrumentationFlag_ePROFILE | CPxPvdInstrumentationFlag_eMEMORY)
};
struct CPxPvd
{
void* obj;
};
CPxAPI CSTRUCT CPxPvd* CPxCreatePvd(CSTRUCT CPxFoundation*);
CPxAPI bool CPxPvd_connect(CSTRUCT CPxPvd*, CSTRUCT CPxPvdTransport*, CENUM CPxPvdInstrumentationFlag);
CPxAPI void CPxPvd_release(CSTRUCT CPxPvd* cpp);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
#ifndef __CPxPvdTransport_H__
#define __CPxPvdTransport_H__
#ifndef CPxPvdTransport_H
#define CPxPvdTransport_H
#ifdef __cplusplus
extern "C" {

20
pgo/physx-c/CPxScene.h Executable file
View File

@ -0,0 +1,20 @@
#ifndef CPxScene_H
#define CPxScene_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxScene
{
void* obj;
};
CPxAPI void CPxScene_release(CSTRUCT CPxScene*);
#ifdef __cplusplus
}
#endif
#endif // !CPxScene_H

30
pgo/physx-c/CPxSceneDesc.h Executable file
View File

@ -0,0 +1,30 @@
#ifndef CPxSceneDesc_H
#define CPxSceneDesc_H
#include "CPxTolerancesScale.h"
#include "CPxVec3.h"
#include "CPxCpuDispatcher.h"
#ifdef __cplusplus
extern "C" {
#endif
struct CPxSceneDesc {
void* obj;
};
/// <summary>
/// Creates a SceneDesc with filterShader=physx::PxDefaultSimulationFilterShader
/// </summary>
/// <param name="CPxTolerancesScale"></param>
/// <returns></returns>
CPxAPI CSTRUCT CPxSceneDesc* NewCPxSceneDesc(CSTRUCT CPxTolerancesScale);
CPxAPI void CPxSceneDesc_set_gravity(CSTRUCT CPxSceneDesc*, CSTRUCT CPxVec3);
CPxAPI void CPxSceneDesc_set_cpuDispatcher(CSTRUCT CPxSceneDesc*, CSTRUCT CPxCpuDispatcher*);
CPxAPI void FreeCPxSceneDesc(CSTRUCT CPxSceneDesc*);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,19 @@
#ifndef CPxTolerancesScale_H
#define CPxTolerancesScale_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxTolerancesScale
{
CPxReal length, speed;
};
CPxAPI CSTRUCT CPxTolerancesScale NewCPxTolerancesScale(CPxReal length, CPxReal speed);
#ifdef __cplusplus
}
#endif
#endif

18
pgo/physx-c/CPxVec3.h Executable file
View File

@ -0,0 +1,18 @@
#ifndef CPxVec3_H
#define CPxVec3_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxVec3 {
float x, y, z;
};
CPxAPI CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z);
#ifdef __cplusplus
}
#endif
#endif // !define CPxVec3_H

View File

@ -1,4 +1,18 @@
#include <stdint.h>
#include <stdbool.h>
#define CPxAPI
#define CSTRUCT struct
#define CENUM enum
#define CPxU32 uint32_t
#define CPxReal float
#include <CPxFoundation.h>
#include <CPxPvd.h>
#include <CPxCpuDispatcher.h>
#include <CPxDefaultCpuDispatcher.h>
#include <CPxPhysics.h>
#include <CPxPvdTransport.h>
#include <CPxScene.h>
#include <CPxSceneDesc.h>
#include <CPxTolerancesScale.h>
#include <CPxVec3.h>