MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / enterMainLoop

Method enterMainLoop

src/main/java/field/app/RunLoop.java:65–184  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63 return Thread.currentThread() == mainThread;
64 }
65
66 public void enterMainLoop() {
67 if (Thread.currentThread() != mainThread)
68 throw new IllegalArgumentException(" cannot enter main loop on non-main thread");
69
70 if (ThreadSync2.getEnabled())
71 ThreadSync2.setSync(new ThreadSync2());
72
73
74 mainThread = Thread.currentThread();
75
76 timeStart = System.nanoTime();
77 while (true) {
78 try {
79 tick++;
80
81 long a = System.nanoTime();
82 frameTime = a - timeStart;
83
84 boolean didWork = false;
85 if (lock.tryLock(1, TimeUnit.DAYS)) {
86 long b = System.nanoTime();
87
88 mainLoop.updateAll();
89
90 long c = System.nanoTime();
91 didWork = ThreadSync.get()
92 .serviceAndCull();
93
94 if (ThreadSync2.getEnabled()) {
95 didWork |= ThreadSync2.getSync()
96 .service();
97 }
98
99 long d = System.nanoTime();
100
101 getLock += b - a;
102 hasLock += d - b;
103 service += d - c;
104 mainloop += c - b;
105 } else {
106 locksMissed++;
107 }
108
109 if (shouldSleep.size() == 0 && !didWork) {
110
111 try {
112 synchronized (eventLock) {
113 eventLock.wait(5);
114 }
115 } catch (InterruptedException ie) {
116 ie.printStackTrace();
117 }
118
119 sleepsTaken++;
120 }
121
122 if (tick % interval == 0) {

Callers 2

goMethod · 0.80
mainMethod · 0.80

Calls 10

getMethod · 0.95
updateAllMethod · 0.80
serviceAndCullMethod · 0.80
serviceMethod · 0.80
waitMethod · 0.80
sizeMethod · 0.45
printlnMethod · 0.45
clearMethod · 0.45
forEachMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected