void MatrixStack::popMatrix() { if (m_stack.size() == 0) { RE_ASSERT(false); // Stack Underflow } m_currentMatrix = m_stack.top(); m_stack.pop(); }
void MatrixStack::pushMatrix() { if (m_stack.size() > k_MatrixStack_MaxSize) { RE_ASSERT(false); // Stack Overflow } m_stack.push(m_currentMatrix); identity(); }
void* reFreeListAllocator::alloc(u32 size, u8 alignment) { RE_ASSERT(size != 0) // check free blocks FreeBlock* prevFreeBlock = nullptr; FreeBlock* freeBlock = _freeBlocks; while (freeBlock) { // calculate adjustment needed to keep object correctly aligned u8 adjustment = alignAdjustmentWithHeader(freeBlock, alignment, sizeof(Header)); // skip block if it is too small if (size + adjustment > freeBlock->size) { prevFreeBlock = freeBlock; freeBlock = prevFreeBlock->next; continue; } // if we ran out of memory if (freeBlock->size - size - adjustment <= sizeof(Header)) { // increases allocation size instead of creating a new block size = freeBlock->size; if (prevFreeBlock != nullptr) { prevFreeBlock->next = freeBlock->next; } else { _freeBlocks = freeBlock->next; } } else { // create a new free block from the remaining memory FreeBlock* nextBlock = (FreeBlock*)( (uptr)freeBlock + size + adjustment); nextBlock->size = freeBlock->size - size - adjustment; nextBlock->next = freeBlock->next; if (prevFreeBlock != nullptr) { prevFreeBlock->next = nextBlock; } else { _freeBlocks = nextBlock; } } uptr alignedAddress = (uptr)freeBlock + adjustment; Header* header = (Header*)(alignedAddress - sizeof(Header)); header->size = size + adjustment; header->adjustment = adjustment; _used += header->size; _numAllocs++; return (void*)alignedAddress; } RE_WARN("Couldn\'t find a free memory block large enough!\n") return nullptr; }
void CLEffect::setPhong(CLPhong* phong) { RE_ASSERT(phong); SAFE_RELEASE(m_phong); m_phong = phong; }