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

ECS Add Sum component #37

Merged
merged 2 commits into from
Sep 17, 2024
Merged

ECS Add Sum component #37

merged 2 commits into from
Sep 17, 2024

Conversation

paulcadman
Copy link
Owner

@paulcadman paulcadman commented Sep 17, 2024

The Sum component allows cmap functions to set one of two alternatives.

The following function will delete the velocity component if the x component of the velocity is less than 5, otherwise will make no change.

f : Velocity -> Unit ⊕ Not Velocity
  | ⟨v⟩ => if v.x < 5
    then .inr .Not
    else .inl ()

@paulcadman paulcadman merged commit 0210a8b into main Sep 17, 2024
2 checks passed
@paulcadman paulcadman deleted the ecs-sum-component branch September 17, 2024 17:36
@awalterschulze
Copy link
Collaborator

@paulcadman shouldn't it be returning the velocity it makes no changes to?

f : Velocity -> Velocity ⊕ Not Velocity
  | ⟨v⟩ => if v.x < 5
    then .inr .Not
    else .inl ⟨v⟩

@paulcadman
Copy link
Owner Author

@paulcadman shouldn't it be returning the velocity it makes no changes to?

f : Velocity -> Velocity ⊕ Not Velocity
  | ⟨v⟩ => if v.x < 5
    then .inr .Not
    else .inl ⟨v⟩

@awalterschulze both approaches work. My example uses the component instance and storage of Unit for which explSet is a no-op.

The advantage of using the Velocity -> Unit ⊕ Not Velocity approach here is that you can see from the type signature that either the Velocity component is deleted or the Velocity component is unchanged.

If you use Velocity -> Velocity ⊕ Not Velocity then the function may change the Velocity or delete the Velocity component.

I used this in the BouncingBall example in a function that either deletes a component or keeps everything the same as before.

/-- An alternative to `deleteAt` that uses a Sum to delete an entry --/
def deleteAt'' (pos : Vector2) (radius : Float) : Position → System World (Unit ⊕ Not Position)

@awalterschulze
Copy link
Collaborator

Ok cool that makes sense, wow never would have thunk

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