forked from kaplayjs/kaplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.ts
104 lines (95 loc) · 2.66 KB
/
constants.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
// some default charsets for loading bitmap fonts
export const ASCII_CHARS =
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
export const DEF_ANCHOR = "topleft";
export const BG_GRID_SIZE = 64;
export const DEF_FONT = "monospace";
export const DBG_FONT = "monospace";
export const DEF_TEXT_SIZE = 36;
export const DEF_TEXT_CACHE_SIZE = 64;
export const MAX_TEXT_CACHE_SIZE = 256;
export const FONT_ATLAS_WIDTH = 2048;
export const FONT_ATLAS_HEIGHT = 2048;
export const SPRITE_ATLAS_WIDTH = 2048;
export const SPRITE_ATLAS_HEIGHT = 2048;
// 0.1 pixel padding to texture coordinates to prevent artifact
export const UV_PAD = 0.1;
export const DEF_HASH_GRID_SIZE = 64;
export const DEF_FONT_FILTER = "linear";
export const LOG_MAX = 8;
export const LOG_TIME = 4;
export const VERTEX_FORMAT = [
{ name: "a_pos", size: 2 },
{ name: "a_uv", size: 2 },
{ name: "a_color", size: 4 },
];
const STRIDE = VERTEX_FORMAT.reduce((sum, f) => sum + f.size, 0);
const MAX_BATCHED_QUAD = 2048;
export const MAX_BATCHED_VERTS = MAX_BATCHED_QUAD * 4 * STRIDE;
export const MAX_BATCHED_INDICES = MAX_BATCHED_QUAD * 6;
// vertex shader template, replace {{user}} with user vertex shader code
export const VERT_TEMPLATE = `
attribute vec2 a_pos;
attribute vec2 a_uv;
attribute vec4 a_color;
varying vec2 v_pos;
varying vec2 v_uv;
varying vec4 v_color;
vec4 def_vert() {
return vec4(a_pos, 0.0, 1.0);
}
{{user}}
void main() {
vec4 pos = vert(a_pos, a_uv, a_color);
v_pos = a_pos;
v_uv = a_uv;
v_color = a_color;
gl_Position = pos;
}
`;
// fragment shader template, replace {{user}} with user fragment shader code
export const FRAG_TEMPLATE = `
precision mediump float;
varying vec2 v_pos;
varying vec2 v_uv;
varying vec4 v_color;
uniform sampler2D u_tex;
vec4 def_frag() {
return v_color * texture2D(u_tex, v_uv);
}
{{user}}
void main() {
gl_FragColor = frag(v_pos, v_uv, v_color, u_tex);
if (gl_FragColor.a == 0.0) {
discard;
}
}
`;
// default {{user}} vertex shader code
export const DEF_VERT = `
vec4 vert(vec2 pos, vec2 uv, vec4 color) {
return def_vert();
}
`;
// default {{user}} fragment shader code
export const DEF_FRAG = `
vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) {
return def_frag();
}
`;
export const COMP_DESC = new Set(["id", "require"]);
export const COMP_EVENTS = new Set([
"add",
"update",
"draw",
"destroy",
"inspect",
"drawInspect",
]);
// TODO: escape
// eslint-disable-next-line
export const TEXT_STYLE_RE = /\[(?<style>\w+)\](?<text>.*?)\[\/\k<style>\]/g;
export const DEF_OFFSCREEN_DIS = 200;
// maximum y velocity with body()
export const DEF_JUMP_FORCE = 640;
export const MAX_VEL = 65536;