From 55e23aa8149e9d7525acbf9bb274d181e46ae5c7 Mon Sep 17 00:00:00 2001 From: vadzz Date: Sun, 4 Aug 2024 15:59:41 +0300 Subject: [PATCH 1/2] feat(client): implement new sdk methods ALTV-278 --- .clang-format | 2 - client/src/bindings/Handling.cpp | 27 ++++++++++++- client/src/bindings/HandlingData.cpp | 35 ++++++++++++++++- client/src/bindings/Vehicle.cpp | 58 ++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 6 deletions(-) diff --git a/.clang-format b/.clang-format index 7cbf8ef7..8dd3281c 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,6 @@ IndentWidth: 4 --- Language: Cpp ColumnLimit: 190 -AccessModifierOffset: 0 AlignAfterOpenBracket: true #AlignConsecutiveAssignments: true AlignConsecutiveBitFields: true @@ -28,7 +27,6 @@ AlwaysBreakTemplateDeclarations: Yes BinPackArguments: false BinPackParameters: false #BitFieldColonSpacing: Both -BraceWrapping: Custom BraceWrapping: AfterCaseLabel: true AfterClass: true diff --git a/client/src/bindings/Handling.cpp b/client/src/bindings/Handling.cpp index ce119d60..d572511d 100644 --- a/client/src/bindings/Handling.cpp +++ b/client/src/bindings/Handling.cpp @@ -221,22 +221,44 @@ static void DriveBiasFrontSetter(v8::Local, v8::Local val vehicle->GetHandling()->SetDriveBiasFront(fvalue); } +static void DriveBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDriveBiasRear()); +} + +static void DriveBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); + + V8_TO_NUMBER(val, fvalue); + vehicle->ReplaceHandling(); + vehicle->GetHandling()->SetDriveBiasRear(fvalue); +} + static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); - V8_RETURN_NUMBER(vehicle->GetHandling()->GetAcceleration()); + V8_RETURN_NUMBER(vehicle->GetHandling()->GetDriveBiasRear()); } static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle); V8_TO_NUMBER(val, fvalue); vehicle->ReplaceHandling(); - vehicle->GetHandling()->SetAcceleration(fvalue); + vehicle->GetHandling()->SetDriveBiasRear(fvalue); } static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1230,6 +1252,7 @@ extern V8Class v8Handling("Handling", Constructor, [](v8::Local, v8::Local val handling->SetDriveBiasFront(fvalue); } +static void DriveBiasRearGetter(v8::Local, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + V8_RETURN_NUMBER(handling->GetDriveBiasRear()); +} + +static void DriveBiasRearSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + + V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); + + auto handling = alt::ICore::Instance().GetHandlingData(modelHash); + V8_CHECK(handling, "handling data for vehicle not found"); + + V8_TO_NUMBER(val, fvalue); + + handling->SetDriveBiasRear(fvalue); +} + static void AccelerationGetter(v8::Local, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); @@ -329,11 +357,13 @@ static void AccelerationGetter(v8::Local, const v8::PropertyCallback auto handling = alt::ICore::Instance().GetHandlingData(modelHash); V8_CHECK(handling, "handling data for vehicle not found"); - V8_RETURN_NUMBER(handling->GetAcceleration()); + V8_RETURN_NUMBER(handling->GetDriveBiasRear()); } static void AccelerationSetter(v8::Local, v8::Local val, const v8::PropertyCallbackInfo& info) { + V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear"); + V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash); @@ -343,7 +373,7 @@ static void AccelerationSetter(v8::Local, v8::Local val, V8_TO_NUMBER(val, fvalue); - handling->SetAcceleration(fvalue); + handling->SetDriveBiasRear(fvalue); } static void InitialDriveGearsGetter(v8::Local, const v8::PropertyCallbackInfo& info) @@ -1759,6 +1789,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local& info) vehicle->SetWheelTyreWidth(wheel, value); } +static void GetWheelDynamicFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_RETURN_BOOLEAN(vehicle->GetWheelDynamicFlag(wheel, flag)); +} + +static void SetWheelDynamicFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(3); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_ARG_TO_BOOLEAN(3, value); + vehicle->SetWheelDynamicFlag(wheel, flag, value); +} + +static void GetWheelConfigFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(2); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_RETURN_BOOLEAN(vehicle->GetWheelConfigFlag(wheel, flag)); +} + +static void SetWheelConfigFlag(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(3); + V8_ARG_TO_INT(1, wheel); + V8_ARG_TO_UINT(2, flag); + V8_ARG_TO_BOOLEAN(3, value); + vehicle->SetWheelConfigFlag(wheel, flag, value); +} + static void GetWheelSurfaceMaterial(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT(); @@ -267,6 +309,15 @@ static void GetWheelSurfaceMaterial(const v8::FunctionCallbackInfo& i V8_RETURN_UINT(vehicle->GetWheelSurfaceMaterial(wheel)); } +static void SetupTransmission(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_GET_THIS_BASE_OBJECT(vehicle, alt::IVehicle); + V8_CHECK_ARGS_LEN(0); + + vehicle->SetupTransmission(); +} + static void StaticGetByRemoteId(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -331,6 +382,11 @@ extern V8Class v8Vehicle("Vehicle", V8Helpers::SetMethod(isolate, tpl, "getWheelTyreWidth", GetWheelTyreWidth); V8Helpers::SetMethod(isolate, tpl, "setWheelTyreWidth", SetWheelTyreWidth); + V8Helpers::SetMethod(isolate, tpl, "getWheelDynamicFlag", GetWheelDynamicFlag); + V8Helpers::SetMethod(isolate, tpl, "setWheelDynamicFlag", SetWheelDynamicFlag); + V8Helpers::SetMethod(isolate, tpl, "getWheelConfigFlag", GetWheelConfigFlag); + V8Helpers::SetMethod(isolate, tpl, "setWheelConfigFlag", SetWheelConfigFlag); + V8Helpers::SetAccessor(isolate, tpl, "engineTemperature"); V8Helpers::SetAccessor(isolate, tpl, "fuelLevel"); V8Helpers::SetAccessor(isolate, tpl, "oilLevel"); @@ -348,6 +404,8 @@ extern V8Class v8Vehicle("Vehicle", V8Helpers::SetAccessor(isolate, tpl, "steeringAngle"); V8Helpers::SetAccessor(isolate, tpl, "suspensionHeight"); + V8Helpers::SetMethod(isolate, tpl, "setupTransmission", SetupTransmission); + /*GETTERS BELOW ARE UNIMPLEMENTED V8Helpers::SetAccessor(isolate, tpl, "isDestroyed", &IsDestroyedGetter); V8Helpers::SetAccessor(isolate, tpl, "driver", &DriverGetter); From e21b1e4ac034a95d0ebbdb98af3d01fda627ddcc Mon Sep 17 00:00:00 2001 From: doxoh Date: Thu, 8 Aug 2024 13:13:30 +0200 Subject: [PATCH 2/2] chore: update sdk --- shared/deps/cpp-sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 22e1fdd3..b1ced940 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 22e1fdd37b8e379d04b279161571276cb7bb12da +Subproject commit b1ced94027a7b3c0c2167b12e45da80b49c8527b