User File #27793144712275990

Upload All User Files

#27793144712275990 - Wolfenstein 3D input and display script

Wolf3d-script-extended.lua
Game: Wolfenstein 3D ( DOS, see all files )
1014 downloads
Uploaded 12/26/2015 3:42 PM by dwangoAC (see all 47)
This script requires a custom build of jpc-rr to properly connect the controller to mouse input and also shows important information on the screen.
dofile("textrender.lua");

mouse_vx = 0;
mouse_vy = 0;
mouse_deadzone = 6000
mouse_ysensitivity = 70;
mouse_xsensitivity = 70;
last_x = 0;
last_y = 0;
last_d = 0;
last_f = 0;
dx = 0;
dy = 0;
dd = 0;
do_stop = false;
save_name = "gamepadSave";

while true do
	a, b = jpcrr.wait_event();
	end
	if a == "message" then
		c,d,e = string.match(b, "(.*) (.*) (.*)");
		if e and c == "BUTTON" then
			if d == "314" and e == "0" then --Load savestate
				jpcrr.load_state_normal(save_name);
			end
			if d == "315" and e == "0" then --Save savestate
				jpcrr.save_state(save_name);
			end
			if d == "304" and e == "1" then
				jpcrr.pc_start();
			end
			if d == "304" and e == "0" then
				do_stop = true;
			end
			if d == "305" then
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "157");
			end
			if d == "307" then
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "57");
			end
			if d == "308" then
				jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "184");
			end
		end
		if e and c == "AXIS" then
			mouse_update = false;
			if d == "0" then
				v = tonumber(e);
				if v <= -mouse_deadzone then
					v = (v + mouse_deadzone) / (32768 - mouse_deadzone) * mouse_xsensitivity;
				elseif v >= mouse_deadzone then
					v = (v - mouse_deadzone) / (32768 - mouse_deadzone) * mouse_xsensitivity;
				else
					v = 0;
				end
				mouse_vx = v;
				mouse_update = true;
			end
			if d == "1" then
				v = tonumber(e);
				if v <= -mouse_deadzone then
					v = (v + mouse_deadzone) / (32768 - mouse_deadzone) * mouse_ysensitivity;
				elseif v >= mouse_deadzone then
					v = (v - mouse_deadzone) / (32768 - mouse_deadzone) * mouse_ysensitivity;
				else
					v = 0;
				end
				mouse_vy = -v;	--y axis is reversed.
				mouse_update = true;
			end
			if d == "2" then --Keyboard right alt, sticky (registers until pressed again)
				if e <= "0" then
				    jpcrr.sendevent("org.jpc.emulator.peripheral.Keyboard", "KEYEDGE", "184");
				end
			end
			if mouse_update then
				--print("Mouse: X=" .. mouse_vx .. " Y=" .. mouse_vy);
				jpcrr.hold_mouse_motion(mouse_vx, mouse_vy);
			end
		end
	if a == "lock" then
		jpcrr.hud.top_gap(3, 16);
		h = jpcrr.read_word(0x468A2);
		x = jpcrr.read_dword(0x004882E);
		y = jpcrr.read_dword(0x0048832);
		d = jpcrr.read_word(0x00048848);
		f = jpcrr.frame_number();
		spd = math.sqrt(dx * dx + dy * dy)
		render_text(3, 0, 0, string.format("%3d, (%7d,%7d) %3d [%+5d,%+5d](%f) %+3d", h, x, y, d, dx, dy, spd, dd),
			false, 0, 255, 0);
		if f ~= last_f then
			dx = x - last_x;
			dy = y - last_y;
			dd = d - last_d;
			last_x = x;
			last_y = y;
			last_d = d;
			last_f = f;
		end
		jpcrr.release_vga();
		if do_stop then
			jpcrr.pc_stop();
			do_stop = false;
		end
		--print(b);
	end
end