|
Post by tango209 on Feb 7, 2015 18:34:20 GMT
Hi,
Is there an easy way to determine if a selected location is a valid hex?
I tried World.instance.hexes.Contains(...), but that dictionary contains over 24,000 entries (pre-populated for performance?) regardless of chunk and hex radius used to create the world.
Thanks!
|
|
|
Post by khash on Feb 7, 2015 20:01:47 GMT
Dictionary is a Hash based search. Which means that search over 24000 entries should not be a big issue (it does not check all other options on the way, but simply jumps to the one you need.)
We create World and register all hexes there so that you may find hex easily, but 24k is still a big number so you may worry that you will pass memory limit on some devices (depend on your texture resolution and hardware capabilities)
|
|
|
Post by tango209 on Feb 7, 2015 22:03:46 GMT
Hi khash,
Sorry, I wasn't more specific. No problem with the Dictionary search or number of items. The problem is when I click off of the map I use World.instance.Contains(...) and there's nothing there to tell me if the returned hex is part of the map or not. I was hoping to not have to iterate over World.instance.chunks and then use chunk.hexesCovered to see if where I clicked contains a hex that is on the map.
|
|
|
Post by khash on Feb 8, 2015 9:17:14 GMT
If you want to consider only hex which is part of the world but not a border type I will go with something like:
Hex h = World.GetInstance().GetHexAt(pos); //Dictionary search is fast if (h.terrainType.source.mode != MHTerrain.Mode.IsBorderType) //reference test is fast { //do something }
|
|