2019-12-25 01:39:38 -05:00
|
|
|
package mindustry;
|
2017-05-03 00:09:48 -04:00
|
|
|
|
2019-12-25 01:39:38 -05:00
|
|
|
import arc.*;
|
|
|
|
import arc.assets.*;
|
|
|
|
import arc.assets.loaders.*;
|
|
|
|
import arc.audio.*;
|
|
|
|
import arc.graphics.*;
|
|
|
|
import arc.graphics.g2d.*;
|
|
|
|
import arc.math.*;
|
|
|
|
import arc.util.*;
|
|
|
|
import arc.util.async.*;
|
|
|
|
import mindustry.core.*;
|
2020-01-11 20:09:20 -05:00
|
|
|
import mindustry.ctype.*;
|
2019-12-25 01:39:38 -05:00
|
|
|
import mindustry.game.EventType.*;
|
|
|
|
import mindustry.gen.*;
|
|
|
|
import mindustry.graphics.*;
|
|
|
|
import mindustry.maps.*;
|
|
|
|
import mindustry.mod.*;
|
|
|
|
import mindustry.net.Net;
|
2020-01-17 18:08:23 -05:00
|
|
|
import mindustry.ui.*;
|
2017-05-03 00:09:48 -04:00
|
|
|
|
2019-12-25 01:39:38 -05:00
|
|
|
import static arc.Core.*;
|
|
|
|
import static mindustry.Vars.*;
|
2018-01-27 14:43:35 -05:00
|
|
|
|
2019-08-30 17:32:49 -04:00
|
|
|
public abstract class ClientLauncher extends ApplicationCore implements Platform{
|
2019-08-27 16:32:22 -04:00
|
|
|
private static final int loadingFPS = 20;
|
|
|
|
|
2019-07-03 19:11:22 -04:00
|
|
|
private long lastTime;
|
2019-08-27 16:32:22 -04:00
|
|
|
private long beginTime;
|
2019-08-26 13:15:53 -04:00
|
|
|
private boolean finished = false;
|
2020-05-06 19:07:37 -04:00
|
|
|
private LoadRenderer loader;
|
2018-01-27 23:42:42 -05:00
|
|
|
|
2018-12-26 17:38:40 -05:00
|
|
|
@Override
|
|
|
|
public void setup(){
|
2020-05-06 19:07:37 -04:00
|
|
|
loader = new LoadRenderer();
|
2020-02-13 09:11:35 -05:00
|
|
|
Events.fire(new ClientCreateEvent());
|
|
|
|
|
2019-12-08 15:17:14 -05:00
|
|
|
Vars.loadLogger();
|
2020-01-11 20:09:20 -05:00
|
|
|
Vars.loadFileLogger();
|
2019-08-30 17:32:49 -04:00
|
|
|
Vars.platform = this;
|
2019-08-27 16:32:22 -04:00
|
|
|
beginTime = Time.millis();
|
2019-08-26 13:15:53 -04:00
|
|
|
|
2018-12-20 12:38:27 -05:00
|
|
|
Time.setDeltaProvider(() -> {
|
|
|
|
float result = Core.graphics.getDeltaTime() * 60f;
|
2019-06-08 22:20:30 -04:00
|
|
|
return (Float.isNaN(result) || Float.isInfinite(result)) ? 1f : Mathf.clamp(result, 0.0001f, 60f / 10f);
|
2018-12-20 12:38:27 -05:00
|
|
|
});
|
|
|
|
|
2020-04-22 15:19:39 -04:00
|
|
|
batch = new SortedSpriteBatch();
|
2019-08-26 13:15:53 -04:00
|
|
|
assets = new AssetManager();
|
2019-08-27 18:25:38 -04:00
|
|
|
assets.setLoader(Texture.class, "." + mapExtension, new MapPreviewLoader());
|
2019-10-02 21:03:56 -04:00
|
|
|
|
|
|
|
tree = new FileTree();
|
|
|
|
assets.setLoader(Sound.class, new SoundLoader(tree));
|
|
|
|
assets.setLoader(Music.class, new MusicLoader(tree));
|
|
|
|
|
2019-09-17 21:55:57 -04:00
|
|
|
assets.load("sprites/error.png", Texture.class);
|
2019-08-26 13:15:53 -04:00
|
|
|
atlas = TextureAtlas.blankAtlas();
|
2019-09-07 14:11:50 -04:00
|
|
|
Vars.net = new Net(platform.getNet());
|
2019-10-02 21:03:56 -04:00
|
|
|
mods = new Mods();
|
2019-08-26 13:15:53 -04:00
|
|
|
|
2020-01-17 18:08:23 -05:00
|
|
|
Fonts.loadSystemCursors();
|
2019-08-27 16:32:22 -04:00
|
|
|
|
2019-08-27 09:27:09 -04:00
|
|
|
assets.load(new Vars());
|
2019-08-31 08:47:53 -04:00
|
|
|
|
2020-01-17 18:08:23 -05:00
|
|
|
Fonts.loadDefaultFont();
|
2019-08-31 08:47:53 -04:00
|
|
|
|
2019-09-08 22:32:47 -04:00
|
|
|
assets.load(new AssetDescriptor<>("sprites/sprites.atlas", TextureAtlas.class)).loaded = t -> {
|
|
|
|
atlas = (TextureAtlas)t;
|
2020-01-17 18:08:23 -05:00
|
|
|
Fonts.mergeFontAtlas(atlas);
|
2019-09-08 22:32:47 -04:00
|
|
|
};
|
2019-08-26 13:15:53 -04:00
|
|
|
|
2019-08-30 17:32:49 -04:00
|
|
|
assets.loadRun("maps", Map.class, () -> maps.loadPreviews());
|
2019-08-27 19:33:41 -04:00
|
|
|
|
2019-08-26 22:53:11 -04:00
|
|
|
Musics.load();
|
|
|
|
Sounds.load();
|
2019-08-26 08:10:27 -04:00
|
|
|
|
2019-08-27 19:33:41 -04:00
|
|
|
assets.loadRun("contentcreate", Content.class, () -> {
|
2019-12-07 14:10:39 -05:00
|
|
|
content.createBaseContent();
|
2019-08-27 19:33:41 -04:00
|
|
|
content.loadColors();
|
2019-12-07 14:10:39 -05:00
|
|
|
}, () -> {
|
|
|
|
mods.loadScripts();
|
|
|
|
content.createModContent();
|
2019-08-27 19:33:41 -04:00
|
|
|
});
|
|
|
|
|
2019-07-06 10:15:21 -04:00
|
|
|
add(logic = new Logic());
|
|
|
|
add(control = new Control());
|
|
|
|
add(renderer = new Renderer());
|
|
|
|
add(ui = new UI());
|
|
|
|
add(netServer = new NetServer());
|
|
|
|
add(netClient = new NetClient());
|
2019-08-26 22:53:11 -04:00
|
|
|
|
2019-09-29 15:21:50 -04:00
|
|
|
assets.load(mods);
|
2019-10-17 23:51:23 -04:00
|
|
|
assets.load(schematics);
|
2019-09-29 15:21:50 -04:00
|
|
|
|
2020-01-18 13:24:14 -05:00
|
|
|
assets.loadRun("contentinit", ContentLoader.class, () -> content.init(), () -> content.load());
|
2019-08-26 22:53:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void add(ApplicationListener module){
|
|
|
|
super.add(module);
|
|
|
|
|
|
|
|
//autoload modules when necessary
|
|
|
|
if(module instanceof Loadable){
|
|
|
|
assets.load((Loadable)module);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resize(int width, int height){
|
2019-09-03 19:14:33 -04:00
|
|
|
if(assets == null) return;
|
|
|
|
|
2019-11-17 11:20:36 -05:00
|
|
|
if(!finished){
|
2019-08-26 22:53:11 -04:00
|
|
|
Draw.proj().setOrtho(0, 0, width, height);
|
2019-09-01 00:45:54 -04:00
|
|
|
}else{
|
|
|
|
super.resize(width, height);
|
2019-08-26 22:53:11 -04:00
|
|
|
}
|
2018-07-27 17:26:12 -04:00
|
|
|
}
|
2018-06-11 15:18:25 -04:00
|
|
|
|
2019-07-03 19:11:22 -04:00
|
|
|
@Override
|
|
|
|
public void update(){
|
2019-08-27 17:44:25 -04:00
|
|
|
if(!finished){
|
2020-05-06 19:07:37 -04:00
|
|
|
loader.draw();
|
|
|
|
if(assets.update(1000 / loadingFPS) && false){
|
2020-05-03 21:18:25 -04:00
|
|
|
Log.info("Total time to load: @", Time.timeSinceMillis(beginTime));
|
2019-08-27 17:44:25 -04:00
|
|
|
for(ApplicationListener listener : modules){
|
|
|
|
listener.init();
|
|
|
|
}
|
2019-12-14 20:49:55 -05:00
|
|
|
mods.eachClass(Mod::init);
|
2019-08-26 13:15:53 -04:00
|
|
|
finished = true;
|
|
|
|
Events.fire(new ClientLoadEvent());
|
2019-10-18 19:31:01 -04:00
|
|
|
super.resize(graphics.getWidth(), graphics.getHeight());
|
|
|
|
app.post(() -> app.post(() -> app.post(() -> app.post(() -> super.resize(graphics.getWidth(), graphics.getHeight())))));
|
2019-08-26 13:15:53 -04:00
|
|
|
}
|
2019-08-27 17:44:25 -04:00
|
|
|
}else{
|
2020-04-30 20:03:11 -04:00
|
|
|
asyncLogic.begin();
|
|
|
|
|
2019-08-26 13:15:53 -04:00
|
|
|
super.update();
|
2020-04-30 20:03:11 -04:00
|
|
|
|
|
|
|
asyncLogic.end();
|
2019-08-26 13:15:53 -04:00
|
|
|
}
|
2019-07-03 19:11:22 -04:00
|
|
|
|
|
|
|
int targetfps = Core.settings.getInt("fpscap", 120);
|
|
|
|
|
2019-07-07 14:11:57 -04:00
|
|
|
if(targetfps > 0 && targetfps <= 240){
|
2019-07-03 19:11:22 -04:00
|
|
|
long target = (1000 * 1000000) / targetfps; //target in nanos
|
|
|
|
long elapsed = Time.timeSinceNanos(lastTime);
|
|
|
|
if(elapsed < target){
|
2019-10-18 20:11:02 -04:00
|
|
|
Threads.sleep((target - elapsed) / 1000000, (int)((target - elapsed) % 1000000));
|
2019-07-03 19:11:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastTime = Time.nanos();
|
|
|
|
}
|
|
|
|
|
2018-07-27 17:26:12 -04:00
|
|
|
@Override
|
2018-12-20 12:38:27 -05:00
|
|
|
public void init(){
|
2019-08-26 22:53:11 -04:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resume(){
|
|
|
|
if(finished){
|
|
|
|
super.resume();
|
|
|
|
}
|
2019-08-26 13:15:53 -04:00
|
|
|
}
|
|
|
|
|
2019-08-30 17:32:49 -04:00
|
|
|
@Override
|
|
|
|
public void pause(){
|
|
|
|
if(finished){
|
|
|
|
super.pause();
|
|
|
|
}
|
|
|
|
}
|
2017-05-03 00:09:48 -04:00
|
|
|
}
|