+void EntityFrame_CL_ReadFrame(void);
+// (client) returns the frame number of the most recent frame recieved
+int EntityFrame_MostRecentlyRecievedFrameNum(entityframe_database_t *d);
+
+typedef struct entity_database4_commit_s
+{
+ // frame number this commit represents
+ int framenum;
+ // number of entities in entity[] array
+ int numentities;
+ // maximum number of entities in entity[] array (dynamic resizing)
+ int maxentities;
+ entity_state_t *entity;
+}
+entity_database4_commit_t;
+
+typedef struct entity_database4_s
+{
+ // what mempool to use for allocations
+ mempool_t *mempool;
+ // reference frame
+ int referenceframenum;
+ // reference entities array is resized according to demand
+ int maxreferenceentities;
+ // array of states for entities, these are indexable by their entity number (yes there are gaps)
+ entity_state_t *referenceentity;
+ // commits waiting to be applied to the reference database when confirmed
+ // (commit[i]->numentities == 0 means it is empty)
+ entity_database4_commit_t commit[MAX_ENTITY_HISTORY];
+ // (server only) the current commit being worked on
+ entity_database4_commit_t *currentcommit;
+ // (server only) if a commit won't fit entirely, continue where it left
+ // off next frame
+ int currententitynumber;
+ // (server only)
+ int latestframenumber;
+}
+entityframe4_database_t;
+
+// should-be-private functions that aren't
+entity_state_t *EntityFrame4_GetReferenceEntity(entityframe4_database_t *d, int number);
+void EntityFrame4_AddCommitEntity(entityframe4_database_t *d, const entity_state_t *s);
+
+// allocate a database
+entityframe4_database_t *EntityFrame4_AllocDatabase(mempool_t *pool);
+// free a database
+void EntityFrame4_FreeDatabase(entityframe4_database_t *d);
+// reset a database (resets compression but does not reallocate anything)
+void EntityFrame4_ResetDatabase(entityframe4_database_t *d);
+// updates database to account for a frame-received acknowledgment
+int EntityFrame4_AckFrame(entityframe4_database_t *d, int framenum, int servermode);
+// writes a frame to the network stream
+void EntityFrame4_WriteFrame(sizebuf_t *msg, entityframe4_database_t *d, int numstates, const entity_state_t *states);
+// reads a frame from the network stream
+void EntityFrame4_CL_ReadFrame(void);
+
+// reset all entity fields (typically used if status changed)
+#define E5_FULLUPDATE (1<<0)
+// E5_ORIGIN32=0: short[3] = s->origin[0] * 8, s->origin[1] * 8, s->origin[2] * 8
+// E5_ORIGIN32=1: float[3] = s->origin[0], s->origin[1], s->origin[2]
+#define E5_ORIGIN (1<<1)
+// E5_ANGLES16=0: byte[3] = s->angle[0] * 256 / 360, s->angle[1] * 256 / 360, s->angle[2] * 256 / 360
+// E5_ANGLES16=1: short[3] = s->angle[0] * 65536 / 360, s->angle[1] * 65536 / 360, s->angle[2] * 65536 / 360
+#define E5_ANGLES (1<<2)
+// E5_MODEL16=0: byte = s->modelindex
+// E5_MODEL16=1: short = s->modelindex
+#define E5_MODEL (1<<3)
+// E5_FRAME16=0: byte = s->frame
+// E5_FRAME16=1: short = s->frame
+#define E5_FRAME (1<<4)
+// byte = s->skin
+#define E5_SKIN (1<<5)
+// E5_EFFECTS16=0 && E5_EFFECTS32=0: byte = s->effects
+// E5_EFFECTS16=1 && E5_EFFECTS32=0: short = s->effects
+// E5_EFFECTS16=0 && E5_EFFECTS32=1: int = s->effects
+// E5_EFFECTS16=1 && E5_EFFECTS32=1: int = s->effects
+#define E5_EFFECTS (1<<6)
+// bits >= (1<<8)
+#define E5_EXTEND1 (1<<7)
+
+// byte = s->renderflags
+#define E5_FLAGS (1<<8)
+// byte = bound(0, s->alpha * 255, 255)
+#define E5_ALPHA (1<<9)
+// byte = bound(0, s->scale * 16, 255)
+#define E5_SCALE (1<<10)
+// flag
+#define E5_ORIGIN32 (1<<11)
+// flag
+#define E5_ANGLES16 (1<<12)
+// flag
+#define E5_MODEL16 (1<<13)
+// byte = s->colormap
+#define E5_COLORMAP (1<<14)
+// bits >= (1<<16)
+#define E5_EXTEND2 (1<<15)
+
+// short = s->tagentity
+// byte = s->tagindex
+#define E5_ATTACHMENT (1<<16)
+// short[4] = s->light[0], s->light[1], s->light[2], s->light[3]
+// byte = s->lightstyle
+// byte = s->lightpflags
+#define E5_LIGHT (1<<17)
+// byte = s->glowsize
+// byte = s->glowcolor
+#define E5_GLOW (1<<18)
+// short = s->effects
+#define E5_EFFECTS16 (1<<19)
+// int = s->effects
+#define E5_EFFECTS32 (1<<20)
+// flag
+#define E5_FRAME16 (1<<21)
+// byte[3] = s->colormod[0], s->colormod[1], s->colormod[2]
+#define E5_COLORMOD (1<<22)
+// bits >= (1<<24)
+#define E5_EXTEND3 (1<<23)
+
+// unused
+#define E5_UNUSED24 (1<<24)
+// unused
+#define E5_UNUSED25 (1<<25)
+// unused
+#define E5_UNUSED26 (1<<26)
+// unused
+#define E5_UNUSED27 (1<<27)
+// unused
+#define E5_UNUSED28 (1<<28)
+// unused
+#define E5_UNUSED29 (1<<29)
+// unused
+#define E5_UNUSED30 (1<<30)
+// bits2 > 0
+#define E5_EXTEND4 (1<<31)
+
+#define ENTITYFRAME5_MAXPACKETLOGS 64
+#define ENTITYFRAME5_MAXSTATES 1024
+
+typedef struct entityframe5_changestate_s
+{
+ unsigned int number;
+ unsigned int bits;
+}
+entityframe5_changestate_t;
+
+typedef struct entityframe5_packetlog_s
+{
+ int packetnumber;
+ int numstates;
+ entityframe5_changestate_t states[ENTITYFRAME5_MAXSTATES];
+ qbyte statsdeltabits[(MAX_CL_STATS+7)/8];
+}
+entityframe5_packetlog_t;
+
+typedef struct entityframe5_database_s
+{
+ // number of the latest message sent to client
+ int latestframenum;
+ // updated by WriteFrame for internal use
+ int viewentnum;
+
+ // logs of all recently sent messages (between acked and latest)
+ entityframe5_packetlog_t packetlog[ENTITYFRAME5_MAXPACKETLOGS];
+
+ // this goes up as needed and causes all the arrays to be reallocated
+ int maxedicts;
+
+ // which properties of each entity have changed since last send
+ int *deltabits; // [maxedicts]
+ // priorities of entities (updated whenever deltabits change)
+ // (derived from deltabits)
+ qbyte *priorities; // [maxedicts]
+ // last frame this entity was sent on, for prioritzation
+ int *updateframenum; // [maxedicts]
+
+ // database of current status of all entities
+ entity_state_t *states; // [maxedicts]
+ // which entities are currently active
+ // (duplicate of the active bit of every state in states[])
+ // (derived from states)
+ qbyte *visiblebits; // [(maxedicts+7)/8]
+
+ // delta compression of stats
+ qbyte statsdeltabits[(MAX_CL_STATS+7)/8];
+ int stats[MAX_CL_STATS];
+
+ // old notes
+
+ // this is used to decide which changestates to set each frame
+ //int numvisiblestates;
+ //entity_state_t visiblestates[MAX_EDICTS];
+
+ // sorted changing states that need to be sent to the client
+ // kept sorted in lowest to highest priority order, because this allows
+ // the numchangestates to simply be decremented whenever an state is sent,
+ // rather than a memmove to remove them from the start.
+ //int numchangestates;
+ //entityframe5_changestate_t changestates[MAX_EDICTS];
+}
+entityframe5_database_t;
+
+entityframe5_database_t *EntityFrame5_AllocDatabase(mempool_t *pool);
+void EntityFrame5_FreeDatabase(entityframe5_database_t *d);
+void EntityFrame5_ResetDatabase(entityframe5_database_t *d);
+void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbits, sizebuf_t *msg);
+int EntityState5_DeltaBitsForState(entity_state_t *o, entity_state_t *n);
+void EntityFrame5_CL_ReadFrame(void);
+void EntityFrame5_LostFrame(entityframe5_database_t *d, int framenum);
+void EntityFrame5_AckFrame(entityframe5_database_t *d, int framenum);
+void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int numstates, const entity_state_t *states, int viewentnum, int *stats, int movesequence);
+
+extern cvar_t developer_networkentities;
+
+#endif
+