Skip to content

Commit

Permalink
Play mode tests (RE-SS3D#1168)
Browse files Browse the repository at this point in the history
* Early work to create runtime test framework, and basics of input dependency injection.

* Created a movement play mode test.

* Divided Playmode Test organisation into Server, Client and Host.
Created separate test proxies and helpers to be used by all types.

* Created initial host game test.

* Added server tests, and added stub methods to ReadyPlayersSystem and RoundSystem to imitate Broadcasts.

* Restructured test scripts, and created tests for late join issue.

* Initial work on pocket tests.

* Finalized tests for Propagating Pocket Problem.

* Streamlining Server creation of Clients.

* Gave player prefab the player tag, for convenience in finding multiple.

* Server-side test for remaining above station level.

* Refactored server side "PlayersRemainAboveStationLevelAfterSpawn" test to set up in UnityTest rather than SetUp.

* Attempt at placing client windows properly. Not yet functional.

* Created FreePlayMultiplayer test to set up and display eight clients.

* Restructured tests folder to include "Asset Audit" assembly and separate out "Known Issue Reproduction"

* Replace Input Manager with Input Action

* Add InputSystem to ToggleInternalClothingUI.cs and NetworkPhysicsDebug.cs

* Delete redundant Update() in ToggleInternalClothingUI.cs and change mouse position read in ItemGrid.cs

* Add checks if scripts are enabled

* Remove Debug.Log(1) in InputSystem.cs

* Add UnityEngine.InputSystem reference to SS3D.Networking.asmdef

* Replace InputInput.GetButtonDown("Drop") in Hands.cs

* Work in progress: Parameterizing scene and prefab tests.

* More work on SceneTests.

* OnDisable()s unsubscribe from controls

* remove if (!enabled)

* Fixed scene loading in SceneTests.

* Completed merge from develop.
- AssetDataTests moved to Asset Audit.
- Assembly definitions updated.

* Moved relevant TilemapTests to Asset Audit assembly, refactored a bit.

* Rationalized EditMode TileMapTests.

* Set up CI pipeline to run Edit Mode tests only.

* Move controls intializations to OnStart()

* Rearrange Swap Hands to X, add summary to InputSystem, add try catch to OnEnable in InteractionController

* Lower InputSystem execution order and remove try catch blocks

* fix conficlt issue

* Moved OnEnable code to OnStart, OnDisable to OnDestroyed, .inputactions to Content/Input

* Make .inputaction file

* Added discrete PlayMode test runner.

* Commence conversion to InputSystem.

* Still trying to get TestInputFixture working

* Working on getting InputTestFixture going... No luck yet.

* Mock input actually working!!

* Commented out most UnityTests.

* Changed build to Linux.

* Changed build back to Windows.

* Changed how the filepath is checked.

* Trying Linux64 now.

* update station level to 0

* uncomment unityTest

* add toEnum utility on string

* add tryget method for assets database

* add utility for item command

* add spawn item command

* remove helper method already present in testHelper

* remove old test

* remove move from testhelper

* uncomment unity test attributes

* Add moveInDirection test helper

* remove useless namespaces

* remove itemcommandUtilities

remove itemcommandUtilities and add methods in entity and item system. Update command accordingly

* partial working tests

* try to fix itemdrop test

* failed attempt at implementing mouse mockup

* some progress : now the item get dropped at real cursor position

* update mouse read position with new input system

* fix last commit

* make playerCanDropItem test functional and clean up

* add a parameter to helper function

* remove useless unworking test

* add interaction controller as field

* move set up inputaction to set up method

* some cleanup

* edit back edit mode test

* Update editmodetestrunner.yml

* remove play mode test runner

* small fix for some tests

* partial fix for server tests

* put back issue reproduction tests

* fix station test height

* bandaid fix

* fix late join tests

* some doc and move kill to unityTearDown

* move controllers to SpessPlayModeTests

* remove some inputAction, put left mouse click in SpessPlayModeTest

* add pick up item to late join tests

* add some doc

* running only edit mode tests

* update editmodetestrunner

* edit workflow

* edit workflow

* edit workflow

* update workflow

* update workflow

* fix test failing in host game action

* fix late join fails

* move stuff to play mode repository

* complete host game action

* simplify hierarchy and clean up redundant stuff

* small fix attribute forgotten

* fixing built staying open at end of tests

* update to fix exceptions

* fixing build

* fix play mode tests

* fix overflow

* Add logAssert ignore fail messages everywhere needed

* Revert "Merge branch 'Fix-container-stack-overflow' into PlayModeTests"

This reverts commit e7d7620, reversing
changes made to 83db4da.

* renaming tests classes

---------

Co-authored-by: Ryan <[email protected]>
Co-authored-by: Mechar418 <[email protected]>
  • Loading branch information
3 people authored Oct 9, 2023
1 parent b7bbc2c commit 35876e4
Show file tree
Hide file tree
Showing 74 changed files with 2,498 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- run: npm install fs
- name: Run tests
uses: game-ci/unity-test-runner@v2
with:
testMode: editmode
env:
UNITY_LICENSE_FILE: ../Documents/UnityLicense.ulf
- name: Produce summary output
Expand Down
125 changes: 125 additions & 0 deletions Assets/Content/Scenes/Empty.unity
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
7 changes: 7 additions & 0 deletions Assets/Content/Scenes/Empty.unity.meta

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

2 changes: 1 addition & 1 deletion Assets/Content/Scenes/Game.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4468402021075485018, guid: cc5383d385556f443b2a7d3202f2b2c1, type: 3}
propertyPath: m_AnchoredPosition.y
value: -229.99997
value: -230.00006
objectReference: {fileID: 0}
- target: {fileID: 4468402022117316798, guid: cc5383d385556f443b2a7d3202f2b2c1, type: 3}
propertyPath: m_AnchorMax.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8711,7 +8711,7 @@ GameObject:
- component: {fileID: 6282983976573159881}
m_Layer: 11
m_Name: Human
m_TagString: Untagged
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
Expand Down
11 changes: 11 additions & 0 deletions Assets/Scripts/SS3D/Data/AssetDatabases/AssetDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public T Get<T>(int index) where T : Object
return Assets[index] as T;
}

