From 175f092673d5eaca32e95ec62aeb10052f16c457 Mon Sep 17 00:00:00 2001 From: opfromthestart Date: Mon, 23 Aug 2021 13:33:18 -0400 Subject: [PATCH] Fixed some stuff -Added default gravity block check in server -Some things I had to copy since i didnt merge right -Adds all gravity blocks to FallingBlock list -LogTop debug thing to check for good textures -Some texture rendering(see above) -Some control changes since I need to get to the edge quickly --- .../ru/windcorp/progressia/server/Server.java | 77 ++++ .../generation/planet/PlanetGenerator.java | 3 +- .../progressia/test/TestChunkCodec.java | 41 +- .../windcorp/progressia/test/TestContent.java | 4 + .../test/TestEntityDataFallingBlock.java | 9 +- .../test/TestEntityLogicFallingBlock.java | 125 ++++-- .../test/TestEntityRenderFallingBlock.java | 7 +- .../test/TestEntityRenderJavapony.java | 381 ++++++++++++++---- .../progressia/test/TestPlayerControls.java | 15 +- 9 files changed, 527 insertions(+), 135 deletions(-) diff --git a/src/main/java/ru/windcorp/progressia/server/Server.java b/src/main/java/ru/windcorp/progressia/server/Server.java index e975b90..c3cbb03 100644 --- a/src/main/java/ru/windcorp/progressia/server/Server.java +++ b/src/main/java/ru/windcorp/progressia/server/Server.java @@ -18,6 +18,8 @@ package ru.windcorp.progressia.server; +import java.util.List; +import java.util.Random; import java.util.function.Consumer; import java.util.function.Function; @@ -25,12 +27,20 @@ import org.apache.logging.log4j.LogManager; import com.google.common.eventbus.EventBus; +import glm.vec._3.Vec3; import glm.vec._3.i.Vec3i; import ru.windcorp.jputil.functions.ThrowingRunnable; import ru.windcorp.progressia.common.Units; import ru.windcorp.progressia.common.util.TaskQueue; import ru.windcorp.progressia.common.util.crash.ReportingEventBus; +import ru.windcorp.progressia.common.world.ChunkDataListener; +import ru.windcorp.progressia.common.world.Coordinates; +import ru.windcorp.progressia.common.world.DefaultChunkData; import ru.windcorp.progressia.common.world.DefaultWorldData; +import ru.windcorp.progressia.common.world.GravityModelRegistry; +import ru.windcorp.progressia.common.world.WorldDataListener; +import ru.windcorp.progressia.common.world.block.BlockData; +import ru.windcorp.progressia.common.world.block.BlockDataRegistry; import ru.windcorp.progressia.common.world.rels.AbsFace; import ru.windcorp.progressia.common.world.rels.AxisRotations; import ru.windcorp.progressia.server.comms.ClientManager; @@ -50,6 +60,8 @@ import ru.windcorp.progressia.server.world.tasks.WorldAccessor; import ru.windcorp.progressia.server.world.ticking.Change; import ru.windcorp.progressia.server.world.ticking.Evaluation; import ru.windcorp.progressia.server.world.ticking.TickerCoordinator; +import ru.windcorp.progressia.test.TestEntityDataFallingBlock; +import ru.windcorp.progressia.test.TestEntityLogicFallingBlock; public class Server { @@ -79,6 +91,71 @@ public class Server { private final TickingSettings tickingSettings = new TickingSettings(); public Server(DefaultWorldData world, Function generatorCreator) { + world.addListener(new WorldDataListener() { + @Override + public void onChunkLoaded(DefaultWorldData world, DefaultChunkData chunk) { + //PlanetGenerator.this.planet; + //LogManager.getLogger().info("Loaded chunk"); + GravityModelRegistry.getInstance().get("Test:PlanetGravityModel"); + chunk.addListener(new ChunkDataListener() { // Falling Block + // spawning logic + @Override + public void onChunkBlockChanged(DefaultChunkData chunk_2, Vec3i blockInChunk, BlockData previous, + BlockData current) { + Vec3i chunkWorldPos = new Vec3i(0,0,0); + Coordinates.getInWorld(chunk_2.getPosition(), blockInChunk, chunkWorldPos); + + /*List underBlocks = getGoodCardinals(fallBlock.getUpVector().negate_()); + + boolean notSupported = false; + for (Vec3i v3 : underBlocks) + { + Vec3i inWorld = occupiedBlock.sub_(v3); + if (context.getBlock(inWorld).getId()=="Test:Air") { + notSupported=true; + break; + } + }*/ + + //chunk.getPosition().mul_(16).add_(blockInChunk); + //LogManager.getLogger().info("Put block {} at {}<{}<{}",current.getId(),chunkWorldPos.x,chunkWorldPos.y,chunkWorldPos.z); + + if (TestEntityLogicFallingBlock.FallingBlocks + .contains(chunk_2.getWorld().getBlock(chunkWorldPos.add_(0, 0, 1)).getId())) { + chunk_2.getWorld().setBlock(chunkWorldPos.add_(0, 0, 1), BlockDataRegistry.getInstance() + .get(chunk_2.getWorld().getBlock(chunkWorldPos.add_(0, 0, 1)).getId()), true); + } + if (!TestEntityLogicFallingBlock.FallingBlocks.contains(current.getId())) { + return; + } + //LogManager.getLogger().info("Cont"); + if (chunk_2.getWorld().getBlock(chunkWorldPos.add_(0, 0, -1)).getId() == "Test:Air") { + LogManager.getLogger().info("Inserting FallingBlock {},{},{}", + chunkWorldPos.x,chunkWorldPos.y,chunkWorldPos.z); + + TestEntityDataFallingBlock fallingBlock = new TestEntityDataFallingBlock(current); + + Vec3i worldPos = chunk_2.getPosition().mul_(16).add_(blockInChunk); + Vec3 floatWorldPos = new Vec3(worldPos.x, worldPos.y, worldPos.z); + fallingBlock.setPosition(floatWorldPos); + + fallingBlock.setEntityId(("Test:FallingBlock" + floatWorldPos.toString() + + String.valueOf(new Random().nextFloat())).hashCode()); + + chunk.getWorld().addEntity(fallingBlock); + //invokeLater(() -> world.addEntity(fallingBlock)); + + //chunk.setBlock(blockInChunk, previous, false); + //invokeLater(() -> world.setBlock(chunkWorldPos, BlockDataRegistry.getInstance().get("Test:Air"), false)); + + + //LogManager.getLogger().info(String.valueOf(chunkWorldPos.x) + " " + // + String.valueOf(chunkWorldPos.y) + " " + String.valueOf(chunkWorldPos.z)); + } + } + }); + } + }); this.world = new DefaultWorldLogic( world, this, diff --git a/src/main/java/ru/windcorp/progressia/server/world/generation/planet/PlanetGenerator.java b/src/main/java/ru/windcorp/progressia/server/world/generation/planet/PlanetGenerator.java index b2c5c8c..0b626c4 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/generation/planet/PlanetGenerator.java +++ b/src/main/java/ru/windcorp/progressia/server/world/generation/planet/PlanetGenerator.java @@ -21,7 +21,6 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.List; - import glm.vec._3.Vec3; import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.util.FloatRangeMap; @@ -58,6 +57,8 @@ public class PlanetGenerator extends AbstractWorldGenerator { this.terrainGenerator = new PlanetTerrainGenerator(this, heightMap, layers); this.featureGenerator = new PlanetFeatureGenerator(this, features); + + } /** diff --git a/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java b/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java index a9298a1..f4e81c5 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java +++ b/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import java.io.DataInput; @@ -33,13 +33,14 @@ import gnu.trove.map.TObjectIntMap; import gnu.trove.map.hash.TObjectIntHashMap; import ru.windcorp.jputil.functions.ThrowingConsumer; import ru.windcorp.progressia.common.state.IOContext; -import ru.windcorp.progressia.common.world.ChunkData; +import ru.windcorp.progressia.common.world.DefaultChunkData; import ru.windcorp.progressia.common.world.DecodingException; -import ru.windcorp.progressia.common.world.WorldData; +import ru.windcorp.progressia.common.world.DefaultWorldData; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.block.BlockDataRegistry; -import ru.windcorp.progressia.common.world.block.BlockFace; +import ru.windcorp.progressia.common.world.generic.GenericChunks; import ru.windcorp.progressia.common.world.io.ChunkCodec; +import ru.windcorp.progressia.common.world.rels.RelFace; import ru.windcorp.progressia.common.world.tile.TileData; import ru.windcorp.progressia.common.world.tile.TileDataRegistry; @@ -75,7 +76,7 @@ public class TestChunkCodec extends ChunkCodec { } @Override - public boolean shouldEncode(ChunkData chunk, IOContext context) { + public boolean shouldEncode(DefaultChunkData chunk, IOContext context) { return true; } @@ -84,12 +85,14 @@ public class TestChunkCodec extends ChunkCodec { */ @Override - public ChunkData decode(WorldData world, Vec3i position, DataInputStream input, IOContext context) - throws DecodingException, IOException { + public DefaultChunkData decode(DefaultWorldData world, Vec3i position, DataInputStream input, IOContext context) + throws DecodingException, + IOException { BlockData[] blockPalette = readBlockPalette(input); TileData[] tilePalette = readTilePalette(input); - ChunkData chunk = new ChunkData(position, world); + DefaultChunkData chunk = new DefaultChunkData(position, world); + readBlocks(input, blockPalette, chunk); readTiles(input, tilePalette, chunk); @@ -118,9 +121,9 @@ public class TestChunkCodec extends ChunkCodec { return palette; } - private void readBlocks(DataInput input, BlockData[] blockPalette, ChunkData chunk) throws IOException { + private void readBlocks(DataInput input, BlockData[] blockPalette, DefaultChunkData chunk) throws IOException { try { - chunk.forEachBiC(guard(v -> { + GenericChunks.forEachBiC(guard(v -> { chunk.setBlock(v, blockPalette[input.readInt()], false); })); } catch (UncheckedIOException e) { @@ -128,7 +131,7 @@ public class TestChunkCodec extends ChunkCodec { } } - private void readTiles(DataInput input, TileData[] tilePalette, ChunkData chunk) throws IOException { + private void readTiles(DataInput input, TileData[] tilePalette, DefaultChunkData chunk) throws IOException { Vec3i bic = new Vec3i(); while (true) { @@ -137,7 +140,7 @@ public class TestChunkCodec extends ChunkCodec { break; bic.set(xOrEndMarker, input.readByte() & 0xFF, input.readByte() & 0xFF); - BlockFace face = BlockFace.getFaces().get(input.readByte() & 0xFF); + RelFace face = RelFace.getFaces().get(input.readByte() & 0xFF); int tiles = input.readByte() & 0xFF; @@ -154,7 +157,7 @@ public class TestChunkCodec extends ChunkCodec { */ @Override - public void encode(ChunkData chunk, DataOutputStream output, IOContext context) throws IOException { + public void encode(DefaultChunkData chunk, DataOutputStream output, IOContext context) throws IOException { Palette blockPalette = createBlockPalette(chunk); Palette tilePalette = createTilePalette(chunk); @@ -165,13 +168,13 @@ public class TestChunkCodec extends ChunkCodec { writeTiles(chunk, tilePalette, output); } - private Palette createBlockPalette(ChunkData chunk) { + private Palette createBlockPalette(DefaultChunkData chunk) { Palette blockPalette = new Palette<>(); - chunk.forEachBiC(v -> blockPalette.add(chunk.getBlock(v))); + GenericChunks.forEachBiC(v -> blockPalette.add(chunk.getBlock(v))); return blockPalette; } - private Palette createTilePalette(ChunkData chunk) { + private Palette createTilePalette(DefaultChunkData chunk) { Palette tilePalette = new Palette<>(); chunk.forEachTile((ts, t) -> tilePalette.add(t)); return tilePalette; @@ -193,9 +196,9 @@ public class TestChunkCodec extends ChunkCodec { } } - private void writeBlocks(ChunkData chunk, Palette blockPalette, DataOutput output) throws IOException { + private void writeBlocks(DefaultChunkData chunk, Palette blockPalette, DataOutput output) throws IOException { try { - chunk.forEachBiC(guard(v -> { + GenericChunks.forEachBiC(guard(v -> { output.writeInt(blockPalette.getNid(chunk.getBlock(v))); })); } catch (UncheckedIOException e) { @@ -203,7 +206,7 @@ public class TestChunkCodec extends ChunkCodec { } } - private void writeTiles(ChunkData chunk, Palette tilePalette, DataOutput output) throws IOException { + private void writeTiles(DefaultChunkData chunk, Palette tilePalette, DataOutput output) throws IOException { Vec3i bic = new Vec3i(); try { diff --git a/src/main/java/ru/windcorp/progressia/test/TestContent.java b/src/main/java/ru/windcorp/progressia/test/TestContent.java index 1244560..99c41fc 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestContent.java +++ b/src/main/java/ru/windcorp/progressia/test/TestContent.java @@ -256,6 +256,10 @@ public class TestContent { register("Test:Statie", TestEntityDataStatie::new); register(new TestEntityRenderStatie("Test:Statie")); register(new TestEntityLogicStatie("Test:Statie")); + + register("Test:FallingBlock", TestEntityDataFallingBlock::new); + register(new TestEntityLogicFallingBlock("Test:FallingBlock")); + register(new TestEntityRenderFallingBlock("Test:FallingBlock")); } private static void regsiterControls() { diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java index 7d11bb6..705d1af 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java @@ -1,5 +1,7 @@ package ru.windcorp.progressia.test; +import org.apache.logging.log4j.LogManager; + import ru.windcorp.progressia.common.collision.AABB; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.entity.EntityData; @@ -17,13 +19,18 @@ public class TestEntityDataFallingBlock extends EntityData { private boolean hasDeleted = false; public TestEntityDataFallingBlock() { - this("Test:FallingBlock", new BlockData("Test:Sand")); + this("Test:FallingBlock", new BlockData("Test:LogTop")); + } + + public TestEntityDataFallingBlock(BlockData data) { + this("Test:FallingBlock", data); } protected TestEntityDataFallingBlock(String id, BlockData blockInput) { super(id); setCollisionModel(new AABB(0, 0, 0, 1, 1, 1)); block = blockInput; + LogManager.getLogger().info(blockInput.getId()); } public void setDestroyed() { diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java index 0730d63..03c725d 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java @@ -1,6 +1,8 @@ package ru.windcorp.progressia.test; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.apache.logging.log4j.LogManager; @@ -10,9 +12,10 @@ import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.common.world.block.BlockDataRegistry; import ru.windcorp.progressia.common.world.entity.EntityData; -import ru.windcorp.progressia.server.Server; -import ru.windcorp.progressia.server.world.TickContext; +import ru.windcorp.progressia.server.world.context.ServerWorldContext; import ru.windcorp.progressia.server.world.entity.EntityLogic; +import ru.windcorp.progressia.test.Rocks.Rock; +import ru.windcorp.progressia.test.Rocks.RockVariant; /** * Logic for Test:FallingBlock @@ -26,6 +29,11 @@ public class TestEntityLogicFallingBlock extends EntityLogic { public void addFallables() { FallingBlocks.add("Test:Sand"); + for (Rock rock : TestContent.ROCKS.getRocks()) + { + FallingBlocks.add(rock.getBlock(RockVariant.GRAVEL).getId()); + FallingBlocks.add(rock.getBlock(RockVariant.SAND).getId()); + } } public TestEntityLogicFallingBlock(String id) { @@ -33,7 +41,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic { addFallables(); } - private Vec3i trueMod(Vec3i input, Vec3i modulus) // Move this to a class in + /*private Vec3i trueMod(Vec3i input, Vec3i modulus) // Move this to a class in // Vec or something { return input.mod_(modulus).add_(modulus).mod_(modulus); @@ -45,28 +53,71 @@ public class TestEntityLogicFallingBlock extends EntityLogic { Vec3i temp = input.div_(divisor); temp.add(new Vec3i(input.x < 0 ? -1 : 0, input.y < 0 ? -1 : 0, input.z < 0 ? -1 : 0)); return temp; + }*/ + + public Vec3i getBestCardinal(Vec3 dir) + { + Vec3 a = dir.abs_(); + if (a.x>a.y && a.x>a.z) + { + return new Vec3i(dir.x>0 ? 1 : -1,0,0); + } + else if (a.y>a.z) + { + return new Vec3i(0,dir.y>0 ? 1 : -1,0); + } + return new Vec3i(0,0,dir.z>0 ? 1 : -1); + } + + public List getGoodCardinals(Vec3 dir) + { + return getGoodCardinals(dir,.05f); + } + + public List getGoodCardinals(Vec3 dir, float d) { + List list = new ArrayList<>(); + Vec3 a = dir.abs_(); + if (a.x>d) + { + list.add(new Vec3i(dir.x>0 ? 1 : -1,0,0)); + } + if (a.y>d) + { + list.add(new Vec3i(0,dir.y>0 ? 1 : -1,0)); + } + if (a.z>d) + { + list.add(new Vec3i(0,0,dir.z>0 ? 1 : -1)); + } + return list; } @Override - public void tick(EntityData entity, TickContext context) { // context.getWorldData() + public void tick(EntityData entity, ServerWorldContext context) { // context.getWorldData() // ClientState.getInstance().getWorld().getData() + if (entity == null) { return; } + // LogManager.getLogger().info("NotNull "+entity.toString()+" // "+String.valueOf(entity!=null) + " " + // context.toString()); super.tick(entity, context); + // friction Vec3 vel = entity.getVelocity(); float friction = 0f; vel = new Vec3(vel.x * friction, vel.y * friction, vel.z); entity.setVelocity(vel); + //TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) context.//context.getEntity(entity.getEntityId()); + TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld() - .getData().getEntity(entity.getEntityId()); // ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); + .getData().getEntity(entity.getEntityId()); + TestEntityDataFallingBlock fallBlock2 = (TestEntityDataFallingBlock) entity;// ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); // fallBlock = (TestEntityDataFallingBlock) entity; // LogManager.getLogger().info("NotNull FB @@ -74,46 +125,56 @@ public class TestEntityLogicFallingBlock extends EntityLogic { if (fallBlock == null) { return; } + + - if (fallBlock.isDone() || !context.getWorld().isBlockLoaded(fallBlock.getBlockInWorld(null))) { + if (fallBlock.isDone() || context.getBlock(fallBlock.getBlockInWorld(null)) == null) { return; } + + //LogManager.getLogger().info("wut"); if (!fallBlock.hasDestroyed()) { - // LogManager.getLogger().info(fallBlock.getStartPos()); - context.getAccessor().setBlock(fallBlock.getBlockInWorld(null), + LogManager.getLogger().info(fallBlock.getPosition().x); + context.setBlock(fallBlock.getBlockInWorld(null), BlockDataRegistry.getInstance().get("Test:Air")); fallBlock.setDestroyed(); } Vec3i occupiedBlock = fallBlock.getBlockInWorld(null); - Vec3i underBlock = occupiedBlock.sub_(0, 0, 1); + Vec3i underBlock = occupiedBlock.sub_(getBestCardinal(fallBlock.getUpVector())); + List underBlocks = getGoodCardinals(fallBlock.getUpVector()); + + boolean notSupported = false; + for (Vec3i v3 : underBlocks) + { + Vec3i inWorld = occupiedBlock.sub_(v3); + if (context.getBlock(inWorld).getId()=="Test:Air") { + notSupported=true; + break; + } + } - Vec3i chunkCoords = trueDiv(underBlock, new Vec3i(16)); - Vec3i inChunkCoords = trueMod(underBlock, new Vec3i(16)); + //LogManager.getLogger().info("InChunk + //"+String.valueOf(chunkCoords.x)+" "+String.valueOf(chunkCoords.y)+" + //"+String.valueOf(chunkCoords.z)+" "+String.valueOf(inChunkCoords.x)+" + ////"+String.valueOf(inChunkCoords.y)+" + //"+String.valueOf(inChunkCoords.z)); + /*LogManager.getLogger().info("FallingBlock is at {},{},{}", + String.valueOf(occupiedBlock.x), + String.valueOf(occupiedBlock.y), + String.valueOf(occupiedBlock.z));*/ + //LogManager.getLogger().info("Block is of type " + + //context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); - // LogManager.getLogger().info("InChunk - // "+String.valueOf(chunkCoords.x)+" "+String.valueOf(chunkCoords.y)+" - // "+String.valueOf(chunkCoords.z)+" "+String.valueOf(inChunkCoords.x)+" - // "+String.valueOf(inChunkCoords.y)+" - // "+String.valueOf(inChunkCoords.z)); - // LogManager.getLogger().info("FallingBlock is at - // "+String.valueOf(occupiedBlock.x)+" - // "+String.valueOf(occupiedBlock.y)+" - // "+String.valueOf(occupiedBlock.z)); - // LogManager.getLogger().info("Block is of type " + - // context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); - - if (context.getWorldData().isBlockLoaded(occupiedBlock) - && context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId() != "Test:Air") { + if (context.getBlock(underBlock) != null + // && context.getBlock(underBlock).getId() != "Test:Air") { + && !notSupported) { LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x) + " " + String.valueOf(occupiedBlock.y) + " " + String.valueOf(occupiedBlock.z)); - // ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, - // fallBlock.getBlock(),true); - context.getAccessor().setBlock(occupiedBlock, fallBlock.getBlock()); - fallBlock.setInvisible(); // Until I know how to properly delete it. - //ClientState.getInstance().getWorld().getData().removeEntity(entity.getEntityId());// context.getWorldData().removeEntity(entity.getEntityId()); - Server server = context.getServer(); - server.invokeLater(() -> server.getWorld().getData().removeEntity(entity.getEntityId())); + context.setBlock(occupiedBlock, fallBlock2.getBlock()); + fallBlock.setInvisible(); + //server.invokeLater(() -> server.getWorld().getData().removeEntity(entity.getEntityId())); + context.removeEntity(fallBlock); } } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java index 5d4ddab..ab121e3 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java @@ -1,5 +1,6 @@ package ru.windcorp.progressia.test; +import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.client.graphics.model.Renderable; import ru.windcorp.progressia.client.graphics.model.ShapeRenderHelper; import ru.windcorp.progressia.client.graphics.model.Shapes; @@ -21,7 +22,7 @@ public class TestEntityRenderFallingBlock extends EntityRender { public TestEntityRenderFallingBlock(String id) { super(id); - String dflt = "Sand";//(String) TestEntityLogicFallingBlock.FallingBlocks.toArray()[0]; + String dflt = TestEntityLogicFallingBlock.FallingBlocks.toArray()[0].toString().substring(5); cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), BlockRenderRegistry.getBlockTexture(dflt ) )// TODO idk actual ggood this .create(); } @@ -34,7 +35,7 @@ public class TestEntityRenderFallingBlock extends EntityRender { public EntityRenderable createRenderable(EntityData entity) { return new EntityRenderable(entity) { @Override - public void render(ShapeRenderHelper renderer) { + public void doRender(ShapeRenderHelper renderer) { // LogManager.getLogger().info("Rendering FallingBlock"); if (((TestEntityDataFallingBlock) entity).isDone()) { return; @@ -42,6 +43,8 @@ public class TestEntityRenderFallingBlock extends EntityRender { // SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/LogSide"), // new AtlasGroup("Blocks", 1 << 12)))); } + TestEntityDataFallingBlock fallEntity = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); + setTexture(BlockRenderRegistry.getBlockTexture(fallEntity.getBlock().getId().substring(5))); // setTexture(new // SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/Sand"), // new AtlasGroup("Blocks", 1 << 12)))); diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java index aa3ad1b..56b71ea 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import java.util.ArrayList; @@ -25,8 +25,8 @@ import glm.vec._3.Vec3; import ru.windcorp.progressia.client.graphics.Colors; import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface; import ru.windcorp.progressia.client.graphics.backend.Usage; -import ru.windcorp.progressia.client.graphics.model.Face; -import ru.windcorp.progressia.client.graphics.model.Faces; +import ru.windcorp.progressia.client.graphics.model.ShapePart; +import ru.windcorp.progressia.client.graphics.model.ShapeParts; import ru.windcorp.progressia.client.graphics.model.LambdaModel; import ru.windcorp.progressia.client.graphics.model.Renderable; import ru.windcorp.progressia.client.graphics.model.Shape; @@ -39,8 +39,8 @@ import ru.windcorp.progressia.client.world.entity.EntityRender; import ru.windcorp.progressia.client.world.entity.EntityRenderRegistry; import ru.windcorp.progressia.client.world.entity.EntityRenderable; import ru.windcorp.progressia.client.world.entity.QuadripedModel; -import ru.windcorp.progressia.common.world.block.BlockFace; import ru.windcorp.progressia.common.world.entity.EntityData; +import ru.windcorp.progressia.common.world.rels.AbsFace; public class TestEntityRenderJavapony extends EntityRender { @@ -54,7 +54,11 @@ public class TestEntityRenderJavapony extends EntityRender { public TestEntityRenderJavapony(String id) { super(id); - ComplexTexture texture = new ComplexTexture(EntityRenderRegistry.getEntityTexture("javapony"), 256, 128); + ComplexTexture texture = new ComplexTexture( + EntityRenderRegistry.getEntityTexture("javapony"), + 256, + 128 + ); this.body = createBody(texture); this.head = createHead(texture); @@ -71,85 +75,230 @@ public class TestEntityRenderJavapony extends EntityRender { Texture tailStartTexture = texture.get(128, 96, 8, 32); - b.addStaticPart(new PppBuilder(WorldRenderProgram.getDefault(), - BlockFace.mapToFaces(tailStartTexture, tailStartTexture, tailStartTexture, tailStartTexture, - tailStartTexture, tailStartTexture)).setOrigin(-60, -4, 14).setDepth(32, 0, -16).setWidth(8) - .setHeight(8).create()); + b.addStaticPart( + new PppBuilder( + WorldRenderProgram.getDefault(), + tailStartTexture + ) + .setOrigin(-60, -4, 14) + .setDepth(32, 0, -16).setWidth(8).setHeight(8) + .create() + ); Texture neckTexture = texture.get(0, 48, 16, 16); - b.addStaticPart(new PppBuilder(WorldRenderProgram.getDefault(), - BlockFace.mapToFaces(neckTexture, neckTexture, neckTexture, neckTexture, neckTexture, neckTexture)) - .setOrigin(0, -8, 8).setWidth(16).setDepth(16).setHeight(2, 0, 16).create()); + b.addStaticPart( + new PppBuilder( + WorldRenderProgram.getDefault(), + neckTexture + ) + .setOrigin(0, -8, 8) + .setWidth(16).setDepth(16).setHeight(2, 0, 16) + .create() + ); - b.addDynamicPart(createTail(texture), - m -> m.translate(-60, 0, 24).rotateX(0.05f * Math.sin(GraphicsInterface.getTime())) - .rotateY(0.05f * Math.sin(Math.PI / 3 * GraphicsInterface.getTime()))); + b.addDynamicPart( + createTail(texture), + m -> m + .translate(-60, 0, 24) + .rotateX(0.05f * Math.sin(GraphicsInterface.getTime())) + .rotateY(0.05f * Math.sin(Math.PI / 3 * GraphicsInterface.getTime())) + ); return new LambdaModel(b); } private static Renderable createMainBody(ComplexTexture texture) { WorldRenderProgram program = WorldRenderProgram.getDefault(); - List faces = new ArrayList<>(); + List faces = new ArrayList<>(); // F BODY - faces.add(Faces.createRectangle(program, texture.get(80, 16, 32, 32), Colors.WHITE, new Vec3(+16, -16, -16), - new Vec3(0, +32, 0), new Vec3(0, 0, +32), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(80, 16, 32, 32), + Colors.WHITE, + new Vec3(+16, -16, -16), + new Vec3(0, +32, 0), + new Vec3(0, 0, +32), + false + ) + ); // NECK BASE - faces.add(Faces.createRectangle(program, texture.get(80, 48, 32, 16), Colors.WHITE, new Vec3(+16, -16, +16), - new Vec3(0, +32, 0), new Vec3(-16, 0, 0), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(80, 48, 32, 16), + Colors.WHITE, + new Vec3(+16, -16, +16), + new Vec3(0, +32, 0), + new Vec3(-16, 0, 0), + false + ) + ); // T BODY (BACK) - faces.add(Faces.createRectangle(program, texture.get(128, 0, 32, 48), Colors.WHITE, new Vec3(0, -16, +16), - new Vec3(0, +32, 0), new Vec3(-48, 0, 0), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(128, 0, 32, 48), + Colors.WHITE, + new Vec3(0, -16, +16), + new Vec3(0, +32, 0), + new Vec3(-48, 0, 0), + false + ) + ); // BOTTOM B (upper) - faces.add(Faces.createRectangle(program, texture.get(144, 48, 32, 16), Colors.WHITE, new Vec3(-48, -16, 0), - new Vec3(0, 32, 0), new Vec3(0, 0, 16), true)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(144, 48, 32, 16), + Colors.WHITE, + new Vec3(-48, -16, 0), + new Vec3(0, 32, 0), + new Vec3(0, 0, 16), + true + ) + ); // BOTTOM B (lower) - faces.add(Faces.createRectangle(program, texture.get(144, 48, 32, 16), Colors.WHITE, new Vec3(-48, -16, -16), - new Vec3(0, 32, 0), new Vec3(0, 0, 16), true)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(144, 48, 32, 16), + Colors.WHITE, + new Vec3(-48, -16, -16), + new Vec3(0, 32, 0), + new Vec3(0, 0, 16), + true + ) + ); // BOTTOM B (stomach) - faces.add(Faces.createRectangle(program, texture.get(144, 48, 32, 16), Colors.WHITE, new Vec3(-48, -16, -16), - new Vec3(0, 32, 0), new Vec3(16, 0, 0), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(144, 48, 32, 16), + Colors.WHITE, + new Vec3(-48, -16, -16), + new Vec3(0, 32, 0), + new Vec3(16, 0, 0), + false + ) + ); // STOMACH - faces.add(Faces.createRectangle(program, texture.get(224, 96, 32, 32), Colors.WHITE, new Vec3(-32, -16, -16), - new Vec3(0, 32, 0), new Vec3(32, 0, 0), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(224, 96, 32, 32), + Colors.WHITE, + new Vec3(-32, -16, -16), + new Vec3(0, 32, 0), + new Vec3(32, 0, 0), + false + ) + ); // BOTTOM F - faces.add(Faces.createRectangle(program, texture.get(112, 48, 32, 16), Colors.WHITE, new Vec3(+16, -16, -16), - new Vec3(0, 32, 0), new Vec3(-16, 0, 0), true)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(112, 48, 32, 16), + Colors.WHITE, + new Vec3(+16, -16, -16), + new Vec3(0, 32, 0), + new Vec3(-16, 0, 0), + true + ) + ); // BODY L - faces.add(Faces.createRectangle(program, texture.get(112, 16, 16, 32), Colors.WHITE, new Vec3(+16, +16, -16), - new Vec3(-16, 0, 0), new Vec3(0, 0, +32), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(112, 16, 16, 32), + Colors.WHITE, + new Vec3(+16, +16, -16), + new Vec3(-16, 0, 0), + new Vec3(0, 0, +32), + false + ) + ); // BODY SIDES (left) - faces.add(Faces.createRectangle(program, texture.get(96, 96, 32, 32), Colors.WHITE, new Vec3(0, +16, -16), - new Vec3(-32, 0, 0), new Vec3(0, 0, +32), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(96, 96, 32, 32), + Colors.WHITE, + new Vec3(0, +16, -16), + new Vec3(-32, 0, 0), + new Vec3(0, 0, +32), + false + ) + ); // QT MARK (left) - faces.add(Faces.createRectangle(program, texture.get(16, 96, 16, 32), Colors.WHITE, new Vec3(-32, +16, -16), - new Vec3(-16, 0, 0), new Vec3(0, 0, +32), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(16, 96, 16, 32), + Colors.WHITE, + new Vec3(-32, +16, -16), + new Vec3(-16, 0, 0), + new Vec3(0, 0, +32), + false + ) + ); // BODY R - faces.add(Faces.createRectangle(program, texture.get(64, 16, 16, 32), Colors.WHITE, new Vec3(0, -16, -16), - new Vec3(+16, 0, 0), new Vec3(0, 0, +32), false)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(64, 16, 16, 32), + Colors.WHITE, + new Vec3(0, -16, -16), + new Vec3(+16, 0, 0), + new Vec3(0, 0, +32), + false + ) + ); // BODY SIDES (right) - faces.add(Faces.createRectangle(program, texture.get(96, 96, 32, 32), Colors.WHITE, new Vec3(0, -16, -16), - new Vec3(-32, 0, 0), new Vec3(0, 0, +32), true)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(96, 96, 32, 32), + Colors.WHITE, + new Vec3(0, -16, -16), + new Vec3(-32, 0, 0), + new Vec3(0, 0, +32), + true + ) + ); // QT MARK (right) - faces.add(Faces.createRectangle(program, texture.get(16, 96, 16, 32), Colors.WHITE, new Vec3(-32, -16, -16), - new Vec3(-16, 0, 0), new Vec3(0, 0, +32), true)); + faces.add( + ShapeParts.createRectangle( + program, + texture.get(16, 96, 16, 32), + Colors.WHITE, + new Vec3(-32, -16, -16), + new Vec3(-16, 0, 0), + new Vec3(0, 0, +32), + true + ) + ); - return new Shape(Usage.STATIC, program, faces.toArray(new Face[faces.size()])); + return new Shape( + Usage.STATIC, + program, + faces.toArray(new ShapePart[faces.size()]) + ); } private static Renderable createHead(ComplexTexture texture) { @@ -157,42 +306,87 @@ public class TestEntityRenderJavapony extends EntityRender { StaticModel.Builder b = StaticModel.builder(); // Head - b.addPart(new PppBuilder(program, texture.getCuboidTextures(0, 64, 32)).setOrigin(-16, -16, 0).setSize(32) - .create()); + b.addPart( + new PppBuilder( + program, + texture.getCuboidTextures(0, 64, 32) + ).setOrigin(-16, -16, 0).setSize(32).create() + ); final float hairOffset = 1f; // Hair - b.addPart(new PppBuilder(program, texture.getCuboidTextures(128, 64, 32)) - .setOrigin(-16 - hairOffset, -16 - hairOffset, -hairOffset).setSize(32 + 2 * hairOffset).create()); + b.addPart( + new PppBuilder( + program, + texture.getCuboidTextures(128, 64, 32) + ) + .setOrigin(-16 - hairOffset, -16 - hairOffset, -hairOffset) + .setSize(32 + 2 * hairOffset) + .create() + ); // Right ear - b.addPart(new PppBuilder(program, texture.getCuboidTextures(48, 128 - 80, 8)).setOrigin(-16 + 3, -16, 32) - .setSize(8).create()); + b.addPart( + new PppBuilder( + program, + texture.getCuboidTextures(48, 128 - 80, 8) + ).setOrigin(-16 + 3, -16, 32).setSize(8).create() + ); // Left ear - b.addPart(new PppBuilder(program, texture.getCuboidTextures(48, 128 - 80, 8)).setOrigin(-16 + 3, +16, 32) - .setSize(8, -8, 8).flip().create()); + b.addPart( + new PppBuilder( + program, + texture.getCuboidTextures(48, 128 - 80, 8) + ).setOrigin(-16 + 3, +16, 32).setSize(8, -8, 8).flip().create() + ); // Muzzle - b.addPart(new PppBuilder(program, - BlockFace.mapToFaces(texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), - texture.get(32 + 8, 64, 16, 8), texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0))).setOrigin(16, -8, 0).setSize(4, 16, 8).create()); + b.addPart( + new PppBuilder( + program, + AbsFace.mapToFaces( + texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0), + texture.get(32 + 8, 64, 16, 8), + texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0) + ) + ).setOrigin(16, -8, 0).setSize(4, 16, 8).create() + ); // Nose - b.addPart(new PppBuilder(program, - BlockFace.mapToFaces(texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), - texture.get(32 + 12, 64 + 8, 8, 4), texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0))).setOrigin(16, -4, 8).setSize(4, 8, 4).create()); + b.addPart( + new PppBuilder( + program, + AbsFace.mapToFaces( + texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0), + texture.get(32 + 12, 64 + 8, 8, 4), + texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0) + ) + ).setOrigin(16, -4, 8).setSize(4, 8, 4).create() + ); return b.build(); } - private static Renderable createLeg(ComplexTexture texture, int textureX, int textureY, boolean isLeft) { - PppBuilder b = new PppBuilder(WorldRenderProgram.getDefault(), - texture.getCuboidTextures(textureX, textureY, 16, 48, 16)).setOrigin(-8, isLeft ? +8 : -8, -48) - .setSize(16, isLeft ? -16 : +16, 48); + private static Renderable createLeg( + ComplexTexture texture, + int textureX, + int textureY, + boolean isLeft + ) { + PppBuilder b = new PppBuilder( + WorldRenderProgram.getDefault(), + texture.getCuboidTextures(textureX, textureY, 16, 48, 16) + ) + .setOrigin(-8, isLeft ? +8 : -8, -48) + .setSize(16, isLeft ? -16 : +16, 48); if (isLeft) b.flip(); @@ -205,26 +399,59 @@ public class TestEntityRenderJavapony extends EntityRender { StaticModel.Builder b = StaticModel.builder(); // Main tail - b.addPart(new PppBuilder(program, - BlockFace.mapToFaces(texture.get(128, 96, 16, 16), texture.get(128, 96, 16, 16), - texture.get(128, 96, 16, 32), texture.get(128, 96, 16, 32), texture.get(144, 96, 16, 32), - texture.get(144, 96, 16, 32))).setOrigin(-8, -8, -32).setSize(16, 16, 32).create()); + b.addPart( + new PppBuilder( + program, + AbsFace.mapToFaces( + texture.get(128, 96, 16, 16), + texture.get(128, 96, 16, 16), + texture.get(128, 96, 16, 32), + texture.get(128, 96, 16, 32), + texture.get(144, 96, 16, 32), + texture.get(144, 96, 16, 32) + ) + ).setOrigin(-8, -8, -32).setSize(16, 16, 32).create() + ); return b.build(); } @Override public EntityRenderable createRenderable(EntityData entity) { - return new QuadripedModel(entity, + return new QuadripedModel( + entity, - new QuadripedModel.Body(body), - new QuadripedModel.Head(head, new Vec3(12, 0, 20), 120, 45, new Vec3(16, 0, 20)), - new QuadripedModel.Leg(leftForeLeg, new Vec3(6, +8.1f, -16), 0.0f), - new QuadripedModel.Leg(rightForeLeg, new Vec3(6, -8.1f, -16), 2.5f), - new QuadripedModel.Leg(leftHindLeg, new Vec3(-36, +8.2f, -16), 2.5f), - new QuadripedModel.Leg(rightHindLeg, new Vec3(-36, -8.2f, -16), 0.0f), + new QuadripedModel.Body(body), + new QuadripedModel.Head( + head, + new Vec3(12, 0, 20), + 120, + 45, + new Vec3(16, 0, 20) + ), + new QuadripedModel.Leg( + leftForeLeg, + new Vec3(6, +8.1f, -16), + 0.0f + ), + new QuadripedModel.Leg( + rightForeLeg, + new Vec3(6, -8.1f, -16), + 2.5f + ), + new QuadripedModel.Leg( + leftHindLeg, + new Vec3(-36, +8.2f, -16), + 2.5f + ), + new QuadripedModel.Leg( + rightHindLeg, + new Vec3(-36, -8.2f, -16), + 0.0f + ), - 1 / 96f); + 1 / 96f + ); } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java b/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java index ee42396..f535f3f 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java +++ b/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java @@ -22,6 +22,9 @@ import glm.Glm; import glm.mat._3.Mat3; import glm.mat._4.Mat4; import glm.vec._3.Vec3; + +import java.util.function.Function; + import org.lwjgl.glfw.GLFW; import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.client.graphics.GUI; @@ -58,6 +61,8 @@ public class TestPlayerControls { // Horizontal and vertical max control speed when flying private static final float FLYING_SPEED = Units.get("6 m/s"); + + private static final Function SPRINTING_FLYING_SPEED = (f) -> {return Math.pow(f,.75)+2*FLYING_SPEED;}; // (0; 1], 1 is instant change, 0 is no control authority private static final float FLYING_CONTROL_AUTHORITY = Units.get("2 1/s"); @@ -101,7 +106,8 @@ public class TestPlayerControls { final float speed, authority; if (isFlying) { - speed = FLYING_SPEED; + double timeSinceLastSpacePress = GraphicsInterface.getTime() - lastSprintPress; + speed = isSprinting ? SPRINTING_FLYING_SPEED.apply(timeSinceLastSpacePress).floatValue() : FLYING_SPEED; authority = FLYING_CONTROL_AUTHORITY; } else { speed = isSprinting ? SPRINTING_SPEED : WALKING_SPEED; @@ -256,10 +262,11 @@ public class TestPlayerControls { double timeSinceLastSpacePress = GraphicsInterface.getTime() - lastSpacePress; if (isPressed && timeSinceLastSpacePress < MODE_SWITCH_MAX_DELAY) { - isSprinting = false; + //isSprinting = false; isFlying = !isFlying; updateGUI(); movementUp = +1; + timeSinceLastSpacePress = MODE_SWITCH_MAX_DELAY; } else { if (isFlying) { movementUp += +1 * multiplier; @@ -274,10 +281,12 @@ public class TestPlayerControls { } private void handleSprint(KeyEvent event) { + + //LogManager.getLogger().info("hi"); double timeSinceLastSpacePress = GraphicsInterface.getTime() - lastSprintPress; - if (event.isPress() && timeSinceLastSpacePress < MODE_SPRINT_SWITCH_MAX_DELAY && !isFlying) { + if (event.isPress() && timeSinceLastSpacePress < MODE_SPRINT_SWITCH_MAX_DELAY) { isSprinting = !isSprinting; updateGUI(); }