Example Camera

This commit is contained in:
2026-06-01 23:04:55 -05:00
parent b14196ff0d
commit d73edb403f
11 changed files with 436 additions and 22 deletions
+129
View File
@@ -0,0 +1,129 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
// ---------------------------------------------------------------------------
// Component (generic base returned by entity.add() for untyped components)
// ---------------------------------------------------------------------------
/** Base component returned by entity.add() for component types without a specific module. */
interface Component {
/** Entity ID this component belongs to. */
readonly entity: number;
/** Component slot ID. */
readonly id: number;
toString(): string;
}
interface ComponentConstructor {
/** Sentinel value for an invalid component ID. */
readonly INVALID: number;
// Component type constants (generated from componentlist.h)
readonly POSITION: number;
readonly CAMERA: number;
readonly RENDERABLE: number;
readonly PHYSICS: number;
readonly TRIGGER: number;
readonly OVERWORLD: number;
readonly PLAYER: number;
readonly INTERACTABLE: number;
readonly OVERWORLD_CAMERA: number;
readonly OVERWORLD_TRIGGER: number;
new(): never;
}
declare var Component: ComponentConstructor;
// ---------------------------------------------------------------------------
// Position
// ---------------------------------------------------------------------------
/** Position/rotation/scale transform component with optional parent hierarchy. */
interface Position extends Component {
/**
* Local-space position. Assigning a Vec3 writes to the C transform and
* marks the world transform dirty. Reading returns a fresh Vec3 copy.
*/
localPosition: Vec3;
/** World-space position (accounts for all parent transforms). */
worldPosition: Vec3;
/** Local-space euler rotation in radians (XYZ). */
localRotation: Vec3;
/** World-space euler rotation in radians. */
worldRotation: Vec3;
/** Local-space scale. */
localScale: Vec3;
/** World-space scale. */
worldScale: Vec3;
/**
* Orients the transform to look at a world-space target point.
* Uses the current local position as the eye. Optionally specify an up
* vector (defaults to Y-up).
*/
lookAt(target: Vec3, up?: Vec3): void;
/**
* Sets this component's parent in the transform hierarchy.
* Pass `null` or `undefined` to detach.
*/
setParent(parent: Position | null | undefined): void;
toString(): string;
}
interface PositionConstructor {
new(): never;
}
declare var Position: PositionConstructor;
// ---------------------------------------------------------------------------
// Camera
// ---------------------------------------------------------------------------
/** Camera projection component. */
interface Camera extends Component {
/** Field of view in radians (perspective projections only). */
fov: number;
/** Near clip plane distance. */
nearClip: number;
/** Far clip plane distance. */
farClip: number;
/** Projection type — one of the Camera.PERSPECTIVE / Camera.ORTHOGRAPHIC constants. */
projType: number;
toString(): string;
}
interface CameraConstructor {
readonly PERSPECTIVE: number;
readonly PERSPECTIVE_FLIPPED: number;
readonly ORTHOGRAPHIC: number;
new(): never;
}
declare var Camera: CameraConstructor;
// ---------------------------------------------------------------------------
// Entity
// ---------------------------------------------------------------------------
interface Entity {
/** Add a component of the given type and return a typed instance. */
add(type: CameraConstructor["PERSPECTIVE"] | number): Component;
toString(): string;
}
interface EntityConstructor {
/** Sentinel value for an invalid entity ID. */
readonly INVALID: number;
/** Creates a new entity and returns it. Returns Entity.INVALID slot if the pool is full. */
create(): Entity;
/** Disposes the entity and all its components. */
dispose(entity: Entity): void;
new(): never;
}
declare var Entity: EntityConstructor;
+3
View File
@@ -19,3 +19,6 @@
/// <reference path="./engine.d.ts" />
/// <reference path="./input.d.ts" />
/// <reference path="./system.d.ts" />
/// <reference path="./vec3.d.ts" />
/// <reference path="./entity.d.ts" />
/// <reference path="./scene.d.ts" />
+30
View File
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** Scene management — request scene transitions and query the active scene. */
interface SceneNamespace {
/** The type constant of the currently active scene, or 0 if none. */
readonly current: number;
/**
* Requests a scene transition. The change takes effect at the start of the
* next safe update tick (current scene is disposed, new scene is initialized).
*
* @param type - A `Scene.*` scene type constant.
*
* @example
* Scene.set(Scene.OVERWORLD);
*/
set(type: number): void;
// Scene type constants (generated from scenelist.h)
readonly INITIAL: number;
readonly TEST: number;
readonly OVERWORLD: number;
}
declare var Scene: SceneNamespace;
+15
View File
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/** A three-component float vector (x, y, z). */
declare class Vec3 {
constructor(x?: number, y?: number, z?: number);
x: number;
y: number;
z: number;
toString(): string;
}