z_zone.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __Z_ZONE__
  21. #define __Z_ZONE__
  22. #include <stdio.h>
  23. //
  24. // ZONE MEMORY
  25. // PU - purge tags.
  26. // Tags < 100 are not overwritten until freed.
  27. #define PU_STATIC 1 // static entire execution time
  28. #define PU_SOUND 2 // static while playing
  29. #define PU_MUSIC 3 // static while playing
  30. #define PU_LEVEL 50 // static until level exited
  31. #define PU_LEVSPEC 51 // a special thinker in a level
  32. // Tags >= 100 are purgable whenever needed.
  33. #define PU_PURGELEVEL 100
  34. #define PU_CACHE 101
  35. /*
  36. #define PU_STATIC_SHARED 4 // static entire execution time
  37. #define PU_SOUND_SHARED 5 // static while playing
  38. #define PU_MUSIC_SHARED 6 // static while playing
  39. #define PU_LEVEL_SHARED 52 // static until level exited
  40. #define PU_LEVSPEC_SHARED 53 // a special thinker in a level
  41. #define PU_CACHE_SHARED 102
  42. */
  43. #define PU_STATIC_SHARED PU_STATIC // static entire execution time
  44. #define PU_SOUND_SHARED PU_SOUND // static while playing
  45. #define PU_MUSIC_SHARED PU_MUSIC // static while playing
  46. #define PU_LEVEL_SHARED PU_LEVEL // static until level exited
  47. #define PU_LEVSPEC_SHARED PU_LEVSPEC // a special thinker in a level
  48. #define PU_CACHE_SHARED PU_CACHE
  49. bool Z_IsStatic( int tag );
  50. void Z_Init (void);
  51. void* Z_Malloc (int size, int tag, void *ptr);
  52. void Z_Free (void *ptr);
  53. void Z_FreeTag(int lowtag );
  54. void Z_FreeTags(int lowtag, int hightag );
  55. void Z_DumpHeap (int lowtag, int hightag);
  56. void Z_FileDumpHeap (FILE *f);
  57. void Z_CheckHeap (void);
  58. void Z_ChangeTag2 (void **ptr, int tag);
  59. int Z_FreeMemory (void);
  60. //bool MallocForLump( int lump, size_t size, void **ptr, int tag );
  61. template< class _type_ >
  62. bool MallocForLump( int lump, size_t size, _type_ * & ptr, int tag ) {
  63. ptr = static_cast< _type_ * >( Z_Malloc( size, tag, 0 ) );
  64. return true;
  65. }
  66. typedef struct memblock_s
  67. {
  68. int size; // including the header and possibly tiny fragments
  69. void** user; // NULL if a free block
  70. int tag; // purgelevel
  71. int id; // should be ZONEID
  72. struct memblock_s* next;
  73. struct memblock_s* prev;
  74. } memblock_t;
  75. //
  76. // This is used to get the local FILE:LINE info from CPP
  77. // prior to really call the function in question.
  78. //
  79. #define Z_ChangeTag(p,t) \
  80. { \
  81. if (( (memblock_t *)( (byte *)(p) - sizeof(memblock_t)))->id!=0x1d4a11) \
  82. I_Error("Z_CT at "__FILE__":%i",__LINE__); \
  83. Z_ChangeTag2((void**)&p,t); \
  84. };
  85. #endif