gxdevice.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "std.h"
  2. #include "gxdevice.h"
  3. #include "gxruntime.h"
  4. gxDevice::gxDevice(){
  5. reset();
  6. }
  7. gxDevice::~gxDevice(){
  8. }
  9. void gxDevice::reset(){
  10. memset( down_state,0,sizeof(down_state) );
  11. memset( axis_states,0,sizeof(axis_states) );
  12. memset( hit_count,0,sizeof(hit_count) );
  13. put=get=0;
  14. }
  15. void gxDevice::downEvent( int key ){
  16. down_state[key]=true;
  17. ++hit_count[key];
  18. if( put-get<QUE_SIZE ) que[put++&QUE_MASK]=key;
  19. }
  20. void gxDevice::upEvent( int key ){
  21. down_state[key]=false;
  22. }
  23. void gxDevice::setDownState( int key,bool down ){
  24. if( down==down_state[key] ) return;
  25. if( down ) downEvent( key );
  26. else upEvent( key );
  27. }
  28. void gxDevice::flush(){
  29. update();
  30. memset( hit_count,0,sizeof(hit_count) );
  31. put=get=0;
  32. }
  33. bool gxDevice::keyDown( int key ){
  34. update();
  35. return down_state[key];
  36. }
  37. int gxDevice::keyHit( int key ){
  38. update();
  39. int n=hit_count[key];
  40. hit_count[key]-=n;
  41. return n;
  42. }
  43. int gxDevice::getKey(){
  44. update();
  45. return get<put ? que[get++ & QUE_MASK] : 0;
  46. }
  47. float gxDevice::getAxisState( int axis ){
  48. update();
  49. return axis_states[axis];
  50. }