Browse Source

Allow game and viewmodel layers to be specified at the level of each UniQuake instance. This will allow multiple instances of the game to run side-by-side with each their own rendering layers.

console
Nico de Poel 5 years ago
parent
commit
a8defed5de
  1. 6
      Assets/Scripts/Bootstrap.cs
  2. 9
      Assets/Scripts/Game/Entity.cs
  3. 8
      Assets/Scripts/Game/GameState.cs
  4. 2
      Assets/Scripts/Layers.cs
  5. 4
      Assets/Scripts/UniQuake.cs

6
Assets/Scripts/Bootstrap.cs

@ -30,6 +30,8 @@ public class Bootstrap : MonoBehaviour
uq.ModDirectory = mod;
uq.AdditionalArguments = ParseArgs();
uq.Camera = mainCamera; // This can be any one of four cameras for split-screen, each with its own culling layer
uq.GameLayer = Layers.Game1;
uq.ViewModelLayer = Layers.ViewModel1;
uq.SetVisualStyle(visualStyles[0]);
}
@ -40,6 +42,8 @@ public class Bootstrap : MonoBehaviour
uq.ModDirectory = mod;
uq.AdditionalArguments = ParseArgs();
uq.Camera = mainCamera;
uq.GameLayer = Layers.Game1;
uq.ViewModelLayer = Layers.ViewModel1;
uq.SetVisualStyle(visualStyles[0]);
}
@ -50,6 +54,8 @@ public class Bootstrap : MonoBehaviour
uq.ModDirectory = mod;
uq.AdditionalArguments = ParseArgs();
uq.Camera = mainCamera;
uq.GameLayer = Layers.Game1;
uq.ViewModelLayer = Layers.ViewModel1;
uq.SetVisualStyle(visualStyles[0]);
}

9
Assets/Scripts/Game/Entity.cs

@ -5,6 +5,7 @@ public class Entity
{
private readonly int entityNum;
private readonly VisualStyle visualStyle;
private readonly Layers layer;
private int skinNumber;
@ -19,19 +20,17 @@ public class Entity
private GameObject brushModel;
private GameObject worldModel;
public Entity(int entityNum, VisualStyle visualStyle)
public Entity(int entityNum, VisualStyle visualStyle, Layers layer)
{
this.entityNum = entityNum;
this.visualStyle = visualStyle;
this.layer = layer;
CreateGameObject();
}
private void CreateGameObject()
{
gameObject = new GameObject($"Entity_{entityNum}")
{
layer = entityNum == 0 ? (int)Layers.View1 : (int)Layers.Game1
};
gameObject = new GameObject($"Entity_{entityNum}") { layer = (int)layer };
skinnedMeshRenderer = gameObject.AddComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.enabled = false;

8
Assets/Scripts/Game/GameState.cs

@ -27,7 +27,7 @@ public class GameState
Destroy();
Resources.UnloadUnusedAssets();
worldGameObject = new GameObject(worldModel.Name) { layer = (int)Layers.Game1 };
worldGameObject = new GameObject(worldModel.Name) { layer = (int)uq.GameLayer };
// The first sub-model contains all of the static geometry
var subModel = worldModel.GetSubModel(0);
@ -37,11 +37,11 @@ public class GameState
private GameObject CreateBrushGameObject(BrushModel.SubModel subModel)
{
var subModelGO = new GameObject(subModel.Name) { layer = (int)Layers.Game1 };
var subModelGO = new GameObject(subModel.Name) { layer = (int)uq.GameLayer };
foreach (var surfaceMesh in subModel.SurfaceMeshes)
{
var meshGO = new GameObject(surfaceMesh.Mesh.name) { layer = (int)Layers.Game1 };
var meshGO = new GameObject(surfaceMesh.Mesh.name) { layer = (int)uq.GameLayer };
meshGO.transform.SetParent(subModelGO.transform);
var mf = meshGO.AddComponent<MeshFilter>();
@ -77,7 +77,7 @@ public class GameState
{
if (!entities.TryGetValue(entityNum, out var entity))
{
entity = new Entity(entityNum, uq.CurrentStyle);
entity = new Entity(entityNum, uq.CurrentStyle, entityNum == 0 ? uq.ViewModelLayer : uq.GameLayer);
entities.Add(entityNum, entity);
}

2
Assets/Scripts/Layers.cs

@ -1,7 +1,7 @@
public enum Layers
{
Game1 = 6,
View1 = 7,
ViewModel1 = 7,
}
public static class LayerExtensions

4
Assets/Scripts/UniQuake.cs

@ -21,6 +21,8 @@ public partial class UniQuake: MonoBehaviour
/// Camera and viewport that this instance of Quake will be rendering to
/// </summary>
public Camera Camera { get; set; }
public Layers GameLayer { get; set; }
public Layers ViewModelLayer { get; set; }
public MissionPack BaseGame { get; set; }
public string ModDirectory { get; set; }
@ -31,7 +33,7 @@ public partial class UniQuake: MonoBehaviour
/// </summary>
public double CurrentTime => Time.realtimeSinceStartupAsDouble - startTime;
public GameAssets GameAssets { get; private set; }
public GameAssets GameAssets { get; private set; } // TODO: Game assets could be shared by multiple UniQuake instances
public GameState GameState { get; private set; }
public VisualStyle CurrentStyle { get; private set; }
private VisualStyle nextStyle;

Loading…
Cancel
Save