Convert bot color conversion to MrRotor values & speedup

This commit is contained in:
NGnius (Graham) 2020-06-08 11:48:10 -04:00
parent b8547c856d
commit 5c5e46e84b
2 changed files with 55 additions and 137 deletions

View file

@ -16,6 +16,8 @@ namespace Pixi.Common
private static Dictionary<BlockColor, float[]> colorMap = null; private static Dictionary<BlockColor, float[]> colorMap = null;
private static Dictionary<byte, BlockColor> botColorMap = null;
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BlockColor QuantizeToBlockColor(Color pixel) public static BlockColor QuantizeToBlockColor(Color pixel)
{ {
@ -47,6 +49,13 @@ namespace Pixi.Common
return c; return c;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BlockColor QuantizeToBlockColor(byte cubeColorEnum)
{
if (botColorMap == null) BuildBotColorMap();
return botColorMap[cubeColorEnum];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BlockColor QuantizeToBlockColor(float[] pixel) public static BlockColor QuantizeToBlockColor(float[] pixel)
{ {
@ -215,5 +224,46 @@ namespace Pixi.Common
colorMap[new BlockColor { Color = BlockColors.Red, Darkness = 8 }] = new float[3] { 0.320f, 0.121f, 0.133f }; colorMap[new BlockColor { Color = BlockColors.Red, Darkness = 8 }] = new float[3] { 0.320f, 0.121f, 0.133f };
colorMap[new BlockColor { Color = BlockColors.Red, Darkness = 9 }] = new float[3] { 0.687f, 0.571f, 0.661f }; colorMap[new BlockColor { Color = BlockColors.Red, Darkness = 9 }] = new float[3] { 0.687f, 0.571f, 0.661f };
} }
private static void BuildBotColorMap()
{
botColorMap = new Dictionary<byte, BlockColor>();
// standard colours
botColorMap[0] = new BlockColor { Color = BlockColors.White, Darkness = 0 };
botColorMap[1] = new BlockColor { Color = BlockColors.White, Darkness = 6 };
botColorMap[4] = new BlockColor { Color = BlockColors.White, Darkness = 8 };
botColorMap[5] = new BlockColor { Color = BlockColors.Red, Darkness = 5 };
botColorMap[2] = new BlockColor { Color = BlockColors.Orange, Darkness = 0 };
botColorMap[6] = new BlockColor { Color = BlockColors.Yellow, Darkness = 0 };
botColorMap[7] = new BlockColor { Color = BlockColors.Green, Darkness = 5 };
botColorMap[3] = new BlockColor { Color = BlockColors.Aqua, Darkness = 5 };
botColorMap[9] = new BlockColor { Color = BlockColors.Blue, Darkness = 5 };
botColorMap[10] = new BlockColor { Color = BlockColors.Purple, Darkness = 5 };
// premium colours
botColorMap[16] = new BlockColor { Color = BlockColors.Red, Darkness = 0 };
botColorMap[17] = new BlockColor { Color = BlockColors.Red, Darkness = 7 };
botColorMap[11] = new BlockColor { Color = BlockColors.Orange, Darkness = 6 };
botColorMap[18] = new BlockColor { Color = BlockColors.Purple, Darkness = 9 };
botColorMap[19] = new BlockColor { Color = BlockColors.Pink, Darkness = 9 };
botColorMap[20] = new BlockColor { Color = BlockColors.Orange, Darkness = 5 };
botColorMap[20] = new BlockColor { Color = BlockColors.Yellow, Darkness = 3 };
botColorMap[14] = new BlockColor { Color = BlockColors.Green, Darkness = 7 };
botColorMap[21] = new BlockColor { Color = BlockColors.Lime, Darkness = 8 };
botColorMap[22] = new BlockColor { Color = BlockColors.Green, Darkness = 6 };
botColorMap[13] = new BlockColor { Color = BlockColors.Lime, Darkness = 5 };
// blue gang
botColorMap[23] = new BlockColor { Color = BlockColors.Blue, Darkness = 8 };
botColorMap[24] = new BlockColor { Color = BlockColors.Aqua, Darkness = 8 };
botColorMap[25] = new BlockColor { Color = BlockColors.Blue, Darkness = 7 };
botColorMap[26] = new BlockColor { Color = BlockColors.White, Darkness = 5 };
botColorMap[27] = new BlockColor { Color = BlockColors.White, Darkness = 4 };
botColorMap[28] = new BlockColor { Color = BlockColors.Aqua, Darkness = 4 };
botColorMap[29] = new BlockColor { Color = BlockColors.Purple, Darkness = 8 };
// purples & pinks
botColorMap[30] = new BlockColor { Color = BlockColors.Pink, Darkness = 0 };
botColorMap[8] = new BlockColor { Color = BlockColors.Pink, Darkness = 5 };
botColorMap[31] = new BlockColor { Color = BlockColors.Pink, Darkness = 4 };
botColorMap[15] = new BlockColor { Color = BlockColors.Red, Darkness = 3 };
}
} }
} }

