Files
esengine/packages/framework/world-streaming/src/components/StreamingAnchorComponent.ts

93 lines
2.3 KiB
TypeScript
Raw Normal View History

import { Component, ECSComponent, Serializable, Serialize, Property } from '@esengine/ecs-framework';
import type { IPositionable } from '@esengine/spatial';
import type { IVector2 } from '@esengine/ecs-framework-math';
/**
*
*
* Marks an entity as a streaming anchor point.
* Chunks are loaded/unloaded based on distance to anchors.
*
*
* /
*
* x/y
* User must update the x/y position each frame.
*/
@ECSComponent('StreamingAnchor')
@Serializable({ version: 1, typeId: 'StreamingAnchor' })
export class StreamingAnchorComponent extends Component implements IPositionable {
/**
* X
*
* Current X position in world units.
*/
@Serialize()
@Property({ type: 'number', label: 'X' })
x: number = 0;
/**
* Y
*
* Current Y position in world units.
*/
@Serialize()
@Property({ type: 'number', label: 'Y' })
y: number = 0;
/**
* (IPositionable )
*
* Get position (IPositionable interface).
*/
get position(): IVector2 {
return { x: this.x, y: this.y };
}
/**
*
*
* Weight multiplier for this anchor's load radius.
* Higher values mean larger load radius around this anchor.
*/
@Serialize()
@Property({ type: 'number', label: 'Weight', min: 0.1, max: 10 })
weight: number = 1.0;
/**
*
*
* Enable directional prefetching based on movement.
*/
@Serialize()
@Property({ type: 'boolean', label: 'Enable Prefetch' })
bEnablePrefetch: boolean = true;
/**
* X
*
* Previous frame X position for velocity calculation.
*/
previousX: number = 0;
/**
* Y
*
* Previous frame Y position for velocity calculation.
*/
previousY: number = 0;
/**
* X
*
* X component of velocity (units per second).
*/
velocityX: number = 0;
/**
* Y
*
* Y component of velocity (units per second).
*/
velocityY: number = 0;
}