fixed singleton initialization

This commit is contained in:
spatialfree 2022-08-03 22:06:43 -04:00
parent 893c10904a
commit fd15fe1e33
5 changed files with 55 additions and 19 deletions

View file

@ -1,8 +1,8 @@
namespace Oriels; namespace Oriels;
public class Mono { public class Mono {
private static readonly Lazy<Mono> lazy = new Lazy<Mono>(() => new Mono()); private static readonly Lazy<Oriels.Mono> lazy = new Lazy<Oriels.Mono>(() => new Oriels.Mono());
public static Mono inst { get { return lazy.Value; } } public static Oriels.Mono inst { get { return lazy.Value; } }
public PullRequest.Noise noise = new PullRequest.Noise(939949595); public PullRequest.Noise noise = new PullRequest.Noise(939949595);
@ -34,6 +34,9 @@ public class Mono {
public Mono() { public Mono() {
Renderer.SetClip(0.02f, 1000f); Renderer.SetClip(0.02f, 1000f);
}
public void Init() {
spaceMono.Init(); spaceMono.Init();
} }

View file

@ -111,7 +111,7 @@ public static class PullRequest {
} }
int position; int position;
public float value { public float uvalue {
get { get {
float v = RNG(position, seed) / (float)CAP; float v = RNG(position, seed) / (float)CAP;
position++; position++;
@ -119,8 +119,14 @@ public static class PullRequest {
} }
} }
public float D1(int position) { public float value { // not ideal *loss of precision*
return RNG(position, seed) / (float)CAP; get {
return uvalue * 2 - 1;
}
}
public float D1(int pos) {
return RNG(pos, seed) / (float)CAP;
} }
public float D2(int x, int y) { public float D2(int x, int y) {
@ -136,8 +142,8 @@ public static class PullRequest {
return RNG(x + (PRIME1 * y) + (PRIME2 * z), seed) / (float)CAP; return RNG(x + (PRIME1 * y) + (PRIME2 * z), seed) / (float)CAP;
} }
public uint RNG(int position, uint seed) { public uint RNG(int pos, uint seed) {
uint mangled = (uint)position; uint mangled = (uint)pos;
mangled *= BIT_NOISE1; mangled *= BIT_NOISE1;
mangled += seed; mangled += seed;
mangled ^= mangled >> 8; mangled ^= mangled >> 8;

View file

@ -10,7 +10,7 @@ using System.Collections.Generic;
namespace Space; namespace Space;
public class Mono { public class Mono {
Node[] nodes = new Node[18];
Vec3 playerPos; Vec3 playerPos;
List<Vec3> enemies = new List<Vec3>(); List<Vec3> enemies = new List<Vec3>();
float spawnTime; float spawnTime;
@ -26,12 +26,25 @@ public class Mono {
} }
public void Init() { public void Init() {
Oriels.PullRequest.Noise noise = Oriels.Mono.inst.noise;
// place nodes around a 10x4x10 cube
for (int i = 0; i < nodes.Length; i++) {
nodes[i] = new Node(
new Vec3(
noise.value * 5f,
noise.value * 2f,
noise.value * 5f
)
);
}
meshCube = Mesh.Cube; meshCube = Mesh.Cube;
} }
public void Frame() { public void Frame() {
Rig rig = Oriels.Mono.inst.rig; Oriels.Rig rig = Oriels.Mono.inst.rig;
Oriel oriel = Oriels.Mono.inst.oriel; Oriels.Oriel oriel = Oriels.Mono.inst.oriel;
Matrix simMatrix = Matrix.TRS( Matrix simMatrix = Matrix.TRS(
new Vec3(0, 0, 0), //-oriel.bounds.dimensions.y / 2.01f, -playerWorldPos.z), new Vec3(0, 0, 0), //-oriel.bounds.dimensions.y / 2.01f, -playerWorldPos.z),
@ -65,8 +78,14 @@ public class Mono {
// RENDER // RENDER
for (int i = 0; i < nodes.Length; i++) {
meshCube.Draw(oriel.matOriel,
Matrix.TRS(nodes[i].pos, Quat.Identity, Vec3.One * 1f) * simMatrix * oriel.matrix.Inverse,
Color.White
);
}
meshCube.Draw(oriel.matOriel, meshCube.Draw(oriel.matOriel,
Matrix.TRS(cursor, Quat.Identity, Vec3.One * 0.02f), Matrix.TRS(cursor, Quat.Identity, Vec3.One * 0.02f),
new Color(1f, 1f, 1f) new Color(1f, 1f, 1f)
@ -153,3 +172,11 @@ public class Mono {
float moveP = 8f; float moveP = 8f;
float moveI = 0.2f; float moveI = 0.2f;
} }
public class Node {
public Vec3 pos;
public Node(Vec3 pos) {
this.pos = pos;
}
}

View file

@ -1,5 +1,4 @@
using System; namespace Oriels;
using StereoKit;
public abstract class SpatialCursor { public abstract class SpatialCursor {
public Vec3 p0, p1, p2, p3; public Vec3 p0, p1, p2, p3;
@ -26,7 +25,7 @@ public class StretchCursor : SpatialCursor {
model.Draw(Matrix.TS(p0, 0.06f)); model.Draw(Matrix.TS(p0, 0.06f));
} }
public override void Calibrate() {} public override void Calibrate() { }
} }
public class ReachCursor : SpatialCursor { public class ReachCursor : SpatialCursor {
@ -80,7 +79,7 @@ public class TwistCursor : SpatialCursor {
Quat from = Quat.LookAt(Vec3.Zero, quat * Vec3.Forward, twistFrom); Quat from = Quat.LookAt(Vec3.Zero, quat * Vec3.Forward, twistFrom);
float twist = (float)(Math.Acos(Vec3.Dot(from * Vec3.Up, quat * Vec3.Up)) / Math.PI); float twist = (float)(Math.Acos(Vec3.Dot(from * Vec3.Up, quat * Vec3.Up)) / Math.PI);
outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0; outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0;
p0 = pos + quat * Vec3.Forward * twist * str; p0 = pos + quat * Vec3.Forward * twist * str;
// Render // Render
@ -174,7 +173,7 @@ public class CubicFlow : SpatialCursor {
// if toggle // if toggle
} }
public override void Calibrate() {} public override void Calibrate() { }
} }
// a more symmetrical one would be cool // a more symmetrical one would be cool

View file

@ -1,6 +1,6 @@
global using System; global using System;
global using StereoKit; global using StereoKit;
global using Oriels; // global using Oriels;
SKSettings settings = new SKSettings { SKSettings settings = new SKSettings {
appName = "oriels", appName = "oriels",
@ -14,8 +14,9 @@ if (!SK.Initialize(settings))
Input.HandSolid(Handed.Max, false); Input.HandSolid(Handed.Max, false);
Input.HandVisible(Handed.Max, true); Input.HandVisible(Handed.Max, true);
Mono mono = Mono.inst; Oriels.Mono mono = Oriels.Mono.inst;
mono.Init();
while (SK.Step(() => { while (SK.Step(() => {
mono.Step(); mono.Step();
})) ; }));
SK.Shutdown(); SK.Shutdown();