Skip to content

Instantly share code, notes, and snippets.

View lucasdamianjohnson's full-sized avatar

Lucas Damian Johnson lucasdamianjohnson

View GitHub Profile
@group(0) @binding(0) var<storage, read_write> WORLD_DATA: array<vec2u>;
struct TEMPLATE_DATA_STRUCT {
segment_1: u32,
segment_2: u32,
segment_3: array<u32,12>,
segment_4: array<u32,3>
}
@group(0) @binding(1) var<storage, read_write> TEMPLATE_DATA: array<TEMPLATE_DATA_STRUCT>;
@lucasdamianjohnson
lucasdamianjohnson / voxel-world-gen.wgsl
Last active December 11, 2023 21:50
voxel world gen on gpu
// NOTE!: vec3u is padded to by 4 bytes
@group(0) @binding(0) var<storage, read_write> worldData: array<vec2u>;
@group(0) @binding(1) var<uniform> processingOptions: vec3<f32>;
fn generate_column(column_position: vec3<f32>) {
//put code here
let minY: f32 = 10;
import http from "http";
import fs from "fs/promises";
const host = "localhost";
const port = 8000;
const getFile = async (path: string) => {
try {
return await fs.readFile(`./public/${path}`);
} catch (e) {
return new Uint8Array(1);
@lucasdamianjohnson
lucasdamianjohnson / positionhash.js
Last active October 31, 2022 16:35
A hash function for XYZ coordinates.
/**
Based on this article:
https://dmauro.com/post/77011214305/a-hashing-function-for-x-y-z-coordinates
*/
const mask = (n) => {
if (n >= 0) {
return 2 * n;
} else {
return -2 * n - 1;
}
@lucasdamianjohnson
lucasdamianjohnson / bytesetExample.ts
Last active November 27, 2021 17:12
Byte Set Example TypeScript
const chunk : number[][][] = [];
const blockBytes : number[] = [];
for(const x of chunk.keys()) {
for(const z of chunk[x].keys()) {
for(const y of chunk[x][z].keys()) {
const block = chunk[x][z][y];
if(!block)continue;
let blockByte = 0;
if(!chunk[x][z][y + 1]) {
blockByte = setBit(blockByte,0,1);
@lucasdamianjohnson
lucasdamianjohnson / getBit.ts
Created November 27, 2021 16:44
Get Bit From Byte In TypeScript
function getBit(number : number, index: number): 0 | 1 {
if (index > 7 || index < 0) {
throw new Error("Index is out of range. Acceptable range is 0 - 7");
}
const value = (number >>> index) & 1;
return <0 | 1>value;
}
@lucasdamianjohnson
lucasdamianjohnson / setBit.ts
Created November 27, 2021 16:30
Set Bit in TypeScript
function setBit(number : number,index: number, value: 0 | 1) {
if (index > 7 || index < 0) {
throw new Error("Index is out of range. Acceptable range is 0 - 7");
}
if (value < 0 || value > 1) {
throw new Error("Value is not in range. Acceptable range is 0 - 1");
}
const setValue = 1 << index;
if (!value) {
number = number & ~setValue;
@lucasdamianjohnson
lucasdamianjohnson / InfoByte.ts
Last active November 27, 2021 15:59
Encode Information In A Single Byte In TypeScript
type BinaryNums = 0 | 1;
type BinraryArray = BinaryNums[];
export class InfoByte {
constructor(private byteValue: number = 0) {}
getNumberValue() {
return this.byteValue;
}
const dsCom: DSCommander = require("dscom");
(async () => {
let mode = "";
dsCom.addParam({
flag : "m",
desc : "Program Mode",
name : "mode",
type : "string"
});
await dsCom.initProgramInput();
const dsCom: DSCommander = require("dscom");
(async () => {
dsCom
.ask("What is the first number?", "num1", "number")
.ask("What is the second number", "num2", "number");
await dsCom.startPrompt();
const num1 = parseInt(<string>dsCom.getInput("num1"));
const num2 = parseInt(<string>dsCom.getInput("num2"));
const total = num1 + num2;
dsCom.BR.C.logSleep([`${num1} + ${num2}`]).CLEAR.BR.G.logSleep([total]);