This repository has been archived by the owner on Nov 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHeadlessOutput.cpp
53 lines (45 loc) · 1.92 KB
/
HeadlessOutput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Created by n30phyte on 17/11/18.
//
#include <HeadlessOutput.h>
void HeadlessOutput::Update(std::vector<int> ball_location,
std::vector<int> paddle0_location,
std::vector<int> paddle1_location) {
// std::vector<std::vector<pongpipe::GameState_Pixels>>
// board(80, std::vector<pongpipe::GameState_Pixels>(80, pongpipe::GameState_Pixels::GameState_Pixels_empty));
//
// board[ball_location[0]][ball_location[1]] = pongpipe::GameState_Pixels::GameState_Pixels_ball;
// board[ball_location[0]][ball_location[1] + 1] = pongpipe::GameState_Pixels::GameState_Pixels_ball;
//
// for (auto i = -3; i < 5; i++) {
// board[paddle0_location[0]][paddle0_location[1] + i] = pongpipe::GameState_Pixels::GameState_Pixels_paddle0;
// board[paddle0_location[0] + 1][paddle0_location[1] + i] =
// pongpipe::GameState_Pixels::GameState_Pixels_paddle0;;
//
// board[paddle1_location[0]][paddle1_location[1] + i] = pongpipe::GameState_Pixels::GameState_Pixels_paddle1;
// board[paddle1_location[0] + 1][paddle1_location[1] + i] =
// pongpipe::GameState_Pixels::GameState_Pixels_paddle1;
// }
//
// std::stringstream response;
//
// response << "1 ";
//
// for (int j = 0; j < 80; j++) {
// for (int i = 0; i < 80; i++) {
// response << board[i][j];
// }
// }
std::stringstream response;
response << "gamestate "
<< ball_location[0] << " " << ball_location[1] << " "
<< paddle0_location[0] << " " << paddle0_location[1] << " "
<< paddle1_location[0] << " " << paddle1_location[1];
zmq::message_t state(response.str().length());
std::cout << response.str() << std::endl;
memcpy(state.data(), response.str().c_str(), response.str().length());
publisher.send(state);
}
HeadlessOutput::HeadlessOutput() {
publisher.bind("tcp://*:5555");
}