@Override public void dispose() { renderer.dispose(); worldMap = null; paths = null; heuristic = null; pathFinder = null; pathSmoother = null; scheduler = null; MessageManager.getInstance().clear(); }
private void requestNewPathFinding( HierarchicalTiledNode startNode, HierarchicalTiledNode endNode, int pathIndex) { TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[pathIndex]; MyPathFinderRequest pfRequest = requestPool.obtain(); pfRequest.startNode = startNode; pfRequest.endNode = endNode; pfRequest.heuristic = heuristic; pfRequest.resultPath = path; pfRequest.pathIndex = pathIndex; pfRequest.responseMessageCode = PF_RESPONSE; MessageManager.getInstance().dispatchMessage(this, PF_REQUEST, pfRequest); }
@Override public void hit(final Entity entity) { // manager.addTimer(entity, timer); // manager.addUpdate(entity, update); CWorld i = CMap.world.get(entity); int msgType = i.world.addTimer(entity, timer); MessageManager.getInstance() .addListener( new Telegraph() { @Override public boolean handleMessage(Telegram msg) { CMap.world.get(entity).world.addHit(entity, hit); return true; } }, msgType); Events.Wood.addAmount(amount); entity.remove(CHit.class); }
public City() { Gdx.app.log(City.class.getSimpleName(), "A new city is born..."); houses = new Array<House>(); MessageManager.getInstance().addListeners(this, TelegramProviderTest.MSG_TIME_TO_ACT); }
@SuppressWarnings("unchecked") @Override public void create(Table table) { lastEndTileX = -1; lastEndTileY = -1; startTileX = 1; startTileY = 1; // Create the map worldMap = new HierarchicalTiledGraph(); int roomCount = 100; int roomMinSize = 2; int roomMaxSize = 8; int squashIterations = 100; worldMap.init(roomCount, roomMinSize, roomMaxSize, squashIterations); paths = (TiledSmoothableGraphPath<HierarchicalTiledNode>[]) new TiledSmoothableGraphPath[NUM_PATHS]; for (int i = 0; i < NUM_PATHS; i++) { paths[i] = new TiledSmoothableGraphPath<HierarchicalTiledNode>(); } numPaths = 0; heuristic = new TiledManhattanDistance<HierarchicalTiledNode>(); IndexedAStarPathFinder<HierarchicalTiledNode> levelPathFinder = new IndexedAStarPathFinder<HierarchicalTiledNode>(worldMap, true); pathFinder = new HierarchicalPathFinder<HierarchicalTiledNode>(worldMap, levelPathFinder); pathSmoother = new PathSmoother<HierarchicalTiledNode, Vector2>( new TiledRaycastCollisionDetector<HierarchicalTiledNode>(worldMap)); pathSmootherRequest = new PathSmootherRequest<HierarchicalTiledNode, Vector2>(); requestPool = new Pool<MyPathFinderRequest>() { @Override protected MyPathFinderRequest newObject() { return new MyPathFinderRequest(); } }; PathFinderQueue<HierarchicalTiledNode> pathFinderQueue = new PathFinderQueue<HierarchicalTiledNode>(pathFinder); MessageManager.getInstance().addListener(pathFinderQueue, PF_REQUEST); scheduler = new LoadBalancingScheduler(100); scheduler.add(pathFinderQueue, 1, 0); renderer = new ShapeRenderer(); inputProcessor = new TiledHierarchicalAStarInputProcessor(this); Table detailTable = new Table(container.skin); detailTable.row(); checkSmooth = new CheckBox("[RED]S[]mooth Path", container.skin); checkSmooth.setChecked(smooth); checkSmooth.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { CheckBox checkBox = (CheckBox) event.getListenerActor(); smooth = checkBox.isChecked(); updatePath(true); } }); detailTable.add(checkSmooth); detailTable.row(); checkDiagonal = new CheckBox("Prefer [RED]D[]iagonal", container.skin); checkDiagonal.setChecked(worldMap.diagonal); checkDiagonal.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { CheckBox checkBox = (CheckBox) event.getListenerActor(); worldMap.diagonal = checkBox.isChecked(); updatePath(true); } }); detailTable.add(checkDiagonal); detailTable.row(); addSeparator(detailTable); detailTable.row(); checkMetrics = new CheckBox("Calculate [RED]M[]etrics", container.skin); checkMetrics.setChecked(metrics); checkMetrics.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { CheckBox checkBox = (CheckBox) event.getListenerActor(); metrics = checkBox.isChecked(); updatePath(true); } }); detailTable.add(checkMetrics); detailTable.row(); addSeparator(detailTable); detailTable.row(); sliderMillisAvailablePerFrame = new Slider(0.1f, 40f, 0.1f, false, container.skin); sliderMillisAvailablePerFrame.setValue(16); final Label labelMillisAvailablePerFrame = new Label( "Millis Available per Frame [[" + sliderMillisAvailablePerFrame.getValue() + "]", container.skin); detailTable.add(labelMillisAvailablePerFrame); detailTable.row(); sliderMillisAvailablePerFrame.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { labelMillisAvailablePerFrame.setText( "Millis Available per Frame [[" + sliderMillisAvailablePerFrame.getValue() + "]"); } }); Table sliderMapfTable = new Table(); sliderMapfTable.add(new Label("[RED]-[] ", container.skin)); sliderMapfTable.add(sliderMillisAvailablePerFrame); sliderMapfTable.add(new Label(" [RED]+[]", container.skin)); detailTable.add(sliderMapfTable); detailWindow = createDetailWindow(detailTable); }