Merge branch 'architecture-memory-fix' of https://github.com/Vexatos/OpenComputers into master-MC1.7.10

This commit is contained in:
Florian Nücke 2016-04-05 20:57:19 +02:00
commit a69c09e4be
4 changed files with 12 additions and 15 deletions

View File

@ -17,7 +17,8 @@ public interface Memory extends Item {
* This factor has to be interpreted by each individual architecture to fit * This factor has to be interpreted by each individual architecture to fit
* its own memory needs. The actual values returned here should roughly be * its own memory needs. The actual values returned here should roughly be
* equivalent to the item's tier. For example, the built-in memory modules * equivalent to the item's tier. For example, the built-in memory modules
* provide 1 for tier one, 2 for tier 1.5, 3 for tier 2, etc. * provide defaults of 192 for tier one, 256 for tier 1.5, 384 for tier 2, etc.
* Mind that those values may be changed in the config file.
* *
* @param stack the item to get the provided memory for. * @param stack the item to get the provided memory for.
* @return the amount of memory the specified component provides. * @return the amount of memory the specified component provides.

View File

@ -12,7 +12,9 @@ import net.minecraft.item.ItemStack
object DriverMemory extends Item with api.driver.item.Memory with api.driver.item.CallBudget { object DriverMemory extends Item with api.driver.item.Memory with api.driver.item.CallBudget {
override def amount(stack: ItemStack) = override def amount(stack: ItemStack) =
Delegator.subItem(stack) match { Delegator.subItem(stack) match {
case Some(memory: item.Memory) => memory.tier + 1 case Some(memory: item.Memory) =>
val sizes = Settings.get.ramSizes
Settings.get.ramSizes(memory.tier max 0 min (sizes.length - 1))
case _ => 0.0 case _ => 0.0
} }

View File

@ -157,13 +157,10 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
memory > 0 memory > 0
} }
private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match { private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0.0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match {
case Some(driver: Memory) => case Some(driver: Memory) => driver.amount(stack) * 1024
val sizes = Settings.get.ramSizes
val tier = math.round(driver.amount(stack)).toInt - 1
sizes(tier max 0 min (sizes.length - 1)) * 1024
case _ => 0 case _ => 0
})) })).toInt max 0 min 50000000
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
@ -432,4 +429,4 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A
// Limit memory again. // Limit memory again.
recomputeMemory(machine.host.internalComponents) recomputeMemory(machine.host.internalComponents)
} }
} }

View File

@ -102,13 +102,10 @@ class LuaJLuaArchitecture(val machine: api.machine.Machine) extends Architecture
memory > 0 memory > 0
} }
private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match { private def memoryInBytes(components: java.lang.Iterable[ItemStack]) = components.foldLeft(0.0)((acc, stack) => acc + (Option(api.Driver.driverFor(stack)) match {
case Some(driver: Memory) => case Some(driver: Memory) => driver.amount(stack) * 1024
val sizes = Settings.get.ramSizes
val tier = math.round(driver.amount(stack)).toInt - 1
sizes(tier max 0 min (sizes.length - 1)) * 1024
case _ => 0 case _ => 0
})) })).toInt max 0 min 50000000
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //