/// <summary> /// Periodically requests the client statuses for all shown users in the buffer. /// </summary> private void PeriodicallyRequestClientStatuses() { if (GameBase.Game.TimeRunning - LastStatusRequestTime < 15000) { return; } // Get all the users in the buffer. var userIds = new List <int>(); for (var i = 0; i < UserBuffer.Count; i++) { var user = UserBuffer.ElementAt(i); if (user.User != null && AvailableUsers.Contains(user.User) && !userIds.Contains(user.User.OnlineUser.Id)) { userIds.Add(user.User.OnlineUser.Id); } } LastStatusRequestTime = GameBase.Game.TimeRunning; if (userIds.Count == 0) { return; } OnlineManager.Client?.RequestUserStatuses(userIds); }
/// <summary> /// Updates all the user info for the current buffer. /// </summary> public void UpdateUserInfo(User user) { lock (UserBuffer) { for (var i = 0; i < UserBuffer.Count; i++) { var item = UserBuffer.ElementAt(i); if (item.User == null || item.User.OnlineUser.Id != user.OnlineUser.Id) { continue; } item.UpdateUser(OnlineManager.OnlineUsers[user.OnlineUser.Id]); var index = AvailableUsers.FindIndex(x => x.OnlineUser.Id == item.User.OnlineUser.Id); if (index == -1) { continue; } AvailableUsers[index] = item.User; SortUsers(); RecalculateContainerHeight(); UpdateBufferUsers(); } } }
/// <summary> /// Updates all of the current buffer users. /// </summary> public void UpdateBufferUsers() { for (var i = 0; i < UserBuffer.Count; i++) { var bufferObject = UserBuffer.ElementAt(i); // In the event that there aren't any available users left, we want to remove these unused // contained drawable objects. if (AvailableUsers.ElementAtOrDefault(PoolStartingIndex + i) == null) { RemoveContainedDrawable(bufferObject); UserBufferObjectsUsed--; continue; } bufferObject.Y = (PoolStartingIndex + i) * DrawableOnlineUser.HEIGHT; bufferObject.UpdateUser(AvailableUsers[PoolStartingIndex + i]); // Make sure the object is contained if it isn't already. if (bufferObject.Parent != ContentContainer) { AddContainedDrawable(bufferObject); } } }
public Registers() { AC = new LinkAccumulator(); PC = new InstructionFieldProgramCounter(); SR = new SwitchRegister(); MQ = new MultiplierQuotient(); DF = new DataField(); IB = new InstructionBuffer(); UB = new UserBuffer(); UF = new UserFlag(); SF = new SaveField(); }
/// <summary> /// Handles shifting the pool whenever the container is scrolled. /// Also initializing any new objects that need it. /// </summary> /// <param name="direction"></param> private void HandlePoolShifting(Direction direction) { switch (direction) { case Direction.Forward: // If there are no available users then there's no need to do anything. if (AvailableUsers.ElementAtOrDefault(PoolStartingIndex) == null || AvailableUsers.ElementAtOrDefault(PoolStartingIndex + MAX_USERS_SHOWN) == null) { return; } var firstUser = UserBuffer.First(); // Check if the object is in the rect of the ScrollContainer. // If it is, then there's no updating that needs to happen. if (!Rectangle.Intersect(firstUser.ScreenRectangle, ScreenRectangle).IsEmpty) { return; } // Update the user's information and y position. firstUser.Y = (PoolStartingIndex + MAX_USERS_SHOWN) * DrawableOnlineUser.HEIGHT; lock (AvailableUsers) firstUser.UpdateUser(AvailableUsers[PoolStartingIndex + MAX_USERS_SHOWN]); // Circuluarly Shift the list forward one. UserBuffer.RemoveFirst(); UserBuffer.AddLast(firstUser); // Take this user, and place them at the bottom. PoolStartingIndex++; break; case Direction.Backward: // If there are no previous available user then there's no need to shift. if (AvailableUsers.ElementAtOrDefault(PoolStartingIndex - 1) == null) { return; } var lastUser = UserBuffer.Last(); // Check if the object is in the rect of the ScrollContainer. // If it is, then there's no updating that needs to happen. if (!Rectangle.Intersect(lastUser.ScreenRectangle, ScreenRectangle).IsEmpty) { return; } lastUser.Y = (PoolStartingIndex - 1) * DrawableOnlineUser.HEIGHT; lock (AvailableUsers) lastUser.UpdateUser(AvailableUsers[PoolStartingIndex - 1]); UserBuffer.RemoveLast(); UserBuffer.AddFirst(lastUser); PoolStartingIndex--; break; default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } }