Skip to content

Commit

Permalink
Source Engine: Fix some parent relationships
Browse files Browse the repository at this point in the history
Fixes the expanding panels in Portal 1 testchmb_a_06.
  • Loading branch information
magcius committed Dec 20, 2024
1 parent af0bb0b commit 28842a7
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/SourceEngine/EntitySystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 28842a7

Please sign in to comment.