github PixeyeHQ/actors.unity 2019.08.30
Actors Framework

latest releases: 2020.06.5, 2020.06.4, 2020.06.3...
5 years ago

Breaking changes :

  • Processors can work as groups. It's useful when you want to have only one group in the processor.
    // Add OnAdd, OnRemove events for group.
    [GroupWantEvent(Op.Add | Op.Remove)]
    sealed class ProcessorObserver : Processor<ComponentObserver>, ITick
    {
        public void Tick(float delta)
        {
            for (int i = 0; i <  source.length; i++)
            {
                ref var cObserver = ref source.entities[i].ComponentObserver();
                for (int j = 0; j < cObserver.length; j++)
                    cObserver.wrappers[j].Check();
            }
        }

        public override void OnAdd(ent[] entities, int length)
        {
            for (int i = 0; i < length; i++)
            {
                ref var cObserver = ref entities[i].ComponentObserver();
                for (int j = 0; j < cObserver.length; j++)
                    cObserver.wrappers[j].FirstTime();
            }
        }
        public override void OnRemove(ent[] entities, int length)
        {
            for (int i = 0; i < length; i++)
            {
                ref var cObserver = ref entities[i].ComponentObserver();
                for (int j = 0; j < cObserver.length; j++)
                    cObserver.wrappers[j].Check();
            }
        }
    }
  • OnAdd / OnRemove delegates for entities groups were changed with event class. Also the event method holds all entities that were added/removed to the group at the current frame.
sealed class ProcessorUI : Processor, ITick
    {
        Group<ComponentUI> groupUI;

        public ProcessorUI()
        {
           // Add Events to the group and choose event type.
            groupUI.Set<Events>(Op.Remove);
          // You can choose both events as well.
         //   groupUI.Set<Events>(Op.Add|Op.Remove);
        }

        // Make a special class for events.
        class Events : GroupEvents
        {
            public override void OnRemove(ent[] entities, int length)
            {
                for (int i = 0; i < length; i++)
                {
                    ref var entity = ref entities[i];
                    var     cUI    = entity.ComponentUI();
                    cUI.view.Release();
                }
            }
        }
}
  • Components boilerplate code have changed.
 sealed class ComponentFSM
    {
        public IFSM source;
        public int stateNext = -1;
        public int stateCurrent = -1;
    }


    #region HELPERS

    static partial class Components
    {
     
       static SComponentFSM sComponentFSM = new SComponentFSM();
        
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        internal static ref ComponentFSM ComponentFSM(in this ent entity)
        =>  ref Storage<ComponentFSM>.components[entity.id];
        
        
        internal class SComponentFSM : Storage<ComponentFSM>.Setup
        {
           //  Component create method.
            public override ComponentFSM Create() => new ComponentFSM();

          // Optional dispose method for all components that must be removed on the current frame.
         // Use this method to revert component to default setup or clean links.
            public override void Dispose(int[] id, int len)
            {
                for (int i = 0; i < len; i++)
                {
                    ref var component = ref components[id[i]];
                    component.source       = null;
                    component.stateCurrent = -1;
                    component.stateNext    = -1;
                }
            }
        }
    }

Don't miss a new actors.unity release

NewReleases is sending notifications on new releases.