Ykkrosh Posted December 22, 2011 Report Share Posted December 22, 2011 I committed some support for saving games with AI players. Testing would be helpful - hopefully it will be able to save and load any game containing AI players without triggering any warnings/errors, and the AI will continue running after loading. (It won't run exactly the same as if you hadn't saved/loaded, though - effectively the AI is restarted from scratch after loading, as if it was starting a new game, so it will forget all of its plans. This also means it won't work when rejoining an in-progress multiplayer match that includes AI players - you'll get an out-of-sync error - but it should be okay in single-player.)Technical details:When saving, the engine calls .Serialize() on each AI script object. That method must return some object (consisting of plain (not class-based) objects, arrays, strings, numbers, etc) which will get stored in the saved game file.When loading, the engine constructs the AI script object like at the start of a game. Then it calls .Deserialize(data), passing it the object that was returned by the call to .Serialize(). Deserialize is responsible for resetting the AI script object based on that data.Currently BaseAI implements Serialize/Deserialize, so it remembers the important state like _rawEntities (things will break if we don't store that). If a particular AI script wanted to save its own state, instead of restarting from scratch after loading, I guess it might be reasonable for it to just reimplement Serialize to do whatever it fancies (including a BaseAI.prototype.Serialize.call(this) to let BaseAI deal with the _rawEntities stuff), though maybe we ought to extend the serializer so it can cope with more interesting data types instead of forcing you to convert everything into plain objects/arrays/strings/numbers if that's a pain. Hopefully the current state is good enough for the next alpha release, though Quote Link to comment Share on other sites More sharing options...
MishFTW Posted December 22, 2011 Report Share Posted December 22, 2011 One step closer! Quote Link to comment Share on other sites More sharing options...
Android_ Posted December 22, 2011 Report Share Posted December 22, 2011 Quote Link to comment Share on other sites More sharing options...
historic_bruno Posted December 23, 2011 Report Share Posted December 23, 2011 I'll test as much as possible tonight, but not noticed any bad behavior yet Well done. Quote Link to comment Share on other sites More sharing options...
quantumstate Posted December 23, 2011 Report Share Posted December 23, 2011 This seems to be working well so far with my testing , saving is very nice to have and this will also be very helpful with my testing. For the future do you think it will be possible to serialize the entire AI without any work from the AI script? Quote Link to comment Share on other sites More sharing options...
historic_bruno Posted December 23, 2011 Report Share Posted December 23, 2011 For the future do you think it will be possible to serialize the entire AI without any work from the AI script?That's the plan, but the serializer needs to support more Javascript features like #406 and #407, which means fiddling around with Spidermonkey's internals. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.