Attempts to improve the loading system
This commit is contained in:
@@ -1,39 +1,55 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.assets.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.core.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.io.*;
|
||||
|
||||
import static io.anuke.arc.Core.*;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Mindustry extends ApplicationCore{
|
||||
private long lastTime;
|
||||
private boolean finished = false;
|
||||
|
||||
@Override
|
||||
public void setup(){
|
||||
Log.setUseColors(false);
|
||||
|
||||
Bench.begin("load setup");
|
||||
Time.setDeltaProvider(() -> {
|
||||
float result = Core.graphics.getDeltaTime() * 60f;
|
||||
return (Float.isNaN(result) || Float.isInfinite(result)) ? 1f : Mathf.clamp(result, 0.0001f, 60f / 10f);
|
||||
});
|
||||
|
||||
batch = new SpriteBatch();
|
||||
assets = new AssetManager();
|
||||
atlas = TextureAtlas.blankAtlas();
|
||||
|
||||
assets.load(new Vars());
|
||||
|
||||
Bench.begin("cursors");
|
||||
UI.loadSystemCursors();
|
||||
|
||||
Bench.begin("vars");
|
||||
Vars.init();
|
||||
Log.setUseColors(false);
|
||||
Bench.begin("bundle");
|
||||
BundleLoader.load();
|
||||
|
||||
Bench.begin("music");
|
||||
Musics.load();
|
||||
Musics.loadBegin();
|
||||
Bench.begin("sound");
|
||||
Sounds.load();
|
||||
Sounds.loadBegin();
|
||||
}
|
||||
|
||||
private void post(){
|
||||
Bench.begin("content");
|
||||
content.load();
|
||||
content.loadColors();
|
||||
@@ -56,7 +72,18 @@ public class Mindustry extends ApplicationCore{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
super.update();
|
||||
//
|
||||
if(!assets.update()){
|
||||
drawLoading();
|
||||
}else{
|
||||
if(!finished){
|
||||
post();
|
||||
finished = true;
|
||||
Events.fire(new ClientLoadEvent());
|
||||
}
|
||||
|
||||
super.update();
|
||||
}
|
||||
|
||||
int targetfps = Core.settings.getInt("fpscap", 120);
|
||||
|
||||
@@ -79,7 +106,17 @@ public class Mindustry extends ApplicationCore{
|
||||
public void init(){
|
||||
super.init();
|
||||
Bench.end();
|
||||
}
|
||||
|
||||
Events.fire(new ClientLoadEvent());
|
||||
void drawLoading(){
|
||||
Core.graphics.clear(Color.BLACK);
|
||||
Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||
float height = UnitScl.dp.scl(100f);
|
||||
|
||||
Draw.color(Pal.darkerGray);
|
||||
Fill.rect(graphics.getWidth()/2f, graphics.getHeight()/2f, graphics.getWidth(), height);
|
||||
Draw.color(Pal.accent);
|
||||
Fill.crect(0, graphics.getHeight()/2f - height/2f, graphics.getWidth() * assets.getProgress(), height);
|
||||
Draw.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.Application.ApplicationType;
|
||||
import io.anuke.arc.assets.*;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.util.Structs;
|
||||
@@ -25,7 +26,7 @@ import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Vars{
|
||||
public class Vars implements Loadable{
|
||||
/** Whether to load locales.*/
|
||||
public static boolean loadLocales = true;
|
||||
/** IO buffer size. */
|
||||
@@ -157,6 +158,16 @@ public class Vars{
|
||||
/** all local players, currently only has one player. may be used for local co-op in the future */
|
||||
public static Player player;
|
||||
|
||||
@Override
|
||||
public void loadAsync(){
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSync(){
|
||||
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
Serialization.init();
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ public class Control implements ApplicationListener{
|
||||
private boolean wasPaused = false;
|
||||
|
||||
public Control(){
|
||||
batch = new SpriteBatch();
|
||||
saves = new Saves();
|
||||
tutorial = new Tutorial();
|
||||
music = new MusicControl();
|
||||
|
||||
Reference in New Issue
Block a user