Attempts to improve the loading system

This commit is contained in:
Anuken 2019-08-26 13:15:53 -04:00
parent 62f683b871
commit 1fc9c82aaf
4 changed files with 66 additions and 8 deletions

View File

@ -63,6 +63,9 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
MethodSpec.Builder load = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
MethodSpec.Builder dispose = MethodSpec.methodBuilder("dispose").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
MethodSpec.Builder loadBegin = MethodSpec.methodBuilder("loadBegin").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
HashSet<String> names = new HashSet<>();
Files.list(Paths.get(path)).forEach(p -> {
String fname = p.getFileName().toString();
@ -81,6 +84,13 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
load.addStatement(name + " = io.anuke.arc.Core.audio."+loadMethod+"(io.anuke.arc.Core.files.internal(io.anuke.arc.Core.app.getType() != io.anuke.arc.Application.ApplicationType.iOS ? $S : $S))",
path.substring(path.lastIndexOf("/") + 1) + "/" + fname, (path.substring(path.lastIndexOf("/") + 1) + "/" + fname).replace(".ogg", ".mp3"));
loadBegin.addStatement("io.anuke.arc.Core.assets.load(io.anuke.arc.Core.app.getType() != io.anuke.arc.Application.ApplicationType.iOS ? $S : $S, "+rtype+".class)",
path.substring(path.lastIndexOf("/") + 1) + "/" + fname,
(path.substring(path.lastIndexOf("/") + 1) + "/" + fname).replace(".ogg", ".mp3"));
dispose.addStatement(name + ".dispose()");
dispose.addStatement(name + " = null");
type.addField(FieldSpec.builder(ClassName.bestGuess(rtype), name, Modifier.STATIC, Modifier.PUBLIC).initializer("new io.anuke.arc.audio.mock.Mock" + rtype.substring(rtype.lastIndexOf(".") + 1)+ "()").build());
@ -92,6 +102,7 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
}
type.addMethod(load.build());
type.addMethod(loadBegin.build());
type.addMethod(dispose.build());
JavaFile.builder(packageName, type.build()).build().writeTo(Utils.filer);
}

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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();