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