Skip to content

Commit

Permalink
Fixed a few bugs but reverted a few of the queueing changes. Still mo…
Browse files Browse the repository at this point in the history
…re work to go.
  • Loading branch information
me4502 committed Oct 12, 2018
1 parent 8cfab73 commit 56aa68a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,13 @@ private ChangeSetExecutor(ChangeSet changeSet, Type type, UndoContext context) {

@Override
public Operation resume(RunContext run) throws WorldEditException {
long start = System.currentTimeMillis();
int count = 0;

while (iterator.hasNext()) {
Change change = iterator.next();
if (type == Type.UNDO) {
change.undo(context);
} else {
change.redo(context);
}

count ++;

if (count % 100 == 0 && System.currentTimeMillis() - start > 50) {
break;
}
}

return iterator.hasNext() ? this : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class FlushOperation implements Operation {

private Actor actor;
private EditSession editSession;
private boolean hasFlushed = false;

public FlushOperation(Actor actor, EditSession editSession) {
this.actor = actor;
Expand All @@ -39,9 +40,14 @@ public FlushOperation(Actor actor, EditSession editSession) {

@Override
public Operation resume(RunContext run) throws WorldEditException {
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
session.remember(editSession);
editSession.flushQueue(actor);
if (!hasFlushed) {
hasFlushed = true;

LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
session.remember(editSession);

return new DelegateOperation(this, editSession.commit());
}

WorldEdit.getInstance().flushBlockBag(actor, editSession);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static <T> Task<T> completeQueued(Operation op, @Nullable Actor actor, @N

actor.print("Added operation to queue.");
Operation operation = op;
if (editSession != null) {
if (editSession != null && !(op instanceof FlushOperation)) {
operation = new OperationQueue(op, new FlushOperation(actor, editSession));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,9 @@ public int getAffected() {
public Operation resume(RunContext run) throws WorldEditException {
Vector position;

long startTime = System.currentTimeMillis();

while ((position = queue.poll()) != null) {
if (function.apply(position)) {
affected++;

if (affected % 100 == 0 && System.currentTimeMillis() - startTime > 50) { // 20TPS 1 tick time.
return this;
}
}

for (Vector dir : directions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,10 @@ public int getAffected() {

@Override
public Operation resume(RunContext run) throws WorldEditException {
long start = System.currentTimeMillis();

while (run.shouldContinue() && iterator.hasNext()) {
if (function.apply(iterator.next())) {
++affected;
}
if (affected % 100 == 0 && System.currentTimeMillis() - start > 50) { // Time of a tick.
break;
}
}

return iterator.hasNext() ? this : null;
Expand Down

0 comments on commit 56aa68a

Please sign in to comment.