Remove sizeFactor, add entity scaling function instead#188
Remove sizeFactor, add entity scaling function instead#188c86ec23b-fef1-4979-b2fa-b9adc351b8cc merged 8 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces the camera/tank “sizeFactor” pattern with an entity-level scaling mechanism (scaleFactor + scale()), aiming to make size updates more consistent and reduce per-tick recomputation.
Changes:
- Removed
CameraEntity.sizeFactorand migrated size math toObjectEntity.scale()/scaleFactor, updating usages across tanks, barrels, bullets, addons, and factory spawning. - Refactored barrel/projectile scaling behavior (notably Rocket/Skimmer) to work with
scale()rather thansizeFactorgetters. - Adjusted a few gameplay/visibility behaviors (camera entity visibility filtering, drone AI view range, initial AI mouse position).
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Native/Camera.ts | Removes camera sizeFactor logic; scales player entity on level changes; tweaks invisible-entity send filter. |
| src/Native/Arena.ts | Uses scaleFactor for factory tank spawn offset calculations. |
| src/Gamemodes/Misc/FactoryTest.ts | Updates factory test offsets to use scaleFactor. |
| src/Entity/Tank/TankBody.ts | Removes sizeFactor getter and per-tick size updates; relies on scale() + scaleFactor. |
| src/Entity/Tank/Projectile/Skimmer.ts | Updates skimmer projectile scaling and barrel width behavior via scale() override. |
| src/Entity/Tank/Projectile/Rocket.ts | Updates rocket projectile scaling + barrel width behavior; adjusts rocket barrel definition width. |
| src/Entity/Tank/Projectile/Minion.ts | Initializes scaleFactor for minion projectile; removes sizeFactor getter. |
| src/Entity/Tank/Projectile/Drone.ts | Removes size-dependent view range; uses constant view range. |
| src/Entity/Tank/Projectile/Bullet.ts | Uses tank.scaleFactor for spawn offsets instead of sizeFactor. |
| src/Entity/Tank/Barrel.ts | Switches barrel sizing math to scaleFactor; removes per-tick resize logic. |
| src/Entity/Tank/AutoTurret.ts | Removes turret sizeFactor getter; ties turret scaling to owner/root scaling. |
| src/Entity/Tank/Addons.ts | Updates addon sizing/rotation behavior to rely on scaling instead of per-tick recompute; guard uses scaleFactor. |
| src/Entity/Object.ts | Adds scaleFactor field and scale() method; deletion animation now uses scale(). |
| src/Entity/Misc/Mothership.ts | Reorders setup so camera player is assigned before setLevel() scaling. |
| src/Entity/Misc/Dominator.ts | Reworks dominator scaling and level setup around scale()/scaleFactor. |
| src/Entity/Misc/Boss/FallenSpike.ts | Applies level-75 size via scale() instead of relying on initial boss sizing. |
| src/Entity/Misc/Boss/FallenMegaTrapper.ts | Applies level-75 size via scale(). |
| src/Entity/Misc/Boss/FallenAC.ts | Applies level-75 size via scale(). |
| src/Entity/Misc/BaseDrones.ts | Removes sizeFactor hack; compensates by changing drone spawner barrel definition sizing. |
| src/Entity/Misc/ArenaCloser.ts | Reworks arena closer scaling + level setup around scale()/scaleFactor. |
| src/Entity/Boss/FallenOverlord.ts | Applies level-75 size via scale(); removes sizeFactor getter usage pattern. |
| src/Entity/Boss/FallenBooster.ts | Applies level-75 size via scale(); removes sizeFactor getter usage pattern. |
| src/Entity/Boss/Defender.ts | Removes sizeFactor logic usage; minor stat tweaks and cleanup. |
| src/Entity/Boss/AbstractBoss.ts | Stops pre-scaling bosses in base constructor; relies on derived bosses to call scale() as needed. |
| src/Entity/AI.ts | Changes initial AI mouse x coordinate from 20 to 0. |
Comments suppressed due to low confidence (1)
src/Entity/Tank/Projectile/Bullet.ts:78
Bulletinstances never initialize their ownscaleFactor, but some projectiles (e.g. those that implementBarrelBaseand spawn childBarrels) rely onthis.scaleFactorfor correct barrel sizing now thatsizeFactoris removed. Right now this is handled ad-hoc in some derived constructors (Rocket/Skimmer/Minion), which makes it easy to miss cases and can produce incorrectly sized child barrels. Consider initializingthis.scaleFactorin the baseBulletconstructor based on the computed bullet size (or otherwise enforcing/centralizing the contract for BarrelBase implementers) so all barrel-spawning projectiles behave consistently.
const bulletDefinition = barrel.definition.bullet;
const scaleFactor = tank.scaleFactor;
const statLevels = tank.cameraEntity.cameraData?.values.statLevels.values;
this.relationsData.values.team = barrel.relationsData.values.team;
this.relationsData.values.owner = tank;
this.physicsData.values.sides = 1;
this.physicsData.values.flags |= PhysicsFlags.noOwnTeamCollision | PhysicsFlags.canEscapeArena;
if (tank.positionData.values.flags & PositionFlags.canMoveThroughWalls) this.positionData.values.flags |= PositionFlags.canMoveThroughWalls
this.physicsData.values.size = (barrel.physicsData.values.width / 2) * bulletDefinition.sizeRatio;
this.styleData.values.color = tank.rootParent.styleData.values.color;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| super(game, camera, inputs); | ||
|
|
||
| camera.cameraData.values.player = this; | ||
| camera.setLevel(300); | ||
| camera.sizeFactor = (ArenaCloser.BASE_SIZE / 50); | ||
|
|
||
| super(game, camera, inputs); | ||
| this.scaleFactor = 1; | ||
| this.scale(ArenaCloser.BASE_SIZE / this.baseSize); | ||
|
|
There was a problem hiding this comment.
Similar to Dominator: camera.setLevel(300) currently runs after player is set, which scales the initial Basic tank body/barrels and is then immediately followed by resetting scaleFactor/rescales and setTank(Tank.ArenaCloser). If the intent is to set stats/level without applying that level-based scaling to the body, consider calling setLevel() before assigning player (or otherwise skipping the initial scale) to avoid extra scaling and transient inconsistent state.
src/Entity/Tank/Barrel.ts
Outdated
| /** Resizes the barrel; when the tank gets bigger, the barrel must as well. */ | ||
| protected resize() { | ||
| const sizeFactor = this.tank.sizeFactor; | ||
| const size = this.physicsData.size = this.definition.size * sizeFactor; | ||
|
|
||
| this.physicsData.width = this.definition.width * sizeFactor; | ||
| this.positionData.angle = this.definition.angle + (this.definition.trapezoidDirection); | ||
| this.positionData.x = Math.cos(this.definition.angle) * (size / 2 + (this.definition.distance || 0)) - Math.sin(this.definition.angle) * this.definition.offset * sizeFactor; | ||
| this.positionData.y = Math.sin(this.definition.angle) * (size / 2 + (this.definition.distance || 0)) + Math.cos(this.definition.angle) * this.definition.offset * sizeFactor; | ||
|
|
||
| // Updates bullet accel too | ||
| this.bulletAccel = (20 + (this.tank.cameraEntity.cameraData?.values.statLevels.values[Stat.BulletSpeed] || 0) * 3) * this.definition.bullet.speed; | ||
| } | ||
|
|
||
| public tick(tick: number) { | ||
| this.resize(); | ||
|
|
||
| this.bulletAccel = (20 + (this.tank.cameraEntity.cameraData?.values.statLevels.values[Stat.BulletSpeed] || 0) * 3) * this.definition.bullet.speed; | ||
| this.relationsData.values.team = this.tank.relationsData.values.team; |
There was a problem hiding this comment.
resize() is now empty but still present, and tick() contains an oddly indented bulletAccel assignment. If resizing is fully replaced by the new scale() flow, consider removing resize() (and any related call sites) and cleaning up the tick() formatting to avoid leaving dead/placeholder code that looks like an incomplete refactor.
| super(arena.game, camera, inputs); | ||
|
|
||
| camera.cameraData.values.player = this; | ||
| camera.setLevel(75); | ||
| camera.sizeFactor = (Dominator.SIZE / 50); | ||
|
|
||
| super(arena.game, camera, inputs); | ||
| this.scaleFactor = 1; | ||
| this.scale(Dominator.SIZE / this.baseSize); | ||
|
|
There was a problem hiding this comment.
This constructor calls camera.setLevel(75) after assigning camera.cameraData.values.player = this, which triggers a scale of the temporary Basic tank body/barrels, and then immediately resets scaleFactor / rescales again before setTank(). Since the level is only used for stats here (and is above maxPlayerLevel anyway), consider reordering so setLevel() happens before assigning player (or otherwise avoiding the initial scale) to prevent redundant scaling work and transient inconsistent scaleFactor/size state.
| // It's weird, but it's how it works | ||
| sizeRatio *= Math.SQRT1_2 | ||
| this.sizeRatio = sizeRatio; | ||
| scaleFactor *= Math.SQRT1_2 |
There was a problem hiding this comment.
Avoid automated semicolon insertion (93% of all statements in the enclosing function have an explicit semicolon).
| scaleFactor *= Math.SQRT1_2 | |
| scaleFactor *= Math.SQRT1_2; |
Removed unused resize method from Barrel class.
Should be faster? also probably more consistent with everything else