littlejsengine 1.18.26 → 1.18.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/littlejs.d.ts +61 -2
- package/dist/littlejs.esm.js +175 -45
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +169 -45
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +169 -45
- package/package.json +2 -1
- package/plugins/threejs.js +3 -0
- package/src/engine.js +1 -1
- package/src/engineAudio.js +103 -39
- package/src/engineDraw.js +15 -0
- package/src/engineExport.js +6 -0
- package/src/engineInput.js +34 -5
- package/src/engineSettings.js +13 -0
package/src/engineExport.js
CHANGED
|
@@ -84,6 +84,7 @@ export
|
|
|
84
84
|
glCircleSides,
|
|
85
85
|
gamepadsEnable,
|
|
86
86
|
gamepadDirectionEmulateStick,
|
|
87
|
+
gamepadAxisFilterEnable,
|
|
87
88
|
inputWASDEmulateDirection,
|
|
88
89
|
touchInputEnable,
|
|
89
90
|
touchGamepadEnable,
|
|
@@ -140,6 +141,7 @@ export
|
|
|
140
141
|
setTouchInputEnable,
|
|
141
142
|
setGamepadsEnable,
|
|
142
143
|
setGamepadDirectionEmulateStick,
|
|
144
|
+
setGamepadAxisFilterEnable,
|
|
143
145
|
setInputWASDEmulateDirection,
|
|
144
146
|
setTouchGamepadEnable,
|
|
145
147
|
setTouchGamepadPassthrough,
|
|
@@ -255,6 +257,7 @@ export
|
|
|
255
257
|
workContext,
|
|
256
258
|
workReadCanvas,
|
|
257
259
|
workReadContext,
|
|
260
|
+
backgroundCanvas,
|
|
258
261
|
mainCanvasSize,
|
|
259
262
|
textureInfos,
|
|
260
263
|
drawCount,
|
|
@@ -280,6 +283,7 @@ export
|
|
|
280
283
|
drawText,
|
|
281
284
|
drawTextScreen,
|
|
282
285
|
setAdditiveBlendMode,
|
|
286
|
+
setBackgroundCanvas,
|
|
283
287
|
combineCanvases,
|
|
284
288
|
engineImageFont,
|
|
285
289
|
ImageFont,
|
|
@@ -367,6 +371,8 @@ export
|
|
|
367
371
|
speakStop,
|
|
368
372
|
getNoteFrequency,
|
|
369
373
|
playSamples,
|
|
374
|
+
playAudioBuffer,
|
|
375
|
+
createAudioBuffer,
|
|
370
376
|
zzfx,
|
|
371
377
|
zzfxG,
|
|
372
378
|
|
package/src/engineInput.js
CHANGED
|
@@ -124,6 +124,7 @@ function inputClear()
|
|
|
124
124
|
touchGamepadStickPointerId.length = 0; // release floating sticks so they re-anchor
|
|
125
125
|
gamepadStickData.length = 0;
|
|
126
126
|
gamepadDpadData.length = 0;
|
|
127
|
+
gamepadAxisCentered.length = 0;
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -361,6 +362,11 @@ const inputData = [[]];
|
|
|
361
362
|
|
|
362
363
|
// gamepad internal variables
|
|
363
364
|
const gamepadStickData = [], gamepadDpadData = [], gamepadHadInput = [];
|
|
365
|
+
// per gamepad, how many consecutive frames each axis has rested inside the
|
|
366
|
+
// dead zone, used to tell stick axes from axes that rest at full deflection
|
|
367
|
+
const gamepadAxisCentered = [];
|
|
368
|
+
// how long an axis must rest inside the dead zone before it counts as a stick
|
|
369
|
+
const gamepadAxisCenteredFrames = 15;
|
|
364
370
|
|
|
365
371
|
// touch gamepad internal variables
|
|
366
372
|
const touchGamepadTimer = new Timer, touchGamepadButtons = [], touchGamepadSticks = [];
|
|
@@ -609,7 +615,7 @@ function inputUpdate()
|
|
|
609
615
|
// gamepad: any button held or stick moved
|
|
610
616
|
let gamepadActive = false;
|
|
611
617
|
for (let s = gamepadStickCount(); s-- && !gamepadActive;)
|
|
612
|
-
gamepadActive = gamepadStick(s).lengthSquared() > .
|
|
618
|
+
gamepadActive = gamepadStick(s).lengthSquared() > .2;
|
|
613
619
|
for (let b = 17; b-- && !gamepadActive;)
|
|
614
620
|
gamepadActive = gamepadIsDown(b);
|
|
615
621
|
|
|
@@ -637,12 +643,12 @@ function inputUpdate()
|
|
|
637
643
|
// gamepads are updated by engine every frame automatically
|
|
638
644
|
function gamepadsUpdate()
|
|
639
645
|
{
|
|
646
|
+
const deadZoneMin=.3, deadZoneMax=.8;
|
|
640
647
|
const applyDeadZones = (v)=>
|
|
641
648
|
{
|
|
642
|
-
const min=.3, max=.8;
|
|
643
649
|
const deadZone = (v)=>
|
|
644
|
-
v >
|
|
645
|
-
v < -
|
|
650
|
+
v > deadZoneMin ? percent(v, deadZoneMin, deadZoneMax) :
|
|
651
|
+
v < -deadZoneMin ? -percent(-v, deadZoneMin, deadZoneMax) : 0;
|
|
646
652
|
return vec2(deadZone(v.x), deadZone(-v.y)).clampLength();
|
|
647
653
|
};
|
|
648
654
|
|
|
@@ -726,6 +732,7 @@ function inputUpdate()
|
|
|
726
732
|
gamepadStickData[i] = undefined;
|
|
727
733
|
gamepadDpadData[i] = undefined;
|
|
728
734
|
gamepadHadInput[i] = undefined;
|
|
735
|
+
gamepadAxisCentered[i] = undefined;
|
|
729
736
|
continue;
|
|
730
737
|
}
|
|
731
738
|
|
|
@@ -734,8 +741,30 @@ function inputUpdate()
|
|
|
734
741
|
const dpad = gamepadDpadData[i] ?? (gamepadDpadData[i] = vec2());
|
|
735
742
|
|
|
736
743
|
// read analog sticks
|
|
744
|
+
// gamepads without standard mapping (steering wheels, flight sticks)
|
|
745
|
+
// can report axes that rest at full deflection instead of center,
|
|
746
|
+
// which would otherwise read as a stick held down forever, so only
|
|
747
|
+
// trust an axis once it has rested inside the dead zone for a moment
|
|
748
|
+
const isStandard = gamepad.mapping === 'standard';
|
|
749
|
+
const centered = gamepadAxisCentered[i] ?? (gamepadAxisCentered[i] = []);
|
|
750
|
+
const readAxis = (j)=>
|
|
751
|
+
{
|
|
752
|
+
const v = gamepad.axes[j];
|
|
753
|
+
if (isStandard && j < 4)
|
|
754
|
+
return v; // spec guarantees axes 0-3 are the two sticks
|
|
755
|
+
if (!gamepadAxisFilterEnable)
|
|
756
|
+
return v;
|
|
757
|
+
|
|
758
|
+
// once an axis has proven it rests at center it stays trusted,
|
|
759
|
+
// otherwise moving it would immediately disqualify it again
|
|
760
|
+
const frames = centered[j] | 0;
|
|
761
|
+
if (frames > gamepadAxisCenteredFrames)
|
|
762
|
+
return v;
|
|
763
|
+
centered[j] = abs(v) < deadZoneMin ? frames + 1 : 0;
|
|
764
|
+
return 0;
|
|
765
|
+
};
|
|
737
766
|
for (let j = 0; j < gamepad.axes.length-1; j+=2)
|
|
738
|
-
sticks[j>>1] = applyDeadZones(vec2(
|
|
767
|
+
sticks[j>>1] = applyDeadZones(vec2(readAxis(j), readAxis(j+1)));
|
|
739
768
|
|
|
740
769
|
// read buttons
|
|
741
770
|
let hadInput = false;
|
package/src/engineSettings.js
CHANGED
|
@@ -236,6 +236,14 @@ let gamepadsEnable = true;
|
|
|
236
236
|
* @memberof Settings */
|
|
237
237
|
let gamepadDirectionEmulateStick = true;
|
|
238
238
|
|
|
239
|
+
/** If true, axes that do not rest near center are ignored on gamepads without
|
|
240
|
+
* standard mapping. Steering wheels and flight sticks report pedal and throttle
|
|
241
|
+
* axes that rest at full deflection, which otherwise reads as a stick held down.
|
|
242
|
+
* @type {boolean}
|
|
243
|
+
* @default
|
|
244
|
+
* @memberof Settings */
|
|
245
|
+
let gamepadAxisFilterEnable = true;
|
|
246
|
+
|
|
239
247
|
/** If true the WASD keys are also routed to the direction keys (for better accessibility)
|
|
240
248
|
* @type {boolean}
|
|
241
249
|
* @default
|
|
@@ -574,6 +582,11 @@ function setGamepadsEnable(enable) { gamepadsEnable = enable; }
|
|
|
574
582
|
* @memberof Settings */
|
|
575
583
|
function setGamepadDirectionEmulateStick(enable) { gamepadDirectionEmulateStick = enable; }
|
|
576
584
|
|
|
585
|
+
/** Set if axes that do not rest near center are ignored on non-standard gamepads
|
|
586
|
+
* @param {boolean} enable
|
|
587
|
+
* @memberof Settings */
|
|
588
|
+
function setGamepadAxisFilterEnable(enable) { gamepadAxisFilterEnable = enable; }
|
|
589
|
+
|
|
577
590
|
/** Set if true the WASD keys are also routed to the direction keys
|
|
578
591
|
* @param {boolean} enable
|
|
579
592
|
* @memberof Settings */
|