Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 15KB

2 years ago
6 years ago
2 years ago
6 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
6 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
6 years ago
2 years ago
2 years ago
4 years ago
3 years ago
4 years ago
2 years ago
4 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 years ago
2 years ago
2 years ago
2 years ago
3 years ago
6 years ago
4 years ago
4 years ago
6 years ago
3 years ago
3 years ago
4 years ago
5 years ago
6 years ago
6 years ago
6 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
6 years ago
3 years ago
3 years ago
3 years ago
3 years ago
6 years ago
6 years ago
3 years ago
5 years ago
3 years ago
5 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
6 years ago
3 years ago
6 years ago
6 years ago
3 years ago
6 years ago
2 years ago
4 years ago
4 years ago
6 years ago
3 years ago
6 years ago
6 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # Svelto.ECS C# Entity Component System framework
  2. Real ECS framework for c\#. Enables to write encapsulated, decoupled, maintainable, highly efficient, data oriented, cache friendly, code without pain. Although the framework is platform agnostic \(compatible with c\# 7 and above and .net standard 2.0 and above\), it comes with several Unity extensions.
  3. ## Svelto.ECS in pills
  4. Svelto.ECS is easy to start with, but full of tricks for expert users. The hardest problem to overcome is usually to shift mentality from OOP programming to ECS programming more than using the framework itself. If you want to read an ECS faq, you can check this article: https://github.com/SanderMertens/ecs-faq
  5. ### Svelto.ECS at glance:
  6. ```csharp
  7. public class SimpleContext
  8. {
  9. public static ExclusiveGroup group0 = new ExclusiveGroup(); //the group where the entity will be built in
  10. public SimpleContext()
  11. {
  12. var simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler();
  13. //Build Svelto Entities and Engines container, called EnginesRoot
  14. _enginesRoot = new EnginesRoot(simpleSubmissionEntityViewScheduler);
  15. var entityFactory = _enginesRoot.GenerateEntityFactory();
  16. var entityFunctions = _enginesRoot.GenerateEntityFunctions();
  17. //Add an Engine to the enginesRoot to manage the SimpleEntities
  18. var behaviourForEntityClassEngine = new BehaviourForEntityClassEngine(entityFunctions);
  19. _enginesRoot.AddEngine(behaviourForEntityClassEngine);
  20. //build a new Entity with ID 0 in group0
  21. entityFactory.BuildEntity<SimpleEntityDescriptor>(new EGID(0, ExclusiveGroups.group0));
  22. //submit the previously built entities to the Svelto database
  23. simpleSubmissionEntityViewScheduler.SubmitEntities();
  24. //as Svelto doesn't provide an engine ticking system, it's the user's responsibility to
  25. //update engines
  26. behaviourForEntityClassEngine.Update();
  27. }
  28. readonly EnginesRoot _enginesRoot;
  29. }
  30. ```
  31. your first entity descriptor:
  32. ```csharp
  33. public struct EntityComponent : IEntityComponent
  34. {
  35. public int counter;
  36. }
  37. class SimpleEntityDescriptor : GenericEntityDescriptor<EntityComponent>
  38. {}
  39. ```
  40. your first engine to apply behaviours to entities:
  41. ```csharp
  42. public class BehaviourForEntityClassEngine : IQueryingEntitiesEngine
  43. {
  44. public BehaviourForEntityClassEngine(IEntityFunctions entityFunctions)
  45. {
  46. _entityFunctions = entityFunctions;
  47. }
  48. public EntitiesDB entitiesDB { get; set; }
  49. public void Ready() { }
  50. public void Update()
  51. {
  52. var (components, count) = entitiesDB.QueryEntities<EntityComponent>(ExclusiveGroups.group0);
  53. for (var i = 0; i < count; i++)
  54. components[i].counter++;
  55. }
  56. readonly IEntityFunctions _entityFunctions;
  57. }
  58. ```
  59. learn more about svelto on the Wiki page: https://github.com/sebas77/Svelto.ECS/wiki
  60. ## Why using Svelto.ECS with Unity?
  61. Svelto.ECS wasn't born just from the needs of a large team, but also as a result of years of reasoning behind software engineering applied to game development. Svelto.ECS hasn't been written just to develop faster code, it has been designed to help develop better code. Performance gains is just one of the benefits in using Svelto.ECS, as ECS is a great way to write cache-friendly code. Svelto.ECS has been developed with the idea of ECS being a paradigm and not just a pattern, letting the user shift completely away from Object Oriented Programming with consequent improvements of the code design and code maintainability. Svelto.ECS is the result of years of iteration of the ECS paradigm applied to real game development with the intent to be as foolproof as possible. Svelto.ECS has been designed to be used by a medium-size/large team working on long term projects where the cost of maintainability is relevant.
  62. **Svelto.ECS is fully compatible with DOTS Burst and Jobs.**
  63. Svelto.ECS is compatible with Unity 2019.3.x cycle as long as it's not used with DOTS ECS.
  64. Svelto.ECS is also designed to use DOTS ECS as engine library, using the SveltoOnDOTS wrapper. This wrapper is designed to take advantage of DOTS for engine related operations, like rendering, physics and so on. When DOTS ECS integration is necessary, Svelto.ECS will always target the last stable unity version with the most up to date DOTS package.
  65. ## Why using Svelto.ECS without Unity?
  66. The question is just for fun! There are so many c# game engines out there (Stride, Monogame, FlatRedBall, WaveEngine, UnrealCLR, UniEngine just to mention some) and Svelto.ECS is compatible with all of them!
  67. ## If you decide to use Svelto.ECS
  68. Svelto.ECS is an Open Source Project provided as it is, no support is guaranteed other than the help given on the Svelto Discord channel. Issues will be fixed when possible. If you decide to adopt Svelto.ECS, it's assumed you are willing to partecipate to the development of the product if necessary.
  69. ## How to clone the repository:
  70. The folders Svelto.ECS and Svelto.Common, where present, are submodules pointing to the relative repositories. If you find them empty, you need to update them through the submodule command. Check some instructions here: https://github.com/sebas77/Svelto.ECS.Vanilla.Example/wiki
  71. ## Svelto distributed as Unity Package through OpenUPM [![openupm](https://img.shields.io/npm/v/com.sebaslab.svelto.ecs?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.sebaslab.svelto.ecs/)
  72. or just install the package that comes from the link https://package-installer.glitch.me/v1/installer/OpenUPM/com.sebaslab.svelto.ecs?registry=https%3A%2F%2Fpackage.openupm.com
  73. **Note on the System.Runtime.CompilerServices.Unsafe.dll dependency and the bit of a mess that Unity Package Dependency System is:**
  74. Unity Package System has a big deficiency when it comes to dll dependency solving: two packages cannot point to the same dependency from different sources. For this reason I decided to let my packages to point to the unsafe dll distribution from openUPM
  75. to solve the unsafe dependency you need to add the following scopedRegistries in manifest.json:
  76. ```
  77. {
  78. "scopedRegistries": [
  79. {
  80. "name": "package.openupm.com",
  81. "url": "https://package.openupm.com",
  82. "scopes": [
  83. "com.sebaslab.svelto.common",
  84. "com.sebaslab.svelto.ecs",
  85. "org.nuget.system.runtime.compilerservices.unsafe"
  86. ]
  87. }
  88. ],
  89. "dependencies": {
  90. "com.sebaslab.svelto.ecs": "3.2.6"
  91. }
  92. }
  93. ```
  94. this is shown in this example too: https://github.com/sebas77/Svelto.MiniExamples/tree/master/UPM-Integration/UPM
  95. ## Svelto distributed as Nuget
  96. I am not a Nuget expert, but thanks to our contributors, Svelto.ECS can be found at https://www.nuget.org/packages/Svelto.ECS/
  97. the Hello World example uses the nuget package directly: https://github.com/sebas77/Svelto.MiniExamples/tree/master/Example5-Net-HelloWorld
  98. ## Official Examples (A.K.A. where is the documentation?)
  99. Svelto doesn't have official documentation. The reason is that documentation is costly to mantain and...I reckon people don't need it, thanks to the highly documented and simple mini-examples. Please check and study them all regardless the platform you intend to use Svelto with.
  100. ### * **Mini Examples**: [https://github.com/sebas77/Svelto.MiniExamples](https://github.com/sebas77/Svelto.MiniExamples) \(including articles\)
  101. * **Unit Tests**: [https://github.com/sebas77/Svelto.ECS.Tests](https://github.com/sebas77/Svelto.ECS.Tests)
  102. After that, you can get all the help you need from the official chat:
  103. **Official Discord Server \(join to get help from me for free!\)**
  104. * [https://discord.gg/3qAdjDb](https://discord.gg/3qAdjDb)
  105. ## Official Articles
  106. **Framework articles:**
  107. * [Svelto ECS 3.0 is finally here](https://www.sebaslab.com/whats-new-in-svelto-ecs-3-0/) \(re-introducing svelto, this article is important for starters!\)
  108. * [Introducing Svelto ECS 2.9](http://www.sebaslab.com/introducing-svelto-ecs-2-9/) \(shows what's changed since 2.8\)
  109. * [Introducing Svelto ECS 2.8](http://www.sebaslab.com/introducing-svelto-ecs-2-8/) \(shows what's changed since 2.7\)
  110. * [Svelto.ECS 2.7: what’s new and best practices](http://www.sebaslab.com/svelto-2-7-whats-new-and-best-practices/) \(shows what's changed since 2.5\)
  111. * [Introducing Svelto ECS 2.5](http://www.sebaslab.com/svelto-ecs-2-5-and-allocation-0-code/) \(shows what's changed since 2.0\)
  112. * [Svelto.ECS 2.0 is production ready](http://www.sebaslab.com/svelto-ecs-2-0-almost-production-ready/) \(shows what's changed since 1.0\)
  113. * [Svelto ECS is now production ready](http://www.sebaslab.com/ecs-1-0/)
  114. **Theory related articles (from the most recent to the oldest, read from the oldest if you are new to it):**
  115. * [OOP abstraction layer in an ECS-centric application](https://www.sebaslab.com/oop-abstraction-layer-in-a-ecs-centric-application/) \(this article is important for starters!\)
  116. * [ECS abstraction layers and module encapsulation](https://www.sebaslab.com/ecs-abstraction-layers-and-modules-encapsulation/)
  117. * [The Quest for Maintainable Code and The Path to ECS](http://www.sebaslab.com/the-quest-for-maintainable-code-and-the-path-to-ecs/)
  118. * [The truth behind Inversion of Control – Part V – Entity Component System design to achieve true Inversion of Flow Control](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-v-drifting-away-from-ioc-containers/)
  119. * [The truth behind Inversion of Control – Part IV – Dependency Inversion Principle](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-iv-dependency-inversion-principle/)
  120. * [The truth behind Inversion of Control – Part III – Entity Component System Design](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-iii-entity-component-systems/)
  121. * [The truth behind Inversion of Control – Part II – Inversion of Control](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-ii-inversion-of-control/)
  122. * [The truth behind Inversion of Control – Part I – Dependency Injection](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-i-dependency-injection/)
  123. * [Inversion of Control with Unity – part 2](http://www.sebaslab.com/ioc-container-for-unity3d-part-2/)
  124. * [Inversion of Control with Unity – part 1](http://www.sebaslab.com/ioc-container-for-unity3d-part-1/)
  125. **Practical articles**
  126. * [Svelto.ECS Internals: How to avoid boxing when using structs with reflection](https://www.sebaslab.com/casting-a-struct-into-an-interface-inside-a-generic-method-without-boxing/)
  127. * [Svelto ECS 3.0 Internals: profiling the Entity Collection](https://www.sebaslab.com/svelto-ecs-3-0-internals-the-entity-collection/)
  128. * [Svelto ECS 3.0 Internals: Support Native Memory Natively](https://www.sebaslab.com/svelto-ecs-3-0-internals-support-native-memory-natively/)
  129. * [Svelto MiniExamples: GUI and Services Layer with Unity](https://www.sebaslab.com/svelto-miniexamples-gui-and-services-layer/)
  130. * [Svelto Mini (Unity) Examples: Doofuses Must Eat](https://www.sebaslab.com/svelto-mini-examples-doofuses-must-eat/)
  131. * [Svelto Mini Examples: The Unity Survival Example](http://www.sebaslab.com/learning-svelto-ecs-by-example-the-unity-survival-example/)
  132. * [Learning Svelto.ECS by example – The Vanilla Example](http://www.sebaslab.com/learning-svelto-ecs-by-example-the-vanilla-example/)
  133. * [Porting a boid simulation from UnityECS/Jobs to Svelto.ECS/Tasks](https://www.sebaslab.com/porting-a-boid-simulation-from-unityecs-to-svelto-ecs/)
  134. * [Svelto.ECS+Tasks to write Data Oriented, Cache Friendly, Multi-Threaded code](http://www.sebaslab.com/svelto-ecs-svelto-tasks-to-write-data-oriented-cache-friendly-multi-threaded-code-in-unity/)
  135. Note: I included the IoC articles just to show how I shifted over the years from using an IoC container to use an ECS framework and the rationale behind its adoption.
  136. ## Users Generated Content \(I removed all the outdated articles, so this is a call for new ones!\)
  137. * [A Beginner’s Guide to Svelto.ECS (3.0) with Unity by Jiheh Ritterling](https://jiheh.medium.com/a-beginners-guide-to-svelto-ecs-3-0-with-unity-e9dbc88a2145)
  138. **Svelto Extensions**
  139. * [Svelto.ECS.Schema - Schema and State Machine extensions for Svelto.ECS](https://github.com/cathei/Svelto.ECS.Schema)
  140. * [Automatic way to control svelto engines order without having to pass in a string using attributes](https://gist.github.com/dragonslaya84/88e6bb998eda8fe4ee912f01d67feec9)
  141. * [Foundation for a possible platform agnostic Svelto.ECS inspector](https://github.com/akrogame/svelto-ecs-inspector)
  142. * [Being able to swap entities between a subset of compound tags to another subset of compound tags](https://gist.github.com/jlreymendez/c2f441aaf6ac7b5f233ecd990314e9cc)
  143. ## In case of bugs
  144. Best option is to fork and clone [https://github.com/sebas77/Svelto.ECS.Tests](https://github.com/sebas77/Svelto.ECS.Tests), add new tests to reproduce the problem and request a pull. I will then fix the issue. Also feel free to contact me on Discord.
  145. ## I like the project, how can I help?
  146. Hey, thanks a lot for considering this. You can help in several ways. The simplest is to talk about Svelto.ECS and spread the word, the more we are, the better it is for the community. Then you can help with the documentation, updating the wiki or writing your own articles. Svelto.ECS has all the features needed to make a game with the ECS pattern, but some areas are lacking: *A visual debugger and more unit tests are needed*. Other platforms other than Unity could get some love too: Stride Game, Godot, monogame, FNA or whatever supports c#. Porting to other languages, especially c++, would be awesome but probably pointless. Please check the lane dedicated to the community tasks list here: https://github.com/users/sebas77/projects/3 and let me know if you want to take something on!
  147. ## Svelto Framework is used to develop the following products\(\*\):
  148. ![image](https://user-images.githubusercontent.com/945379/123062411-65ee3600-d404-11eb-8dca-d30c28ed909d.png)
  149. ![Gamecraft](https://steamcdn-a.akamaihd.net/steamcommunity/public/images/clans/35037633/e05ca4fc6f20f1e6150a6ace1d12fe8cd145fa0d.png)
  150. ![Robocraft Infinity](https://i.ytimg.com/vi/m_4fpgHwoBs/maxresdefault.jpg)
  151. ![Cardlife](https://i.ytimg.com/vi/q2jaUZjnNyg/maxresdefault.jpg)
  152. \*If you want your products made with Svelto here, just send me an email or whatever, I'll be super happy to add them.
  153. _**Note: Dear Svelto Users : Although I am committed to help you and write articles as much as I can, I will never be able to keep all the documentation up to date. If you are a happy svelto user and you want to contribute, please feel free to update the github wiki! 🙏👊**_