/* * Starting point for the module. We do not use main since it would * collide with main in libppapi_cpp. */ int main(int argc, char *argv[]) { fprintf(stdout,"Started main.\n"); g_pCore = (PPB_Core*)PSGetInterface(PPB_CORE_INTERFACE); g_pFullscreen = (PPB_Fullscreen*)PSGetInterface(PPB_FULLSCREEN_INTERFACE); g_pGraphics2D = (PPB_Graphics2D*)PSGetInterface(PPB_GRAPHICS_2D_INTERFACE); g_pInstance = (PPB_Instance*)PSGetInterface(PPB_INSTANCE_INTERFACE); g_pImageData = (PPB_ImageData*)PSGetInterface(PPB_IMAGEDATA_INTERFACE); g_pView = (PPB_View*)PSGetInterface(PPB_VIEW_INTERFACE); g_pInputEvent = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE); g_pKeyboardInput = (PPB_KeyboardInputEvent*) PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE); g_pMouseInput = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE); g_pTouchInput = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE); PSEventSetFilter(PSE_ALL); while (1) { /* Process all waiting events without blocking */ PSEvent* event; while ((event = PSEventTryAcquire()) != NULL) { ProcessEvent(event); PSEventRelease(event); } /* Render a frame, blocking until complete. */ if (g_Context.bound) { Render(); } } return 0; }
// Starting point for the module. We do not use main since it would // collide with main in libppapi_cpp. int app_main(int argc, char* argv[]) { SimpleTemplate app; while (app.isRunning()) { PSEvent* ps_event; // Consume all available events. while ((ps_event = PSEventTryAcquire()) != NULL) { app.HandleEvent(ps_event); PSEventRelease(ps_event); } } return 0; }
void NACL_PumpEvents(_THIS) { PSEvent* ps_event; PP_Resource event; PP_InputEvent_Type type; PP_InputEvent_Modifier modifiers; struct PP_Rect rect; struct PP_FloatPoint fp; struct PP_Point location; struct PP_Var var; const char *str; char text[64]; Uint32 str_len; SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata; SDL_Mouse *mouse = SDL_GetMouse(); if (driverdata->window) { while ((ps_event = PSEventTryAcquire()) != NULL) { event = ps_event->as_resource; switch(ps_event->type) { /* From DidChangeView, contains a view resource */ case PSE_INSTANCE_DIDCHANGEVIEW: driverdata->ppb_view->GetRect(event, &rect); NACL_SetScreenResolution(rect.size.width, rect.size.height, SDL_PIXELFORMAT_UNKNOWN); // FIXME: Rebuild context? See life.c UpdateContext break; /* From HandleInputEvent, contains an input resource. */ case PSE_INSTANCE_HANDLEINPUT: type = driverdata->ppb_input_event->GetType(event); modifiers = driverdata->ppb_input_event->GetModifiers(event); switch(type) { case PP_INPUTEVENT_TYPE_MOUSEDOWN: SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event))); break; case PP_INPUTEVENT_TYPE_MOUSEUP: SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event))); break; case PP_INPUTEVENT_TYPE_WHEEL: /* FIXME: GetTicks provides high resolution scroll events */ fp = driverdata->ppb_wheel_input_event->GetDelta(event); SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y, SDL_MOUSEWHEEL_NORMAL); break; case PP_INPUTEVENT_TYPE_MOUSEENTER: case PP_INPUTEVENT_TYPE_MOUSELEAVE: /* FIXME: Mouse Focus */ break; case PP_INPUTEVENT_TYPE_MOUSEMOVE: location = driverdata->ppb_mouse_input_event->GetPosition(event); SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, location.x, location.y); break; case PP_INPUTEVENT_TYPE_TOUCHSTART: case PP_INPUTEVENT_TYPE_TOUCHMOVE: case PP_INPUTEVENT_TYPE_TOUCHEND: case PP_INPUTEVENT_TYPE_TOUCHCANCEL: /* FIXME: Touch events */ break; case PP_INPUTEVENT_TYPE_KEYDOWN: SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event))); break; case PP_INPUTEVENT_TYPE_KEYUP: SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event))); break; case PP_INPUTEVENT_TYPE_CHAR: var = driverdata->ppb_keyboard_input_event->GetCharacterText(event); str = driverdata->ppb_var->VarToUtf8(var, &str_len); /* str is not null terminated! */ if ( str_len >= SDL_arraysize(text) ) { str_len = SDL_arraysize(text) - 1; } SDL_strlcpy(text, str, str_len ); text[str_len] = '\0'; SDL_SendKeyboardText(text); /* FIXME: Do we have to handle ref counting? driverdata->ppb_var->Release(var);*/ break; default: break; } break; /* From HandleMessage, contains a PP_Var. */ case PSE_INSTANCE_HANDLEMESSAGE: break; /* From DidChangeFocus, contains a PP_Bool with the current focus state. */ case PSE_INSTANCE_DIDCHANGEFOCUS: break; /* When the 3D context is lost, no resource. */ case PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST: break; /* When the mouse lock is lost. */ case PSE_MOUSELOCK_MOUSELOCKLOST: break; default: break; } PSEventRelease(ps_event); } } }
void input_poll(void) { SDL_Event evt; int ino, key; #ifdef __native_client__ { /* Process all waiting events without blocking */ PSEvent* event = NULL; while ((event = PSEventTryAcquire()) != NULL) { ProcessEvent(event); PSEventRelease(event); } } #endif while(SDL_PollEvent(&evt)) { switch(evt.type) { case SDL_KEYDOWN: case SDL_KEYUP: { key = evt.key.keysym.sym; #ifndef __SDLSHIM__ static uint8_t shiftstates = 0; extern bool freezeframe; if (console.IsVisible() && !IsNonConsoleKey(key)) { if (key == SDLK_LSHIFT) { if (evt.type == SDL_KEYDOWN) shiftstates |= LEFTMASK; else shiftstates &= ~LEFTMASK; } else if (key == SDLK_RSHIFT) { if (evt.type == SDL_KEYDOWN) shiftstates |= RIGHTMASK; else shiftstates &= ~RIGHTMASK; } else { int ch = key; if (shiftstates != 0) { ch = toupper(ch); if (ch == '.') ch = '>'; if (ch == '-') ch = '_'; if (ch == '/') ch = '?'; if (ch == '1') ch = '!'; } if (evt.type == SDL_KEYDOWN) console.HandleKey(ch); else console.HandleKeyRelease(ch); } } else #endif // __SDLSHIM__ { ino = mappings[key]; if (ino != 0xff) inputs[ino] = (evt.type == SDL_KEYDOWN); if (evt.type == SDL_KEYDOWN) { if (Replay::IsPlaying() && ino <= LASTCONTROLKEY) { stat("user interrupt - stopping playback of replay"); Replay::end_playback(); memset(inputs, 0, sizeof(inputs)); inputs[ino] = true; } #ifndef __SDLSHIM__ if (key == '`') // bring up console { if (!freezeframe) { sound(SND_SWITCH_WEAPON); console.SetVisible(true); } } else #endif { last_sdl_key = key; } } } } break; case SDL_QUIT: { inputs[ESCKEY] = true; game.running = false; } break; } } }