Physics optimization

From Valve Developer Community
Revision as of 13:36, 16 September 2008 by TomEdwards (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

It's a rare map that exists without any physically-simulated objects. How can we keep the performance costs of all these items under control?

It's a particular issue when we consider that we can't remove objects based on the speed of the CPU - the computer with an eight year old laptop CPU has exactly as many objects to manage as the computer with a liquid-cooled quadcore chip from the year 2020. Fortunately, we have all the tools we need.

Spawnflags

These spawnflags apply to prop_physics, and some to prop_ragdoll.

Start asleep
Suspends all physics calculations until the entity has a force of some sort exerted on it. Its primary use is to avoid the first moments of a map being a slideshow as all of the objects in it 'settle'.
But of course you do want that settling to happen, or else objects will be suspended in the wrong position. You can escape this catch-22 with the map_edit command.
Debris
Debris objects don't collide with anything but brushes, vastly reducing their cost. They can optionally be 'ploughed through' by the player with cl_pushaway_force.
Tip:It can get fiddly to set lots of tiny items as debris. Perhaps a programmer could write some code to automatically do so for models under a certain side when the map spawns?
Motion Disabled
Does exactly what its name suggests. Unlike sleeping, it can be (and is only) affected with the EnableMotion and DisableMotion inputs.
Prevent motion enable on player bump
The object doesn't move when the player bumps into it. To do: Only valid when starting asleep?