Skip to content

Commit

Permalink
Decrease Ram Requirements ( #369 )
Browse files Browse the repository at this point in the history
Also removes previous model compression algorithm.
  • Loading branch information
AlgorithmX2 committed Feb 18, 2018
1 parent e909375 commit d25ad19
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
4 changes: 0 additions & 4 deletions src/main/java/mod/chiselsandbits/config/ModConfig.java
Expand Up @@ -192,9 +192,6 @@ public class ModConfig extends Configuration
@Configured( category = "Client Performance Settings" )
public boolean dynamicRenderFullChunksOnly;

@Configured( category = "Client Performance Settings" )
public boolean enableModelCompression;

@Configured( category = "Balance Settings" )
public boolean blacklistTickingBlocks;

Expand Down Expand Up @@ -382,7 +379,6 @@ private void setDefaults()
dynamicRenderFullChunksOnly = true;
useVBO = UseVBO.AUTOMATIC;
disableCustomVertexFormats = false;
enableModelCompression = true;
enableFaceLightmapExtraction = true;
useGetLightValue = true;

Expand Down
Expand Up @@ -234,13 +234,10 @@ IFaceBuilder getBuilder(
{
if ( ChiseledBlockSmartModel.ForgePipelineDisabled() )
{
if ( ChiselsAndBits.getConfig().enableModelCompression )
return new ChiselsAndBitsBakedQuad.Builder( DefaultVertexFormats.ITEM, true );
else
return new UnpackedQuadBuilderWrapper( DefaultVertexFormats.ITEM );
format = DefaultVertexFormats.ITEM;
}

return new ChiselsAndBitsBakedQuad.Builder( format, ChiselsAndBits.getConfig().enableModelCompression );
return new ChiselsAndBitsBakedQuad.Builder( format );
}

private void generateFaces(
Expand Down
@@ -1,6 +1,8 @@
package mod.chiselsandbits.render.chiseledblock;

import mod.chiselsandbits.render.cache.InMemoryQuadCompressor;
import java.util.concurrent.ConcurrentHashMap;

import mod.chiselsandbits.render.cache.FormatInfo;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
Expand All @@ -13,8 +15,7 @@
public class ChiselsAndBitsBakedQuad extends BakedQuad
{

private static InMemoryQuadCompressor inMemoryCompressor = new InMemoryQuadCompressor();

public static final ConcurrentHashMap<VertexFormat, FormatInfo> formatData = new ConcurrentHashMap<VertexFormat, FormatInfo>();
public static final VertexFormat VERTEX_FORMAT = new VertexFormat();

static
Expand All @@ -28,7 +29,20 @@ public class ChiselsAndBitsBakedQuad extends BakedQuad
VERTEX_FORMAT.addElement( DefaultVertexFormats.TEX_2S );
}

protected final float[][][] rawVertData;
private static int[] packData(
VertexFormat format,
float[][][] unpackedData )
{
FormatInfo fi = formatData.get( format );

if ( fi == null )
{
fi = new FormatInfo( format );
formatData.put( format, fi );
}

return fi.pack( unpackedData );
}

@Override
public void pipe(
Expand All @@ -46,7 +60,7 @@ public void pipe(
{
if ( eMap[e] != format.getElementCount() )
{
consumer.put( e, rawVertData[v][eMap[e]] );
consumer.put( e, getRawPart( v, eMap[e] ) );
}
else
{
Expand All @@ -56,34 +70,37 @@ public void pipe(
}
}

private float[] getRawPart(
int v,
int i )
{
return formatData.get( this.format ).unpack( vertexData, v, i );
}

@Override
public int[] getVertexData() // anyone asking this will expect ITEM.
public int[] getVertexData()
{
final int[] tmpData = new int[format.getNextOffset() /* / 4 * 4 */];

for ( int v = 0; v < 4; v++ )
{
for ( int e = 0; e < format.getElementCount(); e++ )
{
LightUtil.pack( rawVertData[v][e], tmpData, format, v, e );
LightUtil.pack( getRawPart( v, e ), tmpData, format, v, e );
}
}

return tmpData;
}

static int[] OPTIFINE_WORKAROUND = new int[1];

public ChiselsAndBitsBakedQuad(
final float[][][] unpackedData,
final int tint,
final EnumFacing orientation,
final TextureAtlasSprite sprite,
VertexFormat format,
boolean enableModelCompression )
VertexFormat format )
{
super( OPTIFINE_WORKAROUND, tint, orientation, sprite, true, format );
rawVertData = enableModelCompression ? inMemoryCompressor.compress( unpackedData ) : unpackedData;
super( packData( format, unpackedData ), tint, orientation, sprite, true, format );
}

public static class Colored extends ChiselsAndBitsBakedQuad
Expand All @@ -93,10 +110,9 @@ public Colored(
final int tint,
final EnumFacing orientation,
final TextureAtlasSprite sprite,
VertexFormat format,
boolean enableModelCompression )
VertexFormat format )
{
super( unpackedData, tint, orientation, sprite, format, enableModelCompression );
super( unpackedData, tint, orientation, sprite, format );
}
}

Expand All @@ -111,14 +127,11 @@ public static class Builder implements IVertexConsumer, IFaceBuilder
private int elements = 0;

private final VertexFormat format;
private final boolean enableModelCompression;

public Builder(
VertexFormat format,
boolean enableModelCompression )
VertexFormat format )
{
this.format = format;
this.enableModelCompression = enableModelCompression;
}

@Override
Expand Down Expand Up @@ -189,10 +202,10 @@ public BakedQuad create(
{
if ( isColored )
{
return new Colored( unpackedData, tint, orientation, sprite, getFormat(), enableModelCompression );
return new Colored( unpackedData, tint, orientation, sprite, getFormat() );
}

return new ChiselsAndBitsBakedQuad( unpackedData, tint, orientation, sprite, getFormat(), enableModelCompression );
return new ChiselsAndBitsBakedQuad( unpackedData, tint, orientation, sprite, getFormat() );
}

@Override
Expand Down

0 comments on commit d25ad19

Please sign in to comment.