Skip to content

Commit

Permalink
change: Use integer handles for graphics state to avoid passing types
Browse files Browse the repository at this point in the history
  • Loading branch information
jellysquid3 committed Mar 15, 2021
1 parent 2fb1d28 commit de545a5
Show file tree
Hide file tree
Showing 42 changed files with 803 additions and 592 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public class SodiumWorldRenderer implements ChunkStatusListener {
private final Set<BlockEntity> globalBlockEntities = new ObjectOpenHashSet<>();

private Frustum frustum;
private ChunkRenderManager<?> chunkRenderManager;
private ChunkRenderManager chunkRenderManager;
private BlockRenderPassManager renderPassManager;
private ChunkRenderBackend<?> chunkRenderBackend;
private ChunkRenderBackend chunkRenderBackend;

/**
* Instantiates Sodium's world renderer. This should be called at the time of the world renderer initialization.
Expand Down Expand Up @@ -268,12 +268,12 @@ private void initRenderer() {
this.chunkRenderBackend = createChunkRenderBackend(opts.advanced.chunkRendererBackend, vertexFormat);
this.chunkRenderBackend.createShaders();

this.chunkRenderManager = new ChunkRenderManager<>(this, this.chunkRenderBackend, this.renderPassManager, this.world, this.renderDistance);
this.chunkRenderManager = new ChunkRenderManager(this, this.chunkRenderBackend, this.renderPassManager, this.world, this.renderDistance);
this.chunkRenderManager.restoreChunks(this.loadedChunkPositions);
}

private static ChunkRenderBackend<?> createChunkRenderBackend(SodiumGameOptions.ChunkRendererBackendOption opt,
ChunkVertexType vertexFormat) {
private static ChunkRenderBackend createChunkRenderBackend(SodiumGameOptions.ChunkRendererBackendOption opt,
ChunkVertexType vertexFormat) {
boolean disableBlacklist = SodiumClientMod.options().advanced.disableDriverBlacklist;

switch (opt) {
Expand Down Expand Up @@ -435,7 +435,7 @@ public void scheduleRebuildForChunk(int x, int y, int z, boolean important) {
this.chunkRenderManager.scheduleRebuild(x, y, z, important);
}

public ChunkRenderBackend<?> getChunkRenderer() {
public ChunkRenderBackend getChunkRenderer() {
return this.chunkRenderBackend;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package me.jellysquid.mods.sodium.client.render.chunk;

public abstract class ChunkGraphicsState {
import me.jellysquid.mods.sodium.common.util.collections.TrackedArrayItem;

public abstract class ChunkGraphicsState implements TrackedArrayItem {
private final int id;
private final int x, y, z;

protected ChunkGraphicsState(ChunkRenderContainer<?> container) {
protected ChunkGraphicsState(ChunkRenderContainer container, int id) {
this.x = container.getRenderX();
this.y = container.getRenderY();
this.z = container.getRenderZ();
this.id = id;
}

public abstract void delete();
Expand All @@ -22,4 +26,9 @@ public int getY() {
public int getZ() {
return this.z;
}

@Override
public int getId() {
return this.id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package me.jellysquid.mods.sodium.client.render.chunk;

import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;

public class ChunkGraphicsStateArray {
private final int[] key;
private final int[] value;

private int size;

public ChunkGraphicsStateArray(int size) {
this.key = new int[size];
this.value = new int[size];
}

public int get(BlockRenderPass pass) {
return this.get(pass.ordinal());
}

public int get(int pass) {
for (int i = 0; i < this.size; i++) {
if (this.key[i] == pass) {
return this.value[i];
}
}

return -1;
}

public void set(BlockRenderPass pass, int value) {
this.set(pass.ordinal(), value);
}

public void set(int pass, int value) {
if (value == -1) {
this.remove(pass);

return;
}

for (int i = 0; i < this.size; i++) {
if (this.key[i] == pass) {
this.value[i] = value;
return;
}
}

int i = this.size++;

this.key[i] = pass;
this.value[i] = value;
}

public int remove(BlockRenderPass pass) {
return this.remove(pass.ordinal());
}

public int remove(int pass) {
int value = -1;
int split = -1;

for (int i = 0; i < this.size; i++) {
if (this.key[i] == pass) {
split = i;
value = this.value[i];

break;
}
}

if (split < 0) {
return - 1;
}

this.size--;

System.arraycopy(this.key, split + 1, this.key, split, this.size - split);
System.arraycopy(this.value, split + 1, this.value, split, this.size - split);

return value;
}

public int getKey(int i) {
return this.key[i];
}

public int getValue(int i) {
return this.value[i];
}

public int getSize() {
return this.size;
}

public void clear() {
this.size = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@
/**
* The chunk render backend takes care of managing the graphics resource state of chunk render containers. This includes
* the handling of uploading their data to the graphics card and rendering responsibilities.
* @param <T> The type of graphics state to be used in chunk render containers
*/
public interface ChunkRenderBackend<T extends ChunkGraphicsState> {
public interface ChunkRenderBackend {
/**
* Drains the iterator of items and processes each build task's result serially. After this method returns, all
* drained results should be processed.
*/
void upload(Iterator<ChunkBuildResult<T>> queue);
void upload(Iterator<ChunkBuildResult> queue);

/**
* Renders the given chunk render list to the active framebuffer.
* @param renders An iterator over the list of chunks to be rendered
* @param camera The camera context containing chunk offsets for the current render
*/
void render(ChunkRenderListIterator<T> renders, ChunkCameraContext camera);
void render(ChunkRenderListIterator renders, ChunkCameraContext camera);

void createShaders();

Expand All @@ -44,13 +43,13 @@ public interface ChunkRenderBackend<T extends ChunkGraphicsState> {
*/
ChunkVertexType getVertexType();

Class<T> getGraphicsStateType();

default String getRendererName() {
return this.getClass().getSimpleName();
}

default List<String> getDebugStrings() {
return Collections.emptyList();
}

void deleteGraphicsState(int i);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import me.jellysquid.mods.sodium.common.util.DirectionUtil;
import net.minecraft.util.math.Direction;

public class ChunkRenderColumn<T extends ChunkGraphicsState> {
@SuppressWarnings("unchecked")
private final ChunkRenderContainer<T>[] renders = new ChunkRenderContainer[16];

@SuppressWarnings("unchecked")
private final ChunkRenderColumn<T>[] adjacent = new ChunkRenderColumn[6];
public class ChunkRenderColumn {
private final ChunkRenderContainer[] renders = new ChunkRenderContainer[16];
private final ChunkRenderColumn[] adjacent = new ChunkRenderColumn[6];

private final int x, z;

Expand All @@ -20,19 +17,19 @@ public ChunkRenderColumn(int x, int z) {
this.setAdjacentColumn(Direction.DOWN, this);
}

public void setAdjacentColumn(Direction dir, ChunkRenderColumn<T> column) {
public void setAdjacentColumn(Direction dir, ChunkRenderColumn column) {
this.adjacent[dir.ordinal()] = column;
}

public ChunkRenderColumn<T> getAdjacentColumn(Direction dir) {
public ChunkRenderColumn getAdjacentColumn(Direction dir) {
return this.adjacent[dir.ordinal()];
}

public void setRender(int y, ChunkRenderContainer<T> render) {
public void setRender(int y, ChunkRenderContainer render) {
this.renders[y] = render;
}

public ChunkRenderContainer<T> getRender(int y) {
public ChunkRenderContainer getRender(int y) {
return this.renders[y];
}

Expand All @@ -46,7 +43,7 @@ public int getZ() {

public boolean areNeighborsPresent() {
for (Direction dir : DirectionUtil.HORIZONTAL_DIRECTIONS) {
ChunkRenderColumn<T> adj = this.adjacent[dir.ordinal()];
ChunkRenderColumn adj = this.adjacent[dir.ordinal()];

if (adj == null) {
return false;
Expand Down
Loading

0 comments on commit de545a5

Please sign in to comment.