Asteroids & Refactoring
We have proper belts that hug the Grid, reactive properties for planet instance data, and more!
This commit is contained in:
parent
a981a46170
commit
1f90d3639a
42 changed files with 614 additions and 597 deletions
|
|
@ -62,7 +62,6 @@
|
|||
<e p="EditorDispatch.cs" t="Include" />
|
||||
<e p="GalaxyEditor.cs" t="Include" />
|
||||
<e p="SerializerTestWindow.cs" t="Include" />
|
||||
<e p="ZoneEditor.cs" t="Include" />
|
||||
</e>
|
||||
<e p="Galaxy.cs" t="Include" />
|
||||
<e p="Gravity.cs" t="Include" />
|
||||
|
|
@ -1249,11 +1248,11 @@
|
|||
<e p="RethinkConnection.cs" t="Include" />
|
||||
<e p="Sector Display" t="Include">
|
||||
<e p="BlueNoiseProvider.cs" t="Include" />
|
||||
<e p="GameSettings.cs" t="Include" />
|
||||
<e p="GasGiantObject.cs" t="Include" />
|
||||
<e p="GradientMapper.cs" t="Include" />
|
||||
<e p="GravityObject.cs" t="Include" />
|
||||
<e p="PlanetObject.cs" t="Include" />
|
||||
<e p="SectorDisplayProperties.cs" t="Include" />
|
||||
<e p="SectorRenderer.cs" t="Include" />
|
||||
<e p="SnapToGrid.cs" t="Include" />
|
||||
<e p="SunMaterial.cs" t="Include" />
|
||||
|
|
@ -1774,6 +1773,7 @@
|
|||
<e p="PlayerData.cs" t="Include" />
|
||||
<e p="Rect.cs" t="Include" />
|
||||
<e p="RegisterResolver.cs" t="Include" />
|
||||
<e p="Settings.cs" t="Include" />
|
||||
<e p="Ship.cs" t="Include" />
|
||||
<e p="TypeFormatterResolver.cs" t="Include" />
|
||||
<e p="Zone.cs" t="Include" />
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@
|
|||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\MethodDrawers\ButtonMethodDrawer.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\Attributes\NativePropertyDrawerAttribute.cs" />
|
||||
<Compile Include="Assets\Scripts\Editor\SerializerTestWindow.cs" />
|
||||
<Compile Include="Assets\Scripts\Editor\ZoneEditor.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\PropertyDrawers\PropertyDrawer.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\CodeGeneration\PropertyValidatorDatabase.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\PropertyDrawConditions\PropertyDrawCondition.cs" />
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@
|
|||
<Compile Include="Assets\Scripts\NIH\MSAGL\DebugHelpers\Persistence\DoubleStreamElement.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\MSAGL\Core\Geometry\OverlapRemoval\OverlapRemovalNode.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\MSAGL\Routing\Spline\Bundling\Station.cs" />
|
||||
<Compile Include="Assets\Scripts\Sector Display\SectorDisplayProperties.cs" />
|
||||
<Compile Include="Assets\Scripts\Sector Display\GameSettings.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\MSAGL\ValidateArg.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\MSAGL\DebugHelpers\Persistence\CurveStreamElement.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\MSAGL\Routing\Rectilinear\Nudging\PointByDelegateComparer.cs" />
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Material:
|
|||
- _GlossMapScale: 1
|
||||
- _Glossiness: 1
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 1
|
||||
- _Metallic: 0.5
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
|
|
@ -73,6 +73,6 @@ Material:
|
|||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 0.4811321, g: 0.4811321, b: 0.4811321, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ MonoBehaviour:
|
|||
GravityWell: {fileID: 3973935121058605871}
|
||||
Icon: {fileID: 3973935121358855037}
|
||||
SunMaterial: {fileID: 3973935122748960685}
|
||||
GradientMapper: {fileID: 3973935122748960681}
|
||||
GravityWaves: {fileID: 3973935122114073485}
|
||||
--- !u!1 &3973935121058605867
|
||||
GameObject:
|
||||
|
|
@ -308,7 +307,6 @@ GameObject:
|
|||
- component: {fileID: 3973935122748960684}
|
||||
- component: {fileID: 3973935122748960683}
|
||||
- component: {fileID: 3973935122748960682}
|
||||
- component: {fileID: 3973935122748960681}
|
||||
- component: {fileID: 3973935122748960685}
|
||||
m_Layer: 0
|
||||
m_Name: Sphere
|
||||
|
|
@ -393,50 +391,6 @@ SphereCollider:
|
|||
serializedVersion: 2
|
||||
m_Radius: 0.5
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &3973935122748960681
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3973935122748960663}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6d2f8d4338ab9044cb603b1d3e8f189a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
GradientMapDimensions: {x: 32, y: 1}
|
||||
Gradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0.20392157, g: 0.23391679, b: 0.32941177, a: 1}
|
||||
key1: {r: 0.8314088, g: 1, b: 0.34901965, a: 1}
|
||||
key2: {r: 1, g: 1, b: 1, a: 0}
|
||||
key3: {r: 0.09173481, g: 0.054901946, b: 0.6156863, a: 0}
|
||||
key4: {r: 0.16108933, g: 0.18867922, b: 0.16568764, a: 0}
|
||||
key5: {r: 1, g: 1, b: 1, a: 0}
|
||||
key6: {r: 0.287, g: 0.287, b: 0.287, a: 0}
|
||||
key7: {r: 1, g: 1, b: 1, a: 0}
|
||||
ctime0: 9830
|
||||
ctime1: 19468
|
||||
ctime2: 32189
|
||||
ctime3: 40285
|
||||
ctime4: 59174
|
||||
ctime5: 65535
|
||||
ctime6: 41056
|
||||
ctime7: 65535
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 6
|
||||
m_NumAlphaKeys: 2
|
||||
Testing: 0
|
||||
Texture: {fileID: 0}
|
||||
--- !u!114 &3973935122748960685
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ MonoBehaviour:
|
|||
GravityWell: {fileID: 7852221720969441484}
|
||||
Icon: {fileID: 7852221720964551246}
|
||||
SunMaterial: {fileID: 7852221720971737234}
|
||||
GradientMapper: {fileID: 7852221720971737235}
|
||||
GravityWaves: {fileID: 7852221720741322894}
|
||||
FogTint: {fileID: 7852221720816817929}
|
||||
Light: {fileID: 8064377225639657765}
|
||||
|
|
@ -392,7 +391,6 @@ GameObject:
|
|||
- component: {fileID: 7852221720971737230}
|
||||
- component: {fileID: 7852221720971737229}
|
||||
- component: {fileID: 7852221720971737228}
|
||||
- component: {fileID: 7852221720971737235}
|
||||
- component: {fileID: 7852221720971737234}
|
||||
- component: {fileID: 8064377225639657765}
|
||||
m_Layer: 0
|
||||
|
|
@ -478,50 +476,6 @@ SphereCollider:
|
|||
serializedVersion: 2
|
||||
m_Radius: 0.5
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &7852221720971737235
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7852221720971737232}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6d2f8d4338ab9044cb603b1d3e8f189a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
GradientMapDimensions: {x: 32, y: 1}
|
||||
Gradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0, g: 0, b: 0, a: 1}
|
||||
key1: {r: 0.70199996, g: 0, b: 0, a: 1}
|
||||
key2: {r: 0.88699996, g: 0.32692656, b: 0.04688985, a: 0}
|
||||
key3: {r: 0.36200017, g: 0.043000042, b: 1, a: 0}
|
||||
key4: {r: 1, g: 1, b: 1, a: 0}
|
||||
key5: {r: 1, g: 0.99469995, b: 0.45098042, a: 0}
|
||||
key6: {r: 0.287, g: 0.287, b: 0.287, a: 0}
|
||||
key7: {r: 1, g: 1, b: 1, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 6695
|
||||
ctime2: 19184
|
||||
ctime3: 30257
|
||||
ctime4: 65535
|
||||
ctime5: 45707
|
||||
ctime6: 41056
|
||||
ctime7: 65535
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_NumColorKeys: 5
|
||||
m_NumAlphaKeys: 2
|
||||
Testing: 0
|
||||
Texture: {fileID: 0}
|
||||
--- !u!114 &7852221720971737234
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
BIN
Assets/Resources/Sector Display Properties.asset
(Stored with Git LFS)
BIN
Assets/Resources/Sector Display Properties.asset
(Stored with Git LFS)
Binary file not shown.
BIN
Assets/Resources/Settings.asset
(Stored with Git LFS)
Normal file
BIN
Assets/Resources/Settings.asset
(Stored with Git LFS)
Normal file
Binary file not shown.
|
|
@ -2146,8 +2146,8 @@ RectTransform:
|
|||
m_Father: {fileID: 1276686346}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchorMin: {x: 0, y: 0.070361555}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 20, y: 20}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
|
|
@ -5223,7 +5223,7 @@ GameObject:
|
|||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &460484049
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -9808,10 +9808,10 @@ RectTransform:
|
|||
m_Father: {fileID: 1698810628}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 943.50006, y: 0}
|
||||
m_SizeDelta: {x: 1887.0001, y: 0}
|
||||
m_AnchorMin: {x: 0, y: 1}
|
||||
m_AnchorMax: {x: 0, y: 1}
|
||||
m_AnchoredPosition: {x: 943.50006, y: -263.485}
|
||||
m_SizeDelta: {x: 1887.0001, y: 526.97}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &825923021
|
||||
MonoBehaviour:
|
||||
|
|
@ -11685,6 +11685,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 39f95af24dd29a645895a57a75460b0c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2}
|
||||
SectorRenderer: {fileID: 1009503731}
|
||||
TopDownCamera: {fileID: 887677622}
|
||||
FollowCamera: {fileID: 887677622}
|
||||
|
|
@ -11715,7 +11716,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
FogCameraParent: {fileID: 1547889399}
|
||||
Properties: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2}
|
||||
Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2}
|
||||
SectorRoot: {fileID: 2095699057}
|
||||
SectorBrushes: {fileID: 1037490739}
|
||||
SceneCamera: {fileID: 887677622}
|
||||
|
|
@ -12756,7 +12757,7 @@ RectTransform:
|
|||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 825923020}
|
||||
m_RootOrder: 1
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
|
|
@ -16971,9 +16972,9 @@ RectTransform:
|
|||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: -17, y: 0}
|
||||
m_Pivot: {x: 0, y: 1}
|
||||
--- !u!114 &1562936814
|
||||
MonoBehaviour:
|
||||
|
|
@ -18924,8 +18925,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: -0.00012207031}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 37.07837}
|
||||
m_SizeDelta: {x: 0, y: 37.07843}
|
||||
m_Pivot: {x: 0, y: 1}
|
||||
--- !u!114 &1698810629
|
||||
MonoBehaviour:
|
||||
|
|
@ -20342,9 +20343,9 @@ RectTransform:
|
|||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 20}
|
||||
m_SizeDelta: {x: -17, y: 20}
|
||||
m_Pivot: {x: 0, y: 0}
|
||||
--- !u!114 &1850578696
|
||||
MonoBehaviour:
|
||||
|
|
|
|||
BIN
Assets/Scenes/ARPG_Profiles/Postprocessing Profile.asset
(Stored with Git LFS)
BIN
Assets/Scenes/ARPG_Profiles/Postprocessing Profile.asset
(Stored with Git LFS)
Binary file not shown.
|
|
@ -12,6 +12,7 @@ using float2 = Unity.Mathematics.float2;
|
|||
|
||||
public class ActionGameManager : MonoBehaviour
|
||||
{
|
||||
public GameSettings Settings;
|
||||
public SectorRenderer SectorRenderer;
|
||||
public CinemachineVirtualCamera TopDownCamera;
|
||||
public CinemachineVirtualCamera FollowCamera;
|
||||
|
|
@ -38,28 +39,28 @@ public class ActionGameManager : MonoBehaviour
|
|||
var zonePack = File.Exists(zoneFile) ?
|
||||
MessagePackSerializer.Deserialize<ZonePack>(File.ReadAllBytes(zoneFile)) :
|
||||
ZoneGenerator.GenerateZone(
|
||||
context: Context,
|
||||
name: Guid.NewGuid().ToString().Substring(0,8),
|
||||
position: float2.zero,
|
||||
mapLayers: Context.MapLayers.Values,
|
||||
settings: Settings.ZoneSettings,
|
||||
mapLayers: Context.MapLayers,
|
||||
resources: Context.Resources,
|
||||
mass: 100000,
|
||||
radius: 1500
|
||||
mass: Settings.DefaultZoneMass,
|
||||
radius: Settings.DefaultZoneRadius
|
||||
);
|
||||
|
||||
Zone = Context.GetZone(zonePack);
|
||||
SectorRenderer.Context = Context;
|
||||
Zone = new Zone(Settings.PlanetSettings, zonePack);
|
||||
SectorRenderer.LoadZone(Zone);
|
||||
|
||||
ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
|
||||
// ConsoleController.AddCommand("savezone", args =>
|
||||
// {
|
||||
// if (args.Length > 0)
|
||||
// Zone.Value.Data.Name = args[0];
|
||||
// SaveZone();
|
||||
// });
|
||||
ConsoleController.AddCommand("savezone", args =>
|
||||
{
|
||||
if (args.Length > 0)
|
||||
Zone.Data.Name = args[0];
|
||||
SaveZone();
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveZone() => File.WriteAllBytes(
|
||||
Path.Combine(_filePath.FullName, $"{Zone.Data.Name}.zone"), MessagePackSerializer.Serialize(Zone.Pack()));
|
||||
|
||||
public void ToggleEditMode()
|
||||
{
|
||||
_editMode = !_editMode;
|
||||
|
|
@ -74,6 +75,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
_time += Time.deltaTime;
|
||||
Context.Time = Time.time;
|
||||
}
|
||||
Context.Update();
|
||||
Zone.Update(_time, Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ public class DatabaseListView : EditorWindow
|
|||
private Dictionary<Guid, HashSet<Guid>> _itemBlueprints = new Dictionary<Guid, HashSet<Guid>>();
|
||||
private HashSet<Guid> _itemBlueprintFoldouts = new HashSet<Guid>();
|
||||
private HashSet<string> _itemGroupFoldouts = new HashSet<string>();
|
||||
private DirectoryInfo _filePath;
|
||||
|
||||
public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black;
|
||||
|
||||
|
|
@ -56,6 +57,7 @@ public class DatabaseListView : EditorWindow
|
|||
|
||||
void OnEnable()
|
||||
{
|
||||
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
// Create database cache
|
||||
_databaseCache = new DatabaseCache();
|
||||
|
||||
|
|
@ -169,12 +171,12 @@ public class DatabaseListView : EditorWindow
|
|||
|
||||
if (GUILayout.Button("Save"))
|
||||
{
|
||||
_databaseCache.Save(new DirectoryInfo(Application.dataPath).Parent.FullName);
|
||||
_databaseCache.Save(_filePath.FullName);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Load"))
|
||||
{
|
||||
_databaseCache.Load(new DirectoryInfo(Application.dataPath).Parent.FullName);
|
||||
_databaseCache.Load(_filePath.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ public class GalaxyEditor : Editor
|
|||
}
|
||||
|
||||
GUILayout.Label("Preview", EditorStyles.boldLabel);
|
||||
_galaxyMat.SetFloat("Arms", galaxy.MapData.GlobalData.Arms);
|
||||
_galaxyMat.SetFloat("Twist", galaxy.MapData.GlobalData.Twist);
|
||||
_galaxyMat.SetFloat("TwistPower", galaxy.MapData.GlobalData.TwistPower);
|
||||
_galaxyMat.SetFloat("Arms", galaxy.MapData.ShapeSettings.Arms);
|
||||
_galaxyMat.SetFloat("Twist", galaxy.MapData.ShapeSettings.Twist);
|
||||
_galaxyMat.SetFloat("TwistPower", galaxy.MapData.ShapeSettings.TwistExponent);
|
||||
_galaxyMat.SetFloat("SpokeOffset", _currentLayer.SpokeOffset);
|
||||
_galaxyMat.SetFloat("SpokeScale", _currentLayer.SpokeScale);
|
||||
_galaxyMat.SetFloat("CoreBoost", _currentLayer.CoreBoost);
|
||||
|
|
@ -168,7 +168,7 @@ 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.GlobalData);
|
||||
var den = galaxy.MapData.StarDensity.Evaluate(hp, galaxy.MapData.ShapeSettings);
|
||||
if(!float.IsNaN(den))
|
||||
accum += saturate(den) * Random.value;
|
||||
// else
|
||||
|
|
@ -292,7 +292,7 @@ public class GalaxyEditor : Editor
|
|||
R.Db("Aetheria").Table("Galaxy").Insert(data).Run(_connection);
|
||||
}
|
||||
|
||||
R.Db("Aetheria").Table("Galaxy").Insert(galaxy.MapData.GlobalData).Run(_connection);
|
||||
R.Db("Aetheria").Table("Galaxy").Insert(galaxy.MapData.ShapeSettings).Run(_connection);
|
||||
}
|
||||
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MessagePack;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ZoneEditor : EditorWindow
|
||||
{
|
||||
// Singleton to avoid multiple instances of window.
|
||||
private static ZoneEditor _instance;
|
||||
public static ZoneEditor Instance => _instance ?? GetWindow<ZoneEditor>();
|
||||
[MenuItem("Window/Aetheria/Zone Editor")]
|
||||
static void Init() => Instance.Show();
|
||||
|
||||
private SectorRenderer _sectorRenderer;
|
||||
private DirectoryInfo _filePath;
|
||||
private GameContext _context;
|
||||
private DatabaseCache _cache;
|
||||
private Zone _zone;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_instance = this;
|
||||
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
|
||||
// Create Game Context
|
||||
_cache = new DatabaseCache();
|
||||
_cache.Load(_filePath.FullName);
|
||||
_context = new GameContext(_cache, Debug.Log);
|
||||
|
||||
// Find Sector Renderer and apply context
|
||||
_sectorRenderer = FindObjectOfType<SectorRenderer>();
|
||||
_sectorRenderer.Context = _context;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (GUILayout.Button("Load Zone"))
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
foreach(var file in _filePath.EnumerateFiles("*.zone"))
|
||||
menu.AddItem(new GUIContent(file.Name), false, () => LoadZone(file));
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear Zone"))
|
||||
_sectorRenderer.ClearZone();
|
||||
|
||||
if (GUILayout.Button("Save Zone"))
|
||||
SaveZone();
|
||||
|
||||
if (GUILayout.Button("Update Orbits"))
|
||||
{
|
||||
_zone.Update(.01f);
|
||||
//_sectorRenderer.LateUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
// Does the rendering of the map editor in the scene view.
|
||||
private void OnSceneGUI(SceneView sceneView) { }
|
||||
|
||||
void OnFocus()
|
||||
{
|
||||
SceneView.onSceneGUIDelegate -= this.OnSceneGUI; // Just in case
|
||||
SceneView.onSceneGUIDelegate += this.OnSceneGUI;
|
||||
}
|
||||
|
||||
private void LoadZone(FileInfo zoneFile)
|
||||
{
|
||||
var zonePack = MessagePackSerializer.Deserialize<ZonePack>(File.ReadAllBytes(zoneFile.FullName));
|
||||
_zone = new Zone(_context, zonePack);
|
||||
_sectorRenderer.LoadZone(_zone);
|
||||
}
|
||||
|
||||
public void SaveZone()
|
||||
{
|
||||
var dir = Path.Combine(_filePath.FullName, $"{_zone.Data.Name}.zone");
|
||||
File.WriteAllBytes(dir,MessagePackSerializer.Serialize(_zone.Pack()));
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ public class Galaxy : ScriptableObject
|
|||
[Serializable]
|
||||
public class GalaxyMapData
|
||||
{
|
||||
public GlobalData GlobalData = new GlobalData();
|
||||
public GalaxyShapeSettings ShapeSettings = new GalaxyShapeSettings();
|
||||
|
||||
[HideInInspector]
|
||||
public GalaxyMapLayerData StarDensity;
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "Sector Display Properties", menuName = "Aetheria/Sector Display Properties")]
|
||||
public class SectorDisplayProperties : ScriptableObject
|
||||
public class GameSettings : ScriptableObject
|
||||
{
|
||||
public float DefaultZoneRadius;
|
||||
public float DefaultZoneMass;
|
||||
public float DefaultViewDistance;
|
||||
public float DefaultMinimapDistance;
|
||||
public ExponentialCurve BodyDiameter;
|
||||
public GravitySettings GravitySettings;
|
||||
public ExponentialCurve FogTintRadius;
|
||||
public ExponentialCurve LightRadius;
|
||||
public PlanetSettings PlanetSettings;
|
||||
public ZoneGenerationSettings ZoneSettings;
|
||||
}
|
||||
|
||||
|
|
@ -5,6 +5,5 @@ using UnityEngine;
|
|||
public class GasGiantObject : PlanetObject
|
||||
{
|
||||
public SunMaterial SunMaterial;
|
||||
public GradientMapper GradientMapper;
|
||||
public MeshRenderer GravityWaves;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using Unity.Mathematics;
|
|||
public class SectorRenderer : MonoBehaviour
|
||||
{
|
||||
public Transform FogCameraParent;
|
||||
public SectorDisplayProperties Properties;
|
||||
public GameSettings Settings;
|
||||
public Transform SectorRoot;
|
||||
public Transform SectorBrushes;
|
||||
public CinemachineVirtualCamera SceneCamera;
|
||||
|
|
@ -33,11 +33,9 @@ public class SectorRenderer : MonoBehaviour
|
|||
public Texture2D PlanetoidIcon;
|
||||
public Texture2D PlanetIcon;
|
||||
|
||||
private Dictionary<Guid, Transform> _planets = new Dictionary<Guid, Transform>();
|
||||
private Dictionary<Guid, PlanetObject> _planets = new Dictionary<Guid, PlanetObject>();
|
||||
private Zone _zone;
|
||||
private float _viewDistance;
|
||||
|
||||
public GameContext Context { get; set; }
|
||||
|
||||
public float ViewDistance
|
||||
{
|
||||
|
|
@ -63,16 +61,15 @@ public class SectorRenderer : MonoBehaviour
|
|||
|
||||
void Start()
|
||||
{
|
||||
ViewDistance = Properties.DefaultViewDistance;
|
||||
MinimapDistance = Properties.DefaultMinimapDistance;
|
||||
ViewDistance = Settings.DefaultViewDistance;
|
||||
MinimapDistance = Settings.DefaultMinimapDistance;
|
||||
}
|
||||
|
||||
public void LoadZone(Zone zone)
|
||||
{
|
||||
_zone = zone;
|
||||
_zone.GravitySettings = Properties.GravitySettings;
|
||||
SectorBrushes.localScale = zone.Data.Radius * 2 * Vector3.one;
|
||||
_zone.ZoneDepth = 50;
|
||||
_zone.ZoneDepth = 125;
|
||||
_zone.ZoneDepthExponent = .25f;
|
||||
_zone.ZoneDepthRadius = zone.Data.Radius * 2;
|
||||
ClearZone();
|
||||
|
|
@ -108,30 +105,24 @@ public class SectorRenderer : MonoBehaviour
|
|||
planet = Instantiate(Sun, SectorRoot);
|
||||
var sun = (SunObject) planet;
|
||||
sunData.LightColor.Subscribe(c => sun.Light.color = c);
|
||||
sunData.Mass.Subscribe(m => sun.Light.range = Properties.LightRadius.Evaluate(m));
|
||||
sunData.Mass.Subscribe(m => sun.Light.range = Settings.PlanetSettings.LightRadius.Evaluate(m));
|
||||
sunData.FogTintColor.Subscribe(c => sun.FogTint.material.SetColor("_Color", c));
|
||||
sunData.Mass.Subscribe(m => sun.FogTint.transform.localScale = Properties.FogTintRadius.Evaluate(m) * Vector3.one);
|
||||
sunData.Mass.Subscribe(m => sun.FogTint.transform.localScale = Settings.PlanetSettings.FogTintRadius.Evaluate(m) * Vector3.one);
|
||||
}
|
||||
else planet = Instantiate(GasGiant, SectorRoot);
|
||||
|
||||
var gas = (GasGiantObject) planet;
|
||||
gasGiantData.Colors.Subscribe(c => gas.GradientMapper.ApplyGradient(c.ToGradient()));
|
||||
var gasGiant = _zone.PlanetInstances[planetData.ID] as GasGiant;
|
||||
gasGiantData.Colors.Subscribe(c => gas.Body.material.SetTexture("_ColorRamp", c.ToGradient().ToTexture()));
|
||||
gasGiantData.AlbedoRotationSpeed.Subscribe(f => gas.SunMaterial.AlbedoRotationSpeed = f);
|
||||
gasGiantData.FirstOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetRotationSpeed = f);
|
||||
gasGiantData.SecondOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetRotationSpeed = f);
|
||||
gasGiantData.FirstOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetDomainRotationSpeed = f);
|
||||
gasGiantData.SecondOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetDomainRotationSpeed = f);
|
||||
planetData.Mass.CombineLatest(planetData.GravityRadiusMultiplier,
|
||||
(mass, radius) => Properties.GravitySettings.WaveRadius.Evaluate(mass) * radius)
|
||||
.Subscribe(f => gas.GravityWaves.transform.localScale = f * Vector3.one);
|
||||
planetData.Mass.CombineLatest(planetData.GravityDepthMultiplier,
|
||||
(mass, depth) => Properties.GravitySettings.WaveDepth.Evaluate(mass) * depth)
|
||||
.Subscribe(f => gas.GravityWaves.material.SetFloat("_Depth", f));
|
||||
planetData.Mass.Subscribe(f =>
|
||||
{
|
||||
gas.GravityWaves.material.SetFloat("_Frequency", Properties.GravitySettings.WaveFrequency.Evaluate(f));
|
||||
gasGiant.GravityWavesRadius.Subscribe(f => gas.GravityWaves.transform.localScale = f * Vector3.one);
|
||||
gasGiant.GravityWavesDepth.Subscribe(f => gas.GravityWaves.material.SetFloat("_Depth", f));
|
||||
planetData.Mass.Subscribe(f => gas.GravityWaves.material.SetFloat("_Frequency", Settings.PlanetSettings.WaveFrequency.Evaluate(f)));
|
||||
//gas.WaveScroll.Speed = Properties.GravitySettings.WaveSpeed.Evaluate(f);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -139,21 +130,12 @@ public class SectorRenderer : MonoBehaviour
|
|||
//planet.Icon.material.mainTexture = planetData.Mass > Context.GlobalData.PlanetMass ? PlanetIcon : PlanetoidIcon;
|
||||
}
|
||||
|
||||
planetData.Mass.Subscribe(mass =>
|
||||
{
|
||||
var diameter = Properties.BodyDiameter.Evaluate(mass);
|
||||
planet.Body.transform.localScale = diameter * Vector3.one;
|
||||
//planet.GridSnap.Offset = diameter * 2;
|
||||
});
|
||||
|
||||
planetData.Mass.CombineLatest(planetData.GravityRadiusMultiplier,
|
||||
(mass, radius) => Properties.GravitySettings.GravityRadius.Evaluate(mass) * radius)
|
||||
.Subscribe(f => planet.GravityWell.transform.localScale = f * Vector3.one);
|
||||
planetData.Mass.CombineLatest(planetData.GravityDepthMultiplier,
|
||||
(mass, depth) => Properties.GravitySettings.GravityDepth.Evaluate(mass) * depth)
|
||||
.Subscribe(f => planet.GravityWell.material.SetFloat("_Depth", f));
|
||||
|
||||
_planets.Add(planetData.ID, planet.transform);
|
||||
var planetInstance = _zone.PlanetInstances[planetData.ID];
|
||||
planetInstance.BodyRadius.Subscribe(f => planet.Body.transform.localScale = f * Vector3.one);
|
||||
planetInstance.GravityWellRadius.Subscribe(f => planet.GravityWell.transform.localScale = f * Vector3.one);
|
||||
planetInstance.GravityWellDepth.Subscribe(f => planet.GravityWell.material.SetFloat("_Depth", f));
|
||||
|
||||
_planets.Add(planetData.ID, planet);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +149,7 @@ public class SectorRenderer : MonoBehaviour
|
|||
.Skip((int) (((float)i / AsteroidMeshes.Length) * belt.Transforms.Length))
|
||||
.Take((int) (1f / AsteroidMeshes.Length * belt.Transforms.Length))
|
||||
.Select(v => Matrix4x4.TRS(
|
||||
new Vector3(v.x, _zone.GetHeight(v.xy) + 5, v.y),
|
||||
new Vector3(v.x, _zone.GetHeight(v.xy), v.y),
|
||||
Quaternion.Euler(cos(v.z + (float) i / AsteroidMeshes.Length) * 100, sin(v.z + (float) i / AsteroidMeshes.Length) * 100, 0),
|
||||
Vector3.one * (v.w)))
|
||||
.ToArray();
|
||||
|
|
@ -180,12 +162,18 @@ public class SectorRenderer : MonoBehaviour
|
|||
{
|
||||
foreach (var planet in _planets)
|
||||
{
|
||||
var p = _zone.GetOrbitPosition(_zone.Planets[planet.Key].Orbit);
|
||||
planet.Value.position = new Vector3(p.x, _zone.GetHeight(p) + 10, p.y);
|
||||
var planetInstance = _zone.PlanetInstances[planet.Key];
|
||||
var p = _zone.GetOrbitPosition(planetInstance.BodyData.Orbit);
|
||||
planet.Value.transform.position = new Vector3(p.x, _zone.GetHeight(p) + planetInstance.BodyRadius.Value * 2, p.y);
|
||||
if(planet.Value is GasGiantObject gasGiantObject && !(planet.Value is SunObject))
|
||||
{
|
||||
var toParent = normalize(_zone.GetOrbitPosition(_zone.Orbits[planetInstance.BodyData.Orbit].Data.Parent) - p);
|
||||
gasGiantObject.SunMaterial.LightingDirection = new Vector3(toParent.x, 0, toParent.y);
|
||||
}
|
||||
}
|
||||
|
||||
var pos = FogCameraParent.position;
|
||||
FogMaterial.SetVector("_GridTransform", new Vector4(pos.x,pos.z,_viewDistance*2));
|
||||
var fogPos = FogCameraParent.position;
|
||||
FogMaterial.SetVector("_GridTransform", new Vector4(fogPos.x,fogPos.z,_viewDistance*2));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class VolumeSampling : MonoBehaviour
|
|||
|
||||
// Shader needs this matrix to generate world space rays
|
||||
_volMaterial.SetMatrix("_CamProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
|
||||
_volMaterial.SetMatrix("_CamInvProj", (_camera.projectionMatrix * _camera.worldToCameraMatrix).inverse);
|
||||
|
||||
// Shader needs to know the position and scale of cameras used to render input textures
|
||||
if(GridTransform != null)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
protected Func<float2> TargetPosition;
|
||||
protected Func<float2> TargetVelocity;
|
||||
protected bool MatchVelocity;
|
||||
protected List<SimplifiedZoneData> Path;
|
||||
protected List<ZoneDefinition> Path;
|
||||
protected Guid Task;
|
||||
protected bool Moving;
|
||||
protected bool Waiting;
|
||||
|
|
@ -116,7 +116,7 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
if (Moving)
|
||||
{
|
||||
if(_entity.Parent!=Guid.Empty)
|
||||
_context.RemoveParent(_entity);
|
||||
_entity.RemoveParent();
|
||||
|
||||
var targetPosition = TargetPosition();
|
||||
var distance = length(targetPosition - _entity.Position);
|
||||
|
|
@ -179,12 +179,12 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
var homeEntity = _context.Cache.Get<Entity>(HomeEntity);
|
||||
if (Zone == homeEntity.Zone) MoveTo(homeEntity, true, () =>
|
||||
{
|
||||
_context.SetParent(_entity, homeEntity);
|
||||
_entity.SetParent(homeEntity);
|
||||
onFinish?.Invoke();
|
||||
});
|
||||
else MoveTo(homeEntity.Zone.Data.ID, () => MoveTo(homeEntity, true, () =>
|
||||
{
|
||||
_context.SetParent(_entity, homeEntity);
|
||||
_entity.SetParent(homeEntity);
|
||||
onFinish?.Invoke();
|
||||
}));
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh
|
|||
path.RemoveAt(0);
|
||||
if (path.Count > 0)
|
||||
{
|
||||
MoveTo(Zone.WormholePosition(Path[0].ZoneID), false, OnNextZone);
|
||||
MoveTo(Zone.WormholePosition(Path[0]), false, OnNextZone);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class HaulingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
var target = Zone.Entities[haulingTask.Origin] as OrbitalEntity;
|
||||
|
||||
_context.SetParent(_entity, target);
|
||||
_entity.SetParent(target);
|
||||
var itemData = _context.Cache.Get<ItemData>(haulingTask.ItemType);
|
||||
int quantity = min((int) ((_entity.Capacity - _entity.OccupiedCapacity) / itemData.Size), haulingTask.Quantity - _itemsDelivered);
|
||||
if (itemData is SimpleCommodityData)
|
||||
|
|
@ -116,7 +116,7 @@ public class HaulingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
var target = Zone.Entities[haulingTask.Target] as OrbitalEntity;
|
||||
|
||||
_context.SetParent(_entity, target);
|
||||
_entity.SetParent(target);
|
||||
|
||||
var itemData = _context.Cache.Get<ItemData>(haulingTask.ItemType);
|
||||
if (itemData is SimpleCommodityData)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class TowingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var towingTask = _context.Cache.Get<StationTowing>(Task);
|
||||
var target = Zone.Entities[towingTask.Station] as OrbitalEntity;
|
||||
|
||||
_context.SetParent(target, _entity);
|
||||
target.SetParent(_entity);
|
||||
|
||||
_entity.SetMessage("Entering delivery phase.");
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ public class TowingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
var towingTask = _context.Cache.Get<StationTowing>(Task);
|
||||
var target = Zone.Entities[towingTask.Station] as OrbitalEntity;
|
||||
|
||||
_context.RemoveParent(target);
|
||||
target.RemoveParent();
|
||||
|
||||
_entity.SetMessage("Target delivered. Returning Home.");
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class WanderController : ControllerBase, IBehavior
|
|||
var randomEntity = entities[_context.Random.NextInt(entities.Length)];
|
||||
MoveTo(randomEntity, true, () =>
|
||||
{
|
||||
_context.SetParent(_entity, randomEntity);
|
||||
_entity.SetParent(randomEntity);
|
||||
_dockTime = _context.Random.NextFloat(_data.RandomDockTime);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -379,6 +379,22 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
Children.Remove(entity.ID);
|
||||
ChildEvent.Change();
|
||||
}
|
||||
|
||||
public void SetParent(Entity parent)
|
||||
{
|
||||
Parent = parent.ID;
|
||||
parent.AddChild(this);
|
||||
}
|
||||
|
||||
public void RemoveParent()
|
||||
{
|
||||
if (Parent == Guid.Empty)
|
||||
return;
|
||||
|
||||
var parent = Zone.Entities[Parent];
|
||||
parent.RemoveChild(this);
|
||||
Parent = Guid.Empty;
|
||||
}
|
||||
|
||||
public Guid Build(BlueprintData blueprint, float quality, string name, bool direct = false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,26 +22,16 @@ public class ExponentialCurve
|
|||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject]
|
||||
public class GravitySettings
|
||||
public class ExponentialLerp
|
||||
{
|
||||
[JsonProperty("gravityDepth"), Key(0)]
|
||||
public ExponentialCurve GravityDepth;
|
||||
[JsonProperty("exponent"), Key(0)]
|
||||
public float Exponent;
|
||||
|
||||
[JsonProperty("gravityRadius"), Key(1)]
|
||||
public ExponentialCurve GravityRadius;
|
||||
[JsonProperty("max"), Key(1)]
|
||||
public float Minimum;
|
||||
|
||||
[JsonProperty("waveDepth"), Key(2)]
|
||||
public ExponentialCurve WaveDepth;
|
||||
[JsonProperty("min"), Key(2)]
|
||||
public float Maximum;
|
||||
|
||||
[JsonProperty("waveRadius"), Key(3)]
|
||||
public ExponentialCurve WaveRadius;
|
||||
|
||||
[JsonProperty("waveFrequency"), Key(4)]
|
||||
public ExponentialCurve WaveFrequency;
|
||||
|
||||
[JsonProperty("waveSpeed"), Key(5)]
|
||||
public ExponentialCurve WaveSpeed;
|
||||
|
||||
[JsonProperty("gravityStrength"), Key(6)]
|
||||
public float GravityStrength;
|
||||
public float Evaluate(float value) => Minimum + pow(saturate(value), Exponent) * (Maximum - Minimum);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public static class Extensions
|
|||
}
|
||||
|
||||
private static Random? _random;
|
||||
private static Random Random => (Random) (_random ?? (_random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue))));
|
||||
//private static Random Random => (Random) (_random ??= new Random((uint) (DateTime.Now.Ticks%uint.MaxValue)));
|
||||
// public static T RandomElement<T>(this IEnumerable<T> enumerable) => enumerable.ElementAt(Random.NextInt(0, enumerable.Count()));
|
||||
public static float NextPowerDistribution(this ref Random random, float min, float max, float exp, float randexp) =>
|
||||
pow((pow(max, exp + 1) - pow(min, exp + 1)) * pow(random.NextFloat(), randexp) + pow(min, exp + 1), 1 / (exp + 1));
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using static Unity.Mathematics.math;
|
|||
using float2 = Unity.Mathematics.float2;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
using JM.LinqFaster;
|
||||
using UniRx;
|
||||
using float4 = Unity.Mathematics.float4;
|
||||
|
||||
public class GameContext
|
||||
|
|
@ -15,7 +16,7 @@ public class GameContext
|
|||
public Dictionary<string, GalaxyMapLayerData> MapLayers = new Dictionary<string, GalaxyMapLayerData>();
|
||||
public SimpleCommodityData[] Resources;
|
||||
public Dictionary<Guid, List<IController>> CorporationControllers = new Dictionary<Guid, List<IController>>();
|
||||
public Dictionary<Guid, SimplifiedZoneData> GalaxyZones;
|
||||
public Dictionary<Guid, ZoneDefinition> GalaxyZones;
|
||||
|
||||
private Action<string> _logger;
|
||||
|
||||
|
|
@ -76,67 +77,67 @@ public class GameContext
|
|||
_logger(s);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach(var zone in _zones.Values)
|
||||
zone.Update(_deltaTime);
|
||||
|
||||
foreach (var corporation in Cache.GetAll<Corporation>())
|
||||
{
|
||||
foreach (var tasks in corporation.Tasks
|
||||
.Select(id => Cache.Get<AgentTask>(id)) // Fetch the tasks from the database cache
|
||||
.Where(task => !task.Reserved) // Filter out tasks that have already been reserved
|
||||
.GroupBy(task => task.Type)) // Group tasks by type
|
||||
{
|
||||
// Create a list of available controllers for this task type
|
||||
var availableControllers = CorporationControllers[corporation.ID]
|
||||
.Where(controller => controller.Available && controller.TaskType == tasks.Key).ToList();
|
||||
|
||||
// Iterate over the highest priority tasks for which controllers are available
|
||||
foreach (var task in tasks.OrderByDescending(task => task.Priority).Take(availableControllers.Count))
|
||||
{
|
||||
// Find the nearest controller for this task
|
||||
IController nearestController = availableControllers[0];
|
||||
List<SimplifiedZoneData> nearestControllerPath = FindPath(GalaxyZones[availableControllers.First().Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
foreach (var controller in availableControllers.Skip(1))
|
||||
{
|
||||
var path = FindPath(GalaxyZones[controller.Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
if (path.Count < nearestControllerPath.Count)
|
||||
{
|
||||
nearestControllerPath = path;
|
||||
nearestController = controller;
|
||||
}
|
||||
}
|
||||
task.Reserved = true;
|
||||
nearestController.AssignTask(task.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// public void Update()
|
||||
// {
|
||||
// foreach(var zone in _zones.Values)
|
||||
// zone.Update((float) Time, _deltaTime);
|
||||
//
|
||||
// foreach (var corporation in Cache.GetAll<Corporation>())
|
||||
// {
|
||||
// foreach (var tasks in corporation.Tasks
|
||||
// .Select(id => Cache.Get<AgentTask>(id)) // Fetch the tasks from the database cache
|
||||
// .Where(task => !task.Reserved) // Filter out tasks that have already been reserved
|
||||
// .GroupBy(task => task.Type)) // Group tasks by type
|
||||
// {
|
||||
// // Create a list of available controllers for this task type
|
||||
// var availableControllers = CorporationControllers[corporation.ID]
|
||||
// .Where(controller => controller.Available && controller.TaskType == tasks.Key).ToList();
|
||||
//
|
||||
// // Iterate over the highest priority tasks for which controllers are available
|
||||
// foreach (var task in tasks.OrderByDescending(task => task.Priority).Take(availableControllers.Count))
|
||||
// {
|
||||
// // Find the nearest controller for this task
|
||||
// IController nearestController = availableControllers[0];
|
||||
// List<ZoneDefinition> nearestControllerPath = FindPath(GalaxyZones[availableControllers.First().Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
// foreach (var controller in availableControllers.Skip(1))
|
||||
// {
|
||||
// var path = FindPath(GalaxyZones[controller.Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
// if (path.Count < nearestControllerPath.Count)
|
||||
// {
|
||||
// nearestControllerPath = path;
|
||||
// nearestController = controller;
|
||||
// }
|
||||
// }
|
||||
// task.Reserved = true;
|
||||
// nearestController.AssignTask(task.ID);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
public Zone GetZone(Guid zone)
|
||||
{
|
||||
if (_zones.ContainsKey(zone)) return _zones[zone];
|
||||
|
||||
// var zoneData = Cache.Get<ZoneData>(zone);
|
||||
// if (zoneData == null) throw new ArgumentException("Zone parameter is not a valid zone ID!", nameof(zone));
|
||||
//
|
||||
// return GetZone(zoneData);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Zone GetZone(ZonePack zonePack)
|
||||
{
|
||||
var z = new Zone(this, zonePack);
|
||||
_zones.Add(zonePack.Data.ID, z);
|
||||
return z;
|
||||
}
|
||||
|
||||
public void UnloadZone(Guid zone)
|
||||
{
|
||||
_zones.Remove(zone);
|
||||
}
|
||||
// public Zone GetZone(Guid zone)
|
||||
// {
|
||||
// if (_zones.ContainsKey(zone)) return _zones[zone];
|
||||
//
|
||||
// // var zoneData = Cache.Get<ZoneData>(zone);
|
||||
// // if (zoneData == null) throw new ArgumentException("Zone parameter is not a valid zone ID!", nameof(zone));
|
||||
// //
|
||||
// // return GetZone(zoneData);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public Zone GetZone(ZonePack zonePack)
|
||||
// {
|
||||
// var z = new Zone(this, zonePack);
|
||||
// _zones.Add(zonePack.Data.ID, z);
|
||||
// return z;
|
||||
// }
|
||||
//
|
||||
// public void UnloadZone(Guid zone)
|
||||
// {
|
||||
// _zones.Remove(zone);
|
||||
// }
|
||||
|
||||
// public void Warp(Entity entity, Guid targetZone)
|
||||
// {
|
||||
|
|
@ -535,10 +536,9 @@ public class GameContext
|
|||
var orbit = new OrbitData
|
||||
{
|
||||
Context = this,
|
||||
Distance = distance,
|
||||
Distance = new ReactiveProperty<float>(distance),
|
||||
Parent = zone.Orbits.Values.Select(o=>o.Data)
|
||||
.First(orbitData => orbitData.Parent == Guid.Empty).ID,
|
||||
Period = _globalData.OrbitalPeriod(distance),
|
||||
Phase = Random.NextFloat()
|
||||
};
|
||||
zone.AddOrbit(orbit);
|
||||
|
|
@ -686,10 +686,10 @@ public class GameContext
|
|||
{
|
||||
public float Cost;
|
||||
public DijkstraNode Parent;
|
||||
public SimplifiedZoneData Zone;
|
||||
public ZoneDefinition Zone;
|
||||
}
|
||||
|
||||
public List<SimplifiedZoneData> FindPath(SimplifiedZoneData source, SimplifiedZoneData target, bool bestFirst = false)
|
||||
public List<ZoneDefinition> FindPath(ZoneDefinition source, ZoneDefinition target, bool bestFirst = false)
|
||||
{
|
||||
SortedList<float,DijkstraNode> members = new SortedList<float,DijkstraNode>{{0,new DijkstraNode{Zone = source}}};
|
||||
List<DijkstraNode> searched = new List<DijkstraNode>();
|
||||
|
|
@ -715,22 +715,6 @@ public class GameContext
|
|||
}
|
||||
}
|
||||
|
||||
public void SetParent(Entity child, Entity parent)
|
||||
{
|
||||
child.Parent = parent.ID;
|
||||
parent.AddChild(child);
|
||||
}
|
||||
|
||||
public void RemoveParent(Entity child)
|
||||
{
|
||||
if (child.Parent == Guid.Empty)
|
||||
return;
|
||||
|
||||
var parent = Cache.Get<Entity>(child.Parent);
|
||||
parent.RemoveChild(child);
|
||||
child.Parent = Guid.Empty;
|
||||
}
|
||||
|
||||
// public bool MoveCargo(Entity source, Entity target, ItemInstance item, int quantity = int.MaxValue)
|
||||
// {
|
||||
// if (item is CraftedItemInstance craftedItemInstance)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField, JsonProperty("radiusPower"), Key(7)]
|
||||
public float RadiusPower = 1.75f;
|
||||
|
||||
[InspectableField, JsonProperty("massFloor"), Key(8)]
|
||||
[InspectableField, JsonProperty("massFloor"), Key(8)]
|
||||
public float MassFloor = 1;
|
||||
|
||||
[InspectableField, JsonProperty("sunMass"), Key(9)]
|
||||
|
|
@ -80,12 +80,6 @@ public class GlobalData : DatabaseEntry
|
|||
[InspectableField, JsonProperty("orbitPeriodMultiplier"), Key(23)]
|
||||
public float OrbitPeriodMultiplier = 1f;
|
||||
|
||||
[InspectableField, JsonProperty("gravityRadiusExponent"), Key(24)]
|
||||
public float GravityRadiusExponent = 1.5f;
|
||||
|
||||
[InspectableField, JsonProperty("gravityRadiusMultiplier"), Key(25)]
|
||||
public float GravityRadiusMultiplier = 1f;
|
||||
|
||||
[InspectableField, JsonProperty("beltProbability"), Key(26)]
|
||||
public float BeltProbability = .05f;
|
||||
|
||||
|
|
@ -115,9 +109,6 @@ public class GlobalData : DatabaseEntry
|
|||
|
||||
[InspectableField, JsonProperty("warpDistance"), Key(35)]
|
||||
public float WarpDistance = 25;
|
||||
|
||||
[InspectableField, JsonProperty("orbitSpeedMultiplier"), Key(36)]
|
||||
public float OrbitSpeedMultiplier = .25f;
|
||||
|
||||
[InspectableField, JsonProperty("targetPersistenceDuration"), Key(37)]
|
||||
public float TargetPersistenceDuration = 3;
|
||||
|
|
@ -171,11 +162,6 @@ public class GlobalData : DatabaseEntry
|
|||
{
|
||||
return pow(mass, 1 / RadiusPower);
|
||||
}
|
||||
|
||||
public float OrbitalPeriod(float distance)
|
||||
{
|
||||
return pow(distance, OrbitPeriodExponent) * OrbitPeriodMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
[Inspectable, Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
@ -223,14 +209,14 @@ public class GalaxyMapLayerData : DatabaseEntry, INamedEntry
|
|||
[InspectableField, JsonProperty("name"), Key(14)]
|
||||
public string Name;
|
||||
|
||||
public float Evaluate(float2 uv, GlobalData data)
|
||||
public float Evaluate(float2 uv, GalaxyShapeSettings settings)
|
||||
{
|
||||
float2 offset = -float2(.5f, .5f)+uv;
|
||||
float circle = (.5f-length(offset))*2;
|
||||
float angle = pow(length(offset)*2,data.TwistPower) * data.Twist;
|
||||
float angle = pow(length(offset)*2,settings.TwistExponent) * settings.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 spokes = (sin(atan*settings.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, CoreBoostPower) * CoreBoost) + CoreBoostOffset;
|
||||
float gal = max(shape - noise * saturate(circle), 0);
|
||||
|
|
|
|||
|
|
@ -94,13 +94,13 @@ public class GalaxyRequestMessage : Message
|
|||
[MessagePackObject]
|
||||
public class GalaxyResponseMessage : Message
|
||||
{
|
||||
[Key(0)] public SimplifiedZoneData[] Zones;
|
||||
[Key(0)] public ZoneDefinition[] Zones;
|
||||
[Key(1)] public GalaxyMapLayerData StarDensity;
|
||||
[Key(2)] public GlobalData GlobalData;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class SimplifiedZoneData
|
||||
public class ZoneDefinition
|
||||
{
|
||||
[Key(0)] public Guid ZoneID;
|
||||
[Key(1)] public Guid[] Links;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using MessagePack.ReactivePropertyExtension;
|
||||
using MessagePack.Resolvers;
|
||||
|
||||
public static class RegisterResolver
|
||||
|
|
@ -15,7 +16,8 @@ public static class RegisterResolver
|
|||
MathResolver.Instance,
|
||||
TypeResolver.Instance,
|
||||
NativeGuidResolver.Instance,
|
||||
StandardResolver.Instance
|
||||
StandardResolver.Instance,
|
||||
ReactivePropertyResolver.Instance
|
||||
);
|
||||
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);
|
||||
MessagePackSerializer.DefaultOptions = options;
|
||||
|
|
|
|||
67
Assets/Scripts/ServerShared/Settings.cs
Normal file
67
Assets/Scripts/ServerShared/Settings.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject]
|
||||
public class PlanetSettings
|
||||
{
|
||||
public ExponentialCurve GravityDepth;
|
||||
public ExponentialCurve GravityRadius;
|
||||
public ExponentialCurve WaveDepth;
|
||||
public ExponentialCurve WaveRadius;
|
||||
public ExponentialCurve WaveFrequency;
|
||||
public ExponentialCurve WaveSpeed;
|
||||
public ExponentialCurve FogTintRadius;
|
||||
public ExponentialCurve LightRadius;
|
||||
public ExponentialCurve BodyRadius;
|
||||
public ExponentialLerp AsteroidSize;
|
||||
public ExponentialLerp AsteroidHitpoints;
|
||||
public ExponentialLerp AsteroidRespawnTime;
|
||||
public float GravityStrength;
|
||||
public float MiningDifficulty = 500f;
|
||||
|
||||
public ExponentialCurve OrbitPeriod;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject]
|
||||
public class GalaxyShapeSettings
|
||||
{
|
||||
public int Arms = 4;
|
||||
public float Twist = 10;
|
||||
public float TwistExponent = 2;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject(keyAsPropertyName:true), JsonObject]
|
||||
public class ZoneGenerationSettings
|
||||
{
|
||||
public GalaxyShapeSettings ShapeSettings;
|
||||
|
||||
public ExponentialCurve PlanetSafetyRadius;
|
||||
|
||||
public float MassFloor = 1;
|
||||
public float SunMass = 10000;
|
||||
public float GasGiantMass = 2000;
|
||||
public float PlanetMass = 100f;
|
||||
|
||||
public int SatellitePasses = 4;
|
||||
public float SatelliteCreationMassFloor = 100;
|
||||
public float SatelliteCreationProbability = .25f;
|
||||
public float BinaryCreationProbability = .25f;
|
||||
public float RosetteProbability = .25f;
|
||||
|
||||
public ExponentialLerp ZoneRadius;
|
||||
public ExponentialLerp ZoneMass;
|
||||
|
||||
public float BeltProbability = .05f;
|
||||
public float BeltMassCeiling = 500f;
|
||||
|
||||
public ExponentialCurve AsteroidCount;
|
||||
public ExponentialLerp AsteroidRotationSpeed;
|
||||
|
||||
public float ResourceDensityMinimum = .1f;
|
||||
public float ResourceDensityMaximum = 1.5f;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d675657ad7e1e7246b133b7abadaee2f
|
||||
guid: 1f6f6d13d38104545bd2a9bc42773ad3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -2,45 +2,64 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
public class Zone
|
||||
{
|
||||
public float ZoneDepth;
|
||||
public float ZoneDepthExponent;
|
||||
public float ZoneDepthRadius;
|
||||
public GravitySettings GravitySettings;
|
||||
//public HashSet<Guid> Planets = new HashSet<Guid>();
|
||||
public Dictionary<Guid, Entity> Entities = new Dictionary<Guid, Entity>();
|
||||
//public Dictionary<Guid, OrbitData> Orbits = new Dictionary<Guid, OrbitData>();
|
||||
public Dictionary<Guid, BodyData> Planets = new Dictionary<Guid, BodyData>();
|
||||
public Dictionary<Guid, Planet> PlanetInstances = new Dictionary<Guid, Planet>();
|
||||
|
||||
public Dictionary<Guid, Orbit> Orbits = new Dictionary<Guid, Orbit>();
|
||||
public Dictionary<Guid, AsteroidBelt> AsteroidBelts = new Dictionary<Guid, AsteroidBelt>();
|
||||
|
||||
private HashSet<Guid> _updatedOrbits;
|
||||
|
||||
private GameContext _context;
|
||||
private PlanetSettings _settings;
|
||||
private float _time;
|
||||
private Random _random;
|
||||
|
||||
public ZoneData Data { get; }
|
||||
|
||||
public Zone(GameContext context, ZonePack pack)
|
||||
public Zone(PlanetSettings settings, ZonePack pack)
|
||||
{
|
||||
Data = pack.Data;
|
||||
_context = context;
|
||||
_settings = settings;
|
||||
_random = new Random(Convert.ToUInt32(abs(Data.ID.GetHashCode())));
|
||||
|
||||
foreach (var orbit in pack.Orbits)
|
||||
{
|
||||
Orbits.Add(orbit.ID, new Orbit(orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
}
|
||||
foreach (var planet in pack.Planets) Planets.Add(planet.ID, planet);
|
||||
|
||||
foreach (var planet in pack.Planets)
|
||||
{
|
||||
Planets.Add(planet.ID, planet);
|
||||
switch (planet)
|
||||
{
|
||||
case AsteroidBeltData belt:
|
||||
AsteroidBelts[belt.ID] = new AsteroidBelt(belt.Asteroids.Length);
|
||||
break;
|
||||
case GasGiantData gas:
|
||||
PlanetInstances.Add(gas.ID, new GasGiant(settings, gas));
|
||||
break;
|
||||
default:
|
||||
PlanetInstances.Add(planet.ID, new Planet(settings, planet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var entity in pack.Entities) Entities.Add(entity.ID, entity);
|
||||
|
||||
foreach (var belt in pack.Planets.Where(p => p is AsteroidBeltData).Cast<AsteroidBeltData>())
|
||||
AsteroidBelts[belt.ID] = new AsteroidBelt(belt.Asteroids.Length);
|
||||
|
||||
// TODO: Associate planets with stored entities for planetary colonies
|
||||
}
|
||||
|
||||
|
|
@ -57,11 +76,12 @@ public class Zone
|
|||
|
||||
public void AddOrbit(OrbitData orbit)
|
||||
{
|
||||
Orbits.Add(orbit.ID, new Orbit(orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
public void Update(float time, float deltaTime)
|
||||
{
|
||||
_time = time;
|
||||
_updatedOrbits = new HashSet<Guid>();
|
||||
foreach (var orbit in Orbits)
|
||||
{
|
||||
|
|
@ -76,40 +96,40 @@ public class Zone
|
|||
foreach (var entity in Entities.Values) entity.Update(deltaTime);
|
||||
}
|
||||
|
||||
public float2 WormholePosition(Guid target)
|
||||
public float2 WormholePosition(ZoneDefinition target)
|
||||
{
|
||||
var direction = _context.Cache.Get<ZoneData>(target).Position - Data.Position;
|
||||
var direction = target.Position - Data.Position;
|
||||
return normalize(direction) * Data.Radius * .95f;
|
||||
}
|
||||
|
||||
// Determine orbital position recursively, caching parent positions to avoid repeated calculations
|
||||
public float2 GetOrbitPosition(Guid orbit)
|
||||
public float2 GetOrbitPosition(Guid orbitID)
|
||||
{
|
||||
// Root orbit is fixed at center
|
||||
if(orbit==Guid.Empty)
|
||||
// Root orbit is fixed at origin
|
||||
if(orbitID==Guid.Empty)
|
||||
return float2.zero;
|
||||
|
||||
if (!_updatedOrbits.Contains(orbit))
|
||||
if (!_updatedOrbits.Contains(orbitID))
|
||||
{
|
||||
var orbitData = Orbits[orbit].Data;
|
||||
var orbit = Orbits[orbitID];
|
||||
float2 pos = float2.zero;
|
||||
if (orbitData.Period > .01f)
|
||||
if (orbit.Period.Value > .01f)
|
||||
{
|
||||
var phase = (float) frac(_context.Time / orbitData.Period * _context.GlobalData.OrbitSpeedMultiplier);
|
||||
pos = OrbitData.Evaluate(frac(phase + orbitData.Phase)) * orbitData.Distance;
|
||||
var phase = (float) frac(_time / orbit.Period.Value);
|
||||
pos = OrbitData.Evaluate(frac(phase + orbit.Data.Phase)) * orbit.Data.Distance.Value;
|
||||
|
||||
if (float.IsNaN(pos.x))
|
||||
{
|
||||
_context.Log("Orbit position is NaN, something went very wrong!");
|
||||
//_context.Log("Orbit position is NaN, something went very wrong!");
|
||||
pos = float2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
_updatedOrbits.Add(orbit);
|
||||
return GetOrbitPosition(orbitData.Parent) + pos;
|
||||
_updatedOrbits.Add(orbitID);
|
||||
return GetOrbitPosition(orbit.Data.Parent) + pos;
|
||||
}
|
||||
|
||||
return Orbits[orbit].Position;
|
||||
return Orbits[orbitID].Position;
|
||||
}
|
||||
|
||||
public float2 GetOrbitVelocity(Guid orbit)
|
||||
|
|
@ -169,20 +189,20 @@ public class Zone
|
|||
var orbitPosition = GetOrbitPosition(orbitData.Parent);
|
||||
for (var i = 0; i < beltData.Asteroids.Length; i++)
|
||||
{
|
||||
var size = beltData.Asteroids[i].Size;
|
||||
float size;
|
||||
if(belt.RespawnTimers.ContainsKey(i)) size = 0;
|
||||
else if (belt.Damage.ContainsKey(i))
|
||||
{
|
||||
var hpLerp = unlerp(_context.GlobalData.AsteroidSizeMin, _context.GlobalData.AsteroidSizeMax, size);
|
||||
var asteroidHitpoints = lerp(_context.GlobalData.AsteroidHitpointsMin, _context.GlobalData.AsteroidHitpointsMax, pow(hpLerp, _context.GlobalData.AsteroidHitpointsPower));
|
||||
var sizeLerp = (asteroidHitpoints - belt.Damage[i]) / asteroidHitpoints;
|
||||
size = lerp(_context.GlobalData.AsteroidSizeMin, size, sizeLerp);
|
||||
var asteroidHitpoints = _settings.AsteroidHitpoints.Evaluate(beltData.Asteroids[i].Size);
|
||||
var damage = (asteroidHitpoints - belt.Damage[i]) / asteroidHitpoints;
|
||||
size = _settings.AsteroidSize.Evaluate(damage * beltData.Asteroids[i].Size);
|
||||
}
|
||||
else size = _settings.AsteroidSize.Evaluate(beltData.Asteroids[i].Size);
|
||||
|
||||
belt.Transforms[i] = float4(
|
||||
OrbitData.Evaluate((float) frac(_context.Time / _context.GlobalData.OrbitalPeriod(beltData.Asteroids[i].Distance) * _context.GlobalData.OrbitSpeedMultiplier +
|
||||
OrbitData.Evaluate((float) frac(_time / _settings.OrbitPeriod.Evaluate(beltData.Asteroids[i].Distance) +
|
||||
beltData.Asteroids[i].Phase)) * beltData.Asteroids[i].Distance + orbitPosition,
|
||||
(float) (_context.Time * beltData.Asteroids[i].RotationSpeed % (PI * 2)), size);
|
||||
(float) (_time * beltData.Asteroids[i].RotationSpeed % (PI * 2)), size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -191,30 +211,29 @@ public class Zone
|
|||
var parentPosition = GetOrbitPosition(parent);
|
||||
var delta = position - parentPosition;
|
||||
var distance = length(delta);
|
||||
var period = _context.GlobalData.OrbitalPeriod(distance);
|
||||
var period = _settings.OrbitPeriod.Evaluate(distance);
|
||||
var phase = atan2(delta.y, delta.x) / (PI * 2);
|
||||
var currentPhase = frac(_context.Time / period * _context.GlobalData.OrbitSpeedMultiplier);
|
||||
var currentPhase = frac(_time / period);
|
||||
var storedPhase = (float) frac(phase - currentPhase);
|
||||
|
||||
var orbit = new OrbitData
|
||||
{
|
||||
Context = _context,
|
||||
Distance = distance,
|
||||
Distance = new ReactiveProperty<float>(distance),
|
||||
Parent = parent,
|
||||
Period = period,
|
||||
Phase = storedPhase
|
||||
};
|
||||
Orbits.Add(orbit.ID, new Orbit(orbit));
|
||||
Orbits.Add(orbit.ID, new Orbit(_settings, orbit));
|
||||
return orbit;
|
||||
}
|
||||
|
||||
public void MineAsteroid(Entity miner, Guid asteroidBelt, int asteroid, float damage, float efficiency, float penetration)
|
||||
{
|
||||
var planetData = Planets[asteroidBelt];
|
||||
var beltData = Planets[asteroidBelt] as AsteroidBeltData;
|
||||
var belt = AsteroidBelts[asteroidBelt];
|
||||
var asteroidTransform = belt.Transforms[asteroid];
|
||||
var hpLerp = unlerp(_context.GlobalData.AsteroidSizeMin, _context.GlobalData.AsteroidSizeMax, asteroidTransform.w);
|
||||
var asteroidHitpoints = lerp(_context.GlobalData.AsteroidHitpointsMin, _context.GlobalData.AsteroidHitpointsMax, pow(hpLerp, _context.GlobalData.AsteroidHitpointsPower));
|
||||
|
||||
var size = beltData.Asteroids[asteroid].Size;
|
||||
var asteroidHitpoints = _settings.AsteroidHitpoints.Evaluate(size);
|
||||
|
||||
if (!belt.Damage.ContainsKey(asteroid))
|
||||
belt.Damage[asteroid] = 0;
|
||||
|
|
@ -226,53 +245,48 @@ public class Zone
|
|||
|
||||
if (belt.Damage[asteroid] > asteroidHitpoints)
|
||||
{
|
||||
belt.RespawnTimers[asteroid] =
|
||||
lerp(_context.GlobalData.AsteroidRespawnMin, _context.GlobalData.AsteroidRespawnMax, hpLerp);
|
||||
belt.RespawnTimers[asteroid] = _settings.AsteroidRespawnTime.Evaluate(size);
|
||||
belt.Damage.Remove(asteroid);
|
||||
belt.MiningAccumulator.Remove((miner.ID, asteroid));
|
||||
return;
|
||||
}
|
||||
|
||||
var resourceCount = planetData.Resources.Sum(x => x.Value);
|
||||
var resource = planetData.Resources.MaxBy(x => pow(x.Value, 1f / penetration) * _context.Random.NextFloat());
|
||||
if (efficiency * _context.Random.NextFloat() * belt.MiningAccumulator[(miner.ID, asteroid)] * resourceCount / _context.GlobalData.MiningDifficulty > 1 && miner.OccupiedCapacity < miner.Capacity - 1)
|
||||
var resourceCount = beltData.Resources.Sum(x => x.Value);
|
||||
var resource = beltData.Resources.MaxBy(x => pow(x.Value, 1f / penetration) * _random.NextFloat());
|
||||
if (efficiency * _random.NextFloat() * belt.MiningAccumulator[(miner.ID, asteroid)] * resourceCount / _settings.MiningDifficulty > 1 && miner.OccupiedCapacity < miner.Capacity - 1)
|
||||
{
|
||||
belt.MiningAccumulator.Remove((miner.ID, asteroid));
|
||||
var newSimpleCommodity = new SimpleCommodity
|
||||
{
|
||||
Context = _context,
|
||||
Data = resource.Key,
|
||||
Quantity = 1
|
||||
};
|
||||
_context.Cache.Add(newSimpleCommodity);
|
||||
miner.AddCargo(newSimpleCommodity);
|
||||
}
|
||||
}
|
||||
public float GetHeight(float2 position)
|
||||
{
|
||||
float result = -PowerPulse(length(position)/ZoneDepthRadius, ZoneDepthExponent) * ZoneDepth;
|
||||
foreach (var body in Planets.Values)
|
||||
foreach (var body in PlanetInstances.Values)
|
||||
{
|
||||
if (body is AsteroidBeltData) continue;
|
||||
|
||||
var p = (position - GetOrbitPosition(body.Orbit));
|
||||
var p = (position - GetOrbitPosition(body.BodyData.Orbit));
|
||||
var dist = length(p);
|
||||
var gravityRadius = GravitySettings.GravityRadius.Evaluate(body.Mass.Value) * body.GravityRadiusMultiplier.Value;
|
||||
var gravityRadius = body.GravityWellRadius.Value;
|
||||
if (dist < gravityRadius)
|
||||
{
|
||||
var depth = GravitySettings.GravityDepth.Evaluate(body.Mass.Value) * body.GravityDepthMultiplier.Value;
|
||||
result -= PowerPulse(dist / gravityRadius, body.GravityDepthExponent.Value) * depth;
|
||||
var depth = body.GravityWellDepth.Value;
|
||||
result -= PowerPulse(dist / gravityRadius, body.BodyData.GravityDepthExponent.Value) * depth;
|
||||
}
|
||||
|
||||
if (body is GasGiantData)
|
||||
if (body is GasGiant gas)
|
||||
{
|
||||
var waveRadius = GravitySettings.WaveRadius.Evaluate(body.Mass.Value) * body.GravityRadiusMultiplier.Value;
|
||||
var waveRadius = gas.GravityWavesRadius.Value;
|
||||
if(dist < waveRadius)
|
||||
{
|
||||
var depth = GravitySettings.WaveDepth.Evaluate(body.Mass.Value) * body.GravityDepthMultiplier.Value;
|
||||
var frequency = GravitySettings.WaveFrequency.Evaluate(body.Mass.Value);
|
||||
var speed = GravitySettings.WaveSpeed.Evaluate(body.Mass.Value);
|
||||
result -= RadialWaves(dist / gravityRadius, 8, 1.5f, frequency, (float) (_context.Time * speed)) * depth;
|
||||
var depth = gas.GravityWavesDepth.Value;
|
||||
var frequency = _settings.WaveFrequency.Evaluate(body.BodyData.Mass.Value);
|
||||
var speed = _settings.WaveSpeed.Evaluate(body.BodyData.Mass.Value);
|
||||
result -= RadialWaves(dist / waveRadius, 8, 1.5f, frequency, _time * speed) * depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -284,17 +298,19 @@ public class Zone
|
|||
{
|
||||
var normal = GetNormal(position);
|
||||
var f = new float2(normal.x, normal.z);
|
||||
return f * GravitySettings.GravityStrength * lengthsq(f);// * Mathf.Abs(GetHeight(position));
|
||||
return f * _settings.GravityStrength * lengthsq(f);// * Mathf.Abs(GetHeight(position));
|
||||
}
|
||||
|
||||
public static float PowerPulse(float x, float exponent)
|
||||
{
|
||||
x *= 2;
|
||||
x = clamp(x, -1, 1);
|
||||
return pow((x + 1) * (1 - x), exponent);
|
||||
}
|
||||
|
||||
public static float RadialWaves(float x, float maskExponent, float sineExponent, float frequency, float phase)
|
||||
{
|
||||
x *= 2;
|
||||
return PowerPulse(x, maskExponent) * cos(pow(x, sineExponent) * frequency + phase);
|
||||
}
|
||||
|
||||
|
|
@ -322,6 +338,55 @@ public class Zone
|
|||
}
|
||||
}
|
||||
|
||||
public class Planet
|
||||
{
|
||||
public BodyData BodyData;
|
||||
public ReadOnlyReactiveProperty<float> GravityWellDepth;
|
||||
public ReadOnlyReactiveProperty<float> GravityWellRadius;
|
||||
public ReadOnlyReactiveProperty<float> BodyRadius;
|
||||
|
||||
public Planet(PlanetSettings settings, BodyData data)
|
||||
{
|
||||
BodyData = data;
|
||||
BodyRadius = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.BodyRadiusMultiplier,
|
||||
(mass, radius) => settings.BodyRadius.Evaluate(mass) * radius));
|
||||
GravityWellRadius = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.GravityRadiusMultiplier,
|
||||
(mass, radius) => settings.GravityRadius.Evaluate(mass) * radius));
|
||||
GravityWellDepth = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.GravityDepthMultiplier,
|
||||
(mass, depth) => settings.GravityDepth.Evaluate(mass) * depth));
|
||||
}
|
||||
}
|
||||
|
||||
public class GasGiant : Planet
|
||||
{
|
||||
public GasGiantData GasGiantData;
|
||||
public ReadOnlyReactiveProperty<float> GravityWavesDepth;
|
||||
public ReadOnlyReactiveProperty<float> GravityWavesRadius;
|
||||
public ReadOnlyReactiveProperty<float> GravityWavesSpeed;
|
||||
|
||||
public GasGiant(PlanetSettings settings, GasGiantData data) : base(settings, data)
|
||||
{
|
||||
GasGiantData = data;
|
||||
GravityWavesDepth = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.WaveDepthMultiplier,
|
||||
(mass, depth) => settings.WaveDepth.Evaluate(mass) * depth));
|
||||
GravityWavesRadius = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.WaveRadiusMultiplier,
|
||||
(mass, radius) => settings.WaveRadius.Evaluate(mass) * radius));
|
||||
GravityWavesSpeed = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.WaveSpeedMultiplier,
|
||||
(mass, speed) => settings.WaveSpeed.Evaluate(mass) * speed));
|
||||
}
|
||||
}
|
||||
|
||||
// public class Sun : GasGiant
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
public class AsteroidBelt
|
||||
{
|
||||
public float4[] Transforms; // x, y, rotation, scale
|
||||
|
|
@ -343,9 +408,11 @@ public class Orbit
|
|||
public float2 Velocity = float2.zero;
|
||||
public float2 Position = float2.zero;
|
||||
public float2 PreviousPosition = float2.zero;
|
||||
public ReadOnlyReactiveProperty<float> Period;
|
||||
|
||||
public Orbit(OrbitData data)
|
||||
public Orbit(PlanetSettings settings, OrbitData data)
|
||||
{
|
||||
Data = data;
|
||||
Period = new ReadOnlyReactiveProperty<float>(data.Distance.Select(f => settings.OrbitPeriod.Evaluate(f)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,13 +116,16 @@ public abstract class BodyData : DatabaseEntry, INamedEntry
|
|||
[JsonProperty("resources"), Key(4)]
|
||||
public Dictionary<Guid, float> Resources = new Dictionary<Guid, float>();
|
||||
|
||||
[JsonProperty("radiusMul")] [Key(5)]
|
||||
[JsonProperty("bodyRadiusMul")] [Key(5)]
|
||||
public ReactiveProperty<float> BodyRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("gravRadiusMul")] [Key(6)]
|
||||
public ReactiveProperty<float> GravityRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthMul")] [Key(6)]
|
||||
[JsonProperty("depthMul")] [Key(7)]
|
||||
public ReactiveProperty<float> GravityDepthMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthExp")] [Key(7)]
|
||||
[JsonProperty("depthExp")] [Key(8)]
|
||||
public ReactiveProperty<float> GravityDepthExponent = new ReactiveProperty<float>(8);
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
|
|
@ -141,50 +144,69 @@ public class PlanetData : BodyData
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class AsteroidBeltData : BodyData
|
||||
{
|
||||
[JsonProperty("asteroids"), Key(8)]
|
||||
[JsonProperty("asteroids"), Key(9)]
|
||||
public Asteroid[] Asteroids;
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class GasGiantData : BodyData
|
||||
{
|
||||
[JsonProperty("firstOffsetDomainRotationSpeed"), Key(8)]
|
||||
[JsonProperty("firstOffsetDomainRotationSpeed"), Key(9)]
|
||||
public ReactiveProperty<float> FirstOffsetDomainRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("firstOffsetRotationSpeed"), Key(9)]
|
||||
[JsonProperty("firstOffsetRotationSpeed"), Key(10)]
|
||||
public ReactiveProperty<float> FirstOffsetRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("secondOffsetDomainRotationSpeed"), Key(10)]
|
||||
[JsonProperty("secondOffsetDomainRotationSpeed"), Key(11)]
|
||||
public ReactiveProperty<float> SecondOffsetDomainRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("secondOffsetRotationSpeed"), Key(11)]
|
||||
[JsonProperty("secondOffsetRotationSpeed"), Key(12)]
|
||||
public ReactiveProperty<float> SecondOffsetRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("albedoRotationSpeed"), Key(12)]
|
||||
[JsonProperty("albedoRotationSpeed"), Key(13)]
|
||||
public ReactiveProperty<float> AlbedoRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("gravRadiusMul")] [Key(14)]
|
||||
public ReactiveProperty<float> WaveRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthMul")] [Key(15)]
|
||||
public ReactiveProperty<float> WaveDepthMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthExp")] [Key(16)]
|
||||
public ReactiveProperty<float> WaveDepthExponent = new ReactiveProperty<float>(8);
|
||||
|
||||
[JsonProperty("depthExp")] [Key(17)]
|
||||
public ReactiveProperty<float> WaveSpeedMultiplier = new ReactiveProperty<float>(8);
|
||||
|
||||
[JsonProperty("materialOverrides"), Key(13)]
|
||||
[JsonProperty("materialOverrides"), Key(18)]
|
||||
public List<string> MaterialOverrides = new List<string>();
|
||||
|
||||
[JsonProperty("colors"), Key(14)]
|
||||
[JsonProperty("colors"), Key(19)]
|
||||
public ReactiveProperty<float4[]> Colors = new ReactiveProperty<float4[]>();
|
||||
}
|
||||
|
||||
public class SunData : GasGiantData
|
||||
{
|
||||
[JsonProperty("lightColor"), Key(15)]
|
||||
[JsonProperty("lightColor"), Key(20)]
|
||||
public ReactiveProperty<float3> LightColor = new ReactiveProperty<float3>(float3.zero);
|
||||
|
||||
[JsonProperty("fogTintColor"), Key(16)]
|
||||
[JsonProperty("fogTintColor"), Key(21)]
|
||||
public ReactiveProperty<float3> FogTintColor = new ReactiveProperty<float3>(float3.zero);
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class Asteroid
|
||||
{
|
||||
[JsonProperty("distance"), Key(0)]
|
||||
public float Distance;
|
||||
|
||||
[JsonProperty("phase"), Key(1)]
|
||||
public float Phase;
|
||||
|
||||
[JsonProperty("size"), Key(2)]
|
||||
public float Size;
|
||||
|
||||
[JsonProperty("rotationSpeed"), Key(3)]
|
||||
public float RotationSpeed;
|
||||
}
|
||||
|
||||
|
|
@ -195,13 +217,13 @@ public class OrbitData : DatabaseEntry
|
|||
public Guid Parent;
|
||||
|
||||
[JsonProperty("distance"), Key(2)]
|
||||
public float Distance;
|
||||
public ReactiveProperty<float> Distance;
|
||||
|
||||
[JsonProperty("phase"), Key(3)]
|
||||
public float Phase;
|
||||
|
||||
[JsonProperty("period"), Key(4)]
|
||||
public float Period;
|
||||
|
||||
// [JsonProperty("period"), Key(4)]
|
||||
// public float Period;
|
||||
|
||||
public static float2 Evaluate(float phase)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
|
@ -11,13 +12,42 @@ using Random = Unity.Mathematics.Random;
|
|||
public class ZoneGenerator
|
||||
{
|
||||
public static ZonePack GenerateZone(
|
||||
GameContext context,
|
||||
ZoneGenerationSettings settings,
|
||||
Dictionary<string,GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
string name,
|
||||
float2 position)
|
||||
{
|
||||
var random = new Random(Convert.ToUInt32(abs(name.GetHashCode())));
|
||||
var radius = settings.ZoneRadius.Evaluate(random.NextFloat() * mapLayers["Radius"].Evaluate(position, settings.ShapeSettings));
|
||||
var mass = settings.ZoneMass.Evaluate(random.NextFloat() * mapLayers["Mass"].Evaluate(position, settings.ShapeSettings));
|
||||
|
||||
return GenerateZone(settings, mapLayers, resources, name, position, mass, radius, random);
|
||||
}
|
||||
|
||||
public static ZonePack GenerateZone(
|
||||
ZoneGenerationSettings settings,
|
||||
Dictionary<string,GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
float mass,
|
||||
float radius)
|
||||
{
|
||||
var name = Guid.NewGuid().ToString().Substring(0, 8);
|
||||
var position = float2(0f);
|
||||
var random = new Random(Convert.ToUInt32(abs(name.GetHashCode())));
|
||||
|
||||
return GenerateZone(settings, mapLayers, resources, name, position, mass, radius, random);
|
||||
}
|
||||
|
||||
private static ZonePack GenerateZone(
|
||||
ZoneGenerationSettings settings,
|
||||
Dictionary<string,GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
string name,
|
||||
float2 position,
|
||||
IEnumerable<GalaxyMapLayerData> mapLayers,
|
||||
IEnumerable<SimpleCommodityData> resources,
|
||||
float mass = 0,
|
||||
float radius = 0)
|
||||
float mass,
|
||||
float radius,
|
||||
Random random)
|
||||
{
|
||||
var zone = new ZoneData
|
||||
{
|
||||
|
|
@ -30,33 +60,12 @@ public class ZoneGenerator
|
|||
Data = zone
|
||||
};
|
||||
|
||||
var zoneRadius = radius != 0 ? radius : context.Random.NextPowerDistribution(
|
||||
context.GlobalData.MinimumZoneRadius,
|
||||
context.GlobalData.MaximumZoneRadius,
|
||||
context.GlobalData.ZoneRadiusExponent,
|
||||
1 / lerp(
|
||||
context.GlobalData.ResourceDensityMinimum,
|
||||
context.GlobalData.ResourceDensityMaximum,
|
||||
mapLayers
|
||||
.First(m => m.Name == "Radius")
|
||||
.Evaluate(zone.Position, context.GlobalData)));
|
||||
zone.Radius = zoneRadius;
|
||||
|
||||
var zoneMass = mass != 0 ? mass : context.Random.NextPowerDistribution(
|
||||
context.GlobalData.MinimumZoneMass,
|
||||
context.GlobalData.MaximumZoneMass,
|
||||
context.GlobalData.ZoneMassExponent,
|
||||
1 / lerp(
|
||||
context.GlobalData.ResourceDensityMinimum,
|
||||
context.GlobalData.ResourceDensityMaximum,
|
||||
mapLayers
|
||||
.First(m => m.Name == "Mass")
|
||||
.Evaluate(zone.Position, context.GlobalData)));
|
||||
zone.Mass = zoneMass;
|
||||
zone.Radius = radius;
|
||||
zone.Mass = mass;
|
||||
|
||||
//Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
|
||||
|
||||
var planets = GenerateEntities(context, zone, zoneMass, zoneRadius);
|
||||
var planets = GenerateEntities(settings, ref random, zone);
|
||||
|
||||
// Create collections to map between zone generator output and database entries
|
||||
var orbitMap = new Dictionary<GeneratorPlanet, OrbitData>();
|
||||
|
|
@ -67,8 +76,8 @@ public class ZoneGenerator
|
|||
{
|
||||
var data = new OrbitData
|
||||
{
|
||||
Distance = planet.Distance,
|
||||
Period = planet.Period,
|
||||
Distance = new ReactiveProperty<float>(planet.Distance),
|
||||
//Period = planet.Period,
|
||||
Phase = planet.Phase
|
||||
};
|
||||
orbitMap[planet] = data;
|
||||
|
|
@ -83,21 +92,22 @@ public class ZoneGenerator
|
|||
: Guid.Empty;
|
||||
|
||||
// Cache resource densities
|
||||
var resourceMaps = mapLayers.ToDictionary(m => m.ID, m => m.Evaluate(zone.Position, context.GlobalData));
|
||||
var resourceMaps = mapLayers.Values
|
||||
.ToDictionary(m => m.ID, m => m.Evaluate(zone.Position, settings.ShapeSettings));
|
||||
|
||||
pack.Planets = planets.Where(p=>!p.Empty).Select(planet =>
|
||||
{
|
||||
Dictionary<Guid, float> planetResources = new Dictionary<Guid, float>();
|
||||
BodyType bodyType = planet.Belt ? BodyType.Asteroid :
|
||||
planet.Mass > context.GlobalData.SunMass ? BodyType.Sun :
|
||||
planet.Mass > context.GlobalData.GasGiantMass ? BodyType.GasGiant :
|
||||
planet.Mass > context.GlobalData.PlanetMass ? BodyType.Planet : BodyType.Planetoid;
|
||||
planet.Mass > settings.SunMass ? BodyType.Sun :
|
||||
planet.Mass > settings.GasGiantMass ? BodyType.GasGiant :
|
||||
planet.Mass > settings.PlanetMass ? BodyType.Planet : BodyType.Planetoid;
|
||||
|
||||
foreach (var r in resources)
|
||||
{
|
||||
if ((bodyType & r.ResourceBodyType) != 0)
|
||||
{
|
||||
float quantity = ResourceValue(r, context, r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]));
|
||||
float quantity = ResourceValue(ref random, settings, r, r.ResourceDensity.Aggregate(1f, (m, rdm) => m * resourceMaps[rdm]));
|
||||
if (r.Floor < quantity) planetResources.Add(r.ID, quantity);
|
||||
}
|
||||
}
|
||||
|
|
@ -129,21 +139,21 @@ public class ZoneGenerator
|
|||
if (planetData is AsteroidBeltData beltData)
|
||||
{
|
||||
beltData.Asteroids =
|
||||
Enumerable.Range(0, (int) (pow(planetData.Mass.Value, context.GlobalData.BeltMassExponent) / context.GlobalData.BeltMassRatio * orbitMap[planet].Distance))
|
||||
Enumerable.Range(0, (int) (settings.AsteroidCount.Evaluate(beltData.Mass.Value * orbitMap[planet].Distance.Value)))
|
||||
.Select(_ => new Asteroid
|
||||
{
|
||||
Distance = context.Random.NextFloat(orbitMap[planet].Distance * .5f, orbitMap[planet].Distance * 1.5f),
|
||||
Phase = context.Random.NextFloat(),
|
||||
Size = pow(context.Random.NextFloat(), context.GlobalData.AsteroidSizeExponent) *
|
||||
(context.GlobalData.AsteroidSizeMax - context.GlobalData.AsteroidSizeMin) +
|
||||
context.GlobalData.AsteroidSizeMin,
|
||||
RotationSpeed = context.Random.NextFloat() * context.GlobalData.AsteroidRotationSpeed
|
||||
}).ToArray();
|
||||
Distance = random.NextFloat(orbitMap[planet].Distance.Value * .5f, orbitMap[planet].Distance.Value * 1.5f),
|
||||
Phase = random.NextFloat(),
|
||||
Size = random.NextFloat(),
|
||||
RotationSpeed = settings.AsteroidRotationSpeed.Evaluate(random.NextFloat())
|
||||
})
|
||||
//.OrderByDescending(a=>a.Size)
|
||||
.ToArray();
|
||||
}
|
||||
else if (planetData is GasGiantData gas)
|
||||
{
|
||||
var times = Enumerable.Range(0, 5).Select(i => (float) i / 4).ToArray();
|
||||
gas.Colors.Value = times.Select(time => float4(context.Random.NextFloat3(),time)).ToArray();
|
||||
gas.Colors.Value = times.Select(time => float4(random.NextFloat3(),time)).ToArray();
|
||||
gas.AlbedoRotationSpeed.Value = -3;
|
||||
gas.FirstOffsetRotationSpeed.Value = 5;
|
||||
gas.FirstOffsetDomainRotationSpeed.Value = 0;
|
||||
|
|
@ -151,7 +161,7 @@ public class ZoneGenerator
|
|||
gas.SecondOffsetDomainRotationSpeed.Value = -25;
|
||||
if (planetData is SunData sun)
|
||||
{
|
||||
sun.FogTintColor.Value = sun.LightColor.Value = context.Random.NextFloat3();
|
||||
sun.FogTintColor.Value = sun.LightColor.Value = random.NextFloat3();
|
||||
gas.FirstOffsetDomainRotationSpeed.Value = 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -161,36 +171,34 @@ public class ZoneGenerator
|
|||
return pack;
|
||||
}
|
||||
|
||||
static float ResourceValue(SimpleCommodityData resource, GameContext context, float density)
|
||||
static float ResourceValue(ref Random random, ZoneGenerationSettings settings, SimpleCommodityData resource, float density)
|
||||
{
|
||||
return context.Random.NextPowerDistribution(resource.Minimum, resource.Maximum, resource.Exponent,
|
||||
1 / lerp(context.GlobalData.ResourceDensityMinimum, context.GlobalData.ResourceDensityMaximum, density));
|
||||
return random.NextPowerDistribution(resource.Minimum, resource.Maximum, resource.Exponent,
|
||||
1 / lerp(settings.ResourceDensityMinimum, settings.ResourceDensityMaximum, density));
|
||||
}
|
||||
|
||||
public static GeneratorPlanet[] GenerateEntities(GameContext context, ZoneData data, float mass, float radius)
|
||||
public static GeneratorPlanet[] GenerateEntities(ZoneGenerationSettings settings, ref Random random, ZoneData zone)
|
||||
{
|
||||
var random = new Random();
|
||||
random.InitState(unchecked((uint)data.Name.GetHashCode()));
|
||||
|
||||
var root = new GeneratorPlanet
|
||||
{
|
||||
Context = context,
|
||||
Mass = mass,
|
||||
ChildDistanceMaximum = radius * .75f,
|
||||
ChildDistanceMinimum = context.GlobalData.PlanetRadius(mass)
|
||||
Settings = settings,
|
||||
Mass = zone.Mass,
|
||||
ChildDistanceMaximum = zone.Radius * .75f,
|
||||
ChildDistanceMinimum = settings.PlanetSafetyRadius.Evaluate(zone.Mass)
|
||||
};
|
||||
|
||||
// There is some chance of generating a rosette or binary system
|
||||
// Probabilities which are fixed for the entire galaxy are in GlobalData, contained in the GameContext
|
||||
var rosette = random.NextFloat() < context.GlobalData.RosetteProbability;
|
||||
var rosette = random.NextFloat() < settings.RosetteProbability;
|
||||
|
||||
if (rosette)
|
||||
{
|
||||
// Create a rosette with a number of vertices between 2 and 9 inclusive
|
||||
root.ExpandRosette((int)(random.NextFloat(1, 5) + random.NextFloat(1, 5)));
|
||||
root.ExpandRosette(ref random, (int)(random.NextFloat(1, 5) + random.NextFloat(1, 5)));
|
||||
|
||||
// Create a small number of less massive "captured" planets orbiting past the rosette
|
||||
root.ExpandSolar(
|
||||
ref random,
|
||||
count: (int)(random.NextFloat(1, 3) * random.NextFloat(1, 2)),
|
||||
massMulMin: .6f,
|
||||
massMulMax: .8f,
|
||||
|
|
@ -200,11 +208,12 @@ public class ZoneGenerator
|
|||
massFraction: .1f);
|
||||
|
||||
var averageChildMass = root.Children.Sum(p => p.Mass) / root.Children.Count;
|
||||
foreach(var p in root.Children.Where(c=>c.Mass>context.GlobalData.GasGiantMass))
|
||||
foreach(var p in root.Children.Where(c=>c.Mass>settings.GasGiantMass))
|
||||
{
|
||||
var m = p.Mass / averageChildMass;
|
||||
// Give each child in the rosette its own mini solar system
|
||||
p.ExpandSolar(
|
||||
ref random,
|
||||
count: (int) (random.NextFloat(1, 3 * m) + random.NextFloat(1, 3 * m)),
|
||||
massMulMin: 0.75f,
|
||||
massMulMax: 2.5f,
|
||||
|
|
@ -219,6 +228,7 @@ public class ZoneGenerator
|
|||
{
|
||||
// Create a regular old boring solar system
|
||||
root.ExpandSolar(
|
||||
ref random,
|
||||
count: random.NextInt(5, 15),
|
||||
massMulMin: 0.5f,
|
||||
massMulMax: 2.0f,
|
||||
|
|
@ -229,43 +239,65 @@ public class ZoneGenerator
|
|||
);
|
||||
}
|
||||
|
||||
// Get all children that are above the satellite creation mass floor and not rosette members
|
||||
var satelliteCandidates = rosette
|
||||
? root.AllPlanets().Where(p => p != root && p.Parent != root && p.Mass > context.GlobalData.SatelliteCreationMassFloor)
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass > context.GlobalData.SatelliteCreationMassFloor);
|
||||
|
||||
var alreadyExpanded = new List<GeneratorPlanet>();
|
||||
var binaries = new List<GeneratorPlanet>();
|
||||
foreach (var planet in satelliteCandidates)
|
||||
for(int i=0; i<settings.SatellitePasses; i++)
|
||||
{
|
||||
// There's a chance of generating satellites for each qualified planet
|
||||
if (random.NextFloat() < context.GlobalData.SatelliteCreationProbability)
|
||||
// Get all children that are above the satellite creation mass floor and not rosette members
|
||||
var satelliteCandidates = rosette
|
||||
? root.AllPlanets().Where(p =>
|
||||
p != root &&
|
||||
p.Parent != root &&
|
||||
p.Mass > settings.SatelliteCreationMassFloor &&
|
||||
!alreadyExpanded.Contains(p))
|
||||
: root.AllPlanets().Where(p =>
|
||||
p != root &&
|
||||
p.Mass > settings.SatelliteCreationMassFloor &&
|
||||
!alreadyExpanded.Contains(p));
|
||||
|
||||
foreach (var planet in satelliteCandidates)
|
||||
{
|
||||
// Sometimes the satellite is so massive that it forms a binary system (like Earth!)
|
||||
if (random.NextFloat() < context.GlobalData.BinaryCreationProbability)
|
||||
// There's a chance of generating satellites for each qualified planet
|
||||
if (random.NextFloat() < settings.SatelliteCreationProbability)
|
||||
{
|
||||
planet.ExpandRosette(2);
|
||||
binaries.AddRange(planet.Children);
|
||||
// Sometimes the satellite is so massive that it forms a binary system (like Earth!)
|
||||
if (random.NextFloat() < settings.BinaryCreationProbability)
|
||||
{
|
||||
planet.ExpandRosette(ref random, 2);
|
||||
binaries.AddRange(planet.Children);
|
||||
}
|
||||
// Otherwise, terrestrial planets get a couple satellites while gas giants get many
|
||||
else
|
||||
{
|
||||
planet.ExpandSolar(
|
||||
ref random,
|
||||
count: planet.Mass < settings.GasGiantMass ? random.NextInt(1, 3) : random.NextInt(2, 6),
|
||||
massMulMin: .75f,
|
||||
massMulMax: 1.5f,
|
||||
distMulMin: 1.05f,
|
||||
distMulMax: 1.25f,
|
||||
jupiterJump: 1,
|
||||
massFraction: .15f); // Planetary satellites are not nearly as massive as planets themselves
|
||||
}
|
||||
alreadyExpanded.Add(planet);
|
||||
}
|
||||
// Otherwise, terrestrial planets get a couple satellites while gas giants get many
|
||||
else planet.ExpandSolar(
|
||||
count: planet.Mass < context.GlobalData.GasGiantMass ? random.NextInt(1,3) : random.NextInt(4,10),
|
||||
massMulMin: .75f,
|
||||
massMulMax: 1.5f,
|
||||
distMulMin: 1.05f,
|
||||
distMulMax: 1.25f,
|
||||
jupiterJump: 1,
|
||||
massFraction: .15f); // Planetary satellites are not nearly as massive as planets themselves
|
||||
}
|
||||
}
|
||||
|
||||
// Get all children that are below the belt creation mass floor and not rosette members, also exclude binaries
|
||||
var beltCandidates = rosette
|
||||
? root.AllPlanets().Where(p => p != root && p.Parent != root && p.Mass < context.GlobalData.BeltMassCeiling && !binaries.Contains(p))
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass < context.GlobalData.BeltMassCeiling && !binaries.Contains(p));
|
||||
? root.AllPlanets().Where(p => p != root && p.Parent != root && p.Mass < settings.BeltMassCeiling && !binaries.Contains(p))
|
||||
: root.AllPlanets().Where(p => p != root && p.Mass < settings.BeltMassCeiling && !binaries.Contains(p));
|
||||
|
||||
foreach(var planet in beltCandidates.Reverse())
|
||||
if (random.NextFloat() < context.GlobalData.BeltProbability && !planet.Parent.Children.Any(p=>p.Belt))
|
||||
if (random.NextFloat() < settings.BeltProbability && !planet.Parent.Children.Any(p=>p.Belt))
|
||||
planet.Belt = true;
|
||||
|
||||
var totalMass = root.AllPlanets().Sum(p => p.Mass);
|
||||
var rootMass = root.Mass;
|
||||
foreach (var planet in root.AllPlanets())
|
||||
planet.Mass = (planet.Mass / totalMass) * rootMass;
|
||||
|
||||
return root.AllPlanets().ToArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -275,11 +307,11 @@ public class ZoneGenerator
|
|||
// Because they were objects we observed to move in the sky instead of remaining fixed like the stars
|
||||
public class GeneratorPlanet
|
||||
{
|
||||
public GameContext Context;
|
||||
public ZoneGenerationSettings Settings;
|
||||
public float Distance;
|
||||
public float Phase;
|
||||
public float Mass;
|
||||
public float Period;
|
||||
//public float Period;
|
||||
public float ChildDistanceMinimum;
|
||||
public float ChildDistanceMaximum;
|
||||
public bool Empty = false;
|
||||
|
|
@ -295,7 +327,7 @@ public class GeneratorPlanet
|
|||
|
||||
// Create children that fill a single orbit, equally spaced
|
||||
// https://en.wikipedia.org/wiki/Klemperer_rosette
|
||||
public void ExpandRosette(int vertices)
|
||||
public void ExpandRosette(ref Random random, int vertices)
|
||||
{
|
||||
//Debug.Log("Expanding Rosette");
|
||||
|
||||
|
|
@ -306,7 +338,7 @@ public class GeneratorPlanet
|
|||
var sharedMass = Mass / vertices * 2;
|
||||
|
||||
// Proportion of the masses of sequential pairs is random, but only for even vertex counts
|
||||
var proportion = vertices % 2 == 0 ? Context.Random.NextFloat(.5f,.95f) : .5f;
|
||||
var proportion = vertices % 2 == 0 ? random.NextFloat(.5f,.95f) : .5f;
|
||||
|
||||
// Place children at a fixed distance in the center of the range
|
||||
var dist = (ChildDistanceMinimum + ChildDistanceMaximum) / 2;
|
||||
|
|
@ -318,22 +350,22 @@ public class GeneratorPlanet
|
|||
var p1 = OrbitData.Evaluate(1.0f / vertices) * dist;
|
||||
|
||||
// Maximum child distance is half the distance to the neighbor minus the neighbor's radius
|
||||
var p0ChildDist = (distance(p0, p1) * proportion - Context.GlobalData.PlanetRadius(sharedMass * (1 - proportion))) * .75f;
|
||||
var p1ChildDist = (distance(p0, p1) * (1 - proportion) - Context.GlobalData.PlanetRadius(sharedMass * proportion)) * .75f;
|
||||
var p0ChildDist = (distance(p0, p1) * proportion - Settings.PlanetSafetyRadius.Evaluate(sharedMass * (1 - proportion))) * .75f;
|
||||
var p1ChildDist = (distance(p0, p1) * (1 - proportion) - Settings.PlanetSafetyRadius.Evaluate(sharedMass * proportion)) * .75f;
|
||||
|
||||
for (int i = 0; i < vertices; i++)
|
||||
{
|
||||
var child = new GeneratorPlanet
|
||||
{
|
||||
Context = Context,
|
||||
Settings = Settings,
|
||||
Parent = this,
|
||||
Mass = sharedMass * (i % 2 == 0 ? proportion : 1 - proportion), // Masses alternate
|
||||
Distance = dist,
|
||||
Phase = (float) i / vertices,
|
||||
ChildDistanceMaximum = (i % 2 == 0 ? p0ChildDist : p1ChildDist)
|
||||
};
|
||||
child.ChildDistanceMinimum = Context.GlobalData.PlanetRadius(child.Mass) * 2;
|
||||
child.Period = Context.GlobalData.OrbitalPeriod(child.Distance);
|
||||
child.ChildDistanceMinimum = Settings.PlanetSafetyRadius.Evaluate(child.Mass) * 2;
|
||||
//child.Period = Settings..Evaluate(child.Distance);
|
||||
Children.Add(child);
|
||||
}
|
||||
|
||||
|
|
@ -341,7 +373,7 @@ public class GeneratorPlanet
|
|||
}
|
||||
|
||||
// Create children that mimic the distribution of planetary masses in the solar system
|
||||
public void ExpandSolar(int count, float massMulMin, float massMulMax, float distMulMin, float distMulMax, float jupiterJump, float massFraction)
|
||||
public void ExpandSolar(ref Random random, int count, float massMulMin, float massMulMax, float distMulMin, float distMulMax, float jupiterJump, float massFraction)
|
||||
{
|
||||
//Debug.Log("Expanding Solar");
|
||||
// Expansion is impossible when child space is full
|
||||
|
|
@ -360,13 +392,13 @@ public class GeneratorPlanet
|
|||
// jupiterJump is an additional mass multiplier applied after half of the planets
|
||||
for (var i = 1; i < count; i++)
|
||||
{
|
||||
massTotal += masses[i] = masses[i - 1] * Context.Random.NextFloat(massMulMin, massMulMax) * (count/2==i ? jupiterJump : 1);
|
||||
distances[i] = distances[i - 1] * Context.Random.NextFloat(distMulMin, distMulMax);
|
||||
massTotal += masses[i] = masses[i - 1] * random.NextFloat(massMulMin, massMulMax) * (count/2==i ? jupiterJump : 1);
|
||||
distances[i] = distances[i - 1] * random.NextFloat(distMulMin, distMulMax);
|
||||
}
|
||||
|
||||
// Add some randomness to child masses
|
||||
for (var i = 0; i < masses.Length; i++)
|
||||
masses[i] *= Context.Random.NextFloat(.1f, 1f);
|
||||
masses[i] *= random.NextFloat(.1f, 1f);
|
||||
|
||||
// Normalize the masses of the children
|
||||
for (var i = 0; i < count; i++)
|
||||
|
|
@ -378,24 +410,24 @@ public class GeneratorPlanet
|
|||
var oldDistances = (float[]) distances.Clone();
|
||||
for (var i = 0; i < count; i++)
|
||||
distances[i] = lerp(ChildDistanceMinimum, ChildDistanceMaximum,
|
||||
(oldDistances[i] - oldDistances[0]) / (oldDistances[count - 1] - oldDistances[0])) + Context.GlobalData.PlanetRadius(masses[i]);
|
||||
(oldDistances[i] - oldDistances[0]) / (oldDistances[count - 1] - oldDistances[0])) + Settings.PlanetSafetyRadius.Evaluate(masses[i]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
// Only instantiate children above the mass floor
|
||||
if (masses[i] > Context.GlobalData.MassFloor)
|
||||
if (masses[i] > Settings.MassFloor)
|
||||
{
|
||||
var child = new GeneratorPlanet
|
||||
{
|
||||
Context = Context,
|
||||
Settings = Settings,
|
||||
Parent = this,
|
||||
Mass = masses[i],
|
||||
Distance = distances[i],
|
||||
Phase = Context.Random.NextFloat()
|
||||
Phase = random.NextFloat()
|
||||
};
|
||||
child.Period = Context.GlobalData.OrbitalPeriod(child.Distance);
|
||||
child.ChildDistanceMinimum = Context.GlobalData.PlanetRadius(child.Mass) * 2;
|
||||
//child.Period = Context.GlobalData.OrbitalPeriod(child.Distance);
|
||||
child.ChildDistanceMinimum = Settings.PlanetSafetyRadius.Evaluate(child.Mass) * 2;
|
||||
// Maximum child distance of child is the smallest distance to either of its neighbors
|
||||
child.ChildDistanceMaximum = min(i == 0 ? child.Distance - ChildDistanceMinimum : child.Distance - distances[i - 1],
|
||||
i < count - 1 ? distances[i + 1] - child.Distance : float.PositiveInfinity);
|
||||
|
|
|
|||
|
|
@ -358,7 +358,7 @@ public class ColonyTab : MonoBehaviour
|
|||
entity.RemoveCargo(gear);
|
||||
var ship = Context.CreateShip(gear.ID, Enumerable.Empty<Guid>(),
|
||||
Enumerable.Empty<Guid>(), entity.Zone, entity.Corporation, _parentEntity.ID, gear.Name);
|
||||
_context.SetParent(ship, entity);
|
||||
ship.SetParent(entity);
|
||||
}
|
||||
else // Equip Item
|
||||
entity.Equip(gear.ID, true);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
Shader "VolSample/Volume Render" {
|
||||
Properties{
|
||||
_MainTex( "", 2D ) = "white" {}
|
||||
_Surface("Surface", 2D) = "black" {}
|
||||
_Patch("Patch", 2D) = "black" {}
|
||||
_Displacement("Displacement", 2D) = "black" {}
|
||||
|
|
@ -43,6 +44,7 @@
|
|||
// Shared shader code for pixel view rays, given screen pos and camera frame vectors.
|
||||
// Camera vectors are passed in as this shader is run from a post proc camera, so the unity built-in values are not useful.
|
||||
uniform float4x4 _CamProj;
|
||||
uniform float4x4 _CamInvProj;
|
||||
uniform float3 _CamPos;
|
||||
uniform float3 _CamForward;
|
||||
uniform float3 _CamRight;
|
||||
|
|
@ -137,7 +139,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
float4 RayMarch( in float3 origin, in float3 direction, in float zbuf, in float2 screenUV )
|
||||
float4 RayMarch( in float3 origin, in float3 direction, in float zbuf, in float2 screenUV, out float depth )
|
||||
{
|
||||
half rand = nrand(screenUV + frac(_Time.x));
|
||||
//half rand = tex2D(_DitheringTex, screenUV * _DitheringCoords.xy + _DitheringCoords.zw).r;
|
||||
|
|
@ -160,6 +162,8 @@
|
|||
rayDist += step;
|
||||
}
|
||||
|
||||
depth = rayDist;
|
||||
|
||||
return pow( sum, 1 / _Gamma );
|
||||
}
|
||||
|
||||
|
|
@ -196,12 +200,33 @@
|
|||
rayOrigin = _WorldSpaceCameraPos;
|
||||
|
||||
float2 p = 2.0*(q - 0.5);
|
||||
float4 d = mul(_CamProj, float4(p, 1, 1));
|
||||
float4 d = mul(_CamProj, float4(p, 0, 1));
|
||||
d.xyz /= d.w;
|
||||
//rd = (d - rayOrigin);
|
||||
rd = normalize(d - rayOrigin);
|
||||
rayOrigin = d;
|
||||
//rayOrigin += _ProjectionParams.y * rd;
|
||||
}
|
||||
|
||||
float4 frag( v2f i ) : SV_Target
|
||||
inline float LinearEyeDepthToOutDepth(float z)
|
||||
{
|
||||
return (1 - _ZBufferParams.w * z) / (_ZBufferParams.z * z);
|
||||
}
|
||||
|
||||
float3 DepthToWorld(float2 uv, float depth) {
|
||||
float z = (1-depth) * 2.0 - 1.0;
|
||||
|
||||
float4 clipSpacePosition = float4(uv * 2.0 - 1.0, z, 1.0);
|
||||
|
||||
float4 viewSpacePosition = mul(_CamInvProj,clipSpacePosition);
|
||||
viewSpacePosition /= viewSpacePosition.w;
|
||||
|
||||
float4 worldSpacePosition = mul(unity_ObjectToWorld,viewSpacePosition);
|
||||
|
||||
return worldSpacePosition.xyz;
|
||||
}
|
||||
|
||||
float4 frag( v2f i ) : SV_Target //out float outDepth : SV_Depth
|
||||
{
|
||||
float2 q = i.screenPos.xy / i.screenPos.w;
|
||||
|
||||
|
|
@ -212,29 +237,38 @@
|
|||
// z buffer / scene depth for this pixel
|
||||
float4 screenPos = UNITY_PROJ_COORD( i.screenPos );
|
||||
float2 screenUV = screenPos.xy / screenPos.w;
|
||||
float depthValue = LinearEyeDepth( tex2Dproj( _CameraDepthTexture, screenPos ).r );
|
||||
float depthSample = tex2Dproj( _CameraDepthTexture, screenPos ).r;
|
||||
//float depthValue = LinearEyeDepth(depthSample);
|
||||
|
||||
float3 worldDepth = DepthToWorld(screenPos, depthSample);
|
||||
float depthValue = length(worldDepth-rayOrigin);
|
||||
// march through volume
|
||||
float4 clouds = RayMarch( rayOrigin, rayDirection, depthValue, screenUV );
|
||||
float rayDist;
|
||||
float4 clouds = RayMarch( rayOrigin, rayDirection, depthValue, screenUV, rayDist );
|
||||
|
||||
float3 bgcol = tex2Dlod( _MainTex, float4(q, 0., 0.) );
|
||||
// add in camera render colours, if not zfar (so we exclude skybox)
|
||||
if(clouds.a < .99 && depthValue < _DepthCeiling + _DepthBlend)
|
||||
{
|
||||
float3 bgcol = tex2Dlod( _MainTex, float4(q, 0., 0.) );
|
||||
|
||||
// Blend out camera render when outside marching range
|
||||
if( depthValue >= _DepthCeiling )
|
||||
clouds.a = lerp(clouds.a, 1, (depthValue - _DepthCeiling) / _DepthBlend);
|
||||
|
||||
clouds.xyz += (1. - clouds.a) * bgcol;
|
||||
clouds.xyz = lerp(clouds.xyz, bgcol, 1-clouds.a);
|
||||
//clouds.xyz += (1. - clouds.a) * bgcol;
|
||||
// assume zbuffer represents opaque surface
|
||||
clouds.a = 1.;
|
||||
|
||||
}
|
||||
|
||||
// else
|
||||
// {
|
||||
// clouds.xyz = lerp(clouds.xyz, bgcol, );
|
||||
// clouds.xyz = lerp(clouds.xyz, bgcol, 1-clouds.a);
|
||||
// }
|
||||
//clouds.rgb *= clouds.a;
|
||||
|
||||
//outDepth = LinearEyeDepthToOutDepth(min(depthValue, rayDist));
|
||||
|
||||
return clouds;
|
||||
/*
|
||||
|
|
@ -243,6 +277,7 @@
|
|||
// post processing
|
||||
return postProcessing( col, q );*/
|
||||
}
|
||||
|
||||
|
||||
ENDCG
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ TextureImporter:
|
|||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
|
|
@ -26,7 +26,7 @@ TextureImporter:
|
|||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolution: 1
|
||||
seamlessCubemap: 1
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
|
|
|
|||
|
|
@ -509,6 +509,7 @@
|
|||
<Compile Include="Assets\Scripts\ServerShared\Agents\Mining.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\ZoneData.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\NIH\LinqFaster\Max.cs" />
|
||||
<Compile Include="Assets\Scripts\ServerShared\Settings.cs" />
|
||||
<None Include="Assets\Scripts\ServerShared\NIH\LinqFaster\readme.txt" />
|
||||
<None Include="Assets\Scripts\ServerShared\Economy.Shared.Unity.asmdef" />
|
||||
<Reference Include="Unity.Mathematics">
|
||||
|
|
|
|||
BIN
GameData/Home.zone
Normal file
BIN
GameData/Home.zone
Normal file
Binary file not shown.
Loading…
Reference in a new issue