void eUSPInstance::Update(int32_t result)
{
	pp::Module::Get()->core()->CallOnMainThread(17, callback.NewRequiredCallback(&eUSPInstance::Update));
	Handler()->OnLoop();
	audio.Update();
	Draw();
}
void eUSPInstance::Update(int32_t result)
{
	pp::Module::Get()->core()->CallOnMainThread(17, callback.NewCallback(&eUSPInstance::Update));
	if(gamepad)
	{
		PP_GamepadsSampleData gamepad_data;
		gamepad->Sample(pp_instance(), &gamepad_data);
		UpdateGamepads(gamepad_data, gamepad_data_prev);
		gamepad_data_prev = gamepad_data;
	}
	Handler()->OnLoop();
	audio.Update();
	Draw();
}
Beispiel #3
0
  void RenderLoop(int32_t) {

    screen_width = width_;
    screen_height = height_;

    glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    if (rend_framePending()) {
      while (!rend_single_frame()) ;
      printf("Rendered frame\n");
    }

    printf("Swapping buffers\n");
    context_.SwapBuffers(
        callback_factory_.NewCallback(&HelloWorldInstance::RenderLoop));
  }
bool eUSPInstance::SpecialKeyDown(const pp::KeyboardInputEvent event)
{
	int key = event.GetKeyCode();
	enum { K_F12 = 123 };
	if(key == K_F12)
	{
		Handler()->OnAction(A_RESET);
		return true;
	}
	else if(key == 'F' && event.GetModifiers()&PP_INPUTEVENT_MODIFIER_CONTROLKEY)
	{
		full_screen.SetFullscreen(!full_screen.IsFullscreen());
		if(!mouse_locked)
		{
			LockMouse(callback.NewRequiredCallback(&eUSPInstance::DidLockMouse));
		}
		return true;
	}
	return false;
}
bool eUSPInstance::HandleInputEvent(const pp::InputEvent& ev)
{
	switch(ev.GetType())
	{
	case PP_INPUTEVENT_TYPE_KEYDOWN:
		{
			pp::KeyboardInputEvent event(ev);
			if(SpecialKeyDown(event))
				return true;
			int key = event.GetKeyCode();
			dword flags = KF_DOWN|OpJoyKeyFlags();
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, flags);
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_KEYUP:
		{
			pp::KeyboardInputEvent event(ev);
			int key = event.GetKeyCode();
			dword flags = 0;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_ALTKEY)		flags |= KF_ALT;
			if(event.GetModifiers()&PP_INPUTEVENT_MODIFIER_SHIFTKEY)	flags |= KF_SHIFT;
			TranslateKey(key, flags);
			if(key || flags)
			{
				Handler()->OnKey(key, OpJoyKeyFlags());
				return true;
			}
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEMOVE:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			float z = OpZoom();
			float sx, sy;
			GetScaleWithAspectRatio43(&sx, &sy, size.width(), size.height());
			float scale_x = 320.0f/size.width()/sx/z;
			float scale_y = 240.0f/size.height()/sy/z;
			mouse_delta += eMouseDelta(event.GetMovement(), scale_x, scale_y);
			int dx = mouse_delta.x;
			int dy = mouse_delta.y;
			if(dx || dy)
			{
				mouse_delta.x -= dx;
				mouse_delta.y -= dy;
				Handler()->OnMouse(MA_MOVE, dx, -dy);
			}
			return true;
		}
		break;
	case PP_INPUTEVENT_TYPE_MOUSEDOWN:
		if(!mouse_locked)
		{
			LockMouse(callback.NewCallback(&eUSPInstance::DidLockMouse));
		}
		//no break
	case PP_INPUTEVENT_TYPE_MOUSEUP:
		if(mouse_locked)
		{
			pp::MouseInputEvent event(ev);
			Handler()->OnMouse(MA_BUTTON, event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT, ev.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
			return true;
		}
		break;
	default:
		break;
	}
	return false;
}