Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rem 2. Edit this variable if applicable (do not add quotes or end with backslash
set STEAM_PATH=C:\Program Files (x86)\Steam

rem 3. Edit this with your mod's workshop id.
set WORKSHOP_ID=3130656484
set WORKSHOP_ID=3365316959

rem Now you can run it every time you want to update the mod on DS and client.

Expand All @@ -26,6 +26,4 @@ rmdir "%CLIENT_PATH%" /S /Q
rmdir "%DS_PATH%" /S /Q

robocopy.exe .\ "%DS_PATH%" *.* /S /xd .git bin obj .vs ignored /xf *.lnk *.git* *.bat *.zip *.7z *.blend* *.md *.log *.sln *.csproj *.csproj.user *.ruleset modinfo.sbmi
robocopy.exe "%DS_PATH%" "%CLIENT_PATH%" *.* /S

pause
robocopy.exe "%DS_PATH%" "%CLIENT_PATH%" *.* /S
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using VRage.Game.Components;
using Epstein_Fusion_DS.Networking;
using VRage.Game.Components;
using VRage.Utils;
using static Epstein_Fusion_DS.Communication.DefinitionDefs;

namespace Epstein_Fusion_DS.Communication
{
[MySessionComponentDescriptor(MyUpdateOrder.Simulation, int.MinValue)]
[MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation, int.MinValue)]
internal class ModularDefinitionSender : MySessionComponentBase
{
internal ModularDefinitionContainer StoredDef;


public override void LoadData()
{
MyLog.Default.WriteLineAndConsole(
Expand All @@ -19,10 +21,18 @@ public override void LoadData()

// Send definitions over as soon as the API loads, and create the API before anything else can init.
Epstein_Fusion_DS.ModularDefinition.ModularApi.Init(ModContext, SendDefinitions);

new HeartNetwork().LoadData();
}

public override void UpdateAfterSimulation()
{
HeartNetwork.I.Update();
}

protected override void UnloadData()
{
HeartNetwork.I.UnloadData();
Epstein_Fusion_DS.ModularDefinition.ModularApi.UnloadData();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Epstein_Fusion_DS.Communication;
using Epstein_Fusion_DS.HudHelpers;
using Epstein_Fusion_DS.Networking;
using ProtoBuf;
using Sandbox.Game.Entities;
using Sandbox.Game.EntityComponents;
using Sandbox.ModAPI;
using VRage.Game;
using VRage.Game.Components;
using VRage.Game.ModAPI;
using VRage.Game.ModAPI.Network;
using VRage.ModAPI;
using VRage.Network;
using VRage.ObjectBuilders;
using VRage.Sync;
using VRageMath;

namespace Epstein_Fusion_DS.HeatParts.ExtendableRadiators
{
[MyEntityComponentDescriptor(typeof(MyObjectBuilder_TerminalBlock), false, "ExtendableRadiatorBase")]
internal class ExtendableRadiator : MyGameLogicComponent
internal class ExtendableRadiator : MyGameLogicComponent, IMyEventProxy
{
public static readonly Guid RadiatorGuid = new Guid("e6b87818-5fd8-47a6-a480-3365e20214e1");
public static readonly string[] ValidPanelSubtypes =
Expand All @@ -30,7 +31,7 @@ internal class ExtendableRadiator : MyGameLogicComponent
internal StoredRadiator[] StoredRadiators = Array.Empty<StoredRadiator>();
internal RadiatorAnimation Animation;

private bool _isExtended = true;
private MySync<bool, SyncDirection.BothWays> _isExtended;
public bool IsExtended
{
get
Expand All @@ -42,11 +43,7 @@ public bool IsExtended
if (Animation.IsActive)
return;

if (value)
ExtendPanels();
else
RetractPanels();
_isExtended = value;
_isExtended.Value = value;
}
}

Expand All @@ -67,6 +64,9 @@ public override void UpdateOnceBeforeFrame()
if (Block?.CubeGrid?.Physics == null)
return;

if (MyAPIGateway.Session.IsServer)
_isExtended.Value = true;

LoadSettings();

try
Expand All @@ -81,6 +81,13 @@ public override void UpdateOnceBeforeFrame()
Animation = new RadiatorAnimation(this);
NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
//NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

_isExtended.ValueChanged += SyncValueChanged;
}

public override void MarkForClose()
{
_isExtended.ValueChanged -= SyncValueChanged;
}

public override void UpdateAfterSimulation()
Expand All @@ -90,8 +97,6 @@ public override void UpdateAfterSimulation()
// This is stupid, but prevents the mod profiler cost from being incurred every tick per block when inactive
if (Animation.IsActive)
Animation.UpdateTick();
else
MakePanelsVisible(false);
}

public override bool IsSerialized()
Expand All @@ -108,6 +113,17 @@ public override bool IsSerialized()
return base.IsSerialized();
}

private void SyncValueChanged(MySync<bool, SyncDirection.BothWays> sync)
{
if (Animation.IsActive)
return;

if (sync.Value)
ExtendPanels();
else
RetractPanels();
}

internal void SaveSettings()
{
if (Block == null)
Expand Down Expand Up @@ -139,7 +155,11 @@ internal void LoadSettings()
var loadedSettings = MyAPIGateway.Utilities.SerializeFromBinary<StoredRadiator[]>(Convert.FromBase64String(rawData)) ?? Array.Empty<StoredRadiator>();

StoredRadiators = loadedSettings;
_isExtended = StoredRadiators.Length == 0;
if (MyAPIGateway.Session.IsServer)
{
_isExtended.Value = StoredRadiators.Length == 0;
HeartNetwork.SendToEveryoneInSync(new BlockPacket(StoredRadiators, Block.CubeGrid, Block, null), Block.GetPosition());
}

for (int i = 0; i < StoredRadiators.Length; i++)
{
Expand All @@ -166,7 +186,7 @@ internal void LoadSettings()

public void ExtendPanels()
{
if (_isExtended || Animation.IsActive)
if (Animation.IsActive || !MyAPIGateway.Session.IsServer)
return;

Vector3I nextPosition = Block.Position;
Expand All @@ -182,11 +202,13 @@ public void ExtendPanels()
{
MyAPIGateway.Utilities.ShowNotification("Block already exists at position!");
DebugDraw.AddGridPoint(nextPosition, Block.CubeGrid, Color.Red, 4);
_isExtended = false;
_isExtended.Value = false;
return;
}
}

HeartNetwork.SendToEveryoneInSync(new BlockPacket(StoredRadiators, Block.CubeGrid, Block, true), Block.GetPosition());

for (int i = 0; i < StoredRadiators.Length; i++)
{
StoredRadiators[i].ObjectBuilder.Name = null;
Expand All @@ -209,7 +231,7 @@ public void ExtendPanels()
/// <summary>
/// Panels start invisible for the animation to play. This makes them visible again.
/// </summary>
public void MakePanelsVisible(bool clearStored = true)
public void MakePanelsVisible()
{
IMyCubeBlock nextBlock;
int idx = 1;
Expand All @@ -222,13 +244,13 @@ public void MakePanelsVisible(bool clearStored = true)
idx++;
}

if (clearStored)
StoredRadiators = Array.Empty<StoredRadiator>();
StoredRadiators = Array.Empty<StoredRadiator>();
HeartNetwork.SendToEveryoneInSync(new BlockPacket(StoredRadiators, Block.CubeGrid, Block, null), Block.GetPosition());
}

public void RetractPanels()
{
if (!_isExtended)
if (Animation.IsActive || !MyAPIGateway.Session.IsServer)
return;

IMyCubeBlock nextBlock;
Expand All @@ -237,18 +259,15 @@ public void RetractPanels()

while (GetNextPanel(idx, out nextBlock))
{
var builder = nextBlock.GetObjectBuilderCubeBlock(true);

builder.BlockOrientation = nextBlock.Orientation;

Matrix matrix;
builders.Add(new StoredRadiator(builder, nextBlock.LocalMatrix, nextBlock.CalculateCurrentModel(out matrix), Block.LocalMatrix));
var storedRad = new StoredRadiator(nextBlock, Block);
builders.Add(storedRad);

nextBlock.CubeGrid.RemoveBlock(nextBlock.SlimBlock, true);
idx++;
}

StoredRadiators = builders.ToArray();
HeartNetwork.SendToEveryoneInSync(new BlockPacket(StoredRadiators, Block.CubeGrid, Block, false), Block.GetPosition());

Animation.StartRetraction();
}
Expand Down Expand Up @@ -282,6 +301,19 @@ public StoredRadiator(MyObjectBuilder_CubeBlock objectBuilder, Matrix localMatri
Model = model;
BaseLocalMatrix = baseLocalMatrix;
}

public StoredRadiator(IMyCubeBlock block, IMyCubeBlock referenceBlock)
{
var builder = block.GetObjectBuilderCubeBlock(true);

builder.BlockOrientation = block.Orientation;

Matrix matrix;
ObjectBuilder = builder;
LocalMatrix = block.LocalMatrix;
Model = block.CalculateCurrentModel(out matrix);
BaseLocalMatrix = referenceBlock.LocalMatrix;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Epstein_Fusion_DS.HudHelpers;
using Sandbox.Engine.Physics;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using VRage.Game.Components;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRage.ObjectBuilders;
using VRageMath;
using CollisionLayers = Sandbox.Engine.Physics.MyPhysics.CollisionLayers;
using Color = VRageMath.Color;

namespace Epstein_Fusion_DS.HeatParts.ExtendableRadiators
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Epstein_Fusion_DS.HeatParts.ExtendableRadiators;
using ProtoBuf;
using Sandbox.ModAPI;
using VRage.Game.ModAPI;
using static Epstein_Fusion_DS.HeatParts.ExtendableRadiators.ExtendableRadiator;

namespace Epstein_Fusion_DS.Networking
{
[ProtoContract]
internal class BlockPacket : PacketBase
{
private static void LogInfo(string text) => ModularDefinition.ModularApi.Log(text);

[ProtoMember(1)] public StoredRadiator[] Stored;
[ProtoMember(2)] public long CubeGridId;
[ProtoMember(3)] public long RadiatorBlockId;
[ProtoMember(5)] public bool? IsExtending;

private BlockPacket()
{
}

public BlockPacket(StoredRadiator[] stored, IMyCubeGrid grid, IMyCubeBlock radiatorBlock, bool? isExtending)
{
Stored = stored;
CubeGridId = grid.EntityId;
RadiatorBlockId = radiatorBlock.EntityId;
IsExtending = isExtending;

//LogInfo("Sending " + ToString());
}

public override void Received(ulong SenderSteamId)
{
if (MyAPIGateway.Session.IsServer)
return;

//LogInfo("Received " + ToString());

foreach (var radiator in Stored)
{
var block = (MyAPIGateway.Entities.GetEntityById(CubeGridId) as IMyCubeGrid)?.AddBlock(radiator.ObjectBuilder, true);
if (block?.FatBlock != null)
block.FatBlock.Visible = false;
}

var logic = (MyAPIGateway.Entities.GetEntityById(RadiatorBlockId) as IMyCubeBlock)?.GameLogic
?.GetAs<ExtendableRadiator>();
if (logic != null)
{
logic.StoredRadiators = Stored;

if (IsExtending.HasValue)
{
if (IsExtending.Value)
logic.Animation?.StartExtension();
else
logic.Animation?.StartRetraction();
}
}
}

public override string ToString()
{
return $"{CubeGridId}::{RadiatorBlockId}\n{Stored.Length}";
}
}
}
Loading
Loading