/** * Add a replayer to the replayers and create a Subscription for it. * * <p>Caller should hold the lock. * * @param obs * @return */ Subscription addReplayer(Observer<? super TResult> obs) { Subscription s = new Subscription() { final AtomicBoolean once = new AtomicBoolean(); @Override public void unsubscribe() { if (once.compareAndSet(false, true)) { remove(this); } } @Override public boolean isUnsubscribed() { return once.get(); } }; Replayer rp = new Replayer(obs, s); replayers.put(s, rp); rp.replayTill(values.start() + values.size()); return s; }
public void reset(MarioAIOptions marioAIOptions) { // System.out.println("\nLevelScene RESET!"); // this.gameViewer = setUpOptions[0] == 1; // System.out.println("this.mario.isMarioInvulnerable = " + // this.mario.isMarioInvulnerable); // this.levelDifficulty = marioAIOptions.getLevelDifficulty(); // System.out.println("this.levelDifficulty = " + this.levelDifficulty); // this.levelLength = marioAIOptions.getLevelLength(); // System.out.println("this.levelLength = " + this.levelLength); // this.levelSeed = marioAIOptions.getLevelRandSeed(); // System.out.println("levelSeed = " + levelSeed); // this.levelType = marioAIOptions.getLevelType(); // System.out.println("levelType = " + levelType); GlobalOptions.FPS = marioAIOptions.getFPS(); // System.out.println("GlobalOptions.FPS = " + GlobalOptions.FPS); GlobalOptions.isPowerRestoration = marioAIOptions.isPowerRestoration(); // System.out.println("GlobalOptions.isPowerRestoration = " + // GlobalOptions.isPowerRestoration); // GlobalOptions.isPauseWorld = marioAIOptions.isPauseWorld(); GlobalOptions.areFrozenCreatures = marioAIOptions.isFrozenCreatures(); // System.out.println("GlobalOptions = " + GlobalOptions.isPauseWorld); // GlobalOptions.isTimer = marioAIOptions.isTimer(); // System.out.println("GlobalOptions.isTimer = " + GlobalOptions.isTimer); // isToolsConfigurator = setUpOptions[11] == 1; this.setTimeLimit(marioAIOptions.getTimeLimit()); // System.out.println("this.getTimeLimit() = " + this.getTimeLimit()); // this.isViewAlwaysOnTop() ? 1 : 0, setUpOptions[13] GlobalOptions.isVisualization = marioAIOptions.isVisualization(); // System.out.println("visualization = " + visualization); killedCreaturesTotal = 0; killedCreaturesByFireBall = 0; killedCreaturesByStomp = 0; killedCreaturesByShell = 0; bricksBumped = 0; marioInitialPos = marioAIOptions.getMarioInitialPos(); greenMushroomMode = marioAIOptions.getGreenMushroomMode(); if (replayer != null) { try { // replayer.openNextReplayFile(); replayer.openFile("level.lvl"); level = (Level) replayer.readObject(); level.counters.resetUncountableCounters(); // replayer.closeFile(); // replayer.closeRecorder(); } catch (IOException e) { System.err.println("[Mario AI Exception] : level reading failed"); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } else level = LevelGenerator.createLevel(marioAIOptions); String fileName = marioAIOptions.getLevelFileName(); if (!fileName.equals("")) { try { Level.save(level, new ObjectOutputStream(new FileOutputStream(fileName))); } catch (IOException e) { System.err.println("[Mario AI Exception] : Cannot write to file " + fileName); e.printStackTrace(); } } this.levelSeed = level.randomSeed; this.levelLength = level.length; this.levelHeight = level.height; this.levelType = level.type; this.levelDifficulty = level.difficulty; Sprite.spriteContext = this; sprites.clear(); this.width = GlobalOptions.VISUAL_COMPONENT_WIDTH; this.height = GlobalOptions.VISUAL_COMPONENT_HEIGHT; Sprite.setCreaturesGravity(marioAIOptions.getCreaturesGravity()); Sprite.setCreaturesWind(marioAIOptions.getWind()); Sprite.setCreaturesIce(marioAIOptions.getIce()); Mario.resetStatic(marioAIOptions); bonusPoints = -1; mario = new Mario(this); // System.out.println("mario = " + mario); memo = ""; sprites.add(mario); startTime = 1; timeLeft = timeLimit * GlobalOptions.mariosecondMultiplier; tickCount = 0; }