Hi bwy, > bool > -key_as_object::is_key_down(int code) > +key_as_object::is_key_down(int keycode) > { > - if (code < 0 || code >= key::KEYCOUNT) return false; > + if (keycode < 0 || keycode >= key::KEYCOUNT) return false; > > - for(int i = 0; i < > sizeof(m_unreleased_keys)/sizeof(m_unreleased_keys[0]); i++) > - { > - if( m_unreleased_keys[i] != 0) > - { > - for(int j=0; j<8; j++) > - { > - if( m_unreleased_keys[i] & (1 << j) ) > - { > - if(key::codeMap[i*8+j][1] == code) return true; > - } > - } > - } > - } > + // Select the relevant byte of the bit array: > + int byte_index = keycode >> 3; > + // Find bit within the byte: > + int bit_index = keycode - (byte_index << 3); > + > + uint8_t mask = ~(1 << bit_index); > + > + if ((m_unreleased_keys[byte_index] & mask) != > m_unreleased_keys[byte_index] ) return true; ---------> [1] > > return false; > }
Is this an attempt for optimization or fixing anything? Any assumption for with [1]? eg. If there are 2 bits set within the same byte, [1] would always return true. --zou On 10/10/07, Benjamin Wolsey <[EMAIL PROTECTED]> wrote: > CVSROOT: /sources/gnash > Module name: gnash > Changes by: Benjamin Wolsey <bwy> 07/10/10 14:07:58 > > Modified files: > . : ChangeLog > server/asobj : Key.cpp Key.h > > Log message: > * server/asobj/Key.{h,cpp}: change is_key_down() to take SWF > keycode > and check the relevant bit in m_unreleased_keys (bit array). > > CVSWeb URLs: > http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4588&r2=1.4589 > http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Key.cpp?cvsroot=gnash&r1=1.39&r2=1.40 > http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Key.h?cvsroot=gnash&r1=1.28&r2=1.29 > > Patches: > Index: ChangeLog > =================================================================== > RCS file: /sources/gnash/gnash/ChangeLog,v > retrieving revision 1.4588 > retrieving revision 1.4589 > diff -u -b -r1.4588 -r1.4589 > --- ChangeLog 10 Oct 2007 13:38:08 -0000 1.4588 > +++ ChangeLog 10 Oct 2007 14:07:57 -0000 1.4589 > @@ -1,3 +1,8 @@ > +2007-10-10 Benjamin Wolsey <[EMAIL PROTECTED]> > + > + * server/asobj/Key.{h,cpp}: change is_key_down() to take SWF keycode > + and check the relevant bit in m_unreleased_keys (bit array). > + > 2007-10-10 Sandro Santilli <[EMAIL PROTECTED]> > > * server/movie_root.cpp (notify_key_listeners): don't use a > > Index: server/asobj/Key.cpp > =================================================================== > RCS file: /sources/gnash/gnash/server/asobj/Key.cpp,v > retrieving revision 1.39 > retrieving revision 1.40 > diff -u -b -r1.39 -r1.40 > --- server/asobj/Key.cpp 10 Oct 2007 08:55:46 -0000 1.39 > +++ server/asobj/Key.cpp 10 Oct 2007 14:07:58 -0000 1.40 > @@ -51,23 +51,18 @@ > } > > bool > -key_as_object::is_key_down(int code) > +key_as_object::is_key_down(int keycode) > { > - if (code < 0 || code >= key::KEYCOUNT) return false; > + if (keycode < 0 || keycode >= key::KEYCOUNT) return false; > > - for(int i = 0; i < > sizeof(m_unreleased_keys)/sizeof(m_unreleased_keys[0]); i++) > - { > - if( m_unreleased_keys[i] != 0) > - { > - for(int j=0; j<8; j++) > - { > - if( m_unreleased_keys[i] & (1 << j) ) > - { > - if(key::codeMap[i*8+j][1] == code) return true; > - } > - } > - } > - } > + // Select the relevant byte of the bit array: > + int byte_index = keycode >> 3; > + // Find bit within the byte: > + int bit_index = keycode - (byte_index << 3); > + > + uint8_t mask = ~(1 << bit_index); > + > + if ((m_unreleased_keys[byte_index] & mask) != > m_unreleased_keys[byte_index] ) return true; > > return false; > } > @@ -98,9 +93,8 @@ > { > if (code < 0 || code >= key::KEYCOUNT) return; > > - // Key.isDown() only cares about flash keycode, not character, so > - // we lookup keycode to add to m_unreleased_keys. > - > + // This is used for getAscii() of the last key event, so we use gnash's > + // internal code. > m_last_key_event = code; > > // Key.isDown() only cares about flash keycode, not character, so > @@ -286,9 +280,9 @@ > return as_value(); > } > > - int code = fn.arg(0).to_number<int>(); > + int keycode = fn.arg(0).to_number<int>(); > > - return as_value(ko->is_key_down(code)); > + return as_value(ko->is_key_down(keycode)); > } > > /// \brief > > Index: server/asobj/Key.h > =================================================================== > RCS file: /sources/gnash/gnash/server/asobj/Key.h,v > retrieving revision 1.28 > retrieving revision 1.29 > diff -u -b -r1.28 -r1.29 > --- server/asobj/Key.h 10 Oct 2007 07:45:28 -0000 1.28 > +++ server/asobj/Key.h 10 Oct 2007 14:07:58 -0000 1.29 > @@ -16,7 +16,7 @@ > // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA > // > > -/* $Id: Key.h,v 1.28 2007/10/10 07:45:28 bwy Exp $ */ > +/* $Id: Key.h,v 1.29 2007/10/10 14:07:58 bwy Exp $ */ > > #ifndef __KEY_H__ > #define __KEY_H__ > @@ -79,10 +79,17 @@ > > key_as_object(); > > - bool is_key_down(int code); > + // Pass SWF keycode, returns true if currently pressed. > + bool is_key_down(int keycode); > > + // Pass gnash::key::code. Changes m_last_key_event > + // and adds appropriate SWF keycode to bit array of keys > + // pressed (m_unreleased_keys) > void set_key_down(int code); > > + // Pass gnash::key::code. Changes m_last_key_event > + // and removes appropriate SWF keycode from bit array of keys > + // pressed (m_unreleased_keys) > void set_key_up(int code); > > #ifndef NEW_KEY_LISTENER_LIST_DESIGN > > > _______________________________________________ > Gnash-commit mailing list > Gnash-commit@gnu.org > http://lists.gnu.org/mailman/listinfo/gnash-commit > _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit