| 561 | } |
| 562 | |
| 563 | void EnvironmentController::SpawnWeatherParticles(const ScriptInterfaceLevel& level) |
| 564 | { |
| 565 | // Clean up dead particles. |
| 566 | if (Particles.size() > 0) |
| 567 | { |
| 568 | Particles.erase( |
| 569 | std::remove_if( |
| 570 | Particles.begin(), Particles.end(), |
| 571 | [](const WeatherParticle& part) |
| 572 | { |
| 573 | return !part.Enabled; |
| 574 | }), |
| 575 | Particles.end()); |
| 576 | } |
| 577 | |
| 578 | if (level.GetWeatherType() == WeatherType::None || level.GetWeatherStrength() == 0.0f) |
| 579 | return; |
| 580 | |
| 581 | bool clustering = level.GetWeatherClustering(); |
| 582 | |
| 583 | int newParticlesCount = 0; |
| 584 | int density = WEATHER_PARTICLE_SPAWN_DENSITY * level.GetWeatherStrength(); |
| 585 | |
| 586 | // Snow is falling twice as fast and must be spawned accordingly fast. |
| 587 | if (level.GetWeatherType() == WeatherType::Snow) |
| 588 | density *= 2; |
| 589 | |
| 590 | if (density > 0.0f && level.GetWeatherType() != WeatherType::None) |
| 591 | { |
| 592 | while (Particles.size() < WEATHER_PARTICLE_COUNT_MAX) |
| 593 | { |
| 594 | if (newParticlesCount > density) |
| 595 | break; |
| 596 | |
| 597 | newParticlesCount++; |
| 598 | |
| 599 | float dist = 0; |
| 600 | if (level.GetWeatherType() == WeatherType::Snow) |
| 601 | { |
| 602 | dist = WEATHER_SPAWN_DIST_SNOW; |
| 603 | } |
| 604 | else if (level.GetWeatherType() == WeatherType::Rain) |
| 605 | { |
| 606 | dist = WEATHER_SPAWN_DIST_RAIN; |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | dist = WEATHER_SPAWN_DIST_OTHER; |
| 611 | } |
| 612 | |
| 613 | float radius = Random::GenerateInt(0, dist); |
| 614 | short angle = Random::GenerateAngle(); |
| 615 | |
| 616 | auto xPos = Camera.pos.x + ((int)(phd_cos(angle) * radius)); |
| 617 | auto zPos = Camera.pos.z + ((int)(phd_sin(angle) * radius)); |
| 618 | auto yPos = Camera.pos.y - (BLOCK(3) + Random::GenerateInt() & (BLOCK(4) - 1)); |
| 619 | |
| 620 | auto outsideRoom = IsRoomOutside(xPos, yPos, zPos); |
nothing calls this directly
no test coverage detected