Skip to content

Commit

Permalink
Merge pull request #321 from altmp/ALTV-278
Browse files Browse the repository at this point in the history
feat(client): implement new sdk methods
  • Loading branch information
OlegTrofimov authored Aug 8, 2024
2 parents b9dbbca + 1799f7a commit c07785b
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IndentWidth: 4
---
Language: Cpp
ColumnLimit: 190
AccessModifierOffset: 0
AlignAfterOpenBracket: true
#AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: true
Expand All @@ -28,7 +27,6 @@ AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
#BitFieldColonSpacing: Both
BraceWrapping: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
Expand Down
27 changes: 25 additions & 2 deletions client/src/bindings/Handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,44 @@ static void DriveBiasFrontSetter(v8::Local<v8::String>, v8::Local<v8::Value> val
vehicle->GetHandling()->SetDriveBiasFront(fvalue);
}

static void DriveBiasRearGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& 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::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& 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<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& 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::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& 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<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -1230,6 +1252,7 @@ extern V8Class v8Handling("Handling", Constructor, [](v8::Local<v8::FunctionTemp
V8Helpers::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter);
V8Helpers::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasRear", &DriveBiasRearGetter, &DriveBiasRearSetter);
V8Helpers::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter);
V8Helpers::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter);
Expand Down
35 changes: 33 additions & 2 deletions client/src/bindings/HandlingData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,50 @@ static void DriveBiasFrontSetter(v8::Local<v8::String>, v8::Local<v8::Value> val
handling->SetDriveBiasFront(fvalue);
}

static void DriveBiasRearGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& 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::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& 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<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");

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->GetAcceleration());
V8_RETURN_NUMBER(handling->GetDriveBiasRear());
}

static void AccelerationSetter(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& info)
{
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");

V8_GET_ISOLATE_CONTEXT();

V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash);
Expand All @@ -343,7 +373,7 @@ static void AccelerationSetter(v8::Local<v8::String>, v8::Local<v8::Value> val,

V8_TO_NUMBER(val, fvalue);

handling->SetAcceleration(fvalue);
handling->SetDriveBiasRear(fvalue);
}

static void InitialDriveGearsGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
Expand Down Expand Up @@ -1759,6 +1789,7 @@ extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local<v8::Func
V8Helpers::SetAccessor(isolate, tpl, "percentSubmerged", &PercentSubmergedGetter, &PercentSubmergedSetter);
V8Helpers::SetAccessor(isolate, tpl, "percentSubmergedRatio", &PercentSubmergedRatioGetter, &PercentSubmergedRatioSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasFront", &DriveBiasFrontGetter, &DriveBiasFrontSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveBiasRear", &DriveBiasRearGetter, &DriveBiasRearSetter);
V8Helpers::SetAccessor(isolate, tpl, "acceleration", &AccelerationGetter, &AccelerationSetter);
V8Helpers::SetAccessor(isolate, tpl, "initialDriveGears", &InitialDriveGearsGetter, &InitialDriveGearsSetter);
V8Helpers::SetAccessor(isolate, tpl, "driveInertia", &DriveInertiaGetter, &DriveInertiaSetter);
Expand Down
58 changes: 58 additions & 0 deletions client/src/bindings/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,48 @@ static void SetWheelTyreWidth(const v8::FunctionCallbackInfo<v8::Value>& info)
vehicle->SetWheelTyreWidth(wheel, value);
}

static void GetWheelDynamicFlag(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::Value>& 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<v8::Value>& 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<v8::Value>& 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<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
Expand All @@ -267,6 +309,15 @@ static void GetWheelSurfaceMaterial(const v8::FunctionCallbackInfo<v8::Value>& i
V8_RETURN_UINT(vehicle->GetWheelSurfaceMaterial(wheel));
}

static void SetupTransmission(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
Expand Down Expand Up @@ -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<IVehicle, float, &IVehicle::GetEngineTemperature, &IVehicle::SetEngineTemperature>(isolate, tpl, "engineTemperature");
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetFuelLevel, &IVehicle::SetFuelLevel>(isolate, tpl, "fuelLevel");
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetOilLevel, &IVehicle::SetOilLevel>(isolate, tpl, "oilLevel");
Expand All @@ -348,6 +404,8 @@ extern V8Class v8Vehicle("Vehicle",
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetSteeringAngle, &IVehicle::SetSteeringAngle>(isolate, tpl, "steeringAngle");
V8Helpers::SetAccessor<IVehicle, float, &IVehicle::GetSuspensionHeight, &IVehicle::SetSuspensionHeight>(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);
Expand Down
2 changes: 1 addition & 1 deletion shared/deps/cpp-sdk

0 comments on commit c07785b

Please sign in to comment.