private Tuple <SubspaceDisplayEntry[], int> GetSubspaceDisplayEntriesSubspace() { int usedCacheEntries = 0; if (cacheGetSubspaceDisplayEntriesSubspace == null) { cacheGetSubspaceDisplayEntriesSubspace = new SubspaceDisplayEntry[20]; } if (cacheGetSubspaceDisplayEntriesSubspaceDict == null) { cacheGetSubspaceDisplayEntriesSubspaceDict = new Dictionary <int, SubspaceDisplayEntry>(); } if (cacheUnknownGetSubspaceDisplayEntriesSubspaceDict == null) { cacheUnknownGetSubspaceDisplayEntriesSubspaceDict = new Dictionary <string, SubspaceDisplayEntry>(); } //Subspace/subspace simple mode Dictionary <int, List <string> > nonWarpCache = new Dictionary <int, List <string> >(); List <string> warpCache = new List <string>(); //Add us if (timeSyncer.currentSubspace != -1) { List <string> newList = new List <string>(); newList.Add(dmpSettings.playerName); nonWarpCache.Add(timeSyncer.currentSubspace, newList); } else { warpCache.Add(dmpSettings.playerName); } //Add other players foreach (KeyValuePair <string, int> clientEntry in clientSubspaceList) { if (clientEntry.Value != -1) { if (!nonWarpCache.ContainsKey(clientEntry.Value)) { nonWarpCache.Add(clientEntry.Value, new List <string>()); } if (!nonWarpCache[clientEntry.Value].Contains(clientEntry.Key)) { nonWarpCache[clientEntry.Value].Add(clientEntry.Key); } } else { if (!warpCache.Contains(clientEntry.Key)) { warpCache.Add(clientEntry.Key); } } } //Players missing subspace or warp entries List <string> unknownPlayers = new List <string>(); //Process locked players foreach (KeyValuePair <int, List <string> > subspaceEntry in nonWarpCache) { if (timeSyncer.SubspaceExists(subspaceEntry.Key)) { SubspaceDisplayEntry sde; if (!cacheGetSubspaceDisplayEntriesSubspaceDict.ContainsKey(subspaceEntry.Key)) { cacheGetSubspaceDisplayEntriesSubspaceDict.Add(subspaceEntry.Key, new SubspaceDisplayEntry()); } sde = cacheGetSubspaceDisplayEntriesSubspaceDict[subspaceEntry.Key]; sde.subspaceID = subspaceEntry.Key; sde.subspaceEntry = timeSyncer.GetSubspace(subspaceEntry.Key); subspaceEntry.Value.Sort(PlayerSorter); sde.isUs = subspaceEntry.Value.Contains(dmpSettings.playerName); sde.players = subspaceEntry.Value.ToArray(); if (usedCacheEntries < cacheGetSubspaceDisplayEntriesSubspace.Length) { cacheGetSubspaceDisplayEntriesSubspace[usedCacheEntries] = sde; usedCacheEntries++; } } else { foreach (string unknownPlayer in subspaceEntry.Value) { unknownPlayers.Add(unknownPlayer); } } } //Process warping players foreach (string warpingPlayer in warpCache) { if (clientWarpList.ContainsKey(warpingPlayer)) { if (!cacheUnknownGetSubspaceDisplayEntriesSubspaceDict.ContainsKey(warpingPlayer)) { cacheUnknownGetSubspaceDisplayEntriesSubspaceDict.Add(warpingPlayer, new SubspaceDisplayEntry()); } SubspaceDisplayEntry sde = cacheUnknownGetSubspaceDisplayEntriesSubspaceDict[warpingPlayer]; sde.warpingEntry = clientWarpList[warpingPlayer]; sde.players = new string[] { warpingPlayer }; sde.isUs = (warpingPlayer == dmpSettings.playerName); sde.isWarping = true; sde.isUnknown = false; sde.subspaceID = 0; if (usedCacheEntries < cacheGetSubspaceDisplayEntriesSubspace.Length) { cacheGetSubspaceDisplayEntriesSubspace[usedCacheEntries] = sde; usedCacheEntries++; } } else { unknownPlayers.Add(warpingPlayer); } } for (int i = usedCacheEntries; i < cacheGetSubspaceDisplayEntriesSubspace.Length; i++) { cacheGetSubspaceDisplayEntriesSubspace[i] = null; } Array.Sort(cacheGetSubspaceDisplayEntriesSubspace, SubpaceDisplayEntrySorter); if (unknownPlayers.Count > 0) { foreach (string playerName in unknownPlayers) { if (!cacheUnknownGetSubspaceDisplayEntriesSubspaceDict.ContainsKey(playerName)) { cacheUnknownGetSubspaceDisplayEntriesSubspaceDict[playerName] = new SubspaceDisplayEntry(); } SubspaceDisplayEntry sde = cacheUnknownGetSubspaceDisplayEntriesSubspaceDict[playerName]; sde.players = unknownPlayers.ToArray(); sde.isUs = unknownPlayers.Contains(dmpSettings.playerName); sde.isUnknown = true; sde.isWarping = false; sde.subspaceID = 0; if (usedCacheEntries < cacheGetSubspaceDisplayEntriesSubspace.Length) { cacheGetSubspaceDisplayEntriesSubspace[usedCacheEntries] = sde; usedCacheEntries++; } } } return(new Tuple <SubspaceDisplayEntry[], int>(cacheGetSubspaceDisplayEntriesSubspace, usedCacheEntries)); }
private SubspaceDisplayEntry[] GetSubspaceDisplayEntriesSubspace() { //Subspace/subspace simple mode Dictionary <int, List <string> > nonWarpCache = new Dictionary <int, List <string> >(); List <string> warpCache = new List <string>(); //Add us if (timeSyncer.currentSubspace != -1) { List <string> newList = new List <string>(); newList.Add(dmpSettings.playerName); nonWarpCache.Add(timeSyncer.currentSubspace, newList); } else { warpCache.Add(dmpSettings.playerName); } //Add other players foreach (KeyValuePair <string, int> clientEntry in clientSubspaceList) { if (clientEntry.Value != -1) { if (!nonWarpCache.ContainsKey(clientEntry.Value)) { nonWarpCache.Add(clientEntry.Value, new List <string>()); } if (!nonWarpCache[clientEntry.Value].Contains(clientEntry.Key)) { nonWarpCache[clientEntry.Value].Add(clientEntry.Key); } } else { if (!warpCache.Contains(clientEntry.Key)) { warpCache.Add(clientEntry.Key); } } } //Players missing subspace or warp entries List <string> unknownPlayers = new List <string>(); //Return list List <SubspaceDisplayEntry> returnList = new List <SubspaceDisplayEntry>(); //Process locked players foreach (KeyValuePair <int, List <string> > subspaceEntry in nonWarpCache) { if (timeSyncer.SubspaceExists(subspaceEntry.Key)) { SubspaceDisplayEntry sde = new SubspaceDisplayEntry(); sde.subspaceID = subspaceEntry.Key; sde.subspaceEntry = timeSyncer.GetSubspace(subspaceEntry.Key); subspaceEntry.Value.Sort(PlayerSorter); sde.isUs = subspaceEntry.Value.Contains(dmpSettings.playerName); sde.players = subspaceEntry.Value.ToArray(); returnList.Add(sde); } else { foreach (string unknownPlayer in subspaceEntry.Value) { unknownPlayers.Add(unknownPlayer); } } } //Process warping players foreach (string warpingPlayer in warpCache) { if (clientWarpList.ContainsKey(warpingPlayer)) { SubspaceDisplayEntry sde = new SubspaceDisplayEntry(); sde.warpingEntry = clientWarpList[warpingPlayer]; sde.players = new string[] { warpingPlayer }; sde.isUs = (warpingPlayer == dmpSettings.playerName); sde.isWarping = true; returnList.Add(sde); } else { unknownPlayers.Add(warpingPlayer); } } returnList.Sort(SubpaceDisplayEntrySorter); if (unknownPlayers.Count > 0) { SubspaceDisplayEntry sde = new SubspaceDisplayEntry(); sde.players = unknownPlayers.ToArray(); sde.isUs = unknownPlayers.Contains(dmpSettings.playerName); returnList.Add(sde); } return(returnList.ToArray()); }