SHARE
TWEET

Untitled

a guest Jul 16th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. static struct {
  3.     pthread_mutex_t mutex; // this mutex is locked while not running frame, used for events synchronization
  4.     pthread_mutex_t framemutex; // this mutex is locked while engine is running and unlocked while it reading events, used for pause in background.
  5.     event_t queue[ANDROID_MAX_EVENTS];
  6.     volatile int count;
  7.     float mousex, mousey;
  8. } events = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER };
  9.  
  10. #define Android_Lock() pthread_mutex_lock(&events.mutex);
  11. #define Android_Unlock() pthread_mutex_unlock(&events.mutex);
  12. #define Android_PushEvent() Android_Unlock()
  13.  
  14. void Android_RunEvents()
  15. {
  16.     Android_Lock();
  17.     pthread_mutex_unlock( &events.framemutex );
  18.  
  19.     for( int i = 0; i < events.count; i++ )
  20.     {
  21.         event_t *event = events.queue + i;
  22.        
  23.         switch( event->type )
  24.         {
  25.         case event_touchmotion:
  26.             g_Touch.TouchMotion( event );
  27.             break;
  28.         case event_touchdown:
  29.             g_Touch.ButtonPress( event );
  30.             break;
  31.         case event_touchup:
  32.             g_Touch.ButtonPress( event );
  33.             break;
  34.         }
  35.     }
  36.     events.count = 0;
  37.    
  38.     Android_Unlock();
  39.     pthread_mutex_lock( &events.framemutex );
  40. }
  41.  
  42. DLLEXPORT int TouchEvent( int touchDevId, int fingerid, int x, int y, int action )
  43. {
  44.     event_t *ev = Android_AllocEvent();
  45.     switch( action )
  46.     {
  47.         case ACTION_DOWN:
  48.             ev->type = event_touchdown;
  49.         break;
  50.         case ACTION_UP:
  51.             ev->type = event_touchup;
  52.         break;
  53.         case ACTION_MOVE:
  54.             ev->type = event_touchmotion;
  55.             ev->touchDevId = touchDevId;
  56.         break;
  57.         default: break;
  58.     }
  59.  
  60.     ev->x = x;
  61.     ev-> y = y;
  62.     ev->fingerid = fingerid;
  63.     LogPrintf( "TouchEvent, %d, %d", x, y );
  64.  
  65.     Android_PushEvent();
  66. }
  67.  
  68. void CTouchControls::TouchMotion( event_t *ev ) //g_Touch
  69. {
  70.     float x = ev->x / screen_w;
  71.     float y = ev->y / screen_h;
  72.  
  73.     LogPrintf( "TouchMotion, %f, %f", x, y );
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top