#Territory game

1 messages · Page 1 of 1 (latest)

plucky marsh
#

I'm making a game inspired by territorial.io

Players are able to draw on the map, and whenever the edge of their border touches the 'plan', it expands.

Built with DOTS. The world is broken down into 64x64 chunks.

Current limitations and issues:

  • Drawing too fast will cause discontinuities along chunks.
  • Different players are unable to 'capture' territories from others.
#

Territory game

plucky marsh
#

Performance issue.
As the amount of chunks increases, so too does the drawcall count. While each quad is instanced, their material is not. Each one requires its own structuredBuffer to draw each individual pixel.

I will have to investigate a way to enable instancing for structuredBuffers, or share one structuredBuffer among several perhaps hundreds of chunks.

#

At the current maximum zoom level, the player can fill the screen with 2000 chunks, seemingly causing roughly 4000 drawcalls.

Although this means the player can see 8.192.000 pixels at once, it still causes an unacceptable performance drop.

plucky marsh
#

Significantly improved rendering performance.

4096 chunks can now share one material, drastically reducing batch count. Furthermore, I now use ComputeBuffer.BeginWrite rather than ComputeBuffer.SetData.

Where before I would drop to 40-20 frames per second, I am now seeing stable 160 fps. The bottleneck has returned to the CPU.

#

Time to jobify

plucky marsh
#

Now checking growth for other players' occupied territory. They can no longer overlap.

plucky marsh
#

This further tanks performance. The growth algorithm can now easily exceed 10ms when growth covers the entire screen.

plucky marsh
#

Single-threaded performance

queen wolf
#

@plucky marsh The game is available on Android ?

plucky marsh
#

The game is not ready for release. It's missing:

  • Multiplayer
  • Several optimizations (it will probably not perform well at all on mobile)
  • Gameplay features (capturing opponent territory, player goals, user interaction, etc)
plucky marsh
#

So I did jobify GridTerritorySystem, and probably am seeing some performance enhancements.

If you compare with the previous profiler screenshot, there seemingly is a 10x performance increase. However this did not come from multithreading...

#

The bigger reason is this extremely silly block of code, try not to place your palm upon your forehead:

for (int i = 0; i < 64; i++)
{
    opponentMask[i] = 0;

    for (int j = 0; j < playerCount; j++)
    {
        if (j == id)
            continue;

        if (borderHashmap.TryGetValue(key, out var entOther))
            opponentMask[i] |= SystemAPI.GetBuffer<TerritoryBorder>(entOther)[i].Value;
    }
}
plucky marsh
#

Added some noise to the drawings

plucky marsh