当前位置: 首页 > 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.gsyq.cn/news/18860.html

相关文章:

  • 来追梦-D1295 小F过河
  • P3605解题报告
  • C语言的“动态数组”
  • 详细介绍:Spring Boot 应用示例
  • (Sigcomm25) Stellar: 阿里新一代云AI RDMA网络
  • 背包 dp 历年真题:做题记录
  • 【触想智能】什么是工业平板电脑以及工业平板电脑对制造业具有什么意义
  • 虚树学习笔记
  • OUC《软件工程原理与实践》- 实验2:深度学习基础 - OUC
  • 类型转化
  • 事件驱动重塑 AI 数据链路:阿里云 EventBridge 发布 AI ETL 新范式
  • 我把Excel变成了像素画板!用Python实现图片到单元格的映射
  • 2025 年山东染井吉野樱 / 高杆染井吉野樱花 / 染井吉野樱花小苗厂家推荐:绿影园林的培育技术与全规格供应解析
  • 云存储成本自动优化技术解析
  • SAP 中CONCATENATE 空格的时候,空格不生效
  • OIFHA251011 比赛总结
  • 一种智能调度分布式路径计算解决方案
  • 实用指南:SDN 控制器深度剖析:架构、对比与实践部署
  • Halo RAG!
  • 2025 自动门生产厂家最新推荐榜:权威筛选优质品牌,含选购指南与实力厂家深度解析
  • 医德出诊排班挂号管理系统:医院高效运营与便民服务的智能解决方案
  • 2025 年北京市清理化粪池公司最新推荐排行榜:聚焦高压技术与全城服务的权威甄选朝阳区/丰台区/海淀区/通州区清理化粪池厂家推荐
  • 报表方案Stimulsoft 2025.4 重磅发布!新增AI报表助手、C#脚本支持、全新图表类型等多项功能!
  • Prometheus的Exporter的数据采集机制
  • 2025 年珠三角 / 中山 / 东莞 / 佛山厂房出售公司推荐:中创集团产业生态型厂房的价值与服务解析
  • 拷贝和上传文件,涉及隐私协议
  • 2025储罐厂家,钢衬塑储罐,钢塑复合储罐,化工储罐,防腐储罐,PE储罐,盐酸储罐,硫酸储罐,聚丙烯储罐,不锈钢储罐,次氯酸钠储罐各类型最新推荐榜:品质卓越与技术创新的行业先锋!
  • 2025 年国内标志牌生产厂家最新推荐排行榜:聚焦优质企业助力客户精准选择道路/限速/公路/施工/警示/限高/三角/安全标志牌厂家推荐
  • 在Scala中,如何在泛型类中使用类型参数?
  • Maple 2025 来了!AI 赋能 + 6000 + 命令,破解数学计算、科研与教学痛点