forked from fenomas/noa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
246 lines (246 loc) · 8.31 KB
/
index.d.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**
* Main engine class.
* Takes an object full of optional settings as a parameter.
*
* ```js
* import { Engine } from 'noa-engine'
* var noa = new Engine({
* debug: false,
* })
* ```
*
* Note that the options object is also passed to noa's
* child modules ({@link Rendering}, {@link Container}, etc).
* See docs for each module for their options.
*
* @emits tick(dt)
* @emits beforeRender(dt)
* @emits afterRender(dt)
* @emits targetBlockChanged(blockDesc)
*/
export class Engine extends EventEmitter {
/**
* The core Engine constructor uses the following options:
*
* ```js
* var defaultOptions = {
* debug: false,
* silent: false,
* playerHeight: 1.8,
* playerWidth: 0.6,
* playerStart: [0, 10, 0],
* playerAutoStep: false,
* tickRate: 30, // ticks per second
* maxRenderRate: 0, // max FPS, 0 for uncapped
* blockTestDistance: 10,
* stickyPointerLock: true,
* dragCameraOutsidePointerLock: true,
* stickyFullscreen: false,
* skipDefaultHighlighting: false,
* originRebaseDistance: 25,
* }
* ```
*/
constructor(opts?: {});
/** Version string, e.g. `"0.25.4"` */
version: string;
/** @internal */
_paused: boolean;
/** @internal */
_dragOutsideLock: any;
/** @internal */
_originRebaseDistance: any;
/** @internal */
worldOriginOffset: number[];
/** @internal */
positionInCurrentTick: number;
/**
* String identifier for the current world.
* It's safe to ignore this if your game has only one level/world.
*/
worldName: string;
/**
* Multiplier for how fast time moves. Setting this to a value other than
* `1` will make the game speed up or slow down. This can significantly
* affect how core systems behave (particularly physics!).
*/
timeScale: number;
/** Child module for managing the game's container, canvas, etc. */
container: Container;
/** The game's tick rate (ticks per second)
* @readonly
*/
readonly tickRate: any;
/** The game's max framerate (use `0` for uncapped) */
maxRenderRate: any;
/** Inputs manager - abstracts key/mouse input */
inputs: import("./lib/inputs").Inputs;
/** A registry where voxel/material properties are managed */
registry: Registry;
/** Manages the world, chunks, and all voxel data */
world: World;
/** Rendering manager */
rendering: Rendering;
/** Physics engine - solves collisions, properties, etc. */
physics: Physics;
/** Entity manager / Entity Component System (ECS) */
entities: Entities;
/** Alias to `noa.entities` */
ents: Entities;
/** Entity id for the player entity */
playerEntity: number;
/** Manages the game's camera, view angle, sensitivity, etc. */
camera: Camera;
/** How far to check for a solid voxel the player is currently looking at */
blockTestDistance: any;
/**
* Callback to determine which voxels can be targeted.
* Defaults to a solidity check, but can be overridden with arbitrary logic.
* @type {(blockID: number) => boolean}
*/
blockTargetIdCheck: (blockID: number) => boolean;
/**
* Dynamically updated object describing the currently targeted block.
* @type {null | {
* blockID:number,
* position: number[],
* normal: number[],
* adjacent: number[],
* }}
*/
targetedBlock: {
blockID: number;
position: number[];
normal: number[];
adjacent: number[];
};
defaultBlockHighlightFunction: (tgt: any) => void;
/** @internal */
_terrainMesher: TerrainMesher;
/** @internal */
_objectMesher: ObjectMesher;
/** @internal */
_targetedBlockDat: {
blockID: number;
position: any;
normal: any;
adjacent: any;
};
/** @internal */
_prevTargetHash: number;
/** @internal */
makeTargetHash: (pos: any, norm: any, id: any) => number;
/** @internal */
_pickPos: any;
/** @internal */
_pickResult: {
_localPosition: any;
position: number[];
normal: number[];
};
/** @internal */
vec3: typeof vec3;
/** @internal */
ndarray: any;
/**
* Tick function, called by container module at a fixed timestep.
* Clients should not normally need to call this manually.
* @internal
*/
tick(dt: any): void;
/**
* Render function, called every animation frame. Emits #beforeRender(dt), #afterRender(dt)
* where dt is the time in ms *since the last tick*.
* Clients should not normally need to call this manually.
* @internal
*/
render(dt: any, framePart: any): void;
/** Pausing the engine will also stop render/tick events, etc. */
setPaused(paused?: boolean): void;
/**
* Get the voxel ID at the specified position
*/
getBlock(x: any, y?: number, z?: number): any;
/**
* Sets the voxel ID at the specified position.
* Does not check whether any entities are in the way!
*/
setBlock(id: any, x: any, y?: number, z?: number): any;
/**
* Adds a block, unless there's an entity in the way.
*/
addBlock(id: any, x: any, y?: number, z?: number): any;
/**
* Precisely converts a world position to the current internal
* local frame of reference.
*
* See `/docs/positions.md` for more info.
*
* Params:
* * `global`: input position in global coords
* * `globalPrecise`: (optional) sub-voxel offset to the global position
* * `local`: output array which will receive the result
*/
globalToLocal(global: any, globalPrecise: any, local: any): any;
/**
* Precisely converts a world position to the current internal
* local frame of reference.
*
* See `/docs/positions.md` for more info.
*
* Params:
* * `local`: input array of local coords
* * `global`: output array which receives the result
* * `globalPrecise`: (optional) sub-voxel offset to the output global position
*
* If both output arrays are passed in, `global` will get int values and
* `globalPrecise` will get fractional parts. If only one array is passed in,
* `global` will get the whole output position.
*/
localToGlobal(local: any, global: any, globalPrecise?: any): any;
/**
* Raycast through the world, returning a result object for any non-air block
*
* See `/docs/positions.md` for info on working with precise positions.
*
* @param {number[]} pos where to pick from (default: player's eye pos)
* @param {number[]} dir direction to pick along (default: camera vector)
* @param {number} dist pick distance (default: `noa.blockTestDistance`)
* @param {(id:number) => boolean} blockTestFunction which voxel IDs can be picked (default: any solid voxel)
*/
pick(pos?: number[], dir?: number[], dist?: number, blockTestFunction?: (id: number) => boolean): {
position: number[];
normal: number[];
_localPosition: number[];
};
/**
* @internal
* Do a raycast in local coords.
* See `/docs/positions.md` for more info.
* @param {number[]} pos where to pick from (default: player's eye pos)
* @param {number[]} dir direction to pick along (default: camera vector)
* @param {number} dist pick distance (default: `noa.blockTestDistance`)
* @param {(id:number) => boolean} blockTestFunction which voxel IDs can be picked (default: any solid voxel)
* @returns { null | {
* position: number[],
* normal: number[],
* _localPosition: number[],
* }}
*/
_localPick(pos?: number[], dir?: number[], dist?: number, blockTestFunction?: (id: number) => boolean): null | {
position: number[];
normal: number[];
_localPosition: number[];
};
}
import { EventEmitter } from "events";
import { Container } from "./lib/container";
import { Registry } from "./lib/registry";
import { World } from "./lib/world";
import { Rendering } from "./lib/rendering";
import { Physics } from "./lib/physics";
import { Entities } from "./lib/entities";
import { Camera } from "./lib/camera";
import TerrainMesher from "./lib/terrainMesher";
import ObjectMesher from "./lib/objectMesher";
import vec3 from "gl-vec3";