-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(discord): rewrite + make it thread-safe
The rewrite was necessary to be able to achieve the system to be thread-safe. It gave the opportunity to organise how the subsystem works. This also ensures the subsystem is easy to: - Implement new features! - Fix bugs without breaking stuff - Separated the thread into its own class - Subsystem manages the communication with the thread - Re-organized the system - Fix: disable discord-ipc library logger
- Loading branch information
1 parent
9f7bf17
commit 2002af3
Showing
5 changed files
with
415 additions
and
286 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
71 changes: 71 additions & 0 deletions
71
...DiscordRPC/src/main/java/org/terasology/engine/subsystem/discordrpc/DiscordRPCBuffer.java
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,71 @@ | ||
// Copyright 2020 The Terasology Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.terasology.engine.subsystem.discordrpc; | ||
|
||
import java.time.OffsetDateTime; | ||
|
||
/** | ||
* A threaded-safe shared buffer used to store information for {@link DiscordRPCThread} to be processed as {@link com.jagrosh.discordipc.entities.RichPresence} | ||
* | ||
* It helps avoiding allocating unnecessary objects for the rich presence. | ||
*/ | ||
public final class DiscordRPCBuffer { | ||
private String state; | ||
private OffsetDateTime startTimestamp; | ||
private boolean changed; | ||
|
||
/** | ||
* Sets the current party status | ||
* | ||
* @param state The current party status | ||
*/ | ||
public synchronized void setState(String state) { | ||
this.state = state; | ||
this.changed = true; | ||
} | ||
|
||
/** | ||
* Returns the current party status | ||
* | ||
* @return The current party status | ||
*/ | ||
public synchronized String getState() { | ||
return state; | ||
} | ||
|
||
/** | ||
* Sets the start of the game | ||
* | ||
* @param startTimestamp The time when that action has start or null to hide it | ||
*/ | ||
public synchronized void setStartTimestamp(OffsetDateTime startTimestamp) { | ||
this.startTimestamp = startTimestamp; | ||
this.changed = true; | ||
} | ||
|
||
/** | ||
* Returns the start of the game | ||
* | ||
* @return The start of the game | ||
*/ | ||
public synchronized OffsetDateTime getStartTimestamp() { | ||
return startTimestamp; | ||
} | ||
|
||
/** | ||
* Check if the buffer has changed | ||
* | ||
* @return if the buffer has changed | ||
*/ | ||
public synchronized boolean hasChanged() { | ||
return changed; | ||
} | ||
|
||
/** | ||
* Resets the buffer's change state to false | ||
*/ | ||
synchronized void resetState() { | ||
this.changed = false; | ||
} | ||
} |
Oops, something went wrong.