Removed unused linear_allocator.ts

* Updated misc types
This commit is contained in:
Lucas Dower 2023-11-04 12:27:27 +00:00
parent 1d051dbcc8
commit a1d0fa1aff
5 changed files with 77 additions and 84 deletions

View File

@ -221,35 +221,35 @@ export namespace RGBAUtil {
}
export class OtS_Colours {
public static get BLACK() {
public static get BLACK(): RGBA {
return { r: 0.0, g: 0.0, b: 0.0, a: 1.0 };
}
public static get WHITE() {
public static get WHITE(): RGBA {
return { r: 1.0, g: 1.0, b: 1.0, a: 1.0 };
}
public static get RED() {
public static get RED(): RGBA {
return { r: 1.0, g: 0.0, b: 0.0, a: 1.0 };
}
public static get GREEN() {
public static get GREEN(): RGBA {
return { r: 0.0, g: 1.0, b: 0.0, a: 1.0 };
}
public static get BLUE() {
public static get BLUE(): RGBA {
return { r: 0.0, g: 0.0, b: 1.0, a: 1.0 };
}
public static get YELLOW() {
public static get YELLOW(): RGBA {
return { r: 1.0, g: 1.0, b: 0.0, a: 1.0 };
}
public static get CYAN() {
public static get CYAN(): RGBA {
return { r: 0.0, g: 1.0, b: 1.0, a: 1.0 };
}
public static get MAGENTA() {
public static get MAGENTA(): RGBA {
return { r: 1.0, g: 0.0, b: 1.0, a: 1.0 };
}
}

View File

@ -1,48 +0,0 @@
export class LinearAllocator<T> {
private _items: Array<T>;
private _nextIndex: number;
private _max: number;
private _itemConstructor: () => T;
public constructor(getNewItem: () => T) {
this._items = new Array<T>();
this._nextIndex = 0;
this._max = 0;
this._itemConstructor = getNewItem;
}
private _add(item: T) {
this._items[this._nextIndex] = item;
++this._nextIndex;
this._max = Math.max(this._max, this._nextIndex);
}
public reset() {
this._nextIndex = 0;
}
public get(index: number): T | undefined {
return this._items[index];
}
public size() {
return this._nextIndex;
}
public place(): T {
if (this._nextIndex >= this._max) {
//console.log('Adding new item at index', this._nextIndex);
const newItem = this._itemConstructor();
this._add(newItem);
return newItem;
} else {
++this._nextIndex;
//console.log('Returning item at index', this._nextIndex - 1);
return this._items[this._nextIndex - 1];
}
}
public max() {
return this._max;
}
}

View File

@ -156,11 +156,13 @@ export class OtS_BlockMesh_Converter {
let bestDistance = Infinity;
let bestCandidate: (string | null) = null;
const visibility = neighbourhood.getFaceVisibility(position.x, position.y, position.z);
if (visibility === null) {
return null;
}
for (const block of this._config.mode.data.blocks) {
const visibility = neighbourhood.getFaceVisibility(position.x, position.y, position.z);
if (visibility === null) {
return null;
}
const averageColour: RGBA = { r: 0, g: 0, b: 0, a: 0 };
{

View File

@ -1,24 +0,0 @@
import { LinearAllocator } from '../src/linear_allocator';
import { Vector3 } from '../src/vector';
test('RegExpBuilder', () => {
const vec = new LinearAllocator<Vector3>(() => {
return new Vector3(0, 0, 0);
});
expect(vec.size()).toBe(0);
expect(vec.max()).toBe(0);
const first = vec.place();
first.x = 1;
expect(vec.size()).toBe(1);
expect(vec.max()).toBe(1);
const second = vec.place();
second.x = 2;
expect(vec.size()).toBe(2);
expect(vec.max()).toBe(2);
vec.reset();
expect(vec.size()).toBe(0);
expect(vec.max()).toBe(2);
const newFirst = vec.place();
expect(newFirst.x).toBe(1);
});

View File

@ -30,3 +30,66 @@ test('Per-block', () => {
expect(blockMesh.isBlockAt(2, 0, 0)).toBe(true);
expect(blockMesh.getBlockAt(2, 0, 0)?.name).toBe('BLUE-BLOCK');
});
test('Per-face', () => {
const voxelMesh = new OtS_VoxelMesh();
voxelMesh.addVoxel(0, 0, 0, OtS_Colours.RED);
voxelMesh.addVoxel(0, -1, 0, OtS_Colours.BLUE);
voxelMesh.addVoxel(1, 0, 0, OtS_Colours.BLUE);
voxelMesh.addVoxel(-1, 0, 0, OtS_Colours.BLUE);
voxelMesh.addVoxel(0, 0, 1, OtS_Colours.BLUE);
voxelMesh.addVoxel(0, 0, -1, OtS_Colours.BLUE);
const converter = new OtS_BlockMesh_Converter();
converter.setConfig({
mode: {
type: 'per-face', data: {
blocks: [
{
name: 'RED-TOP-BLOCK',
textures: {
up: 'RED',
down: 'BLACK',
north: 'BLACK',
south: 'BLACK',
east: 'BLACK',
west: 'BLACK',
},
},
{
name: 'BLUE-BLOCK',
textures: {
up: 'BLUE',
down: 'BLUE',
north: 'BLUE',
south: 'BLUE',
east: 'BLUE',
west: 'BLUE',
},
},
{
name: 'KINDA-RED-BLOCK',
textures: {
up: 'KINDA-RED',
down: 'KINDA-RED',
north: 'KINDA-RED',
south: 'KINDA-RED',
east: 'KINDA-RED',
west: 'KINDA-RED',
},
}
],
textures: {
'RED': OtS_Colours.RED,
'BLACK': OtS_Colours.BLACK,
'BLUE': OtS_Colours.BLUE,
'KINDA-RED': { r: 0.5, g: 0.0, b: 0.0, a: 1.0 },
},
}
},
});
const blockMesh = converter.process(voxelMesh);
expect(blockMesh.getBlockCount()).toBe(6);
expect(blockMesh.getBlockAt(0, 0, 0)?.name).toBe('RED-TOP-BLOCK');
});