void VRendererNodeCommon::UpdateTimeOfDay()
{
  // Update the active sky.
  IVSky* pSky = m_spSky;
  if (pSky == NULL)
  {
    pSky = Vision::World.GetActiveSky();
  }
  if (pSky != NULL)
  {
    pSky->Tick(0);
  }

  // Update Time Of Day handler.
  IVTimeOfDay* pTimeOfDayInterface = Vision::Renderer.GetTimeOfDayHandler();
  if (pTimeOfDayInterface != NULL)
  {
    VASSERT_MSG(pTimeOfDayInterface->IsOfType(V_RUNTIME_CLASS(VTimeOfDay)),
      "Incompatible time of day handler installed - has to be VTimeOfDay or a subclass of it!");
    VTimeOfDay* pTimeOfDay = vstatic_cast<VTimeOfDay*>(pTimeOfDayInterface);
    pTimeOfDay->UpdateFogParameters();

    VColorRef vAmbientColor = pTimeOfDay->GetAmbientColor();
    Vision::Renderer.SetGlobalAmbientColor(vAmbientColor.ToFloat().getAsVec4(1.0f));
  }
  else
  {
    // Set the default global ambient color.
    Vision::Renderer.SetGlobalAmbientColor(Vision::Renderer.GetDefaultGlobalAmbientColor());
  }
}
Ejemplo n.º 2
0
// Game loop that updates the scene
void VisionApp_cl::OnUpdateScene()
{
  VISION_PROFILE_FUNCTION(VIS_PROFILE_GAMELOOP);

  IVisSceneManager_cl *pSceneManager = Vision::GetSceneManager();
  VASSERT(pSceneManager);

  // Check whether we should use async physics
  IVisPhysicsModule_cl *pPhysicsModule = Vision::GetApplication()->GetPhysicsModule();
  bool bAsyncPhysics;
  if (pPhysicsModule != NULL && pPhysicsModule->GetUseAsynchronousPhysics())
    bAsyncPhysics = true;
  else
    bAsyncPhysics = false; 

  //Timer is not longer updated here, because it needs to be updated right after the frame flip
  float fElapsedTime = Vision::GetTimer()->GetTimeDifference();

  // Advance the scene update counter
  Vision::Game.SetUpdateSceneCount( Vision::Game.GetUpdateSceneCount() + 1 );

  Vision::Callbacks.OnUpdateSceneBegin.TriggerCallbacks();


  //Send any queued messages before we remove entities
  Vision::Game.ProcessMessageQueue();

  // Delete "dead" entities from previous frame
  {
    VISION_PROFILE_FUNCTION( VIS_PROFILE_GAMELOOP_UPDATELOOP );
    Vision::Game.FreeRemovedEntities();
  }

  // Run the pre-physics loop: statistics, prethink, events & animations
  if ( Vision::Editor.IsPlaying() )
    RunPreThink(fElapsedTime);

  //Process animation messages after processing animations
  Vision::Game.ProcessMessageQueue();

  // Run the physics simulation (if physics simulation is set to synchronous)
  if ( Vision::Editor.IsPlaying() && !bAsyncPhysics)
  {
    RunPhysics(fElapsedTime);
    FetchPhysicsResults();
  }

  // Run the post-physics loop: posthink
  if ( Vision::Editor.IsPlaying() )
    RunThink(fElapsedTime);

  // for the editor, we call the EditorThinkFunction function in every mode for every entity:
  if (Vision::Editor.IsInEditor())
  {
    const int iCount = VisBaseEntity_cl::ElementManagerGetSize();
    for (int i=0;i<iCount;i++)
    {
      VisBaseEntity_cl *pEntity = VisBaseEntity_cl::ElementManagerGet(i);
      if (pEntity)
        pEntity->EditorThinkFunction();
    }
  }

  // handle the lightsources (e.g. color animation)
  if (Vision::Editor.IsAnimatingOrPlaying())
    VisLightSource_cl::HandleAllLightSources(fElapsedTime);

  // update the core engine and module system
  RunUpdateLoop();
  Vision::Game.ResetUpdatedEntitiesList();

  // Kick off asynchronous physics simulation
  if ( Vision::Editor.IsPlaying() && bAsyncPhysics )
  {
    RunPhysics(fElapsedTime);
  }

  // Handle portal/visibility zone transitions
  VisObject3DVisData_cl::HandleAllNodeTransitions();

  //Handle render contexts
  VisRenderContext_cl::HandleAllRenderContexts(fElapsedTime);

  //Animate textures (in animate mode)
  VisTextureAnimInstance_cl::HandleAllAnims(Vision::Editor.IsAnimatingOrPlaying() ? fElapsedTime : 0.f);

  // scroll sky only when animating scene
  IVSky *pSky = Vision::World.GetActiveSky();
  if (pSky != NULL && Vision::Editor.IsAnimatingOrPlaying())
    pSky->Tick(fElapsedTime);

  Vision::Callbacks.OnUpdateSceneFinished.TriggerCallbacks();
}