3 #include <BLIB/Cameras/2D/Camera2D.hpp>
4 #include <BLIB/Util/Random.hpp>
15 constexpr
float SpawnRate = 450.f;
16 constexpr
float FastFallSpeed = -340.f;
17 constexpr
float SlowFallSpeed = -100.f;
18 constexpr
float GroundTime = -2.f;
19 constexpr
float HorizontalAccel = 128.f;
20 constexpr
float HorizontalVel = 64.f;
21 constexpr
float StopTime = 4.f;
22 constexpr
float StopSpeed = 1.f / StopTime;
23 constexpr
float RespawnDelay = 2.f;
25 std::size_t deadCount = 0;
38 pos.x = bl::util::Random::get<float>(area.left - 300.f, area.left + area.width + 300.f);
39 pos.y = bl::util::Random::get<float>(area.top - 300.f, area.top + area.height + 300.f);
40 vel.x = bl::util::Random::get<float>(-HorizontalVel, HorizontalVel);
41 vel.y = bl::util::Random::get<float>(-1.f, 1.f);
42 height = bl::util::Random::get<float>(140.f, 200.f);
79 static constexpr
bool ContainsTransparency =
true;
81 static constexpr
bool CreateRenderPipeline =
true;
83 static constexpr std::initializer_list<std::uint32_t> RenderPassIds =
84 bl::pcl::RenderConfigDefaults<Snowflake>::RenderPassIds;
88 bl::pcl::RenderConfigDescriptorList<bl::rc::ds::TexturePoolFactory,
89 bl::rc::ds::Scene2DFactory,
90 bl::pcl::DescriptorSetFactory<Snowflake, GpuSnowflake>>;
92 static constexpr
bool EnableDepthTesting =
true;
93 static constexpr VkPrimitiveTopology Topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
94 static constexpr
const char* VertexShader =
"Resources/Shaders/Particles/snowflake.vert.spv";
95 static constexpr
const char* FragmentShader = bl::rc::Config::ShaderIds::Fragment2DSkinnedLit;
111 : fallVel(fallVel) {}
115 virtual void update(Proxy& proxy,
float dt,
float)
override {
116 for (
Snowflake& flake : proxy.particles()) {
117 if (flake.height > 0.f) {
118 flake.pos += flake.vel * dt;
119 flake.height += fallVel * dt;
120 if (flake.vel.y > 0.f) {
121 flake.vel.x -= HorizontalAccel * dt;
122 if (flake.vel.x < -HorizontalVel) { flake.vel.y = -1.f; }
125 flake.vel.x += HorizontalAccel * dt;
126 if (flake.vel.x > HorizontalVel) { flake.vel.y = 1.f; }
129 if (flake.height < 0.f) flake.height = -0.001f;
131 else { flake.height -= dt; }
146 virtual void update(Proxy& proxy, std::span<Snowflake> particles,
float dt,
float)
override {
149 if (drop.height <= GroundTime) {
151 if (time >= RespawnDelay) { ++deadCount; }
171 virtual void update(Proxy& proxy,
float dt,
float)
override {
172 const std::size_t current = proxy.getManager().getParticleCount();
173 if (current < target) {
174 residual += SpawnRate * dt;
175 if (residual >= 1.f || deadCount > 0) {
176 const std::size_t maxSpawn = target - current;
177 const std::size_t toSpawn =
178 std::min(
static_cast<std::size_t
>(std::floor(residual)) + deadCount, maxSpawn);
179 residual -=
static_cast<float>(toSpawn);
181 bl::cam::Camera2D* cam = observer.getCurrentCamera<bl::cam::Camera2D>();
182 if (!cam) {
return; }
183 const sf::FloatRect area = cam->getVisibleArea();
184 for (std::size_t i = 0; i < toSpawn; ++i) { proxy.emit(area); }
190 bl::rc::RenderTarget& observer;
199 , _type(hard ? (thunder ?
Weather::HardSnowThunder :
Weather::HardSnow) :
201 , targetParticleCount(hard ?
Properties::HardSnowParticleCount() :
203 , fallSpeed(hard ? FastFallSpeed : SlowFallSpeed)
205 , thunder(thunder, hard) {}
209 if (engine) { engine->particleSystem().removeUniqueSystem<
snow::Snowflake>(); }
214 void Snow::start(bl::engine::Engine& e, bl::rc::RenderTarget& renderTarget,
Map& map) {
218 const auto sampler = e.renderer().vulkanState().samplerCache.noFilterBorderClamped();
223 emitter = particles->addEmitter<
snow::TimeEmitter>(renderTarget, targetParticleCount);
226 particles->addToScene(renderTarget.getCurrentScene());
228 particles->getRenderer().getGlobals().textureId = snowTxtr.id();
229 particles->getRenderer().getComponent()->makeSprite(snowTxtr);
230 for (
auto& v : particles->getRenderer().getComponent()->vertexBuffer.vertices()) {
240 bool Snow::stopped()
const {
return particles && particles->getParticleCount() == 0; }
243 if (stopFactor >= 0.f) {
244 stopFactor = std::min(stopFactor + StopSpeed * dt, 1.f);
246 targetParticleCount -
247 static_cast<unsigned int>(
static_cast<float>(targetParticleCount) * stopFactor));
248 if (stopFactor >= 0.8f) {
Core classes and functionality for both the editor and game.
core::map::weather::fog::GlobalShaderInfo GlobalShaderInfo
core::map::weather::snow::Snowflake Snowflake
core::map::weather::snow::GpuSnowflake GpuSnowflake
The primary map class that represents a usable map in the game.
float getMinDepth() const
Returns the maximum depth possible for this map. Maximum is always 0.f. Minimum is negative,...
Parent weather system for maps. Manages active weather.
Wrapper around bl::engine::Configuration. Provides application configuration in variables that may be...
static constexpr std::uint32_t SnowflakePipelineId
static const std::string & SnowFlakeFile()
Snowflake(const sf::FloatRect &area)
GpuSnowflake & operator=(const Snowflake &drop)
bl::pcl::RenderConfigDescriptorList< bl::rc::ds::TexturePoolFactory, bl::rc::ds::Scene2DFactory, bl::pcl::DescriptorSetFactory< Snowflake, GpuSnowflake > > DescriptorSets
virtual void update(Proxy &proxy, float dt, float) override
virtual ~GravityAffector()=default
GravityAffector(float fallVel)
virtual void update(Proxy &proxy, std::span< Snowflake > particles, float dt, float) override
virtual ~TimeSink()=default
virtual void update(Proxy &proxy, float dt, float) override
void setTarget(std::size_t t)
virtual ~TimeEmitter()=default
TimeEmitter(bl::rc::RenderTarget &observer, std::size_t target)
virtual void stop() override
Stops the snow.
virtual Weather::Type type() const override
One of LightSnow, LightSnowThunder, HardSnow, HardSnowThunder.
virtual bool stopped() const override
Returns true when no snow is left after a call to stop()
Snow(bool hard, bool thunder)
Create snowy weather.
virtual void start(bl::engine::Engine &engine, bl::rc::RenderTarget &renderTarget, Map &map) override
Start the snow.
virtual void update(float dt) override
Updates all the flakes and spawns more.
virtual ~Snow()
Destroy the Snow object.
void stop()
Prevents further thunder and fades out current strike if present.