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.

92 lines
2.1 KiB

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