From 28842a79a4fd2a5610a82c906ec3ec8c0f33d0e1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 20 Dec 2024 12:23:42 -0800 Subject: [PATCH] Source Engine: Fix some parent relationships Fixes the expanding panels in Portal 1 testchmb_a_06. --- src/SourceEngine/EntitySystem.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/SourceEngine/EntitySystem.ts b/src/SourceEngine/EntitySystem.ts index 353b47185..4c400bcf0 100644 --- a/src/SourceEngine/EntitySystem.ts +++ b/src/SourceEngine/EntitySystem.ts @@ -291,10 +291,12 @@ export class BaseEntity { this.playSequenceIndex(this.findSequenceLabel(label)); } - public spawn(entitySystem: EntitySystem): void { + public setupParent(entitySystem: EntitySystem): void { if (this.entity.parentname) this.setParentEntity(entitySystem.findEntityByTargetName(this.entity.parentname)); + } + public spawn(entitySystem: EntitySystem): void { if (this.entity.defaultanim) { this.seqdefaultindex = this.findSequenceLabel(this.entity.defaultanim); this.playSequenceIndex(this.seqdefaultindex); @@ -1111,6 +1113,7 @@ abstract class BaseDoor extends BaseToggle { } private hitTop(entitySystem: EntitySystem): void { + this.toggleState = ToggleState.Top; this.output_onFullyOpen.fire(entitySystem, this, this); if (this.wait > 0) { @@ -1119,6 +1122,7 @@ abstract class BaseDoor extends BaseToggle { } private hitBottom(entitySystem: EntitySystem): void { + this.toggleState = ToggleState.Bottom; this.output_onFullyClosed.fire(entitySystem, this, this); } @@ -4465,9 +4469,16 @@ export class EntitySystem { // Still fetching; nothing to do. return; } else if (spawnStateAction === SpawnState.ReadyForSpawn) { + // Set all parent relationships so that the origin relationships are correct + // before calling the spawn method on anything. + for (let i = 0; i < this.entities.length; i++) { + const entity = this.entities[i]; + assert(entity.spawnState === SpawnState.ReadyForSpawn); + entity.setupParent(this); + } + for (let i = 0; i < this.entities.length; i++) - if (this.entities[i].spawnState === SpawnState.ReadyForSpawn) - this.entities[i].spawn(this); + this.entities[i].spawn(this); } this.processOutputQueue();