Hey guys! Been a lurker here for a while, I quite recently took up game development as a hobby, and it kind of turned into a passion. I’m a second-year CS&Systems Design student in uni.
I’ve been reading up on a lot of material for the past six or so months and I decided to make my own game from the ground-up - a pixel-art old school 2D RPG (with a lot of modern elements in combat/mechanics). Main reason for doing my own engine is
- I think a challenge is incredibly fun
- I want and love to learn!
I’ve come quite long already and have got many systems I’m happy with (for now) in place for most of the things you’d want out of a basic 2D-engine in place. My next step is allowing my engine to load huge tile-maps with multiple layers in an efficient way.
I’ve written my own XML-parser for Tiled-maps that can handle everything except for polygon-colission (as of yet). The way I’m doing it now is just loading the entire tilemap into arrays and only updating/rendering my players viewPort + x.
My question is if you have any guidance on an implementation for loading my arrays from chunks of a HUGE tileMap into the relevant data structures for collission-checking/updating/rendering based on my player’s location in the world.
My thought process right now is it would be incredibly useful if I wouldn’t have to divide my tileMap-file into many small chunks, but maybe get away with eight chunks on hard-storage, and load the entire big chunk with its data into I guess a treeMap? This might consume 1GB of memory at most, and I think I’m fine with that right now. (If I’d need to trim that down I could just make sure the solution is scalable and divide the map into more chunks later on).
Then based on X,Y I would load in a few extra screens surrounding the player into my arrays from the treeMap and only update/render relevant screens, with x screens away updating less frequently etc.
The way I’m thinking about it right now is (simplified):
Say I have a TileMap, 2000x3000 tiles, divided into
8/16 “worldChunks”.
Loading it into my game I would:
-
Load one of X “big-chunks” into my TreeMap (“WorldMap”).
-
Based on player X,Y - calculate an area of X screens surrounding the player and
load into memory. -
When I get close to an edge, save the state of npcs/mobs/objects on these screens
-
Load next X screens into memory, free up previous chunks for GC to collect
Is this a reasonable approach to solving the problem? Do you have any useful tips/guidance or other ideas for me to think about? Any warnings of an approach like this?
Basically, any tips or inspiration for a scalable solution here would be greatly appreciated!