Performance question

Hello,

i have tested the current implementation on my sisters MacBook Pro (pre SandyBridge) and the performance was not good at all.



The scene contains:

-PostWater filter

-50 Objects

~1000 Triangles



FPS: ~10

The performance seems very low to me.



What could cause the problem is that on each of my blocks a CustomControl is attached, (Most of the do nothing)

Could this be a problem or should i look somewhere else?

You might have to run a profiler to see where the slowdown is. But that does seem quite slow. Maybe the videocard isn’t very good.

It can also depend what you are doing in your custom control.

Well, that is the point, all i do on every loop is:

For each block: (Nearly 200times / scene)

[java]

protected void controlUpdate(float tpf) {

if (this.speed != 0) {

current = current + (speed * tpf);

height = (float) Math.sin(current);



Vector3f loc = this.spatial.getLocalTranslation();

loc.y = (float) (this.height1.5);

this.spatial.setLocalTranslation(loc);

}

}

[/java]

Ten (10) times update block for the enemys:

[java]

protected void controlUpdate(float tpf) {

this.currentRotation=this.currentRotation+(this.rotationSpeed
tpf);

if(this.spatial.getParent()!=null){

this.spatial.getParent().getParent().setLocalRotation(new Quaternion().fromAngleAxis(this.currentRotation*FastMath.DEG_TO_RAD, Vector3f.UNIT_Y));

}

if(this.cam!=null){

this.spatial.setLocalRotation(this.spatial.getParent().getWorldRotation().inverse());

}

if(this.coolDownTime>=0){

this.coolDownTime=this.coolDownTime-tpf;

}

}

[/java]

And one time the update for the player which includes the collision querry:

[java]

if (status == 0) {

this.spatial.setMaterial(this.mat_default);

status = 1;

}

if(!tower.isGameRunning()) return;

if (this.physicsReversed) {

this.gravityReverseTimeLeft = this.gravityReverseTimeLeft - tpf;

if (this.gravityReverseTimeLeft <= 0) {

this.physicsReversed = false;

this.spatial.setMaterial(this.mat_default);

}

}

boolean touchBottom = false;

float fBottom = 0;

boolean touchTop = false;

float fTop = 0;

boolean touchLeft = false;

boolean touchRight = false;



if (tpf

< 0.2) {

if (!this.physicsReversed) {

this.currentMovement = this.currentMovement - (this.gravity * tpf);

} else {

this.currentMovement = this.currentMovement + (this.gravity * tpf);

}

}

GhostControl playerPhysics = this.spatial.getControl(GhostControl.class);



