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

Physics refactor. #77

Merged
merged 9 commits into from
Feb 6, 2024
Merged

Physics refactor. #77

merged 9 commits into from
Feb 6, 2024

Conversation

Richardn2002
Copy link
Collaborator

Rationale:

  • PhysicsState and PhysicsSystem trait can be viewed as the requirements for the provided Runge-Kutta method impl to work. So they are all contained in file runge_kutta.rs. Simple Physics systems can choose to utilize the impl, thus using the structs and implementing the traits, or not, completely forgetting about that file, during implementation of tick().
  • tick() of SimplePhysicsSystems enum-dispatches to tick()s of variants, instead of dynamic dispatches, as for inox2d users are not supposed to bring their own physics systems (as of now).
  • Decoupling is done realizing that one step of physics simulation is a closure yielding a Vec2 and changing some contained states, per step. Thus letting one step do the calc, return the Vec2 and letting external code setting params based on the return value will solve the previous ownership problem.
  • TODO: The call to step the physics system is put naively inside end_set_params(), and without actual time elapsed passed in. Takeaway is, the physics step should be after param setting and before full puppet transform re-calc. But future refactor should provide the user with a better interface (physics still run if end_set_params() not called, and actual time elapsed passed in).

Richardn2002 and others added 7 commits January 3, 2024 19:09
Rationale:
- `PhysicsState` and `PhysicsSystem` trait can be viewed as the requirements for the provided Runge-Kutta method impl to work. So they are all contained in file `runge_kutta.rs`. Simple Physics systems can choose to utilize the impl, thus using the structs and implementing the traits, or not, completely forgetting about that file, during implementation of `tick()`.
- `tick()` of `SimplePhysicsSystems` enum-dispatches to `tick()`s of variants, instead of dynamic dispatches, as for inox2d users are not supposed to bring their own physics systems (as of now).
- Decoupling is done realizing that one step of physics simulation is a closure yielding a `Vec2` and changing some contained states, per step. Thus letting one step do the calc, return the `Vec2` and letting external code setting params based on the return value will solve the previous ownership problem.
- TODO: The call to step the physics system is put naively inside `end_set_params()`, and without actual time elapsed passed in. Takeaway is, the physics step should be after param setting and before full puppet transform re-calc. But future refactor should provide the user with a better interface (physics still run if `end_set_params()` not called, and actual time elapsed passed in).
inox2d/src/physics.rs Outdated Show resolved Hide resolved
@Speykious
Copy link
Member

I'll merge this in and we can continue the work on the branch itself

@Speykious Speykious merged commit 2f64179 into Inochi2D:physics Feb 6, 2024
10 of 11 checks passed
@Richardn2002 Richardn2002 deleted the physics branch September 30, 2024 13:10
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

Successfully merging this pull request may close these issues.

2 participants