void CEmiter::Read_t( CTStream &strm,BOOL bNetwork) { if (strm.PeekID_t()!=CChunkID(ID_EMITER_VER)) return; strm.GetID_t(); INDEX ctMaxParticles; strm>>ctMaxParticles; em_bInitialized=TRUE; INDEX ietType; strm>>ietType; em_etType=(CEmiterType) ietType; strm>>em_tmStart; strm>>em_tmLife; strm>>em_vG; strm>>em_colGlobal; strm>>em_iGlobal; if(ctMaxParticles==0) return; em_aepParticles.Push(ctMaxParticles); for(INDEX i=0; i<em_aepParticles.Count(); i++) { CEmittedParticle &em=em_aepParticles[i]; em.Read_t(strm,bNetwork); } }
// read bytes from buffer to stream SLONG CBuffer::ReadBytesToStream(CTStream &strm, SLONG slSize) { ASSERT(slSize>0); // clamp size to amount of bytes actually in the buffer SLONG slUsed = bu_slSize-bu_slFree; if (slUsed<slSize) { slSize = slUsed; } // if there is nothing to read if (slSize==0) { // do nothing return 0; } // read part of block after read pointer to the end of buffer SLONG slSizeEnd = __min(bu_slSize-bu_slReadOffset, slSize); strm.Write_t(bu_pubBuffer+bu_slReadOffset, slSizeEnd); // if that is not all if (slSizeEnd<slSize) { // read rest from start of buffer strm.Write_t(bu_pubBuffer, slSize-slSizeEnd); } // move read pointer bu_slReadOffset+=slSize; bu_slReadOffset%=bu_slSize; bu_slFree+=slSize; ASSERT(bu_slReadOffset>=0 && bu_slReadOffset<bu_slSize); ASSERT(bu_slFree>=0 && bu_slFree<=bu_slSize); return slSize; }
/* Unpack from stream to stream. */ void CCompressor::UnpackStream_t(CTMemoryStream &strmSrc, CTStream &strmDst) // throw char * { // read the header SLONG slSizeDst, slSizeSrc; strmSrc>>slSizeDst; strmSrc>>slSizeSrc; // get the buffer of source stream UBYTE *pubSrc = strmSrc.mstrm_pubBuffer + strmSrc.mstrm_slLocation; // allocate buffer for decompression UBYTE *pubDst = (UBYTE*)AllocMemory(slSizeDst); // compress there BOOL bOk = Unpack(pubSrc, slSizeSrc, pubDst, slSizeDst); // if failed if (!bOk) { // report error FreeMemory(pubDst); ThrowF_t(TRANS("Error while unpacking a stream.")); } // write the uncompressed data to destination strmDst.Write_t(pubDst, slSizeDst); strmDst.SetPos_t(0); FreeMemory(pubDst); }
void CEmiter::Write_t( CTStream &strm,BOOL bNetwork) { if( !em_bInitialized) return; INDEX ctMaxParticles=em_aepParticles.Count(); strm.WriteID_t(CChunkID(ID_EMITER_VER)); strm<<ctMaxParticles; strm<<INDEX(em_etType); strm<<em_tmStart; strm<<em_tmLife; strm<<em_vG; strm<<em_colGlobal; strm<<em_iGlobal; for(INDEX i=0; i<em_aepParticles.Count(); i++) { CEmittedParticle &em=em_aepParticles[i]; em.Write_t(strm,bNetwork); } }
// convert from old version of texture mapping defintion void CMappingDefinition::ReadOld_t(CTStream &strm) // throw char * { // old texture mapping orientation and offsets structure // - obsolete - used only for loading old worlds class CTextureMapping_old { public: ULONG tm_ulFlags; // flags ANGLE tm_aRotation; // angle of texture rotation FLOAT tm_fOffsetU; // texture offsets (in meters) FLOAT tm_fOffsetV; } tmo; strm.Read_t(&tmo, sizeof(tmo)); FLOAT fSin = Sin(tmo.tm_aRotation); FLOAT fCos = Cos(tmo.tm_aRotation); md_fUOffset = -tmo.tm_fOffsetU; md_fVOffset = -tmo.tm_fOffsetV; md_fUoS = +fCos; md_fUoT = -fSin; md_fVoS = +fSin; md_fVoT = +fCos; }
void CCompressor::PackStream_t(CTMemoryStream &strmSrc, CTStream &strmDst) // throw char * { // get the buffer of source stream UBYTE *pubSrc = strmSrc.mstrm_pubBuffer + strmSrc.mstrm_slLocation; SLONG slSizeSrc = strmSrc.GetStreamSize(); // allocate buffer for compression SLONG slSizeDst = NeededDestinationSize(slSizeSrc); UBYTE *pubDst = (UBYTE*)AllocMemory(slSizeDst); // compress there BOOL bOk = Pack(pubSrc, slSizeSrc, pubDst, slSizeDst); // if failed if (!bOk) { // report error FreeMemory(pubDst); ThrowF_t(TRANS("Error while packing a stream.")); } // write the header to destination strmDst<<slSizeSrc; strmDst<<slSizeDst; // write the compressed data to destination strmDst.Write_t(pubDst, slSizeDst); FreeMemory(pubDst); }
void CEmittedParticle::Read_t( CTStream &strm,BOOL bNetwork) { strm.ReadRawChunk_t( this, sizeof(CEmittedParticle)); }
void CEmittedParticle::Write_t( CTStream &strm,BOOL bNetwork) { strm.WriteRawChunk_t( this, sizeof(CEmittedParticle)); }