-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Renderer simplification and Render plugins (#2185)
This PR simplifies the renderer code to prepare for custom render plugins, this will allow custom renderers with custom shaders to be built into excalibur. ## Changes: - Add border drawing to circles and rectangles 🎉 - Split the monolithic style renderer into separate internal renderer plugins - Improve the Shader code abstractions, adds a safety feature and error logging to avoid common shader/webgl issues - Remove complicated pooling strategy, and remove Poolable which is invalid in stricter TS (mentioned in #2157)
- Loading branch information
Showing
70 changed files
with
3,195 additions
and
1,281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Test Draw Call Limits and Orderings</title> | ||
</head> | ||
<body> | ||
<canvas id="game"></canvas> | ||
<div> | ||
<div>Draw Calls:<span id="draw-calls">0</span></div> | ||
<div># Items:<span id="drawn-items">0</span></div> | ||
<button id="add">Add 1000 Items</button> | ||
</div> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="./index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/// <reference path="../../lib/excalibur.d.ts" /> | ||
|
||
|
||
var game = new ex.Engine({ | ||
canvasElementId: 'game', | ||
width: 600, | ||
height: 400 | ||
}); | ||
|
||
var tex = new ex.ImageSource('https://cdn.rawgit.com/excaliburjs/Excalibur/7dd48128/assets/sword.png'); | ||
|
||
var loader = new ex.Loader([tex]); | ||
|
||
var random = new ex.Random(1337); | ||
|
||
var items = [{pos: ex.Vector.Zero, vel: ex.vec(random.integer(50, 100), random.integer(50, 100))}]; | ||
var drawCalls$ = document.getElementById('draw-calls'); | ||
var drawnItems$ = document.getElementById('drawn-items'); | ||
var add$ = document.getElementById('add'); | ||
add$.addEventListener('click', () => { | ||
for (let i = 0; i < 1000; i++) { | ||
items.push({ | ||
pos: ex.vec(0, 0), | ||
vel: ex.vec(random.integer(50, 100), random.integer(50, 100)) | ||
}); | ||
} | ||
}); | ||
|
||
game.start(loader).then(() => { | ||
const width = tex.width; | ||
const height = tex.height; | ||
game.onPostUpdate = (_engine, deltaMs) => { | ||
for (let i = 0; i < items.length; i++) { | ||
items[i].pos.addEqual(items[i].vel.scale(deltaMs/1000)); | ||
if ((items[i].pos.x + width / 2) > 600 || items[i].pos.x < 0) { | ||
items[i].vel.x *= -1; | ||
} | ||
|
||
if ((items[i].pos.y + height / 2) > 400 || items[i].pos.y < 0) { | ||
items[i].vel.y *= -1; | ||
} | ||
} | ||
game.graphicsContext.drawCircle(ex.vec(200, 200), width / 4, ex.Color.Blue, ex.Color.Black, 2); | ||
}; | ||
|
||
game.onPostDraw = (_engine, deltaMs) => { | ||
const blue = ex.Color.Blue; | ||
const black = ex.Color.Black; | ||
for (let i = 0; i < items.length; i++) { | ||
game.graphicsContext.drawImage(tex.image, | ||
0, 0, width, height, | ||
items[i].pos.x, items[i].pos.y, width / 2, height / 2); | ||
|
||
// game.graphicsContext.drawCircle(items[i].pos, width / 4, blue, black, 2); | ||
// game.graphicsContext.drawRectangle(items[i].pos, width, height, blue, black, 2); | ||
} | ||
}; | ||
|
||
game.on('postframe', () => { | ||
drawCalls$.innerText = game.stats.currFrame.graphics.drawCalls.toString(); | ||
drawnItems$.innerText = game.stats.currFrame.graphics.drawnImages.toString(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.