@Test public void testSpeed() throws MapLoadException, InterruptedException { MatchConstants.init(new NetworkTimer(true), 0); MainGrid grid = MapUtils.getBigMap().loadMainGrid(null).getMainGrid(); MainGridDataAccessor gridAccessor = new MainGridDataAccessor(grid); short width = gridAccessor.getWidth(); short height = gridAccessor.getHeight(); BitSet notBlockingSet = new BitSet(width * height); LandscapeGrid landscapeGrid = gridAccessor.getLandscapeGrid(); for (short y = 0; y < height; y++) { for (short x = 0; x < width; x++) { notBlockingSet.set(x + y * width, !landscapeGrid.getLandscapeTypeAt(x, y).isBlocking); } } Thread.sleep(500L); MilliStopWatch watch = new MilliStopWatch(); PartitionCalculatorAlgorithm partitioner = new PartitionCalculatorAlgorithm(0, 0, width, height, notBlockingSet, IBlockingProvider.DEFAULT_IMPLEMENTATION); partitioner.calculatePartitions(); System.out.println("\n\n\n\nnumber of partitions: " + partitioner.getNumberOfPartitions()); watch.stop("partitioning test needed:"); } }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings, EMapStartResources startResources) throws MapLoadException { try (ObjectInputStream ois = new ObjectInputStream(super.getMapDataStream())) { MatchConstants.deserialize(ois); PlayerState[] playerStates = (PlayerState[]) ois.readObject(); GameSerializer gameSerializer = new GameSerializer(); MainGrid mainGrid = gameSerializer.load(ois); mainGrid.initWithPlayerSettings(playerSettings); RescheduleTimer.loadFrom(ois); ois.close(); return new MainGridWithUiSettings(mainGrid, playerStates); } catch (IOException | ClassNotFoundException ex) { throw new MapLoadException(ex); } }
mainGrid = gridWithUiState.getMainGrid(); PlayerState playerState = gridWithUiState.getPlayerState(playerId);
@Test public void testCompareOldAndNew() throws MapLoadException { MatchConstants.init(new NetworkTimer(true), 0); MainGrid grid = MapUtils.getBigMap().loadMainGrid(null).getMainGrid(); MainGridDataAccessor gridAccessor = new MainGridDataAccessor(grid); short width = gridAccessor.getWidth(); short height = gridAccessor.getHeight(); BitSet notBlockingSet = new BitSet(width * height); LandscapeGrid landscapeGrid = gridAccessor.getLandscapeGrid(); for (short y = 0; y < height; y++) { for (short x = 0; x < width; x++) { notBlockingSet.set(x + y * width, !landscapeGrid.getLandscapeTypeAt(x, y).isBlocking); } } PartitionCalculatorAlgorithm partitioner = new PartitionCalculatorAlgorithm(0, 0, width, height, notBlockingSet, IBlockingProvider.DEFAULT_IMPLEMENTATION); partitioner.calculatePartitions(); // System.out.println("\n\n\n\nnumber of partitions: " + partitioner.getNumberOfPartitions()); for (short y = 0; y < height; y++) { for (short x = 0; x < width; x++) { assertEquals(gridAccessor.getLandscapeGrid().getBlockedPartitionAt(x, y), partitioner.getPartitionAt(x, y)); } } } }
@Test public void testIfSavegameOfSavegameEqualsSavegame() throws IOException, MapLoadException, ClassNotFoundException, InterruptedException { final byte playerId = 0; final int targetTimeMinutes = 30; MapLoader map = MapUtils.getMountainlake(); ReplayUtils.PlayMapResult directSavegameReplay = ReplayUtils.playMapToTargetTimes(map, playerId, targetTimeMinutes); assertDirectSavegameReplay(1, directSavegameReplay); MapLoader savegame = directSavegameReplay.getSavegames()[0]; Thread.sleep(2000L); // loading + saving might happend in less than a second => make sure the next savegame is saved with a different name System.out.println("Loading savegame..."); MatchConstants.init(new NetworkTimer(true), 0L); MainGridWithUiSettings loadedMap = savegame.loadMainGrid(PlayerSetting.createDefaultSettings(playerId, (byte) savegame.getMaxPlayers())); MainGrid mainGrid = loadedMap.getMainGrid(); PlayerState playerState = loadedMap.getPlayerState(playerId); mainGrid.initForPlayer(playerId, playerState.getFogOfWar()); MapLoader savegameOfSavegame; try { System.out.println("Creating savegame of savegame..."); savegameOfSavegame = MapUtils.saveMainGrid(mainGrid, playerId, playerState.getUiState()); assertNotNull(savegameOfSavegame); } finally { mainGrid.stopThreads(); JSettlersGame.clearState(); } // compare direct savegame with replayed savegame. MapUtils.compareMapFiles(savegame, savegameOfSavegame); }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings, EMapStartResources startResources) throws MapLoadException { MilliStopWatch watch = new MilliStopWatch(); loadMapContent(startResources, playerSettings); OriginalMapFileContent mapData = mapContent.mapData; mapData.calculateBlockedPartitions(); watch.stop("Loading original map data required"); byte numberOfPlayers = (byte) getMaxPlayers(); if (playerSettings == null || CommonConstants.ACTIVATE_ALL_PLAYERS) { playerSettings = new PlayerSetting[numberOfPlayers]; for (int i = 0; i < numberOfPlayers; i++) { playerSettings[i] = new PlayerSetting((byte) i); } } MainGrid mainGrid = new MainGrid(getMapId(), getMapName(), mapData, playerSettings); PlayerState[] playerStates = new PlayerState[numberOfPlayers]; for (byte playerId = 0; playerId < numberOfPlayers; playerId++) { playerStates[playerId] = new PlayerState(playerId, new UIState(mapData.getStartPoint(playerId))); } return new MainGridWithUiSettings(mainGrid, playerStates); }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings, EMapStartResources startResources) throws MapLoadException { MilliStopWatch watch = new MilliStopWatch(); IMapData mapData = getMapData(); watch.stop("Loading map data required"); byte numberOfPlayers = (byte) getMaxPlayers(); if (playerSettings == null || CommonConstants.ACTIVATE_ALL_PLAYERS) { playerSettings = new PlayerSetting[numberOfPlayers]; for (int i = 0; i < numberOfPlayers; i++) { playerSettings[i] = new PlayerSetting((byte) i); } } MainGrid mainGrid = new MainGrid(getMapId(), getMapName(), mapData, playerSettings); PlayerState[] playerStates = new PlayerState[numberOfPlayers]; for (byte playerId = 0; playerId < numberOfPlayers; playerId++) { playerStates[playerId] = new PlayerState(playerId, new UIState(mapData.getStartPoint(playerId))); } return new MainGridWithUiSettings(mainGrid, playerStates); }