A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.9 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. namespace SemiColinGames {
  5. // An IList<T>, backed by a List<T>, that prints out a debug message any time that the Capacity
  6. // of the underlying List changes.
  7. public class ProfilingList<T> : IList<T> {
  8. private readonly List<T> items;
  9. private readonly string name;
  10. private int previousCapacity;
  11. public ProfilingList(int capacity, string name) {
  12. items = new List<T>(capacity);
  13. previousCapacity = capacity;
  14. this.name = name;
  15. }
  16. public bool IsReadOnly {
  17. get { return false; }
  18. }
  19. public void Add(T item) {
  20. items.Add(item);
  21. CheckCapacity();
  22. }
  23. public void Insert(int index, T item) {
  24. items.Insert(index, item);
  25. CheckCapacity();
  26. }
  27. [Conditional("DEBUG")]
  28. private void CheckCapacity() {
  29. if (items.Capacity != previousCapacity) {
  30. Debug.WriteLine($"ProfilingList {name} capacity: {previousCapacity} -> {items.Capacity}");
  31. previousCapacity = items.Capacity;
  32. }
  33. }
  34. // Everything below this point is boilerplate delegation to the underlying list.
  35. public void Clear() {
  36. items.Clear();
  37. }
  38. public bool Contains(T item) {
  39. return items.Contains(item);
  40. }
  41. public int Count {
  42. get => items.Count;
  43. }
  44. public int IndexOf(T item) {
  45. return items.IndexOf(item);
  46. }
  47. public bool Remove(T item) {
  48. return items.Remove(item);
  49. }
  50. public void CopyTo(T[] array, int arrayIndex) {
  51. items.CopyTo(array, arrayIndex);
  52. }
  53. public void RemoveAt(int index) {
  54. items.RemoveAt(index);
  55. }
  56. public T this[int index] {
  57. get { return items[index]; }
  58. set { items[index] = value; }
  59. }
  60. public IEnumerator<T> GetEnumerator() {
  61. return items.GetEnumerator();
  62. }
  63. IEnumerator IEnumerable.GetEnumerator() {
  64. return items.GetEnumerator();
  65. }
  66. }
  67. }