Skip to content

Commit 7c51205

Browse files
committed
Updated Blackholio Unity demo with new index names
1 parent 4329313 commit 7c51205

4 files changed

Lines changed: 20 additions & 20 deletions

File tree

demo/Blackholio/client-unity/Assets/PlayModeTests/PlayModeExampleTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public IEnumerator CreatePlayerAndTestDecay()
7171
while (!playerCreated) yield return null;
7272

7373
Debug.Assert(GameManager.LocalIdentity != default, "GameManager.localIdentity != default");
74-
var player = GameManager.Conn.Db.Player.Identity.Find(GameManager.LocalIdentity);
74+
var player = GameManager.Conn.Db.Player.PlayerIdentityIdxBtree.Find(GameManager.LocalIdentity);
7575
Debug.Assert(player != null, nameof(player) + " != null");
7676
var circle = GameManager.Conn.Db.Circle.Iter().FirstOrDefault(a => a.PlayerId == player.PlayerId);
7777

@@ -87,13 +87,13 @@ public IEnumerator CreatePlayerAndTestDecay()
8787
while (foodEaten < 50)
8888
{
8989
Debug.Assert(circle != null, nameof(circle) + " != null");
90-
var ourEntity = GameManager.Conn.Db.Entity.EntityId.Find(circle.EntityId);
90+
var ourEntity = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(circle.EntityId);
9191
var toChosenFood = new UnityEngine.Vector2(1000, 0);
9292
int chosenFoodId = 0;
9393
foreach (var food in GameManager.Conn.Db.Food.Iter())
9494
{
9595
var thisFoodId = food.EntityId;
96-
var foodEntity = GameManager.Conn.Db.Entity.EntityId.Find(thisFoodId);
96+
var foodEntity = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(thisFoodId);
9797
Debug.Assert(foodEntity != null, nameof(foodEntity) + " != null");
9898
Debug.Assert(ourEntity != null, nameof(ourEntity) + " != null");
9999
var foodEntityPosition = foodEntity.Position;
@@ -109,10 +109,10 @@ public IEnumerator CreatePlayerAndTestDecay()
109109
}
110110
}
111111

112-
if (GameManager.Conn.Db.Entity.EntityId.Find(chosenFoodId) != null)
112+
if (GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(chosenFoodId) != null)
113113
{
114-
var ourNewEntity = GameManager.Conn.Db.Entity.EntityId.Find(circle.EntityId);
115-
var foodEntity = GameManager.Conn.Db.Entity.EntityId.Find(chosenFoodId);
114+
var ourNewEntity = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(circle.EntityId);
115+
var foodEntity = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(chosenFoodId);
116116
Debug.Assert(foodEntity != null, nameof(foodEntity) + " != null");
117117
Debug.Assert(ourNewEntity != null, nameof(ourNewEntity) + " != null");
118118
var toThisFood = (Vector2)foodEntity.Position - (Vector2)ourNewEntity.Position;
@@ -130,9 +130,9 @@ public IEnumerator CreatePlayerAndTestDecay()
130130

131131
PlayerController.Local.SetTestInput(UnityEngine.Vector2.zero);
132132
Debug.Assert(circle != null, nameof(circle) + " != null");
133-
var massStart = GameManager.Conn.Db.Entity.EntityId.Find(circle.EntityId)!.Mass;
133+
var massStart = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(circle.EntityId)!.Mass;
134134
yield return new WaitForSeconds(10);
135-
var massEnd = GameManager.Conn.Db.Entity.EntityId.Find(circle.EntityId)!.Mass;
135+
var massEnd = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(circle.EntityId)!.Mass;
136136
Debug.Assert(massEnd < massStart, "Mass should have decayed");
137137
}
138138

@@ -260,7 +260,7 @@ public IEnumerator ReconnectionViaReloadingScene()
260260
while (!playerCreated) yield return null;
261261

262262
Debug.Assert(GameManager.LocalIdentity != default, "GameManager.localIdentity != default");
263-
var player = GameManager.Conn.Db.Player.Identity.Find(GameManager.LocalIdentity);
263+
var player = GameManager.Conn.Db.Player.PlayerIdentityIdxBtree.Find(GameManager.LocalIdentity);
264264
Debug.Assert(player != null, nameof(player) + " != null");
265265
var circle = GameManager.Conn.Db.Circle.Iter().FirstOrDefault(a => a.PlayerId == player.PlayerId);
266266

@@ -273,7 +273,7 @@ public IEnumerator ReconnectionViaReloadingScene()
273273
SceneManager.LoadScene("Scenes/Main");
274274

