-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpacked_entity.h
212 lines (163 loc) · 4.89 KB
/
packed_entity.h
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//=============================================================================//
#if !defined( PACKED_ENTITY_H )
#define PACKED_ENTITY_H
#ifdef _WIN32
#pragma once
#endif
#include <const.h>
#include <basetypes.h>
#include <mempool.h>
#include <utlvector.h>
#include <tier0/dbg.h>
//#include "common.h"
// Matched with the memdbgoff at end of header
#include "memdbgon.h"
// This is extra spew to the files cltrace.txt + svtrace.txt
// #define DEBUG_NETWORKING 1
#if defined( DEBUG_NETWORKING )
#include "convar.h"
void SpewToFile( PRINTF_FORMAT_STRING char const* pFmt, ... );
extern ConVar sv_packettrace;
#define TRACE_PACKET( text ) if ( sv_packettrace.GetInt() ) { SpewToFile text ; };
#else
#define TRACE_PACKET( text )
#endif
enum
{
ENTITY_SENTINEL = 9999 // larger number than any real entity number
};
#define FLAG_IS_COMPRESSED (1<<31)
class CSendProxyRecipients;
class SendTable;
class RecvTable;
class ServerClass;
class ClientClass;
class IChangeFrameList;
// Replaces entity_state_t.
// This is what we send to clients.
class PackedEntity
{
public:
PackedEntity();
~PackedEntity();
void SetNumBits( int nBits );
int GetNumBits() const;
int GetNumBytes() const;
void SetCompressed();
bool IsCompressed() const;
// Access the data in the entity.
void* GetData();
void FreeData();
// Copy the data into the PackedEntity's data and make sure the # bytes allocated is
// an integer multiple of 4.
bool AllocAndCopyPadded( const void *pData, unsigned long size );
// These are like Get/Set, except SnagChangeFrameList clears out the
// PackedEntity's pointer since the usage model in sv_main is to keep
// the same CChangeFrameList in the most recent PackedEntity for the
// lifetime of an edict.
//
// When the PackedEntity is deleted, it deletes its current CChangeFrameList if it exists.
void SetChangeFrameList( IChangeFrameList *pList );
IChangeFrameList* GetChangeFrameList();
IChangeFrameList* SnagChangeFrameList();
// If this PackedEntity has a ChangeFrameList, then this calls through. If not, it returns all props
int GetPropsChangedAfterTick( int iTick, int *iOutProps, int nMaxOutProps );
// Access the recipients array.
const CSendProxyRecipients* GetRecipients() const;
int GetNumRecipients() const;
void SetRecipients( const CUtlMemory<CSendProxyRecipients> &recipients );
bool CompareRecipients( const CUtlMemory<CSendProxyRecipients> &recipients );
void SetSnapshotCreationTick( int nTick );
int GetSnapshotCreationTick() const;
void SetShouldCheckCreationTick( bool bState );
bool ShouldCheckCreationTick() const;
void SetServerAndClientClass( ServerClass *pServerClass, ClientClass *pClientClass );
public:
ServerClass *m_pServerClass; // Valid on the server
ClientClass *m_pClientClass; // Valid on the client
int m_nEntityIndex; // Entity index.
int m_ReferenceCount; // reference count;
private:
CUtlVector<CSendProxyRecipients> m_Recipients;
void *m_pData; // Packed data.
int m_nBits; // Number of bits used to encode.
IChangeFrameList *m_pChangeFrameList; // Only the most current
// This is the tick this PackedEntity was created on
unsigned int m_nSnapshotCreationTick : 31;
unsigned int m_nShouldCheckCreationTick : 1;
};
inline void PackedEntity::SetNumBits( int nBits )
{
Assert( !( nBits & 31 ) );
m_nBits = nBits;
}
inline void PackedEntity::SetCompressed()
{
m_nBits |= FLAG_IS_COMPRESSED;
}
inline bool PackedEntity::IsCompressed() const
{
return (m_nBits & FLAG_IS_COMPRESSED) != 0;
}
inline int PackedEntity::GetNumBits() const
{
Assert( !( m_nBits & 31 ) );
return m_nBits & ~(FLAG_IS_COMPRESSED);
}
inline int PackedEntity::GetNumBytes() const
{
return 0;
//return Bits2Bytes( m_nBits );
}
inline void* PackedEntity::GetData()
{
return m_pData;
}
inline void PackedEntity::FreeData()
{
if ( m_pData )
{
free(m_pData);
m_pData = NULL;
}
}
inline void PackedEntity::SetChangeFrameList( IChangeFrameList *pList )
{
Assert( !m_pChangeFrameList );
m_pChangeFrameList = pList;
}
inline IChangeFrameList* PackedEntity::GetChangeFrameList()
{
return m_pChangeFrameList;
}
inline IChangeFrameList* PackedEntity::SnagChangeFrameList()
{
IChangeFrameList *pRet = m_pChangeFrameList;
m_pChangeFrameList = NULL;
return pRet;
}
inline void PackedEntity::SetSnapshotCreationTick( int nTick )
{
m_nSnapshotCreationTick = (unsigned int)nTick;
}
inline int PackedEntity::GetSnapshotCreationTick() const
{
return (int)m_nSnapshotCreationTick;
}
inline void PackedEntity::SetShouldCheckCreationTick( bool bState )
{
m_nShouldCheckCreationTick = bState ? 1 : 0;
}
inline bool PackedEntity::ShouldCheckCreationTick() const
{
return m_nShouldCheckCreationTick == 1 ? true : false;
}
#include "memdbgoff.h"
#endif // PACKED_ENTITY_H