q5play 4.1.0 → 4.1.1

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/q5play.d.ts +2 -2
  3. package/q5play.js +10 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5play",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "author": "quinton-ashley",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "description": "A beginner friendly, web-based game engine that uses q5.js WebGPU for graphics and Box2D v3 WASM for physics.",
package/q5play.d.ts CHANGED
@@ -1932,8 +1932,8 @@ declare global {
1932
1932
  * @param startPos starting position of the ray cast
1933
1933
  * @param direction direction of the ray
1934
1934
  * @param maxDistance max distance the ray should check
1935
- * @param limiter limiter function that's run each time the ray intersects a sprite, return true to stop the ray
1936
- * @returns An array of sprites that the ray cast hit, sorted by distance. The sprite closest to the starting point will be at index 0.
1935
+ * @param limiter callback that's run each time the ray intersects a sprite, receives an intersected sprite as an input parameter, return true to stop the ray
1936
+ * @returns An array of sprites that the ray cast hit, sorted by distance. The sprite closest to the starting point will be at index 0. If a limiter is provided, this array includes the sprite that caused the ray to stop.
1937
1937
  */
1938
1938
  rayCastAll(startPos: any, direction: number, maxDistance: number, limiter?: Function): Sprite[];
1939
1939
  /**
package/q5play.js CHANGED
@@ -381,7 +381,10 @@ async function q5playPreSetup(q) {
381
381
  $.imageMode($.CENTER);
382
382
 
383
383
  const ZERO_VEC = new b2Vec2(0, 0),
384
- ZERO_ROT = b2MakeRot(0);
384
+ ZERO_ROT = b2MakeRot(0),
385
+ NULL_FILTER = new b2QueryFilter();
386
+ NULL_FILTER.categoryBits = 0xffffffff;
387
+ NULL_FILTER.maskBits = 0xffffffff;
385
388
 
386
389
  let meterSize = 60;
387
390
 
@@ -5075,14 +5078,9 @@ async function q5playPreSetup(q) {
5075
5078
 
5076
5079
  const point = scaleTo(x, y),
5077
5080
  proxy = b2MakeProxy(point, 1, radius / meterSize),
5078
- filter = new b2QueryFilter(),
5079
5081
  shapes = [];
5080
5082
 
5081
- // no filter
5082
- filter.categoryBits = 0xffffffff;
5083
- filter.maskBits = 0xffffffff;
5084
-
5085
- b2World_OverlapShape(wID, proxy, filter, (overlapResult) => {
5083
+ b2World_OverlapShape(wID, proxy, NULL_FILTER, (overlapResult) => {
5086
5084
  const { shapeId } = overlapResult;
5087
5085
  if (shapeId) {
5088
5086
  shapes.push(shapeDict[shapeId.index1]);
@@ -5091,7 +5089,6 @@ async function q5playPreSetup(q) {
5091
5089
  });
5092
5090
 
5093
5091
  proxy.delete();
5094
- filter.delete();
5095
5092
 
5096
5093
  if (!shapes.length) return [];
5097
5094
 
@@ -5179,16 +5176,13 @@ async function q5playPreSetup(q) {
5179
5176
  const origin = scaleTo(startX, startY);
5180
5177
  const translation = scaleTo(endX - startX, endY - startY);
5181
5178
 
5182
- const filter = new b2QueryFilter();
5183
- filter.categoryBits = 0xffffffff;
5184
- filter.maskBits = 0xffffffff;
5185
-
5186
5179
  const results = [];
5187
5180
 
5188
- b2World_CastRay(wID, origin, translation, filter, (castResult) => {
5181
+ b2World_CastRay(wID, origin, translation, NULL_FILTER, (castResult) => {
5189
5182
  const shape = shapeDict[castResult.shapeId.index1];
5190
5183
  if (shape?.sprite) {
5191
5184
  const s = shape.sprite;
5185
+
5192
5186
  s.ray = new RayInfo(
5193
5187
  s,
5194
5188
  castResult.point.x,
@@ -5199,18 +5193,15 @@ async function q5playPreSetup(q) {
5199
5193
  maxDistance
5200
5194
  );
5201
5195
  results.push(s);
5196
+
5197
+ if (limiter && limiter(s)) return 0; // stop raycast
5202
5198
  }
5203
5199
  return 1; // continue to collect all hits
5204
5200
  });
5205
5201
 
5206
- filter.delete();
5207
-
5208
5202
  // sort results by distance from start
5209
5203
  results.sort((a, b) => a.ray.distance - b.ray.distance);
5210
-
5211
- if (!limiter) return results;
5212
-
5213
- return results.filter(limiter);
5204
+ return results;
5214
5205
  }
5215
5206
  };
5216
5207