GOSImagePool.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. //
  7. GOSImagePool::GOSImagePool() :
  8. imageHash(
  9. 4099,
  10. NULL,
  11. true
  12. )
  13. {
  14. Verify(gos_GetCurrentHeap() == Heap);
  15. texturePath = "";
  16. }
  17. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. //
  19. GOSImagePool::~GOSImagePool()
  20. {
  21. HashIteratorOf<GOSImage*, MString> images(&imageHash);
  22. images.DeletePlugs();
  23. }
  24. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. //
  26. void GOSImagePool::UnLoadImages (void)
  27. {
  28. HashIteratorOf<GOSImage*, MString> images(&imageHash);
  29. GOSImage *image = images.ReadAndNext();
  30. while (image)
  31. {
  32. RemoveImage(image);
  33. image = images.ReadAndNext();
  34. }
  35. }
  36. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. //
  38. GOSImage*
  39. GOSImagePool::GetImage(const char* image_name)
  40. {
  41. Check_Object(this);
  42. MString imageName = image_name;
  43. Verify(imageName.GetLength() > 0);
  44. //
  45. //---------------------------
  46. // Get the image for the name
  47. //---------------------------
  48. //
  49. GOSImage *image;
  50. if ((image = imageHash.Find(imageName)) == NULL)
  51. {
  52. gos_PushCurrentHeap(Heap);
  53. image = new GOSImage(image_name);
  54. Register_Object(image);
  55. gos_PopCurrentHeap();
  56. imageHash.AddValue(image, image->imageName);
  57. }
  58. Check_Object(image);
  59. return image;
  60. }
  61. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. //
  63. GOSImage*
  64. GOSImagePool::GetImage(const char *image_name, gos_TextureFormat format, int size, gos_TextureHints hints)
  65. {
  66. Check_Object(this);
  67. MString imageName = image_name;
  68. Verify(imageName.GetLength() > 0);
  69. //
  70. //---------------------------
  71. // Get the image for the name
  72. //---------------------------
  73. //
  74. GOSImage *image;
  75. if ((image = imageHash.Find(imageName)) == NULL)
  76. {
  77. gos_PushCurrentHeap(Heap);
  78. image = new GOSImage(image_name, hints);
  79. Register_Object(image);
  80. gos_PopCurrentHeap();
  81. imageHash.AddValue(image, image->imageName);
  82. }
  83. #ifdef _ARMOR
  84. else
  85. {
  86. }
  87. #endif
  88. Check_Object(image);
  89. return image;
  90. }
  91. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. //
  93. void
  94. GOSImagePool::RemoveImage(GOSImage *image)
  95. {
  96. Check_Object(this);
  97. Unregister_Object(image);
  98. delete image;
  99. }
  100. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. //
  102. TGAFilePool::TGAFilePool(const char* path)
  103. {
  104. texturePath = path;
  105. }
  106. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. //
  108. bool
  109. TGAFilePool::LoadImage(GOSImage *image, int hint)
  110. {
  111. if( (image->flags & GOSImage::Loaded) != 0)
  112. return true;
  113. MString file_name = texturePath;
  114. file_name += image->imageName;
  115. file_name += ".tga";
  116. char *fFileName = file_name;
  117. if (((fFileName[0] != 'F') || (fFileName[0] != 'f')) &&
  118. ((fFileName[1] != 'X') || (fFileName[1] != 'x')))
  119. hint |= gosHint_DisableMipmap;
  120. DWORD nodeIndex = mcTextureManager->loadTexture(file_name,gos_Texture_Detect, hint);
  121. image->SetHandle(nodeIndex);
  122. image->flags |= GOSImage::Loaded;
  123. return ((image->flags & GOSImage::Loaded) != 0);
  124. }