Skip to content

Commit

Permalink
Changes Alignment to be exposed as an enum so that emscripten doesn’t…
Browse files Browse the repository at this point in the history
… new it every time we get it.
  • Loading branch information
luigi-rosso authored and avivian committed Oct 20, 2022
1 parent f2a519d commit 997a531
Show file tree
Hide file tree
Showing 9 changed files with 1,215 additions and 935 deletions.
73 changes: 73 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Never
TabWidth: 4
BreakBeforeBraces: Allman
IndentCaseLabels: true
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
NamespaceIndentation: None
AccessModifierOffset: -4
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ColumnLimit: 100
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: Align
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortCaseLabelsOnASingleLine: false
PenaltyReturnTypeOnItsOwnLine: 100
BreakBeforeBraces: Custom
SortIncludes: false
BraceWrapping:
AfterEnum: true
AfterClass: true
AfterControlStatement: true
AfterNamespace: true
AfterFunction: true
AfterStruct: true
AfterObjCDeclaration: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
AfterCaseLabel: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
---
Language: ObjC
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
NamespaceIndentation: All
AccessModifierOffset: -4
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ColumnLimit: 100
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: Align
BreakBeforeBraces: Custom
SortIncludes: false
BraceWrapping:
AfterEnum: true
AfterClass: true
AfterControlStatement: true
AfterNamespace: true
AfterFunction: true
AfterStruct: true
AfterObjCDeclaration: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
AfterCaseLabel: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
8 changes: 8 additions & 0 deletions wasm/build_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ elif [ "$OPTION" = "release" ]; then
else
premake5 gmake2 $PREMAKE_FLAGS && AR=emar CC=emcc CXX=em++ make -j$NCPU
fi

# If you want to run the leak checker with debug symbols, copy
# canvas_advanced.wasm to the parcel example's assets folder. Commented out for
# now as it should only happen if you're not building single and the canvas
# version.
# ----
# du build/bin/debug/canvas_advanced.wasm
# cp build/bin/debug/canvas_advanced.wasm examples/parcel_example/assets/canvas_advanced.wasm
83 changes: 82 additions & 1 deletion wasm/examples/parcel_example/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "regenerator-runtime";
import RiveCanvas from "../../../js/npm/webgl_advanced_single/webgl_advanced_single.mjs";
// import RiveCanvas from "../../build/bin/debug/canvas_advanced_single.mjs";
import RiveCanvas from "../../build/bin/debug/canvas_advanced.mjs";
// import RiveCanvas from "../../../js/npm/webgl_advanced_single/webgl_advanced_single.mjs";
import { registerTouchInteractions } from "../../../js/src/utils";
// import RiveCanvas from '../../../js/npm/canvas_advanced_single/canvas_advanced_single.mjs';
import AvatarAnimation from "./look.riv";
Expand Down Expand Up @@ -178,10 +180,89 @@ async function main() {
const numCanvases = parseInt(params.numCanvases || 0) || 10;
const hasRandomSizes = !!params.hasRandomSizes || false;
const rive = await RiveCanvas();

// Optionally perform leak checks right after rive is initialized.
// await checkForLeaks(rive);

rive.enableFPSCounter();
for (let i = 0; i < numCanvases; i++) {
await renderRiveAnimation({ rive, num: i, hasRandomSizes });
}
}

async function checkForLeaks(rive) {
const riveEx = RIVE_EXAMPLES[0];
const { hasStateMachine } = riveEx;
var stateMachine, animation;
const bytes = await (await fetch(new Request(riveEx.riveFile))).arrayBuffer();
const file = await rive.load(new Uint8Array(bytes));
const artboard = file.defaultArtboard();
artboard.advance(0);
if (hasStateMachine) {
stateMachine = new rive.StateMachineInstance(
artboard.stateMachineByIndex(0),
artboard
);
} else {
animation = new rive.LinearAnimationInstance(
artboard.animationByName(riveEx.animation),
artboard
);
}
const num = 0;
let canvas = document.getElementById(`canvas${num}`);
if (!canvas) {
const body = document.querySelector("body");
canvas = document.createElement("canvas");
canvas.id = `canvas${num}`;
body.appendChild(canvas);
}
canvas.width = "400";
canvas.height = "400";
// Don't use the offscreen renderer for FF as it should have a context limit of 300
const renderer = rive.makeRenderer(canvas, true);
var elapsedSeconds = 0.0167;
// Render 20 frames.
for (var i = 0; i < 100; i++) {
renderer.clear();
if (artboard) {
if (stateMachine) {
stateMachine.advance(elapsedSeconds);
}
if (animation) {
animation.advance(elapsedSeconds);
animation.apply(1);
}
artboard.advance(elapsedSeconds);
renderer.save();
renderer.align(
rive.Fit.contain,
rive.Alignment.center,
{
minX: 0,
minY: 0,
maxX: canvas.width,
maxY: canvas.height,
},
artboard.bounds
);
artboard.draw(renderer);
renderer.restore();
}
renderer.flush();
}

renderer.delete();
if (stateMachine) {
stateMachine.delete();
}
if (animation) {
animation.delete();
}
file.delete();
rive.cleanup();
// Report any leaks.
rive.doLeakCheck();
}

main();
6 changes: 6 additions & 0 deletions wasm/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,4 +874,10 @@ Rive.onRuntimeInitialized = function () {
);
Rive["disableFPSCounter"] = _animationCallbackHandler.disableFPSCounter;
_animationCallbackHandler.onAfterCallbacks = flushCanvasRenderers;

Rive["cleanup"] = function () {
if (_rectanizer) {
_rectanizer.delete();
}
};
};
Loading

0 comments on commit 997a531

Please sign in to comment.