bloody-engine 1.0.3 → 1.0.5

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 (62) hide show
  1. package/dist/node/index.js +400 -0
  2. package/dist/web/core/buffer.d.ts +58 -0
  3. package/dist/web/core/buffer.d.ts.map +1 -0
  4. package/dist/web/core/grahpic-device.d.ts +66 -0
  5. package/dist/web/core/grahpic-device.d.ts.map +1 -0
  6. package/dist/web/core/index.d.ts +8 -0
  7. package/dist/web/core/index.d.ts.map +1 -0
  8. package/dist/web/core/resource-loader-factory.d.ts +90 -0
  9. package/dist/web/core/resource-loader-factory.d.ts.map +1 -0
  10. package/dist/web/core/resource-loader.d.ts +71 -0
  11. package/dist/web/core/resource-loader.d.ts.map +1 -0
  12. package/dist/web/core/resource-pipeline.d.ts +139 -0
  13. package/dist/web/core/resource-pipeline.d.ts.map +1 -0
  14. package/dist/web/core/shader.d.ts +62 -0
  15. package/dist/web/core/shader.d.ts.map +1 -0
  16. package/dist/web/core/texture.d.ts +69 -0
  17. package/dist/web/core/texture.d.ts.map +1 -0
  18. package/dist/web/demo-node.d.ts +2 -0
  19. package/dist/web/demo-node.d.ts.map +1 -0
  20. package/dist/web/examples/batch-renderer-demo.d.ts +10 -0
  21. package/dist/web/examples/batch-renderer-demo.d.ts.map +1 -0
  22. package/dist/web/examples/projection-examples.d.ts +87 -0
  23. package/dist/web/examples/projection-examples.d.ts.map +1 -0
  24. package/dist/web/examples/resource-loader-demo.d.ts +14 -0
  25. package/dist/web/examples/resource-loader-demo.d.ts.map +1 -0
  26. package/dist/web/examples/shader-examples.d.ts +92 -0
  27. package/dist/web/examples/shader-examples.d.ts.map +1 -0
  28. package/dist/web/examples/sprite-batch-renderer-demo.d.ts +12 -0
  29. package/dist/web/examples/sprite-batch-renderer-demo.d.ts.map +1 -0
  30. package/dist/web/index.d.ts +7 -0
  31. package/dist/web/index.d.ts.map +1 -0
  32. package/dist/web/index.js +760 -474
  33. package/dist/web/index.umd.js +23 -23
  34. package/dist/web/platforms/browser/browser-context.d.ts +31 -0
  35. package/dist/web/platforms/browser/browser-context.d.ts.map +1 -0
  36. package/dist/web/platforms/browser/browser-resource-loader.d.ts +67 -0
  37. package/dist/web/platforms/browser/browser-resource-loader.d.ts.map +1 -0
  38. package/dist/web/platforms/node/node-context.d.ts +31 -0
  39. package/dist/web/platforms/node/node-context.d.ts.map +1 -0
  40. package/dist/web/platforms/node/node-resource-loader.d.ts +73 -0
  41. package/dist/web/platforms/node/node-resource-loader.d.ts.map +1 -0
  42. package/dist/web/platforms/node/sdl-window.d.ts +41 -0
  43. package/dist/web/platforms/node/sdl-window.d.ts.map +1 -0
  44. package/dist/web/projection.test.d.ts +5 -0
  45. package/dist/web/projection.test.d.ts.map +1 -0
  46. package/dist/web/public-api.d.ts +25 -0
  47. package/dist/web/public-api.d.ts.map +1 -0
  48. package/dist/web/rendering/batch-renderer.d.ts +273 -0
  49. package/dist/web/rendering/batch-renderer.d.ts.map +1 -0
  50. package/dist/web/rendering/camera.d.ts +153 -0
  51. package/dist/web/rendering/camera.d.ts.map +1 -0
  52. package/dist/web/rendering/projection.d.ts +108 -0
  53. package/dist/web/rendering/projection.d.ts.map +1 -0
  54. package/dist/web/rendering/rendering-context-factory.d.ts +24 -0
  55. package/dist/web/rendering/rendering-context-factory.d.ts.map +1 -0
  56. package/dist/web/rendering/rendering-context.d.ts +77 -0
  57. package/dist/web/rendering/rendering-context.d.ts.map +1 -0
  58. package/dist/web/rendering/vertex.d.ts +98 -0
  59. package/dist/web/rendering/vertex.d.ts.map +1 -0
  60. package/dist/web/scene/scene.d.ts +139 -0
  61. package/dist/web/scene/scene.d.ts.map +1 -0
  62. package/package.json +5 -4
