void CMonoActor::FullSerialize(TSerialize ser) { ser.BeginGroup("ManagedActor"); IMonoArray *pArgs = CreateMonoArray(1); pArgs->InsertNativePointer(&ser); m_pScript->GetClass()->InvokeArray(m_pScript, "InternalFullSerialize", pArgs); ser.EndGroup(); }
mono::object CScriptbind_Entity::GetEntityLinks(IEntity *pEntity) { // the first link IEntityLink *pLink = pEntity->GetEntityLinks(); IMonoArray *pDynArray = CreateDynamicMonoArray(); while(pLink != nullptr) { pDynArray->InsertNativePointer(pLink); pLink = pLink->next; } return pDynArray->GetManagedObject(); }
mono::object CScriptbind_Physics::SimulateExplosion(pe_explosion explosion) { gEnv->pPhysicalWorld->SimulateExplosion(&explosion); if(explosion.nAffectedEnts > 0) { IMonoArray *pAffectedEnts = CreateMonoArray(explosion.nAffectedEnts); for(int i = 0; i < explosion.nAffectedEnts; i++) pAffectedEnts->InsertNativePointer(explosion.pAffectedEnts[i]); pAffectedEnts->Release(); return pAffectedEnts->GetManagedObject(); } return NULL; }
ICryScriptInstance *CScriptSystem::InstantiateScript(const char *scriptName, EMonoScriptFlags scriptFlags, IMonoArray *pConstructorParameters, bool throwOnFail) { FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SCRIPT, gEnv->bProfilerEnabled); auto *pInstance = new CCryScriptInstance(scriptFlags); IMonoArray *pScriptCreationArgs = CreateMonoArray(5); pScriptCreationArgs->Insert(scriptName); pScriptCreationArgs->Insert(scriptFlags); pScriptCreationArgs->InsertNativePointer(pInstance); pScriptCreationArgs->InsertMonoObject((pConstructorParameters != nullptr ? pConstructorParameters->GetManagedObject() : nullptr)); pScriptCreationArgs->Insert(throwOnFail); auto result = m_pScriptManager->GetClass()->GetMethod("CreateScriptInstance", 5)->InvokeArray(m_pScriptManager->GetManagedObject(), pScriptCreationArgs); SAFE_RELEASE(pScriptCreationArgs); if(!result) return nullptr; pInstance->SetManagedObject((MonoObject *)result, true); if(scriptFlags & eScriptFlag_GameRules) { IMonoClass *pGameRulesInitParamsClass = m_pCryBraryAssembly->GetClass("GameRulesInitializationParams"); IMonoArray *pArgs = CreateMonoArray(1); SGameRulesInitializationParams params; pArgs->InsertMonoObject(pGameRulesInitParamsClass->BoxObject(¶ms)); InitializeScriptInstance(pInstance, pArgs); SAFE_RELEASE(pArgs); } for each(auto listener in m_listeners) listener->OnScriptInstanceCreated(scriptName, scriptFlags, pInstance); return pInstance; }
void CMonoEntityExtension::FullSerialize(TSerialize ser) { IEntity *pEntity = GetEntity(); ser.BeginGroup("Properties"); auto pPropertyHandler = static_cast<CEntityPropertyHandler *>(pEntity->GetClass()->GetPropertyHandler()); for(int i = 0; i < pPropertyHandler->GetPropertyCount(); i++) { if(ser.IsWriting()) { IEntityPropertyHandler::SPropertyInfo propertyInfo; pPropertyHandler->GetPropertyInfo(i, propertyInfo); ser.Value(propertyInfo.name, pPropertyHandler->GetProperty(pEntity, i)); } else { IEntityPropertyHandler::SPropertyInfo propertyInfo; pPropertyHandler->GetPropertyInfo(i, propertyInfo); char *propertyValue = nullptr; ser.ValueChar(propertyInfo.name, propertyValue, 0); pPropertyHandler->SetProperty(pEntity, i, propertyValue); } } ser.EndGroup(); ser.BeginGroup("ManagedEntity"); IMonoArray *pArgs = CreateMonoArray(1); pArgs->InsertNativePointer(&ser); m_pScript->GetClass()->InvokeArray(m_pScript->GetManagedObject(), "InternalFullSerialize", pArgs); pArgs->Release(); ser.EndGroup(); }
bool CMonoActor::NetSerialize( TSerialize ser, EEntityAspects aspect, uint8 profile, int pflags ) { if (aspect == eEA_Physics) { pe_type type = PE_NONE; switch (profile) { case eAP_NotPhysicalized: type = PE_NONE; break; case eAP_Spectator: type = PE_LIVING; break; case eAP_Alive: type = PE_LIVING; break; case eAP_Sleep: type = PE_ARTICULATED; break; case eAP_Frozen: type = PE_RIGID; break; case eAP_Ragdoll: type = PE_ARTICULATED; break; case eAP_Linked: //if actor is attached to a vehicle - don't serialize actor physics additionally return true; break; default: return false; } // TODO: remove this when craig fixes it in the network system if (profile==eAP_Spectator) { int x=0; ser.Value("unused", x, 'skip'); } else if (profile==eAP_Sleep) { int x=0; ser.Value("unused1", x, 'skip'); ser.Value("unused2", x, 'skip'); } if (type == PE_NONE) return true; IEntityPhysicalProxy * pEPP = (IEntityPhysicalProxy *) GetEntity()->GetProxy(ENTITY_PROXY_PHYSICS); if (ser.IsWriting()) { if (!pEPP || !pEPP->GetPhysicalEntity() || pEPP->GetPhysicalEntity()->GetType() != type) { gEnv->pPhysicalWorld->SerializeGarbageTypedSnapshot( ser, type, 0 ); return true; } } else if (!pEPP) { return false; } // PLAYERPREDICTION if(type!=PE_LIVING) { pEPP->SerializeTyped( ser, type, pflags ); } // ~PLAYERPREDICTION } ser.BeginGroup("ManagedActor"); IMonoArray *pArgs = CreateMonoArray(4); pArgs->InsertNativePointer(&ser); pArgs->Insert(aspect); pArgs->Insert(profile); pArgs->Insert(pflags); m_pScript->GetClass()->InvokeArray(m_pScript, "InternalNetSerialize", pArgs); ser.EndGroup(); return true; }
void CMonoFlowNode::ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo) { m_pActInfo = pActInfo; if(m_pHookedGraph && m_pScript != nullptr) { m_pHookedGraph->UnregisterHook(this); m_pHookedGraph = nullptr; } switch(event) { case eFE_Activate: { IFlowNodeData *pNodeData = pActInfo->pGraph->GetNodeData(pActInfo->myID); if(!pNodeData) return; int numInputPorts = pNodeData->GetNumInputPorts(); if(m_flags & EFLN_TARGET_ENTITY) numInputPorts--; // last input is the entity port. for(int i = 0; i < numInputPorts; i++) { if(IsPortActive(i)) { switch(GetPortType(pActInfo, i)) { case eFDT_Void: m_pScript->CallMethod("OnPortActivated", i); break; case eFDT_Int: m_pScript->CallMethod("OnPortActivated", i, CFlowBaseNodeInternal::GetPortInt(pActInfo, i)); break; case eFDT_Float: m_pScript->CallMethod("OnPortActivated", i, CFlowBaseNodeInternal::GetPortFloat(pActInfo, i)); break; case eFDT_EntityId: m_pScript->CallMethod("OnPortActivated", i, CFlowBaseNodeInternal::GetPortEntityId(pActInfo, i)); break; case eFDT_Vec3: m_pScript->CallMethod("OnPortActivated", i, CFlowBaseNodeInternal::GetPortVec3(pActInfo, i)); break; case eFDT_String: m_pScript->CallMethod("OnPortActivated", i, CFlowBaseNodeInternal::GetPortString(pActInfo, i)); break; case eFDT_Bool: m_pScript->CallMethod("OnPortActivated", i, CFlowBaseNodeInternal::GetPortBool(pActInfo, i)); break; default: break; } } } } break; case eFE_Initialize: m_pScript->CallMethod("OnInit"); break; case eFE_SetEntityId: { if(pActInfo->pEntity) { IMonoArray *pParams = CreateMonoArray(2); pParams->InsertNativePointer(pActInfo->pEntity); pParams->Insert(pActInfo->pEntity->GetId()); m_pScript->GetClass()->GetMethod("InternalSetTargetEntity", 2)->InvokeArray(m_pScript->GetManagedObject(), pParams); pParams->Release(); } } break; case eFE_Update: m_pScript->CallMethod("OnNodeUpdate"); break; } }