Skip to content

Commit

Permalink
shared: add new SDK stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Sep 30, 2023
1 parent fb7be0a commit c3b893e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 4 additions & 2 deletions server/src/bindings/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_CONSTRUCTOR();
V8_CHECK_ARGS_LEN_MIN_MAX(3, 6);
V8_CHECK_ARGS_LEN_MIN_MAX(3, 7);

uint32_t model;
if(info[0]->IsString())
Expand Down Expand Up @@ -48,7 +48,9 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
lodDistance = lodDistanceVal;
}

IObject* object = alt::ICore::Instance().CreateObject(model, pos, rot, alpha, textureVariation, lodDistance);
V8_ARG_TO_UINT_OPT(info.Length() <= 4 ? 4 : 7, streamingDistance, 0);

IObject* object = alt::ICore::Instance().CreateObject(model, pos, rot, alpha, textureVariation, lodDistance, streamingDistance);
V8_BIND_BASE_OBJECT(object, "Failed to create object");
}

Expand Down
5 changes: 3 additions & 2 deletions server/src/bindings/Ped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_CONSTRUCTOR();
V8_CHECK_ARGS_LEN(3);
V8_CHECK_ARGS_LEN_MIN(3);

uint32_t model;
if(info[0]->IsString())
Expand All @@ -26,8 +26,9 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)

V8_ARG_TO_VECTOR3(2, pos);
V8_ARG_TO_VECTOR3(3, rot);
V8_ARG_TO_UINT_OPT(4, streamingDistance, 0);

IPed* ped = alt::ICore::Instance().CreatePed(model, pos, rot);
IPed* ped = alt::ICore::Instance().CreatePed(model, pos, rot, streamingDistance);
V8_BIND_BASE_OBJECT(ped, "Failed to create ped");
}

Expand Down
10 changes: 7 additions & 3 deletions server/src/bindings/Vehicle.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <iso646.h>

#include "stdafx.h"

#include "V8Helpers.h"
Expand All @@ -18,7 +20,7 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_CONSTRUCTOR();
V8_CHECK_ARGS_LEN2(3, 7);
V8_CHECK_ARGS_LEN_MIN_MAX(3, 8);

V8_CHECK(info[0]->IsString() || info[0]->IsNumber(), "string or number expected");

Expand All @@ -36,11 +38,11 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)

alt::Position pos;
alt::Rotation rot;

if(info.Length() == 3)
{
V8_ARG_TO_VECTOR3(2, position);
V8_ARG_TO_VECTOR3(3, rotation);

pos = position;
rot = rotation;
}
Expand All @@ -57,7 +59,9 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
rot = { rx, ry, rz };
}

IVehicle* veh = alt::ICore::Instance().CreateVehicle(modelHash, pos, rot);
V8_ARG_TO_UINT_OPT(info.Length() <= 4 ? 4 : 8, streamingDistance, 0);

IVehicle* veh = alt::ICore::Instance().CreateVehicle(modelHash, pos, rot, streamingDistance);

V8_BIND_BASE_OBJECT(veh, "Failed to create vehicle");
}
Expand Down
11 changes: 11 additions & 0 deletions shared/bindings/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ static void ModelGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8
V8_RETURN_UINT(ent->GetModel());
}


static void StreamingDistanceGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity);
V8_RETURN_UINT(ent->GetStreamingDistance());
}

static void ModelSetter(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& info)
{
V8_GET_ISOLATE_CONTEXT();
Expand Down Expand Up @@ -283,6 +291,9 @@ extern V8Class v8Entity("Entity",

V8Helpers::SetAccessor<IEntity, bool, &IEntity::HasCollision, &IEntity::SetCollision>(isolate, tpl, "collision");

V8Helpers::SetAccessor(isolate, tpl, "streamingDistance", &StreamingDistanceGetter);


V8Helpers::SetAccessor<IEntity, uint32_t, &IEntity::GetTimestamp>(isolate, tpl, "timestamp");
#endif // ALT_SERVER_API

Expand Down

0 comments on commit c3b893e

Please sign in to comment.