bloody-engine 1.0.2 → 1.0.4

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 (66) hide show
  1. package/dist/node/index.js +0 -5
  2. package/dist/web/batch-renderer.test.d.ts +12 -0
  3. package/dist/web/batch-renderer.test.d.ts.map +1 -0
  4. package/dist/web/core/buffer.d.ts +58 -0
  5. package/dist/web/core/buffer.d.ts.map +1 -0
  6. package/dist/web/core/grahpic-device.d.ts +66 -0
  7. package/dist/web/core/grahpic-device.d.ts.map +1 -0
  8. package/dist/web/core/index.d.ts +8 -0
  9. package/dist/web/core/index.d.ts.map +1 -0
  10. package/dist/web/core/resource-loader-factory.d.ts +90 -0
  11. package/dist/web/core/resource-loader-factory.d.ts.map +1 -0
  12. package/dist/web/core/resource-loader.d.ts +71 -0
  13. package/dist/web/core/resource-loader.d.ts.map +1 -0
  14. package/dist/web/core/resource-pipeline.d.ts +139 -0
  15. package/dist/web/core/resource-pipeline.d.ts.map +1 -0
  16. package/dist/web/core/shader.d.ts +62 -0
  17. package/dist/web/core/shader.d.ts.map +1 -0
  18. package/dist/web/core/texture.d.ts +69 -0
  19. package/dist/web/core/texture.d.ts.map +1 -0
  20. package/dist/web/demo-node.d.ts +2 -0
  21. package/dist/web/demo-node.d.ts.map +1 -0
  22. package/dist/web/examples/batch-renderer-demo.d.ts +10 -0
  23. package/dist/web/examples/batch-renderer-demo.d.ts.map +1 -0
  24. package/dist/web/examples/projection-examples.d.ts +87 -0
  25. package/dist/web/examples/projection-examples.d.ts.map +1 -0
  26. package/dist/web/examples/resource-loader-demo.d.ts +14 -0
  27. package/dist/web/examples/resource-loader-demo.d.ts.map +1 -0
  28. package/dist/web/examples/shader-examples.d.ts +92 -0
  29. package/dist/web/examples/shader-examples.d.ts.map +1 -0
  30. package/dist/web/examples/sprite-batch-renderer-demo.d.ts +12 -0
  31. package/dist/web/examples/sprite-batch-renderer-demo.d.ts.map +1 -0
  32. package/dist/web/index-node-batch.d.ts +10 -0
  33. package/dist/web/index-node-batch.d.ts.map +1 -0
  34. package/dist/web/index.d.ts +7 -0
  35. package/dist/web/index.d.ts.map +1 -0
  36. package/dist/web/index.js +34 -37
  37. package/dist/web/index.umd.js +7 -7
  38. package/dist/web/platforms/browser/browser-context.d.ts +31 -0
  39. package/dist/web/platforms/browser/browser-context.d.ts.map +1 -0
  40. package/dist/web/platforms/browser/browser-resource-loader.d.ts +67 -0
  41. package/dist/web/platforms/browser/browser-resource-loader.d.ts.map +1 -0
  42. package/dist/web/platforms/node/node-context.d.ts +31 -0
  43. package/dist/web/platforms/node/node-context.d.ts.map +1 -0
  44. package/dist/web/platforms/node/node-resource-loader.d.ts +73 -0
  45. package/dist/web/platforms/node/node-resource-loader.d.ts.map +1 -0
  46. package/dist/web/platforms/node/sdl-window.d.ts +41 -0
  47. package/dist/web/platforms/node/sdl-window.d.ts.map +1 -0
  48. package/dist/web/projection.test.d.ts +5 -0
  49. package/dist/web/projection.test.d.ts.map +1 -0
  50. package/dist/web/public-api.d.ts +20 -0
  51. package/dist/web/public-api.d.ts.map +1 -0
  52. package/dist/web/rendering/batch-renderer.d.ts +273 -0
  53. package/dist/web/rendering/batch-renderer.d.ts.map +1 -0
  54. package/dist/web/rendering/camera.d.ts +153 -0
  55. package/dist/web/rendering/camera.d.ts.map +1 -0
  56. package/dist/web/rendering/projection.d.ts +108 -0
  57. package/dist/web/rendering/projection.d.ts.map +1 -0
  58. package/dist/web/rendering/rendering-context-factory.d.ts +24 -0
  59. package/dist/web/rendering/rendering-context-factory.d.ts.map +1 -0
  60. package/dist/web/rendering/rendering-context.d.ts +77 -0
  61. package/dist/web/rendering/rendering-context.d.ts.map +1 -0
  62. package/dist/web/rendering/vertex.d.ts +98 -0
  63. package/dist/web/rendering/vertex.d.ts.map +1 -0
  64. package/dist/web/scene/scene.d.ts +139 -0
  65. package/dist/web/scene/scene.d.ts.map +1 -0
  66. package/package.json +5 -4
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Camera System for 2D/2.5D Rendering
3
+ *
4
+ * Provides camera positioning (x, y), zoom control, and view matrix generation
5
+ * for offsetting global rendering position.
6
+ */
7
+ /**
8
+ * Matrix4 utilities for 2D camera transformations
9
+ * Matrices are stored in column-major order (WebGL convention)
10
+ */
11
+ export declare class Matrix4 {
12
+ /**
13
+ * Create an identity matrix
14
+ * @returns 4x4 identity matrix in column-major order
15
+ */
16
+ static identity(): Float32Array;
17
+ /**
18
+ * Create a translation matrix
19
+ * @param x Translation along X axis
20
+ * @param y Translation along Y axis
21
+ * @param z Translation along Z axis (default 0)
22
+ * @returns 4x4 translation matrix in column-major order
23
+ */
24
+ static translation(x: number, y: number, z?: number): Float32Array;
25
+ /**
26
+ * Create a scale matrix
27
+ * @param x Scale factor along X axis
28
+ * @param y Scale factor along Y axis
29
+ * @param z Scale factor along Z axis (default 1)
30
+ * @returns 4x4 scale matrix in column-major order
31
+ */
32
+ static scale(x: number, y: number, z?: number): Float32Array;
33
+ /**
34
+ * Multiply two matrices (result = a * b)
35
+ * @param a First matrix (left operand)
36
+ * @param b Second matrix (right operand)
37
+ * @returns Result of matrix multiplication in column-major order
38
+ */
39
+ static multiply(a: Float32Array, b: Float32Array): Float32Array;
40
+ /**
41
+ * Create a view matrix from camera position and zoom
42
+ * The view matrix transforms world coordinates to camera/eye coordinates
43
+ *
44
+ * View = Translation(-cameraX, -cameraY, 0) * Scale(zoom, zoom, 1)
45
+ *
46
+ * @param x Camera X position (translation will be negative)
47
+ * @param y Camera Y position (translation will be negative)
48
+ * @param zoom Camera zoom level (1.0 = no zoom, >1 = zoom in, <1 = zoom out)
49
+ * @returns 4x4 view matrix in column-major order
50
+ */
51
+ static createViewMatrix(x: number, y: number, zoom: number): Float32Array;
52
+ }
53
+ /**
54
+ * Camera for 2D/2.5D rendering
55
+ * Controls the viewport position and zoom level
56
+ */
57
+ export declare class Camera {
58
+ private _x;
59
+ private _y;
60
+ private _zoom;
61
+ private _viewMatrix;
62
+ private _viewMatrixDirty;
63
+ /**
64
+ * Create a new camera
65
+ * @param x Initial X position (default 0)
66
+ * @param y Initial Y position (default 0)
67
+ * @param zoom Initial zoom level (default 1.0)
68
+ */
69
+ constructor(x?: number, y?: number, zoom?: number);
70
+ /**
71
+ * Get the camera X position
72
+ */
73
+ get x(): number;
74
+ /**
75
+ * Set the camera X position
76
+ */
77
+ set x(value: number);
78
+ /**
79
+ * Get the camera Y position
80
+ */
81
+ get y(): number;
82
+ /**
83
+ * Set the camera Y position
84
+ */
85
+ set y(value: number);
86
+ /**
87
+ * Get the camera zoom level
88
+ */
89
+ get zoom(): number;
90
+ /**
91
+ * Set the camera zoom level
92
+ * Values: 1.0 = no zoom, >1 = zoom in, <1 = zoom out
93
+ */
94
+ set zoom(value: number);
95
+ /**
96
+ * Set both X and Y position at once
97
+ * @param x New X position
98
+ * @param y New Y position
99
+ */
100
+ setPosition(x: number, y: number): void;
101
+ /**
102
+ * Move the camera by a relative offset
103
+ * @param dx X offset to add to current position
104
+ * @param dy Y offset to add to current position
105
+ */
106
+ move(dx: number, dy: number): void;
107
+ /**
108
+ * Scale the zoom by a factor
109
+ * @param factor Multiplier for current zoom (e.g., 1.1 to zoom in 10%)
110
+ */
111
+ zoomBy(factor: number): void;
112
+ /**
113
+ * Reset camera to default position and zoom
114
+ */
115
+ reset(): void;
116
+ /**
117
+ * Get the view matrix for this camera
118
+ * The view matrix transforms world coordinates to camera space
119
+ * Caches the result until camera properties change
120
+ *
121
+ * @returns 4x4 view matrix in column-major order
122
+ */
123
+ getViewMatrix(): Float32Array;
124
+ /**
125
+ * Convert screen coordinates to world coordinates
126
+ * Useful for mouse picking and interaction
127
+ *
128
+ * @param screenX Screen X coordinate (pixels)
129
+ * @param screenY Screen Y coordinate (pixels)
130
+ * @param viewportWidth Viewport width in pixels
131
+ * @param viewportHeight Viewport height in pixels
132
+ * @returns World coordinates {x, y}
133
+ */
134
+ screenToWorld(screenX: number, screenY: number, viewportWidth: number, viewportHeight: number): {
135
+ x: number;
136
+ y: number;
137
+ };
138
+ /**
139
+ * Convert world coordinates to screen coordinates
140
+ * Useful for UI positioning and debug rendering
141
+ *
142
+ * @param worldX World X coordinate
143
+ * @param worldY World Y coordinate
144
+ * @param viewportWidth Viewport width in pixels
145
+ * @param viewportHeight Viewport height in pixels
146
+ * @returns Screen coordinates {x, y} in pixels
147
+ */
148
+ worldToScreen(worldX: number, worldY: number, viewportWidth: number, viewportHeight: number): {
149
+ x: number;
150
+ y: number;
151
+ };
152
+ }
153
+ //# sourceMappingURL=camera.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../../../src/rendering/camera.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,qBAAa,OAAO;IAClB;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,YAAY;IAS/B;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAE,MAAU,GAAG,YAAY;IASrE;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAE,MAAU,GAAG,YAAY;IAS/D;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY;IAmB/D;;;;;;;;;;OAUG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY;CAQ1E;AAED;;;GAGG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,gBAAgB,CAAiB;IAEzC;;;;;OAKG;gBACS,CAAC,GAAE,MAAU,EAAE,CAAC,GAAE,MAAU,EAAE,IAAI,GAAE,MAAY;IAM5D;;OAEG;IACH,IAAI,CAAC,IAAI,MAAM,CAEd;IAED;;OAEG;IACH,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAGlB;IAED;;OAEG;IACH,IAAI,CAAC,IAAI,MAAM,CAEd;IAED;;OAEG;IACH,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAGlB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAGrB;IAED;;;;OAIG;IACH,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAMvC;;;;OAIG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI;IAMlC;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAOb;;;;;;OAMG;IACH,aAAa,IAAI,YAAY;IAQ7B;;;;;;;;;OASG;IACH,aAAa,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACrB;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;IAY3B;;;;;;;;;OASG;IACH,aAAa,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACrB;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;CAW5B"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * 2.5D Isometric Projection Mathematics
3
+ *
4
+ * Converts between grid coordinates (xgrid, ygrid, zheight) and screen coordinates (xscreen, yscreen).
5
+ * This is the mathematical core for 2.5D rendering with isometric perspective.
6
+ *
7
+ * Coordinate Systems:
8
+ * - Grid space: (xgrid, ygrid, zheight) - logical game world coordinates
9
+ * - Screen space: (xscreen, yscreen) - pixel coordinates on display
10
+ */
11
+ export interface GridCoord {
12
+ xgrid: number;
13
+ ygrid: number;
14
+ zheight: number;
15
+ }
16
+ export interface ScreenCoord {
17
+ xscreen: number;
18
+ yscreen: number;
19
+ }
20
+ export interface FractionalGridCoord {
21
+ xgrid: number;
22
+ ygrid: number;
23
+ zheight: number;
24
+ }
25
+ /**
26
+ * Projection configuration for isometric view
27
+ */
28
+ export declare class ProjectionConfig {
29
+ readonly tileWidth: number;
30
+ readonly tileHeight: number;
31
+ readonly zScale: number;
32
+ constructor(tileWidth?: number, tileHeight?: number, zScale?: number);
33
+ }
34
+ /**
35
+ * Projects grid coordinates to screen coordinates using isometric projection.
36
+ *
37
+ * Formula:
38
+ * xscreen = (xgrid - ygrid) × (tileWidth / 2)
39
+ * yscreen = (xgrid + ygrid) × (tileHeight / 2) - (zheight × zScale)
40
+ *
41
+ * @param gridCoord Grid-space coordinate
42
+ * @param config Projection configuration
43
+ * @returns Screen-space coordinate in pixels
44
+ */
45
+ export declare function gridToScreen(gridCoord: GridCoord, config: ProjectionConfig): ScreenCoord;
46
+ /**
47
+ * Converts screen coordinates back to fractional grid coordinates.
48
+ * This is the inverse transformation, used for mouse picking.
49
+ *
50
+ * The isometric projection matrix is:
51
+ * [xscreen] [tileWidth/2 -tileWidth/2 ] [xgrid]
52
+ * [yscreen] = [tileHeight/2 tileHeight/2] [ygrid] - [0, zheight * zScale]^T
53
+ *
54
+ * Inverting this 2x2 matrix:
55
+ * A = [[tw/2, -tw/2], [th/2, th/2]]
56
+ * det(A) = (tw/2)(th/2) - (-tw/2)(th/2) = tw*th/4 + tw*th/4 = tw*th/2
57
+ *
58
+ * A^-1 = (1 / det(A)) * [[th/2, tw/2], [-th/2, tw/2]]
59
+ * = (2 / (tw*th)) * [[th/2, tw/2], [-th/2, tw/2]]
60
+ * = [[1/tw, 1/th], [-1/tw, 1/th]]
61
+ *
62
+ * Therefore:
63
+ * xgrid = (xscreen / (tileWidth/2) - yscreen / (tileHeight/2)) / 2
64
+ * ygrid = (-xscreen / (tileWidth/2) + yscreen / (tileHeight/2)) / 2
65
+ *
66
+ * Simplified:
67
+ * xgrid = xscreen / tileWidth + yscreen / tileHeight
68
+ * ygrid = -xscreen / tileWidth + yscreen / tileHeight
69
+ *
70
+ * @param screenCoord Screen-space coordinate in pixels
71
+ * @param config Projection configuration
72
+ * @param zheight Optional height to add back to yscreen before inversion
73
+ * @returns Fractional grid-space coordinate
74
+ */
75
+ export declare function screenToGrid(screenCoord: ScreenCoord, config: ProjectionConfig, zheight?: number): FractionalGridCoord;
76
+ /**
77
+ * Converts screen coordinates to grid coordinates with automatic height detection.
78
+ * Assumes zheight = 0 (picking at ground level).
79
+ *
80
+ * @param screenCoord Screen-space coordinate in pixels
81
+ * @param config Projection configuration
82
+ * @returns Grid-space coordinate at ground level (zheight = 0)
83
+ */
84
+ export declare function screenToGridAtGroundLevel(screenCoord: ScreenCoord, config: ProjectionConfig): GridCoord;
85
+ /**
86
+ * Calculates the offset from a grid cell to the center of that cell in screen space.
87
+ * Useful for positioning entities at cell centers.
88
+ *
89
+ * @param config Projection configuration
90
+ * @returns Offset to cell center in screen coordinates
91
+ */
92
+ export declare function getCellCenterOffset(config: ProjectionConfig): ScreenCoord;
93
+ /**
94
+ * Validates if a grid coordinate is within typical bounds.
95
+ *
96
+ * @param gridCoord Grid-space coordinate
97
+ * @param maxGridSize Maximum size of grid (assumes square grid)
98
+ * @returns True if coordinate is within bounds
99
+ */
100
+ export declare function isGridCoordValid(gridCoord: GridCoord, maxGridSize?: number): boolean;
101
+ /**
102
+ * Creates a default projection configuration suitable for most 2.5D games.
103
+ * Uses standard tile dimensions.
104
+ *
105
+ * @returns Default ProjectionConfig
106
+ */
107
+ export declare function createDefaultProjection(): ProjectionConfig;
108
+ //# sourceMappingURL=projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/rendering/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAGtB,SAAS,GAAE,MAAW,EACtB,UAAU,GAAE,MAAW,EACvB,MAAM,GAAE,MAAY;CAMvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,gBAAgB,GACvB,WAAW,CAUb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,gBAAgB,EACxB,OAAO,GAAE,MAAU,GAClB,mBAAmB,CAiBrB;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,gBAAgB,GACvB,SAAS,CAOX;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW,CASzE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,MAAa,GACzB,OAAO,CAQT;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,IAAI,gBAAgB,CAE1D"}
@@ -0,0 +1,24 @@
1
+ import { RenderingContext, RenderingContextOptions } from '../rendering/rendering-context';
2
+ /**
3
+ * Factory for creating environment-appropriate rendering contexts
4
+ * Abstracts environment detection from the application code
5
+ */
6
+ export declare class RenderingContextFactory {
7
+ /**
8
+ * Detect if running in a browser environment
9
+ */
10
+ static isBrowserEnvironment(): boolean;
11
+ /**
12
+ * Create a rendering context appropriate for the current environment
13
+ */
14
+ static createContext(options: RenderingContextOptions): RenderingContext;
15
+ /**
16
+ * Create a browser-specific rendering context
17
+ */
18
+ static createBrowserContext(options: RenderingContextOptions): RenderingContext;
19
+ /**
20
+ * Create a Node.js-specific rendering context
21
+ */
22
+ static createNodeContext(options: RenderingContextOptions): RenderingContext;
23
+ }
24
+ //# sourceMappingURL=rendering-context-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rendering-context-factory.d.ts","sourceRoot":"","sources":["../../../src/rendering/rendering-context-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,gCAAgC,CAAC;AAIxC;;;GAGG;AACH,qBAAa,uBAAuB;IAClC;;OAEG;IACH,MAAM,CAAC,oBAAoB,IAAI,OAAO;IAItC;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB;IAQxE;;OAEG;IACH,MAAM,CAAC,oBAAoB,CACzB,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB;IAInB;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB;CAG7E"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Standardized rendering context interface
3
+ * Abstracts away environment-specific (DOM vs Node.js) details
4
+ * Ensures the engine core never directly references DOM APIs
5
+ */
6
+ export interface RenderingContext {
7
+ /**
8
+ * The underlying WebGL rendering context
9
+ */
10
+ glContext: WebGLRenderingContext;
11
+ /**
12
+ * Canvas/drawable surface width in pixels
13
+ */
14
+ width: number;
15
+ /**
16
+ * Canvas/drawable surface height in pixels
17
+ */
18
+ height: number;
19
+ /**
20
+ * Whether this context is in a browser environment
21
+ */
22
+ isBrowser: boolean;
23
+ /**
24
+ * Resize the rendering context
25
+ */
26
+ resize(width: number, height: number): void;
27
+ /**
28
+ * Get the current viewport dimensions
29
+ */
30
+ getViewport(): {
31
+ width: number;
32
+ height: number;
33
+ };
34
+ /**
35
+ * Clear the rendering context (prepare for new frame)
36
+ */
37
+ clear(color?: {
38
+ r: number;
39
+ g: number;
40
+ b: number;
41
+ a: number;
42
+ }): void;
43
+ /**
44
+ * Present/swap the rendering buffers (if applicable)
45
+ */
46
+ present(): void;
47
+ /**
48
+ * Cleanup and release resources
49
+ */
50
+ dispose(): void;
51
+ }
52
+ /**
53
+ * Context creation options
54
+ */
55
+ export interface RenderingContextOptions {
56
+ /**
57
+ * Canvas element (browser only)
58
+ */
59
+ canvas?: HTMLCanvasElement;
60
+ /**
61
+ * WebGL context creation options
62
+ */
63
+ contextAttributes?: WebGLContextAttributes;
64
+ /**
65
+ * Whether to preserve drawing buffer between frames
66
+ */
67
+ preserveDrawingBuffer?: boolean;
68
+ /**
69
+ * Canvas width in pixels
70
+ */
71
+ width: number;
72
+ /**
73
+ * Canvas height in pixels
74
+ */
75
+ height: number;
76
+ }
77
+ //# sourceMappingURL=rendering-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rendering-context.d.ts","sourceRoot":"","sources":["../../../src/rendering/rendering-context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,SAAS,EAAE,qBAAqB,CAAC;IAEjC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5C;;OAEG;IACH,WAAW,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAEjD;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAEpE;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;IAEhB;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B;;OAEG;IACH,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;IAE3C;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * 2.5D Sprite Vertex Structure
3
+ *
4
+ * Defines the vertex format for 2.5D sprites with support for:
5
+ * - Position (x, y, z)
6
+ * - Texture coordinates (u, v)
7
+ * - Color tint (r, g, b, a)
8
+ * - Texture index (for texture atlases)
9
+ *
10
+ * Vertex Layout (9 floats per vertex):
11
+ * [0-2] Position: x, y, z
12
+ * [3-4] TexCoord: u, v
13
+ * [5-8] Color: r, g, b, a
14
+ * [9] TexIndex: texture index (integer passed as float)
15
+ */
16
+ /**
17
+ * Represents a single vertex with all 2.5D sprite attributes
18
+ */
19
+ export interface SpriteVertex {
20
+ /** Position in world space */
21
+ x: number;
22
+ y: number;
23
+ z: number;
24
+ /** Texture coordinates */
25
+ u: number;
26
+ v: number;
27
+ /** Color tint (0-1 range) */
28
+ r: number;
29
+ g: number;
30
+ b: number;
31
+ a: number;
32
+ /** Texture index for texture atlas selection */
33
+ texIndex: number;
34
+ }
35
+ /**
36
+ * Float layout per vertex in the vertex buffer
37
+ * Total: 10 floats per vertex
38
+ */
39
+ export declare const VERTEX_LAYOUT: {
40
+ readonly FLOATS_PER_VERTEX: 10;
41
+ readonly POSITION_OFFSET: 0;
42
+ readonly TEXCOORD_OFFSET: 3;
43
+ readonly COLOR_OFFSET: 5;
44
+ readonly TEXINDEX_OFFSET: 9;
45
+ readonly STRIDE: number;
46
+ };
47
+ /**
48
+ * Convert a SpriteVertex to a Float32Array segment
49
+ * Useful for building vertex buffers
50
+ */
51
+ export declare function spriteVertexToArray(vertex: SpriteVertex): Float32Array;
52
+ /**
53
+ * Create a default sprite vertex
54
+ * Useful for initialization
55
+ */
56
+ export declare function createDefaultSpriteVertex(): SpriteVertex;
57
+ /**
58
+ * Sprite quad instance data for batch rendering
59
+ * Extends the basic QuadInstance with 2.5D sprite features
60
+ */
61
+ export interface SpriteQuadInstance {
62
+ /** Position in 2.5D space */
63
+ x: number;
64
+ y: number;
65
+ z: number;
66
+ /** Width and height */
67
+ width: number;
68
+ height: number;
69
+ /** Rotation in radians */
70
+ rotation: number;
71
+ /** Color tint (0-1 range, default white) */
72
+ color?: {
73
+ r: number;
74
+ g: number;
75
+ b: number;
76
+ a: number;
77
+ };
78
+ /** Texture coordinates (UV region in texture atlas) */
79
+ uvRect?: {
80
+ uMin: number;
81
+ vMin: number;
82
+ uMax: number;
83
+ vMax: number;
84
+ };
85
+ /** Texture index for atlas selection */
86
+ texIndex?: number;
87
+ /** Grid position for GPU-based transformation (optional) */
88
+ gridX?: number;
89
+ gridY?: number;
90
+ }
91
+ /**
92
+ * Generate 6 vertices (2 triangles) for a quad with the specified properties
93
+ *
94
+ * @param instance The sprite quad instance data
95
+ * @returns Array of 6 vertices forming the quad
96
+ */
97
+ export declare function generateQuadVertices(instance: SpriteQuadInstance): SpriteVertex[];
98
+ //# sourceMappingURL=vertex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vertex.d.ts","sourceRoot":"","sources":["../../../src/rendering/vertex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,0BAA0B;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,6BAA6B;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;CAOhB,CAAC;AAEX;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAatE;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,YAAY,CAaxD;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,KAAK,CAAC,EAAE;QACN,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,uDAAuD;IACvD,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,kBAAkB,GAC3B,YAAY,EAAE,CAmEhB"}
@@ -0,0 +1,139 @@
1
+ import { ProjectionConfig, GridCoord } from '../rendering/projection';
2
+ /**
3
+ * Scene configuration and constants
4
+ * Shared between Node.js and Browser rendering
5
+ */
6
+ export declare const SCENE_CONFIG: {
7
+ width: number;
8
+ height: number;
9
+ targetFPS: number;
10
+ };
11
+ export declare const PROJECTION_CONFIG: ProjectionConfig;
12
+ /**
13
+ * Entity for visualization (used in projection demo)
14
+ */
15
+ export interface VisualizationEntity {
16
+ id: string;
17
+ name: string;
18
+ gridPos: GridCoord;
19
+ color: [number, number, number];
20
+ size: number;
21
+ }
22
+ /**
23
+ * Projection visualization entities to render
24
+ */
25
+ export declare const PROJECTION_ENTITIES: VisualizationEntity[];
26
+ export declare const GEOMETRY: {
27
+ quad: {
28
+ name: string;
29
+ vertices: Float32Array<ArrayBuffer>;
30
+ stride: number;
31
+ };
32
+ triangle: {
33
+ name: string;
34
+ vertices: Float32Array<ArrayBuffer>;
35
+ stride: number;
36
+ };
37
+ };
38
+ export declare const SHADERS_V1: {
39
+ vertex: string;
40
+ fragment: string;
41
+ };
42
+ export declare const SHADERS_V2: {
43
+ vertex: string;
44
+ fragment: string;
45
+ };
46
+ export declare const SHADERS: {
47
+ vertex: string;
48
+ fragment: string;
49
+ };
50
+ /**
51
+ * SHADERS_V3 - GPU-Based 2.5D Transformation
52
+ *
53
+ * This version moves the isometric projection from CPU to GPU.
54
+ * The vertex shader receives grid coordinates and transforms them to screen space.
55
+ *
56
+ * Attributes:
57
+ * - aGridPosition: Grid position (x, y) in world space
58
+ * - aZPosition: Z position for depth layering
59
+ * - aLocalOffset: Local offset from quad center (for rotation)
60
+ * - aTexCoord: Texture coordinates
61
+ * - aColor: Color tint
62
+ * - aTexIndex: Texture atlas index
63
+ *
64
+ * Uniforms:
65
+ * - uTileSize: Size of tiles (width, height) for isometric projection
66
+ * - uCamera: Camera position (x, y) and zoom
67
+ * - uRotation: Rotation angle in radians
68
+ * - uQuadSize: Size of the quad (width, height)
69
+ * - uZScale: Scale factor for Z height (vertical exaggeration)
70
+ * - uResolution: Screen resolution for NDC conversion
71
+ */
72
+ export declare const SHADERS_V3: {
73
+ vertex: string;
74
+ fragment: string;
75
+ };
76
+ export declare const TEXTURE_CONFIG: {
77
+ size: number;
78
+ type: string;
79
+ };
80
+ export declare const ANIMATION_CONFIG: {
81
+ background: {
82
+ offsetR: number;
83
+ amplitudeR: number;
84
+ speedR: number;
85
+ offsetG: number;
86
+ amplitudeG: number;
87
+ speedG: number;
88
+ offsetB: number;
89
+ amplitudeB: number;
90
+ speedB: number;
91
+ };
92
+ quads: {
93
+ count: number;
94
+ scale: number;
95
+ baseRadius: number;
96
+ radiusVariation: number;
97
+ radiusSpeed: number;
98
+ orbitalSpeed: number;
99
+ rotationSpeed: number;
100
+ colors: number[][];
101
+ };
102
+ triangles: {
103
+ count: number;
104
+ scale: number;
105
+ baseRadius: number;
106
+ radiusVariation: number;
107
+ radiusSpeed: number;
108
+ orbitalSpeed: number;
109
+ rotationSpeed: number;
110
+ rotationDirection: number;
111
+ colors: number[][];
112
+ };
113
+ };
114
+ /**
115
+ * Calculate background color for a given elapsed time
116
+ */
117
+ export declare function getBackgroundColor(elapsedSeconds: number): {
118
+ r: number;
119
+ g: number;
120
+ b: number;
121
+ a: number;
122
+ };
123
+ /**
124
+ * Calculate quad transformations for animation
125
+ */
126
+ export declare function getQuadTransforms(elapsedSeconds: number): {
127
+ matrix: Float32Array<ArrayBuffer>;
128
+ color: number[];
129
+ index: number;
130
+ }[];
131
+ /**
132
+ * Calculate triangle transformations for animation
133
+ */
134
+ export declare function getTriangleTransforms(elapsedSeconds: number): {
135
+ matrix: Float32Array<ArrayBuffer>;
136
+ color: number[];
137
+ index: number;
138
+ }[];
139
+ //# sourceMappingURL=scene.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../../src/scene/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAE3E;;;GAGG;AAEH,eAAO,MAAM,YAAY;;;;CAIxB,CAAC;AAMF,eAAO,MAAM,iBAAiB,kBAI7B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,mBAAmB,EAoCpD,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;;CA6DpB,CAAC;AAKF,eAAO,MAAM,UAAU;;;CA2BtB,CAAC;AAKF,eAAO,MAAM,UAAU;;;CAsCtB,CAAC;AAGF,eAAO,MAAM,OAAO;;;CAAa,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,UAAU;;;CAgFtB,CAAC;AAGF,eAAO,MAAM,cAAc;;;CAG1B,CAAC;AAGF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4C5B,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM;;;;;EAQxD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM;;;;IA6CvD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,MAAM;;;;IA8C3D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bloody-engine",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A WebGL-based 2.5D graphics engine for isometric rendering",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,8 +39,8 @@
39
39
  "scripts": {
40
40
  "dev": "vite",
41
41
  "build": "npm run build:web && npm run build:node",
42
- "build:web": "vite build --config vite.config.web.ts",
43
- "build:node": "vite build --config vite.config.node.ts",
42
+ "build:web": "tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist/web && vite build --config vite.config.web.ts",
43
+ "build:node": "tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist/node && vite build --config vite.config.node.ts",
44
44
  "build:demo": "vite build --config vite.config.demo.ts",
45
45
  "preview": "vite preview",
46
46
  "demo": "npm run build:demo && node dist/demo/index.js"
@@ -49,7 +49,8 @@
49
49
  "@types/gl": "^6.0.5",
50
50
  "@types/node": "^20.10.6",
51
51
  "typescript": "^5.3.3",
52
- "vite": "^7.3.0"
52
+ "vite": "^7.3.0",
53
+ "vite-plugin-dts": "^4.5.4"
53
54
  },
54
55
  "dependencies": {
55
56
  "@kmamal/sdl": "^0.11.13",