private static void MS_InitPkLoop_Update(DateTime now) { ZhanDuiZhengBaMatchConfig matchConfig = ZhanDuiZhengBa_K._Config.MatchConfigList.Find((ZhanDuiZhengBaMatchConfig _m) => _m.ID == ZhanDuiZhengBa_K.SyncData.RealActID); List <ZhanDuiZhengBa_K.JoinRolePkData> tmpRoleDatas = new List <ZhanDuiZhengBa_K.JoinRolePkData>(); using (List <RangeKey> .Enumerator enumerator = ZhanDuiZhengBaUtils.GetDayPkGroupRange(ZhanDuiZhengBa_K.SyncData.RealActID).GetEnumerator()) { while (enumerator.MoveNext()) { RangeKey range = enumerator.Current; List <ZhanDuiZhengBa_K.JoinRolePkData> groupRoles = ZhanDuiZhengBa_K.TodayJoinRoleDatas.FindAll((ZhanDuiZhengBa_K.JoinRolePkData _r) => _r.Group >= range.Left && _r.Group <= range.Right); if (groupRoles != null && groupRoles.Count == 2) { ZhanDuiZhengBa_K.JoinRolePkData joinRole = groupRoles[0]; ZhanDuiZhengBa_K.JoinRolePkData joinRole2 = groupRoles[1]; if (joinRole.CurrGameID <= 0) { if (!ZhanDuiZhengBa_K.CreateGameFuBen(now, matchConfig, joinRole, joinRole2)) { return; } } } else if (groupRoles != null && groupRoles.Count == 1) { if (!Consts.TestMode) { ZhanDuiZhengBa_K.JoinRolePkData joinRole3 = groupRoles[0]; joinRole3.ToServerID = 0; joinRole3.CurrGameID = 0; joinRole3.WaitReqEnter = false; } else { ZhanDuiZhengBa_K.JoinRolePkData joinRole = groupRoles[0]; ZhanDuiZhengBa_K.JoinRolePkData joinRole2 = groupRoles[0]; if (joinRole.CurrGameID <= 0) { if (!ZhanDuiZhengBa_K.CreateGameFuBen(now, matchConfig, joinRole, joinRole2)) { return; } } } } } } ZhanDuiZhengBa_K.StateMachine.SetCurrState(5, now); }
public static void Init(XElement xml) { if (GameManager.FlagDisableNameServer) { Global.Flag_NameServer = false; return; } NameServerIP = Global.GetSafeAttributeStr(xml, "NameServer", "IP"); NameServerPort = (int)Global.GetSafeAttributeLong(xml, "NameServer", "Port"); ServerPingTaiID = Global.GetSafeAttributeStr(xml, "NameServer", "PingTaiID"); if (!int.TryParse(ServerPingTaiID, out NameServerConfig) || NameServerConfig > 1) { NameServerConfig = 1; } DefaultServerData.Host = NameServerIP; DefaultServerData.Port = NameServerPort; GetIPV4IP(DefaultServerData); if (!File.Exists("NameServer.xml")) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("警告:没有名字服务器列表文件(NameServer.xml)"); Console.ForegroundColor = ConsoleColor.White; return; } XElement xmlNameServer = XElement.Load("NameServer.xml"); foreach (var item in xmlNameServer.DescendantsAndSelf("Server")) { NameServerData serverData = new NameServerData(); serverData.ID = (int)Global.GetSafeAttributeLong(item, "ID"); serverData.Host = Global.GetSafeAttributeStr(item, "host"); serverData.Port = (int)Global.GetSafeAttributeLong(item, "port"); int start = (int)Global.GetSafeAttributeLong(item, "start"); int end = (int)Global.GetSafeAttributeLong(item, "end"); RangeKey range = new RangeKey(start, end); ZoneID2NameServerDict.Add(range, serverData); } }
private bool AssignGameFuben(KuaFuRoleData kuaFuRoleData, RangeKey range, DateTime now) { DateTime stateEndTime = now.AddSeconds((double)this.EnterGameSecs); TianTiFuBenData tianTiFuBenData = null; KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData { ServerId = kuaFuRoleData.ServerId, RoleId = kuaFuRoleData.RoleId }; List <KuaFuRoleData> updateRoleDataList = new List <KuaFuRoleData>(); if (!this.ProcessTianTiFuBenDataDict.TryGetValue(range, out tianTiFuBenData)) { tianTiFuBenData = new TianTiFuBenData(); this.ProcessTianTiFuBenDataDict.Add(range, tianTiFuBenData); } else if (!this.CanAddFuBenRole(tianTiFuBenData, kuaFuRoleData)) { return(true); } int roleCount = tianTiFuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData); bool result; if (roleCount < Consts.TianTiRoleCountTotal) { result = true; } else { try { int kfSrvId = 0; int gameId = this.Persistence.GetNextGameId(); bool createSuccess = ClientAgentManager.Instance().AssginKfFuben(this.GameType, (long)gameId, roleCount, out kfSrvId); if (createSuccess) { tianTiFuBenData.ServerId = kfSrvId; tianTiFuBenData.GameId = gameId; tianTiFuBenData.EndTime = Global.NowTime.AddMinutes(8.0); this.AddGameFuBen(tianTiFuBenData); this.Persistence.LogCreateTianTiFuBen(tianTiFuBenData.GameId, tianTiFuBenData.ServerId, 0, roleCount); foreach (KuaFuFuBenRoleData role in tianTiFuBenData.RoleDict.Values) { KuaFuRoleKey key = KuaFuRoleKey.Get(role.ServerId, role.RoleId); KuaFuRoleData kuaFuRoleDataTemp; if (this.RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleDataTemp)) { kuaFuRoleDataTemp.UpdateStateTime(tianTiFuBenData.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks); } } tianTiFuBenData.State = GameFuBenState.Start; this.NotifyFuBenRoleEnterGame(tianTiFuBenData); this.ProcessTianTiFuBenDataDict.Remove(range); return(true); } return(false); } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } result = false; } return(result); }
private void CheckRoleTimerProc(DateTime now, out int signUpCnt, out int startCount) { signUpCnt = 0; startCount = 0; bool assgionGameFuBen = true; long maxRemoveRoleTicks = now.AddHours(-2.0).Ticks; long waitTicks = now.AddSeconds((double)(-(double)this.Persistence.SignUpWaitSecs1)).Ticks; long waitTicks2 = now.AddSeconds((double)(-(double)this.Persistence.SignUpWaitSecs3)).Ticks; long waitTicksAll = now.AddSeconds((double)(-(double)this.Persistence.SignUpWaitSecsAll)).Ticks; long waitTicksMax = now.AddSeconds((double)(-(double)this.Persistence.WaitForJoinMaxSecs)).Ticks; this.ProcessTianTiFuBenDataDict.Clear(); foreach (KuaFuRoleData kuaFuRoleData in this.RoleIdKuaFuRoleDataDict.Values) { int oldGameId = 0; lock (kuaFuRoleData) { if (kuaFuRoleData.State == KuaFuRoleStates.None || kuaFuRoleData.State > KuaFuRoleStates.StartGame) { if (kuaFuRoleData.StateEndTicks < maxRemoveRoleTicks) { KuaFuRoleData kuaFuRoleDataTemp; this.RoleIdKuaFuRoleDataDict.TryRemove(KuaFuRoleKey.Get(kuaFuRoleData.ServerId, kuaFuRoleData.RoleId), out kuaFuRoleDataTemp); continue; } } else if (kuaFuRoleData.State == KuaFuRoleStates.NotifyEnterGame || kuaFuRoleData.State == KuaFuRoleStates.EnterGame) { if (kuaFuRoleData.StateEndTicks < now.Ticks) { kuaFuRoleData.Age++; kuaFuRoleData.State = KuaFuRoleStates.None; oldGameId = kuaFuRoleData.GameId; } } else if (kuaFuRoleData.State == KuaFuRoleStates.SignUp) { if (kuaFuRoleData.StateEndTicks < waitTicksMax) { kuaFuRoleData.Age++; kuaFuRoleData.State = KuaFuRoleStates.None; } } } if (kuaFuRoleData.State == KuaFuRoleStates.SignUp) { signUpCnt++; if (assgionGameFuBen) { RangeKey range = this.GetAssignRange(kuaFuRoleData.GroupIndex, kuaFuRoleData.StateEndTicks, waitTicks, waitTicks2, waitTicksAll); assgionGameFuBen = this.AssignGameFuben(kuaFuRoleData, range, now); } } else if (kuaFuRoleData.State == KuaFuRoleStates.SignUpWaiting) { signUpCnt++; } else if (kuaFuRoleData.State == KuaFuRoleStates.StartGame) { startCount++; } if (oldGameId > 0) { this.RemoveRoleFromFuBen(oldGameId, kuaFuRoleData.RoleId); AsyncDataItem evItem = new AsyncDataItem(KuaFuEventTypes.RoleStateChange, new object[] { kuaFuRoleData }); ClientAgentManager.Instance().PostAsyncEvent(kuaFuRoleData.ServerId, this.GameType, evItem); } } }
// Start is called before the first frame update void Start() { m_BatchRendererGroup = new BatchRendererGroup(this.OnPerformCulling, IntPtr.Zero); #if ENABLE_PICKING m_PickingMaterial = LoadMaterialWithHideAndDontSave("Hidden/HDRP/BRGPicking"); m_BatchRendererGroup.SetPickingMaterial(m_PickingMaterial); #endif #if ENABLE_ERROR_LOADING_MATERIALS if (SetFallbackMaterialsOnStart) { m_ErrorMaterial = LoadMaterialWithHideAndDontSave("Hidden/HDRP/MaterialError"); m_BatchRendererGroup.SetErrorMaterial(m_ErrorMaterial); m_LoadingMaterial = LoadMaterialWithHideAndDontSave("Hidden/HDRP/MaterialLoading"); m_BatchRendererGroup.SetLoadingMaterial(m_LoadingMaterial); } #endif // Create a batch... var renderers = FindObjectsOfType <MeshRenderer>(); Debug.Log("Converting " + renderers.Length + " renderers..."); m_renderers = new NativeArray <DrawRenderer>(renderers.Length, Allocator.Persistent); m_batchHash = new NativeHashMap <DrawKey, int>(1024, Allocator.Persistent); m_rangeHash = new NativeHashMap <RangeKey, int>(1024, Allocator.Persistent); m_drawBatches = new NativeList <DrawBatch>(Allocator.Persistent); m_drawRanges = new NativeList <DrawRange>(Allocator.Persistent); // Fill the GPU-persistent scene data ComputeBuffer int bigDataBufferVector4Count = 4 /*zero*/ + 1 /*probes*/ + 1 /*speccube*/ + 7 /*SH*/ + m_renderers.Length * 3 * 2 /*per renderer 4x3 matrix+inverse*/; var vectorBuffer = new NativeArray <Vector4>(bigDataBufferVector4Count, Allocator.Temp); // First 4xfloat4 of ComputeBuffer needed to be zero filled for default property fall back! vectorBuffer[0] = new Vector4(0, 0, 0, 0); vectorBuffer[1] = new Vector4(0, 0, 0, 0); vectorBuffer[2] = new Vector4(0, 0, 0, 0); vectorBuffer[3] = new Vector4(0, 0, 0, 0); var startOffset = 4; // Fill global data (shared between all batches) var probesOcclusionOffset = startOffset; vectorBuffer[probesOcclusionOffset] = new Vector4(1, 1, 1, 1); startOffset++; var specCubeOffset = startOffset; vectorBuffer[specCubeOffset] = ReflectionProbe.defaultTextureHDRDecodeValues; startOffset++; var SHOffset = startOffset; var SH = new SHProperties(RenderSettings.ambientProbe); vectorBuffer[SHOffset + 0] = SH.SHAr; vectorBuffer[SHOffset + 1] = SH.SHAg; vectorBuffer[SHOffset + 2] = SH.SHAb; vectorBuffer[SHOffset + 3] = SH.SHBr; vectorBuffer[SHOffset + 4] = SH.SHBg; vectorBuffer[SHOffset + 5] = SH.SHBb; vectorBuffer[SHOffset + 6] = SH.SHC; startOffset += 7; var localToWorldOffset = startOffset; var worldToLocalOffset = localToWorldOffset + m_renderers.Length * 3; m_instances = new NativeList <DrawInstance>(1024, Allocator.Persistent); for (int i = 0; i < renderers.Length; i++) { var renderer = renderers[i]; m_renderers[i] = new DrawRenderer { bounds = new AABB { Center = new float3(0, 0, 0), Extents = new float3(0, 0, 0) } }; var meshFilter = renderer.gameObject.GetComponent <MeshFilter>(); if (!renderer || !meshFilter || !meshFilter.sharedMesh || renderer.enabled == false) { continue; } // Disable the existing Unity MeshRenderer to avoid double rendering! renderer.enabled = false; /* mat4x3 packed like this: * p1.x, p1.w, p2.z, p3.y, * p1.y, p2.x, p2.w, p3.z, * p1.z, p2.y, p3.x, p3.w, * 0.0, 0.0, 0.0, 1.0 */ var m = renderer.transform.localToWorldMatrix; vectorBuffer[i * 3 + 0 + localToWorldOffset] = new Vector4(m.m00, m.m10, m.m20, m.m01); vectorBuffer[i * 3 + 1 + localToWorldOffset] = new Vector4(m.m11, m.m21, m.m02, m.m12); vectorBuffer[i * 3 + 2 + localToWorldOffset] = new Vector4(m.m22, m.m03, m.m13, m.m23); var mi = renderer.transform.worldToLocalMatrix; vectorBuffer[i * 3 + 0 + worldToLocalOffset] = new Vector4(mi.m00, mi.m10, mi.m20, mi.m01); vectorBuffer[i * 3 + 1 + worldToLocalOffset] = new Vector4(mi.m11, mi.m21, mi.m02, mi.m12); vectorBuffer[i * 3 + 2 + worldToLocalOffset] = new Vector4(mi.m22, mi.m03, mi.m13, mi.m23); // Renderer bounds var transformedBounds = AABB.Transform(m, meshFilter.sharedMesh.bounds.ToAABB()); m_renderers[i] = new DrawRenderer { bounds = transformedBounds }; var mesh = m_BatchRendererGroup.RegisterMesh(meshFilter.sharedMesh); var sharedMaterials = new List <Material>(); renderer.GetSharedMaterials(sharedMaterials); var shadows = renderer.shadowCastingMode; for (int matIndex = 0; matIndex < sharedMaterials.Count; matIndex++) { var material = m_BatchRendererGroup.RegisterMaterial(sharedMaterials[matIndex]); var key = new DrawKey { material = material, meshID = mesh, submeshIndex = (uint)matIndex, shadows = shadows }; #if ENABLE_PICKING key.pickableObjectInstanceID = renderer.gameObject.GetInstanceID(); #endif var drawBatch = new DrawBatch { key = key, instanceCount = 0, instanceOffset = 0 }; m_instances.Add(new DrawInstance { key = key, instanceIndex = i }); int drawBatchIndex; if (m_batchHash.TryGetValue(key, out drawBatchIndex)) { drawBatch = m_drawBatches[drawBatchIndex]; } else { drawBatchIndex = m_drawBatches.Length; m_drawBatches.Add(drawBatch); m_batchHash[key] = drawBatchIndex; // Different renderer settings? -> new range var rangeKey = new RangeKey { shadows = shadows }; var drawRange = new DrawRange { key = rangeKey, drawCount = 0, drawOffset = 0, }; int drawRangeIndex; if (m_rangeHash.TryGetValue(rangeKey, out drawRangeIndex)) { drawRange = m_drawRanges[drawRangeIndex]; } else { drawRangeIndex = m_drawRanges.Length; m_drawRanges.Add(drawRange); m_rangeHash[rangeKey] = drawRangeIndex; } drawRange.drawCount++; m_drawRanges[drawRangeIndex] = drawRange; } drawBatch.instanceCount++; m_drawBatches[drawBatchIndex] = drawBatch; } } m_GPUPersistentInstanceData = new GraphicsBuffer(GraphicsBuffer.Target.Raw, (int)bigDataBufferVector4Count * 16 / 4, 4); m_GPUPersistentInstanceData.SetData(vectorBuffer); Debug.Log("DrawRanges: " + m_drawRanges.Length + ", DrawBatches: " + m_drawBatches.Length + ", Instances: " + m_instances.Length); // Prefix sum to calculate draw offsets for each DrawRange int prefixSum = 0; for (int i = 0; i < m_drawRanges.Length; i++) { var drawRange = m_drawRanges[i]; drawRange.drawOffset = prefixSum; m_drawRanges[i] = drawRange; prefixSum += drawRange.drawCount; } // Generate draw index ranges for each DrawRange m_drawIndices = new NativeArray <int>(m_drawBatches.Length, Allocator.Persistent); var m_internalRangeIndex = new NativeArray <int>(m_drawRanges.Length, Allocator.Temp); for (int i = 0; i < m_drawBatches.Length; i++) { var draw = m_drawBatches[i]; if (m_rangeHash.TryGetValue(new RangeKey { shadows = draw.key.shadows }, out int drawRangeIndex)) { var drawRange = m_drawRanges[drawRangeIndex]; m_drawIndices[drawRange.drawOffset + m_internalRangeIndex[drawRangeIndex]] = i; m_internalRangeIndex[drawRangeIndex]++; } } m_internalRangeIndex.Dispose(); // Prefix sum to calculate instance offsets for each DrawCommand prefixSum = 0; for (int i = 0; i < m_drawBatches.Length; i++) { // DrawIndices remap to get DrawCommands ordered by DrawRange var remappedIndex = m_drawIndices[i]; var drawBatch = m_drawBatches[remappedIndex]; drawBatch.instanceOffset = prefixSum; m_drawBatches[remappedIndex] = drawBatch; prefixSum += drawBatch.instanceCount; } // Generate instance index ranges for each DrawCommand m_instanceIndices = new NativeArray <int>(m_instances.Length, Allocator.Persistent); var m_internalDrawIndex = new NativeArray <int>(m_drawBatches.Length, Allocator.Temp); for (int i = 0; i < m_instances.Length; i++) { var instance = m_instances[i]; if (m_batchHash.TryGetValue(instance.key, out int drawBatchIndex)) { var drawBatch = m_drawBatches[drawBatchIndex]; m_instanceIndices[drawBatch.instanceOffset + m_internalDrawIndex[drawBatchIndex]] = instance.instanceIndex; m_internalDrawIndex[drawBatchIndex]++; } } m_internalDrawIndex.Dispose(); // Bounds ("infinite") UnityEngine.Bounds bounds = new Bounds(new Vector3(0, 0, 0), new Vector3(1048576.0f, 1048576.0f, 1048576.0f)); m_BatchRendererGroup.SetGlobalBounds(bounds); // Batch metadata buffer... // Per instance data int objectToWorldID = Shader.PropertyToID("unity_ObjectToWorld"); int worldToObjectID = Shader.PropertyToID("unity_WorldToObject"); int colorID = Shader.PropertyToID("_BaseColor"); // Global data (should be moved to C++ side) int probesOcclusionID = Shader.PropertyToID("unity_ProbesOcclusion"); int specCubeID = Shader.PropertyToID("unity_SpecCube0_HDR"); int SHArID = Shader.PropertyToID("unity_SHAr"); int SHAgID = Shader.PropertyToID("unity_SHAg"); int SHAbID = Shader.PropertyToID("unity_SHAb"); int SHBrID = Shader.PropertyToID("unity_SHBr"); int SHBgID = Shader.PropertyToID("unity_SHBg"); int SHBbID = Shader.PropertyToID("unity_SHBb"); int SHCID = Shader.PropertyToID("unity_SHC"); var batchMetadata = new NativeArray <MetadataValue>(11, Allocator.Temp); batchMetadata[0] = CreateMetadataValue(objectToWorldID, localToWorldOffset * UnsafeUtility.SizeOf <Vector4>(), true); batchMetadata[1] = CreateMetadataValue(worldToObjectID, worldToLocalOffset * UnsafeUtility.SizeOf <Vector4>(), true); batchMetadata[2] = CreateMetadataValue(probesOcclusionID, probesOcclusionOffset * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[3] = CreateMetadataValue(specCubeID, specCubeOffset * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[4] = CreateMetadataValue(SHArID, (SHOffset + 0) * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[5] = CreateMetadataValue(SHAgID, (SHOffset + 1) * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[6] = CreateMetadataValue(SHAbID, (SHOffset + 2) * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[7] = CreateMetadataValue(SHBrID, (SHOffset + 3) * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[8] = CreateMetadataValue(SHBgID, (SHOffset + 4) * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[9] = CreateMetadataValue(SHBbID, (SHOffset + 5) * UnsafeUtility.SizeOf <Vector4>(), false); batchMetadata[10] = CreateMetadataValue(SHCID, (SHOffset + 6) * UnsafeUtility.SizeOf <Vector4>(), false); // Register batch m_batchID = m_BatchRendererGroup.AddBatch(batchMetadata, m_GPUPersistentInstanceData.bufferHandle); m_initialized = true; }
public static bool AssignGameFuben(KF5v5PiPeiTeam kuaFuRoleData, RangeKey range, DateTime now) { int roleCount = 0; DateTime stateEndTime = now.AddSeconds((double)TianTi5v5Service.EnterGameSecs); List <KuaFuFuBenRoleData> updateRoleDataList = new List <KuaFuFuBenRoleData>(); KuaFu5v5FuBenData KuaFu5v5FuBenData = new KuaFu5v5FuBenData(); int side = 0; int removeZhanDuiIDFromPiPeiList = 0; KF5v5PiPeiTeam team = kuaFuRoleData; if (Consts.TianTiRoleCountTotal > 1) { foreach (Tuple <KF5v5PiPeiTeam, int, int, int> z in TianTi5v5Service.ProcessPiPeiList) { if (z.Item2 >= range.Left && z.Item2 <= range.Right) { if (kuaFuRoleData.GroupIndex >= z.Item3 && kuaFuRoleData.GroupIndex <= z.Item4) { if (TianTi5v5Service.CanAddFuBenRole(kuaFuRoleData.TeamID, z.Item1.TeamID)) { removeZhanDuiIDFromPiPeiList = z.Item1.TeamID; team = z.Item1; if (KuaFu5v5FuBenData.AddZhanDui(team.TeamID, ref roleCount, ref side)) { TianTi5v5ZhanDuiData teamData; if (TianTi5v5Service.ZhanDuiDict.TryGetValue(team.TeamID, out teamData)) { foreach (TianTi5v5ZhanDuiRoleData role in teamData.teamerList) { KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData { ServerId = team.ServerID, RoleId = role.RoleID, Side = side }; KuaFu5v5FuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, team.TeamID); } } } } } } } if (removeZhanDuiIDFromPiPeiList == 0) { TianTi5v5Service.ProcessPiPeiList.Add(new Tuple <KF5v5PiPeiTeam, int, int, int>(kuaFuRoleData, kuaFuRoleData.GroupIndex, range.Left, range.Right)); return(true); } TianTi5v5Service.ProcessPiPeiList.RemoveAll((Tuple <KF5v5PiPeiTeam, int, int, int> x) => x.Item1.TeamID == removeZhanDuiIDFromPiPeiList); TianTi5v5Service.ProcessPiPeiList.RemoveAll((Tuple <KF5v5PiPeiTeam, int, int, int> x) => x.Item1.TeamID == kuaFuRoleData.TeamID); } team = kuaFuRoleData; if (KuaFu5v5FuBenData.AddZhanDui(team.TeamID, ref roleCount, ref side)) { TianTi5v5ZhanDuiData teamData; if (TianTi5v5Service.ZhanDuiDict.TryGetValue(team.TeamID, out teamData)) { foreach (TianTi5v5ZhanDuiRoleData role in teamData.teamerList) { KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData { ServerId = team.ServerID, RoleId = role.RoleID, Side = side }; KuaFu5v5FuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, team.TeamID); } } } try { int kfSrvId = 0; int gameId = TianTi5v5Service.Persistence.GetNextGameId(); bool createSuccess = ClientAgentManager.Instance().AssginKfFuben(TianTi5v5Service.GameType, (long)gameId, roleCount, out kfSrvId); if (createSuccess) { KuaFu5v5FuBenData.ServerId = kfSrvId; KuaFu5v5FuBenData.GameId = gameId; KuaFu5v5FuBenData.GameType = (int)TianTi5v5Service.GameType; KuaFu5v5FuBenData.EndTime = Global.NowTime.AddMinutes(8.0); KuaFu5v5FuBenData.LoginInfo = KuaFuServerManager.GetKuaFuLoginInfo(kuaFuRoleData.ServerID, kfSrvId); TianTi5v5Service.AddGameFuBen(KuaFu5v5FuBenData); TianTi5v5Service.Persistence.LogCreateTianTiFuBen(KuaFu5v5FuBenData.GameId, KuaFu5v5FuBenData.ServerId, 0, roleCount); foreach (int zhanDuiID in KuaFu5v5FuBenData.ZhanDuiDict.Keys) { KF5v5PiPeiTeam kuaFuRoleDataTemp; if (TianTi5v5Service.PiPeiDict.TryGetValue(zhanDuiID, out kuaFuRoleDataTemp)) { kuaFuRoleDataTemp.State = 3; kuaFuRoleDataTemp.StateEndTicks = stateEndTime.Ticks; kuaFuRoleDataTemp.GameId = KuaFu5v5FuBenData.GameId; } } KuaFu5v5FuBenData.State = GameFuBenState.Start; TianTi5v5Service.NotifyFuBenRoleEnterGame(KuaFu5v5FuBenData); TianTi5v5Service.AddRolePairFightCount(KuaFu5v5FuBenData); return(true); } return(false); } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } return(false); }
private static void CheckRoleTimerProc(DateTime now, out int signUpCnt, out int startCount) { signUpCnt = 0; startCount = 0; bool assgionGameFuBen = true; long maxRemoveRoleTicks = now.AddHours(-1.0).Ticks; long waitTicks = now.AddSeconds((double)(-(double)TianTi5v5Service.Persistence.SignUpWaitSecs1)).Ticks; long waitTicks2 = now.AddSeconds((double)(-(double)TianTi5v5Service.Persistence.SignUpWaitSecs3)).Ticks; long waitTicksAll = now.AddSeconds((double)(-(double)TianTi5v5Service.Persistence.SignUpWaitSecsAll)).Ticks; long waitTicksMax = now.AddSeconds((double)(-(double)TianTi5v5Service.Persistence.WaitForJoinMaxSecs)).Ticks; TianTi5v5Service.ProcessPiPeiList.Clear(); List <int> removeList = new List <int>(); foreach (KF5v5PiPeiTeam kuaFuRoleData in TianTi5v5Service.PiPeiDict.Values) { int oldGameId = 0; lock (kuaFuRoleData) { if (kuaFuRoleData.State == 0 || kuaFuRoleData.State > 5) { if (kuaFuRoleData.StateEndTicks < maxRemoveRoleTicks) { kuaFuRoleData.State = 0; removeList.Add(kuaFuRoleData.TeamID); continue; } } else if (kuaFuRoleData.State == 3 || kuaFuRoleData.State == 4) { if (kuaFuRoleData.StateEndTicks < now.Ticks) { kuaFuRoleData.State = 0; removeList.Add(kuaFuRoleData.TeamID); oldGameId = kuaFuRoleData.GameId; } } else if (kuaFuRoleData.State == 1) { if (kuaFuRoleData.StateEndTicks < waitTicksMax) { kuaFuRoleData.State = 0; removeList.Add(kuaFuRoleData.TeamID); continue; } } } if (kuaFuRoleData.State == 1) { signUpCnt++; if (assgionGameFuBen) { RangeKey range = TianTi5v5Service.GetAssignRange(kuaFuRoleData.GroupIndex, kuaFuRoleData.StateEndTicks, waitTicks, waitTicks2, waitTicksAll); assgionGameFuBen = TianTi5v5Service.AssignGameFuben(kuaFuRoleData, range, now); } } else if (kuaFuRoleData.State == 2) { signUpCnt++; } else if (kuaFuRoleData.State == 5) { startCount++; } if (oldGameId > 0) { TianTi5v5Service.RemoveRoleFromFuBen(oldGameId, kuaFuRoleData.TeamID); } } foreach (int id in removeList) { KF5v5PiPeiTeam kuaFuRoleDataTemp; if (TianTi5v5Service.PiPeiDict.TryRemove(id, out kuaFuRoleDataTemp)) { if (kuaFuRoleDataTemp.State == 1) { TianTi5v5Service.PiPeiDict.TryAdd(id, kuaFuRoleDataTemp); } } } }
private bool AssignGameFuben(KuaFuRoleData kuaFuRoleData, RangeKey range, DateTime now) { int roleCount = 0; DateTime stateEndTime = now.AddSeconds(EnterGameSecs); TianTiFuBenData tianTiFuBenData = null; KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData() { ServerId = kuaFuRoleData.ServerId, RoleId = kuaFuRoleData.RoleId, }; List <KuaFuRoleData> updateRoleDataList = new List <KuaFuRoleData>(); if (!ProcessTianTiFuBenDataDict.TryGetValue(range, out tianTiFuBenData)) { tianTiFuBenData = new TianTiFuBenData(); ProcessTianTiFuBenDataDict.Add(range, tianTiFuBenData); } else if (!CanAddFuBenRole(tianTiFuBenData, kuaFuRoleData)) { return(true); } roleCount = tianTiFuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData); if (roleCount < Consts.TianTiRoleCountTotal) { return(true); } try { int kfSrvId = 0; int gameId = Persistence.GetNextGameId(); bool createSuccess = ClientAgentManager.Instance().AssginKfFuben(GameType, gameId, roleCount, out kfSrvId); if (createSuccess) { tianTiFuBenData.ServerId = kfSrvId; tianTiFuBenData.GameId = gameId; tianTiFuBenData.EndTime = Global.NowTime.AddMinutes(Consts.TianTiGameFuBenMaxExistMinutes); AddGameFuBen(tianTiFuBenData); Persistence.LogCreateTianTiFuBen(tianTiFuBenData.GameId, tianTiFuBenData.ServerId, 0, roleCount); foreach (var role in tianTiFuBenData.RoleDict.Values) { KuaFuRoleData kuaFuRoleDataTemp; KuaFuRoleKey key = KuaFuRoleKey.Get(role.ServerId, role.RoleId); if (RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleDataTemp)) { kuaFuRoleDataTemp.UpdateStateTime(tianTiFuBenData.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks); } } tianTiFuBenData.State = GameFuBenState.Start; NotifyFuBenRoleEnterGame(tianTiFuBenData); ProcessTianTiFuBenDataDict.Remove(range); } else { //如果分配失败,则返回false,本轮不在尝试分配 return(false); } return(true); } catch (System.Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } return(false); }
private static bool FixSyncData_State(DateTime now) { bool bForceModify = false; int endID = 0; lock (ZhanDuiZhengBa_K.Mutex) { if (now.Day > ZhanDuiZhengBaConsts.StartMonthDay) { endID = ZhanDuiZhengBa_K._Config.MatchConfigList[ZhanDuiZhengBa_K._Config.MatchConfigList.Count - 1].ID; } else if (now.Day == ZhanDuiZhengBaConsts.StartMonthDay) { for (int i = 0; i < ZhanDuiZhengBa_K._Config.MatchConfigList.Count; i++) { ZhanDuiZhengBaMatchConfig c0 = ZhanDuiZhengBa_K._Config.MatchConfigList[i]; if (now.TimeOfDay.Ticks < c0.DayBeginTick) { break; } if (now.TimeOfDay.Ticks >= c0.ResultTick) { endID = c0.ID; } } } if (endID == ZhanDuiZhengBaUtils.WhichDayResultByGrade(EZhengBaGrade.Grade1)) { ZhanDuiZhengBa_K.SyncData.HasSeasonEnd = true; ZhanDuiZhengBa_K.SyncData.TopZhanDui = ZhanDuiZhengBa_K.Persistence.GetLastTopZhanDui(ZhanDuiZhengBa_K.SyncData.Month); } else { ZhanDuiZhengBa_K.SyncData.HasSeasonEnd = false; ZhanDuiZhengBa_K.SyncData.TopZhanDui = ZhanDuiZhengBa_K.Persistence.GetLastTopZhanDui(ZhengBaUtils.MakeMonth(now.AddMonths(-1))); } int id; for (id = 1; id <= endID; id++) { ZhanDuiZhengBaMatchConfig config = ZhanDuiZhengBa_K._Config.MatchConfigList.Find((ZhanDuiZhengBaMatchConfig _m) => _m.ID == id); EZhengBaGrade preGrade = config.JoinGrade; EZhengBaGrade willUpGrade = config.WillUpGrade; List <ZhanDuiZhengBaZhanDuiData> roleList = ZhanDuiZhengBa_K.SyncData.ZhanDuiList.FindAll((ZhanDuiZhengBaZhanDuiData _r) => _r.Grade > (int)willUpGrade); if (roleList.Count > 0) { List <ZhanDuiZhengBaZhanDuiData> upGradeList = new List <ZhanDuiZhengBaZhanDuiData>(); using (List <RangeKey> .Enumerator enumerator = ZhanDuiZhengBaUtils.GetDayPkGroupRange(id).GetEnumerator()) { while (enumerator.MoveNext()) { RangeKey range = enumerator.Current; List <ZhanDuiZhengBaZhanDuiData> groupRoleList = ZhanDuiZhengBa_K.SyncData.ZhanDuiList.FindAll((ZhanDuiZhengBaZhanDuiData _r) => _r.Group >= range.Left && _r.Group <= range.Right && _r.Grade <= (int)preGrade); if (groupRoleList.Count != 0) { if (!groupRoleList.Exists((ZhanDuiZhengBaZhanDuiData _r) => _r.Grade <= (int)willUpGrade)) { groupRoleList.Sort(delegate(ZhanDuiZhengBaZhanDuiData _l, ZhanDuiZhengBaZhanDuiData _r) { int result; if (_l.Grade != _r.Grade) { result = _l.Grade - _r.Grade; } else { result = _l.DuanWeiRank - _r.DuanWeiRank; } return(result); }); ZhanDuiZhengBaZhanDuiData selectRole = groupRoleList[0]; LogManager.WriteLog(LogTypes.Error, string.Format("战队争霸::晋级补位 [s{0}.{1}] {2}->{3}", new object[] { selectRole.ZoneId, selectRole.ZhanDuiID, selectRole.Grade, (int)willUpGrade }), null, true); selectRole.Grade = (int)willUpGrade; bForceModify = true; upGradeList.Add(selectRole); if (groupRoleList.Count >= 2) { ZhanDuiZhengBaZhanDuiData faildRole = groupRoleList[1]; faildRole.Grade = (int)preGrade; } } } } } } } ZhanDuiZhengBa_K.SyncData.RealActID = endID; foreach (ZhanDuiZhengBaZhanDuiData role in ZhanDuiZhengBa_K.SyncData.ZhanDuiList) { if (endID <= 0) { if (role.Grade != 64 || role.State != 0) { role.Grade = 64; role.State = 0; bForceModify = true; } } else { EZhengBaGrade upGrade = ZhanDuiZhengBa_K._Config.MatchConfigList.Find((ZhanDuiZhengBaMatchConfig _m) => _m.ID == endID).WillUpGrade; if (role.Grade <= (int)upGrade && role.State != 1) { role.State = 1; bForceModify = true; } if (role.Grade > (int)upGrade && role.State != 2) { role.State = 2; bForceModify = true; } if (role.Grade == 1) { ZhanDuiZhengBa_K.SyncData.TopZhanDui = role.ZhanDuiID; } } } } return(bForceModify); }
private bool FixSyncData_State(DateTime now) { bool bForceModify = false; int nowDay = now.Day - ZhengBaConsts.StartMonthDay + 1; lock (this.Mutex) { int rankOfDay; for (rankOfDay = 7; rankOfDay >= 1; rankOfDay--) { EZhengBaGrade willUpGrade = ZhengBaUtils.GetDayUpGrade(rankOfDay); ZhengBaMatchConfig matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == rankOfDay); List <ZhengBaRoleInfoData> roleList = this.SyncData.RoleList.FindAll((ZhengBaRoleInfoData _r) => _r.Grade == (int)willUpGrade); if (roleList.Count > 0) { int needUpNum = matchConfig.MaxUpGradeNum - roleList.Count; if (needUpNum > 0) { List <ZhengBaRoleInfoData> upGradeList = new List <ZhengBaRoleInfoData>(); if (rankOfDay <= 3) { List <ZhengBaRoleInfoData> luckList = this.SyncData.RoleList.FindAll((ZhengBaRoleInfoData _r) => _r.Grade > (int)willUpGrade); luckList.Sort(delegate(ZhengBaRoleInfoData _l, ZhengBaRoleInfoData _r) { int result; if (_l.Grade < _r.Grade) { result = -1; } else if (_l.Grade > _r.Grade) { result = 1; } else { result = _l.DuanWeiRank - _r.DuanWeiRank; } return(result); }); foreach (ZhengBaRoleInfoData luckRole in luckList.GetRange(0, Math.Min(needUpNum, luckList.Count))) { upGradeList.Add(luckRole); LogManager.WriteLog(LogTypes.Error, string.Format("晋级补位 [s{0}.{1}] {2}->{3}", new object[] { luckRole.ZoneId, luckRole.RoleId, luckRole.Grade, (int)willUpGrade }), null, true); luckRole.Grade = (int)willUpGrade; bForceModify = true; } } else { using (List <RangeKey> .Enumerator enumerator2 = ZhengBaUtils.GetDayPkGroupRange(rankOfDay).GetEnumerator()) { while (enumerator2.MoveNext()) { RangeKey range = enumerator2.Current; List <ZhengBaRoleInfoData> groupRoleList = this.SyncData.RoleList.FindAll((ZhengBaRoleInfoData _r) => _r.Group >= range.Left && _r.Group <= range.Right); if (!groupRoleList.Exists((ZhengBaRoleInfoData _r) => _r.Grade <= (int)ZhengBaUtils.GetDayUpGrade(rankOfDay))) { groupRoleList.RemoveAll((ZhengBaRoleInfoData _r) => _r.Grade != (int)ZhengBaUtils.GetDayUpGrade(rankOfDay - 1)); if (groupRoleList.Count > 0) { groupRoleList.Sort((ZhengBaRoleInfoData _l, ZhengBaRoleInfoData _r) => _l.DuanWeiRank - _r.DuanWeiRank); ZhengBaRoleInfoData selectRole = groupRoleList[0]; LogManager.WriteLog(LogTypes.Error, string.Format("晋级补位 [s{0}.{1}] {2}->{3}", new object[] { selectRole.ZoneId, selectRole.RoleId, selectRole.Grade, (int)willUpGrade }), null, true); selectRole.Grade = (int)ZhengBaUtils.GetDayUpGrade(rankOfDay); bForceModify = true; upGradeList.Add(selectRole); } } } } } foreach (ZhengBaRoleInfoData luckRole in upGradeList) { this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaButtetinJoin, new object[] { new ZhengBaBulletinJoinData { NtfType = ZhengBaBulletinJoinData.ENtfType.MailUpgradeRole, Args1 = luckRole.RoleId } })); } } break; } } this.SyncData.RankResultOfDay = rankOfDay; this.SyncData.RealActDay = rankOfDay; foreach (ZhengBaRoleInfoData role in this.SyncData.RoleList) { if (rankOfDay <= 0) { if (role.Grade != 100 || role.State != 0 || role.Group != 0) { role.Grade = 100; role.State = 0; role.Group = 0; bForceModify = true; } } else { EZhengBaGrade upGrade = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == rankOfDay).WillUpGrade; if (role.Grade <= (int)upGrade && role.State != 1) { role.State = 1; bForceModify = true; } if (role.Grade > (int)upGrade && role.State != 2) { role.State = 2; bForceModify = true; } } if (role.Grade == 1 && this.SyncData.LastKingModTime != this.SyncData.Month) { this.SyncData.LastKingData = role; this.SyncData.LastKingModTime = this.SyncData.Month; } } if (nowDay > 0 && this.SyncData.RealActDay < nowDay) { if (this.SyncData.RealActDay < 7) { ZhengBaMatchConfig matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == this.SyncData.RealActDay + 1); if (now.TimeOfDay.Ticks < matchConfig.DayBeginTick) { this.SyncData.RealActDay++; } } else { this.SyncData.RealActDay = 8; } } } return(bForceModify); }
private void MS_InitPkLoop_Enter(DateTime now) { this.ThisLoopPkLogs.Clear(); this.CurrLoopIndex++; ZhengBaMatchConfig matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == this.SyncData.RealActDay); if (this.HadUpGradeRoleNum >= matchConfig.MaxUpGradeNum || this.TodayJoinRoleDatas.Count <= 1) { this.StateMachine.SetCurrState(ZhengBaStateMachine.StateType.TodayPkEnd, now); } else { if (matchConfig.Mathching == EZhengBaMatching.Random) { Random r = new Random((int)now.Ticks); int i = 0; while (this.TodayJoinRoleDatas.Count > 0 && i < this.TodayJoinRoleDatas.Count * 2) { int idx = r.Next(0, this.TodayJoinRoleDatas.Count); int idx2 = r.Next(0, this.TodayJoinRoleDatas.Count); ZhengBaManagerK.JoinRolePkData tmp = this.TodayJoinRoleDatas[idx]; this.TodayJoinRoleDatas[idx] = this.TodayJoinRoleDatas[idx2]; this.TodayJoinRoleDatas[idx2] = tmp; i++; } } else if (matchConfig.Mathching == EZhengBaMatching.Group) { List <ZhengBaManagerK.JoinRolePkData> tmpRoleDatas = new List <ZhengBaManagerK.JoinRolePkData>(); using (List <RangeKey> .Enumerator enumerator = ZhengBaUtils.GetDayPkGroupRange(this.SyncData.RealActDay).GetEnumerator()) { while (enumerator.MoveNext()) { RangeKey range = enumerator.Current; List <ZhengBaManagerK.JoinRolePkData> groupRoles = this.TodayJoinRoleDatas.FindAll((ZhengBaManagerK.JoinRolePkData _r) => _r.Group >= range.Left && _r.Group <= range.Right); if (groupRoles != null && groupRoles.Count == 2) { tmpRoleDatas.AddRange(groupRoles); } } } this.TodayJoinRoleDatas.Clear(); this.TodayJoinRoleDatas.AddRange(tmpRoleDatas); } else { Debug.Assert(false, "unknown pk match type"); } int currIdx = 0; for (int i = 0; i < this.TodayJoinRoleDatas.Count / 2; i++) { ZhengBaManagerK.JoinRolePkData joinRole = this.TodayJoinRoleDatas[currIdx++]; ZhengBaManagerK.JoinRolePkData joinRole2 = this.TodayJoinRoleDatas[currIdx++]; int toServerId = 0; int gameId = TianTiPersistence.Instance.GetNextGameId(); if (ClientAgentManager.Instance().AssginKfFuben(TianTiService.Instance.GameType, (long)gameId, 2, out toServerId)) { joinRole.ToServerID = (joinRole2.ToServerID = toServerId); joinRole.CurrGameID = (joinRole2.CurrGameID = gameId); joinRole.WaitReqEnter = (joinRole2.WaitReqEnter = true); joinRole.WaitKuaFuLogin = (joinRole2.WaitKuaFuLogin = false); ZhengBaNtfEnterData data = new ZhengBaNtfEnterData(); data.RoleId1 = joinRole.RoleID; data.RoleId2 = joinRole2.RoleID; data.ToServerId = toServerId; data.GameId = gameId; data.Day = this.SyncData.RealActDay; data.Loop = this.CurrLoopIndex; this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaNtfEnter, new object[] { data })); ZhengBaPkLogData log = new ZhengBaPkLogData(); log.Month = this.SyncData.Month; log.Day = this.SyncData.RealActDay; log.RoleID1 = joinRole.RoleID; log.ZoneID1 = joinRole.ZoneId; log.RoleName1 = joinRole.RoleName; log.RoleID2 = joinRole2.RoleID; log.ZoneID2 = joinRole2.ZoneId; log.RoleName2 = joinRole2.RoleName; log.StartTime = now; this.ThisLoopPkLogs[gameId] = log; } else { LogManager.WriteLog(LogTypes.Error, string.Format("众神争霸第{0}天第{1}轮分配游戏服务器失败,role1={2},role2={3}", new object[] { this.SyncData.RealActDay, this.CurrLoopIndex, joinRole.RoleID, joinRole2.RoleID }), null, true); } } while (currIdx < this.TodayJoinRoleDatas.Count) { ZhengBaManagerK.JoinRolePkData joinRole3 = this.TodayJoinRoleDatas[currIdx++]; joinRole3.ToServerID = 0; joinRole3.CurrGameID = 0; joinRole3.WaitReqEnter = false; joinRole3.WaitKuaFuLogin = false; } this.StateMachine.SetCurrState(ZhengBaStateMachine.StateType.NotifyEnter, now); } }
private void INTERNAL_segmentWalkForNextKey( IComparable<RecordKey> startkeytest, bool direction_is_forward, ISortedSegment curseg_raw, RangeKey curseg_rangekey, IScannableDictionary<RecordKey, RecordData> handledIndexRecords, int maxgen, IScannableDictionary<RecordKey, RecordData> recordsBeingAssembled, bool equal_ok, SegmentWalkStats stats) { // TODO: convert all ISortedSegments to be IScannable IScannable<RecordKey, RecordUpdate> curseg = (IScannable<RecordKey, RecordUpdate>)curseg_raw; stats.segmentWalkInvocations++; // first look in this segment for a next-key **IF** it may contain one if (curseg_rangekey.directlyContainsKey(startkeytest)) { // we need to keep looking until we find a live record, as we need all the deletion tombstones // between startkey and the next live record. IEnumerable<KeyValuePair<RecordKey, RecordUpdate>> seg_scanner; if (direction_is_forward) { seg_scanner = curseg.scanForward( new ScanRange<RecordKey>( startkeytest, new ScanRange<RecordKey>.maxKey(), null)); } else { seg_scanner = curseg.scanBackward( new ScanRange<RecordKey>( new ScanRange<RecordKey>.minKey(), startkeytest, null)); } foreach (var kvp in seg_scanner) { if (!equal_ok) { // have ">" test vs ">=" if (startkeytest.CompareTo(kvp.Key) == 0) { continue; } } RecordData partial_record; stats.rowAccumulate_TryGet++; if (!recordsBeingAssembled.TryGetValue(kvp.Key, out partial_record)) { partial_record = new RecordData(RecordDataState.NOT_PROVIDED, kvp.Key); recordsBeingAssembled[kvp.Key] = partial_record; } else { stats.rowDuplicatesAppeared++; } partial_record.applyUpdate(kvp.Value); stats.rowUpdatesApplied++; #if DEBUG_SEGMENT_ACCUMULATION for (int depth = 10; depth > maxgen; depth--) { Console.Write(" "); } Console.WriteLine("accumulated update: {0}", kvp); #endif if (partial_record.State != RecordDataState.DELETED) { // we accumulated to at least one live record, so stop adding potential records break; } } } // find all generation range references that are relevant for this key // .. make a note of which ones are "current" if (curseg_rangekey.directlyContainsKey(GEN_KEY_PREFIX)) { BDSkipList<RecordKey, RecordUpdate> todo_list = new BDSkipList<RecordKey, RecordUpdate>(); for (int i = maxgen - 1; i >= 0; i--) { stats.segmentRangeRowScansPerformed++; foreach (KeyValuePair<RecordKey, RecordUpdate> rangerow in RangeKey.findAllEligibleRangeRows(curseg, startkeytest, i, stats)) { // see if it is new for our handledIndexRecords dataset RecordData partial_rangedata; stats.segmentAccumulate_TryGet++; if (!handledIndexRecords.TryGetValue(rangerow.Key, out partial_rangedata)) { partial_rangedata = new RecordData(RecordDataState.NOT_PROVIDED, rangerow.Key); handledIndexRecords[rangerow.Key] = partial_rangedata; } if ((partial_rangedata.State == RecordDataState.INCOMPLETE) || (partial_rangedata.State == RecordDataState.NOT_PROVIDED)) { // we're suppilying new data for this index record partial_rangedata.applyUpdate(rangerow.Value); stats.segmentUpdatesApplied++; // because we're suppilying new data, we should add this to our // private TODO list if it is a FULL update, NOT a tombstone if (rangerow.Value.type == RecordUpdateTypes.FULL) { #if DEBUG_SEGMENT_RANGE_WALK for (int depth = 10; depth > maxgen; depth--) { Console.Write(" "); } Console.WriteLine("adding SegmentRangeRow: {0}", rangerow); #endif todo_list.Add(rangerow); } } } } // now repeat the walk through our todo list: foreach (KeyValuePair<RecordKey, RecordUpdate> rangepointer in todo_list.scanBackward(null)) { if (rangepointer.Value.type == RecordUpdateTypes.DELETION_TOMBSTONE) { // skip deletion tombstones stats.segmentDeletionTombstonesSkipped++; continue; } SegmentReader next_seg = segmentReaderFromRow(rangepointer); RangeKey next_seg_rangekey = RangeKey.decodeFromRecordKey(rangepointer.Key); #if DEBUG_SEGMENT_WALK for (int depth = 10; depth > maxgen; depth--) { Console.Write(" "); } Console.WriteLine("..WalkForNextKey descending to: {0}", rangepointer); #endif // RECURSE INTERNAL_segmentWalkForNextKey( startkeytest, direction_is_forward, next_seg, next_seg_rangekey, handledIndexRecords, maxgen - 1, recordsBeingAssembled, equal_ok, stats); } // now repeat the walk of range references in this segment, this time actually descending } }
private void INTERNAL_segmentWalkCursorSetupForNextKey( IComparable<RecordKey> startkeytest, bool direction_is_forward, ISortedSegment curseg_raw, RangeKey curseg_rangekey, IScannableDictionary<RecordKey, RecordData> handledIndexRecords, int maxgen, IScannableDictionary<RangeKey, IScannable<RecordKey, RecordUpdate>> segmentsWithRecords, bool equal_ok, SegmentWalkStats stats) { // TODO: convert all ISortedSegments to be IScannable IScannable<RecordKey, RecordUpdate> curseg = (IScannable<RecordKey, RecordUpdate>)curseg_raw; stats.segmentWalkInvocations++; // first look in this segment for a next-key **IF** it may contain one if (curseg_rangekey.directlyContainsKey(startkeytest)) { // add the current segment to the list of segments with records. segmentsWithRecords.Add(curseg_rangekey,curseg); } // find all generation range references that are relevant for this key // .. make a note of which ones are "current" if (curseg_rangekey.directlyContainsKey(GEN_KEY_PREFIX)) { BDSkipList<RecordKey, RecordUpdate> todo_list = new BDSkipList<RecordKey, RecordUpdate>(); if (curseg_rangekey.generation > stats.handlingGeneration) { throw new Exception("cursor segup generation priority inversion"); } stats.handlingGeneration = curseg_rangekey.generation; for (int i = maxgen - 1; i >= 0; i--) { stats.segmentRangeRowScansPerformed++; foreach (KeyValuePair<RecordKey, RecordUpdate> rangerow in RangeKey.findAllEligibleRangeRows(curseg, startkeytest, i, stats)) { // see if it is new for our handledIndexRecords dataset RecordData partial_rangedata; stats.segmentAccumulate_TryGet++; if (!handledIndexRecords.TryGetValue(rangerow.Key, out partial_rangedata)) { partial_rangedata = new RecordData(RecordDataState.NOT_PROVIDED, rangerow.Key); handledIndexRecords[rangerow.Key] = partial_rangedata; } if ((partial_rangedata.State == RecordDataState.INCOMPLETE) || (partial_rangedata.State == RecordDataState.NOT_PROVIDED)) { // we're suppilying new data for this index record partial_rangedata.applyUpdate(rangerow.Value); stats.segmentUpdatesApplied++; // because we're suppilying new data, we should add this to our // private TODO list if it is a FULL update, NOT a tombstone if (rangerow.Value.type == RecordUpdateTypes.FULL) { #if DEBUG_SEGMENT_RANGE_WALK for (int depth = 10; depth > maxgen; depth--) { Console.Write(" "); } Console.WriteLine("adding SegmentRangeRow: {0}", rangerow); #endif todo_list.Add(rangerow); } } } } // now repeat the walk through our todo list: foreach (KeyValuePair<RecordKey, RecordUpdate> rangepointer in todo_list.scanBackward(null)) { if (rangepointer.Value.type == RecordUpdateTypes.DELETION_TOMBSTONE) { // skip deletion tombstones stats.segmentDeletionTombstonesSkipped++; continue; } SegmentReader next_seg = segmentReaderFromRow(rangepointer); RangeKey next_seg_rangekey = RangeKey.decodeFromRecordKey(rangepointer.Key); #if DEBUG_SEGMENT_WALK for (int depth = 10; depth > maxgen; depth--) { Console.Write(" "); } Console.WriteLine("..WalkForNextKey descending to: {0}", rangepointer); #endif // RECURSE INTERNAL_segmentWalkCursorSetupForNextKey( startkeytest, direction_is_forward, next_seg, next_seg_rangekey, handledIndexRecords, maxgen - 1, segmentsWithRecords, equal_ok, stats); } // now repeat the walk of range references in this segment, this time actually descending } }