Galaxy Viewing
This commit is contained in:
parent
5617053f83
commit
cddeaf38a9
123 changed files with 11232 additions and 290 deletions
|
|
@ -33,7 +33,7 @@ public static class CultClient {
|
|||
if (Verified || m is LoginMessage || m is RegisterMessage || m is VerifyMessage)
|
||||
{
|
||||
Logger($"Sending message {MessagePackSerializer.SerializeToJson(m as Message)}");
|
||||
_peer.Send(m as Message);
|
||||
_peer.Send(m);
|
||||
}
|
||||
else OnError?.Invoke("Cannot send, client is not verified!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using UnityEditor;
|
|||
using UnityEngine;
|
||||
using static UnityEditor.EditorGUILayout;
|
||||
using Random = UnityEngine.Random;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[CustomEditor(typeof(Galaxy))]
|
||||
public class GalaxyEditor : Editor
|
||||
|
|
@ -69,10 +70,9 @@ public class GalaxyEditor : Editor
|
|||
}
|
||||
|
||||
GUILayout.Label("Preview", EditorStyles.boldLabel);
|
||||
_galaxyMat.SetFloat("Arms", galaxy.MapData.Arms);
|
||||
_galaxyMat.SetFloat("Twist", galaxy.MapData.Twist);
|
||||
_galaxyMat.SetFloat("TwistPower", galaxy.MapData.TwistPower);
|
||||
_galaxyMat.SetFloat("Arms", galaxy.MapData.Arms);
|
||||
_galaxyMat.SetFloat("Arms", galaxy.MapData.GlobalData.Arms);
|
||||
_galaxyMat.SetFloat("Twist", galaxy.MapData.GlobalData.Twist);
|
||||
_galaxyMat.SetFloat("TwistPower", galaxy.MapData.GlobalData.TwistPower);
|
||||
_galaxyMat.SetFloat("SpokeOffset", _currentLayer.SpokeOffset);
|
||||
_galaxyMat.SetFloat("SpokeScale", _currentLayer.SpokeScale);
|
||||
_galaxyMat.SetFloat("CoreBoost", _currentLayer.CoreBoost);
|
||||
|
|
@ -170,9 +170,9 @@ public class GalaxyEditor : Editor
|
|||
var accum = 0f;
|
||||
foreach (var hp in points.Select(p=>p+Random.insideUnitCircle * ((points[0]-points[1]).magnitude/2)))
|
||||
{
|
||||
var den = galaxy.MapData.StarDensity.Evaluate(hp, galaxy.MapData);
|
||||
var den = galaxy.MapData.StarDensity.Evaluate(hp, galaxy.MapData.GlobalData);
|
||||
if(!float.IsNaN(den))
|
||||
accum += den * Random.value;
|
||||
accum += saturate(den) * Random.value;
|
||||
// else
|
||||
// Debug.Log($"Density at ({hp.x},{hp.y}) is NaN");
|
||||
if (accum > 1 && (!stars.Any() || stars.Min(s=>(s-hp).magnitude) > _minStarDistance) )
|
||||
|
|
@ -283,6 +283,16 @@ public class GalaxyEditor : Editor
|
|||
Wormholes = star.Links.Select(i => starIDs[galaxy.MapData.Stars[i]]).ToList()
|
||||
}).Run(_connection);
|
||||
}
|
||||
|
||||
galaxy.MapData.GlobalData.MapLayers["StarDensity"] = galaxy.MapData.StarDensity.ID = Guid.NewGuid();
|
||||
R.Db("Aetheria").Table("Galaxy").Insert(galaxy.MapData.StarDensity).Run(_connection);
|
||||
foreach (var kvp in galaxy.MapData.ResourceDensities)
|
||||
{
|
||||
galaxy.MapData.GlobalData.MapLayers[kvp.Key] = kvp.Value.ID = Guid.NewGuid();
|
||||
R.Db("Aetheria").Table("Galaxy").Insert(kvp.Value).Run(_connection);
|
||||
}
|
||||
|
||||
R.Db("Aetheria").Table("Galaxy").Insert(galaxy.MapData.GlobalData).Run(_connection);
|
||||
}
|
||||
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
|
@ -321,6 +331,7 @@ public class GalaxyEditor : Editor
|
|||
layer.CoreBoost = FloatField("Core Boost", layer.CoreBoost);
|
||||
layer.CoreBoostOffset = FloatField("Core Boost Offset", layer.CoreBoostOffset);
|
||||
layer.CoreBoostPower = FloatField("Core Boost Power", layer.CoreBoostPower);
|
||||
layer.NoisePosition = FloatField("Noise Position", layer.NoisePosition);
|
||||
layer.NoiseOffset = FloatField("Noise Offset", layer.NoiseOffset);
|
||||
layer.NoiseAmplitude = FloatField("Noise Amplitude", layer.NoiseAmplitude);
|
||||
layer.NoiseGain = FloatField("Noise Gain", layer.NoiseGain);
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ public class SerializerTestWindow : EditorWindow
|
|||
|
||||
public void OnGUI()
|
||||
{
|
||||
var obj = new ShieldData() {ID = Guid.NewGuid(), Name = "Bar" , HeatPerformanceCurve = new []{float4(0,0,0,0), float4(1,1,1,1)}} as DatabaseEntry;
|
||||
|
||||
//var obj = new ShieldData() {ID = Guid.NewGuid(), Name = "Bar" , HeatPerformanceCurve = new []{float4(0,0,0,0), float4(1,1,1,1)}} as DatabaseEntry;
|
||||
var obj = new GalaxyRequestMessage() as Message;
|
||||
// JsonSerializer serializer = new JsonSerializer();
|
||||
// serializer.Converters.Add(new MathJsonConverter());
|
||||
// serializer.Converters.Add(Converter.DateTimeConverter);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ using JM.LinqFaster;
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using static NoiseFbm;
|
||||
|
||||
[CreateAssetMenu(menuName = "Aetheria/Galaxy")]
|
||||
public class Galaxy : ScriptableObject
|
||||
|
|
@ -20,15 +19,13 @@ public class Galaxy : ScriptableObject
|
|||
[Serializable]
|
||||
public class GalaxyMapData
|
||||
{
|
||||
public int Arms = 4;
|
||||
public float Twist = 10;
|
||||
public float TwistPower = 2;
|
||||
public GlobalData GlobalData = new GlobalData() {ID = Guid.NewGuid()};
|
||||
|
||||
[HideInInspector]
|
||||
public GalaxyMapLayerData StarDensity;
|
||||
public GalaxyMapLayerData StarDensity;
|
||||
[HideInInspector]
|
||||
public Dictionary<string,GalaxyMapLayerData> ResourceDensities = new Dictionary<string, GalaxyMapLayerData>();
|
||||
[HideInInspector]
|
||||
public Dictionary<string,GalaxyMapLayerData> ResourceDensities = new Dictionary<string, GalaxyMapLayerData>();
|
||||
//[HideInInspector]
|
||||
public List<StarData> Stars = new List<StarData>();
|
||||
}
|
||||
|
||||
|
|
@ -78,104 +75,6 @@ public class StarData
|
|||
public List<int> Links = new List<int>();
|
||||
}
|
||||
|
||||
public static class NoiseFbm
|
||||
{
|
||||
public static float fBm(float2 p, int octaves, float frequency, float offset, float amplitude, float lacunarity, float gain)
|
||||
{
|
||||
float freq = frequency, amp = .5f;
|
||||
float sum = 0;
|
||||
for(int i = 0; i < octaves; i++)
|
||||
{
|
||||
sum += snoise(p * freq) * amp;
|
||||
freq *= lacunarity;
|
||||
amp *= gain;
|
||||
}
|
||||
return (sum + offset)*amplitude;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class GalaxyMapLayerData
|
||||
{
|
||||
public float CoreBoost = 1.05f;
|
||||
public float CoreBoostOffset = .1f;
|
||||
public float CoreBoostPower = 2.25f;
|
||||
public float SpokeScale = 1;
|
||||
public float SpokeOffset = 0;
|
||||
public float EdgeReduction = 3;
|
||||
public float NoiseOffset = 0;
|
||||
public float NoiseAmplitude = 1.5f;
|
||||
public float NoiseGain = .7f;
|
||||
public float NoiseLacunarity = 2;
|
||||
public int NoiseOctaves = 7;
|
||||
public float NoiseFrequency = 1;
|
||||
public float NoisePosition = 1337;
|
||||
|
||||
public float Evaluate(float2 uv, GalaxyMapData galaxy)
|
||||
{
|
||||
float2 offset = -float2(.5f, .5f)+uv;
|
||||
float circle = (.5f-length(offset))*2;
|
||||
float angle = pow(length(offset)*2,galaxy.TwistPower) * galaxy.Twist;
|
||||
float2 twist = float2(offset.x*cos(angle) - offset.y*sin(angle), offset.x*sin(angle) + offset.y*cos(angle));
|
||||
float atan = atan2(twist.y,twist.x);
|
||||
float spokes = (sin(atan*galaxy.Arms) + SpokeOffset) * SpokeScale;
|
||||
float noise = fBm(uv + float2(NoisePosition), NoiseOctaves, NoiseFrequency, NoiseOffset, NoiseAmplitude, NoiseLacunarity, NoiseGain);
|
||||
float shape = lerp(spokes - EdgeReduction * length(offset), 1, pow(circle + CoreBoostOffset, CoreBoostPower) * CoreBoost);
|
||||
float gal = max(shape - noise * saturate(circle), 0);
|
||||
|
||||
return gal;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Vector2Extension {
|
||||
|
||||
public static Vector2 Rotate(this Vector2 v, float degrees) {
|
||||
float sin = Mathf.Sin(degrees * Mathf.Deg2Rad);
|
||||
float cos = Mathf.Cos(degrees * Mathf.Deg2Rad);
|
||||
|
||||
float tx = v.x;
|
||||
float ty = v.y;
|
||||
v.x = (cos * tx) - (sin * ty);
|
||||
v.y = (sin * tx) + (cos * ty);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class NameData
|
||||
{
|
||||
public Dictionary<string, Dictionary<string, List<string>>> Names = new Dictionary<string, Dictionary<string, List<string>>>();
|
||||
|
||||
public void Add(string dataString)
|
||||
{
|
||||
//Debug.Log("Adding " + dataString);
|
||||
var all = dataString.Split(',');
|
||||
var name = all[0].Split(" -.".ToCharArray(),StringSplitOptions.RemoveEmptyEntries).OrderByDescending(s=>s.Length).First();
|
||||
var region = all[1].Split('/');
|
||||
var continent = region[0];
|
||||
var capital = region[1];
|
||||
if(!Names.ContainsKey(continent))
|
||||
Names[continent] = new Dictionary<string, List<string>>();
|
||||
if(!Names[continent].ContainsKey(capital))
|
||||
Names[continent][capital] = new List<string>();
|
||||
Names[continent][capital].Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ContinentData
|
||||
{
|
||||
public string Name;
|
||||
public List<RegionData> Regions;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class RegionData
|
||||
{
|
||||
public string Name;
|
||||
public List<string> Towns;
|
||||
}
|
||||
|
||||
public class VoronoiLink
|
||||
{
|
||||
public Vertex2 point1;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class DatabaseCache
|
|||
var exists = _entries.ContainsKey(entry.ID);
|
||||
_entries[entry.ID] = entry;
|
||||
var type = entry.GetType();
|
||||
var types = type.FindInterfaces((_, __) => true, null).Append(type);
|
||||
var types = type.GetParentTypes();
|
||||
foreach (var t in types)
|
||||
{
|
||||
if(!_types.ContainsKey(t))
|
||||
|
|
|
|||
|
|
@ -76,6 +76,38 @@ public static class Extensions
|
|||
return InterfaceClasses[type] = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(ass => ass.GetTypes()).Where(t => t.IsClass && t.GetInterfaces().Contains(type)).ToArray();
|
||||
}
|
||||
|
||||
private static Dictionary<Type,Type[]> ParentTypes = new Dictionary<Type, Type[]>();
|
||||
|
||||
public static Type[] GetParentTypes(this Type type)
|
||||
{
|
||||
if (ParentTypes.ContainsKey(type))
|
||||
return ParentTypes[type];
|
||||
return ParentTypes[type] = type.GetParents().ToArray();
|
||||
}
|
||||
|
||||
private static IEnumerable<Type> GetParents(this Type type)
|
||||
{
|
||||
// is there any base type?
|
||||
if (type == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
// return all implemented or inherited interfaces
|
||||
foreach (var i in type.GetInterfaces())
|
||||
{
|
||||
yield return i;
|
||||
}
|
||||
|
||||
// return all inherited types
|
||||
var currentBaseType = type.BaseType;
|
||||
while (currentBaseType != null)
|
||||
{
|
||||
yield return currentBaseType;
|
||||
currentBaseType= currentBaseType.BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<Type,Type[]> ChildClasses = new Dictionary<Type, Type[]>();
|
||||
public static Type[] GetAllChildClasses(this Type type)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using static NoiseFbm;
|
||||
|
||||
[Serializable]
|
||||
[RethinkTable("Galaxy")]
|
||||
[MessagePackObject]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
@ -43,4 +49,93 @@ public class GlobalData : DatabaseEntry
|
|||
|
||||
[InspectableField] [JsonProperty("rosetteProbability")] [Key(12)]
|
||||
public float RosetteProbability = .25f;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyArms")] [Key(13)]
|
||||
public int Arms = 4;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyTwist")] [Key(14)]
|
||||
public float Twist = 10;
|
||||
|
||||
[InspectableField] [JsonProperty("galaxyTwistPower")] [Key(15)]
|
||||
public float TwistPower = 2;
|
||||
|
||||
[InspectableField] [JsonProperty("mapLayers")] [Key(16)]
|
||||
public Dictionary<string, Guid> MapLayers = new Dictionary<string, Guid>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[RethinkTable("Galaxy")]
|
||||
[MessagePackObject]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class GalaxyMapLayerData : DatabaseEntry
|
||||
{
|
||||
[InspectableField] [JsonProperty("coreBoost")] [Key(1)]
|
||||
public float CoreBoost = 1.05f;
|
||||
|
||||
[InspectableField] [JsonProperty("coreBoostOffset")] [Key(2)]
|
||||
public float CoreBoostOffset = .1f;
|
||||
|
||||
[InspectableField] [JsonProperty("coreBoostPower")] [Key(3)]
|
||||
public float CoreBoostPower = 2.25f;
|
||||
|
||||
[InspectableField] [JsonProperty("spokeScale")] [Key(4)]
|
||||
public float SpokeScale = 1;
|
||||
|
||||
[InspectableField] [JsonProperty("spokeOffset")] [Key(5)]
|
||||
public float SpokeOffset = 0;
|
||||
|
||||
[InspectableField] [JsonProperty("edgeReduction")] [Key(6)]
|
||||
public float EdgeReduction = 3;
|
||||
|
||||
[InspectableField] [JsonProperty("noiseOffset")] [Key(7)]
|
||||
public float NoiseOffset = 0;
|
||||
|
||||
[InspectableField] [JsonProperty("noiseAmplitude")] [Key(8)]
|
||||
public float NoiseAmplitude = 1.5f;
|
||||
|
||||
[InspectableField] [JsonProperty("noiseGain")] [Key(9)]
|
||||
public float NoiseGain = .7f;
|
||||
|
||||
[InspectableField] [JsonProperty("noiseLacunarity")] [Key(10)]
|
||||
public float NoiseLacunarity = 2;
|
||||
|
||||
[InspectableField] [JsonProperty("noiseOctaves")] [Key(11)]
|
||||
public int NoiseOctaves = 7;
|
||||
|
||||
[InspectableField] [JsonProperty("noiseFrequency")] [Key(12)]
|
||||
public float NoiseFrequency = 1;
|
||||
|
||||
[InspectableField] [JsonProperty("noisePosition")] [Key(13)]
|
||||
public float NoisePosition = 1337;
|
||||
|
||||
public float Evaluate(float2 uv, GlobalData data)
|
||||
{
|
||||
float2 offset = -float2(.5f, .5f)+uv;
|
||||
float circle = (.5f-length(offset))*2;
|
||||
float angle = pow(length(offset)*2,data.TwistPower) * data.Twist;
|
||||
float2 t = float2(offset.x*cos(angle) - offset.y*sin(angle), offset.x*sin(angle) + offset.y*cos(angle));
|
||||
float atan = atan2(t.y,t.x);
|
||||
float spokes = (sin(atan*data.Arms) + SpokeOffset) * SpokeScale;
|
||||
float noise = fBm(uv + float2(NoisePosition), NoiseOctaves, NoiseFrequency, NoiseOffset, NoiseAmplitude, NoiseLacunarity, NoiseGain);
|
||||
float shape = lerp(spokes - EdgeReduction * length(offset), 1, pow(circle + CoreBoostOffset, CoreBoostPower) * CoreBoost);
|
||||
float gal = max(shape - noise * saturate(circle), 0);
|
||||
|
||||
return gal;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NoiseFbm
|
||||
{
|
||||
public static float fBm(float2 p, int octaves, float frequency, float offset, float amplitude, float lacunarity, float gain)
|
||||
{
|
||||
float freq = frequency, amp = .5f;
|
||||
float sum = 0;
|
||||
for(int i = 0; i < octaves; i++)
|
||||
{
|
||||
sum += snoise(p * freq) * amp;
|
||||
freq *= lacunarity;
|
||||
amp *= gain;
|
||||
}
|
||||
return (sum + offset)*amplitude;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,11 @@ using Unity.Mathematics;
|
|||
[Union(5,typeof(LoginSuccessMessage))]
|
||||
[Union(6,typeof(ChatMessage))]
|
||||
[Union(7,typeof(ChatBroadcastMessage))]
|
||||
[Union(8,typeof(ChangeNameMessage))]
|
||||
[Union(9,typeof(GalaxyRequestMessage))]
|
||||
[Union(10,typeof(GalaxyResponseMessage))]
|
||||
[Union(11,typeof(ZoneRequestMessage))]
|
||||
[Union(12,typeof(ZoneResponseMessage))]
|
||||
[MessagePackObject]
|
||||
public abstract class Message
|
||||
{
|
||||
|
|
@ -79,12 +84,17 @@ public class ChangeNameMessage : Message
|
|||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class GalaxyRequestMessage : Message { }
|
||||
public class GalaxyRequestMessage : Message
|
||||
{
|
||||
//[Key(0)] public int RequiredByMessagePack;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class GalaxyResponseMessage : Message
|
||||
{
|
||||
[Key(0)] public GalaxyResponseZone[] Zones;
|
||||
[Key(1)] public GalaxyMapLayerData StarDensity;
|
||||
[Key(2)] public GlobalData GlobalData;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
Loading…
Reference in a new issue