Added full block descriptions, improved shield shaders

This commit is contained in:
Anuken
2017-11-20 19:02:35 -05:00
parent aedf46257a
commit 806b762333
7 changed files with 131 additions and 78 deletions

View File

@@ -8,6 +8,7 @@ uniform sampler2D u_texture;
uniform vec4 u_color; uniform vec4 u_color;
uniform vec2 u_texsize; uniform vec2 u_texsize;
uniform float u_time; uniform float u_time;
uniform float u_scaling;
uniform vec2 u_offset; uniform vec2 u_offset;
varying vec4 v_color; varying vec4 v_color;
@@ -19,7 +20,7 @@ void main() {
vec2 coords = (T * u_texsize) + u_offset; vec2 coords = (T * u_texsize) + u_offset;
T += vec2(sin(coords.y / 3.0 + u_time / 20.0) / 250.0, sin(coords.x / 3.0 + u_time / 20.0) / 250.0); T += vec2(sin(coords.y / 3.0 + u_time / 20.0) / 250.0, sin(coords.x / 3.0 + u_time / 20.0) / 250.0) * u_scaling;
float si = 1.0 + sin(u_time / 20.0 /*+ (coords.x + coords.y) / 30.0*/) / 8.0; float si = 1.0 + sin(u_time / 20.0 /*+ (coords.x + coords.y) / 30.0*/) / 8.0;

View File

@@ -126,13 +126,11 @@ public class Renderer extends RendererModule{
long time = TimeUtils.nanoTime(); long time = TimeUtils.nanoTime();
drawDefault(); drawDefault();
if(Timers.get("profiled", profileTime)) Profiler.draw = TimeUtils.timeSinceNanos(time); if(Timers.get("profiled", profileTime))
Profiler.draw = TimeUtils.timeSinceNanos(time);
if(Vars.debug && Vars.debugGL && Timers.get("profile", 60)){ if(Vars.debug && Vars.debugGL && Timers.get("profile", 60)){
UCore.log("shaders: " + GLProfiler.shaderSwitches, UCore.log("shaders: " + GLProfiler.shaderSwitches, "calls: " + GLProfiler.drawCalls, "bindings: " + GLProfiler.textureBindings, "vertices: " + GLProfiler.vertexCount.average);
"calls: " + GLProfiler.drawCalls,
"bindings: " + GLProfiler.textureBindings,
"vertices: " + GLProfiler.vertexCount.average);
} }
camera.position.set(lastx - deltax, lasty - deltay, 0); camera.position.set(lastx - deltax, lasty - deltay, 0);
@@ -150,11 +148,13 @@ public class Renderer extends RendererModule{
long time = TimeUtils.nanoTime(); long time = TimeUtils.nanoTime();
renderTiles(); renderTiles();
if(Timers.get("profilebd", profileTime)) Profiler.blockDraw = TimeUtils.timeSinceNanos(time); if(Timers.get("profilebd", profileTime))
Profiler.blockDraw = TimeUtils.timeSinceNanos(time);
time = TimeUtils.nanoTime(); time = TimeUtils.nanoTime();
Entities.draw(); Entities.draw();
if(Timers.get("profileed", profileTime)) Profiler.entityDraw = TimeUtils.timeSinceNanos(time); if(Timers.get("profileed", profileTime))
Profiler.entityDraw = TimeUtils.timeSinceNanos(time);
drawShield(); drawShield();
@@ -179,11 +179,9 @@ public class Renderer extends RendererModule{
Draw.alpha(0.6f); Draw.alpha(0.6f);
for(Entity entity : Entities.all()){ for(Entity entity : Entities.all()){
if(entity instanceof Enemy){ if(entity instanceof Enemy){
Enemy enemy = (Enemy)entity; Enemy enemy = (Enemy) entity;
if(Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight) if(Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight).setCenter(camera.position.x, camera.position.y).overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))){
.setCenter(camera.position.x, camera.position.y)
.overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))){
continue; continue;
} }
@@ -220,8 +218,8 @@ public class Renderer extends RendererModule{
if(floorCache == null || floorCache.length != chunksx || floorCache[0].length != chunksy){ if(floorCache == null || floorCache.length != chunksx || floorCache[0].length != chunksy){
floorCache = new Cache[chunksx][chunksy]; floorCache = new Cache[chunksx][chunksy];
for(int x = 0; x < chunksx; x ++){ for(int x = 0; x < chunksx; x++){
for(int y = 0; y < chunksy; y ++){ for(int y = 0; y < chunksy; y++){
renderCache(x, y); renderCache(x, y);
} }
} }
@@ -294,6 +292,23 @@ public class Renderer extends RendererModule{
Draw.color(); Draw.color();
} }
} }
if(Vars.debug && Vars.debugChunks){
Draw.color(Color.YELLOW);
Draw.thick(1f);
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;
if(!Mathf.inBounds(worldx, worldy, floorCache))
continue;
Draw.linerect(worldx * chunksize * tilesize, worldy * chunksize * tilesize,
chunksize * tilesize, chunksize * tilesize);
}
}
Draw.reset();
}
} }
void renderCache(int cx, int cy){ void renderCache(int cx, int cy){
@@ -316,6 +331,7 @@ public class Renderer extends RendererModule{
void renderPixelOverlay(){ void renderPixelOverlay(){
//draw tutorial placement point
if(Vars.control.tutorial.showBlock()){ if(Vars.control.tutorial.showBlock()){
int x = World.core.x + Vars.control.tutorial.getPlacePoint().x; int x = World.core.x + Vars.control.tutorial.getPlacePoint().x;
int y = World.core.y + Vars.control.tutorial.getPlacePoint().y; int y = World.core.y + Vars.control.tutorial.getPlacePoint().y;
@@ -323,7 +339,7 @@ public class Renderer extends RendererModule{
Draw.thick(1f); Draw.thick(1f);
Draw.color(Color.YELLOW); Draw.color(Color.YELLOW);
Draw.square(x * tilesize, y * tilesize, tilesize/2f + Mathf.sin(Timers.time(), 4f, 1f)); Draw.square(x * tilesize, y * tilesize, tilesize / 2f + Mathf.sin(Timers.time(), 4f, 1f));
Draw.color(Color.ORANGE); Draw.color(Color.ORANGE);
Draw.thick(2f); Draw.thick(2f);
@@ -333,7 +349,9 @@ public class Renderer extends RendererModule{
Draw.reset(); Draw.reset();
} }
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android) && AndroidInput.mode == PlaceMode.cursor){ //draw placement box
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements)
&& (!ui.hasMouse() || android) && AndroidInput.mode == PlaceMode.cursor){
float x = 0; float x = 0;
float y = 0; float y = 0;
@@ -349,11 +367,10 @@ public class Renderer extends RendererModule{
tiley = Input.tiley(); tiley = Input.tiley();
} }
x = tilex*tilesize; x = tilex * tilesize;
y = tiley*tilesize; y = tiley * tilesize;
boolean valid = World.validPlace(tilex, tiley, player.recipe.result) && (android || boolean valid = World.validPlace(tilex, tiley, player.recipe.result) && (android || Input.cursorNear());
Input.cursorNear());
Vector2 offset = player.recipe.result.getPlaceOffset(); Vector2 offset = player.recipe.result.getPlaceOffset();
@@ -361,9 +378,7 @@ public class Renderer extends RendererModule{
Draw.color(valid ? Color.PURPLE : Color.SCARLET); Draw.color(valid ? Color.PURPLE : Color.SCARLET);
Draw.thickness(2f); Draw.thickness(2f);
Draw.linecrect(x + offset.x, y + offset.y, Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si, tilesize * player.recipe.result.height + si);
tilesize * player.recipe.result.width + si,
tilesize * player.recipe.result.height + si);
player.recipe.result.drawPlace(tilex, tiley, valid); player.recipe.result.drawPlace(tilex, tiley, valid);
@@ -390,7 +405,8 @@ public class Renderer extends RendererModule{
//block breaking //block breaking
if(Inputs.buttonDown(Buttons.RIGHT) && World.validBreak(Input.tilex(), Input.tiley())){ if(Inputs.buttonDown(Buttons.RIGHT) && World.validBreak(Input.tilex(), Input.tiley())){
Tile tile = World.tile(Input.tilex(), Input.tiley()); Tile tile = World.tile(Input.tilex(), Input.tiley());
if(tile.isLinked()) tile = tile.getLinked(); if(tile.isLinked())
tile = tile.getLinked();
Vector2 offset = tile.block().getPlaceOffset(); Vector2 offset = tile.block().getPlaceOffset();
Draw.color(Color.YELLOW, Color.SCARLET, player.breaktime / tile.getBreakTime()); Draw.color(Color.YELLOW, Color.SCARLET, player.breaktime / tile.getBreakTime());
@@ -409,6 +425,7 @@ public class Renderer extends RendererModule{
} }
} }
//draw selected block health
if(player.recipe == null && !ui.hasMouse()){ if(player.recipe == null && !ui.hasMouse()){
Tile tile = World.tile(Input.tilex(), Input.tiley()); Tile tile = World.tile(Input.tilex(), Input.tiley());
@@ -420,8 +437,7 @@ public class Renderer extends RendererModule{
Vector2 offset = target.block().getPlaceOffset(); Vector2 offset = target.block().getPlaceOffset();
if(target.entity != null) if(target.entity != null)
drawHealth(target.entity.x + offset.x, target.entity.y - 3f - target.block().height/2f * Vars.tilesize + offset.y, drawHealth(target.entity.x + offset.x, target.entity.y - 3f - target.block().height / 2f * Vars.tilesize + offset.y, target.entity.health, target.entity.maxhealth);
target.entity.health, target.entity.maxhealth);
target.block().drawPixelOverlay(target); target.block().drawPixelOverlay(target);
} }
@@ -429,12 +445,13 @@ public class Renderer extends RendererModule{
boolean smoothcam = Settings.getBool("smoothcam"); boolean smoothcam = Settings.getBool("smoothcam");
//draw entity health bars
for(Entity entity : Entities.all()){ for(Entity entity : Entities.all()){
if(entity instanceof DestructibleEntity && !(entity instanceof TileEntity)){ if(entity instanceof DestructibleEntity && !(entity instanceof TileEntity)){
DestructibleEntity dest = ((DestructibleEntity) entity); DestructibleEntity dest = ((DestructibleEntity) entity);
if(dest instanceof Player && Vars.snapCamera && smoothcam && Settings.getBool("pixelate")){ if(dest instanceof Player && Vars.snapCamera && smoothcam && Settings.getBool("pixelate")){
drawHealth((int)dest.x, (int)dest.y - 7f, dest.health, dest.maxhealth); drawHealth((int) dest.x, (int) dest.y - 7f, dest.health, dest.maxhealth);
}else{ }else{
drawHealth(dest.x, dest.y - 7f, dest.health, dest.maxhealth); drawHealth(dest.x, dest.y - 7f, dest.health, dest.maxhealth);
} }

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Shader; import io.anuke.ucore.graphics.Shader;
import io.anuke.ucore.util.Tmp; import io.anuke.ucore.util.Tmp;
@@ -35,10 +36,14 @@ public class Shaders{
@Override @Override
public void apply(){ public void apply(){
float scale = Settings.getBool("pixelate") ? 1 : Core.cameraScale / Core.camera.zoom;
float scaling = Core.cameraScale / 4f / Core.camera.zoom;
shader.setUniformf("u_color", color); shader.setUniformf("u_color", color);
shader.setUniformf("u_time", Timers.time()); shader.setUniformf("u_time", Timers.time());
shader.setUniformf("u_scaling", scaling);
shader.setUniformf("u_offset", Tmp.v1.set(Core.camera.position.x, Core.camera.position.y)); shader.setUniformf("u_offset", Tmp.v1.set(Core.camera.position.x, Core.camera.position.y));
shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth(), region.getTexture().getHeight())); shader.setUniformf("u_texsize", Tmp.v1.set(region.getTexture().getWidth() / scale,
region.getTexture().getHeight() / scale));
} }
} }

View File

@@ -665,7 +665,33 @@ public class UI extends SceneModule{
header.addImage(region).size(8*5).padTop(4).units(Unit.dp); header.addImage(region).size(8*5).padTop(4).units(Unit.dp);
Label nameLabel = new Label(recipe.result.formalName); Label nameLabel = new Label(recipe.result.formalName);
nameLabel.setWrap(true); nameLabel.setWrap(true);
header.add(nameLabel).padLeft(4).width(160f).units(Unit.dp); header.add(nameLabel).padLeft(4).width(135f).units(Unit.dp);
//extra info
if(recipe.result.fullDescription != null){
header.addButton("?", ()->{
Label desclabel = new Label(recipe.result.fullDescription);
desclabel.setWrap(true);
boolean wasPaused = GameState.is(State.paused);
GameState.set(State.paused);
FloatingDialog d = new FloatingDialog("Block Info");
Table top = new Table();
top.left();
top.add(new Image(region)).size(8*5).units(Unit.dp);
top.add("[orange]"+recipe.result.formalName).padLeft(6f).units(Unit.dp);
d.content().add(top).fill().left();
d.content().row();
d.content().add(desclabel).width(600).units(Unit.dp);
d.buttons().addButton("OK", ()->{
if(!wasPaused) GameState.set(State.playing);
d.hide();
}).size(110, 50).pad(10f).units(Unit.dp);
d.show();
}).fillX().top().right().size(36f, 40f).units(Unit.dp);
}
desctable.add().pad(2).units(Unit.dp); desctable.add().pad(2).units(Unit.dp);

View File

@@ -31,6 +31,8 @@ public class Vars{
public static boolean debug = false; public static boolean debug = false;
//whether to debug openGL info //whether to debug openGL info
public static boolean debugGL = false; public static boolean debugGL = false;
//whether to draw chunk borders
public static boolean debugChunks = false;
//whether turrets have infinite ammo (only with debug) //whether turrets have infinite ammo (only with debug)
public static boolean infiniteAmmo = true; public static boolean infiniteAmmo = true;
//whether to show paths of enemies //whether to show paths of enemies

View File

@@ -13,6 +13,8 @@ public class DefenseBlocks{
stonewall = new Wall("stonewall"){{ stonewall = new Wall("stonewall"){{
health = 50; health = 50;
formalName = "stone wall"; formalName = "stone wall";
fullDescription =
"A cheap defensive block. Useful for protecting the core and turrets in the first few waves.";
}}, }},
ironwall = new Wall("ironwall"){{ ironwall = new Wall("ironwall"){{

Binary file not shown.