Skip to content

Commit 74c7efe

Browse files
authored
Set gravity for ball prediction (#105)
* Set gravity for ball prediction * Run formatter * Update ball pred test * Actually set gravity * Update build.yml to run tests * Fix test * Directly set WorldGravityZ
1 parent 0784434 commit 74c7efe

File tree

18 files changed

+46
-22
lines changed

18 files changed

+46
-22
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
with:
2020
submodules: 'recursive'
2121

22+
- name: Test
23+
run: dotnet test
24+
2225
- name: Build
2326
run: dotnet publish -r win-x64
2427

@@ -37,6 +40,9 @@ jobs:
3740
with:
3841
submodules: 'recursive'
3942

43+
- name: Test
44+
run: dotnet test
45+
4046
- name: Build
4147
run: dotnet publish -r linux-x64
4248

RLBotCS/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
if (args.Length > 0 && args[0] == "--version")
1010
{
11-
Console.WriteLine("RLBotServer v5.beta.6.3");
11+
Console.WriteLine("RLBotServer v5.beta.6.4");
1212
Environment.Exit(0);
1313
}
1414

RLBotCS/ManagerTools/BallPredictor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public static partial class BallPredictor
5656
[LibraryImport("rl_ball_sym", EntryPoint = "set_heatseeker_target")]
5757
private static partial void SetHeatseekerTarget(byte blueGoal);
5858

59+
[LibraryImport("rl_ball_sym", EntryPoint = "set_gravity")]
60+
private static partial void SetGravity(float gravityZ);
61+
5962
[LibraryImport("rl_ball_sym", EntryPoint = "step")]
6063
private static unsafe partial BallSlice* Step(BallSlice ball, ushort ticks);
6164

@@ -122,7 +125,8 @@ public static PredictionMode UpdateMode(MatchConfigurationT matchConfig)
122125
public static BallPredictionT Generate(
123126
float currentTime,
124127
BallInfoT currentBall,
125-
(TouchT, uint)? lastTouch
128+
(TouchT, uint)? lastTouch,
129+
float gravityZ
126130
)
127131
{
128132
BallSlice ball = new()
@@ -165,6 +169,8 @@ public static BallPredictionT Generate(
165169
}
166170
}
167171

172+
SetGravity(gravityZ);
173+
168174
unsafe
169175
{
170176
var ballSlices = Step(ball, numSlices);

RLBotCS/ManagerTools/ConfigValidator.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static bool Validate(MatchConfigurationT config)
4343
config.LauncherArg = "";
4444
}
4545
}
46-
46+
4747
config.Mutators ??= new();
4848
config.PlayerConfigurations ??= new();
4949
config.ScriptConfigurations ??= new();
@@ -139,7 +139,7 @@ List<PlayerConfigurationT> players
139139
// Fallback if above fails or user didn't include paints
140140
player.Loadout ??= new();
141141
player.Loadout.LoadoutPaint ??= new();
142-
142+
143143
player.RunCommand = "";
144144
player.RootDir = "";
145145

@@ -161,7 +161,10 @@ List<PlayerConfigurationT> players
161161
break;
162162
}
163163

164-
player.SpawnId = player.Variety.Type == PlayerClass.Human ? 0 : $"{player.AgentId}/{player.Team}/{i}".GetHashCode();
164+
player.SpawnId =
165+
player.Variety.Type == PlayerClass.Human
166+
? 0
167+
: $"{player.AgentId}/{player.Team}/{i}".GetHashCode();
165168
}
166169

167170
if (humanCount > 1)

RLBotCS/ManagerTools/MatchStarter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private void LoadMatch(MatchConfigurationT matchConfig, PlayerSpawner spawner)
305305
{
306306
spawner.DespawnPlayers(toDespawnIds);
307307
}
308-
308+
309309
// We can flush C&S despawn commands immediately
310310
spawner.Flush();
311311
}
@@ -451,7 +451,7 @@ private bool SpawnCars(
451451
{
452452
spawner.Flush();
453453
}
454-
454+
455455
return true;
456456
}
457457

RLBotCS/ManagerTools/PlayerSpawner.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ public void SpawnHuman(PlayerConfigurationT config, uint desiredIndex)
5454
.FirstOrDefault(kp => config.SpawnId == kp.SpawnId);
5555
if (alreadySpawnedPlayer != null)
5656
{
57-
_gameState.PlayerMapping.QueueIndexChange(alreadySpawnedPlayer.PlayerIndex, desiredIndex);
57+
_gameState.PlayerMapping.QueueIndexChange(
58+
alreadySpawnedPlayer.PlayerIndex,
59+
desiredIndex
60+
);
5861
return;
5962
}
6063

6164
_gameState.PlayerMapping.AddPendingSpawn(
6265
new SpawnTracker
6366
{
64-
CommandId = 0, // Human spawning must use command id 0 for reasons in bridge
67+
CommandId = 0, // Human spawning must use command id 0 for reasons in bridge
6568
SpawnId = config.SpawnId,
6669
DesiredPlayerIndex = desiredIndex,
6770
IsBot = false,

RLBotCS/Server/BridgeContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ MatchStarter matchStarter
4444
public PerfMonitor PerfMonitor { get; } = new();
4545

4646
public PlayerSpawner GetPlayerSpawner() => new(ref GameState, SpawnCommandQueue);
47+
4748
public void UpdateTimeMutators()
4849
{
4950
var mutators = MatchConfig!.Mutators;

RLBotCS/Server/BridgeHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ private async Task HandleServer()
137137
_context.PerfMonitor.ClearAll();
138138
}
139139

140-
if (_context.MatchStarter.HasSpawnedMap && _context.GameState.MatchPhase == MatchPhase.Paused && _context.SpawnCommandQueue.Count > 0)
140+
if (
141+
_context.MatchStarter.HasSpawnedMap
142+
&& _context.GameState.MatchPhase == MatchPhase.Paused
143+
&& _context.SpawnCommandQueue.Count > 0
144+
)
141145
{
142146
_context.Logger.LogDebug("Sending queued spawning commands");
143147
_context.SpawnCommandQueue.Flush();

RLBotCS/Server/BridgeMessage/SetGameState.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ public void HandleMessage(BridgeContext context)
1313
if (GameState.MatchInfo is { } matchInfo)
1414
{
1515
if (matchInfo.WorldGravityZ is { } gravity)
16+
{
1617
context.MatchCommandQueue.AddConsoleCommand(
1718
FlatToCommand.MakeGravityCommand(gravity.Val)
1819
);
20+
context.GameState.WorldGravityZ = gravity.Val;
21+
}
1922

2023
if (matchInfo.GameSpeed is { } speed)
2124
context.MatchCommandQueue.AddConsoleCommand(
@@ -58,10 +61,7 @@ public void HandleMessage(BridgeContext context)
5861

5962
if (car.BoostAmount is { } boostAmount)
6063
{
61-
context.MatchCommandQueue.AddSetBoostCommand(
62-
(ushort)id,
63-
(int)boostAmount.Val
64-
);
64+
context.MatchCommandQueue.AddSetBoostCommand((ushort)id, (int)boostAmount.Val);
6565
}
6666
}
6767

RLBotCS/Server/FlatBuffersServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private void AddSession(TcpClient client)
3232
Thread sessionThread = new(() =>
3333
{
3434
_context.Logger.LogDebug("Client {} connected", clientId);
35-
35+
3636
FlatBuffersSession session = new(
3737
client,
3838
clientId,

0 commit comments

Comments
 (0)