Skip to content

Commit

Permalink
Add partial debugger support for new types (#715)
Browse files Browse the repository at this point in the history
* Add PACKED_VECTOR4_ARRAY type

* Disable noUselessElse lint rule

* Fix lint rules and formatting

* Implement decoding for PACKED_VECTOR4_ARRAY

* Implement decoding for typed Arrays
  • Loading branch information
DaelonSuzuka authored Sep 15, 2024
1 parent bc89f27 commit e45d122
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
7 changes: 7 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@
"files": {
"include": ["src/**/*.ts"],
"ignore": ["node_modules"]
},
"linter": {
"rules": {
"style": {
"noUselessElse": "off"
}
}
}
}
76 changes: 67 additions & 9 deletions src/debugger/godot4/variables/variant_decoder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
GDScriptTypes,
BufferModel,
type BufferModel,
Vector3,
Vector2,
Basis,
Expand All @@ -23,6 +23,7 @@ import {
Projection,
ENCODE_FLAG_64,
ENCODE_FLAG_OBJECT_AS_ID,
ENCODE_FLAG_TYPED_ARRAY,
RID,
Callable,
Signal,
Expand Down Expand Up @@ -143,7 +144,11 @@ export class VariantDecoder {
case GDScriptTypes.DICTIONARY:
return this.decode_Dictionary(model);
case GDScriptTypes.ARRAY:
return this.decode_Array(model);
if (type & ENCODE_FLAG_TYPED_ARRAY) {
return this.decode_TypedArray(model);
} else {
return this.decode_Array(model);
}
case GDScriptTypes.PACKED_BYTE_ARRAY:
return this.decode_PackedByteArray(model);
case GDScriptTypes.PACKED_INT32_ARRAY:
Expand All @@ -168,6 +173,12 @@ export class VariantDecoder {
} else {
return this.decode_PackedVector3fArray(model);
}
case GDScriptTypes.PACKED_VECTOR4_ARRAY:
if (type & ENCODE_FLAG_OBJECT_AS_ID) {
return this.decode_PackedVector4dArray(model);
} else {
return this.decode_PackedVector4fArray(model);
}
case GDScriptTypes.PACKED_COLOR_ARRAY:
return this.decode_PackedColorArray(model);
default:
Expand All @@ -177,7 +188,7 @@ export class VariantDecoder {

public get_dataset(buffer: Buffer) {
const len = buffer.readUInt32LE(0);
if (buffer.length != len + 4) {
if (buffer.length !== len + 4) {
return undefined;
}
const model: BufferModel = {
Expand Down Expand Up @@ -220,19 +231,36 @@ export class VariantDecoder {
return output;
}

private decode_TypedArray(model: BufferModel) {
const output: Array<any> = [];

// TODO: the type information is currently discarded
// it needs to be decoded and then packed into the output somehow

const type = this.decode_UInt32(model);
const count = this.decode_UInt32(model);

for (let i = 0; i < count; i++) {
const value = this.decode_variant(model);
output.push(value);
}

return output;
}

private decode_Basisf(model: BufferModel) {
return new Basis(
this.decode_Vector3f(model),
this.decode_Vector3f(model),
this.decode_Vector3f(model)
this.decode_Vector3f(model), //
);
}

private decode_Basisd(model: BufferModel) {
return new Basis(
this.decode_Vector3d(model),
this.decode_Vector3d(model),
this.decode_Vector3d(model)
this.decode_Vector3d(model), //
);
}

Expand Down Expand Up @@ -476,6 +504,16 @@ export class VariantDecoder {
return output;
}

private decode_PackedVector4fArray(model: BufferModel) {
const count = this.decode_UInt32(model);
const output: Vector4[] = [];
for (let i = 0; i < count; i++) {
output.push(this.decode_Vector4f(model));
}

return output;
}

private decode_PackedVector2dArray(model: BufferModel) {
const count = this.decode_UInt32(model);
const output: Vector2[] = [];
Expand All @@ -496,6 +534,16 @@ export class VariantDecoder {
return output;
}

private decode_PackedVector4dArray(model: BufferModel) {
const count = this.decode_UInt32(model);
const output: Vector4[] = [];
for (let i = 0; i < count; i++) {
output.push(this.decode_Vector4d(model));
}

return output;
}

private decode_Quaternionf(model: BufferModel) {
const x = this.decode_Float32(model);
const y = this.decode_Float32(model);
Expand Down Expand Up @@ -555,26 +603,36 @@ export class VariantDecoder {
}

private decode_Projectionf(model: BufferModel) {
return new Projection(this.decode_Vector4f(model), this.decode_Vector4f(model), this.decode_Vector4f(model), this.decode_Vector4f(model));
return new Projection(
this.decode_Vector4f(model),
this.decode_Vector4f(model),
this.decode_Vector4f(model),
this.decode_Vector4f(model),
);
}

private decode_Projectiond(model: BufferModel) {
return new Projection(this.decode_Vector4d(model), this.decode_Vector4d(model), this.decode_Vector4d(model), this.decode_Vector4d(model));
return new Projection(
this.decode_Vector4d(model),
this.decode_Vector4d(model),
this.decode_Vector4d(model),
this.decode_Vector4d(model),
);
}

private decode_Transform2Df(model: BufferModel) {
return new Transform2D(
this.decode_Vector2f(model),
this.decode_Vector2f(model),
this.decode_Vector2f(model)
this.decode_Vector2f(model), //
);
}

private decode_Transform2Dd(model: BufferModel) {
return new Transform2D(
this.decode_Vector2d(model),
this.decode_Vector2d(model),
this.decode_Vector2d(model)
this.decode_Vector2d(model), //
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/debugger/godot4/variables/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ export enum GDScriptTypes {
PACKED_VECTOR2_ARRAY,
PACKED_VECTOR3_ARRAY,
PACKED_COLOR_ARRAY,
PACKED_VECTOR4_ARRAY,

VARIANT_MAX
}

export const ENCODE_FLAG_64 = 1 << 16;
export const ENCODE_FLAG_OBJECT_AS_ID = 1 << 16;
export const ENCODE_FLAG_TYPED_ARRAY = 1 << 16;

export interface BufferModel {
buffer: Buffer;
Expand Down

0 comments on commit e45d122

Please sign in to comment.