コード例 #1
0
ファイル: WorldClone.cs プロジェクト: yika-aixi/TrueSync
        public void Clone(IWorld iWorld, bool doChecksum)
        {
            World world = (World)iWorld;

            Reset();

            if (doChecksum)
            {
                checksum = ChecksumExtractor.GetEncodedChecksum();
            }

            clonedPhysics.Clear();

            foreach (RigidBody rb in world.RigidBodies)
            {
                RigidBodyClone rigidBodyClone = poolRigidBodyClone.GetNew();
                rigidBodyClone.Clone(rb);

                clonedPhysics.Add(rb.GetInstance(), rigidBodyClone);
            }

            clonedArbiters.Clear();
            foreach (Arbiter arb in world.ArbiterMap.Arbiters)
            {
                ArbiterClone arbiterClone = poolArbiterClone.GetNew();
                arbiterClone.Clone(arb);

                clonedArbiters.Add(arbiterClone);
            }

            clonedArbitersTrigger.Clear();
            foreach (Arbiter arb in world.ArbiterTriggerMap.Arbiters)
            {
                ArbiterClone arbiterClone = poolArbiterClone.GetNew();
                arbiterClone.Clone(arb);

                clonedArbitersTrigger.Add(arbiterClone);
            }

            collisionIslands.Clear();

            for (index = 0, length = world.islands.Count; index < length; index++)
            {
                CollisionIsland ci = world.islands[index];

                CollisionIslandClone collisionIslandClone = poolCollisionIslandClone.GetNew();
                collisionIslandClone.Clone(ci);

                collisionIslands.Add(collisionIslandClone);
            }

            cloneCollision.Clone((CollisionSystemPersistentSAP)world.CollisionSystem);

            clonedInitialCollisions.Clear();
            clonedInitialCollisions.AddAll(world.initialCollisions);

            clonedInitialTriggers.Clear();
            clonedInitialTriggers.AddAll(world.initialTriggers);

            rigidBodyInstanceCount  = RigidBody.instanceCount;
            constraintInstanceCount = Constraint.instanceCount;
        }
コード例 #2
0
ファイル: ConfigParser.cs プロジェクト: yeins/Iso85834Net
        private static void ParseGuides <T>(XmlNodeList nodes,
                                            MessageFactory <T> mfact) where T : IsoMessage
        {
            ArrayList <XmlElement> subs = null;
            var guides = new HashDictionary <int, HashDictionary <int, FieldParseInfo> >();

            for (var i = 0; i < nodes.Count; i++)
            {
                var elem = (XmlElement)nodes.Item(i);
                if (elem != null)
                {
                    var type = ParseType(elem.GetAttribute("type"));
                    if (type == -1)
                    {
                        throw new IOException("Invalid ISO8583 type for parse guide: " + elem.GetAttribute("type"));
                    }
                    if (elem.GetAttribute("extends") != null && !elem.GetAttribute("extends").IsEmpty())
                    {
                        if (subs == null)
                        {
                            subs = new ArrayList <XmlElement>(nodes.Count - i);
                        }
                        subs.Add(elem);
                        continue;
                    }
                    var parseMap = new HashDictionary <int, FieldParseInfo>();
                    var fields   = elem.GetElementsByTagName("field");
                    for (var j = 0; j < fields.Count; j++)
                    {
                        var f = (XmlElement)fields.Item(j);
                        if (f != null && f.ParentNode == elem)
                        {
                            var num = int.Parse(f.GetAttribute("num"));
                            parseMap.Add(num,
                                         GetParser(f,
                                                   mfact));
                        }
                    }

                    mfact.SetParseMap(type,
                                      parseMap);
                    if (guides.Contains(type))
                    {
                        guides[type] = parseMap;
                    }
                    else
                    {
                        guides.Add(type,
                                   parseMap);
                    }
                }
            }
            if (subs != null)
            {
                foreach (var elem in subs)
                {
                    var type = ParseType(elem.GetAttribute("type"));
                    var @ref = ParseType(elem.GetAttribute("extends"));
                    if (@ref == -1)
                    {
                        throw new ArgumentException("Message template " + elem.GetAttribute("type") +
                                                    " extends invalid template " + elem.GetAttribute("extends"));
                    }
                    var parent = guides[@ref];
                    if (parent == null)
                    {
                        throw new ArgumentException("Parsing guide " + elem.GetAttribute("type") +
                                                    " extends nonexistent guide " + elem.GetAttribute("extends"));
                    }
                    var child = new HashDictionary <int, FieldParseInfo>();
                    child.AddAll(parent);
                    var fields = GetDirectChildrenByTagName(elem,
                                                            "field");
                    foreach (var f in fields)
                    {
                        var num     = int.Parse(f.GetAttribute("num"));
                        var typedef = f.GetAttribute("type");
                        if ("exclude".Equals(typedef))
                        {
                            child.Remove(num);
                        }
                        else
                        {
                            child.Add(num,
                                      GetParser(f,
                                                mfact));
                        }
                    }
                    mfact.SetParseMap(type,
                                      child);
                    if (guides.Contains(type))
                    {
                        guides[type] = child;
                    }
                    else
                    {
                        guides.Add(type,
                                   child);
                    }
                }
            }
        }