fixed an issue that lead to invalid energy states (missing 'else'...), most notably in robots not turning on when too full; added safeguard to avoid excess energy after load to cause trouble in tryChangeBuffer

This commit is contained in:
Florian Nücke 2014-03-07 13:27:16 +01:00
parent 01110c0f0e
commit bd4df5b61d

View File

@ -64,6 +64,10 @@ trait Connector extends network.Connector with Node {
else {
this.synchronized(distributor match {
case Some(d) => d.synchronized {
if (localBuffer > localBufferSize) {
d.changeBuffer(localBuffer - localBufferSize)
localBuffer = localBufferSize
}
val newGlobalBuffer = globalBuffer + delta
newGlobalBuffer >= 0 && newGlobalBuffer <= globalBufferSize && d.changeBuffer(delta) == 0
}
@ -86,7 +90,7 @@ trait Connector extends network.Connector with Node {
if (network != null) {
if (localBufferSize <= 0 && size > 0) d.addConnector(this)
else if (localBufferSize > 0 && size == 0) d.removeConnector(this)
d.globalBufferSize = math.max(d.globalBufferSize - localBufferSize + size, 0)
else d.globalBufferSize = math.max(d.globalBufferSize - localBufferSize + size, 0)
}
localBufferSize = math.max(size, 0)
val surplus = math.max(localBuffer - localBufferSize, 0)