A8 This function in ackphysX.h starts the physics simulation loop, and sets up level_load and ent_remove events for automatically registering and unregistering static objects. Alternatively, you can use your own physics loop and handle all registering / unregistering manually.
function physX_level_load()
{
if (level_ent)
pXent_settype(level_ent,PH_STATIC,PH_POLY);
for (you = ent_next(NULL); you; you = ent_next(you))
{
if (you.emask&DYNAMIC) continue; // only register static ents
if (you.flags&PASSABLE) continue;
var type = ent_type(you);
if (type >= 2 && type <= 5) // blocks, models, or terrain
pXent_settype(you,PH_STATIC,PH_POLY);
}
}
function physX_ent_remove(ENTITY* ent)
{
if (ent.body) // unregister entity before removal
pXent_settype(ent,0,0);
}
function physX_open()
{
physX_load();
pX_setsteprate(60,8,0);
pX_setunit(1/40);
on_exit = physX_destroy;
on_level_load = physX_level_load;
on_ent_remove = physX_ent_remove;
while(1) {
physX_run(time_step/16);
wait(1);
}
}
Slow