Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ public interface ResourceReload {
* @return a new resource reload.
*/
static ResourceReload start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, CompletableFuture<?> initialTask) {
return start(manager, reloaders, backgroundExecutor, mainThreadExecutor, initialTask, () -> {});
}

static ResourceReload start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, CompletableFuture<?> initialTask, Runnable finalTask) {
if (ResourceLoader.LOGGER.isDebugEnabled()) {
return ProfiledResourceReload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, initialTask);
return ProfiledResourceReload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, initialTask, finalTask);
} else {
return SimpleResourceReload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, initialTask);
return SimpleResourceReload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, initialTask, finalTask);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,12 @@ private ResourceReload startReload(Executor backgroundExecutor, Executor mainThr
}
});

ResourceReload reload = ResourceReload.start(this, reloaders, backgroundExecutor, mainThreadExecutor, initialTask);

reload.result().thenRun(() -> {
return ResourceReload.start(this, reloaders, backgroundExecutor, mainThreadExecutor, initialTask, () -> {
if (this.type == ResourceType.CLIENT_ASSETS) {
ClientResourceLoaderEvents.END_RESOURCE_RELOAD.invoker().accept(this, context);
} else if (this.type == ResourceType.SERVER_DATA) {
ServerResourceLoaderEvents.END_RESOURCE_RELOAD.invoker().accept(this, context);
}
});

return reload;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

public class ProfiledResourceReload extends SimpleResourceReload<ProfiledResourceReload.ProfileResult> {

public static ResourceReload start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, CompletableFuture<?> initialTask) {
public static ResourceReload start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, CompletableFuture<?> initialTask, Runnable finalTask) {
ProfiledResourceReload reload = new ProfiledResourceReload();
reload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, TASK_FACTORY, initialTask);
reload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, TASK_FACTORY, initialTask, finalTask);
return reload;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

public class SimpleResourceReload<R> implements ResourceReload {

public static ResourceReload start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, CompletableFuture<?> initialTask) {
public static ResourceReload start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, CompletableFuture<?> initialTask, Runnable finalTask) {
SimpleResourceReload<Void> reload = new SimpleResourceReload<>();
reload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, TaskFactory.SIMPLE, initialTask);
reload.start(manager, reloaders, backgroundExecutor, mainThreadExecutor, TaskFactory.SIMPLE, initialTask, finalTask);
return reload;
}

Expand All @@ -40,11 +40,14 @@ public static ResourceReload start(ResourceManager manager, List<ResourceReloade
private int reloaderCount;
private CompletableFuture<List<R>> result;

void start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, TaskFactory<R> taskFactory, CompletableFuture<?> initialTask) {
void start(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, TaskFactory<R> taskFactory, CompletableFuture<?> initialTask, Runnable finalTask) {
this.runningReloaders.addAll(reloaders);
this.reloaderCount = reloaders.size();

this.result = this.startTasks(manager, reloaders, backgroundExecutor, mainThreadExecutor, taskFactory, initialTask);
this.result = this.startTasks(manager, reloaders, backgroundExecutor, mainThreadExecutor, taskFactory, initialTask).thenApplyAsync(results -> {
finalTask.run();
return results;
}, mainThreadExecutor);
}

CompletableFuture<List<R>> startTasks(ResourceManager manager, List<ResourceReloader> reloaders, Executor backgroundExecutor, Executor mainThreadExecutor, TaskFactory<R> taskFactory, CompletableFuture<?> initialTask) {
Expand Down