Skip to content

Commit bd7f0f3

Browse files
committed
Cleanup
1 parent 0708b74 commit bd7f0f3

2 files changed

Lines changed: 68 additions & 39 deletions

File tree

fusion/fusion.script

Lines changed: 0 additions & 21 deletions
This file was deleted.

fusion/src/fusion.cpp

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,55 @@ static FusionObject* CreateFusionObject(dmhash_t id, FusionCore::ObjectRoot* obj
466466
return fusion_object;
467467
}
468468

469+
static bool IsPropertyVector3(dmGameObject::HInstance instance, dmhash_t component_id, dmhash_t property_id)
470+
{
471+
dmVMath::Vector3 out;
472+
return (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsVector3(instance, component_id, property_id, &out));
473+
}
474+
static bool IsPropertyVector4(dmGameObject::HInstance instance, dmhash_t component_id, dmhash_t property_id)
475+
{
476+
dmVMath::Vector4 out;
477+
return (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsVector4(instance, component_id, property_id, &out));
478+
}
479+
static bool IsPropertyQuat(dmGameObject::HInstance instance, dmhash_t component_id, dmhash_t property_id)
480+
{
481+
dmVMath::Quat out;
482+
return (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsQuat(instance, component_id, property_id, &out));
483+
}
484+
static bool IsPropertyFloat(dmGameObject::HInstance instance, dmhash_t component_id, dmhash_t property_id)
485+
{
486+
float out;
487+
return (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsFloat(instance, component_id, property_id, &out));
488+
}
489+
static bool IsPropertyBool(dmGameObject::HInstance instance, dmhash_t component_id, dmhash_t property_id)
490+
{
491+
bool out;
492+
return (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsBool(instance, component_id, property_id, &out));
493+
}
494+
static bool IsPropertyHash(dmGameObject::HInstance instance, dmhash_t component_id, dmhash_t property_id)
495+
{
496+
dmhash_t out;
497+
return (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsHash(instance, component_id, property_id, &out));
498+
}
499+
500+
static bool IsPropertySynced(dmGameObject::HInstance instance, dmhash_t component_id, dmhash_t property_id, ScriptProperties* properties)
501+
{
502+
dmArray<dmhash_t>** props = properties->Get(component_id);
503+
if (props != 0x0)
504+
{
505+
int prop_count = (*props)->Size();
506+
for (int i = 0; i < prop_count; i++)
507+
{
508+
dmhash_t synced_property_id = (**props)[i];
509+
if (property_id == synced_property_id)
510+
{
511+
return true;
512+
}
513+
}
514+
}
515+
return false;
516+
}
517+
469518

