mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 03:08:38 +07:00
Fixed most world rendering
This commit is contained in:
parent
1e8b844eac
commit
bc9110b344
@ -95,7 +95,6 @@ public class Vars{
|
||||
public static boolean headless = false;
|
||||
public static float controllerMin = 0.25f;
|
||||
public static float baseControllerSpeed = 11f;
|
||||
public static boolean snapCamera = true;
|
||||
|
||||
public static ContentLoader content;
|
||||
public static GameState state;
|
||||
|
@ -18,10 +18,13 @@ import io.anuke.arc.graphics.g2d.SpriteBatch;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Rectangle;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.util.ScreenRecorder;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.util.pooling.Pools;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.effect.GroundEffectEntity;
|
||||
import io.anuke.mindustry.entities.effect.GroundEffectEntity.GroundEffect;
|
||||
@ -39,7 +42,8 @@ public class Renderer implements ApplicationListener{
|
||||
public final OverlayRenderer overlays = new OverlayRenderer();
|
||||
|
||||
private Color clearColor;
|
||||
private int targetscale = baseCameraScale;
|
||||
private float targetscale = baseCameraScale;
|
||||
private float camerascale = baseCameraScale;
|
||||
private Rectangle rect = new Rectangle(), rect2 = new Rectangle();
|
||||
private Vector2 avgPosition = new Vector2();
|
||||
private float shakeIntensity, shaketime;
|
||||
@ -99,16 +103,13 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
camera.position.set(players[0].x, players[0].y);
|
||||
graphics.clear(Color.PURPLE);
|
||||
Draw.proj(camera.projection());
|
||||
players[0].drawAll();
|
||||
Draw.flush();
|
||||
|
||||
/*
|
||||
//TODO hack, find source of this bug
|
||||
Color.WHITE.set(1f, 1f, 1f, 1f);
|
||||
|
||||
camerascale = Mathf.lerpDelta(camerascale, targetscale, 0.1f);
|
||||
camera.width = graphics.getWidth() / camerascale;
|
||||
camera.height = graphics.getHeight() / camerascale;
|
||||
|
||||
if(state.is(State.menu)){
|
||||
graphics.clear(Color.BLACK);
|
||||
}else{
|
||||
@ -122,32 +123,20 @@ public class Renderer implements ApplicationListener{
|
||||
camera.position.lerpDelta(position, 0.08f);
|
||||
}
|
||||
}else if(!mobile){
|
||||
camera.position.set(position);
|
||||
camera.position.lerpDelta(position, 0.08f);
|
||||
}
|
||||
|
||||
camera.position.x = Mathf.clamp(camera.position.x, -tilesize / 2f, world.width() * tilesize - tilesize / 2f);
|
||||
camera.position.y = Mathf.clamp(camera.position.y, -tilesize / 2f, world.height() * tilesize - tilesize / 2f);
|
||||
|
||||
float prex = camera.position.x, prey = camera.position.y;
|
||||
//TODO update screenshake
|
||||
updateShake(0.75f);
|
||||
|
||||
float deltax = camera.position.x - prex, deltay = camera.position.y - prey;
|
||||
float lastx = camera.position.x, lasty = camera.position.y;
|
||||
|
||||
if(snapCamera){
|
||||
camera.position.set((int) camera.position.x, (int) camera.position.y);
|
||||
}
|
||||
|
||||
draw();
|
||||
|
||||
camera.position.set(lastx - deltax, lasty - deltay);
|
||||
}
|
||||
|
||||
if(!ui.chatfrag.chatOpen()){
|
||||
//TODO does not work
|
||||
//ScreenRecorder.record(); //this only does something if CoreGifRecorder is on the class path, which it usually isn't
|
||||
}*/
|
||||
ScreenRecorder.record(); //this only does something if CoreGifRecorder is on the class path, which it usually isn't
|
||||
}
|
||||
}
|
||||
|
||||
void updateShake(float scale){
|
||||
@ -174,7 +163,7 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
Draw.proj(camera.projection());
|
||||
|
||||
blocks.drawFloor();
|
||||
blocks.floor.drawFloor();
|
||||
|
||||
drawAndInterpolate(groundEffectGroup, e -> e instanceof BelowLiquidTrait);
|
||||
drawAndInterpolate(puddleGroup);
|
||||
@ -222,20 +211,6 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
overlays.drawTop();
|
||||
|
||||
//TODO fog
|
||||
/*
|
||||
if(showFog){
|
||||
Graphics.surface();
|
||||
}else{
|
||||
Graphics.flushSurface();
|
||||
}*/
|
||||
|
||||
//batch.end();
|
||||
|
||||
if(showFog){
|
||||
// fog.draw();
|
||||
}
|
||||
|
||||
//TODO this isn't necessary anymore
|
||||
//Graphics.beginCam();
|
||||
|
||||
@ -253,6 +228,7 @@ public class Renderer implements ApplicationListener{
|
||||
//Graphics.surface(effectSurface, true, false);
|
||||
|
||||
float trnsX = -12, trnsY = -13;
|
||||
Draw.color(0, 0, 0, 0.15f);
|
||||
|
||||
for(EntityGroup<? extends BaseUnit> group : unitGroups){
|
||||
if(!group.isEmpty()){
|
||||
@ -266,7 +242,7 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
//Draw.color(0, 0, 0, 0.15f);
|
||||
//Graphics.flushSurface();
|
||||
// Draw.color();
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
private void drawAllTeams(boolean flying){
|
||||
@ -307,11 +283,6 @@ public class Renderer implements ApplicationListener{
|
||||
EntityDraw.drawWith(group, toDraw, drawer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height){
|
||||
camera.resize(width, height);
|
||||
}
|
||||
|
||||
public Vector2 averagePosition(){
|
||||
avgPosition.setZero();
|
||||
|
||||
@ -321,15 +292,11 @@ public class Renderer implements ApplicationListener{
|
||||
return avgPosition;
|
||||
}
|
||||
|
||||
public void setCameraScale(int amount){
|
||||
targetscale = amount;
|
||||
public void scaleCamera(float amount){
|
||||
targetscale += amount;
|
||||
clampScale();
|
||||
}
|
||||
|
||||
public void scaleCamera(int amount){
|
||||
setCameraScale(targetscale + amount);
|
||||
}
|
||||
|
||||
public void clampScale(){
|
||||
float s = io.anuke.arc.scene.ui.layout.Unit.dp.scl(1f);
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(s * 2), Math.round(s * 5));
|
||||
|
@ -22,7 +22,7 @@ public class BlockRenderer{
|
||||
private final static int initialRequests = 32 * 32;
|
||||
private final static int expandr = 6;
|
||||
|
||||
private FloorRenderer floorRenderer;
|
||||
public final FloorRenderer floor;
|
||||
|
||||
private Array<BlockRequest> requests = new Array<>(true, initialRequests, BlockRequest.class);
|
||||
private IntSet teamChecks = new IntSet();
|
||||
@ -33,7 +33,7 @@ public class BlockRenderer{
|
||||
private FrameBuffer shadows = new FrameBuffer(1, 1);
|
||||
|
||||
public BlockRenderer(){
|
||||
floorRenderer = new FloorRenderer();
|
||||
floor = new FloorRenderer();
|
||||
|
||||
for(int i = 0; i < requests.size; i++){
|
||||
requests.set(i, new BlockRequest());
|
||||
@ -163,12 +163,6 @@ public class BlockRenderer{
|
||||
}
|
||||
|
||||
BlockRequest req = requests.get(iterateidx);
|
||||
|
||||
if(req.layer != lastLayer){
|
||||
if(lastLayer != null) layerEnds(lastLayer);
|
||||
layerBegins(req.layer);
|
||||
}
|
||||
|
||||
Block block = req.tile.block();
|
||||
|
||||
if(req.layer == Layer.block){
|
||||
@ -217,24 +211,6 @@ public class BlockRenderer{
|
||||
}
|
||||
}
|
||||
|
||||
public void beginFloor(){
|
||||
floorRenderer.beginDraw();
|
||||
}
|
||||
|
||||
public void endFloor(){
|
||||
floorRenderer.endDraw();
|
||||
}
|
||||
|
||||
public void drawFloor(){
|
||||
floorRenderer.drawFloor();
|
||||
}
|
||||
|
||||
private void layerBegins(Layer layer){
|
||||
}
|
||||
|
||||
private void layerEnds(Layer layer){
|
||||
}
|
||||
|
||||
private void addRequest(Tile tile, Layer layer){
|
||||
if(requestidx >= requests.size){
|
||||
requests.add(new BlockRequest());
|
||||
|
@ -16,7 +16,6 @@ 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;
|
||||
|
||||
@ -148,8 +147,6 @@ public class FloorRenderer{
|
||||
|
||||
ObjectSet<CacheLayer> used = new ObjectSet<>();
|
||||
|
||||
Sector sector = world.getSector();
|
||||
|
||||
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
|
||||
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
|
||||
Tile tile = world.tile(tilex, tiley);
|
||||
|
@ -17,7 +17,7 @@ public enum Binding implements KeyBind{
|
||||
rotate(new Axis(KeyCode.SCROLL)),
|
||||
dash(KeyCode.SHIFT_LEFT),
|
||||
drop_unit(KeyCode.SHIFT_LEFT),
|
||||
gridMode(KeyCode.CONTROL_LEFT),
|
||||
gridMode(KeyCode.SPACE),
|
||||
gridModeShift(KeyCode.SHIFT_LEFT),
|
||||
zoom_hold(KeyCode.CONTROL_LEFT, "view"),
|
||||
zoom(new Axis(KeyCode.SCROLL)),
|
||||
|
@ -139,11 +139,11 @@ public class DesktopInput extends InputHandler{
|
||||
if(state.is(State.menu) || Core.scene.hasDialog()) return;
|
||||
|
||||
//zoom and rotate things
|
||||
if(Math.abs(Core.input.axis(Binding.zoom)) > 0 && (Core.input.keyDown(Binding.zoom_hold))){
|
||||
renderer.scaleCamera((int) Core.input.axis(Binding.zoom));
|
||||
if(Math.abs(Core.input.axisTap(Binding.zoom)) > 0 && (Core.input.keyDown(Binding.zoom_hold))){
|
||||
renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
|
||||
}
|
||||
|
||||
renderer.minimap.zoomBy(-(int) Core.input.axis(Binding.zoom_minimap));
|
||||
renderer.minimap.zoomBy(-Core.input.axisTap(Binding.zoom_minimap));
|
||||
|
||||
if(player.isDead()) return;
|
||||
|
||||
|
@ -148,8 +148,8 @@ public class HudFragment extends Fragment{
|
||||
});
|
||||
|
||||
//minimap
|
||||
parent.fill(t -> t.top().right().add(new Minimap())
|
||||
.visible(() -> !state.is(State.menu) && Core.settings.getBool("minimap")));
|
||||
//TODO screws everything up, somehow
|
||||
//parent.fill(t -> t.top().right().add(new Minimap()).visible(() -> !state.is(State.menu) && Core.settings.getBool("minimap")));
|
||||
|
||||
//paused table
|
||||
parent.fill(t -> {
|
||||
|
@ -178,7 +178,7 @@ public class Floor extends Block{
|
||||
|
||||
TextureRegion region = floor.edgeRegions[i];
|
||||
|
||||
Draw.rect(region, tile.worldx() + floor.offsets[i].x, tile.worldy() + floor.offsets[i].y, region.getWidth(), region.getHeight());
|
||||
Draw.rect(region, tile.worldx() + floor.offsets[i].x + region.getWidth()/2f, tile.worldy() + floor.offsets[i].y + region.getHeight()/2f, region.getWidth(), region.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user