View file

@ -188,141 +188,9 @@ namespace Pixi.Robots
{ {
// I hope these colours are accurate, I just guessed // I hope these colours are accurate, I just guessed
// TODO colour accuracy (lol that won't ever happen) // TODO colour accuracy (lol that won't ever happen)
switch (colour) BlockColor c = ColorSpaceUtility.QuantizeToBlockColor(colour);
{ result.color = c.Color;
case 0: result.darkness = c.Darkness;
result.color = BlockColors.White;
result.darkness = 0;
break;
case 1:
result.color = BlockColors.White;
result.darkness = 5;
break;
case 2:
result.color = BlockColors.Orange;
result.darkness = 0;
break;
case 3:
result.color = BlockColors.Blue;
result.darkness = 2;
break;
case 4:
result.color = BlockColors.White;
result.darkness = 8;
break;
case 5:
result.color = BlockColors.Red;
result.darkness = 0;
break;
case 6:
result.color = BlockColors.Yellow;
result.darkness = 0;
break;
case 7:
result.color = BlockColors.Green;
result.darkness = 0;
break;
case 8:
result.color = BlockColors.Purple;
result.darkness = 0;
break;
case 9:
result.color = BlockColors.Blue;
result.darkness = 7;
break;
case 10:
result.color = BlockColors.Purple;
result.darkness = 5;
break;
case 11:
result.color = BlockColors.Orange;
result.darkness = 7;
break;
case 12:
result.color = BlockColors.Green;
result.darkness = 3;
break;
case 13:
result.color = BlockColors.Green;
result.darkness = 2;
break;
case 14:
result.color = BlockColors.Pink;
result.darkness = 3;
break;
case 15:
result.color = BlockColors.Pink;
result.darkness = 2;
break;
case 16:
result.color = BlockColors.Red;
result.darkness = 2;
break;
case 17:
result.color = BlockColors.Orange;
result.darkness = 8;
break;
case 18:
result.color = BlockColors.Red;
result.darkness = 7;
break;
case 19:
result.color = BlockColors.Pink;
result.darkness = 0;
break;
case 20:
result.color = BlockColors.Yellow;
result.darkness = 2;
break;
case 21:
result.color = BlockColors.Green;
result.darkness = 7;
break;
case 22:
result.color = BlockColors.Green;
result.darkness = 8;
break;
case 23:
result.color = BlockColors.Blue;
result.darkness = 8;
break;
case 24:
result.color = BlockColors.Aqua;
result.darkness = 7;
break;
case 25:
result.color = BlockColors.Blue;
result.darkness = 6;
break;
case 26:
result.color = BlockColors.Aqua;
result.darkness = 5;
break;
case 27:
result.color = BlockColors.Blue;
result.darkness = 4;
break;
case 28:
result.color = BlockColors.Aqua;
result.darkness = 3;
break;
case 29:
result.color = BlockColors.Blue;
result.darkness = 5;
break;
case 30:
result.color = BlockColors.Purple;
result.darkness = 3;
break;
case 31:
result.color = BlockColors.Purple;
result.darkness = 1;
break;
default:
result.color = BlockColors.Aqua;
result.darkness = 0;
break;
}
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]