当前位置: 首页 > news >正文

随手写的一个子进程

主进程

import ClearTouchGroundCacheCode from '../utils/workers/clearTouchGroundCache.worker.js';  
const blob = new Blob([ClearTouchGroundCacheCode], { type: 'application/javascript' });this.clearTouchGroundCacheWorker = new Worker(URL.createObjectURL(blob));this.clearTouchGroundCacheWorker.postMessage({type: 'clearCache',data: { cache: JSON.stringify(_context.touchGroundCache?.[2]), minGx, maxGx, minGz, maxGz, minX, maxX, minZ, maxZ },});// 接收 Worker 返回的数据this.clearTouchGroundCacheWorker.onmessage = (e) => {const msg = e.data;if (msg.type === 'clearDone') {const { keysToDelete, minX, maxX, minZ, maxZ } = msg.data;// 执行删除for (const key of keysToDelete) {if (_context.touchGroundCache[2]?.[key]) {// delete _context.touchGroundCache[2][key];_context.touchGroundCache[2][key] = null; //比delete更快}}console.log(`✅ 已清除x:${minX}-${maxX}z:${minZ}- ${maxZ}缓存`);}};

 子进程:

/** @Author: Simoon.jia* @Date: 2025-10-11 14:57:24* @LastEditors: Simoon.jia* @LastEditTime: 2025-10-11 15:21:15* @Description: 描述*/
// clearTouchGroundCache.worker.js
console.log('[Worker] clearTouchGroundCache.worker.js 已加载');self.onmessage = (e) => {const msg = e.data;if (msg.type === 'clearCache') {const { cache, minGx, maxGx, minGz, maxGz, minX, maxX, minZ, maxZ } = msg.data;const keysToDelete = [];const newCache = JSON.parse(cache);// 遍历格子索引,筛选存在的 keyfor (const key in newCache) {const [gx, gz] = key.split('_').map(Number);if (gx >= minGx && gx <= maxGx && gz >= minGz && gz <= maxGz) {keysToDelete.push(key);}}// 回传 key 数组给主线程self.postMessage({type: 'clearDone',data: { keysToDelete, minX, maxX, minZ, maxZ },});}
};

roolup配置:

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import glslify from 'rollup-plugin-glslify';
import { string } from 'rollup-plugin-string';
export default {input: 'src/avw.js',output: [{file: 'dist/avw.scene.core.min.js',format: 'umd',name: 'avwCore',sourcemap: true,},{file: '../AVW.Scene/lib/avw.scene.core.module.min.js',format: 'esm',name: 'avwCore',sourcemap: false,},],plugins: [resolve({browser: true,}),commonjs(),glslify(),string({include: '**/*.worker.js', // 把 worker 当作字符串处理}),],onwarn(warning, warn) {if (warning.code === 'EVAL') return;warn(warning);},
};

 

http://www.hskmm.com/?act=detail&tid=28695

相关文章:

  • 来追梦-D1295 小F过河
  • P3605解题报告
  • P13763 解题报告
  • CF1082E 解题报告
  • 国标GB28181算法算力平台EasyGBS具备哪些核心流媒体技术?
  • 2025 年净化车间源头厂家最新推荐排行榜:精选实力企业,助力企业精准选择优质净化车间服务商无尘/gmp/新能源/锂电池净化车间厂家推荐
  • C语言的“动态数组”
  • 背包 dp 历年真题:做题记录
  • 【触想智能】什么是工业平板电脑以及工业平板电脑对制造业具有什么意义
  • 2025 年国内无尘车间源头厂家最新推荐排行榜:聚焦无菌洁净领域优选企业助力企业精准选型万级/十万级/洁净/食品厂/千级无尘车间厂家推荐
  • 新手小白安装Typroa遇到的问题 - I
  • 怎么能跑得快,怎么突破瓶颈
  • (Sigcomm25) Stellar: 阿里新一代云AI RDMA网络
  • 高效工作,五步工作法
  • 虚树学习笔记
  • 市场营销:
  • Python3开发敏感词过滤程序底层逻辑记录
  • OUC《软件工程原理与实践》- 实验2:深度学习基础 - OUC
  • 类型转化
  • 【IEEE出版】第五届电子信息工程与计算机技术国际学术会议(EIECT 2025)
  • 【AP出版】第七届文学、艺术与人文发展国际学术会议(ICLAHD 2025)
  • 事件驱动重塑 AI 数据链路:阿里云 EventBridge 发布 AI ETL 新范式
  • 我把Excel变成了像素画板!用Python实现图片到单元格的映射
  • 如何通过内核版本检查判断FreeBSD是否需要重启
  • 2025 年山东染井吉野樱 / 高杆染井吉野樱花 / 染井吉野樱花小苗厂家推荐:绿影园林的培育技术与全规格供应解析
  • C#中关于InvokeRequired 属性 与Invoke方法
  • 云存储成本自动优化技术解析
  • MZOI 20251011【CSP-】模拟 T2 序列区间
  • SAP 中CONCATENATE 空格的时候,空格不生效
  • Java的各类定时任务实现