Skip to content

Commit

Permalink
1.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Aug 7, 2024
1 parent 07f12a2 commit 639de26
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 64 deletions.
4 changes: 2 additions & 2 deletions dist/littlejs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ declare module "littlejs.esm" {
setHSLA(h?: number, s?: number, l?: number, a?: number): Color;
/** Returns this color expressed in hsla format
* @return {Array} */
getHSLA(): any[];
HSLA(): any[];
/** Returns a new color that has each component randomly adjusted
* @param {Number} [amount]
* @param {Number} [alphaAmount]
Expand Down Expand Up @@ -1473,7 +1473,7 @@ declare module "littlejs.esm" {
* 1, 0, 9, 1 // channel notes
* ],
* [ // channel 1
* 0, 1, // instrument 1, right speaker
* 0, 1, // instrument 0, right speaker
* 0, 12, 17, -1 // channel notes
* ]
* ],
Expand Down
47 changes: 28 additions & 19 deletions dist/littlejs.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ class Color

/** Returns this color expressed in hsla format
* @return {Array} */
getHSLA()
HSLA()
{
const r = clamp(this.r);
const g = clamp(this.g);
Expand Down Expand Up @@ -2724,9 +2724,21 @@ function mouseToScreen(mousePos)
///////////////////////////////////////////////////////////////////////////////
// Gamepad input

// gamepad internal variables
const stickData = [];

// gamepads are updated by engine every frame automatically
function gamepadsUpdate()
{
const applyDeadZones = (v)=>
{
const min=.3, max=.8;
const deadZone = (v)=>
v > min ? percent( v, min, max) :
v < -min ? -percent(-v, min, max) : 0;
return vec2(deadZone(v.x), deadZone(-v.y)).clampLength();
}

// update touch gamepad if enabled
if (touchGamepadEnable && isTouchDevice)
{
Expand All @@ -2738,7 +2750,16 @@ function gamepadsUpdate()
{
// read virtual analog stick
const sticks = stickData[0] || (stickData[0] = []);
sticks[0] = vec2(touchGamepadStick.x, -touchGamepadStick.y); // flip vertical
sticks[0] = vec2();
if (touchGamepadAnalog)
sticks[0] = applyDeadZones(touchGamepadStick);
else if (touchGamepadStick.lengthSquared() > .3)
{
// convert to 8 way dpad
sticks[0].x = Math.round(touchGamepadStick.x);
sticks[0].y = -Math.round(touchGamepadStick.y);
sticks[0] = sticks[0].clampLength();
}

// read virtual gamepad buttons
const data = inputData[1] || (inputData[1] = []);
Expand Down Expand Up @@ -2769,14 +2790,9 @@ function gamepadsUpdate()

if (gamepad)
{
// read clamp dead zone of analog sticks
const deadZone = .3, deadZoneMax = .8, applyDeadZone = (v)=>
v > deadZone ? percent( v, deadZone, deadZoneMax) :
v < -deadZone ? -percent(-v, deadZone, deadZoneMax) : 0;

// read analog sticks
for (let j = 0; j < gamepad.axes.length-1; j+=2)
sticks[j>>1] = vec2(applyDeadZone(gamepad.axes[j]), applyDeadZone(-gamepad.axes[j+1])).clampLength();
sticks[j>>1] = applyDeadZones(vec2(gamepad.axes[j],gamepad.axes[j+1]));

// read buttons
for (let j = gamepad.buttons.length; j--;)
Expand Down Expand Up @@ -2905,14 +2921,7 @@ function createTouchGamepad()
if (touchPos.distance(stickCenter) < touchGamepadSize)
{
// virtual analog stick
if (touchGamepadAnalog)
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
else
{
// 8 way dpad
const angle = touchPos.subtract(stickCenter).angle();
touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
}
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
}
else if (touchPos.distance(buttonCenter) < touchGamepadSize)
{
Expand Down Expand Up @@ -3171,7 +3180,7 @@ class SoundWave extends Sound
* 1, 0, 9, 1 // channel notes
* ],
* [ // channel 1
* 0, 1, // instrument 1, right speaker
* 0, 1, // instrument 0, right speaker
* 0, 12, 17, -1 // channel notes
* ]
* ],
Expand Down Expand Up @@ -4981,7 +4990,7 @@ const engineName = 'LittleJS';
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.9.3';
const engineVersion = '1.9.4';

/** Frames per second to update
* @type {Number}
Expand Down Expand Up @@ -5063,7 +5072,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
timeReal += frameTimeDeltaMS / 1e3;
frameTimeBufferMS += paused ? 0 : frameTimeDeltaMS;
if (!debugSpeedUp)
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp incase of slow framerate
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp in case of slow framerate
updateCanvas();

if (paused)
Expand Down
2 changes: 1 addition & 1 deletion dist/littlejs.esm.min.js

Large diffs are not rendered by default.

47 changes: 28 additions & 19 deletions dist/littlejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ class Color

/** Returns this color expressed in hsla format
* @return {Array} */
getHSLA()
HSLA()
{
const r = clamp(this.r);
const g = clamp(this.g);
Expand Down Expand Up @@ -2724,9 +2724,21 @@ function mouseToScreen(mousePos)
///////////////////////////////////////////////////////////////////////////////
// Gamepad input

// gamepad internal variables
const stickData = [];

// gamepads are updated by engine every frame automatically
function gamepadsUpdate()
{
const applyDeadZones = (v)=>
{
const min=.3, max=.8;
const deadZone = (v)=>
v > min ? percent( v, min, max) :
v < -min ? -percent(-v, min, max) : 0;
return vec2(deadZone(v.x), deadZone(-v.y)).clampLength();
}

// update touch gamepad if enabled
if (touchGamepadEnable && isTouchDevice)
{
Expand All @@ -2738,7 +2750,16 @@ function gamepadsUpdate()
{
// read virtual analog stick
const sticks = stickData[0] || (stickData[0] = []);
sticks[0] = vec2(touchGamepadStick.x, -touchGamepadStick.y); // flip vertical
sticks[0] = vec2();
if (touchGamepadAnalog)
sticks[0] = applyDeadZones(touchGamepadStick);
else if (touchGamepadStick.lengthSquared() > .3)
{
// convert to 8 way dpad
sticks[0].x = Math.round(touchGamepadStick.x);
sticks[0].y = -Math.round(touchGamepadStick.y);
sticks[0] = sticks[0].clampLength();
}

// read virtual gamepad buttons
const data = inputData[1] || (inputData[1] = []);
Expand Down Expand Up @@ -2769,14 +2790,9 @@ function gamepadsUpdate()

if (gamepad)
{
// read clamp dead zone of analog sticks
const deadZone = .3, deadZoneMax = .8, applyDeadZone = (v)=>
v > deadZone ? percent( v, deadZone, deadZoneMax) :
v < -deadZone ? -percent(-v, deadZone, deadZoneMax) : 0;

// read analog sticks
for (let j = 0; j < gamepad.axes.length-1; j+=2)
sticks[j>>1] = vec2(applyDeadZone(gamepad.axes[j]), applyDeadZone(-gamepad.axes[j+1])).clampLength();
sticks[j>>1] = applyDeadZones(vec2(gamepad.axes[j],gamepad.axes[j+1]));

// read buttons
for (let j = gamepad.buttons.length; j--;)
Expand Down Expand Up @@ -2905,14 +2921,7 @@ function createTouchGamepad()
if (touchPos.distance(stickCenter) < touchGamepadSize)
{
// virtual analog stick
if (touchGamepadAnalog)
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
else
{
// 8 way dpad
const angle = touchPos.subtract(stickCenter).angle();
touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
}
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
}
else if (touchPos.distance(buttonCenter) < touchGamepadSize)
{
Expand Down Expand Up @@ -3171,7 +3180,7 @@ class SoundWave extends Sound
* 1, 0, 9, 1 // channel notes
* ],
* [ // channel 1
* 0, 1, // instrument 1, right speaker
* 0, 1, // instrument 0, right speaker
* 0, 12, 17, -1 // channel notes
* ]
* ],
Expand Down Expand Up @@ -4981,7 +4990,7 @@ const engineName = 'LittleJS';
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.9.3';
const engineVersion = '1.9.4';

/** Frames per second to update
* @type {Number}
Expand Down Expand Up @@ -5063,7 +5072,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
timeReal += frameTimeDeltaMS / 1e3;
frameTimeBufferMS += paused ? 0 : frameTimeDeltaMS;
if (!debugSpeedUp)
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp incase of slow framerate
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp in case of slow framerate
updateCanvas();

if (paused)
Expand Down
2 changes: 1 addition & 1 deletion dist/littlejs.min.js

Large diffs are not rendered by default.

47 changes: 28 additions & 19 deletions dist/littlejs.release.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ class Color

/** Returns this color expressed in hsla format
* @return {Array} */
getHSLA()
HSLA()
{
const r = clamp(this.r);
const g = clamp(this.g);
Expand Down Expand Up @@ -2338,9 +2338,21 @@ function mouseToScreen(mousePos)
///////////////////////////////////////////////////////////////////////////////
// Gamepad input

// gamepad internal variables
const stickData = [];

// gamepads are updated by engine every frame automatically
function gamepadsUpdate()
{
const applyDeadZones = (v)=>
{
const min=.3, max=.8;
const deadZone = (v)=>
v > min ? percent( v, min, max) :
v < -min ? -percent(-v, min, max) : 0;
return vec2(deadZone(v.x), deadZone(-v.y)).clampLength();
}

// update touch gamepad if enabled
if (touchGamepadEnable && isTouchDevice)
{
Expand All @@ -2352,7 +2364,16 @@ function gamepadsUpdate()
{
// read virtual analog stick
const sticks = stickData[0] || (stickData[0] = []);
sticks[0] = vec2(touchGamepadStick.x, -touchGamepadStick.y); // flip vertical
sticks[0] = vec2();
if (touchGamepadAnalog)
sticks[0] = applyDeadZones(touchGamepadStick);
else if (touchGamepadStick.lengthSquared() > .3)
{
// convert to 8 way dpad
sticks[0].x = Math.round(touchGamepadStick.x);
sticks[0].y = -Math.round(touchGamepadStick.y);
sticks[0] = sticks[0].clampLength();
}

// read virtual gamepad buttons
const data = inputData[1] || (inputData[1] = []);
Expand Down Expand Up @@ -2383,14 +2404,9 @@ function gamepadsUpdate()

if (gamepad)
{
// read clamp dead zone of analog sticks
const deadZone = .3, deadZoneMax = .8, applyDeadZone = (v)=>
v > deadZone ? percent( v, deadZone, deadZoneMax) :
v < -deadZone ? -percent(-v, deadZone, deadZoneMax) : 0;

// read analog sticks
for (let j = 0; j < gamepad.axes.length-1; j+=2)
sticks[j>>1] = vec2(applyDeadZone(gamepad.axes[j]), applyDeadZone(-gamepad.axes[j+1])).clampLength();
sticks[j>>1] = applyDeadZones(vec2(gamepad.axes[j],gamepad.axes[j+1]));

// read buttons
for (let j = gamepad.buttons.length; j--;)
Expand Down Expand Up @@ -2519,14 +2535,7 @@ function createTouchGamepad()
if (touchPos.distance(stickCenter) < touchGamepadSize)
{
// virtual analog stick
if (touchGamepadAnalog)
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
else
{
// 8 way dpad
const angle = touchPos.subtract(stickCenter).angle();
touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
}
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
}
else if (touchPos.distance(buttonCenter) < touchGamepadSize)
{
Expand Down Expand Up @@ -2785,7 +2794,7 @@ class SoundWave extends Sound
* 1, 0, 9, 1 // channel notes
* ],
* [ // channel 1
* 0, 1, // instrument 1, right speaker
* 0, 1, // instrument 0, right speaker
* 0, 12, 17, -1 // channel notes
* ]
* ],
Expand Down Expand Up @@ -4595,7 +4604,7 @@ const engineName = 'LittleJS';
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.9.3';
const engineVersion = '1.9.4';

/** Frames per second to update
* @type {Number}
Expand Down Expand Up @@ -4677,7 +4686,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
timeReal += frameTimeDeltaMS / 1e3;
frameTimeBufferMS += paused ? 0 : frameTimeDeltaMS;
if (!debugSpeedUp)
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp incase of slow framerate
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp in case of slow framerate
updateCanvas();

if (paused)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "littlejsengine",
"version": "1.9.3",
"version": "1.9.4",
"description": "LittleJS - Tiny and Fast HTML5 Game Engine",
"main": "dist/littlejs.esm.js",
"types": "dist/littlejs.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const engineName = 'LittleJS';
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.9.3';
const engineVersion = '1.9.4';

/** Frames per second to update
* @type {Number}
Expand Down

0 comments on commit 639de26

Please sign in to comment.