doomtool.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * ipak.h
  3. * General purpose data file management intended to be used
  4. * as a read-only memory mapped file to play nice with iPhone OS's
  5. * non-swapping and variable memory management.
  6. *
  7. * Created by John Carmack on 4/9/09.
  8. * Copyright 2009 id Software. All rights reserved.
  9. *
  10. */
  11. //============================================================
  12. //
  13. // In-file structures
  14. //
  15. // These stuctures are in the mapped data file, and shared
  16. // between the app and utility.
  17. //
  18. // Type headers are stored separately from the bulk data to minimize the
  19. // number of active pages.
  20. //
  21. // The full hash of the name is stored in nameHash, and nameHash&(PK_HASH_BUCKETS-1) is
  22. // used to chain structures of a particular type together.
  23. //
  24. //============================================================
  25. #define MAX_PK_NAME 64
  26. typedef struct {
  27. int nameHash; // PK_HashName( name )
  28. int nextOnHashChain; // -1 = end of chain
  29. char name[MAX_PK_NAME]; // in canonical form: backslashes to slashes and lowercase
  30. } pkName_t;
  31. #define PK_HASH_CHAINS 256
  32. typedef struct {
  33. int tableOfs; // // &firstStruct = (byte *)dfHeader + tableOfs
  34. int count;
  35. int structSize; // sizeof( pkWavData_t ), etc
  36. int hashChains[PK_HASH_CHAINS]; // -1 = end of chain
  37. } pkType_t;
  38. // dfWavData holds everything necessary to fully create an OpenAL sample buffer
  39. typedef struct {
  40. pkName_t name;
  41. int wavDataOfs;
  42. int wavChannels; // 1 or 2
  43. int wavChannelBytes; // 1 or 2
  44. int wavRate; // 22050, etc
  45. int wavNumSamples; // each sample holds all the channels
  46. // we may want looping information here later
  47. } pkWavData_t;
  48. // iPhone does not natively support palettized textures, but we
  49. // might conceivably want to support luminance and intensity textures
  50. // in the future.
  51. typedef enum {
  52. TF_565,
  53. TF_5551,
  54. TF_4444,
  55. TF_8888,
  56. TF_LA,
  57. TF_PVR4,
  58. TF_PVR4A,
  59. TF_PVR2,
  60. TF_PVR2A,
  61. } textureFormat_t;
  62. // dfImageData_t holds everything necessary to fully create an OpenGL texture object
  63. typedef struct {
  64. pkName_t name;
  65. int picDataOfs; // the raw bits to pass to gl, mipmaps appended
  66. // for PVR formats, the minimum size of each level is 32 bytes
  67. int format;
  68. int uploadWidth;
  69. int uploadHeight;
  70. int numLevels; // 1 for non mipmapped, otherwise log2( largest dimension )
  71. // glTexParameters
  72. int wrapS;
  73. int wrapT;
  74. int minFilter;
  75. int magFilter;
  76. int aniso;
  77. // The upload sizes can be larger than the source sizes for
  78. // non power of two sources, or for non square sources in the
  79. // case of PVR compression.
  80. int srcWidth;
  81. int srcHeight;
  82. float maxS; // srcWidth / uploadWidth
  83. float maxT;
  84. // Track the outlines of up to two boxes of non-transparent pixels
  85. // to allow optimized drawing of sprites with large empty areas.
  86. // The reason for two boxes is that the common lights have something
  87. // at the top and something at the bottom, with nothing inbetween.
  88. // These are inclusive bounds of the rows / columns in
  89. // uploadWidth / uploadHeight with non-0 alpha
  90. int numBounds;
  91. int bounds[2][2][2];
  92. } pkTextureData_t;
  93. typedef struct {
  94. pkName_t name;
  95. int rawDataOfs; // (byte *)pkHeader + dataOfs
  96. int rawDataLen; // there will always be a 0 byte appended to terminate strings
  97. // that is not counted in this length
  98. } pkRawData_t;
  99. #define PKFILE_VERSION 0x12340002
  100. typedef struct {
  101. int version;
  102. pkType_t textures;
  103. pkType_t wavs;
  104. pkType_t raws;
  105. } pkHeader_t;
  106. //============================================================
  107. //
  108. // In-memory, writable structures
  109. //
  110. //============================================================
  111. typedef struct {
  112. unsigned glTexNum;
  113. const pkTextureData_t *textureData;
  114. // we will need to add LRU links if texture caching is needed
  115. } pkTexture_t;
  116. typedef struct {
  117. unsigned alBufferNum; // created with the staticBuffer extension directly in the mapped memory
  118. const pkWavData_t *wavData;
  119. } pkWav_t;
  120. void PK_Init( const char *pakFileName );
  121. const pkName_t *PK_FindType( const char *rawName, const pkType_t *type, int *index );
  122. const byte * PK_FindRaw( const char *rawName, int *len ); // len can be NULL if you don't need it
  123. pkTexture_t * PK_FindTexture( const char *imageName );
  124. pkWav_t * PK_FindWav( const char *soundName );
  125. // The name will be converted to canonical name (backslashes converted to slashes and lowercase)
  126. // before generating a hash.
  127. int PK_HashName( const char *name, char canonical[MAX_PK_NAME] );
  128. void PK_BindTexture( pkTexture_t *tex );
  129. void PK_DrawTexture( pkTexture_t *tex, int x, int y );
  130. void PK_StretchTexture( pkTexture_t *tex, float x, float y, float w, float h );
  131. extern pkHeader_t * pkHeader;
  132. extern int pkSize;
  133. // images and wavs have writable state, so they need separate
  134. // structs that also point to the source in the pak file
  135. extern pkTexture_t *pkTextures;
  136. extern pkWav_t * pkWavs;