game-data-gen 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/lib/group.js +37 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ npx game-data-gen <input-file-path> <optional-output-file-path>
|
|
|
47
47
|
| `array float32` | `- positions array float32 64` |
|
|
48
48
|
| `array float64` | `- positions array float64 64` |
|
|
49
49
|
|
|
50
|
-
Array fields
|
|
50
|
+
Array fields always require a length. A `count` variable and `push`/`pop` functions are generated to simulate a dynamic array within the fixed capacity.
|
|
51
51
|
|
|
52
52
|
### soa (Structure of Arrays)
|
|
53
53
|
|
|
@@ -72,7 +72,7 @@ For example `src/data.md`:
|
|
|
72
72
|
# game group
|
|
73
73
|
|
|
74
74
|
- playerId number
|
|
75
|
-
- entityIds array uint16
|
|
75
|
+
- entityIds array uint16 64
|
|
76
76
|
|
|
77
77
|
# particle soa 10_000
|
|
78
78
|
|
|
@@ -97,7 +97,7 @@ This will create or update the `src/data.ts` file (see below). The data and func
|
|
|
97
97
|
*/
|
|
98
98
|
|
|
99
99
|
export let playerId = 0;
|
|
100
|
-
export const entityIds = new Uint16Array();
|
|
100
|
+
export const entityIds = new Uint16Array(64);
|
|
101
101
|
export let entityIdsCount = 0;
|
|
102
102
|
|
|
103
103
|
/** Set the value of the playerId field within the game group. */
|
package/dist/lib/group.js
CHANGED
|
@@ -21,43 +21,39 @@ export function addGroup(header, fields, output) {
|
|
|
21
21
|
addZeroFunction(name, fields, output);
|
|
22
22
|
}
|
|
23
23
|
function addFieldDefinition(field, output) {
|
|
24
|
-
const [fieldName, fieldType, fieldArrayType, fieldArrayLength
|
|
24
|
+
const [fieldName, fieldType, fieldArrayType, fieldArrayLength] = field.split(" ");
|
|
25
25
|
switch (fieldType) {
|
|
26
26
|
case FieldType.NUMBER:
|
|
27
27
|
output.push(`export let ${fieldName} = 0`);
|
|
28
28
|
break;
|
|
29
29
|
case FieldType.ARRAY:
|
|
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
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
if (isDynamicArray(fieldType, fieldArrayLength)) {
|
|
58
|
-
output.push(`export let ${fieldName}Count = 0`);
|
|
59
|
-
}
|
|
30
|
+
switch (fieldArrayType) {
|
|
31
|
+
case ArrayType.INT_8:
|
|
32
|
+
output.push(`export const ${fieldName} = new Int8Array(${fieldArrayLength})`);
|
|
33
|
+
break;
|
|
34
|
+
case ArrayType.INT_16:
|
|
35
|
+
output.push(`export const ${fieldName} = new Int16Array(${fieldArrayLength})`);
|
|
36
|
+
break;
|
|
37
|
+
case ArrayType.INT_32:
|
|
38
|
+
output.push(`export const ${fieldName} = new Int32Array(${fieldArrayLength})`);
|
|
39
|
+
break;
|
|
40
|
+
case ArrayType.UINT_8:
|
|
41
|
+
output.push(`export const ${fieldName} = new Uint8Array(${fieldArrayLength})`);
|
|
42
|
+
break;
|
|
43
|
+
case ArrayType.UINT_16:
|
|
44
|
+
output.push(`export const ${fieldName} = new Uint16Array(${fieldArrayLength})`);
|
|
45
|
+
break;
|
|
46
|
+
case ArrayType.UINT_32:
|
|
47
|
+
output.push(`export const ${fieldName} = new Uint32Array(${fieldArrayLength})`);
|
|
48
|
+
break;
|
|
49
|
+
case ArrayType.FLOAT_32:
|
|
50
|
+
output.push(`export const ${fieldName} = new Float32Array(${fieldArrayLength})`);
|
|
51
|
+
break;
|
|
52
|
+
case ArrayType.FLOAT_64:
|
|
53
|
+
output.push(`export const ${fieldName} = new Float64Array(${fieldArrayLength})`);
|
|
54
|
+
break;
|
|
60
55
|
}
|
|
56
|
+
output.push(`export let ${fieldName}Count = 0`);
|
|
61
57
|
break;
|
|
62
58
|
}
|
|
63
59
|
}
|
|
@@ -72,8 +68,8 @@ function addFieldSetFunction(name, field, output) {
|
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
70
|
function addFieldPushFunction(name, field, output) {
|
|
75
|
-
const [fieldName, fieldType
|
|
76
|
-
if (
|
|
71
|
+
const [fieldName, fieldType] = field.split(" ");
|
|
72
|
+
if (fieldType === FieldType.ARRAY) {
|
|
77
73
|
output.push("");
|
|
78
74
|
output.push(`/** Push a value onto the ${fieldName} field within the ${name} group. */`);
|
|
79
75
|
output.push(`export function push${capitalize(fieldName)}(v: number) {`);
|
|
@@ -82,8 +78,8 @@ function addFieldPushFunction(name, field, output) {
|
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
function addFieldPopFunction(name, field, output) {
|
|
85
|
-
const [fieldName, fieldType
|
|
86
|
-
if (
|
|
81
|
+
const [fieldName, fieldType] = field.split(" ");
|
|
82
|
+
if (fieldType === FieldType.ARRAY) {
|
|
87
83
|
output.push("");
|
|
88
84
|
output.push(`/** Pop a value from the ${fieldName} field within the ${name} group. */`);
|
|
89
85
|
output.push(`export function pop${capitalize(fieldName)}() {`);
|
|
@@ -92,11 +88,11 @@ function addFieldPopFunction(name, field, output) {
|
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
90
|
function addFieldZeroFunction(name, field, output) {
|
|
95
|
-
const [fieldName, fieldType
|
|
91
|
+
const [fieldName, fieldType] = field.split(" ");
|
|
96
92
|
output.push("");
|
|
97
93
|
output.push(`/** Zero the ${fieldName} field within the ${name} group. */`);
|
|
98
94
|
output.push(`export function zero${capitalize(fieldName)}() {`);
|
|
99
|
-
zeroField(fieldName, fieldType,
|
|
95
|
+
zeroField(fieldName, fieldType, output);
|
|
100
96
|
output.push("}");
|
|
101
97
|
}
|
|
102
98
|
function addZeroFunction(name, fields, output) {
|
|
@@ -104,26 +100,18 @@ function addZeroFunction(name, fields, output) {
|
|
|
104
100
|
output.push(`/** Zero all fields within the ${name} group. */`);
|
|
105
101
|
output.push(`export function zero${capitalize(name)}() {`);
|
|
106
102
|
for (const field of fields) {
|
|
107
|
-
const [fieldName, fieldType
|
|
108
|
-
zeroField(fieldName, fieldType,
|
|
103
|
+
const [fieldName, fieldType] = field.split(" ");
|
|
104
|
+
zeroField(fieldName, fieldType, output);
|
|
109
105
|
}
|
|
110
106
|
output.push("}");
|
|
111
107
|
}
|
|
112
|
-
function zeroField(name, type,
|
|
108
|
+
function zeroField(name, type, output) {
|
|
113
109
|
switch (type) {
|
|
114
110
|
case FieldType.NUMBER:
|
|
115
111
|
output.push(` ${name} = 0`);
|
|
116
112
|
break;
|
|
117
113
|
case FieldType.ARRAY:
|
|
118
|
-
|
|
119
|
-
output.push(` ${name}Count = 0`);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
output.push(` ${name}.fill(0)`);
|
|
123
|
-
}
|
|
114
|
+
output.push(` ${name}Count = 0`);
|
|
124
115
|
break;
|
|
125
116
|
}
|
|
126
117
|
}
|
|
127
|
-
function isDynamicArray(fieldType, fieldArrayLength) {
|
|
128
|
-
return fieldType === FieldType.ARRAY && !fieldArrayLength;
|
|
129
|
-
}
|