How can I optimise physics so that it might be a little more blunt but more performant?
I’m creating a voxel-engine and exploding parts are small physics blocks. But on my macbook pro (2x3.2GHz, 16GB RAM) I can only create like 800 blocks before the frame-rate drops heavily.
This is how I do it…
I’m creating a pool of blocks like this:
node = context->GetSubsystem<Game>()->scene_->CreateChild("Box");
node->SetPosition(Vector3((float)(rand()%1000+1000), (float)(rand()%1000)+1000, (float)(rand()%1000+1000)));
node->SetScale(1.0f);
model = node->CreateComponent<StaticModel>();
model->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
model->SetMaterial(cache->GetResource<Material>("Materials/vcolors2.xml"));
model->SetCastShadows(true);
shape = node->CreateComponent<CollisionShape>();
shape->SetBox(Vector3::ONE);
body = node->CreateComponent<RigidBody>();
body->SetCollisionEventMode(COLLISION_NEVER);
body->SetMass(10.1f);
body->SetFriction(30.0f);
body->SetRollingFriction(20.0f);
model->SetEnabled(false);
free = true;
Then I initiate a new block from the pool like this:
node->SetPosition(pos);
SharedPtr<Material> m = model->GetMaterial()->Clone();
m->SetShaderParameter("MatDiffColor",Vector4(color.x_/255.0f, color.y_/255.0f, color.z_/255.0f, 0.2f));
model->SetMaterial(m);
body->SetLinearVelocity(velocity*(float)OBJECT_VELOCITY);
model->SetEnabled(true);
free = false;
Any suggestions how to increase performance so that I might add more than just 800 blocks (in this case).
Thanks in advance!