forked from jondubois/iogrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
117 lines (110 loc) · 3.19 KB
/
config.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Global configuration options for IOGrid back end
module.exports = {
// Having a large world (lower player density) is more efficient.
// You can divide it up into cells to split up the workload between
// multiple CPU cores.
WORLD_WIDTH: 2000,
WORLD_HEIGHT: 2000,
// Dividing the world into tall vertical strips (instead of square cells)
// tends to be more efficient (but this may vary depending on your use case
// and world size).
WORLD_CELL_WIDTH: 500,
WORLD_CELL_HEIGHT: 2000,
/*
The WORLD_CELL_OVERLAP_DISTANCE allows players/states from two different
cells on the grid to interact with one another.
States from different cells will show un in your cell controller but will have a
special 'external' property set to true.
This represents the maximum distance that two states can be from one another if they
are in different cells and need to interact with one another.
A smaller value is more efficient. Since this overlap area requires coordination
between multiple cells.
*/
WORLD_CELL_OVERLAP_DISTANCE: 150,
/*
This is the interval (in milliseconds) within which the world updates itself.
It also determines the frequency at which data is broadcast to users.
Making this value higher will boost performance and reduce bandwidth consumption
but will increase lag. 20ms is actually really fast - If you add some sort of
motion smoothing on the front end, 50ms or higher should be more than adequate.
*/
WORLD_UPDATE_INTERVAL: 20,
// Delete states which have gone stale (not being updated anymore).
WORLD_STALE_TIMEOUT: 1000,
// Coins don't move, so we will only refresh them
// once per second.
SPECIAL_UPDATE_INTERVALS: {
1000: ['coin']
},
PLAYER_DEFAULT_MOVE_SPEED: 10,
PLAYER_DIAMETER: 45,
PLAYER_MASS: 20,
// Note that the number of bots needs to be either 0 or a multiple of the number of
// worker processes or else it will get rounded up/down.
BOT_COUNT: 10,
BOT_MOVE_SPEED: 5,
BOT_MASS: 10,
BOT_DIAMETER: 45,
BOT_CHANGE_DIRECTION_PROBABILITY: 0.01,
COIN_UPDATE_INTERVAL: 1000,
COIN_DROP_INTERVAL: 400,
COIN_MAX_COUNT: 200,
COIN_PLAYER_NO_DROP_RADIUS: 80,
// The probabilities need to add up to 1.
COIN_TYPES: [
{
type: 4,
value: 1,
radius: 10,
probability: 0.25
},
{
type: 3,
value: 2,
radius: 10,
probability: 0.6
},
{
type: 2,
value: 6,
radius: 10,
probability: 0.1
},
{
type: 1,
value: 12,
radius: 10,
probability: 0.05
}
],
// We can use this to filter out properties which don't need to be sent
// to the front end.
OUTBOUND_STATE_TRANSFORMERS: {
coin: genericStateTransformer,
player: genericStateTransformer
}
};
var privateProps = {
ccid: true,
tcid: true,
mass: true,
speed: true,
changeDirProb: true,
repeatOp: true,
swid: true,
processed: true,
groupWith: true,
ungroupFrom: true,
group: true,
version: true,
external: true
};
function genericStateTransformer(state) {
var clone = {};
Object.keys(state).forEach(function (key) {
if (!privateProps[key]) {
clone[key] = state[key];
}
});
return clone;
}