tsShapeAlloc.h
Engine/source/ts/tsShapeAlloc.h
Classes:
Alloc structure used in the reading/writing of shapes.
Reading Operations:
get(): reads one or more entries of type from input buffer (doesn't affect output buffer)
copyToShape(): copies entries of type from input buffer to output buffer
allocShape(): creates room for entries of type in output buffer (no effect on input buffer)
getPointer(): gets pointer to next entries of type in input buffer (no effect on input buffer)
note:set(): adds one entry to appropriate bufferall operations advance current "position" of input and output buffers writing operations:
copyToBuffer(): adds count entries to approrpiate buffer
getBuffer(): returns associated buffer (i.e., getBuffer32 gets 32bit buffer)
getBufferSize(): returns size of associated buffer
DECLARE_ALLOC(suffix, type) type get##suffix(); \ get##suffix(type*,); \ type * copyToShape##suffix(,bool returnSomething=false); \ type * getPointer##suffix(); \ type * allocShape##suffix(); \ bool checkGuard##suffix(); \ type getPrevGuard##suffix(); \ type getSaveGuard##suffix(); \ type * getBuffer##suffix(); \ getBufferSize##suffix(); \ setGuard##suffix(); \ type * extend##suffix(); \ type set##suffix(type); \ copyToBuffer##suffix(type*,);
Detailed Description
Reading Operations:
get(): reads one or more entries of type from input buffer (doesn't affect output buffer)
copyToShape(): copies entries of type from input buffer to output buffer
allocShape(): creates room for entries of type in output buffer (no effect on input buffer)
getPointer(): gets pointer to next entries of type in input buffer (no effect on input buffer)
note:set(): adds one entry to appropriate bufferall operations advance current "position" of input and output buffers writing operations:
copyToBuffer(): adds count entries to approrpiate buffer
getBuffer(): returns associated buffer (i.e., getBuffer32 gets 32bit buffer)
getBufferSize(): returns size of associated buffer
DECLARE_ALLOC(suffix, type) type get##suffix(); \ get##suffix(type*,); \ type * copyToShape##suffix(,bool returnSomething=false); \ type * getPointer##suffix(); \ type * allocShape##suffix(); \ bool checkGuard##suffix(); \ type getPrevGuard##suffix(); \ type getSaveGuard##suffix(); \ type * getBuffer##suffix(); \ getBufferSize##suffix(); \ setGuard##suffix(); \ type * extend##suffix(); \ type set##suffix(type); \ copyToBuffer##suffix(type*,);
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _TSSHAPEALLOC_H_ 25#define _TSSHAPEALLOC_H_ 26 27#ifndef _PLATFORM_H_ 28#include "platform/platform.h" 29#endif 30#ifndef _MMATH_H_ 31#include "math/mMath.h" 32#endif 33 34/// Alloc structure used in the reading/writing of shapes. 35/// 36/// In read mode we assemble contents of 32-bit, 16-bit, and 8-bit buffers 37/// into a single destination buffer. 38/// 39/// In write mode we dissemble a stream of memory (which may be scattered in physical memory) 40/// into 32-bit, 16-bit, 8-bit, Point3F, and Point2F buffers using function calls similar 41/// to the read calls. 42/// 43/// Read usage: 44/// 1. call "setRead" with each incoming memory buffers and clear=true. 45/// 2. run through set of operations for allocating and transfering memory to target buffer 46/// these are the operations under "DECLARE_ALLOC" that call readOnly in the .cc file. 47/// 3. call "doAlloc" to create buffer exactly as large as needed. 48/// 4. repeat step 1 & 2 to do the actual transfer of memory, except with clear=false 49/// (note: first time through nothing was copied to the shape, we only kept track 50/// of the size of the transfer). 51/// 5. call getBuffer to get the target (destination buffer) 52/// 53/// write usage: 54/// 1. call "setWrite" (no parameters). 55/// 2. run through set of operations for allocating and transfering memory to internal buffers 56/// these are the operations under "DECLARE_ALLOC" that call writeOnly in the .cc file. 57/// 3. call getBuffer32 and getBufferSize32 to get 32-bit buffer and size. Similarly for 58/// 16-bit, 8-bit (getBuffer16, getBuffer8). 59/// 60/// TSShape::assesmbleShape and TSShape::dissembleShape can be used as examples 61class TSShapeAlloc 62{ 63 S32 mMode; ///< read or write 64 65 /// reading and writing (when reading these are the input; when writing these are the output) 66 S32 * mMemBuffer32; 67 S16 * mMemBuffer16; 68 S8 * mMemBuffer8; 69 70 /// for writing only... 71 S32 mSize32; 72 S32 mSize16; 73 S32 mSize8; 74 S32 mFullSize32; 75 S32 mFullSize16; 76 S32 mFullSize8; 77 78 /// reading and writing... 79 S32 mMemGuard32; 80 S16 mMemGuard16; 81 S8 mMemGuard8; 82 83 /// reading 84 S32 mSaveGuard32; 85 S16 mSaveGuard16; 86 S8 mSaveGuard8; 87 88 /// reading only...this is the output 89 S8 * mDest; 90 S32 mSize; 91 S32 mMult; ///< mult incoming sizes by this (when 0, then mDest doesn't grow --> skip mode) 92 93 public: 94 95 enum { ReadMode = 0, WriteMode = 1, PageSize = 1024 }; ///< PageSize must be multiple of 4 so that we can always 96 ///< "over-read" up to next dword 97 98 void setRead(S32 * buff32, S16 * buff16, S8 * buff8, bool clear); 99 void setWrite(); 100 101 // reading only... 102 void doAlloc(); 103 void align32(); ///< align on dword boundary 104 S8 * getBuffer() { return mDest; } 105 S32 getSize() { return mSize; } 106 void setSkipMode(bool skip) { mMult = skip ? 0 : 1; } 107 108 /// @name Reading Operations: 109 /// 110 /// get(): reads one or more entries of type from input buffer (doesn't affect output buffer) 111 /// 112 /// copyToShape(): copies entries of type from input buffer to output buffer 113 /// 114 /// allocShape(): creates room for entries of type in output buffer (no effect on input buffer) 115 /// 116 /// getPointer(): gets pointer to next entries of type in input buffer (no effect on input buffer) 117 /// 118 /// @note all operations advance current "position" of input and output buffers 119 /// writing operations: 120 /// 121 /// set(): adds one entry to appropriate buffer 122 /// 123 /// copyToBuffer(): adds count entries to approrpiate buffer 124 /// 125 /// getBuffer(): returns associated buffer (i.e., getBuffer32 gets 32bit buffer) 126 /// 127 /// getBufferSize(): returns size of associated buffer 128 /// 129 /// @{ 130 131 #define DECLARE_ALLOC(suffix,type) \ 132 type get##suffix(); \ 133 void get##suffix(type*,S32); \ 134 type * copyToShape##suffix(S32,bool returnSomething=false); \ 135 type * getPointer##suffix(S32); \ 136 type * allocShape##suffix(S32); \ 137 bool checkGuard##suffix(); \ 138 type getPrevGuard##suffix(); \ 139 type getSaveGuard##suffix(); \ 140 type * getBuffer##suffix(); \ 141 S32 getBufferSize##suffix(); \ 142 void setGuard##suffix(); \ 143 type * extend##suffix(S32); \ 144 type set##suffix(type); \ 145 void copyToBuffer##suffix(type*,S32); 146 147 148 DECLARE_ALLOC(32,S32) 149 DECLARE_ALLOC(16,S16) 150 DECLARE_ALLOC(8,S8) 151 /// @} 152 153 void checkGuard(); 154 void setGuard(); 155}; 156 157#endif // _H_TS_SHAPE_ALLOC_ 158