int CScriptbind_Physics::RayWorldIntersection(Vec3 origin, Vec3 dir, int objFlags, unsigned int flags, int maxHits, mono::object skipEntities, mono::object &hits) { IPhysicalEntity **pSkipEnts = NULL; int numSkipEnts = 0; if(skipEntities) { IMonoArray *pSkipEntities = *skipEntities; numSkipEnts = pSkipEntities->GetSize(); pSkipEnts = new IPhysicalEntity*[numSkipEnts]; for(int i = 0; i < numSkipEnts; i++) { IMonoObject *pItem = *pSkipEntities->GetItem(i); #ifndef RELEASE if(!pItem) g_pScriptSystem->GetCryBraryAssembly()->GetException("CryEngine", "NullPointerException")->Throw(); #endif pSkipEnts[i] = pItem->Unbox<IPhysicalEntity *>(); SAFE_RELEASE(pItem); } pSkipEntities->Release(); } ray_hit *pHits = new ray_hit[maxHits]; int numHits = gEnv->pPhysicalWorld->RayWorldIntersection(origin, dir, objFlags, flags, pHits, maxHits, pSkipEnts, numSkipEnts); SAFE_DELETE_ARRAY(pSkipEnts); if(numHits > 0) { IMonoClass *pRayHitClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("RaycastHit"); IMonoArray *pRayHits = CreateMonoArray(numHits);//, pRayHitClass); for(int i = 0; i < numHits; i++) pRayHits->InsertMonoObject(pRayHitClass->BoxObject(&pHits[i])); hits = pRayHits->GetManagedObject(); pRayHits->Release(); } delete[] pHits; return numHits; }
bool CMonoFlowNode::CreatedNode(TFlowNodeId id, const char *name, TFlowNodeTypeId typeId, IFlowNodePtr pNode) { if(pNode==this) { const char *typeName = gEnv->pFlowSystem->GetTypeName(typeId); IMonoObject *pScript = g_pScriptSystem->InstantiateScript(gEnv->pFlowSystem->GetTypeName(typeId), eScriptFlag_FlowNode); IMonoClass *pNodeInfo = g_pScriptSystem->GetCryBraryAssembly()->GetClass("NodeInitializationParams", "CryEngine.Flowgraph.Native"); IMonoArray *pArgs = CreateMonoArray(1); pArgs->InsertMonoObject(pNodeInfo->BoxObject(&SMonoNodeInfo(this, id, m_pActInfo->pGraph->GetGraphId()))); mono::object result = g_pScriptSystem->InitializeScriptInstance(pScript, pArgs); pArgs->Release(); m_pScript = pScript; if(result) { IMonoObject *pResult = *result; bool bResult = pResult->Unbox<bool>(); SAFE_RELEASE(pResult); return bResult; } CryLogAlways("Failed to create node %s", gEnv->pFlowSystem->GetTypeName(typeId)); return false; } return true; }
mono::object CScriptbind_Entity::QueryAreas(EntityId id, Vec3 vPos, int maxResults, bool forceCalculation) { SAreaManagerResult *pResults = new SAreaManagerResult[maxResults]; int numResults = 0; gEnv->pEntitySystem->GetAreaManager()->QueryAreas(id, vPos, pResults, maxResults, numResults); IMonoArray *pArray = CreateDynamicMonoArray(); IMonoClass *pClass = GetMonoScriptSystem()->GetCryBraryAssembly()->GetClass("AreaQueryResult"); for(int i = 0; i < numResults; i++) { auto result = pResults[i]; if(result.pArea != nullptr) pArray->InsertMonoObject(pClass->BoxObject(&result)); } delete[] pResults; mono::object managedArray = pArray->GetManagedObject(); pArray->Release(false); return managedArray; }
void CMonoActor::FullSerialize(TSerialize ser) { ser.BeginGroup("ManagedActor"); IMonoArray *pArgs = CreateMonoArray(1); pArgs->InsertNativePointer(&ser); m_pScript->GetClass()->InvokeArray(m_pScript->GetManagedObject(), "InternalFullSerialize", pArgs); pArgs->Release(); ser.EndGroup(); }
IMPLEMENT_RMI(CMonoActor, ClScriptRMI) { IMonoClass *pActorClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("Entity"); IMonoArray *pNetworkArgs = CreateMonoArray(3); pNetworkArgs->Insert(ToMonoString(params.methodName.c_str())); pNetworkArgs->InsertMonoObject(params.args); pNetworkArgs->Insert(params.targetId); pActorClass->InvokeArray(nullptr, "OnRemoteInvocation", pNetworkArgs); pNetworkArgs->Release(); return true; }
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; }
void CMonoEntityExtension::RMIParams::SerializeWith(TSerialize ser) { IMonoArray *pArgs; int length; if(args != nullptr) { pArgs = *args; length = pArgs->GetSize(); } else length = 0; ser.Value("length", length); ser.Value("methodName", methodName); ser.Value("targetId", targetId, 'eid'); if(length > 0) { if(ser.IsWriting()) { for(int i = 0; i < length; i++) { IMonoObject *pItem = *pArgs->GetItem(i); pItem->GetAnyValue().SerializeWith(ser); SAFE_RELEASE(pItem); } } else { pArgs = g_pScriptSystem->GetScriptDomain()->CreateArray(length); for(int i = 0; i < length; i++) { MonoAnyValue value; value.SerializeWith(ser); pArgs->InsertAny(value, i); } args = pArgs->GetManagedObject(); } pArgs->Release(); } }
mono::object CScriptbind_Entity::GetEntitiesInBox(AABB bbox, int objTypes) { IPhysicalEntity **pEnts = nullptr; IMonoClass *pEntityIdClass = GetMonoScriptSystem()->GetCryBraryAssembly()->GetClass("EntityId"); int numEnts = gEnv->pPhysicalWorld->GetEntitiesInBox(bbox.min, bbox.max, pEnts, objTypes); IMonoArray *pEntities = CreateDynamicMonoArray(); for(int i = 0; i < numEnts; i++) pEntities->InsertMonoObject(pEntityIdClass->BoxObject(&mono::entityId(gEnv->pPhysicalWorld->GetPhysicalEntityId(pEnts[i])))); auto result = pEntities->GetManagedObject(); pEntities->Release(); return result; }
void CCryScriptInstance::OnReloadComplete() { if(m_scriptId == 0) return; IMonoObject *pScriptManager = g_pScriptSystem->GetScriptManager(); IMonoArray *pArgs = CreateMonoArray(2); pArgs->Insert(m_scriptId); pArgs->Insert(m_flags); if(mono::object result = pScriptManager->GetClass()->InvokeArray(pScriptManager->GetManagedObject(), "GetScriptInstanceById", pArgs)) { SetManagedObject((MonoObject *)result, true); } else MonoWarning("Failed to locate script instance %i after reload!", m_scriptId); pArgs->Release(); }
bool CMonoEntityExtension::Init(IGameObject *pGameObject) { SetGameObject(pGameObject); pGameObject->EnablePhysicsEvent( true, eEPE_OnPostStepImmediate ); if (!GetGameObject()->BindToNetwork()) return false; IEntity *pEntity = GetEntity(); IEntityClass *pEntityClass = pEntity->GetClass(); m_pScript = g_pScriptSystem->InstantiateScript(pEntityClass->GetName(), eScriptFlag_Entity); IMonoClass *pEntityInfoClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("EntityInitializationParams", "CryEngine.Native"); SMonoEntityInfo entityInfo(pEntity); IMonoArray *pArgs = CreateMonoArray(1); pArgs->InsertMonoObject(pEntityInfoClass->BoxObject(&entityInfo)); g_pScriptSystem->InitializeScriptInstance(m_pScript, pArgs); pArgs->Release(); int numProperties; auto pProperties = static_cast<CEntityPropertyHandler *>(pEntityClass->GetPropertyHandler())->GetQueuedProperties(pEntity->GetId(), numProperties); if(pProperties) { for(int i = 0; i < numProperties; i++) { auto queuedProperty = pProperties[i]; SetPropertyValue(queuedProperty.propertyInfo, queuedProperty.value.c_str()); } } m_bInitialized = true; return true; }
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(); }
mono::object CScriptbind_Entity::QueryProximity(AABB box, mono::string className, uint32 nEntityFlags) { SEntityProximityQuery query; if(className != nullptr) query.pEntityClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ToCryString(className)); query.box = box; query.nEntityFlags = nEntityFlags; gEnv->pEntitySystem->QueryProximity(query); IMonoClass *pEntityIdClass = GetMonoScriptSystem()->GetCryBraryAssembly()->GetClass("EntityId"); IMonoArray *pEntities = CreateDynamicMonoArray(); for(int i = 0; i < query.nCount; i++) pEntities->InsertMonoObject(pEntityIdClass->BoxObject(&mono::entityId(query.pEntities[i]->GetId()))); auto result = pEntities->GetManagedObject(); pEntities->Release(); return result; }
mono::object CScriptbind_Entity::GetEntitiesByClasses(mono::object classes) { IMonoArray *pClassArray = *classes; int numClasses = pClassArray->GetSize(); IEntityClass **pClasses = new IEntityClass *[numClasses]; for(int i = 0; i < numClasses; i++) pClasses[i] = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ToCryString((mono::string)pClassArray->GetManagedObject())); IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator(); IMonoClass *pEntityIdClass = GetMonoScriptSystem()->GetCryBraryAssembly()->GetClass("EntityId"); IMonoArray *pEntities = CreateDynamicMonoArray(); pIt->MoveFirst(); while(!pIt->IsEnd()) { if(IEntity *pEntity = pIt->Next()) { IEntityClass *pEntityClass = pEntity->GetClass(); for(int i = 0; i < numClasses; i++) { if(pEntityClass == pClasses[i]) { pEntities->InsertMonoObject(pEntityIdClass->BoxObject(&mono::entityId(pEntity->GetId()))); break; } } } } auto result = pEntities->GetManagedObject(); pEntities->Release(); return result; }
mono::object CScriptbind_Entity::GetEntitiesByClass(mono::string _class) { IEntityClass *pDesiredClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ToCryString(_class)); IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator(); IMonoClass *pEntityIdClass = GetMonoScriptSystem()->GetCryBraryAssembly()->GetClass("EntityId"); IMonoArray *pEntities = CreateDynamicMonoArray(); pIt->MoveFirst(); while(!pIt->IsEnd()) { if(IEntity *pEntity = pIt->Next()) { if(pEntity->GetClass() == pDesiredClass) pEntities->InsertMonoObject(pEntityIdClass->BoxObject(&mono::entityId(pEntity->GetId()))); } } auto result = pEntities->GetManagedObject(); pEntities->Release(); return result; }
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; } }