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
refactor(f1): collapse OS/native branches to web (Engine, PathResolver, OpenGLHeaders, GLDevice)
esengineab3edd7a670c
diff --git a/src/esengine/core/Engine.cpp b/src/esengine/core/Engine.cppindex 0a59103f7..df8575f6d 100644--- a/src/esengine/core/Engine.cpp+++ b/src/esengine/core/Engine.cpp@@ -18,33 +18,17 @@ namespace esengine {const char* Engine::getPlatformName() {#ifdef ES_PLATFORM_WXGAMEreturn "WeChat MiniGame";-#elif defined(ES_PLATFORM_WEB)- return "Web";-#elif defined(ES_PLATFORM_WINDOWS)- return "Windows";-#elif defined(ES_PLATFORM_MACOS)- return "macOS";-#elif defined(ES_PLATFORM_LINUX)- return "Linux";#else- return "Unknown";+ return "Web";#endif}bool Engine::isWebPlatform() {-#ifdef ES_PLATFORM_WEBreturn true;-#else- return false;-#endif}bool Engine::hasWebGL2() {-#ifdef ES_PLATFORM_WEB- return true; // We require WebGL2-#else- return false;-#endif+ return true; // WebGL2 is a hard requirement}} // namespace esenginediff --git a/src/esengine/platform/PathResolver.cpp b/src/esengine/platform/PathResolver.cppindex 119711530..e7cd6018e 100644--- a/src/esengine/platform/PathResolver.cpp+++ b/src/esengine/platform/PathResolver.cpp@@ -12,18 +12,6 @@#include "PathResolver.hpp"#include "../core/Log.hpp"-#ifdef ES_PLATFORM_WEB- // Web platform - no executable path needed-#elif defined(_WIN32) || defined(_WIN64)- #include <windows.h>-#elif defined(__APPLE__)- #include <mach-o/dyld.h>- #include <limits.h>-#elif defined(__linux__)- #include <unistd.h>- #include <limits.h>-#endif-#include <algorithm>namespace esengine {@@ -35,17 +23,10 @@ bool PathResolver::initialized_ = false;void PathResolver::init() {if (initialized_) return;-#ifdef ES_SOURCE_DIR- // Development mode: use source directory for editor assets- editorRoot_ = ES_SOURCE_DIR;- projectRoot_ = ES_SOURCE_DIR;- ES_LOG_INFO("PathResolver initialized (dev mode) - Editor root: {}", editorRoot_);-#else- // Release mode: use executable directory+ // Web has no executable/source directory; paths resolve relative to the VFS root.editorRoot_ = getExecutableDirectory();projectRoot_ = editorRoot_;ES_LOG_INFO("PathResolver initialized - Editor root: {}", editorRoot_);-#endifinitialized_ = true;}@@ -106,70 +87,12 @@ std::string PathResolver::projectPath(const std::string& relativePath) {bool PathResolver::isAbsolutePath(const std::string& path) {if (path.empty()) return false;--#if defined(_WIN32) || defined(_WIN64)- if (path.length() >= 2 && path[1] == ':') {- return true;- }- if (path.length() >= 2 && (path[0] == '\\' && path[1] == '\\')) {- return true;- }-#else- if (path[0] == '/') {- return true;- }-#endif-- return false;+ return path[0] == '/';}std::string PathResolver::getExecutableDirectory() {-#ifdef ES_PLATFORM_WEB+ // Web has no executable directory; assets resolve from the VFS root.return "";--#elif defined(_WIN32) || defined(_WIN64)- char buffer[MAX_PATH];- DWORD length = GetModuleFileNameA(nullptr, buffer, MAX_PATH);- if (length > 0 && length < MAX_PATH) {- std::string path(buffer);- auto pos = path.find_last_of("\\/");- if (pos != std::string::npos) {- return path.substr(0, pos);- }- }- return ".";--#elif defined(__APPLE__)- char buffer[PATH_MAX];- uint32_t size = sizeof(buffer);- if (_NSGetExecutablePath(buffer, &size) == 0) {- char realPath[PATH_MAX];- if (realpath(buffer, realPath)) {- std::string path(realPath);- auto pos = path.find_last_of('/');- if (pos != std::string::npos) {- return path.substr(0, pos);- }- }- }- return ".";--#elif defined(__linux__)- char buffer[PATH_MAX];- ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);- if (len != -1) {- buffer[len] = '\0';- std::string path(buffer);- auto pos = path.find_last_of('/');- if (pos != std::string::npos) {- return path.substr(0, pos);- }- }- return ".";--#else- return ".";-#endif}std::string PathResolver::normalizePath(const std::string& path) {@@ -177,19 +100,11 @@ std::string PathResolver::normalizePath(const std::string& path) {std::string result = path;-#if defined(_WIN32) || defined(_WIN64)- std::replace(result.begin(), result.end(), '/', '\\');-- while (result.length() > 1 && result.back() == '\\') {- result.pop_back();- }-#elsestd::replace(result.begin(), result.end(), '\\', '/');while (result.length() > 1 && result.back() == '/') {result.pop_back();}-#endifreturn result;}diff --git a/src/esengine/renderer/GLDevice.cpp b/src/esengine/renderer/GLDevice.cppindex 3396ce83c..624063310 100644--- a/src/esengine/renderer/GLDevice.cpp+++ b/src/esengine/renderer/GLDevice.cpp@@ -624,12 +624,7 @@ void GLDevice::pixelStorei(u32 pname, i32 param) {}void GLDevice::setUnpackFlipY(bool enabled) {-#ifdef ES_PLATFORM_WEBglPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, enabled ? GL_TRUE : GL_FALSE);-#else- // Native image data is flipped CPU-side at load (stbi_set_flip_vertically_on_load).- (void)enabled;-#endif}// =============================================================================@@ -674,11 +669,8 @@ void GLDevice::readPixels(i32 x, i32 y, u32 w, u32 h, GfxPixelFormat format, voi// =============================================================================void GLDevice::setWireframe(bool enabled) {-#ifndef ES_PLATFORM_WEB- glPolygonMode(GL_FRONT_AND_BACK, enabled ? GL_LINE : GL_FILL);-#else+ // glPolygonMode is not available in WebGL2 / GLES3; wireframe is a no-op.(void)enabled;-#endif}u32 GLDevice::getError() {diff --git a/src/esengine/renderer/OpenGLHeaders.hpp b/src/esengine/renderer/OpenGLHeaders.hppindex 6d04f755f..add7c5576 100644--- a/src/esengine/renderer/OpenGLHeaders.hpp+++ b/src/esengine/renderer/OpenGLHeaders.hpp@@ -12,24 +12,13 @@#pragma once// =============================================================================-// Platform-specific OpenGL Headers+// OpenGL Headers// =============================================================================-#ifdef ES_PLATFORM_WEB- // Web platform uses OpenGL ES 3.0- #include <GLES3/gl3.h>-#elif defined(__APPLE__)- // macOS uses OpenGL framework- #include <OpenGL/gl3.h>-#else- // Windows/Linux use GLAD for modern OpenGL- #ifdef _WIN32- #include <windows.h>- #endif- #include <glad/glad.h>-#endif+// Web/wasm targets OpenGL ES 3.0 (WebGL 2.0).+#include <GLES3/gl3.h>-// GL blend equation constants/functions not present in all glad configurations+// GL blend equation constants not guaranteed across all GLES3/WebGL2 headers#ifndef GL_FUNC_ADD#define GL_FUNC_ADD 0x8006#endif@@ -43,7 +32,7 @@#define GL_BLEND_EQUATION 0x8009#endif-// GL constants not present in all headers / glad configurations+// GL constants not guaranteed across all GLES3/WebGL2 headers#ifndef GL_CONTEXT_LOST#define GL_CONTEXT_LOST 0x0507#endif