Quake II RTX doxygen  1.0 dev
fifo.c File Reference
#include "shared/shared.h"
#include "common/fifo.h"
#include "common/msg.h"

Go to the source code of this file.

Functions

size_t FIFO_Read (fifo_t *fifo, void *buffer, size_t len)
 
size_t FIFO_Write (fifo_t *fifo, const void *buffer, size_t len)
 
qboolean FIFO_ReadMessage (fifo_t *fifo, size_t msglen)
 

Function Documentation

◆ FIFO_Read()

size_t FIFO_Read ( fifo_t *  fifo,
void buffer,
size_t  len 
)

Definition at line 23 of file fifo.c.

24 {
25  size_t wrapped, head = fifo->ay - fifo->ax;
26 
27  if (head > len) {
28  if (buffer) {
29  memcpy(buffer, fifo->data + fifo->ax, len);
30  fifo->ax += len;
31  }
32  return len;
33  }
34 
35  wrapped = len - head;
36  if (wrapped > fifo->bs) {
37  wrapped = fifo->bs;
38  }
39  if (buffer) {
40  memcpy(buffer, fifo->data + fifo->ax, head);
41  memcpy((byte *)buffer + head, fifo->data, wrapped);
42  fifo->ax = wrapped;
43  fifo->ay = fifo->bs;
44  fifo->bs = 0;
45  }
46 
47  return head + wrapped;
48 }

Referenced by gtv_read_frame().

◆ FIFO_ReadMessage()

qboolean FIFO_ReadMessage ( fifo_t *  fifo,
size_t  msglen 
)

Definition at line 89 of file fifo.c.

90 {
91  size_t len;
92  byte *data;
93 
94  data = FIFO_Peek(fifo, &len);
95  if (len < msglen) {
96  // read in two chunks into message buffer
97  if (!FIFO_TryRead(fifo, msg_read_buffer, msglen)) {
98  return qfalse; // not yet available
99  }
101  } else {
102  // read in a single block without copying any memory
103  SZ_Init(&msg_read, data, msglen);
104  FIFO_Decommit(fifo, msglen);
105  }
106 
107  msg_read.cursize = msglen;
108  return qtrue;
109 }

Referenced by AC_ParseMessage(), gtv_read_frame(), and parse_message().

◆ FIFO_Write()

size_t FIFO_Write ( fifo_t *  fifo,
const void buffer,
size_t  len 
)

Definition at line 50 of file fifo.c.

51 {
52  size_t tail, wrapped, remaining;
53 
54  if (fifo->bs) {
55  remaining = fifo->ax - fifo->bs;
56  if (len > remaining) {
57  len = remaining;
58  }
59  if (buffer) {
60  memcpy(fifo->data + fifo->bs, buffer, len);
61  fifo->bs += len;
62  }
63  return len;
64  }
65 
66  tail = fifo->size - fifo->ay;
67  if (tail > len) {
68  if (buffer) {
69  memcpy(fifo->data + fifo->ay, buffer, len);
70  fifo->ay += len;
71  }
72  return len;
73  }
74 
75  wrapped = len - tail;
76  if (wrapped > fifo->ax) {
77  wrapped = fifo->ax;
78  }
79  if (buffer) {
80  memcpy(fifo->data + fifo->ay, buffer, tail);
81  memcpy(fifo->data, (byte *)buffer + tail, wrapped);
82  fifo->ay = fifo->size;
83  fifo->bs = wrapped;
84  }
85 
86  return tail + wrapped;
87 }

Referenced by AC_Flush(), parse_stream_data(), and write_stream().

msg_read
sizebuf_t msg_read
Definition: msg.c:37
msg_read_buffer
byte msg_read_buffer[MAX_MSGLEN]
Definition: msg.c:38
SZ_Init
void SZ_Init(sizebuf_t *buf, void *data, size_t size)
Definition: sizebuf.c:31
head
unsigned head
Definition: screen.c:529