Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize #65

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cocos/core/animation/kinematics/ccd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export function ccdIK(

const iEndFactor = links.length - 1;
const endFactor = links[iEndFactor];
for (let iteration = 0; iteration < maxIterations; ++iteration) {
// Won't run in infinite loop since we have `nLinks >= 2`
if (forward) {
if (forward) {
for (let iteration = 0; iteration < maxIterations; ++iteration) {
// Won't run in infinite loop since we have `nLinks >= 2`
for (let iLink = 0; iLink < iEndFactor; ++iLink) {
const result = correct(iLink);
if (result === IterationResult.INTERRUPTED) {
Expand All @@ -54,7 +54,10 @@ export function ccdIK(
return;
}
}
} else {
}
} else {
for (let iteration = 0; iteration < maxIterations; ++iteration) {
// Won't run in infinite loop since we have `nLinks >= 2`
for (let iLink = iEndFactor - 1; iLink >= 0; --iLink) {
const result = correct(iLink);
if (result === IterationResult.INTERRUPTED) {
Expand Down
47 changes: 26 additions & 21 deletions cocos/core/animation/marionette/condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class BinaryCondition implements Condition {
evaluation.setLhs,
evaluation,
);
const rhsValue = bindOr(
const rhsValue = bindNumericOr(
context,
rhs,
VariableType.NUMBER,
Expand All @@ -81,27 +81,30 @@ export declare namespace BinaryCondition {

class BinaryConditionEval implements ConditionEval {
private declare _operator: BinaryOperator;
private declare _operands: [Value, Value | undefined];
private declare _lhs: number;
private declare _rhs: number;
private declare _result: boolean;

constructor (operator: BinaryOperator, lhs: Value, rhs?: Value) {
constructor (operator: BinaryOperator, lhs: number, rhs: number) {
this._operator = operator;
this._operands = [lhs, rhs];
this._lhs = lhs;
this._rhs = rhs;
this._eval();
}

public reset (lhs: Value, rhs?: Value) {
this._operands = [lhs, rhs];
public reset (lhs: number, rhs: number) {
this._lhs = lhs;
this._rhs = rhs;
this._eval();
}

public setLhs (value: Value) {
this._operands[0] = value;
public setLhs (value: number) {
this._lhs = value;
this._eval();
}

public setRhs (value: Value) {
this._operands[1] = value;
public setRhs (value: number) {
this._rhs = value;
this._eval();
}

Expand All @@ -113,8 +116,10 @@ class BinaryConditionEval implements ConditionEval {
}

private _eval () {
// TODO: rhs assertion?
const [lhs, rhs] = this._operands;
const {
_lhs: lhs,
_rhs: rhs,
} = this;
switch (this._operator) {
default:
case BinaryOperator.EQUAL_TO:
Expand All @@ -124,16 +129,16 @@ class BinaryConditionEval implements ConditionEval {
this._result = lhs !== rhs;
break;
case BinaryOperator.LESS_THAN:
this._result = lhs < rhs!;
this._result = lhs < rhs;
break;
case BinaryOperator.LESS_THAN_OR_EQUAL_TO:
this._result = lhs <= rhs!;
this._result = lhs <= rhs;
break;
case BinaryOperator.GREATER_THAN:
this._result = lhs > rhs!;
this._result = lhs > rhs;
break;
case BinaryOperator.GREATER_THAN_OR_EQUAL_TO:
this._result = lhs >= rhs!;
this._result = lhs >= rhs;
break;
}
}
Expand Down Expand Up @@ -163,7 +168,7 @@ export class UnaryCondition implements Condition {

public [createEval] (context: ConditionEvalContext) {
const { operator, operand } = this;
const evaluation = new UnaryConditionEval(operator, 0.0);
const evaluation = new UnaryConditionEval(operator, false);
const value = bindOr(
context,
operand,
Expand All @@ -182,20 +187,20 @@ export declare namespace UnaryCondition {

class UnaryConditionEval implements ConditionEval {
private declare _operator: UnaryOperator;
private declare _operand: Value;
private declare _operand: boolean;
private declare _result: boolean;

constructor (operator: UnaryOperator, operand: Value) {
constructor (operator: UnaryOperator, operand: boolean) {
this._operator = operator;
this._operand = operand;
this._eval();
}

public reset (value: Value) {
public reset (value: boolean) {
this.setOperand(value);
}

public setOperand (value: Value) {
public setOperand (value: boolean) {
this._operand = value;
this._eval();
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/animation/marionette/parametric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function bindNumericOr<TValue, TThis, TArgs extends any[]> (
...args,
);

return initialValue;
return initialValue as unknown as number;
}

export function validateVariableExistence (varInstance: VarInstance | undefined, name: string): varInstance is VarInstance {
Expand Down