@leafer/renderer 1.0.0-rc.3 → 1.0.0-rc.30
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/package.json +4 -4
- package/src/Renderer.ts +28 -16
- package/types/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/renderer",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.30",
|
|
4
4
|
"description": "@leafer/renderer",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/leaferjs/leafer.git"
|
|
17
17
|
},
|
|
18
|
-
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/renderer",
|
|
18
|
+
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/partner/renderer",
|
|
19
19
|
"bugs": "https://github.com/leaferjs/leafer/issues",
|
|
20
20
|
"keywords": [
|
|
21
21
|
"leafer",
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.30"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.30"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/Renderer.ts
CHANGED
|
@@ -19,6 +19,7 @@ export class Renderer implements IRenderer {
|
|
|
19
19
|
|
|
20
20
|
public waitAgain: boolean
|
|
21
21
|
public changed: boolean
|
|
22
|
+
public ignore: boolean
|
|
22
23
|
|
|
23
24
|
public config: IRendererConfig = {
|
|
24
25
|
usePartRender: true,
|
|
@@ -109,6 +110,11 @@ export class Renderer implements IRenderer {
|
|
|
109
110
|
} else {
|
|
110
111
|
this.requestLayout()
|
|
111
112
|
|
|
113
|
+
if (this.ignore) {
|
|
114
|
+
this.ignore = this.rendering = false
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
112
118
|
this.emitRender(RenderEvent.BEFORE)
|
|
113
119
|
|
|
114
120
|
if (this.config.usePartRender && this.totalTimes > 1) {
|
|
@@ -134,7 +140,7 @@ export class Renderer implements IRenderer {
|
|
|
134
140
|
const { canvas, updateBlocks: list } = this
|
|
135
141
|
if (!list) return debug.warn('PartRender: need update attr')
|
|
136
142
|
|
|
137
|
-
|
|
143
|
+
this.mergeBlocks()
|
|
138
144
|
list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty()) this.clipRender(block) })
|
|
139
145
|
}
|
|
140
146
|
|
|
@@ -144,19 +150,19 @@ export class Renderer implements IRenderer {
|
|
|
144
150
|
|
|
145
151
|
const bounds = block.getIntersect(canvas.bounds)
|
|
146
152
|
const includes = block.includes(this.target.__world)
|
|
147
|
-
const realBounds = new Bounds(
|
|
153
|
+
const realBounds = new Bounds(bounds)
|
|
148
154
|
|
|
149
155
|
canvas.save()
|
|
150
156
|
|
|
151
157
|
if (includes && !Debug.showRepaint) {
|
|
152
158
|
canvas.clear()
|
|
153
159
|
} else {
|
|
154
|
-
bounds.spread(
|
|
160
|
+
bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil()
|
|
155
161
|
canvas.clearWorld(bounds, true)
|
|
156
162
|
canvas.clipWorld(bounds, true)
|
|
157
163
|
}
|
|
158
164
|
|
|
159
|
-
this.__render(bounds, realBounds)
|
|
165
|
+
this.__render(bounds, includes, realBounds)
|
|
160
166
|
canvas.restore()
|
|
161
167
|
|
|
162
168
|
Run.end(t)
|
|
@@ -168,14 +174,14 @@ export class Renderer implements IRenderer {
|
|
|
168
174
|
|
|
169
175
|
canvas.save()
|
|
170
176
|
canvas.clear()
|
|
171
|
-
this.__render(canvas.bounds)
|
|
177
|
+
this.__render(canvas.bounds, true)
|
|
172
178
|
canvas.restore()
|
|
173
179
|
|
|
174
180
|
Run.end(t)
|
|
175
181
|
}
|
|
176
182
|
|
|
177
|
-
protected __render(bounds: IBounds, realBounds?: IBounds): void {
|
|
178
|
-
const options: IRenderOptions = bounds
|
|
183
|
+
protected __render(bounds: IBounds, includes?: boolean, realBounds?: IBounds,): void {
|
|
184
|
+
const options: IRenderOptions = bounds.includes(this.target.__world) ? { includes } : { bounds, includes }
|
|
179
185
|
|
|
180
186
|
if (this.needFill) this.canvas.fillWorld(bounds, this.config.fill)
|
|
181
187
|
if (Debug.showRepaint) this.canvas.strokeWorld(bounds, 'red')
|
|
@@ -204,7 +210,7 @@ export class Renderer implements IRenderer {
|
|
|
204
210
|
const { updateBlocks: list } = this
|
|
205
211
|
if (list) {
|
|
206
212
|
const bounds = new Bounds()
|
|
207
|
-
bounds.
|
|
213
|
+
bounds.setList(list)
|
|
208
214
|
list.length = 0
|
|
209
215
|
list.push(bounds)
|
|
210
216
|
}
|
|
@@ -214,10 +220,13 @@ export class Renderer implements IRenderer {
|
|
|
214
220
|
const startTime = Date.now()
|
|
215
221
|
Platform.requestRender(() => {
|
|
216
222
|
this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)))
|
|
217
|
-
|
|
218
|
-
|
|
223
|
+
|
|
224
|
+
if (this.running) {
|
|
225
|
+
this.target.emit(AnimateEvent.FRAME)
|
|
226
|
+
if (this.changed && this.canvas.view) this.render()
|
|
227
|
+
this.target.emit(RenderEvent.NEXT)
|
|
219
228
|
}
|
|
220
|
-
|
|
229
|
+
|
|
221
230
|
if (this.target) this.__requestRender()
|
|
222
231
|
})
|
|
223
232
|
}
|
|
@@ -229,9 +238,14 @@ export class Renderer implements IRenderer {
|
|
|
229
238
|
const bounds = new Bounds(0, 0, width, height)
|
|
230
239
|
if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
|
|
231
240
|
this.addBlock(this.canvas.bounds)
|
|
232
|
-
this.target.forceUpdate('
|
|
241
|
+
this.target.forceUpdate('surface')
|
|
242
|
+
return
|
|
233
243
|
}
|
|
234
244
|
}
|
|
245
|
+
|
|
246
|
+
// 需要象征性派发一下渲染事件
|
|
247
|
+
this.addBlock(new Bounds(0, 0, 1, 1))
|
|
248
|
+
this.changed = true
|
|
235
249
|
}
|
|
236
250
|
|
|
237
251
|
protected __onLayoutEnd(event: LayoutEvent): void {
|
|
@@ -240,7 +254,7 @@ export class Renderer implements IRenderer {
|
|
|
240
254
|
if (item.updatedList) item.updatedList.list.some(leaf => {
|
|
241
255
|
empty = (!leaf.__world.width || !leaf.__world.height)
|
|
242
256
|
if (empty) {
|
|
243
|
-
if (!leaf.isLeafer) debug.
|
|
257
|
+
if (!leaf.isLeafer) debug.tip(leaf.innerName, ': empty')
|
|
244
258
|
empty = (!leaf.isBranch || leaf.isBranchLeaf) // render object
|
|
245
259
|
}
|
|
246
260
|
return empty
|
|
@@ -271,9 +285,7 @@ export class Renderer implements IRenderer {
|
|
|
271
285
|
if (this.target) {
|
|
272
286
|
this.stop()
|
|
273
287
|
this.__removeListenEvents()
|
|
274
|
-
this.target = null
|
|
275
|
-
this.canvas = null
|
|
276
|
-
this.config = null
|
|
288
|
+
this.target = this.canvas = this.config = null
|
|
277
289
|
}
|
|
278
290
|
}
|
|
279
291
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare class Renderer implements IRenderer {
|
|
|
12
12
|
rendering: boolean;
|
|
13
13
|
waitAgain: boolean;
|
|
14
14
|
changed: boolean;
|
|
15
|
+
ignore: boolean;
|
|
15
16
|
config: IRendererConfig;
|
|
16
17
|
protected renderBounds: IBounds;
|
|
17
18
|
protected renderOptions: IRenderOptions;
|
|
@@ -29,7 +30,7 @@ declare class Renderer implements IRenderer {
|
|
|
29
30
|
partRender(): void;
|
|
30
31
|
clipRender(block: IBounds): void;
|
|
31
32
|
fullRender(): void;
|
|
32
|
-
protected __render(bounds: IBounds, realBounds?: IBounds): void;
|
|
33
|
+
protected __render(bounds: IBounds, includes?: boolean, realBounds?: IBounds): void;
|
|
33
34
|
renderHitView(_options: IRenderOptions): void;
|
|
34
35
|
renderBoundsView(_options: IRenderOptions): void;
|
|
35
36
|
addBlock(block: IBounds): void;
|