コード例 #1
0
ファイル: SDS.cs プロジェクト: IronFox/Shard
        public SDS MergeWith(SDS other, MergeStrategy strategy, EntityChange.ExecutionContext ctx)
        {
            if (Generation != other.Generation)
            {
                throw new IntegrityViolation("Generation mismatch: " + Generation + " != " + other.Generation);
            }

            SDS exclusiveSource = null;
            int exclusiveChoice = 0;

            if (strategy == MergeStrategy.Exclusive || strategy == MergeStrategy.ExclusiveWithPositionCorrection)
            {
                exclusiveChoice = SelectExclusiveSource(this, other);
                exclusiveSource = (exclusiveChoice == -1 ? this : other);
            }

            InconsistencyCoverage merged = InconsistencyCoverage.GetMinimum(IC, other.IC);
            EntityPool            pool   = new EntityPool(ctx);

            foreach (var e in this.FinalEntities)
            {
                if (IC.IsInconsistentR(ctx.LocalSpace.Relativate(e.ID.Position)))
                {
                    continue;                       //for now
                }
                pool.Insert(e);
            }
            foreach (var e in other.FinalEntities)
            {
                if (other.IC.IsInconsistentR(ctx.LocalSpace.Relativate(e.ID.Position)))
                {
                    continue;                       //for now
                }
                if (pool.Contains(e.ID.Guid))
                {
                    continue;
                }
                pool.Insert(e);
            }
            //at this point we merged all fully consistent entities from either. If the inconsistent areas did not overlap then the result should contain all entities in their consistent state


            if (!merged.IsFullyConsistent)
            {
                if (strategy == MergeStrategy.EntitySelective)
                {
                    MergeInconsistentEntitiesComp(pool, this, other, merged, ctx);
                }
                else
                {
                    MergeInconsistentEntitiesEx(pool, exclusiveSource, strategy == MergeStrategy.ExclusiveWithPositionCorrection, merged, ctx);
                }
            }
            return(new SDS(Generation, pool.ToArray(), merged));
        }
コード例 #2
0
        public Tuple <SDS, IntermediateSDS> Complete()
        {
            //Log.Message("Finalize SDS g" + generation);

            var cs = data.localChangeSet.Clone();
            InconsistencyCoverage ic = data.ic.Clone();

            foreach (var n in Simulation.Neighbors)
            {
                IntBox box = n.ICImportRegion;

                var rcs = old.InboundRCS[n.LinearIndex];
                if (rcs != null)
                {
                    cs.Include(rcs.CS);
                    ic.Include(rcs.IC, box.Min);
                    if (rcs.IC.OneCount > 0)
                    {
                        Log.Message(n.Name + ": Inconsistent RCS @g" + generation + ": " + rcs.IC.OneCount);
                    }
                }
                else
                {
                    Log.Message(n.Name + ": Missing RCS @g" + generation);
                    ic.SetOne(box);
                }
            }
            EntityPool p2 = data.entities.Clone();

            cs.Execute(p2, ic, ctx);

            SDS rs = new SDS(generation, p2.ToArray(), ic);

#if !DRY_RUN
            if (!ic.AnySet)
            {
                DB.PutAsync(new SerialSDS(rs, Simulation.ID.XYZ), false).Wait();
            }
#endif
            Log.Message("Completed g" + Generation + " with IC ones: " + ic.OneCount + " " + Math.Round((float)ic.OneCount / ic.Size.Product * 100) + "%");
            return(new Tuple <SDS, IntermediateSDS>(rs, data));
        }