From 3b69c89cb34e74364c46558159170fa1a0020709 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 18 Jun 2024 10:51:59 -0500 Subject: [PATCH 1/3] force sync attempt --- .../AsteroidEntities/AsteroidSpawner.cs | 12 +++++++ .../Scripts/DynamicAsteroids/MainSession.cs | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs index 9ae8cff6..c5880a1a 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs @@ -508,6 +508,18 @@ private void ProcessGravityCheckQueue() } } + public List GetAsteroidStates() + { + return _asteroids.Select(asteroid => new AsteroidState + { + Position = asteroid.PositionComp.GetPosition(), + Size = asteroid.Size, + Type = asteroid.Type, + EntityId = asteroid.EntityId + }).ToList(); + } + + public void SpawnAsteroids(List zones) { int totalSpawnAttempts = 0; diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs index 176f854f..cb7afb34 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs @@ -2,6 +2,7 @@ using Invalid.DynamicRoids; using Sandbox.ModAPI; using System; +using System.Linq; using VRage.Game.Components; using VRage.Input; using VRageMath; @@ -137,6 +138,31 @@ private void RemoveSpawnArea(string name) MyAPIGateway.Utilities.ShowMessage("DynamicAsteroids", $"Removed spawn area '{name}'"); } + private void SyncAsteroidsToPlayers() + { + if (!MyAPIGateway.Session.IsServer) return; + + var asteroidStates = _spawner.GetAsteroidStates(); + var messages = asteroidStates.Select(state => new AsteroidNetworkMessage( + state.Position, + state.Size, + Vector3D.Zero, + Vector3D.Zero, + state.Type, + false, + state.EntityId, + false, + true, + Quaternion.Identity + )).ToArray(); + + var container = new AsteroidNetworkMessageContainer(messages); + var messageBytes = MyAPIGateway.Utilities.SerializeToBinary(container); + + MyAPIGateway.Multiplayer.SendMessageToOthers(32000, messageBytes); + } + + public override void UpdateAfterSimulation() { try @@ -164,8 +190,11 @@ public override void UpdateAfterSimulation() _spawner.SendNetworkMessages(); _networkMessageTimer = AsteroidSettings.NetworkMessageInterval; } + + SyncAsteroidsToPlayers(); // Add this line to sync asteroids periodically } + if (MyAPIGateway.Session?.Player?.Character != null && _spawner._asteroids != null) { Vector3D characterPosition = MyAPIGateway.Session.Player.Character.PositionComp.GetPosition(); @@ -210,6 +239,11 @@ private void OnMessageReceived(byte[] message) Log.Info($"Client: Received message of {message.Length} bytes"); var asteroidMessage = MyAPIGateway.Utilities.SerializeFromBinary(message); + if (asteroidMessage.IsInitialCreation) + { + SyncAsteroidsToPlayers(); // Sync all asteroids when a new player joins + } + if (asteroidMessage.IsRemoval) { var asteroid = MyEntities.GetEntityById(asteroidMessage.EntityId) as AsteroidEntity; From 2698869c280d80cd781cbf53aca48b40d707e2a0 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 18 Jun 2024 10:59:44 -0500 Subject: [PATCH 2/3] Revert "force sync attempt" This reverts commit 3b69c89cb34e74364c46558159170fa1a0020709. --- .../AsteroidEntities/AsteroidSpawner.cs | 12 ------- .../Scripts/DynamicAsteroids/MainSession.cs | 34 ------------------- 2 files changed, 46 deletions(-) diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs index c5880a1a..9ae8cff6 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidSpawner.cs @@ -508,18 +508,6 @@ private void ProcessGravityCheckQueue() } } - public List GetAsteroidStates() - { - return _asteroids.Select(asteroid => new AsteroidState - { - Position = asteroid.PositionComp.GetPosition(), - Size = asteroid.Size, - Type = asteroid.Type, - EntityId = asteroid.EntityId - }).ToList(); - } - - public void SpawnAsteroids(List zones) { int totalSpawnAttempts = 0; diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs index cb7afb34..176f854f 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/MainSession.cs @@ -2,7 +2,6 @@ using Invalid.DynamicRoids; using Sandbox.ModAPI; using System; -using System.Linq; using VRage.Game.Components; using VRage.Input; using VRageMath; @@ -138,31 +137,6 @@ private void RemoveSpawnArea(string name) MyAPIGateway.Utilities.ShowMessage("DynamicAsteroids", $"Removed spawn area '{name}'"); } - private void SyncAsteroidsToPlayers() - { - if (!MyAPIGateway.Session.IsServer) return; - - var asteroidStates = _spawner.GetAsteroidStates(); - var messages = asteroidStates.Select(state => new AsteroidNetworkMessage( - state.Position, - state.Size, - Vector3D.Zero, - Vector3D.Zero, - state.Type, - false, - state.EntityId, - false, - true, - Quaternion.Identity - )).ToArray(); - - var container = new AsteroidNetworkMessageContainer(messages); - var messageBytes = MyAPIGateway.Utilities.SerializeToBinary(container); - - MyAPIGateway.Multiplayer.SendMessageToOthers(32000, messageBytes); - } - - public override void UpdateAfterSimulation() { try @@ -190,11 +164,8 @@ public override void UpdateAfterSimulation() _spawner.SendNetworkMessages(); _networkMessageTimer = AsteroidSettings.NetworkMessageInterval; } - - SyncAsteroidsToPlayers(); // Add this line to sync asteroids periodically } - if (MyAPIGateway.Session?.Player?.Character != null && _spawner._asteroids != null) { Vector3D characterPosition = MyAPIGateway.Session.Player.Character.PositionComp.GetPosition(); @@ -239,11 +210,6 @@ private void OnMessageReceived(byte[] message) Log.Info($"Client: Received message of {message.Length} bytes"); var asteroidMessage = MyAPIGateway.Utilities.SerializeFromBinary(message); - if (asteroidMessage.IsInitialCreation) - { - SyncAsteroidsToPlayers(); // Sync all asteroids when a new player joins - } - if (asteroidMessage.IsRemoval) { var asteroid = MyEntities.GetEntityById(asteroidMessage.EntityId) as AsteroidEntity; From 5fc1de55db9f6007c2502695d87e7b62334a72c7 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Tue, 18 Jun 2024 12:32:12 -0500 Subject: [PATCH 3/3] put the size back to size/2 --- .../DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs index 392e0f5e..11a4da7c 100644 --- a/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs +++ b/Dynamic Asteroids/Data/Scripts/DynamicAsteroids/AsteroidEntities/AsteroidEntity.cs @@ -502,8 +502,7 @@ public bool DoDamage(float damage, MyStringHash damageSource, bool sync, MyHitIn private void CreatePhysics() { float mass = 10000 * Size * Size * Size; - //float radius = Size / 2; // Assuming Size represents the diameter - float radius = Size; // Assuming Size represents the diameter + float radius = Size / 2; // Assuming Size represents the diameter PhysicsSettings settings = MyAPIGateway.Physics.CreateSettingsForPhysics( this,