示例#1
0
文件: Group.cs 项目: flycodes/NanoECS
    public bool Remove(TEntity entity)
    {
        existingEntities = null;

        if (onAddCreated)
        {
            onAdd.Remove(entity);
        }

        if (!entity.IsReserved)
        {
            if (onRemoveCreated)
            {
                onRemove.Add(entity);
            }
        }
        else
        {
            if (onRemoveCreated)
            {
                onRemove.Remove(entity);
            }
        }

        var mayRemove = Entities.Remove(entity);

        RemoveFromCollectors(entity);

#if NANOECS_VERBOSE_DEBUG
        var res = mayRemove ? " succesfully removed from the " + Name : " not removed from the " + Name + ". It doesn't contain this";
        UnityEngine.Debug.Log("entity" + entity.ID + res);
#endif
        return(mayRemove);
    }
示例#2
0
文件: Group.cs 项目: flycodes/NanoECS
    public void InternalTryAddToOnDestroy(TEntity entity)
    {
        if (!onDestroyCreated)
        {
            return;
        }

        onDestroy.Add(entity);
    }
示例#3
0
 protected virtual void OnChannelDetachedAsync(
     Channel <Message> channel, ref Collector <ValueTask> taskCollector)
 {
     if (!ChannelProcessors.TryGetValue(channel, out var channelProcessor))
     {
         return;
     }
     taskCollector.Add(channelProcessor.DisposeAsync());
 }
示例#4
0
 public override void Process()
 {
     _srcGetter(ref _value);
     _dstGetter(ref _hash);
     // The two arrays should be consistent in their density, length, count, etc.
     Contracts.Assert(_value.IsDense == _hash.IsDense);
     Contracts.Assert(_value.Length == _hash.Length);
     Contracts.Assert(_value.Count == _hash.Count);
     for (int i = 0; i < _value.Count; ++i)
     {
         Collector.Add(_hash.Values[i], _value.Values[i]);
     }
 }
示例#5
0
                public override void Process()
                {
                    // REVIEW: This is suboptimal. We're essentially getting the source value
                    // twice, since the hash function will also do this. On the other hand, the obvious
                    // refactoring of changing the hash getter to be a value mapper and using that, I
                    // think has a disadvantage of incurring an *additional* delegate call within the
                    // getter, and possibly that's worse than this (since that would always be a cost
                    // for every application of the transform, and this is a cost only at the start,
                    // in some very specific situations I suspect will be a minority case).

                    // We don't get the source until we're certain we want to retain that value.
                    _dstGetter(ref _hash);
                    // Missing values do not get KeyValues. The first entry in the KeyValues metadata
                    // array corresponds to the first valid key, that is, where dstSlot is 1.
                    Collector.Add(_hash, _srcGetter, ref _value);
                }
示例#6
0
文件: Group.cs 项目: flycodes/NanoECS
    public bool Add(TEntity entity)
    {
        var mayAdd = Entities.Add(entity);

        if (mayAdd)
        {
            existingEntities = null;
            if (onAddCreated)
            {
                onAdd.Add(entity);
            }
        }

#if NANOECS_VERBOSE_DEBUG
        var res = mayAdd ? " succesfully added to the " + Name : " not added to the " + Name + ". It already contains this";
        UnityEngine.Debug.Log("entity" + entity.ID + res);
#endif
        return(mayAdd);
    }
 public void Add(T item)
 {
     Collector.Add(item);
 }
