Thread: SoundUtils
View Single Post
Old 08-31-2009, 10:30 PM   #30
ToukoAozaki
extends net.wc3c.Jasser
 
Join Date: Jun 2008
Posts: 336

Submissions (5)

ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)ToukoAozaki will become famous soon enough (60)

Send a message via MSN to ToukoAozaki
Default

Quote:
Originally Posted by Rising_Dusk
And make it O(n) with that loop? I guess speed doesn't matter, but Vex has got me not liking that in principle. I dunno, if TimerUtils red can get away with an H2I-MIN_HANDLE_ID approach, I don't think it's a problem. I do see your point here, though, but I'm just not sure..

That is O(n) only if hashing function returns a constant value, making hash collisions 100% of the time. The technique Griffen suggested is one of the hashtable techniques to deal with hash collisions. Basically you save a copy of the key object reference itself, and compare it with the stored value after lookup with the hash of the key. If the key doesn't match, then try checking the next object pointed by the entry. This is generally done with linked lists, but arrays will do fine if every object has assigned unique indices. This technique generally works like supposed O(1) on average. Having poor hash will make the performance closer to theoretical O(n) worse case though.

Quote:
Originally Posted by Rising_Dusk
Yes, I noticed that too. The most frustrating part is the difference when the game lags, because that causes some strange discontinuities as well. I found that the difference between game time and real time is only noticeable for sounds over 2 minutes long (this may be system-dependent, as my computer is relatively slow). In testing I didn't think it was that big of an issue, but if it's system-dependent then it's basically impossible to reliably fix.

Just get an approximate factor and add the extra gap (like 15 percentage point). While added gap would make recycling a bit inefficient, but at least it would be bulletproof from unwanted bugs.
ToukoAozaki is offline   Reply With Quote