55 lines
2 KiB
C++
55 lines
2 KiB
C++
#pragma once
|
|
|
|
#include "Particle.h"
|
|
#include <vector>
|
|
#include <memory>
|
|
|
|
// ParticleSystem class header - manages collections of particles
|
|
|
|
class ParticleSystem {
|
|
public:
|
|
ParticleSystem(int width, int height);
|
|
~ParticleSystem() = default;
|
|
|
|
// Disable copying
|
|
ParticleSystem(const ParticleSystem&) = delete;
|
|
ParticleSystem& operator=(const ParticleSystem&) = delete;
|
|
|
|
// Core simulation methods
|
|
void update(float deltaTime);
|
|
void step();
|
|
|
|
// Particle management methods
|
|
void addParticle(const Particle& particle);
|
|
void removeParticle(int x, int y);
|
|
bool isEmpty(int x, int y) const;
|
|
|
|
// Material placement methods
|
|
void placeMaterial(int x, int y, Particle::MaterialType material);
|
|
bool isValidPosition(int x, int y) const;
|
|
|
|
// Getter methods
|
|
int getWidth() const { return width_; }
|
|
int getHeight() const { return height_; }
|
|
int getParticleCount() const { return particleCount_; }
|
|
Particle* getParticle(int x, int y);
|
|
const std::vector<std::unique_ptr<Particle>>& getAllParticles() const { return particles_; }
|
|
|
|
private:
|
|
int width_;
|
|
int height_;
|
|
std::vector<std::vector<std::unique_ptr<Particle>>> grid_;
|
|
std::vector<std::unique_ptr<Particle>> particles_;
|
|
int particleCount_;
|
|
|
|
// Helper methods
|
|
void initializeGrid();
|
|
void updateParticlePosition(Particle& particle, float deltaTime);
|
|
bool tryMoveParticle(Particle& particle, const glm::vec2& direction);
|
|
void applyBoundaryConstraints(Particle& particle);
|
|
bool isAtBoundary(const Particle& particle) const;
|
|
bool wouldCrossBoundary(const Particle& particle, const glm::vec2& direction) const;
|
|
void handleBoundaryCollision(Particle& particle);
|
|
bool isMovingTowardsBoundary(const Particle& particle) const;
|
|
void clampParticleToBoundaries(Particle& particle);
|
|
};
|