Skip to content

Commit

Permalink
Actually queue the additions...
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Jan 30, 2024
1 parent e568880 commit 23bb6cc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions core/src/mindustry/ui/dialogs/JoinDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ public void refreshCommunity(){

long[] lastFrame = {0};
long[] start = {0};
long[] queued = {0};
for(int i = 0; i < defaultServers.size; i ++){
ServerGroup group = defaultServers.get((i + defaultServers.size/2) % defaultServers.size);
boolean hidden = group.hidden();
Expand All @@ -446,14 +447,20 @@ public void refreshCommunity(){
String resaddress = address.contains(":") ? address.split(":")[0] : address;
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;

var ref = new Object() { // The wonders of programming in java.
Cons<Host> cons = null;
};
net.pingHost(resaddress, resport, ref.cons = res -> {
Cons<Host>[] cons = new Cons[]{null};
net.pingHost(resaddress, resport, cons[0] = res -> {
var frame = Core.graphics.getFrameId();
if (lastFrame[0] == frame && Time.timeSinceMillis(start[0]) > 5) { // Limit frames to 5ms (arbitrary value)
queued[0]++;
Core.app.post(() -> cons[0].get(res));
return;
} else start[0] = Time.millis(); // Save the time on the first call each frame
} else { // Save the time on the first call each frame
start[0] = Time.millis();
if (queued[0] > 0) {
Log.debug("Queued server additions: @", queued[0]);
queued[0] = 0;
}
}
lastFrame[0] = frame;

if(refreshes != cur) return;
Expand Down

0 comments on commit 23bb6cc

Please sign in to comment.