GameMaker Draw GUI from ds_map

D

DeadZombie

Guest
Hello, guys!
I decided to display inventory from ds_map using 'Draw GUI' event, but then I wondered, isn't it too expensive getting map values using this event? Because maps are not sorted in any (recognizable) way, meaning that to find a certain key I may have to iterate through the whole thing (which is very slow) every time Draw GUI works.

Please enlight me, how often 'Draw GIU' gets data from map and refresh displayed text? What event would be better to use if I want to refresh data only if map's values changed?
 
D

DeadZombie

Guest
The only thing that cropped up in my head is variables creation, which will be supply 'Draw GIU' with new data. And every time map values changed I can retrieve data from Map and transfer it to variables.
 

Ido-f

Member
draw GUI event runs once per frame, as does every other event.

Maps are not sorted in a recognizable way but that's only relevant if you don't have the keys for them. It's a rare scenario.
Usually you do, as you're the one who created the map, so you just need to read the map values one by one using the keys.
The keys are hashed into the correct map index. They say it's almost as fast as an array.
 
D

DeadZombie

Guest
draw GUI event runs once per frame, as does every other event.

Maps are not sorted in a recognizable way but that's only relevant if you don't have the keys for them. It's a rare scenario.
Usually you do, as you're the one who created the map, so you just need to read the map values one by one using the keys.
The keys are hashed into the correct map index. They say it's almost as fast as an array.
So if I get value by key it takes O(1) or O(n) in the worst case? Which means displaying values directly from HashMap is a good idea?))
 
Top