Zef Posted June 6, 2014 Share Posted June 6, 2014 Hi there, I am currently using phaser for a simulation of life evolving a neural network inside little creatures. This relies on generation after generation of these creatures being evolved with a genetic algorithm. I am currently relying on the arcade physics system to handle collisions and overlaps etc, and the little creatures survive by eating food, and hunting each other. Or at least that is what they should learn to do. Currently each round last 45 seconds, this in itself isn't a problem, but I have been trying to find a way to step the Phaser engine at the fastest speed possible so that I can complete a number of simulations in the shortest possible time. It can take 1000s of generations before the creatures evolve to show intelligent behaviour. I am struggling to achieve this at present. I have tried using game.enableStep() and then in the update function calling game.step() more than once but this doesn't appear to work. Does anyone know how I can do this? Thanks for you help. ps. I have made a little site showcasing the neural network http://jozefmaxted.co.uk/neural/index.html I plan to add more examples and will put the code up on Github soon. Its the sort of thing that will be really handy for creating AI for games. Luis Felipe 1 Link to comment Share on other sites More sharing options...
Zef Posted June 6, 2014 Author Share Posted June 6, 2014 If anyone is interest here is a link to the current state of the simulation too http://jozefmaxted.co.uk/neural/lifesim/index.html Link to comment Share on other sites More sharing options...
j0hnskot Posted June 6, 2014 Share Posted June 6, 2014 I don't know if i understand you correctly but i guess you want the update loop to tick more that 60 times per second. I guess this is not possible since the max the browser allow is 60. But i may be wrong! Link to comment Share on other sites More sharing options...
Zef Posted June 6, 2014 Author Share Posted June 6, 2014 I'm sure there will be a way to do it. If I am correct requestAniimationFrame will cap at 60fps, but I presume that is just calling the phaser update function. All I need is some way of calling update more than once each time. Thanks for your help ;p Link to comment Share on other sites More sharing options...
lewster32 Posted June 7, 2014 Share Posted June 7, 2014 I'd say what you need to do is to separate your logic from the rendering loop altogether. Do your calculations on a short (or even 0) length timeout so they can run as fast as you need, and then have the Phaser update loop just render the results each time it's called. You should not be trying to call Phaser's update routine any faster than the browser can render it, as that becomes highly wasteful and will severely reduce performance. Link to comment Share on other sites More sharing options...
Zef Posted June 8, 2014 Author Share Posted June 8, 2014 Hi, yeah I think that is the way I will be going actually. Its a shame because I wanted to make use of arcade physics but it looks like I will need to use something else now. Link to comment Share on other sites More sharing options...
lewster32 Posted June 8, 2014 Share Posted June 8, 2014 For what it's worth, you can still use things such as Rectangle.intersects and the heavier, less performant Sprite.overlap to do overlap detection as often as your simulation loop occurs. There probably is a way to hook into the physics system directly and run it within your simulation loop however I think this question is best left to someone with more intimate knowledge of how this is wired into the framework. Link to comment Share on other sites More sharing options...
Recommended Posts