Skip to content

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.

chore: remove dead code — Engine class, dead headers, orphan tools

esenginee6430d8c3a4e
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f70f52bc9..8a27030b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,6 @@ add_subdirectory(third_party)
# =============================================================================
set(ESENGINE_SOURCES
- src/esengine/core/Engine.cpp
src/esengine/core/EstellaContext.cpp
src/esengine/core/Log.cpp
src/esengine/resource/ResourceManager.cpp
@@ -111,7 +110,6 @@ endif()
set(ESENGINE_HEADERS
src/esengine/ESEngine.hpp
src/esengine/core/Types.hpp
- src/esengine/core/Engine.hpp
src/esengine/core/Log.hpp
src/esengine/core/Reflection.hpp
src/esengine/core/ServiceRegistry.hpp
@@ -135,7 +133,6 @@ set(ESENGINE_HEADERS
src/esengine/resource/Handle.hpp
src/esengine/resource/ResourcePool.hpp
src/esengine/resource/ResourceManager.hpp
- src/esengine/resource/Resource.hpp
src/esengine/renderer/RenderContext.hpp
src/esengine/renderer/Shader.hpp
src/esengine/renderer/Buffer.hpp
diff --git a/src/esengine/ESEngine.hpp b/src/esengine/ESEngine.hpp
index 3550e60f9..267f4bbae 100644
--- a/src/esengine/ESEngine.hpp
+++ b/src/esengine/ESEngine.hpp
@@ -20,7 +20,6 @@
// Core
#include "core/Types.hpp"
#include "core/Log.hpp"
-#include "core/Engine.hpp"
#include "core/EstellaContext.hpp"
// Math
diff --git a/src/esengine/core/Engine.cpp b/src/esengine/core/Engine.cpp
deleted file mode 100644
index df8575f6d..000000000
--- a/src/esengine/core/Engine.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * @file Engine.cpp
- * @brief Engine static utility implementation
- * @details Provides platform detection and GPU capability queries.
- *
- * @author ESEngine Team
- * @date 2025
- *
- * @copyright Copyright (c) 2025 ESEngine Team
- * Licensed under the MIT License.
- */
-
-#include "Engine.hpp"
-#include "Log.hpp"
-
-namespace esengine {
-
-const char* Engine::getPlatformName() {
-#ifdef ES_PLATFORM_WXGAME
- return "WeChat MiniGame";
-#else
- return "Web";
-#endif
-}
-
-bool Engine::isWebPlatform() {
- return true;
-}
-
-bool Engine::hasWebGL2() {
- return true; // WebGL2 is a hard requirement
-}
-
-} // namespace esengine
diff --git a/src/esengine/core/Engine.hpp b/src/esengine/core/Engine.hpp
deleted file mode 100644
index 3e46696c9..000000000
--- a/src/esengine/core/Engine.hpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * @file Engine.hpp
- * @brief Engine information and capabilities
- * @details Provides engine version information, platform detection,
- * and feature capability queries.
- *
- * @author ESEngine Team
- * @date 2025
- *
- * @copyright Copyright (c) 2025 ESEngine Team
- * Licensed under the MIT License.
- */
-#pragma once
-
-// =============================================================================
-// Includes
-// =============================================================================
-
-// Project includes
-#include "Types.hpp"
-
-// Standard library
-#include <string>
-
-namespace esengine {
-
-// =============================================================================
-// Engine Version
-// =============================================================================
-
-/**
- * @brief Engine version information
- *
- * @details Provides compile-time version constants and a utility
- * function for retrieving the version string.
- */
-struct EngineVersion {
- /** @brief Major version number (breaking changes) */
- static constexpr u32 MAJOR = 0;
- /** @brief Minor version number (new features) */
- static constexpr u32 MINOR = 1;
- /** @brief Patch version number (bug fixes) */
- static constexpr u32 PATCH = 0;
-
- /**
- * @brief Gets the version as a string
- * @return Version in "MAJOR.MINOR.PATCH" format
- */
- static std::string toString() {
- return std::to_string(MAJOR) + "." +
- std::to_string(MINOR) + "." +
- std::to_string(PATCH);
- }
-};
-
-// =============================================================================
-// Engine Class
-// =============================================================================
-
-/**
- * @brief Global engine information and capability queries
- *
- * @details Provides static methods for querying engine metadata,
- * platform information, and graphics capabilities.
- *
- * @code
- * std::cout << Engine::getName() << " v" << Engine::getVersion() << std::endl;
- *
- * if (Engine::isWebPlatform()) {
- * // Web-specific code
- * }
- *
- * if (Engine::hasWebGL2()) {
- * // Use WebGL 2 features
- * }
- * @endcode
- */
-class Engine {
-public:
- // =========================================================================
- // Engine Information
- // =========================================================================
-
- /**
- * @brief Gets the engine name
- * @return "ESEngine"
- */
- static const char* getName() { return "ESEngine"; }
-
- /**
- * @brief Gets the engine version string
- * @return Version in "MAJOR.MINOR.PATCH" format
- */
- static std::string getVersion() { return EngineVersion::toString(); }
-
- // =========================================================================
- // Platform Information
- // =========================================================================
-
- /**
- * @brief Gets the current platform name
- * @return Platform identifier (e.g., "Web", "Windows", "Linux")
- */
- static const char* getPlatformName();
-
- /**
- * @brief Checks if running on a web platform
- * @return True if ES_PLATFORM_WEB is defined
- */
- static bool isWebPlatform();
-
- // =========================================================================
- // Capability Queries
- // =========================================================================
-
- /**
- * @brief Checks if WebGL 2.0 is available
- * @return True if WebGL 2.0 context is active
- *
- * @note Only meaningful on web platforms.
- */
- static bool hasWebGL2();
-
- Engine() = delete;
-};
-
-} // namespace esengine
diff --git a/src/esengine/renderer/TextureSlotAllocator.hpp b/src/esengine/renderer/TextureSlotAllocator.hpp
deleted file mode 100644
index 10d78a504..000000000
--- a/src/esengine/renderer/TextureSlotAllocator.hpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#pragma once
-
-#include "../core/Types.hpp"
-#include "GfxDevice.hpp"
-
-#include <array>
-
-namespace esengine {
-
-template<u32 MaxSlots>
-class TextureSlotAllocator {
-public:
- void init(u32 whiteTextureId) {
- white_texture_id_ = whiteTextureId;
- reset();
- }
-
- void reset() {
- for (u32 i = 0; i < MaxSlots; ++i) {
- slots_[i] = white_texture_id_;
- }
- slot_count_ = 1;
- }
-
- f32 findOrAllocate(u32 textureId) {
- if (textureId == 0) {
- return 0.0f;
- }
- for (u32 i = 0; i < slot_count_; ++i) {
- if (slots_[i] == textureId) {
- return static_cast<f32>(i);
- }
- }
- if (slot_count_ >= MaxSlots) {
- return -1.0f;
- }
- slots_[slot_count_] = textureId;
- return static_cast<f32>(slot_count_++);
- }
-
- bool isFull() const {
- return slot_count_ >= MaxSlots;
- }
-
- void bindAll(GfxDevice& device) const {
- for (u32 i = 0; i < slot_count_; ++i) {
- device.bindTexture(i, slots_[i]);
- }
- }
-
- u32 slotCount() const { return slot_count_; }
-
-private:
- std::array<u32, MaxSlots> slots_{};
- u32 slot_count_ = 1;
- u32 white_texture_id_ = 0;
-};
-
-} // namespace esengine
diff --git a/src/esengine/resource/Resource.hpp b/src/esengine/resource/Resource.hpp
deleted file mode 100644
index 77a1a8763..000000000
--- a/src/esengine/resource/Resource.hpp
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- * @file Resource.hpp
- * @brief Aggregate header for resource management system
- *
- * @author ESEngine Team
- * @date 2026
- *
- * @copyright Copyright (c) 2026 ESEngine Team
- * Licensed under the MIT License.
- */
-#pragma once
-
-#include "Handle.hpp"
-#include "ResourcePool.hpp"
-#include "ResourceManager.hpp"
diff --git a/tools/bundle-playable.js b/tools/bundle-playable.js
deleted file mode 100644
index f666828af..000000000
--- a/tools/bundle-playable.js
+++ /dev/null
@@ -1,205 +0,0 @@
-#!/usr/bin/env node
-/**
- * Bundle ESEngine game into a single HTML file for playable ads.
- *
- * Usage:
- * node tools/bundle-playable.js --wasm build-web-single/sdk/esengine.single.js \
- * --game sdk/examples/playground/build/playable/game.js \
- * --assets sdk/examples/playground/assets \
- * --output playable.html
- */
-
-const fs = require('fs');
-const path = require('path');
-
-const MIME_TYPES = {
- '.png': 'image/png',
- '.jpg': 'image/jpeg',
- '.jpeg': 'image/jpeg',
- '.gif': 'image/gif',
- '.webp': 'image/webp',
- '.svg': 'image/svg+xml',
-};
-
-const HTML_TEMPLATE = `<!DOCTYPE html>
-<html lang="en">
-<head>
-<meta charset="UTF-8">
-<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
-<meta name="ad.size" content="width=320,height=480">
-<title>Playable</title>
-<style>
-*{margin:0;padding:0;box-sizing:border-box}
-html,body{width:100%;height:100%;overflow:hidden;background:#000}
-#canvas{display:block;width:100%;height:100%;touch-action:none}
-</style>
-</head>
-<body>
-<canvas id="canvas"></canvas>
-<script>
-{{WASM_SDK}}
-</script>
-<script>
-{{GAME_CODE}}
-</script>
-<script>
-(function(){
- function resize(){
- var c=document.getElementById('canvas');
- var dpr=window.devicePixelRatio||1;
- c.width=window.innerWidth*dpr;
- c.height=window.innerHeight*dpr;
- }
- window.addEventListener('resize',resize);
- resize();
-
- ESEngineModule({
- canvas:document.getElementById('canvas'),
- print:function(t){console.log(t)},
- printErr:function(t){console.error(t)}
- }).then(function(Module){
- if(typeof Game!=='undefined'&&typeof Game.main==='function'){
- Game.main(Module);
- }else{
- console.error('Game.main not found');
- }
- }).catch(function(e){
- if(e!=='unwind'&&(!e.message||!e.message.includes('unwind'))){
- console.error('Failed:',e);
- }
- });
-})();
-</script>
-</body>
-</html>`;
-
-function parseArgs(args) {
- const result = { wasm: null, game: null, assets: null, output: 'playable.html' };
- for (let i = 0; i < args.length; i++) {
- if (args[i] === '--wasm' && args[i + 1]) {
- result.wasm = args[++i];
- } else if (args[i] === '--game' && args[i + 1]) {
- result.game = args[++i];
- } else if (args[i] === '--assets' && args[i + 1]) {
- result.assets = args[++i];
- } else if (args[i] === '--output' && args[i + 1]) {
- result.output = args[++i];
- } else if (args[i] === '--help' || args[i] === '-h') {
- console.log(`
-Bundle ESEngine game into single HTML for playable ads.
-
-Usage:
- node bundle-playable.js --wasm <sdk.js> --game <game.js> [--assets <dir>] [--output <out.html>]
-
-Options:
- --wasm Path to esengine.single.js (WASM SDK with inlined binary)
- --game Path to game.js (IIFE bundle with SDK runtime)
- --assets Path to assets directory (images will be inlined as base64)
- --output Output HTML file (default: playable.html)
-
-Example:
- node tools/bundle-playable.js \\
- --wasm build-web-single/sdk/esengine.single.js \\
- --game sdk/examples/playground/build/playable/game.js \\
- --assets sdk/examples/playground/assets \\
- --output playable.html
-`);
- process.exit(0);
- }
- }
- return result;
-}
-
-function scanAssets(assetsDir) {
- const assets = new Map();
- if (!fs.existsSync(assetsDir)) {
- return assets;
- }
-
- function scan(dir, prefix = '') {
- const entries = fs.readdirSync(dir, { withFileTypes: true });
- for (const entry of entries) {
- const fullPath = path.join(dir, entry.name);
- const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
-
- if (entry.isDirectory()) {
- scan(fullPath, relativePath);
- } else {
- const ext = path.extname(entry.name).toLowerCase();
- if (MIME_TYPES[ext]) {
- const data = fs.readFileSync(fullPath);
- const base64 = data.toString('base64');
- const dataUrl = `data:${MIME_TYPES[ext]};base64,${base64}`;
- assets.set(relativePath, dataUrl);
- }
- }
- }
- }
-
- scan(assetsDir);
- return assets;
-}
-
-function inlineAssets(code, assets, assetsPrefix) {
- let result = code;
- for (const [relativePath, dataUrl] of assets) {
- const assetPath = assetsPrefix ? `${assetsPrefix}/${relativePath}` : relativePath;
- result = result.split(`'${assetPath}'`).join(`'${dataUrl}'`);
- result = result.split(`"${assetPath}"`).join(`"${dataUrl}"`);
- }
- return result;
-}
-
-function main() {
- const args = parseArgs(process.argv.slice(2));
-
- if (!args.wasm) {
- console.error('Error: --wasm is required');
- process.exit(1);
- }
- if (!args.game) {
- console.error('Error: --game is required');
- process.exit(1);
- }
-
- if (!fs.existsSync(args.wasm)) {
- console.error(`Error: WASM SDK not found: ${args.wasm}`);
- process.exit(1);
- }
- if (!fs.existsSync(args.game)) {
- console.error(`Error: Game JS not found: ${args.game}`);
- process.exit(1);
- }
-
- const wasmSdk = fs.readFileSync(args.wasm, 'utf-8');
- let gameCode = fs.readFileSync(args.game, 'utf-8');
-
- // Inline assets if provided
- if (args.assets) {
- const assets = scanAssets(args.assets);
- if (assets.size > 0) {
- console.log(`Inlining ${assets.size} asset(s)...`);
- for (const [name] of assets) {
- console.log(` - ${name}`);
- }
- gameCode = inlineAssets(gameCode, assets, 'assets');
- }
- }
-
- const html = HTML_TEMPLATE
- .replace('{{WASM_SDK}}', wasmSdk)
- .replace('{{GAME_CODE}}', gameCode);
-
- // Ensure output directory exists
- const outDir = path.dirname(args.output);
- if (outDir && !fs.existsSync(outDir)) {
- fs.mkdirSync(outDir, { recursive: true });
- }
-
- fs.writeFileSync(args.output, html, 'utf-8');
-
- const sizeKb = (fs.statSync(args.output).size / 1024).toFixed(1);
- console.log(`Created: ${args.output} (${sizeKb} KB)`);
-}
-
-main();
diff --git a/tools/pack_bitmap_font.py b/tools/pack_bitmap_font.py
deleted file mode 100644
index fabc6a965..000000000
--- a/tools/pack_bitmap_font.py
+++ /dev/null
@@ -1,241 +0,0 @@
-#!/usr/bin/env python3
-"""
-Bitmap Font Packer for ESEngine
-
-Generates a font atlas (PNG) and metrics file (JSON) from a TTF font.
-Only includes specified characters to minimize file size.
-
-Usage:
- python pack_bitmap_font.py --font font.ttf --size 32 --chars chars.txt --output output_prefix
-
-Requirements:
- pip install Pillow freetype-py
-"""
-
-import argparse
-import json
-import math
-import sys
-from pathlib import Path
-
-try:
- from PIL import Image, ImageDraw
- import freetype
-except ImportError:
- print("Error: Required packages not installed.")
- print("Run: pip install Pillow freetype-py")
- sys.exit(1)
-
-
-# Common Chinese characters (most frequently used ~500)
-COMMON_CHINESE = """
-的一是不了在人有我他这为之大来以个中上们到说国和地也子时道出而要于就下得可你年生自会那后能对着事其里所去行过家十用发天如然作方成者多日都三小军二无同主经长儿母开看起五当已从心进动战么定现并系由问表所向间位与变使关十化法务高外政美全何济体建各明记力史样合接治电办点代新期活式特程通等门应反今共因解运第五外科员直象利文气军程取九原平代美安名回做基任入名至结党声各调组展空求路务员级教海完带象体月明便处象界权表电加即反
-"""
-
-# ASCII printable characters
-ASCII_CHARS = ''.join(chr(i) for i in range(32, 127))
-
-
-def get_default_chars():
- """Get default character set: ASCII + common Chinese"""
- return ASCII_CHARS + COMMON_CHINESE.replace('\n', '').replace(' ', '')
-
-
-def load_chars_from_file(filepath):
- """Load characters from a text file"""
- with open(filepath, 'r', encoding='utf-8') as f:
- chars = f.read()
- # Remove whitespace and duplicates while preserving order
- seen = set()
- result = []
- for c in chars:
- if c not in seen and c.strip():
- seen.add(c)
- result.append(c)
- return ''.join(result)
-
-
-def pack_font(font_path, font_size, chars, output_prefix, padding=2, atlas_size=1024):
- """
- Pack font glyphs into an atlas
-
- Args:
- font_path: Path to TTF font
- font_size: Font size in pixels
- chars: String of characters to include
- output_prefix: Output path prefix (will create .png and .json)
- padding: Padding between glyphs
- atlas_size: Maximum atlas size
- """
- # Load font
- face = freetype.Face(font_path)
- face.set_pixel_sizes(0, font_size)
-
- # Calculate metrics
- ascent = face.size.ascender >> 6
- descent = -(face.size.descender >> 6)
- line_height = (face.size.height >> 6)
-
- # First pass: measure all glyphs
- glyph_data = []
- for char in chars:
- try:
- face.load_char(char, freetype.FT_LOAD_RENDER)
- glyph = face.glyph
- bitmap = glyph.bitmap
-
- glyph_data.append({
- 'char': char,
- 'codepoint': ord(char),
- 'width': bitmap.width,
- 'height': bitmap.rows,
- 'bearingX': glyph.bitmap_left,
- 'bearingY': glyph.bitmap_top,
- 'advance': glyph.advance.x >> 6,
- 'buffer': bytes(bitmap.buffer) if bitmap.buffer else b'',
- 'pitch': bitmap.pitch
- })
- except Exception as e:
- print(f"Warning: Failed to load glyph '{char}' (U+{ord(char):04X}): {e}")
-
- if not glyph_data:
- print("Error: No glyphs loaded")
- return False
-
- # Sort by height for better packing
- glyph_data.sort(key=lambda g: -g['height'])
-
- # Calculate atlas size needed
- total_area = sum((g['width'] + padding) * (g['height'] + padding) for g in glyph_data)
- min_size = int(math.sqrt(total_area) * 1.2)
- atlas_width = min(atlas_size, max(256, 2 ** math.ceil(math.log2(min_size))))
- atlas_height = atlas_width
-
- # Pack glyphs (simple row-based packing)
- atlas = Image.new('RGBA', (atlas_width, atlas_height), (0, 0, 0, 0))
-
- x, y = padding, padding
- row_height = 0
-
- metrics = {
- 'fontSize': font_size,
- 'lineHeight': line_height,
- 'ascent': ascent,
- 'descent': descent,
- 'atlasWidth': atlas_width,
- 'atlasHeight': atlas_height,
- 'glyphs': []
- }
-
- for glyph in glyph_data:
- w, h = glyph['width'], glyph['height']
-
- # Check if we need to move to next row
- if x + w + padding > atlas_width:
- x = padding
- y += row_height + padding
- row_height = 0
-
- # Check if atlas is full
- if y + h + padding > atlas_height:
- # Try larger atlas
- if atlas_width < atlas_size:
- print(f"Warning: Atlas full, increasing size from {atlas_width} to {atlas_width * 2}")
- return pack_font(font_path, font_size, chars, output_prefix,
- padding, min(atlas_size, atlas_width * 2))
- else:
- print(f"Error: Atlas full, couldn't fit all glyphs")
- break
-
- # Draw glyph
- if w > 0 and h > 0 and glyph['buffer']:
- glyph_img = Image.new('L', (w, h))
- # Copy bitmap data row by row
- for row in range(h):
- for col in range(w):
- idx = row * glyph['pitch'] + col
- if idx < len(glyph['buffer']):
- glyph_img.putpixel((col, row), glyph['buffer'][idx])
-
- # Convert to RGBA (white text with alpha)
- rgba_img = Image.new('RGBA', (w, h))
- for py in range(h):
- for px in range(w):
- alpha = glyph_img.getpixel((px, py))
- rgba_img.putpixel((px, py), (255, 255, 255, alpha))
-
- atlas.paste(rgba_img, (x, y))
-
- # Store metrics
- metrics['glyphs'].append({
- 'char': glyph['char'],
- 'codepoint': glyph['codepoint'],
- 'width': float(w),
- 'height': float(h),
- 'bearingX': float(glyph['bearingX']),
- 'bearingY': float(glyph['bearingY']),
- 'advance': float(glyph['advance']),
- 'u0': x / atlas_width,
- 'v0': y / atlas_height,
- 'u1': (x + w) / atlas_width,
- 'v1': (y + h) / atlas_height
- })
-
- # Move position
- x += w + padding
- row_height = max(row_height, h)
-
- # Save outputs
- atlas_path = f"{output_prefix}.png"
- metrics_path = f"{output_prefix}.json"
-
- atlas.save(atlas_path, 'PNG', optimize=True)
-
- with open(metrics_path, 'w', encoding='utf-8') as f:
- json.dump(metrics, f, ensure_ascii=False, indent=2)
-
- print(f"Generated: {atlas_path} ({atlas_width}x{atlas_height})")
- print(f"Generated: {metrics_path} ({len(metrics['glyphs'])} glyphs)")
- print(f"Atlas size: {Path(atlas_path).stat().st_size / 1024:.1f} KB")
-
- return True
-
-
-def main():
- parser = argparse.ArgumentParser(description='Pack bitmap font for ESEngine')
- parser.add_argument('--font', '-f', required=True, help='Input TTF font path')
- parser.add_argument('--size', '-s', type=int, default=32, help='Font size in pixels')
- parser.add_argument('--chars', '-c', help='File containing characters to include')
- parser.add_argument('--output', '-o', required=True, help='Output path prefix')
- parser.add_argument('--padding', '-p', type=int, default=2, help='Padding between glyphs')
- parser.add_argument('--atlas-size', type=int, default=2048, help='Maximum atlas size')
- parser.add_argument('--ascii-only', action='store_true', help='Only include ASCII characters')
-
- args = parser.parse_args()
-
- # Determine character set
- if args.ascii_only:
- chars = ASCII_CHARS
- elif args.chars:
- chars = load_chars_from_file(args.chars)
- else:
- chars = get_default_chars()
-
- print(f"Font: {args.font}")
- print(f"Size: {args.size}px")
- print(f"Characters: {len(chars)}")
-
- success = pack_font(
- args.font,
- args.size,
- chars,
- args.output,
- args.padding,
- args.atlas_size
- )
-
- sys.exit(0 if success else 1)
-
-
-if __name__ == '__main__':
- main()