Thursday, June 2, 2022
HomeGame Developmentunity - The way to shortly calculate the variety of tiles between...

unity – The way to shortly calculate the variety of tiles between buildings in a tile system


my buddy and I are presently engaged on a metropolis builder sport like Anno/Cities Skylines however with some personal concepts and tweaks. (in fact, on a a lot smaller scale)

At the moment, we’re struggling a bit with implementing the financial system system and hoped that we might get some concepts for the implementation.

Residence buildings and all different buildings (manufacturing/service) are related by roads. For our service buildings (fireplace stations, police, and so on.) we wish to have a distance-based system as an alternative of an space of affect. Meaning, relying on what number of tiles a residence constructing is away from a service constructing the decrease the impact.

At the moment, I attempted one strategy with a breath deep algorithm.

The algorithm begins on the service constructing and progresses alongside the highway. The algorithm first searches for adjoining roads after which writes them into a listing of roads. It then saves the present tile distance into the highway gameobject earlier than shifting to the subsequent highway within the listing. (I attempted for example it within the image)

Though the algorithm works properly and is appropriate with a number of service constructing overlapping, the primary downside of this strategy is the efficiency.

Testing with 10 buildings or so, brought about robust body drops/freezing of the sport.

I might additionally should run this frequently because the participant can take away roads and repair buildings so I’ve to replace it to account for any adjustments in buildings. (–> again to downside 1)

For the reason that values are saved on the highway. All buildings additionally should examine the highway they’re related to frequently. (Didn’t check it but however I assume this might additionally take a heavy toll on the efficiency.)

I might attempt to use threading/ the job system to cut back the workload from the primary thread and stop freezing of the sport. However my present implementation depends on sport objects and the Unity API which isn’t appropriate with threading (afaik). I believe I might rewrite it to be appropriate however I additionally suppose that the strategy itself is flawed.

One other concept I had was to make use of an A* algorithm to examine the gap of the residential constructing to the closest service constructing. That method I might not have to avoid wasting the info on the roads however it will nonetheless be fairly computation intensive. (I already began to implement this, (additionally with threading in thoughts) however I’ve a number of bugs and the algorithm presently doesn’t work correctly in any respect.

As I stated I don’t suppose my strategy is probably the most elegant one. Does somebody have a greater algorithm or a greater strategy to retailer the info in our sport to permit quicker entry and calculations?

In case you want additional particulars I’ll attempt to present extra particulars on my present implementation.

We additionally admire each concept and suggestion on the final information administration construction to permit environment friendly information dealing with for the financial system (manufacturing, good consummation, taxes, and so on.)

Lastly, we’re sorry if it is a silly query. We aren’t probably the most skilled programmer and are studying on the fly 🙂
Problem

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments