Snapshot_Jobs.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 __SNAPSHOT_JOBS_H__
  21. #define __SNAPSHOT_JOBS_H__
  22. #include "LightweightCompression.h"
  23. //#define SNAPSHOT_CHECKSUMS
  24. typedef int32 objectSize_t;
  25. static const objectSize_t SIZE_STALE = MAX_TYPE( objectSize_t ); // Special size to indicate object went stale
  26. static const objectSize_t SIZE_NOT_STALE = MAX_TYPE( objectSize_t ) - 1; // Special size to indicate object is no longer stale
  27. static const int RLE_COMPRESSION_PADDING = 16; // Padding to accommodate possible enlargement due to zlre compression
  28. // OBJ_DEST_SIZE_ALIGN16 returns the total space needed to store an object for reading/writing during jobs
  29. #define OBJ_DEST_SIZE_ALIGN16( s ) ( ( ( s ) + 15 ) & ~15 )
  30. static const uint32 OBJ_VIS_STALE = ( 1 << 0 ); // Object went stale
  31. static const uint32 OBJ_VIS_NOT_STALE = ( 1 << 1 ); // Object no longer stale
  32. static const uint32 OBJ_NEW = ( 1 << 2 ); // New object (not in the last snap)
  33. static const uint32 OBJ_DELETED = ( 1 << 3 ); // Object was deleted (not going to be in the new snap)
  34. static const uint32 OBJ_DIFFERENT = ( 1 << 4 ); // Objects are in both snaps, but different
  35. static const uint32 OBJ_SAME = ( 1 << 5 ); // Objects are in both snaps, and are the same (we don't send these, which means ack)
  36. // This struct is used to communicate data from the obj jobs to the lzw job
  37. struct ALIGNTYPE16 objHeader_t {
  38. int32 objID; // Id of object.
  39. int32 size; // Size data object holds (will be 0 if the obj is being deleted)
  40. int32 csize; // Size after zrle compression
  41. uint32 flags; // Flags used to communicate state from obj job to lzw delta job
  42. uint8 * data; // Data ptr to obj memory
  43. #ifdef SNAPSHOT_CHECKSUMS
  44. uint32 checksum; // Checksum before compression, used for sanity checking
  45. #endif
  46. };
  47. struct objJobState_t {
  48. uint8 valid;
  49. uint8 * data;
  50. uint16 size;
  51. uint16 objectNum;
  52. uint32 visMask;
  53. };
  54. // Input to initial jobs that produce delta'd zrle compressed versions of all the snap obj's
  55. struct ALIGNTYPE16 objParms_t {
  56. // Input
  57. uint8 visIndex;
  58. objJobState_t newState;
  59. objJobState_t oldState;
  60. // Output
  61. objHeader_t * destHeader;
  62. uint8 * dest;
  63. };
  64. // Output from the job that takes the results of the delta'd zrle obj's.
  65. // This struct contains the start of where the final delta packet data is within lzwMem
  66. struct ALIGNTYPE16 lzwDelta_t {
  67. int offset; // Offset into lzwMem
  68. int size;
  69. int snapSequence;
  70. };
  71. // Struct used to maintain state that needs to persist across lzw jobs
  72. struct ALIGNTYPE16 lzwInOutData_t {
  73. int numlzwDeltas; // Num pending deltas written
  74. bool fullSnap; // True if entire snap was written out in one delta
  75. lzwDelta_t * lzwDeltas; // Info about each final delta packet written out
  76. int maxlzwDeltas; // Max lzw deltas
  77. uint8 * lzwMem; // Resulting final lzw delta packet data
  78. int maxlzwMem; // Max size in bytes that can fit in lzwMem
  79. int lzwDmaOut; // How much of lzwMem needs to be DMA'ed back out
  80. int lzwBytes; // Final delta packet bytes written
  81. int optimalLength; // Optimal length of lzw streams
  82. int snapSequence;
  83. uint16 lastObjId; // Last obj id written out
  84. lzwCompressionData_t * lzwData;
  85. };
  86. // Input to the job that takes the results of the delta'd zrle obj's, and turns them into lzw delta packets
  87. struct ALIGNTYPE16 lzwParm_t {
  88. // Input
  89. int numObjects; // Number of objects this job needs to process
  90. objHeader_t * headers; // Object headers
  91. int curTime; // Cur snap time
  92. int baseTime; // Base snap time
  93. int baseSequence;
  94. bool saveDictionary;
  95. bool fragmented; // This lzw stream should continue where the last one left off
  96. // In/Out
  97. lzwInOutData_t * ioData; // In/Out
  98. };
  99. extern void SnapshotObjectJob( objParms_t * parms );
  100. extern void LZWJob( lzwParm_t * parm );
  101. #endif // __SNAPSHOT_JOBS_H__