Evtl. fix unerklärliche async client fehler

This commit is contained in:
hydrant
2021-04-21 19:37:01 +02:00
parent d413c5c8cb
commit 4c35539b23
5 changed files with 20 additions and 11 deletions

View File

@@ -147,7 +147,7 @@ class RageEntityAttachmentPool implements IEntityAttachmentPool {
let e = new RageAttachments(entity, attachments, attachmentObjects); let e = new RageAttachments(entity, attachments, attachmentObjects);
this.attachmentPool.push(e); this.attachmentPool.push(e);
return e; return e;
} }
at(remoteId: any): IEntityAttachments { at(remoteId: any): IEntityAttachments {
@@ -188,6 +188,10 @@ class RagePlayerPool implements IPlayerPool {
fn(new RagePlayer(e)); fn(new RagePlayer(e));
}); });
} }
exists(entity: IPlayer): boolean {
return mp.players.exists(entity.id);
}
} }
@@ -280,6 +284,10 @@ class RageVehiclePool implements IVehiclePool {
fn(new RageVehicle(e)); fn(new RageVehicle(e));
}) })
} }
exists(entity: IVehicle): boolean {
return mp.vehicles.exists(entity.id);
}
} }
export { export {
@@ -290,5 +298,5 @@ export {
RageEntityAttachmentPool, RageEntityAttachmentPool,
RageVehicle, RageVehicle,
RageVehiclePool, RageVehiclePool,
} }

View File

@@ -10,8 +10,8 @@ export default class RageGame implements IGame {
events: IEvents = new RageEvents; events: IEvents = new RageEvents;
ui: IUi = new RageUi; ui: IUi = new RageUi;
async wait(ms: number): Promise<void> { wait(ms: number): void {
await mp.game.waitAsync(ms); mp.game.wait(ms);
} }
disableDefaultEngineBehaviour(): void { disableDefaultEngineBehaviour(): void {

View File

@@ -1,5 +1,5 @@
interface IGame { interface IGame {
wait(ms: number): Promise<void>; wait(ms: number): void;
events: IEvents; events: IEvents;
ui: IUi; ui: IUi;
@@ -75,6 +75,7 @@ interface IVehicle extends IEntity {
interface IEntityPool<TEntity> { interface IEntityPool<TEntity> {
at(id: number): TEntity; at(id: number): TEntity;
forEach(fn: (entity: TEntity) => void): void; forEach(fn: (entity: TEntity) => void): void;
exists(entity: TEntity): boolean;
} }

View File

@@ -15,7 +15,7 @@ export default function attachmentManager(game: IGame) {
{ {
attachments: {}, attachments: {},
addFor: async function (entity, id) { addFor: function (entity, id) {
if (this.attachments.hasOwnProperty(id)) { if (this.attachments.hasOwnProperty(id)) {
if (!entity.__attachmentObjects) { if (!entity.__attachmentObjects) {
entity.__attachmentObjects = {}; entity.__attachmentObjects = {};

View File

@@ -10,9 +10,9 @@ game.events.add('SERVER:Vehicle:UpdateData', (vehId, dataStr) => {
setVehicleData(vehicle, data); setVehicleData(vehicle, data);
}); });
game.events.onPlayerEnterVehicle(async (vehicle, seat) => { game.events.onPlayerEnterVehicle((vehicle, seat) => {
while (!game.players.local.inVehicle) { while (!game.players.local.inVehicle) {
await game.wait(0); game.wait(0);
} }
if (vehicle) { if (vehicle) {
@@ -22,11 +22,11 @@ game.events.onPlayerEnterVehicle(async (vehicle, seat) => {
} }
}); });
game.events.onPlayerExitVehicle(async () => { game.events.onPlayerExitVehicle(() => {
var veh = game.players.local.vehicle; var veh = game.players.local.vehicle;
while (game.players.local.inVehicle) { while (game.players.local.inVehicle) {
await game.wait(0); game.wait(0);
} }
if (veh) { if (veh) {
@@ -51,7 +51,7 @@ game.events.onEntityStreamIn((entity: IEntity) => {
}); });
function setVehicleData(veh: IVehicle, data: VehicleData): void { function setVehicleData(veh: IVehicle, data: VehicleData): void {
if (!veh) { if (!veh || !game.vehicles.exists(veh)) {
return; return;
} }