Is there any way to improve fps when using physx in Esenthel Engine?
I've been able to simulate 2000 boxes, even with graphically "intensive" visualization with PhysX at about 40 FPS:
http://www.youtube.com/watch?v=ojhmkkVoWaI
However this runs at about 6 FPS for me (after the boxes all fell down):
Code:
#include "stdafx.h"
Actor ground;
Memb<Actor> boxes;
void InitPre()
{
App.name("Physics");
App.flag=APP_MS_EXCLUSIVE|APP_NO_FX|APP_RESIZABLE;
Paks.add("../data/engine.pak");
D.sync(true);
}
Bool Init()
{
Cam.dist=4;
// create physics
Physics.create();
// create actors
REPD(x,10)
{
REPD(y,20)
{
REPD(z,10)
{
Actor& a = boxes.New();
a.create(Box (0.6,1.0,0.6 ,Vec(x,y,z)));
}
}
}
ground.create(Box (150,2,150,Vec(0 ,-2, 0)), 0); // create ground actor from Box and density=0 (which means it's a static actor - will not move)
return true;
}
void Shut()
{
}
Bool Update()
{
if(Kb.bp(KB_ESC))return false;
CamHandle(0.1,100,CAMH_ZOOM|CAMH_ROT);
static Bool simulatedOnce= false;
if(simulatedOnce)Physics.get();// end frame simulation
Physics.sim(); // start frame simulation
simulatedOnce = true;
return true;
}
void Draw()
{
D .clear();
Physics.draw (); // draw physical actors
D.text(-D.w()+0.2,D.h()-0.1,Str16(L"FPS: ")+Tm.fps());
}
Notice I already make best use of multi threading by letting it simulate from one call to update up to the next.
---
Btw., if you look at my code, is this how you would do something like this? (I'm pretty new o this engine, so I could use some advice.)
Especially the creation of the boxes (Do I need to store them? Should I use another memory structure?) and the text drawing (Would I position stuff on the screen like this? Is what I do to create the text string (
Str16(L"FPS: ")+Tm.fps()) good practice? How do I make text left aligned? Where are the default text draw settings?)
Hmm, OK, If I call
Physics.sim() with
1/60.0f, I also get 40 FPS. Looks like the physx engine was made for that update rate.