TRAFFICSIM_APP.game = TRAFFICSIM_APP.game || {};

TRAFFICSIM_APP.game.VehicleController = function (worldController) {
    var self = this;

    var worldController = worldController;
    var vehicles = [];

    this.getWorldController = function () {
        return this._worldController;
    };

    function initializeRandomCars(numberOfCars) {
        for (var i = 0; i < numberOfCars; i++) {
            var car = new TRAFFICSIM_APP.game.Vehicle(
                worldController,
                worldController.getGameplayScene().getApplication().getModelContainer().getModelByName("car").clone(),
                TRAFFICSIM_APP.game.VehicleType.CAR);
            var nodes = worldController.getRoadController().getNodes();

            if (nodes[i * 2]) {
                var node = nodes[i * 2];
                car.setNode(node);
                car.setPosition(node.position.copy());
                vehicles.push(car);
                worldController.getThreeJSScene().add(car.getModel());
            }
        }
    }

    this.initializeCars = function () {
        initializeRandomCars(20);
    };

    this.update = function (deltaTime) {
        vehicles.forEach(function (vehicle) {
            vehicle.update(deltaTime);
        });
    };

    this.getVehicles = function () {
        return vehicles;
    }
};
TRAFFICSIM_APP.game = TRAFFICSIM_APP.game || {};

TRAFFICSIM_APP.game.VehicleController = function (worldController) {
    var self = this;

    var worldController = worldController;
    var vehicles = [];

    this.getWorldController = function () {
        return this._worldController;
    };

    function initializeRandomCars(numberOfCars) {
        for (var i = 0; i < numberOfCars; i++) {
            var car = new TRAFFICSIM_APP.game.Vehicle(
                worldController,
                worldController.getGameplayScene().getApplication().getModelContainer().getModelByName("car").clone(),
                TRAFFICSIM_APP.game.VehicleType.CAR);
            var nodes = worldController.getRoadController().getNodes();

            if (nodes[i * 2]) {
                var node = nodes[i * 2];
                car.setNode(node);
                car.setPosition(node.position.copy());
                vehicles.push(car);
                worldController.getThreeJSScene().add(car.getModel());
            }
        }
    }

    this.initializeCars = function () {
        initializeRandomCars(5);
    };

    this.update = function (deltaTime) {
        vehicles.forEach(function (vehicle) {
            vehicle.update(deltaTime);
        });
    };

    this.getVehicles = function () {
        return vehicles;
    }
};
Reduce the amount of cars since collision detections does not work properly with this many cars for some reason.
Reduce the amount of cars since collision detections does not work properly with this many cars for some reason.