示例#8
0
        /// <summary>
        /// 추천친구 리스트
        /// </summary>
        /// <param name="gameUID"></param>
        /// <param name="proto"></param>
        /// <returns></returns>
        public async Task <(eNetworkResult, CommonLib.Protocol.Recommend_Friend_List_Response)> RecommendFriendListAsync(uint gameUID)
        {
            CommonLib.Protocol.Recommend_Friend_List_Response proto = new CommonLib.Protocol.Recommend_Friend_List_Response();


            long resultSize = 12;
            long resultHalf = resultSize / 2;
            //List<CommonLib.Protocol.Friend> friends = new List<CommonLib.Protocol.Friend>();

            var collector = new Collector();

            collector.Add(Key.GameUID, gameUID);

            var assetController = collector.Regist <Controller.AccountAsset>();

            if (await assetController.GetAsync() == false)
            {
                GameLog.Log(LogLevel.Error, $"RemoteDictionary.Community.RecommendFriend() AccountAsset.Get() Fail, gameUID={gameUID}");
                return(eNetworkResult.RECOMMEND_FRIEND_FAIL_TO_GET_ASSET, proto);
            }

            var  levelKey = CoreLib.Redis.Key.RecommendFriendLevel();
            long endPos   = await Redis.SortedSetLengthAsync(levelKey);

            //한건도 없는 경우 체크
            if (endPos >= 0)
            {
                long pos = endPos;

                var uidArray = await Redis.SortedSetRangeByScoreAsync(levelKey, assetController.Level, assetController.Level, take : 1, order : Order.Descending);

                int range = 1;
                while (uidArray.Length == 0)
                {
                    if (range > 10)
                    {
                        break;
                    }
                    uidArray = await Redis.SortedSetRangeByScoreAsync(levelKey, assetController.Level - range, assetController.Level + range, take : 1, order : Order.Descending);

                    range++;
                }

                if (uidArray.Length > 0)
                {
                    var rank = await Redis.SortedSetRankAsync(levelKey, uidArray[0]);

                    if (rank.HasValue)
                    {
                        pos = rank.Value;
                    }
                }

                var start = pos - resultHalf;
                var end   = pos + resultHalf;

                //오버 체크
                if (end > endPos)
                {
                    var length = end - endPos;
                    //뒤에 인원이 부족하면 앞으로
                    start -= length;
                }

                if (start < 0)
                {
                    start = 0;
                }

                //최종 조율
                end = start + resultSize;
                if (end > endPos)
                {
                    end = endPos;
                }

                var uids = await Redis.SortedSetRangeByRankAsync(levelKey, start, end);

                foreach (var uid in uids)
                {
                    //todo 나중에 친구 관계도 체크 해야함
                    if ((ulong)uid == gameUID)
                    {
                        continue;
                    }
                    if (proto.Friends.Count == 10)
                    {
                        break;
                    }

                    var cacheKey = CoreLib.Redis.Key.RecommendFriendCache((uint)uid);
                    //비동기라 꼼꼼하게 체크해야 함
                    if (await Redis.KeyExistsAsync(cacheKey))
                    {
                        var cache = await Redis.StringGetAsync(cacheKey);

                        //비동기라 꼼꼼하게 체크해야 함
                        if (cache.HasValue)
                        {
                            var friend = MessagePackSerializer.Deserialize <db_friend>(cache);

                            var packetFriend = new CommonLib.Protocol.Friend()
                            {
                                GameUID   = friend.gameUID,
                                ProfileID = friend.profileID,
                                WorldName = friend.worldName,
                                Level     = friend.level,
                            };

                            proto.Friends.Add(packetFriend);
                        }
                    }
                }
            }

            return(eNetworkResult.SUCCESS, proto);
        }
