Skip to content

Commit

Permalink
chore(map): clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Jan 14, 2024
1 parent 064c107 commit d5008d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 72 deletions.
9 changes: 2 additions & 7 deletions src/lib/map/light/MapLight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import {
LightParamsRecord,
LightRecord,
} from '@wowserhq/format';
import {
getDayNightTime,
interpolateColorTable,
interpolateNumericTable,
selectLightsForPosition,
} from './util.js';
import { getDayNightTime, interpolateNumericTable, selectLightsForPosition } from './util.js';
import { SUN_PHI_TABLE, SUN_THETA_TABLE } from './table.js';
import { LIGHT_FLOAT_BAND, LIGHT_INT_BAND, LIGHT_PARAM } from './const.js';
import { LIGHT_PARAM } from './const.js';
import { getAreaLightsFromDb } from './db.js';
import { AreaLight, WeightedAreaLight } from './types.js';
import SceneLight from '../../light/SceneLight.js';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/map/light/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';
import { AreaLight, WeightedAreaLight } from './types.js';
import { MAP_CORNER_X, MAP_CORNER_Y } from '@wowserhq/format';
import { AreaLight, WeightedAreaLight } from './types.js';

const clamp = (value: number, min: number, max: number) => {
return Math.min(Math.max(value, min), max);
Expand Down
66 changes: 2 additions & 64 deletions src/lib/map/loader/util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
MAP_CHUNK_FACE_COUNT_X,
MAP_CHUNK_FACE_COUNT_Y,
MAP_CHUNK_HEIGHT,
MAP_CHUNK_VERTEX_COUNT,
MAP_CHUNK_VERTEX_STEP_X,
MAP_CHUNK_VERTEX_STEP_Y,
MAP_CHUNK_WIDTH,
} from '@wowserhq/format';
import { MAP_CHUNK_FACE_COUNT_X, MAP_CHUNK_FACE_COUNT_Y } from '@wowserhq/format';
import { DEFAULT_TERRAIN_VERTEX_BUFFER } from './const.js';

const isTerrainHole = (holes: number, x: number, y: number) => {
Expand All @@ -17,55 +9,6 @@ const isTerrainHole = (holes: number, x: number, y: number) => {
return (hole & holes) !== 0;
};

const createDefaultTerrainVertexBuffer = () => {
// Vertex coordinates for x-axis (forward axis)
const vxe = new Float32Array(MAP_CHUNK_FACE_COUNT_X + 1);
const vxo = new Float32Array(MAP_CHUNK_FACE_COUNT_X);
for (let i = 0; i < MAP_CHUNK_FACE_COUNT_X; i++) {
const vx = -(i * MAP_CHUNK_VERTEX_STEP_X);
vxe[i] = vx;
vxo[i] = vx - MAP_CHUNK_VERTEX_STEP_X / 2.0;
}
vxe[MAP_CHUNK_FACE_COUNT_X] = -MAP_CHUNK_HEIGHT;

// Vertex coordinates for y-axis (right axis)
const vye = new Float32Array(MAP_CHUNK_FACE_COUNT_Y + 1);
const vyo = new Float32Array(MAP_CHUNK_FACE_COUNT_Y);
for (let i = 0; i < MAP_CHUNK_FACE_COUNT_Y; i++) {
const vy = -(i * MAP_CHUNK_VERTEX_STEP_Y);
vye[i] = vy;
vyo[i] = vy - MAP_CHUNK_VERTEX_STEP_Y / 2.0;
}
vye[MAP_CHUNK_FACE_COUNT_Y] = -MAP_CHUNK_WIDTH;

const vertexBuffer = new ArrayBuffer(MAP_CHUNK_VERTEX_COUNT * 16);
const vertexBufferView = new DataView(vertexBuffer);

let i = 0;

for (let x = 0; x < MAP_CHUNK_FACE_COUNT_X + 1; x++) {
// Evens
for (let y = 0; y < MAP_CHUNK_FACE_COUNT_Y + 1; y++) {
vertexBufferView.setFloat32(i * 16 + 0, vxe[x], true);
vertexBufferView.setFloat32(i * 16 + 4, vye[y], true);

i++;
}

// Odds
if (x < MAP_CHUNK_FACE_COUNT_X) {
for (let y = 0; y < MAP_CHUNK_FACE_COUNT_Y; y++) {
vertexBufferView.setFloat32(i * 16 + 0, vxo[x], true);
vertexBufferView.setFloat32(i * 16 + 4, vyo[y], true);

i++;
}
}
}

return vertexBuffer;
};

const createTerrainVertexBuffer = (vertexHeights: Float32Array, vertexNormals: Int8Array) => {
// Copy the default vertex buffer (contains x and y coordinates)
const data = DEFAULT_TERRAIN_VERTEX_BUFFER.slice(0);
Expand Down Expand Up @@ -137,9 +80,4 @@ const mergeTerrainLayerSplats = (layerSplats: Uint8Array[], width: number, heigh
return data;
};

export {
createDefaultTerrainVertexBuffer,
createTerrainIndexBuffer,
createTerrainVertexBuffer,
mergeTerrainLayerSplats,
};
export { createTerrainIndexBuffer, createTerrainVertexBuffer, mergeTerrainLayerSplats };

0 comments on commit d5008d9

Please sign in to comment.