inline ComponentType* GetComponentOfBaseType() const 
 { 
   VisBaseEntity_cl* pEntity = GetEntity();
   if (pEntity == NULL)
     return NULL;
   return pEntity->Components().GetComponentOfBaseType<ComponentType>();
 }
Esempio n. 2
0
void VCameraHandling::DeactivateAllCameras()
{
  // Deactivate all orbit and path cameras.
  const unsigned int uiNumEntities = VisBaseEntity_cl::ElementManagerGetSize();

  for (unsigned int uiElementIndex = 0; uiElementIndex < uiNumEntities; uiElementIndex++)
  {
    VisBaseEntity_cl* pEntity = VisBaseEntity_cl::ElementManagerGet(uiElementIndex);
    if (pEntity == NULL)
      continue;

    VFreeCamera* pFreeCamera = vdynamic_cast<VFreeCamera*>(pEntity);
    VOrbitCamera* pOrbitCamera = pEntity->Components().GetComponentOfBaseType<VOrbitCamera>();
    PathCameraEntity* pPathCamera = vdynamic_cast<PathCameraEntity*>(pEntity);

    if (pFreeCamera != NULL)
      pFreeCamera->SetThinkFunctionStatus(FALSE);

    if (pOrbitCamera != NULL)
      pOrbitCamera->SetEnabled(false);

    if (pPathCamera != NULL)
      pPathCamera->Stop();
  }
}
Esempio n. 3
0
void RPG_GameManager::OnAfterSceneLoaded()
{
  RPG_RendererUtil::StoreViewParams(m_storedViewParams);

  // Set up game view params
  RPG_ViewParams viewParams = m_storedViewParams;
  {
    viewParams.m_projectionType = VIS_PROJECTIONTYPE_PERSPECTIVE;
    viewParams.m_nearClip = 50.f;
    viewParams.m_farClip = 2500.f;
    viewParams.m_fovX = 0.f;
    viewParams.m_fovY = 50.f;
  }

  RPG_RendererUtil::LoadViewParams(viewParams);

  // Local player
  VisBaseEntity_cl* playerEntity = SpawnPlayer("Prefabs\\Demo_Player_Hero.vprefab");

  if(playerEntity)
  {
    RPG_PlayerControllerComponent *const playerController = static_cast<RPG_PlayerControllerComponent*>
      (playerEntity->Components().GetComponentOfBaseType(V_RUNTIME_CLASS(RPG_PlayerControllerComponent)));

    VASSERT(playerController);
    if(playerController)
    {
      RPG_PlayerUI::s_instance.SetController(playerController);
    }
  }
}
Esempio n. 4
0
VisBaseEntity_cl* MyGameManager::SpawnPlayer(const VString& prefabName, hkvVec3 const& position, hkvVec3 const& orientation)
{
	
    VisBaseEntity_cl* playerEntity = CreateEntityFromPrefab(prefabName, position, orientation);
    playerEntity->InitFunction();
    
    if(playerEntity)
    {
        PlayerComponent *const playerController = static_cast<PlayerComponent*>
        (playerEntity->Components().GetComponentOfBaseType(V_RUNTIME_CLASS(PlayerComponent)));
        
        //VASSERT(playerController);
        if(playerController)
        {
            spGUIContext = new VGUIMainContext(NULL);
            // Create a GUI context
            mDialog = new PlayerDialog(playerController);
            mDialog->InitDialog(spGUIContext, NULL, NULL);
            spGUIContext->ShowDialog(mDialog);
            spGUIContext->SetActivate(true);
        }
        
        m_playerEntity = playerEntity->GetWeakReference();
        //Vision::Message.Add(1, "Spawn");
    }
    
    return playerEntity;
}
Esempio n. 5
0
void GameState::InitFunction()
{
  // Add target component
  VisTriggerTargetComponent_cl *pTargetComp = new VisTriggerTargetComponent_cl();
  AddComponent(pTargetComp);

  // Get trigger box entity
  VisBaseEntity_cl *pTriggerBoxEntity = Vision::Game.SearchEntity("TriggerBox");
  VASSERT(pTriggerBoxEntity);

  // Find source component
  VisTriggerSourceComponent_cl* pSourceComp = vstatic_cast<VisTriggerSourceComponent_cl*>(
    pTriggerBoxEntity->Components().GetComponentOfTypeAndName(VisTriggerSourceComponent_cl::GetClassTypeId(), "OnObjectEnter"));
  VASSERT(pSourceComp != NULL);

  // Link source and target component 
  IVisTriggerBaseComponent_cl::OnLink(pSourceComp, pTargetComp);
  
  m_eState = GAME_STATE_RUN;
}
void IVTransitionEventTrigger::MessageFunction( int iID, INT_PTR iParamA, INT_PTR iParamB )
{  
  IVAnimationEventTrigger::MessageFunction(iID, iParamA, iParamB);

#ifdef WIN32
  if (iID == VIS_MSG_EDITOR_GETSTANDARDVALUES)
  {
    // Get bone names
    const char *szKey = (const char *)iParamA;
    if (!strcmp(szKey,"Event"))
    {
      // Check for model and skeleton
      VisBaseEntity_cl* pEntity = (VisBaseEntity_cl *)m_pOwner;
      if (pEntity == NULL)
        return;

      // Check if there is a transition state machine component
      VTransitionStateMachine* tsm = static_cast<VTransitionStateMachine*> (pEntity->Components().GetComponentOfType(V_RUNTIME_CLASS(VTransitionStateMachine)));
      if (tsm == NULL)
        return;
            
      // Fill list with event names (first entry is empty)
      VStrList *pDestList = (VStrList*) iParamB;
      int count = tsm->GetTransitionTable()->GetNumSequenceDefs();
      for (int i = 0; i < count; i++)
      {
        int events = tsm->GetTransitionTable()->GetSequenceDefByIndex(i)->GetNumAnimationEvents();
        for (int e = 0; e < events; e++)
        {
          pDestList->AddUniqueString(tsm->GetTransitionTable()->GetSequenceDefByIndex(i)->GetAnimationEventByIndex(e)->GetEventString());
        }
      }
    }
  }
#endif
}
bool IVTransitionEventTrigger::CommonInit()
{
  // Initialize base component
  if (!IVAnimationEventTrigger::CommonInit())
    return false;

  // Get owner entity
  VisBaseEntity_cl *pEntity = (VisBaseEntity_cl *)m_pOwner;
  if (pEntity == NULL)
    return false;

  // Check if there is a transition state machine component and register this instance as an
  // event listener. If no TSM is present do not return false as the base class might still 
  // have been initialized successfully listening to animation events triggered by the Vision
  // animation system.
  VTransitionStateMachine* tsm = static_cast<VTransitionStateMachine*> (pEntity->Components().GetComponentOfType(V_RUNTIME_CLASS(VTransitionStateMachine)));
  if (tsm != NULL)
  {
    tsm->AddEventListener(this);
    tsm->SetForwardingAnimEvents(true);
  }
  
  return true;
}
Esempio n. 8
0
void VCameraHandling::BuildCameraList()
{
  VAppMenu* pMainMenu = GetParent()->GetAppModule<VAppMenu>();
  if (pMainMenu == NULL)
    return;

  int iActionIndex = 0;
  VAppMenuItems menuItems;
  menuItems.Add(VAppMenuItem("<Switch to Free Camera>", iActionIndex++, 0, false));

#if defined(WIN32) && !defined(_VISION_WINRT)
  // Add option to disable WASD controls.
  m_iWASDActionIndex = iActionIndex++;
  menuItems.Add(VAppMenuItem("<Toggle Free Camera WASD Controls>", m_iWASDActionIndex, 1, true, m_bWASDEnabled));
#endif

  // Find camera objects in the scene.
  // Only store element manager indices in order to be able to detect removed objects.
  unsigned int uiNumOrbitCameras = 0;
  unsigned int uiNumCameraPositions = 0;
  unsigned int uiNumPathCameras = 0;

  const unsigned int uiNumEntities = VisBaseEntity_cl::ElementManagerGetSize();
  for (unsigned int uiElementIndex = 0; uiElementIndex < uiNumEntities; uiElementIndex++)
  {
    VisBaseEntity_cl* pEntity = VisBaseEntity_cl::ElementManagerGet(uiElementIndex);
    if (pEntity == NULL)
      continue;

    // Try to convert the entity to all of the supported camera types.
    VOrbitCamera* pOrbitCamera = pEntity->Components().GetComponentOfBaseType<VOrbitCamera>();
    CameraPositionEntity* pCameraPosition = vdynamic_cast<CameraPositionEntity*>(pEntity);
    PathCameraEntity* pPathCamera = vdynamic_cast<PathCameraEntity*>(pEntity);

    // Menu name data 
    const char* szKey = "";
    const char* szCameraType = "";
    unsigned int uiSortingKey = 0;
    unsigned int uiCameraIndex = 0;

    if (pOrbitCamera != NULL)
    {
      // If the owner entity's key is not set, use the model's file name.
      const char* szKey = pEntity->GetObjectKey();
      if (VStringUtil::IsEmpty(szKey))
        szKey = (pEntity->GetMesh() ? pEntity->GetMesh()->GetFilename() : "");

      szCameraType = "OrbitCamera";
      uiSortingKey = 2;
      uiCameraIndex = uiNumOrbitCameras++;
    }
    else if (pCameraPosition != NULL)
    {
      szKey = pEntity->GetObjectKey();
      szCameraType = "CameraPosition";
      uiSortingKey = 3;
      uiCameraIndex = uiNumCameraPositions++;
    }
    else if (pPathCamera != NULL)
    {
      szKey = pEntity->GetObjectKey();
      szCameraType = "PathCamera";
      uiSortingKey = 4;
      uiCameraIndex = uiNumPathCameras++;
    }
    else
    {
      // If we haven't found a free camera entity yet, try to store this one.
      if (m_spFreeCamera == NULL)
        m_spFreeCamera = vdynamic_cast<VFreeCamera*>(pEntity);

      // No camera found.
      continue;
    }

    // Generate menu name.
    VString sMenuName;
    if (VStringUtil::IsEmpty(szKey))
      sMenuName.Format("%s%02d", szCameraType, uiCameraIndex + 1);
    else
      sMenuName.Format("%s%02d (%s)", szCameraType, uiCameraIndex + 1, szKey);

    menuItems.Add(VAppMenuItem(sMenuName, iActionIndex, uiSortingKey, false));
    m_actionMap.SetAt(iActionIndex++, EntityAccessor(pEntity, sMenuName));
  }

  m_callbacks.Append(pMainMenu->RegisterGroup(m_sMenuGroupName, menuItems, NULL, VAPP_DEFAULT_SORTING_2 + 1));
  RegisterCallbacks();
}