rapid-render 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -24,8 +24,8 @@ Rapid is a focused WebGL 2D rendering engine for games and visual tools. lightwe
24
24
 
25
25
  ## Highlights
26
26
 
27
- - **Automatic batching**
28
- Rapid automatically batches compatible draw work. Multi-texture batching binds different textures into a single draw call, eliminating manual grouping.
27
+ - **Rendering speed**
28
+ An efficient batching system significantly reduces draw calls, allowing Rapid.js to maintain smooth, stable performance even when rendering large numbers of sprites at once.
29
29
 
30
30
  - **Powerful custom shaders**
31
31
  Add sprite and geometry effects through shader hooks while still using Rapid's normal renderer, transforms, textures, and draw APIs.
@@ -68,7 +68,6 @@ Performance Comparison: Rapid vs. Other Renderers and Game Engines
68
68
  <p align="center">
69
69
  <a href="https://nightre.github.io/Rapid.js/benchmark/">
70
70
  <img src="./docs/benchmark/benchmark.png" alt="Benchmark Result">
71
- <img src="./docs/benchmark/benchmark2.png" alt="Benchmark Result">
72
71
  </a>
73
72
  </p>
74
73
 
package/dist/buffer.d.ts CHANGED
@@ -49,6 +49,7 @@ export declare class DynamicArrayBuffer {
49
49
  * Resets the element usage count to zero. The underlying memory capacity is preserved.
50
50
  */
51
51
  clear(): void;
52
+ static removeAtIndices(indices: number[], targets: DynamicArrayBuffer[]): number;
52
53
  /**
53
54
  * Checks if the buffer has enough space for additional elements and resizes the buffer if necessary.
54
55
  * @param size - The number of new elements that need to be accommodated.
package/dist/color.d.ts CHANGED
@@ -104,6 +104,8 @@ export declare class Color {
104
104
  static FromHSL(h: number, s: number, l: number): Color;
105
105
  static FromRGB(r: number, g: number, b: number): Color;
106
106
  static fromNorm(r: number, g: number, b: number, a?: number): Color;
107
+ static clampColorByte(value: number): number;
108
+ static packColor(r: number, g: number, b: number, a: number, premultipliedAlpha: boolean): number;
107
109
  /**
108
110
  * Creates a Color instance from a hexadecimal color string.
109
111
  * @param hexString - The hexadecimal color string, e.g., '#RRGGBB' or '#RRGGBBAA'.
package/dist/draw.d.ts CHANGED
@@ -10,25 +10,26 @@ export type DrawPoint = Vec2 | {
10
10
  x: number;
11
11
  y: number;
12
12
  };
13
- export interface IDrawOptions extends ITransformOptions {
13
+ export interface IDrawOptions extends ITransformOptions, IDisplayOptions {
14
+ }
15
+ export interface IDisplayOptions {
14
16
  shader?: DrawShader;
15
17
  customMatrix?: number;
16
18
  }
17
- export interface IDrawParticleBatchOptions {
18
- shader?: DrawShader;
19
+ export interface IDrawParticleBatchOptions extends IDisplayOptions {
19
20
  texture: Texture;
20
- x: Array<number>;
21
- y: Array<number>;
22
- rotation: Array<number>;
23
- color: Array<Color>;
21
+ x: ArrayLike<number>;
22
+ y: ArrayLike<number>;
23
+ rotation?: ArrayLike<number> | number;
24
+ color?: ArrayLike<Color> | ArrayLike<number> | number;
24
25
  count?: number;
25
- scaleX?: number;
26
- scaleY?: number;
26
+ scaleX?: ArrayLike<number>;
27
+ scaleY?: ArrayLike<number>;
27
28
  originX?: number;
28
29
  originY?: number;
29
30
  flipX?: boolean;
30
31
  flipY?: boolean;
31
- isRotated?: boolean;
32
+ reverseOrder?: boolean;
32
33
  }
33
34
  export interface ISpriteOptions extends IDrawOptions {
34
35
  texture: Texture;
@@ -60,7 +61,7 @@ export interface ICircleOptions extends IDrawOptions {
60
61
  color?: Color;
61
62
  segments?: number;
62
63
  }
63
- export declare const drawSpriteRaw: (rapid: Rapid, options: ISpriteOptions) => void;
64
+ export declare const getColorUint32: (premultipliedAlpha: boolean, color?: Color) => number;
64
65
  export declare const drawSprite: (rapid: Rapid, options: ISpriteOptions) => void;
65
66
  export declare const drawParticles: (rapid: Rapid, options: IDrawParticleBatchOptions) => void;
66
67
  export declare const drawGraphic: (rapid: Rapid, options: IGraphicOptions) => void;
@@ -3,9 +3,7 @@ import { Vec2 } from './math';
3
3
  import { Rapid } from './render';
4
4
  export interface ITransformOptions {
5
5
  /** Whether to push a save before applying transforms. Default: true. */
6
- saveTransform?: boolean;
7
- /** Called immediately after the save (if any). */
8
- afterSave?: () => void;
6
+ modifyStack?: boolean;
9
7
  x?: number;
10
8
  y?: number;
11
9
  position?: Vec2;
@@ -28,6 +26,7 @@ export declare class MatrixStore {
28
26
  buffer: DynamicArrayBuffer;
29
27
  /** The raw floating-point data of all matrices. */
30
28
  data: Float32Array;
29
+ temporary: number;
31
30
  /**
32
31
  * Creates a new MatrixStore.
33
32
  * @param capacity - The initial capacity of the matrix store (default is 10).
@@ -203,6 +202,7 @@ export declare class MatrixStore {
203
202
  */
204
203
  setMatrix(index: number, f: Float32Array | number[]): void;
205
204
  multiplyAffineInPlace(index: number, a: number, b: number, c: number, dValue: number, tx: number, ty: number): void;
205
+ multiplyAffine(indexIn: number, indexOut: number, a: number, b: number, c: number, dValue: number, tx: number, ty: number): void;
206
206
  }
207
207
  /**
208
208
  * A highly performant MatrixStack useful for hierarchal scene graphs.
@@ -355,7 +355,7 @@ export declare class MatrixStack {
355
355
  };
356
356
  /**
357
357
  * Applies a transform options object to the current matrix state.
358
- * Optionally saves the matrix first (saveTransform defaults to true).
358
+ * Optionally saves the matrix first
359
359
  */
360
- applyTransform(transform: ITransformOptions, width?: number, height?: number): void;
360
+ applyTransform(transform: ITransformOptions, width?: number, height?: number, customMatrix?: number): void;
361
361
  }
