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.

87 lines
1.1 KiB

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