Reset & restart
This commit is contained in:
parent
d86ad9b2c3
commit
53e11ccbed
|
@ -136,13 +136,13 @@ namespace server {
|
|||
//server.writeString("world", error);
|
||||
|
||||
|
||||
//Scene demo_scene;
|
||||
//if (demo_scene.ParseFromString(message)){
|
||||
//std::cout << "POSSIBLE POSITIONS"<< std::endl;
|
||||
//for (int i=0; i<demo_scene.position_size(); ++i){
|
||||
// std::cout << " x: " << demo_scene.position(i).pos_x() << " y: " << demo_scene.position(i).pos_y() << std::endl;
|
||||
//}
|
||||
//}
|
||||
Scene demo_scene;
|
||||
if (demo_scene.ParseFromString(message)){
|
||||
std::cout << "POSSIBLE POSITIONS THREAD"<< std::endl;
|
||||
for (int i=0; i<demo_scene.position_size(); ++i){
|
||||
std::cout << " x: " << demo_scene.position(i).pos_x() << " y: " << demo_scene.position(i).pos_y() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
logTCPError("Failed to send world", error);
|
||||
|
@ -266,8 +266,10 @@ namespace server {
|
|||
_proto -> LoadScene(scene, values);
|
||||
|
||||
auto message = std::make_unique<std::string>();
|
||||
if (scene.SerializeToString(message.get()))
|
||||
|
||||
if (scene.SerializeToString(message.get())){
|
||||
_worldThread.push(std::move(message));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -320,6 +322,7 @@ namespace server {
|
|||
|
||||
bool CarlaCommunication::tryReadRequestNewEpisode(){
|
||||
std::unique_ptr <std::string> request = _worldThread.tryPop();
|
||||
|
||||
if (request == nullptr) return false;
|
||||
|
||||
RequestNewEpisode reqEpisode;
|
||||
|
|
|
@ -51,7 +51,8 @@ namespace thread {
|
|||
}
|
||||
|
||||
void push(std::unique_ptr<R> item) {
|
||||
_readQueue.push(std::move(item));
|
||||
|
||||
if (item != nullptr) _readQueue.push(std::move(item));
|
||||
}
|
||||
|
||||
void reconnect(){
|
||||
|
@ -78,9 +79,6 @@ namespace thread {
|
|||
_restart = false;
|
||||
_readQueue.canWait(true);
|
||||
while (!_restart && !_done) {
|
||||
|
||||
std::cout << "1" << std::endl;
|
||||
|
||||
auto value = _readQueue.wait_and_pop();
|
||||
if (value != nullptr) {
|
||||
_readJob(*value);
|
||||
|
|
|
@ -58,21 +58,17 @@ namespace thread {
|
|||
private:
|
||||
void workerThread() {
|
||||
while (!_done){
|
||||
std::cout << "2.1" << std::endl;
|
||||
_connectionJob();
|
||||
_restart = false;
|
||||
_queue.canWait(true);
|
||||
while (!_restart && !_done) {
|
||||
|
||||
std::cout << "2.2" << std::endl;
|
||||
|
||||
auto value = _queue.wait_and_pop();
|
||||
if (value != nullptr) _job(*value);
|
||||
//Sleep(10);
|
||||
if (value != nullptr) {
|
||||
_job(*value);
|
||||
}//Sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "2.3" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::atomic_bool _done;
|
||||
|
|
|
@ -57,22 +57,14 @@ namespace thread {
|
|||
|
||||
void workerThread() {
|
||||
while (!_done){
|
||||
std::cout << "3.1" << std::endl;
|
||||
|
||||
_connectJob();
|
||||
_restart = false;
|
||||
_queue.canWait(true);
|
||||
while (!_restart && !_done) {
|
||||
|
||||
std::cout << "3.2" << std::endl;
|
||||
|
||||
_queue.push(std::move(_job()));
|
||||
//Sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "3.3" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
std::atomic_bool _done;
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace thread {
|
|||
//_queue.push(new_value);
|
||||
//_condition.notify_one();
|
||||
_value = std::move(new_value);
|
||||
_condition.notify_one();
|
||||
}
|
||||
|
||||
void canWait(bool wait){
|
||||
|
@ -42,7 +43,6 @@ namespace thread {
|
|||
_condition.wait(lock, [this]() {
|
||||
return _value != nullptr || !_canWait;
|
||||
});
|
||||
|
||||
return std::move(_value);
|
||||
}
|
||||
|
||||
|
|
|
@ -125,10 +125,10 @@ int main(int argc, char *argv[]) {
|
|||
const std::array<float, 16u> pMatrix = {{ 10.0 }};
|
||||
sceneValues.projection_matrices.push_back(pMatrix);
|
||||
|
||||
std::cout << "POSSIBLE POSITIONS 5"<< std::endl;
|
||||
/* std::cout << "POSSIBLE POSITIONS "<< std::endl;
|
||||
for (int i=0; i<sceneValues.possible_positions.size(); ++i){
|
||||
std::cout << " x: " << sceneValues.possible_positions[i].x << " y: " << sceneValues.possible_positions[i].y << std::endl;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
if (!server.sendSceneValues(sceneValues)) std::cerr << "ERROR while sending SceneValues" << std::endl;
|
||||
|
@ -153,7 +153,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
while (true) {
|
||||
float steer, gas;
|
||||
/*bool newEpisode = false;
|
||||
bool newEpisode = false;
|
||||
if (!server.newEpisodeRequested(newEpisode)){
|
||||
std::cerr << "ERROR while checking for newEpisode request" << std::endl;
|
||||
break;
|
||||
|
@ -184,7 +184,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
}else {
|
||||
*/
|
||||
|
||||
bool error = false, readed = false;
|
||||
if (!server.tryReadControl(steer, gas, readed)){
|
||||
std::cerr << "ERROR while reading Control" << std::endl;
|
||||
|
@ -201,7 +201,7 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
}
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << " ----- RESTARTING -----" << std::endl;
|
||||
|
|
Loading…
Reference in New Issue