Example #1
0
        private void EnsureEntities(Meta Meta)
        {
            //CMloInstanceDefs = MetaTypes.ConvertDataArray<CMloInstanceDef>(Meta, MetaName.CMloInstanceDef, CMapData.entities);
            CMloInstanceDefs = MetaTypes.GetTypedDataArray <CMloInstanceDef>(Meta, MetaName.CMloInstanceDef);
            if (CMloInstanceDefs != null)
            {
            }

            var eptrs = MetaTypes.GetPointerArray(Meta, CMapData.entities);

            //CEntityDefs = MetaTypes.ConvertDataArray<CEntityDef>(Meta, MetaName.CEntityDef, CMapData.entities);
            CEntityDefs = MetaTypes.GetTypedDataArray <CEntityDef>(Meta, MetaName.CEntityDef);
            if (CEntityDefs != null)
            {
            }



            int instcount = 0;

            if (CEntityDefs != null)
            {
                instcount += CEntityDefs.Length;
            }
            if (CMloInstanceDefs != null)
            {
                instcount += CMloInstanceDefs.Length;
            }

            if (instcount > 0)
            {
                //build the entity hierarchy.
                List <YmapEntityDef> roots   = new List <YmapEntityDef>(instcount);
                List <YmapEntityDef> alldefs = new List <YmapEntityDef>(instcount);

                if (CEntityDefs != null)
                {
                    for (int i = 0; i < CEntityDefs.Length; i++)
                    {
                        YmapEntityDef d = new YmapEntityDef(this, i, ref CEntityDefs[i]);
                        alldefs.Add(d);
                    }
                }
                if (CMloInstanceDefs != null)
                {
                    for (int i = 0; i < CMloInstanceDefs.Length; i++)
                    {
                        YmapEntityDef d = new YmapEntityDef(this, i, ref CMloInstanceDefs[i]);
                        alldefs.Add(d);
                    }
                }


                for (int i = 0; i < alldefs.Count; i++)
                {
                    YmapEntityDef d      = alldefs[i];
                    int           pind   = d.CEntityDef.parentIndex;
                    bool          isroot = false;
                    if ((pind < 0) || (pind >= alldefs.Count) || (pind >= i)) //index check? might be a problem
                    {
                        isroot = true;
                    }
                    else
                    {
                        YmapEntityDef p = alldefs[pind];
                        if ((p.CEntityDef.lodLevel <= d.CEntityDef.lodLevel) ||
                            ((p.CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) &&
                             (d.CEntityDef.lodLevel != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)))
                        {
                            isroot = true;
                            p      = null;
                        }
                    }

                    if (isroot)
                    {
                        roots.Add(d);
                    }
                    else
                    {
                        YmapEntityDef p = alldefs[pind];
                        p.AddChild(d);
                    }
                }
                for (int i = 0; i < alldefs.Count; i++)
                {
                    alldefs[i].ChildListToArray();
                }

                AllEntities  = alldefs.ToArray();
                RootEntities = roots.ToArray();


                foreach (var ent in AllEntities)
                {
                    ent.Extensions = MetaTypes.GetExtensions(Meta, ent.CEntityDef.extensions);
                }
            }
        }