void GameStateModule::update() { // Check comm input last so we can reset button toggles. if (buttonPressInput.message().toggle() != last_button) { last_button = !last_button; if (!commInput.message().have_remote_gc() || latest_data.state() == STATE_PLAYING) { advanceState(); } } if (initialStateInput.message().toggle() != last_initial) { last_initial = !last_initial; if (!commInput.message().have_remote_gc()) reset(); } if (switchTeamInput.message().toggle() != last_team) { last_team = !last_team; if (!commInput.message().have_remote_gc() && latest_data.state() == STATE_INITIAL) switchTeam(); } if (switchKickOffInput.message().toggle() != last_kickoff) { last_kickoff = !last_kickoff; if (!commInput.message().have_remote_gc() && latest_data.state() == STATE_INITIAL) switchKickOff(); } if (commInput.message().have_remote_gc()) { latest_data = commInput.message(); if (latest_data.state() != STATE_PLAYING) { keep_time = false; } else { keep_time = true; } } if (keep_time) { // @TODO: keep track of secs remaining if we have no comm. } }
void GameStateModule::update() { // Check comm input last so we can reset button toggles. if (buttonPressInput.message().toggle() != last_button) { last_button = !last_button; if (!commInput.message().have_remote_gc() || latest_data.state() == STATE_PLAYING) { advanceState(); } } if (initialStateInput.message().toggle() != last_initial) { last_initial = !last_initial; if (!commInput.message().have_remote_gc()) reset(); } if (switchTeamInput.message().toggle() != last_team) { last_team = !last_team; if (!commInput.message().have_remote_gc() && latest_data.state() == STATE_INITIAL) switchTeam(); } if (switchKickOffInput.message().toggle() != last_kickoff) { last_kickoff = !last_kickoff; if (!commInput.message().have_remote_gc() && latest_data.state() == STATE_INITIAL) switchKickOff(); } if (commInput.message().have_remote_gc()) { latest_data = commInput.message(); if (latest_data.state() != STATE_PLAYING) { keep_time = false; start_time = 0; } else { keep_time = true; if (!start_time) { start_time = realtime_micro_time(); } } // Did GC get our message yet?? for (int i = 0; i < latest_data.team_size(); ++i) { messages::TeamInfo* team = latest_data.mutable_team(i); if (team->team_number() == team_number) { messages::RobotInfo* player = team->mutable_player(player_number-1); if (response_status == GAMECONTROLLER_RETURN_MSG_MAN_PENALISE) { if(player->penalty()) { response_status = GAMECONTROLLER_RETURN_MSG_ALIVE; } } else if (response_status == GAMECONTROLLER_RETURN_MSG_MAN_UNPENALISE) { if(!player->penalty()) { response_status == GAMECONTROLLER_RETURN_MSG_ALIVE; } } } } } if (keep_time && commInput.message().have_remote_gc()) { long long diff_time = realtime_micro_time() - start_time; latest_data.set_secs_remaining(600 - static_cast<unsigned int>(diff_time/MICROS_PER_SECOND)); //TODO keep track of penalty times } }