@Override public void start() { super.start(); environment = new Continuous2D(1.0, config.getEnvironmentWidth(), config.getEnvironmentHeight()); drawProxy = new DrawProxy(environment.getWidth(), environment.getHeight()); environment.setObjectLocation(drawProxy, new Double2D()); physicsWorld = new World(new Vec2()); placementArea = new PlacementArea((float) environment.getWidth(), (float) environment.getHeight()); placementArea.setSeed(config.getSimulationSeed()); schedule.reset(); System.gc(); physicsWorld.setContactListener(contactListener); // Create ALL the objects createWalls(); createTargetArea(); robotFactory.placeInstances( placementArea.new ForType<>(), physicsWorld, config.getTargetAreaPlacement()); config.getResourceFactory().placeInstances(placementArea.new ForType<>(), physicsWorld); // Now actually add the objects that have been placed to the world and schedule for (PhysicalObject object : placementArea.getPlacedObjects()) { drawProxy.registerDrawable(object.getPortrayal()); schedule.scheduleRepeating(object); } schedule.scheduleRepeating( simState -> physicsWorld.step(TIME_STEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS)); }
// create target area private void createTargetArea() { int environmentWidth = config.getEnvironmentWidth(); int environmentHeight = config.getEnvironmentHeight(); final int width, height; final Vec2 position; if (config.getTargetAreaPlacement() == SimConfig.Direction.SOUTH) { width = environmentWidth; height = config.getTargetAreaThickness(); position = new Vec2(width / 2f, height / 2f); } else if (config.getTargetAreaPlacement() == SimConfig.Direction.NORTH) { width = environmentWidth; height = config.getTargetAreaThickness(); position = new Vec2(environmentWidth - width / 2f, environmentHeight - height / 2f); } else if (config.getTargetAreaPlacement() == SimConfig.Direction.EAST) { width = config.getTargetAreaThickness(); height = environmentHeight; position = new Vec2(environmentWidth - width / 2f, height / 2f); } else if (config.getTargetAreaPlacement() == SimConfig.Direction.WEST) { width = config.getTargetAreaThickness(); height = environmentHeight; position = new Vec2(width / 2f, height / 2f); } else { return; // Don't know where to place this target area } targetArea = new TargetAreaObject( physicsWorld, position, width, height, config.getResourceFactory().getTotalResourceValue(), config.getSimulationIterations()); // Add target area to placement area (trust that space returned since nothing else placed // yet). PlacementArea.Space space = placementArea.getRectangularSpace(width, height, position, 0f); placementArea.placeObject(space, targetArea); }