@@ -2,12 +2,13 @@ import { Color } from './color';
2
2
  import { Vec2 } from './math';
3
3
  import { Rapid } from './render';
4
4
  import { Texture } from './texture';
5
- export type ParticleAttributeTypes = number | Vec2 | Color;
5
+ import { DynamicArrayBuffer } from './buffer';
6
+ import { CustomGlShader } from './webgl/glshader';
6
7
  /**
7
8
  * Describes an animated attribute: it transitions from `start` to `end`
8
9
  * over the particle's lifetime, optionally with a per-second damping factor.
9
10
  */
10
- export interface ParticleAttribute<T extends ParticleAttributeTypes> {
11
+ export interface ParticleAttribute<T = number> {
11
12
  /** Starting value (scalar, range tuple, or fixed value). */
12
13
  start?: T | [T, T];
13
14
  /** Ending value. Defaults to `start` if omitted (no change over time). */
@@ -24,7 +25,7 @@ export interface ParticleAttribute<T extends ParticleAttributeTypes> {
24
25
  delta?: T;
25
26
  }
26
27
  /** Internal resolved state of one animated attribute. */
27
- export interface ParticleAttributeData<T extends ParticleAttributeTypes> {
28
+ export interface ParticleAttributeData<T = number> {
28
29
  value: T;
29
30
  delta?: T;
30
31
  damping?: number;
@@ -48,7 +49,8 @@ export interface IParticleAnimation {
48
49
  }
49
50
  export interface IParticleOptions {
50
51
  /** Texture(s) to pick from. Pass a weighted tuple `[Texture, weight][]` for weighted random. */
51
- texture: Texture | Texture[] | [Texture, number][];
52
+ texture: Texture;
53
+ shader: CustomGlShader;
52
54
  /** Particle lifetime in seconds, or a [min, max] range. */
53
55
  life: number | [number, number];
54
56
  /** Animation / per-attribute configuration. */
@@ -73,37 +75,22 @@ export interface IParticleOptions {
73
75
  emitTime?: number;
74
76
  /** Whether particles are positioned relative to the emitter (default: true). */
75
77
  localSpace?: boolean;
76
- /** World-space position of the emitter (used when localSpace is false). */
77
- position?: Vec2;
78
78
  origin?: Vec2;
79
79
  }
80
- export declare class Particle {
81
- private life;
82
- private maxLife;
83
- private texture;
84
- private options;
85
- private position;
86
- private datas;
87
- private rapid;
88
- constructor(rapid: Rapid, options: IParticleOptions);
89
- private processAttribute;
90
- private updateNumberAttribute;
91
- private updateVec2Attribute;
92
- private updateColorAttribute;
93
- private updateAttributes;
94
- private getDelta;
95
- /**
96
- * Updates particle state.
97
- * @param deltaTime - Seconds elapsed since last frame
98
- * @returns `true` while the particle is alive, `false` when it should be removed
99
- */
100
- update(deltaTime: number): boolean;
101
- /**
102
- * Renders the particle using the Rapid engine's matrixStack + drawSprite.
103
- * The emitter is responsible for calling save/restore around a batch of particles.
104
- */
105
- render(): void;
106
- private initializePosition;
80
+ type ParticleAttributeValue = number | Vec2 | Color;
81
+ declare class ParticleAttributeStore {
82
+ readonly components: {
83
+ value: DynamicArrayBuffer;
84
+ delta: DynamicArrayBuffer;
85
+ damping: DynamicArrayBuffer;
86
+ }[];
87
+ constructor(size?: number);
88
+ getArrayBuffer(): DynamicArrayBuffer[];
89
+ update(deltaTime: number): void;
90
+ get(particleIndex: number, componentIndex?: number): number;
91
+ private getComponent;
92
+ private resolveComponent;
93
+ create<T extends ParticleAttributeValue>(attribute: ParticleAttribute<T> | T | undefined, defaultData: T, lifeTime?: number): number;
107
94
  }
108
95
  /**
109
96
  * Creates and manages a pool of Particle instances.
@@ -119,7 +106,6 @@ export declare class Particle {
119
106
  * ```
120
107
  */
121
108
  export declare class ParticleEmitter {
122
- private particles;
123
109
  private options;
124
110
  private emitting;
125
111
  private emitTimer;
@@ -128,16 +114,28 @@ export declare class ParticleEmitter {
128
114
  private emitTimeCounter;
129
115
  /** Whether spawned particles are positioned in local emitter space (default: true). */
130
116
  localSpace: boolean;
131
- /** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
132
- position: Vec2;
133
117
  private rapid;
134
- gameObject?: unknown;
118
+ x: DynamicArrayBuffer;
119
+ y: DynamicArrayBuffer;
120
+ scaleX: DynamicArrayBuffer;
121
+ scaleY: DynamicArrayBuffer;
122
+ rotation: DynamicArrayBuffer;
123
+ color: DynamicArrayBuffer;
124
+ animations: {
125
+ speed: ParticleAttributeStore;
126
+ rotation: ParticleAttributeStore;
127
+ scale: ParticleAttributeStore;
128
+ color: ParticleAttributeStore;
129
+ velocity: ParticleAttributeStore;
130
+ };
131
+ count: number;
135
132
  /**
136
133
  * Creates a new particle emitter.
137
134
  * @param rapid - The Rapid renderer instance
138
135
  * @param options - Emitter configuration options
139
136
  */
140
137
  constructor(rapid: Rapid, options: IParticleOptions);
138
+ getAllArrayBuffer(): DynamicArrayBuffer[];
141
139
  /** Replaces the emitter's texture at runtime. */
142
140
  setTexture(texture: Texture): void;
143
141
  /**
@@ -160,18 +158,18 @@ export declare class ParticleEmitter {
160
158
  * Respects `maxParticles` if set.
161
159
  */
162
160
  emit(count: number): void;
161
+ createParticle(): void;
163
162
  /**
164
163
  * Updates the emitter and all live particles.
165
164
  * @param deltaTime - Seconds elapsed since last frame
166
165
  */
167
166
  update(deltaTime: number): void;
167
+ updateParticle(deltaTime: number): number[];
168
168
  /**
169
169
  * Renders all live particles.
170
170
  * In local-space mode the emitter's own transform is applied around the batch.
171
171
  */
172
172
  render(): void;
173
- /** Returns the current number of live particles. */
174
- getParticleCount(): number;
175
173
  /** Returns `true` if the emitter is running or still has live particles. */
176
174
  isActive(): boolean;
177
175
  /**
@@ -179,3 +177,4 @@ export declare class ParticleEmitter {
179
177
  */
180
178
  oneShot(): void;
181
179
  }
180
+ export {};