Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/engine/workers/GameWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,20 @@ export class WorkerGame extends GameCore {
repairTargetId: unit.repairTargetId,
hasSpeedBuff: unit.hasBuff('stim'),
hasDamageBuff: unit.hasBuff('damage_boost'),
// Movement/targeting for waypoint visualization
targetX: unit.targetX,
targetY: unit.targetY,
speed: unit.speed,
// Command queue (serialized for transfer)
commandQueue: unit.commandQueue.map(cmd => ({
type: cmd.type,
targetX: cmd.targetX,
targetY: cmd.targetY,
targetEntityId: cmd.targetEntityId,
})),
// Combat stats for range overlays
attackRange: unit.attackRange,
sightRange: unit.sightRange,
});
}

Expand Down Expand Up @@ -706,6 +720,9 @@ export class WorkerGame extends GameCore {
hasProductionQueue: building.productionQueue.length > 0,
rallyX: building.rallyX,
rallyY: building.rallyY,
// Combat stats for range overlays
attackRange: building.attackRange,
sightRange: building.sightRange,
});
}

Expand Down
56 changes: 56 additions & 0 deletions src/engine/workers/RenderStateAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class UnitEntityAdapter implements IEntity {
private unitComponent: UnitAdapter;
private healthComponent: HealthAdapter;
private selectableComponent: SelectableAdapter;
private velocityComponent: VelocityAdapter;

constructor(data: UnitRenderState) {
this.id = data.id;
Expand All @@ -43,6 +44,7 @@ class UnitEntityAdapter implements IEntity {
this.unitComponent = new UnitAdapter(data);
this.healthComponent = new HealthAdapter(data);
this.selectableComponent = new SelectableAdapter(data);
this.velocityComponent = new VelocityAdapter(data);
}

public get<T>(componentType: string): T | undefined {
Expand All @@ -55,6 +57,8 @@ class UnitEntityAdapter implements IEntity {
return this.healthComponent as unknown as T;
case 'Selectable':
return this.selectableComponent as unknown as T;
case 'Velocity':
return this.velocityComponent as unknown as T;
default:
return undefined;
}
Expand All @@ -74,6 +78,7 @@ class UnitEntityAdapter implements IEntity {
this.unitComponent.update(data);
this.healthComponent.update(data);
this.selectableComponent.update(data);
this.velocityComponent.update(data);
}
}

Expand Down Expand Up @@ -118,6 +123,15 @@ class UnitAdapter {
public carryingMinerals: number;
public carryingVespene: number;
public gatherTargetId: number | null;
// Movement/targeting for waypoint visualization
public targetX: number | null;
public targetY: number | null;
public speed: number;
// Command queue for shift-click visualization
public commandQueue: Array<{ type: string; targetX?: number; targetY?: number; targetEntityId?: number }>;
// Combat stats for range overlays
public attackRange: number;
public sightRange: number;

constructor(data: UnitRenderState) {
this.unitId = data.unitId;
Expand All @@ -133,6 +147,12 @@ class UnitAdapter {
this.carryingMinerals = data.carryingMinerals;
this.carryingVespene = data.carryingVespene;
this.gatherTargetId = data.gatherTargetId;
this.targetX = data.targetX;
this.targetY = data.targetY;
this.speed = data.speed;
this.commandQueue = data.commandQueue;
this.attackRange = data.attackRange;
this.sightRange = data.sightRange;
}

public update(data: UnitRenderState): void {
Expand All @@ -149,6 +169,12 @@ class UnitAdapter {
this.carryingMinerals = data.carryingMinerals;
this.carryingVespene = data.carryingVespene;
this.gatherTargetId = data.gatherTargetId;
this.targetX = data.targetX;
this.targetY = data.targetY;
this.speed = data.speed;
this.commandQueue = data.commandQueue;
this.attackRange = data.attackRange;
this.sightRange = data.sightRange;
}

public isSelected(): boolean {
Expand Down Expand Up @@ -212,6 +238,29 @@ class SelectableAdapter {
}
}

/**
* Velocity-like adapter - derives velocity from position delta (current - previous)
* This allows animation systems to detect movement for walk/idle transitions.
*/
class VelocityAdapter {
public x: number;
public y: number;
public z: number;

constructor(data: UnitRenderState) {
// Velocity is approximated from position change between frames
this.x = data.x - data.prevX;
this.y = data.y - data.prevY;
this.z = data.z - data.prevZ;
}

public update(data: UnitRenderState): void {
this.x = data.x - data.prevX;
this.y = data.y - data.prevY;
this.z = data.z - data.prevZ;
}
}

// ============================================================================
// BUILDING ENTITY ADAPTER
// ============================================================================
Expand Down Expand Up @@ -300,6 +349,9 @@ class BuildingComponentAdapter {
public liftProgress: number;
// Production queue simulation for renderer compatibility
public productionQueue: { progress: number }[];
// Combat stats for range overlays
public attackRange: number;
public sightRange: number;

constructor(data: BuildingRenderState) {
this.buildingId = data.buildingId;
Expand All @@ -315,6 +367,8 @@ class BuildingComponentAdapter {
this.productionQueue = data.hasProductionQueue
? [{ progress: data.productionProgress }]
: [];
this.attackRange = data.attackRange;
this.sightRange = data.sightRange;
}

public update(data: BuildingRenderState): void {
Expand All @@ -331,6 +385,8 @@ class BuildingComponentAdapter {
this.productionQueue = data.hasProductionQueue
? [{ progress: data.productionProgress }]
: [];
this.attackRange = data.attackRange;
this.sightRange = data.sightRange;
}

public isReady(): boolean {
Expand Down
23 changes: 23 additions & 0 deletions src/engine/workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ export interface UnitRenderState {
// Buff indicators
hasSpeedBuff: boolean;
hasDamageBuff: boolean;
// Movement/targeting for waypoint visualization
targetX: number | null;
targetY: number | null;
speed: number;
// Command queue for shift-click visualization (serialized)
commandQueue: SerializedQueuedCommand[];
// Combat stats for range overlays
attackRange: number;
sightRange: number;
}

/**
* Serialized form of QueuedCommand for transfer to main thread.
* Simplified to only include render-relevant data.
*/
export interface SerializedQueuedCommand {
type: string;
targetX?: number;
targetY?: number;
targetEntityId?: number;
}

/**
Expand Down Expand Up @@ -111,6 +131,9 @@ export interface BuildingRenderState {
// Rally point
rallyX: number | null;
rallyY: number | null;
// Combat stats for range overlays
attackRange: number;
sightRange: number;
}

/**
Expand Down