cache-friendliest way to initialize a struct from an enum argument associated with necessary data?

35 Views Asked by At

In my ECS game engine, my SpriteComponent has a constructor where the sole argument is an enum-type that represents a specific "instance" of the struct.

ex: the enum REDMAGIC is associated with the SpriteComponent struct values: {x,y,z}

These SpriteComponents are added to Entities at runtime for example when a player is shooting. To me, this means I want to construct SpriteComponents in the most cache-friendly way possible.

I have 3 approaches in mind:

  1. use a hashtable to get data and then assign to my new SpriteComponent ex: std::unordered_map<enum, {x,y,z}>

  2. use a vector or array to get data and then assign to my new SpriteComponent ex: std::vector<{x,y,z}>

  3. manually assign values with a bunch of case or if statements:

     switch(enum){
         case REDMAGIC:
              x = 1;
              y = 2;
              z = 3;
         case BLUEMAGIC:
              ...
    

I am new to data-oriented design and do not know how to reason about which approach would be best for cache-friendliness. I am concerned about using switch/case or a lot of if statements because there will be over 100 different possibilities. any input would be appreciate, thank you.

0

There are 0 best solutions below