bool CEnvironment::SetWeatherFX(shared_str name) { if (bWFX) return false; if (name.size()){ EnvsMapIt it = WeatherFXs.find(name); R_ASSERT3 (it!=WeatherFXs.end(),"Invalid weather effect name.",*name); EnvVec* PrevWeather = CurrentWeather; VERIFY(PrevWeather); CurrentWeather = &it->second; CurrentWeatherName = it->first; float rewind_tm = WFX_TRANS_TIME*fTimeFactor; float start_tm = fGameTime+rewind_tm; float current_length; float current_weight; if (Current[0]->exec_time>Current[1]->exec_time){ float x = fGameTime>Current[0]->exec_time?fGameTime-Current[0]->exec_time:(DAY_LENGTH-Current[0]->exec_time)+fGameTime; current_length = (DAY_LENGTH-Current[0]->exec_time)+Current[1]->exec_time; current_weight = x/current_length; }else{ current_length = Current[1]->exec_time-Current[0]->exec_time; current_weight = (fGameTime-Current[0]->exec_time)/current_length; } clamp (current_weight,0.f,1.f); std::sort (CurrentWeather->begin(),CurrentWeather->end(),sort_env_etl_pred); CEnvDescriptor* C0 = CurrentWeather->at(0); CEnvDescriptor* C1 = CurrentWeather->at(1); CEnvDescriptor* CE = CurrentWeather->at(CurrentWeather->size()-2); CEnvDescriptor* CT = CurrentWeather->at(CurrentWeather->size()-1); C0->copy (*Current[0]); C0->exec_time = NormalizeTime(fGameTime-((rewind_tm/(Current[1]->exec_time-fGameTime))*current_length-rewind_tm)); C1->copy (*Current[1]); C1->exec_time = NormalizeTime(start_tm); for (EnvIt t_it=CurrentWeather->begin()+2; t_it!=CurrentWeather->end()-1; t_it++) (*t_it)->exec_time= NormalizeTime(start_tm+(*t_it)->exec_time_loaded); SelectEnv (PrevWeather,WFX_end_desc[0],CE->exec_time); SelectEnv (PrevWeather,WFX_end_desc[1],WFX_end_desc[0]->exec_time+0.5f); CT->copy (*WFX_end_desc[0]);CT->exec_time = NormalizeTime(CE->exec_time+rewind_tm); wfx_time = TimeDiff(fGameTime,CT->exec_time); bWFX = true; // sort wfx envs std::sort (CurrentWeather->begin(),CurrentWeather->end(),sort_env_pred); Current[0] = C0; Current[1] = C1; #ifdef WEATHER_LOGGING Msg ("Starting WFX: '%s' - %3.2f sec",*name,wfx_time); for (EnvIt l_it=CurrentWeather->begin(); l_it!=CurrentWeather->end(); l_it++) Msg (". Env: '%s' Tm: %3.2f",*(*l_it)->sect_name,(*l_it)->exec_time); #endif }else{ #ifndef _EDITOR FATAL ("! Empty weather effect name"); #endif } return true; }
void CEnvironment::SelectEnvs(float gt) { VERIFY(CurrentWeather); if ((Current[0] == Current[1]) && (Current[0] == 0)) { VERIFY(!bWFX); // first or forced start SelectEnvs(CurrentWeather, Current[0], Current[1], gt); } else { bool bSelect = false; if (Current[0]->exec_time > Current[1]->exec_time) { // terminator bSelect = (gt > Current[1]->exec_time) && (gt < Current[0]->exec_time); } else { bSelect = (gt > Current[1]->exec_time); } if (bSelect) { Current[0] = Current[1]; SelectEnv(CurrentWeather, Current[1], gt); #ifdef WEATHER_LOGGING Msg("Weather: '%s' Desc: '%s' Time: %3.2f/%3.2f", CurrentWeatherName.c_str(), Current[1]->m_identifier.c_str(), Current[1]->exec_time, fGameTime); #endif } } }