as good as input can get with single threaded javascript

pull/1/head
PolicyChanges1@gmail.com 2021-03-01 18:11:10 -05:00
parent a521652ea8
commit 5133845b19
5 changed files with 188 additions and 228 deletions

View File

@ -31,6 +31,7 @@ body{
height:100%; height:100%;
position: absolute; position: absolute;
left:210px; left:210px;
boarder:1px solid #6666;
background:rgba(1,1,1,.10); background:rgba(1,1,1,.10);
} }

207
dist/tetrion.js vendored
View File

@ -428,8 +428,10 @@ var utils = require('./utils.js');
var UserInputs = { var UserInputs = {
init() { init() {
this.dt = 0; this.gamepadShiftTimer = new Date();
this.debugTimer = new Date(); this.gamepadButtonTimer = new Date();
this.keyboardKeyTimer = new Date();
this.keyboardShiftTimer = new Date();
this.settingsMap = new Map(); this.settingsMap = new Map();
// var init = utils.getCookie("init"); // var init = utils.getCookie("init");
@ -453,21 +455,6 @@ var UserInputs = {
gamepadEnabled() { gamepadEnabled() {
return gamepad.controller || false; return gamepad.controller || false;
}, },
incDeciframes() {
this.keyboardButtonsDeciframes++;
this.keyboardDirectionArrowsDeciframes++;
this.gamepadButtonsDeciFrames++;
this.gamepadDirectionPadDeciFrames++;
},
incTickCounter() {
this.ticks++;
if(this.ticks > 1200000)this.ticks = 0; // set to 0 every 12 seconds?
},
getTickCounter() {
return this.ticks;
},
processGamepadInput() { processGamepadInput() {
this.gamepadButtonsDown(this.settingsMap.get("Gamepad Harddrop")); // hard drop this.gamepadButtonsDown(this.settingsMap.get("Gamepad Harddrop")); // hard drop
@ -488,34 +475,34 @@ var UserInputs = {
return; return;
}, },
// Single press gamepad buttons
// X, Y, A, B , RB, LB Buttons
gamepadButtonsDown(finds) { gamepadButtonsDown(finds) {
var deciDAS = 50.0; var DAS = 167.0;
var deciARR = 10.0; var ARR = 300.0;
var isContained = this.gpButtons.includes(finds); var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds);
if(isPrevContained != isContained ) { if(isPrevContained != isContained ) {
this.isGamepadButtonDown = false; // Not being held yet
// Do once this.gamepadButtonTimer = new Date();
this.isPassedDelayGamepadShift = false;
// Add button to queue on pressed input
if(isContained) if(isContained)
this.gamepadQueue.push(finds); this.gamepadQueue.push(finds);
} }
var gamepadDASFrames = this.gamepadButtonsDeciFrames;
if (!this.isGamepadButtonDown) { var deltaTime = (new Date()).getTime() - this.gamepadButtonTimer.getTime();
if (gamepadDASFrames >= deciDAS) { if (!this.isPassedDelayGamepadShift) {
this.gamepadButtonsDeciFrames = 0; if (deltaTime >= DAS) {
this.isGamepadButtonDown = true; this.gamepadButtonTimer = new Date();
this.isPassedDelayGamepadShift = true;
} }
} else { } else {
if (gamepadDASFrames >= deciARR && isContained) { if (deltaTime >= ARR && isContained) {
//this.gamepadQueue.push(finds); this.gamepadQueue.push(finds);
this.gamepadButtonsDeciFrames = 0; this.gamepadButtonTimer = new Date();
} }
} }
@ -523,32 +510,34 @@ var UserInputs = {
// Direction Pad // Direction Pad
gamepadDPadDown(finds) { gamepadDPadDown(finds) {
var DAS = parseInt(this.settingsMap.get("Gamepad DAS")); //65.0; var DAS = parseInt(this.settingsMap.get("Gamepad DAS"));
var ARR = parseInt(this.settingsMap.get("Gamepad ARR")); //20.0; var ARR = parseInt(this.settingsMap.get("Gamepad ARR"));
var isContained = this.gpButtons.includes(finds); var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds);
if(isPrevContained != isContained ) { if(isPrevContained != isContained ) {
this.isGamepadDown = false; // Not being held yet
// Do once this.gamepadShiftTimer = new Date();
this.isDelayedPassedGamepadShift = false;
// Add button to queue on pressed input
if(isContained) if(isContained)
this.gamepadQueue.push(finds); this.gamepadQueue.push(finds);
} }
var gamepadDirectionDasFrames = this.gamepadDirectionPadDeciFrames;
if (!this.isGamepadDown) { var deltaTime = (new Date()).getTime() - this.gamepadShiftTimer.getTime();
if (gamepadDirectionDasFrames >= DAS) {
this.gamepadDirectionPadDeciFrames = 0; if (!this.isDelayedPassedGamepadShift) {
this.isGamepadDown = true; if (deltaTime >= DAS) {
this.gamepadShiftTimer = new Date();
} this.isDelayedPassedGamepadShift = true;
}
else
{
if (gamepadDirectionDasFrames >= ARR && isContained) {
this.gamepadQueue.push(finds);
this.gamepadDirectionPadDeciFrames = 0;
}
} }
}
else {
if (deltaTime >= ARR && isContained) {
this.gamepadQueue.push(finds);
this.gamepadShiftTimer = new Date();
}
}
return; return;
@ -568,36 +557,37 @@ var UserInputs = {
// keyboard keys z,x,space // keyboard keys z,x,space
processKeyDown(key) processKeyDown(key)
{ {
var deciDAS = 50.0; var DAS = 167.0;
var deciARR = 50.0; var ARR = 300.0;
// todo: fix this mess if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) { // Not being held yet
this.keyboardKeyTimer = new Date();
this.isKeyboardKeyDown = false; this.isPassedDelayKeyboardKey = false;
// Add shift to queue on pressed input
if(this.keyboardKeys[key] == true) if(this.keyboardKeys[key] == true)
this.inputQueue.push(key); this.inputQueue.push(key);
//this.keyboardKeys[key] = false;
} }
var keyboardDASFrames = this.keyboardButtonsDeciframes; var deltaTime = (new Date()).getTime() - this.keyboardKeyTimer.getTime();
if (!this.isKeyboardKeyDown) { if (!this.isPassedDelayKeyboardKey) {
if (keyboardDASFrames >= deciDAS) { if (deltaTime >= DAS) {
this.keyboardKeyTimer = new Date();
this.keyboardButtonsDeciframes = 0; this.keyboardButtonsDeciframes = 0;
this.isKeyboardKeyDown = true; this.isPassedDelayKeyboardKey = true;
} }
} else { } else {
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) { if (deltaTime >= ARR && this.keyboardKeys[key] == true) {
//this.inputQueue.push(key); this.inputQueue.push(key);
this.keyboardButtonsDeciframes = 0; this.keyboardKeyTimer = new Date();
} }
} }
}, },
// Process applicable key inputs
processKeyShift() { processKeyShift() {
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Left"))); //39); // right this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Left"))); //39); // right
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Right"))); //37); // left this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Right"))); //37); // left
@ -610,25 +600,30 @@ var UserInputs = {
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) { if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
// Not being held yet // Not being held yet
this.isPassedDelay = false; this.isPassedDelayKeyboardShift = false;
this.keyboardShiftTimer = new Date();
// Do shift if key has been pushed down
if(this.keyboardKeys[key] == true) if(this.keyboardKeys[key] == true)
this.inputQueue.push(key); this.inputQueue.push(key);
} }
var deltaTime = (new Date()).getTime() - this.keyboardShiftTimer.getTime();
if (!this.isPassedDelayKeyboardShift) {
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes; if (deltaTime >= DAS) {
this.keyboardShiftTimer = new Date();
if (!this.isPassedDelay) { this.isPassedDelayKeyboardShift = true;
if (keyboardDASFrames >= DAS) {
this.keyboardDirectionArrowsDeciframes = 0;
this.isPassedDelay = true;
} }
} }
else if(keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) { else if(deltaTime >= ARR && this.keyboardKeys[key] == true) {
this.inputQueue.push(key); this.inputQueue.push(key);
this.keyboardDirectionArrowsDeciframes = 0; this.keyboardShiftTimer = new Date();
} }
}, },
keyDown(event) { keyDown(event) {
@ -657,16 +652,10 @@ var UserInputs = {
this.prevKeyboardKeys = {...this.keyboardKeys}; this.prevKeyboardKeys = {...this.keyboardKeys};
}, },
// button states // button states
isPassedDelay: false, isPassedDelayKeyboardShift: false,
isKeyboardKeyDown: false, isPassedDelayKeyboardKey: false,
isGamepadDown: false, isPassedDelayGamepadShift: false,
isGamepadButtonDown: false, isPassedDelayGamepadButton: false,
// das frame counters
keyboardButtonsDeciframes: 0, // DAS controlled frames/10 for non-shifted keys
keyboardDirectionArrowsDeciframes: 0, // DAS controlled frames/10 for mino shifting keys
gamepadButtonsDeciFrames: 0, // DAS controlled frames/10 for non-shifted keys
gamepadDirectionPadDeciFrames: 0, // DAS controlled frames/10 for mino shifting keys
// buttons state contatiners // buttons state contatiners
gpButtons: [], gpButtons: [],
@ -677,10 +666,8 @@ var UserInputs = {
// button pressed containers // button pressed containers
inputQueue: [], inputQueue: [],
gamepadQueue: [], gamepadQueue: [],
ticks: 0, settingsList: ["Soft Drop Rate [1 - 100]",
settingsList: ["init",
"Keyboard DAS", "Keyboard ARR", "Keyboard Harddrop", "Keyboard Hold", "Keyboard DAS", "Keyboard ARR", "Keyboard Harddrop", "Keyboard Hold",
"Keyboard Left", "Keyboard Right", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Left", "Keyboard Right", "Keyboard Rotateccw", "Keyboard Rotate",
"Keyboard Down", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background", "Keyboard Down", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background",
@ -690,12 +677,12 @@ var UserInputs = {
"Gamepad Down","Gamepad Pophold", "Gamepad Reset", "Gamepad Background", "Gamepad Down","Gamepad Pophold", "Gamepad Reset", "Gamepad Background",
"path", "High Score"], "path", "High Score"],
settingsDefault: ["true", settingsDefault: ["70",
"50.0", "16.0", "32", "16", "167.0", "33.0", "32", "16",
"37", "39", "90", "88", "37", "39", "90", "88",
"40", "17", "82", "81", "40", "17", "82", "81",
"50.0", "16.0", "RB", "LB", "167.0", "33.0", "RB", "LB",
"DPad-Left", "DPad-Right", "A", "B", "DPad-Left", "DPad-Right", "A", "B",
"DPad-Down", "DPad-Up", "Back", "", "DPad-Down", "DPad-Up", "Back", "",
"=/",""], "=/",""],
@ -1126,25 +1113,18 @@ Tetris.prototype = {
}, },
// tick input data -- wont have better than 4-15ms resolution since javascript is single theaded // tick input data -- wont have better than 4-15ms resolution since javascript is single theaded and any ARR or DAS below 15ms will likely be broken
_processTick: async function() { _processTick: async function() {
//var deltaTime = (new Date()).getTime() - this.eventTimer.getTime(); //var deltaTime = (new Date()).getTime() - this.eventTimer.getTime();
//console.log("desync time: " + deltaTime); //console.log("desync time: " + deltaTime);
inputs.incDeciframes();
inputs.incTickCounter();
if(this.isTimerOn) { if(this.isTimerOn) {
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime; var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
if(inputs.getTickCounter() >= 20) { // Set html element at a reasonble rate
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
}
} }
@ -1158,14 +1138,14 @@ Tetris.prototype = {
var halfFrame = 5.0 //8.0; var halfFrame = 5.0 //8.0;
var halfFramePlus = 10.0; var halfFramePlus = 10.0;
if(inputs.getTickCounter() >= tenthOfFrame) {
inputs.updateGamepad(); inputs.updateGamepad();
inputs.processGamepadDPad(); inputs.processGamepadDPad();
inputs.processGamepadInput(); inputs.processGamepadInput();
}
// drain gamepad queue // drain gamepad queue
if( inputs.getTickCounter() > halfFrame) // 8 millisecons // if( inputs.getTickCounter() > halfFrame) // 8 millisecons
{ // {
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){ while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
var curkey = inputs.gamepadQueue.shift(); var curkey = inputs.gamepadQueue.shift();
if(curkey == "DPad-Left") { if(curkey == "DPad-Left") {
@ -1214,14 +1194,13 @@ Tetris.prototype = {
} }
inputs.gamepadQueue = []; inputs.gamepadQueue = [];
} // }
//inputs.gamepadButtonClear(); //inputs.gamepadButtonClear();
} }
// Do keyboard // Do keyboard
inputs.processKeys(); inputs.processKeys();
inputs.processKeyShift(); inputs.processKeyShift();
// Keyboard inputs // Keyboard inputs
while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){ while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){

View File

@ -50,6 +50,7 @@
<iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false" ></iframe> <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false" ></iframe>
<!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/MlSSRt?gui=&paused=false&muted=false" allowfullscreen></iframe> --> <!-- <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/MlSSRt?gui=&paused=false&muted=false" allowfullscreen></iframe> -->

View File

@ -4,8 +4,10 @@ var utils = require('./utils.js');
var UserInputs = { var UserInputs = {
init() { init() {
this.dt = 0; this.gamepadShiftTimer = new Date();
this.debugTimer = new Date(); this.gamepadButtonTimer = new Date();
this.keyboardKeyTimer = new Date();
this.keyboardShiftTimer = new Date();
this.settingsMap = new Map(); this.settingsMap = new Map();
// var init = utils.getCookie("init"); // var init = utils.getCookie("init");
@ -29,21 +31,6 @@ var UserInputs = {
gamepadEnabled() { gamepadEnabled() {
return gamepad.controller || false; return gamepad.controller || false;
}, },
incDeciframes() {
this.keyboardButtonsDeciframes++;
this.keyboardDirectionArrowsDeciframes++;
this.gamepadButtonsDeciFrames++;
this.gamepadDirectionPadDeciFrames++;
},
incTickCounter() {
this.ticks++;
if(this.ticks > 1200000)this.ticks = 0; // set to 0 every 12 seconds?
},
getTickCounter() {
return this.ticks;
},
processGamepadInput() { processGamepadInput() {
this.gamepadButtonsDown(this.settingsMap.get("Gamepad Harddrop")); // hard drop this.gamepadButtonsDown(this.settingsMap.get("Gamepad Harddrop")); // hard drop
@ -64,34 +51,34 @@ var UserInputs = {
return; return;
}, },
// Single press gamepad buttons
// X, Y, A, B , RB, LB Buttons
gamepadButtonsDown(finds) { gamepadButtonsDown(finds) {
var deciDAS = 50.0; var DAS = 167.0;
var deciARR = 10.0; var ARR = 300.0;
var isContained = this.gpButtons.includes(finds); var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds);
if(isPrevContained != isContained ) { if(isPrevContained != isContained ) {
this.isGamepadButtonDown = false; // Not being held yet
// Do once this.gamepadButtonTimer = new Date();
this.isPassedDelayGamepadShift = false;
// Add button to queue on pressed input
if(isContained) if(isContained)
this.gamepadQueue.push(finds); this.gamepadQueue.push(finds);
} }
var gamepadDASFrames = this.gamepadButtonsDeciFrames;
if (!this.isGamepadButtonDown) { var deltaTime = (new Date()).getTime() - this.gamepadButtonTimer.getTime();
if (gamepadDASFrames >= deciDAS) { if (!this.isPassedDelayGamepadShift) {
this.gamepadButtonsDeciFrames = 0; if (deltaTime >= DAS) {
this.isGamepadButtonDown = true; this.gamepadButtonTimer = new Date();
this.isPassedDelayGamepadShift = true;
} }
} else { } else {
if (gamepadDASFrames >= deciARR && isContained) { if (deltaTime >= ARR && isContained) {
//this.gamepadQueue.push(finds); this.gamepadQueue.push(finds);
this.gamepadButtonsDeciFrames = 0; this.gamepadButtonTimer = new Date();
} }
} }
@ -99,32 +86,34 @@ var UserInputs = {
// Direction Pad // Direction Pad
gamepadDPadDown(finds) { gamepadDPadDown(finds) {
var DAS = parseInt(this.settingsMap.get("Gamepad DAS")); //65.0; var DAS = parseInt(this.settingsMap.get("Gamepad DAS"));
var ARR = parseInt(this.settingsMap.get("Gamepad ARR")); //20.0; var ARR = parseInt(this.settingsMap.get("Gamepad ARR"));
var isContained = this.gpButtons.includes(finds); var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds);
if(isPrevContained != isContained ) { if(isPrevContained != isContained ) {
this.isGamepadDown = false; // Not being held yet
// Do once this.gamepadShiftTimer = new Date();
this.isDelayedPassedGamepadShift = false;
// Add button to queue on pressed input
if(isContained) if(isContained)
this.gamepadQueue.push(finds); this.gamepadQueue.push(finds);
} }
var gamepadDirectionDasFrames = this.gamepadDirectionPadDeciFrames;
if (!this.isGamepadDown) { var deltaTime = (new Date()).getTime() - this.gamepadShiftTimer.getTime();
if (gamepadDirectionDasFrames >= DAS) {
this.gamepadDirectionPadDeciFrames = 0; if (!this.isDelayedPassedGamepadShift) {
this.isGamepadDown = true; if (deltaTime >= DAS) {
this.gamepadShiftTimer = new Date();
} this.isDelayedPassedGamepadShift = true;
}
else
{
if (gamepadDirectionDasFrames >= ARR && isContained) {
this.gamepadQueue.push(finds);
this.gamepadDirectionPadDeciFrames = 0;
}
} }
}
else {
if (deltaTime >= ARR && isContained) {
this.gamepadQueue.push(finds);
this.gamepadShiftTimer = new Date();
}
}
return; return;
@ -144,36 +133,37 @@ var UserInputs = {
// keyboard keys z,x,space // keyboard keys z,x,space
processKeyDown(key) processKeyDown(key)
{ {
var deciDAS = 50.0; var DAS = 167.0;
var deciARR = 50.0; var ARR = 300.0;
// todo: fix this mess if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key] && this.isKeyBoardKeyDown == true) { // Not being held yet
this.keyboardKeyTimer = new Date();
this.isKeyboardKeyDown = false; this.isPassedDelayKeyboardKey = false;
// Add shift to queue on pressed input
if(this.keyboardKeys[key] == true) if(this.keyboardKeys[key] == true)
this.inputQueue.push(key); this.inputQueue.push(key);
//this.keyboardKeys[key] = false;
} }
var keyboardDASFrames = this.keyboardButtonsDeciframes; var deltaTime = (new Date()).getTime() - this.keyboardKeyTimer.getTime();
if (!this.isKeyboardKeyDown) { if (!this.isPassedDelayKeyboardKey) {
if (keyboardDASFrames >= deciDAS) { if (deltaTime >= DAS) {
this.keyboardKeyTimer = new Date();
this.keyboardButtonsDeciframes = 0; this.keyboardButtonsDeciframes = 0;
this.isKeyboardKeyDown = true; this.isPassedDelayKeyboardKey = true;
} }
} else { } else {
if (keyboardDASFrames >= deciARR && this.keyboardKeys[key] == true) { if (deltaTime >= ARR && this.keyboardKeys[key] == true) {
//this.inputQueue.push(key); this.inputQueue.push(key);
this.keyboardButtonsDeciframes = 0; this.keyboardKeyTimer = new Date();
} }
} }
}, },
// Process applicable key inputs
processKeyShift() { processKeyShift() {
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Left"))); //39); // right this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Left"))); //39); // right
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Right"))); //37); // left this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("Keyboard Right"))); //37); // left
@ -186,25 +176,30 @@ var UserInputs = {
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) { if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
// Not being held yet // Not being held yet
this.isPassedDelay = false; this.isPassedDelayKeyboardShift = false;
this.keyboardShiftTimer = new Date();
// Do shift if key has been pushed down
if(this.keyboardKeys[key] == true) if(this.keyboardKeys[key] == true)
this.inputQueue.push(key); this.inputQueue.push(key);
} }
var deltaTime = (new Date()).getTime() - this.keyboardShiftTimer.getTime();
if (!this.isPassedDelayKeyboardShift) {
var keyboardDASFrames = this.keyboardDirectionArrowsDeciframes; if (deltaTime >= DAS) {
this.keyboardShiftTimer = new Date();
if (!this.isPassedDelay) { this.isPassedDelayKeyboardShift = true;
if (keyboardDASFrames >= DAS) {
this.keyboardDirectionArrowsDeciframes = 0;
this.isPassedDelay = true;
} }
} }
else if(keyboardDASFrames >= ARR && this.keyboardKeys[key] == true) { else if(deltaTime >= ARR && this.keyboardKeys[key] == true) {
this.inputQueue.push(key); this.inputQueue.push(key);
this.keyboardDirectionArrowsDeciframes = 0; this.keyboardShiftTimer = new Date();
} }
}, },
keyDown(event) { keyDown(event) {
@ -233,16 +228,10 @@ var UserInputs = {
this.prevKeyboardKeys = {...this.keyboardKeys}; this.prevKeyboardKeys = {...this.keyboardKeys};
}, },
// button states // button states
isPassedDelay: false, isPassedDelayKeyboardShift: false,
isKeyboardKeyDown: false, isPassedDelayKeyboardKey: false,
isGamepadDown: false, isPassedDelayGamepadShift: false,
isGamepadButtonDown: false, isPassedDelayGamepadButton: false,
// das frame counters
keyboardButtonsDeciframes: 0, // DAS controlled frames/10 for non-shifted keys
keyboardDirectionArrowsDeciframes: 0, // DAS controlled frames/10 for mino shifting keys
gamepadButtonsDeciFrames: 0, // DAS controlled frames/10 for non-shifted keys
gamepadDirectionPadDeciFrames: 0, // DAS controlled frames/10 for mino shifting keys
// buttons state contatiners // buttons state contatiners
gpButtons: [], gpButtons: [],
@ -253,10 +242,8 @@ var UserInputs = {
// button pressed containers // button pressed containers
inputQueue: [], inputQueue: [],
gamepadQueue: [], gamepadQueue: [],
ticks: 0, settingsList: ["Soft Drop Rate [1 - 100]",
settingsList: ["init",
"Keyboard DAS", "Keyboard ARR", "Keyboard Harddrop", "Keyboard Hold", "Keyboard DAS", "Keyboard ARR", "Keyboard Harddrop", "Keyboard Hold",
"Keyboard Left", "Keyboard Right", "Keyboard Rotateccw", "Keyboard Rotate", "Keyboard Left", "Keyboard Right", "Keyboard Rotateccw", "Keyboard Rotate",
"Keyboard Down", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background", "Keyboard Down", "Keyboard Pophold", "Keyboard Reset", "Keyboard Background",
@ -266,12 +253,12 @@ var UserInputs = {
"Gamepad Down","Gamepad Pophold", "Gamepad Reset", "Gamepad Background", "Gamepad Down","Gamepad Pophold", "Gamepad Reset", "Gamepad Background",
"path", "High Score"], "path", "High Score"],
settingsDefault: ["true", settingsDefault: ["70",
"50.0", "16.0", "32", "16", "167.0", "33.0", "32", "16",
"37", "39", "90", "88", "37", "39", "90", "88",
"40", "17", "82", "81", "40", "17", "82", "81",
"50.0", "16.0", "RB", "LB", "167.0", "33.0", "RB", "LB",
"DPad-Left", "DPad-Right", "A", "B", "DPad-Left", "DPad-Right", "A", "B",
"DPad-Down", "DPad-Up", "Back", "", "DPad-Down", "DPad-Up", "Back", "",
"=/",""], "=/",""],

View File

@ -419,25 +419,18 @@ Tetris.prototype = {
}, },
// tick input data -- wont have better than 4-15ms resolution since javascript is single theaded // tick input data -- wont have better than 4-15ms resolution since javascript is single theaded and any ARR or DAS below 15ms will likely be broken
_processTick: async function() { _processTick: async function() {
//var deltaTime = (new Date()).getTime() - this.eventTimer.getTime(); //var deltaTime = (new Date()).getTime() - this.eventTimer.getTime();
//console.log("desync time: " + deltaTime); //console.log("desync time: " + deltaTime);
inputs.incDeciframes();
inputs.incTickCounter();
if(this.isTimerOn) { if(this.isTimerOn) {
var deltaPlayTime = new Date().getTime() - this.sequencePrevTime; var deltaPlayTime = new Date().getTime() - this.sequencePrevTime;
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
if(inputs.getTickCounter() >= 20) { // Set html element at a reasonble rate
document.getElementById("Time").value = (deltaPlayTime/1000).toString();
}
} }
@ -451,14 +444,14 @@ Tetris.prototype = {
var halfFrame = 5.0 //8.0; var halfFrame = 5.0 //8.0;
var halfFramePlus = 10.0; var halfFramePlus = 10.0;
if(inputs.getTickCounter() >= tenthOfFrame) {
inputs.updateGamepad(); inputs.updateGamepad();
inputs.processGamepadDPad(); inputs.processGamepadDPad();
inputs.processGamepadInput(); inputs.processGamepadInput();
}
// drain gamepad queue // drain gamepad queue
if( inputs.getTickCounter() > halfFrame) // 8 millisecons // if( inputs.getTickCounter() > halfFrame) // 8 millisecons
{ // {
while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){ while((inputs.gamepadQueue != undefined && inputs.gamepadQueue.length >= 1)){
var curkey = inputs.gamepadQueue.shift(); var curkey = inputs.gamepadQueue.shift();
if(curkey == "DPad-Left") { if(curkey == "DPad-Left") {
@ -507,14 +500,13 @@ Tetris.prototype = {
} }
inputs.gamepadQueue = []; inputs.gamepadQueue = [];
} // }
//inputs.gamepadButtonClear(); //inputs.gamepadButtonClear();
} }
// Do keyboard // Do keyboard
inputs.processKeys(); inputs.processKeys();
inputs.processKeyShift(); inputs.processKeyShift();
// Keyboard inputs // Keyboard inputs
while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){ while((inputs.inputQueue != undefined && inputs.inputQueue.length >= 1)){