Minimal resource consumption on returning coordinates

09/20/2014 05:39 drakejoe67#1
Okay so I've tried a few methods already, as I am coding custom skills for my project and I'm quite in a pit where I can't seem to come up with a solution to ease the performance used to just return the values.

The original code which took too much is by using these:

All coordinates from 000 - 999 both X and Y in dictionary loaded from start of server.

Calculating a cone;
Using ConcurrentDictionary
and filter down with the Math of the cone

Lastly I fill the new ConcDictionary with the coordinates that is correct.
Once it gets to the last coordinate, example 682, then it will automatically break on Y.

However because of this, it has still looped from 000 all way to 600 skipping coordinates and just unnesecary use of computer resources.

Code:
Original:
Coordinates as Entity //Needs replacement
So, I'll let you guys state your opinions, pretty sure you guys can come up with something much better. but remember, I need it to return the X,Y value of everything within a cone/circle or any sort depending on the math.
09/20/2014 08:51 Spirited#2
Quote:
Originally Posted by drakejoe67 View Post
Okay so I've tried a few methods already, as I am coding custom skills for my project and I'm quite in a pit where I can't seem to come up with a solution to ease the performance used to just return the values.

The original code which took too much is by using these:

All coordinates from 000 - 999 both X and Y in dictionary loaded from start of server.

Calculating a cone;
Using ConcurrentDictionary
and filter down with the Math of the cone

Lastly I fill the new ConcDictionary with the coordinates that is correct.
Once it gets to the last coordinate, example 682, then it will automatically break on Y.

However because of this, it has still looped from 000 all way to 600 skipping coordinates and just unnesecary use of computer resources.

Code:
Original:
Coordinates as Entity //Needs replacement
So, I'll let you guys state your opinions, pretty sure you guys can come up with something much better. but remember, I need it to return the X,Y value of everything within a cone/circle or any sort depending on the math.
That is horribly inefficient. Do you know what's behind a dictionary to start with? It's a tree of some design. To get a value from the tree, it compares the search key with the root's key. If the search key is greater than the root key, it branches right; else, it branches left. It keeps comparing keys until the key of the child leaf matches the search key. You're talking about close to a million leaves just for getting a coordinate from the Canyon map. Although trees do minimize comparisons, that's still a crap ton of comparisons.

Load coordinates in an array and all you have to do is run a quick arithmetic statement to get coordinates from memory. No comparisons required, at all. Not only is that far less memory usage than using a dictionary, it's magnitudes better in terms of efficiency. With leaves, you have to not only store the key and value (instead of just the value), you have to store pointers to the child and parent leaves in the branch. So, in recap, a dictionary with even one coordinate inside it is less efficient than an entire map stored as an array (in CPU cycles). Dictionaries are not a good idea. If resource consumption is your only concern, an array is still the way to go - just think smarter about your bit allocation.
09/20/2014 09:23 KraHen#3
Why would you even keep the coordinates in an array, you can calculate cones with high school math and just generate the coords. Also, you dont really need a cone. You need two triangles. One larger pointing to the player and one connected to it pointing in the opposite direction. It`s more than enough in this case.
09/20/2014 09:29 Spirited#4
Quote:
Originally Posted by KraHen View Post
Why would you even keep the coordinates in an array, you can calculate cones with high school math and just generate the coords. Also, you dont really need a cone. You need two triangles. One larger pointing to the player and one connected to it pointing in the opposite direction. It`s more than enough in this case.
Alright, I'm not understanding this. What is this thread even talking about if it's not loading coordinates from a data map for Conquer Online? Is this related to this section at all? Why a cone, why triangles? What is going on here? What does "calculate a cone" even mean? The area, volume, vertex, draw points in OpenGL? I need English and I need context.
09/20/2014 10:27 drakejoe67#5
Only using math is fine, it just makes things take more time and since I am using this for multi purposes I think it's easier to do like Fang said.

Why I asked for a method Fang suggested is simply because I need a list of all available coordinate of a map to use for well, my custom features.

Though, my 2nd method of trying to find a way to do this. I already have an arithmetic method without an array of dictionary of coordinates. But I generated the coordinates after calculation which took alot less performance. Though this is trouble some when the math is different depending on which direction I shoot a skill as an example.

For Math calculation to make cones and such, I got all that no problem.

So then, something I have yet to try but very unsure of, how efficient is using array and the Where => method? Will it still loop through entire array and lag as shit since coordinates are like 1500 x 1500 on some maps.
09/20/2014 18:20 Spirited#6
Quote:
Originally Posted by drakejoe67 View Post
Only using math is fine, it just makes things take more time and since I am using this for multi purposes I think it's easier to do like Fang said.

Why I asked for a method Fang suggested is simply because I need a list of all available coordinate of a map to use for well, my custom features.

Though, my 2nd method of trying to find a way to do this. I already have an arithmetic method without an array of dictionary of coordinates. But I generated the coordinates after calculation which took alot less performance. Though this is trouble some when the math is different depending on which direction I shoot a skill as an example.

For Math calculation to make cones and such, I got all that no problem.

So then, something I have yet to try but very unsure of, how efficient is using array and the Where => method? Will it still loop through entire array and lag as shit since coordinates are like 1500 x 1500 on some maps.
The where method in Linq acts like a query. It uses conditionals as well. I'm not sure how they do it, if it's in parallel or just in sequence (which would be even more inefficient than a dictionary), but it's still not the way to do it. Again, I would just use a simple algorithm and an array (storing each row in sequence that can be accessed using the following formula).

coordinates + (x * width)) + y