Made register callable inside the mainloop

This commit is contained in:
josua 2019-08-28 11:00:06 +10:00
parent b23de9a3d4
commit 655d8d187b
1 changed files with 14 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import mainloop.time.MainloopTimer;
public class MainloopManager
{
protected ArrayList<MainloopTask> tasks;
protected ArrayList<MainloopTask> tasks_to_add = new ArrayList<MainloopTask>();
protected IMainloopEvent handler;
protected boolean running = false;
protected MainloopTimer timer;
@ -54,6 +55,18 @@ public class MainloopManager
public void update()
{
// Does the tasks to add array have content in it
if(tasks_to_add.size() > 0)
{
// Add all the tasks to add
for(MainloopTask task : tasks_to_add) {
tasks.add(task);
}
// Clear the tasks to add array
tasks_to_add.clear();
}
// Loop over the tasks
for(Iterator<MainloopTask> i=tasks.iterator();i.hasNext();)
{
@ -73,7 +86,7 @@ public class MainloopManager
}
public void register(IMainloopTask task) {
tasks.add(new MainloopTask(task));
tasks_to_add.add(new MainloopTask(task));
}
}