StringView::StringView(const StringView &str, uint32 begin, uint32 end) : _str(str.c_str()+begin) , _length(end-begin) { ARC_ASSERT(begin <= str.length(),"Invalid StringView begin."); ARC_ASSERT(end <= str.length(), "Invalid StringView end"); }
void AsyncProcessor<Input, Output>::Start() { ARC_ASSERT(!m_isRunning); ARC_ASSERT(m_processorFunction != nullptr); m_inputBuffer.Reset(); m_outputBuffer->Reset(); m_isRunning = true; m_workFuture = std::async(std::launch::async, m_processorFunction); }
T& get(uint32 index) { ARC_ASSERT(T::Value <= D::fields.size(), "field index out of bounds"); ARC_ASSERT(D::fields[T::Value].m_type == TypeInfo<T::Type>::dynamic, "wrong type"); ARC_ASSERT(index <= m_size, "array index out of bouds"); auto a = static_cast<T*>(m_data[T::Value]); return a[index]; }
AsyncProcessor<Input, Output>::AsyncProcessor(int minBatchSize /*= 20*/, int maxBatchSize /*= 100*/, boost::optional<std::chrono::milliseconds> batchTimeout /*= boost::none*/) : m_minBatchSize(minBatchSize), m_maxBatchSize(maxBatchSize), m_timeout(batchTimeout), m_isRunning(false), m_outputBuffer(nullptr) { ARC_ASSERT(minBatchSize <= maxBatchSize); ARC_ASSERT(minBatchSize > 0 && maxBatchSize > 0); }
template<typename T> inline void Slice<T>::trim_front(uint32 n) { ARC_ASSERT(n <= _size, "Trim value larger than buffer length"); _data += n; _size -= n; }
void push(lua_State *state, Value &value) { ARC_ASSERT(state == value.m_state, "value belongs to different lua state"); if (!value.valid()) lua_pushnil(state); // get value and push it onto stack lua_rawgeti(state, LUA_REGISTRYINDEX, value.m_ref); }
void Renderer_GL44::geometry_unmap_indices(GeometryID id) { ARC_ASSERT(m_geometry_indices.valid(id.value()), "Invalid GeometryID"); auto& mesh = m_geometry_data[id.value()]; auto target = gl::BufferType::Array; gl::bind_buffer(target, mesh.gl_id); gl::unmap_buffer(target); }
std::vector<unsigned char> InMemoryStream::GetBytes(unsigned int count) { ARC_ASSERT(count <= GetAvailableLength()); std::vector<unsigned char> result; result.resize(count); auto currentPos = m_data + m_bytesRead; std::copy(currentPos, currentPos + count, result.begin()); m_bytesRead += count; return result; }
UntypedBuffer Renderer_GL44::geometry_map_indices(GeometryID id) { ARC_ASSERT(m_geometry_indices.valid(id.value()), "Invalid GeometryID"); auto& mesh = m_geometry_data[id.value()]; auto target = gl::BufferType::Array; gl::bind_buffer(target, mesh.gl_id); void* ptr = gl::map_buffer_range(target, mesh.index_begin, mesh.index_size, gl::BufferAccess::Write | gl::BufferAccess::InvalidateRange); if (ptr == nullptr) return INVALID_UNTYPED_BUFFER; return{ ptr, mesh.index_size }; }
inline void AsyncProcessor<std::function<void()>, void>::Start() { ARC_ASSERT(!m_isRunning); m_processorFunction = [this]() { while (m_inputBuffer.ResultsPending() && !m_isStopping) { auto input = m_inputBuffer.GetNext(m_timeout); if (input) { (*input)(); } } }; m_inputBuffer.Reset(); m_isRunning = true; m_workFuture = std::async(std::launch::async, m_processorFunction); }
void Util::AsyncProcessor<Input, Output>::SetBatchProcessor(ProcessBatch func) { ARC_ASSERT(!m_isRunning); m_processorFunction = [this, func]() { while (m_inputBuffer.ResultsPending() && !m_isStopping) { auto input = m_inputBuffer.GetMultiple(m_minBatchSize, m_maxBatchSize, m_timeout); if (input.size() > 0) { auto output = func(input); m_outputBuffer->Append(std::move(output)); } } if (!m_inputBuffer.ResultsPending()) { m_outputBuffer->Complete(); } }; }
void Util::AsyncProcessor<Input, Output>::SetProcessor(ProcessSingle func) { ARC_ASSERT(!m_isRunning); m_processorFunction = [this, func]() { while (m_inputBuffer.ResultsPending() && !m_isStopping) { auto input = m_inputBuffer.GetNext(m_timeout); if (input) { auto output = func(*input); m_outputBuffer->Append(output); } } if (!m_inputBuffer.ResultsPending()) { m_outputBuffer->Complete(); } }; }
bool buffer_writer::write(const char * s) { if (_ptr == nullptr) return false; auto r = remaining(); auto cntr = snprintf( _ptr+_iter, r+1, "%s", s ); ARC_ASSERT(cntr >= 0, "snprintf error"); uint32 cnt = cntr < 0 ? 0 : cntr; if (cnt <= r) { _iter += cnt; return true; } else { _iter = _cap; return false; } }
GeometryID Renderer_GL44::geometry_create(GeometryBufferType buffer_type, uint32 index_count, uint32 vertex_count, GeometryConfigID geometry_config_id) { ARC_ASSERT(m_geometry_config_data.valid(geometry_config_id.value()), "Invalid GeometryConfigID"); auto& buffer = m_geom_buffer_data[(uint32)buffer_type]; auto& config = *m_geometry_config_data.data(geometry_config_id.value()); auto& vertex_layout = *config.layout; // check wheter the buffer has enough free memory uint32 vertex_stride = vertex_layout.stride(); uint32 aligned_begin = memory::util::forward_align(buffer.front, vertex_stride); uint32 vertex_size = vertex_count * vertex_stride; uint32 index_size = index_count * byte_size(config.index_type); uint32 block_end = aligned_begin + vertex_size + index_size; if (block_end > buffer.size) return INVALID_GEOMETRY_ID; // not enough memory uint32 index = m_geometry_indices.create(); auto& mesh = m_geometry_data[index]; mesh.buffer_type = buffer_type; mesh.vertex_begin = aligned_begin; mesh.vertex_begin_count = aligned_begin / vertex_layout.stride(); mesh.vertex_count = vertex_count; mesh.vertex_size = vertex_size; mesh.index_begin = aligned_begin + vertex_size; mesh.index_begin_count = mesh.index_begin / byte_size(config.index_type); mesh.index_count = index_count; mesh.index_size = index_size; mesh.block_begin = buffer.front; mesh.block_size = block_end - buffer.front; mesh.gl_id = buffer.gl_id; mesh.geometry_config_id = geometry_config_id; buffer.front = block_end; return GeometryID{ index }; }
bool buffer_writer::write(void* ptr) { if (_ptr == nullptr) return false; if (ptr == nullptr) return write("0x0",3); auto r = remaining(); auto cntr = snprintf( _ptr+_iter, r+1, "%p", ptr ); ARC_ASSERT(cntr >= 0, "snprintf error"); uint32 cnt = cntr < 0 ? 0 : cntr; if (cnt <= r) { _iter += cnt; return true; } else { _iter = _cap; return false; } }
void DummyAllocator::free(void *data) { ARC_ASSERT(data == nullptr, "trying to free memory with dummy allocator"); }
void InMemoryStream::Advance(unsigned int count) { ARC_ASSERT(count <= GetAvailableLength()); m_bytesRead += count; }
void* DummyAllocator::allocate(uint64 size, uint32 align) { ARC_ASSERT(size == 0, "trying to allocate memory with dummy allocator"); return nullptr; }
void InMemoryStream::Rewind(unsigned int count) { ARC_ASSERT(m_bytesRead >= count); m_bytesRead -= count; }
bool Value::is_error() { ARC_ASSERT(m_error ? valid() : true, "Error value should always be valid"); return m_error; }
void InMemoryStream::EnsureBytesAvailable(unsigned int count /* = 0 */) { ARC_ASSERT(count <= GetAvailableLength()); UNREFERENCED_PARAMETER(count); // needed for release builds // nothing to do here other than assert, There is no data source to pull extra bytes from }
State::State() { m_state = luaL_newstate(); ARC_ASSERT(m_state != nullptr, "could not create lua state"); }
GeometryBufferType Renderer_GL44::geometry_get_buffer(GeometryID id) { ARC_ASSERT(m_geometry_indices.valid(id.value()), "Invalid GeometryID"); auto& mesh = m_geometry_data[id.value()]; return mesh.buffer_type; }
GeometryConfigID Renderer_GL44::geometry_get_config(GeometryID id) { ARC_ASSERT(m_geometry_indices.valid(id.value()), "Invalid GeometryID"); auto& mesh = m_geometry_data[id.value()]; return mesh.geometry_config_id; }
uint32 Renderer_GL44::geometry_get_vertex_count(GeometryID id) { ARC_ASSERT(m_geometry_indices.valid(id.value()), "Invalid GeometryID"); auto& mesh = m_geometry_data[id.value()]; return mesh.vertex_count; }
void Util::AsyncProcessor<Input, Output>::Connect(Util::InputBuffer<Output>* outputBuffer) { ARC_ASSERT(outputBuffer != nullptr); m_outputBuffer = outputBuffer; }
long long InMemoryStream::GetBytesRemainaingLength() { ARC_ASSERT(m_length - m_bytesRead > 0); return m_length - m_bytesRead; }