Successful desktop compilation

This commit is contained in:
Anuken
2018-12-26 17:38:40 -05:00
parent 8879593381
commit 3b42b604e1
53 changed files with 560 additions and 585 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ repositories {
dependencies {
implementation project(":core")
implementation project(":kryonet")
implementation project(":net")
implementation 'com.android.support:support-v4:28.0.0'
implementation 'org.sufficientlysecure:donations:2.5'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
@@ -129,7 +129,7 @@ public class RemoteWriteGenerator{
method.beginControlFlow("if(" + getCheckString(methodEntry.where) + ")");
//add statement to create packet from pool
method.addStatement("$1N packet = $2N.obtain($1N.class, $1N::new)", "io.anuke.mindustry.net.Packets.InvokePacket", "io.anuke.arc.util.Pooling");
method.addStatement("$1N packet = $2N.obtain($1N.class, $1N::new)", "io.anuke.mindustry.net.Packets.InvokePacket", "io.anuke.arc.util.pooling.Pools");
//assign buffer
method.addStatement("packet.writeBuffer = TEMP_BUFFER");
//assign priority
@@ -53,7 +53,7 @@ public class SerializeAnnotationProcessor extends AbstractProcessor{
TypeSpec.Builder serializer = TypeSpec.anonymousClassBuilder("")
.addSuperinterface(ParameterizedTypeName.get(
ClassName.bestGuess("io.anuke.arc.io.TypeSerializer"), type));
ClassName.bestGuess("io.anuke.arc.Settings.TypeSerializer"), type));
MethodSpec.Builder writeMethod = MethodSpec.methodBuilder("write")
.returns(void.class)
@@ -84,8 +84,8 @@ public class SerializeAnnotationProcessor extends AbstractProcessor{
writeMethod.addStatement("stream.write" + capName + "(object." + name + ")");
readMethod.addStatement("object." + name + "= stream.read" + capName + "()");
}else{
writeMethod.addStatement("io.anuke.arc.core.Core.settings.getSerializer(" + typeName+ ".class).write(stream, object." + name + ")");
readMethod.addStatement("object." + name + " = (" +typeName+")io.anuke.arc.core.Core.settings.getSerializer(" + typeName+ ".class).read(stream)");
writeMethod.addStatement("io.anuke.arc.Core.settings.getSerializer(" + typeName+ ".class).write(stream, object." + name + ")");
readMethod.addStatement("object." + name + " = (" +typeName+")io.anuke.arc.Core.settings.getSerializer(" + typeName+ ".class).read(stream)");
}
}
@@ -94,7 +94,7 @@ public class SerializeAnnotationProcessor extends AbstractProcessor{
serializer.addMethod(writeMethod.build());
serializer.addMethod(readMethod.build());
method.addStatement("io.anuke.arc.core.Core.settings.setSerializer($N, $L)", Utils.elementUtils.getBinaryName(elem).toString().replace('$', '.') + ".class", serializer.build());
method.addStatement("io.anuke.arc.Core.settings.setSerializer($N, $L)", Utils.elementUtils.getBinaryName(elem).toString().replace('$', '.') + ".class", serializer.build());
}
classBuilder.addMethod(method.build());
+7 -16
View File
@@ -88,13 +88,13 @@ project(":desktop"){
dependencies{
compile project(":core")
compile project(":kryonet")
compile project(":net")
if(new File(projectDir.parent, '../debug').exists() && System.properties["release"] == null) compile project(":debug")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile project(":Arc:backends:backend-lwjgl3")
compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.0'
}
}
@@ -145,7 +145,7 @@ project(":ios"){
dependencies{
compile project(":core")
implementation project(":kryonet")
implementation project(":net")
compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
@@ -170,21 +170,12 @@ project(":core"){
if(new File(projectDir.parent, '../Arc').exists() && comp){
compile project(":Arc:arc-core")
//compile project(":Arc:extensions:freetype")
compile project(":Arc:extensions:freetype")
}else{
//TODO compile arc from jitpack
//compile 'com.github.Anuken.Arc:arc:-SNAPSHOT'
}
// if(new File(projectDir.parent, '../GDXGifRecorder').exists() && comp){
// compile project(":GDXGifRecorder")
// }
//compile "com.badlogicgames.gdx:gdx:$gdxVersion"
//compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
//compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compileOnly project(":annotations")
annotationProcessor project(":annotations")
}
@@ -196,7 +187,7 @@ project(":server"){
dependencies{
compile project(":core")
compile project(":kryonet")
compile project(":net")
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
@@ -235,7 +226,7 @@ project(":annotations"){
}
}
project(":kryonet"){
project(":net"){
apply plugin: "java"
dependencies{

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

+15 -13
View File
@@ -1,6 +1,6 @@
package io.anuke.mindustry;
import io.anuke.arc.ApplicationListener;
import io.anuke.arc.ApplicationCore;
import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.util.Log;
@@ -11,10 +11,10 @@ import io.anuke.mindustry.io.BundleLoader;
import static io.anuke.mindustry.Vars.*;
public class Mindustry implements ApplicationListener{
private long lastFrameTime;
public class Mindustry extends ApplicationCore{
public Mindustry(){
@Override
public void setup(){
Time.setDeltaProvider(() -> {
float result = Core.graphics.getDeltaTime() * 60f;
return Float.isNaN(result) || Float.isInfinite(result) ? 1f : Math.min(result, 60f / 10f);
@@ -28,26 +28,28 @@ public class Mindustry implements ApplicationListener{
BundleLoader.load();
content.load();
Core.app.addListener(logic = new Logic());
Core.app.addListener(world = new World());
Core.app.addListener(control = new Control());
Core.app.addListener(renderer = new Renderer());
Core.app.addListener(ui = new UI());
Core.app.addListener(netServer = new NetServer());
Core.app.addListener(netClient = new NetClient());
add(logic = new Logic());
add(world = new World());
add(control = new Control());
add(renderer = new Renderer());
add(ui = new UI());
add(netServer = new NetServer());
add(netClient = new NetClient());
}
@Override
public void init(){
super.init();
Log.info("Time to load [total]: {0}", Time.elapsed());
Events.fire(new GameLoadEvent());
}
@Override
public void update(){
lastFrameTime = Time.millis();
long lastFrameTime = Time.millis();
//TODO ??render it all??
super.update();
int fpsCap = Core.settings.getInt("fpscap", 125);
@@ -2,7 +2,7 @@ package io.anuke.mindustry.content;
import io.anuke.arc.Core;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.Graphics;
import io.anuke.arc.graphics.Blending;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
@@ -202,14 +202,14 @@ public class Mechs implements ContentList{
public void draw(Player player){
if(player.shootHeat <= 0.01f) return;
float alpha = Core.batch.getColor().a;
float alpha = Core.graphics.batch().getColor().a;
Shaders.build.progress = player.shootHeat;
Shaders.build.region = armorRegion;
Shaders.build.time = Time.time() / 10f;
Shaders.build.color.set(Palette.accent).a = player.shootHeat;
Draw.shader(Shaders.build);
Draw.alpha(1f);
Draw.rect(armorRegion, player.snappedX(), player.snappedY(), player.rotation);
Draw.rect(armorRegion, player.snappedX(), player.snappedY()).rot(player.rotation);
Draw.shader(Shaders.mix);
Draw.color(1f, 1f, 1f, alpha);
}
@@ -268,13 +268,11 @@ public class Mechs implements ContentList{
public void draw(Player player){
float scl = scld(player);
if(scl < 0.01f) return;
float alpha = Core.batch.getColor().a;
float alpha = Core.graphics.batch().getColor().a;
Draw.shader();
Graphics.setAdditiveBlending();
Draw.color(Palette.lancerLaser);
Draw.alpha(scl/2f);
Draw.rect(shield, player.snappedX() + Mathf.range(scl/2f), player.snappedY() + Mathf.range(scl/2f), player.rotation - 90);
Graphics.setNormalBlending();
Draw.rect(shield, player.snappedX() + Mathf.range(scl/2f), player.snappedY() + Mathf.range(scl/2f)).rot(player.rotation - 90).blend(Blending.additive);
Draw.shader(Shaders.mix);
Draw.color();
Draw.alpha(alpha);
@@ -58,7 +58,7 @@ public class TurretBlocks extends BlockList implements ContentList{
ammoUseEffect = ShootFx.shellEjectSmall;
health = 160;
drawer = (tile, entity) -> Draw.rect(entity.target != null ? shootRegion : region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
drawer = (tile, entity) -> Draw.rect(entity.target != null ? shootRegion : region, tile.drawx() + tr2.x, tile.drawy() + tr2.y).rot(entity.rotation - 90);
}
};
@@ -157,20 +157,25 @@ public class TurretBlocks extends BlockList implements ContentList{
ammoUseEffect = ShootFx.shellEjectBig;
drawer = (tile, entity) -> {
Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
float offsetx = (int) (Mathf.abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 3f);
float offsety = -(int) (Mathf.abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 2f);
Draw.rect(region, tile.drawx() + tr2.x, tile.drawy() + tr2.y).rot(entity.rotation - 90);
float offsetx = (int) (abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 3f);
float offsety = -(int) (abscurve(Mathf.curve(entity.reload / reload, 0.3f, 0.2f)) * 2f);
for(int i : Mathf.signs){
float rot = entity.rotation + 90 * i;
Draw.rect(panels[i == -1 ? 0 : 1],
tile.drawx() + tr2.x + Angles.trnsx(rot, offsetx, offsety),
tile.drawy() + tr2.y + Angles.trnsy(rot, -offsetx, offsety), entity.rotation - 90);
tile.drawy() + tr2.y + Angles.trnsy(rot, -offsetx, offsety)).rot(entity.rotation - 90);
}
};
health = 360;
}
/** Converts a value range from 0-1 to a value range 0-1-0. */
float abscurve(float f){
return 1f - Math.abs(f - 0.5f) * 2f;
}
};
ripple = new ArtilleryTurret("ripple"){{
@@ -1,6 +1,14 @@
package io.anuke.mindustry.content.bullets;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.CapStyle;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.BlockFx;
@@ -15,14 +23,10 @@ import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.Lightning;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Shapes;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BuildBlock;
import io.anuke.mindustry.world.blocks.distribution.MassDriver.DriverBulletData;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.util.Time;
import io.anuke.arc.graphics.*;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.world;
@@ -342,10 +346,10 @@ public class TurretBullets extends BulletList implements ContentList{
float w = 11f, h = 13f;
Draw.color(Palette.bulletYellowBack);
Draw.rect("shell-back", b.x, b.y, w, h, b.angle() + 90);
Draw.rect("shell-back", b.x, b.y, w, h).rot(b.angle() + 90);
Draw.color(Palette.bulletYellow);
Draw.rect("shell", b.x, b.y, w, h, b.angle() + 90);
Draw.rect("shell", b.x, b.y, w, h).rot(b.angle() + 90);
Draw.reset();
}
@@ -379,7 +383,7 @@ public class TurretBullets extends BulletList implements ContentList{
float baseAngle = data.to.angleTo(data.from);
//if angles are nearby, then yes, it did
if(Mathf.angNear(angleTo, baseAngle, 2f)){
if(Angles.near(angleTo, baseAngle, 2f)){
intersect = true;
//snap bullet position back; this is used for low-FPS situations
b.set(data.to.x + Angles.trnsx(baseAngle, hitDst), data.to.y + Angles.trnsy(baseAngle, hitDst));
@@ -263,14 +263,14 @@ public class BlockFx extends FxList implements ContentList{
Draw.reset();
});
ripple = new GroundEffect(false, 30, e -> {
Draw.color(Hue.shift(Tmp.c1.set(e.color), 2, 0.1f));
Draw.color(Tmp.c1.set(e.color).shiftValue(0.1f));
Lines.stroke(e.fout() + 0.4f);
Lines.circle(e.x, e.y, 2f + e.fin() * 4f);
Draw.reset();
});
bubble = new Effect(20, e -> {
Draw.color(Hue.shift(Tmp.c1.set(e.color), 2, 0.1f));
Draw.color(Tmp.c1.set(e.color).shiftValue(0.1f));
Lines.stroke(e.fout() + 0.2f);
Angles.randLenVectors(e.id, 2, 8f, (x, y) -> {
Lines.circle(e.x + x, e.y + y, 1f + e.fin() * 3f);
@@ -4,6 +4,7 @@ import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.game.ContentList;
@@ -1,16 +1,16 @@
package io.anuke.mindustry.content.fx;
import io.anuke.arc.graphics.Color;
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.game.ContentList;
import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.graphics.Shapes;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Shapes;
public class ShootFx extends FxList implements ContentList{
public static Effect shootSmall, shootHeal, shootSmallSmoke, shootBig, shootBig2, shootBigSmoke, shootBigSmoke2, shootSmallFlame, shootLiquid, shellEjectSmall, shellEjectMedium, shellEjectBig, lancerLaserShoot, lancerLaserShootSmoke, lancerLaserCharge, lancerLaserChargeBegin, lightningCharge, lightningShoot;
@@ -111,7 +111,7 @@ public class ShootFx extends FxList implements ContentList{
Draw.rect("white",
e.x + Angles.trnsx(lr, len) + Mathf.randomSeedRange(e.id + i + 7, 3f * e.fin()),
e.y + Angles.trnsy(lr, len) + Mathf.randomSeedRange(e.id + i + 8, 3f * e.fin()),
1f, 2f, rot + e.fin() * 50f * i);
1f, 2f).rot(rot + e.fin() * 50f * i);
Draw.color();
});
@@ -125,7 +125,7 @@ public class ShootFx extends FxList implements ContentList{
Draw.rect("casing",
e.x + Angles.trnsx(lr, len) + Mathf.randomSeedRange(e.id + i + 7, 3f * e.fin()),
e.y + Angles.trnsy(lr, len) + Mathf.randomSeedRange(e.id + i + 8, 3f * e.fin()),
2f, 3f, rot);
2f, 3f).rot(rot);
}
Draw.color(Color.LIGHT_GRAY, Color.GRAY, e.fin());
@@ -148,8 +148,8 @@ public class ShootFx extends FxList implements ContentList{
Draw.rect("casing",
e.x + Angles.trnsx(lr, len) + Mathf.randomSeedRange(e.id + i + 7, 3f * e.fin()),
e.y + Angles.trnsy(lr, len) + Mathf.randomSeedRange(e.id + i + 8, 3f * e.fin()),
2.5f, 4f,
rot + e.fin() * 30f * i + Mathf.randomSeedRange(e.id + i + 9, 40f * e.fin()));
2.5f, 4f)
.rot(rot + e.fin() * 30f * i + Mathf.randomSeedRange(e.id + i + 9, 40f * e.fin()));
}
Draw.color(Color.LIGHT_GRAY);
@@ -57,11 +57,12 @@ public class Control implements ApplicationListener{
unlocks = new Unlocks();
Core.input.setCatch(KeyCode.BACK, true);
Core.keybinds.setDefaults(Binding.values());
Effects.setShakeFalloff(10000f);
content.initialize(Content::init);
Core.atlas = new TextureAtlas("sprites.atlas");
Core.atlas = new TextureAtlas("sprites/sprites.atlas");
content.initialize(Content::load);
unlocks.load();
@@ -10,6 +10,7 @@ import io.anuke.arc.entities.trait.DrawTrait;
import io.anuke.arc.entities.trait.Entity;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.function.Predicate;
import io.anuke.arc.graphics.Camera;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Lines;
@@ -37,7 +38,6 @@ public class Renderer implements ApplicationListener{
public final BlockRenderer blocks = new BlockRenderer();
public final MinimapRenderer minimap = new MinimapRenderer();
public final OverlayRenderer overlays = new OverlayRenderer();
public final FogRenderer fog = new FogRenderer();
private Color clearColor;
private int targetscale = baseCameraScale;
@@ -45,6 +45,7 @@ public class Renderer implements ApplicationListener{
private Vector2 avgPosition = new Vector2();
public Renderer(){
camera = new Camera();
Lines.setCircleVertices(14);
Shaders.init();
@@ -285,11 +286,6 @@ public class Renderer implements ApplicationListener{
camera.resize(width, height);
}
@Override
public void dispose(){
fog.dispose();
}
public Vector2 averagePosition(){
avgPosition.setZero();
+19 -10
View File
@@ -5,6 +5,8 @@ import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.Graphics.Cursor;
import io.anuke.arc.Graphics.Cursor.SystemCursor;
import io.anuke.arc.freetype.FreeTypeFontGenerator;
import io.anuke.arc.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.Colors;
@@ -24,7 +26,6 @@ import io.anuke.arc.scene.ui.layout.Unit;
import io.anuke.arc.util.Align;
import io.anuke.arc.util.Strings;
import io.anuke.arc.util.Time;
import io.anuke.arc.freetype.*;
import io.anuke.mindustry.editor.MapEditorDialog;
import io.anuke.mindustry.game.EventType.ResizeEvent;
import io.anuke.mindustry.graphics.Palette;
@@ -32,17 +33,18 @@ import io.anuke.mindustry.ui.dialogs.*;
import io.anuke.mindustry.ui.fragments.*;
import static io.anuke.arc.scene.actions.Actions.*;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.disableUI;
public class UI implements ApplicationListener{
private FreeTypeFontGenerator generator;
public final MenuFragment menufrag = new MenuFragment();
public final HudFragment hudfrag = new HudFragment();
public final ChatFragment chatfrag = new ChatFragment();
public final PlayerListFragment listfrag = new PlayerListFragment();
public final BackgroundFragment backfrag = new BackgroundFragment();
public final LoadingFragment loadfrag = new LoadingFragment();
public MenuFragment menufrag;
public HudFragment hudfrag;
public ChatFragment chatfrag;
public PlayerListFragment listfrag;
public BackgroundFragment backfrag;
public LoadingFragment loadfrag;
public AboutDialog about;
public RestartDialog restart;
@@ -71,7 +73,7 @@ public class UI implements ApplicationListener{
public UI(){
Skin skin = new Skin(Core.atlas);
generateFonts();
generateFonts(skin);
skin.load(Core.files.internal("ui/uiskin.json"));
for(BitmapFont font : skin.getAll(BitmapFont.class).values()){
@@ -120,7 +122,7 @@ public class UI implements ApplicationListener{
Core.graphics.restoreCursor();
}
void generateFonts(){
void generateFonts(Skin skin){
generator = new FreeTypeFontGenerator(Core.files.internal("fonts/pixel.ttf"));
FreeTypeFontParameter param = new FreeTypeFontParameter();
param.size = (int)(14*2 * Math.max(Unit.dp.scl(1f), 0.5f));
@@ -145,6 +147,13 @@ public class UI implements ApplicationListener{
@Override
public void init(){
menufrag = new MenuFragment();
hudfrag = new HudFragment();
chatfrag = new ChatFragment();
listfrag = new PlayerListFragment();
backfrag = new BackgroundFragment();
loadfrag = new LoadingFragment();
editor = new MapEditorDialog();
controls = new ControlsDialog();
restart = new RestartDialog();
@@ -1,21 +1,20 @@
package io.anuke.mindustry.editor;
import io.anuke.arc.Core;
import io.anuke.arc.collection.IntSet;
import io.anuke.arc.collection.IntSet.IntSetIterator;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.util.Disposable;
import io.anuke.arc.util.IntSet;
import io.anuke.arc.util.IntSet.IntSetIterator;
import io.anuke.arc.util.Pack;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.IndexedRenderer;
import io.anuke.mindustry.maps.MapTileData.DataPosition;
import io.anuke.mindustry.world.Block;
import io.anuke.arc.Core;
import io.anuke.arc.Graphics;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.IndexedRenderer;
import io.anuke.arc.util.Structs;
import io.anuke.arc.util.Bits;
import io.anuke.arc.math.geom.Geometry;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.tilesize;
@@ -56,7 +55,7 @@ public class MapRenderer implements Disposable{
public void draw(float tx, float ty, float tw, float th){
Graphics.end();
Draw.flush();
IntSetIterator it = updates.iterator();
while(it.hasNext){
@@ -79,15 +78,12 @@ public class MapRenderer implements Disposable{
mesh = chunks[x][y];
}
mesh.getTransformMatrix().setToTranslation(tx, ty, 0).scl(tw / (width * tilesize),
th / (height * tilesize), 1f);
mesh.setProjectionMatrix(Core.batch.getProjectionMatrix());
mesh.getTransformMatrix().setToTranslation(tx, ty).scale(tw / (width * tilesize), th / (height * tilesize));
mesh.setProjectionMatrix(Core.graphics.batch().getProjection());
mesh.render(Core.atlas.getTextures().first());
}
}
Graphics.begin();
}
public void updatePoint(int x, int y){
+28 -58
View File
@@ -1,32 +1,27 @@
package io.anuke.mindustry.editor;
import io.anuke.arc.Input.Buttons;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Batch;
import io.anuke.arc.input.GestureDetector;
import io.anuke.arc.input.GestureDetector.GestureListener;
import io.anuke.arc.math.Bresenham2;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.collection.Array;
import io.anuke.mindustry.editor.DrawOperation.TileOperation;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.ui.GridImage;
import io.anuke.arc.Core;
import io.anuke.arc.Graphics;
import io.anuke.arc.Inputs;
import io.anuke.arc.collection.Array;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.graphics.g2d.ScissorStack;
import io.anuke.arc.input.GestureDetector;
import io.anuke.arc.input.GestureDetector.GestureListener;
import io.anuke.arc.input.KeyCode;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.*;
import io.anuke.arc.scene.Element;
import io.anuke.arc.scene.event.InputEvent;
import io.anuke.arc.scene.event.InputListener;
import io.anuke.arc.scene.event.Touchable;
import io.anuke.arc.scene.ui.TextField;
import io.anuke.arc.scene.ui.layout.Unit;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Tmp;
import io.anuke.mindustry.editor.DrawOperation.TileOperation;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.input.Binding;
import io.anuke.mindustry.ui.GridImage;
import static io.anuke.mindustry.Vars.mobile;
import static io.anuke.mindustry.Vars.ui;
@@ -60,7 +55,7 @@ public class MapView extends Element implements GestureListener{
brushPolygons[i] = Geometry.pixelCircle(size, (index, x, y) -> Mathf.dst(x, y, index, index) <= index - 0.5f);
}
Core.input.addProcessor(0, new GestureDetector(20, 0.5f, 2, 0.15f, this));
Core.input.getInputProcessors().insert(0, new GestureDetector(20, 0.5f, 2, 0.15f, this));
touchable(Touchable.enabled);
addListener(new InputListener(){
@@ -74,16 +69,16 @@ public class MapView extends Element implements GestureListener{
}
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
if(pointer != 0){
return false;
}
if(!mobile && button != Buttons.LEFT && button != Buttons.MIDDLE){
if(!mobile && button != KeyCode.MOUSE_LEFT && button != KeyCode.MOUSE_MIDDLE){
return true;
}
if(button == Buttons.MIDDLE){
if(button == KeyCode.MOUSE_MIDDLE){
lastTool = tool;
tool = EditorTool.zoom;
}
@@ -112,8 +107,8 @@ public class MapView extends Element implements GestureListener{
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button){
if(!mobile && button != Buttons.LEFT && button != Buttons.MIDDLE){
public void touchUp(InputEvent event, float x, float y, int pointer, KeyCode button){
if(!mobile && button != KeyCode.MOUSE_LEFT && button != KeyCode.MOUSE_MIDDLE){
return;
}
@@ -214,16 +209,16 @@ public class MapView extends Element implements GestureListener{
super.act(delta);
if(Core.scene.getKeyboardFocus() == null || !(Core.scene.getKeyboardFocus() instanceof TextField) &&
!Core.input.keyDown(io.anuke.arc.input.Input.CONTROL_LEFT)){
float ax = Core.input.getAxis("move_x");
float ay = Core.input.getAxis("move_y");
!Core.input.keyDown(KeyCode.CONTROL_LEFT)){
float ax = Core.input.axis(Binding.move_x);
float ay = Core.input.axis(Binding.move_y);
offsetx -= ax * 15f / zoom;
offsety -= ay * 15f / zoom;
}
if(ui.editor.hasPane()) return;
zoom += Core.input.scroll() / 10f * zoom;
zoom += Core.input.axis(KeyCode.SCROLL) / 10f * zoom;
clampZoom();
}
@@ -258,7 +253,7 @@ public class MapView extends Element implements GestureListener{
}
@Override
public void draw(Batch batch, float alpha){
public void draw(){
float ratio = 1f / ((float) editor.getMap().width() / editor.getMap().height());
float size = Math.min(width, height);
float sclwidth = size * zoom;
@@ -268,7 +263,9 @@ public class MapView extends Element implements GestureListener{
image.setImageSize(editor.getMap().width(), editor.getMap().height());
Graphics.beginClip(x, y, width, height);
if(!ScissorStack.pushScissors(rect.set(x, y, width, height))){
return;
}
Draw.color(Palette.remove);
Lines.stroke(2f);
@@ -279,7 +276,7 @@ public class MapView extends Element implements GestureListener{
if(grid){
Draw.color(Color.GRAY);
image.setBounds(centerx - sclwidth / 2, centery - sclheight / 2, sclwidth, sclheight);
image.draw(batch, alpha);
image.draw();
Draw.color();
}
@@ -323,8 +320,6 @@ public class MapView extends Element implements GestureListener{
}
}
Graphics.endClip();
Draw.color(Palette.accent);
Lines.stroke(Unit.dp.scl(3f));
Lines.rect(x, y, width, height);
@@ -335,27 +330,7 @@ public class MapView extends Element implements GestureListener{
return Core.scene.getKeyboardFocus() != null
&& Core.scene.getKeyboardFocus().isDescendantOf(ui.editor)
&& ui.editor.isShown() && tool == EditorTool.zoom &&
Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true) == this;
}
@Override
public boolean touchDown(float x, float y, int pointer, int button){
return false;
}
@Override
public boolean tap(float x, float y, int count, int button){
return false;
}
@Override
public boolean longPress(float x, float y){
return false;
}
@Override
public boolean fling(float velocityX, float velocityY, int button){
return false;
Core.scene.hit(Core.input.mouse().x, Core.input.mouse().y, true) == this;
}
@Override
@@ -366,11 +341,6 @@ public class MapView extends Element implements GestureListener{
return false;
}
@Override
public boolean panStop(float x, float y, int pointer, int button){
return false;
}
@Override
public boolean zoom(float initialDistance, float distance){
if(!active()) return false;
@@ -34,9 +34,9 @@ public class ArtilleryBulletType extends BasicBulletType{
float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout());
Draw.color(backColor);
Draw.rect(backRegion, b.x, b.y, bulletWidth * scale, height * scale, b.angle() - 90);
Draw.rect(backRegion, b.x, b.y, bulletWidth * scale, height * scale).rot(b.angle() - 90);
Draw.color(frontColor);
Draw.rect(frontRegion, b.x, b.y, bulletWidth * scale, height * scale, b.angle() - 90);
Draw.rect(frontRegion, b.x, b.y, bulletWidth * scale, height * scale).rot(b.angle() - 90);
Draw.color();
}
}
@@ -8,7 +8,7 @@ import io.anuke.arc.entities.EntityGroup;
import io.anuke.arc.entities.impl.TimedEntity;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.util.Structs;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.pooling.Pool.Poolable;
@@ -22,6 +22,7 @@ import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.game.EventType.BuildSelectEvent;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Shapes;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Recipe;
@@ -353,8 +354,8 @@ public interface BuilderTrait extends Entity{
float ey = tile.worldy() + Mathf.sin(Time.time() + 48, swingScl + 2f, swingMag);
Draw.color(Color.LIGHT_GRAY, Color.WHITE, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl));
//TODO better laser drawing functions
//Shapes.laser("minelaser", "minelaser-end", px, py, ex, ey);
Shapes.laser("minelaser", "minelaser-end", px, py, ex, ey);
if(unit instanceof Player && ((Player) unit).isLocal){
Lines.stroke(1f, Palette.accent);
@@ -1,7 +1,11 @@
package io.anuke.mindustry.entities.units;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Predict;
import io.anuke.mindustry.entities.TileEntity;
@@ -12,11 +16,6 @@ import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.arc.util.Time;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.math.Angles;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Vector2;
import java.io.DataInput;
import java.io.DataOutput;
@@ -155,7 +154,7 @@ public abstract class GroundUnit extends BaseUnit{
Draw.rect(type.legRegion,
x + Angles.trnsx(baseRotation, ft * i),
y + Angles.trnsy(baseRotation, ft * i),
12f * i, 12f - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
12f * i, 12f - Mathf.clamp(ft * i, 0, 2)).rot(baseRotation - 90);
}
if(floor.isLiquid){
@@ -164,16 +163,16 @@ public abstract class GroundUnit extends BaseUnit{
Draw.tint(Color.WHITE);
}
Draw.rect(type.baseRegion, x, y, baseRotation - 90);
Draw.rect(type.baseRegion, x, y).rot(baseRotation - 90);
Draw.rect(type.region, x, y, rotation - 90);
Draw.rect(type.region, x, y).rot(rotation - 90);
for(int i : Mathf.signs){
float tra = rotation - 90, trY = -weapon.getRecoil(this, i > 0) + type.weaponOffsetY;
float w = i > 0 ? -12 : 12;
Draw.rect(weapon.equipRegion,
x + Angles.trnsx(tra, type.weaponOffsetX * i, trY),
y + Angles.trnsy(tra, type.weaponOffsetX * i, trY), w, 12, rotation - 90);
y + Angles.trnsy(tra, type.weaponOffsetX * i, trY), w, 12).rot(rotation - 90);
}
drawItems();
@@ -191,7 +190,7 @@ public abstract class GroundUnit extends BaseUnit{
if(dst(target) < getWeapon().getAmmo().getRange()){
rotate(angleTo(target));
if(Mathf.angNear(angleTo(target), rotation, 13f)){
if(Angles.near(angleTo(target), rotation, 13f)){
AmmoType ammo = getWeapon().getAmmo();
Vector2 to = Predict.intercept(GroundUnit.this, target, ammo.bullet.speed);
@@ -163,7 +163,6 @@ public class Saves{
public void save(){
long time = totalPlaytime;
renderer.fog.writeFog();
long prev = totalPlaytime;
totalPlaytime = time;
@@ -2,19 +2,22 @@ package io.anuke.mindustry.graphics;
import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.Graphics;
import io.anuke.arc.collection.IntArray;
import io.anuke.arc.collection.IntSet;
import io.anuke.arc.collection.IntSet.IntSetIterator;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.graphics.Camera;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.GL20;
import io.anuke.arc.graphics.g2d.CacheBatch;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.g2d.SpriteBatch;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Structs;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
import io.anuke.mindustry.maps.Sector;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
@@ -33,7 +36,7 @@ public class FloorRenderer{
private IntArray drawnLayers = new IntArray();
public FloorRenderer(){
Events.on(WorldLoadGraphicsEvent.class, event -> clearTiles());
Events.on(WorldLoadEvent.class, event -> clearTiles());
}
public void drawFloor(){
@@ -41,13 +44,13 @@ public class FloorRenderer{
return;
}
OrthographicCamera camera = Core.camera;
Camera camera = Core.camera;
int crangex = (int) (camera.width / (chunksize * tilesize)) + 1;
int crangey = (int) (camera.height / (chunksize * tilesize)) + 1;
int camx = Mathf.scl(camera.position.x, chunksize * tilesize);
int camy = Mathf.scl(camera.position.y, chunksize * tilesize);
int camx = (int)(camera.position.x / (chunksize * tilesize));
int camy = (int)(camera.position.y / (chunksize * tilesize));
int layers = CacheLayer.values().length;
@@ -81,7 +84,7 @@ public class FloorRenderer{
drawnLayers.sort();
Graphics.end();
Draw.flush();
beginDraw();
for(int i = 0; i < drawnLayers.size; i++){
@@ -91,7 +94,6 @@ public class FloorRenderer{
}
endDraw();
Graphics.begin();
}
public void beginDraw(){
@@ -99,7 +101,7 @@ public class FloorRenderer{
return;
}
cbatch.setProjectionMatrix(Core.camera.combined);
cbatch.setProjection(Core.camera.projection());
cbatch.beginDraw();
Core.gl.glEnable(GL20.GL_BLEND);
@@ -118,7 +120,7 @@ public class FloorRenderer{
return;
}
OrthographicCamera camera = Core.camera;
Camera camera = Core.camera;
int crangex = (int) (camera.width / (chunksize * tilesize)) + 1;
int crangey = (int) (camera.height / (chunksize * tilesize)) + 1;
@@ -127,8 +129,8 @@ public class FloorRenderer{
for(int x = -crangex; x <= crangex; x++){
for(int y = -crangey; y <= crangey; y++){
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y;
int worldx = (int)(camera.position.x / (chunksize * tilesize)) + x;
int worldy = (int)(camera.position.y / (chunksize * tilesize)) + y;
if(!Structs.inBounds(worldx, worldy, cache)){
continue;
@@ -145,7 +147,7 @@ public class FloorRenderer{
private void fillChunk(float x, float y){
Draw.color(Color.BLACK);
Fill.crect(x, y, chunksize * tilesize, chunksize * tilesize);
Fill.rect().set(x, y, chunksize * tilesize, chunksize * tilesize);
Draw.color();
}
@@ -172,11 +174,8 @@ public class FloorRenderer{
}
private void cacheChunkLayer(int cx, int cy, Chunk chunk, CacheLayer layer){
Graphics.useBatch(cbatch);
cbatch.begin();
Sector sector = world.getSector();
SpriteBatch current = Core.graphics.batch();
Core.graphics.useBatch(cbatch);
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
@@ -196,10 +195,8 @@ public class FloorRenderer{
}
}
}
cbatch.end();
Graphics.popBatch();
chunk.caches[layer.ordinal()] = cbatch.getLastCache();
Core.graphics.useBatch(current);
chunk.caches[layer.ordinal()] = cbatch.flushCache();
}
public void clearTiles(){
@@ -1,176 +0,0 @@
package io.anuke.mindustry.graphics;
import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.Graphics;
import io.anuke.arc.collection.Array;
import io.anuke.arc.entities.EntityDraw;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.GL20;
import io.anuke.arc.graphics.Pixmap.Format;
import io.anuke.arc.graphics.Texture;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Fill;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.graphics.glutils.FrameBuffer;
import io.anuke.arc.util.Disposable;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.game.EventType.TileChangeEvent;
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
import io.anuke.mindustry.world.Tile;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.*;
/**Used for rendering fog of war. A framebuffer is used for this.*/
public class FogRenderer implements Disposable{
private TextureRegion region = new TextureRegion();
private FrameBuffer buffer;
private ByteBuffer pixelBuffer;
private Array<Tile> changeQueue = new Array<>();
private int shadowPadding;
private boolean dirty;
public FogRenderer(){
Events.on(WorldLoadEvent.class, event -> {
dispose();
shadowPadding = -1;
buffer = new FrameBuffer(Format.RGBA8888, world.width(), world.height(), false);
changeQueue.clear();
//clear buffer to black
buffer.begin();
Core.graphics.clear(0, 0, 0, 1f);
buffer.end();
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
if(tile.getTeam() == players[0].getTeam() && tile.block().synthetic() && tile.block().viewRange > 0){
changeQueue.add(tile);
}
}
}
pixelBuffer = ByteBuffer.allocateDirect(world.width() * world.height() * 4);
dirty = true;
});
Events.on(TileChangeEvent.class, event -> {
if(event.tile.getTeam() == players[0].getTeam() && event.tile.block().synthetic() && event.tile.block().viewRange > 0){
changeQueue.add(event.tile);
}
});
}
public void writeFog(){
if(buffer == null) return;
buffer.begin();
pixelBuffer.position(0);
Core.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);
Core.gl.glReadPixels(0, 0, world.width(), world.height(), GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);
pixelBuffer.position(0);
for(int i = 0; i < world.width() * world.height(); i++){
int x = i % world.width();
int y = i / world.width();
byte r = pixelBuffer.get();
if(r != 0){
world.tile(x, y).setVisibility((byte)1);
}
pixelBuffer.position(pixelBuffer.position() + 3);
}
buffer.end();
}
public int getPadding(){
return -shadowPadding;
}
public void draw(){
if(buffer == null) return;
float vw = Core.camera.width ;
float vh = Core.camera.height ;
float px = Core.camera.position.x - vw / 2f;
float py = Core.camera.position.y - vh / 2f;
float u = (px / tilesize) / buffer.getWidth();
float v = (py / tilesize) / buffer.getHeight();
float u2 = ((px + vw) / tilesize) / buffer.getWidth();
float v2 = ((py + vh) / tilesize) / buffer.getHeight();
Core.batch.getProjectionMatrix().setToOrtho2D(0, 0, buffer.getWidth() * tilesize, buffer.getHeight() * tilesize);
Draw.color(Color.WHITE);
buffer.begin();
Graphics.beginClip((-shadowPadding), (-shadowPadding), (world.width() + shadowPadding*2), (world.height() + shadowPadding*2));
Graphics.begin();
EntityDraw.setClip(false);
renderer.drawAndInterpolate(playerGroup, player -> !player.isDead() && player.getTeam() == players[0].getTeam(), Unit::drawView);
renderer.drawAndInterpolate(unitGroups[players[0].getTeam().ordinal()], unit -> !unit.isDead(), Unit::drawView);
for(Tile tile : changeQueue){
float viewRange = tile.block().viewRange;
if(viewRange < 0) continue;
Fill.circle(tile.drawx(), tile.drawy(), tile.block().viewRange);
}
changeQueue.clear();
if(dirty){
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
if(tile.discovered()){
Fill.rect(tile.worldx(), tile.worldy(), tilesize, tilesize);
}
}
}
dirty = false;
}
EntityDraw.setClip(true);
Graphics.end();
buffer.end();
Graphics.endClip();
region.setTexture(buffer.getTexture());
region.setRegion(u, v2, u2, v);
Core.batch.setProjectionMatrix(Core.camera.combined);
Draw.shader(Shaders.fog);
renderer.pixelSurface.getBuffer().begin();
Graphics.begin();
Core.batch.draw(region, px, py, vw, vh);
Graphics.end();
renderer.pixelSurface.getBuffer().end();
Draw.shader();
Graphics.setScreen();
Core.batch.draw(renderer.pixelSurface.texture(), 0, Core.graphics.getHeight(), Core.graphics.getWidth(), -Core.graphics.getHeight());
Graphics.end();
}
public Texture getTexture(){
return buffer.getTexture();
}
@Override
public void dispose(){
if(buffer != null) buffer.dispose();
}
}
@@ -0,0 +1,248 @@
package io.anuke.mindustry.graphics;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.VertexAttributes.Usage;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.graphics.glutils.Shader;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.Matrix3;
import io.anuke.arc.util.Disposable;
//TODO this class is a trainwreck, remove it
public class IndexedRenderer implements Disposable{
private final static int vsize = 5;
private Shader program = createDefaultShader();
private Mesh mesh;
private float[] tmpVerts = new float[vsize * 6];
private float[] vertices;
private Matrix3 projMatrix = new Matrix3();
private Matrix3 transMatrix = new Matrix3();
private Matrix3 combined = new Matrix3();
private float color = Color.WHITE.toFloatBits();
public IndexedRenderer(int sprites){
resize(sprites);
}
static public Shader createDefaultShader(){
String vertexShader = "attribute vec4 " + Shader.POSITION_ATTRIBUTE + ";\n" //
+ "attribute vec2 " + Shader.TEXCOORD_ATTRIBUTE + "0;\n" //
+ "uniform mat4 u_projTrans;\n" //
+ "varying vec2 v_texCoords;\n" //
+ "\n" //
+ "void main()\n" //
+ "{\n" //
+ " v_texCoords = " + Shader.TEXCOORD_ATTRIBUTE + "0;\n" //
+ " gl_Position = u_projTrans * " + Shader.POSITION_ATTRIBUTE + ";\n" //
+ "}\n";
String fragmentShader = "#ifdef GL_ES\n" //
+ "#define LOWP lowp\n" //
+ "precision mediump float;\n" //
+ "#else\n" //
+ "#define LOWP \n" //
+ "#endif\n" //
+ "varying vec2 v_texCoords;\n" //
+ "uniform sampler2D u_texture;\n" //
+ "void main()\n"//
+ "{\n" //
+ " gl_FragColor = texture2D(u_texture, v_texCoords);\n" //
+ "}";
return new Shader(vertexShader, fragmentShader);
}
public void render(Texture texture){
Core.gl.glEnable(GL20.GL_BLEND);
updateMatrix();
program.begin();
texture.bind();
program.setUniformMatrix("u_projTrans", combined);
program.setUniformi("u_texture", 0);
mesh.render(program, GL20.GL_TRIANGLES, 0, vertices.length / 5);
program.end();
}
public void setColor(Color color){
this.color = color.toFloatBits();
}
public void draw(int index, TextureRegion region, float x, float y, float w, float h){
final float fx2 = x + w;
final float fy2 = y + h;
final float u = region.getU();
final float v = region.getV2();
final float u2 = region.getU2();
final float v2 = region.getV();
float[] vertices = tmpVerts;
int idx = 0;
vertices[idx++] = x;
vertices[idx++] = y;
vertices[idx++] = color;
vertices[idx++] = u;
vertices[idx++] = v;
vertices[idx++] = x;
vertices[idx++] = fy2;
vertices[idx++] = color;
vertices[idx++] = u;
vertices[idx++] = v2;
vertices[idx++] = fx2;
vertices[idx++] = fy2;
vertices[idx++] = color;
vertices[idx++] = u2;
vertices[idx++] = v2;
//tri2
vertices[idx++] = x;
vertices[idx++] = y;
vertices[idx++] = color;
vertices[idx++] = u;
vertices[idx++] = v;
vertices[idx++] = fx2;
vertices[idx++] = y;
vertices[idx++] = color;
vertices[idx++] = u2;
vertices[idx++] = v;
vertices[idx++] = fx2;
vertices[idx++] = fy2;
vertices[idx++] = color;
vertices[idx++] = u2;
vertices[idx++] = v2;
mesh.updateVertices(index * vsize * 6, vertices);
}
public void draw(int index, TextureRegion region, float x, float y, float w, float h, float rotation){
final float u = region.getU();
final float v = region.getV2();
final float u2 = region.getU2();
final float v2 = region.getV();
final float originX = w / 2, originY = h / 2;
final float cos = Mathf.cosDeg(rotation);
final float sin = Mathf.sinDeg(rotation);
float fx = -originX;
float fy = -originY;
float fx2 = w - originX;
float fy2 = h - originY;
final float worldOriginX = x + originX;
final float worldOriginY = y + originY;
float x1 = cos * fx - sin * fy;
float y1 = sin * fx + cos * fy;
float x2 = cos * fx - sin * fy2;
float y2 = sin * fx + cos * fy2;
float x3 = cos * fx2 - sin * fy2;
float y3 = sin * fx2 + cos * fy2;
float x4 = x1 + (x3 - x2);
float y4 = y3 - (y2 - y1);
x1 += worldOriginX;
y1 += worldOriginY;
x2 += worldOriginX;
y2 += worldOriginY;
x3 += worldOriginX;
y3 += worldOriginY;
x4 += worldOriginX;
y4 += worldOriginY;
float[] vertices = tmpVerts;
int idx = 0;
vertices[idx++] = x1;
vertices[idx++] = y1;
vertices[idx++] = color;
vertices[idx++] = u;
vertices[idx++] = v;
vertices[idx++] = x3;
vertices[idx++] = y3;
vertices[idx++] = color;
vertices[idx++] = u2;
vertices[idx++] = v2;
vertices[idx++] = x4;
vertices[idx++] = y4;
vertices[idx++] = color;
vertices[idx++] = u;
vertices[idx++] = v2;
//tri2
vertices[idx++] = x1;
vertices[idx++] = y1;
vertices[idx++] = color;
vertices[idx++] = u;
vertices[idx++] = v;
vertices[idx++] = x2;
vertices[idx++] = y2;
vertices[idx++] = color;
vertices[idx++] = u2;
vertices[idx++] = v;
vertices[idx++] = x3;
vertices[idx++] = y3;
vertices[idx++] = color;
vertices[idx++] = u2;
vertices[idx++] = v2;
mesh.updateVertices(index * vsize * 6, vertices);
}
public Matrix3 getTransformMatrix(){
return transMatrix;
}
public void setTransformMatrix(Matrix3 matrix){
transMatrix = matrix;
}
public Matrix3 getProjectionMatrix(){
return projMatrix;
}
public void setProjectionMatrix(Matrix3 matrix){
projMatrix = matrix;
}
public void resize(int sprites){
if(mesh != null) mesh.dispose();
mesh = new Mesh(true, 6 * sprites, 0,
new VertexAttribute(Usage.Position, 2, "a_position"),
new VertexAttribute(Usage.ColorPacked, 4, "a_color"),
new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));
vertices = new float[6 * sprites * vsize];
mesh.setVertices(vertices);
}
private void updateMatrix(){
combined.set(projMatrix).mul(transMatrix);
}
@Override
public void dispose(){
mesh.dispose();
program.dispose();
}
}
@@ -37,11 +37,11 @@ public class Shaders{
build = new UnitBuild();
mix = new MixShader();
fog = new FogShader();
fullMix = new Shader("fullmix", "default");
fullMix = new LoadShader("fullmix", "default");
menu = new MenuShader();
}
public static class MenuShader extends Shader{
public static class MenuShader extends LoadShader{
float time = 0f;
public MenuShader(){
@@ -60,13 +60,13 @@ public class Shaders{
}
}
public static class FogShader extends Shader{
public static class FogShader extends LoadShader{
public FogShader(){
super("fog", "default");
}
}
public static class MixShader extends Shader{
public static class MixShader extends LoadShader{
public Color color = new Color(Color.WHITE);
public MixShader(){
@@ -93,7 +93,7 @@ public class Shaders{
}
}
public static class UnitBuild extends Shader{
public static class UnitBuild extends LoadShader{
public float progress, time;
public Color color = new Color();
public TextureRegion region;
@@ -113,8 +113,9 @@ public class Shaders{
}
}
public static class Outline extends Shader{
public static class Outline extends LoadShader{
public Color color = new Color();
public TextureRegion region = new TextureRegion();
public Outline(){
super("outline", "default");
@@ -127,9 +128,10 @@ public class Shaders{
}
}
public static class BlockBuild extends Shader{
public static class BlockBuild extends LoadShader{
public Color color = new Color();
public float progress;
public TextureRegion region = new TextureRegion();
public BlockBuild(){
super("blockbuild", "default");
@@ -146,8 +148,9 @@ public class Shaders{
}
}
public static class BlockPreview extends Shader{
public static class BlockPreview extends LoadShader{
public Color color = new Color();
public TextureRegion region = new TextureRegion();
public BlockPreview(){
super("blockpreview", "default");
@@ -162,7 +165,7 @@ public class Shaders{
}
}
public static class Shield extends Shader{
public static class Shield extends LoadShader{
public Shield(){
super("shield", "default");
@@ -180,7 +183,7 @@ public class Shaders{
}
}
public static class SurfaceShader extends Shader{
public static class SurfaceShader extends LoadShader{
public SurfaceShader(String frag){
super(frag, "default");
@@ -196,4 +199,10 @@ public class Shaders{
setUniformf("time", Time.time());
}
}
public static class LoadShader extends Shader{
public LoadShader(String frag, String vert){
super(Core.files.internal("shaders/" + vert + ".vertex"), Core.files.internal("shaders/" + frag + ".fragment"));
}
}
}
@@ -0,0 +1,39 @@
package io.anuke.mindustry.graphics;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.CapStyle;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf;
//TODO remove
public class Shapes{
public static void laser(String line, String edge, float x, float y, float x2, float y2, float scale){
laser(line, edge, x, y, x2, y2, Mathf.atan2(x2 - x, y2 - y), scale);
}
public static void laser(String line, String edge, float x, float y, float x2, float y2){
laser(line, edge, x, y, x2, y2, Mathf.atan2(x2 - x, y2 - y), 1f);
}
public static void laser(String line, String edge, float x, float y, float x2, float y2, float rotation, float scale){
Lines.stroke(12f * scale);
Lines.line(Core.atlas.find(line), x, y, x2, y2, CapStyle.none, 0f);
Lines.stroke(1f);
TextureRegion region = Core.atlas.find(edge);
Draw.rect(edge, x, y, region.getWidth() * Draw.scl, region.getHeight() * scale * Draw.scl).rot(rotation + 180);
Draw.rect(edge, x2, y2, region.getWidth() * Draw.scl, region.getHeight() * scale * Draw.scl).rot(rotation);
}
public static void tri(float x, float y, float width, float length, float rotation){
float oy = 17f / 63f * length;
Core.graphics.batch().draw().tex(Core.atlas.find("shape-3")).pos(x - width / 2f, y - oy)
.origin(width / 2f, oy).size(width, length).rot(rotation - 90);
}
}
@@ -86,28 +86,6 @@ public abstract class SaveFileVersion{
i += consecutives;
}
}
//write visibility, length-run encoded
for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i % world.width(), i / world.width());
boolean discovered = tile.discovered();
int consecutives = 0;
for(int j = i + 1; j < world.width() * world.height() && consecutives < 32767*2-1; j++){
Tile nextTile = world.tile(j % world.width(), j / world.width());
if(nextTile.discovered() != discovered){
break;
}
consecutives++;
}
stream.writeBoolean(discovered);
stream.writeShort(consecutives);
i += consecutives;
}
}
public void readMap(DataInputStream stream) throws IOException{
@@ -175,18 +153,6 @@ public abstract class SaveFileVersion{
tiles[x][y] = tile;
}
for(int i = 0; i < width * height; i++){
boolean discovered = stream.readBoolean();
int consecutives = stream.readUnsignedShort();
if(discovered){
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
tiles[newx][newy].setVisibility((byte) 1);
}
}
i += consecutives;
}
content.setTemporaryMapper(null);
world.endMapLoad();
}
@@ -2,7 +2,6 @@ package io.anuke.mindustry.maps;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.GridMap;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Liquids;
import io.anuke.mindustry.content.Mechs;
@@ -30,7 +29,7 @@ public class SectorPresets{
//command center mission
add(new SectorPreset(0, 1,
Structs.array(
Array.ofRecursive(
Missions.blockRecipe(UnitBlocks.daggerFactory),
new UnitMission(UnitTypes.dagger),
Missions.blockRecipe(UnitBlocks.commandCenter),
@@ -42,7 +41,7 @@ public class SectorPresets{
//pad mission
add(new SectorPreset(0, -2,
Structs.array(
Array.ofRecursive(
Missions.blockRecipe(mobile ? UpgradeBlocks.alphaPad : UpgradeBlocks.dartPad),
new MechMission(mobile ? Mechs.alpha : Mechs.dart),
new WaveMission(15)
@@ -51,7 +50,7 @@ public class SectorPresets{
//oil mission
add(new SectorPreset(-2, 0,
Structs.array(
Array.ofRecursive(
Missions.blockRecipe(ProductionBlocks.cultivator),
Missions.blockRecipe(ProductionBlocks.waterExtractor),
new ContentMission(Items.biomatter),
@@ -93,28 +93,6 @@ public class NetworkIO{
}
}
//write visibility, length-run encoded
for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i % world.width(), i / world.width());;
boolean discovered = tile.discovered();
int consecutives = 0;
for(int j = i + 1; j < world.width() * world.height() && consecutives < 32767*2-1; j++){
Tile nextTile = world.tile(j % world.width(), j / world.width());;
if(nextTile.discovered() != discovered){
break;
}
consecutives++;
}
stream.writeBoolean(discovered);
stream.writeShort(consecutives);
i += consecutives;
}
stream.write(Team.all.length);
//write team data
@@ -247,18 +225,6 @@ public class NetworkIO{
tiles[x][y] = tile;
}
for(int i = 0; i < width * height; i++){
boolean discovered = stream.readBoolean();
int consecutives = stream.readUnsignedShort();
if(discovered){
for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
tiles[newx][newy].setVisibility((byte) 1);
}
}
i += consecutives;
}
state.teams = new Teams();
byte teams = stream.readByte();
+1 -29
View File
@@ -1,22 +1,18 @@
package io.anuke.mindustry.ui;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Texture.TextureFilter;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.scene.Element;
import io.anuke.arc.scene.event.InputEvent;
import io.anuke.arc.scene.event.InputListener;
import io.anuke.arc.scene.ui.layout.Container;
import io.anuke.mindustry.graphics.Shaders;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.renderer;
public class Minimap extends Container<Element>{
public Minimap(){
super(new Element(){
TextureRegion r = new TextureRegion();
@Override
public void draw(){
@@ -27,30 +23,6 @@ public class Minimap extends Container<Element>{
if(renderer.minimap.getTexture() != null){
renderer.minimap.drawEntities(x, y, width, height);
}
if(showFog){
renderer.fog.getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
r.set(renderer.minimap.getRegion());
float pad = renderer.fog.getPadding();
float px = r.getU() * world.width() + pad;
float py = r.getV() * world.height() + pad;
float px2 = r.getU2() * world.width() + pad;
float py2 = r.getV2() * world.height() + pad;
r.setTexture(renderer.fog.getTexture());
r.setU(px / (world.width() + pad*2f));
r.setV(1f - py / (world.height() + pad*2f));
r.setU2(px2 / (world.width() + pad*2f));
r.setV2(1f - py2 / (world.height() + pad*2f));
Draw.shader(Shaders.fog);
Draw.rect().tex(r).set(x, y, width, height);
Draw.shader();
renderer.fog.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
}
});
@@ -232,7 +232,7 @@ public class JoinDialog extends FloatingDialog{
pad = 6;
}
Cell<TextButton> cell = ((Table) pane.getParent()).getCell(button);
Cell cell = ((Table) pane.getParent()).getCell(button);
if(!Mathf.isEqual(cell.getMinWidth(), pw)){
cell.width(pw);
@@ -42,8 +42,6 @@ public class Tile implements Position, TargetTrait{
private byte team;
/** Tile elevation. -1 means slope.*/
private byte elevation;
/** Fog visibility status: 3 states, but saved as a single bit. 0 = unexplored, 1 = visited, 2 = currently visible (saved as 1)*/
private byte visibility;
public Tile(int x, int y){
this.x = (short) x;
@@ -67,10 +65,6 @@ public class Tile implements Position, TargetTrait{
this.team = team;
}
public boolean discovered(){
return visibility > 0;
}
/**Returns this tile's position as a {@link Pos}.*/
public int pos(){
return Pos.get(x, y);
@@ -171,14 +165,6 @@ public class Tile implements Position, TargetTrait{
this.floor = type;
}
public byte getVisibility(){
return visibility;
}
public void setVisibility(byte visibility){
this.visibility = visibility;
}
public byte getRotation(){
return rotation;
}
@@ -99,14 +99,11 @@ public class Reconstructor extends Block{
ReconstructorEntity entity = tile.entity();
ReconstructorEntity oe = other.entity();
//called in main thread to prevent issues
threads.run(() -> {
unlink(entity);
unlink(oe);
unlink(entity);
unlink(oe);
entity.link = other.pos();
oe.link = tile.pos();
});
entity.link = other.pos();
oe.link = tile.pos();
}
@Remote(targets = Loc.both, called = Loc.server, forward = true)
@@ -15,6 +15,7 @@ import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.graphics.Shapes;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
@@ -71,11 +72,10 @@ public class RepairPoint extends Block{
float ang = entity.angleTo(entity.target);
float len = 5f;
//TODO new laser drawing system
Draw.color(Color.valueOf("e8ffd7"));
//Shapes.laser("laser", "laser-end",
// tile.drawx() + Angles.trnsx(ang, len), tile.drawy() + Angles.trnsy(ang, len),
// entity.target.x, entity.target.y, entity.strength);
Shapes.laser("laser", "laser-end",
tile.drawx() + Angles.trnsx(ang, len), tile.drawy() + Angles.trnsy(ang, len),
entity.target.x, entity.target.y, entity.strength);
Draw.color();
}
}
@@ -1,14 +1,14 @@
package io.anuke.mindustry.desktop;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.JsonValue.ValueType;
import com.badlogic.gdx.utils.JsonWriter.OutputType;
import io.anuke.arc.Core;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.OS;
import io.anuke.arc.util.serialization.JsonValue;
import io.anuke.arc.util.serialization.JsonValue.ValueType;
import io.anuke.arc.util.serialization.JsonWriter.OutputType;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.net.Net;
import io.anuke.arc.core.Settings;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.OS;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -1,8 +1,8 @@
package io.anuke.mindustry.desktop;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import io.anuke.arc.ApplicationListener;
import io.anuke.arc.backends.lwjgl3.Lwjgl3Application;
import io.anuke.arc.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import io.anuke.kryonet.KryoClient;
import io.anuke.kryonet.KryoServer;
import io.anuke.mindustry.Mindustry;
@@ -3,18 +3,18 @@ package io.anuke.mindustry.desktop;
import club.minnced.discord.rpc.DiscordEventHandlers;
import club.minnced.discord.rpc.DiscordRPC;
import club.minnced.discord.rpc.DiscordRichPresence;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Base64Coder;
import io.anuke.arc.collection.Array;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.util.OS;
import io.anuke.arc.util.Strings;
import io.anuke.arc.util.serialization.Base64Coder;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.core.Platform;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.ui.dialogs.FileChooser;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.util.OS;
import io.anuke.arc.util.Strings;
import java.net.NetworkInterface;
import java.util.Enumeration;
Binary file not shown.
Binary file not shown.
@@ -2,10 +2,10 @@ package io.anuke.kryonet;
import com.esotericsoftware.kryonet.FrameworkMessage;
import com.esotericsoftware.kryonet.serialization.Serialization;
import io.anuke.arc.function.Supplier;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.net.Packet;
import io.anuke.mindustry.net.Registrator;
import io.anuke.arc.function.Supplier;
import io.anuke.arc.util.Pooling;
import java.nio.ByteBuffer;
@@ -1,8 +1,10 @@
package io.anuke.kryonet;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import com.esotericsoftware.kryonet.*;
import io.anuke.arc.Core;
import io.anuke.arc.collection.Array;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.net.Host;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.Net.ClientProvider;
@@ -10,8 +12,6 @@ import io.anuke.mindustry.net.Net.SendMode;
import io.anuke.mindustry.net.NetworkIO;
import io.anuke.mindustry.net.Packets.Connect;
import io.anuke.mindustry.net.Packets.Disconnect;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.util.Pooling;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor;
@@ -23,7 +23,8 @@ import java.net.NetworkInterface;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedSelectorException;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.netClient;
import static io.anuke.mindustry.Vars.port;
public class KryoClient implements ClientProvider{
final Client client;
@@ -50,7 +51,7 @@ public class KryoClient implements ClientProvider{
return;
}
}
Gdx.app.postRunnable(() -> lastCallback.accept(host));
Core.app.post(() -> lastCallback.accept(host));
foundAddresses.add(datagramPacket.getAddress());
}
@@ -194,9 +195,9 @@ public class KryoClient implements ClientProvider{
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
Host host = NetworkIO.readServerData(packet.getAddress().getHostAddress(), buffer);
Gdx.app.postRunnable(() -> valid.accept(host));
Core.app.post(() -> valid.accept(host));
}catch(Exception e){
Gdx.app.postRunnable(() -> invalid.accept(e));
Core.app.post(() -> invalid.accept(e));
}
}
});
@@ -209,7 +210,7 @@ public class KryoClient implements ClientProvider{
foundAddresses.clear();
lastCallback = callback;
client.discoverHosts(port, 3000);
Gdx.app.postRunnable(done);
Core.app.post(done);
}
});
}
@@ -231,9 +232,9 @@ public class KryoClient implements ClientProvider{
private void handleException(Exception e){
if(e instanceof KryoNetException){
Gdx.app.postRunnable(() -> Net.showError(new IOException("mismatch")));
Core.app.post(() -> Net.showError(new IOException("mismatch")));
}else{
Gdx.app.postRunnable(() -> Net.showError(e));
Core.app.post(() -> Net.showError(e));
}
}
@@ -1,7 +1,7 @@
package io.anuke.kryonet;
import com.esotericsoftware.minlog.Log;
import com.esotericsoftware.minlog.Log.Logger;
import com.esotericsoftware.kryonet.util.Log;
import com.esotericsoftware.kryonet.util.Log.Logger;
import io.anuke.arc.util.ColorCodes;
import java.io.PrintWriter;
@@ -1,6 +1,5 @@
package io.anuke.kryonet;
import com.badlogic.gdx.utils.Array;
import com.dosse.upnp.UPnP;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.FrameworkMessage;
@@ -8,6 +7,10 @@ import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Listener.LagListener;
import com.esotericsoftware.kryonet.Server;
import com.esotericsoftware.kryonet.util.InputStreamSender;
import io.anuke.arc.Core;
import io.anuke.arc.collection.Array;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.net.*;
import io.anuke.mindustry.net.Net.SendMode;
@@ -16,8 +19,6 @@ import io.anuke.mindustry.net.Packets.Connect;
import io.anuke.mindustry.net.Packets.Disconnect;
import io.anuke.mindustry.net.Packets.StreamBegin;
import io.anuke.mindustry.net.Packets.StreamChunk;
import io.anuke.arc.core.Timers;
import io.anuke.arc.util.Log;
import net.jpountz.lz4.LZ4Compressor;
import net.jpountz.lz4.LZ4Factory;
@@ -27,8 +28,6 @@ import java.nio.channels.ClosedSelectorException;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import static io.anuke.mindustry.Vars.threads;
public class KryoServer implements ServerProvider{
final Server server;
final CopyOnWriteArrayList<KryoConnection> connections = new CopyOnWriteArrayList<>();
+3 -4
View File
@@ -1,4 +1,4 @@
include 'desktop', 'core', 'kryonet', 'server', 'ios', 'annotations', 'tools', 'tests'
include 'desktop', 'core', 'net', 'server', 'ios', 'annotations', 'tools', 'tests'
def use = { String name, String path ->
include(name)
@@ -25,9 +25,8 @@ if(System.properties["release"] == null || System.properties["release"] == "fals
use(':Arc:arc-core', '../Arc/arc-core')
use(':Arc:extensions', '../Arc/extensions')
use(':Arc:extensions:freetype', '../Arc/extensions/freetype')
}
if (new File(settingsDir, '../GDXGifRecorder').exists()) {
use(':GDXGifRecorder', '../GDXGifRecorder')
use(':Arc:backends', '../Arc/backends')
use(':Arc:backends:backend-lwjgl3', '../Arc/backends/backend-lwjgl3')
}
if (new File(settingsDir, '../debug').exists()) {
use(':debug', '../debug')
@@ -1,10 +1,10 @@
package io.anuke.mindustry;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.OrderedMap;
import com.badlogic.gdx.utils.PropertiesUtils;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.OrderedMap;
import io.anuke.arc.function.BiFunction;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.io.PropertiesUtils;
import java.io.File;
import java.io.FileInputStream;
+3 -2
View File
@@ -1,8 +1,9 @@
package io.anuke.mindustry;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.arc.graphics.g2d.TextureAtlas.AtlasRegion;
import io.anuke.arc.graphics.g2d.TextureRegion;
public class GenRegion extends TextureRegion {
public class GenRegion extends AtlasRegion{
public String name;
public boolean invalid;
public ImageContext context;
+8 -7
View File
@@ -1,7 +1,9 @@
package io.anuke.mindustry;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.units.UnitType;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Item;
@@ -10,9 +12,8 @@ import io.anuke.mindustry.type.Mech;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.Hue;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.content;
public class Generators {
@@ -50,7 +51,7 @@ public class Generators {
for (int y = 0; y < base.height(); y++) {
Color result = top.getColor(x, y);
if(result.a > 0.01f){
Hue.mix(result, color, 0.45f, result);
result.lerp(color, 0.45f);
base.draw(x, y, result);
}
}
@@ -144,7 +145,7 @@ public class Generators {
for(Block block : content.blocks()){
if(!(block instanceof Floor)) continue;
Floor floor = (Floor)block;
if(floor.getIcon().length > 0 && !Draw.hasRegion(floor.name + "-cliff-side")){
if(floor.getIcon().length > 0 && !Core.atlas.has(floor.name + "-cliff-side")){
Image floori = context.get(floor.getIcon()[0]);
Color color = floori.getColor(0, 0).mul(1.3f, 1.3f, 1.3f, 1f);
+7 -7
View File
@@ -1,13 +1,13 @@
package io.anuke.mindustry;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.util.Structs;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.awt.Graphics2D;
import java.io.IOException;
import java.util.ArrayList;
@@ -110,10 +110,10 @@ public class Image {
x, y,
x + region.getWidth(),
y + region.getHeight(),
(flipx ? region.getRegionX() + region.getWidth() : region.getRegionX()) + ofx,
(flipy ? region.getRegionY() + region.getHeight() : region.getRegionY()) + ofy,
(flipx ? region.getRegionX() : region.getRegionX() + region.getWidth()) + ofx,
(flipy ? region.getRegionY() : region.getRegionY() + region.getHeight()) + ofy,
(flipx ? region.getX() + region.getWidth() : region.getX()) + ofx,
(flipy ? region.getY() + region.getHeight() : region.getY()) + ofy,
(flipx ? region.getX() : region.getX() + region.getWidth()) + ofx,
(flipy ? region.getY() : region.getY() + region.getHeight()) + ofy,
null);
}
+19 -20
View File
@@ -1,17 +1,18 @@
package io.anuke.mindustry;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.core.ContentLoader;
import io.anuke.arc.core.Core;
import io.anuke.arc.core.Timers;
import io.anuke.arc.util.Atlas;
import io.anuke.arc.Core;
import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.graphics.g2d.TextureAtlas;
import io.anuke.arc.graphics.g2d.TextureAtlas.AtlasRegion;
import io.anuke.arc.graphics.g2d.TextureAtlas.TextureAtlasData;
import io.anuke.arc.graphics.g2d.TextureAtlas.TextureAtlasData.Region;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Log.LogHandler;
import io.anuke.arc.util.Log.NoopLogHandler;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.core.ContentLoader;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
@@ -31,7 +32,7 @@ public class ImageContext {
TextureAtlasData data = new TextureAtlasData(new FileHandle(spritesFolder + "/sprites.atlas"),
new FileHandle(spritesFolder), false);
ObjectMap<String, TextureRegion> regionCache = new ObjectMap<>();
ObjectMap<String, AtlasRegion> regionCache = new ObjectMap<>();
for(Region region : data.getRegions()){
int x = region.left, y = region.top, width = region.width, height = region.height;
@@ -43,30 +44,30 @@ public class ImageContext {
}
@Override
public int getRegionX(){
public int getX(){
return x;
}
@Override
public int getRegionY(){
public int getY(){
return y;
}
@Override
public int getRegionWidth(){
public int getWidth(){
return width;
}
@Override
public int getRegionHeight(){
public int getHeight(){
return height;
}
});
}
Core.atlas = new Atlas(){
Core.atlas = new TextureAtlas(){
@Override
public TextureRegion getRegion(String name){
public AtlasRegion find(String name){
if(!regionCache.containsKey(name)){
GenRegion region = new GenRegion();
region.name = name;
@@ -78,13 +79,11 @@ public class ImageContext {
}
@Override
public boolean hasRegion(String s) {
public boolean has(String s) {
return regionCache.containsKey(s);
}
};
Core.atlas.setErrorRegion("error");
image = ImageIO.read(new File(spritesFolder + "/sprites.png"));
}
@@ -99,7 +98,7 @@ public class ImageContext {
}
public Image get(String name){
return get(Core.atlas.getRegion(name));
return get(Core.atlas.find(name));
}
public Image get(TextureRegion region){
@@ -1,7 +1,7 @@
package io.anuke.mindustry;
import io.anuke.arc.core.Timers;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Time;
import java.io.IOException;