Skip to content

Commit

Permalink
server: add entityAndAnimHashPairs to startSyncedScene event (#291)
Browse files Browse the repository at this point in the history
* server: add entityAndAnimHashPairs to startSyncedScene event

* server: fix wrong used value
  • Loading branch information
deluvas1911 authored Jul 27, 2023
1 parent d3bb52c commit 3a5c267
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/src/events/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,25 @@ V8_LOCAL_EVENT_HANDLER startSyncedScene(EventType::START_SYNCED_SCENE,
{
auto ev = static_cast<const alt::CStartSyncedSceneEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();
const auto ctx = resource->GetContext();

args.push_back(resource->GetBaseObjectOrNull(ev->GetSource()));
args.push_back(V8Helpers::JSValue(ev->GetSceneID()));
args.push_back(resource->CreateVector3(ev->GetStartPosition()));
args.push_back(resource->CreateVector3(ev->GetStartRotation()));
args.push_back(V8Helpers::JSValue(ev->GetAnimDictHash()));

const auto entityAndAnimHashPairs = ev->GetEntityAndAnimHashPairs();
const auto animHashArray = v8::Array::New(isolate, entityAndAnimHashPairs.size());
auto idx = 0;
for (auto [entity, animHash] : entityAndAnimHashPairs)
{
V8_NEW_OBJECT(entityAnimPair)
V8_OBJECT_SET_BASE_OBJECT(entityAnimPair, "entity", entity.get())
V8_OBJECT_SET_UINT(entityAnimPair, "animHash", animHash)
animHashArray->Set(ctx, idx++, entityAnimPair);
}
args.push_back(animHashArray);
});

V8_LOCAL_EVENT_HANDLER stopSyncedScene(EventType::STOP_SYNCED_SCENE,
Expand Down
2 changes: 2 additions & 0 deletions shared/helpers/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@

#define V8_OBJECT_SET_NULL(v8Val, prop) (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), v8::Null(isolate));

#define V8_OBJECT_SET_BASE_OBJECT(v8Val, prop, val) (v8Val)->Set(ctx, v8::String::NewFromUtf8(isolate, prop).ToLocalChecked(), resource->GetBaseObjectOrNull(val));

#define V8_NEW_OBJECT(val) v8::Local<v8::Object> val = v8::Object::New(isolate);

#define V8_NEW_ARGS(val) std::vector<v8::Local<v8::Value>> val;
Expand Down

0 comments on commit 3a5c267

Please sign in to comment.