Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperate PolkaDOTS, fix Linux compatibility, add containerization pipeline, and add experiment operation mechanism to deployment #1

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Move PolkaDOTS to self-contained package
  • Loading branch information
JerritEic committed Nov 13, 2023
commit 188a1c97e07df0048a26b3edd41123fc9058f4ff
3 changes: 1 addition & 2 deletions Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7670ed7fdc2d435abe14606c6942102a, type: 3}
m_Name:
m_EditorClassIdentifier:
editorArgs: -seed 42 -deploymentID 0 -userID 7 -multiplayRole Host -logStats -statsFile
./Builds/ServerClientLinuxDebug/logs/stats.csv
editorArgs: '-seed 42 -userID 7 '
useDeploymentConfig: 0
deploymentConfig: "{\n\t\"nodes\":[\n\t\t{\n\t\t\t\"nodeID\":0,\n\t\t\t\"nodeIP\":\"\",\n\t\t\t\"worldConfigs\":[\n\t\t\t\t{\n\t\t\t\t\t\"worldName\":
\"GameServer\",\n\t\t\t\t\t\"worldType\":\"Server\",\n\t\t\t\t\t\"initializationMode\":\"Connect\",\n\t\t\t\t\t\"multiplayStreamingRoles\":\"Disabled\",\n\t\t\t\t\t\"serverNodeID\":0,\n\t\t\t\t\t\"streamingNodeID\":-1,\n\t\t\t\t\t\"numThinClients\":0,\n\t\t\t\t\t\"services\":[],\n\t\t\t\t\t\"serviceFilterType\":\"Includes\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"worldName\":
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Editor.meta

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

2 changes: 0 additions & 2 deletions Assets/Scripts/Editor/DrawIfProperty.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections;
using System.Linq;
using Opencraft;
using UnityEditor;
using UnityEngine;

Expand Down
50 changes: 14 additions & 36 deletions Assets/Scripts/Player/Authoring/PlayerAuthoring.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
using System;
using Opencraft.Terrain.Utilities;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode;
using Unity.Physics;
using Unity.Transforms;
using UnityEngine;

namespace Opencraft.Player.Authoring
{

public struct Player : IComponentData
public struct PlayerContainingArea : IComponentData
{
// Link to an associated configuration entity
//public Entity PlayerConfig;
// Link to containing area
public Entity ContainingArea;
// Link to containing area
public int3 ContainingAreaLocation;
// Movement variables
//[GhostField(Quantization = 1000)] public float3 Velocity;
//[GhostField] public byte OnGround;
//[GhostField] public NetworkTick JumpStart;

[GhostField] public int JumpVelocity;
[GhostField] public float Pitch;
[GhostField] public float Yaw;

// Connection related variables
[GhostField] public FixedString32Bytes Username;
public BlobAssetReference<BlobString> multiplayConnectionID;
public Entity Area;
// Where that area is
public int3 AreaLocation;
}

// Component marking this entity as having a specific block selected.
Expand All @@ -43,12 +25,7 @@ public struct SelectedBlock : IComponentData
public int3 neighborBlockLoc;
}


// Similar to NewSpawn, marks this player entity as freshly instantiated
public struct NewPlayer : IComponentData, IEnableableComponent
{
}


// All of a player's input for a frame, uses special component type IInputComponentData
[GhostComponent(PrefabType = GhostPrefabType.AllPredicted, OwnerSendType = SendToOwnerType.SendToNonOwner)]
public struct PlayerInput : IInputComponentData
Expand All @@ -68,17 +45,20 @@ public struct PlayerInput : IInputComponentData
public readonly RefRW<LocalTransform> Transform;

readonly RefRO<AutoCommandTarget> m_AutoCommandTarget;
readonly RefRW<Player> m_Character;
readonly RefRW<PolkaDOTS.Player> m_Character;
//readonly RefRW<PhysicsVelocity> m_Velocity;
readonly RefRO<PlayerInput> m_Input;
readonly RefRO<GhostOwner> m_Owner;
readonly RefRW<SelectedBlock> m_SelectedBlock;
readonly RefRW<PlayerContainingArea> m_Area;

public AutoCommandTarget AutoCommandTarget => m_AutoCommandTarget.ValueRO;
public PlayerInput Input => m_Input.ValueRO;
public int OwnerNetworkId => m_Owner.ValueRO.NetworkId;
public ref Player Player => ref m_Character.ValueRW;
//public ref PhysicsVelocity Velocity => ref m_Velocity.ValueRW;
public ref PolkaDOTS.Player Player => ref m_Character.ValueRW;

