60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
"use strict";
|
|
|
|
const FramesBuilder = (function(){
|
|
|
|
const FramesBuilder = function(hollow_bond){
|
|
|
|
const add = (chunk, inputs) => {
|
|
|
|
const id = FrameModel.get_id(inputs.x, inputs.y, inputs.z),
|
|
frame = (
|
|
chunk.frames[id] ||
|
|
hollow_bond.map.frames[id] ||
|
|
new FrameModel(hollow_bond, inputs)
|
|
);
|
|
|
|
chunk.frames[id] = frame;
|
|
// chunk.frames_by_position[id] = frame;
|
|
|
|
return frame;
|
|
};
|
|
|
|
this.generate_seam = chunk => {
|
|
|
|
for(let py = chunk.yf; py < chunk.yt; py ++){
|
|
|
|
[[chunk.xf, "west"], [chunk.xt, "east"]].forEach(([wall_x, neighbor]) => {
|
|
if(chunk.neighbors[neighbor])
|
|
for(let cursor_z = chunk.zf, i = 0; cursor_z < chunk.zt; i ++)
|
|
(
|
|
cursor_z += Math.floor(hollow_bond.hash.seam_vertical_x(wall_x, py, chunk.zf, py + 1, chunk.zt, i) * hollow_bond.chunk_frame_maximum_gap) + 1
|
|
) < chunk.zt && add(chunk, {
|
|
x : wall_x,
|
|
y : py,
|
|
z : cursor_z,
|
|
axis : "vertical"
|
|
});
|
|
});
|
|
|
|
[[chunk.zf, "north"], [chunk.zt, "south"]].forEach(([wall_z, neighbor]) => {
|
|
if(chunk.neighbors[neighbor])
|
|
for(let cursor_x = chunk.xf, i = 0; cursor_x < chunk.xt; i ++)
|
|
(
|
|
cursor_x += Math.floor(hollow_bond.hash.seam_vertical_z(chunk.xf, py, wall_z, chunk.xt, py + 1, i) * hollow_bond.chunk_frame_maximum_gap) + 1
|
|
) < chunk.xt && add(chunk, {
|
|
x : cursor_x,
|
|
y : py,
|
|
z : wall_z,
|
|
axis : "horizontal"
|
|
});
|
|
});
|
|
|
|
};
|
|
|
|
return chunk.frames;
|
|
};
|
|
|
|
};
|
|
|
|
return FramesBuilder;
|
|
})(); |