/bike.h |
---|
11,10 → 11,11 |
#include <cmath> |
#include <time.h> |
#include <stdio.h> |
#include <pthread.h> |
using namespace std; |
class Bike : public QThread |
class Bike : public QObject |
{ |
Q_OBJECT |
/mainwindow.h |
---|
8,6 → 8,7 |
#include <QTimer> |
#include <QGLWidget> |
#include "bike.h" |
class MainWindow : public QGLWidget |
/main.cpp |
---|
7,4 → 7,5 |
MainWindow w; |
w.show(); |
return a.exec(); |
pthread_exit(NULL); |
} |
/bike.cpp |
---|
166,6 → 166,7 |
time_t result = time(NULL); |
cout << result << ": Recieved next move from " << name.toStdString().c_str() << endl; |
pthread_exit(NULL); |
} |
int sign(int x){ |
/mainwindow.cpp |
---|
37,6 → 37,12 |
} |
} |
void *runtherun(void *bike){ |
Bike *realbike = (Bike *)bike; |
realbike->run(); |
pthread_exit(NULL); |
} |
void MainWindow::paintEvent(QPaintEvent *e) |
{ |
if (suddenDeath) |
64,6 → 70,7 |
if (ready) |
{ |
cout << ":: Sent move request..." << endl; |
pthread_t threads[bikes.count()]; |
for (int i = 0; i < bikes.count(); i++) |
{ |
if (bikes[i]->show) |
70,7 → 77,7 |
{ |
bikes[i]->hasHadGo = false; |
bikes[i]->bikes = bikes; |
bikes[i]->start(); |
pthread_create(&threads[i],NULL,runtherun,(void *)bikes[i]); |
} |
} |
Bike *bike; |