Skip to content

Commit

Permalink
fix bugs with unlocked warps, different culling setup
Browse files Browse the repository at this point in the history
  • Loading branch information
amcolash committed Jan 2, 2025
1 parent 5a55d67 commit d977019
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/classes/Environment/Warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ export function warpTo(location: WarpType, player: Player, offset?: Types.Math.V
scene.sound.play(sound);

scene.cameras.main.fadeOut(200, 0, 0, 0, (_camera: Cameras.Scene2D.Camera, progress: number) => {
if (progress >= 1) scene.cameras.main.fadeIn(1000, 0, 0, 0);
if (progress >= 1) {
scene.time.delayedCall(300, () => scene.cameras.main.fadeIn(1000, 0, 0, 0));
}
});

scene.cameras.main.stopFollow();
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Player/Journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class Journal extends GameObjects.Image {

handleSideEffects(entry: JournalEntry, silent: boolean) {
const { warpAdd } = JournalData[entry];
if (warpAdd) updateWarpLocked(this.scene, warpAdd, true);
if (warpAdd) updateWarpLocked(this.scene, warpAdd, false);

if (entry === JournalEntry.ClockFirstGear || entry === JournalEntry.ClockSecondGear) {
const clock = getNPC(this.scene, NPCType.ClockTower);
Expand Down
4 changes: 2 additions & 2 deletions src/classes/Player/Quests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export class Quests extends GameObjects.Container {

handleSideEffects(type: QuestType, completed: boolean, silent?: boolean) {
const { warpAdd, warpComplete } = QuestData[type];
if (warpAdd) updateWarpLocked(this.scene as Game, warpAdd, true);
if (completed && warpComplete) updateWarpLocked(this.scene as Game, warpComplete, true);
if (warpAdd) updateWarpLocked(this.scene as Game, warpAdd, false);
if (completed && warpComplete) updateWarpLocked(this.scene as Game, warpComplete, false);

if (type === QuestType.FindPotionIngredients && !completed) {
const scene = this.player.scene;
Expand Down
2 changes: 1 addition & 1 deletion src/data/cutscene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function updateSphinx(scene: Scene, complete?: boolean, instant?: boolean
(wall.body as Physics.Arcade.Body)?.updateFromGameObject();
}

updateWarpLocked(scene, WarpType.ForestEast, complete || false);
updateWarpLocked(scene, WarpType.ForestEast, !complete);

const { x, y } = NPCData[NPCType.Sphinx];
const newX = complete ? x + 200 : x;
Expand Down
70 changes: 42 additions & 28 deletions src/scenes/Game.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GameObjects, Scene, Types } from 'phaser';
import { GameObjects, Geom, Scene, Types } from 'phaser';

import { DebugLight } from '../classes/Debug/DebugLight';
import { DebugUI } from '../classes/Debug/DebugUI';
Expand Down Expand Up @@ -158,45 +158,59 @@ export class Game extends Scene {
this.frustumCull();
}

// Reused rectangles for frustum culling
cameraBounds: Geom.Rectangle = new Geom.Rectangle(0, 0, Config.width + 300, Config.height + 300);
objectBounds: Geom.Rectangle = new Geom.Rectangle(0, 0, 0, 0);

frustumCull() {
const start = performance.now();

const children = this.children.getAll().filter((object) => {
this.cameraBounds.x = this.cameras.main.scrollX - 150;
this.cameraBounds.y = this.cameras.main.scrollY - 150;

const children = this.children.getAll();

// let visible = '';
let count = 0;
let total = 0;
for (let child of children) {
if (
object instanceof GameObjects.Image ||
object instanceof GameObjects.Sprite ||
object instanceof GameObjects.Particles.ParticleEmitter ||
object instanceof GameObjects.Graphics
child instanceof GameObjects.Image ||
child instanceof GameObjects.Sprite ||
child instanceof GameObjects.Particles.ParticleEmitter ||
child instanceof GameObjects.Graphics
) {
return !(
object instanceof Slope ||
(!(object instanceof Warp) && object.name?.startsWith('Warp')) || // TODO: Get frustum culling working for warps
object.depth >= Layer.Ui ||
object.name?.length === 0
);
if (
child.depth !== Layer.Debug &&
(child instanceof Slope ||
(!(child instanceof Warp) && child.name?.startsWith('Warp')) ||
child.depth >= Layer.Ui ||
child.name?.length === 0)
) {
continue;
}

total++;

this.objectBounds.setTo(child.x, child.y, child.width || 1, child.height || 1);
if (Geom.Intersects.RectangleToRectangle(this.cameraBounds, this.objectBounds)) {
if (child instanceof Warp) child.updateLocked();
else child.setVisible(true);

// visible += child.name + ', ';
count++;
} else {
child.setVisible(false);
}
}
return false;
});

for (let child of children) child.setVisible(false);
const visible = this.cameras.main.cull(children);

for (let child of visible) {
if (child instanceof Warp) child.updateLocked();
else child.visible = true;
}

// logEvery(
// 'culling',
// 1000,
// children.length,
// visible.length,
// visible.map((v) => v.name)
// );
// logEvery('culling', 1000, count, total);

if (globalStats && !this.cullingStats)
this.cullingStats = globalStats.addPanel(Panel('Culling', '#9ad8e4', '#064b62'));
this.cullingStats?.update(performance.now() - start);
// this.cullingStats?.update(count);
}

createBackgrounds() {
Expand Down

0 comments on commit d977019

Please sign in to comment.