fix numbering and selection splitting

This commit is contained in:
Daniella / Tove 2024-05-31 20:35:54 +02:00
parent 8d7fbd0b53
commit 535b3a06a4
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
4 changed files with 12 additions and 10 deletions

View file

@ -27,7 +27,7 @@ public class RemoteEventManager {
public final ArrayList<Socket> clients = new ArrayList<>();
public ServerSocket server = null;
private int id = 0, maxID = 0;
private int id = -1, peers = 0, maxID = 0;
private final Queue<RemoteEvent> toSend = new LinkedList<>();
private final Queue<RemoteEvent> toProcess = new LinkedList<>();
@ -90,7 +90,7 @@ public class RemoteEventManager {
s.getOutputStream().flush();
s.setSoTimeout(1);
clients.add(s);
publish(new RemoteInitEvent(++maxID));
publish(new RemoteInitEvent(++maxID, clients.size()));
BaseBand.notify("[Remote] Client connected.");
} else {
s.close();
@ -181,13 +181,14 @@ public class RemoteEventManager {
while(!toProcess.isEmpty()) {
RemoteEvent event = toProcess.poll();
if(event instanceof RemoteInitEvent) {
peers = ((RemoteInitEvent) event).clients;
if(id == -1) {
id = ((RemoteInitEvent) event).id;
BaseBand.notify("[Remote] Received ID: " + id + ".");
BaseBand.notify("[Remote] Received ID: " + id + ". Peers connected: " + peers + ".");
}
else {
maxID = ((RemoteInitEvent) event).id;
BaseBand.notify("[Remote] Someone connected with ID " + maxID + ".");
BaseBand.notify("[Remote] Someone connected with ID " + maxID + ". Peers connected: " + peers + ".");
}
}
else {
@ -203,7 +204,7 @@ public class RemoteEventManager {
}
public int getPeers() {
return maxID + 1;
return peers;
}
}

View file

@ -5,9 +5,10 @@ import de.tudbut.obj.Save;
public class RemoteInitEvent extends RemoteEvent {
@Save
public int id;
public int id, clients;
public RemoteInitEvent(int id) {
public RemoteInitEvent(int id, int clients) {
this.id = id;
this.clients = clients;
}
}

View file

@ -16,7 +16,7 @@ public class BlockUtils {
xSideLength = sideLength;
else
zSideLength = sideLength;
for (int i = 0; i <= selections.length; i++) {
for (int i = 0; i < selections.length; i++) {
BlockPos pos1 = selection.pos1.add(xSideLength * i, 0, zSideLength * i);
BlockPos pos2 = selection.pos2.add(Math.min(xSideLength * (i + 1), size.getX()), 0, Math.min(zSideLength * (i + 1), size.getZ()));
selections[i] = new Selection(pos1, pos2);

View file

@ -22,12 +22,12 @@ public class Selection {
}
public long longestSide() {
Vec3i size = pos2.subtract(pos1);
Vec3i size = size();
return Math.max(Math.max(size.getX(), size.getY()), size.getZ());
}
public long longestSideH() {
Vec3i size = pos2.subtract(pos1);
Vec3i size = size();
return Math.max(size.getX(), size.getZ());
}
}