/** * wechat-config.js - 微信小游戏性能优化配置 * * 功能: * 1. 性能监控和调优参数 * 2. 分包加载配置 * 3. 资源管理策略 * 4. GC优化建议 */ module.exports = { /** * 性能优化配置 */ performance: { // 目标帧率(微信小游戏建议60fps,低端机可降至30) targetFPS: 60, // 最大同屏水果数量(根据性能调整) maxFruitsOnScreen: 40, // 对象池大小配置 objectPool: { fruit: 50, // 水果对象池大小 bullet: 20, // 子弹对象池大小 enemy: 30, // 敌机对象池大小 effect: 15, // 特效对象池大小 }, // GC触发间隔(毫秒) gcInterval: 30000, // 内存警告阈值(MB) memoryWarningThreshold: 200, // 是否启用性能监控 enablePerformanceMonitor: true, // 性能数据上报间隔(秒) performanceReportInterval: 60, }, /** * 分包加载配置 * 微信小游戏主包限制20MB,需要使用分包 */ subpackages: [ { name: 'core', root: 'subpackages/core/', // 核心游戏逻辑(必须首先加载) includes: [ 'assets/scripts/core/*', 'assets/scripts/gameplay/*', ], }, { name: 'levels', root: 'subpackages/levels/', // 关卡配置和Boss数据 includes: [ 'assets/resources/levels/*', 'assets/resources/bosses/*', ], // 按需加载 lazy: true, }, { name: 'audio', root: 'subpackages/audio/', // 音频资源(体积大,单独分包) includes: [ 'assets/resources/audio/*', ], lazy: true, }, { name: 'ui', root: 'subpackages/ui/', // UI界面资源 includes: [ 'assets/resources/ui/*', 'assets/prefabs/ui/*', ], lazy: true, }, ], /** * 资源加载策略 */ resourceLoading: { // 预加载策略 preload: { // 启动时预加载的核心资源 onStartup: [ 'audio/bgm_main', 'audio/sfx_merge', 'textures/fruit_1', 'textures/fruit_2', ], // 关卡开始前预加载 beforeLevel: (level) => [ `levels/level_${level}`, `bosses/boss_${level}`, ], }, // 异步加载超时时间(毫秒) loadTimeout: 10000, // 最大并发加载数 maxConcurrentLoads: 3, // 资源缓存大小限制(MB) cacheSizeLimit: 50, }, /** * 微信特定优化 */ wechatOptimization: { // 使用 wx.loadSubpackage 预下载分包 preloadSubpackages: ['core'], // 启用微信小游戏开放数据域(如果需要排行榜等功能) enableOpenDataContext: false, // 使用 wx.triggerGC() 主动触发GC的时机 gcTriggers: [ 'sceneChange', // 场景切换时 'gameOver', // 游戏结束时 'background', // 进入后台时 ], // 图片压缩设置 imageCompression: { quality: 80, // JPEG质量 maxWidth: 1024, // 最大宽度 maxHeight: 1024, // 最大高度 format: 'webp', // 优先使用WebP格式 }, }, /** * 调试和监控配置 */ debug: { // 启用性能面板 enablePerformancePanel: false, // 日志级别:'debug' | 'info' | 'warn' | 'error' logLevel: 'info', // 是否上报错误到微信分析 reportErrors: true, // 性能数据采集项 metrics: [ 'fps', 'memory', 'drawCalls', 'triangles', 'loadTime', ], }, };