Add async scene drawing for Foliage and Terrain

This commit is contained in:
Wojtek Figat
2022-11-10 23:43:36 +01:00
parent ea5e38fdd1
commit 4ba1531cda
6 changed files with 62 additions and 48 deletions

View File

@@ -306,4 +306,21 @@ public:
Memory::ConstructItems(_allocation.Get() + index, &item, 1);
return index;
}
/// <summary>
/// Adds the specified item to the collection.
/// </summary>
/// <param name="item">The item to add.</param>
/// <returns>Index of the added element.</returns>
int32 Add(T&& item)
{
const int32 count = (int32)Platform::AtomicRead(&_count);
const int32 capacity = (int32)Platform::AtomicRead(&_capacity);
const int32 minCapacity = count + PLATFORM_THREADS_LIMIT; // Ensure there is a room for all threads (eg. all possible threads add item at once)
if (minCapacity >= capacity)
EnsureCapacity(minCapacity);
const int32 index = (int32)Platform::InterlockedIncrement(&_count) - 1;
Memory::MoveItems(_allocation.Get() + index, &item, 1);
return index;
}
};