Skip to content

Commit

Permalink
Don't draw offscreen particles
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Nov 11, 2021
1 parent 638e328 commit 566b4cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/object/cloud_particle_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,16 @@ void CloudParticleSystem::draw(DrawingContext& context)
if (!enabled)
return;

const auto& region = Sector::current()->get_active_region();

context.push_transform();

std::unordered_map<SurfacePtr, SurfaceBatch> batches;
for (const auto& particle : particles) {

if(!region.contains(particle->pos))
continue;

if (particle->alpha != 1.f) {
const auto& batch_it = batches.emplace(
particle->texture->clone(),
Expand Down
5 changes: 5 additions & 0 deletions src/object/particlesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <math.h>

#include "supertux/globals.hpp"
#include "supertux/sector.hpp"
#include "util/reader.hpp"
#include "util/reader_mapping.hpp"
#include "util/writer.hpp"
Expand Down Expand Up @@ -81,6 +82,7 @@ ParticleSystem::draw(DrawingContext& context)

float scrollx = context.get_translation().x;
float scrolly = context.get_translation().y;
const auto& region = Sector::current()->get_active_region();

context.push_transform();
context.set_translation(Vector(max_particle_size,max_particle_size));
Expand All @@ -99,6 +101,9 @@ ParticleSystem::draw(DrawingContext& context)
pos.y = fmodf(particle->pos.y - scrolly, virtual_height);
if (pos.y < 0) pos.y += virtual_height;

if(!region.contains(particle->pos))
continue;

//if(pos.x > virtual_width) pos.x -= virtual_width;
//if(pos.y > virtual_height) pos.y -= virtual_height;

Expand Down
5 changes: 4 additions & 1 deletion src/object/particlesystem_interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ ParticleSystem_Interactive::draw(DrawingContext& context)
return;

context.push_transform();

const auto& region = Sector::current()->get_active_region();
std::unordered_map<SurfacePtr, SurfaceBatch> batches;
for (const auto& particle : particles) {
if(!region.contains(particle->pos))
continue;

auto it = batches.find(particle->texture);
if (it == batches.end()) {
const auto& batch_it = batches.emplace(particle->texture,
Expand Down

0 comments on commit 566b4cb

Please sign in to comment.