Rudimentary rendering

This commit is contained in:
Anuken
2020-02-05 23:04:48 -05:00
parent 8172e69f8c
commit a11f6efe0a
23 changed files with 10629 additions and 10513 deletions

View File

@@ -188,6 +188,7 @@ public class Vars implements Loadable{
public static void init(){
Serialization.init();
Groups.init();
DefaultSerializers.typeMappings.put("mindustry.type.ContentType", "mindustry.ctype.ContentType");
if(loadLocales){

View File

@@ -201,7 +201,7 @@ public class Control implements ApplicationListener, Loadable{
}
void createPlayer(){
//player = new Playerc();
player = PlayerEntity.create();
player.name(Core.settings.getString("name"));
player.color().set(Core.settings.getInt("color-0"));
@@ -244,28 +244,6 @@ public class Control implements ApplicationListener, Loadable{
});
}
//TODO remove, make it viable on a server
/*public void playZone(Zone zone){
ui.loadAnd(() -> {
logic.reset();
net.reset();
world.loadGenerator(zone.generator);
zone.rules.get(state.rules);
state.rules.zone = zone;
for(Tilec core : state.teams.playerCores()){
for(ItemStack stack : zone.getStartingItems()){
core.items().add(stack.item, stack.amount);
}
}
state.set(State.playing);
state.wavetime = state.rules.waveSpacing;
control.saves.zoneSave();
logic.play();
Events.fire(Trigger.newGame);
});
}*/
public void playSector(Sector sector){
ui.loadAnd(() -> {
logic.reset();

View File

@@ -122,8 +122,7 @@ public class NetClient implements ApplicationListener{
net.handleClient(InvokePacket.class, packet -> {
packet.writeBuffer.position(0);
//TODO fix remote read client
// RemoteReadClient.readPacket(packet.writeBuffer, packet.type);
RemoteReadClient.readPacket(packet.writeBuffer, packet.type);
});
}
@@ -176,8 +175,7 @@ public class NetClient implements ApplicationListener{
//invoke event for all clients but also locally
//this is required so other clients get the correct name even if they don't know who's sending it yet
//TODO uncomment when it works
//Call.sendMessage(message, colorizeName(player.id(), player.name()), player);
Call.sendMessage(message, colorizeName(player.id(), player.name()), player);
}else{
//log command to console but with brackets
Log.info("<&y{0}: &lm{1}&lg>", player.name(), message);

View File

@@ -188,8 +188,7 @@ public class NetServer implements ApplicationListener{
con.modclient = true;
}
//TODO place instance of player here
Playerc player = null;//new Playerc();
Playerc player = PlayerEntity.create();
player.admin(admins.isAdmin(uuid, packet.usid));
player.con(con);
player.con().usid = packet.usid;
@@ -222,8 +221,7 @@ public class NetServer implements ApplicationListener{
net.handleServer(InvokePacket.class, (con, packet) -> {
if(con.player == null) return;
try{
//TODO uncomment when compilation works
//RemoteReadServer.readPacket(packet.writeBuffer, packet.type, con.player);
RemoteReadServer.readPacket(packet.writeBuffer, packet.type, con.player);
}catch(ValidateException e){
Log.debug("Validation failed for '{0}': {1}", e.player, e.getMessage());
}catch(RuntimeException e){
@@ -483,7 +481,7 @@ public class NetServer implements ApplicationListener{
float rotation, float baseRotation,
float xVelocity, float yVelocity,
Tile mining,
boolean boosting, boolean shooting, boolean chatting, boolean building,
boolean boosting, boolean shooting, boolean chatting,
BuildRequest[] requests,
float viewX, float viewY, float viewWidth, float viewHeight
){
@@ -603,8 +601,7 @@ public class NetServer implements ApplicationListener{
}else if(action == AdminAction.trace){
TraceInfo info = new TraceInfo(other.con().address, other.uuid(), other.con().modclient, other.con().mobile);
if(player.con() != null){
//TODO uncomment
//Call.onTraceInfo(player.con(), other, info);
Call.onTraceInfo(player.con(), other, info);
}else{
NetClient.onTraceInfo(other, info);
}

View File

@@ -11,7 +11,9 @@ import arc.util.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import static arc.Core.*;
import static mindustry.Vars.*;
@@ -23,7 +25,7 @@ public class Renderer implements ApplicationListener{
public final LightRenderer lights = new LightRenderer();
public final Pixelator pixelator = new Pixelator();
public FrameBuffer shieldBuffer = new FrameBuffer(2, 2);
public FrameBuffer effectBuffer = new FrameBuffer(2, 2);
private Bloom bloom;
private Color clearColor;
private float targetscale = Scl.scl(4);
@@ -104,7 +106,7 @@ public class Renderer implements ApplicationListener{
@Override
public void dispose(){
minimap.dispose();
shieldBuffer.dispose();
effectBuffer.dispose();
blocks.dispose();
if(bloom != null){
bloom.dispose();
@@ -169,7 +171,115 @@ public class Renderer implements ApplicationListener{
}
public void draw(){
//TODO do it
camera.update();
if(Float.isNaN(camera.position.x) || Float.isNaN(camera.position.y)){
camera.position.set(player);
}
graphics.clear(clearColor);
if(!graphics.isHidden() && (Core.settings.getBool("animatedwater") || Core.settings.getBool("animatedshields")) && (effectBuffer.getWidth() != graphics.getWidth() || effectBuffer.getHeight() != graphics.getHeight())){
effectBuffer.resize(graphics.getWidth(), graphics.getHeight());
}
Draw.proj(camera.projection());
blocks.floor.drawFloor();
render(RenderLayer.floor);
blocks.processBlocks();
blocks.drawShadows();
Draw.color();
blocks.floor.beginDraw();
blocks.floor.drawLayer(CacheLayer.walls);
blocks.floor.endDraw();
blocks.drawBlocks(Layer.block);
blocks.drawFog();
blocks.drawDestroyed();
Draw.shader(Shaders.blockbuild, true);
blocks.drawBlocks(Layer.placement);
Draw.shader();
blocks.drawBlocks(Layer.overlay);
render(RenderLayer.groundShadows);
render(RenderLayer.ground);
blocks.drawBlocks(Layer.turret);
render(RenderLayer.flyingShadows);
blocks.drawBlocks(Layer.power);
blocks.drawBlocks(Layer.lights);
render(RenderLayer.flying);
Draw.flush();
if(bloom != null && !pixelator.enabled()){
bloom.capture();
}
render(RenderLayer.bullets);
render(RenderLayer.effects);
Draw.flush();
if(bloom != null && !pixelator.enabled()){
bloom.render();
}
overlays.drawBottom();
if(player.isBuilder()){
player.builder().drawBuildRequests();
}
overlays.drawTop();
//TODO should use (draw)
Groups.player.each(p -> !p.dead(), Playerc::drawName);
if(state.rules.lighting){
lights.draw();
}
drawLanding();
Draw.color();
Draw.flush();
}
private void render(RenderLayer layer){
}
private void drawLanding(){
if(landTime > 0 && player.closestCore() != null){
float fract = landTime / Fx.coreLand.lifetime;
Tilec entity = player.closestCore();
TextureRegion reg = entity.block().icon(Cicon.full);
float scl = Scl.scl(4f) / camerascale;
float s = reg.getWidth() * Draw.scl * scl * 4f * fract;
Draw.color(Pal.lightTrail);
Draw.rect("circle-shadow", entity.getX(), entity.getY(), s, s);
Angles.randLenVectors(1, (1f- fract), 100, 1000f * scl * (1f-fract), (x, y, fin, fout) -> {
Lines.stroke(scl * fin);
Lines.lineAngle(entity.getX() + x, entity.getY() + y, Mathf.angle(x, y), (fin * 20 + 1f) * scl);
});
Draw.color();
Draw.mixcol(Color.white, fract);
Draw.rect(reg, entity.getX(), entity.getY(), reg.getWidth() * Draw.scl * scl, reg.getHeight() * Draw.scl * scl, fract * 135f);
Draw.reset();
}
}
/*
public void draw(){
@@ -182,8 +292,8 @@ public class Renderer implements ApplicationListener{
graphics.clear(clearColor);
if(!graphics.isHidden() && (Core.settings.getBool("animatedwater") || Core.settings.getBool("animatedshields")) && (shieldBuffer.getWidth() != graphics.getWidth() || shieldBuffer.getHeight() != graphics.getHeight())){
shieldBuffer.resize(graphics.getWidth(), graphics.getHeight());
if(!graphics.isHidden() && (Core.settings.getBool("animatedwater") || Core.settings.getBool("animatedshields")) && (effectBuffer.getWidth() != graphics.getWidth() || effectBuffer.getHeight() != graphics.getHeight())){
effectBuffer.resize(graphics.getWidth(), graphics.getHeight());
}
Draw.proj(camera.projection());
@@ -246,15 +356,15 @@ public class Renderer implements ApplicationListener{
if(shieldGroup.countInBounds() > 0){
if(settings.getBool("animatedshields") && Shaders.shield != null){
Draw.flush();
shieldBuffer.begin();
effectBuffer.begin();
graphics.clear(Color.clear);
shieldGroup.draw();
shieldGroup.draw(shield -> true, ShieldEntity::drawOver);
Draw.flush();
shieldBuffer.end();
effectBuffer.end();
Draw.shader(Shaders.shield);
Draw.color(Pal.accent);
Draw.rect(Draw.wrap(shieldBuffer.getTexture()), camera.position.x, camera.position.y, camera.width, -camera.height);
Draw.rect(Draw.wrap(effectBuffer.getTexture()), camera.position.x, camera.position.y, camera.width, -camera.height);
Draw.color();
Draw.shader();
}else{

View File

@@ -138,8 +138,7 @@ public class EditorTile extends Tile{
Block block = block();
if(block.hasEntity()){
//TODO uncomment once this mess is figure out
//entity = block.newEntity().init(this, false);
entity = block.newEntity().init(this, false);
entity.cons(new ConsumeModule(entity));
if(block.hasItems) entity.items(new ItemModule());
if(block.hasLiquids) entity.liquids(new LiquidModule());

View File

@@ -12,6 +12,7 @@ import mindustry.content.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.world.*;
import static mindustry.Vars.*;
@@ -29,8 +30,7 @@ public class Damage{
public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, Color color){
for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i++){
int branches = 5 + Mathf.clamp((int)(power / 30), 1, 20);
//TODO uncomment
//Time.run(i * 2f + Mathf.random(4f), () -> Lightning.create(Team.derelict, Pal.power, 3, x, y, Mathf.random(360f), branches + Mathf.range(2)));
Time.run(i * 2f + Mathf.random(4f), () -> Lightning.create(Team.derelict, Pal.power, 3, x, y, Mathf.random(360f), branches + Mathf.range(2)));
}
for(int i = 0; i < Mathf.clamp(flammability / 4, 0, 30); i++){

View File

@@ -12,7 +12,7 @@ import static mindustry.Vars.*;
/** Represents a group of a certain type of entity.*/
@SuppressWarnings("unchecked")
public class EntityGroup<T extends Entityc> implements Iterable<T>{
private final Array<T> array = new Array<>(false, 32);
private final Array<T> array;
private final Array<T> intersectArray = new Array<>();
private final Rect intersectRect = new Rect();
private IntMap<T> map;
@@ -21,7 +21,9 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
private int index;
public EntityGroup(boolean spatial, boolean mapping){
public EntityGroup(Class<T> type, boolean spatial, boolean mapping){
array = new Array<>(false, 32, type);
if(spatial){
tree = new QuadTree<>(new Rect(0, 0, 0, 0));
}

View File

@@ -708,8 +708,10 @@ public class EntityComps{
admin = typing = false;
lastText = null;
textFadeTime = 0f;
unit.controller(unit.type().createController());
unit = null;
if(!dead()){
unit.controller(unit.type().createController());
unit = Nulls.unit;
}
}
public void update(){
@@ -757,7 +759,7 @@ public class EntityComps{
}
boolean dead(){
return unit == Nulls.builder;
return unit.isNull();
}
String uuid(){

View File

@@ -57,7 +57,7 @@ public enum CacheLayer{
if(!Core.settings.getBool("animatedwater")) return;
renderer.blocks.floor.endc();
renderer.shieldBuffer.begin();
renderer.effectBuffer.begin();
Core.graphics.clear(Color.clear);
renderer.blocks.floor.beginc();
}
@@ -66,10 +66,10 @@ public enum CacheLayer{
if(!Core.settings.getBool("animatedwater")) return;
renderer.blocks.floor.endc();
renderer.shieldBuffer.end();
renderer.effectBuffer.end();
Draw.shader(shader);
Draw.rect(Draw.wrap(renderer.shieldBuffer.getTexture()), camera.position.x, camera.position.y, camera.width, -camera.height);
Draw.rect(Draw.wrap(renderer.effectBuffer.getTexture()), camera.position.x, camera.position.y, camera.width, -camera.height);
Draw.shader();
renderer.blocks.floor.beginc();

View File

@@ -247,6 +247,8 @@ public class MenuRenderer implements Disposable{
}
private void drawFlyers(){
//TODO fix
if(true) return;
Draw.color(0f, 0f, 0f, 0.4f);
TextureRegion icon = flyerType.icon(Cicon.full);

View File

@@ -0,0 +1,11 @@
package mindustry.graphics;
public enum RenderLayer{
floor,
groundShadows,
ground,
flyingShadows,
flying,
bullets,
effects
}

View File

@@ -74,7 +74,10 @@ public class Fonts{
int ch = Integer.parseInt(character);
TextureRegion region = Core.atlas.find(texture);
if(region.getTexture() != uitex) throw new IllegalArgumentException("Font icon '" + texture + "' is not in the UI texture.");
if(region.getTexture() != uitex){
continue;
//throw new IllegalArgumentException("Font icon '" + texture + "' is not in the UI texture.");
}
unicodeIcons.put(nametex[0], ch);

View File

@@ -457,7 +457,6 @@ public class Tile implements Position{
Block block = block();
if(block.hasEntity()){
//TODO assign data and don't use new entity
entity = block.newEntity().init(this, block.update);
entity.cons(new ConsumeModule(entity));
if(block.hasItems) entity.items(new ItemModule());