Advertisement
Guest User

Untitled

a guest
Jul 20th, 2023
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. if (handlerIdleProgress == null){
  2. handlerIdleProgress = new Handler(); //starting the handler that manages idle progress
  3. final long[] cyclesLeft = {secondsElapsed}; //this is to make the value available to "run()". just see it as a long
  4. updaterIdleProgress = new Thread() {
  5. @Override
  6. public void run() {
  7. long start = System.currentTimeMillis(); //i take the start time
  8. List<Area> areas = Utils.compileDungeonList(); //i list the dungeons for "for" iteration
  9. while (System.currentTimeMillis() - start < 50 && cyclesLeft[0] > 0){ //if ran for < 50ms && cycles are left
  10. for (Area e : areas){
  11. e.tick(); //i do a thing for each area (practically, next turn)
  12. }
  13. cyclesLeft[0] -= 1; //subtract a cycle
  14. }
  15. //after running for 50 ms, if there are cycles left to compute, i run it again after 25ms.
  16. //this is to prevent ANR, as freezing the screen for 5+ seconds isn't ideal
  17. if (cyclesLeft[0] > 0) handlerIdleProgress.postDelayed(this, 25);
  18. else {
  19. //at the end of the cycle, i start the normal execution. it just does one cycle per second
  20. //while the app is open
  21. if(handlerUI == null) {
  22. handlerUI = new Handler();
  23. updaterUI = new Thread() {
  24. @Override
  25. public void run() {/* ... */}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement