Do I have too many rooms or am I doing this wrong?

I’m attempting to recreate the downtown area of a modern city. I currently have around 600 rooms, all interconnected, and intend to add more. I’d like to give the player a compass to lead them across town which points toward the best route to a specific location. Although, the game simply hangs (stops) whenever it is examined, unless I lower the amount of rooms to around 150. It still takes at least six seconds, but then it can find the best route instantly anytime afterwards. I have the same result using trying to list the number of moves as well.

I’m still becoming familiar with the basic functions, but I’ve stripped my code of all elements aside from my essential functions/plugins and it seems obvious the amount of rooms is my issue. Is there a better way to accomplish this type of tracking function on such a large scale?

I’ve included a stripped down version of my story with around 150 rooms. It’s a minimal working version with the described lag. (521 KB)

Wow! Without checking your source code at the moment, I would definitely say that route-finding on a 600-room map is not going to be the way to go–route-finding is going to get slower the more rooms you have, just as a matter of mathematical necessity.

I’d use coordinates; assign each room x,y coordinates and have the compass calculate the difference between the location and the destination and convert that to a direction. This is more realistic as a way that a compass might work anyway. If your map recreates a grid you might even be able to do this automatically–go through when play begins and make sure that a room that’s north of another room has a y-coordinate one higher, etc.

FWIW: On first run, after wandering away from the spawn point, it took 20 seconds to route-find the way back, but subsequent attempts (after moving around the game) were instantaneous. (6L38 for Gnome.)

If you can’t find a way to speed it up, the next best option is to add a “Please wait, loading…” text to a when play begins rule and trigger a route calculation to get the initial slowdown out of the way. It’s better than have the actual gameplay pause the first time it’s actually used.

Hmm, I guess I may have been too pessimistic. Under the hood, the first time you try route-finding does it calculate all the routes? If so, then route-finding is faster than I thought… and doing a precalculation at startup definitely seems like a good idea.

Is there a difference between slow and fast route-finding here? Is it possible that with the larger map some memory limit is being exceeded?

It also recalculates if circumstances change significantly, e.g. the PC presses a button and a new exit appears to the east.

Yes, if fast route-finding is enabled then every time a route is queried and the map has changed since the last query, the shortest paths from each room to every other room are computed simultaneously using the Floyd-Warshall algorithm.

“Slow route-finding” spreads that delay out, so to speak, so there’s a smaller pause every time a route is calculated rather than one big one after each map change.

Thank you for your input everyone! I found a way to accomplish this based on your comments.

The compass-like item (A Cube) plays a central part in my story and will be used very early on.
I can’t allow lag, or my players would quit in the type of context my game will be played.

FWIW, I’m using Trizbort. Here’s what the full map looks like so far and where I intend to send the player to and from with their compass-type object.

Trizbort has been very useful for this scenario. I’m able to place objects very easily and manage their location.

I’m unable to effectively generate coordinates for the map based on how the city and interiors of my blocks will soon become irregularly shaped. This would be too much to keep straight, and it’s impossible to see the printed names of spaces with the same name (e.g. The Sidewalk) until after they’re exported.

I fixed this by manually placing a type of object in each space as scenery that will tell the cube which direction to point. Here’s an example with just one object:

[code]A CR-NE is in TheSidewalk48.

A locator-NE is a kind of thing. A locator-NE is scenery.

Cuberoute is text that varies.

The player carries The Cube. The description of the cube is “A perfectly shaped cube with dark, mirrored faces. The illuminated image of a compass shines through one side. The compass dial points quiveringly to the [cuberoute].”

Every turn:
If a locator-NE is in the location:
now cuberoute is “northeast.”;
If a locator-NW is in the location:
now cuberoute is “northwest.”;
If a locator-SE is in the location:
now cuberoute is “southeast.”;
If a locator-SW is in the location:
now cuberoute is “southwest.”;
If a locator-E is in the location:
now cuberoute is “east.”;
If a locator-N is in the location:
now cuberoute is “north.”;
If a locator-W is in the location:
now cuberoute is “west.”;
If a locator-S is in the location:
now cuberoute is “south.”[/code]

If the only function of the locators is to tell the compass which way to point, you won’t need to do that. (In some circumstances having lots of extra things will give you a big performance hit.) You can give rooms direction-valued properties, something like this:

A room has a direction called cube-way. The player carries The Cube. The description of the cube is "A perfectly shaped cube with dark, mirrored faces. The illuminated image of a compass shines through one side. The compass dial points quiveringly to the [cube-way of the location]."

…with probably a special case when you’re actually in the location.

That’s a lovely-looking map; I can see how Trizbort is useful. Sorry that the coordinate suggestion was unhelpful, I’m a bit hung up on coordinates.

Thanks Matt, your suggestion solved my overwhelming objects issue. I still end up needing to place the locators within Trizbot to see what direction each room should point the player and then remove them after I create the rule. Trizbort generates room names for generic-named rooms in the sequence they’re created, so it’s easier to sniff the right direction out this way.

Although, I did get a bit too optimistic again and presumed I could extend the bounds of the game even further. I only have 42 game objects, minimal extensions, but it looks like having 1796 rooms causes some delay as well (example). Also, the web-version is about 18Mb, something a bit outside the bounds of what I intend to use it for.

I still have a way to include the full-scale map into the project I’m working on, but I think it will be after I use a minimized version of the map with just a few hundred rooms.