1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-22 05:47:44 +03:00

Fix multiple crashes, add shader fallback

This commit is contained in:
Anuken 2017-12-13 13:13:22 -05:00
parent ece7ad0fd3
commit 66b068f5e0
10 changed files with 59 additions and 33 deletions

View File

@ -79,7 +79,7 @@ project(":core") {
apply plugin: "java"
dependencies {
compile 'com.github.Anuken:ucore:a1ae9be'
compile 'com.github.Anuken:ucore:dfceb01'
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
}

View File

@ -9,7 +9,6 @@ import io.anuke.mindustry.core.*;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.Formatter;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.World;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.ucore.core.Inputs;
import io.anuke.ucore.core.Timers;

View File

@ -4,11 +4,8 @@ import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.I18NBundle;
import io.anuke.mindustry.core.Control;
import io.anuke.mindustry.core.Renderer;
import io.anuke.mindustry.core.UI;
import io.anuke.mindustry.core.*;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.world.World;
import io.anuke.ucore.scene.ui.layout.Unit;
public class Vars{

View File

@ -26,7 +26,6 @@ import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.Entities;
@ -179,17 +178,6 @@ public class Control extends Module{
GameState.set(State.playing);
}
public void findCore(){
for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){
if(world.tile(x, y).block() == ProductionBlocks.core){
core = world.tile(x, y);
return;
}
}
}
}
public Tile getCore(){
return core;
}
@ -433,6 +421,10 @@ public class Control extends Module{
wavetime = 0f;
}
if(Inputs.keyUp(Keys.C)){
GameState.set(State.playing);
}
if(Inputs.keyUp(Keys.U)){
Vars.showUI = !Vars.showUI;
}

View File

