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.

80 lines
1.9 KiB

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