public ref PlayerContainingArea ContainingArea => ref m_Area.ValueRW;

public ref SelectedBlock SelectedBlock => ref m_SelectedBlock.ValueRW;
}

Expand All @@ -92,11 +72,9 @@ public override void Bake(PlayerAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new PlayerInput());
AddComponent(entity, new Player
{
//PlayerConfig = GetEntity(authoring.playerConfig.gameObject, TransformUsageFlags.Dynamic)
});
AddComponent(entity, new NewPlayer());
AddComponent(entity, new PolkaDOTS.Player());
AddComponent(entity, new PolkaDOTS.NewPlayer());
AddComponent(entity, new PlayerContainingArea());
AddComponent(entity, new SelectedBlock());
}
}
Expand Down
32 changes: 0 additions & 32 deletions Assets/Scripts/Player/Authoring/PlayerConfigAuthoring.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/Scripts/Player/Authoring/PlayerConfigAuthoring.cs.meta

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/Scripts/Player/Emulated.meta

This file was deleted.

25 changes: 0 additions & 25 deletions Assets/Scripts/Player/Emulated/EmulationBehaviours.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/Scripts/Player/Emulated/InputPlayback.meta

This file was deleted.

14 changes: 8 additions & 6 deletions Assets/Scripts/Player/Multiplay/MultiplayPlayerController.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using System;
using UnityEngine;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Linq;
using System.Net.Mime;
using Opencraft.Statistics;
using Unity.Entities;
using Unity.Profiling;
using Unity.RenderStreaming;
using Unity.Serialization;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine.UI;
using Random = UnityEngine.Random;

