Skip to content

Commit

Permalink
fix(client): entity sync info
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed Jan 7, 2024
1 parent 2b57965 commit 56f78d0
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions shared/bindings/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,37 @@ static void GetSyncInfo(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_BASE_OBJECT(entity, alt::IEntity);

const auto syncInfo = entity->GetSyncInfo();

v8::Local<v8::Object> 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<v8::Object> 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<v8::Array> 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<v8::Array> propertiesUpdateTick = v8::Array::New(isolate, static_cast<int>(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<v8::Value>& info)
Expand Down

0 comments on commit 56f78d0

Please sign in to comment.