From 4a590c5fa20c9cacf72b5494cb3fe19e7ae20ce7 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 17 Jan 2015 12:58:45 +0800 Subject: [PATCH] IDebugInfo now works with multiparts --- .../scala/edx/core/ResonantPartFactory.scala | 1 + .../part/connector/TPartNodeProvider.scala | 11 +- .../edx/core/prefab/pass/TDebugInfo.java | 30 ++ .../edx/electrical/battery/TileBattery.scala | 4 +- .../multimeter/MultimeterGrid.scala | 282 +++++++++--------- .../mechanical/mech/grid/NodeMechanical.scala | 22 +- 6 files changed, 192 insertions(+), 158 deletions(-) create mode 100644 src/main/scala/edx/core/prefab/pass/TDebugInfo.java diff --git a/src/main/scala/edx/core/ResonantPartFactory.scala b/src/main/scala/edx/core/ResonantPartFactory.scala index a47638ade..c443ee057 100644 --- a/src/main/scala/edx/core/ResonantPartFactory.scala +++ b/src/main/scala/edx/core/ResonantPartFactory.scala @@ -25,6 +25,7 @@ object ResonantPartFactory extends IPartFactory MultiPartRegistry.registerParts(this, partMap.keys.toArray) MultipartGenerator.registerTrait("resonant.api.tile.INodeProvider", "edx.core.prefab.pass.TNodeProvider") + MultipartGenerator.registerTrait("resonant.lib.debug.IDebugInfo", "edx.core.prefab.pass.TDebugInfo") MultipartGenerator.registerPassThroughInterface("net.minecraftforge.fluids.IFluidHandler") } diff --git a/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala b/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala index a47c7816d..1298db221 100644 --- a/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala +++ b/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala @@ -1,6 +1,7 @@ package edx.core.prefab.part.connector import java.util +import java.util.{List => JList} import codechicken.multipart.TMultiPart import net.minecraft.nbt.NBTTagCompound @@ -8,7 +9,7 @@ import net.minecraftforge.common.util.ForgeDirection import resonant.api.ISave import resonant.api.tile.INodeProvider import resonant.api.tile.node.INode -import resonant.lib.debug.DebugInfo +import resonant.lib.debug.IDebugInfo import resonant.lib.grid.core.Node import scala.collection.convert.wrapAll._ @@ -17,7 +18,7 @@ import scala.collection.convert.wrapAll._ * A node trait that can be mixed into any multipart nodes. Mixing this trait will cause nodes to reconstruct/deconstruct when needed. * @author Calclavia */ -trait TPartNodeProvider extends PartAbstract with INodeProvider with DebugInfo +trait TPartNodeProvider extends PartAbstract with INodeProvider with IDebugInfo { protected val nodes = new util.HashSet[Node] @@ -70,13 +71,13 @@ trait TPartNodeProvider extends PartAbstract with INodeProvider with DebugInfo return nodes.filter(node => nodeType.isAssignableFrom(node.getClass)).headOption.getOrElse(null).asInstanceOf[N] } - override def getDebugInfo: List[String] = + override def getDebugInfo: JList[String] = { - val debugs = nodes.toList.filter(_.isInstanceOf[DebugInfo]) + val debugs = nodes.toList.filter(_.isInstanceOf[IDebugInfo]) if (debugs.size > 0) { - return debugs.map(_.asInstanceOf[DebugInfo].getDebugInfo).reduceLeft(_ ::: _) + return debugs.map(_.asInstanceOf[IDebugInfo].getDebugInfo.toList).reduceLeft(_ ::: _) } return List[String]() } diff --git a/src/main/scala/edx/core/prefab/pass/TDebugInfo.java b/src/main/scala/edx/core/prefab/pass/TDebugInfo.java new file mode 100644 index 000000000..2b8eec30d --- /dev/null +++ b/src/main/scala/edx/core/prefab/pass/TDebugInfo.java @@ -0,0 +1,30 @@ +package edx.core.prefab.pass; + +import codechicken.multipart.TMultiPart; +import codechicken.multipart.TileMultipart; +import resonant.lib.debug.IDebugInfo; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Calclavia + */ +public class TDebugInfo extends TileMultipart implements IDebugInfo +{ + @Override + public List getDebugInfo() + { + List list = new ArrayList(); + + for (TMultiPart node : jPartList()) + { + if (node instanceof IDebugInfo) + { + list.addAll(((IDebugInfo) node).getDebugInfo()); + } + } + + return list; + } +} diff --git a/src/main/scala/edx/electrical/battery/TileBattery.scala b/src/main/scala/edx/electrical/battery/TileBattery.scala index 330f5629c..45302d139 100644 --- a/src/main/scala/edx/electrical/battery/TileBattery.scala +++ b/src/main/scala/edx/electrical/battery/TileBattery.scala @@ -14,6 +14,7 @@ import net.minecraftforge.client.model.AdvancedModelLoader import net.minecraftforge.common.util.ForgeDirection import org.lwjgl.opengl.GL11._ import resonant.lib.content.prefab.{TElectric, TEnergyStorage, TIO} +import resonant.lib.grid.core.TSpatialNodeProvider import resonant.lib.grid.energy.EnergyStorage import resonant.lib.network.discriminator.PacketType import resonant.lib.network.handle.{TPacketReceiver, TPacketSender} @@ -41,13 +42,14 @@ object TileBattery def getEnergyForTier(tier: Int) = Math.round(Math.pow(500000000, (tier / (maxTier + 0.7f)) + 1) / 500000000) * 500000000 } -class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric with TPacketSender with TPacketReceiver with TEnergyStorage +class TileBattery extends SpatialTile(Material.iron) with TIO with TElectric with TSpatialNodeProvider with TPacketSender with TPacketReceiver with TEnergyStorage { var renderEnergyAmount = 0d var doCharge = false private var markClientUpdate = false private var markDistributionUpdate = false + nodes.add(dcNode) energy = new EnergyStorage textureName = "material_metal_side" ioMap = 0 diff --git a/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala b/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala index 8ef98a8df..7aee31f3d 100644 --- a/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala +++ b/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala @@ -14,165 +14,165 @@ import scala.collection.mutable.ArrayBuffer class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with IUpdate { final val displayInformation = new ArrayBuffer[String] - * + /** * The available graphs to be handled. */ final val graphs = new ArrayBuffer[Graph[_]] + final val energyGraph: GraphL = new GraphL("energy", maxData) + final val powerGraph: GraphL = new GraphL("power", maxData) + final val energyCapacityGraph: GraphL = new GraphL("capacity", 1) + final val voltageGraph: GraphL = new GraphL("voltage", maxData) + final val torqueGraph: GraphD = new GraphD("torque", maxData) + final val angularVelocityGraph: GraphD = new GraphD("speed", maxData) + final val fluidGraph: GraphI = new GraphI("fluid", maxData) + final val thermalGraph: GraphF = new GraphF("temperature", maxData) + final val pressureGraph: GraphI = new GraphI("pressure", maxData) + /** + * Maximum data points a graph can store. + */ + private val maxData: Int = 1 + /** + * The absolute center of the multimeter screens. + */ + var center: Vector3 = new Vector3 + /** + * The relative bound sizes. + */ + var upperBound: Vector3 = new Vector3 + var lowerBound: Vector3 = new Vector3 + /** + * The overall size of the multimeter + */ + var size: Vector3 = new Vector3 + /** + * If the screen is not a perfect rectangle, don't render. + */ + var isEnabled: Boolean = true + var primaryMultimeter: PartMultimeter = null + private var doUpdate: Boolean = false -/*nal val energyGraph: GraphL = new GraphL("energy", maxData) -final val powerGraph: GraphL = new GraphL("power", maxData) -final val energyCapacityGraph: GraphL = new GraphL("capacity", 1) -final val voltageGraph: GraphL = new GraphL("voltage", maxData) -final val torqueGraph: GraphD = new GraphD("torque", maxData) -final val angularVelocityGraph: GraphD = new GraphD("speed", maxData) -final val fluidGraph: GraphI = new GraphI("fluid", maxData) -final val thermalGraph: GraphF = new GraphF("temperature", maxData) -final val pressureGraph: GraphI = new GraphI("pressure", maxData) -fi /** - * Maximum data points a graph can store. - */ -private val maxData: Int = 1 /** - * The absolute center of the multimeter screens. - */ -var center: Vector3 = new Vector3 -/** - * The relative bound sizes. - */ -var upperBound: Vector3 = new Vector3 -var lowerBound: Vector3 = new Vector3 -/** - * The overall size of the multimeter - */ -var size: Vector3 = new Vector3 -/** - * If the screen is not a perfect rectangle, don't render. - */ -var isEnabled: Boolean = true -var primaryMultimeter: PartMultimeter = null -private var doUpdate: Boolean = false + graphs += energyGraph + graphs += powerGraph + graphs += energyCapacityGraph + graphs += voltageGraph + graphs += torqueGraph + graphs += angularVelocityGraph + graphs += fluidGraph + graphs += thermalGraph + graphs += pressureGraph -graphs += energyGraph -graphs += powerGraph -graphs += energyCapacityGraph -graphs += voltageGraph -graphs += torqueGraph -graphs += angularVelocityGraph -graphs += fluidGraph -graphs += thermalGraph -graphs += pressureGraph - -def getDisplay(graphID: Int): String = -{ - val graph = graphs(graphID) - var graphValue: String = "" - if (graph == energyGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyGraph.get).toString - if (graph == powerGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.WATT, powerGraph.get).toString - if (graph == energyCapacityGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyCapacityGraph.get).toString - if (graph == voltageGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.VOLTAGE, voltageGraph.get).toString - if (graph == torqueGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.NEWTON_METER, torqueGraph.get, true).toString - if (graph == angularVelocityGraph) graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get) + " rad/s" - if (graph == fluidGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.LITER, fluidGraph.get.toInt).toString - if (graph == thermalGraph) graphValue = UnitDisplay.roundDecimals(thermalGraph.get.toFloat) + " K" - if (graph == pressureGraph) graphValue = UnitDisplay.roundDecimals(pressureGraph.get.toInt) + " Pa" - return getLocalized(graph) + ": " + graphValue -} - -def getLocalized(graph: Graph[_]): String = -{ - return LanguageUtility.getLocal("tooltip.graph." + graph.name) -} - -def isPrimary(check: PartMultimeter): Boolean = -{ - return primaryMultimeter == check -} - -def update(delta: Double) -{ - graphs.foreach(_.doneQueue()) - doUpdate = false -} - -def markUpdate -{ - doUpdate = true -} - -def canUpdate: Boolean = -{ - return doUpdate && continueUpdate -} - -def continueUpdate: Boolean = -{ - return getNodes.size > 0 -} - -override def isValidNode(node: AnyRef): Boolean = -{ - return node.isInstanceOf[PartMultimeter] && node.asInstanceOf[PartMultimeter].world != null && node.asInstanceOf[PartMultimeter].tile != null -} - -override def reconstruct -{ - if (getNodes.size > 0) + def getDisplay(graphID: Int): String = { - primaryMultimeter = null - upperBound = null - lowerBound = null - super.reconstruct - center = upperBound.midPoint(lowerBound) - upperBound -= center - lowerBound -= center - size = new Vector3(Math.abs(upperBound.x) + Math.abs(lowerBound.x), Math.abs(upperBound.y) + Math.abs(lowerBound.y), Math.abs(upperBound.z) + Math.abs(lowerBound.z)) - val area: Double = (if (size.x != 0) size.x else 1) * (if (size.y != 0) size.y else 1) * (if (size.z != 0) size.z else 1) - isEnabled = area == getNodes.size - UpdateTicker.threaded.addUpdater(this) + val graph = graphs(graphID) + var graphValue: String = "" + if (graph == energyGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyGraph.get).toString + if (graph == powerGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.WATT, powerGraph.get).toString + if (graph == energyCapacityGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyCapacityGraph.get).toString + if (graph == voltageGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.VOLTAGE, voltageGraph.get).toString + if (graph == torqueGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.NEWTON_METER, torqueGraph.get, true).toString + if (graph == angularVelocityGraph) graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get) + " rad/s" + if (graph == fluidGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.LITER, fluidGraph.get.toInt).toString + if (graph == thermalGraph) graphValue = UnitDisplay.roundDecimals(thermalGraph.get.toFloat) + " K" + if (graph == pressureGraph) graphValue = UnitDisplay.roundDecimals(pressureGraph.get.toInt) + " Pa" + return getLocalized(graph) + ": " + graphValue + } - getNodes foreach (c => - { - c.updateDesc - c.updateGraph - }) + def getLocalized(graph: Graph[_]): String = + { + return LanguageUtility.getLocal("tooltip.graph." + graph.name) + } + def isPrimary(check: PartMultimeter): Boolean = + { + return primaryMultimeter == check + } + + def update(delta: Double) + { + graphs.foreach(_.doneQueue()) + doUpdate = false + } + + def markUpdate + { doUpdate = true } -} -def load(nbt: NBTTagCompound) -{ - val nbtList: NBTTagList = nbt.getTagList("graphs", 0) - - for (i <- 0 until nbtList.tagCount) + def canUpdate: Boolean = { - val nbtCompound: NBTTagCompound = nbtList.getCompoundTagAt(i) - graphs.get(i).load(nbtCompound) + return doUpdate && continueUpdate } -} -def save: NBTTagCompound = -{ - val nbt: NBTTagCompound = new NBTTagCompound - val data: NBTTagList = new NBTTagList - graphs.foreach(g => data.appendTag(g.save())) - nbt.setTag("graphs", data) - return nbt -} + def continueUpdate: Boolean = + { + return getNodes.size > 0 + } -protected override def reconstructNode(node: PartMultimeter) -{ - node.setNetwork(this) - if (primaryMultimeter == null) primaryMultimeter = node - if (upperBound == null) + override def isValidNode(node: AnyRef): Boolean = { - upperBound = node.getPosition.add(1) + return node.isInstanceOf[PartMultimeter] && node.asInstanceOf[PartMultimeter].world != null && node.asInstanceOf[PartMultimeter].tile != null } - if (lowerBound == null) + + override def reconstruct { - lowerBound = node.getPosition + if (getNodes.size > 0) + { + primaryMultimeter = null + upperBound = null + lowerBound = null + super.reconstruct + center = upperBound.midPoint(lowerBound) + upperBound -= center + lowerBound -= center + size = new Vector3(Math.abs(upperBound.x) + Math.abs(lowerBound.x), Math.abs(upperBound.y) + Math.abs(lowerBound.y), Math.abs(upperBound.z) + Math.abs(lowerBound.z)) + val area: Double = (if (size.x != 0) size.x else 1) * (if (size.y != 0) size.y else 1) * (if (size.z != 0) size.z else 1) + isEnabled = area == getNodes.size + UpdateTicker.threaded.addUpdater(this) + + getNodes foreach (c => + { + c.updateDesc + c.updateGraph + }) + + doUpdate = true + } + } + + def load(nbt: NBTTagCompound) + { + val nbtList: NBTTagList = nbt.getTagList("graphs", 0) + + for (i <- 0 until nbtList.tagCount) + { + val nbtCompound: NBTTagCompound = nbtList.getCompoundTagAt(i) + graphs.get(i).load(nbtCompound) + } + } + + def save: NBTTagCompound = + { + val nbt: NBTTagCompound = new NBTTagCompound + val data: NBTTagList = new NBTTagList + graphs.foreach(g => data.appendTag(g.save())) + nbt.setTag("graphs", data) + return nbt + } + + protected override def reconstructNode(node: PartMultimeter) + { + node.setNetwork(this) + if (primaryMultimeter == null) primaryMultimeter = node + if (upperBound == null) + { + upperBound = node.getPosition.add(1) + } + if (lowerBound == null) + { + lowerBound = node.getPosition + } + upperBound = upperBound.max(node.getPosition.add(1)) + lowerBound = lowerBound.min(node.getPosition) } - upperBound = upperBound.max(node.getPosition.add(1)) - lowerBound = lowerBound.min(node.getPosition) -} } \ No newline at end of file diff --git a/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala b/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala index 8d3c34a91..520968bce 100644 --- a/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala +++ b/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala @@ -3,7 +3,7 @@ package edx.mechanical.mech.grid import edx.core.interfaces.TNodeMechanical import edx.core.prefab.node.TMultipartNode import resonant.api.tile.INodeProvider -import resonant.lib.debug.DebugInfo +import resonant.lib.debug.IDebugInfo import resonant.lib.grid.core.{GridNode, NodeGrid, TTileConnector} import resonant.lib.transform.vector.IVectorWorld @@ -15,7 +15,7 @@ import scala.collection.convert.wrapAll._ * * @author Calclavia, Darkguardsman */ -class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](parent) with TTileConnector[NodeMechanical] with TMultipartNode[NodeMechanical] with TNodeMechanical with IVectorWorld with DebugInfo +class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](parent) with TTileConnector[NodeMechanical] with TMultipartNode[NodeMechanical] with TNodeMechanical with IVectorWorld with IDebugInfo { /** * Angle calculations @@ -51,15 +51,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par return prevAngle } - /** - * Gets the angular velocity of the mechanical device from a specific side - * - * @return Angular velocity in meters per second - */ - override def angularVelocity = _angularVelocity - - def angularVelocity_=(newVel: Double) = _angularVelocity = newVel - /** * Sets the mechanical node's angle based on its connections */ @@ -98,6 +89,15 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par override def toString = "NodeMechanical [" + connections.size() + " Torque: " + BigDecimal(torque).setScale(2, BigDecimal.RoundingMode.HALF_UP) + " Velocity: " + BigDecimal(angularVelocity).setScale(2, BigDecimal.RoundingMode.HALF_UP) + "]" + /** + * Gets the angular velocity of the mechanical device from a specific side + * + * @return Angular velocity in meters per second + */ + override def angularVelocity = _angularVelocity + + def angularVelocity_=(newVel: Double) = _angularVelocity = newVel + /** * Gets the torque of the mechanical device from a specific side *