Hello folks,
I am working on a new version of my in which I improve basically any aspect of the game. Each spaceship has a set of rooms that are connected to each other. Characters can walk freely to any non-obstructed area in the spaceship to repair stuff, heal their colleagues, etc.
![](https://uploads.gamedev.net/forums/monthly_2020_04/3da6d21a38dc4e4fa23df541c149d37a.ss_901b34c7d13cdfd285328c1d03cc3c332d87e336.1920x1080.jpg)
Until now, I use pre-generated graphs for each room available in the game. When the game starts, I import the pre-loaded graphs and connect them on the edges. This works perfectly fine. However, I stored the graphs in generated source code files resulting very very large files. In addition, finding a path (A* algorithm) in very large environments could take a very long time - I use the same approach for dungeons.
I wanted to get rid of the large code files containing my graphs, make the creation process of the graph simpler and the path finding faster. After doing some heavy thinking, I came up with this idea:
- I do not store any graph information anywhere! (So I get rid of my large files)
- Instead, when starting the game, I take a black canvas and paint a rectangle in the size of the room for each room on my spaceship (or dungeon).
- Next, I paint all pixels black that lie inside walls, doors or objects. This is very easy and fast, because I store the bounding box for any object and all I have to do is to paint a black polygon on the canvas for each bounding box.
This takes around 80ms for the largest spaceship in my game, is 100% dynamic, fail-proof and fast. I also do not need to store a complex graph. All I have is an image where each white pixel is a location where a character can walk.
However, I ran into an issue: performance for pathfinding. The higher the resolution of my image, the larger is the graph. And the A* algorithm takes its time in large graphs. If I reduce the resolution, the graph is not as exact as I need it to be.
I wanted to ask for your ideas how to speed the pathfinding up?
I tried building a graph on top of my graph in which I connect the center of all rooms to the adjacent rooms. This way, my algorithm would only search along the correct direction. While this spees pathfinding up, it takes a few second to generate this additional graph and it also adds a lot of complexity.