Attempts to improve the loading system
This commit is contained in:
@@ -63,6 +63,9 @@ public class AssetsAnnotationProcessor extends AbstractProcessor{
|
|||||||
MethodSpec.Builder load = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
MethodSpec.Builder load = MethodSpec.methodBuilder("load").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||||
MethodSpec.Builder dispose = MethodSpec.methodBuilder("dispose").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<>();
|
HashSet<String> names = new HashSet<>();
|
||||||
Files.list(Paths.get(path)).forEach(p -> {
|
Files.list(Paths.get(path)).forEach(p -> {
|
||||||
String fname = p.getFileName().toString();
|
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))",
|
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"));
|
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 + ".dispose()");
|
||||||
dispose.addStatement(name + " = null");
|
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());
|
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(load.build());
|
||||||
|
type.addMethod(loadBegin.build());
|
||||||
type.addMethod(dispose.build());
|
type.addMethod(dispose.build());
|
||||||
JavaFile.builder(packageName, type.build()).build().writeTo(Utils.filer);
|
JavaFile.builder(packageName, type.build()).build().writeTo(Utils.filer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,55 @@
|
|||||||
package io.anuke.mindustry;
|
package io.anuke.mindustry;
|
||||||
|
|
||||||
import io.anuke.arc.*;
|
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.math.*;
|
||||||
|
import io.anuke.arc.scene.ui.layout.*;
|
||||||
import io.anuke.arc.util.*;
|
import io.anuke.arc.util.*;
|
||||||
import io.anuke.mindustry.core.*;
|
import io.anuke.mindustry.core.*;
|
||||||
import io.anuke.mindustry.game.EventType.*;
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
import io.anuke.mindustry.gen.*;
|
import io.anuke.mindustry.gen.*;
|
||||||
|
import io.anuke.mindustry.graphics.*;
|
||||||
import io.anuke.mindustry.io.*;
|
import io.anuke.mindustry.io.*;
|
||||||
|
|
||||||
|
import static io.anuke.arc.Core.*;
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class Mindustry extends ApplicationCore{
|
public class Mindustry extends ApplicationCore{
|
||||||
private long lastTime;
|
private long lastTime;
|
||||||
|
private boolean finished = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup(){
|
public void setup(){
|
||||||
|
Log.setUseColors(false);
|
||||||
|
|
||||||
|
Bench.begin("load setup");
|
||||||
Time.setDeltaProvider(() -> {
|
Time.setDeltaProvider(() -> {
|
||||||
float result = Core.graphics.getDeltaTime() * 60f;
|
float result = Core.graphics.getDeltaTime() * 60f;
|
||||||
return (Float.isNaN(result) || Float.isInfinite(result)) ? 1f : Mathf.clamp(result, 0.0001f, 60f / 10f);
|
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");
|
Bench.begin("cursors");
|
||||||
UI.loadSystemCursors();
|
UI.loadSystemCursors();
|
||||||
|
|
||||||
Bench.begin("vars");
|
Bench.begin("vars");
|
||||||
Vars.init();
|
|
||||||
Log.setUseColors(false);
|
|
||||||
Bench.begin("bundle");
|
Bench.begin("bundle");
|
||||||
BundleLoader.load();
|
BundleLoader.load();
|
||||||
|
|
||||||
Bench.begin("music");
|
Bench.begin("music");
|
||||||
Musics.load();
|
Musics.loadBegin();
|
||||||
Bench.begin("sound");
|
Bench.begin("sound");
|
||||||
Sounds.load();
|
Sounds.loadBegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void post(){
|
||||||
Bench.begin("content");
|
Bench.begin("content");
|
||||||
content.load();
|
content.load();
|
||||||
content.loadColors();
|
content.loadColors();
|
||||||
@@ -56,7 +72,18 @@ public class Mindustry extends ApplicationCore{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
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);
|
int targetfps = Core.settings.getInt("fpscap", 120);
|
||||||
|
|
||||||
@@ -79,7 +106,17 @@ public class Mindustry extends ApplicationCore{
|
|||||||
public void init(){
|
public void init(){
|
||||||
super.init();
|
super.init();
|
||||||
Bench.end();
|
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.*;
|
||||||
import io.anuke.arc.Application.ApplicationType;
|
import io.anuke.arc.Application.ApplicationType;
|
||||||
|
import io.anuke.arc.assets.*;
|
||||||
import io.anuke.arc.files.FileHandle;
|
import io.anuke.arc.files.FileHandle;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.util.Structs;
|
import io.anuke.arc.util.Structs;
|
||||||
@@ -25,7 +26,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class Vars{
|
public class Vars implements Loadable{
|
||||||
/** Whether to load locales.*/
|
/** Whether to load locales.*/
|
||||||
public static boolean loadLocales = true;
|
public static boolean loadLocales = true;
|
||||||
/** IO buffer size. */
|
/** 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 */
|
/** all local players, currently only has one player. may be used for local co-op in the future */
|
||||||
public static Player player;
|
public static Player player;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadAsync(){
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadSync(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
Serialization.init();
|
Serialization.init();
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public class Control implements ApplicationListener{
|
|||||||
private boolean wasPaused = false;
|
private boolean wasPaused = false;
|
||||||
|
|
||||||
public Control(){
|
public Control(){
|
||||||
batch = new SpriteBatch();
|
|
||||||
saves = new Saves();
|
saves = new Saves();
|
||||||
tutorial = new Tutorial();
|
tutorial = new Tutorial();
|
||||||
music = new MusicControl();
|
music = new MusicControl();
|
||||||
|
|||||||
Reference in New Issue
Block a user