void CMonoFlowNode::GetConfiguration(SFlowNodeConfig &config) { CRY_ASSERT(m_pScript); if(mono::object result = m_pScript->CallMethod("GetNodeConfig")) { IMonoObject *pResult = *result; SMonoNodeConfig monoConfig = pResult->Unbox<SMonoNodeConfig>(); config.nFlags |= monoConfig.flags; config.sDescription = _HELP(ToCryString(monoConfig.description)); config.SetCategory(monoConfig.category); m_flags = config.nFlags; m_cloneType = monoConfig.cloneType; // Ports IMonoArray *pInputPorts = *monoConfig.inputs; int numInputs = pInputPorts->GetSize(); auto pInputs = new SInputPortConfig[numInputs + 1]; for(int i = 0; i < numInputs; i++) { IMonoObject *pInputObject = *pInputPorts->GetItem(i); pInputs[i] = pInputObject->Unbox<SMonoInputPortConfig>().Convert(); SAFE_RELEASE(pInputObject); } SInputPortConfig nullInputPortConfig = {0}; pInputs[numInputs] = nullInputPortConfig; config.pInputPorts = pInputs; SAFE_RELEASE(pInputPorts); IMonoArray *pOutputPorts = *monoConfig.outputs; int numOutputs = pOutputPorts->GetSize(); auto pOutputs = new SOutputPortConfig[numOutputs + 1]; for(int i = 0; i < numOutputs; i++) { IMonoObject *pOutputObject = *pOutputPorts->GetItem(i); pOutputs[i] = pOutputObject->Unbox<SMonoOutputPortConfig>().Convert(); SAFE_RELEASE(pOutputObject); } SOutputPortConfig nullOutputPortConfig = {0}; pOutputs[numOutputs] = nullOutputPortConfig; config.pOutputPorts = pOutputs; SAFE_RELEASE(pOutputPorts); SAFE_RELEASE(pResult); } }
void CFlowNode::GetConfiguration(SFlowNodeConfig &config) { CRY_ASSERT(m_pScript); if(IMonoObject *pResult = m_pScript->CallMethod("GetNodeConfig")) { SMonoNodeConfig monoConfig = pResult->Unbox<SMonoNodeConfig>(); config.nFlags |= monoConfig.flags; config.sDescription = _HELP(ToCryString(monoConfig.description)); config.SetCategory(monoConfig.category); m_cloneType = monoConfig.cloneType; // Ports static const int MAX_NODE_PORT_COUNT = 20; SInputPortConfig nullptrConfig = {0}; SOutputPortConfig nullptrOutputConfig = {0}; IMonoArray *pInputPorts = *monoConfig.inputs; auto pInputs = new SInputPortConfig[MAX_NODE_PORT_COUNT]; for(int i = 0; i < pInputPorts->GetSize(); i++) pInputs[i] = pInputPorts->GetItem(i)->Unbox<SMonoInputPortConfig>().Convert(); for(int i = pInputPorts->GetSize(); i < MAX_NODE_PORT_COUNT; i++) pInputs[i] = nullptrConfig; config.pInputPorts = pInputs; SAFE_RELEASE(pInputPorts); // Convert MonoArray type to our custom CScriptArray for easier handling. IMonoArray *pOutputPorts = *monoConfig.outputs; auto pOutputs = new SOutputPortConfig[MAX_NODE_PORT_COUNT]; for(int i = 0; i < pOutputPorts->GetSize(); i++) pOutputs[i] = pOutputPorts->GetItem(i)->Unbox<SMonoOutputPortConfig>().Convert(); for(int i = pOutputPorts->GetSize(); i < MAX_NODE_PORT_COUNT; i++) pOutputs[i] = nullptrOutputConfig; config.pOutputPorts = pOutputs; SAFE_RELEASE(pOutputPorts); } }
mono::object CScriptbind_ScriptTable::CallMethod(IScriptTable *pScriptTable, mono::string methodName, mono::object params) { HSCRIPTFUNCTION scriptFunction = 0; if (pScriptTable && pScriptTable->GetValue(ToCryString(methodName), scriptFunction)) { if(!gEnv->pScriptSystem->BeginCall(scriptFunction)) return nullptr; IMonoArray *pArgs = *params; gEnv->pScriptSystem->PushFuncParam(pScriptTable); for(int i = 0; i < pArgs->GetSize(); i++) { auto anyValue = GetAnyValue(pArgs->GetItem(i)); gEnv->pScriptSystem->PushFuncParamAny(anyValue); } ScriptAnyValue ret; gEnv->pScriptSystem->EndCallAny(ret); auto result = ToMonoObject(ret); gEnv->pScriptSystem->ReleaseFunc(scriptFunction); return result; } return nullptr; }
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; }
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::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; }
bool CScriptbind_Entity::RegisterEntityClass(SEntityRegistrationParams params) { const char *className = ToCryString(params.Name); if(gEnv->pEntitySystem->GetClassRegistry()->FindClass(className)) { MonoWarning("Aborting registration of entity class %s, a class with the same name already exists", className); return false; } int numProperties = 0; SMonoEntityPropertyInfo *pProperties; if(params.Properties != nullptr) { IMonoArray *pPropertyArray = *params.Properties; numProperties = pPropertyArray->GetSize(); pProperties = new SMonoEntityPropertyInfo[numProperties]; for (int iProperty = 0; iProperty < numProperties; iProperty++) { mono::object propertyObject = pPropertyArray->GetItem(iProperty); if(propertyObject == nullptr) continue; auto property = *(SMonoEntityProperty *)mono_object_unbox((MonoObject *)propertyObject); SMonoEntityPropertyInfo propertyInfo; propertyInfo.info.name = ToCryString(property.name); propertyInfo.info.description = ToCryString(property.description); propertyInfo.info.editType = ToCryString(property.editType); propertyInfo.info.type = property.type; propertyInfo.info.limits.min = property.limits.min; propertyInfo.info.limits.max = property.limits.max; propertyInfo.defaultValue = ToCryString(property.defaultValue); pProperties[iProperty] = propertyInfo; } } IEntityClassRegistry::SEntityClassDesc entityClassDesc; entityClassDesc.flags = params.Flags; entityClassDesc.sName = className; entityClassDesc.editorClassInfo.sCategory = ToCryString(params.Category); if(params.EditorHelper != nullptr) entityClassDesc.editorClassInfo.sHelper = ToCryString(params.EditorHelper); if(params.EditorIcon != nullptr) entityClassDesc.editorClassInfo.sIcon = ToCryString(params.EditorIcon); m_monoEntityClasses.push_back(className); bool result = gEnv->pEntitySystem->GetClassRegistry()->RegisterClass(new CEntityClass(entityClassDesc, pProperties, numProperties)); static SMonoEntityCreator creator; static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetIGameObjectSystem()->RegisterExtension(className, &creator, nullptr); return result; }
bool CScriptbind_Entity::RegisterEntityClass(SEntityRegistrationParams params) { const char *className = ToCryString(params.Name); if(gEnv->pEntitySystem->GetClassRegistry()->FindClass(className)) { MonoWarning("Aborting registration of entity class %s, a class with the same name already exists", className); return false; } std::vector<IEntityPropertyHandler::SPropertyInfo> properties; if(params.Folders != nullptr) { IMonoArray *pFolderArray = *params.Folders; int numFolders = pFolderArray->GetSize(); for (int iFolder = 0; iFolder < numFolders; ++iFolder) { IMonoObject *pFolderObject = pFolderArray->GetItem(iFolder); if(!pFolderObject) continue; auto folder = pFolderObject->Unbox<SMonoEntityPropertyFolder>(); if(folder.properties == nullptr) continue; bool bDefaultFolder = !strcmp(ToCryString(folder.name), "Default") && iFolder == 0; if(!bDefaultFolder) // first element contains properties not organized into folders { IEntityPropertyHandler::SPropertyInfo folderInfo; folderInfo.name = ToCryString(folder.name); folderInfo.type = IEntityPropertyHandler::FolderBegin; properties.push_back(folderInfo); } IMonoArray *pPropertyArray = *folder.properties; for(int iProperty = 0; iProperty < pPropertyArray->GetSize(); iProperty++) { IMonoObject *pPropertyObject = pPropertyArray->GetItem(iProperty); if(pPropertyObject == nullptr) continue; auto property = pPropertyObject->Unbox<SMonoEntityProperty>(); IEntityPropertyHandler::SPropertyInfo propertyInfo; propertyInfo.name = ToCryString(property.name); propertyInfo.description = ToCryString(property.description); propertyInfo.editType = ToCryString(property.editType); propertyInfo.type = property.type; propertyInfo.limits.min = property.limits.min; propertyInfo.limits.max = property.limits.max; properties.push_back(propertyInfo); } if(!bDefaultFolder) { IEntityPropertyHandler::SPropertyInfo folderInfo; folderInfo.name = ToCryString(folder.name); folderInfo.type = IEntityPropertyHandler::FolderEnd; properties.push_back(folderInfo); } } } IEntityClassRegistry::SEntityClassDesc entityClassDesc; entityClassDesc.flags = params.Flags; entityClassDesc.sName = className; entityClassDesc.editorClassInfo.sCategory = ToCryString(params.Category); if(params.EditorHelper != nullptr) entityClassDesc.editorClassInfo.sHelper = ToCryString(params.EditorHelper); if(params.EditorIcon != nullptr) entityClassDesc.editorClassInfo.sIcon = ToCryString(params.EditorIcon); m_monoEntityClasses.push_back(className); bool result = gEnv->pEntitySystem->GetClassRegistry()->RegisterClass(new CEntityClass(entityClassDesc, properties)); static SMonoEntityCreator creator; gEnv->pGameFramework->GetIGameObjectSystem()->RegisterExtension(className, &creator, nullptr); return result; }