Skip to content

Commit

Permalink
chore: remove units where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Dec 5, 2024
1 parent 86ebfa9 commit 60f8c4b
Show file tree
Hide file tree
Showing 76 changed files with 512 additions and 460 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added `easing` option to `moveTo(...)`
- Added new option bag style input to actions with durations in milliseconds instead of speed
```typescript
player.actions.rotateTo({angleRadians: angle, durationMs: 1000, rotationType});
player.actions.moveTo({pos: ex.vec(100, 100), durationMs: 1000});
player.actions.scaleTo({scale: ex.vec(2, 2), durationMs: 1000});
player.actions.rotateTo({angleRadians: angle, duration: 1000, rotationType});
player.actions.moveTo({pos: ex.vec(100, 100), duration: 1000});
player.actions.scaleTo({scale: ex.vec(2, 2), duration: 1000});
player.actions.repeatForever(ctx => {
ctx.curveTo({
controlPoints: [cp1, cp2, dest],
durationMs: 5000,
duration: 5000,
mode: 'uniform'
});
ctx.curveTo({
controlPoints: [cp2, cp1, start1],
durationMs: 5000,
duration: 5000,
mode: 'uniform'
});
});
Expand Down Expand Up @@ -267,6 +267,7 @@ are doing mtv adjustments during precollision.

### Updates

- Remove units by default from parameters
- Perf improve PolygonCollider.contains(...) perf by keeping geometry tests in local space.
- Perf improvement to image rendering! with ImageRendererV2! Roughly doubles the performance of image rendering
- Perf improvement to retrieving components with `ex.Entity.get()` which widely improves engine performance
Expand Down
4 changes: 2 additions & 2 deletions sandbox/tests/bezier/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ actor.onPostUpdate = () => {
actor.actions.repeatForever((ctx) => {
ctx.curveTo({
controlPoints: [cp1, cp2, dest],
durationMs: 5000,
duration: 5000,
mode: 'uniform'
});
ctx.curveTo({
controlPoints: [cp2, cp1, start1],
durationMs: 5000,
duration: 5000,
mode: 'uniform'
});
});
Expand Down
6 changes: 3 additions & 3 deletions sandbox/tests/flash-shader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ actor.graphics.use(tex.toSprite());

game.add(actor);

var flash = (actor: ex.Actor, color: ex.Color, durationMs: number) => {
var flash = (actor: ex.Actor, color: ex.Color, duration: number) => {
const material = game.graphicsContext.createMaterial({
name: 'flash-material',
color,
Expand All @@ -41,8 +41,8 @@ var flash = (actor: ex.Actor, color: ex.Color, durationMs: number) => {
actor.graphics.material = material;
ex.coroutine(
function* () {
const total = durationMs;
let currentDuration = durationMs;
const total = duration;
let currentDuration = duration;
while (currentDuration > 0) {
const elapsed = yield;
currentDuration -= elapsed;
Expand Down
2 changes: 1 addition & 1 deletion sandbox/tests/rotation/rotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ engine.input.pointers.primary.on('down', (e: ex.PointerEvent) => {
var vector = new ex.Vector(e.worldPos.x - player.pos.x, e.worldPos.y - player.pos.y);
var angle = vector.toAngle();

player.actions.rotateTo({ angleRadians: angle, durationMs: 1000, rotationType });
player.actions.rotateTo({ angle: angle, duration: 1000, rotationType });
//console.log('rotating from ' + player.rotation + ' to ' + angle);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Actions/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Entity } from '../EntityComponentSystem/Entity';
*/
export interface Action {
id: number;
update(elapsedMs: number): void;
update(elapsed: number): void;
isComplete(entity: Entity): boolean;
reset(): void;
stop(): void;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/Actions/Action/ActionSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class ActionSequence implements Action {
this._sequenceBuilder(this._sequenceContext);
}

public update(elapsedMs: number): void {
this._actionQueue.update(elapsedMs);
public update(elapsed: number): void {
this._actionQueue.update(elapsed);
}

public isComplete(): boolean {
Expand Down
6 changes: 3 additions & 3 deletions src/engine/Actions/Action/Blink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Blink implements Action {
this._duration = (timeVisible + timeNotVisible) * numBlinks;
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._started) {
this._started = true;
this._elapsedTime = 0;
Expand All @@ -29,8 +29,8 @@ export class Blink implements Action {
return;
}

this._elapsedTime += elapsedMs;
this._totalTime += elapsedMs;
this._elapsedTime += elapsed;
this._totalTime += elapsed;
if (this._graphics.isVisible && this._elapsedTime >= this._timeVisible) {
this._graphics.isVisible = false;
this._elapsedTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Actions/Action/CallMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class CallMethod implements Action {
this._method = method;
}

public update(elapsedMs: number) {
public update(elapsed: number) {
this._method();
this._hasBeenCalled = true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Actions/Action/CurveBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface CurveByOptions {
/**
* Total duration for the action to run
*/
durationMs: number;
duration: number;
/**
* Dynamic mode will speed up/slow down depending on the curve
*
Expand Down Expand Up @@ -51,20 +51,20 @@ export class CurveBy implements Action {
controlPoints: [vec(0, 0), ...options.controlPoints],
quality: options.quality
});
this._durationMs = options.durationMs;
this._durationMs = options.duration;
this._mode = options.mode ?? this._mode;
this._currentMs = this._durationMs;
}

update(elapsedMs: number): void {
update(elapsed: number): void {
if (!this._started) {
this._curve.setControlPoint(0, this._tx.globalPos);
this._curve.setControlPoint(1, this._curve.controlPoints[1].add(this._tx.globalPos));
this._curve.setControlPoint(2, this._curve.controlPoints[2].add(this._tx.globalPos));
this._curve.setControlPoint(3, this._curve.controlPoints[3].add(this._tx.globalPos));
this._started = true;
}
this._currentMs -= elapsedMs;
this._currentMs -= elapsed;
const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1);
if (this._mode === 'dynamic') {
this._tx.pos = this._curve.getPoint(t);
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Actions/Action/CurveTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface CurveToOptions {
/**
* Total duration for the action to run
*/
durationMs: number;
duration: number;
/**
* Dynamic mode will speed up/slow down depending on the curve
*
Expand Down Expand Up @@ -52,17 +52,17 @@ export class CurveTo implements Action {
controlPoints: [vec(0, 0), ...options.controlPoints],
quality: options.quality
});
this._durationMs = options.durationMs;
this._durationMs = options.duration;
this._mode = options.mode ?? this._mode;
this._currentMs = this._durationMs;
}

update(elapsedMs: number): void {
update(elapsed: number): void {
if (!this._started) {
this._curve.setControlPoint(0, this._tx.globalPos.clone());
this._started = true;
}
this._currentMs -= elapsedMs;
this._currentMs -= elapsed;
const t = clamp(remap(0, this._durationMs, 0, 1, this._durationMs - this._currentMs), 0, 1);
if (this._mode === 'dynamic') {
this._tx.pos = this._curve.getPoint(t);
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Actions/Action/Delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export class Delay implements Action {
private _delay: number;
private _started: boolean = false;
private _stopped = false;
constructor(durationMs: number) {
this._delay = durationMs;
constructor(duration: number) {
this._delay = duration;
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._started) {
this._started = true;
}

this._elapsedTime += elapsedMs;
this._elapsedTime += elapsed;
}

isComplete(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Actions/Action/Die.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Die implements Action {
this._entity = entity;
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
this._entity.get(ActionsComponent).clearActions();
this._entity.kill();
this._stopped = true;
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Actions/Action/EaseBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { vec, Vector } from '../../Math/vector';
import { Action, nextActionId } from '../Action';

/**
* @deprecated use moveBy({offset: Vector, durationMs: number, easing: EasingFunction})
* @deprecated use moveBy({offset: Vector, duration: number, easing: EasingFunction})
*/
export class EaseBy implements Action {
id = nextActionId();
Expand Down Expand Up @@ -36,14 +36,14 @@ export class EaseBy implements Action {
this._lerpEnd = this._lerpStart.add(this._offset);
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._initialized) {
this._initialize();
this._initialized = true;
}

// Need to update lerp time first, otherwise the first update will always be zero
this._currentLerpTime += elapsedMs;
this._currentLerpTime += elapsed;
let newX = this._tx.pos.x;
let newY = this._tx.pos.y;
if (this._currentLerpTime < this._lerpDuration) {
Expand All @@ -63,7 +63,7 @@ export class EaseBy implements Action {
newY = this.easingFcn(this._currentLerpTime, this._lerpStart.y, this._lerpEnd.y, this._lerpDuration);
}
// Given the lerp position figure out the velocity in pixels per second
this._motion.vel = vec((newX - this._tx.pos.x) / (elapsedMs / 1000), (newY - this._tx.pos.y) / (elapsedMs / 1000));
this._motion.vel = vec((newX - this._tx.pos.x) / (elapsed / 1000), (newY - this._tx.pos.y) / (elapsed / 1000));
} else {
this._tx.pos = vec(this._lerpEnd.x, this._lerpEnd.y);
this._motion.vel = Vector.Zero;
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Actions/Action/EaseTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { vec, Vector } from '../../Math/vector';
import { Action, nextActionId } from '../Action';

/**
* @deprecated use moveTo({pos: Vector, durationMs: number, easing: EasingFunction})
* @deprecated use moveTo({pos: Vector, duration: number, easing: EasingFunction})
*/
export class EaseTo implements Action {
id = nextActionId();
Expand Down Expand Up @@ -34,14 +34,14 @@ export class EaseTo implements Action {
this._currentLerpTime = 0;
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._initialized) {
this._initialize();
this._initialized = true;
}

// Need to update lerp time first, otherwise the first update will always be zero
this._currentLerpTime += elapsedMs;
this._currentLerpTime += elapsed;
let newX = this._tx.pos.x;
let newY = this._tx.pos.y;
if (this._currentLerpTime < this._lerpDuration) {
Expand All @@ -61,7 +61,7 @@ export class EaseTo implements Action {
newY = this.easingFcn(this._currentLerpTime, this._lerpStart.y, this._lerpEnd.y, this._lerpDuration);
}
// Given the lerp position figure out the velocity in pixels per second
this._motion.vel = vec((newX - this._tx.pos.x) / (elapsedMs / 1000), (newY - this._tx.pos.y) / (elapsedMs / 1000));
this._motion.vel = vec((newX - this._tx.pos.x) / (elapsed / 1000), (newY - this._tx.pos.y) / (elapsed / 1000));
} else {
this._tx.pos = vec(this._lerpEnd.x, this._lerpEnd.y);
this._motion.vel = Vector.Zero;
Expand Down
11 changes: 5 additions & 6 deletions src/engine/Actions/Action/Fade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export class Fade implements Action {
private _started = false;
private _stopped = false;

constructor(entity: Entity, endOpacity: number, durationMs: number) {
constructor(entity: Entity, endOpacity: number, duration: number) {
this._graphics = entity.get(GraphicsComponent);
this._endOpacity = endOpacity;
this._remainingTime = this._originalTime = durationMs;
this._remainingTime = this._originalTime = duration;
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._graphics) {
return;
}
Expand All @@ -38,11 +38,10 @@ export class Fade implements Action {
}

if (this._remainingTime > 0) {
this._graphics.opacity +=
(this._multiplier * (Math.abs(this._graphics.opacity - this._endOpacity) * elapsedMs)) / this._remainingTime;
this._graphics.opacity += (this._multiplier * (Math.abs(this._graphics.opacity - this._endOpacity) * elapsed)) / this._remainingTime;
}

this._remainingTime -= elapsedMs;
this._remainingTime -= elapsed;

if (this.isComplete()) {
this._graphics.opacity = this._endOpacity;
Expand Down
10 changes: 5 additions & 5 deletions src/engine/Actions/Action/Flash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class Flash implements Action {
private _total: number = 0;
private _currentDuration: number = 0;

constructor(entity: Entity, color: Color, durationMs: number = 1000) {
constructor(entity: Entity, color: Color, duration: number = 1000) {
this._graphics = entity.get(GraphicsComponent);
this._duration = durationMs;
this._duration = duration;
this._entity = entity;
this._material = entity.scene?.engine.graphicsContext.createMaterial({
name: 'flash-material',
Expand All @@ -40,10 +40,10 @@ export class Flash implements Action {
color.rgb = color.rgb * color.a;
}`
}) as Material;
this._total = durationMs;
this._total = duration;
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._started) {
this._started = true;
this._total = this._duration;
Expand All @@ -54,7 +54,7 @@ export class Flash implements Action {
return;
}

this._currentDuration -= elapsedMs;
this._currentDuration -= elapsed;

if (this._graphics) {
this._material?.update((shader: Shader) => {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Actions/Action/Follow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Follow implements Action {
this._speed = 0;
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._started) {
this._started = true;
this._distanceBetween = this._current.distance(this._end);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Actions/Action/Meet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Meet implements Action {
}
}

public update(elapsedMs: number): void {
public update(elapsed: number): void {
if (!this._started) {
this._started = true;
this._distanceBetween = this._current.distance(this._end);
Expand Down
Loading

0 comments on commit 60f8c4b

Please sign in to comment.