Skip to content

Commit 5411e12

Browse files
authored
Merge pull request #6 from CLSFramework/structure
change structure
2 parents cdf543d + db490c0 commit 5411e12

24 files changed

+451
-307
lines changed

ChangeLog.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# ChangeLog
22

3+
## [0.1.4] - 2024-09-03
4+
5+
### Added
6+
-
7+
8+
### Fixed
9+
-
10+
11+
### Changed
12+
- Change the structure of the RPC clients.
13+
- Move some fields and methods in gRrpc/thrift client to the base class (```IRpcClient```).
14+
- Add ```RpcPlayerClient``` that handles the preprocess check and execution.
15+
- The ```ThriftPlayerClient``` and ```GrpcPlayerClient``` inherit from the ```RpcPlayerClient``` for preprocess handling.
16+
- Preprocess:
17+
- Add ```need_preprocess``` to the ```State``` message.
18+
- Add ```ignore_preprocess``` to the ```PlayerActions``` message.
19+
- Player Agents now first check whether they require preprocess actions, send the ```bool``` as the ```need_preprocess``` field in the ```State``` message. Then, if the server sends the ```ignore_preprocess=false (default value)``` to the proxy, the proxy will call ```doPreprocess``` method. If ther server sends the ```ignore_preprocess=true``` to the proxy, the proxy will not call the ```doPreprocess``` method and execute the ```PlayerActoins```.
20+
21+
322
## [0.1.3] - 2024-09-02
423

