polygone
|
|
Posted on: July 16, 2011, 12:05:09 pm |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
OK I've done all of GM's data structures now. I haven't fully tested all of the functions so let me know if anything doesn't work, doesn't mimic GM's behaviour or of course can be made more efficient. There is a small incompatibility from GM that when a data structure is destroyed in GM it leaves a gap in the index value (this is replicated), but then when GM creates a new data structure afterwards it fills in the gaps of the indexes (which has not been replicated because it seems retarded). This shouldn't cause any problems though unless people are calling data structure indexes as literals or something. And there is a also slight incompatibility with ds_queues when you have multiple priorities of the same value. The way I have handled it, it will always return the lowest value with multiple the priorities the same. The way GM handles it, is it returns the value which was first added to the priority queue. This should unlikely cause any issues though as you shouldn't be setting priorities the same anyway. Anyway code posted on pastebin (because I'm way over the forum character limit): http://pastebin.com/earWGw8Z
|
|
« Last Edit: July 20, 2011, 05:34:53 am by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
|
polygone
|
|
Reply #3 Posted on: July 27, 2011, 06:46:42 am |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
You should free the arrays you allocate in the grid class- C++ isn't garbage collected and heap-allocated memory doesn't get freed when it goes out of scope. Just "delete[] grid_array;" in the destructor and when you resize it.
I tried that when I was writing it and it didn't work, so I just left it for Josh to sort. I'm not entirely sure why you would choose multimap over map or unordered_map for ds_map. It just seems to add complexity in this case. To mimic GM's behaviour, it allows you to set two keys the same. You shouldn't erase and re-insert for ds_*_replace()- it's redundant and in the case of vector (where it has to copy the other elements over and then back) very slow. What do you use instead? For ds_map_find_next() you could just get an iterator to the key and increment it instead of doing a linear search through the map. Doesn't work with multimap in the case where two keys have been set the same. GM's behavior with regard to priority queues is the point of priority queues. There's no problem with adding multiple things that have the same priority- in that case it should simply act as the queue that its name implies and return the first one inserted. That behaviour was annoying to replicate so I didn't bother. I don't think it makes too much difference.
|
|
« Last Edit: July 27, 2011, 07:26:18 am by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
|
|
polygone
|
|
Reply #7 Posted on: July 27, 2011, 01:46:20 pm |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
Yes that would work.
|
|
« Last Edit: July 27, 2011, 05:06:28 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
polygone
|
|
Reply #9 Posted on: August 01, 2011, 09:02:58 am |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
What exactly didn't work? It's just a simple insertion in two places. I can't remember, I was going to go back to it at the end but I forgot so I just left it for josh to add when he moved everything into .cpp (however I see now that he didn't add it or actually change anything that was talked about in the irc). GM allows you to ds_map_add() twice with the same key, but you can only ever access the first one you added so it seems more like a bug than anything useful. There's really no reason keep that behavior. You can't reference it directly but if you delete a key then you are able to reference the one next which had the same key. "My car's engine is broken but it was annoying to fix so I didn't bother. The wheels still turn, right?" This is a very minor inconsistency with a behaviour that shouldn't be relied on anyway and is also unlikely to cause any detrimental inconsistency with anybody's game, fixing it will cost on efficiency I deemed it not worth doing.
|
|
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #12 Posted on: August 01, 2011, 11:28:30 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Well, they're missing speed and efficiency, too. But I'm going for "working" with those functions--they're kind of unusable.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
|