Skip to content

Commit

Permalink
2024/01/11 - Debug playground setup
Browse files Browse the repository at this point in the history
  • Loading branch information
FadiShawki committed Jan 11, 2024
1 parent 475a46c commit cc5e1d5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/@orbitmines/explorer/OrbitMinesExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const Line = ({ start, mid, end, scale, color = line.color }: any) =>
lineWidth={line.width * scale}
/>

const circle = { radius: 3, color: "orange", segments: 30, }
export const circle = { radius: 3, color: "orange", segments: 30, }
export const Vertex = ({ position, color = circle.color }: any) =>
<Circle position={position} material-color={color} args={[circle.radius, circle.segments]} />

Expand Down
41 changes: 36 additions & 5 deletions src/@orbitmines/explorer/Ray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from "lodash";
import {NotImplementedError, PreventsImplementationBug} from "./errors/errors";
import {InterfaceOptions} from "./OrbitMinesExplorer";


// SHOULDNT CLASSIFY THESE?
Expand Down Expand Up @@ -480,25 +481,55 @@ export class Ray // Other possibly names: AbstractDirectionality, ..., ??


//TODO USED FOR DEBUG NOW
move = (func: (self: Ray) => Ray, traversed: Ray[]): Ray => {
move = (func: (self: Ray) => Ray, memory: boolean, Interface: Ray): Ray => {
const target_ray = func(this.self);
const target = target_ray.as_reference().o({
...this._dirty_store,
position:
target_ray.any.position
?? this.self.any.position
?? [0, 0, 0]
?? Ray.POSITION_OF_DOOM
});
console.log('move', `${this.self.label.split(' ')[0]} -> ${target.self.label.split(' ')[0]}`);

if (!target_ray.any.traversed) {
traversed.push(target);
target_ray.any.traversed = true;
if (memory) {
if (!target_ray.any.traversed) {
Interface.any.rays.push(target);
target_ray.any.traversed = true;
}
} else {
Interface.any.rays = [target];
}

return target;
}

static POSITION_OF_DOOM = [0, 300, 0]

// TODO: Abstract away as compilation
get render_options(): Required<InterfaceOptions> {
return ({
position:
this.self.any.position
?? (this.is_none() ? Ray.POSITION_OF_DOOM : [0, 0, 0]),
rotation:
this.self.any.rotation
?? [0, 0, 0],
scale:
this.self.any.scale
?? (this.is_none() ? 1.5 : 1.5),
color:
this.self.any.color
?? (this.is_none() ? 'red' : {
[RayType.VERTEX]: 'orange',
[RayType.TERMINAL]: '#FF5555',
[RayType.INITIAL]: '#5555FF',
[RayType.REFERENCE]: '#555555',
}[this.type]
)
});
}

debug = (c: DebugResult): DebugRay => {
if (c[this.label] !== undefined)
return c[this.label]!;
Expand Down
39 changes: 16 additions & 23 deletions src/@orbitmines/explorer/debug/DebugCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
_Continuation, _Vertex,
add,
AutoRay,
AutoVertex,
AutoVertex, circle,
InterfaceOptions,
Line,
SimpleRenderedRay,
Expand All @@ -31,12 +31,14 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => {
} = useThree();

const space_between = 20 * scale;

const memory = true;

const [Interface] = useState<Ray>(Ray.vertex().o({
selection: Ray
.vertex().o({ position: [0, 0, 0], scale, color: 'orange' })
.initial.o({ position: [-space_between, 0, 0] }).terminal
.terminal.o({ position: [space_between, 0, 0 ]}).initial
.vertex().o({ position: [0, 0, 0], scale, color: '#FF55FF' })
.initial.o({ position: [-space_between, 0, 0], scale }).terminal
.terminal.o({ position: [space_between, 0, 0 ], scale }).initial
.as_reference().o({
position: [0, 0, 0],
scale,
Expand All @@ -49,17 +51,17 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => {
hotkeys: [
{
combo: "a", global: true, label: "", onKeyDown: () => {
Interface.any.selection = Interface.any.selection.move((self: Ray) => self.initial, Interface.any.rays);
Interface.any.selection = Interface.any.selection.move((self: Ray) => self.initial, memory, Interface);
}
},
{
combo: "d", global: true, label: "", onKeyDown: () => {
Interface.any.selection = Interface.any.selection.move((self: Ray) => self.terminal, Interface.any.rays);
Interface.any.selection = Interface.any.selection.move((self: Ray) => self.terminal, memory, Interface);
}
},
{
combo: "w", global: true, label: "", onKeyDown: () => {
Interface.any.selection = Interface.any.selection.move((self: Ray) => self.self, Interface.any.rays);
Interface.any.selection = Interface.any.selection.move((self: Ray) => self.self, memory, Interface);
}
},
{
Expand All @@ -83,32 +85,23 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => {

hotkeyConfig.set(...hotkeys);

const render: { [TKey in keyof InterfaceOptions]: (ray: Ray) => InterfaceOptions[TKey] } = {
position: (ray: Ray) => ray.self.any.position ?? (ray.is_none() ? [0, 400, 0] : [0, 0, 0]),
rotation: (ray: Ray) => ray.self.any.rotation ?? [0, 0, 0],
scale: (ray: Ray): number => ray.self.any.scale ?? (ray.is_none() ? 1.5 : 1.5),
color: (ray: Ray): string => ray.self.any.color ?? (ray.is_none() ? 'red' : 'orange'),
}

const options = (ray: Ray): Required<InterfaceOptions> => _.mapValues(render, (func: any) => func(ray)) as Required<InterfaceOptions>;

const Render = ({ ray }: { ray: Ray }) => {
const initial: Required<InterfaceOptions> = options(ray.self.initial.as_reference());
const vertex: Required<InterfaceOptions> = options(ray);
const terminal: Required<InterfaceOptions> = options(ray.self.terminal.as_reference());
const initial: Required<InterfaceOptions> = ray.self.initial.as_reference().render_options;
const vertex: Required<InterfaceOptions> = ray.render_options;
const terminal: Required<InterfaceOptions> = ray.self.terminal.as_reference().render_options;

switch (ray.type) {
case RayType.REFERENCE:
return <AutoVertex position={Interface.any.selection.self.position} rotation={[0, 0, Math.PI / 2]} scale={0.75} color="#55FF55" />
return <AutoVertex position={Interface.any.selection.self.position} rotation={[0, 0, Math.PI / 2]} scale={scale / 2} color="#55FF55" />
case RayType.INITIAL: {
return <>
<Line start={terminal.position} end={add(vertex.position, [torus.radius * vertex.scale, 0, 0])} {..._.pick(vertex, 'color', 'scale')} />
<Line start={add(terminal.position, [-circle.radius * vertex.scale, 0, 0])} end={add(vertex.position, [torus.radius * vertex.scale, 0, 0])} {..._.pick(vertex, 'color', 'scale')} />
<_Continuation {...vertex} />
</>
}
case RayType.TERMINAL: {
return <>
<Line start={initial.position} end={add(vertex.position, [-torus.radius * vertex.scale, 0, 0])} {..._.pick(vertex, 'color', 'scale')} />
<Line start={add(initial.position, [circle.radius * vertex.scale, 0, 0])} end={add(vertex.position, [-torus.radius * vertex.scale, 0, 0])} {..._.pick(vertex, 'color', 'scale')} />
<_Continuation {...vertex} />
</>
}
Expand All @@ -121,7 +114,7 @@ const DebugInterface = ({ scale = 1.5 }: InterfaceOptions) => {
return <>
{Interface.any.stats ? <StatsPanels/> : <></>}

<AutoVertex position={(Interface.any.selection as Ray).any.position} rotation={[0, 0, Math.PI / 5]} scale={0.75} color="#555555" />
<AutoVertex position={(Interface.any.selection as Ray).any.position} rotation={[0, 0, Math.PI / 5]} scale={scale / 2} color="#555555" />

{/*{Interface.any.rays.map((ray: Ray) => <Render key={ray.label} ray={ray} />)}*/}
{Interface.any.rays.map((ray: Ray) => <Render key={ray.self.label} ray={ray} />)}
Expand Down

0 comments on commit cc5e1d5

Please sign in to comment.