Ejemplo n.º 1
0
        /// <summary>
        /// Generate the fastest possible accessor for the given property. See more details on <see cref="MemberAccessor"/>
        /// </summary>
        internal static void DoGeneratePropertyAccessor(ref MemberAccessor accessor, MapItemInfo item, Converter parentItem, PropertyInfo property)
        {
            // All property optimizations rely on the parent being a reference-type.
            if (!parentItem.IsValueItemType)
            {
                // Value type property - Just support some basic primitives.
                if (item.IsValueTypeItem)
                {
                    // Rationale: Generating an accessor for value types is very difficult, as JIT gen
                    // for value types varies wildly and is too implementation-specific. Since this
                    // is only designed to be a quick and dirty fast accessor anyway, it's easiest if
                    // we only support the very basic primitives (which are very common anyway)
                    // and nothing more. "MakeGenericMethod" is too expensive.
                    bool successful = TryGenerateAccessorPrimitive(ref accessor, parentItem.ItemType, item.GetItemType(), property);
                    if (successful)
                    {
                        return;
                    }
                }

                // Reference type property - Simply force cast to "object".
                else
                {
                    CreateAllRefTypeAccessor(ref accessor, parentItem.ItemType, item.GetItemType(), property);
                    return;
                }
            }

            // Unoptimized
            accessor.Initialize(MemberAccessorType.SlowProperty, property, null);
        }
Ejemplo n.º 2
0
        static void PopulateTypeInfo(ref ArrayTypeInfo info, MapItemInfo itemInfo, Type type)
        {
            int rank = type.GetArrayRank();

            info.ElementType = itemInfo.GetItemType();
            info.PerItem     = itemInfo;

            if (type.IsSZArray)
            {
                info.FastConversion = GetFastType(info.ElementType);
                info.Type           = ArrayType.SZArrayManual;

                //info.Type = info.FastConversion == FastConversionType.None ? ArrayType.SZArrayManual : ArrayType.SZArrayFast;
            }
            else if (rank == 1)
            {
                info.Rank = 1;
                info.Type = ArrayType.SNZArray;
            }
            else
            {
                if (rank == 32)
                {
                    throw new Exception("ABSave does not support arrays with exactly 32 dimensions, only below.");
                }
                info.Rank = (byte)rank;
                info.Type = ArrayType.MultiDimensional;
            }
        }
Ejemplo n.º 3
0
        internal MapItemInfo GetRuntimeMapItem(Type type)
        {
            MapGenerator?gen = GetGenerator();
            MapItemInfo  map = gen.GetRuntimeMap(type);

            ReleaseGenerator(gen);
            return(map);
        }
Ejemplo n.º 4
0
        void SerializeItemNoSetup(object obj, MapItemInfo info, ref BitTarget header, bool skipHeader)
        {
            Converter item = info.Converter;

            ABSaveUtils.WaitUntilNotGenerating(item);

            SerializeConverter(obj, info.Converter, ref header, skipHeader);
        }
Ejemplo n.º 5
0
        void SerializeActualType(object obj, Type type)
        {
            MapItemInfo info = GetRuntimeMapItem(type);

            var newTarget = new BitTarget(this);

            SerializeItemNoSetup(obj, info, ref newTarget, true);
        }
Ejemplo n.º 6
0
        object DeserializeItemNoSetup(MapItemInfo info, bool skipHeader)
        {
            Converter item = info.Converter;

            ABSaveUtils.WaitUntilNotGenerating(item);

            return(DeserializeConverter(info.Converter, skipHeader));
        }
Ejemplo n.º 7
0
 public object DeserializeExactNonNullItem(MapItemInfo info)
 {
     _currentHeader = new BitSource()
     {
         Deserializer = this
     };
     _readHeader = false;
     return(DeserializeItemNoSetup(info, true));
 }
Ejemplo n.º 8
0
        public void ResetStateWithMapFor(Type type)
        {
            ResetState();

            var gen = CurrentMap.GetGenerator();

            CurrentMapItem = gen.GetMap(type);
            ABSaveMap.ReleaseGenerator(gen);
        }
Ejemplo n.º 9
0
 public void SerializePossibleNullableItem(object obj, MapItemInfo info, ref BitTarget header)
 {
     // Say it's "not null" if it is nullable.
     if (info.IsNullable)
     {
         header.WriteBitOn();
     }
     SerializeItemNoSetup(obj, info, ref header, info.IsNullable);
 }
Ejemplo n.º 10
0
    /// <summary>
    /// Insantiates the status at given position and sets the info (sprite, text).
    /// For now only used for player.
    /// </summary>
    public void ShowMapItem(Vector2 pWorldPosition, MapItemInfo pInfo)
    {
        if (pInfo.StatusSprite == null)
        {
            Debug.Log($"Map item has no status defined");
            return;
        }

        ShowStatus(pWorldPosition, pInfo.StatusText, pInfo.StatusSprite);
    }
