-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak(onesync): refine net time sync code
The goal of this commit is to improve the readability of `rage::netTimeSync` related code. Additionally, it aims to improve the maintainability of `CloneExperiments.cpp` by logically splitting certain parts of the file into appropriate chunks. The code refine isn't intended to be a full fledged refactor but rather a first step towards facilitating future refactoring efforts.
- Loading branch information
Showing
5 changed files
with
468 additions
and
531 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,74 @@ | ||
#pragma once | ||
|
||
struct TrustAddressData | ||
{ | ||
uint32_t m_addr; | ||
uint16_t m_port; | ||
}; | ||
|
||
struct TrustAddress1604 | ||
{ | ||
TrustAddressData m_addr1; | ||
TrustAddressData m_addr2; | ||
}; | ||
|
||
struct TrustAddress2060 | ||
{ | ||
TrustAddressData m_addr1; | ||
TrustAddressData m_addr2; | ||
TrustAddressData m_addr3; | ||
}; | ||
|
||
struct TrustAddress2372 | ||
{ | ||
uint32_t m_addr; | ||
}; | ||
|
||
template<int Build> | ||
using TrustAddress = std::conditional_t<(Build >= 2372), TrustAddress2372, std::conditional_t<(Build >= 2060), TrustAddress2060, TrustAddress1604>>; | ||
|
||
namespace rage | ||
{ | ||
class netConnectionManager; | ||
|
||
template<int Build> | ||
class netTimeSync | ||
{ | ||
public: | ||
virtual ~netTimeSync() = 0; | ||
|
||
void Update(); | ||
void HandleTimeSync(net::Buffer& buffer); | ||
bool IsInitialized(); | ||
void SetConnectionManager(netConnectionManager* mgr); | ||
|
||
private: | ||
netConnectionManager* m_connectionMgr; // +8 (1604) | ||
TrustAddress<Build> m_trustAddr; // +16 | ||
uint32_t m_sessionKey; // +32 | ||
int32_t m_timeDelta; // +36 | ||
struct | ||
{ | ||
void* self; | ||
void* cb; | ||
} m_messageDelegate; // +40 | ||
char m_pad_56[32]; | ||
uint32_t m_nextSync; // +88 | ||
uint32_t m_configTimeBetweenSyncs; // +92 | ||
uint32_t m_configMaxBackoff; // +96, usually 60000 | ||
uint32_t m_effectiveTimeBetweenSyncs; // +100 | ||
uint32_t m_lastRtt; // +104 | ||
uint32_t m_retryCount; // +108 | ||
uint32_t m_requestSequence; // +112 | ||
uint32_t m_replySequence; // +116 | ||
uint32_t m_flags; // +120 | ||
uint32_t m_packetFlags; // +124 | ||
uint32_t m_lastTime; // +128, used to prevent time from going backwards | ||
uint8_t m_applyFlags; // +132 | ||
uint8_t m_disabled; // +133 | ||
}; | ||
} | ||
|
||
static_assert(sizeof(rage::netTimeSync<1604>) == 136); | ||
static_assert(sizeof(rage::netTimeSync<2060>) == 144); | ||
static_assert(sizeof(rage::netTimeSync<2372>) == 128); |
Oops, something went wrong.