Genbox / VelcroPhysics

High performance 2D collision detection system with realistic physics responses.
MIT License
662 stars 114 forks source link

Serializable templates #46

Open acaly opened 6 years ago

acaly commented 6 years ago

Hi,

I am wondering whether we can make the templates serializable, specifically, serializable with DataContractSerializer and BinaryFormatter. By storing the template in resources instead of hard-code in C# one by one, it will definitely make the built-in template more useful when we are serializing a game scene.

I am also wondering whether we can add a list/array of FixtureTemplate in BodyTemplate, which allows us to store only one BodyTemplate to create on body. Now we need to specify a BodyTemplate and attach several Fixtures. Also this does the same as FixtureTemplate, which contains a Shape (or ShapeTemplate, please below). The final goal is to make template easier to use, especially more friendly to game scene serialization.

If you think it's reasonable, I can make a pull request. This requires the following work:

This may requires more tests, but I don't have a clear idea on how to do that yet. What are your suggestions?

Thanks.

damian-666 commented 6 years ago

My team did this with an earlier version of Farseer. If you request I can upload it to a new fork for your reference. We put DataContract directly into the Body and Fixture class you'd just have to search for it. Fixtures can be generated from the state in body, and/ or directly serialized. We had created content before finalizing it, and maybe it is not ideal code, but the result is serialization in .net with reasonably sized files and decent level-loading performance. The best part is that is is 99% tagging the non-derivative state and super easy to maintain with customization to the engine. This could be merged into the main branch because its mostly just tags and helps to see what is minimal description of physical state and what is cache state.