Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Entity Component System - a different approach to game and app development

134 views

Published on

Presentation delivered at CodeStar Night, discussing ECS (Entity Component System) as a different approach for game and app development.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Entity Component System - a different approach to game and app development

  1. 1. Entity Component System - a different approach to game / application development Maxim Zaks @iceX33
  2. 2. Object Oriented Programming SOLID Principals
  3. 3. public class Rectangle { public double Width { get; set; } public double Height { get; set; } }
  4. 4. public class AreaCalculator { public double Area(Rectangle[] shapes) { double area = 0; foreach (var shape in shapes) { area += shape.Width*shape.Height; } return area; } }
  5. 5. public double Area(object[] shapes) { double area = 0; foreach (var shape in shapes) { if (shape is Rectangle) { Rectangle rectangle = (Rectangle) shape; area += rectangle.Width*rectangle.Height; } else { Circle circle = (Circle)shape; area += circle.Radius * circle.Radius * Math.PI; } } return area; }
  6. 6. public abstract class Shape { public abstract double Area(); }
  7. 7. public class Rectangle : Shape { public double Width { get; set; } public double Height { get; set; } public override double Area() { return Width*Height; } } public class Circle : Shape { public double Radius { get; set; } public override double Area() { return Radius*Radius*Math.PI; } }
  8. 8. public double Area(Shape[] shapes) { double area = 0; foreach (var shape in shapes) { area += shape.Area(); } return area; }
  9. 9. OOP -> Abstraction
  10. 10. Wassily Kandinsky: Komposition VIII, 1923. Öl auf Leinwand
  11. 11. Functional Programming
  12. 12. rectangleArea :: Float -> Float -> Float rectangleArea a b = a * b
  13. 13. data Shape = Circle Float | Rectangle Float Float area :: Shape -> Float area (Circle r) = pi * r * r area (Rectangle width height) = width * height sum $ map area [(Circle 5), (Rectangle 2 3), (Circle 7)]
  14. 14. FP -> Function Composition
  15. 15. Entity Component System
  16. 16. struct RadiusComponent { float value; } struct HeightComponent { float value; } struct WidthComponent { float value; } struct AreaComponent { float value; }
  17. 17. Compute Circle Area System • get all entities which have RadiusComponent • set computed AreaComponent on this entity
  18. 18. Compute Rectangle Area System • get all entities which have WidthComponent and HeightComponent • set computed AreaComponent on entity
  19. 19. Compute Sum of Areas System • get all entities which have AreaComponent • compute a sum of values • do something with it
  20. 20. Systems query for data / get data injected
  21. 21. Systems don't return They change sate, or perform side effects
  22. 22. Systems don't care about the whole picture
  23. 23. Elephant and the blind men https://en.wikipedia.org/wiki/Blindmenandanelephant
  24. 24. Interactive vs. pure computation
  25. 25. Systems are executed periodically
  26. 26. How to implement an early exit?
  27. 27. Define better query • get all entities which have RadiusComponent and don't have AreaComponent
  28. 28. What happens when value is changed by outside interaction?
  29. 29. Solutions • Introduce special components for outside interactions • Use an ECS which supports reactive systems
  30. 30. What is a reactive system?
  31. 31. Component events • Added • Removed • Replaced
  32. 32. ECS vs. FP • ECS is built for interactive computations • mutation is ok • side effects are ok
  33. 33. ECS vs. OOP
  34. 34. Data driven vs. Abstraction
  35. 35. Clean architecture • SOLID in regards to ECS
  36. 36. Single responsibility principle
  37. 37. Open close principle
  38. 38. Liskov substitution principle
  39. 39. Interface segregation principle
  40. 40. Dependency inversion principle
  41. 41. Lets talk about testability
  42. 42. Lets talk about debug-ability
  43. 43. Lets talk about performance
  44. 44. If you want to know more • Have a look at work Unity3D does https://unity3d.com/unity/ features/job-system-ECS • Mike Acton @ CppCon 2014 https://www.youtube.com/watch? v=rX0ItVEVjHc • Catherine West @ Rust Conf 2018 https://www.youtube.com/ watch?v=aKLntZcp27M • ECS Lab Discord Server https://discord.gg/eCpyZSg
  45. 45. Thank you! Maxim Zaks @iceX33 Questions?

×