diff --git a/shared/bindings/Entity.cpp b/shared/bindings/Entity.cpp index 5b4518f4..3450903f 100644 --- a/shared/bindings/Entity.cpp +++ b/shared/bindings/Entity.cpp @@ -230,21 +230,37 @@ static void GetSyncInfo(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_GET_THIS_BASE_OBJECT(entity, alt::IEntity); - const auto syncInfo = entity->GetSyncInfo(); - - v8::Local obj = v8::Object::New(isolate); - obj->Set(ctx, V8Helpers::JSValue("active"), V8Helpers::JSValue(syncInfo.active)); - obj->Set(ctx, V8Helpers::JSValue("receivedTick"), V8Helpers::JSValue(syncInfo.receivedTick)); - obj->Set(ctx, V8Helpers::JSValue("fullyReceivedTick"), V8Helpers::JSValue(syncInfo.fullyReceivedTick)); - obj->Set(ctx, V8Helpers::JSValue("sendTick"), V8Helpers::JSValue(syncInfo.sendTick)); - obj->Set(ctx, V8Helpers::JSValue("ackedSendTick"), V8Helpers::JSValue(syncInfo.ackedSendTick)); - obj->Set(ctx, V8Helpers::JSValue("propertyCount"), V8Helpers::JSValue(syncInfo.propertyCount)); - obj->Set(ctx, V8Helpers::JSValue("componentCount"), V8Helpers::JSValue(syncInfo.componentCount)); - obj->Set(ctx, V8Helpers::JSValue("propertiesUpdateTick"), V8Helpers::JSValue(syncInfo.propertiesUpdateTick)); - obj->Set(ctx, V8Helpers::JSValue("componentPropertyIndex"), V8Helpers::JSValue(syncInfo.componentPropertyIndex)); - obj->SetIntegrityLevel(ctx, v8::IntegrityLevel::kFrozen); - - V8_RETURN(obj); + auto syncInfo = entity->GetSyncInfo(); + + v8::Local result = v8::Object::New(isolate); + V8_OBJECT_SET_BOOLEAN(result, "active", syncInfo.active > 0); + V8_OBJECT_SET_UINT(result, "receivedTick", syncInfo.receivedTick); + V8_OBJECT_SET_UINT(result, "fullyReceivedTick", syncInfo.fullyReceivedTick); + V8_OBJECT_SET_UINT(result, "sendTick", syncInfo.sendTick); + V8_OBJECT_SET_UINT(result, "ackedSendTick", syncInfo.ackedSendTick); + V8_OBJECT_SET_NUMBER(result, "propertyCount", syncInfo.propertyCount); + V8_OBJECT_SET_NUMBER(result, "componentCount", syncInfo.componentCount); + + const v8::Local componentPropertyIndex = v8::Array::New(isolate, syncInfo.componentCount); + uint32_t lastPropertyIdx = 0; + for(uint32_t i = 0; i < syncInfo.componentCount; i++) + { + const uint32_t endIdx = i == syncInfo.componentCount - 1 + ? syncInfo.propertyCount + : syncInfo.componentPropertyIndex[i]; + const v8::Local propertiesUpdateTick = v8::Array::New(isolate, static_cast(endIdx - lastPropertyIdx)); + for (uint32_t j = lastPropertyIdx; j < endIdx; j++) + { + propertiesUpdateTick->Set(ctx, j - lastPropertyIdx, V8Helpers::JSValue(syncInfo.propertiesUpdateTick[j])); + } + componentPropertyIndex->Set(ctx, i, propertiesUpdateTick); + lastPropertyIdx = endIdx; + } + + // 2d array of property update ticks grouped per component + result->Set(ctx, v8::String::NewFromUtf8(isolate, "propertyUpdateTicks").ToLocalChecked(), componentPropertyIndex); + + V8_RETURN(result); } static void StaticGetByScriptID(const v8::FunctionCallbackInfo& info)