A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat: Add ECS-style App framework with TypeScript bindings
esenginea59c8a1d26dc
diff --git a/CMakeLists.txt b/CMakeLists.txtindex a95811a88..a6737d8bf 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -38,6 +38,7 @@ set(ESENGINE_SOURCESsrc/esengine/core/Application.cppsrc/esengine/core/Engine.cppsrc/esengine/core/Log.cpp+ src/esengine/app/App.cppsrc/esengine/resource/ResourceManager.cppsrc/esengine/resource/ShaderParser.cppsrc/esengine/resource/LoaderJobQueue.cpp@@ -341,7 +342,10 @@ esengine_set_strict_warnings(esengine)if(ES_BUILD_WEB OR ES_BUILD_WXGAME)add_executable(esengine_sdk src/esengine/bindings/WebSDKEntry.cpp)- target_link_libraries(esengine_sdk PRIVATE esengine)+ # Use --whole-archive to force link entire engine (prevent dead code elimination)+ target_link_libraries(esengine_sdk PRIVATE+ -Wl,--whole-archive esengine -Wl,--no-whole-archive+ )es_apply_sdk_settings(esengine_sdk)set_target_properties(esengine_sdk PROPERTIESdiff --git a/bindings/App.ts b/bindings/App.tsnew file mode 100644index 000000000..27d8b2d39--- /dev/null+++ b/bindings/App.ts@@ -0,0 +1,513 @@+/**+ * @file App.ts+ * @brief Type-safe ECS Application wrapper for TypeScript+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++import type {+ ESEngineModule,+ Registry,+ NativeApp,+ EntityVector,+ Entity,+ LocalTransform as ILocalTransform,+ WorldTransform as IWorldTransform,+ Sprite as ISprite,+ Camera as ICamera,+ Canvas as ICanvas,+ Velocity as IVelocity,+ Parent as IParent,+ Children as IChildren+} from './esengine';++// =============================================================================+// Component Classes+// =============================================================================++export class LocalTransform {+ static readonly componentName = 'LocalTransform';+ position = { x: 0, y: 0, z: 0 };+ rotation = { w: 1, x: 0, y: 0, z: 0 };+ scale = { x: 1, y: 1, z: 1 };+}++export class WorldTransform {+ static readonly componentName = 'WorldTransform';+ matrix: number[] = [];+ position = { x: 0, y: 0, z: 0 };+ rotation = { w: 1, x: 0, y: 0, z: 0 };+ scale = { x: 1, y: 1, z: 1 };+}++export class Sprite {+ static readonly componentName = 'Sprite';+ texture = 0;+ color = { x: 1, y: 1, z: 1, w: 1 };+ size = { x: 32, y: 32 };+ uvOffset = { x: 0, y: 0 };+ uvScale = { x: 1, y: 1 };+ layer = 0;+ flipX = false;+ flipY = false;+}++export class Camera {+ static readonly componentName = 'Camera';+ projectionType = 0;+ fov = 60;+ orthoSize = 5;+ nearPlane = 0.1;+ farPlane = 1000;+ aspectRatio = 1.77;+ isActive = true;+ priority = 0;+}++export class Canvas {+ static readonly componentName = 'Canvas';+ designResolution = { x: 1920, y: 1080 };+ pixelsPerUnit = 100;+ scaleMode = 0;+ matchWidthOrHeight = 0.5;+ backgroundColor = { x: 0, y: 0, z: 0, w: 1 };+}++export class Velocity {+ static readonly componentName = 'Velocity';+ linear = { x: 0, y: 0, z: 0 };+ angular = { x: 0, y: 0, z: 0 };+}++export class Parent {+ static readonly componentName = 'Parent';+ entity = 0;+}++export class Children {+ static readonly componentName = 'Children';+ entities: Entity[] = [];+}++// =============================================================================+// Component Type Utilities+// =============================================================================++type ComponentClass<T = unknown> = {+ new(): T;+ readonly componentName: string;+};++type InstanceOf<T> = T extends ComponentClass<infer I> ? I : never;++type ComponentInstances<T extends ComponentClass[]> = {+ [K in keyof T]: InstanceOf<T[K]>;+};++// =============================================================================+// Schedule+// =============================================================================++export enum Schedule {+ Startup = 0,+ PreUpdate = 1,+ Update = 2,+ PostUpdate = 3,+ PreRender = 4,+ Render = 5,+ PostRender = 6,+}++// =============================================================================+// Time+// =============================================================================++export interface Time {+ readonly delta: number;+ readonly elapsed: number;+ readonly frameCount: number;+}++// =============================================================================+// Query+// =============================================================================++export class Query<T extends ComponentClass[]> {+ private readonly module_: ESEngineModule;+ private readonly registry_: Registry;+ private readonly components_: T;++ constructor(module: ESEngineModule, registry: Registry, components: T) {+ this.module_ = module;+ this.registry_ = registry;+ this.components_ = components;+ }++ *[Symbol.iterator](): Iterator<[Entity, ...ComponentInstances<T>]> {+ const entities = this.getEntities();++ for (const entity of entities) {+ const components = this.components_.map(C =>+ this.getComponent(entity, C.componentName)+ ) as ComponentInstances<T>;+ yield [entity, ...components];+ }+ }++ forEach(callback: (entity: Entity, ...components: ComponentInstances<T>) => void): void {+ for (const [entity, ...components] of this) {+ callback(entity, ...components);+ }+ }++ single(): [Entity, ...ComponentInstances<T>] | null {+ for (const result of this) {+ return result;+ }+ return null;+ }++ isEmpty(): boolean {+ return this.single() === null;+ }++ private getEntities(): Entity[] {+ const names = this.components_.map(C => C.componentName).join('');+ const queryName = `query${names}`;+ const queryFn = this.module_[queryName] as+ ((registry: Registry) => EntityVector) | undefined;++ if (typeof queryFn === 'function') {+ const entityVector = queryFn(this.registry_);+ const result: Entity[] = [];+ const size = entityVector.size();+ for (let i = 0; i < size; i++) {+ result.push(entityVector.get(i));+ }+ return result;+ }+ return [];+ }++ private getComponent(entity: Entity, name: string): unknown {+ const getter = `get${name}`;+ const getterFn = this.registry_[getter] as (entity: Entity) => unknown;+ return getterFn.call(this.registry_, entity);+ }+}++// =============================================================================+// Resources+// =============================================================================++export class Res<T> {+ constructor(private readonly value_: T) {}++ get(): T {+ return this.value_;+ }+}++export class ResMut<T> {+ constructor(private value_: T) {}++ get(): T {+ return this.value_;+ }++ set(value: T): void {+ this.value_ = value;+ }+}++// =============================================================================+// Entity Builder+// =============================================================================++export class EntityBuilder {+ private readonly registry_: Registry;+ private readonly entity_: Entity;++ constructor(registry: Registry) {+ this.registry_ = registry;+ this.entity_ = registry.create();+ }++ with<T extends ComponentClass>(Component: T, data: Partial<InstanceOf<T>>): this {+ const name = Component.componentName;+ const defaults = new Component();+ const component = Object.assign({}, defaults, data);+ const adder = `add${name}`;+ const addFn = this.registry_[adder] as (entity: Entity, component: unknown) => void;+ addFn.call(this.registry_, this.entity_, component);+ return this;+ }++ id(): Entity {+ return this.entity_;+ }+}++// =============================================================================+// Commands+// =============================================================================++export class Commands {+ private readonly registry_: Registry;+ private readonly pendingDespawns_: Entity[] = [];++ constructor(registry: Registry) {+ this.registry_ = registry;+ }++ spawn(): EntityBuilder {+ return new EntityBuilder(this.registry_);+ }++ despawn(entity: Entity): void {+ this.pendingDespawns_.push(entity);+ }++ insert<T extends ComponentClass>(entity: Entity, Component: T, data: Partial<InstanceOf<T>>): void {+ const name = Component.componentName;+ const defaults = new Component();+ const component = Object.assign({}, defaults, data);+ const adder = `add${name}`;+ const addFn = this.registry_[adder] as (entity: Entity, component: unknown) => void;+ addFn.call(this.registry_, entity, component);+ }++ remove<T extends ComponentClass>(entity: Entity, Component: T): void {+ const name = Component.componentName;+ const remover = `remove${name}`;+ const removeFn = this.registry_[remover] as (entity: Entity) => void;+ removeFn.call(this.registry_, entity);+ }++ has<T extends ComponentClass>(entity: Entity, Component: T): boolean {+ const name = Component.componentName;+ const checker = `has${name}`;+ const hasFn = this.registry_[checker] as (entity: Entity) => boolean;+ return hasFn.call(this.registry_, entity);+ }++ get<T extends ComponentClass>(entity: Entity, Component: T): InstanceOf<T> {+ const name = Component.componentName;+ const getter = `get${name}`;+ const getFn = this.registry_[getter] as (entity: Entity) => InstanceOf<T>;+ return getFn.call(this.registry_, entity);+ }++ flush(): void {+ for (const entity of this.pendingDespawns_) {+ this.registry_.destroy(entity);+ }+ this.pendingDespawns_.length = 0;+ }+}++// =============================================================================+// World+// =============================================================================++export class World {+ private readonly module_: ESEngineModule;+ private readonly registry_: Registry;++ constructor(module: ESEngineModule, registry: Registry) {+ this.module_ = module;+ this.registry_ = registry;+ }++ query<T extends ComponentClass[]>(...components: T): Query<T> {+ return new Query(this.module_, this.registry_, components);+ }++ spawn(): EntityBuilder {+ return new EntityBuilder(this.registry_);+ }++ commands(): Commands {+ return new Commands(this.registry_);+ }++ get<T extends ComponentClass>(entity: Entity, Component: T): InstanceOf<T> {+ const name = Component.componentName;+ const getter = `get${name}`;+ const getFn = this.registry_[getter] as (entity: Entity) => InstanceOf<T>;+ return getFn.call(this.registry_, entity);+ }++ has<T extends ComponentClass>(entity: Entity, Component: T): boolean {+ const name = Component.componentName;+ const checker = `has${name}`;+ const hasFn = this.registry_[checker] as (entity: Entity) => boolean;+ return hasFn.call(this.registry_, entity);+ }+}++// =============================================================================+// System Types+// =============================================================================++export type SystemFn = (world: World, time: Time) => void;++export abstract class System {+ protected world_!: World;+ protected time_!: Time;++ onStart?(): void;+ onUpdate?(): void;+ onDestroy?(): void;++ /** @internal */+ _bind(world: World, time: Time): void {+ this.world_ = world;+ this.time_ = time;+ }+}++export abstract class StartupSystem extends System {+ abstract onStart(): void;+}++export abstract class UpdateSystem extends System {+ abstract onUpdate(): void;+}++// =============================================================================+// App Config+// =============================================================================++export interface AppConfig {+ title?: string;+ width?: number;+ height?: number;+ vsync?: boolean;+}++// =============================================================================+// App+// =============================================================================++interface ModuleWithCallback extends ESEngineModule {+ _esRunJSSystems?: (schedule: number, dt: number) => void;+}++type SystemEntry = SystemFn | System;++export class App {+ private readonly module_: ESEngineModule;+ private readonly cppApp_: NativeApp;+ private readonly systems_ = new Map<Schedule, SystemEntry[]>();+ private readonly systemInstances_: System[] = [];+ private readonly resources_ = new Map<string, unknown>();++ constructor(module: ESEngineModule, config?: AppConfig) {+ this.module_ = module;++ if (config) {+ const cppConfig = new module.AppConfig();+ if (config.title) cppConfig.title = config.title;+ if (config.width) cppConfig.width = config.width;+ if (config.height) cppConfig.height = config.height;+ if (config.vsync !== undefined) cppConfig.vsync = config.vsync;+ this.cppApp_ = module.createAppWithConfig(cppConfig);+ } else {+ this.cppApp_ = module.createApp();+ }++ for (let i = 0; i <= Schedule.PostRender; i++) {+ this.systems_.set(i as Schedule, []);+ }++ (module as ModuleWithCallback)._esRunJSSystems = (schedule: number) => {+ this.runSystems(schedule as Schedule);+ };+ }++ addSystem(schedule: Schedule, system: SystemFn | System): this {+ const systems = this.systems_.get(schedule);+ if (systems) {+ systems.push(system);+ if (system instanceof System) {+ this.systemInstances_.push(system);+ }+ }+ return this;+ }++ addStartupSystem(system: SystemFn | StartupSystem): this {+ return this.addSystem(Schedule.Startup, system);+ }++ addUpdateSystem(system: SystemFn | UpdateSystem): this {+ return this.addSystem(Schedule.Update, system);+ }++ insertResource<T>(name: string, value: T): this {+ this.resources_.set(name, value);+ return this;+ }++ getResource<T>(name: string): T | undefined {+ return this.resources_.get(name) as T | undefined;+ }++ run(): void {+ this.cppApp_.run();+ }++ quit(): void {+ this.cppApp_.quit();+ }++ world(): World {+ return new World(this.module_, this.cppApp_.registry());+ }++ time(): Time {+ return this.cppApp_.time();+ }++ width(): number {+ return this.cppApp_.width();+ }++ height(): number {+ return this.cppApp_.height();+ }++ private runSystems(schedule: Schedule): void {+ const systems = this.systems_.get(schedule);+ if (!systems) return;++ const world = this.world();+ const time = this.time();++ for (const system of systems) {+ if (typeof system === 'function') {+ system(world, time);+ } else {+ system._bind(world, time);+ if (schedule === Schedule.Startup && system.onStart) {+ system.onStart();+ } else if (system.onUpdate) {+ system.onUpdate();+ }+ }+ }+ }+}++// =============================================================================+// Factory+// =============================================================================++export function createApp(module: ESEngineModule, config?: AppConfig): App {+ return new App(module, config);+}diff --git a/bindings/esengine.d.ts b/bindings/esengine.d.tsindex 71b6ab4ca..99ff3f5f7 100644--- a/bindings/esengine.d.ts+++ b/bindings/esengine.d.ts@@ -27,12 +27,29 @@ export interface UVec2 { x: number; y: number; }export interface Quat { w: number; x: number; y: number; z: number; }export type Mat4 = number[];+// =============================================================================+// Enums+// =============================================================================++export const enum ProjectionType {+ Perspective = 0,+ Orthographic = 1+}++export const enum CanvasScaleMode {+ FixedWidth = 0,+ FixedHeight = 1,+ Expand = 2,+ Shrink = 3,+ Match = 4+}+// =============================================================================// Components// =============================================================================export interface Camera {- projectionType: any;+ projectionType: ProjectionType;fov: number;orthoSize: number;nearPlane: number;@@ -45,7 +62,7 @@ export interface Camera {export interface Canvas {designResolution: UVec2;pixelsPerUnit: number;- scaleMode: any;+ scaleMode: CanvasScaleMode;matchWidthOrHeight: number;backgroundColor: Vec4;}@@ -55,10 +72,11 @@ export interface Parent {}export interface Children {+ entities: Entity[];}export interface Sprite {- texture: any;+ texture: number;color: Vec4;size: Vec2;uvOffset: Vec2;@@ -100,34 +118,109 @@ export interface Registry {getCamera(entity: Entity): Camera;addCamera(entity: Entity, component: Camera): void;removeCamera(entity: Entity): void;+hasCanvas(entity: Entity): boolean;getCanvas(entity: Entity): Canvas;addCanvas(entity: Entity, component: Canvas): void;removeCanvas(entity: Entity): void;+hasParent(entity: Entity): boolean;getParent(entity: Entity): Parent;addParent(entity: Entity, component: Parent): void;removeParent(entity: Entity): void;+hasChildren(entity: Entity): boolean;getChildren(entity: Entity): Children;addChildren(entity: Entity, component: Children): void;removeChildren(entity: Entity): void;+hasSprite(entity: Entity): boolean;getSprite(entity: Entity): Sprite;addSprite(entity: Entity, component: Sprite): void;removeSprite(entity: Entity): void;+hasLocalTransform(entity: Entity): boolean;getLocalTransform(entity: Entity): LocalTransform;addLocalTransform(entity: Entity, component: LocalTransform): void;removeLocalTransform(entity: Entity): void;+hasWorldTransform(entity: Entity): boolean;getWorldTransform(entity: Entity): WorldTransform;addWorldTransform(entity: Entity, component: WorldTransform): void;removeWorldTransform(entity: Entity): void;+hasVelocity(entity: Entity): boolean;getVelocity(entity: Entity): Velocity;addVelocity(entity: Entity, component: Velocity): void;removeVelocity(entity: Entity): void;++ [key: string]: unknown;+}++// =============================================================================+// Resource Types+// =============================================================================++export type ShaderHandle = number;+export type TextureHandle = number;++export const enum TextureFormat {+ RGB8 = 0,+ RGBA8 = 1+}++export interface ResourceManager {+ init(): void;+ shutdown(): void;+ createShader(vertSrc: string, fragSrc: string): ShaderHandle;+ createTexture(width: number, height: number, pixelsPtr: number, pixelsLen: number, format: TextureFormat): TextureHandle;+ releaseShader(handle: ShaderHandle): void;+ releaseTexture(handle: TextureHandle): void;+}++// =============================================================================+// App Types+// =============================================================================++export const enum Schedule {+ Startup = 0,+ PreUpdate = 1,+ Update = 2,+ PostUpdate = 3,+ PreRender = 4,+ Render = 5,+ PostRender = 6,+}++export interface Time {+ delta: number;+ elapsed: number;+ frameCount: number;+}++export interface AppConfig {+ title: string;+ width: number;+ height: number;+ vsync: boolean;+}++export interface NativeApp {+ run(): void;+ quit(): void;+ registry(): Registry;+ time(): Time;+ width(): number;+ height(): number;+}++// =============================================================================+// Query Types+// =============================================================================++export interface EntityVector {+ size(): number;+ get(index: number): Entity;}// =============================================================================@@ -135,7 +228,9 @@ export interface Registry {// =============================================================================export interface ESEngineModule {- Registry: new () => Registry;+ ResourceManager: new () => ResourceManager;+ AppConfig: new () => AppConfig;+Camera: new () => Camera;Canvas: new () => Canvas;Parent: new () => Parent;@@ -144,6 +239,26 @@ export interface ESEngineModule {LocalTransform: new () => LocalTransform;WorldTransform: new () => WorldTransform;Velocity: new () => Velocity;++ Schedule: typeof Schedule;+ TextureFormat: typeof TextureFormat;+ ProjectionType: typeof ProjectionType;+ CanvasScaleMode: typeof CanvasScaleMode;++ createApp(): NativeApp;+ createAppWithConfig(config: AppConfig): NativeApp;+ getApp(): NativeApp;++ queryLocalTransform(registry: Registry): EntityVector;+ queryLocalTransformSprite(registry: Registry): EntityVector;++ HEAPU8: Uint8Array;+ _malloc(size: number): number;+ _free(ptr: number): void;++ _esRunJSSystems?: (schedule: number, dt: number) => void;++ [key: string]: unknown;}export default function createModule(): Promise<ESEngineModule>;diff --git a/bindings/example.ts b/bindings/example.tsnew file mode 100644index 000000000..dff857cd3--- /dev/null+++ b/bindings/example.ts@@ -0,0 +1,75 @@+/**+ * @file example.ts+ * @brief Example usage of ESEngine ECS API+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++import createModule from './esengine';+import {+ App,+ Schedule,+ StartupSystem,+ UpdateSystem,+ LocalTransform,+ Sprite+} from './App';++// =============================================================================+// Systems+// =============================================================================++class SpawnSystem extends StartupSystem {+ onStart(): void {+ this.world_.spawn()+ .with(LocalTransform, {+ position: { x: 400, y: 300, z: 0 }+ })+ .with(Sprite, {+ color: { x: 1, y: 0, z: 0, w: 1 },+ size: { x: 64, y: 64 }+ });+ }+}++class MovementSystem extends UpdateSystem {+ onUpdate(): void {+ for (const [_, transform] of this.world_.query(LocalTransform)) {+ transform.position.x += Math.sin(this.time_.elapsed * 2) * 50 * this.time_.delta;+ }+ }+}++class RenderSystem extends UpdateSystem {+ onUpdate(): void {+ for (const [entity, transform, sprite] of this.world_.query(LocalTransform, Sprite)) {+ console.log(`Entity ${entity}: pos=(${transform.position.x.toFixed(1)}, ${transform.position.y.toFixed(1)}), layer=${sprite.layer}`);+ }+ }+}++// =============================================================================+// Main+// =============================================================================++async function main(): Promise<void> {+ const module = await createModule();++ const app = new App(module, {+ title: 'ECS Example',+ width: 800,+ height: 600+ });++ app.addStartupSystem(new SpawnSystem())+ .addUpdateSystem(new MovementSystem())+ .addSystem(Schedule.Render, new RenderSystem());++ app.run();+}++main().catch(console.error);diff --git a/bindings/tsconfig.json b/bindings/tsconfig.jsonnew file mode 100644index 000000000..5ad6b3ace--- /dev/null+++ b/bindings/tsconfig.json@@ -0,0 +1,17 @@+{+ "compilerOptions": {+ "target": "ES2020",+ "module": "ESNext",+ "lib": ["ES2020", "DOM"],+ "moduleResolution": "node",+ "strict": true,+ "noEmit": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "forceConsistentCasingInFileNames": true,+ "declaration": true,+ "declarationMap": true+ },+ "include": ["*.ts"],+ "exclude": ["node_modules"]+}diff --git a/src/esengine/app/App.cpp b/src/esengine/app/App.cppnew file mode 100644index 000000000..d9df982fe--- /dev/null+++ b/src/esengine/app/App.cpp@@ -0,0 +1,197 @@+/**+ * @file App.cpp+ * @brief ECS-style application framework implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "App.hpp"+#include "../core/Log.hpp"+#include "../renderer/RenderPipeline.hpp"++#ifdef ES_PLATFORM_WEB+#include <emscripten.h>+#include <emscripten/html5.h>+#endif++namespace esengine {++App* App::instance_ = nullptr;++// =============================================================================+// Constructor / Destructor+// =============================================================================++App::App() : App(AppConfig{}) {}++App::App(const AppConfig& config) : config_(config) {+ ES_ASSERT(instance_ == nullptr, "Only one App instance allowed");+ instance_ = this;+}++App::~App() {+ if (initialized_) {+ shutdown();+ }+ instance_ = nullptr;+}++// =============================================================================+// Builder Methods+// =============================================================================++App& App::setConfig(const AppConfig& config) {+ config_ = config;+ return *this;+}++App& App::addPlugin(Unique<Plugin> plugin) {+ plugins_.push_back(std::move(plugin));+ return *this;+}++App& App::addSystem(Schedule schedule, SystemFn system) {+ systems_[static_cast<usize>(schedule)].push_back(std::move(system));+ return *this;+}++App& App::addStartupSystem(SystemFn system) {+ return addSystem(Schedule::Startup, std::move(system));+}++// =============================================================================+// Lifecycle+// =============================================================================++void App::init() {+ if (initialized_) return;++ ES_LOG_INFO("App initializing...");++ platform_ = Platform::create();+ platform_->initialize(config_.width, config_.height);++ resourceManager_.init();++ renderContext_ = makeUnique<RenderContext>();+ renderContext_->init();++ renderer_ = makeUnique<Renderer>(*renderContext_);++ for (auto& plugin : plugins_) {+ plugin->build(*this);+ }++ initialized_ = true;+ ES_LOG_INFO("App initialized");+}++void App::shutdown() {+ if (!initialized_) return;++ ES_LOG_INFO("App shutting down...");++ renderer_.reset();++ renderContext_->shutdown();+ renderContext_.reset();++ resourceManager_.shutdown();++ platform_->shutdown();+ platform_.reset();++ initialized_ = false;+ ES_LOG_INFO("App shutdown complete");+}++void App::run() {+ init();+ running_ = true;++#ifdef ES_PLATFORM_WEB+ emscripten_set_main_loop_arg(+ [](void* arg) {+ static_cast<App*>(arg)->runFrame();+ },+ this, 0, 1);+#else+ while (running_) {+ runFrame();+ }+ shutdown();+#endif+}++void App::quit() {+ running_ = false;+#ifdef ES_PLATFORM_WEB+ emscripten_cancel_main_loop();+#endif+}++void App::runFrame() {+ static f64 lastTime = 0.0;+ f64 currentTime = platform_->getTime();+ f32 dt = static_cast<f32>(currentTime - lastTime);+ lastTime = currentTime;++ if (dt > 0.1f) dt = 0.1f;++ time_.delta = dt;+ time_.elapsed += dt;+ time_.frameCount++;++ platform_->pollEvents();+ input_.update();++ if (!startupRan_) {+ runSystems(Schedule::Startup);+#ifdef ES_PLATFORM_WEB+ runJSSystems(Schedule::Startup, dt);+#endif+ startupRan_ = true;+ }++ runSystems(Schedule::PreUpdate);++#ifdef ES_PLATFORM_WEB+ runJSSystems(Schedule::Update, dt);+#endif++ runSystems(Schedule::Update);+ runSystems(Schedule::PostUpdate);++ renderer_->beginFrame();+ runSystems(Schedule::PreRender);+ runSystems(Schedule::Render);+ runSystems(Schedule::PostRender);+ renderer_->endFrame();++ platform_->swapBuffers();+}++void App::runSystems(Schedule schedule) {+ auto& systems = systems_[static_cast<usize>(schedule)];+ for (auto& system : systems) {+ system(registry_, time_.delta);+ }+}++#ifdef ES_PLATFORM_WEB+EM_JS(void, es_call_js_systems, (int schedule, float dt), {+ if (Module._esRunJSSystems) {+ Module._esRunJSSystems(schedule, dt);+ }+});++void App::runJSSystems(Schedule schedule, f32 dt) {+ es_call_js_systems(static_cast<int>(schedule), dt);+}+#endif++} // namespace esenginediff --git a/src/esengine/app/App.hpp b/src/esengine/app/App.hppnew file mode 100644index 000000000..2f129c9d4--- /dev/null+++ b/src/esengine/app/App.hpp@@ -0,0 +1,161 @@+/**+ * @file App.hpp+ * @brief ECS-style application framework+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++#include "Schedule.hpp"+#include "../core/Types.hpp"+#include "../ecs/Registry.hpp"+#include "../platform/Platform.hpp"+#include "../platform/input/Input.hpp"+#include "../resource/ResourceManager.hpp"+#include "../renderer/RenderContext.hpp"+#include "../renderer/Renderer.hpp"++#include <functional>+#include <string>+#include <vector>++namespace esengine {++// =============================================================================+// Forward Declarations+// =============================================================================++class App;+class Plugin;++// =============================================================================+// Type Aliases+// =============================================================================++using SystemFn = std::function<void(ecs::Registry&, f32)>;++// =============================================================================+// App Configuration+// =============================================================================++struct AppConfig {+ std::string title = "ESEngine";+ u32 width = 800;+ u32 height = 600;+ bool vsync = true;+};++// =============================================================================+// Resources (Global Singletons)+// =============================================================================++struct Time {+ f32 delta = 0.0f;+ f32 elapsed = 0.0f;+ u64 frameCount = 0;+};++// =============================================================================+// Plugin Interface+// =============================================================================++class Plugin {+public:+ virtual ~Plugin() = default;+ virtual void build(App& app) = 0;+};++// =============================================================================+// App Class+// =============================================================================++class App {+public:+ App();+ explicit App(const AppConfig& config);+ ~App();++ App(const App&) = delete;+ App& operator=(const App&) = delete;++ // =========================================================================+ // Builder Pattern+ // =========================================================================++ App& setConfig(const AppConfig& config);+ App& addPlugin(Unique<Plugin> plugin);++ template<typename T, typename... Args>+ App& addPlugin(Args&&... args) {+ return addPlugin(makeUnique<T>(std::forward<Args>(args)...));+ }++ App& addSystem(Schedule schedule, SystemFn system);+ App& addStartupSystem(SystemFn system);++ // =========================================================================+ // Lifecycle+ // =========================================================================++ void run();+ void quit();++ // =========================================================================+ // Accessors+ // =========================================================================++ ecs::Registry& registry() { return registry_; }+ const ecs::Registry& registry() const { return registry_; }++ resource::ResourceManager& resources() { return resourceManager_; }+ Input& input() { return input_; }+ const Time& time() const { return time_; }+ Renderer& renderer() { return *renderer_; }+ RenderContext& renderContext() { return *renderContext_; }++ u32 width() const { return config_.width; }+ u32 height() const { return config_.height; }++ static App& get() { return *instance_; }++ // =========================================================================+ // JS Interop (Web platform)+ // =========================================================================++#ifdef ES_PLATFORM_WEB+ void runJSSystems(Schedule schedule, f32 dt);+#endif++private:+ void init();+ void runFrame();+ void shutdown();++ void runSystems(Schedule schedule);++ AppConfig config_;++ Unique<Platform> platform_;+ Input input_;+ ecs::Registry registry_;+ resource::ResourceManager resourceManager_;+ Unique<RenderContext> renderContext_;+ Unique<Renderer> renderer_;++ Time time_;++ std::vector<Unique<Plugin>> plugins_;+ std::vector<SystemFn> systems_[SCHEDULE_COUNT];++ bool running_ = false;+ bool initialized_ = false;+ bool startupRan_ = false;++ static App* instance_;+};++} // namespace esenginediff --git a/src/esengine/app/Schedule.hpp b/src/esengine/app/Schedule.hppnew file mode 100644index 000000000..902a800b2--- /dev/null+++ b/src/esengine/app/Schedule.hpp@@ -0,0 +1,34 @@+/**+ * @file Schedule.hpp+ * @brief System execution schedule phases+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++#include "../core/Types.hpp"++namespace esengine {++/**+ * @brief Execution phases for systems+ */+enum class Schedule : u8 {+ Startup, ///< Run once at application start+ PreUpdate, ///< Before main update (input processing)+ Update, ///< Main game logic+ PostUpdate, ///< After update (physics, collision response)+ PreRender, ///< Before rendering (culling, sorting)+ Render, ///< Rendering+ PostRender, ///< After rendering (debug overlays)++ Count+};++constexpr usize SCHEDULE_COUNT = static_cast<usize>(Schedule::Count);++} // namespace esenginediff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex f6ed03b47..27fb6af6b 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -15,6 +15,11 @@#include <emscripten/bind.h>#include "../ecs/Registry.hpp"#include "../math/Math.hpp"+#include "../resource/ResourceManager.hpp"+#include "../renderer/Texture.hpp"+#include "../renderer/Shader.hpp"+#include "../app/App.hpp"+#include "../app/Schedule.hpp"#include "../ecs/components/Camera.hpp"#include "../ecs/components/Canvas.hpp"@@ -27,6 +32,23 @@ using namespace emscripten;using namespace esengine;using namespace esengine::ecs;+// =============================================================================+// Enums+// =============================================================================++EMSCRIPTEN_BINDINGS(esengine_enums) {+ enum_<esengine::ecs::ProjectionType>("ProjectionType")+ .value("Perspective", esengine::ecs::ProjectionType::Perspective)+ .value("Orthographic", esengine::ecs::ProjectionType::Orthographic);++ enum_<esengine::ecs::CanvasScaleMode>("CanvasScaleMode")+ .value("FixedWidth", esengine::ecs::CanvasScaleMode::FixedWidth)+ .value("FixedHeight", esengine::ecs::CanvasScaleMode::FixedHeight)+ .value("Expand", esengine::ecs::CanvasScaleMode::Expand)+ .value("Shrink", esengine::ecs::CanvasScaleMode::Shrink)+ .value("Match", esengine::ecs::CanvasScaleMode::Match);+}+// =============================================================================// Math Types// =============================================================================@@ -123,7 +145,6 @@ EMSCRIPTEN_BINDINGS(esengine_components) {EMSCRIPTEN_BINDINGS(esengine_registry) {class_<Registry>("Registry")- .constructor<>().function("create", optional_override([](Registry& r) {return static_cast<u32>(r.create());}))@@ -250,4 +271,117 @@ EMSCRIPTEN_BINDINGS(esengine_registry) {;}+// =============================================================================+// Resource Manager+// =============================================================================++EMSCRIPTEN_BINDINGS(esengine_resources) {+ using namespace esengine::resource;++ class_<ResourceManager>("ResourceManager")+ .constructor<>()+ .function("init", &ResourceManager::init)+ .function("shutdown", &ResourceManager::shutdown)+ .function("createShader", optional_override([](ResourceManager& rm,+ const std::string& vertSrc, const std::string& fragSrc) -> u32 {+ return rm.createShader(vertSrc, fragSrc).id();+ }))+ .function("createTexture", optional_override([](ResourceManager& rm,+ u32 width, u32 height, uintptr_t pixelsPtr, usize pixelsLen, int format) -> u32 {+ const u8* pixels = reinterpret_cast<const u8*>(pixelsPtr);+ ConstSpan<u8> span(pixels, pixelsLen);+ return rm.createTexture(width, height, span,+ static_cast<TextureFormat>(format)).id();+ }))+ .function("releaseShader", optional_override([](ResourceManager& rm, u32 handle) {+ rm.releaseShader(ShaderHandle(handle));+ }))+ .function("releaseTexture", optional_override([](ResourceManager& rm, u32 handle) {+ rm.releaseTexture(TextureHandle(handle));+ }));++ enum_<TextureFormat>("TextureFormat")+ .value("RGB8", TextureFormat::RGB8)+ .value("RGBA8", TextureFormat::RGBA8);+}++// =============================================================================+// App+// =============================================================================++EMSCRIPTEN_BINDINGS(esengine_app) {+ enum_<Schedule>("Schedule")+ .value("Startup", Schedule::Startup)+ .value("PreUpdate", Schedule::PreUpdate)+ .value("Update", Schedule::Update)+ .value("PostUpdate", Schedule::PostUpdate)+ .value("PreRender", Schedule::PreRender)+ .value("Render", Schedule::Render)+ .value("PostRender", Schedule::PostRender);++ value_object<Time>("Time")+ .field("delta", &Time::delta)+ .field("elapsed", &Time::elapsed)+ .field("frameCount", &Time::frameCount);++ value_object<AppConfig>("AppConfig")+ .field("title", &AppConfig::title)+ .field("width", &AppConfig::width)+ .field("height", &AppConfig::height)+ .field("vsync", &AppConfig::vsync);++ class_<App>("App")+ .function("run", &App::run)+ .function("quit", &App::quit)+ .function("registry", optional_override([](App& app) -> Registry* {+ return &app.registry();+ }), allow_raw_pointers())+ .function("time", &App::time)+ .function("width", &App::width)+ .function("height", &App::height);++ function("createApp", optional_override([]() -> App* {+ static App app;+ return &app;+ }), allow_raw_pointers());++ function("createAppWithConfig", optional_override([](const AppConfig& config) -> App* {+ static App app(config);+ return &app;+ }), allow_raw_pointers());++ function("getApp", optional_override([]() -> App* {+ return &App::get();+ }), allow_raw_pointers());+}++// =============================================================================+// View Iterator for Query+// =============================================================================++EMSCRIPTEN_BINDINGS(esengine_query) {+ class_<std::vector<u32>>("EntityVector")+ .constructor<>()+ .function("size", &std::vector<u32>::size)+ .function("get", optional_override([](const std::vector<u32>& v, usize i) {+ return v[i];+ }));++ function("queryLocalTransformSprite", optional_override([](Registry& reg) {+ std::vector<u32> entities;+ reg.each<LocalTransform, Sprite>([&entities](Entity e, LocalTransform&, Sprite&) {+ entities.push_back(static_cast<u32>(e));+ });+ return entities;+ }));++ function("queryLocalTransform", optional_override([](Registry& reg) {+ std::vector<u32> entities;+ reg.each<LocalTransform>([&entities](Entity e, LocalTransform&) {+ entities.push_back(static_cast<u32>(e));+ });+ return entities;+ }));+}+#endif // ES_PLATFORM_WEB