Skip to content

Commit

Permalink
Make changes to VBOs and add a config option for them
Browse files Browse the repository at this point in the history
- Rendering with VBOs can be enabled and disabled
- BlockEntityClientState was generalized into CableVBOContainer
- Most reliance on an available BlockEntity for rendering with VBOs has been removed
- Major refactoring of VBO rendering away from CableOutputBlockEntityRenderer
- Abstracted BlockEntityOutputs
  • Loading branch information
FoundationGames committed Aug 7, 2023
1 parent beb55f0 commit 1422f25
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 221 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.foundationgames.phonos.block.entity;

import io.github.foundationgames.phonos.client.render.BlockEntityClientState;
import io.github.foundationgames.phonos.client.render.CableVBOContainer;
import io.github.foundationgames.phonos.sound.emitter.SoundSource;
import io.github.foundationgames.phonos.util.UniqueId;
import io.github.foundationgames.phonos.world.sound.block.BlockConnectionLayout;
Expand All @@ -23,14 +23,15 @@ public abstract class AbstractOutputBlockEntity extends BlockEntity implements S
public final BlockEntityOutputs outputs;
protected @Nullable NbtCompound pendingNbt = null;
protected final long emitterId;
private BlockEntityClientState clientState;

private CableVBOContainer vboContainer;

public AbstractOutputBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, BlockConnectionLayout outputLayout) {
super(type, pos, state);

this.emitterId = UniqueId.ofBlock(pos);
this.outputs = new BlockEntityOutputs(outputLayout, this);
this.clientState = null;
this.vboContainer = null;
}

@Override
Expand Down Expand Up @@ -120,20 +121,29 @@ public BlockEntityOutputs getOutputs() {
}

@Override
public BlockEntityClientState getClientState() {
if (this.clientState == null) {
this.clientState = new BlockEntityClientState();
public void enforceVBOState(boolean enabled) {
if (this.vboContainer != null && !enabled) {
this.vboContainer.close();

this.vboContainer = null;
}
}

@Override
public CableVBOContainer getOrCreateVBOContainer() {
if (this.vboContainer == null) {
this.vboContainer = new CableVBOContainer();
}

this.clientState.genState(this.outputs);
return this.clientState;
this.vboContainer.refresh(this.outputs);
return this.vboContainer;
}

@Override
public void markRemoved() {
if (this.hasWorld() && this.world.isClient && this.clientState != null) {
this.clientState.dirty = true;
this.clientState.close();
if (this.hasWorld() && this.world.isClient() && this.vboContainer != null) {
this.vboContainer.rebuild = true;
this.vboContainer.close();
}
super.markRemoved();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.foundationgames.phonos.block.entity;

import io.github.foundationgames.phonos.block.PhonosBlocks;
import io.github.foundationgames.phonos.client.render.BlockEntityClientState;
import io.github.foundationgames.phonos.client.render.CableVBOContainer;
import io.github.foundationgames.phonos.network.PayloadPackets;
import io.github.foundationgames.phonos.sound.SoundStorage;
import io.github.foundationgames.phonos.sound.emitter.SoundEmitterTree;
Expand Down Expand Up @@ -47,17 +47,17 @@ public class ElectronicJukeboxBlockEntity extends JukeboxBlockEntity implements
private final BlockEntityType<?> type;
private @Nullable NbtCompound pendingNbt = null;
private final long emitterId;
private BlockEntityClientState clientState;

private @Nullable SoundEmitterTree playingSound = null;

private CableVBOContainer vboContainer;

public ElectronicJukeboxBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(pos, state);
this.type = type;
this.emitterId = UniqueId.ofBlock(pos);

this.outputs = new BlockEntityOutputs(OUTPUT_LAYOUT, this);
this.clientState = null;
this.vboContainer = null;
}

public ElectronicJukeboxBlockEntity(BlockPos pos, BlockState state) {
Expand Down Expand Up @@ -201,20 +201,29 @@ public BlockEntityOutputs getOutputs() {
}

@Override
public BlockEntityClientState getClientState() {
if (this.clientState == null) {
this.clientState = new BlockEntityClientState();
public void enforceVBOState(boolean enabled) {
if (this.vboContainer != null && !enabled) {
this.vboContainer.close();

this.vboContainer = null;
}
}

@Override
public CableVBOContainer getOrCreateVBOContainer() {
if (this.vboContainer == null) {
this.vboContainer = new CableVBOContainer();
}

this.clientState.genState(this.outputs);
return this.clientState;
this.vboContainer.refresh(this.outputs);
return this.vboContainer;
}

@Override
public void markRemoved() {
if (this.hasWorld() && this.world.isClient && this.clientState != null) {
this.clientState.dirty = true;
this.clientState.close();
if (this.hasWorld() && this.world.isClient() && this.vboContainer != null) {
this.vboContainer.rebuild = true;
this.vboContainer.close();
}
super.markRemoved();
}
Expand Down

This file was deleted.

Loading

0 comments on commit 1422f25

Please sign in to comment.