示例#9
0
        public async Task <(eNetworkResult, CommonLib.Protocol.Recommend_Friend_Info_Response)> RecommendFriendInfoAsync(uint gameUID, uint targetGameUID)
        {
            CommonLib.Protocol.Recommend_Friend_Info_Response proto = new CommonLib.Protocol.Recommend_Friend_Info_Response()
            {
                Account = new CommonLib.Protocol.Friend(),
            };

            proto.Account.GameUID = 0;

            var cacheKey = CoreLib.Redis.Key.RecommendFriendCache(targetGameUID);

            //비동기라 꼼꼼하게 체크해야 함
            if (await Redis.KeyExistsAsync(cacheKey))
            {
                var cache = await Redis.StringGetAsync(cacheKey);

                //비동기라 꼼꼼하게 체크해야 함
                if (cache.HasValue)
                {
                    var friend = MessagePackSerializer.Deserialize <db_friend>(cache);

                    proto.Account.GameUID   = friend.gameUID;
                    proto.Account.ProfileID = friend.profileID;
                    proto.Account.WorldName = friend.worldName;
                    proto.Account.Level     = friend.level;

                    foreach (var dbBuilding in friend.buildings)
                    {
                        proto.Account.Buildings.Add(new CommonLib.Protocol.Building2()
                        {
                            BuildingUID = dbBuilding.BuildingUID,
                            BuildingID  = dbBuilding.BuildingID,
                            PosX        = dbBuilding.PosX,
                            PosY        = dbBuilding.PosY,
                            PosZ        = dbBuilding.PosZ,
                            Rot         = dbBuilding.Rot,
                            Level       = dbBuilding.Level,
                            Status      = (CommonLib.Protocol.Building2.Types.eStatus)dbBuilding.Status,
                            SkinID      = dbBuilding.SkinID,
                        });
                    }

                    foreach (var dbFish in friend.fishes)
                    {
                        proto.Account.Fishes.Add(new CommonLib.Protocol.Fish()
                        {
                            FishUID     = dbFish.FishUID,
                            FishID      = dbFish.FishID,
                            Status      = (CommonLib.Protocol.Fish.Types.eStatus)dbFish.Status,
                            AcquireTime = dbFish.AcquireTime.Ticks,
                            Size        = dbFish.Size,
                            GrowthLevel = dbFish.GrowthLevel,
                            GrowthExp   = dbFish.GrowthExp,
                            GrowthTime  = dbFish.GrowthTime.Ticks
                        });
                    }
                }
            }

            //캐시에서 찾을 수 없음
            if (proto.Account.GameUID == 0)
            {
                var collector = new Collector();
                collector.Add(Key.GameUID, targetGameUID);

                var assetController = collector.Regist <Controller.AccountAsset>();
                if (await assetController.GetAsync() == false)
                {
                    GameLog.Log(LogLevel.Error, $"RemoteDictionary.Community.RecommendFriendInfo() AccountAsset.Get() Fail, gameUID={gameUID}");
                    return(eNetworkResult.RECOMMEND_FRIEND_INFO_FAIL_TO_GET_ASSET, proto);
                }

                proto.Account.GameUID   = targetGameUID;
                proto.Account.ProfileID = assetController.ProfileID;
                proto.Account.WorldName = assetController.WorldName;
                proto.Account.Level     = assetController.Level;

                var buildingsController = collector.Regist <Controller.BuildingFindall>();

                if (await buildingsController.GetAsync() == false)
                {
                    GameLog.Log(LogLevel.Error, $"RemoteDictionary.Community.RecommendFriendInfo() BuildingFindall.Get, gameUID={gameUID}");
                    return(eNetworkResult.RECOMMEND_FRIEND_INFO_FAIL_TO_LOAD_GETBUILDINGS, proto);
                }

                foreach (var dbBuilding in buildingsController.DBValues)
                {
                    proto.Account.Buildings.Add(new CommonLib.Protocol.Building2()
                    {
                        BuildingUID = dbBuilding.BuildingUID,
                        BuildingID  = dbBuilding.BuildingID,
                        PosX        = dbBuilding.PosX,
                        PosY        = dbBuilding.PosY,
                        PosZ        = dbBuilding.PosZ,
                        Rot         = dbBuilding.Rot,
                        Level       = dbBuilding.Level,
                        Status      = (CommonLib.Protocol.Building2.Types.eStatus)dbBuilding.Status,
                        SkinID      = dbBuilding.SkinID,
                    });
                }

                var fishesController = collector.Regist <Controller.FishesFindall>();

                if (await fishesController.GetAsync() == false)
                {
                    GameLog.Log(LogLevel.Error, $"RemoteDictionary.Community.RecommendFriendInfo() Fishes.Get, gameUID={gameUID}");
                    return(eNetworkResult.RECOMMEND_FRIEND_INFO_FAIL_TO_LOAD_FISHES, proto);
                }

                foreach (var dbFish in fishesController.Values)
                {
                    proto.Account.Fishes.Add(new CommonLib.Protocol.Fish()
                    {
                        FishUID     = dbFish.FishUID,
                        FishID      = dbFish.FishID,
                        Status      = (CommonLib.Protocol.Fish.Types.eStatus)dbFish.Status,
                        AcquireTime = dbFish.AcquireTime.Ticks,
                        Size        = dbFish.Size,
                        GrowthLevel = dbFish.GrowthLevel,
                        GrowthExp   = dbFish.GrowthExp,
                        GrowthTime  = dbFish.GrowthTime.Ticks
                    });
                }
            }

            return(eNetworkResult.SUCCESS, proto);
        }