Tracking de l'application VApp (IHM du jeu)

This commit is contained in:
2025-05-11 18:04:12 +02:00
commit 89e9db9b62
17763 changed files with 3718499 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
import { ICallNotification } from '../interfaces';
const scheduledIntervalIdentifiers: Map<number, number> = new Map();
const scheduledTimeoutIdentifiers: Map<number, number> = new Map();
export const clearScheduledInterval = (timerId: number) => {
const identifier = scheduledIntervalIdentifiers.get(timerId);
if (identifier !== undefined) {
clearTimeout(identifier);
scheduledIntervalIdentifiers.delete(timerId);
} else {
throw new Error(`There is no interval scheduled with the given id "${timerId}".`);
}
};
export const clearScheduledTimeout = (timerId: number) => {
const identifier = scheduledTimeoutIdentifiers.get(timerId);
if (identifier !== undefined) {
clearTimeout(identifier);
scheduledTimeoutIdentifiers.delete(timerId);
} else {
throw new Error(`There is no timeout scheduled with the given id "${timerId}".`);
}
};
const computeDelayAndExpectedCallbackTime = (delay: number, nowInMainThread: number) => {
let now: number;
let remainingDelay: number;
const nowInWorker = performance.now();
const elapsed = Math.max(0, nowInWorker - nowInMainThread);
now = nowInWorker;
remainingDelay = delay - elapsed;
const expected = now + remainingDelay;
return { expected, remainingDelay };
};
const setTimeoutCallback = (identifiers: Map<number, number>, timerId: number, expected: number, timerType: string) => {
const now = performance.now();
if (now > expected) {
postMessage(<ICallNotification>{ id: null, method: 'call', params: { timerId, timerType } });
} else {
identifiers.set(timerId, setTimeout(setTimeoutCallback, expected - now, identifiers, timerId, expected, timerType));
}
};
export const scheduleInterval = (delay: number, timerId: number, nowInMainThread: number) => {
const { expected, remainingDelay } = computeDelayAndExpectedCallbackTime(delay, nowInMainThread);
scheduledIntervalIdentifiers.set(
timerId,
setTimeout(setTimeoutCallback, remainingDelay, scheduledIntervalIdentifiers, timerId, expected, 'interval')
);
};
export const scheduleTimeout = (delay: number, timerId: number, nowInMainThread: number) => {
const { expected, remainingDelay } = computeDelayAndExpectedCallbackTime(delay, nowInMainThread);
scheduledTimeoutIdentifiers.set(
timerId,
setTimeout(setTimeoutCallback, remainingDelay, scheduledTimeoutIdentifiers, timerId, expected, 'timeout')
);
};

View File

@@ -0,0 +1,5 @@
import { TBrokerMessage } from '../types';
export interface IBrokerEvent extends Event {
data: TBrokerMessage;
}

View File

@@ -0,0 +1,13 @@
import { TTimerType } from '../types';
export interface ICallNotification {
id: null;
method: 'call';
params: {
timerId: number;
timerType: TTimerType;
};
}

View File

@@ -0,0 +1,13 @@
import { TTimerType } from '../types';
export interface IClearRequest {
id: number;
method: 'clear';
params: {
timerId: number;
timerType: TTimerType;
};
}

View File

@@ -0,0 +1,5 @@
export interface IClearResponse {
error: null;
id: number;
}

View File

@@ -0,0 +1,9 @@
export interface IErrorNotification {
error: {
message: string;
};
id: null;
result: null;
}

View File

@@ -0,0 +1,9 @@
export interface IErrorResponse {
error: {
message: string;
};
id: number;
result: null;
}

View File

@@ -0,0 +1,8 @@
export * from './broker-event';
export * from './call-notification';
export * from './clear-request';
export * from './clear-response';
export * from './error-notification';
export * from './error-response';
export * from './set-notification';
export * from './worker-event';

View File

@@ -0,0 +1,17 @@
import { TTimerType } from '../types';
export interface ISetNotification {
id: null;
method: 'set';
params: {
delay: number;
now: number;
timerId: number;
timerType: TTimerType;
};
}

View File

@@ -0,0 +1,5 @@
import { TWorkerMessage } from '../types';
export interface IWorkerEvent extends Event {
data: TWorkerMessage;
}

54
VApp/node_modules/worker-timers-worker/src/module.ts generated vendored Normal file
View File

@@ -0,0 +1,54 @@
import { clearScheduledInterval, clearScheduledTimeout, scheduleInterval, scheduleTimeout } from './helpers/timer';
import { IBrokerEvent, IClearResponse, IErrorNotification, IErrorResponse } from './interfaces';
/*
* @todo Explicitly referencing the barrel file seems to be necessary when enabling the
* isolatedModules compiler option.
*/
export * from './interfaces/index';
export * from './types/index';
addEventListener('message', ({ data }: IBrokerEvent) => {
try {
if (data.method === 'clear') {
const {
id,
params: { timerId, timerType }
} = data;
if (timerType === 'interval') {
clearScheduledInterval(timerId);
postMessage(<IClearResponse>{ error: null, id });
} else if (timerType === 'timeout') {
clearScheduledTimeout(timerId);
postMessage(<IClearResponse>{ error: null, id });
} else {
throw new Error(`The given type "${timerType}" is not supported`);
}
} else if (data.method === 'set') {
const {
params: { delay, now, timerId, timerType }
} = data;
if (timerType === 'interval') {
scheduleInterval(delay, timerId, now);
} else if (timerType === 'timeout') {
scheduleTimeout(delay, timerId, now);
} else {
throw new Error(`The given type "${timerType}" is not supported`);
}
} else {
throw new Error(`The given method "${(<any>data).method}" is not supported`);
}
} catch (err) {
postMessage(<IErrorNotification | IErrorResponse>{
error: {
message: err.message
},
id: data.id,
result: null
});
}
});

View File

@@ -0,0 +1,6 @@
{
"compilerOptions": {
"isolatedModules": true
},
"extends": "tsconfig-holy-grail/src/tsconfig-web-worker"
}

View File

@@ -0,0 +1,3 @@
import { IClearRequest, ISetNotification } from '../interfaces';
export type TBrokerMessage = IClearRequest | ISetNotification;

View File

@@ -0,0 +1,3 @@
export * from './broker-message';
export * from './timer-type';
export * from './worker-message';

View File

@@ -0,0 +1 @@
export type TTimerType = 'interval' | 'timeout';

View File

@@ -0,0 +1,3 @@
import { ICallNotification, IClearResponse, IErrorNotification, IErrorResponse } from '../interfaces';
export type TWorkerMessage = ICallNotification | IClearResponse | IErrorNotification | IErrorResponse;