BGE: GUI control over frame rate, logic rate, physics rate and physics subrate.

Four new buttons in World settings to control frame rate:
fps:  Nominal frame rate in frame per second.
      Also sets the physics timestep = 1/fps
phys: Maximum number of physics timestep per game frame in case
      the actual fps is less than nominal. This allows the 
      physics to keep up with real time even if the graphics slows
      down the game.
sub:  Fixed number of simulation substeps per physic timestep.
      Improves the precision of the physics simulation. Useful for
      fast moving objects for example.
log:  Maximum number of logic steps per game frame in case the 
      actual fps is less than nominal. This allows the logic
      system to follow the physics simulation. 
      Upper bound = phys 
      (setting the value higher than phys has no effect).
      On games with heavy logic system, it is useful to set this
      value to 1, to keep logic time under control.

All these values were already accessible from Python except phys:

GameLogic.getMaxPhysicsFrame():
	Gets the maximum number of physics frame per render frame.

GameLogic.setMaxPhysicsFrame(phys):
	Sets the maximum number of physics timestep that are executed per render frame.
	Higher value allows physics to keep up with realtime even if graphics slows down the game.
	Physics timestep is fixed and equal to 1/tickrate (see setLogicTicRate)
	maxphysics/ticrate is the maximum delay of the renderer that physics can compensate.
      phys: integer
This commit is contained in:
2009-05-21 18:10:19 +00:00
parent d54126f78e
commit 036ebc5523
9 changed files with 102 additions and 10 deletions

View File

@@ -308,6 +308,21 @@ static PyObject* gPyGetMaxLogicFrame(PyObject*)
return PyInt_FromLong(KX_KetsjiEngine::GetMaxLogicFrame());
}
static PyObject* gPySetMaxPhysicsFrame(PyObject*, PyObject* args)
{
int frame;
if (!PyArg_ParseTuple(args, "i:setMaxPhysicsFrame", &frame))
return NULL;
KX_KetsjiEngine::SetMaxPhysicsFrame(frame);
Py_RETURN_NONE;
}
static PyObject* gPyGetMaxPhysicsFrame(PyObject*)
{
return PyInt_FromLong(KX_KetsjiEngine::GetMaxPhysicsFrame());
}
static PyObject* gPySetPhysicsTicRate(PyObject*, PyObject* args)
{
float ticrate;
@@ -501,6 +516,8 @@ static struct PyMethodDef game_methods[] = {
{"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS, (PY_METHODCHAR)"stop using the audio dsp (for performance reasons)"},
{"getMaxLogicFrame", (PyCFunction) gPyGetMaxLogicFrame, METH_NOARGS, (PY_METHODCHAR)"Gets the max number of logic frame per render frame"},
{"setMaxLogicFrame", (PyCFunction) gPySetMaxLogicFrame, METH_VARARGS, (PY_METHODCHAR)"Sets the max number of logic frame per render frame"},
{"getMaxPhysicsFrame", (PyCFunction) gPyGetMaxPhysicsFrame, METH_NOARGS, (PY_METHODCHAR)"Gets the max number of physics frame per render frame"},
{"setMaxPhysicsFrame", (PyCFunction) gPySetMaxPhysicsFrame, METH_VARARGS, (PY_METHODCHAR)"Sets the max number of physics farme per render frame"},
{"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_NOARGS, (PY_METHODCHAR)"Gets the logic tic rate"},
{"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (PY_METHODCHAR)"Sets the logic tic rate"},
{"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (PY_METHODCHAR)"Gets the physics tic rate"},