Added a new global state in mj_global.* and a big patch to use that state.