separate( adagate )

procedure getKeyInputs( 
	mainWin : access GLFWwindow
	) is

	nowTime, deltaTime : gldouble;
	hdang: float;
	slewsec: gldouble;
	keydlay: constant gldouble := 0.2; --0.016;

begin


	nowTime:=glfwGetTime;
	deltaTime := nowTime-oldKbTime;




-- First, we process continuous key-press responses: quit, Nearer, Further, Pan, Move

--Quit
if glfwgetkey( mainWin, glfw_key_escape ) = Glfw_Press then

	userexit:=true;
	if onIsland then
		mystexit:=true;
	end if;

--Quit
elsif glfwgetkey( mainWin, glfw_key_q ) = Glfw_Press then

	userexit:=true;
	if onIsland then
		mystexit:=true;
	end if;

end if;



--zoomNearer
if glfwgetkey( mainWin, glfw_key_n ) = Glfw_Press then
			zoomwheel.zdist:=0.99*zoomwheel.zdist;
			if zoomwheel.zdist<0.1 then zoomwheel.zdist:=0.1; end if;
			camdist:=float(zoomwheel.zdist); --??

--zoomFurther
elsif glfwgetkey( mainWin, glfw_key_f ) = Glfw_Press then
			zoomwheel.zdist:=1.01*zoomwheel.zdist;
			if zoomwheel.zdist>10.0 then zoomwheel.zdist:=10.0; end if;
			camdist:=float(zoomwheel.zdist); --??

--zoomNormalize
elsif glfwgetkey( mainWin, glfw_key_z ) = Glfw_Press then
			if camdist>1.01 then
				camdist := 0.99*camdist;
			elsif camdist<0.99 then
				camdist := 1.01*camdist;
			end if;

end if;


moving:=false;
--MoveForw
if 
	glfwgetkey( mainWin, glfw_key_up ) = Glfw_Press 
	or glfwgetkey( mainWin, glfw_key_w ) = Glfw_Press 
then

	if onIsland then
		myst_moveForward(nowTime);
	else
		moveForward(nowTime);
	end if;

--MoveBak
elsif 
	glfwgetkey( mainWin, glfw_key_down ) = Glfw_Press 
	or glfwgetkey( mainWin, glfw_key_s ) = Glfw_Press 
then
	if onIsland then
		myst_moveBackward(nowTime);
	else
		moveBackward(nowTime);
	end if;

end if;


--panLeft
if 
	glfwgetkey( mainWin, glfw_key_left ) = Glfw_Press 
	or glfwgetkey( mainWin, glfw_key_a ) = Glfw_Press 
then 

	slewsec:=nowTime-slewtime;

	if slewsec<0.1 then
		roty := +0.5*kslu*float(slewsec);
		if thirdperson then
			hdang := angrate3*roty;
		else
			hdang := angrate1*roty;
		end if;
		horiang := horiang + hdang;
		slewToAv; --27jan18

		roty:=0.0;

			if thirdperson then -- vertang represents camera
				xlook := fmath.cos(0.0)*fmath.sin(horiAng);
				zlook := fmath.cos(0.0)*fmath.cos(horiAng);
			else
				xlook := fmath.cos(vertAng)*fmath.sin(horiAng);
				zlook := fmath.cos(vertAng)*fmath.cos(horiAng);
			end if;
			cylook := fmath.sin(vertAng);

		--updategamestate; --automatic in moveforward
	end if;
	slewtime := nowTime;


--panRight
elsif 
	glfwgetkey( mainWin, glfw_key_right ) = Glfw_Press 
	or glfwgetkey( mainWin, glfw_key_d ) = Glfw_Press 
then 

	slewsec:=nowTime-slewtime;

	if slewsec<0.1 then
		roty := -0.5*kslu*float(slewsec);
		if thirdperson then
			hdang := angrate3*roty;
		else
			hdang := angrate1*roty;
		end if;
		horiang := horiang + hdang;
		slewToAv; --27jan18

		roty:=0.0;

			if thirdperson then -- vertang represents camera
				xlook := fmath.cos(0.0)*fmath.sin(horiAng);
				zlook := fmath.cos(0.0)*fmath.cos(horiAng);
			else
				xlook := fmath.cos(vertAng)*fmath.sin(horiAng);
				zlook := fmath.cos(vertAng)*fmath.cos(horiAng);
			end if;
			cylook := fmath.sin(vertAng);

		--updategamestate; --automatic in moveforward
	end if;
	slewtime := nowTime;
end if;





-- Second, we process discrete key-press events -----------------------

if deltaTime > keydlay then
--if deltaT > keydlay then


	if glfwgetkey( mainWin, glfw_key_e ) = Glfw_Press then

		if not onIsland then

			portalEnabled:=true;

			--normally music stops AFTER shooting both portals
			--but when debugging I like to better hear shots,
			--and it doesn't hurt to stop music here:
			if level=1 then
				snd4ada_hpp.stopLoop(falls);
			elsif level=2 then
				snd4ada_hpp.stopLoop(dark);
			elsif level=3 then
				snd4ada_hpp.stopLoop(gothic);
			elsif level=4 then
				snd4ada_hpp.stopLoop(neptune);
			end if;

			oldKbTime := nowTime;
		end if;

	elsif glfwgetkey( mainWin, glfw_key_m ) = Glfw_Press then
		thirdPerson := not thirdPerson;
		oldKbTime := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_x ) = Glfw_Press then

		if onIsland then
			detales:=not detales;
		else
			details:=not details;
		end if;

		oldKbTime := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_h ) = Glfw_Press then
		help:=not help;
		oldKbTime := nowTime;

	elsif glfwgetkey( mainWin, glfw_key_l ) = Glfw_Press then

		if not onIsland then
			shootLeft(nowTime);
			oldKbTime := nowTime;
		end if;

	elsif glfwgetkey( mainWin, glfw_key_r ) = Glfw_Press then
		if not onIsland then
			shootRight(nowTime);
			oldKbTime := nowTime;
		end if;


	elsif glfwgetkey( mainWin, glfw_key_space ) = Glfw_Press then --pickDrop

		if not onIsland then
			jumpTime := nowTime;
			pyjump:= yme;
			vyjump:=2.0;
			jumping:=true;

			oldKbTime := nowTime;
		end if;

	end if;

end if; --deltaTime>keydlay

end getKeyInputs;





