0

I'm working on a strategy game. One of the main mechanics is that the game map can be manipulated. Change terrain, elevation and so on. The map is randomly generated and consists of a block of a specified size. This is the problem. If I generate say a map of 230x130 block with size 5 pixels then it is still fine. Zoom, pan, edit is pretty fast, but if I want to make the world bigger, it's terrible.

I have the map as a 2D array where each index represents one block. Each block has its own position, size, neighbors, and lots of other statistics. What is the ideal way to save or work with the map?

The game is made in TypeScript.

  • 1
    Have you done any profiling to determine where the slowness is coming from? That is, which code is taking the longest? If we know that then it’s easier to suggest a data structure that avoids running that code as often. – Ryan1729 Jul 06 '20 at 09:21
  • When you say a 2D array, do you mean an array of arrays, or one array you index into with something like `x + y * width`? The latter requires fewer allocations, and so is a likely improvement over the former if that is what you are using. – Ryan1729 Jul 06 '20 at 09:25
  • Accessing arrays is usually pretty fast. I suspect that the interface you use for graphics is slow. You probably should tell us what library you are using and give us your rendering code. – QuantumDeveloper Jul 11 '20 at 18:01

0 Answers0