From 39a56c8e5548cdfee31b6a877d7523fe31b7c00a Mon Sep 17 00:00:00 2001 From: Lignum Date: Fri, 5 May 2017 18:22:40 +0200 Subject: [PATCH] Get rid of the PaletteColour class It just took up a bunch of space. We're storing an array of float[3] now. --- .../computercraft/shared/util/Palette.java | 60 ++++--------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/util/Palette.java b/src/main/java/dan200/computercraft/shared/util/Palette.java index 3d40d6af8..1371a1f84 100644 --- a/src/main/java/dan200/computercraft/shared/util/Palette.java +++ b/src/main/java/dan200/computercraft/shared/util/Palette.java @@ -4,42 +4,8 @@ import net.minecraft.nbt.NBTTagCompound; 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 class Palette { 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 class Palette { 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 class Palette { 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 class Palette 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" ); } } }