constructor(vehicleConstructor = Vehicle) { this.vehicleConstructor_ = vehicleConstructor; this.disposed_ = false; this.observers_ = new Set(); this.vehicles_ = new Map(); this.rcVehicles_ = new Set(); this.callbacks_ = new ScopedCallbacks(); this.callbacks_.addEventListener( 'vehiclespawn', VehicleManager.prototype.onVehicleSpawn.bind(this)); this.callbacks_.addEventListener( 'vehicledeath', VehicleManager.prototype.onVehicleDeath.bind(this)); this.callbacks_.addEventListener( 'vehiclestreamin', VehicleManager.prototype.onVehicleStreamIn.bind(this)); // TODO(Russell): Handle OnVehicleDamangeStatusUpdate // TODO(Russell): Handle OnVehicleMod // TODO(Russell): Handle OnVehiclePaintjob // TODO(Russell): Handle OnVehicleRespray // TODO(Russell): Handle OnVehicleSirenStateChange this.processTrailerUpdates(); }
constructor() { this.delegates_ = new Set(); this.callbacks_ = new ScopedCallbacks(); this.callbacks_.addEventListener( 'playertext', CommunicationManager.prototype.onPlayerText.bind(this)); }
// Releases all references and state held by the player manager. dispose() { this.callbacks_.dispose(); this.callbacks_ = null; this.observers_ = null; this.players_ = null; }
constructor() { this.commands_ = {}; // Attach the global event listeners which we need to reliably handle commands. this.callbacks_ = new ScopedCallbacks(); this.callbacks_.addEventListener( 'playercommandtext', CommandManager.prototype.onPlayerCommandText.bind(this)); }
constructor(race, player, skipSignup, manager) { this.participants_ = new RaceParticipants(); this.finishedCount_ = 0; this.race_ = race; this.state_ = RunningRace.STATE_SIGNUP; this.manager_ = manager; this.resetVehicleDamageCounter_ = 0; // Acquire a unique virtual world for this race to take place in. this.virtualWorld_ = VirtualWorld.acquire('RunningRace (' + race.id + ')'); // Scope all entities created by this race to the lifetime of the race. this.entities_ = new ScopedEntities(); // Create a promise that is to be resolved when the race has finished. this.finishedPromise_ = new Promise(resolve => this.resolveFinishedPromise_ = resolve); // Sign the first player up for the race. this.addPlayer(player); // Advance the state to loading if the sign-up state for the race should be skipped. Mind that // the race may already be in loading state if it has a maximum of one player. If the sign-up // state should not be skipped, advance the state after a certain number of seconds. if (skipSignup) this.advanceState(RunningRace.STATE_LOADING); else wait(RaceSettings.RACE_SIGNUP_WAIT_DURATION).then(() => this.advanceState(RunningRace.STATE_LOADING)); // Listen to the required callbacks. Use a scoped callbacks object because this object is // ephemeral, and the listeners won't be necessary after the race has finished. this.callbacks_ = new ScopedCallbacks(); this.callbacks_.addEventListener('playerdeath', this.__proto__.onPlayerDeathOrDisconnect.bind(this)); this.callbacks_.addEventListener('playerdisconnect', this.__proto__.onPlayerDeathOrDisconnect.bind(this)); this.callbacks_.addEventListener('playerstatechange', this.__proto__.onPlayerStateChange.bind(this)); }
finish() { for (let participant of this.participants_.racingParticipants()) { participant.advance(RaceParticipant.STATE_DROP_OUT); // Forcefully remove them from the race. this.removeParticipant(participant); } this.callbacks_.dispose(); this.entities_.dispose(); VirtualWorld.release(this.virtualWorld_); this.resolveFinishedPromise_(this.participants_.finishedParticipants()); }
// Releases all references and state held by the vehicle manager. dispose() { this.disposed_ = true; this.callbacks_.dispose(); this.callbacks_ = null; // Forcefully dispose all vehicles created through JavaScript on the server. this.vehicles_.forEach(vehicle => vehicle.dispose()); if (this.vehicles_.size > 0) throw new Error('There are vehicles left in the vehicle manager after disposing it.'); this.vehicles_ = null; this.observers_ = null; }
constructor(playerConstructor = Player) { this.playerConstructor_ = playerConstructor; this.players_ = new Map(); this.observers_ = new Set(); this.callbacks_ = new ScopedCallbacks(); this.callbacks_.addEventListener( 'playerconnect', PlayerManager.prototype.onPlayerConnect.bind(this)); this.callbacks_.addEventListener( 'playerkeystatechange', PlayerManager.prototype.onPlayerKeyStateChange.bind(this)); this.callbacks_.addEventListener( 'playerlevelchange', PlayerManager.prototype.onPlayerLevelChange.bind(this)); this.callbacks_.addEventListener( 'playerlogin', PlayerManager.prototype.onPlayerLogin.bind(this)); this.callbacks_.addEventListener( 'playerstatechange', PlayerManager.prototype.onPlayerStateChange.bind(this)); this.callbacks_.addEventListener( 'playerdisconnect', PlayerManager.prototype.onPlayerDisconnect.bind(this)); this.callbacks_.addEventListener( 'playerguestlogin', PlayerManager.prototype.onPlayerGuestLogin.bind(this)); }
].forEach(name => this.callbacks_.addEventListener(toEventName(name), this.__proto__[toMethodName(name)].bind(this)));
// Disposes of the callbacks created as part of this class. dispose() { this.callbacks_.dispose(); }