public bool TryGet<T>(int index, out T asset) where T : Object
{
if(index >= 0 && index < Assets.Count)
{
asset = Assets[index] as T;
return true;
}
asset = null;
return false;
}

/// <summary>
/// Adds abd asset to the asset database. Should be used only for additional content or runtime stuff.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scripts/SS3D/Data/Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public static TAsset Get<TAsset>(int databaseId, int assetId) where TAsset : Obj
return GetDatabase(databaseId).Get<TAsset>(assetId);
}

public static bool TryGet<TAsset>(int databaseId, int assetId, out TAsset asset) where TAsset : Object
{
if(GetDatabase(databaseId).TryGet(assetId, out asset))
{
return true;
}
asset= null;
return false;
}

/// <summary>
/// Generic getter, supports all databases and all asset database enums.
/// </summary>
Expand Down
18 changes: 17 additions & 1 deletion Assets/Scripts/SS3D/Systems/Entities/EntitySystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Coimbra;
using Coimbra.Services.Events;
Expand All @@ -7,8 +7,10 @@
using FishNet.Object.Synchronizing;
using SS3D.Core;
using SS3D.Core.Behaviours;
using SS3D.Core.Settings;
using SS3D.Logging;
using SS3D.Systems.Entities.Events;
using SS3D.Systems.PlayerControl;
using SS3D.Systems.Rounds;
using SS3D.Systems.Rounds.Events;
using SS3D.Utils;
Expand Down Expand Up @@ -148,6 +150,20 @@ public void CmdSpawnLatePlayer(Player player, NetworkConnection networkConnectio
SpawnLatePlayer(player);
}

public bool TryGetOwnedEntity(NetworkConnection conn, out Entity entity)
{
foreach(Entity e in SpawnedPlayers)
{
if(e.Owner == conn)
{
entity = e;
return true;
}
}
entity = null;
return false;
}

