1 | #include "Flatline.h"
|
---|
2 | #include "../Oni_Symbols.h"
|
---|
3 | #include <assert.h>
|
---|
4 | #include "Flatline_Packet.h"
|
---|
5 |
|
---|
6 | #define FLAG_AND_INCREMENT( FLAG ) PD->UpdateFlags |= (1 << FLAG ); DataPointer += FLpData_PartSize( FLAG );
|
---|
7 |
|
---|
8 | void FLsPacketBuild( uint8_t p, PlayerData* PD, bool UpdateAll )
|
---|
9 | {
|
---|
10 | Character* Player = PlayerList[p]->Chr;
|
---|
11 | ActiveCharacter* APlayer = ONrGetActiveCharacter(Player);
|
---|
12 | player_info * PI = PlayerList[p];
|
---|
13 | uint8_t * DataPointer = PD->data;
|
---|
14 | PD->ID = p;
|
---|
15 |
|
---|
16 | //if ( data has changed )
|
---|
17 | //{
|
---|
18 | // copy it to the buffer
|
---|
19 | // copy it to the player info
|
---|
20 | // set the changed flag
|
---|
21 | // increment the buffer pointer
|
---|
22 | //}
|
---|
23 |
|
---|
24 | /*
|
---|
25 | //Could probably send this every frame, but afk players can save a few bytes, eh?
|
---|
26 | if( PI->Input.Actions1 != PI->InputFromClient.Actions1 ||
|
---|
27 | PI->Input.Actions2 != PI->InputFromClient.Actions2 ||
|
---|
28 | PI->Input.MouseDeltaX != PI->InputFromClient.MouseDeltaX ||
|
---|
29 | PI->Input.MouseDeltaY != PI->InputFromClient.MouseDeltaY )
|
---|
30 | {*/
|
---|
31 |
|
---|
32 | //Better in case of dropped packets to send input every frame
|
---|
33 | if(1)
|
---|
34 | {
|
---|
35 | memcpy( DataPointer, &PI->InputFromClient, sizeof(PlayerInput));
|
---|
36 | PI->Input = PI->InputFromClient;
|
---|
37 |
|
---|
38 | FLAG_AND_INCREMENT( PFlag_Input );
|
---|
39 | }
|
---|
40 |
|
---|
41 | if( PI->Facings.Facing != Player->Facing ||
|
---|
42 | PI->Facings.DesiredFacing != Player->DesiredFacing || UpdateAll )
|
---|
43 | {
|
---|
44 | PlayerFacing* ptr = (void*)DataPointer;
|
---|
45 | ptr->Facing = Player->Facing;
|
---|
46 | ptr->DesiredFacing = Player->DesiredFacing;
|
---|
47 |
|
---|
48 | PI->Facings = *ptr;
|
---|
49 |
|
---|
50 | FLAG_AND_INCREMENT( PFlag_Facing );
|
---|
51 | }
|
---|
52 |
|
---|
53 | if(PI->Health.Health != Player->Health ||
|
---|
54 | PI->Health.MaxHealth != Player->MaxHealth || UpdateAll )
|
---|
55 | {
|
---|
56 | PlayerHealth* ptr = (void*)DataPointer;
|
---|
57 | ptr->Health = Player->Health;
|
---|
58 | ptr->MaxHealth = Player->MaxHealth;
|
---|
59 |
|
---|
60 | PI->Health = *ptr;
|
---|
61 |
|
---|
62 | FLAG_AND_INCREMENT( PFlag_Health );
|
---|
63 | }
|
---|
64 |
|
---|
65 | //Score
|
---|
66 | //skipping for now
|
---|
67 |
|
---|
68 | //Frame and ping can be sent every frame, i guess. Improve this later,
|
---|
69 | if( 1 )
|
---|
70 | {
|
---|
71 | PlayerFP* ptr = (void*)DataPointer;
|
---|
72 | if(APlayer)
|
---|
73 | {
|
---|
74 | ptr->Frame = APlayer->Frame;
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | ptr->Frame = -1;
|
---|
79 | }
|
---|
80 | ptr->Ping = PI->Ping;
|
---|
81 |
|
---|
82 | PI->Frame = ptr->Frame;
|
---|
83 |
|
---|
84 | FLAG_AND_INCREMENT( PFlag_FramePing );
|
---|
85 | }
|
---|
86 |
|
---|
87 | //Skipping inventory because we dont need it right now
|
---|
88 | if( 0 )
|
---|
89 | {
|
---|
90 | //Do inventory
|
---|
91 | }
|
---|
92 |
|
---|
93 | if( PI->Class != Player->ONCC || UpdateAll )
|
---|
94 | {
|
---|
95 | snprintf( DataPointer, 32, "%s", TMrInstance_GetInstanceName( Player->ONCC ) );
|
---|
96 | snprintf( PI->ClassString, 32, "%s", DataPointer );
|
---|
97 | PI->Class = Player->ONCC;
|
---|
98 |
|
---|
99 | FLAG_AND_INCREMENT( PFlag_Class );
|
---|
100 | }
|
---|
101 |
|
---|
102 | if(APlayer)
|
---|
103 | {
|
---|
104 | if( (APlayer->PhyContext) && (memcmp(&PI->Position, &APlayer->PhyContext->Position, sizeof(Vector3)) || UpdateAll ))
|
---|
105 | {
|
---|
106 | Vector3* ptr = (Vector3*)DataPointer;
|
---|
107 | *ptr = PI->Position = APlayer->PhyContext->Position;
|
---|
108 |
|
---|
109 | FLAG_AND_INCREMENT( PFlag_Position );
|
---|
110 | }
|
---|
111 |
|
---|
112 | if(APlayer->Animation != PI->Animation || !APlayer->Frame || UpdateAll )
|
---|
113 | {
|
---|
114 | snprintf( DataPointer, 32, "%s", TMrInstance_GetInstanceName( APlayer->Animation ) );
|
---|
115 | snprintf( PI->AnimationString, 32, "%s", DataPointer );
|
---|
116 | PI->Animation = APlayer->Animation;
|
---|
117 |
|
---|
118 |
|
---|
119 | FLAG_AND_INCREMENT( PFlag_Animation );
|
---|
120 | }
|
---|
121 |
|
---|
122 | if(APlayer->targetThrow)
|
---|
123 | {
|
---|
124 | if(!PI->HasAppliedThrow || UpdateAll )
|
---|
125 | {
|
---|
126 | PlayerThrowData* ptr = (void*)DataPointer;
|
---|
127 | ptr->throwing = Players[APlayer->throwing].list_slot;
|
---|
128 | memcpy(ptr->throwName, TMrInstance_GetInstanceName(APlayer->targetThrow), 31);
|
---|
129 | ptr->throwFrame = ONrGetActiveCharacter(APlayer->targetThrow)->Frame;
|
---|
130 |
|
---|
131 | PI->ThrowData = *ptr;
|
---|
132 |
|
---|
133 | PI->HasAppliedThrow = 1;
|
---|
134 |
|
---|
135 | FLAG_AND_INCREMENT( PFlag_Throws );
|
---|
136 | }
|
---|
137 | }
|
---|
138 | else
|
---|
139 | {
|
---|
140 | PI->HasAppliedThrow = 0;
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | PD->Size = (uint32_t)DataPointer - (uint32_t)PD;
|
---|
145 |
|
---|
146 | PI->UpdateFlags = PD->UpdateFlags;
|
---|
147 |
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 | void FLsSendPlayerData()
|
---|
153 | {
|
---|
154 | PlayerData BuildData[32] = {0};
|
---|
155 | uint8_t p = 0;
|
---|
156 | uint32_t PacketSize = 0;
|
---|
157 | flatline_packet OutputPacket = {0};
|
---|
158 | uint8_t* OutputPointer = OutputPacket.data;
|
---|
159 | //Most of the time we won't even hit this. Could probably be bumped up a few hundred bytes
|
---|
160 | const uint32_t max_packet_size = 1000;
|
---|
161 |
|
---|
162 | //Prepare buffers
|
---|
163 | OutputPacket.id = PK_PLAYER_DATA;
|
---|
164 | memset( BuildData, 0, sizeof(PlayerData) * 32 );
|
---|
165 |
|
---|
166 | //Build data
|
---|
167 | for(p = 0; p < MAX_PLAYERS; p++)
|
---|
168 | {
|
---|
169 | if(PlayerList[p] && PlayerList[p]->Chr)
|
---|
170 | {
|
---|
171 | FLsPacketBuild(p, &BuildData[p], 0);
|
---|
172 |
|
---|
173 | assert( BuildData[p].Size < 255 );
|
---|
174 |
|
---|
175 | if( BuildData[p].Size > 0 )
|
---|
176 | {
|
---|
177 |
|
---|
178 | //If we hit maximum size, send the packet and reset the buffer for a new one
|
---|
179 | if( BuildData[p].Size + PacketSize > max_packet_size )
|
---|
180 | {
|
---|
181 | UDPServer_SendToAll(&OutputPacket, PacketSize + FLATLINE_HEADER);
|
---|
182 |
|
---|
183 | memset( OutputPacket.data, 0, PacketSize );
|
---|
184 | OutputPointer = OutputPacket.data;
|
---|
185 | PacketSize = 0;
|
---|
186 | }
|
---|
187 |
|
---|
188 | //add to the packet
|
---|
189 | memcpy( OutputPointer, &BuildData[p], BuildData[p].Size );
|
---|
190 |
|
---|
191 | OutputPointer += BuildData[p].Size;
|
---|
192 | PacketSize += BuildData[p].Size;
|
---|
193 | }
|
---|
194 | }
|
---|
195 | }
|
---|
196 | //Send data
|
---|
197 | if( PacketSize > 0 )
|
---|
198 | {
|
---|
199 | UDPServer_SendToAll(&OutputPacket, PacketSize + FLATLINE_HEADER);
|
---|
200 | }
|
---|
201 | }
|
---|