TypeEngine
The TypeEngine serves as the central coordinator and main entry point for the entire game engine. It manages all sub-engines through dependency injection and orchestrates the game loop.
Purpose
The TypeEngine acts as the central coordinator that:
- Orchestrates sub-engines: Manages lifecycle of all specialized engines
- Coordinates game loop: Handles the main update cycle and timing
- Manages dependency injection: Provides sub-engines with their required dependencies
- Handles scene transitions: Coordinates scene loading and switching
- Provides unified interface: Single entry point for game initialization and control
Architecture Role
Public Methods
Initialization
constructor(options: TypeEngineOptions)
Creates TypeEngine instance with configuration options including project path, rendering settings, and physics configuration.
Engine Lifecycle
async setup(): Promise<void>
Initializes all sub-engines and prepares the engine for operation. Must be called before starting the game loop.
async start(): Promise<void>
Starts the main game loop and begins engine operation.
stop(): void
Stops the game loop and engine operation.
Scene Management
async loadScene(sceneName: string): Promise<void>
Loads and transitions to a specified scene by name.
getCurrentScene(): Scene | null
Returns the currently active scene.
Update Loop
update(deltaTime: number): void
Main update method called each frame. Coordinates updates across all sub-engines in proper order.
Engine Access
getEngine<T>(engineName: string): T
Provides access to specific sub-engines for advanced usage.
Interaction with Sub-Engines
Dependency Injection
The TypeEngine creates and injects dependencies for all sub-engines:
// Example of dependency injection
const entityEngine = new EntityEngine({
engine: this, // Reference to TypeEngine
EventEngine: this.EventEngine
});
const renderEngine = new RenderEngine({
engine: this,
EventEngine: this.EventEngine,
width: options.render.width,
height: options.render.height
});
Update Coordination
TypeEngine coordinates the update cycle across all sub-engines:
- TimeEngine: Calculates delta time
- SystemEngine: Updates all game systems
- PhysicsEngine: Updates physics simulation (via PhysicsSystem)
- RenderEngine: Renders visual updates (via RenderPixiSystem)
- EventEngine: Processes queued events
Event Communication
All sub-engines communicate through the EventEngine, which TypeEngine manages:
// Sub-engines emit events
this.EventEngine.emit('entity:created', entityData);
// Other sub-engines listen for events
this.EventEngine.on('entity:created', this.handleEntityCreated);
Configuration
TypeEngine Options
interface TypeEngineOptions {
projectPath: string; // Path to game project files
render: {
width: number; // Render window width
height: number; // Render window height
htmlTagId?: string; // HTML element ID for rendering
};
physics?: {
gravity?: { // Physics world gravity
x: number;
y: number;
};
};
}
Usage Example
const engine = new TypeEngine({
projectPath: './game-project',
render: {
width: 1024,
height: 768,
htmlTagId: 'game-canvas'
},
physics: {
gravity: { x: 0, y: 0.8 }
}
});
await engine.setup();
await engine.start();
Game Loop Coordination
The TypeEngine manages the main game loop:
Performance Considerations
Efficient Coordination
- Single Update Call: Coordinates all sub-engines through single update cycle
- Dependency Injection: Eliminates singleton patterns and global state
- Event-Driven: Reduces coupling between sub-engines through events
Resource Management
- Centralized Initialization: All sub-engines initialized together
- Proper Cleanup: Handles cleanup of all sub-engines on shutdown
- Memory Efficiency: Manages object lifecycle across the entire engine
Integration Patterns
Game Application Integration
class Game {
private engine: TypeEngine;
async initialize() {
this.engine = new TypeEngine({
projectPath: './assets',
render: { width: 800, height: 600 }
});
await this.engine.setup();
await this.engine.start();
}
async loadLevel(levelName: string) {
await this.engine.loadScene(levelName);
}
}
Custom System Integration
// TypeEngine automatically loads and manages custom systems
// through SystemEngine based on system.manage.json configuration
Notes
- TypeEngine is the single entry point for the entire game engine
- All sub-engines receive TypeEngine reference for coordination
- Manages the complete engine lifecycle from initialization to shutdown
- Provides unified interface while maintaining separation of concerns
- Handles cross-engine communication through EventEngine
- Essential for proper dependency injection and engine coordination