@@ -0,0 +1,273 @@
1
+ import { Shader } from '../core/shader';
2
+ import { Texture } from '../core/texture';
3
+ import { Camera } from './camera';
4
+ /**
5
+ * V1 Quad instance data (for backward compatibility)
6
+ */
7
+ export interface QuadInstance {
8
+ /** X position */
9
+ x: number;
10
+ /** Y position */
11
+ y: number;
12
+ /** Width */
13
+ width: number;
14
+ /** Height */
15
+ height: number;
16
+ /** Rotation in radians */
17
+ rotation: number;
18
+ /** Color as [r, g, b] (0-1 range) */
19
+ color: [number, number, number];
20
+ }
21
+ /**
22
+ * V2 Sprite Quad instance data with full 2.5D support
23
+ */
24
+ export interface SpriteQuadInstance {
25
+ /** Position in 2.5D space */
26
+ x: number;
27
+ y: number;
28
+ z: number;
29
+ /** Width and height */
30
+ width: number;
31
+ height: number;
32
+ /** Rotation in radians */
33
+ rotation: number;
34
+ /** Color tint (0-1 range, default white) */
35
+ color?: {
36
+ r: number;
37
+ g: number;
38
+ b: number;
39
+ a: number;
40
+ };
41
+ /** Texture coordinates (UV region in texture atlas) */
42
+ uvRect?: {
43
+ uMin: number;
44
+ vMin: number;
45
+ uMax: number;
46
+ vMax: number;
47
+ };
48
+ /** Texture index for atlas selection */
49
+ texIndex?: number;
50
+ /** Grid position for GPU-based transformation (optional) */
51
+ gridX?: number;
52
+ gridY?: number;
53
+ }
54
+ /**
55
+ * V1 Batch Renderer for backward compatibility
56
+ * Renders 2D colored quads with position and texture coordinates
57
+ *
58
+ * Features:
59
+ * - Dynamic vertex buffer for per-frame updates
60
+ * - Batch rendering of multiple quads in single draw call
61
+ * - Simple 2D positioning and coloring
62
+ */
63
+ export declare class BatchRenderer {
64
+ private gl;
65
+ private shader;
66
+ private vertexBuffer;
67
+ private maxQuads;
68
+ private vertexData;
69
+ private quads;
70
+ private isDirty;
71
+ private verticesPerQuad;
72
+ private floatsPerVertex;
73
+ private texture;
74
+ /**
75
+ * Create a new batch renderer (V1)
76
+ * @param gl WebGL rendering context
77
+ * @param shader Shader program to use
78
+ * @param maxQuads Maximum number of quads to batch (default 1000)
79
+ */
80
+ constructor(gl: WebGLRenderingContext, shader: Shader, maxQuads?: number);
81
+ /**
82
+ * Set the texture for batch rendering
83
+ * @param texture The texture to use when rendering
84
+ */
85
+ setTexture(texture: Texture | null): void;
86
+ /**
87
+ * Add a quad to the batch
88
+ * @param quad Quad instance to add
89
+ */
90
+ addQuad(quad: QuadInstance): void;
91
+ /**
92
+ * Clear all quads from the batch
93
+ */
94
+ clear(): void;
95
+ /**
96
+ * Get number of quads currently in batch
97
+ */
98
+ getQuadCount(): number;
99
+ /**
100
+ * Update the batch - rebuilds vertex buffer if quads changed
101
+ */
102
+ update(): void;
103
+ /**
104
+ * Render the batch
105
+ * @param camera Optional camera for view transform (defaults to identity matrix)
106
+ */
107
+ render(camera?: Camera): void;
108
+ /**
109
+ * Generate vertices for a quad with rotation applied
110
+ * Returns 6 vertices (2 triangles)
111
+ * @private
112
+ */
113
+ private generateQuadVertices;
114
+ /**
115
+ * Dispose resources
116
+ */
117
+ dispose(): void;
118
+ }
119
+ /**
120
+ * V2 Batch Renderer for 2.5D sprites
121
+ * Supports position (x, y, z), texture coordinates (u, v),
122
+ * color tint (r, g, b, a), and texture index for texture atlases
123
+ */
124
+ export declare class SpriteBatchRenderer {
125
+ private gl;
126
+ private shader;
127
+ private vertexBuffer;
128
+ private maxQuads;
129
+ private vertexData;
130
+ private quads;
131
+ private isDirty;
132
+ private verticesPerQuad;
133
+ private floatsPerVertex;
134
+ private texture;
135
+ private depthTestEnabled;
136
+ /**
137
+ * Create a new sprite batch renderer (V2)
138
+ * @param gl WebGL rendering context
139
+ * @param shader Shader program to use (should be SHADERS_V2)
140
+ * @param maxQuads Maximum number of quads to batch (default 1000)
141
+ */
142
+ constructor(gl: WebGLRenderingContext, shader: Shader, maxQuads?: number);
143
+ /**
144
+ * Set the texture for batch rendering
145
+ * @param texture The texture to use when rendering
146
+ */
147
+ setTexture(texture: Texture | null): void;
148
+ /**
149
+ * Add a sprite quad to the batch
150
+ * @param quad Sprite quad instance to add
151
+ */
152
+ addQuad(quad: SpriteQuadInstance): void;
153
+ /**
154
+ * Clear all quads from the batch
155
+ */
156
+ clear(): void;
157
+ /**
158
+ * Get number of quads currently in batch
159
+ */
160
+ getQuadCount(): number;
161
+ /**
162
+ * Update the batch - rebuilds vertex buffer if quads changed
163
+ */
164
+ update(): void;
165
+ /**
166
+ * Set whether depth testing is enabled
167
+ * When enabled, sprites with lower Z values appear behind sprites with higher Z values
168
+ * @param enabled Whether to enable depth testing (default true)
169
+ */
170
+ setDepthTestEnabled(enabled: boolean): void;
171
+ /**
172
+ * Render the batch
173
+ * @param camera Optional camera for view transform (defaults to identity matrix)
174
+ */
175
+ render(camera?: Camera): void;
176
+ /**
177
+ * Generate vertices for a quad with rotation applied
178
+ * Returns 6 vertices (2 triangles)
179
+ * @private
180
+ */
181
+ private generateQuadVertices;
182
+ /**
183
+ * Dispose resources
184
+ */
185
+ dispose(): void;
186
+ }
187
+ /**
188
+ * GPU-Based Sprite Batch Renderer (V3)
189
+ *
190
+ * This version moves the 2.5D transformation from CPU to GPU.
191
+ * The vertex shader handles isometric projection, rotation, and camera transform.
192
+ *
193
+ * Key differences from SpriteBatchRenderer (V2):
194
+ * - Stores grid position (gridX, gridY) instead of screen position (x, y)
195
+ * - Passes local offset to shader for GPU-based rotation
196
+ * - Shader handles isometric projection and camera transform
197
+ * - Reduced CPU overhead for transformation calculations
198
+ *
199
+ * Vertex Layout (12 floats per vertex):
200
+ * [0-1] GridPosition: gridX, gridY
201
+ * [2] ZPosition: z
202
+ * [3-4] LocalOffset: localX, localY (quad corner offset)
203
+ * [5-6] TexCoord: u, v
204
+ * [7-10] Color: r, g, b, a
205
+ * [11] TexIndex: texture index
206
+ */
207
+ export declare class GPUBasedSpriteBatchRenderer {
208
+ private gl;
209
+ private shader;
210
+ private vertexBuffer;
211
+ private maxQuads;
212
+ private vertexData;
213
+ private quads;
214
+ private isDirty;
215
+ private verticesPerQuad;
216
+ private floatsPerVertex;
217
+ private texture;
218
+ private depthTestEnabled;
219
+ private tileSize;
220
+ private zScale;
221
+ private resolution;
222
+ /**
223
+ * Create a new GPU-based sprite batch renderer (V3)
224
+ * @param gl WebGL rendering context
225
+ * @param shader Shader program to use (should be SHADERS_V3)
226
+ * @param maxQuads Maximum number of quads to batch (default 1000)
227
+ * @param tileSize Tile size for isometric projection (default {width: 64, height: 32})
228
+ * @param zScale Scale factor for Z height (default 1.0)
229
+ */
230
+ constructor(gl: WebGLRenderingContext, shader: Shader, maxQuads?: number, tileSize?: {
231
+ width: number;
232
+ height: number;
233
+ }, zScale?: number);
234
+ /**
235
+ * Set the texture for batch rendering
236
+ * @param texture The texture to use when rendering
237
+ */
238
+ setTexture(texture: Texture | null): void;
239
+ /**
240
+ * Add a sprite quad to the batch
241
+ * If gridX and gridY are provided, uses GPU transformation.
242
+ * Otherwise, converts x, y to grid coordinates.
243
+ * @param quad Sprite quad instance to add
244
+ */
245
+ addQuad(quad: SpriteQuadInstance): void;
246
+ /**
247
+ * Clear all quads from the batch
248
+ */
249
+ clear(): void;
250
+ /**
251
+ * Get number of quads currently in batch
252
+ */
253
+ getQuadCount(): number;
254
+ /**
255
+ * Update the batch - rebuilds vertex buffer if quads changed
256
+ */
257
+ update(): void;
258
+ /**
259
+ * Set whether depth testing is enabled
260
+ * @param enabled Whether to enable depth testing (default true)
261
+ */
262
+ setDepthTestEnabled(enabled: boolean): void;
263
+ /**
264
+ * Render the batch with GPU-based transformation
265
+ * @param camera Camera for view transform
266
+ */
267
+ render(camera: Camera): void;
268
+ /**
269
+ * Clean up GPU resources
270
+ */
271
+ dispose(): void;
272
+ }
273
+ //# sourceMappingURL=batch-renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-renderer.d.ts","sourceRoot":"","sources":["../../../src/rendering/batch-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iBAAiB;IACj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;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,MAAM,IAAI,IAAI;IA4Fd;;;OAGG;IACH,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAI3C;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAoK5B;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
@@ -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,CAA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d,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"}