/// <summary>
/// Spawns a player after the round has started
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void HandleUpdate(ref EventContext context, in UpdateEvent updateEvent)
/// </summary>
private void UpdateMousePositionTransforms()
{
// Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
// Ray ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
// Vector3 mousePos = ray.origin - ray.direction * (ray.origin.y / ray.direction.y);
// mousePos = new Vector3(mousePos.x, transform.position.y, mousePos.z);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/SS3D/Systems/Gamemodes/GamemodeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed class GamemodeSystem : NetworkSystem
protected override void OnStart()
{
base.OnStart();
Setup();
if (base.IsServer) Setup();
}

public override void OnStartClient()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using SS3D.Core;
using SS3D.Systems.Entities;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using SS3D.Systems;
using SS3D.Data;
using SS3D.Data.AssetDatabases;
using SS3D.Data.Enums;
using SS3D.Systems.Inventory.Items;
using SS3D.Utils;
using SS3D.Core.Settings;
using UnityEngine;
using UnityEngine.UIElements;
using FishNet.Managing.Server;
using FishNet;
using FishNet.Connection;
using UnityEngine.InputSystem;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
public class SpawnItemCommand : Command
{
public override string LongDescription => "Spawn item using item name at the same position as human or at position x,z";
public override string ShortDescription => "Spawn item";
public override ServerRoleTypes AccessLevel => ServerRoleTypes.User;

public override CommandType Type => CommandType.Server;

public override string Perform(string[] args, NetworkConnection conn)
{
CheckArgsResponse checkArgsResponse = CheckArgs(args);
if (checkArgsResponse.IsValid == false)
return checkArgsResponse.InvalidArgs;
string itemName = args[0];
if(!Subsystems.Get<EntitySystem>().TryGetOwnedEntity(conn, out Entity entity))
{
return "Connection does not own any entity registered in entity system.";
};

ItemSystem itemSystem = Subsystems.Get<ItemSystem>();
itemSystem.CmdSpawnItem(itemName.ToEnum<ItemId>(), entity.transform.position, Quaternion.identity);
return $"item {itemName} spawned at position {entity.transform.position}";
}

protected override CheckArgsResponse CheckArgs(string[] args)
{
CheckArgsResponse response = new CheckArgsResponse();
if (args.Length != 1 && args.Length != 3)
{
response.IsValid = false;
response.InvalidArgs = "Invalid number of arguments";
return response;
}
string itemName = args[0];
if(!Assets.TryGet((int) AssetDatabases.Items, (int) itemName.ToEnum<ItemId>(), out Item item))
{
response.IsValid = false;
response.InvalidArgs = $"item with name {itemName} not found";
return response;
}

response.IsValid = true;
return response;
}
}
}

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 @@ -82,13 +82,15 @@ protected override void OnDestroyed()
/// Runs the most prioritised interaction
/// </summary>
[Client]
private void HandleRunPrimary(InputAction.CallbackContext callbackContext)
public void HandleRunPrimary(InputAction.CallbackContext callbackContext)
{

Debug.Log("run primary : " + Mouse.current.position.ReadValue());
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
Ray ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
List<InteractionEntry> viableInteractions = GetViableInteractions(ray, out InteractionEvent interactionEvent);

if (viableInteractions.Count <= 0)
Expand All @@ -112,7 +114,7 @@ private void HandleView(InputAction.CallbackContext callbackContext)
{
return;
}
Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
Ray ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
List<InteractionEntry> viableInteractions = GetViableInteractions(ray, out InteractionEvent interactionEvent);

ViewTargetInteractions(viableInteractions, interactionEvent, ray);
Expand Down Expand Up @@ -156,7 +158,7 @@ void handleInteractionSelected(IInteraction interaction, RadialInteractionButton
CmdRunInteraction(ray, interactionName);
}

_radialView.SetInteractions(interactions, interactionEvent, Input.mousePosition);
_radialView.SetInteractions(interactions, interactionEvent, Mouse.current.position.ReadValue());
_radialView.OnInteractionSelected += handleInteractionSelected;
_radialView.ShowInteractionsMenu();
}
Expand Down Expand Up @@ -190,7 +192,7 @@ private void InteractInHand(GameObject target, GameObject sourceObject, bool sho

if (showMenu && interactions.Count > 0)
{
Vector3 mousePosition = Input.mousePosition;
Vector3 mousePosition = Mouse.current.position.ReadValue();
mousePosition.y = Mathf.Max(_radialView.RectTransform.rect.height, mousePosition.y);

_radialView.SetInteractions(interactions, interactionEvent, mousePosition);
Expand Down
Loading

0 comments on commit 35876e4

Please sign in to comment.