void AItem::TakeFrom(AItem* otherItem) { // Get the amount of items needed to add int amountToAdd = otherItem->GetAmount(); // Can we just add to this item if (GetRemainingSpace() >= amountToAdd) { SetAmount(GetAmount() + otherItem->GetAmount()); otherItem->SetAmount(0); } else { // If we're greater than stack size just set the amount to max size otherItem->SetAmount(otherItem->GetAmount() - GetRemainingSpace()); SetAmount(GetStackSize()); } }
//------------------------------------------------------------------------------ void* LinearAllocator::Allocate(std::size_t allocationSize) noexcept { CS_ASSERT(allocationSize <= GetRemainingSpace(), "Allocation is too big to fit in the remaining space."); std::uint8_t* output = m_nextPointer; m_nextPointer = MemoryUtils::Align(m_nextPointer + allocationSize, sizeof(std::intptr_t)); ++m_activeAllocationCount; return output; }