Following discussion on the forum, it sounds like a good idea to implement an object sleep mechanism to save CPU cycles for objects that have nothing to do.
The way I imagine it is having two pools for game objects; the gameObjects array in core.js, and a new array for sleepingObjects. Calling me.game.sleep(obj) will remove obj from gameObjects, and push it into sleepingObjects. And me.game.wakeup(obj) will do the opposite.
A sleeping object will never be iterated in the update or draw loops, saving precious CPU time.
Further, we can enable a flag like me.sys.enableAutoSleep to put objects to sleep when they leave the viewport. Deciding on a good method of waking up a sleeping object without polling will be crucial for this flag to be useful. I suppose worst-case, polling infrequently (once per second?) could work.
Following discussion on the forum, it sounds like a good idea to implement an object sleep mechanism to save CPU cycles for objects that have nothing to do.
The way I imagine it is having two pools for game objects; the
gameObjectsarray in core.js, and a new array forsleepingObjects. Callingme.game.sleep(obj)will removeobjfromgameObjects, and push it intosleepingObjects. Andme.game.wakeup(obj)will do the opposite.A sleeping object will never be iterated in the update or draw loops, saving precious CPU time.
Further, we can enable a flag like
me.sys.enableAutoSleepto put objects to sleep when they leave the viewport. Deciding on a good method of waking up a sleeping object without polling will be crucial for this flag to be useful. I suppose worst-case, polling infrequently (once per second?) could work.