QUICKLY Writing an Entity Component System (ECS) in C++

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ม.ค. 2025

ความคิดเห็น • 15

  • @codingwithmat
    @codingwithmat  8 หลายเดือนก่อน +6

    Turns out that working with parameter packs isn't easy in c++ 😬

    • @frontalachivment3604
      @frontalachivment3604 3 หลายเดือนก่อน +1

      Euphoric start: lets quickly write it meets reality "eh its not easy" :D

  • @matthewerdman
    @matthewerdman 21 วันที่ผ่านมา +2

    Cool, another Mat who writes in good ol' C++. I just finished my ECS. It's definitely a hack job. However, I DO have a square that moves to where ever you click at so... I wish I could show you my code and see what you think. It's all in one header file mainly with a little bit of concrete stuff for non-templated classes, not to big. Best of luck.

    • @codingwithmat
      @codingwithmat  15 วันที่ผ่านมา

      Hey, thanks for watching! It's good seeing that people are also trying out creating their own ECS libraries :) - Join our discord and post the link to your github in there, happy to review it during a stream!

  • @yohwllo2127
    @yohwllo2127 8 หลายเดือนก่อน +4

    I think the map which stores the vector to the data should have some sort of reserve function, mainly for performance when creating large amts of objects.

    • @codingwithmat
      @codingwithmat  8 หลายเดือนก่อน

      Probably, whenever we create the registry making those reserves would certainly be welcome. I'm going to benchmark this little lib in the next ECS stream, stay tuned for that! (will probably be next week at some point)

  • @ghaddar0292
    @ghaddar0292 5 หลายเดือนก่อน +1

    Thanks for the video. I'm starting to learn how to implement an ECS system in C++ and this was definitely educational. I have two questions/concerns on the implementation.
    1- Type info may return different results on different platforms or compiler or invocations of the program. Hence, I don't think it is reliable to use especially wheh dealing with serializing state from and to disk.
    2- I may be mistaken, but creating a new vector of entities each time when get is called does not seem ideal as that will allocate new memory each time. I don't know how to implement yet, but returning an iterator to the entity ids which have the component may avoid this issue.

    • @codingwithmat
      @codingwithmat  5 หลายเดือนก่อน +1

      Hey @ghaddar0292 , thanks for watching!
      (1) you are correct, `typeinfo` will return different names and hashes between platforms. In this implementation, the ECS only uses the information internally to keep track where the vectors of entities are stored for each component.
      (2) This implementation changed quite a bit. There was actually some issues somewhere with the use of iterators in this implementation and memory sanitisers.If you take a look at the current state of the code, the entities are basically stored as a `std::variant`, and I now use a map of `{bitmask, component combo entities}` to store the data internally.

  • @Tomab3
    @Tomab3 4 หลายเดือนก่อน

    Why dont you just use type_index ? Wouldn’t it easily solve the problem of getting all entities having a component of a certain type ? Just use it as the key for unordered list and have the value as list of entity ids

    • @codingwithmat
      @codingwithmat  4 หลายเดือนก่อน

      Hmm, I'll think about that. Using the id would be friendlier than the type name for hashing purposes for sure :)

  • @xthebumpx
    @xthebumpx 8 หลายเดือนก่อน +1

    Coke Zero gang! Went and got myself one before starting the stream

    • @codingwithmat
      @codingwithmat  8 หลายเดือนก่อน +1

      Coke zero makes you code better that's a fact

  • @ypathan420
    @ypathan420 8 หลายเดือนก่อน

    bruh.... u using edge... whyyyyyy ???

    • @codingwithmat
      @codingwithmat  8 หลายเดือนก่อน +4

      chad browser

    • @ChrisCarlos64
      @ChrisCarlos64 7 หลายเดือนก่อน

      I use it myself as well. It's Chromium at this point and personally Bing has been better at searching than Google's service lately IMO. (Still mostly use Duckduckgo).