23 #include "refbox_state_writer.h"
25 #include <netcomm/worldinfo/transceiver.h>
26 #include <utils/time/time.h>
27 #include <utils/time/clock.h>
32 #define log(...) if (__debug) {\
33 printf("%3u %s ", __counter, get_time().c_str());\
39 using namespace fawkes;
42 std::string get_time() throw()
44 Clock* c = Clock::instance();
46 char* buf =
new char[Time::TIMESTR_SIZE];
48 std::string str = buf;
50 std::string::size_type from =
51 1+str.find_first_of(
' ',
52 1+str.find_first_of(
' ',
53 1+str.find_first_of(
' ')));
54 std::string::size_type to = str.find_last_of(
' ');
55 return str.substr(from, to - from + 1);
83 for (vector<string>::const_iterator it = hosts.begin(); it != hosts.end();
93 for (map<RemoteBlackBoard*, GameStateInterface*>::iterator it = __giss.begin();
94 it != __giss.end(); it++) {
104 void RefBoxStateBBWriter::connect(
const string& host)
111 log(
"Successfully connected to %s\n", host.c_str());
112 set_gamestate(__game_state, __state_team);
113 set_score(__score_cyan, __score_magenta);
114 set_team_goal(__our_team, __our_goal_color);
118 log(
"Connecting to %s failed\n", host.c_str());
133 log(
"Setting gamestate to '%d' for team '%s'\n",
136 __game_state = game_state;
137 __state_team = state_team;
139 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
213 log(
"Setting score to %u:%u (cyan:magenta)\n", score_cyan, score_magenta);
215 __score_cyan = score_cyan;
216 __score_magenta = score_magenta;
218 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
234 log(
"Setting team color to '%s' and goal color to '%s'\n",
238 __our_team = our_team;
239 __our_goal_color = goal_color;
241 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
264 log(
"Setting half to '%s'\n",
269 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
273 gis->
set_half(GameStateInterface::HALF_FIRST);
276 gis->
set_half(GameStateInterface::HALF_SECOND);
288 log(
"Sending worldinfo\n");
290 set<RemoteBlackBoard*> erase_rbbs;
291 set<string> reconnect_hosts;
294 for (map<RemoteBlackBoard*,GameStateInterface*>::iterator it = __giss.begin(); it != __giss.end(); it++) {
297 const string host = __rbbs[rbb].c_str();
301 log(
"%u. Successfully wrote game state on %s\n", ++i, __rbbs[rbb].c_str());
303 log(
"%u. Writing game state on %s failed, reason:\n", ++i, __rbbs[rbb].c_str());
305 log(
"I will reconnect after this loop\n");
306 erase_rbbs.insert(rbb);
307 reconnect_hosts.insert(host);
310 for (set<RemoteBlackBoard*>::iterator it = erase_rbbs.begin(); it != erase_rbbs.end(); it++) {
315 for (set<std::string>::iterator it = reconnect_hosts.begin(); it != reconnect_hosts.end(); it++) {
316 std::string host = *it;
317 log(
"Reconnecting to %s\n", host.c_str());
321 log(
"Sending worldinfo done\n");