const TSharedPtr<FJsonObject>& FJsonValue::AsObject() const { const TSharedPtr<FJsonObject> *Object = &EMPTY_OBJECT; if (!TryGetObject(Object)) { ErrorMessage(TEXT("Object")); } return *Object; }
void ezWorld::ProcessQueuedMessage(const ezInternal::WorldData::MessageQueue::Entry& entry) { if (entry.m_MetaData.m_uiReceiverIsComponent) { ezUInt64 uiReceiverComponent = entry.m_MetaData.m_uiReceiverComponent; ezComponentHandle hComponent(*reinterpret_cast<ezComponentId*>(&uiReceiverComponent)); ezComponent* pReceiverComponent = nullptr; if (TryGetComponent(hComponent, pReceiverComponent)) { pReceiverComponent->SendMessage(*entry.m_pMessage); } else { #if EZ_ENABLED(EZ_COMPILE_FOR_DEBUG) if (entry.m_pMessage->GetDebugMessageRouting()) { ezLog::Warning("ezWorld::ProcessQueuedMessage: Receiver ezComponent for message of type '{0}' does not exist anymore.", entry.m_pMessage->GetId()); } #endif } } else { ezGameObjectHandle hObject(ezGameObjectId(entry.m_MetaData.m_uiReceiverObject)); ezGameObject* pReceiverObject = nullptr; if (TryGetObject(hObject, pReceiverObject)) { if (entry.m_MetaData.m_uiRecursive) { pReceiverObject->SendMessageRecursive(*entry.m_pMessage); } else { pReceiverObject->SendMessage(*entry.m_pMessage); } } else { #if EZ_ENABLED(EZ_COMPILE_FOR_DEBUG) if (entry.m_pMessage->GetDebugMessageRouting()) { ezLog::Warning("ezWorld::ProcessQueuedMessage: Receiver ezGameObject for message of type '{0}' does not exist anymore.", entry.m_pMessage->GetId()); } #endif } } }
ezGameObjectHandle ezWorld::CreateObject(const ezGameObjectDesc& desc, ezGameObject*& out_pObject) { CheckForWriteAccess(); ezGameObject* pParentObject = nullptr; ezGameObject::TransformationData* pParentData = nullptr; ezUInt32 uiParentIndex = 0; ezUInt32 uiHierarchyLevel = 0; bool bDynamic = desc.m_bDynamic; if (TryGetObject(desc.m_hParent, pParentObject)) { pParentData = pParentObject->m_pTransformationData; uiParentIndex = desc.m_hParent.m_InternalId.m_InstanceIndex; uiHierarchyLevel = pParentObject->m_uiHierarchyLevel + 1; // if there is a parent hierarchy level is parent level + 1 EZ_ASSERT_DEV(uiHierarchyLevel < (1 << 12), "Max hierarchy level reached"); bDynamic |= pParentObject->IsDynamic(); } // get storage for the transformation data ezGameObject::TransformationData* pTransformationData = m_Data.CreateTransformationData(bDynamic, uiHierarchyLevel); // get storage for the object itself ezGameObject* pNewObject = m_Data.m_ObjectStorage.Create(); // insert the new object into the id mapping table ezGameObjectId newId = m_Data.m_Objects.Insert(pNewObject); newId.m_WorldIndex = m_uiIndex; // fill out some data pNewObject->m_InternalId = newId; pNewObject->m_Flags = ezObjectFlags::None; pNewObject->m_Flags.AddOrRemove(ezObjectFlags::Dynamic, bDynamic); pNewObject->m_Flags.AddOrRemove(ezObjectFlags::Active, desc.m_bActive); pNewObject->m_sName = desc.m_sName; pNewObject->m_pWorld = this; pNewObject->m_ParentIndex = uiParentIndex; pNewObject->m_Tags = desc.m_Tags; pNewObject->m_uiTeamID = desc.m_uiTeamID; pNewObject->m_uiHierarchyLevel = uiHierarchyLevel; // fill out the transformation data pTransformationData->m_pObject = pNewObject; pTransformationData->m_pParentData = pParentData; pTransformationData->m_localPosition = ezSimdConversion::ToVec3(desc.m_LocalPosition); pTransformationData->m_localRotation = ezSimdConversion::ToQuat(desc.m_LocalRotation); pTransformationData->m_localScaling = ezSimdConversion::ToVec4(desc.m_LocalScaling.GetAsVec4(desc.m_LocalUniformScaling)); pTransformationData->m_globalTransform.SetIdentity(); pTransformationData->m_velocity.SetZero(); pTransformationData->m_localBounds.SetInvalid(); pTransformationData->m_localBounds.m_BoxHalfExtents.SetW(ezSimdFloat::Zero()); pTransformationData->m_globalBounds = pTransformationData->m_localBounds; pTransformationData->m_hSpatialData.Invalidate(); if (pParentData != nullptr) { pTransformationData->UpdateGlobalTransformWithParent(); } else { pTransformationData->UpdateGlobalTransform(); } pTransformationData->m_lastGlobalPosition = pTransformationData->m_globalTransform.m_Position; // link the transformation data to the game object pNewObject->m_pTransformationData = pTransformationData; // fix links LinkToParent(pNewObject); out_pObject = pNewObject; return ezGameObjectHandle(newId); }