| 128 | */ |
| 129 | |
| 130 | void NetPacket::InitStream(std::size_t minCapacity, UInt64 cursorPos, OpenModeFlags openMode) |
| 131 | { |
| 132 | NazaraAssert(minCapacity >= cursorPos, "Cannot init stream with a smaller capacity than wanted cursor pos"); |
| 133 | |
| 134 | { |
| 135 | Nz::LockGuard lock(*s_availableBuffersMutex); |
| 136 | |
| 137 | FreeStream(); //< In case it wasn't released yet |
| 138 | |
| 139 | if (!s_availableBuffers.empty()) |
| 140 | { |
| 141 | m_buffer = std::move(s_availableBuffers.back().second); |
| 142 | s_availableBuffers.pop_back(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (!m_buffer) |
| 147 | m_buffer = std::make_unique<ByteArray>(); |
| 148 | |
| 149 | m_buffer->Resize(minCapacity); |
| 150 | |
| 151 | m_memoryStream.SetBuffer(m_buffer.get(), openMode); |
| 152 | m_memoryStream.SetCursorPos(cursorPos); |
| 153 | SetStream(&m_memoryStream); |
| 154 | } |
| 155 | |
| 156 | /*! |
| 157 | * \brief Initializes the NetPacket class |
nothing calls this directly
no test coverage detected