Skip to content

andrei-c2512/falling-sand-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Video A Falling Sand engine with DirectX
This is an old project(2022) and the quality of code does not represent how I develop today

Table of contents

  1. Set-up
  2. ChilliFramework
  3. Description
  4. Optimisations

Set-up

Make sure you have Visual Studio Community Edition. This project is quite old(2022) and developed on the 2017 edition.

After that, just search for the VS Community file and open it.

ChilliFramework

The project was built on top of the ChilliFramework. A DirectX framework that is lower level than OpenGL and provides direct access to the window pixel buffer. I had to create my own drawing functions which was a way of realising how math is actually very cool.

Description

The idea of a Falling Sand game is not that complicated. You transform a selected area into a matrix of elements of a fixed size, and each element has a set of rules as to how to interact with other matrix elements around it.

For a quick overview as to how these rules work, you can watch this video.

The engine supports a basic variety of elements:

  • Water
  • Stone
  • Fire
  • Wood
  • Acid
  • Steam
  • Smoke
  • Toxic Gas
  • Snow

Optimisations

The real challange does not come from implementing the interaction between elements, but from scaling and optimising.

Just on the GIF shown above, there are 129600 particles that need to be rendered, and 9X the amount that need to be updated off screen.

The use of:

  • separation of concerns
  • const correctness
  • copy vs reference vs move
  • minimalizing the amount of checks I have
  • switching from a class composition approach to inheritence and back to composition
  • creating a chunk system for efficient particle updates
  • avoding std::function overhead

Has made a huge impact on performance.

While the system is not perfect, and can benefit from a variety of optimisations (Assembly/new data arrangements/class relations), it was a challanging and fun project. Hope I will go back to it one day.

About

2D particle simulator, inspired by the Falling Everything Engine of Noita

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published