Skip to content

Commit 67f4312

Browse files
committed
Update RLBotCPP submodule and clean up examplebot code.
1 parent 81fb9c7 commit 67f4312

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

examplebot.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string>
55

66
#include "bot.h"
7+
#include "color.h"
78
#include "interface.h"
89
#include "rlbot_generated.h"
910
#include "scopedrenderer.h"
@@ -13,12 +14,12 @@
1314

1415
ExampleBot::ExampleBot(int _index, int _team, std::string _name)
1516
: Bot(_index, _team, _name) {
16-
rlbotcpp::GameState gamestate = rlbotcpp::GameState();
17+
rlbot::GameState gamestate = rlbot::GameState();
1718

1819
gamestate.ballState.physicsState.location = {0, 0, 1000};
1920
gamestate.ballState.physicsState.velocity = {0, 0, 5000};
2021

21-
rlbotcpp::CarState carstate = rlbotcpp::CarState();
22+
rlbot::CarState carstate = rlbot::CarState();
2223
carstate.physicsState.location = {0, 500, 1000};
2324
carstate.physicsState.velocity = {500, 1000, 1000};
2425
carstate.physicsState.angularVelocity = {1, 2, 3};
@@ -27,14 +28,13 @@ ExampleBot::ExampleBot(int _index, int _team, std::string _name)
2728

2829
gamestate.carStates[_index] = carstate;
2930

30-
rlbotcpp::Interface::SetGameState(gamestate);
31+
rlbot::Interface::SetGameState(gamestate);
3132
}
3233

33-
rlbotcpp::Controller
34+
rlbot::Controller
3435
ExampleBot::GetOutput(const rlbot::flat::GameTickPacket *gameTickPacket,
3536
const rlbot::flat::FieldInfo *fieldInfo,
3637
const rlbot::flat::BallPrediction *ballPrediction) {
37-
rlbotcpp::Controller controller{0};
3838

3939
rlbot::flat::Vector3 ballLocation =
4040
*gameTickPacket->ball()->physics()->location();
@@ -45,38 +45,39 @@ ExampleBot::GetOutput(const rlbot::flat::GameTickPacket *gameTickPacket,
4545
rlbot::flat::Rotator carRotation =
4646
*gameTickPacket->players()->Get(index)->physics()->rotation();
4747

48+
// Calculate the velocity of the ball.
4849
float velocity = sqrt(ballVelocity.x() * ballVelocity.x() +
4950
ballVelocity.y() * ballVelocity.y() +
5051
ballVelocity.z() * ballVelocity.z());
5152

52-
// This renderer will build and send the packet once it goes out of scope
53-
rlbotcpp::ScopedRenderer renderer("test");
54-
53+
// Load the ballprediction into a vector to use for rendering.
5554
std::vector<const rlbot::flat::Vector3 *> points;
5655

5756
for (uint32_t i = 0; i < ballPrediction->slices()->size(); i++) {
5857
points.push_back(ballPrediction->slices()->Get(i)->physics()->location());
5958
}
6059

61-
renderer.DrawPolyLine3D(rlbotcpp::Color{0xFF, 0x00, 0x00, 0xFF}, points);
60+
// This renderer will build and send the packet once it goes out of scope.
61+
rlbot::ScopedRenderer renderer("test");
6262

63-
renderer.DrawString2D("Hello world!", rlbotcpp::Color{0x00, 0xFF, 0x00, 0xFF},
63+
renderer.DrawPolyLine3D(rlbot::Color::red, points);
64+
renderer.DrawString2D("Hello world!", rlbot::Color::green,
6465
rlbot::flat::Vector3{10, 10, 0}, 4, 4);
65-
66-
renderer.DrawString3D(std::to_string(velocity),
67-
rlbotcpp::Color{0xFF, 0x00, 0xFF, 0xFF}, ballLocation,
68-
2, 2);
66+
renderer.DrawString3D(std::to_string(velocity), rlbot::Color::magenta,
67+
ballLocation, 2, 2);
6968

7069
// Calculate to get the angle from the front of the bot's car to the ball.
7170
double botToTargetAngle = atan2(ballLocation.y() - carLocation.y(),
7271
ballLocation.x() - carLocation.x());
7372
double botFrontToTargetAngle = botToTargetAngle - carRotation.yaw();
74-
// Correct the angle
73+
// Correct the angle.
7574
if (botFrontToTargetAngle < -PI)
7675
botFrontToTargetAngle += 2 * PI;
7776
if (botFrontToTargetAngle > PI)
7877
botFrontToTargetAngle -= 2 * PI;
7978

79+
rlbot::Controller controller{0};
80+
8081
// Decide which way to steer in order to get to the ball.
8182
if (botFrontToTargetAngle > 0)
8283
controller.steer = 1;

examplebot.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#include "bot.h"
44

5-
class ExampleBot : public rlbotcpp::Bot {
5+
class ExampleBot : public rlbot::Bot {
66
public:
77
ExampleBot(int _index, int _team, std::string _name);
8-
rlbotcpp::Controller
8+
rlbot::Controller
99
GetOutput(const rlbot::flat::GameTickPacket *gameTickPacket,
1010
const rlbot::flat::FieldInfo *fieldInfo,
1111
const rlbot::flat::BallPrediction *ballPrediction);

main.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ uint16_t getPortFromFile(std::string filename) {
2323
}
2424

2525
int main(int argc, char **argv) {
26-
rlbotcpp::platform::SetWorkingDirectory(
27-
rlbotcpp::platform::GetExecutableDirectory());
26+
rlbot::platform::SetWorkingDirectory(
27+
rlbot::platform::GetExecutableDirectory());
2828
uint16_t port = getPortFromFile("port.cfg");
2929

3030
std::string interface_dll = std::string(DLLNAME);
@@ -40,14 +40,14 @@ int main(int argc, char **argv) {
4040
}
4141
}
4242

43-
rlbotcpp::Interface::LoadInterface(interface_dll);
43+
rlbot::Interface::LoadInterface(interface_dll);
4444

45-
while (!rlbotcpp::Interface::IsInitialized()) {
46-
rlbotcpp::platform::SleepMilliseconds(1);
45+
while (!rlbot::Interface::IsInitialized()) {
46+
rlbot::platform::SleepMilliseconds(1);
4747
}
4848

49-
rlbotcpp::BotManager<ExampleBot> botmanager =
50-
rlbotcpp::BotManager<ExampleBot>();
49+
rlbot::BotManager<ExampleBot> botmanager =
50+
rlbot::BotManager<ExampleBot>();
5151
botmanager.StartBotServer(port);
5252

5353
return 0;

0 commit comments

Comments
 (0)