update 0.9.0 goodies
This commit is contained in:
parent
d99a5c7185
commit
e401b93e22
11 changed files with 514 additions and 93 deletions
21
sae/amiga.js
21
sae/amiga.js
|
|
@ -92,6 +92,8 @@ const SAEE_Video_LinkShader = 44;
|
|||
|
||||
const SAEE_Audio_RequiresWebAudio = 50;
|
||||
|
||||
const SAEE_Input_GamepadNotReady = 60;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* global references */
|
||||
|
||||
|
|
@ -147,7 +149,11 @@ const SAEC_info = (function() {
|
|||
},
|
||||
video: {
|
||||
canvas: false,
|
||||
webGL: false
|
||||
webGL: false,
|
||||
pointerLock: false
|
||||
},
|
||||
input: {
|
||||
gamepad: false
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -216,6 +222,7 @@ const SAEC_info = (function() {
|
|||
var ctx = canvas.getContext("2d");
|
||||
var imageData = ctx.createImageData(16, 16);
|
||||
info.video.canvas = true;
|
||||
|
||||
try {
|
||||
const glParams = {
|
||||
alpha: false,
|
||||
|
|
@ -229,9 +236,16 @@ const SAEC_info = (function() {
|
|||
ctx = canvas.getContext("webgl", glParams) || canvas.getContext("experimental-webgl", glParams);
|
||||
info.video.webGL = true;
|
||||
} catch(e) {}
|
||||
|
||||
if (canvas.requestPointerLock || canvas.mozRequestPointerLock)
|
||||
info.video.pointerLock = true;
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
/* input */
|
||||
if (navigator.getGamepads || navigator.webkitGetGamepads)
|
||||
info.input.gamepad = true;
|
||||
|
||||
return info;
|
||||
})();
|
||||
|
||||
|
|
@ -454,9 +468,8 @@ function ScriptedAmigaEmulator() {
|
|||
return err;
|
||||
if ((err = this.audio.obtain()) != SAEE_None)
|
||||
return err;
|
||||
|
||||
this.input.setup(); //inputdevice_init();
|
||||
|
||||
if ((err = this.input.setup()) != SAEE_None) //inputdevice_init();
|
||||
return err;
|
||||
if ((err = this.gui.setup()) != SAEE_None)
|
||||
return err;
|
||||
|
||||
|
|
|
|||
12
sae/audio.js
12
sae/audio.js
|
|
@ -211,11 +211,11 @@ function SAEO_Audio() {
|
|||
|
||||
/*---------------------------------*/
|
||||
|
||||
const INV32768 = 1.0 / 32768; /* mul is always fasten than div */
|
||||
const INV32768 = 1.0 / 32768; /* mul is always faster than div */
|
||||
|
||||
function scaleplay(e, buffer, frames) {
|
||||
var chn=SAEV_config.audio.channels;
|
||||
var z=e.outputBuffer.length;
|
||||
var chn = SAEV_config.audio.channels;
|
||||
var z = e.outputBuffer.length;
|
||||
if (muted) {
|
||||
for (var ch = 0; ch < chn; ch++) {
|
||||
var data = e.outputBuffer.getChannelData(ch);
|
||||
|
|
@ -224,13 +224,13 @@ function SAEO_Audio() {
|
|||
}
|
||||
return;
|
||||
}
|
||||
/*if (driver.context.sampleRate != used_freq) {
|
||||
} else*/ {
|
||||
/*if (driver.context.sampleRate != used_freq) {} else*/
|
||||
{
|
||||
var step = frames / z;
|
||||
|
||||
for (var ch = 0; ch < chn; ch++) {
|
||||
var data = e.outputBuffer.getChannelData(ch);
|
||||
var tbuf=buffer[ch];
|
||||
var tbuf = buffer[ch];
|
||||
for (var i = 0, j = 0.0; i < z; i++, j += step)
|
||||
data[i] = tbuf[j >>> 0] * INV32768;
|
||||
}
|
||||
|
|
|
|||
13
sae/cia.js
13
sae/cia.js
|
|
@ -793,8 +793,7 @@ function SAEO_CIA() {
|
|||
|
||||
function check_led() {
|
||||
var v = ciaapra;
|
||||
|
||||
v |= ~ciaadra; /* output is high when pin"s direction is input */
|
||||
v |= ~ciaadra; /* output is high when pin's direction is input */
|
||||
var led2 = (v & 2) ? 0 : 1;
|
||||
if (led2 != led) {
|
||||
calc_led(led);
|
||||
|
|
@ -824,12 +823,18 @@ function SAEO_CIA() {
|
|||
if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Mouse) {
|
||||
if (!SAER.input.mouse.button[0]) tmp |= 0x40;
|
||||
if (dra & 0x40) tmp = (tmp & ~0x40) | (pra & 0x40);
|
||||
} else if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Joy0) {
|
||||
} else if (
|
||||
SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Joy ||
|
||||
SAEV_config.ports[0].type == SAEC_Config_Ports_Type_JoyEmu
|
||||
) {
|
||||
if (!SAER.input.joystick[0].button[0]) tmp |= 0x40;
|
||||
if (dra & 0x40) tmp = (tmp & ~0x40) | (pra & 0x40);
|
||||
} else tmp |= 0x40;
|
||||
|
||||
if (SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Joy1) {
|
||||
if (
|
||||
SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Joy ||
|
||||
SAEV_config.ports[1].type == SAEC_Config_Ports_Type_JoyEmu
|
||||
) {
|
||||
if (!SAER.input.joystick[1].button[0]) tmp |= 0x80;
|
||||
if (dra & 0x80) tmp = (tmp & ~0x80) | (pra & 0x80);
|
||||
} else tmp |= 0x80;
|
||||
|
|
|
|||
|
|
@ -266,6 +266,10 @@ function SAEO_Config_Mount_Data() { //uaedev_config_data
|
|||
const SAEC_Config_Video_API_Canvas = 0;
|
||||
const SAEC_Config_Video_API_WebGL = 1;
|
||||
|
||||
const SAEC_Config_Video_Cursor_Show = 0;
|
||||
const SAEC_Config_Video_Cursor_Hide = 1;
|
||||
const SAEC_Config_Video_Cursor_Lock = 2;
|
||||
|
||||
const SAEC_Config_Video_HResolution_LoRes = 0;
|
||||
const SAEC_Config_Video_HResolution_HiRes = 1;
|
||||
const SAEC_Config_Video_HResolution_SuperHiRes = 2;
|
||||
|
|
@ -372,8 +376,8 @@ const SAEC_Config_Audio_Interpol_Crux = 3;
|
|||
|
||||
const SAEC_Config_Ports_Type_None = 0;
|
||||
const SAEC_Config_Ports_Type_Mouse = 1;
|
||||
const SAEC_Config_Ports_Type_Joy0 = 2;
|
||||
const SAEC_Config_Ports_Type_Joy1 = 3;
|
||||
const SAEC_Config_Ports_Type_Joy = 2;
|
||||
const SAEC_Config_Ports_Type_JoyEmu = 3;
|
||||
|
||||
const SAEC_Config_Ports_Move_None = 0;
|
||||
const SAEC_Config_Ports_Move_Arrows = 1;
|
||||
|
|
@ -382,6 +386,8 @@ const SAEC_Config_Ports_Move_WASD = 3;
|
|||
|
||||
const SAEC_Config_Ports_Fire_None = 0;
|
||||
|
||||
const SAEC_Config_Ports_Device_None = -1;
|
||||
|
||||
/*---------------------------------*/
|
||||
/* debug */
|
||||
|
||||
|
|
@ -574,8 +580,7 @@ function SAEO_Config() {
|
|||
this.video = {
|
||||
id: "",
|
||||
enabled: false,
|
||||
//driver: 0,
|
||||
hideCursor: false,
|
||||
cursor: 0,
|
||||
|
||||
scandoubler: false, //gfx_scandoubler
|
||||
framerate: 0, //gfx_framerate
|
||||
|
|
@ -673,11 +678,13 @@ function SAEO_Config() {
|
|||
this.ports = [{
|
||||
type: SAEC_Config_Ports_Type_Mouse,
|
||||
move: SAEC_Config_Ports_Move_WASD,
|
||||
fire: [49,50]
|
||||
fire: [49,50],
|
||||
device: SAEC_Config_Ports_Device_None
|
||||
}, {
|
||||
type: SAEC_Config_Ports_Type_Joy1,
|
||||
type: SAEC_Config_Ports_Type_JoyEmu,
|
||||
move: SAEC_Config_Ports_Move_Arrows,
|
||||
fire: [16,17]
|
||||
fire: [16,17],
|
||||
device: SAEC_Config_Ports_Device_None
|
||||
}];
|
||||
|
||||
this.keyboard = {
|
||||
|
|
@ -1076,7 +1083,7 @@ function SAEO_Configuration() {
|
|||
|
||||
p.video.id = "video";
|
||||
p.video.enabled = true;
|
||||
p.video.hideCursor = true;
|
||||
p.video.cursor = SAEC_Config_Video_Cursor_Lock;
|
||||
p.video.scandoubler = false;
|
||||
p.video.framerate = 1;
|
||||
p.video.hresolution = SAEC_Config_Video_HResolution_HiRes;
|
||||
|
|
@ -1161,9 +1168,11 @@ function SAEO_Configuration() {
|
|||
p.ports[0].type = SAEC_Config_Ports_Type_Mouse;
|
||||
p.ports[0].move = SAEC_Config_Ports_Move_WASD;
|
||||
p.ports[0].fire = [49,50];
|
||||
p.ports[1].type = SAEC_Config_Ports_Type_Joy1;
|
||||
p.ports[0].device = SAEC_Config_Ports_Device_None;
|
||||
p.ports[1].type = SAEC_Config_Ports_Type_JoyEmu;
|
||||
p.ports[1].move = SAEC_Config_Ports_Move_Arrows;
|
||||
p.ports[1].fire = [16,17];
|
||||
p.ports[1].device = SAEC_Config_Ports_Device_None;
|
||||
/*memset (&p.jports[0], 0, sizeof (struct jport));
|
||||
memset (&p.jports[1], 0, sizeof (struct jport));
|
||||
memset (&p.jports[2], 0, sizeof (struct jport));
|
||||
|
|
@ -2400,7 +2409,17 @@ function SAEO_Configuration() {
|
|||
p.chipset.cia.tod = p.chipset.ntsc ? SAEC_Config_Chipset_CIA_TOD_60Hz : SAEC_Config_Chipset_CIA_TOD_50Hz;
|
||||
|
||||
built_in_chipset_prefs(p);
|
||||
|
||||
//inputdevice_fix_prefs(p);
|
||||
if (p.ports[0].type == SAEC_Config_Ports_Type_Joy && p.ports[0].device == SAEC_Config_Ports_Device_None) {
|
||||
p.ports[0].type = SAEC_Config_Ports_Type_JoyEmu;
|
||||
SAEF_warn("config.fixup_prefs() p.ports[0].device is invalid. (falling back to joystick-emulation)");
|
||||
}
|
||||
if (p.ports[1].type == SAEC_Config_Ports_Type_Joy && p.ports[1].device == SAEC_Config_Ports_Device_None) {
|
||||
p.ports[1].type = SAEC_Config_Ports_Type_JoyEmu;
|
||||
SAEF_warn("config.fixup_prefs() p.ports[1].device is invalid. (falling back to joystick-emulation)");
|
||||
}
|
||||
|
||||
return true; //err == 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
168
sae/input.js
168
sae/input.js
|
|
@ -19,35 +19,32 @@ function SAEO_Mouse() {
|
|||
this.button = [false, false, false];
|
||||
this.pos = 0;
|
||||
|
||||
var cx = 0;
|
||||
var cy = 0;
|
||||
var mx = 0;
|
||||
var my = 0;
|
||||
var lx = -1;
|
||||
var ly = -1;
|
||||
var cx = 0, cy = 0;
|
||||
var mx = 0, my = 0;
|
||||
var lx = -1, ly = -1;
|
||||
|
||||
this.reset = function() {
|
||||
this.button = [0, 0, 0];
|
||||
this.button = [false, false, false];
|
||||
cx = cy = 0;
|
||||
lx = ly = -1;
|
||||
};
|
||||
|
||||
this.mousedown = function(e) {
|
||||
e = e || window.event;
|
||||
if (!e) return;
|
||||
e = e || window.event; if (e === undefined) return;
|
||||
|
||||
this.button[e.button] = true;
|
||||
};
|
||||
|
||||
this.mouseup = function(e) {
|
||||
e = e || window.event;
|
||||
if (!e) return;
|
||||
e = e || window.event; if (e === undefined) return;
|
||||
|
||||
this.button[e.button] = false;
|
||||
};
|
||||
|
||||
this.mouseover = function(e) {
|
||||
if (SAEV_config.video.hideCursor)
|
||||
e = e || window.event; if (e === undefined) return;
|
||||
|
||||
if (SAEV_config.video.cursor == SAEC_Config_Video_Cursor_Hide)
|
||||
SAER.video.hideCursor(true);
|
||||
|
||||
this.mousemove(e);
|
||||
|
|
@ -56,23 +53,26 @@ function SAEO_Mouse() {
|
|||
};
|
||||
|
||||
this.mouseout = function(e) {
|
||||
e = e || window.event; if (e === undefined) return;
|
||||
|
||||
this.mouseup(e);
|
||||
|
||||
if (SAEV_config.video.hideCursor)
|
||||
if (SAEV_config.video.cursor == SAEC_Config_Video_Cursor_Hide)
|
||||
SAER.video.hideCursor(false);
|
||||
};
|
||||
|
||||
this.mousemove = function(e) {
|
||||
e = e || window.event;
|
||||
if (!e) return;
|
||||
e = e || window.event; if (e === undefined) return;
|
||||
|
||||
if (e.pageX || e.pageY) {
|
||||
if (e.pageX !== undefined) {
|
||||
cx = e.pageX;
|
||||
cy = e.pageY;
|
||||
} else if (e.clientX || e.clientY) {
|
||||
} else if (e.clientX !== undefined) {
|
||||
cx = e.clientX;
|
||||
cy = e.clientY;
|
||||
}
|
||||
} else
|
||||
cx = cy = 0;
|
||||
|
||||
if (lx == -1) {
|
||||
lx = cx;
|
||||
ly = cy;
|
||||
|
|
@ -80,6 +80,25 @@ function SAEO_Mouse() {
|
|||
//SAEF_log("input.mousemove() %d %d", cx, cy);
|
||||
};
|
||||
|
||||
this.mousemove_locked = function(e) {
|
||||
e = e || window.event; if (e === undefined) return;
|
||||
|
||||
if (e.movementX !== undefined) {
|
||||
cx += e.movementX;
|
||||
cy += e.movementY;
|
||||
} else if (e.mozMovementX !== undefined) {
|
||||
cx += e.mozMovementX;
|
||||
cy += e.mozMovementY;
|
||||
} else
|
||||
cx = cy = 0;
|
||||
|
||||
if (lx == -1) {
|
||||
lx = cx;
|
||||
ly = cy;
|
||||
}
|
||||
//SAEF_log("input.mousemove_locked() %d %d", cx, cy);
|
||||
};
|
||||
|
||||
this.update = function() {
|
||||
if (lx != -1) {
|
||||
var dx = cx - lx;
|
||||
|
|
@ -113,15 +132,80 @@ function SAEO_Mouse() {
|
|||
}
|
||||
}
|
||||
|
||||
function SAEO_Joystick(type) {
|
||||
this.type = type;
|
||||
function SAEO_Joystick(port) {
|
||||
this.port = port;
|
||||
this.button = [false, false, false];
|
||||
this.state = [false, false, false, false];
|
||||
this.dir = 0;
|
||||
this.requestID = null;
|
||||
|
||||
this.reset = function() {
|
||||
this.button = [false, false, false];
|
||||
this.state = [false, false, false, false];
|
||||
this.dir = 0;
|
||||
this.requestID = null;
|
||||
};
|
||||
|
||||
this.setup = function() {
|
||||
if (SAEV_config.ports[this.port].type == SAEC_Config_Ports_Type_Joy) {
|
||||
var dev = SAEV_config.ports[this.port].device;
|
||||
var pad;
|
||||
|
||||
if (navigator.getGamepads)
|
||||
pad = navigator.getGamepads()[dev];
|
||||
else if (navigator.webkitGetGamepads)
|
||||
pad = navigator.webkitGetGamepads()[dev];
|
||||
else
|
||||
pad = null;
|
||||
|
||||
if (pad && pad.connected) {
|
||||
var joystick = this;
|
||||
|
||||
/* the gamepad API only supports polling not events */
|
||||
function pollGamepad() {
|
||||
var dev = SAEV_config.ports[joystick.port].device;
|
||||
var pad;
|
||||
|
||||
if (navigator.getGamepads)
|
||||
pad = navigator.getGamepads()[dev];
|
||||
else if (navigator.webkitGetGamepads)
|
||||
pad = navigator.webkitGetGamepads()[dev];
|
||||
else
|
||||
pad = null;
|
||||
|
||||
if (pad && pad.connected) {
|
||||
joystick.button = [
|
||||
pad.buttons[0].pressed,
|
||||
pad.buttons[1].pressed,
|
||||
false /* ignore fire2/button3 */
|
||||
];
|
||||
joystick.state = [
|
||||
pad.axes[0] < -0.6, /* l */
|
||||
pad.axes[1] < -0.6, /* u */
|
||||
pad.axes[0] > 0.6, /* r */
|
||||
pad.axes[1] > 0.6 /* d */
|
||||
];
|
||||
joystick.requestID = window.requestAnimationFrame(pollGamepad); /* next request */
|
||||
}
|
||||
}
|
||||
this.requestID = window.requestAnimationFrame(pollGamepad); /* initial request */
|
||||
|
||||
SAEF_log("Joystick.setup() assigned controller " + pad.id + " #" + pad.index + " to port " + this.port);
|
||||
} else {
|
||||
SAEF_error("Joystick.setup() chosen gamepad device with index " + dev + " was not detected.");
|
||||
return SAEE_Input_GamepadNotReady;
|
||||
}
|
||||
}
|
||||
return SAEE_None;
|
||||
};
|
||||
|
||||
this.cleanup = function() {
|
||||
if (SAEV_config.ports[this.port].type == SAEC_Config_Ports_Type_Joy) {
|
||||
if (this.requestID !== null) {
|
||||
window.cancelAnimationFrame(this.requestID);
|
||||
this.requestID = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.update = function() {
|
||||
|
|
@ -146,7 +230,7 @@ function SAEO_Joystick(type) {
|
|||
var b9 = (l ^ 1) ? 2 : 0;
|
||||
|
||||
this.dir = ((b8 | b9) << 8) | (b0 | b1);*/
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function SAEO_Keyboard() {
|
||||
|
|
@ -575,7 +659,7 @@ function SAEO_Keyboard() {
|
|||
}
|
||||
|
||||
/* joystick emul */
|
||||
if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Joy0) {
|
||||
if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_JoyEmu) {
|
||||
var l, u, r, d, f1, f2;
|
||||
switch (SAEV_config.ports[0].move) {
|
||||
case SAEC_Config_Ports_Move_Arrows:
|
||||
|
|
@ -628,7 +712,7 @@ function SAEO_Keyboard() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Joy1) {
|
||||
if (SAEV_config.ports[1].type == SAEC_Config_Ports_Type_JoyEmu) {
|
||||
var l, u, r, d, f1, f2;
|
||||
switch (SAEV_config.ports[1].move) {
|
||||
case SAEC_Config_Ports_Move_Arrows:
|
||||
|
|
@ -754,8 +838,8 @@ function SAEO_Keyboard() {
|
|||
function SAEO_Input() {
|
||||
this.mouse = new SAEO_Mouse();
|
||||
this.joystick = new Array(2);
|
||||
this.joystick[0] = new SAEO_Joystick(SAEC_Config_Ports_Type_Joy0);
|
||||
this.joystick[1] = new SAEO_Joystick(SAEC_Config_Ports_Type_Joy1);
|
||||
this.joystick[0] = new SAEO_Joystick(0);
|
||||
this.joystick[1] = new SAEO_Joystick(1);
|
||||
this.keyboard = new SAEO_Keyboard();
|
||||
|
||||
var potgo = {
|
||||
|
|
@ -764,10 +848,22 @@ function SAEO_Input() {
|
|||
};
|
||||
|
||||
this.setup = function () {
|
||||
var err;
|
||||
|
||||
this.keyboard.setup();
|
||||
if ((err = this.joystick[0].setup()) == SAEE_None) {
|
||||
if ((err = this.joystick[1].setup()) == SAEE_None)
|
||||
return SAEE_None;
|
||||
|
||||
this.joystick[0].cleanup();
|
||||
}
|
||||
this.keyboard.cleanup();
|
||||
return err;
|
||||
};
|
||||
|
||||
this.cleanup = function () {
|
||||
this.joystick[1].cleanup();
|
||||
this.joystick[0].cleanup();
|
||||
this.keyboard.cleanup();
|
||||
};
|
||||
|
||||
|
|
@ -796,11 +892,18 @@ function SAEO_Input() {
|
|||
if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Mouse) {
|
||||
if (this.mouse.button[2]) v &= 0xfbff;
|
||||
if (this.mouse.button[1]) v &= 0xfeff;
|
||||
} else if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Joy0) {
|
||||
} else if (
|
||||
SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Joy ||
|
||||
SAEV_config.ports[0].type == SAEC_Config_Ports_Type_JoyEmu
|
||||
){
|
||||
if (this.joystick[0].button[1]) v &= 0xfbff;
|
||||
if (this.joystick[0].button[2]) v &= 0xfeff;
|
||||
}
|
||||
if (SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Joy1) {
|
||||
|
||||
if (
|
||||
SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Joy ||
|
||||
SAEV_config.ports[1].type == SAEC_Config_Ports_Type_JoyEmu
|
||||
){
|
||||
if (this.joystick[1].button[1]) v &= 0xbfff;
|
||||
if (this.joystick[1].button[2]) v &= 0xefff;
|
||||
}
|
||||
|
|
@ -826,7 +929,10 @@ function SAEO_Input() {
|
|||
if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Mouse) {
|
||||
this.mouse.update();
|
||||
return this.mouse.pos;
|
||||
} else if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Joy0) {
|
||||
} else if (
|
||||
SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Joy ||
|
||||
SAEV_config.ports[0].type == SAEC_Config_Ports_Type_JoyEmu
|
||||
) {
|
||||
this.joystick[0].update();
|
||||
return this.joystick[0].dir;
|
||||
}
|
||||
|
|
@ -837,7 +943,10 @@ function SAEO_Input() {
|
|||
if (SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Mouse) {
|
||||
this.mouse.update();
|
||||
return this.mouse.pos;
|
||||
} else if (SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Joy1) {
|
||||
} else if (
|
||||
SAEV_config.ports[1].type == SAEC_Config_Ports_Type_Joy ||
|
||||
SAEV_config.ports[1].type == SAEC_Config_Ports_Type_JoyEmu
|
||||
) {
|
||||
this.joystick[1].update();
|
||||
return this.joystick[1].dir;
|
||||
}
|
||||
|
|
@ -848,4 +957,3 @@ function SAEO_Input() {
|
|||
//SAEF_log("Input.JOYTEST() $%04x", v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
24
sae/prototypes.js
vendored
24
sae/prototypes.js
vendored
|
|
@ -76,3 +76,27 @@ if (!performance.now) {
|
|||
return Date.now() - this.timing.navigationStart;
|
||||
};
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* AnimationFrame */
|
||||
|
||||
(function() {
|
||||
var lastTime = 0;
|
||||
|
||||
if (!window.requestAnimationFrame) {
|
||||
console.warn("This browser does not support 'window.requestAnimationFrame'. Falling back to 'setTimeout'...");
|
||||
window.requestAnimationFrame = function(callback, element) {
|
||||
var currTime = new Date().getTime();
|
||||
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
||||
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall);
|
||||
lastTime = currTime + timeToCall;
|
||||
return id;
|
||||
};
|
||||
}
|
||||
if (!window.cancelAnimationFrame) {
|
||||
console.warn("This browser does not support 'window.cancelAnimationFrame'. Falling back to 'clearTimeout'...");
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
|
|
|||
73
sae/video.js
73
sae/video.js
|
|
@ -90,6 +90,7 @@ function SAEO_Video() {
|
|||
this.ctx = null;
|
||||
this.texture = null;
|
||||
this.surface = null;
|
||||
this.requestPointerLock = null;
|
||||
|
||||
this.div = null;
|
||||
this.shown = false;
|
||||
|
|
@ -194,6 +195,24 @@ function SAEO_Video() {
|
|||
return SAEE_None;
|
||||
}
|
||||
|
||||
function pointerLockChange() {
|
||||
if (document.pointerLockElement === hAmigaWnd.canvas || document.mozPointerLockElement === hAmigaWnd.canvas) {
|
||||
hAmigaWnd.canvas.onmousedown = function(e) {
|
||||
SAER.input.mouse.mousedown(e);
|
||||
};
|
||||
hAmigaWnd.canvas.onmouseup = function(e) {
|
||||
SAER.input.mouse.mouseup(e);
|
||||
};
|
||||
document.addEventListener("mousemove", SAER.input.mouse.mousemove_locked, false);
|
||||
//SAEF_log("sae.video() mouse-pointer locked");
|
||||
} else {
|
||||
hAmigaWnd.canvas.onmousedown = function(e) {};
|
||||
hAmigaWnd.canvas.onmouseup = function(e) {};
|
||||
document.removeEventListener("mousemove", SAER.input.mouse.mousemove_locked, false);
|
||||
//SAEF_log("sae.video() mouse-pointer unlocked");
|
||||
}
|
||||
}
|
||||
|
||||
function CreateWindow(left, top, width, height) {
|
||||
var hWnd = new HWND();
|
||||
|
||||
|
|
@ -237,26 +256,48 @@ function SAEO_Video() {
|
|||
return false;
|
||||
};
|
||||
if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Mouse) {
|
||||
hWnd.canvas.onmousedown = function(e) {
|
||||
SAER.input.mouse.mousedown(e);
|
||||
};
|
||||
hWnd.canvas.onmouseup = function(e) {
|
||||
SAER.input.mouse.mouseup(e);
|
||||
};
|
||||
hWnd.canvas.onmouseover = function(e) {
|
||||
SAER.input.mouse.mouseover(e);
|
||||
};
|
||||
hWnd.canvas.onmouseout = function(e) {
|
||||
SAER.input.mouse.mouseout(e);
|
||||
};
|
||||
hWnd.canvas.onmousemove = function(e) {
|
||||
SAER.input.mouse.mousemove(e);
|
||||
if (SAEV_config.video.cursor == SAEC_Config_Video_Cursor_Lock)
|
||||
hWnd.canvas.requestPointerLock = hWnd.canvas.requestPointerLock || hWnd.canvas.mozRequestPointerLock;
|
||||
else
|
||||
hWnd.canvas.requestPointerLock = null;
|
||||
|
||||
if (typeof hWnd.canvas.requestPointerLock == "function") {
|
||||
document.addEventListener("pointerlockchange", pointerLockChange, false);
|
||||
document.addEventListener("mozpointerlockchange", pointerLockChange, false);
|
||||
|
||||
hWnd.canvas.onclick = function(e) {
|
||||
if (!(document.pointerLockElement === hAmigaWnd.canvas || document.mozPointerLockElement === hAmigaWnd.canvas))
|
||||
hWnd.canvas.requestPointerLock();
|
||||
};
|
||||
} else {
|
||||
hWnd.canvas.onmousedown = function(e) {
|
||||
SAER.input.mouse.mousedown(e);
|
||||
};
|
||||
hWnd.canvas.onmouseup = function(e) {
|
||||
SAER.input.mouse.mouseup(e);
|
||||
};
|
||||
hWnd.canvas.onmouseover = function(e) {
|
||||
SAER.input.mouse.mouseover(e);
|
||||
};
|
||||
hWnd.canvas.onmouseout = function(e) {
|
||||
SAER.input.mouse.mouseout(e);
|
||||
};
|
||||
hWnd.canvas.onmousemove = function(e) {
|
||||
SAER.input.mouse.mousemove(e);
|
||||
};
|
||||
}
|
||||
}
|
||||
return hWnd;
|
||||
}
|
||||
|
||||
function DestroyWindow(hWnd) {
|
||||
if (SAEV_config.ports[0].type == SAEC_Config_Ports_Type_Mouse) {
|
||||
if (typeof hWnd.canvas.requestPointerLock == "function") {
|
||||
document.removeEventListener('pointerlockchange', pointerLockChange, false);
|
||||
document.removeEventListener('mozpointerlockchange', pointerLockChange, false);
|
||||
}
|
||||
hWnd.canvas.requestPointerLock = null;
|
||||
}
|
||||
if (SAEV_config.video.api == SAEC_Config_Video_API_WebGL)
|
||||
hWnd.texture = null;
|
||||
else if (SAEV_config.video.api == SAEC_Config_Video_API_Canvas)
|
||||
|
|
@ -286,10 +327,8 @@ function SAEO_Video() {
|
|||
hWnd.shown = true;
|
||||
}
|
||||
else if (nCmdShow == SW_HIDE && hWnd.shown) {
|
||||
if (hWnd.div !== null) {
|
||||
if (hWnd.div !== null)
|
||||
hWnd.div.removeChild(hWnd.canvas);
|
||||
hWnd.canvas = null;
|
||||
}
|
||||
|
||||
hWnd.shown = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue