12 #define MOCK_SIZE 513 // number of lines with mocked values
19 cout <<
"Initiating Unity" << endl;
24 if(this->buildPid > 0)
26 cout <<
"Killing unity process: " << this->buildPid << endl;
27 kill(this->buildPid, SIGTERM);
30 if(!this->infoFile.is_open())
31 this->infoFile.close();
33 if(!this->altitudeFile.is_open())
34 this->altitudeFile.close();
36 if(!this->rotationFile.is_open())
37 this->rotationFile.close();
39 if(!this->positionFile.is_open())
40 this->positionFile.close();
42 cout <<
"Terminating Unity" << endl;
48 this->buildPid = fork();
49 if(this->buildPid == -1)
51 cout <<
"Problems while initiazing a new process!!!" << endl;
57 if(this->buildPid > 0)
59 cout <<
"Initiating unity build with the process: " << this->buildPid << endl;
68 cout <<
"Error while initiating unity build" << endl;
80 this->altitudeFile.open(
UNITY_ALTITUDE_FILE, std::ios::in | std::ios::binary | std::ios::ate);
85 if(!this->infoFile.is_open() || !this->altitudeFile.is_open() ||
86 !this->rotationFile.is_open() || this->positionFile.is_open())
88 cout <<
"Couldn't open unity communication files";
94 static std::ifstream file;
98 std::cout <<
"Mocaaaando" << std::endl;
99 static int mockIndex = 0;
104 file.open(
"files/unity_altitude_mock.txt", std::ios::in | std::ios::binary | std::ios::ate);
110 std::cout <<
"Unity mockData loaded: " << MOCK_SIZE *
sizeof(double) <<
" bytes long" << std::endl;
114 std::cout <<
"Failed to load unity mockData" << std::endl;
122 returned = (int)
mockData[mockIndex];
126 if(this->altitudeFile.is_open())
129 this->altitudeFile.sync();
131 this->altitudeFile >> returned;
134 this->altitudeFile.seekg(0, ios_base::beg);
137 std::cout <<
"Failed to load unity altitude" << std::endl;
146 if(this->positionFile.is_open())
152 this->positionFile << x <<
" " << z;
155 this->positionFile.flush();
158 std::cout <<
"Failed to write unity position" << std::endl;
163 if(this->rotationFile.is_open())
169 this->rotationFile << x <<
" " << y <<
" " << z;
172 this->rotationFile.flush();
175 std::cout <<
"Failed to write unity rotation" << std::endl;
180 if(this->infoFile.is_open())
186 this->infoFile << info;
189 this->infoFile.flush();
192 std::cout <<
"Failed to write unity information" << std::endl;
#define UNITY_ROTATION_FILE
#define UNITY_POSITION_FILE
void setPlayerRotation(double x, double y, double z)
#define CURRENT_UNITY_BUILD
#define UNITY_ALTITUDE_FILE
void setInfo(const char *info, int chars_written)
void setPlayerPosition(double x, double z)
static double mockData[MOCK_SIZE]