Devlog #6 Mega Layouts

Keeping with the theme of last week which was optimization of the Verdant Village, this week I've decided to talk about why I find myself in the pickle I'm in. As stated last week the game can take about 15 to 20 seconds of loading at the start, once the game is loaded however there will never be another load screen. While I work to optimize that I felt it might be good to explain why it is the way it is.

Every game engine is different. The game engine that I am using to make Verdant Village is called Construct 2. In Construct 2 you create your game on a series of what are called layouts. Think of them like a canvas, if you were to open up paint on your computer that blank white square looks similar to a layout. The difference obviously is instead of painting on it you can then insert objects, sprites, data, events, actions, etc, to create a game. The end result will usually look something like what the game would look like when you first boot it up.

Usually, a game is split up between these layouts in order to not strain the computer and to keep things running smoothly. For instance, if you look at and of the old 2D Zelda games. If you can imagine a dungeon in one of those games you might imagine a series of rooms the player moves through. I cannot vouch for how those games were actually coded but if you were to make it in the Construct 2 engine you would likely put each room on a separate layout. Or at the very least you would put the entire dungeon in a layout separate from the overworld.

The reason for this practice is that when a game is loaded the computer has to load all the active assets like sprites, and music, into memory so it can be quickly accessed. Since people don't want to have long wait times between rooms the game is split up into smaller segments. As a result, when you move between layouts the engine only needs to load a small section of the game instead of loading up every asset again. The result as you can imagine is a much smoother experience for the player. Games are filled with all sorts of tricks like this to keep the player from feeling any downtime.

Now we come to the problem. There is one particular function in Verdant Village that prevents me from doing what I stated above. That problem is NPC pathfinding. For those who are unfamiliar NPC pathfinding is the process by which an NPC in the game is told to go to a location, the NPC will pick out a path through the layout and then start to move until it reaches its destination. This sort of behavior does not play nice with multiple layouts. Theoretically I could make a system in which NPC's find a path towards the edge of their current layout and then transfer to another layout and continue on. However, this doesn't work because if a layout isn't in use then it is not loaded. Since the game has to follow the player around from layout to layout chances are you will not always be in the same layout as every NPC in the game. As a result, some NPCs would never be loaded and therefore would never move anywhere or do anything until you enter their layout. Since activities for NPCs are also triggered based on the time of day you would also have to be in their layout when the timer is up in order for them to start moving.

It’s an unfortunate reality. At the moment the only solution seems to be making a mega layout. That is one all-encompassing layout that handles every room in the game at the same time. As a result, the upfront load time is longer, but the tradeoff is that I can have functioning NPCs moving around the game to create a far more realistic environment for the player, at the end of the day I would still say its worth it.