470519
static bool BuildObjectHeader(dmhash_t id, dmMessage::URL* factory_url, FusionObjectOptions* options, uint8_t* header, size_t &header_length, size_t &words_count)
471520
{
@@ -527,53 +576,47 @@ static bool BuildObjectHeader(dmhash_t id, dmMessage::URL* factory_url, FusionOb
527576
// todo: this is not pretty - we are trying every property type one
528577
// after another since we have no type inspection in dmSDK
529578
dmhash_t property_id = (**props)[i];
530-
bool outbool;
531-
dmhash_t outhash;
532-
float outfloat;
533-
dmVMath::Quat outquat;
534-
dmVMath::Vector3 outv3;
535-
dmVMath::Vector4 outv4;
536-
if (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsVector3(instance, component_id, property_id, &outv3))
579+
if (IsPropertyVector3(instance, component_id, property_id))
537580
{
538581
dmLogInfo(" Script property %s VECTOR3", dmHashReverseSafe64(property_id));
539582
words_count += 3;
540583
actual_prop_count++;
541584
header_length += PushHash(header + header_length, property_id);
542585
header_length += PushUint8(header + header_length, ScriptPropertyType::VECTOR3);
543586
}
544-
else if (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsVector4(instance, component_id, property_id, &outv4))
587+
else if (IsPropertyVector4(instance, component_id, property_id))
545588
{
546589
dmLogInfo(" Script property %s VECTOR4", dmHashReverseSafe64(property_id));
547590
words_count += 4;
548591
actual_prop_count++;
549592
header_length += PushHash(header + header_length, property_id);
550593
header_length += PushUint8(header + header_length, ScriptPropertyType::VECTOR4);
551594
}
552-
else if (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsQuat(instance, component_id, property_id, &outquat))
595+
else if (IsPropertyQuat(instance, component_id, property_id))
553596
{
554597
dmLogInfo(" Script property %s QUAT", dmHashReverseSafe64(property_id));
555598
words_count += 4;
556599
actual_prop_count++;
557600
header_length += PushHash(header + header_length, property_id);
558601
header_length += PushUint8(header + header_length, ScriptPropertyType::QUAT);
559602
}
560-
else if (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsFloat(instance, component_id, property_id, &outfloat))
603+
else if (IsPropertyFloat(instance, component_id, property_id))
561604
{
562605
dmLogInfo(" Script property %s FLOAT", dmHashReverseSafe64(property_id));
563606
words_count += 1;
564607
actual_prop_count++;
565608
header_length += PushHash(header + header_length, property_id);
566609
header_length += PushUint8(header + header_length, ScriptPropertyType::FLOAT);
567610
}
568-
else if (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsBool(instance, component_id, property_id, &outbool))
611+
else if (IsPropertyBool(instance, component_id, property_id))
569612
{
570613
dmLogInfo(" Script property %s BOOL", dmHashReverseSafe64(property_id));
571614
words_count += 1;
572615
actual_prop_count++;
573616
header_length += PushHash(header + header_length, property_id);
574617
header_length += PushUint8(header + header_length, ScriptPropertyType::BOOLEAN);
575618
}
576-
else if (dmGameObject::PROPERTY_RESULT_OK == dmGameObject::GetPropertyAsHash(instance, component_id, property_id, &outhash))
619+
else if (IsPropertyHash(instance, component_id, property_id))
577620
{
578621
dmLogInfo(" Script property %s HASH", dmHashReverseSafe64(property_id));
579622
words_count += 2;
@@ -1066,7 +1109,7 @@ static void Fusion_OnSubObjectCreated(FusionCore::ObjectChild* child)
10661109

10671110
static void Fusion_OnObjectDestroyed(const FusionCore::ObjectRoot* object, const FusionCore::DestroyModes mode)
10681111
{
1069-
dmLogInfo("Fusion_OnObjectDestroyed owner: %d local player: %d", object->GetOwner(), g_Ctx->m_FusionClient->LocalPlayerId());
1112+
dmLogInfo("Fusion_OnObjectDestroyed local player: %d", g_Ctx->m_FusionClient->LocalPlayerId());
10701113

10711114
if (mode == FusionCore::DestroyModes::Local)
10721115
{
@@ -1136,14 +1179,14 @@ static void Fusion_OnObjectOwnerAssigned(FusionCore::ObjectRoot* object)
11361179
lua_newtable(L);
11371180
dmScript::PushHash(L, fusion_object->m_Id);
11381181
lua_setfield(L, -2, "id");
1139-
lua_pushinteger(L, object->GetOwner());
1182+
lua_pushinteger(L, g_Ctx->m_FusionClient->GetOwner(object));
11401183
lua_setfield(L, -2, "owner");
11411184
CallListener(L, 3, 0);
11421185
}
11431186

11441187
FusionMessages::OnObjectOwnerAssigned msg;
11451188
msg.m_Id = fusion_object->m_Id;
1146-
msg.m_Owner = object->GetOwner();
1189+
msg.m_Owner = g_Ctx->m_FusionClient->GetOwner(object);
11471190
dmGameObject::Result result = PostDDF(fusion_object->m_Id, &msg);
11481191
}
11491192
static void Fusion_OnObjectOwnerChanged(FusionCore::ObjectRoot* object)
@@ -1164,14 +1207,14 @@ static void Fusion_OnObjectOwnerChanged(FusionCore::ObjectRoot* object)
11641207
lua_newtable(L);
11651208
dmScript::PushHash(L, fusion_object->m_Id);
11661209
lua_setfield(L, -2, "id");
1167-
lua_pushinteger(L, object->GetOwner());
1210+
lua_pushinteger(L, g_Ctx->m_FusionClient->GetOwner(object));
11681211
lua_setfield(L, -2, "owner");
11691212
CallListener(L, 3, 0);
11701213
}
11711214

11721215
FusionMessages::OnObjectOwnerChanged msg;
11731216
msg.m_Id = fusion_object->m_Id;
1174-
msg.m_Owner = object->GetOwner();
1217+
msg.m_Owner = g_Ctx->m_FusionClient->GetOwner(object);
11751218
dmGameObject::Result result = PostDDF(fusion_object->m_Id, &msg);
11761219
}
11771220
static void Fusion_OnPredictionOverride(FusionCore::ObjectRoot* object)
@@ -2349,6 +2392,7 @@ static int SendRpc(lua_State* L)
23492392

23502393
DM_LUA_STACK_CHECK(L, 1);
23512394

2395+
dmhash_t event = dmScript::CheckHashOrString(L, 3);
23522396
FusionCore::PlayerId target_player_id = (FusionCore::PlayerId)luaL_checknumber(L, 1);
23532397

23542398
FusionCore::ObjectId target_object_id;
@@ -2357,9 +2401,15 @@ static int SendRpc(lua_State* L)
23572401
dmhash_t target_id = dmScript::CheckHashOrString(L, 2);
23582402
FusionCore::ObjectRoot* target_object = GetFusionObjectFromEngineId(target_id);
23592403
target_object_id = target_object->Id;
2404+
2405+
// Workaround: SDK server doesn't resolve TARGET_OWNER for MasterClient-owned objects.
2406+
if ((FusionCore::ObjectOwnerPlayerId == target_player_id)
2407+
&& (FusionCore::ObjectOwnerModes::MasterClient == target_object->GetOwnerMode()))
2408+
{
2409+
target_player_id = FusionCore::MasterClientPlayerId;
2410+
}
23602411
}
23612412

2362-
dmhash_t event = dmScript::CheckHashOrString(L, 3);
23632413

23642414
// serialize data
23652415
const uint32_t MAX_DATA_SIZE = 2048;

0 commit comments

Comments
 (0)