/*
* Gathers input from Player GameObject
*/
namespace Opencraft.Player.Multiplay
{
// Collects input either from local devices or a remote input stream using InputActions
public class MultiplayPlayerController : MonoBehaviour
{

[SerializeField] InputReceiver playerInput;
[DontSerialize] public string username;
[DontSerialize]public Vector2 inputMovement;
Expand All @@ -28,7 +30,7 @@ public class MultiplayPlayerController : MonoBehaviour
[DontSerialize]public bool playerEntityExists;
[DontSerialize]public bool playerEntityRequestSent;
[DontSerialize]public Entity playerEntity;

public Text debugText;
//public Text tooltipText;

Expand All @@ -37,7 +39,7 @@ public class MultiplayPlayerController : MonoBehaviour
protected void Awake()
{
playerInput.onDeviceChange += OnDeviceChange;
username = $"{Config.UserID}";
username = $"{PolkaDOTS.Config.UserID}";
}

private void OnEnable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Opencraft.Player.Authoring;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode;
using Unity.Rendering;
using Unity.RenderStreaming;
using Unity.VisualScripting;
using UnityEngine;

/*
* Links player entities and objects
*/
namespace Opencraft.Player.Multiplay
{
// Run on Multiplay hosts, handles sending player spawn/destroy RPCs for Multiplay guests and linking
// player GameObjects to player entities based on Multiplay connectionID
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
[UpdateAfter(typeof(MultiplayInitSystem))]
[UpdateAfter(typeof(PolkaDOTS.Multiplay.MultiplayInitSystem))]
[UpdateInGroup(typeof(InitializationSystemGroup))]
public partial class MultiplayPlayerSystem : SystemBase
public partial class MultiplayPlayerLinkSystem : SystemBase
{
private EntityQuery playerQuery;
protected override void OnCreate()
{
playerQuery= new EntityQueryBuilder(Allocator.Temp)
.WithAllRW<Authoring.Player>()
.WithAll<NewPlayer>()
.WithAllRW<PolkaDOTS.Player>()
.WithAll<PolkaDOTS.NewPlayer>()
.WithAll<GhostOwnerIsLocal>()
.Build(this);
RequireForUpdate<PlayerSpawner>();
}
protected override void OnUpdate()
{
Multiplay multiplay = MultiplaySingleton.Instance;
PolkaDOTS.Multiplay.Multiplay multiplay = PolkaDOTS.Multiplay.MultiplaySingleton.Instance;
if (multiplay.IsUnityNull())
return;

Expand All @@ -57,6 +56,11 @@ protected override void OnUpdate()
if (!playerController.playerEntityExists &&
!playerController.playerEntityRequestSent)
{
// If this player controller is a guest player, use their username instead of the local one
if (connID != "LOCALPLAYER")
{
playerController.username = connID;
}
// Create a spawn player rpc
foreach (var (id, entity) in SystemAPI.Query<RefRO<NetworkId>>().WithEntityAccess()
.WithAll<NetworkStreamInGame>())
Expand Down Expand Up @@ -102,7 +106,7 @@ protected override void OnUpdate()

bool linkPlayerIfExists(ref MultiplayPlayerController playerController, ref EntityCommandBuffer commandBuffer, in PlayerSpawner playerSpawner, in string connID)
{
NativeArray<Authoring.Player> playerData = playerQuery.ToComponentDataArray<Authoring.Player>(Allocator.Temp);
NativeArray<PolkaDOTS.Player> playerData = playerQuery.ToComponentDataArray<PolkaDOTS.Player>(Allocator.Temp);
NativeArray<Entity> playerEntities = playerQuery.ToEntityArray(Allocator.Temp);
for (int i = 0; i < playerEntities.Length; i++)
{
Expand All @@ -119,20 +123,16 @@ bool linkPlayerIfExists(ref MultiplayPlayerController playerController, ref Enti
ref BlobString blobString = ref builder.ConstructRoot<BlobString>();
builder.AllocateString(ref blobString, connID);
// Copy new player component
commandBuffer.SetComponent(playerEntity, new Authoring.Player
commandBuffer.SetComponent(playerEntity, new PolkaDOTS.Player
{
//PlayerConfig = player.PlayerConfig,
//Velocity = player.Velocity,
//OnGround = player.OnGround,
//JumpStart = player.JumpStart,
JumpVelocity = player.JumpVelocity,
Username = player.Username,
multiplayConnectionID = builder.CreateBlobAssetReference<BlobString>(Allocator.Persistent)
});
builder.Dispose();
// Create a new block outline entity. Used by the HighlightSelectedBlockSystem on clients
commandBuffer.Instantiate(playerSpawner.BlockOutline);
commandBuffer.SetComponentEnabled<NewPlayer>(playerEntity, false);
commandBuffer.SetComponentEnabled<PolkaDOTS.NewPlayer>(playerEntity, false);
// Color the player red since it is locally controlled
commandBuffer.SetComponent(playerEntity,
new URPMaterialPropertyBaseColor() { Value = new float4(1, 0, 0, 1) });
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Player/PlayerActionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial struct PlayerActionSystem : ISystem
public void OnCreate(ref SystemState state)
{

state.RequireForUpdate<Authoring.Player>();
state.RequireForUpdate<PolkaDOTS.Player>();
state.RequireForUpdate<TerrainArea>();
state.RequireForUpdate<TerrainSpawner>();
_terrainBlocksBufferLookup = state.GetBufferLookup<TerrainBlocks>(false);
Expand Down
7 changes: 3 additions & 4 deletions Assets/Scripts/Player/PlayerInputSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Opencraft.Player.Authoring;
using Opencraft.Player.Emulated;
using Opencraft.Player.Multiplay;
using Unity.Entities;
using Unity.Mathematics;
Expand All @@ -11,20 +10,20 @@

namespace Opencraft.Player
{
// Collects player input from any local or guest clients every frame.
// Applies collected input to player entities
// Also moves the camera locally for these clients
[UpdateInGroup(typeof(GhostInputSystemGroup))]
public partial struct SamplePlayerInput : ISystem
{
private static float3 _cameraOffset = new float3(0.0f,Env.CAMERA_Y_OFFSET,0.0f);
public void OnUpdate(ref SystemState state)
{
Multiplay.Multiplay multiplay = MultiplaySingleton.Instance;
PolkaDOTS.Multiplay.Multiplay multiplay = PolkaDOTS.Multiplay.MultiplaySingleton.Instance;
if (multiplay.IsUnityNull())
return;
// Apply movement input to owned player ghosts
foreach (var (player, localToWorld, input)
in SystemAPI.Query<RefRO<Authoring.Player>, RefRO<LocalToWorld>, RefRW<PlayerInput>>()
in SystemAPI.Query<RefRO<PolkaDOTS.Player>, RefRO<LocalToWorld>, RefRW<PlayerInput>>()
.WithAll<GhostOwnerIsLocal>())
{
// Check if the connection has been created
Expand Down
Loading