PolledInput charQueue
Archives Forums/BlitzMax Bug Reports/PolledInput charQueue
| ||
You are using an char array (charQueue) with a fix length of 256 bytes. This array is never cleared. What would happen if somebody enters more than 256 chars without using FlushKeys: GetChar wouldn't work. I would recommend: Global charGet,charPut,charQueue[256] -> Global charQueue[0] && Case EVENT_KEYCHAR If charPut-charGet<256 charQueue[charPut & 255]=ev.data charPut:+1 EndIf -> Case EVENT_KEYCHAR charQueue=charQueue[..Len(charQueue)] charQueue[Len(charQueue)-1]=ev.data && Function GetChar() If autoPoll PollSystem If charGet=charPut Return 0 Local n=charQueue[charGet & 255] charGet:+1 Return n End Function -> Function GetChar() If autoPoll PollSystem if Len(charQueue)=0 Return 0 Local n=charQueue[0] charQueue=charQueue[1..] Return n End Function && Function FlushKeys() PollSystem charGet=0 charPut=0 For Local i=0 Until 256 keyStates[i]=0 keyHits[i]=0 Next End Function -> Function FlushKeys() PollSystem'btw here no "If autoPoll"? charQueue=New Int[0] For Local i=0 Until 256 keyStates[i]=0 keyHits[i]=0 Next End Function Or did I misunderstand something? Greez Last edited 2010 |