void MainUI::paintGL() { updateAccelerometer(); UpdateInputState(&input_state); time_update(); UpdateRunLoop(&input_state); }
const JoystickState& getState(bool update_state = true) { if (update_state) UpdateInputState(); return state; }
//----------------------------------------------------------------------------- // Name: MainDialogProc // Desc: Handles dialog messages //----------------------------------------------------------------------------- INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ) { UNREFERENCED_PARAMETER( lParam ); switch( msg ) { case WM_INITDIALOG: if( FAILED( InitDirectInput( hDlg ) ) ) { MessageBox( NULL, TEXT( "Error Initializing DirectInput" ), TEXT( "DirectInput Sample" ), MB_ICONERROR | MB_OK ); EndDialog( hDlg, 0 ); } // Set a timer to go off 30 times a second. At every timer message // the input device will be read SetTimer( hDlg, 0, 1000 / 30, NULL ); return TRUE; case WM_ACTIVATE: if( WA_INACTIVE != wParam && g_pJoystick ) { // Make sure the device is acquired, if we are gaining focus. g_pJoystick->Acquire(); } return TRUE; case WM_TIMER: // Update the input device every timer message if( FAILED( UpdateInputState( hDlg ) ) ) { KillTimer( hDlg, 0 ); MessageBox( NULL, TEXT( "Error Reading Input State. " ) \ TEXT( "The sample will now exit." ), TEXT( "DirectInput Sample" ), MB_ICONERROR | MB_OK ); EndDialog( hDlg, TRUE ); } return TRUE; case WM_COMMAND: switch( LOWORD( wParam ) ) { case IDCANCEL: EndDialog( hDlg, 0 ); return TRUE; } case WM_DESTROY: // Cleanup everything KillTimer( hDlg, 0 ); FreeDirectInput(); return TRUE; } return FALSE; // Message not handled }
void GetInput(PlainJoystickState* pjs) { UpdateInputState(dev->bus_id); pjs->kcode=kcode[dev->bus_id] | 0xF901; pjs->joy[PJAI_X1]=GetBtFromSgn(joyx[dev->bus_id]); pjs->joy[PJAI_Y1]=GetBtFromSgn(joyy[dev->bus_id]); pjs->trigger[PJTI_R]=rt[dev->bus_id]; pjs->trigger[PJTI_L]=lt[dev->bus_id]; }
extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env, jobject obj) { static bool hasSetThreadName = false; if (!hasSetThreadName) { hasSetThreadName = true; setCurrentThreadName("AndroidRender"); } if (renderer_inited) { // TODO: Look into if these locks are a perf loss { lock_guard guard(input_state.lock); input_state.pad_lstick_x = left_joystick_x_async; input_state.pad_lstick_y = left_joystick_y_async; input_state.pad_rstick_x = right_joystick_x_async; input_state.pad_rstick_y = right_joystick_y_async; UpdateInputState(&input_state); } NativeUpdate(input_state); { lock_guard guard(input_state.lock); EndInputState(&input_state); } NativeRender(); time_update(); } else { ELOG("BAD: Ended up in nativeRender even though app has quit.%s", ""); // Shouldn't really get here. Let's draw magenta. glDepthMask(GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(1.0, 0.0, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } lock_guard guard(frameCommandLock); while (!frameCommands.empty()) { FrameCommand frameCmd; frameCmd = frameCommands.front(); frameCommands.pop(); DLOG("frameCommand %s %s", frameCmd.command.c_str(), frameCmd.params.c_str()); jstring cmd = env->NewStringUTF(frameCmd.command.c_str()); jstring param = env->NewStringUTF(frameCmd.params.c_str()); env->CallVoidMethod(obj, postCommand, cmd, param); env->DeleteLocalRef(cmd); env->DeleteLocalRef(param); } }
void EmuScreen::update(InputState &input) { if (errorMessage_.size()) { screenManager()->push(new ErrorScreen( "Error loading file", errorMessage_)); errorMessage_ = ""; return; } if (invalid_) return; // First translate touches into pad input. UpdateGamepad(input); UpdateInputState(&input); // Then translate pad input into PSP pad input. static const int mapping[12][2] = { {PAD_BUTTON_A, CTRL_CROSS}, {PAD_BUTTON_B, CTRL_CIRCLE}, {PAD_BUTTON_X, CTRL_SQUARE}, {PAD_BUTTON_Y, CTRL_TRIANGLE}, {PAD_BUTTON_UP, CTRL_UP}, {PAD_BUTTON_DOWN, CTRL_DOWN}, {PAD_BUTTON_LEFT, CTRL_LEFT}, {PAD_BUTTON_RIGHT, CTRL_RIGHT}, {PAD_BUTTON_LBUMPER, CTRL_LTRIGGER}, {PAD_BUTTON_RBUMPER, CTRL_RTRIGGER}, {PAD_BUTTON_START, CTRL_START}, {PAD_BUTTON_SELECT, CTRL_SELECT}, }; for (int i = 0; i < 12; i++) { if (input.pad_buttons_down & mapping[i][0]) { __CtrlButtonDown(mapping[i][1]); } if (input.pad_buttons_up & mapping[i][0]) { __CtrlButtonUp(mapping[i][1]); } } __CtrlSetAnalog(input.pad_lstick_x, input.pad_lstick_y); if (input.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK)) { if (g_Config.bBufferedRendering) fbo_unbind(); screenManager()->push(new InGameMenuScreen()); } }
static void BackgroundInitKernel (DWORD TimeOut) { LoadMasterShipList (TaskSwitch); TaskSwitch (); InitGameKernel (); while ((GetTimeCounter () <= TimeOut) && !(GLOBAL (CurrentActivity) & CHECK_ABORT)) { UpdateInputState (); TaskSwitch (); } }
inline static void ExecuteInputPoll() { // Hm, we may hold the input_state lock for quite a while (time it takes to poll all devices)... // If that becomes an issue, maybe should poll to a copy of inputstate and only hold the lock while // copying that one to the real one? lock_guard guard(input_state.lock); input_state.pad_buttons = 0; input_state.pad_lstick_x = 0; input_state.pad_lstick_y = 0; input_state.pad_rstick_x = 0; input_state.pad_rstick_y = 0; if (host && (focused || !g_Config.bGamepadOnlyFocused)) { host->PollControllers(input_state); } UpdateInputState(&input_state); }
extern "C" void Java_com_henrikrydgard_libnative_NativeRenderer_displayRender(JNIEnv *env, jobject obj) { // Too spammy // ILOG("NativeApp.displayRender()"); if (renderer_inited) { // TODO: Look into if these locks are a perf loss { lock_guard guard(input_state.lock); pad_buttons_down |= pad_buttons_async_set; pad_buttons_down &= ~pad_buttons_async_clear; input_state.pad_buttons = pad_buttons_down; KeyQueueCopyQueue(key_queue_async, input_state.key_queue); UpdateInputState(&input_state); } { lock_guard guard(input_state.lock); input_state.pad_lstick_x = left_joystick_x_async; input_state.pad_lstick_y = left_joystick_y_async; } NativeUpdate(input_state); { lock_guard guard(input_state.lock); EndInputState(&input_state); } NativeRender(); time_update(); } else { ELOG("BAD: Ended up in nativeRender even though app has quit.%s", ""); // Shouldn't really get here. Let's draw magenta. glstate.depthWrite.set(GL_TRUE); glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(1.0, 0.0, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } if (!frameCommand.empty()) { ILOG("frameCommand %s %s", frameCommand.c_str(), frameCommandParam.c_str()); jstring cmd = env->NewStringUTF(frameCommand.c_str()); jstring param = env->NewStringUTF(frameCommandParam.c_str()); env->CallVoidMethod(obj, postCommand, cmd, param); frameCommand = ""; frameCommandParam = ""; } }
//----------------------------------------------------------------------------- // Name: MainDialogProc // Desc: Handles dialog messages //----------------------------------------------------------------------------- INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_INITDIALOG: if( FAILED( InitDirectInput( hDlg ) ) ) { MessageBox( NULL, TEXT( "Error Initializing DirectInput" ), TEXT( "DirectInput Sample" ), MB_ICONERROR | MB_OK ); EndDialog( hDlg, 0 ); } // Set a timer to go off 30 times a second. At every timer message // the input device will be read SetTimer( hDlg, 0, 1000 / 30, NULL ); return TRUE; case WM_TIMER: // Update the input device every timer message if( FAILED( UpdateInputState( hDlg ) ) ) { KillTimer( hDlg, 0 ); MessageBox( NULL, TEXT( "Error Reading Input State. " ) \ TEXT( "The sample will now exit." ), TEXT( "DirectInput Sample" ), MB_ICONERROR | MB_OK ); EndDialog( hDlg, TRUE ); } return TRUE; case WM_COMMAND: switch( LOWORD( wParam ) ) { case IDCANCEL: EndDialog( hDlg, 0 ); return TRUE; } break; case WM_DESTROY: // Cleanup everything KillTimer( hDlg, 0 ); FreeDirectInput(); return TRUE; } return FALSE; // Message not handled }
// JavaEGL extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env, jobject obj) { static bool hasSetThreadName = false; if (!hasSetThreadName) { hasSetThreadName = true; setCurrentThreadName("AndroidRender"); } if (renderer_inited) { // TODO: Look into if these locks are a perf loss { lock_guard guard(input_state.lock); input_state.pad_lstick_x = left_joystick_x_async; input_state.pad_lstick_y = left_joystick_y_async; input_state.pad_rstick_x = right_joystick_x_async; input_state.pad_rstick_y = right_joystick_y_async; UpdateInputState(&input_state); } NativeUpdate(input_state); { lock_guard guard(input_state.lock); EndInputState(&input_state); } NativeRender(graphicsContext); time_update(); } else { ELOG("BAD: Ended up in nativeRender even though app has quit.%s", ""); // Shouldn't really get here. Let's draw magenta. // TODO: Should we have GL here? glDepthMask(GL_TRUE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(1.0, 0.0, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } lock_guard guard(frameCommandLock); if (!nativeActivity) { while (!frameCommands.empty()) frameCommands.pop(); return; } ProcessFrameCommands(env); }
extern "C" void Java_com_henrikrydgard_libnative_NativeRenderer_displayRender(JNIEnv *env, jobject obj) { if (renderer_inited) { // TODO: Look into if these locks are a perf loss { lock_guard guard(input_state.lock); input_state.pad_lstick_x = left_joystick_x_async; input_state.pad_lstick_y = left_joystick_y_async; input_state.pad_rstick_x = right_joystick_x_async; input_state.pad_rstick_y = right_joystick_y_async; UpdateInputState(&input_state); } NativeUpdate(input_state); { lock_guard guard(input_state.lock); EndInputState(&input_state); } NativeRender(); time_update(); } else { ELOG("BAD: Ended up in nativeRender even though app has quit.%s", ""); // Shouldn't really get here. Let's draw magenta. glstate.depthWrite.set(GL_TRUE); glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(1.0, 0.0, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } lock_guard guard(frameCommandLock); while (!frameCommands.empty()) { FrameCommand frameCmd; frameCmd = frameCommands.front(); frameCommands.pop(); DLOG("frameCommand %s %s", frameCmd.command.c_str(), frameCmd.params.c_str()); jstring cmd = env->NewStringUTF(frameCmd.command.c_str()); jstring param = env->NewStringUTF(frameCmd.params.c_str()); env->CallVoidMethod(obj, postCommand, cmd, param); } }
void DoInput (void *pInputState, BOOLEAN resetInput) { if (resetInput) FlushInput (); do { MENU_SOUND_FLAGS soundFlags; Async_process (); TaskSwitch (); UpdateInputState (); #if DEMO_MODE || CREATE_JOURNAL if (ArrowInput != DemoInput) #endif { #if CREATE_JOURNAL JournalInput (InputState); #endif /* CREATE_JOURNAL */ } soundFlags = MenuKeysToSoundFlags (&PulsedInputState); if (MenuSounds && (soundFlags & (sound_0 | sound_1))) { SOUND S; S = MenuSounds; if (soundFlags & sound_1) S = SetAbsSoundIndex (S, MENU_SOUND_SUCCESS); PlaySoundEffect (S, 0, NotPositional (), NULL, 0); } if (inputCallback) inputCallback (); } while (((INPUT_STATE_DESC*)pInputState)->InputFunc (pInputState)); if (resetInput) FlushInput (); }
static inline void UpdateRunLoop() { UpdateScreenScale(); { { #ifdef _WIN32 lock_guard guard(input_state.lock); input_state.pad_buttons = 0; input_state.pad_lstick_x = 0; input_state.pad_lstick_y = 0; input_state.pad_rstick_x = 0; input_state.pad_rstick_y = 0; host->PollControllers(input_state); UpdateInputState(&input_state); #endif } NativeUpdate(input_state); EndInputState(&input_state); } NativeRender(); }
void ChatMainUI::clickTab(int index) { m_nChannelMenuIndex = index; m_nCurClientChId = m_showingChannels[m_nChannelMenuIndex]; //客户端私聊频道未玩家ID if(m_nCurClientChId >= ChannelType_Count) { m_nCurSeverChId = ChannelType_Personal; } else { m_nCurSeverChId = (ChannelType)m_nCurClientChId; } UpdateCurChanel(); updateChannelClose(index); showNewMsgSign(); UpdateInputState(); }
void Core_RunLoop() { while (!coreState) { time_update(); double startTime = time_now_d(); UpdateScreenScale(); { { #ifdef _WIN32 lock_guard guard(input_state.lock); input_state.pad_buttons = 0; input_state.pad_lstick_x = 0; input_state.pad_lstick_y = 0; input_state.pad_rstick_x = 0; input_state.pad_rstick_y = 0; // Temporary hack. if (GetAsyncKeyState(VK_ESCAPE)) { input_state.pad_buttons |= PAD_BUTTON_MENU; } host->PollControllers(input_state); UpdateInputState(&input_state); #endif } NativeUpdate(input_state); EndInputState(&input_state); } NativeRender(); time_update(); // Simple throttling to not burn the GPU in the menu. #ifdef _WIN32 if (globalUIState != UISTATE_INGAME) { double sleepTime = 16.666 - (time_now_d() - startTime) * 1000.0; if (sleepTime > 0.0) Sleep((int)sleepTime); GL_SwapBuffers(); } else if (!Core_IsStepping()) { GL_SwapBuffers(); } #endif } }
BOOLEAN AnyButtonPress (BOOLEAN CheckSpecial) { int i, j; (void) CheckSpecial; // Ignored UpdateInputState (); for (i = 0; i < NUM_TEMPLATES; i++) { for (j = 0; j < NUM_KEYS; j++) { if (CurrentInputState.key[i][j]) return TRUE; } } for (i = 0; i < NUM_MENU_KEYS; i++) { if (CurrentInputState.menu[i]) return TRUE; } return FALSE; }
static inline void UpdateRunLoop() { { { #ifdef _WIN32 lock_guard guard(input_state.lock); input_state.pad_buttons = 0; input_state.pad_lstick_x = 0; input_state.pad_lstick_y = 0; input_state.pad_rstick_x = 0; input_state.pad_rstick_y = 0; host->PollControllers(input_state); UpdateInputState(&input_state); #endif } NativeUpdate(input_state); EndInputState(&input_state); } if (globalUIState != UISTATE_EXIT) { NativeRender(); } }
// Pre: caller holds the graphics lock. void MeleeGameOver (void) { COUNT playerI; DWORD TimeOut; BOOLEAN PressState, ButtonState; // Show the battle result. for (playerI = 0; playerI < NUM_PLAYERS; playerI++) DrawPickMeleeFrame (playerI); #ifdef NETPLAY negotiateReadyConnections(true, NetState_inSetup); #endif TimeOut = GetTimeCounter () + (ONE_SECOND * 4); PressState = PulsedInputState.menu[KEY_MENU_SELECT] || PulsedInputState.menu[KEY_MENU_CANCEL]; do { UpdateInputState (); ButtonState = PulsedInputState.menu[KEY_MENU_SELECT] || PulsedInputState.menu[KEY_MENU_CANCEL]; if (PressState) { PressState = ButtonState; ButtonState = FALSE; } Async_process (); TaskSwitch (); } while (!(GLOBAL (CurrentActivity) & CHECK_ABORT) && (!ButtonState && (!(PlayerControl[0] & PlayerControl[1] & PSYTRON_CONTROL) || GetTimeCounter () < TimeOut))); }
void Core_RunLoop() { while (!coreState) { time_update(); double startTime = time_now_d(); UpdateScreenScale(); { { #ifdef _WIN32 lock_guard guard(input_state.lock); input_state.pad_buttons = 0; input_state.pad_lstick_x = 0; input_state.pad_lstick_y = 0; input_state.pad_rstick_x = 0; input_state.pad_rstick_y = 0; host->PollControllers(input_state); UpdateInputState(&input_state); #endif } NativeUpdate(input_state); EndInputState(&input_state); } NativeRender(); time_update(); // Simple throttling to not burn the GPU in the menu. #ifdef _WIN32 if (globalUIState != UISTATE_INGAME) { double diffTime = time_now_d() - startTime; int sleepTime = (int) (1000000.0 / 60.0) - (int) (diffTime * 1000000.0); if (sleepTime > 0) Sleep(sleepTime / 1000); GL_SwapBuffers(); } else if (!Core_IsStepping()) { GL_SwapBuffers(); } #endif } }
//----------------------------------------------------------------------------- // Name: PollingThread() // output: return value/code // Desc: Thread function that polls a new joystick every ?5ms. // It also reports thru girder how many joysticks it found //----------------------------------------------------------------------------- DWORD WINAPI PollingThread( LPVOID lpParameter ) { // space for message char cString[256] = {0}; //report no. of joysticks found and wait a sec to read it. Sleep(400); //sprintf(cString, "Found %d JoyPads", (g_joyno)); //TriggerEvent(cString); //Sleep(2000); // main polling loop while (WaitForSingleObject(DeathEvent, PollingTimeout) == WAIT_TIMEOUT) { if( FAILED(UpdateInputState()) ){ sprintf(cString, "Error Updating Joypad"); //TriggerEvent(cString); } } // exit thread return 0; }
void BlackberryMain::runMain() { bool running = true; while (running && !g_quitRequested) { input_state.mouse_valid = false; input_state.accelerometer_valid = false; while (true) { // Handle Blackberry events bps_event_t *event = NULL; bps_get_event(&event, 0); if (event == NULL) break; // Ran out of events int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { handleInput(screen_event_get_event(event)); } else if (domain == navigator_get_domain()) { switch(bps_event_get_code(event)) { case NAVIGATOR_INVOKE_TARGET: { const navigator_invoke_invocation_t *invoke = navigator_invoke_event_get_invocation(event); if(invoke) { boot_filename = navigator_invoke_invocation_get_uri(invoke)+7; // Remove file:// } } break; case NAVIGATOR_ORIENTATION: sensor_remap_coordinates(navigator_event_get_orientation_angle(event)); break; case NAVIGATOR_BACK: case NAVIGATOR_SWIPE_DOWN: NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE, KEY_DOWN)); break; case NAVIGATOR_EXIT: return; } } else if (domain == sensor_get_domain()) { if (SENSOR_ACCELEROMETER_READING == bps_event_get_code(event)) { sensor_event_get_xyz(event, &(input_state.acc.y), &(input_state.acc.x), &(input_state.acc.z)); AxisInput axis; axis.deviceId = DEVICE_ID_ACCELEROMETER; axis.flags = 0; axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X; axis.value = input_state.acc.x; NativeAxis(axis); axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y; axis.value = input_state.acc.y; NativeAxis(axis); axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z; axis.value = input_state.acc.z; NativeAxis(axis); } } } UpdateInputState(&input_state); NativeUpdate(input_state); // Work in Progress // Currently: Render to HDMI port (eg. 1080p) when in game. Render to device when in menu. // Idea: Render to all displays. Controls go to internal, game goes to external(s). if (GetUIState() == UISTATE_INGAME && !emulating) { emulating = true; switchDisplay(screen_emu); if (g_Config.iShowFPSCounter == 4) { int options = SCREEN_DEBUG_STATISTICS; screen_set_window_property_iv(screen_win[0], SCREEN_PROPERTY_DEBUG, &options); } } else if (GetUIState() != UISTATE_INGAME && emulating) { emulating = false; switchDisplay(screen_ui); } NativeRender(); EndInputState(&input_state); time_update(); // This handles VSync if (emulating) eglSwapBuffers(egl_disp[screen_emu], egl_surf[screen_emu]); else eglSwapBuffers(egl_disp[screen_ui], egl_surf[screen_ui]); } }
void EmuScreen::update(InputState &input) { globalUIState = UISTATE_INGAME; if (errorMessage_.size()) { screenManager()->push(new ErrorScreen( "Error loading file", errorMessage_)); errorMessage_ = ""; return; } if (invalid_) return; float leftstick_x = 0.0f; float leftstick_y = 0.0f; float rightstick_x = 0.0f; float rightstick_y = 0.0f; // Virtual keys. __CtrlSetRapidFire(virtKeys[VIRTKEY_RAPID_FIRE - VIRTKEY_FIRST]); // First translate touches into native pad input. // Do this no matter the value of g_Config.bShowTouchControls, some people // like to use invisible controls... // Don't force on platforms that likely don't have a touchscreen, like Win32, OSX, and Linux... // TODO: What are good ifdefs for OSX and Linux, without breaking other mobile platforms? #ifdef _WIN32 if(g_Config.bShowTouchControls) { #endif // TODO: Make new better touch buttons so we don't have to do this crap. // Copy over the mouse data from the real inputstate. fakeInputState.mouse_valid = input.mouse_valid; fakeInputState.pad_last_buttons = fakeInputState.pad_buttons; fakeInputState.pad_buttons = input.pad_buttons; memcpy(fakeInputState.pointer_down, input.pointer_down, sizeof(input.pointer_down)); memcpy(fakeInputState.pointer_x, input.pointer_x, sizeof(input.pointer_x)); memcpy(fakeInputState.pointer_y, input.pointer_y, sizeof(input.pointer_y)); fakeInputState.pad_lstick_x = 0.0f; fakeInputState.pad_lstick_y = 0.0f; fakeInputState.pad_rstick_x = 0.0f; fakeInputState.pad_rstick_y = 0.0f; UpdateGamepad(fakeInputState); UpdateInputState(&fakeInputState); for (size_t i = 0; i < ARRAY_SIZE(legacy_touch_mapping); i++) { if (fakeInputState.pad_buttons_down & legacy_touch_mapping[i].from) __CtrlButtonDown(legacy_touch_mapping[i].to); if (fakeInputState.pad_buttons_up & legacy_touch_mapping[i].from) __CtrlButtonUp(legacy_touch_mapping[i].to); } leftstick_x += fakeInputState.pad_lstick_x; leftstick_y += fakeInputState.pad_lstick_y; rightstick_x += fakeInputState.pad_rstick_x; rightstick_y += fakeInputState.pad_rstick_y; if (g_Config.bShowAnalogStick) { __CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT); __CtrlSetAnalogY(clamp1(leftstick_y), CTRL_STICK_LEFT); } __CtrlSetAnalogX(clamp1(rightstick_x), CTRL_STICK_RIGHT); __CtrlSetAnalogY(clamp1(rightstick_y), CTRL_STICK_RIGHT); // Also send the special buttons to input, since that's where they're handled. input.pad_buttons_down |= fakeInputState.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK | PAD_BUTTON_RIGHT_THUMB | PAD_BUTTON_LEFT_THUMB); input.pad_buttons_up |= fakeInputState.pad_buttons_up & (PAD_BUTTON_MENU | PAD_BUTTON_BACK | PAD_BUTTON_RIGHT_THUMB | PAD_BUTTON_LEFT_THUMB); input.pad_buttons = fakeInputState.pad_buttons; #ifdef _WIN32 } #endif // Still checking input.pad_buttons here to support the onscreen throttle button. PSP_CoreParameter().unthrottle = virtKeys[VIRTKEY_UNTHROTTLE - VIRTKEY_FIRST] || (input.pad_buttons & PAD_BUTTON_UNTHROTTLE) != 0; // Apply tilt to left stick if (g_Config.bAccelerometerToAnalogHoriz) { // TODO: Deadzone, etc. leftstick_x += clamp1(curve1(input.acc.y) * 2.0f); __CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT); } // Make sure fpsLimit starts at 0 if (PSP_CoreParameter().fpsLimit != 0 && PSP_CoreParameter().fpsLimit != 1) { PSP_CoreParameter().fpsLimit = 0; } // This is still here to support the iOS on screen back button. if (input.pad_buttons_down & (PAD_BUTTON_BACK)) { screenManager()->push(new PauseScreen()); } }
int main(int argc, char *argv[]) { std::string app_name; std::string app_name_nice; float zoom = 1.0f; bool tablet = false; bool aspect43 = false; const char *zoomenv = getenv("ZOOM"); const char *tabletenv = getenv("TABLET"); const char *ipad = getenv("IPAD"); if (zoomenv) { zoom = atof(zoomenv); } if (tabletenv) { tablet = atoi(tabletenv) ? true : false; } if (ipad) aspect43 = true; bool landscape; NativeGetAppInfo(&app_name, &app_name_nice, &landscape); // Change these to temporarily test other resolutions. aspect43 = false; tablet = false; float density = 1.0f; //zoom = 1.5f; if (landscape) { if (tablet) { pixel_xres = 1280 * zoom; pixel_yres = 800 * zoom; } else if (aspect43) { pixel_xres = 1024 * zoom; pixel_yres = 768 * zoom; } else { pixel_xres = 800 * zoom; pixel_yres = 480 * zoom; } } else { // PC development hack for more space //pixel_xres = 1580 * zoom; //pixel_yres = 1000 * zoom; if (tablet) { pixel_xres = 800 * zoom; pixel_yres = 1280 * zoom; } else if (aspect43) { pixel_xres = 768 * zoom; pixel_yres = 1024 * zoom; } else { pixel_xres = 480 * zoom; pixel_yres = 800 * zoom; } } net::Init(); #ifdef __APPLE__ // Make sure to request a somewhat modern GL context at least - the // latest supported by MacOSX (really, really sad...) // Requires SDL 2.0 (which is even more sad, as that hasn't been released yet) //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); #endif if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } #ifdef EGL if (EGL_Open()) return 1; #endif SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); if (SDL_SetVideoMode(pixel_xres, pixel_yres, 0, #ifdef USING_GLES2 SDL_SWSURFACE | SDL_FULLSCREEN #else SDL_OPENGL #endif ) == NULL) { fprintf(stderr, "SDL SetVideoMode failed: Unable to create OpenGL screen: %s\n", SDL_GetError()); SDL_Quit(); return(2); } #ifdef EGL EGL_Init(); #endif SDL_WM_SetCaption(app_name_nice.c_str(), NULL); #ifdef MAEMO SDL_ShowCursor(SDL_DISABLE); #endif #ifndef USING_GLES2 if (GLEW_OK != glewInit()) { printf("Failed to initialize glew!\n"); return 1; } if (GLEW_VERSION_2_0) { printf("OpenGL 2.0 or higher.\n"); } else { printf("Sorry, this program requires OpenGL 2.0.\n"); return 1; } #endif #ifdef _MSC_VER // VFSRegister("temp/", new DirectoryAssetReader("E:\\Temp\\")); TCHAR path[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path); PathAppend(path, (app_name + "\\").c_str()); #else // Mac / Linux char path[512]; const char *the_path = getenv("HOME"); if (!the_path) { struct passwd* pwd = getpwuid(getuid()); if (pwd) the_path = pwd->pw_dir; } strcpy(path, the_path); if (path[strlen(path)-1] != '/') strcat(path, "/"); #endif #ifdef _WIN32 NativeInit(argc, (const char **)argv, path, "D:\\", "BADCOFFEE"); #else NativeInit(argc, (const char **)argv, path, "/tmp", "BADCOFFEE"); #endif dp_xres = (float)pixel_xres * density / zoom; dp_yres = (float)pixel_yres * density / zoom; pixel_in_dps = (float)pixel_xres / dp_xres; NativeInitGraphics(); glstate.viewport.set(0, 0, pixel_xres, pixel_yres); float dp_xscale = (float)dp_xres / pixel_xres; float dp_yscale = (float)dp_yres / pixel_yres; printf("Pixels: %i x %i\n", pixel_xres, pixel_yres); printf("Virtual pixels: %i x %i\n", dp_xres, dp_yres); SDL_AudioSpec fmt; fmt.freq = 44100; fmt.format = AUDIO_S16; fmt.channels = 2; fmt.samples = 1024; fmt.callback = &mixaudio; fmt.userdata = (void *)0; if (SDL_OpenAudio(&fmt, NULL) < 0) { ELOG("Failed to open audio: %s", SDL_GetError()); return 1; } // Audio must be unpaused _after_ NativeInit() SDL_PauseAudio(0); #ifdef PANDORA // Joysticks init, we the nubs if setup as Joystick int numjoys = SDL_NumJoysticks(); if (numjoys>0) for (int i=0; i<numjoys; i++) { if (strncmp(SDL_JoystickName(i), "nub0", 4) == 0) ljoy=SDL_JoystickOpen(i); if (strncmp(SDL_JoystickName(i), "nub1", 4) == 0) rjoy=SDL_JoystickOpen(i); } #endif int framecount = 0; bool nextFrameMD = 0; float t = 0, lastT = 0; while (true) { input_state.accelerometer_valid = false; input_state.mouse_valid = true; int quitRequested = 0; SDL_Event event; while (SDL_PollEvent(&event)) { float mx = event.motion.x * dp_xscale; float my = event.motion.y * dp_yscale; if (event.type == SDL_QUIT) { quitRequested = 1; } else if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_ESCAPE) { quitRequested = 1; } } else if (event.type == SDL_MOUSEMOTION) { input_state.pointer_x[0] = mx; input_state.pointer_y[0] = my; NativeTouch(0, mx, my, 0, TOUCH_MOVE); } else if (event.type == SDL_MOUSEBUTTONDOWN) { if (event.button.button == SDL_BUTTON_LEFT) { //input_state.mouse_buttons_down = 1; input_state.pointer_down[0] = true; nextFrameMD = true; NativeTouch(0, mx, my, 0, TOUCH_DOWN); } } else if (event.type == SDL_MOUSEBUTTONUP) { if (event.button.button == SDL_BUTTON_LEFT) { input_state.pointer_down[0] = false; nextFrameMD = false; //input_state.mouse_buttons_up = 1; NativeTouch(0, mx, my, 0, TOUCH_UP); } } } if (quitRequested) break; const uint8 *keys = (const uint8 *)SDL_GetKeyState(NULL); if (keys[SDLK_ESCAPE]) break; SimulateGamepad(keys, &input_state); UpdateInputState(&input_state); NativeUpdate(input_state); NativeRender(); EndInputState(&input_state); if (framecount % 60 == 0) { // glsl_refresh(); // auto-reloads modified GLSL shaders once per second. } #ifdef EGL eglSwapBuffers(g_eglDisplay, g_eglSurface); #else if (!keys[SDLK_TAB] || t - lastT >= 1.0/60.0) { SDL_GL_SwapBuffers(); lastT = t; } #endif // Simple frame rate limiting // while (time_now() < t + 1.0f/60.0f) { // sleep_ms(0); // time_update(); // } time_update(); t = time_now(); framecount++; } // Faster exit, thanks to the OS. Remove this if you want to debug shutdown // The speed difference is only really noticable on Linux. On Windows you do notice it though #ifdef _WIN32 exit(0); #endif NativeShutdownGraphics(); SDL_PauseAudio(1); SDL_CloseAudio(); NativeShutdown(); #ifdef EGL EGL_Close(); #endif SDL_Quit(); net::Shutdown(); exit(0); return 0; }
void EmuScreen::update(InputState &input) { globalUIState = UISTATE_INGAME; if (errorMessage_.size()) { screenManager()->push(new ErrorScreen( "Error loading file", errorMessage_)); errorMessage_ = ""; return; } if (invalid_) return; // First translate touches into native pad input. // Do this no matter the value of g_Config.bShowTouchControls, some people // like to use invisible controls... // Don't force on platforms that likely don't have a touchscreen, like Win32, OSX, and Linux... // TODO: What are good ifdefs for OSX and Linux, without breaking other mobile platforms? #ifdef _WIN32 if(g_Config.bShowTouchControls) { #endif UpdateGamepad(input); UpdateInputState(&input); #ifdef _WIN32 } #endif // Then translate pad input into PSP pad input. Also, add in tilt. static const int mapping[12][2] = { {PAD_BUTTON_A, CTRL_CROSS}, {PAD_BUTTON_B, CTRL_CIRCLE}, {PAD_BUTTON_X, CTRL_SQUARE}, {PAD_BUTTON_Y, CTRL_TRIANGLE}, {PAD_BUTTON_UP, CTRL_UP}, {PAD_BUTTON_DOWN, CTRL_DOWN}, {PAD_BUTTON_LEFT, CTRL_LEFT}, {PAD_BUTTON_RIGHT, CTRL_RIGHT}, {PAD_BUTTON_LBUMPER, CTRL_LTRIGGER}, {PAD_BUTTON_RBUMPER, CTRL_RTRIGGER}, {PAD_BUTTON_START, CTRL_START}, {PAD_BUTTON_SELECT, CTRL_SELECT}, }; for (int i = 0; i < 12; i++) { if (input.pad_buttons_down & mapping[i][0]) { __CtrlButtonDown(mapping[i][1]); } if (input.pad_buttons_up & mapping[i][0]) { __CtrlButtonUp(mapping[i][1]); } } float stick_x = input.pad_lstick_x; float stick_y = input.pad_lstick_y; float rightstick_x = input.pad_rstick_x; float rightstick_y = input.pad_rstick_y; I18NCategory *s = GetI18NCategory("Screen"); // Apply tilt to left stick if (g_Config.bAccelerometerToAnalogHoriz) { // TODO: Deadzone, etc. stick_x += clamp1(curve1(input.acc.y) * 2.0f); stick_x = clamp1(stick_x); } __CtrlSetAnalog(stick_x, stick_y, 0); __CtrlSetAnalog(rightstick_x, rightstick_x, 1); if (PSP_CoreParameter().fpsLimit != 2) { // Don't really need to show these, it's pretty obvious what unthrottle does, // in contrast to the three state toggle /* if (input.pad_buttons_down & PAD_BUTTON_UNTHROTTLE) { osm.Show(s->T("unlimited", "Speed: unlimited!"), 1.0, 0x50E0FF); } if (input.pad_buttons_up & PAD_BUTTON_UNTHROTTLE) { osm.Show(s->T("standard", "Speed: standard"), 1.0); }*/ } if (input.pad_buttons & PAD_BUTTON_UNTHROTTLE) { PSP_CoreParameter().unthrottle = true; } else { PSP_CoreParameter().unthrottle = false; } // Make sure fpsLimit starts at 0 if (PSP_CoreParameter().fpsLimit != 0 && PSP_CoreParameter().fpsLimit != 1 && PSP_CoreParameter().fpsLimit != 2) { PSP_CoreParameter().fpsLimit = 0; } //Toggle between 3 different states of fpsLimit if (input.pad_buttons_down & PAD_BUTTON_LEFT_THUMB) { if (PSP_CoreParameter().fpsLimit == 0) { PSP_CoreParameter().fpsLimit = 1; osm.Show(s->T("fixed", "Speed: fixed"), 1.0); } else if (PSP_CoreParameter().fpsLimit == 1) { PSP_CoreParameter().fpsLimit = 2; osm.Show(s->T("unlimited", "Speed: unlimited!"), 1.0, 0x50E0FF); } else if (PSP_CoreParameter().fpsLimit == 2) { PSP_CoreParameter().fpsLimit = 0; osm.Show(s->T("standard", "Speed: standard"), 1.0); } } if (input.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK | PAD_BUTTON_RIGHT_THUMB)) { if (g_Config.bBufferedRendering) fbo_unbind(); screenManager()->push(new PauseScreen()); } }
void EmuScreen::update(InputState &input) { globalUIState = UISTATE_INGAME; if (errorMessage_.size()) { screenManager()->push(new ErrorScreen( "Error loading file", errorMessage_)); errorMessage_ = ""; return; } if (invalid_) return; // First translate touches into native pad input. if (g_Config.bShowTouchControls) UpdateGamepad(input); UpdateInputState(&input); // Then translate pad input into PSP pad input. Also, add in tilt. static const int mapping[12][2] = { {PAD_BUTTON_A, CTRL_CROSS}, {PAD_BUTTON_B, CTRL_CIRCLE}, {PAD_BUTTON_X, CTRL_SQUARE}, {PAD_BUTTON_Y, CTRL_TRIANGLE}, {PAD_BUTTON_UP, CTRL_UP}, {PAD_BUTTON_DOWN, CTRL_DOWN}, {PAD_BUTTON_LEFT, CTRL_LEFT}, {PAD_BUTTON_RIGHT, CTRL_RIGHT}, {PAD_BUTTON_LBUMPER, CTRL_LTRIGGER}, {PAD_BUTTON_RBUMPER, CTRL_RTRIGGER}, {PAD_BUTTON_START, CTRL_START}, {PAD_BUTTON_SELECT, CTRL_SELECT}, }; for (int i = 0; i < 12; i++) { if (input.pad_buttons_down & mapping[i][0]) { __CtrlButtonDown(mapping[i][1]); } if (input.pad_buttons_up & mapping[i][0]) { __CtrlButtonUp(mapping[i][1]); } } float stick_x = input.pad_lstick_x; float stick_y = input.pad_lstick_y; // Apply tilt if (g_Config.bAccelerometerToAnalogHoriz) { // TODO: Deadzone, etc. stick_x += clamp1(curve1(input.acc.y) * 2.0f); stick_x = clamp1(stick_x); } __CtrlSetAnalog(stick_x, stick_y); if (input.pad_buttons & PAD_BUTTON_LEFT_THUMB) { PSP_CoreParameter().unthrottle = true; } else { PSP_CoreParameter().unthrottle = false; } if (input.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK | PAD_BUTTON_RIGHT_THUMB)) { if (g_Config.bBufferedRendering) fbo_unbind(); screenManager()->push(new PauseScreen()); } }
int main(int argc, char *argv[]) { std::string app_name; std::string app_name_nice; bool landscape; NativeGetAppInfo(&app_name, &app_name_nice, &landscape); net::Init(); #ifdef __APPLE__ // Make sure to request a somewhat modern GL context at least - the // latest supported by MacOSX (really, really sad...) // Requires SDL 2.0 // We really should upgrade to SDL 2.0 soon. //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); #endif if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } #ifdef EGL if (EGL_Open()) return 1; #endif SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); int mode; #ifdef USING_GLES2 mode = SDL_SWSURFACE | SDL_FULLSCREEN; #else mode = SDL_OPENGL; for (int i = 1; i < argc; i++) if (!strcmp(argv[i],"--fullscreen")) mode |= SDL_FULLSCREEN; #endif if (mode & SDL_FULLSCREEN) { const SDL_VideoInfo* info = SDL_GetVideoInfo(); pixel_xres = info->current_w; pixel_yres = info->current_h; g_Config.bFullScreen = true; } else { // set a sensible default resolution (2x) pixel_xres = 480 * 2; pixel_yres = 272 * 2; g_Config.bFullScreen = false; } dp_xres = (float)pixel_xres; dp_yres = (float)pixel_yres; if (SDL_SetVideoMode(pixel_xres, pixel_yres, 0, mode) == NULL) { fprintf(stderr, "SDL SetVideoMode failed: Unable to create OpenGL screen: %s\n", SDL_GetError()); SDL_Quit(); return(2); } #ifdef EGL EGL_Init(); #endif SDL_WM_SetCaption((app_name_nice + " " + PPSSPP_GIT_VERSION).c_str(), NULL); #ifdef MAEMO SDL_ShowCursor(SDL_DISABLE); #endif #ifndef USING_GLES2 if (GLEW_OK != glewInit()) { printf("Failed to initialize glew!\n"); return 1; } if (GLEW_VERSION_2_0) { printf("OpenGL 2.0 or higher.\n"); } else { printf("Sorry, this program requires OpenGL 2.0.\n"); return 1; } #endif #ifdef _MSC_VER // VFSRegister("temp/", new DirectoryAssetReader("E:\\Temp\\")); TCHAR path[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path); PathAppend(path, (app_name + "\\").c_str()); #else // Mac / Linux char path[512]; const char *the_path = getenv("HOME"); if (!the_path) { struct passwd* pwd = getpwuid(getuid()); if (pwd) the_path = pwd->pw_dir; } strcpy(path, the_path); if (path[strlen(path)-1] != '/') strcat(path, "/"); #endif #ifdef _WIN32 NativeInit(argc, (const char **)argv, path, "D:\\", "BADCOFFEE"); #else NativeInit(argc, (const char **)argv, path, "/tmp", "BADCOFFEE"); #endif pixel_in_dps = (float)pixel_xres / dp_xres; float dp_xscale = (float)dp_xres / pixel_xres; float dp_yscale = (float)dp_yres / pixel_yres; g_dpi_scale = dp_xres / (float)pixel_xres; printf("Pixels: %i x %i\n", pixel_xres, pixel_yres); printf("Virtual pixels: %i x %i\n", dp_xres, dp_yres); NativeInitGraphics(); SDL_AudioSpec fmt; fmt.freq = 44100; fmt.format = AUDIO_S16; fmt.channels = 2; fmt.samples = 2048; fmt.callback = &mixaudio; fmt.userdata = (void *)0; if (SDL_OpenAudio(&fmt, NULL) < 0) ELOG("Failed to open audio: %s", SDL_GetError()); // Audio must be unpaused _after_ NativeInit() SDL_PauseAudio(0); #ifdef PANDORA int numjoys = SDL_NumJoysticks(); // Joysticks init, we the nubs if setup as Joystick if (numjoys > 0) { ljoy = SDL_JoystickOpen(0); if (numjoys > 1) rjoy = SDL_JoystickOpen(1); } #else joystick = new SDLJoystick(); #endif EnableFZ(); int framecount = 0; float t = 0; float lastT = 0; while (true) { input_state.accelerometer_valid = false; input_state.mouse_valid = true; int quitRequested = 0; SDL_Event event; while (SDL_PollEvent(&event)) { float mx = event.motion.x * dp_xscale; float my = event.motion.y * dp_yscale; switch (event.type) { case SDL_QUIT: quitRequested = 1; break; case SDL_KEYDOWN: { int k = event.key.keysym.sym; KeyInput key; key.flags = KEY_DOWN; key.keyCode = KeyMapRawSDLtoNative.find(k)->second; key.deviceId = DEVICE_ID_KEYBOARD; NativeKey(key); break; } case SDL_KEYUP: { int k = event.key.keysym.sym; KeyInput key; key.flags = KEY_UP; key.keyCode = KeyMapRawSDLtoNative.find(k)->second; key.deviceId = DEVICE_ID_KEYBOARD; NativeKey(key); break; } case SDL_MOUSEBUTTONDOWN: switch (event.button.button) { case SDL_BUTTON_LEFT: { input_state.pointer_x[0] = mx; input_state.pointer_y[0] = my; //input_state.mouse_buttons_down = 1; input_state.pointer_down[0] = true; input_state.mouse_valid = true; TouchInput input; input.x = mx; input.y = my; input.flags = TOUCH_DOWN; input.id = 0; NativeTouch(input); KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_DOWN); NativeKey(key); } break; case SDL_BUTTON_RIGHT: { KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_DOWN); NativeKey(key); } break; case SDL_BUTTON_WHEELUP: { KeyInput key; key.deviceId = DEVICE_ID_MOUSE; key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; key.flags = KEY_DOWN; NativeKey(key); } break; case SDL_BUTTON_WHEELDOWN: { KeyInput key; key.deviceId = DEVICE_ID_MOUSE; key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; key.flags = KEY_DOWN; NativeKey(key); } break; } break; case SDL_MOUSEMOTION: if (input_state.pointer_down[0]) { input_state.pointer_x[0] = mx; input_state.pointer_y[0] = my; input_state.mouse_valid = true; TouchInput input; input.x = mx; input.y = my; input.flags = TOUCH_MOVE; input.id = 0; NativeTouch(input); } break; case SDL_MOUSEBUTTONUP: switch (event.button.button) { case SDL_BUTTON_LEFT: { input_state.pointer_x[0] = mx; input_state.pointer_y[0] = my; input_state.pointer_down[0] = false; input_state.mouse_valid = true; //input_state.mouse_buttons_up = 1; TouchInput input; input.x = mx; input.y = my; input.flags = TOUCH_UP; input.id = 0; NativeTouch(input); KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_UP); NativeKey(key); } break; case SDL_BUTTON_RIGHT: { KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_UP); NativeKey(key); } break; case SDL_BUTTON_WHEELUP: { KeyInput key; key.deviceId = DEVICE_ID_DEFAULT; key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; key.flags = KEY_UP; NativeKey(key); } break; case SDL_BUTTON_WHEELDOWN: { KeyInput key; key.deviceId = DEVICE_ID_DEFAULT; key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; key.flags = KEY_UP; NativeKey(key); } break; } break; default: joystick->ProcessInput(event); break; } } if (quitRequested) break; const uint8 *keys = (const uint8 *)SDL_GetKeyState(NULL); SimulateGamepad(keys, &input_state); UpdateInputState(&input_state); NativeUpdate(input_state); NativeRender(); #ifndef MAEMO if (lastUIState != globalUIState) { lastUIState = globalUIState; if (lastUIState == UISTATE_INGAME && g_Config.bFullScreen && !g_Config.bShowTouchControls) SDL_ShowCursor(SDL_DISABLE); if (lastUIState != UISTATE_INGAME && g_Config.bFullScreen) SDL_ShowCursor(SDL_ENABLE); } #endif EndInputState(&input_state); if (framecount % 60 == 0) { // glsl_refresh(); // auto-reloads modified GLSL shaders once per second. } #ifdef EGL eglSwapBuffers(g_eglDisplay, g_eglSurface); #else if (!keys[SDLK_TAB] || t - lastT >= 1.0/60.0) { SDL_GL_SwapBuffers(); lastT = t; } #endif time_update(); t = time_now(); framecount++; } #ifndef PANDORA delete joystick; joystick = NULL; #endif // Faster exit, thanks to the OS. Remove this if you want to debug shutdown // The speed difference is only really noticable on Linux. On Windows you do notice it though #ifdef _WIN32 exit(0); #endif NativeShutdownGraphics(); SDL_PauseAudio(1); SDL_CloseAudio(); NativeShutdown(); #ifdef EGL EGL_Close(); #endif SDL_Quit(); net::Shutdown(); exit(0); return 0; }
// Entry Point int main(int argc, char *argv[]) { static screen_context_t screen_cxt; // Receive events from window manager screen_create_context(&screen_cxt, 0); //Initialise Blackberry Platform Services bps_initialize(); net::Init(); init_GLES2(screen_cxt); #ifdef BLACKBERRY10 // Dev Alpha: 1280x768, 4.2", 356DPI, 0.6f scale int dpi; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_DPI, &dpi); #else // Playbook: 1024x600, 7", 170DPI, 1.25f scale int screen_phys_size[2]; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size); int screen_resolution[2]; screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution); double diagonal_pixels = sqrt(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1]); double diagonal_inches = 0.0393700787 * sqrt(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1]); int dpi = (int)(diagonal_pixels / diagonal_inches + 0.5); #endif float dpi_scale = 213.6f / dpi; dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale); NativeInit(argc, (const char **)argv, "data/", "/accounts/1000/shared", "BADCOFFEE"); NativeInitGraphics(); screen_request_events(screen_cxt); navigator_request_events(0); dialog_request_events(0); #ifdef BLACKBERRY10 vibration_request_events(0); #endif BlackberryAudio* audio = new BlackberryAudio(); InputState input_state; bool running = true; while (running) { input_state.mouse_valid = false; input_state.accelerometer_valid = false; SimulateGamepad(&input_state); while (true) { // Handle Blackberry events bps_event_t *event = NULL; bps_get_event(&event, 0); if (event == NULL) break; // Ran out of events int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { int screen_val, buttons, pointerId; int pair[2]; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pair); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pointerId); input_state.mouse_valid = true; switch(screen_val) { // Touchscreen case SCREEN_EVENT_MTOUCH_TOUCH: case SCREEN_EVENT_MTOUCH_RELEASE: // Up, down input_state.pointer_down[pointerId] = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH); case SCREEN_EVENT_MTOUCH_MOVE: input_state.pointer_x[pointerId] = pair[0] * dpi_scale; input_state.pointer_y[pointerId] = pair[1] * dpi_scale; break; // Mouse, Simulator case SCREEN_EVENT_POINTER: screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &buttons); if (buttons == SCREEN_LEFT_MOUSE_BUTTON) { // Down input_state.pointer_x[pointerId] = pair[0] * dpi_scale; input_state.pointer_y[pointerId] = pair[1] * dpi_scale; input_state.pointer_down[pointerId] = true; } else if (input_state.pointer_down[pointerId]) { // Up input_state.pointer_x[pointerId] = pair[0] * dpi_scale; input_state.pointer_y[pointerId] = pair[1] * dpi_scale; input_state.pointer_down[pointerId] = false; } break; // Keyboard case SCREEN_EVENT_KEYBOARD: int flags, value; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &value); if (flags & (KEY_DOWN | KEY_SYM_VALID)) { for (int b = 0; b < 14; b++) { if (value == buttonMappings[b]) input_state.pad_buttons |= (1<<b); } } break; } } else if (domain == navigator_get_domain()) { switch(bps_event_get_code(event)) { case NAVIGATOR_BACK: case NAVIGATOR_SWIPE_DOWN: input_state.pad_buttons |= PAD_BUTTON_MENU; break; case NAVIGATOR_EXIT: running = false; break; } } } UpdateInputState(&input_state); NativeUpdate(input_state); EndInputState(&input_state); NativeRender(); // On Blackberry, this handles VSync for us eglSwapBuffers(egl_disp, egl_surf); } screen_stop_events(screen_cxt); bps_shutdown(); NativeShutdownGraphics(); delete audio; NativeShutdown(); kill_GLES2(); net::Shutdown(); screen_destroy_context(screen_cxt); exit(0); return 0; }
BOOLEAN DoConfirmExit (void) { BOOLEAN result; if (PlayingTrack ()) PauseTrack (); LockMutex (GraphicsLock); { RECT r; STAMP s; RECT ctxRect; CONTEXT oldContext; RECT oldRect; BOOLEAN response = FALSE, done; oldContext = SetContext (ScreenContext); GetContextClipRect (&oldRect); SetContextClipRect (NULL); GetContextClipRect (&ctxRect); r.extent.width = CONFIRM_WIN_WIDTH + 4; r.extent.height = CONFIRM_WIN_HEIGHT + 4; r.corner.x = (ctxRect.extent.width - r.extent.width) >> 1; r.corner.y = (ctxRect.extent.height - r.extent.height) >> 1; s = SaveContextFrame (&r); SetSystemRect (&r); DrawConfirmationWindow (response); FlushGraphics (); FlushInput (); done = FALSE; do { // Forbid recursive calls or pausing here! ExitRequested = FALSE; GamePaused = FALSE; UpdateInputState (); if (GLOBAL (CurrentActivity) & CHECK_ABORT) { // something else triggered an exit done = TRUE; response = TRUE; } else if (PulsedInputState.menu[KEY_MENU_SELECT]) { done = TRUE; PlayMenuSound (MENU_SOUND_SUCCESS); } else if (PulsedInputState.menu[KEY_MENU_CANCEL]) { done = TRUE; response = FALSE; } else if (PulsedInputState.menu[KEY_MENU_LEFT] || PulsedInputState.menu[KEY_MENU_RIGHT]) { response = !response; DrawConfirmationWindow (response); PlayMenuSound (MENU_SOUND_MOVE); } SleepThread (ONE_SECOND / 30); } while (!done); // Restore the screen under the confirmation window DrawStamp (&s); DestroyDrawable (ReleaseDrawable (s.frame)); ClearSystemRect (); if (response || (GLOBAL (CurrentActivity) & CHECK_ABORT)) { result = TRUE; GLOBAL (CurrentActivity) |= CHECK_ABORT; } else { result = FALSE; } ExitRequested = FALSE; GamePaused = FALSE; FlushInput (); SetContextClipRect (&oldRect); SetContext (oldContext); } UnlockMutex (GraphicsLock); if (PlayingTrack ()) ResumeTrack (); return (result); }
extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(JNIEnv *env, jobject obj, jobject _surf) { ANativeWindow *wnd = ANativeWindow_fromSurface(env, _surf); WLOG("runEGLRenderLoop. display_xres=%d display_yres=%d", display_xres, display_yres); if (wnd == nullptr) { ELOG("Error: Surface is null."); return false; } AndroidEGLGraphicsContext *graphicsContext = new AndroidEGLGraphicsContext(); if (!graphicsContext->Init(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format)) { ELOG("Failed to initialize graphics context."); delete graphicsContext; return false; } if (!renderer_inited) { NativeInitGraphics(graphicsContext); renderer_inited = true; } exitRenderLoop = false; renderLoopRunning = true; while (!exitRenderLoop) { static bool hasSetThreadName = false; if (!hasSetThreadName) { hasSetThreadName = true; setCurrentThreadName("AndroidRender"); } // TODO: Look into if these locks are a perf loss { lock_guard guard(input_state.lock); input_state.pad_lstick_x = left_joystick_x_async; input_state.pad_lstick_y = left_joystick_y_async; input_state.pad_rstick_x = right_joystick_x_async; input_state.pad_rstick_y = right_joystick_y_async; UpdateInputState(&input_state); } NativeUpdate(input_state); { lock_guard guard(input_state.lock); EndInputState(&input_state); } NativeRender(graphicsContext); time_update(); graphicsContext->SwapBuffers(); ProcessFrameCommands(env); } ILOG("After render loop."); g_gameInfoCache->WorkQueue()->Flush(); NativeDeviceLost(); ILOG("NativeDeviceLost completed."); NativeShutdownGraphics(); renderer_inited = false; graphicsContext->Shutdown(); renderLoopRunning = false; WLOG("Render loop function exited."); return true; }