-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
81 lines (64 loc) · 2.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { ECRRule, PlayerInfo, SimpleEcr } from "@worldscapes/common";
import {
SimpleEngineServer,
SimpleNetworkServer,
SimpleServerAuth,
SimpleServerSimulation,
WebsocketServerNetworkAdapter
} from "@worldscapes/server";
import {GameSettings, MatterSerializer} from "@worldscapes-arkanoid/common";
import { commandInitializer } from "./setup/initializers/command.initializer";
import { ruleInitializer } from "./setup/initializers/rule.initializer";
import {ConsoleParams, readArgs } from "./setup/cli/readArgs";
const consoleArgs: ConsoleParams = readArgs();
const gameRoomSettings = {
player1: consoleArgs.player1,
player2: consoleArgs.player2
};
const players: PlayerInfo[] = [
gameRoomSettings.player1,
gameRoomSettings.player2
];
const DEFAULT_GAME_SETTINGS: GameSettings = {
initialPoints: 5,
gameRoomWidth: 1000,
gameRoomHeight: 1000,
platformWidth: 120,
platformHeight: 20,
platformGapFromBorder: 25,
platformDensity: 10000,
platformFriction: 0.01,
platformRestitution: 1.1, //1.05,
ballRadius: 14,
ballDensity: 0.001,
ballRestitution: 1.21, //1.22,
ballInitialForce: 10 * 0.001,
};
const commands = commandInitializer(gameRoomSettings, DEFAULT_GAME_SETTINGS);
const rules = ruleInitializer(gameRoomSettings, DEFAULT_GAME_SETTINGS);
(async function init() {
console.log("Initializing Engine.");
console.log("Setting up network server.");
const serverAdapter = new WebsocketServerNetworkAdapter(
new SimpleServerAuth(players),
consoleArgs.port
);
await serverAdapter.isReady();
console.log("Network server is up.");
console.log("Creating simulation instance");
const ecr = new SimpleEcr();
ecr.injectCommands(commands);
rules.forEach(rule => ecr.addRule(rule as unknown as ECRRule));
console.log("Creating Engine Server.");
const server = new SimpleEngineServer(
new SimpleServerSimulation(ecr, players),
new SimpleNetworkServer(
serverAdapter,
new MatterSerializer(),
),
{ simulationTickInterval: 24 }
);
console.log("Starting Engine Server.");
server.start();
console.log("Initialized.");
})().then();