IGameObject* DoSpawnGameObject( const GameObjectSpawnParams& params ) { IGameObject* pGameObject = 0; EGameObject type = params.type; if (type < EGO_COUNT) { std::string name = m_GlobalParameters.go[type].base_name; char buff[16]; _snprintf_s(buff, sizeof(buff), _TRUNCATE, "%d",++(m_NextGameObjectNumber[type])); name += buff; IObject* pObj = IObjectUtils::CreateObjectAndEntity( "GameObject", name.c_str() ); IObjectUtils::GetObject( &pGameObject, pObj->GetObjectId() ); AUVec3f pos = (params.spawnPosition.IsInfinite()) ? GetSpawnPosition(type) : params.spawnPosition; pGameObject->Init(type, pos); m_GameObjects[type].insert(pGameObject); } // Notify any listeners that object was created for (size_t i=0; i<m_Listeners.size(); ++i) { m_Listeners[i]->OnGameObjectCreated(pGameObject); } return pGameObject; }
virtual void UpdateBehavior( float timeDelta ) { IGameObject* pGameObject = 0; IObjectUtils::GetObject( &pGameObject, m_pBBCommon->enemy_collision_objectid ); m_pBBCommon->time_to_next_attack -= timeDelta; if ( m_pBBCommon->time_to_next_attack <= 0.0f ) { m_pBBCommon->time_to_next_attack += m_pGameObjectParams->attack_speed; if (pGameObject && pGameObject->GetBehavior()) { float enemyHealth = pGameObject->GetBehavior()->ReceiveDamage( m_pGameObjectParams->attack_damage ); if ( enemyHealth <= 0.0f && pGameObject->GetGameObjectType() == EGO_RBC ) { ConsumeRBC(); pGameObject = 0; } } } if (!pGameObject || pGameObject->GetGameTeam() == EGT_INFECTION) { m_pBBCommon->enemy_collision_objectid.SetInvalid(); } }
void ApplyTeamRepulsionFields( IGameObject* pGameObject, AUVec3f& desiredPosition, float frameDelta ) { const AUVec3f& refPos = pGameObject->GetEntity()->GetPosition(); const float refDist = pGameObject->GetCollisionRadius(); const float forceStartMultiplier = 1.5f; TGameObjects& data = m_Objects[pGameObject->GetGameTeam()]; TGameObjects::iterator it = data.begin(); TGameObjects::iterator itEnd = data.end(); while (it != itEnd) { IGameObject* pTeamObject = *it; if (pTeamObject != pGameObject) { const AUVec3f& teamObjectPos = pTeamObject->GetEntity()->GetPosition(); const float minAllowedDist = refDist + pTeamObject->GetCollisionRadius(); const float distSqr = (refPos - teamObjectPos).MagnitudeSqr(); const float forceStart = minAllowedDist * forceStartMultiplier; if ( distSqr < forceStart * forceStart ) { float repulsionMagnitude = (forceStart - sqrt(distSqr)) / ( forceStart * ( 1.0f - 1.0f / forceStartMultiplier ) ); AUVec3f dir = (refPos - teamObjectPos).GetNormalised(); desiredPosition += dir * pGameObject->GetMaxSpeed() * frameDelta * repulsionMagnitude; } } ++it; } }
void CModelExporter::Export(const char* pszFileName) { m_serializer.Reset(); size_t uTotalRootNodeCnt = m_pIGameScene->GetTopLevelNodeCount(); std::vector<IGameNode*> meshNodeVector; for(size_t x = 0; x < uTotalRootNodeCnt; x++) { IGameNode* pNode = m_pIGameScene->GetTopLevelNode(x); IGameObject* pObject = pNode->GetIGameObject(); IGameObject::ObjectTypes gameType = pObject->GetIGameType(); if(gameType == IGameObject::IGAME_MESH) { meshNodeVector.push_back(pNode); } } int uMeshNodeCount = meshNodeVector.size(); m_serializer << uMeshNodeCount; for(auto pNode : meshNodeVector) { ExportMesh(pNode); } m_serializer.Deserialize(pszFileName); }
IGameObject* gkGameObjectSystem::CreateLightGameObject( CRapidXmlParseNode* node ) { if (node) { // attribute ColorF color(1,1,1,1); float radius = 1; bool fakeshadow = false; bool globalShadow = false; // transform Vec3 trans(0,0,0); Quat rot(1,0,0,0); Vec3 scale(1,1,1); node->GetAttribute(_T("Color"), color); node->GetAttribute(_T("Radius"), radius); node->GetAttribute(_T("FakeShadow"), fakeshadow); node->GetAttribute(_T("GloabalShadow"), globalShadow); node->GetTranslation(trans); node->GetOrientation(rot); node->GetScale(scale); IGameObject* go = CreateLightGameObject(node->GetAttribute(_T("Name")), trans, radius, color, fakeshadow); IGameObjectLightLayer* llayer = (IGameObjectLightLayer*)(go->getGameObjectLayer( eGL_LightLayer )); llayer->setGlobalShadow( globalShadow ); return go; } return NULL; }
void CheckForCollisions( IGameObject* pGameObject, AUVec3f& desiredPosition, float frameDelta ) { const AUVec3f& refPos = pGameObject->GetEntity()->GetPosition(); const float refDist = pGameObject->GetCollisionRadius(); for (int i=0; i<EGT_COUNT; ++i) { TGameObjects& data = m_Objects[i]; TGameObjects::iterator it = data.begin(); TGameObjects::iterator itEnd = data.end(); while (it != itEnd) { IGameObject* pTestObject = *it; if (pTestObject != pGameObject) { const AUVec3f& testObjectPos = pTestObject->GetEntity()->GetPosition(); float distSqr = (refPos - testObjectPos).MagnitudeSqr(); float minAllowedDist = refDist + pTestObject->GetCollisionRadius(); if ( (distSqr <= minAllowedDist * minAllowedDist) && (pGameObject->GetGameTeam() != pTestObject->GetGameTeam()) ) { // Set desired position to edge of collision radii AUVec3f dir = (refPos - testObjectPos).GetNormalised(); desiredPosition = testObjectPos + dir * minAllowedDist; pTestObject->OnCollision( pGameObject ); pGameObject->OnCollision( pTestObject ); } } ++it; } } }
void MeshExporter::_dumpJoint(IGameNode * node) { IGameObject * obj = node->GetIGameObject(); IGameObject::MaxType T = obj->GetMaxType(); IGameObject::ObjectTypes type = obj->GetIGameType(); const char * name = node->GetName(); switch(type) { case IGameObject::IGAME_BONE: case IGameObject::IGAME_HELPER: { joint * bone = mMeshSource->NewJoint(node->GetName()); int parent = -1; if (node->GetNodeParent()) { parent = _getJointId(node->GetNodeParent()->GetName()); mMeshSource->SetJointLink(parent, mMeshSource->GetJointCount() - 1); } else { INode* pNode = node->GetMaxNode()->GetParentNode(); if (pNode) parent = _getJointId(pNode->GetName()); } IGameControl * pGameControl = node->GetIGameControl(); // base matrix { GMatrix matWorld = node->GetLocalTM(); bone->position = Utility::ToFloat3(matWorld.Translation()); bone->rotation = Utility::ToQuat(matWorld.Rotation()); bone->scale = Utility::ToFloat3(matWorld.Scaling()); /* if (node->GetNodeParent()) { int parentId = _getBoneId(node->GetNodeParent()->GetName()); if (parentId != -1) { xBone * parentBn = GetBone(parentId); bone->position = bone->position - parentBn->position; bone->orientation = parentBn->orientation.Inverse() * bone->orientation; bone->scale = bone->scale / parentBn->scale; } } */ } _dumpAnimation(pGameControl, mMeshSource->GetJointCount() - 1); } break; } }
void Models_Manager::DeleteModel(const std::string& gameModelName) { IGameObject* model = gameModelList[gameModelName]; model->Destroy(); gameModelList.erase(gameModelName); }
CAnimatedCharacterSample::~CAnimatedCharacterSample() { if(m_pAnimatedCharacter != NULL) { IGameObject *pGameObject = GetGameObject(); pGameObject->ReleaseExtension("AnimatedCharacter"); } }
CMonoEntityExtension::~CMonoEntityExtension() { if (m_pAnimatedCharacter) { IGameObject *pGameObject = GetGameObject(); pGameObject->ReleaseExtension("AnimatedCharacter"); } }
CMannequinObject::~CMannequinObject() { if (m_pAnimatedCharacter) { IGameObject* pGameObject = GetGameObject(); pGameObject->ReleaseExtension("AnimatedCharacter"); } }
CBattleEvent* CBattleDust::FindEvent(EntityId id) { IGameObject *pBattleEventGameObject = g_pGame->GetIGameFramework()->GetGameObject(id); if(pBattleEventGameObject) { return static_cast<CBattleEvent*>(pBattleEventGameObject->QueryExtension("BattleEvent")); } return NULL; }
void RegisterEvents( IGameObjectExtension& goExt, IGameObject& gameObject ) { gameObject.UnRegisterExtForEvents( &goExt, NULL, 0 ); const int iScriptEventID = eGFE_ScriptEvent; gameObject.RegisterExtForEvents( &goExt, &iScriptEventID, 1 ); const int iStartSharingScreenEventID = eDoorPanelGameObjectEvent_StartShareScreen; gameObject.RegisterExtForEvents( &goExt, &iStartSharingScreenEventID, 1 ); const int iStopSharingScreenEventID = eDoorPanelGameObjectEvent_StopShareScreen; gameObject.RegisterExtForEvents( &goExt, &iStopSharingScreenEventID, 1 ); }
void RegisterEvents( IGameObjectExtension& goExt, IGameObject& gameObject ) { const int events[] = { eGFE_ScriptEvent, eMineGameObjectEvent_RegisterListener, eMineGameObjectEvent_UnRegisterListener, eMineGameObjectEvent_OnNotifyDestroy}; gameObject.UnRegisterExtForEvents( &goExt, NULL, 0 ); gameObject.RegisterExtForEvents( &goExt, events, (sizeof(events) / sizeof(int)) ); }
void RegisterEvents( IGameObjectExtension& goExt, IGameObject& gameObject ) { const int events[] = { eGFE_ScriptEvent, eMineEventListenerGameObjectEvent_Enabled, eMineEventListenerGameObjectEvent_Disabled, eMineEventListenerGameObjectEvent_Destroyed}; gameObject.UnRegisterExtForEvents( &goExt, NULL, 0 ); gameObject.RegisterExtForEvents( &goExt, events, (sizeof(events) / sizeof(int)) ); }
// Pushes results into m_workingData void DoGetPerceived( const TGameObjects& data, const IGameObject* pPerceiver, const AUVec3f& center, float radius ) const { size_t count = data.size(); for (size_t j=0; j<count; ++j) { IGameObject* pObj = data[j]; float dist = (pObj->GetEntity()->GetPosition() - center).Magnitude(); if ( pObj->GetEntityId() != pPerceiver->GetEntityId() && dist < radius ) { m_workingData.push_back( pObj ); } } }
void CScriptbind_ActorSystem::RemoteInvocation(EntityId entityId, EntityId targetId, mono::string methodName, mono::object args, ERMInvocation target, int channelId) { CRY_ASSERT(entityId != 0); IGameObject *pGameObject = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetGameObject(entityId); CRY_ASSERT(pGameObject); CMonoEntityExtension::RMIParams params(args, ToCryString(methodName), targetId); if(target & eRMI_ToServer) pGameObject->InvokeRMI(CMonoActor::SvScriptRMI(), params, target, channelId); else pGameObject->InvokeRMI(CMonoActor::ClScriptRMI(), params, target, channelId); }
void CScriptbind_Entity::RemoteInvocation(EntityId entityId, EntityId targetId, mono::string methodName, mono::object args, ERMInvocation target, int channelId) { CRY_ASSERT(entityId != 0); IGameObject *pGameObject = gEnv->pGameFramework->GetGameObject(entityId); CRY_ASSERT(pGameObject); CMonoEntityExtension::RMIParams params(*args, ToCryString(methodName), targetId); if(target & eRMI_ToServer) pGameObject->InvokeRMI(CMonoEntityExtension::SvScriptRMI(), params, target, channelId); else pGameObject->InvokeRMI(CMonoEntityExtension::ClScriptRMI(), params, target, channelId); }
float GetStrengthSum( const TGameObjects& objects ) const { float sum = 0; TGameObjects::const_iterator it = objects.begin(); TGameObjects::const_iterator itEnd = objects.end(); while (it != itEnd) { IGameObject* pGameObject = *it; sum += pGameObject->GetThreatRating(); ++it; } return sum; }
virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: IGameFramework* const pGameFramework = gEnv->pGame->GetIGameFramework(); IGameObject* const pGameObject = pGameFramework->GetGameObject(pActInfo->pEntity->GetId()); if(IsPortActive(pActInfo, EIP_Enslave) || IsPortActive(pActInfo, EIP_UnEnslave) ) { IAnimatedCharacter* const pAnimChar = pGameObject ? (IAnimatedCharacter*) pGameObject->QueryExtension("AnimatedCharacter") : NULL; if(pAnimChar && pAnimChar->GetActionController()) { const EntityId slaveChar = GetPortEntityId(pActInfo, EIP_Slave); IGameObject* pSlaveGameObject = pGameFramework->GetGameObject(slaveChar); IAnimatedCharacter* pSlaveAnimChar = pSlaveGameObject ? (IAnimatedCharacter*) pSlaveGameObject->QueryExtension("AnimatedCharacter") : NULL; if(pSlaveAnimChar && pSlaveAnimChar->GetActionController()) { IAnimationDatabaseManager &dbManager = gEnv->pGame->GetIGameFramework()->GetMannequinInterface().GetAnimationDatabaseManager(); uint32 db_crc32 = CCrc32::ComputeLowercase(GetPortString(pActInfo, EIP_DB)); const IAnimationDatabase* db = dbManager .FindDatabase(db_crc32); const string& scopeContextName = GetPortString(pActInfo, EIP_ScopeContext); const string& requestedScopeContext = scopeContextName.empty() ? "SlaveChar" : scopeContextName; const TagID scopeContext = pAnimChar->GetActionController()->GetContext().controllerDef.m_scopeContexts.Find(scopeContextName.c_str()); pAnimChar->GetActionController()->SetSlaveController(*pSlaveAnimChar->GetActionController(), scopeContext, IsPortActive(pActInfo, EIP_Enslave) ? true : false, db); ActivateOutput(pActInfo, EOP_Success, 1 ); } else { CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or Animated character found for the slave"); ActivateOutput(pActInfo, EOP_Fail, 1 ); } } else { CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or AnimatedCharacter found"); ActivateOutput(pActInfo, EOP_Fail, 1 ); } } break; } }
void CSubStructure::onInit(IGameObject& object, IGameWorld& world) { // init all components foreachComponent([](IComponent& component, IGameObject& object){component.init(object);}, std::ref(object)); // need to write the component subobject loop ourselves here, because we need the shared_ptr // build the physic body for(auto& cell : mCells) { auto fixture = physics::Fixture::create(object.getBody(), cell->shape(), 10.f); fixture.setRestitution(0.1); fixture.setFriction(0.5); for(std::size_t i = 0; i < cell->component_count(); ++i) { addChild(cell->getComponent(i)); fixture.addMass(cell->getComponent(i)->weight()); } } // add the armour segments to the object definition for(unsigned i = 0; i < mArmour.size(); ++i) { auto pob = std::make_shared<property::CPropertyObject>("armour" + to_string(i)); addChild(pob); pob->addChild(mArmour[i].armour->getSharedPropertyObject()); pob->addProperty( property::CProperty::create("p1", pob.get(), mArmour[i].p1) ); pob->addProperty( property::CProperty::create("p2", pob.get(), mArmour[i].p2) ); } }
virtual AUVec3f CalculateDesiredPosition( float timeDelta ) { AUVec3f pos = m_pOwner->GetEntity()->GetPosition(); IGameObject* pGameObject = 0; IObjectUtils::GetObject( &pGameObject, m_pBBCommon->enemy_collision_objectid ); if (pGameObject) { AUVec3f targetVec = pGameObject->GetEntity()->GetPosition() - m_pBBCommon->current_position; AUVec3f targetDir = targetVec.GetNormalised(); float dist = std::min( targetVec.Magnitude(), m_pOwner->GetMaxSpeed() * timeDelta ); pos += targetDir * dist; } return pos; }
void Unreal3DExport::ExportNode( IGameNode * child ) { DebugPrint( _T("ExportNode: %s\n"), child->GetName() ); CheckCancel(); ProgressMsg.printf(GetString(IDS_INFO_ENUM_OBJ),NodeIdx,NodeCount,TSTR(child->GetName())); pInt->ProgressUpdate(Progress+((float)NodeIdx/NodeCount*U3D_PROGRESS_ENUM), FALSE, ProgressMsg.data()); ++NodeIdx; if( child->IsGroupOwner() ) { // do nothing } else { IGameObject * obj = child->GetIGameObject(); switch(obj->GetIGameType()) { case IGameObject::IGAME_MESH: { if( !bIgnoreHidden || !child->IsNodeHidden() ) { Nodes.Append(1,&child); } break; } case IGameObject::IGAME_HELPER: { if( !bIgnoreHidden || !child->IsNodeHidden() ) { TrackedNodes.Append(1,&child); } } break; } child->ReleaseIGameObject(); } for( int i=0; i<child->GetChildCount(); ++i ) { IGameNode * n = child->GetNodeChild(i); ExportNode(n); } }
void CPaneHierarchy::RefreshHierarchy() { m_wndTreeHierarchy.DeleteAllItems(); uint32 count = gEnv->pGameObjSystem->getGameObjectCount(); uint32 realcount = 0; uint32 fullcount = 0; for( uint32 i=0; i < count; ++i) { IGameObject* go = gEnv->pGameObjSystem->GetGameObjectById(i); if (go && go->getParent() == NULL && go->getGameObjectSuperClass() != eGOClass_SYSTEM) { //HTREEITEM hItem = m_wndTreeHierarchy.InsertItem( go->getName().c_str() ); RefreshChild(go, NULL); } } }
IGameObject* gkGameObjectSystem::CreateStaticGeoGameObject( CRapidXmlParseNode* node ) { if (node) { // transform Vec3 trans(0,0,0); Quat rot(1,0,0,0); Vec3 scale(1,1,1); node->GetTranslation(trans); node->GetOrientation(rot); node->GetScale(scale); IGameObject* statObj = CreateStaticGeoGameObject(node->GetAttribute(_T("Name")), node->GetAttribute(_T("MeshName")), trans, rot); if (statObj) { IGameObjectRenderLayer* pRenderLayer = statObj->getRenderLayer(); if (pRenderLayer) { gkLogMessage(_T("Load Material")); pRenderLayer->setMaterialName(node->GetAttribute(_T("MaterialName"))); gkLogMessage(_T("Material Loaded")); } statObj->setPosition(trans); statObj->setOrientation(rot); statObj->setScale(scale); #ifdef OS_WIN32 if (node->GetAttribute(_T("Physical")) && !_tcsicmp(node->GetAttribute(_T("Physical")), _T("true"))) { IGameObjectPhysicLayer* pPhysicLayer = gEnv->pPhysics->CreatePhysicLayer(); statObj->setGameObjectLayer(pPhysicLayer); pPhysicLayer->createStatic(); } else if (node->GetAttribute(_T("Physical")) && !_tcsicmp(node->GetAttribute(_T("Physical")), _T("rigidsphere"))) { IGameObjectPhysicLayer* pPhysicLayer = gEnv->pPhysics->CreatePhysicLayer(); statObj->setGameObjectLayer(pPhysicLayer); pPhysicLayer->createDynamic(IGameObjectPhysicLayer::ePDT_Sphere); } #endif } return statObj; } return NULL; }
void CSubStructure::onStep(IGameObject& object, const IGameWorld& world, WorldActionQueue& push_action) { foreachComponent([](IComponent& c, IGameObject& o, const IGameWorld& w, WorldActionQueue& p){ c.step(o, w, p);}, std::ref(object), std::ref(world), std::ref(push_action)); if(mStructurePoints <= 0) { object.remove(); } }
void CLivingEntitySample::Reset( const bool enteringGameMode ) { ResetCharacterModel(); ResetAnimationState(); Physicalize(); IGameObject* pGameObject = GetGameObject(); if ( enteringGameMode ) { pGameObject->EnablePostUpdates( this ); pGameObject->EnablePrePhysicsUpdate( ePPU_Always ); } else { pGameObject->DisablePostUpdates( this ); pGameObject->EnablePrePhysicsUpdate( ePPU_Never ); } }
void DoDestroyGameObject( ObjectId id ) { IObjectFactorySystem* pFactory = PerModuleInterface::g_pSystemTable->pObjectFactorySystem; IObject* pObj = pFactory->GetObject(id); if (pObj) { IGameObject* pGameObject = 0; IObjectUtils::GetObject( &pGameObject, pObj->GetObjectId() ); // Notify any listeners that object is about to be destroyed for (size_t i=0; i<m_Listeners.size(); ++i) { m_Listeners[i]->OnGameObjectAboutToDestroy(pGameObject); } m_GameObjects[pGameObject->GetGameObjectType()].erase(pGameObject); IObjectUtils::DestroyObjectAndEntity( pGameObject->GetEntityId() ); } }
void TrianExporter::ExportNodeInfo( IGameNode * node ) { //If the node is a group owner, do nothing with it. if( !node->IsGroupOwner() ) { //Get the game object. IGameObject * obj = node->GetIGameObject(); //We will only dump the info if it is a IGAME_MESH. if( obj->GetIGameType() == IGameObject::IGAME_MESH ) { //Get the Mesh. IGameMesh * gm = ( IGameMesh * )obj; //If initialization works, dump the mesh. if( gm->InitializeData() ) DumpMesh( gm ); } } }
void CVTOLVehicleManager::SetupMovement(EntityId entityId) { IVehicle* pVehicle = m_pVehicleSystem->GetVehicle(entityId); if(pVehicle) { if (CVehicleMovementBase* pMovement = StaticCast_CVehicleMovementBase(pVehicle->GetMovement())) { pMovement->Reset(); pMovement->SetRemotePilot(true); pMovement->StartDriving(0); } IGameObject* pGameObject = pVehicle->GetGameObject(); pGameObject->SetUpdateSlotEnableCondition(pVehicle, IVehicle::eVUS_Always, eUEC_WithoutAI); pGameObject->SetUpdateSlotEnableCondition(pVehicle, IVehicle::eVUS_EnginePowered, eUEC_WithoutAI); pGameObject->EnableUpdateSlot(pVehicle, IVehicle::eVUS_EnginePowered); pGameObject->EnableUpdateSlot(pVehicle, IVehicle::eVUS_Always); } }