Skip to content

Commit

Permalink
Fix the "models in the same position"
Browse files Browse the repository at this point in the history
Models were not in the same position, however something funny was happening because (0,0,0) was not empty. However, it wasn't meshing correctly (I think). This led to both (0,-1,0) and (0,0,0) having a face rendered at the same position. This needs to be looked into.
  • Loading branch information
kitskub committed Sep 8, 2014
1 parent b01f5be commit 2e37686
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.flowpowered.math.vector.Vector3f;

public class PlayerControlledMovementComponent extends EntityComponent {
private static final float SPEED = 20f;
private static final float SPEED = 10f;

private Player controller;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void generate(CuboidBlockMaterialBuffer blockData, World world) {
}
final int bottom = Math.max(-32, minBlockY);
final int top = Math.min(-1, maxBlockY);
blockData.setHorizontalLayer(bottom, top - bottom + 1, material);
blockData.setHorizontalLayer(bottom, top - bottom, material);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ public void run() {
return null;
}

private static volatile int genCount = 0;

public static int getGenCount() {
return genCount;
}

// If loadopt.isWait(), this method is run synchronously and so is any further generation
// If !loadopt.isWait(), this method is run by a runnable, because the loading is taxing; any further generation is also run in its own Runnable
private FlowChunk loadOrGenChunkImmediately(int worldX, int worldY, int worldZ, final LoadOption loadopt) {
Expand All @@ -193,7 +187,6 @@ private FlowChunk loadOrGenChunkImmediately(int worldX, int worldY, int worldZ,
return newChunk;
}

genCount++;
generator.generateChunk(worldX, worldY, worldZ, loadopt.isWait());
if (!loadopt.isWait()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private void generateChunk0(final int chunkXWorld, final int chunkYWorld, final
throw new IllegalStateException("Unable to set generate state for column " + sectionX + ", " + sectionY +", " + sectionZ + " in region " + region.getBase().toBlockString() + " to copying, state is " + generated.get() + " wait is " + wait);
}
region.setGeneratedChunks(chunks);
genCount.incrementAndGet();

// We need to set the generated state before we unlock the readLock so waiting generators get the state immediately
if (!generated.compareAndSet(GenerateState.COPYING, GenerateState.COPIED)) {
Expand All @@ -185,7 +186,13 @@ private void generateChunk0(final int chunkXWorld, final int chunkYWorld, final
sectionLock.unlock();
}
}


private static AtomicInteger genCount = new AtomicInteger();

public static int getGenCount() {
return genCount.get();
}

private static void initExecutorService(Logger logger) {
if (pool.get() == null) {
pool.compareAndSet(null, LoggingThreadPoolExecutor.newFixedThreadExecutorWithMarkedName(Runtime.getRuntime().availableProcessors() * 2 + 1, "RegionGenerator - async pool", logger));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/flowpowered/engine/render/FlowRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

import com.flowpowered.api.render.Renderer;
import com.flowpowered.commons.TPSMonitor;
import com.flowpowered.engine.geo.region.FlowRegion;
import com.flowpowered.engine.geo.region.RegionGenerator;
import com.flowpowered.engine.scheduler.FlowScheduler;
import com.flowpowered.engine.scheduler.render.RenderThread;
import com.flowpowered.math.vector.Vector2i;
Expand Down Expand Up @@ -332,7 +332,7 @@ private void updateHUD() {
Camera camera = renderModelsNode.getAttribute("camera");
positionModel.setString("Position: " + camera.getPosition().toInt().toString() + " Rotation: " + camera.getRotation().toString());

genCountModel.setString("GenCount: " + FlowRegion.getGenCount());
genCountModel.setString("GenCount: " + RegionGenerator.getGenCount());
}

/**
Expand Down Expand Up @@ -450,10 +450,10 @@ public void saveScreenshot(File outputDir) {
@Override
public Vector2i getResolution() {
return windowSize;
}
}

@Override
public float getAspectRatio() {
return (float) windowSize.getY() / windowSize.getX();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public synchronized void render() {
previous = null;
}
}
if (!renderer.isChunkVisible(getPosition())) {
return;
}
// If we have a vertex array, we can render
if (complete) {
// Only render if the model has a vertex array and we're visible
if (getVertexArray() != null) {
if (!renderer.isChunkVisible(getPosition())) {
return;
}
super.render();
}
} else if (previous != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import com.flowpowered.api.geo.reference.WorldReference;
import com.flowpowered.api.geo.snapshot.ChunkSnapshot;
import com.flowpowered.api.input.KeyboardEvent;
import com.flowpowered.api.material.block.BlockFace;
import com.flowpowered.api.material.block.BlockFaces;
import com.flowpowered.commons.ViewFrustum;
import com.flowpowered.commons.ticking.TickingElement;
import com.flowpowered.engine.FlowClient;
Expand Down Expand Up @@ -179,14 +177,15 @@ private void updateChunkModels() {
addChunkModel(snapshot);
chunkLastUpdateNumbers.put(position, snapshot.getUpdateNumber());

// TODO: add this back in to make ChunkModels in render as efficient as possible
// Remesh surrounding chunks
for (BlockFace f : BlockFaces.NESWBT) {
Vector3i localPosition = position.add(f.getOffset());
ChunkSnapshot old = oldChunks.get(localPosition);
if (old != null) {
chunkLastUpdateNumbers.put(localPosition, 0);
}
}
//for (BlockFace f : BlockFaces.NESWBT) {
// Vector3i localPosition = position.add(f.getOffset());
// ChunkSnapshot old = oldChunks.get(localPosition);
// if (old != null) {
// chunkLastUpdateNumbers.put(localPosition, 0);
// }
//}
}

for (ChunkSnapshot chunk : oldChunks.values()) {
Expand Down

0 comments on commit 2e37686

Please sign in to comment.