-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from InvalidArgument3/roid-rewrite
dynamicdebris template for later
- Loading branch information
Showing
25 changed files
with
854 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Dynamic Debris Framework/Data/Scripts/DynamicDebrisFramework/API/ApiDelegates.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.API { | ||
internal class ApiDelegates { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Dynamic Debris Framework/Data/Scripts/DynamicDebrisFramework/API/DebrisFrameworkAPI.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.API { | ||
internal class DebrisFrameworkAPI { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ic Debris Framework/Data/Scripts/DynamicDebrisFramework/Components/DebrisDamageHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.Components { | ||
internal class DebrisDamageHandler { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ic Debris Framework/Data/Scripts/DynamicDebrisFramework/Components/DebrisGridComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.Components { | ||
internal class DebrisGridComponent { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...bris Framework/Data/Scripts/DynamicDebrisFramework/Components/DebrisIntegrityComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.Components { | ||
internal class DebrisIntegrityComponent { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...Debris Framework/Data/Scripts/DynamicDebrisFramework/Core/Session/DebrisNetworkManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.Core.Session { | ||
internal class DebrisNetworkManager { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...Debris Framework/Data/Scripts/DynamicDebrisFramework/Core/Session/DebrisPhysicsManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.Core.Session { | ||
internal class DebrisPhysicsManager { | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
...bris Framework/Data/Scripts/DynamicDebrisFramework/Core/Session/DebrisSessionComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
using Sandbox.ModAPI; | ||
using VRage.Game.Components; | ||
using VRage.Game.ModAPI; | ||
using System; | ||
using System.Collections.Generic; | ||
using VRageMath; | ||
using DynamicDebrisFramework.Entities; | ||
using DynamicDebrisFramework.Spawning; | ||
using DynamicDebrisFramework.Utils; | ||
using DynamicDebrisFramework.Zones; | ||
using VRage.Game; | ||
|
||
|
||
namespace DynamicDebrisFramework.Core.Session { | ||
[MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation)] | ||
public class DebrisSessionComponent : MySessionComponentBase { | ||
public static DebrisSessionComponent Instance { get; private set; } | ||
|
||
private readonly DebrisNetworkManager _networkManager; | ||
private readonly SpawnManager _spawnManager; | ||
private readonly ZoneManager _zoneManager; | ||
private readonly DebrisEntityManager _entityManager; | ||
private readonly DebrisLogger _logger; | ||
private readonly DebrisConfig _config; | ||
|
||
private bool _isInitialized; | ||
private readonly Random _random; | ||
|
||
public DebrisSessionComponent() { | ||
Instance = this; | ||
_random = new Random(_config.Seed); | ||
_logger = new DebrisLogger(); | ||
_networkManager = new DebrisNetworkManager(); | ||
_spawnManager = new SpawnManager(); | ||
_zoneManager = new ZoneManager(); | ||
_entityManager = new DebrisEntityManager(); | ||
} | ||
|
||
public override void LoadData() { | ||
try { | ||
_logger.Info("Loading Dynamic Debris Framework..."); | ||
_config.LoadConfig(); | ||
|
||
if (MyAPIGateway.Session.IsServer) { | ||
InitializeServer(); | ||
} | ||
else { | ||
InitializeClient(); | ||
} | ||
|
||
RegisterNetworkHandlers(); | ||
_isInitialized = true; | ||
_logger.Info("Dynamic Debris Framework loaded successfully."); | ||
} | ||
catch (Exception ex) { | ||
_logger.Error($"Failed to load Dynamic Debris Framework: {ex}"); | ||
} | ||
} | ||
|
||
private void InitializeServer() { | ||
_logger.Info("Initializing server components..."); | ||
_spawnManager.Initialize(_config); | ||
_zoneManager.Initialize(_config); | ||
_entityManager.Initialize(_config); | ||
} | ||
|
||
private void InitializeClient() { | ||
_logger.Info("Initializing client components..."); | ||
_networkManager.InitializeClient(); | ||
} | ||
|
||
private void RegisterNetworkHandlers() { | ||
_logger.Info("Registering network handlers..."); | ||
MyAPIGateway.Multiplayer.RegisterSecureMessageHandler( | ||
_config.NetworkChannels.EntitySync, | ||
_networkManager.HandleEntitySync); | ||
MyAPIGateway.Multiplayer.RegisterSecureMessageHandler( | ||
_config.NetworkChannels.ZoneSync, | ||
_networkManager.HandleZoneSync); | ||
} | ||
|
||
public override void UpdateAfterSimulation() { | ||
try { | ||
if (!_isInitialized) return; | ||
|
||
if (MyAPIGateway.Session.IsServer) { | ||
UpdateServer(); | ||
} | ||
|
||
UpdateClient(); | ||
} | ||
catch (Exception ex) { | ||
_logger.Error($"Error in update cycle: {ex}"); | ||
} | ||
} | ||
|
||
private void UpdateServer() { | ||
_zoneManager.Update(); | ||
_spawnManager.Update(); | ||
_entityManager.Update(); | ||
_networkManager.SyncToClients(); | ||
} | ||
|
||
private void UpdateClient() { | ||
_entityManager.UpdateClient(); | ||
_zoneManager.UpdateClient(); | ||
} | ||
|
||
protected override void UnloadData() { | ||
try { | ||
_logger.Info("Unloading Dynamic Debris Framework..."); | ||
|
||
if (MyAPIGateway.Session?.IsServer == true) { | ||
_entityManager.CleanupEntities(); | ||
} | ||
|
||
UnregisterNetworkHandlers(); | ||
|
||
_spawnManager.Close(); | ||
_zoneManager.Close(); | ||
_entityManager.Close(); | ||
_networkManager.Close(); | ||
_logger.Close(); | ||
|
||
Instance = null; | ||
} | ||
catch (Exception ex) { | ||
_logger.Error($"Error during framework shutdown: {ex}"); | ||
} | ||
} | ||
|
||
private void UnregisterNetworkHandlers() { | ||
MyAPIGateway.Multiplayer.UnregisterSecureMessageHandler( | ||
_config.NetworkChannels.EntitySync, | ||
_networkManager.HandleEntitySync); | ||
MyAPIGateway.Multiplayer.UnregisterSecureMessageHandler( | ||
_config.NetworkChannels.ZoneSync, | ||
_networkManager.HandleZoneSync); | ||
} | ||
|
||
public Vector3D GetRandomVector() { | ||
double theta = _random.NextDouble() * 2.0 * Math.PI; | ||
double phi = Math.Acos(2.0 * _random.NextDouble() - 1.0); | ||
double sinPhi = Math.Sin(phi); | ||
|
||
return new Vector3D( | ||
sinPhi * Math.Cos(theta), | ||
sinPhi * Math.Sin(theta), | ||
Math.Cos(phi) | ||
); | ||
} | ||
|
||
public bool IsPlayerAdmin(IMyPlayer player) { | ||
return MyAPIGateway.Session.OnlineMode == MyOnlineModeEnum.OFFLINE | ||
|| MyAPIGateway.Session.IsUserAdmin(player.SteamUserId); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...c Debris Framework/Data/Scripts/DynamicDebrisFramework/Core/Session/DebrisSpawnManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DynamicDebrisFramework.Core.Session { | ||
internal class DebrisSpawnManager { | ||
} | ||
} |
Oops, something went wrong.