Skip to content

makifcevik/sdl2_sand_simulation

Repository files navigation

2D Cellular Automata Engine (Sand Simulation)

Build Platform C++ Standard Dependencies

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.

Table of Contents

Overview

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.

Key Features

  • 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.

Tech Stack

  • Language: C++
  • Graphics/Windowing: SDL2 (Simple DirectMedia Layer)
  • Build System: CMake
  • DevOps: GitHub Actions (Cross-platform CI/CD)

Roadmap & Future Optimizations

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::jthread or thread pools) to process independent grid chunks in parallel.
  • SIMD Instructions: Exploring vectorization for particle state updates to maximize hardware efficiency.

Getting Started

Prerequisites

  • CMake (3.25+)
  • C++ Compiler (GCC, Clang, or MSVC)
  • SDL2 Library (development headers)
  • vcpkg for dependency management (SDL2, fmt)

Build Instructions

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 Release

Running the Simulation

After building, you can run the executable generated in the build directory:

# On Linux
./build/Simulation

# On Windows
.\build\app\Release\Simulation.exe

How To Play

  • Use left click to place sand.
  • Use right click to erase sand.
  • Scroll up or down to adjust the brush size.

License

Distributed under the MIT License.

About

A high performance 2 dimensional sand simulation engine built with SDL2. This project follows Google C++ Styles.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Generated from makifcevik/cpp_starter