rapid-render 0.1.0 → 0.1.2-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.
- package/README.md +59 -97
- package/dist/assets.d.ts +92 -0
- package/dist/audio.d.ts +59 -0
- package/dist/depth.d.ts +8 -0
- package/dist/game.d.ts +292 -0
- package/dist/index.d.ts +9 -3
- package/dist/input.d.ts +93 -0
- package/dist/interface.d.ts +337 -32
- package/dist/light.d.ts +7 -0
- package/dist/line.d.ts +15 -2
- package/dist/log.d.ts +2 -0
- package/dist/math.d.ts +272 -45
- package/dist/particle.d.ts +73 -0
- package/dist/rapid.global.js +1 -1
- package/dist/rapid.js +1 -1
- package/dist/rapid.umd.cjs +1 -1
- package/dist/regions/attributes.d.ts +44 -0
- package/dist/regions/graphic_region.d.ts +7 -20
- package/dist/regions/region.d.ts +23 -7
- package/dist/regions/sprite_region.d.ts +5 -26
- package/dist/render.d.ts +159 -45
- package/dist/texture.d.ts +105 -13
- package/dist/tilemap.d.ts +98 -0
- package/dist/utils.d.ts +106 -0
- package/dist/webgl/glshader.d.ts +15 -4
- package/dist/webgl/uniform.d.ts +14 -0
- package/dist/webgl/utils.d.ts +11 -1
- package/package.json +11 -5
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import Rapid from "./render";
|
|
2
|
+
import { IRegisterTileOptions, ILayerRenderOptions } from "./interface";
|
|
3
|
+
import { Texture } from "./texture";
|
|
4
|
+
import { Vec2 } from "./math";
|
|
5
|
+
/**
|
|
6
|
+
* Represents a tileset that manages tile textures and their properties.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TileSet {
|
|
9
|
+
/** Map storing tile textures and their associated options */
|
|
10
|
+
private textures;
|
|
11
|
+
/** Width of each tile in the tileset */
|
|
12
|
+
width: number;
|
|
13
|
+
/** Height of each tile in the tileset */
|
|
14
|
+
height: number;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new TileSet instance.
|
|
17
|
+
* @param width - The width of each tile in pixels
|
|
18
|
+
* @param height - The height of each tile in pixels
|
|
19
|
+
*/
|
|
20
|
+
constructor(width: number, height: number);
|
|
21
|
+
/**
|
|
22
|
+
* Registers a new tile with the given ID and options.
|
|
23
|
+
* @param id - The unique identifier for the tile
|
|
24
|
+
* @param options - The tile options or texture to register
|
|
25
|
+
*/
|
|
26
|
+
setTile(id: string | number, options: IRegisterTileOptions | Texture): void;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the registered tile options for the given ID.
|
|
29
|
+
* @param id - The unique identifier of the tile to retrieve
|
|
30
|
+
* @returns The registered tile options, or undefined if not found
|
|
31
|
+
*/
|
|
32
|
+
getTile(id: string | number): IRegisterTileOptions | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents a tilemap renderer that handles rendering of tile-based maps.
|
|
36
|
+
*/
|
|
37
|
+
export declare class TileMapRender {
|
|
38
|
+
private rapid;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new TileMapRender instance.
|
|
41
|
+
* @param rapid - The Rapid rendering instance to use.
|
|
42
|
+
*/
|
|
43
|
+
constructor(rapid: Rapid);
|
|
44
|
+
/**
|
|
45
|
+
* 将需要 y-sort 的回调根据它们的 y 坐标分组到一个 Map 中。
|
|
46
|
+
* 使用 Map 是为了避免因地图坐标过大而创建稀疏数组,从而优化内存使用。
|
|
47
|
+
*
|
|
48
|
+
* @param ySortCallbacks - Array of y-sort callbacks to process.
|
|
49
|
+
* @param height - The effective height of a tile row, used for grouping.
|
|
50
|
+
* @returns A Map where keys are row indices (y) and values are arrays of y-sort callbacks for that row.
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private getYSortRow;
|
|
54
|
+
/**
|
|
55
|
+
* Calculates the error offset values for tile rendering.
|
|
56
|
+
* @param options - Layer rendering options containing error values.
|
|
57
|
+
* @returns Object containing x and y error offsets.
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
private getOffset;
|
|
61
|
+
/**
|
|
62
|
+
* Renders a row of y-sorted entities.
|
|
63
|
+
* @param rapid - The Rapid rendering instance.
|
|
64
|
+
* @param ySortRow - Array of y-sort callbacks to render.
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
private renderYSortRow;
|
|
68
|
+
/**
|
|
69
|
+
* Calculates tile rendering data based on the viewport and tileset.
|
|
70
|
+
* @param tileSet - The tileset to use for rendering.
|
|
71
|
+
* @param options - Layer rendering options.
|
|
72
|
+
* @returns Object containing calculated tile rendering data.
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
private getTileData;
|
|
76
|
+
/**
|
|
77
|
+
* Renders the tilemap layer based on the provided data and options.
|
|
78
|
+
*
|
|
79
|
+
* @param data - A 2D array representing the tilemap data.
|
|
80
|
+
* @param options - The rendering options for the tilemap layer.
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
renderLayer(data: (number | string)[][], options: ILayerRenderOptions): void;
|
|
84
|
+
/**
|
|
85
|
+
* Converts local coordinates to map coordinates.
|
|
86
|
+
* @param local - The local coordinates.
|
|
87
|
+
* @param options - The rendering options.
|
|
88
|
+
* @returns The map coordinates.
|
|
89
|
+
*/
|
|
90
|
+
localToMap(local: Vec2, options: ILayerRenderOptions): Vec2;
|
|
91
|
+
/**
|
|
92
|
+
* Converts map coordinates to local coordinates.
|
|
93
|
+
* @param map - The map coordinates.
|
|
94
|
+
* @param options - The rendering options.
|
|
95
|
+
* @returns The local coordinates.
|
|
96
|
+
*/
|
|
97
|
+
mapToLocal(map: Vec2, options: ILayerRenderOptions): Vec2;
|
|
98
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { IMathObject } from './interface';
|
|
3
|
+
interface TweenrEvents {
|
|
4
|
+
complete: () => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Manages the interpolation of a property on a target object over a specific duration.
|
|
8
|
+
* @template T - The type of the value being tweened (e.g., number, Vec2, Color).
|
|
9
|
+
*/
|
|
10
|
+
export declare class Tween<T extends IMathObject<T> | number> extends EventEmitter<TweenrEvents> {
|
|
11
|
+
private target;
|
|
12
|
+
private property;
|
|
13
|
+
private to;
|
|
14
|
+
private from;
|
|
15
|
+
private duration;
|
|
16
|
+
private easing;
|
|
17
|
+
private elapsed;
|
|
18
|
+
isRunning: boolean;
|
|
19
|
+
isFinished: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of Tween.
|
|
22
|
+
* @param target - The object whose property will be animated.
|
|
23
|
+
* @param property - The name of the property to animate.
|
|
24
|
+
* @param to - The target value of the property.
|
|
25
|
+
* @param duration - The duration of the animation in seconds.
|
|
26
|
+
* @param easing - The easing function to use for the animation.
|
|
27
|
+
*/
|
|
28
|
+
constructor(target: any, property: string, to: T, duration: number, easing: EasingFunction);
|
|
29
|
+
/**
|
|
30
|
+
* Starts the tween animation.
|
|
31
|
+
* It captures the initial state of the property.
|
|
32
|
+
*/
|
|
33
|
+
start(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Updates the tween's state. This should be called every frame.
|
|
36
|
+
* @param deltaTime - The time elapsed since the last frame, in seconds.
|
|
37
|
+
*/
|
|
38
|
+
update(deltaTime: number): void;
|
|
39
|
+
}
|
|
40
|
+
export declare const isPlainObject: (obj: any) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* A type definition for an easing function.
|
|
43
|
+
* It takes a progress ratio (0 to 1) and returns a modified ratio.
|
|
44
|
+
* @param t - The linear progress of the animation, from 0 to 1.
|
|
45
|
+
* @returns The eased progress, typically also from 0 to 1.
|
|
46
|
+
*/
|
|
47
|
+
export type EasingFunction = (t: number) => number;
|
|
48
|
+
/**
|
|
49
|
+
* A collection of common easing functions for tweening.
|
|
50
|
+
* Reference: https://easings.net/
|
|
51
|
+
*/
|
|
52
|
+
export declare class Easing {
|
|
53
|
+
static Linear: EasingFunction;
|
|
54
|
+
static EaseInQuad: EasingFunction;
|
|
55
|
+
static EaseOutQuad: EasingFunction;
|
|
56
|
+
static EaseInOutQuad: EasingFunction;
|
|
57
|
+
static EaseInCubic: EasingFunction;
|
|
58
|
+
static EaseOutCubic: EasingFunction;
|
|
59
|
+
static EaseInOutCubic: EasingFunction;
|
|
60
|
+
static EaseInQuart: EasingFunction;
|
|
61
|
+
static EaseOutQuart: EasingFunction;
|
|
62
|
+
static EaseInOutQuart: EasingFunction;
|
|
63
|
+
}
|
|
64
|
+
interface TimerEvents {
|
|
65
|
+
timeout: () => void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Represents a timer that executes a callback after a specified duration.
|
|
69
|
+
* The timer can be set to repeat. It is managed and updated by the Game's main loop.
|
|
70
|
+
*/
|
|
71
|
+
export declare class Timer extends EventEmitter<TimerEvents> {
|
|
72
|
+
private duration;
|
|
73
|
+
private repeat;
|
|
74
|
+
private elapsedTime;
|
|
75
|
+
/** Indicates whether the timer is currently active and counting down. */
|
|
76
|
+
isRunning: boolean;
|
|
77
|
+
/** Indicates whether the timer has finished its lifecycle (for non-repeating timers). */
|
|
78
|
+
isFinished: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Creates an instance of a Timer.
|
|
81
|
+
* @param duration - The duration of the timer in seconds.
|
|
82
|
+
* @param onComplete - The callback function to execute when the timer completes a cycle.
|
|
83
|
+
* @param repeat - Whether the timer should restart automatically after completion. Defaults to false.
|
|
84
|
+
*/
|
|
85
|
+
constructor(duration: number, repeat?: boolean);
|
|
86
|
+
/**
|
|
87
|
+
* Starts or resumes the timer.
|
|
88
|
+
*/
|
|
89
|
+
start(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Stops (pauses) the timer. It can be resumed with start().
|
|
92
|
+
*/
|
|
93
|
+
stop(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Updates the timer's state. This is called by the Game loop every frame.
|
|
96
|
+
* @param deltaTime - The time elapsed since the last frame, in seconds.
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
update(deltaTime: number): void;
|
|
100
|
+
/**
|
|
101
|
+
* Immediately stops the timer and marks it as finished, preventing any further execution.
|
|
102
|
+
* This is used for cleanup to avoid memory leaks from stale callbacks.
|
|
103
|
+
*/
|
|
104
|
+
destroy(): void;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
package/dist/webgl/glshader.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { IAttribute,
|
|
1
|
+
import { IAttribute, ShaderType } from "../interface";
|
|
2
2
|
import Rapid from "../render";
|
|
3
|
+
import { Uniform } from "./uniform";
|
|
4
|
+
import RenderRegion from "../regions/region";
|
|
3
5
|
declare class GLShader {
|
|
4
6
|
attributeLoc: Record<string, number>;
|
|
5
7
|
uniformLoc: Record<string, WebGLUniformLocation>;
|
|
6
8
|
program: WebGLProgram;
|
|
9
|
+
textureUnitNum: number;
|
|
10
|
+
private attributes;
|
|
7
11
|
private gl;
|
|
8
|
-
constructor(rapid: Rapid, vs: string, fs: string);
|
|
12
|
+
constructor(rapid: Rapid, vs: string, fs: string, attributes?: IAttribute[], textureUnitNum?: number);
|
|
9
13
|
/**
|
|
10
14
|
* Set the uniform of this shader
|
|
11
15
|
* @param uniforms
|
|
12
16
|
* @param usedTextureUnit How many texture units have been used
|
|
13
17
|
*/
|
|
14
|
-
setUniforms(
|
|
18
|
+
setUniforms(uniform: Uniform, region: RenderRegion): void;
|
|
15
19
|
private getUniform;
|
|
16
20
|
/**
|
|
17
21
|
* use this shader
|
|
@@ -19,9 +23,16 @@ declare class GLShader {
|
|
|
19
23
|
use(): void;
|
|
20
24
|
private parseShader;
|
|
21
25
|
/**
|
|
22
|
-
* Set vertex
|
|
26
|
+
* Set vertex attribute in glsl shader
|
|
23
27
|
* @param element
|
|
24
28
|
*/
|
|
25
29
|
setAttribute(element: IAttribute): void;
|
|
30
|
+
/**
|
|
31
|
+
* Set vertex attributes in glsl shader
|
|
32
|
+
* @param elements
|
|
33
|
+
*/
|
|
34
|
+
setAttributes(elements: IAttribute[]): void;
|
|
35
|
+
updateAttributes(): void;
|
|
36
|
+
static createCostumShader(rapid: Rapid, vs: string, fs: string, type: ShaderType, textureUnitNum?: number): GLShader;
|
|
26
37
|
}
|
|
27
38
|
export default GLShader;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { UniformType, WebGLContext } from '../interface';
|
|
2
|
+
import RenderRegion from '../regions/region';
|
|
3
|
+
export declare class Uniform {
|
|
4
|
+
private data;
|
|
5
|
+
isDirty: boolean;
|
|
6
|
+
constructor(data: UniformType);
|
|
7
|
+
setUniform(key: string, data: UniformType[string]): void;
|
|
8
|
+
/**
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
clearDirty(): void;
|
|
12
|
+
getUnifromNames(): string[];
|
|
13
|
+
bind(gl: WebGLContext, uniformName: string, loc: WebGLUniformLocation, region: RenderRegion): void;
|
|
14
|
+
}
|
package/dist/webgl/utils.d.ts
CHANGED
|
@@ -21,7 +21,17 @@ export declare const compileShader: (gl: WebGLContext, source: string, type: num
|
|
|
21
21
|
* @returns
|
|
22
22
|
*/
|
|
23
23
|
export declare const createShaderProgram: (gl: WebGLContext, vsSource: string, fsSource: string) => WebGLProgram;
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Creates a WebGL texture either from an image source or as a blank texture
|
|
26
|
+
* @param gl - The WebGL rendering context
|
|
27
|
+
* @param source - The image source or dimensions for a blank texture
|
|
28
|
+
* @param antialias - Whether to enable antialiasing
|
|
29
|
+
* @returns A WebGL texture
|
|
30
|
+
*/
|
|
31
|
+
export declare function createTexture(gl: WebGLContext, source: TexImageSource | {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
}, antialias: boolean, withSize?: boolean, flipY?: boolean, wrapMode?: 'repeat' | 'mirror' | 'clamp'): WebGLTexture;
|
|
25
35
|
export declare function generateFragShader(fs: string, max: number): string;
|
|
26
36
|
export declare const FLOAT = 5126;
|
|
27
37
|
export declare const UNSIGNED_BYTE = 5121;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rapid-render",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -14,22 +14,28 @@
|
|
|
14
14
|
"require": "./dist/rapid.umd.cjs"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"dev": "rollup -c rollup.config.dev.js -w",
|
|
17
|
+
"dev:build": "rollup -c rollup.config.dev.js -w",
|
|
18
|
+
"dev:serve": "node ./scripts/dev-server.js",
|
|
19
|
+
"dev": "concurrently \"npm run dev:build\" \"npm run dev:serve\"",
|
|
18
20
|
"build": "rollup -c rollup.config.prod.js && tsc",
|
|
19
21
|
"docs": "typedoc"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
24
|
+
"express": "^4.18.2",
|
|
22
25
|
"rollup": "^4.12.0",
|
|
23
26
|
"rollup-plugin-dts": "^6.1.0",
|
|
24
|
-
"rollup-plugin-server": "^0.7.0",
|
|
25
27
|
"rollup-plugin-string": "^3.0.0",
|
|
26
28
|
"rollup-plugin-terser": "^7.0.2",
|
|
27
29
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
28
30
|
"tslib": "^2.6.2",
|
|
29
|
-
"typedoc": "^0.
|
|
31
|
+
"typedoc-theme-category-nav": "^0.0.3",
|
|
30
32
|
"typescript": "^5.3.3"
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"
|
|
35
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
|
+
"concurrently": "^9.1.2",
|
|
38
|
+
"eventemitter3": "^5.0.1",
|
|
39
|
+
"typedoc": "^0.28.3"
|
|
34
40
|
}
|
|
35
41
|
}
|