discord-rpc: Formatting

This commit is contained in:
Jonas Kvinge
2025-04-11 22:50:14 +02:00
parent aab9889174
commit f9e4f9a09a
14 changed files with 95 additions and 113 deletions

View File

@@ -18,22 +18,15 @@ struct Backoff {
double rand01() { return randDistribution(randGenerator); } double rand01() { return randDistribution(randGenerator); }
Backoff(int64_t min, int64_t max) Backoff(int64_t min, int64_t max)
: minAmount(min) : minAmount(min), maxAmount(max), current(min), fails(0), randGenerator(static_cast<uint64_t>(time(0))) {
, maxAmount(max)
, current(min)
, fails(0)
, randGenerator(static_cast<uint64_t>(time(0)))
{
} }
void reset() void reset() {
{
fails = 0; fails = 0;
current = minAmount; current = minAmount;
} }
int64_t nextDelay() int64_t nextDelay() {
{
++fails; ++fails;
int64_t delay = static_cast<int64_t>(static_cast<double>(current) * 2.0 * rand01()); int64_t delay = static_cast<int64_t>(static_cast<double>(current) * 2.0 * rand01());
current = std::min(current + delay, maxAmount); current = std::min(current + delay, maxAmount);

View File

@@ -119,4 +119,3 @@ bool BaseConnection::Read(void *data, size_t length) {
} }
} // namespace discord_rpc } // namespace discord_rpc

View File

@@ -123,4 +123,3 @@ bool BaseConnection::Read(void *data, size_t length) {
} }
} // namespace discord_rpc } // namespace discord_rpc

View File

@@ -101,4 +101,3 @@ extern "C" void Discord_RegisterSteamGame(const char *applicationId,
sprintf(command, "xdg-open steam://rungameid/%s", steamId); sprintf(command, "xdg-open steam://rungameid/%s", steamId);
Discord_Register(applicationId, command); Discord_Register(applicationId, command);
} }

View File

@@ -180,4 +180,3 @@ extern "C" void Discord_RegisterSteamGame(const char *applicationId,
Discord_RegisterW(appId, command); Discord_RegisterW(appId, command);
} }

View File

@@ -346,8 +346,7 @@ extern "C" void Discord_Shutdown(void) {
extern "C" void Discord_UpdatePresence(const DiscordRichPresence *presence) { extern "C" void Discord_UpdatePresence(const DiscordRichPresence *presence) {
{ {
std::lock_guard<std::mutex> guard(PresenceMutex); std::lock_guard<std::mutex> guard(PresenceMutex);
QueuedPresence.length = JsonWriteRichPresenceObj( QueuedPresence.length = JsonWriteRichPresenceObj(QueuedPresence.buffer, sizeof(QueuedPresence.buffer), Nonce++, Pid, presence);
QueuedPresence.buffer, sizeof(QueuedPresence.buffer), Nonce++, Pid, presence);
UpdatePresence.exchange(true); UpdatePresence.exchange(true);
} }
SignalIOActivity(); SignalIOActivity();
@@ -476,4 +475,3 @@ extern "C" void Discord_UpdateHandlers(DiscordEventHandlers *newHandlers) {
} }
} // namespace discord_rpc } // namespace discord_rpc

View File

@@ -17,8 +17,7 @@ class MsgQueue {
public: public:
MsgQueue() {} MsgQueue() {}
ElementType* GetNextAddMessage() ElementType *GetNextAddMessage() {
{
// if we are falling behind, bail // if we are falling behind, bail
if (pendingSends_.load() >= QueueSize) { if (pendingSends_.load() >= QueueSize) {
return nullptr; return nullptr;
@@ -29,8 +28,7 @@ public:
void CommitAdd() { ++pendingSends_; } void CommitAdd() { ++pendingSends_; }
bool HavePendingSends() const { return pendingSends_.load() != 0; } bool HavePendingSends() const { return pendingSends_.load() != 0; }
ElementType* GetNextSendMessage() ElementType *GetNextSendMessage() {
{
auto index = (nextSend_++) % QueueSize; auto index = (nextSend_++) % QueueSize;
return &queue_[index]; return &queue_[index];
} }

View File

@@ -130,4 +130,3 @@ bool RpcConnection::Read(JsonDocument &message) {
} }
} // namespace discord_rpc } // namespace discord_rpc

View File

@@ -61,4 +61,3 @@ struct RpcConnection {
}; };
} // namespace discord_rpc } // namespace discord_rpc

View File

@@ -246,4 +246,3 @@ size_t JsonWriteJoinReply(char *dest, size_t maxLen, const char *userId, int rep
} }
} // namespace discord_rpc } // namespace discord_rpc