예제 #1
0
        public long GenerateId()
        {
            uint time = TimeSince2020();

            if (time == lastIdTime)
            {
                ++this.idThisSecCount;
            }
            else
            {
                this.lastIdTime     = time;
                this.idThisSecCount = 1;
            }
            if (this.idThisSecCount == ushort.MaxValue)
            {
                Log.Error($"id count per sec overflow: {this.idThisSecCount}");
            }


            if (++value > ushort.MaxValue - 1)
            {
                this.value = 0;
            }
#if SERVER
            IdStruct idStruct = new IdStruct(time, Game.Options.Process, value);
#else
            IdStruct idStruct = new IdStruct(time, 0, value);
#endif
            return(idStruct.ToLong());
        }
예제 #2
0
파일: IdGenerater.cs 프로젝트: wqaetly/ET
        public long GenerateId()
        {
            uint time = TimeSince2020();

            if (time > this.lastIdTime)
            {
                this.lastIdTime = time;
                this.value      = 0;
            }
            else
            {
                ++this.value;

                if (value > ushort.MaxValue - 1)
                {
                    this.value = 0;
                    ++this.lastIdTime; // 借用下一秒
                    Log.Error($"id count per sec overflow: {time} {this.lastIdTime}");
                }
            }

            IdStruct idStruct = new IdStruct(this.lastIdTime, GlobalDefine.Options.Process, value);

            return(idStruct.ToLong());
        }
예제 #3
0
        public static long GenerateId()
        {
            long time = TimeHelper.ClientNowSeconds();

            if (time != lastTime)
            {
                value    = 0;
                lastTime = time;
            }

            if (++value > ushort.MaxValue - 1)
            {
                Log.Error($"id is not enough! value: {value}");
            }

            if (time > int.MaxValue)
            {
                Log.Error($"time > int.MaxValue value: {time}");
            }

            IdStruct idStruct = new IdStruct(process, (uint)time, (ushort)value);

            return(idStruct.ToLong());
        }