mirror of https://github.com/encounter/SDL.git
Added SDL_PeekIntoDataQueue().
This commit is contained in:
parent
d90fce3c9e
commit
28149e11c8
|
@ -225,6 +225,31 @@ SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
|
||||||
|
{
|
||||||
|
size_t len = _len;
|
||||||
|
Uint8 *buf = (Uint8 *) _buf;
|
||||||
|
Uint8 *ptr = buf;
|
||||||
|
SDL_DataQueuePacket *packet;
|
||||||
|
|
||||||
|
if (!queue) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (packet = queue->head; len && packet; packet = packet->next) {
|
||||||
|
const size_t avail = packet->datalen - packet->startpos;
|
||||||
|
const size_t cpy = SDL_min(len, avail);
|
||||||
|
SDL_assert(queue->queued_bytes >= avail);
|
||||||
|
|
||||||
|
SDL_memcpy(ptr, packet->data + packet->startpos, cpy);
|
||||||
|
ptr += cpy;
|
||||||
|
len -= cpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (size_t) (ptr - buf);
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
|
SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ void SDL_FreeDataQueue(SDL_DataQueue *queue);
|
||||||
void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack);
|
void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack);
|
||||||
int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *data, const size_t len);
|
int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *data, const size_t len);
|
||||||
size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *buf, const size_t len);
|
size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *buf, const size_t len);
|
||||||
|
size_t SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *buf, const size_t len);
|
||||||
size_t SDL_CountDataQueue(SDL_DataQueue *queue);
|
size_t SDL_CountDataQueue(SDL_DataQueue *queue);
|
||||||
|
|
||||||
/* this sets a section of the data queue aside (possibly allocating memory for it)
|
/* this sets a section of the data queue aside (possibly allocating memory for it)
|
||||||
|
|
Loading…
Reference in New Issue