Started P2P rework (#2966)

* First iteration of P2P rework

Changed frequency to short instead of long.
Added a per grid RNG to request a new frequency, hopefully without many collisons.
Added a helper to convert between a frequency and 4 colours
This commit is contained in:
yueh
2017-07-28 22:06:19 +02:00
committed by GitHub
parent 52d28fabe3
commit bcc4a732ed
6 changed files with 190 additions and 29 deletions
@@ -0,0 +1,60 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.helpers;
import com.google.common.base.Preconditions;
import appeng.api.util.AEColor;
public class P2PHelper
{
public AEColor[] toColors( short frequency )
{
final AEColor[] colors = new AEColor[4];
for( int i = 0; i < 4; i++ )
{
int nibble = ( frequency >> 4 * ( 3 - i ) ) & 0xF;
colors[i] = AEColor.values()[nibble];
}
return colors;
}
public short fromColors( AEColor[] colors )
{
Preconditions.checkArgument( colors.length == 4 );
int t = 0;
for( int i = 0; i < 4; i++ )
{
int code = colors[3 - i].ordinal() << 4 * i;
t |= code;
}
return (short) ( t & 0xFFFF );
}
}