public void RegisterBatchUpdate <UpdateInterface, T>(UpdateBucketWithUpdater <UpdateInterface> .BatchUpdateDelegate batch_update)
    {
        string text  = MakeBucketId(typeof(T), GetUpdateRate <UpdateInterface>());
        Entry  value = ManifestEntry <UpdateInterface>(text, false);

        DebugUtil.DevAssert(GetImplementedInterfaces(typeof(T)).Contains(GetUpdateRate <UpdateInterface>()), "T does not implement the UpdateInterface it is registering for BatchUpdate under");
        DebugUtil.DevAssert(value.buckets.Length == 1, "don't do a batch update with load balancing because load balancing will produce many small batches which is inefficient");
        ((UpdateBucketWithUpdater <UpdateInterface>)value.buckets[0]).batch_update_delegate = batch_update;
        bucketTable[text] = value;
    }
        public static void FindEggToGuard(List <UpdateBucketWithUpdater <Instance> .Entry> instances, float time_delta)
        {
            ListPool <KPrefabID, EggProtectionMonitor> .PooledList pooledList = ListPool <KPrefabID, EggProtectionMonitor> .Allocate();

            pooledList.Capacity = Mathf.Max(pooledList.Capacity, Components.Pickupables.Count);
            IEnumerator enumerator = Components.Pickupables.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Pickupable pickupable = (Pickupable)enumerator.Current;
                    pooledList.Add(pickupable.gameObject.GetComponent <KPrefabID>());
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            ListPool <Egg, EggProtectionMonitor> .PooledList pooledList2 = ListPool <Egg, EggProtectionMonitor> .Allocate();

            find_eggs_job.Reset(pooledList);
            for (int i = 0; i < pooledList.Count; i += 256)
            {
                find_eggs_job.Add(new FindEggsTask(i, Mathf.Min(i + 256, pooledList.Count)));
            }
            GlobalJobManager.Run(find_eggs_job);
            for (int j = 0; j != find_eggs_job.Count; j++)
            {
                find_eggs_job.GetWorkItem(j).Finish(pooledList, pooledList2);
            }
            pooledList.Recycle();
            foreach (UpdateBucketWithUpdater <Instance> .Entry instance in instances)
            {
                UpdateBucketWithUpdater <Instance> .Entry current = instance;
                GameObject eggToGuard = null;
                int        num        = 100;
                foreach (Egg item in pooledList2)
                {
                    Egg current2       = item;
                    int navigationCost = current.data.navigator.GetNavigationCost(current2.cell);
                    if (navigationCost != -1 && navigationCost < num)
                    {
                        eggToGuard = current2.game_object;
                        num        = navigationCost;
                    }
                }
                current.data.SetEggToGuard(eggToGuard);
            }
            pooledList2.Recycle();
        }
    public Handle Schedule <SimUpdateType>(string name, UpdateBucketWithUpdater <SimUpdateType> .IUpdater bucket_updater, UpdateRate update_rate, SimUpdateType updater, bool load_balance = false)
    {
        Entry value = ManifestEntry <SimUpdateType>(name, load_balance);
        UpdateBucketWithUpdater <SimUpdateType> updateBucketWithUpdater = (UpdateBucketWithUpdater <SimUpdateType>)value.buckets[value.nextBucketIdx];
        Handle result = default(Handle);

        result.handle       = updateBucketWithUpdater.Add(updater, Singleton <StateMachineUpdater> .Instance.GetFrameTime(update_rate, updateBucketWithUpdater.frame), bucket_updater);
        result.bucket       = updateBucketWithUpdater;
        value.nextBucketIdx = (value.nextBucketIdx + 1) % value.buckets.Length;
        bucketTable[name]   = value;
        return(result);
    }
Exemplo n.º 4
0
            public BatchUpdateContext(List <UpdateBucketWithUpdater <ISim200ms> .Entry> amount_instances, float time_delta)
            {
                for (int i = 0; i != amount_instances.Count; i++)
                {
                    UpdateBucketWithUpdater <ISim200ms> .Entry value = amount_instances[i];
                    value.lastUpdateTime = 0f;
                    amount_instances[i]  = value;
                }
                this.amount_instances = amount_instances;
                this.time_delta       = time_delta;
                results = ListPool <Result, AmountInstance> .Allocate();

                results.Capacity = this.amount_instances.Count;
            }
Exemplo n.º 5
0
 public void Run(BatchUpdateContext context)
 {
     for (int i = start; i != end; i++)
     {
         UpdateBucketWithUpdater <ISim200ms> .Entry entry = context.amount_instances[i];
         AmountInstance amountInstance = (AmountInstance)entry.data;
         float          num            = amountInstance.GetDelta() * context.time_delta;
         if (num != 0f)
         {
             context.results.Add(new BatchUpdateContext.Result
             {
                 amount_instance = amountInstance,
                 previous        = amountInstance.value,
                 delta           = num
             });
             amountInstance.SetValue(amountInstance.value + num);
         }
     }
 }
 public static void ModifyBrightness(List <UpdateBucketWithUpdater <Instance> .Entry> instances, ModifyLuxDelegate modify_lux, float time_delta)
 {
     modify_brightness_job.Reset(null);
     for (int i = 0; i != instances.Count; i++)
     {
         UpdateBucketWithUpdater <Instance> .Entry value = instances[i];
         value.lastUpdateTime = 0f;
         instances[i]         = value;
         Instance data = value.data;
         modify_lux(data, time_delta);
         data.light.Range = data.originalRange * (float)data.light.Lux / (float)data.originalLux;
         data.light.RefreshShapeAndPosition();
         if (data.light.RefreshShapeAndPosition() != 0)
         {
             modify_brightness_job.Add(new ModifyBrightnessTask(data.light.emitter));
         }
     }
     GlobalJobManager.Run(modify_brightness_job);
     for (int j = 0; j != modify_brightness_job.Count; j++)
     {
         modify_brightness_job.GetWorkItem(j).Finish();
     }
 }