Ejemplo n.º 11
0
        public object?DeserializeItem(MapItemInfo info, ref BitSource header)
        {
            // Do null checks
            if (!info.IsValueTypeItem && !header.ReadBit())
            {
                return(null);
            }

            _currentHeader = header;
            _readHeader    = true;
            return(DeserializeNullableItem(info, false));
        }
Ejemplo n.º 12
0
        public static Units CreateMapItem(MapItemInfo info, UnitControlType unitControlType = UnitControlType.None)
        {
            if (info == null)
            {
                return(null);
            }
            SkillUnitData vo = Singleton <SkillUnitDataMgr> .Instance.GetVo(info.uniTypeId);

            if (vo == null)
            {
                return(null);
            }
            Dictionary <DataType, object> dictionary = new Dictionary <DataType, object>();

            dictionary.Add(DataType.NameId, info.uniTypeId);
            dictionary.Add(DataType.TeamType, (TeamType)info.group);
            if (info.unitId != 0)
            {
                dictionary.Add(DataType.UniqueId, info.unitId);
            }
            Units units;

            if (vo.IsBloodBall)
            {
                units = MapManager.Instance.SpawnBuffItem(dictionary, null, MoveController.SVectgor3ToVector3(info.burnPos), Quaternion.identity, unitControlType);
            }
            else
            {
                Units unit = MapManager.Instance.GetUnit(info.callUnitId);
                units = MapManager.Instance.SpawnSkillUnit(dictionary, null, MoveController.SVectgor3ToVector3(info.burnPos), Quaternion.identity, unitControlType, unit, info.callSkillId);
                HighEffectData vo2 = Singleton <HighEffectDataManager> .Instance.GetVo(info.hieffId);

                if (vo2 != null)
                {
                    List <Units> list = new List <Units>();
                    if (info.targetUnitIds != null)
                    {
                        for (int i = 0; i < info.targetUnitIds.Count; i++)
                        {
                            Units unit2 = MapManager.Instance.GetUnit(info.targetUnitIds[i]);
                            list.Add(unit2);
                        }
                    }
                    BornUnitAction.SetPosition(units, list, unit, vo2, MoveController.SVectgor3ToVector3(info.burnPos));
                }
            }
            if (units)
            {
                units.UpdateVisible();
            }
            return(units);
        }
Ejemplo n.º 13
0
        public void SerializeItem(object?obj, MapItemInfo item, ref BitTarget header)
        {
            if (obj == null)
            {
                header.WriteBitOff();
                header.Apply();
            }

            else
            {
                SerializePossibleNullableItem(obj, item, ref header);
            }
        }
Ejemplo n.º 14
0
        public void SerializeItem(object?obj, MapItemInfo item)
        {
            if (obj == null)
            {
                WriteByte(0);
            }

            else
            {
                var currentHeader = new BitTarget(this);
                SerializePossibleNullableItem(obj, item, ref currentHeader);
            }
        }
Ejemplo n.º 15
0
        object?DeserializeNullableItem(MapItemInfo info, bool skipHeader)
        {
            if (info.IsNullable)
            {
                EnsureReadHeader();
                if (!_currentHeader.ReadBit())
                {
                    return(null);
                }
                skipHeader = true;
            }

            return(DeserializeItemNoSetup(info, skipHeader));
        }
Ejemplo n.º 16
0
        public object?DeserializeItem(MapItemInfo info)
        {
            // Do null checks
            if (info.IsValueTypeItem)
            {
                _currentHeader = new BitSource()
                {
                    Deserializer = this
                };
                _readHeader = false;
            }
            else
            {
                _currentHeader = new BitSource(this);
                if (!_currentHeader.ReadBit())
                {
                    return(null);
                }

                _readHeader = true;
            }

            return(DeserializeNullableItem(info, false));
        }
Ejemplo n.º 17
0
 public void SerializeExactNonNullItem(object obj, MapItemInfo item, ref BitTarget header) =>
 SerializeItemNoSetup(obj, item, ref header, true);
Ejemplo n.º 18
0
        public void SerializeExactNonNullItem(object obj, MapItemInfo item)
        {
            var currentHeader = new BitTarget(this);

            SerializeItemNoSetup(obj, item, ref currentHeader, true);
        }
Ejemplo n.º 19
0
 public GenMap(object obj, MapItemInfo item) => (Obj, Item) = (obj, item);
Ejemplo n.º 20
0
 public object DeserializeExactNonNullItem(MapItemInfo info, ref BitSource header)
 {
     _currentHeader = header;
     _readHeader    = true;
     return(DeserializeItemNoSetup(info, true));
 }