Skip to content

Commit

Permalink
client: alt.Ped.streamedIn getter
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed Jun 30, 2023
1 parent 7f5e983 commit 910cc89
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/src/CV8ScriptRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,18 @@ void CV8ScriptRuntime::OnEntityStreamIn(alt::IEntity* entity)
streamedInPlayers.insert({ entity->GetID(), dynamic_cast<alt::IPlayer*>(entity) });
break;
}
case alt::IEntity::Type::LOCAL_VEHICLE:
case alt::IEntity::Type::VEHICLE:
{
streamedInVehicles.insert({ entity->GetID(), dynamic_cast<alt::IVehicle*>(entity) });
break;
}
case alt::IEntity::Type::LOCAL_PED:
case alt::IEntity::Type::PED:
{
streamedInPeds.insert({ entity->GetID(), dynamic_cast<alt::IPed*>(entity) });
break;
}
}
}

Expand All @@ -429,5 +436,6 @@ void CV8ScriptRuntime::OnDisconnect()
{
streamedInPlayers.clear();
streamedInVehicles.clear();
streamedInPeds.clear();
resourcesLoaded = false;
}
6 changes: 6 additions & 0 deletions client/src/CV8ScriptRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CV8ScriptRuntime : public alt::IScriptRuntime, public IRuntimeEventHandler

std::unordered_map<uint16_t, alt::IPlayer*> streamedInPlayers;
std::unordered_map<uint16_t, alt::IVehicle*> streamedInVehicles;
std::unordered_map<uint16_t, alt::IPed*> streamedInPeds;

uint32_t activeWorkers = 0;

Expand Down Expand Up @@ -213,6 +214,11 @@ class CV8ScriptRuntime : public alt::IScriptRuntime, public IRuntimeEventHandler
{
return streamedInVehicles;
}
auto GetStreamedInPeds()
{
return streamedInPeds;
}


void OnDisconnect();
};
19 changes: 19 additions & 0 deletions client/src/bindings/Ped.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "CV8ScriptRuntime.h"
#include "V8Helpers.h"
#include "V8ResourceImpl.h"
#include "helpers/BindHelpers.h"
Expand All @@ -16,6 +17,23 @@ static void CountGetter(v8::Local<v8::String> name, const v8::PropertyCallbackIn
V8_RETURN_UINT(alt::ICore::Instance().GetPeds().size());
}


static void StreamedInGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();

auto streamedIn = CV8ScriptRuntime::Instance().GetStreamedInPeds();
auto arr = v8::Array::New(isolate, streamedIn.size());
int i = 0;
for(auto kv : streamedIn)
{
arr->Set(ctx, i, resource->GetOrCreateEntity(kv.second, "Ped")->GetJSVal(isolate));
i++;
}

V8_RETURN(arr);
}

static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
Expand Down Expand Up @@ -61,6 +79,7 @@ extern V8Class v8Ped("Ped", v8Entity, [](v8::Local<v8::FunctionTemplate> tpl)

V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter);
V8Helpers::SetStaticAccessor(isolate, tpl, "count", &CountGetter);
V8Helpers::SetStaticAccessor(isolate, tpl, "streamedIn", &StreamedInGetter);
V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID);
V8Helpers::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID);

Expand Down

0 comments on commit 910cc89

Please sign in to comment.