Split transmit into two separate methods

This removes the interdimensional and range options from the packet
and ensures they are provides them from the transmit* methods instead.
This commit is contained in:
SquidDev
2017-05-18 23:50:14 +01:00
parent a328308f67
commit d76ce22db7
6 changed files with 81 additions and 60 deletions
@@ -38,11 +38,21 @@ public interface IPacketNetwork
/**
* Submit a packet for transmitting across the network. This will route the packet through the network, sending it
* to all reachable receivers.
* to all receivers within range (or any interdimensional ones).
*
* @param packet The packet to send.
* @see IPacketReceiver#receiveDifferentDimension(Packet)
* @see #transmitInterdimensional(Packet)
* @see IPacketReceiver#receiveSameDimension(Packet, double)
*/
void transmit( @Nonnull Packet packet );
void transmitSameDimension( @Nonnull Packet packet, double range );
/**
* Submit a packet for transmitting across the network. This will route the packet through the network, sending it
* to all receivers across all dimensions.
*
* @param packet The packet to send.
* @see #transmitSameDimension(Packet, double)
* @see IPacketReceiver#receiveDifferentDimension(Packet)
*/
void transmitInterdimensional( @Nonnull Packet packet );
}
@@ -41,7 +41,7 @@ public interface IPacketReceiver
* @return The maximum distance this device can send and receive messages.
* @see #isInterdimensional()
* @see #receiveSameDimension(Packet packet, double)
* @see Packet#getRange()
* @see IPacketNetwork#transmitInterdimensional(Packet)
*/
double getRange();
@@ -53,7 +53,7 @@ public interface IPacketReceiver
* @return Whether this receiver receives packets from other dimensions.
* @see #getRange()
* @see #receiveDifferentDimension(Packet)
* @see Packet#isInterdimensional()
* @see IPacketNetwork#transmitInterdimensional(Packet)
*/
boolean isInterdimensional();
@@ -64,7 +64,9 @@ public interface IPacketReceiver
* if so, queue the appropriate modem event.
* @param distance The distance this packet has travelled from the source.
* @see Packet
* @see IPacketNetwork#transmit(Packet)
* @see #getRange()
* @see IPacketNetwork#transmitSameDimension(Packet, double)
* @see IPacketNetwork#transmitInterdimensional(Packet)
*/
void receiveSameDimension( @Nonnull Packet packet, double distance );
@@ -74,7 +76,8 @@ public interface IPacketReceiver
* @param packet The packet to receive. Generally you should check that you are listening on the given channel and,
* if so, queue the appropriate modem event.
* @see Packet
* @see IPacketNetwork#transmit(Packet)
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see IPacketNetwork#transmitSameDimension(Packet, double)
* @see #isInterdimensional()
*/
void receiveDifferentDimension( @Nonnull Packet packet );
@@ -14,7 +14,8 @@ import javax.annotation.Nullable;
* Represents a packet which may be sent across a {@link IPacketNetwork}.
*
* @see IPacketSender
* @see IPacketNetwork#transmit(Packet)
* @see IPacketNetwork#transmitSameDimension(Packet, double)
* @see IPacketNetwork#transmitInterdimensional(Packet)
* @see IPacketReceiver#receiveDifferentDimension(Packet)
* @see IPacketReceiver#receiveSameDimension(Packet, double)
*/
@@ -24,8 +25,6 @@ public class Packet
private final int m_replyChannel;
private final Object m_payload;
private final double m_range;
private final boolean m_interdimensional;
private final IPacketSender m_sender;
/**
@@ -38,15 +37,13 @@ public class Packet
* event or returning from a peripheral call.
* @param sender The object which sent this packet.
*/
public Packet( int channel, int replyChannel, @Nullable Object payload, double range, boolean interdimensional, @Nonnull IPacketSender sender )
public Packet( int channel, int replyChannel, @Nullable Object payload, @Nonnull IPacketSender sender )
{
Preconditions.checkNotNull( sender, "sender cannot be null" );
m_channel = channel;
m_replyChannel = replyChannel;
m_payload = payload;
m_range = range;
m_interdimensional = interdimensional;
m_sender = sender;
}
@@ -83,32 +80,6 @@ public class Packet
return m_payload;
}
/**
* Get the minimum distance this packet will travel.
*
* Packets may still travel further if there is a more sensitive receiver available.
*
* @return The distance this packet will travel.
* @see IPacketReceiver#getRange()
*/
public double getRange()
{
return m_range;
}
/**
* Whether this packet will travel across dimensions.
*
* Packets may still be received if there is a more sensitive receiver available.
*
* @return If this packet will travel across dimensions.
* @see IPacketReceiver#isInterdimensional()
*/
public boolean isInterdimensional()
{
return m_interdimensional;
}
/**
* The object which sent this message.
*
@@ -130,8 +101,6 @@ public class Packet
if( m_channel != packet.m_channel ) return false;
if( m_replyChannel != packet.m_replyChannel ) return false;
if( Double.compare( packet.m_range, m_range ) != 0 ) return false;
if( m_interdimensional != packet.m_interdimensional ) return false;
if( m_payload != null ? !m_payload.equals( packet.m_payload ) : packet.m_payload != null ) return false;
return m_sender.equals( packet.m_sender );
}
@@ -143,9 +112,6 @@ public class Packet
result = m_channel;
result = 31 * result + m_replyChannel;
result = 31 * result + (m_payload != null ? m_payload.hashCode() : 0);
long temp = Double.doubleToLongBits( m_range );
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (m_interdimensional ? 1 : 0);
result = 31 * result + m_sender.hashCode();
return result;
}