@ -99,8 +99,10 @@ public class Renderer extends RendererModule{
}else{
boolean smoothcam = Settings.getBool("smoothcam");
if(control.core == null){ //how is this possible? apparently it is
control.findCore();
if(control.core == null){
ui.showGameError();
GameState.set(State.menu);
return;
}
if(control.core.block() == ProductionBlocks.core){
@ -250,9 +252,15 @@ public class Renderer extends RendererModule{
Tmp.tr2.setRegion(texture);
Shaders.shield.region = Tmp.tr2;
Shaders.shield.hits = shieldHits;
if(Shaders.shield.isFallback){
Draw.color(1f, 1f, 1f, 0.3f);
Shaders.outline.color = Color.SKY;
Shaders.outline.region = Tmp.tr2;
}
Graphics.end();
Graphics.shader(Shaders.shield);
Graphics.shader(Shaders.shield.isFallback ? Shaders.outline : Shaders.shield);
Graphics.setScreen();
Core.batch.draw(texture, 0, Gdx.graphics.getHeight(), Gdx.graphics.getWidth(), -Gdx.graphics.getHeight());
@ -260,6 +268,8 @@ public class Renderer extends RendererModule{
Graphics.shader();
Graphics.end();
Graphics.beginCam();
Draw.color();
}
public void addShieldHit(float x, float y){

View File

@ -38,7 +38,7 @@ public class UI extends SceneModule{
Table loadingtable, desctable, configtable;
MindustrySettingsDialog prefs;
MindustryKeybindDialog keys;
Dialog about, restart, levels, upgrades, load, settingserror;
Dialog about, restart, levels, upgrades, load, settingserror, gameerror;
MenuDialog menu;
Tooltip tooltip;
Tile configTile;
@ -162,6 +162,15 @@ public class UI extends SceneModule{
settingserror.hide();
}).size(80f, 55f).pad(4);
gameerror = new Dialog("An error has occured", "dialog");
gameerror.content().add(new Label("[SCARLET]An unexpected error has occured, which would have caused a crash. "
+ "[]Please report the exact circumstances under which this error occured to the developer: "
+ "\n[ORANGE]anukendev@gmail.com[]"){{
setWrap(true);
}}).width(600f).units(Unit.dp).pad(10f);
gameerror.buttons().addButton("OK", ()-> gameerror.hide()).size(200f, 50).units(Unit.dp);
//gameerror.setFillParent(true);
load = new LoadDialog();
upgrades = new UpgradeDialog();
@ -298,10 +307,13 @@ public class UI extends SceneModule{
if(e instanceof Table){
((Table)e).invalidateHierarchy();
}
}
}
public void showGameError(){
gameerror.show();
}
public void updateWeapons(){
((WeaponFragment)weaponfrag).updateWeapons();
}

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry.world;
package io.anuke.mindustry.core;
import static io.anuke.mindustry.Vars.*;
@ -10,10 +10,12 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.effect.Fx;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Sounds;
@ -95,6 +97,11 @@ public class World extends Module{
}
public Tile tile(int x, int y){
if(tiles == null){
ui.showGameError();
GameState.set(State.menu);
return null;
}
if(!Mathf.inBounds(x, y, tiles)) return null;
return tiles[x][y];
}
@ -103,6 +110,10 @@ public class World extends Module{
return tile(Mathf.scl2(x, tilesize), Mathf.scl2(y, tilesize));
}
public Tile[][] getTiles(){
return tiles;
}
public Tile[] getNearby(int x, int y){
temptiles[0] = tile(x+1, y);
temptiles[1] = tile(x, y+1);
@ -179,7 +190,7 @@ public class World extends Module{
Generator.generate(mapPixmaps[map.ordinal()], tiles);
//TODO multiblock core
placeBlock(control.getCore().x, control.getCore().y, ProductionBlocks.core, 0);
placeBlock(control.getCore().x, control.getCore().y, ProductionBlocks.core, 0, false);
if(map != Map.tutorial){
setDefaultBlocks();
@ -229,7 +240,7 @@ public class World extends Module{
}
//TODO move to control or player?
public void placeBlock(int x, int y, Block result, int rotation){
public void placeBlock(int x, int y, Block result, int rotation, boolean effects){
Tile tile = tile(x, y);
//just in case
@ -251,15 +262,15 @@ public class World extends Module{
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}
Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
}
}
}else{
Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
}
Effects.shake(2f, 2f, player);
Sounds.play("place");
//Effects.shake(2f, 2f, player);
if(effects) Sounds.play("place");
}
//TODO move this to control?

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.entities.enemies;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.reflect.ClassReflection;
@ -37,6 +38,7 @@ public class Enemy extends DestructibleEntity{
protected boolean targetCore = false;
protected boolean stopNearCore = true;
protected float mass = 1f;
protected String className;
public float idletime = 0f;
public int spawn;
@ -56,6 +58,8 @@ public class Enemy extends DestructibleEntity{
maxhealth = 60;
heal();
className = ClassReflection.getSimpleName(getClass()).toLowerCase();
}
public float drawSize(){
@ -252,7 +256,8 @@ public class Enemy extends DestructibleEntity{
@Override
public void draw(){
String region = ClassReflection.getSimpleName(getClass()).toLowerCase() + "-t" + Mathf.clamp(tier, 1, 3);
if(Timers.get(this, "asd", 30)) Gdx.app.error("ENEMY", "Currently drawing at " + x + " " + y);
String region = className + "-t" + Mathf.clamp(tier, 1, 3);
Shaders.outline.color.set(tierColors[tier - 1]);
Shaders.outline.region = Draw.region(region);

View File

@ -87,7 +87,7 @@ public class AndroidInput extends InputAdapter{
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && Vars.world.validPlace(tilex, tiley, player.recipe.result)){
Vars.world.placeBlock(tilex, tiley, player.recipe.result, player.rotation);
Vars.world.placeBlock(tilex, tiley, player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);

View File

@ -56,7 +56,7 @@ public class Input{
Vars.world.validPlace(tilex(), tiley(), player.recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
Vars.world.placeBlock(tilex(), tiley(), player.recipe.result, player.rotation);
Vars.world.placeBlock(tilex(), tiley(), player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);