Skip to content

Commit

Permalink
Simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Jun 29, 2024
1 parent c35d854 commit 91f2d64
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private CaptureTile[] computeDirtyTiles(int captureId, byte[] capture) {
final byte[] tileData = createTile(capture, captureDimension.width, offset, tw, th);
final long cs = CaptureTile.computeChecksum(tileData, 0, tileData.length);
if (cs != previousCapture[tileId]) {
dirty[tileId] = new CaptureTile(captureId, tileId, cs, new Position(tx, ty), tw, th, tileData);
dirty[tileId] = new CaptureTile(captureId, cs, new Position(tx, ty), tw, th, tileData);
hasDirty = true;
}
++tileId;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/mpo/dayon/assisted/mouse/MouseEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ private void mainLoop() throws InterruptedException {

private static int syncOnTick(final long start, final int captureCount) throws InterruptedException {
int delayedCaptureCount = 0;

while (true) {
final long captureMaxEnd = start + (captureCount + delayedCaptureCount) * 50L;
final long capturePause = captureMaxEnd - System.currentTimeMillis();
if (capturePause < 0) {
++delayedCaptureCount;
} else if (capturePause > 0) {
Thread.sleep(capturePause);
break;
return delayedCaptureCount;
}
}
return delayedCaptureCount;
}

private boolean fireOnLocationUpdated(Point location) {
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/mpo/dayon/common/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,19 @@ static void main(String[] args) {
final File appHomeDir = Runner.getOrCreateAppHomeDir();
Map<String, String> programArgs = Runner.extractProgramArgs(args);
String language = Runner.overrideLocale(programArgs.get("lang"));
if (hasAssistant(args)) {
Runner.logAppInfo("dayon_assistant");
SwingUtilities.invokeLater(() -> {
Runner.logAppInfo(hasAssistant(args) ? "dayon_assistant" : "dayon_assisted");
try {
SwingUtilities.invokeLater(() -> AssistantRunner.launchAssistant(language));
if (hasAssistant(args)) {
AssistantRunner.launchAssistant(language);
} else {
AssistedRunner.launchAssisted(programArgs.get("ah"), programArgs.get("ap"));
}
} catch (Exception ex) {
FatalErrorHandler.bye("The assistant is dead!", ex);
FatalErrorHandler.bye(hasAssistant(args) ? "The assistant is dead!" : "The assisted is dead!", ex);
}
} else {
Runner.logAppInfo("dayon_assisted");
try {
SwingUtilities.invokeLater(() -> AssistedRunner.launchAssisted(programArgs.get("ah"), programArgs.get("ap")));
} catch (Exception ex) {
FatalErrorHandler.bye("The assisted is dead!", ex);
}
}
prepareKeystore(appHomeDir);
});
new Thread(() -> prepareKeystore(appHomeDir)).start();
}

static void logAppInfo(String appName) {
Expand Down
27 changes: 4 additions & 23 deletions src/main/java/mpo/dayon/common/capture/CaptureTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class CaptureTile {

private final int captureId;

private final int id;

private final long checksum;

private final Position position;
Expand All @@ -36,7 +34,6 @@ public class CaptureTile {

private CaptureTile() {
this.captureId = -1;
this.id = -1;
this.checksum = -1;
this.position = new Position(-1, -1);
this.width = -1;
Expand All @@ -46,9 +43,8 @@ private CaptureTile() {
this.fromCache = false;
}

public CaptureTile(int captureId, int id, long checksum, Position position, int width, int height, byte[] capture) {
public CaptureTile(int captureId, long checksum, Position position, int width, int height, byte[] capture) {
this.captureId = captureId;
this.id = id;
this.checksum = checksum;
this.position = position;
this.width = width;
Expand All @@ -61,9 +57,8 @@ public CaptureTile(int captureId, int id, long checksum, Position position, int
/**
* Assisted to assistant : result of network data decompression.
*/
public CaptureTile(int captureId, int id, XYWH xywh, MemByteBuffer capture) {
public CaptureTile(int captureId, XYWH xywh, MemByteBuffer capture) {
this.captureId = captureId;
this.id = id;
this.checksum = computeChecksum(capture.getInternal(), 0, capture.size()); // cache usage (!)
this.position = new Position(xywh.x, xywh.y);
this.width = xywh.w;
Expand All @@ -79,9 +74,8 @@ public CaptureTile(int captureId, int id, XYWH xywh, MemByteBuffer capture) {
/**
* Assisted to assistant : result of network data decompression (single level tile).
*/
public CaptureTile(int captureId, int id, XYWH xywh, byte singleLevel) {
public CaptureTile(int captureId, XYWH xywh, byte singleLevel) {
this.captureId = captureId;
this.id = id;
this.checksum = -1;
this.position = new Position(xywh.x, xywh.y);
this.width = xywh.w;
Expand All @@ -96,9 +90,8 @@ public CaptureTile(int captureId, int id, XYWH xywh, byte singleLevel) {
/**
* Assisted to assistant : result of network data decompression (from the cache).
*/
public CaptureTile(int captureId, int id, XYWH xywh, CaptureTile cached) {
public CaptureTile(int captureId, XYWH xywh, CaptureTile cached) {
this.captureId = captureId;
this.id = id;
this.checksum = -1;
this.position = new Position(xywh.x, xywh.y);
this.width = xywh.w;
Expand All @@ -120,14 +113,6 @@ public static long computeChecksum(byte[] data, int offset, int len) {
return checksum.getValue();
}

public int getCaptureId() {
return captureId;
}

public int getId() {
return id;
}

public long getChecksum() {
return checksum;
}
Expand All @@ -144,10 +129,6 @@ public int getWidth() {
return width;
}

public int getHeight() {
return height;
}

public MemByteBuffer getCapture() {
return capture;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mpo/dayon/common/log/LogAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import java.util.Date;

public abstract class LogAppender {
private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS");

protected String format(LogLevel level, String message) {
protected static String format(LogLevel level, String message) {
return String.format("[%20.20s] [%5.5s] (%s) %s", Thread.currentThread().getName(), level,
dateFormat.format(Date.from(Instant.now())), (message == null) ? "" : message);
DATE_FORMAT.format(Date.from(Instant.now())), (message == null) ? "" : message);
}

public void append(LogLevel level, String message) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mpo/dayon/common/log/LogLevel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package mpo.dayon.common.log;

public enum LogLevel {
DEBUG, INFO, WARN, ERROR, FATAL,
DEBUG, INFO, WARN, ERROR, FATAL
}
6 changes: 3 additions & 3 deletions src/main/java/mpo/dayon/common/squeeze/Compressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ public Capture decompress(TileCache cache, MemByteBuffer zipped) throws IOExcept
final int value = in.readShort();
if (value >= 0 && value < 256) // single-level
{
dirty[tidx] = new CaptureTile(cId, tidx, xywh[tidx], (byte) value);
dirty[tidx] = new CaptureTile(cId, xywh[tidx], (byte) value);
} else if (value == 256) // multi-level (cached)
{
dirty[tidx] = new CaptureTile(cId, tidx, xywh[tidx], cache.get(in.readInt()));
dirty[tidx] = new CaptureTile(cId, xywh[tidx], cache.get(in.readInt()));
} else // multi-level (not cached)
{
processUncached(cache, in, cId, xywh[tidx], dirty, tidx, value);
Expand All @@ -184,7 +184,7 @@ private void processUncached(TileCache cache, DataInputStream in, int cId, Captu
}
final MemByteBuffer out = new MemByteBuffer();
rle.runLengthDecode(out, new MemByteBuffer(tdata));
dirty[tidx] = new CaptureTile(cId, tidx, xywh, out);
dirty[tidx] = new CaptureTile(cId, xywh, out);
cache.add(dirty[tidx]);
}
}

0 comments on commit 91f2d64

Please sign in to comment.