-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Value type components #47
base: master
Are you sure you want to change the base?
Value type components #47
Conversation
It seems like I accidentally included my commit to change the family size limit from 8 to 16 components, is that ok? |
To be honest - since this will be a huge undertaking anyways I'd like to keep this out of the PR for now - maybe just open another PR that we can merge before we continue with this and have it already in main. |
The outward facing API is not very clean right now I agree. However we have to be mindful about which APIs will be deprecated. Let's do a 2 step with the following steps:
This will allow reasoning about API separate from the structure based refactor. |
Codecov Report
@@ Coverage Diff @@
## master #47 +/- ##
===========================================
- Coverage 98.09% 61.65% -36.45%
===========================================
Files 30 23 -7
Lines 1368 1523 +155
===========================================
- Hits 1342 939 -403
- Misses 26 584 +558 |
Should be an add-on PR following after this one. |
There are multiple aspects to this: a) not using structs will break memory-locality/cache-friendlyness so using classes for components is never recommended However I propose a mixed approach. We do not want to hamper performance by always checking if a component is a struct, but we can do a little bit better as not checking at all. Another way would be to analyse what Apple is doing with the ECS (using structs) in RealityKit https://developer.apple.com/documentation/realitykit/component |
I think adding debug checks is probably the best solution to that issue right now
By this I'm assuming you mean only implement read-write families in this pr? because otherwise the ecs would not be properly functioning and the pr would break families
Yep, that sounds sensible. I'll work on that PR first then.
Ok, I guess I'll have to once again google how to revert a commit from the git history lol. And then I'll create a PR for that change. |
exactly - we have to keep the scope manageable and not get ahead of ourselves. All these ideas are great and should be available ultimately. Just one step at a time :-) |
…o value-type-components # Conflicts: # Sources/FirebladeECS/FSM.swift
Description
This PR aims to address the current performance and thread-safety limitations of the ECS by switching to using value type components. This allows better memory usage patterns, better performance, easier thread safety, and opens up many possible alleys for improvement (such as creating a system scheduler that analyses read and write dependencies between systems to automatically run systems in parallel where possible).
This will also address issue #46.
Detailed Design
These changes will overhaul massive portions of the API and will likely warrant a bump of the major version.
Here are the main tasks to be completed:
AnyObject
conformance fromComponent
protocolFSM
API working againPossible future optimisations
After implementing the basis of value type components there are many optimisations that can be implemented.
System
API to formalise how systems should be declared in a type-safe and thread-safe mannerTickScheduler
API which can run systems in a specified order and maybe even run systems in parallel when they are identified to have no common dependenciesSwift limitations
The main limitation that I have identified so far is that there isn't a way (that I know of) to restrict a protocol to only value types (unlike restricting to reference types which is possible with
AnyObject
. The only workaround I can see for this is putting advice all throughout the documentation saying to use value types for components. It technically shouldn't break the ECS if a component is a reference type, however it breaks a lot of thread-safety guarantees and would probably make for pretty confusing code.Testing
Once I am finished, I will make sure that all the tests pass and, most importantly, are still valid with the new component semantics. Currently they all pass but they most definitely shouldn't.
Source Impact
This will break every single package which depends on the ECS.
Checklist