summaryrefslogtreecommitdiff
path: root/engine/dt_send_eng.h
blob: 45f4eecb57857195f13d0cdec9ae6c99ef329a82 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef DATATABLE_SEND_ENG_H
#define DATATABLE_SEND_ENG_H
#ifdef _WIN32
#pragma once
#endif


#include "dt_send.h"
#include "bitbuf.h"
#include "utlmemory.h"

typedef unsigned int CRC32_t;

class CStandardSendProxies;


#define MAX_DELTABITS_SIZE 2048

// ------------------------------------------------------------------------ //
// SendTable functions.
// ------------------------------------------------------------------------ //

// Precalculate data that enables the SendTable to be used to encode data.
bool		SendTable_Init( SendTable **pTables, int nTables );
void		SendTable_Term();
CRC32_t		SendTable_GetCRC();
int			SendTable_GetNum();
SendTable	*SendTabe_GetTable(int index);


// Return the number of unique properties in the table.
int	SendTable_GetNumFlatProps( SendTable *pTable );

// compares properties and writes delta properties
int SendTable_WriteAllDeltaProps(
	const SendTable *pTable,					
	const void *pFromData,
	const int	nFromDataBits,
	const void *pToData,
	const int nToDataBits,
	const int nObjectID,
	bf_write *pBufOut );

// Write the properties listed in pCheckProps and nCheckProps.
void SendTable_WritePropList(
	const SendTable *pTable,
	const void *pState,
	const int nBits,
	bf_write *pOut,
	const int objectID,
	const int *pCheckProps,
	const int nCheckProps
	);

//
// Writes the property indices that must be written to move from pFromState to pToState into pDeltaProps.
// Returns the number of indices written to pDeltaProps.
//
int	SendTable_CalcDelta(
	const SendTable *pTable,
	
	const void *pFromState,
	const int nFromBits,

	const void *pToState,
	const int nToBits,

	int *pDeltaProps,
	int nMaxDeltaProps,

	const int objectID );


// This function takes the list of property indices in startProps and the values from
// SendProxies in pProxyResults, and fills in a new array in outProps with the properties
// that the proxies want to allow for iClient's client.
//
// If pOldStateProxies is non-null, this function adds new properties into the output list
// if a proxy has turned on from the previous state.
int SendTable_CullPropsFromProxies( 
	const SendTable *pTable,
	
	const int *pStartProps,
	int nStartProps,

	const int iClient,
	
	const CSendProxyRecipients *pOldStateProxies,
	const int nOldStateProxies, 
	
	const CSendProxyRecipients *pNewStateProxies,
	const int nNewStateProxies,
	
	int *pOutProps,
	int nMaxOutProps
	);


// Encode the properties that are referenced in the delta bits.
// If pDeltaBits is NULL, then all the properties are encoded.
bool SendTable_Encode(
	const SendTable *pTable,
	const void *pStruct, 
	bf_write *pOut, 
	int objectID = -1,
	CUtlMemory<CSendProxyRecipients> *pRecipients = NULL,	// If non-null, this is an array of CSendProxyRecipients.
															// The array must have room for pTable->GetNumDataTableProxies().
	bool bNonZeroOnly = false								// If this is true, then it will write all properties that have
															// nonzero values.
	);


// In order to receive a table, you must send it from the server and receive its info
// on the client so the client knows how to unpack it.
bool SendTable_WriteInfos( SendTable *pTable, bf_write *pBuf );

// do all kinds of checks on a packed entity bitbuffer
bool SendTable_CheckIntegrity( SendTable *pTable, const void *pData, const int nDataBits );


#endif // DATATABLE_SEND_ENG_H