524
### Added
@@ -11,6 +30,7 @@
1130
### Changed
1231
- change input arguments names in start files (by [NaderZare](https://github.com/naderzare), [ArefSayareh](https://github.com/Arefsa78))
1332

33+
1434
## [0.1.2] - 2024-09-01
1535

1636
### Added

idl/grpc/service.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ message State {
260260
RegisterResponse register_response = 1;
261261
WorldModel world_model = 2;
262262
WorldModel full_world_model = 3;
263+
bool need_preprocess = 4;
263264
}
264265

265266
enum AgentType {
@@ -840,6 +841,7 @@ message PlayerAction {
840841

841842
message PlayerActions {
842843
repeated PlayerAction actions = 1;
844+
bool ignore_preprocess = 2;
843845
}
844846

845847
message ChangePlayerType {

idl/thrift/soccer_service.thrift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ struct WorldModel {
262262
struct State {
263263
1: RegisterResponse register_response,
264264
2: WorldModel world_model,
265-
3: WorldModel full_world_model
265+
3: WorldModel full_world_model,
266+
4: bool need_preprocess
266267
}
267268

268269
struct InitMessage {
@@ -803,7 +804,8 @@ struct PlayerAction {
803804
}
804805

805806
struct PlayerActions {
806-
1: list<PlayerAction> actions
807+
1: list<PlayerAction> actions,
808+
2: bool ignore_preprocess
807809
}
808810

809811
struct ChangePlayerType {

src/grpc-client/grpc_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void GrpcClient::sendInitMessage(bool offline_logging) const
417417
}
418418
}
419419

420-
bool GrpcClient::Register() const
420+
bool GrpcClient::Register()
421421
{
422422
ClientContext context;
423423
protos::RegisterRequest request;

src/grpc-client/grpc_client.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ using protos::TrainerAction;
2424

2525
class GrpcClient : public IRpcClient{
2626
public:
27+
protos::AgentType M_agent_type;
2728
std::string M_target;
2829
std::shared_ptr<Channel> M_channel;
2930
std::unique_ptr<Game::Stub> M_stub_;
30-
bool M_is_connected = false;
31-
bool M_param_sent = false;
32-
protos::AgentType M_agent_type;
33-
int M_unum;
34-
std::string M_team_name;
3531
protos::RegisterResponse * M_register_response = new protos::RegisterResponse();
3632

3733
~GrpcClient() {}
@@ -42,12 +38,9 @@ class GrpcClient : public IRpcClient{
4238
void sendPlayerParams() const;
4339
void sendPlayerType() const;
4440
void sendInitMessage(bool offline_logging) const;
45-
bool Register() const;
41+
bool Register() override;
4642
void sendByeCommand() const override;
4743
bool connectToGrpcServer() override;
48-
bool isConnected() const override{
49-
return M_is_connected;
50-
}
5144

5245
static rcsc::ViewWidth convertViewWidth(protos::ViewWidth view_width);
5346
static rcsc::SideID convertSideID(protos::Side side_id);

src/grpc-client/grpc_client_coach.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ GrpcClientCoach::GrpcClientCoach()
2828
M_agent_type = protos::AgentType::CoachT;
2929
}
3030

31-
void GrpcClientCoach::init(rcsc::CoachAgent *agent,
31+
void GrpcClientCoach::init(rcsc::SoccerAgent *agent,
3232
std::string target,
3333
int port,
3434
bool use_same_grpc_port,
3535
bool add_20_to_grpc_port_if_right_side)
3636
{
37-
M_agent = agent;
37+
M_agent = static_cast<rcsc::CoachAgent *>(agent);
3838
M_unum = 12;
39-
M_team_name = agent->world().ourTeamName();
39+
M_team_name = M_agent->world().ourTeamName();
4040
if (add_20_to_grpc_port_if_right_side)
4141
if (M_agent->world().ourSide() == rcsc::SideID::RIGHT)
4242
port += 20;

src/grpc-client/grpc_client_coach.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class GrpcClientCoach : public GrpcClient {
88
public:
99
GrpcClientCoach() ;
1010

11-
void init(rcsc::CoachAgent * agent,
11+
void init(rcsc::SoccerAgent * agent,
1212
std::string target="localhost",
1313
int port=50051,
1414
bool use_same_grpc_port=true,
15-
bool add_20_to_grpc_port_if_right_side=false);
15+
bool add_20_to_grpc_port_if_right_side=false) override;
1616

1717
void getActions();
1818
State generateState() const;

src/grpc-client/grpc_client_player.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ GrpcClientPlayer::GrpcClientPlayer()
8383
M_agent_type = protos::AgentType::PlayerT;
8484
}
8585

86-
void GrpcClientPlayer::init(rcsc::PlayerAgent *agent,
86+
void GrpcClientPlayer::init(rcsc::SoccerAgent *agent,
8787
std::string target,
8888
int port,
8989
bool use_same_grpc_port,
9090
bool add_20_to_grpc_port_if_right_side)
9191
{
92-
M_agent = agent;
93-
M_unum = agent->world().self().unum();
94-
M_team_name = agent->world().ourTeamName();
92+
M_agent = static_cast<rcsc::PlayerAgent *>(agent);
93+
M_unum = M_agent->world().self().unum();
94+
M_team_name = M_agent->world().ourTeamName();
9595
if (add_20_to_grpc_port_if_right_side)
9696
if (M_agent->world().ourSide() == rcsc::SideID::RIGHT)
9797
port += 20;
@@ -108,7 +108,9 @@ void GrpcClientPlayer::init(rcsc::PlayerAgent *agent,
108108
void GrpcClientPlayer::getActions()
109109
{
110110
auto agent = M_agent;
111+
bool pre_process = checkPreprocess(agent);
111112
State state = generateState();
113+
state.set_need_preprocess(pre_process);
112114
protos::RegisterResponse* response = new protos::RegisterResponse(*M_register_response);
113115
state.set_allocated_register_response(response);
114116
protos::PlayerActions actions;
@@ -122,6 +124,16 @@ void GrpcClientPlayer::getActions()
122124
return;
123125
}
124126

127+
if (pre_process && !actions.ignore_preprocess())
128+
{
129+
if (doPreprocess(agent))
130+
{
131+
rcsc::dlog.addText( rcsc::Logger::TEAM,
132+
__FILE__": preprocess done" );
133+
return;
134+
}
135+
}
136+
125137
int body_action_done = 0;
126138
for (int i = 0; i < actions.actions_size(); i++)
127139
{

src/grpc-client/grpc_client_player.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#include "grpc_client.h"
22
#include "player/sample_communication.h"
3+
#include "rpc-client/rpc-player-client.h"
34

4-
class GrpcClientPlayer : public GrpcClient {
5+
class GrpcClientPlayer : public GrpcClient, public RpcPlayerClient {
56
rcsc::PlayerAgent * M_agent;
67
Communication::Ptr sample_communication;
78
public:
89
GrpcClientPlayer();
910

10-
void init(rcsc::PlayerAgent * agent,
11+
void init(rcsc::SoccerAgent * agent,
1112
std::string target="localhost",
1213
int port=50051,
1314
bool use_same_grpc_port=true,
14-
bool add_20_to_grpc_port_if_right_side=false);
15+
bool add_20_to_grpc_port_if_right_side=false) override;
1516

1617
void getActions();
1718
void addSayMessage(protos::Say sayMessage) const;

src/grpc-client/grpc_client_trainer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ GrpcClientTrainer::GrpcClientTrainer()
2727
M_agent_type = protos::AgentType::TrainerT;
2828
}
2929

30-
void GrpcClientTrainer::init(rcsc::TrainerAgent *agent,
30+
void GrpcClientTrainer::init(rcsc::SoccerAgent *agent,
3131
std::string target,
3232
int port,
3333
bool use_same_grpc_port,
3434
bool add_20_to_grpc_port_if_right_side)
3535
{
36-
M_agent = agent;
36+
M_agent = static_cast<rcsc::TrainerAgent *>(agent);
3737
M_unum = 13;
38-
M_team_name = agent->world().ourTeamName();
38+
M_team_name = M_agent->world().ourTeamName();
3939
if (add_20_to_grpc_port_if_right_side)
4040
if (M_agent->world().ourSide() == rcsc::SideID::RIGHT)
4141
port += 20;

0 commit comments

Comments
 (0)