Tips and Tricks to CO Programming

01/27/2012 06:53 12k#1
I just want to hear some ideas and tricks that some of you guys are using now days in your programming in the co community. It doesn't have to be something big or save a lot of performance or anything. Just something crafty how you handle things that is unique. For example, for my dropped floor items dictionary. Instead of using each items UID as the key. I actually use the X coord concatenated to the Y coord. So X = 429, Y = 378 becomes 429378. The number will always be less then a uint. The reason I do that is because instead of searching through all the dropped items using a loop to see if a spot on the ground is taken, I can just use the Dict.ContainsKey method.
01/27/2012 07:21 I don't have a username#2
I never thought about that.
01/27/2012 07:26 12k#3
I like it that way things can never stack. And the keys will never be the same as long as u always have X first, or always have Y first.
01/27/2012 08:42 blaсkNull#4
Make sure you use as much CPU as possible.
01/27/2012 11:46 Korvacs#5
Quote:
Originally Posted by 12k View Post
I like it that way things can never stack. And the keys will never be the same as long as u always have X first, or always have Y first.
The coordinates 345 , 79 and 34, 579 are the same, hurray for not thinking things through!

Also does this mean when you spawn a character you loop through all combinations of the coordinates within the viewable range individually?
01/27/2012 12:59 12k#6
Quote:
Originally Posted by Korvacs View Post
The coordinates 345 , 79 and 34, 579 are the same, hurray for not thinking things through!

Also does this mean when you spawn a character you loop through all combinations of the coordinates within the viewable range individually?
Lol? Why would i do that. Characters can stack and can walk on items. This has nothing to do with dmaps. Its just for dropping items really. And in which case I don't think your going to be dropping an item on the other side of the map are you? No, you check coords 0-+2 away from you. As for the duplicate entry for the dict. I always add a 0 to the Y value if its less then 100. Hurray for not thinking about things on that one once again. How about you stop trying to pick things apart for once.

#edit if your meaning for spawning items i use the same way any typical source does.
01/27/2012 13:04 Korvacs#7
You add a zero? Please tell me your not doing this with strings and parsing and are instead using maths to solve this, please tell me that you have thought about maps with coordinates that go into the thousands.

My point was when you spawn a character you have to show it all the items on its screen, so you have to check all of the cords on the screen to find the items that have been dropped.

How about explaining yourself clearly for once x.x
01/27/2012 13:14 12k#8
1. Check bottom of last post. I didnt get it updated in time.

2. Only reason for explaining myself clearly is for you because nobody else wants to try to pick apart everything.

3. Woopdy doo make 79 as Y to 0079 and 555 into 0555. Problem w/ the thousands solved.

4. Ofc I am.

Have you said 1 positive thing in a post in your last 500 (other then on ur servers thread)? Pretty sad when thats a serious question and its directed at a mod.
01/27/2012 13:26 Korvacs#9
Lol, well anyway my Tip/Trick would be to move to parallel programing with the use of concurrent dictionaries for any collection which could potentially be required to both read and write to at the same time, so any collection that contains, accounts, characters, items, monsters, would most likely benefit from this.
01/27/2012 13:32 12k#10
A while ago pro4never suggested this to me. It worked pretty well. I don't quite understand why the concurrent dictionaries always require an "out" as an arg when ur removing or updating though. Rather annoying.
01/27/2012 14:19 Korvacs#11
Because typically once you remove something from a collection you want to do something with it, if not then you could write an extension which just removes the object and doesn't return it through an out.
01/27/2012 16:05 pro4never#12
Korv is correct though... the floor system you're talking about is actually most likely LESS efficient than the basic 'loop through a collection' type system due to the extra overhead for inserting entries as well as calculations and loops needed to check screen for spawning items to yourself.

If you really want efficiency then just write a proper quad system which will make it plenty efficient and allow scalability as more objects are added to the map.
01/27/2012 17:03 12k#13
Quote:
Originally Posted by pro4never View Post
Korv is correct though... the floor system you're talking about is actually most likely LESS efficient than the basic 'loop through a collection' type system due to the extra overhead for inserting entries as well as calculations and loops needed to check screen for spawning items to yourself.

If you really want efficiency then just write a proper quad system which will make it plenty efficient and allow scalability as more objects are added to the map.
Haha, didn't say it was more efficient or less efficient. Its just a unique way I handle them. As the first post says. He was just trying to give me reasons why it wouldnt work. Not why it wasnt good for performance.
01/27/2012 18:12 InfamousNoone#14
uint uid = x | (y << 16);

if you insist on constructing a uid based on x,y
given x,y < 0xffff
01/27/2012 19:53 pro4never#15
Quote:
Originally Posted by 12k View Post
Haha, didn't say it was more efficient or less efficient. Its just a unique way I handle them. As the first post says. He was just trying to give me reasons why it wouldnt work. Not why it wasnt good for performance.
The two are not always mutually exclusive...

If something is not efficient then regardless of its functionality then it is not the ideal solution.

Please god... lets not all turn into hipster programmers who code something so it's not so 'mainstream'. Obviously conquer sources that are public are FAR from optimized but doing something just to be unique is not the way to go... Your reasons for adopting a new system should be efficiency and or ease of use.

Your system is neither which is why korv was insulting it (and now I get to jump on that bandwagon it seems)