if (playerPhysics

!= null) {

List<PhysicsCollisionObject> collisions= playerPhysics.getOverlappingObjects();

if (collisions.size() > 0) {

//if(!true){

for (Iterator<PhysicsCollisionObject> it = collisions.iterator(); it.hasNext():wink: {

PhysicsCollisionObject physicsCollisionObject = it.next();

Spatial collideWith = (Spatial) physicsCollisionObject.getUserObject();

BlockControl blockPhysics = collideWith.getControl(BlockControl.class);

if (blockPhysics != null) {

if (blockPhysics.isSolid()) {

// if (collideWith.getWorldTranslation().x > -this.sideModifier && collideWith.getWorldTranslation().x < this.sideModifier) {

if (this.spatial.getWorldTranslation().y > collideWith.getWorldTranslation().y) {

if (this.spatial.getWorldTranslation().y - collideWith.getWorldTranslation().y > 0.2) {

touchBottom = true;

fBottom = collideWith.getWorldTranslation().y;

} else {

if (collideWith.getWorldTranslation().x < 0) {

touchLeft = true;

touchBottom = false;

} else {

touchRight = true;

touchBottom = false;

}

}

if (touchBottom) {

if (this.physicsReversed) {

blockPhysics.onHit(this);

}

}

}

if (this.spatial.getWorldTranslation().y < collideWith.getWorldTranslation().y) {

if (this.spatial.getWorldTranslation().y - collideWith.getWorldTranslation().y < -0.2) {

touchTop = true;

fTop = collideWith.getWorldTranslation().y;

} else {

if (collideWith.getWorldTranslation().x < 0) {

touchLeft = true;

touchTop = false;

} else {

touchRight = true;

touchTop = false;

}

}

if (touchTop) {

if (!this.physicsReversed) {

blockPhysics.onHit(this);

}

}

}



}

} else {

EnemyControl enemy = collideWith.getControl(EnemyControl.class);

if (enemy != null) {

if (!this.isDucked) {

enemy.onHit(this);

}

}

}

}



}

}



if (!this.physicsReversed) {

if (touchBottom && this.currentMovement < 0) {

this.currentMovement = 0;

}

if (touchTop && this.currentMovement > 0) {

this.currentMovement = 0;

}



if (touchBottom && this.wantDuck && !touchTop && !this.isDucked) {

this.spatial.setLocalScale(1, 0.5f, 1);

this.isDucked = true;

}

if (this.isDucked && !this.wantDuck) {

this.spatial.setLocalScale(1, 1, 1);

this.isDucked = false;

}



if (touchBottom && this.wantJump && !touchTop && !this.isDucked) {

this.currentMovement = this.jumpForce;

this.isJumping = true;

this.wantJump = false;

if (this.jumpSound.getParent() == null) {

( this.spatial).getParent().attachChild(this.jumpSound);

}

this.jumpSound.playInstance();

}

if (!this.isJumping && this.currentMovement > 0) {

this.currentMovement = 0;

}

if (touchBottom && this.currentMovement >= 0) {

Vector3f pos = this.spatial.getWorldTranslation();

pos.y = fBottom + this.highModifier;

this.spatial.setLocalTranslation(pos);

}

if (touchTop && this.currentMovement <= 0) {

Vector3f pos = this.spatial.getWorldTranslation();

pos.y = fTop - this.highModifier;

this.spatial.setLocalTranslation(pos);

}

} else {

if (touchBottom && this.currentMovement < 0) {

this.currentMovement = 0;

}

if (touchTop && this.currentMovement > 0) {

this.currentMovement = 0;

}

if (touchTop && this.wantDuck && !touchBottom && !this.isDucked) {

this.spatial.setLocalScale(1, 0.5f, 1);

this.isDucked = true;

}

if (this.isDucked && !this.wantDuck) {

this.spatial.setLocalScale(1, 1, 1);

this.isDucked = false;

}

if (touchTop && this.wantJump && !touchBottom && !this.isDucked) {

this.currentMovement = -this.jumpForce;

this.isJumping = true;

this.wantJump = false;

if (this.jumpSound.getParent() == null) {

( this.spatial).getParent().attachChild(this.jumpSound);

}

this.jumpSound.playInstance();

}

if (!this.isJumping && this.currentMovement < 0) {

this.currentMovement = 0;



}



if (touchBottom && this.currentMovement <= 0) {

Vector3f pos = this.spatial.getWorldTranslation();

pos.y = fBottom + this.highModifier;

this.spatial.setLocalTranslation(pos);

}

if (touchTop && this.currentMovement >= 0) {

Vector3f pos = this.spatial.getWorldTranslation();

pos.y = fTop - this.highModifier;

this.spatial.setLocalTranslation(pos);

}

}



if (wantTurnLeft

&& !touchLeft && !this.isDucked) {

this.currentRotation = this.currentRotation + (this.rotationSpeed * tpf);

this.tower.updateRotation(this.currentRotation);

}



if (wantTurnRight

&& !touchRight && !this.isDucked) {

this.currentRotation = this.currentRotation - (this.rotationSpeed * tpf);

this.tower.updateRotation(this.currentRotation);

}

Vector3f pos = this.spatial.getWorldTranslation();





if (this.isDucked) {

if (this.physicsReversed) {

pos.y = pos.y + (this.highModifier / 4);

} else {

pos.y = pos.y - (this.highModifier / 4);

}

}

pos.y = pos.y + this.currentMovement;

if(pos.y<-2)this.reportPlayerDeath();

if(pos.y>1200) this.reportPlayerDeath();



this.spatial.setLocalTranslation(pos);







}

[/java]



Ok the control for the player might be a bit expensive, but i do not think that it could cause such a loss in fps.

Here is the picture of the profiler result:

http://i.imgur.com/fYRXe.png

What sort of baseline FPS do you get with the test cases that come with JME?

Nothing jumps out at me with your code as to what might be slowing it down.

I have not tested it yet since i only copied the dist package to the mac.

However i can remember playing Gothic 3, Battlefield 2 and C+C Generals on this system.

Going to investige what framerate the tests have

the only way to find out is to delete specific “fishy” parts of the code temporarly, like physics, etc.

and test fps to see if it improved. Of course do that in a seperate copy of your project in order not to lose data.