Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializable templates #46

Open
acaly opened this issue Oct 31, 2017 · 1 comment
Open

Serializable templates #46

acaly opened this issue Oct 31, 2017 · 1 comment

Comments

@acaly
Copy link

acaly commented Oct 31, 2017

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:

  • Add attributes to classes and properties.
  • Add default constructors.
  • Change Shape in FixtureTemplate to ShapeTemplate, and Body to BodyTemplate in JointTemplate. Compared with their templates, Shape and Body are difficult to serialize.
  • Add an array of FixtureTemplate in BodyTemplate.
  • Add a helper function in Factory class to create Body and Joint objects in a World.

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants