void DataPipe::SetGP(vector3di pos) { unsigned l; GP = pos; WriteLock(); status = DPIPE_BUSY; for (l = 0; l < HOLDCHUNKS; l++) { SaveChunk(l); chstat[l].s = DPCHK_QUEUE; } #if HOLDCHUNKS == 1 l = 0; #elif HOLDCHUNKS == 9 l = 1 * 3 + 1; #else /*18 or 27*/ l = 1 * 9 + 1 * 3 + 1; #endif #ifdef DPDEBUG dbg_print("[DP] SetGP(): [%d %d %d]",GP.X,GP.Y,GP.Z); #endif MakeChunk(l,GP); UpdateModelsSceneRoot(); status = DPIPE_IDLE; WriteUnlock(); }
boolean MemMakeCppChunk (bytessize CppObjSize, indextype AllocQty, indextype ExtendQty, idtype CoreDbId, ft F,lt Z,zz *Status, numtype *Chunk) { boolean VaryLength = False; boolean PtrChunk = True; MakeChunk (VaryLength, PtrChunk, CppObjSize, AllocQty, ExtendQty, CoreDbId, McStat, Chunk); TRACK(TrackBak,"MemMakeCppChunk\n"); return(STAT); }
TEST_F(TestDownloader, DownloaderShouldPushDataToQueue) { const std::string data(CHUNK_SIZE, '$'); FakeSource src(data, CHUNK_DELAY); Queue q; Downloader dl(src, q); dl.Start(); dl.Wait(); ASSERT_EQ(MakeChunk(data), q.Pop(CHUNK_SIZE)); }
TEST_F(TestDownloader, CancelShouldStopDownloader) { const std::string data(CHUNK_SIZE, '$'); FakeSource src(data, CHUNK_DELAY, CHUNK_NUMBER); Queue q; Downloader dl(src, q); dl.Start(); usleep(CHUNK_DELAY); dl.Cancel(); ASSERT_EQ(MakeChunk(data), q.Pop(CHUNK_SIZE * CHUNK_NUMBER)); }
boolean MemMakeStrChunk (bytessize MaxLength, indextype NumStrings, indextype ExtendQty, bytessize TextLength, idtype CoreDbId, ft F,lt Z,zz *Status, numtype *StrChunk) { boolean VaryLength = False; boolean PtrChunk = True; numtype TextChunk = 0; struchdr *StrucHdr = NullPtr; if (MakeChunk (VaryLength, PtrChunk, sizeof (stringstruc), NumStrings, ExtendQty, CoreDbId, McStat, StrChunk)) VaryLength = True; PtrChunk = False; if (Normal(*Status) && *StrChunk) if (MakeChunk (VaryLength, PtrChunk, sizeof (char), TextLength, ExtendQty*32, CoreDbId, McStat, &TextChunk)) { Extend_Qty (TextChunk) = ExtendQty * 32; MaxUnit_Length (TextChunk) = MaxLength; IsData_Chunk (*StrChunk); StrucHdr = (struchdr *)Chunk_Addr (*StrChunk); StrucHdr->TextChunk = TextChunk; StrucHdr->TextVbn = 0; StrucHdr->FirstFreeGap = 0; Stack_Ptr (*StrChunk)++; } TRACK(TrackBak,"MemMakeStrChunk\n"); return(STAT); }
bool PutChunk ( LFA_FileRef inFileRef, RiffState & inOutRiffState, long riffType, long tagID, const char * inBuffer, UInt32 inBufferSize ) { UInt32 len; UInt64 pos; atag tag; // Make sure we're writting an even number of bytes. Required by the RIFF specification. XMP_Assert ( (inBufferSize & 1) == 0 ); try { bool found = FindChunk ( inOutRiffState, tagID, 0, 0, NULL, &len, &pos ); if ( found ) { if ( len == inBufferSize ) { LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, inBuffer, inBufferSize ); return true; } pos -= 8; tag.id = MakeUns32LE ( ckidPremierePadding ); LFA_Seek ( inFileRef, pos, SEEK_SET ); LFA_Write ( inFileRef, &tag, 4 ); if ( len > inBufferSize ) { pos += 8; AddTag ( inOutRiffState, ckidPremierePadding, len, pos, 0, 0, 0 ); } } } catch ( ... ) { // If a write fails, it throws, so we return false return false; } bool ok = MakeChunk ( inFileRef, inOutRiffState, riffType, (inBufferSize + 8) ); if ( ! ok ) return false; return WriteChunk ( inFileRef, tagID, inBuffer, inBufferSize ); }
boolean MemMakeChunk (bytessize UnitSize, indextype AllocQty, indextype ExtendQty, idtype CoreDbId, ft F,lt Z,zz *Status, numtype *Chunk) { boolean VaryLength = False; boolean PtrChunk = False; if (!UnitSize || !AllocQty) { *Status = Err_BadUnitSize; } if (Normal(*Status)) if (MakeChunk (VaryLength, PtrChunk, UnitSize, AllocQty, ExtendQty, CoreDbId, McStat, Chunk)) { IsNumeric_Chunk (*Chunk); IsData_Chunk (*Chunk); } TRACK(TrackBak,"MemMakeChunk\n"); return(STAT); }
bool DataPipe::Move(const vector3di shf) { vector3di rgp; //Check shift vector first if ( (abs(shf.X) > 1) || (abs(shf.Y) > 1) || (abs(shf.Z) > 1) ) return false; #ifdef DPDEBUG dbg_print("[DP] Move(): shift = [%d %d %d]",shf.X,shf.Y,shf.Z); #endif rgp = GP + shf; if (rgp.Z == 0) { //TODO: Z-thru } if (wgen) wgen->WrapCoords(&rgp); #if HOLDCHUNKS == 1 SetGP(rgp); return true; #else /* 9, 18, 27 */ int l,nl,x,y,z,nx,ny; PChunk swa; SChunkState swb; #if HOLDCHUNKS == 9 if (shf.Z) { SetGP(GP+shf); return true; } #else /* 18, 27 */ int nz; #if HOLDCHUNKS == 18 if (shf.Z > 0) { SetGP(GP+shf); return true; } #endif #endif //Lock everything WriteLock(); status = DPIPE_BUSY; GP = rgp; //Swap remaining chunks and mark new ones for (x = 0; x < 3; x++) { for (y = 0; y < 3; y++) { #if HOLDCHUNKS == 18 for (z = 0; z < 2; z++) { #else for (z = 0; z < 3; z++) { #endif nx = (shf.X < 0)? 2-x:x; ny = (shf.Y < 0)? 2-y:y; #if HOLDCHUNKS > 9 #if HOLDCHUNKS == 27 nz = (shf.Z < 0)? 2-z:z; #else nz = (shf.Z < 0)? 1-z:z; #endif l = nz * 9 + ny * 3 + nx; nl = (nz + shf.Z) * 9 + (ny + shf.Y) * 3 + nx + shf.X; #else l = ny * 3 + nx; nl = (ny + shf.Y) * 3 + nx + shf.X; #endif /* 9 chunks */ if ( ((shf.X > 0) && (nx > 1)) || ((shf.X < 0) && (nx < 1)) || ((shf.Y > 0) && (ny > 1)) || ((shf.Y < 0) && (ny < 1)) || #if HOLDCHUNKS > 9 ((shf.Z > 0) && (nz > 1)) || ((shf.Z < 0) && (nz < 1)) || #endif (nl < 0) || (nl >= HOLDCHUNKS)) { //new chunk chstat[l].s = DPCHK_QUEUE; #ifdef DPDEBUG dbg_print("[DP] Marking chunk %d",l); #endif continue; } #ifdef DPDEBUG dbg_print("[DP] Swapping chunks %d <-> %d",l,nl); #endif //swap chunks swa = chunks[l]; chunks[l] = chunks[nl]; chunks[nl] = swa; swb = chstat[l]; chstat[l] = chstat[nl]; chstat[nl] = swb; } } } //Update models root UpdateModelsSceneRoot(); //Release everything status = DPIPE_IDLE; WriteUnlock(); return true; #endif } void DataPipe::ChunkQueue() { if (status != DPIPE_IDLE) return; #if HOLDCHUNKS == 1 /* Do nothing */ return; #else vector3di cur; bool fnd = false; unsigned l; /* Apply soft-lock to not interfere with rendering * while time-consuming loading or generation is * processing. */ ReadLock(); #if HOLDCHUNKS == 9 int i,j; cur.Z = GP.Z; for (i = -1, l = 0; i < 2; i++) { cur.Y = GP.Y + i; for (j = -1; j < 2; j++, l++) { cur.X = GP.X + j; if (chstat[l].s == DPCHK_QUEUE) { fnd = true; goto chunk_found; } } } #elif HOLDCHUNKS == 18 int i,j,k; for (i = -1, l = 0; i <= 0; i++) { cur.Z = GP.Z + i; for (j = -1; j < 2; j++) { cur.Y = GP.Y + j; for (k = -1; k < 2; k++, l++) { cur.X = GP.X + k; if (chstat[l].s == DPCHK_QUEUE) { fnd = true; goto chunk_found; } } } } #elif HOLDCHUNKS == 27 int i,j,k; for (i = -1, l = 0; i < 2; i++) { cur.Z = GP.Z + i; for (j = -1; j < 2; j++) { cur.Y = GP.Y + j; for (k = -1; k < 2; k++, l++) { cur.X = GP.X + k; if (chstat[l].s == DPCHK_QUEUE) { fnd = true; goto chunk_found; } } } } #endif chunk_found: if (fnd) { chstat[l].s = DPCHK_LOADING; MakeChunk(l,cur); } ReadUnlock(); #endif } void DataPipe::MakeChunk(const unsigned l, const vector3di pos) { SDataPlacement plc; if (chstat[l].changed) SaveChunk(l); if (!FindChunk(pos,&plc)) { if (wgen) { wgen->GenerateChunk(chunks[l],pos); chstat[l].s = DPCHK_READY; chstat[l].pos = pos.ToSimVecInt(); #ifdef DPDEBUG dbg_print("[DP] Chunk %u generated at [%d %d %d]",l,pos.X,pos.Y,pos.Z); #endif } else { chstat[l].s = DPCHK_ERROR; chstat[l].changed = false; #ifdef DPDEBUG dbg_print("[DP] No WorldGen instance to generate chunk at [%d %d %d]",l,pos.X,pos.Y,pos.Z); #endif } } else if (!LoadChunk(&plc,chunks[l])) { chstat[l].s = DPCHK_ERROR; chstat[l].changed = false; #ifdef DPDEBUG dbg_print("[DP] Error loading chunk %u at [%d %d %d]",l,pos.X,pos.Y,pos.Z); #endif } else { chstat[l].s = DPCHK_READY; chstat[l].pos = pos.ToSimVecInt(); #ifdef DPDEBUG dbg_print("[DP] Chunk %u loaded at [%d %d %d]",l,pos.X,pos.Y,pos.Z); #endif } }