separate(adagate)

procedure handle_gamepad( nowTime: gldouble ) is
begin

if gamepad or joystik then

	--first, AXES:
	axes := glfwGetJoystickAxes(glfw_joystick_1, akount'access); 
	--gp(0..3), js(0..2)

	buttons := glfwGetJoystickButtons(glfw_joystick_1, bkount'access);
	--gp(0..15), js(0..7)
	-- see glfw3.ads::233

end if;


if gamepad then

	-- right stik
	axis_rx2 := axes(glfw_gamepad_axis_right_x);
	axis_ry3 := axes(glfw_gamepad_axis_right_y); --NOT on Joystik
	handle_gc_look(axis_rx2,axis_ry3); --lookdir

	-- left stik (use this for joystik)
	axis_lx0 := axes(glfw_gamepad_axis_left_x); 
	axis_ly1 := axes(glfw_gamepad_axis_left_y);
	handle_gc_move(currentTime,axis_lx0,axis_ly1); --forw/back

	-- buttons:
	btn0 := buttons(0); --jump
	btn4 := buttons(glfw_gamepad_button_left_bumper); 
	btn5 := buttons(glfw_gamepad_button_right_bumper); 


	if onIsland then

		if 
			(btn4=glfw_press or btn5=glfw_press)
			and (currenttime-pltime)>pickdwell
		then

			if mseated and neardhd and (dhdstate<5) then
				pickLeft;
			end if;
			pltime:=currentTime;
		end if;


	else

		if ((currentTime-shtime)>shootdwell) then
			if btn4=glfw_press then --shoot
				shootLeft(currentTime);
				shtime:=currentTime;
			elsif btn5=glfw_press then --shoot
				shootRight(currentTime);
				shtime:=currentTime;
			elsif btn0=glfw_press then --jump
				jumpTime := currentTime;
				pyjump:= yme;
				vyjump:=2.0;
				jumping:=true;
			end if;
		end if;

	end if;

elsif joystik then

	-- stik (use this for joystik)
	axis_lx0 := axes(glfw_gamepad_axis_left_x); 
	axis_ly1 := axes(glfw_gamepad_axis_left_y);
	handle_gc_look(axis_lx0,axis_ly1); --lookdir

	-- second, buttons:
	btn0 := buttons(0); -- bak
	btn1 := buttons(1); -- for (thumbCenter)
	btn2 := buttons(2); -- pik/shootL (thumbL)
	btn3 := buttons(3); -- pik/shootR (thumbR)
	btn4 := buttons(4); -- jump (base)

	if (btn0=glfw_press) then
		moveBackward(currentTime);
	elsif (btn1=glfw_press) then
		moveForward(currentTime);
	end if;

	if onIsland then

		if 
			(btn2=glfw_press or btn3=glfw_press)
			and (currenttime-pltime)>pickdwell
		then

			if mseated and neardhd and (dhdstate<5) then
				pickLeft;
			end if;
			pltime:=currentTime;
		end if;


	else

		if ((currentTime-shtime)>shootdwell) then
			if btn2=glfw_press then
				shootLeft(currentTime);
				shtime:=currentTime;
			elsif btn3=glfw_press then
				shootRight(currentTime);
				shtime:=currentTime;
			elsif btn4=glfw_press then
				jumpTime := currentTime;
				pyjump:= yme;
				vyjump:=2.0;
				jumping:=true;
			end if;
		end if;

	end if;


end if; --joystik

end handle_gamepad;

