Skip to content

Commit

Permalink
Reduce calls to get time
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Jul 16, 2024
1 parent 81859cb commit 9f77bc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ public void run() {

Set<Repair> completed = new HashSet<>();
Set<Repair> executed = new HashSet<>();
while (System.currentTimeMillis() - start < Config.RepairMaxTickTime) {
long time = System.currentTimeMillis();
while (time - start < Config.RepairMaxTickTime) {
Repair repair = repairs.poll();
if (repair == null)
break; // No repairs, jump out

if (repair.run()) {
if (repair.run(time)) {
// Repair placed at least a block, return to back of queue
executed.add(repair);
} // Else leave at top of queue

if (repair.isDone())
if (repair.isDone()) {
completed.add(repair);
}

time = System.currentTimeMillis();
}
repairs.addAll(executed);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public int remaining() {
return queue.size();
}

public boolean run() {
double elapsedTicks = (System.currentTimeMillis() - lastExecution) * 20.0 / 1000;
public boolean run(long time) {
double elapsedTicks = (time - lastExecution) * 20.0 / 1000;
int placedBlocks = 0;

while (elapsedTicks > Config.RepairTicksPerBlock && placedBlocks <= Config.RepairMaxBlocksPerTick) {
Expand All @@ -67,7 +67,7 @@ public boolean run() {
}

if (placedBlocks > 0) {
lastExecution = System.currentTimeMillis();
lastExecution = time;
return true;
}

Expand Down

0 comments on commit 9f77bc6

Please sign in to comment.