loading screen
This commit is contained in:
parent
987ed4059e
commit
d4f6d3e4f9
6 changed files with 139 additions and 95 deletions
|
@ -147,7 +147,6 @@ import game.window.WindowEvent;
|
|||
import game.world.BlockPos;
|
||||
import game.world.BoundingBox;
|
||||
import game.world.Chunk;
|
||||
import game.world.Converter;
|
||||
import game.world.Facing;
|
||||
import game.world.HitPosition;
|
||||
import game.world.HitPosition.ObjectType;
|
||||
|
@ -427,7 +426,7 @@ public class Game implements IThreadListener {
|
|||
|
||||
public void connectToIntegrated(Server server, String user) {
|
||||
this.debugWorld = server.getFolder() == null;
|
||||
this.displayGuiScreen(null);
|
||||
// this.displayGuiScreen(null);
|
||||
SocketAddress socket = server.setLocalEndpoint();
|
||||
NetConnection connection = NetConnection.provideLocalClient(socket);
|
||||
connection.setNetHandler(new NetHandlerLoginClient(connection, this));
|
||||
|
@ -2083,7 +2082,7 @@ public class Game implements IThreadListener {
|
|||
}
|
||||
|
||||
Log.SYSTEM.info("Beende ...");
|
||||
unload();
|
||||
unload(false);
|
||||
this.getSoundManager().unload();
|
||||
Region.killIO();
|
||||
this.renderGlobal.stopChunkBuilders();
|
||||
|
@ -2107,7 +2106,7 @@ public class Game implements IThreadListener {
|
|||
|
||||
public void disconnected(String 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));
|
||||
}
|
||||
|
||||
|
@ -2263,7 +2262,7 @@ public class Game implements IThreadListener {
|
|||
return this.theWorld != null && server == null;
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
public void unload(boolean loading) {
|
||||
if(this.theWorld != null) {
|
||||
if(server == null && this.getNetHandler() != null)
|
||||
this.getNetHandler().getNetworkManager().closeChannel("Quitting");
|
||||
|
@ -2271,30 +2270,36 @@ public class Game implements IThreadListener {
|
|||
if(server != null)
|
||||
server.shutdown();
|
||||
}
|
||||
while(server != null && !server.isStopped()) {
|
||||
if(server != null) {
|
||||
if(loading) {
|
||||
this.displayGuiScreen(GuiLoading.makeSaveTask(server));
|
||||
}
|
||||
else {
|
||||
while(!server.isStopped()) {
|
||||
try {
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
server = null;
|
||||
}
|
||||
|
||||
public void startServer(File dir, String user) {
|
||||
server = new Server(dir);
|
||||
server.start();
|
||||
while(server != null && !server.isStarted()) {
|
||||
try {
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
}
|
||||
}
|
||||
if(server != null) {
|
||||
server.setVar("viewDistance", "" + this.renderDistance);
|
||||
this.connectToIntegrated(server, user);
|
||||
}
|
||||
this.displayGuiScreen(GuiLoading.makeLoadTask(server, user));
|
||||
// while(server != null && !server.isStarted()) {
|
||||
// try {
|
||||
// Thread.sleep(10L);
|
||||
// }
|
||||
// catch(InterruptedException e) {
|
||||
// }
|
||||
// }
|
||||
// if(server != null) {
|
||||
// }
|
||||
}
|
||||
|
||||
private void startSound(boolean load) {
|
||||
|
|
|
@ -117,7 +117,7 @@ public final class Server implements Runnable, IThreadListener {
|
|||
private ChannelFuture endpoint;
|
||||
private ChannelFuture localEndpoint;
|
||||
private String localUser;
|
||||
// private String message;
|
||||
private String message;
|
||||
|
||||
private boolean running = true;
|
||||
private boolean stopped;
|
||||
|
@ -138,7 +138,8 @@ public final class Server implements Runnable, IThreadListener {
|
|||
private int pingTimer;
|
||||
private int syncTimer;
|
||||
private int perfTimer;
|
||||
// private int progress = -1;
|
||||
private int progress = -1;
|
||||
private int total = 0;
|
||||
|
||||
Server(File dir) {
|
||||
// this.owner = owner;
|
||||
|
@ -215,36 +216,24 @@ public final class Server implements Runnable, IThreadListener {
|
|||
if(this.debug)
|
||||
return;
|
||||
if(message) {
|
||||
this.setProgress(true, -1, 0);
|
||||
this.startProgress(true, this.worlds.size());
|
||||
}
|
||||
long last = System.currentTimeMillis();
|
||||
int done = 0;
|
||||
this.saveWorldInfo();
|
||||
for(WorldServer world : this.worlds) {
|
||||
if(message) {
|
||||
long time = System.currentTimeMillis();
|
||||
if(time - last >= 10L) {
|
||||
if(this.setProgress(true, (done * 100) / this.worlds.size(), (int)(time - last))) {
|
||||
last = time;
|
||||
}
|
||||
}
|
||||
this.setProgress(done);
|
||||
}
|
||||
++done;
|
||||
world.saveAllChunks();
|
||||
}
|
||||
this.setProgress(-1);
|
||||
}
|
||||
|
||||
private boolean setProgress(boolean save, int progress, int delta) {
|
||||
// this.setProgress(progress);
|
||||
if(progress == -1) {
|
||||
private void startProgress(boolean save, int amount) {
|
||||
this.setTotal(amount);
|
||||
this.setProgress(0);
|
||||
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) {
|
||||
|
@ -266,7 +255,7 @@ public final class Server implements Runnable, IThreadListener {
|
|||
long time = System.currentTimeMillis();
|
||||
Log.JNI.info("Starte Server Version " + Config.VERSION);
|
||||
if(!this.debug) {
|
||||
// this.setMessage("Welt wird erstellt");
|
||||
this.setMessage("Welt wird erstellt und geladen");
|
||||
FolderInfo info = Region.loadWorldInfo(this.baseDir);
|
||||
// if(dtime == -1L) // {
|
||||
// dtime = World.START_TIME;
|
||||
|
@ -312,24 +301,6 @@ public final class Server implements Runnable, IThreadListener {
|
|||
}
|
||||
this.setTpsTarget(20.0f);
|
||||
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()) {
|
||||
if(WorldServer.needsLoading(this.baseDir, dim)) {
|
||||
this.getWorld(dim.getDimensionId()).loadForcedChunks();
|
||||
|
@ -381,6 +352,34 @@ public final class Server implements Runnable, IThreadListener {
|
|||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
// boolean pause = this.paused;
|
||||
// this.paused = this.pause;
|
||||
|
@ -539,29 +538,41 @@ public final class Server implements Runnable, IThreadListener {
|
|||
return this.usermap.get(user.toLowerCase());
|
||||
}
|
||||
|
||||
// public String getMessage() {
|
||||
// synchronized(this) {
|
||||
// return this.message;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public int getProgress() {
|
||||
// synchronized(this) {
|
||||
// return this.progress;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void setMessage(String message) {
|
||||
// synchronized(this) {
|
||||
// this.message = message;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void setProgress(int progress) {
|
||||
// synchronized(this) {
|
||||
// this.progress = progress;
|
||||
// }
|
||||
// }
|
||||
public String getMessage() {
|
||||
synchronized(this) {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
synchronized(this) {
|
||||
return this.progress;
|
||||
}
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
synchronized(this) {
|
||||
return this.total;
|
||||
}
|
||||
}
|
||||
|
||||
private void setMessage(String message) {
|
||||
synchronized(this) {
|
||||
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) {
|
||||
this.schedule(new Runnable() {
|
||||
|
@ -672,6 +683,9 @@ public final class Server implements Runnable, IThreadListener {
|
|||
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": "
|
||||
+ 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 SPacketHeldItemChange(player.inventory.currentItem));
|
||||
conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(),
|
||||
|
@ -1102,8 +1116,8 @@ public final class Server implements Runnable, IThreadListener {
|
|||
|
||||
void stopServer() {
|
||||
if(!this.stopped) {
|
||||
// this.setProgress(-1);
|
||||
// this.setMessage("Stoppe server");
|
||||
this.setProgress(-1);
|
||||
this.setMessage("Stoppe server");
|
||||
Log.JNI.info("Beende Server");
|
||||
if(this.started)
|
||||
for(NetHandlerPlayServer conn : Lists.newArrayList(this.players)) {
|
||||
|
|
|
@ -18,14 +18,27 @@ public class GuiLoading extends Gui {
|
|||
private Bar progressBar1;
|
||||
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() {
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
if(server.isStarted()) {
|
||||
gm.displayGuiScreen(null);
|
||||
return;
|
||||
}
|
||||
boolean started = false;
|
||||
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
if(!this.started && server.isStarted()) {
|
||||
this.started = true;
|
||||
// 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);
|
||||
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) {
|
||||
this.taskLabel.setText(task);
|
||||
this.taskLabel.setText(task == null ? "" : task);
|
||||
}
|
||||
|
||||
public void setBar(String desc) {
|
||||
|
|
|
@ -91,8 +91,8 @@ public class GuiMenu extends Gui {
|
|||
}
|
||||
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiMenu.this.gm.unload();
|
||||
GuiMenu.this.gm.displayGuiScreen(INSTANCE);
|
||||
GuiMenu.this.gm.unload(true);
|
||||
// GuiMenu.this.gm.displayGuiScreen(INSTANCE);
|
||||
}
|
||||
}, this.gm.isRemote() ? "Verbindung trennen" : "Welt schließen"));
|
||||
this.shift();
|
||||
|
|
|
@ -334,6 +334,8 @@ public abstract class Config {
|
|||
public static boolean itemFallDamage = true;
|
||||
@Var(name = "registration")
|
||||
public static boolean register = true;
|
||||
@Var(name = "preload_chunks_local")
|
||||
public static boolean preloadLocal = true;
|
||||
|
||||
@Var(name = "keepInventory")
|
||||
public static boolean keepInventory = false;
|
||||
|
@ -351,6 +353,8 @@ public abstract class Config {
|
|||
public static boolean auth = false;
|
||||
@Var(name = "teleportForAll")
|
||||
public static boolean teleportAllowed = false;
|
||||
@Var(name = "preload_chunks_all") // Vorsicht Lag!!
|
||||
public static boolean preloadAll = false;
|
||||
|
||||
// @Var(name = "maxPolygonalPoints")
|
||||
// public static int polygonalPoints = -1;
|
||||
|
|
|
@ -1267,7 +1267,7 @@ public final class Converter {
|
|||
else {
|
||||
gui.resetSub();
|
||||
}
|
||||
gui.setTask(conv.action == null ? "" : conv.action);
|
||||
gui.setTask(conv.action);
|
||||
}
|
||||
}));
|
||||
final NBTTagCompound tag = nbt;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue