Skip to content

Commit

Permalink
add atmosblocker and some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Dec 5, 2024
1 parent 8cd0084 commit eead23d
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 93 deletions.
20 changes: 18 additions & 2 deletions Assets/Content/WorldObjects/Structures/Walls/SteelWall.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ GameObject:
- component: {fileID: 6072928490511251397}
- component: {fileID: -6923105539505770605}
- component: {fileID: -7978277362494375466}
- component: {fileID: 827317970361906839}
m_Layer: 0
m_Name: SteelWall
m_TagString: Untagged
Expand Down Expand Up @@ -265,8 +266,8 @@ MonoBehaviour:
<ChildNetworkObjects>k__BackingField: []
SerializedTransformProperties:
Position: {x: 0, y: 0, z: 0}
Rotation: {x: 0, y: 0, z: 0, w: 0}
LocalScale: {x: 0, y: 0, z: 0}
Rotation: {x: 0, y: 0, z: 0, w: 1}
LocalScale: {x: 1, y: 1, z: 1}
_isNetworked: 1
_isGlobal: 0
_initializeOrder: 0
Expand Down Expand Up @@ -367,6 +368,21 @@ MonoBehaviour:
_networkObjectCache: {fileID: -2900075557854325373}
_asset: {fileID: 11400000, guid: afd2790edc5c26a48ae1e0f45ecb1f32, type: 2}
_tileObjectSo: {fileID: 11400000, guid: a0b4e2f901dd14b429586c816b29b97f, type: 2}
--- !u!114 &827317970361906839
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3591147544166670882}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2db43ceae5151054892557650c883733, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 255
_addedNetworkObject: {fileID: -2900075557854325373}
_networkObjectCache: {fileID: 0}
--- !u!1 &7790124558541205835
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using SS3D.Core;
using SS3D.Core.Behaviours;
using SS3D.Engine.AtmosphericsRework;

public class AtmosBlocker : NetworkActor
{
public override void OnStartServer(){
base.OnStartServer();
Subsystems.Get<AtmosManager>().ChangeState(Position, AtmosState.Blocked);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ private void Update()

public AtmosContainer GetAtmosContainer(Vector3 worldPosition)
{
if (atmosMaps == null)
{
return null;
}
foreach (AtmosMap map in atmosMaps)
{
AtmosContainer atmos = map.GetTileAtmosObject(worldPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
using SS3D.Engine.AtmosphericsRework;
using SS3D.Interactions;
using SS3D.Interactions.Interfaces;
using SS3D.Systems.Atmospherics.AtmosRework.Machinery;
using SS3D.Systems.Tile;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;

public class FilterAtmosObject : BasicAtmosDevice, IInteractionTarget
public class FilterAtmosObject : TrinaryAtmosDevice
{
private const float MaxPressure = 4500f;

Expand Down Expand Up @@ -57,29 +54,19 @@ public class FilterAtmosObject : BasicAtmosDevice, IInteractionTarget
[Server]
public override void StepAtmos(float dt)
{
if (!_filterActive)
base.StepAtmos(dt);
if (!_filterActive || !AllPipesConnected)
{
return;
}

Vector3 otherOutputPosition = transform.position + transform.forward;
Vector3 filterOutputPosition = transform.position + transform.right;
Vector3 inputPosition = transform.position - transform.forward;

if (!Subsystems.Get<PipeSystem>().TryGetAtmosPipe(otherOutputPosition, _pipeLayer, out IAtmosPipe outputOther)
|| !Subsystems.Get<PipeSystem>().TryGetAtmosPipe(filterOutputPosition, _pipeLayer, out IAtmosPipe outputFiltered)
|| !Subsystems.Get<PipeSystem>().TryGetAtmosPipe(inputPosition, _pipeLayer, out IAtmosPipe input))
{
return;
}

// Both outputs must not be blocked
if (outputFiltered.AtmosObject.Pressure > MaxPressure && outputOther.AtmosObject.Pressure > MaxPressure)
if (SidePipe.AtmosObject.Pressure > MaxPressure && FrontPipe.AtmosObject.Pressure > MaxPressure)
{
return;
}

AtmosObject atmosInput = input.AtmosObject;
AtmosObject atmosInput = BackPipe.AtmosObject;
float maxMolesToTransfer = (atmosInput.Pressure * _litersPerSecond * dt) / (GasConstants.gasConstant * atmosInput.Temperature);
float4 molesToTransfer = atmosInput.CoreGassesProportions * math.max(maxMolesToTransfer, atmosInput.TotalMoles);

Expand All @@ -90,9 +77,9 @@ public override void StepAtmos(float dt)


bool4 filterCoreGasses= new bool4(_filterOxygen, _filterNitrogen, _filterCarbonDioxyde, _filterPlasma);
Subsystems.Get<PipeSystem>().AddCoreGasses(filterOutputPosition, molesToTransfer * (int4)filterCoreGasses, _pipeLayer);
Subsystems.Get<PipeSystem>().AddCoreGasses(otherOutputPosition, molesToTransfer * (int4)!filterCoreGasses, _pipeLayer);
Subsystems.Get<PipeSystem>().RemoveCoreGasses(inputPosition, molesToTransfer, _pipeLayer);
Subsystems.Get<PipeSystem>().AddCoreGasses(SidePipePosition, molesToTransfer * (int4)filterCoreGasses, _pipeLayer);
Subsystems.Get<PipeSystem>().AddCoreGasses(FrontPipePosition, molesToTransfer * (int4)!filterCoreGasses, _pipeLayer);
Subsystems.Get<PipeSystem>().RemoveCoreGasses(BackPipePosition, molesToTransfer, _pipeLayer);
}

private void FilterInteract(InteractionEvent interactionEvent, InteractionReference arg2)
Expand All @@ -101,7 +88,7 @@ private void FilterInteract(InteractionEvent interactionEvent, InteractionRefere
filterView.GetComponent<FilterView>().Initialize(this);
}

public IInteraction[] CreateTargetInteractions(InteractionEvent interactionEvent)
public override IInteraction[] CreateTargetInteractions(InteractionEvent interactionEvent)
{
return new IInteraction[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Unity.Mathematics;
using UnityEngine;

public class MixerAtmosObject : BasicAtmosDevice, IInteractionTarget
public class MixerAtmosObject : TrinaryAtmosDevice
{

private const float MaxPressure = 4500f;
Expand All @@ -27,8 +27,6 @@ public class MixerAtmosObject : BasicAtmosDevice, IInteractionTarget
[SyncVar(OnChange = nameof(SyncTargetPressure))]
private float _targetPressure = 101f;

private TileLayer _pipeLayer = TileLayer.PipeLeft;

[ServerRpc(RequireOwnership = false)] public void SetMixerActive(bool mixerActive) => _mixerActive = mixerActive;

[ServerRpc(RequireOwnership = false)] public void SetTargetPressure(float targetPressure) => _targetPressure = targetPressure;
Expand All @@ -42,7 +40,7 @@ public class MixerAtmosObject : BasicAtmosDevice, IInteractionTarget
public GameObject MixerViewPrefab;


public IInteraction[] CreateTargetInteractions(InteractionEvent interactionEvent)
public override IInteraction[] CreateTargetInteractions(InteractionEvent interactionEvent)
{
return new IInteraction[]
{
Expand All @@ -55,40 +53,31 @@ public IInteraction[] CreateTargetInteractions(InteractionEvent interactionEvent

public override void StepAtmos(float dt)
{
if (!_mixerActive)
{
return;
}
base.StepAtmos(dt);

Vector3 outputPosition = transform.position + transform.forward;
Vector3 secondInputPosition = transform.position + transform.right;
Vector3 firstInputPosition = transform.position - transform.forward;

if (!Subsystems.Get<PipeSystem>().TryGetAtmosPipe(outputPosition, _pipeLayer, out IAtmosPipe output)
|| !Subsystems.Get<PipeSystem>().TryGetAtmosPipe(secondInputPosition, _pipeLayer, out IAtmosPipe secondInput)
|| !Subsystems.Get<PipeSystem>().TryGetAtmosPipe(firstInputPosition, _pipeLayer, out IAtmosPipe firstInput))
if (!_mixerActive || !AllPipesConnected)
{
return;
}

float ratioOnetoTwo = _inputOneAmount / 100f;

if (firstInput.AtmosObject.TotalMoles <= 1f || secondInput.AtmosObject.TotalMoles <= 1f ||output.AtmosObject.Pressure >= _targetPressure || output.AtmosObject.Pressure >= MaxPressure)
if (BackPipe.AtmosObject.TotalMoles <= 1f || SidePipe.AtmosObject.TotalMoles <= 1f || FrontPipe.AtmosObject.Pressure >= _targetPressure || FrontPipe.AtmosObject.Pressure >= MaxPressure)
{
return;
}

// Calculate necessary moles to transfer using PV=nRT
float pressureDifference = _targetPressure - output.AtmosObject.Pressure;
float transferMoles = dt * pressureDifference * 1000 * output.AtmosObject.Volume / (output.AtmosObject.Temperature * GasConstants.gasConstant);
float pressureDifference = _targetPressure - FrontPipe.AtmosObject.Pressure;
float transferMoles = dt * pressureDifference * 1000 * FrontPipe.AtmosObject.Volume / (FrontPipe.AtmosObject.Temperature * GasConstants.gasConstant);

float transferMoles1 = ratioOnetoTwo * transferMoles;
float transferMoles2 = (1f - ratioOnetoTwo) * transferMoles;


// We can't transfer more moles than there are
float firstInputTotalMoles = firstInput.AtmosObject.TotalMoles;
float secondInputTotalMoles = secondInput.AtmosObject.TotalMoles;
float firstInputTotalMoles = BackPipe.AtmosObject.TotalMoles;
float secondInputTotalMoles = SidePipe.AtmosObject.TotalMoles;

// If one of the inputs didn't contain enough gas, scale the other down
if (transferMoles1 > firstInputTotalMoles)
Expand All @@ -103,13 +92,13 @@ public override void StepAtmos(float dt)
transferMoles2 = secondInputTotalMoles;
}

float4 molesFirstToTransfer = firstInput.AtmosObject.CoreGassesProportions * transferMoles1;
float4 molesSecondToTransfer = firstInput.AtmosObject.CoreGassesProportions * transferMoles2;
float4 molesFirstToTransfer = BackPipe.AtmosObject.CoreGassesProportions * transferMoles1;
float4 molesSecondToTransfer = BackPipe.AtmosObject.CoreGassesProportions * transferMoles2;

Subsystems.Get<PipeSystem>().RemoveCoreGasses(firstInputPosition, molesFirstToTransfer, _pipeLayer);
Subsystems.Get<PipeSystem>().RemoveCoreGasses(secondInputPosition, molesSecondToTransfer, _pipeLayer);
Subsystems.Get<PipeSystem>().AddCoreGasses(outputPosition, molesFirstToTransfer, _pipeLayer);
Subsystems.Get<PipeSystem>().AddCoreGasses(outputPosition, molesSecondToTransfer, _pipeLayer);
Subsystems.Get<PipeSystem>().RemoveCoreGasses(BackPipePosition, molesFirstToTransfer, Pipelayer);
Subsystems.Get<PipeSystem>().RemoveCoreGasses(SidePipePosition, molesSecondToTransfer, Pipelayer);
Subsystems.Get<PipeSystem>().AddCoreGasses(FrontPipePosition, molesFirstToTransfer, Pipelayer);
Subsystems.Get<PipeSystem>().AddCoreGasses(FrontPipePosition, molesSecondToTransfer, Pipelayer);
}

private void MixerInteract(InteractionEvent interactionEvent, InteractionReference arg2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using SS3D.Core;
using SS3D.Interactions;
using SS3D.Interactions.Interfaces;
using SS3D.Systems.Atmospherics.AtmosRework.Machinery;
using SS3D.Systems.Tile;
using UnityEngine;

public abstract class TrinaryAtmosDevice : BasicAtmosDevice, IInteractionTarget
{
protected Vector3 FrontPipePosition;
protected Vector3 BackPipePosition;
protected Vector3 SidePipePosition;

protected IAtmosPipe FrontPipe;
protected IAtmosPipe BackPipe;
protected IAtmosPipe SidePipe;


protected TileLayer Pipelayer = TileLayer.PipeLeft;

[SerializeField]
private bool _sideOnRight;

protected bool AllPipesConnected => FrontPipe != null && BackPipe != null && SidePipe != null;

public override void StepAtmos(float dt)
{
FrontPipePosition = transform.position + transform.forward;
BackPipePosition = transform.position - transform.forward;
SidePipePosition = _sideOnRight ? transform.position + transform.right : transform.position - transform.right;

Subsystems.Get<PipeSystem>().TryGetAtmosPipe(FrontPipePosition, Pipelayer, out FrontPipe);
Subsystems.Get<PipeSystem>().TryGetAtmosPipe(BackPipePosition, Pipelayer, out BackPipe);
Subsystems.Get<PipeSystem>().TryGetAtmosPipe(SidePipePosition, Pipelayer, out SidePipe);
}

public abstract IInteraction[] CreateTargetInteractions(InteractionEvent interactionEvent);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

0 comments on commit eead23d

Please sign in to comment.