MCPcopy Create free account
hub / github.com/badvision/jace / captureState

Method captureState

src/main/java/jace/state/StateManager.java:299–346  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

297 int stateCount = 0;
298
299 public void captureState() {
300 // If the state graph is invalidated it means we have to abandon all
301 // previously captured states. This helps ensure that rewinding will
302 // not result in an unintended or invalid state.
303 if (!isValid) {
304 alphaState = null;
305 if (allStateVariables != null) {
306 allStateVariables.clear();
307 }
308 allStateVariables = null;
309 // This will probably result in a lot of invalidated objects
310 // so it's a good idea to suggest to the JVM to reclaim memory now.
311 System.gc();
312
313 if (Emulator.instance == null) {
314 return;
315 }
316
317 // Re-examine the object structure of the emulator in case it changed
318 buildStateMap();
319 System.out.println(allStateVariables.size() + " variables tracked per state");
320 System.out.println(objectLookup.entrySet().size() + " objects tracked in emulator model");
321 isValid = true;
322 stateCount = 0;
323 }
324 if (alphaState == null) {
325 System.gc();
326 alphaState = captureAlphaState();
327 alphaState.tail = alphaState;
328 } else {
329 if (Runtime.getRuntime().freeMemory() <= freeRequired) {
330 invalidate();
331 return;
332 }
333 while (stateCount >= maxStates) {
334 removeOldestState();
335 stateCount--;
336 }
337
338 State newState = captureDeltaState(alphaState.tail);
339// State newState = (stateCount % 2 == 0) ? captureDeltaState(alphaState.tail) : captureAlphaState();
340 alphaState.tail.addState(newState);
341 alphaState.tail = newState;
342 }
343 // Now capture the current screen
344 alphaState.tail.screenshot = getScreenshot();
345 stateCount++;
346 }
347
348 private Image getScreenshot() {
349 Image screen = computer.getVideo().getFrameBuffer();

Callers 1

notifyVBLActiveMethod · 0.95

Calls 7

buildStateMapMethod · 0.95
captureAlphaStateMethod · 0.95
invalidateMethod · 0.95
removeOldestStateMethod · 0.95
captureDeltaStateMethod · 0.95
getScreenshotMethod · 0.95
addStateMethod · 0.80

Tested by

no test coverage detected