wadpath.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // AJM: added this file in
  2. #include "csg.h"
  3. wadpath_t* g_pWadPaths[MAX_WADPATHS];
  4. int g_iNumWadPaths = 0;
  5. // =====================================================================================
  6. // PushWadPath
  7. // adds a wadpath into the wadpaths list, without duplicates
  8. // =====================================================================================
  9. void PushWadPath(const char* const path, bool inuse)
  10. {
  11. int i;
  12. wadpath_t* current;
  13. if (!strlen(path))
  14. return; // no path
  15. // check for pre-existing path
  16. for (i = 0; i < g_iNumWadPaths; i++)
  17. {
  18. current = g_pWadPaths[i];
  19. if (!strcmp(current->path, path))
  20. return;
  21. }
  22. current = (wadpath_t*)malloc(sizeof(wadpath_t));
  23. safe_strncpy(current->path, path, _MAX_PATH);
  24. current->usedbymap = inuse;
  25. current->usedtextures = 0; // should be updated later in autowad procedures
  26. g_pWadPaths[g_iNumWadPaths++] = current;
  27. #ifdef _DEBUG
  28. Log("[dbg] PushWadPath: %i[%s]\n", g_iNumWadPaths, path);
  29. #endif
  30. }
  31. // =====================================================================================
  32. // IsUsedWadPath
  33. // =====================================================================================
  34. bool IsUsedWadPath(const char* const path)
  35. {
  36. int i;
  37. wadpath_t* current;
  38. for (i = 0; i < g_iNumWadPaths; i++)
  39. {
  40. current = g_pWadPaths[i];
  41. if (!strcmp(current->path, path))
  42. {
  43. if (current->usedbymap)
  44. return true;
  45. return false;
  46. }
  47. }
  48. return false;
  49. }
  50. // =====================================================================================
  51. // IsListedWadPath
  52. // =====================================================================================
  53. bool IsListedWadPath(const char* const path)
  54. {
  55. int i;
  56. wadpath_t* current;
  57. for (i = 0; i < g_iNumWadPaths; i++)
  58. {
  59. current = g_pWadPaths[i];
  60. if (!strcmp(current->path, path))
  61. return true;
  62. }
  63. return false;
  64. }
  65. // =====================================================================================
  66. // FreeWadPaths
  67. // =====================================================================================
  68. void FreeWadPaths()
  69. {
  70. int i;
  71. wadpath_t* current;
  72. for (i = 0; i < g_iNumWadPaths; i++)
  73. {
  74. current = g_pWadPaths[i];
  75. free(current);
  76. }
  77. }
  78. // =====================================================================================
  79. // GetUsedWads
  80. // parse the "wad" keyvalue into wadpath_t structs
  81. // =====================================================================================
  82. void GetUsedWads()
  83. {
  84. const char* pszWadPaths;
  85. char szTmp[_MAX_PATH];
  86. int i, j;
  87. pszWadPaths = ValueForKey(&g_entities[0], "wad");
  88. for(i = 0; i < MAX_WADPATHS; i++)
  89. {
  90. memset(szTmp, 0, sizeof(szTmp)); // are you happy zipster?
  91. for (j = 0; j < _MAX_PATH; j++, pszWadPaths++)
  92. {
  93. if (pszWadPaths[0] == ';')
  94. {
  95. pszWadPaths++;
  96. PushWadPath(szTmp, true);
  97. break;
  98. }
  99. if (pszWadPaths[0] == 0)
  100. {
  101. PushWadPath(szTmp, true); // fix by AmericanRPG for last wadpath ignorance bug
  102. return;
  103. }
  104. szTmp[j] = pszWadPaths[0];
  105. }
  106. }
  107. }