loading screen

This commit is contained in:
Sen 2025-03-16 23:14:24 +01:00
parent 987ed4059e
commit d4f6d3e4f9
6 changed files with 139 additions and 95 deletions

View file

@ -147,7 +147,6 @@ import game.window.WindowEvent;
import game.world.BlockPos; import game.world.BlockPos;
import game.world.BoundingBox; import game.world.BoundingBox;
import game.world.Chunk; import game.world.Chunk;
import game.world.Converter;
import game.world.Facing; import game.world.Facing;
import game.world.HitPosition; import game.world.HitPosition;
import game.world.HitPosition.ObjectType; import game.world.HitPosition.ObjectType;
@ -427,7 +426,7 @@ public class Game implements IThreadListener {
public void connectToIntegrated(Server server, String user) { public void connectToIntegrated(Server server, String user) {
this.debugWorld = server.getFolder() == null; this.debugWorld = server.getFolder() == null;
this.displayGuiScreen(null); // this.displayGuiScreen(null);
SocketAddress socket = server.setLocalEndpoint(); SocketAddress socket = server.setLocalEndpoint();
NetConnection connection = NetConnection.provideLocalClient(socket); NetConnection connection = NetConnection.provideLocalClient(socket);
connection.setNetHandler(new NetHandlerLoginClient(connection, this)); connection.setNetHandler(new NetHandlerLoginClient(connection, this));
@ -2083,7 +2082,7 @@ public class Game implements IThreadListener {
} }
Log.SYSTEM.info("Beende ..."); Log.SYSTEM.info("Beende ...");
unload(); unload(false);
this.getSoundManager().unload(); this.getSoundManager().unload();
Region.killIO(); Region.killIO();
this.renderGlobal.stopChunkBuilders(); this.renderGlobal.stopChunkBuilders();
@ -2107,7 +2106,7 @@ public class Game implements IThreadListener {
public void disconnected(String msg) { public void disconnected(String msg) {
Log.SYSTEM.info("Getrennt: %s", msg); Log.SYSTEM.info("Getrennt: %s", msg);
this.unload(); this.unload(true);
this.displayGuiScreen(new GuiInfo("Von Server getrennt", TextColor.RED + "Verbindung zum Server wurde getrennt\n\n" + TextColor.RESET + msg)); this.displayGuiScreen(new GuiInfo("Von Server getrennt", TextColor.RED + "Verbindung zum Server wurde getrennt\n\n" + TextColor.RESET + msg));
} }
@ -2263,7 +2262,7 @@ public class Game implements IThreadListener {
return this.theWorld != null && server == null; return this.theWorld != null && server == null;
} }
public void unload() { public void unload(boolean loading) {
if(this.theWorld != null) { if(this.theWorld != null) {
if(server == null && this.getNetHandler() != null) if(server == null && this.getNetHandler() != null)
this.getNetHandler().getNetworkManager().closeChannel("Quitting"); this.getNetHandler().getNetworkManager().closeChannel("Quitting");
@ -2271,11 +2270,18 @@ public class Game implements IThreadListener {
if(server != null) if(server != null)
server.shutdown(); server.shutdown();
} }
while(server != null && !server.isStopped()) { if(server != null) {
try { if(loading) {
Thread.sleep(10L); this.displayGuiScreen(GuiLoading.makeSaveTask(server));
} }
catch(InterruptedException e) { else {
while(!server.isStopped()) {
try {
Thread.sleep(10L);
}
catch(InterruptedException e) {
}
}
} }
} }
server = null; server = null;
@ -2284,17 +2290,16 @@ public class Game implements IThreadListener {
public void startServer(File dir, String user) { public void startServer(File dir, String user) {
server = new Server(dir); server = new Server(dir);
server.start(); server.start();
while(server != null && !server.isStarted()) { this.displayGuiScreen(GuiLoading.makeLoadTask(server, user));
try { // while(server != null && !server.isStarted()) {
Thread.sleep(10L); // try {
} // Thread.sleep(10L);
catch(InterruptedException e) { // }
} // catch(InterruptedException e) {
} // }
if(server != null) { // }
server.setVar("viewDistance", "" + this.renderDistance); // if(server != null) {
this.connectToIntegrated(server, user); // }
}
} }
private void startSound(boolean load) { private void startSound(boolean load) {

View file

@ -117,7 +117,7 @@ public final class Server implements Runnable, IThreadListener {
private ChannelFuture endpoint; private ChannelFuture endpoint;
private ChannelFuture localEndpoint; private ChannelFuture localEndpoint;
private String localUser; private String localUser;
// private String message; private String message;
private boolean running = true; private boolean running = true;
private boolean stopped; private boolean stopped;
@ -138,7 +138,8 @@ public final class Server implements Runnable, IThreadListener {
private int pingTimer; private int pingTimer;
private int syncTimer; private int syncTimer;
private int perfTimer; private int perfTimer;
// private int progress = -1; private int progress = -1;
private int total = 0;
Server(File dir) { Server(File dir) {
// this.owner = owner; // this.owner = owner;
@ -215,36 +216,24 @@ public final class Server implements Runnable, IThreadListener {
if(this.debug) if(this.debug)
return; return;
if(message) { if(message) {
this.setProgress(true, -1, 0); this.startProgress(true, this.worlds.size());
} }
long last = System.currentTimeMillis();
int done = 0; int done = 0;
this.saveWorldInfo(); this.saveWorldInfo();
for(WorldServer world : this.worlds) { for(WorldServer world : this.worlds) {
if(message) { if(message) {
long time = System.currentTimeMillis(); this.setProgress(done);
if(time - last >= 10L) {
if(this.setProgress(true, (done * 100) / this.worlds.size(), (int)(time - last))) {
last = time;
}
}
} }
++done; ++done;
world.saveAllChunks(); world.saveAllChunks();
} }
this.setProgress(-1);
} }
private boolean setProgress(boolean save, int progress, int delta) { private void startProgress(boolean save, int amount) {
// this.setProgress(progress); this.setTotal(amount);
if(progress == -1) { this.setProgress(0);
Log.JNI.info((save ? "Speichere" : "Generiere und lade") + " Level " + (this.baseDir == null ? "." : this.baseDir.getName())); Log.JNI.info((save ? "Speichere" : "Generiere und lade") + " Level " + (this.baseDir == null ? "." : this.baseDir.getName()));
return true;
}
else if(!save && delta > 1000) {
Log.JNI.info("Bereite Spawnbereich vor" + ": " + progress + "%");
return true;
}
return false;
} }
public void unloadWorld(WorldServer world) { public void unloadWorld(WorldServer world) {
@ -266,7 +255,7 @@ public final class Server implements Runnable, IThreadListener {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
Log.JNI.info("Starte Server Version " + Config.VERSION); Log.JNI.info("Starte Server Version " + Config.VERSION);
if(!this.debug) { if(!this.debug) {
// this.setMessage("Welt wird erstellt"); this.setMessage("Welt wird erstellt und geladen");
FolderInfo info = Region.loadWorldInfo(this.baseDir); FolderInfo info = Region.loadWorldInfo(this.baseDir);
// if(dtime == -1L) // { // if(dtime == -1L) // {
// dtime = World.START_TIME; // dtime = World.START_TIME;
@ -312,24 +301,6 @@ public final class Server implements Runnable, IThreadListener {
} }
this.setTpsTarget(20.0f); this.setTpsTarget(20.0f);
if(!this.debug) { if(!this.debug) {
// int done = 0;
// this.setMessage("Landschaft wird generiert");
// this.setProgress(false, -1, 0);
// WorldServer world = this.getWorld(Config.spawnDim);
// world = world == null ? this.space : world;
// long last = System.currentTimeMillis();
// for(int x = -192; x <= 192 && this.running; x += 16) {
// for(int z = -192; z <= 192 && this.running; z += 16) {
// long time1 = System.currentTimeMillis();
// if(time1 - last >= 10L) {
// if(this.setProgress(false, done * 100 / 625, (int)(time1 - last))) {
// last = time1;
// }
// }
// ++done;
// world.loadChunk(Config.spawnX + x >> 4, Config.spawnZ + z >> 4);
// }
// }
for(Dimension dim : UniverseRegistry.getDimensions()) { for(Dimension dim : UniverseRegistry.getDimensions()) {
if(WorldServer.needsLoading(this.baseDir, dim)) { if(WorldServer.needsLoading(this.baseDir, dim)) {
this.getWorld(dim.getDimensionId()).loadForcedChunks(); this.getWorld(dim.getDimensionId()).loadForcedChunks();
@ -380,6 +351,34 @@ public final class Server implements Runnable, IThreadListener {
Log.JNI.info("Server wurde beendet"); Log.JNI.info("Server wurde beendet");
} }
} }
private void preload(Entity entity) {
int done = 0;
int total = Config.distance * 2 + 1;
total *= total;
this.setMessage("Landschaft wird generiert");
this.startProgress(false, total);
WorldServer world = this.getWorld(Config.spawnDim);
world = world == null ? this.space : world;
int bx = (int)entity.posX >> 4;
int bz = (int)entity.posZ >> 4;
long last = System.currentTimeMillis();
for(int x = -Config.distance; x <= Config.distance && this.running; x++) {
for(int z = -Config.distance; z <= Config.distance && this.running; z++) {
long time = System.currentTimeMillis();
if(time - last >= 10L) {
this.setProgress(done);
if(time - last > 1000L) {
Log.JNI.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%");
last = time;
}
}
++done;
world.loadChunk(bx + x, bz + z);
}
}
this.setProgress(-1);
}
private void tick() { private void tick() {
// boolean pause = this.paused; // boolean pause = this.paused;
@ -539,29 +538,41 @@ public final class Server implements Runnable, IThreadListener {
return this.usermap.get(user.toLowerCase()); return this.usermap.get(user.toLowerCase());
} }
// public String getMessage() { public String getMessage() {
// synchronized(this) { synchronized(this) {
// return this.message; return this.message;
// } }
// } }
//
// public int getProgress() { public int getProgress() {
// synchronized(this) { synchronized(this) {
// return this.progress; return this.progress;
// } }
// } }
//
// private void setMessage(String message) { public int getTotal() {
// synchronized(this) { synchronized(this) {
// this.message = message; return this.total;
// } }
// } }
//
// private void setProgress(int progress) { private void setMessage(String message) {
// synchronized(this) { synchronized(this) {
// this.progress = progress; this.message = message;
// } }
// } }
private void setProgress(int progress) {
synchronized(this) {
this.progress = progress;
}
}
private void setTotal(int total) {
synchronized(this) {
this.total = total;
}
}
public void setVar(String cv, String value) { public void setVar(String cv, String value) {
this.schedule(new Runnable() { this.schedule(new Runnable() {
@ -672,6 +683,9 @@ public final class Server implements Runnable, IThreadListener {
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": " + player.getId() + " auf Level " + world.dimension.getDimensionId() + ": "
+ String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden"); + String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden");
if(Config.preloadAll || (Config.preloadLocal && conn.isLocal()))
this.preload(player);
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player))); conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player)));
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(), conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(),
@ -1102,8 +1116,8 @@ public final class Server implements Runnable, IThreadListener {
void stopServer() { void stopServer() {
if(!this.stopped) { if(!this.stopped) {
// this.setProgress(-1); this.setProgress(-1);
// this.setMessage("Stoppe server"); this.setMessage("Stoppe server");
Log.JNI.info("Beende Server"); Log.JNI.info("Beende Server");
if(this.started) if(this.started)
for(NetHandlerPlayServer conn : Lists.newArrayList(this.players)) { for(NetHandlerPlayServer conn : Lists.newArrayList(this.players)) {

View file

@ -18,14 +18,27 @@ public class GuiLoading extends Gui {
private Bar progressBar1; private Bar progressBar1;
private Bar progressBar2; private Bar progressBar2;
public static GuiLoading makeLoadTask(final Server server) { public static GuiLoading makeLoadTask(final Server server, final String user) {
return new GuiLoading("Lade Welt ...", new Callback() { return new GuiLoading("Lade Welt ...", new Callback() {
boolean started = false;
public void poll(Game gm, GuiLoading gui) { public void poll(Game gm, GuiLoading gui) {
if(server.isStarted()) { if(!this.started && server.isStarted()) {
gm.displayGuiScreen(null); this.started = true;
return; // gm.displayGuiScreen(null);
server.setVar("viewDistance", "" + gm.renderDistance);
gm.connectToIntegrated(server, user);
// return;
} }
int progress = server.getProgress();
if(progress < 0) {
gui.resetBar();
}
else {
gui.setBar(null, "Chunks", Math.max(1, server.getTotal()));
gui.setProgress(progress);
}
gui.setTask(server.getMessage());
} }
}); });
} }
@ -37,7 +50,15 @@ public class GuiLoading extends Gui {
gm.displayGuiScreen(GuiMenu.INSTANCE); gm.displayGuiScreen(GuiMenu.INSTANCE);
return; return;
} }
int progress = server.getProgress();
if(progress < 0) {
gui.resetBar();
}
else {
gui.setBar(null, "Dimensionen", Math.max(1, server.getTotal()));
gui.setProgress(progress);
}
gui.setTask(server.getMessage());
} }
}); });
} }
@ -62,7 +83,7 @@ public class GuiLoading extends Gui {
} }
public void setTask(String task) { public void setTask(String task) {
this.taskLabel.setText(task); this.taskLabel.setText(task == null ? "" : task);
} }
public void setBar(String desc) { public void setBar(String desc) {

View file

@ -91,8 +91,8 @@ public class GuiMenu extends Gui {
} }
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() { this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() {
public void use(ActButton elem, ActButton.Mode action) { public void use(ActButton elem, ActButton.Mode action) {
GuiMenu.this.gm.unload(); GuiMenu.this.gm.unload(true);
GuiMenu.this.gm.displayGuiScreen(INSTANCE); // GuiMenu.this.gm.displayGuiScreen(INSTANCE);
} }
}, this.gm.isRemote() ? "Verbindung trennen" : "Welt schließen")); }, this.gm.isRemote() ? "Verbindung trennen" : "Welt schließen"));
this.shift(); this.shift();

View file

@ -334,6 +334,8 @@ public abstract class Config {
public static boolean itemFallDamage = true; public static boolean itemFallDamage = true;
@Var(name = "registration") @Var(name = "registration")
public static boolean register = true; public static boolean register = true;
@Var(name = "preload_chunks_local")
public static boolean preloadLocal = true;
@Var(name = "keepInventory") @Var(name = "keepInventory")
public static boolean keepInventory = false; public static boolean keepInventory = false;
@ -351,6 +353,8 @@ public abstract class Config {
public static boolean auth = false; public static boolean auth = false;
@Var(name = "teleportForAll") @Var(name = "teleportForAll")
public static boolean teleportAllowed = false; public static boolean teleportAllowed = false;
@Var(name = "preload_chunks_all") // Vorsicht Lag!!
public static boolean preloadAll = false;
// @Var(name = "maxPolygonalPoints") // @Var(name = "maxPolygonalPoints")
// public static int polygonalPoints = -1; // public static int polygonalPoints = -1;

View file

@ -1267,7 +1267,7 @@ public final class Converter {
else { else {
gui.resetSub(); gui.resetSub();
} }
gui.setTask(conv.action == null ? "" : conv.action); gui.setTask(conv.action);
} }
})); }));
final NBTTagCompound tag = nbt; final NBTTagCompound tag = nbt;