Supertiles and Map Generation
Welp, I'm addicted. Before we get started, let me turn on the sun and show what's happened since last time:
I love this. Over the past couple of days, I've been stuck at home with covid and messing around with different iterative map expanding techniques. This is the latest attempt and the one that's really starting to look good.
Before getting here, I went through a node/edge based triangulating map generator, raw perlin noise, a bunch of ideas on rulesets - and now this. As with most things, there's a lot left behind the scenes before I'll actually be able to use it (like adding checkpoints and quest objectives!) - but I feel like it's reached a critical point where I can begin adding functionality rather than looking for something to get started.
What happens here is actually a multi-stage process that was really fun to put together:
First, the infinite map is cut into 128x128 supertiles. As we pan across the map, these tiles are loaded and unloaded as needed so we limit what needs to be pushed to GPU.
When a unit first enters a new supertile, its 3x3 neighborhood is flagged as visited and pushed into a rudimentary wavefunction collapse-based map generator. (If you're interested in wavefunction collapse, there's many posts that go through it way better than I would, I recommend taking a look at e.g. https://github.com/mxgmn/WaveFunctionCollapse or https://robertheaton.com/2018/12/17/wavefunction-collapse-algorithm/)
The map generator pushes some base properties to each tile coordinate, then collapses 200 tiles per frame, updating constraints as it goes.
To ensure we 1. don't break visited parts of the map and 2. can maintain framerate - rather than backtracking as one normally would in wavefunction collapse, this generator does a two-stage retry process in local neighborhoods where constraints fail to resolve - first relaxing some less important constraints and second accepting constraint violations when not resolvable. This can create a few errors in the map generation over large maps, but avoids backtracking searches, which I'm fine with for now. In addition, logging the constraint violations helps to identify issues.
After the generator, a second stage refiner runs on an additional 200 tiles per frame - replacing tiles in fully resolved 3x3 neighborhoods with other tiles according to a ruleset to make the world look a bit more interesting.
After this, each resolved tile can be one of many different variants of the same tile, which helps break up the monotony of an otherwise quite small tileset.
Finally, we add in the night-time lighting:
Zooming out, I actually think it's starting to look a bit nice:
Having checked this off, next on my list is getting pathfinding and some gameplay UI together. Hoping to update on that next!
We still survive
Lost in the post-apocalyptic wasteland
Status | Prototype |
Author | linusmartensson |
Genre | Strategy, Survival |
Tags | 2D, Real time strategy, Singleplayer |
More posts
- UI, UX, AI, Save,Load, Animations, EverythingJun 04, 2024
- I started building somethingMay 24, 2024
Leave a comment
Log in with itch.io to leave a comment.