Team Fortress 2 Source Code as on 22/4/2020
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.

79 lines
1.1 KiB

  1. #ifndef VERTEX_CACHE_H
  2. #define VERTEX_CACHE_H
  3. class VertexCache
  4. {
  5. public:
  6. VertexCache(int size)
  7. {
  8. numEntries = size;
  9. entries = new int[numEntries];
  10. for(int i = 0; i < numEntries; i++)
  11. entries[i] = -1;
  12. }
  13. VertexCache() { VertexCache(16); }
  14. ~VertexCache() { delete[] entries; entries = 0; }
  15. bool InCache(int entry)
  16. {
  17. bool returnVal = false;
  18. for(int i = 0; i < numEntries; i++)
  19. {
  20. if(entries[i] == entry)
  21. {
  22. returnVal = true;
  23. break;
  24. }
  25. }
  26. return returnVal;
  27. }
  28. int AddEntry(int entry)
  29. {
  30. int removed;
  31. removed = entries[numEntries - 1];
  32. //push everything right one
  33. for(int i = numEntries - 2; i >= 0; i--)
  34. {
  35. entries[i + 1] = entries[i];
  36. }
  37. entries[0] = entry;
  38. return removed;
  39. }
  40. void Clear()
  41. {
  42. memset(entries, -1, sizeof(int) * numEntries);
  43. }
  44. void Copy(VertexCache* inVcache)
  45. {
  46. for(int i = 0; i < numEntries; i++)
  47. {
  48. inVcache->Set(i, entries[i]);
  49. }
  50. }
  51. int At(int index) { return entries[index]; }
  52. void Set(int index, int value) { entries[index] = value; }
  53. private:
  54. int *entries;
  55. int numEntries;
  56. };
  57. #endif