275275
while (!connected || !subscribed) yield return null;
276-
var newPlayer = GameManager.Conn.Db.Player.Identity.Find(GameManager.LocalIdentity);
276+
var newPlayer = GameManager.Conn.Db.Player.PlayerIdentityIdxBtree.Find(GameManager.LocalIdentity);
277277
Debug.Assert(player.PlayerId == newPlayer.PlayerId, "PlayerIds should match!");
278278
var newCircle = GameManager.Conn.Db.Circle.Iter().FirstOrDefault(a => a.PlayerId == newPlayer.PlayerId);
279279
Debug.Assert(circle.EntityId == newCircle.EntityId, "Circle EntityIds should match!");

demo/Blackholio/client-unity/Assets/Scripts/EntityController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected virtual void Spawn(int entityId)
2323
{
2424
EntityId = entityId;
2525

26-
var entity = GameManager.Conn.Db.Entity.EntityId.Find(entityId);
26+
var entity = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(entityId);
2727
LerpStartPosition = LerpTargetPosition = transform.position = (Vector2)entity.Position;
2828
transform.localScale = Vector3.one;
2929
TargetScale = MassToScale(entity.Mass);

demo/Blackholio/client-unity/Assets/Scripts/GameManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ private void HandleSubscriptionApplied(SubscriptionEventContext ctx)
105105

106106
// Once we have the initial subscription sync'd to the client cache
107107
// Get the world size from the config table and set up the arena
108-
var worldSize = Conn.Db.Config.Id.Find(0).WorldSize;
108+
var worldSize = Conn.Db.Config.ConfigIdIdxBtree.Find(0).WorldSize;
109109
SetupArena(worldSize);
110110

111111
// Check to see if we already have a player, if we don't we'll need to create one
112-
var player = ctx.Db.Player.Identity.Find(LocalIdentity);
112+
var player = ctx.Db.Player.PlayerIdentityIdxBtree.Find(LocalIdentity);
113113
if (string.IsNullOrEmpty(player.Name))
114114
{
115115
// The player has to choose a username
@@ -127,7 +127,7 @@ private void HandleSubscriptionApplied(SubscriptionEventContext ctx)
127127
else
128128
{
129129
// We already have a player
130-
if (ctx.Db.Circle.PlayerId.Filter(player.PlayerId).Any())
130+
if (ctx.Db.Circle.CirclePlayerIdIdxBtree.Filter(player.PlayerId).Any())
131131
{
132132
// We already have at least one circle, we should just be able to start
133133
// playing immediately.
@@ -217,7 +217,7 @@ private static PlayerController GetOrCreatePlayer(int playerId)
217217
{
218218
if (!Players.TryGetValue(playerId, out var playerController))
219219
{
220-
var player = Conn.Db.Player.PlayerId.Find(playerId);
220+
var player = Conn.Db.Player.PlayerPlayerIdIdxBtree.Find(playerId);
221221
playerController = PrefabManager.SpawnPlayer(player);
222222
Players.Add(playerId, playerController);
223223
}

demo/Blackholio/client-unity/Assets/Scripts/PlayerController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public class PlayerController : MonoBehaviour
1111

1212
public static PlayerController Local { get; private set; }
1313

14-
private int PlayerId;
14+
private Identity PlayerIdentity;
1515
private float LastMovementSendTimestamp;
1616
private Vector2? LockInputPosition;
1717
private List<CircleController> OwnedCircles = new List<CircleController>();
1818

19-
public string Username => GameManager.Conn.Db.Player.PlayerId.Find(PlayerId).Name;
19+
public string Username => GameManager.Conn.Db.Player.PlayerIdentityIdxBtree.Find(PlayerIdentity).Name;
2020
public int NumberOfOwnedCircles => OwnedCircles.Count;
2121
public bool IsLocalPlayer => this == Local;
2222

2323
public void Initialize(Player player)
2424
{
25-
PlayerId = player.PlayerId;
25+
PlayerIdentity = player.Identity;
2626
if (player.Identity == GameManager.LocalIdentity)
2727
{
2828
Local = this;
@@ -59,7 +59,7 @@ public void OnCircleDeleted(CircleController deletedCircle)
5959
public int TotalMass()
6060
{
6161
return (int)OwnedCircles
62-
.Select(circle => GameManager.Conn.Db.Entity.EntityId.Find(circle.EntityId))
62+
.Select(circle => GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(circle.EntityId))
6363
.Sum(e => e?.Mass ?? 0); //If this entity is being deleted on the same frame that we're moving, we can have a null entity here.
6464
}
6565

@@ -74,7 +74,7 @@ public int TotalMass()
7474
float totalMass = 0;
7575
foreach (var circle in OwnedCircles)
7676
{
77-
var entity = GameManager.Conn.Db.Entity.EntityId.Find(circle.EntityId);
77+
var entity = GameManager.Conn.Db.Entity.EntityEntityIdIdxBtree.Find(circle.EntityId);
7878
var position = circle.transform.position;
7979
totalPos += (Vector2)position * entity.Mass;
8080
totalMass += entity.Mass;

0 commit comments

Comments
 (0)