From 9190d7c12d1bbdcfc401543128fb0219e6fc0a81 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 31 May 2021 17:14:46 -0400 Subject: alpha.predev.2 --- .../java/net/cshift/transit/network/Channel.java | 7 +++-- .../java/net/cshift/transit/network/INode.java | 10 +++--- .../net/cshift/transit/network/PoolManifest.java | 36 ++++++++++++++++++++++ .../net/cshift/transit/type/group/TypeGroup.java | 11 ++----- src/main/resources/fabric.mod.json | 2 +- 5 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 src/main/java/net/cshift/transit/network/PoolManifest.java (limited to 'src') diff --git a/src/main/java/net/cshift/transit/network/Channel.java b/src/main/java/net/cshift/transit/network/Channel.java index 43dbabc..c7be552 100644 --- a/src/main/java/net/cshift/transit/network/Channel.java +++ b/src/main/java/net/cshift/transit/network/Channel.java @@ -7,7 +7,7 @@ import net.cshift.transit.network.packet.IStaticPacket; * @apiNote A channel represents a connection between two nodes. It is able to send data in packets, and serves as a way to organize incoming traffic. * @param The type of data the packets will be transfering */ -public class Channel { +public final class Channel { private INode to; private int id; private String group; @@ -16,7 +16,7 @@ public class Channel { * Negative IDs indicate a terminated connection, so do not initialize the class with a negative ID. * * @param node The recieving node - * @param id The channel's id, as assigned by the recieving node. + * @param id The channel's id, as assigned by the recieving node. In most cases, this will match the pool ID as a way to match channels to pools. * @param group */ public Channel(INode node, int id, String group) @@ -75,6 +75,7 @@ public class Channel { /** Pressure * + * @apiNote This part of the api is not properly documented yet, and it's use is not reccommended for cross-mod communications. * @return A Number representing the pressure from the channel (in base group units). */ public Number pressure() @@ -84,7 +85,7 @@ public class Channel { /** Max transfer rate * - * @return A Number representing the max transfer rate from the channel (in base group units). + * @return A Number representing the max transfer rate from the channel (in base group units per tick). */ public Number rate() { diff --git a/src/main/java/net/cshift/transit/network/INode.java b/src/main/java/net/cshift/transit/network/INode.java index 0396347..8f74dd6 100644 --- a/src/main/java/net/cshift/transit/network/INode.java +++ b/src/main/java/net/cshift/transit/network/INode.java @@ -8,12 +8,10 @@ import net.cshift.transit.network.packet.*; */ public interface INode { - /** Returns true if the group given is used by the node + /** Returns a channel manifest for the INode * - * @param group the group to query - * @return {@code true} if the node supports the group */ - public boolean hasGroup(String group); + public PoolManifest getManifest(); /** Get the system managing the node or {@code null} if there isn't one * @@ -34,7 +32,7 @@ public interface INode * @param asker The asking node * @return A channel if the node accepts the request, {@code null} otherwise */ - public Channel connect(String group, INode asker); + public Channel connect(int poolID, INode asker); /** Accept a packet from a channel (or not). * @@ -58,7 +56,7 @@ public interface INode * * @apiNote Do not call this function, use Channel.rate() instead. * @param channel The channel asking for the transfer rate - * @return A Number representing the transfer rate from the channel (in base group units). + * @return A Number representing the transfer rate from the channel (in base group units per tick). */ public Number getRate(Channel channel); diff --git a/src/main/java/net/cshift/transit/network/PoolManifest.java b/src/main/java/net/cshift/transit/network/PoolManifest.java new file mode 100644 index 0000000..d6bec43 --- /dev/null +++ b/src/main/java/net/cshift/transit/network/PoolManifest.java @@ -0,0 +1,36 @@ +package net.cshift.transit.network; + +/** + * @author Kyle Gunger + * @apiNote A channel manifest represents a set of possible data/resource pools that another node can request a channel to. + */ +public interface PoolManifest { + + /** Represents the number of pools that the node has access to for the specified resource. + * @apiNote A "pool" in this context represents an independant network of resources. + * Pool zero should be the default group that simple nodes will attempt to connect to. + * @param group The TypeGroup that the pool belongs to + */ + public int poolCount(String group); + + /** The ID of the pool. The INode will use this in a connection attempt with the other INode. + * + * @param group The TypeGroup the pool belongs to + * @param pool Array-like index for pool (gotten from poolCount) + */ + public int poolID(String group, int pool); + + /** If the mod supports named pools, the names can be querried through this function. + * + * @param group The TypeGroup the pool belongs to + * @param pool Array-like index for pool (gotten from poolCount) + */ + public String poolName(String group, int pool); + + /** If the mod supports pool descriptions, they can be accessed by this method. + * + * @param group The TypeGroup the pool belongs to + * @param pool Array-like index for pool (gotten from poolCount) + */ + public String poolDescription(String group, int pool); +} diff --git a/src/main/java/net/cshift/transit/type/group/TypeGroup.java b/src/main/java/net/cshift/transit/type/group/TypeGroup.java index 596a511..d120cba 100644 --- a/src/main/java/net/cshift/transit/type/group/TypeGroup.java +++ b/src/main/java/net/cshift/transit/type/group/TypeGroup.java @@ -204,12 +204,7 @@ public class TypeGroup @Deprecated public IStaticPacket convertPacket(IStaticPacket packet, Type type) { - if(isInGroup(packet.getType()) && isInGroup(type)) - { - return convertPacketRaw(packet, type); - } - - return null; + return type.convertFrom(packet, this.getGroup()); } /**Convert a packet to a new type Returns null if the type isn't found. @@ -225,7 +220,7 @@ public class TypeGroup Type toType = getType(groupID, typeID); if(toType != null) { - return convertPacketRaw(packet, toType); + return toType.convertFrom(packet, this.getGroup()); } return null; @@ -243,7 +238,7 @@ public class TypeGroup Type toType = getType(typeID); if(toType != null) { - return convertPacketRaw(packet, toType); + return toType.convertFrom(packet, this.getGroup()); } return null; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1ef3567..913c80c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "transit-api", - "version": "2.0.0-alpha.predev", + "version": "2.0.0-alpha.predev.2", "name": "Transit API", "description": "Move things about!", -- cgit v1.2.3