* test(hex): add procedural hex dungeon levels for engine QA Cross-module simulation levels exercise hex tilemap procgen, FOV, 2D lighting, spatial pickup + inventory, and particles. Includes a playable examples/hex-levels demo with level select and a pipeline crawl. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * test(hex): expand levels 06–15 and fog-raid pipeline Add Flow Field swarm, cell-cost detours, multi-revealer perception, FoW mask/algorithms, camera pick, dual-grid, procgen variants, QuadTree cull, multi-light, particle/stash transfer, and a fog-raid pipeline. Update the playable hex-levels demo for levels 6–9. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * test(hex): add fixture JSON data and data-driven hex tests Expand catalog/items/loot/seeds/perception fixtures, handcrafted maps, and particle configs. Wire the hex-levels demo to load items and particle JSON plus fixtures.nut loot tables. Register hex_level_data.cpp coverage. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * test(hex): fix data fixtures assertions for zeroerr and sparse gens Avoid CHECK_EQ on bag->addItem (double-eval), and only enforce minWalkable on dungeon.bsp in the seeds matrix smoke. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * feat(hex): boot each level from distinct catalog configs Enrich catalog/fixtures with per-level FOV, light, cell-cost, and enable flags. Wire examples/hex-levels to apply those boot settings on level switch. Add hex.data.catalog.bootEachLevelDistinctConfig to verify each catalog entry starts with its own applied configuration. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * docs(hex): note per-level boot configs in data README Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * test(hex): add levels 16–20 and extra data-driven coverage Expand simulation with facing-cone FOV, flow+cell-cost, seed reproducibility, corner peek, equipment equip, and torchEscort / catalogRaid pipelines. Add fixture tests for perception gates, all loot tables, enable-flag consistency, seed path samples, map markers, defaults, equipment slots, and mist particles on dungeon. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * docs(hex): clarify expanded test coverage in README Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * test(hex): add levels 21–25 and broader fixture validation Cover hex world↔tile roundtrip, FOV memory clear, findGroupPath, multi-algo FOV smoke, blocked-cell sync, and costlyFogPickup pipeline. Add data tests for loot/item referential integrity, feature tags, particle schema, algorithm registration, ring-door path, categories, detection margin, and door walkability. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * feat(hex): expand catalog to 31 levels (0–30) and playable cycle Add levels 16–30 with distinct boot configs (facing cone, flow+cost, maze/WFC/drunkard, mist particles, raid combo). Regenerate fixtures.nut with LEVEL_IDS; main.nut cycles all catalog levels via N/B. Add simulation cases 26–30 and catalog presence tests. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> * fix(hex): harden level 02/17 against non-portable procgen paths macOS CI failed hex.level.02.dynamicFov (empty path) and hex.level.17.flowPlusCellCost (path length == 2) because spawn↔exit layouts from DTL/std distributions differ across libstdc++ vs libc++. Use handcrafted hex maps so FOV memory and flow+cost assertions are platform-stable. Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
3.5 KiB
3.5 KiB
程序化生成模块
脚本入口: eve.Procgen()
按算法名和 Params 生成网格、地图层、图像、法线图或 GPU 纹理。
基本用法
local gen = eve.Procgen();
local p = gen.newParams();
p.setSeed(42); p.setSize(64, 40);
local grid = gen.generate("dungeon.bsp", p);
对象关系与调用时机
Params 描述 seed、尺寸和算法参数;Grid2D 是结果;OutputSpec 决定写入 TileLayer、Image 或 Texture;Procgen 按注册算法名执行。
目标导向指南
生成可玩的地牢层
创建 Params,设置 seed 和尺寸,按需添加算法参数;用 generate("dungeon.bsp", p) 先检查 Grid,也可配置 Output 将结果直接写入 TileLayer。保存 seed 可复现关卡。也可用 generate("wfc.simple", p)(preset=dungeon|cave|terrain)做约束驱动铺贴。
生成等值面网格(Marching Cubes)
local p = gen.newParams();
p.setSeed(1);
p.setInt("resolution", 32);
p.setString("field", "sphere"); // sphere | torus | noise | terrain
local cpu = gen.buildMesh("mesh.marchingcubes", p);
local gpu = gen.generateMesh("mesh.marchingcubes", p, gfx);
生成无缝材质
设置 texture recipe、尺寸、octaves、pixelSize 和 seamless,调用纹理或法线图生成接口;开发期切换 seed 预览,发布时缓存 Texture,不能每帧重新生成。
常见问题
- 未保存 seed,无法复现玩家问题。
- Output palette 缺少算法输出的 tile key。
- 在每帧 update 生成大地图或纹理。
API 快查
下列方法名来自当前 Squirrel 绑定;同一模块创建的辅助对象(例如 World、Body、Source)的方法也列在这里。
addObject()、addObjectAt()、applyToLayer()、buildMesh()、clearObjects()、fill()、generate()、generateImage()、generateMesh()、generateNormalImage()generateTexture()、generateTo()、getAlgorithmCount()、getAlgorithmId()、getCell()、getFloat()、getHeight()、getInt()getLayer()、getMeshRecipeCount()、getMeshRecipeId()、getMeta()、getName()、getObjectCount()、getObjectGid()、getObjectHeight()、getObjectName()、getObjectType()getObjectWidth()、getObjectX()、getObjectY()、getPalette()、getPaletteGid()、getPath()、getSeed()、getString()getTarget()、getTextureRecipeCount()、getTextureRecipeId()、getWidth()、gridToJson()、has()、hasAlgorithm()、hasMeshRecipe()、hasTextureRecipe()lastError()、newGrid()、newOutput()、newParams()、resize()、setCell()、setFloat()、setInt()setLayer()、setMeta()、setPalette()、setPaletteGid()、setPath()、setSeed()、setSize()、setString()setTarget()
使用要点
- 模块对象和它创建的资源对象应保存在全局或实体状态中,不要在每帧重复创建。
- 带
update(dt)的系统应在eve_update调用;绘制方法应在eve_render调用。 - 参数约束、默认值和返回类型以对应模块头文件及
addFunc绑定为准;本文 API 快查与当前源码同步生成。
源码: src/modules/procgen/
相关测试: 在 test/ 中搜索 procgen;跨模块 hex 关卡见 test/hex_level_simulation.cpp、test/hex_level_data.cpp、examples/hex-levels/。