A pet project aimed to explore the Wave Function Collapse (WFC) algorithm applied to a hexagonal grid, dynamic linking application and low-level rendering.
This is a project developed to experiment with several concepts:
- Procedural Generation: Implementation of the Wave Function Collapse algorithm for generating consistent hexagonal maps based on adjacency rules.
- Dynamic Linking: The core generation logic is compiled into a dynamic library (
.dll), which is loaded at runtime by the main application using Windows API (LoadLibrary,GetProcAddress). - Low-Level Rendering: A dedicated debug visualizer built with bgfx to render the generated hex grids.
- Language: C++20
- Build System: CMake
- Libraries:
library/: The core WFC logic, compiled as a dll.mainApp/: A simple host application to dynamically load the generator library with sample arguments.debugVisualiser/: A bgfx-based tool for visualizing the generation results.tinyxml2/: XML parsing for configuration and tile data.
The project uses CMake and expects bgfx, glfw and opengl to be available on the system. The definitions for the libraries should be passed as CMake arguments.
- Configure the project:
cmake . -DBGFX_DIR=path/to/bgfx/root -DBGFX_LIB_DIR=path/to/bgfx/libs -DGLFW_DIR=path/to/glfw/root -DGLFW_LIB_DIR=path/to/glfw/libsMake sure that bgfx has shaderc support enabled. - Build the project. There are several targets available:
WFCHexGeneratorLib: The WFC library.WFCHexGenerator: The library accessor. The default files are config.xml and output.xml.bgfxdebugvisualiser: A bgfx-based tool for visualizing the generation results. Accepts the xml filename argument to visualize a specific map.cleanShadersandcompileShaders: Utility targets for the shader files.
- The algorithm currently supports only adjacency rules. A sample configuration can be found in
config.xml. - While the types of the tiles are configurable, the visualiser supports only the types listed in the sample config. See
debugVisualiser/hexConfigLoader.cppfor color mapping. - For the large maps, the visualiser may not show all the tiles due to the camera being static and no controls or position/angle adjustments. See
debugVisualiser/Simple2DHexGridDrawer.cpp, specificallybx::mtxLookAtfor camera position.
