Get rid of the PaletteColour class

It just took up a bunch of space. We're storing an array of float[3] now.
This commit is contained in:
Lignum 2017-05-05 18:22:40 +02:00
parent 6997471280
commit 39a56c8e55
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D
1 changed files with 13 additions and 47 deletions

View File

@ -4,42 +4,8 @@
public class Palette
{
private static class PaletteColour
{
private float m_r, m_g, m_b;
public PaletteColour(float r, float g, float b)
{
m_r = r;
m_g = g;
m_b = b;
}
@Override
public boolean equals(Object o)
{
if(this == o) return true;
if(o == null || getClass() != o.getClass()) return false;
PaletteColour that = (PaletteColour) o;
if(Float.compare( that.m_r, m_r ) != 0) return false;
if(Float.compare( that.m_g, m_g ) != 0) return false;
return Float.compare( that.m_b, m_b ) == 0;
}
@Override
public int hashCode()
{
int result = (m_r != +0.0f ? Float.floatToIntBits( m_r ) : 0);
result = 31 * result + (m_g != +0.0f ? Float.floatToIntBits( m_g ) : 0);
result = 31 * result + (m_b != +0.0f ? Float.floatToIntBits( m_b ) : 0);
return result;
}
}
private static final int PALETTE_SIZE = 16;
private final PaletteColour[] colours = new PaletteColour[ PALETTE_SIZE ];
private final float[][] colours = new float[PALETTE_SIZE][3];
public Palette()
{
@ -51,7 +17,9 @@ public void setColour(int i, float r, float g, float b)
{
if( i >= 0 && i < colours.length )
{
colours[ i ] = new PaletteColour( r, g, b );
colours[i][0] = r;
colours[i][1] = g;
colours[i][2] = b;
}
}
@ -64,17 +32,16 @@ public float[] getColour( int i )
{
if( i >= 0 && i < colours.length )
{
PaletteColour c = colours[ i ];
return new float[] { c.m_r, c.m_g, c.m_b };
return colours[i];
}
return null;
}
public void resetColour( int i )
{
if(i >= 0 && i < colours.length )
if( i >= 0 && i < colours.length )
{
setColour( i, Colour.values()[ i ] );
setColour( i, Colour.values()[i] );
}
}
@ -90,11 +57,10 @@ public NBTTagCompound writeToNBT( NBTTagCompound nbt )
{
for(int i = 0; i < colours.length; ++i)
{
PaletteColour c = colours[i];
String prefix = "term_palette_colour_" + i;
nbt.setFloat( prefix + "_r", c.m_r );
nbt.setFloat( prefix + "_g", c.m_g );
nbt.setFloat( prefix + "_b", c.m_b );
nbt.setFloat( prefix + "_r", colours[i][0] );
nbt.setFloat( prefix + "_g", colours[i][1] );
nbt.setFloat( prefix + "_b", colours[i][2] );
}
return nbt;
}
@ -104,9 +70,9 @@ public void readFromNBT( NBTTagCompound nbt )
for(int i = 0; i < colours.length; ++i)
{
String prefix = "term_palette_colour_" + i;
colours[i].m_r = nbt.getFloat( prefix + "_r" );
colours[i].m_g = nbt.getFloat( prefix + "_g" );
colours[i].m_b = nbt.getFloat( prefix + "_b" );
colours[i][0] = nbt.getFloat( prefix + "_r" );
colours[i][1] = nbt.getFloat( prefix + "_g" );
colours[i][2] = nbt.getFloat( prefix + "_b" );
}
}
}