I'm trying to incorporate a sleep system into my engine. I've tried several approaches so far, and they all had significant issues. The putting objects to sleep part is simple enough, just detect when they stop moving for a certain amount of time and flag them as sleeping, and skip contacts between two sleeping objects.
The hard part is when to wake them up. Obviously, waking up any object in contact with an awake object is not going to work, because they'd just keep waking each other up indefinitely. Instead, I made them set each other's "sleep" time to the minimum of the two, so eventually the whole island goes to sleep. This works pretty well, but in some cases it's pretty useless - for instance, if I make a very long chain of dominos and start collapsing it, then the end of the collapsed chain will always keep the whole thing awake even though 90% of it isn't moving, so eventually the simulation slows down significantly.
I've checked some simpler engines and another approach I found was to only wake up objects when the awake object in the pair exceeds certain velocity. However, this means that sometimes the solver will try to solve contacts between a sleeping and awake object, so I made it treat sleeping objects as stationary (infinite mass/momentum). This fixed the domino chain, but caused a much bigger issue in other simulations. Taking the newton cradle example (or any other scene where something collides into a group of resting objects), it simply can't propagate impulses through the chain of stationary balls - if the third ball in chain never moves (since the fourth ball is blocking it), it will never wake up the fourth ball.
It seems that the waking up checks need to be repeated every time a body's velocity changes during contact resolution. This means an object has to be waken up, it's contacts with adjacent sleeping bodies need to be re-activated and initialized (which involves collision checks and some additional computations) and added to the active contact list for subsequent resolution steps.
It sounds like it could work, but I'm not sure if I like the idea of mixing the collision and resolution stages. Am I on the right track here?