Skip to content

Commit

Permalink
Optimize tile creation
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Dec 18, 2024
1 parent 2490bd6 commit eb6b0eb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ private static int syncOnTick(final long start, final int captureCount, final in
while (true) {
final long captureMaxEnd = start + (captureCount + delayedCaptureCount) * tick;
final long capturePause = captureMaxEnd - System.currentTimeMillis();
if (capturePause < 0) {
if (capturePause < 0L) {
++delayedCaptureCount;
Log.warn(format("Skipping capture (%d) %s", captureId + delayedCaptureCount, UnitUtilities.toElapsedTime(-capturePause)));
} else if (capturePause > 0) {
Log.warn(format("Skipping capture (%s) %s", captureId + delayedCaptureCount, UnitUtilities.toElapsedTime(-capturePause)));
} else if (capturePause > 0L) {
try {
TimeUnit.MILLISECONDS.sleep(capturePause);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -210,7 +210,7 @@ private CaptureTile[] computeDirtyTiles(byte[] capture) {
for (int ty = 0; ty < captureDimension.height; ty += TILE_DIMENSION.height) {
final int th = min(captureDimension.height - ty, TILE_DIMENSION.height);
for (int tx = 0; tx < captureDimension.width; tx += TILE_DIMENSION.width) {
final int tw = Math.min(captureDimension.width - tx, TILE_DIMENSION.width);
final int tw = min(captureDimension.width - tx, TILE_DIMENSION.width);
tileData = createTile(capture, captureDimension.width, tw, th, tx, ty, pixelSize);
final long cs = CaptureTile.computeChecksum(tileData, 0, tileData.length);
if (cs != previousCapture[tileId]) {
Expand All @@ -230,13 +230,14 @@ private static byte[] createTile(byte[] capture, int width, int tw, int th, int
final int capacity = tw * th * pixelSize;
final byte[] tile = new byte[capacity];
final int maxSrcPos = capture.length;
final int maxDestPos = capacity - tw * pixelSize + 1;
int srcPos = ty * width * pixelSize + tx * pixelSize;
int destPos = 0;
while (destPos < maxDestPos && srcPos < maxSrcPos) {
System.arraycopy(capture, srcPos, tile, destPos, tw * pixelSize);
srcPos += width * pixelSize;
destPos += tw * pixelSize;
final int screenRowIncrement = width * pixelSize;
final int tileRowIncrement = tw * pixelSize;
while (destPos < capacity && srcPos < maxSrcPos) {
System.arraycopy(capture, srcPos, tile, destPos, tileRowIncrement);
srcPos += screenRowIncrement;
destPos += tileRowIncrement;
}
return tile;
}
Expand Down

0 comments on commit eb6b0eb

Please sign in to comment.