A 2D Cellular Automata Simulation Engine built using C++ and SDL2. This project serves as a high-performance particle simulation engine, efficiently managing real-time rendering and complex state updates for thousands of active, interacting particles.
This project implements cellular automata rules to simulate the physical behavior of granular materials (like sand) in real-time. The core engine is responsible for grid management, particle state transitions, and continuous frame rendering, serving as a functional Minimum Viable Product (MVP) for physics-based grid simulations.
- Real-Time Physics Engine: Handles the logic and state updates for thousands of active particles seamlessly.
- Fast Rendering Pipeline: Utilizes SDL2 for efficient 2D graphical output directly tied to the simulation grid.
- Automated CI/CD: Integrated a CI/CD pipeline using GitHub Actions to automate builds and testing across different platforms (Linux/Windows), ensuring continuous code stability.
- Language: C++
- Graphics/Windowing: SDL2 (Simple DirectMedia Layer)
- Build System: CMake
- DevOps: GitHub Actions (Cross-platform CI/CD)
While the engine is fully functional at an MVP level, several system-level optimizations are planned to scale the simulation to handle millions of particles efficiently:
- Spatial Partitioning (Chunking): Dividing the simulation grid into active and inactive chunks to prevent the engine from processing empty space, drastically reducing CPU cycles.
- Multi-threading: Transitioning from a single-threaded update loop to a multi-threaded architecture (e.g., using
std::jthreador thread pools) to process independent grid chunks in parallel. - SIMD Instructions: Exploring vectorization for particle state updates to maximize hardware efficiency.
- CMake (3.25+)
- C++ Compiler (GCC, Clang, or MSVC)
- SDL2 Library (development headers)
- vcpkg for dependency management (SDL2, fmt)
git clone https://github.com/makifcevik/sdl2_sand_simulation.git
cd sdl2_sand_simulation
# Configure the project (replace with your actual vcpkg path)
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE="C:/PATH_TO_vcpkg/scripts/buildsystems/vcpkg.cmake"
# Compile the project
cmake --build build --config ReleaseAfter building, you can run the executable generated in the build directory:
# On Linux
./build/Simulation
# On Windows
.\build\app\Release\Simulation.exe- Use left click to place sand.
- Use right click to erase sand.
- Scroll up or down to adjust the brush size.
Distributed under the MIT License.