forked from MightyPirates/OpenComputers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize color write and increase bitblt limits
the color write improvements appears to give clients a 90% speed up on loading color nbt
- Loading branch information
Showing
5 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package li.cil.oc.util | ||
|
||
import net.minecraft.nbt.NBTTagCompound | ||
|
||
object NbtDataStream { | ||
def getShortArray(nbt: NBTTagCompound, key: String, array2d: Array[Array[Short]], w: Int, h: Int) : Boolean = { | ||
if (!nbt.hasKey(key)) { | ||
return false | ||
} | ||
|
||
val rawByteReader = new java.io.ByteArrayInputStream(nbt.getByteArray(key)) | ||
val memReader = new java.io.DataInputStream(rawByteReader) | ||
for (y <- 0 until h) { | ||
for (x <- 0 until w) { | ||
if (2 > memReader.available()) { | ||
return true // not great, but get out now | ||
} | ||
array2d(y)(x) = memReader.readShort() | ||
} | ||
} | ||
true | ||
} | ||
|
||
def getIntArrayLegacy(nbt: NBTTagCompound, key: String, array2d: Array[Array[Short]], w: Int, h: Int) : Boolean = { | ||
if (!nbt.hasKey(key)) { | ||
return false | ||
} | ||
// legacy format | ||
val c = nbt.getIntArray(key) | ||
for (y <- 0 until h) { | ||
val rowColor = array2d(y) | ||
for (x <- 0 until w) { | ||
val index = x + y * w | ||
if (index >= c.length) { | ||
return true // not great, but, the read at least started | ||
} | ||
rowColor(x) = c(index).toShort | ||
} | ||
} | ||
true | ||
} | ||
|
||
def setShortArray(nbt: NBTTagCompound, key: String, array: Array[Short]): Unit = { | ||
val rawByteWriter = new java.io.ByteArrayOutputStream() | ||
val memWriter = new java.io.DataOutputStream(rawByteWriter) | ||
array.foreach(memWriter.writeShort(_)) | ||
nbt.setByteArray(key, rawByteWriter.toByteArray) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters