MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Tick

Method Tick

Source/Engine/Content/Storage/FlaxStorage.cpp:1507–1543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1505}
1506
1507void FlaxStorage::Tick(double time)
1508{
1509 // Skip if file is in use
1510 if (Platform::AtomicRead(&_chunksLock) != 0)
1511 return;
1512
1513 bool wasAnyUsed = false;
1514 const float unusedDataChunksLifetime = ContentStorageManager::UnusedDataChunksLifetime.GetTotalSeconds();
1515 for (int32 i = 0; i < _chunks.Count(); i++)
1516 {
1517 auto chunk = _chunks.Get()[i];
1518 const bool wasUsed = (time - chunk->LastAccessTime) < unusedDataChunksLifetime;
1519 if (!wasUsed &&
1520 chunk->IsLoaded() &&
1521 EnumHasNoneFlags(chunk->Flags, FlaxChunkFlags::KeepInMemory) &&
1522 Platform::AtomicRead(&chunk->IsLoading) == 0)
1523 {
1524 // Guard the unloading so if other thread wants to lock the chunks will need to wait for this to end
1525 Platform::InterlockedIncrement(&_isUnloadingData);
1526 if (Platform::AtomicRead(&_chunksLock) != 0 || Platform::AtomicRead(&chunk->IsLoading) != 0)
1527 {
1528 // Someone started loading so skip ticking
1529 Platform::InterlockedDecrement(&_isUnloadingData);
1530 return;
1531 }
1532 chunk->Unload();
1533 Platform::InterlockedDecrement(&_isUnloadingData);
1534 }
1535 wasAnyUsed |= wasUsed;
1536 }
1537
1538 // Release file handles in none of chunks is in use
1539 if (!wasAnyUsed && Platform::AtomicRead(&_chunksLock) == 0)
1540 {
1541 CloseFileHandles();
1542 }
1543}
1544
1545#if USE_EDITOR
1546

Callers 1

JobMethod · 0.45

Calls 8

EnumHasNoneFlagsFunction · 0.85
AtomicReadFunction · 0.50
InterlockedIncrementFunction · 0.50
InterlockedDecrementFunction · 0.50
CountMethod · 0.45
GetMethod · 0.45
IsLoadedMethod · 0.45
UnloadMethod · 0.45

Tested by

no test coverage detected