-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add realistic broadcasting (throttle)
- Loading branch information
1 parent
6c5c313
commit 8fd5e7e
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package udp | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
) | ||
|
||
type Header struct { | ||
PacketFormat uint16 // 2021 | ||
GameMajorVersion uint8 // Game major version - "X.00" | ||
GameMinorVersion uint8 // Game minor version - "1.XX" | ||
PacketVersion uint8 // Version of this packet type, all start from 1 | ||
PacketID uint8 // Identifier for the packet type, see below | ||
SessionUID uint64 // Unique identifier for the session | ||
SessionTime float32 // Session timestamp | ||
FrameIdentifier uint32 // Identifier for the frame the data was retrieved on | ||
PlayerCarIndex uint8 // Index of player's car in the array | ||
SecondaryPlayerCarIndex uint8 // Index of secondary player's car in the array (split screen) | ||
} | ||
|
||
func (h *Header) Read(buf []byte) error { | ||
reader := bytes.NewReader(buf) | ||
if err := binary.Read(reader, binary.LittleEndian, h); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (h *Header) Second() int32 { | ||
return int32(h.SessionTime) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters