Beispiel #1
0
        // combination of proxy and composite design patterns
        // allows you to implement a pattern or a construct which is called
        static void CompositeProxy()
        {
            // every single creature increase the X to move them
            var creatures = new Creature2[100]; // ARRAY OF STRUCTURES

            // Age X Y Age X Y Age X Y - cpu has to jump on X's

            // Much faster, how can we implement this
            // Age Age Age Age
            // X X X X
            // Y Y Y Y
            foreach (var c in creatures)
            {
                // is not memory efficient
                // modern cpus like data next to each other in a predictable sequence
                c.X++;
            }

            var creatures2 = new Creatures(100); // STRUCTURE OF ARRAYS

            // AOS/SOA DUALITY REPRESENT THINGS ONE WAY OR ANOTHER, in other languages is implemented implicitily
            // We can build proxies that pretty much do the same thing.
            // type of c is Creatures.CreatureProxy
            foreach (var c in creatures2)
            {
                // modify each one of the creatures
                // we modify something on the proxy

                // I am referencing creatures.x[index] and use thisr eference to increment the value
                c.X++;
            }
        }
 // reference to all creatures
 // reference to the index of the creature
 public CreatureProxy(Creatures creatures, int index)
 {
     _creatures = creatures;
     _index     = index;
 }