BOOL engine_update() { float delta; float currentTime; currentTime = E_Sys_Milliseconds(); delta = (float) (currentTime - engine->lastRenderTime); SCRIPTING_Update(delta); WORLD_Update(delta); REN_Update(delta); engine->lastRenderTime = currentTime; return engine->isRunning; }
/** * Process the next input event. */ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) { struct engine* androidEngine = (struct engine*)app->userData; int touchCount = 0; static int previousTouchCount; int numButton; touch_t* touch; touch_t* currentTouchSet; struct TOUCHSTATE *touchstate = 0; struct TOUCHSTATE *prev_touchstate = 0; int nSourceId = AInputEvent_getSource( event ); if (nSourceId == AINPUT_SOURCE_TOUCHPAD) touchstate = engine.touchstate_pad; // GJT: For Xperia Play...and other devices? else if (nSourceId == AINPUT_SOURCE_TOUCHSCREEN) touchstate = engine.touchstate_screen; else return 0; // GJT: Volume? Keyboard? Let the system handle it... if (engine.menuVisible) { numButton = MENU_GetNumButtonsTouches(); currentTouchSet = MENU_GetCurrentButtonTouches(); } else { numButton = NUM_BUTTONS; currentTouchSet = touches; } if (engine.menuVisible || engine.controlMode == CONTROL_MODE_VIRT_PAD) { size_t pointerCount = AMotionEvent_getPointerCount(event); size_t i; for (i = 0; i < pointerCount; i++) { size_t pointerId = AMotionEvent_getPointerId(event, i); size_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; touchstate[pointerId].x = AMotionEvent_getX( event, i ); touchstate[pointerId].y = AMotionEvent_getY( event, i ); LOGI("DEBUG BEFORE x %f y %f", touchstate[pointerId].x, touchstate[pointerId].y); // Transforming from whatever screen resolution we have to the original iPhone 320*480 touchstate[pointerId].x = ( touchstate[pointerId].x - renderer.viewPortDimensions[VP_X] ) * commScale[X] ; touchstate[pointerId].y = ( touchstate[pointerId].y - renderer.viewPortDimensions[VP_Y] ) * commScale[Y] ; LOGI("DEBUG AFTER x %f y %f", touchstate[pointerId].x, touchstate[pointerId].y); touchCount++; // find which one it is closest to int minDist = INT_MAX; // allow up to 64 unit moves to be drags int minIndex = -1; int dist; touch_t *t2 = currentTouchSet; int i; for ( i = 0 ; i < numButton ; i++ ) { dist = SQUARE( t2->iphone_coo_SysPos[X] - touchstate[pointerId].x ) + SQUARE( t2->iphone_coo_SysPos[Y] - touchstate[pointerId].y ) ; LOGI("DEBUG dist %i minDist %i", dist, minDist); if ( dist < minDist ) { minDist = dist; minIndex = i; touch = t2; } t2++; } if ( minIndex != -1 ) { if (action == AMOTION_EVENT_ACTION_UP) { touch->down = 0; } else { if (action == AMOTION_EVENT_ACTION_DOWN) { } touch->down = 1; touch->dist[X] = MIN(1,(touchstate[pointerId].x - touches[minIndex].iphone_coo_SysPos[X])/touches[minIndex].iphone_size); touch->dist[Y] = MIN(1,(touches[minIndex].iphone_coo_SysPos[Y] - touchstate[pointerId].y)/touches[minIndex].iphone_size); LOGI("DEBUG minIndexIphone %i", touches[minIndex].iphone_size); } } } LOGI("DEBUG touchcount %i previous %i", touchCount, previousTouchCount); if ( touchCount == 5 && previousTouchCount != 5 ) { MENU_Set(MENU_HOME); engine.requiredSceneId = 0; } previousTouchCount = touchCount; return 1; } else { size_t pointerCount = AMotionEvent_getPointerCount(event); size_t i; for (i = 0; i < pointerCount; i++) { size_t pointerCount = AMotionEvent_getPointerCount(event); size_t pointerId = AMotionEvent_getPointerId(event, i); size_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; size_t pointerIndex = i; int historySize = AMotionEvent_getHistorySize(event); touchstate[pointerId].x = AMotionEvent_getX( event, pointerIndex ); touchstate[pointerId].y = AMotionEvent_getY( event, pointerIndex ); LOGI("DEBUG history %i", historySize); LOGI("DEBUG nomenu x %f y %f", touchstate[pointerId].x, touchstate[pointerId].y); if (historySize > 0) { //prev_touchstate[pointerId].x = AMotionEvent_getX( event, pointerIndex ); //prev_touchstate[pointerId].y = AMotionEvent_getY( event, pointerIndex ); LOGI("DEBUG nomenu prevx %f prevy %f", prev_touchstate[pointerId].x, prev_touchstate[pointerId].y); } //Transforming from whatever screen resolution we have to the original iPHone 320*480 /*touchstate[pointerId].x = ( touchstate[pointerId].x- renderer.viewPortDimensions[VP_X] ) * commScale[X] ;//* renderer.resolution ; touchstate[pointerId].y = ( touchstate[pointerId].y- renderer.viewPortDimensions[VP_Y] ) * commScale[Y] ;//* renderer.resolution; prev_touchstate[pointerId].x = ( prev_touchstate[pointerId].x- renderer.viewPortDimensions[VP_X] ) * commScale[X] ;//* renderer.resolution ; prev_touchstate[pointerId].y = ( prev_touchstate[pointerId].y- renderer.viewPortDimensions[VP_Y] ) * commScale[Y] ;//* renderer.resolution;*/ touchCount++; if (action == AMOTION_EVENT_ACTION_UP) { if (touchCount == 1) //Last finger ended touches[BUTTON_FIRE].down = 0; } else { if (action == AMOTION_EVENT_ACTION_MOVE) { //printf("m\n"); LOGI("DEBUG MOVE x %f y %f", touchstate[pointerId].x, touchstate[pointerId].y); //LOGI("DEBUG MOVE prevx %f prevy %f", prev_touchstate[pointerId].x, prev_touchstate[pointerId].y); touches[BUTTON_MOVE].down = 1; //touches[BUTTON_MOVE].dist[X] = (touchstate[pointerId].x - prev_touchstate[pointerId].x)*40/(float)320; //touches[BUTTON_MOVE].dist[Y] = (touchstate[pointerId].y - prev_touchstate[pointerId].y)*-40/(float)480; } if (action == AMOTION_EVENT_ACTION_DOWN) { int currTime = E_Sys_Milliseconds(); if (currTime-lastTouchBegan < 200) touches[BUTTON_GHOST].down = 1; lastTouchBegan = currTime ; touches[BUTTON_FIRE].down = 1; } } } if ( touchCount == 5 && previousTouchCount != 5 ) { MENU_Set(MENU_HOME); engine.requiredSceneId=0; } previousTouchCount = touchCount; return 1; } return 0; }