-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
156 lines (134 loc) · 4.95 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctime>
#include <string>
#include <thread>
#include <vector>
#include <iostream>
#include "includes/GUI/guiFunctions.h"
#include "includes/Client/client.hpp"
#include "includes/Client/Engine.hpp"
#include "includes/Client/signs.hpp"
#include "includes/Client/config.hpp"
#include "includes/Client/CLP.hpp"
line_data myline;
vector<sign_data> mysigns;
Engine engine;
System syst;
Client *client;
int main(int argc, char* argv[])
{
/* GUI initialization */
Platform wi;
struct nk_context* ctx;
windowInitialization(&wi, "Client", WINDOW_WIDTH, WINDOW_HEIGHT);
ctx = ctxInitialization(&wi, WINDOW_WIDTH, WINDOW_HEIGHT);
loadDefaultFont(&wi);
glEnable(GL_TEXTURE_2D);
struct nk_image streamImage;
struct nk_image stopSign = loadImageFromFile("../images/stop.jpeg");
struct nk_image giveWaySign = loadImageFromFile("../images/ustupi.jpg");
struct nk_image mainRoadSign = loadImageFromFile("../images/glavnaya.jpg");
struct nk_image crosswalkSign = loadImageFromFile("../images/crosswalk.jpeg");
struct nk_image greenLight = loadImageFromFile("../images/green_light.jpg");
struct nk_image yellowLight = loadImageFromFile("../images/yellow_light.jpg");
struct nk_image redLight = loadImageFromFile("../images/red_light.jpg");
/* Client initialization */
Object<std::vector<unsigned char>> *curObj = NULL;
Queue<std::vector<unsigned char>> &queue = syst.iqueue;
CLP::parse(argc, argv, syst);
client = new Client(syst);
printf("[I]: Connecting to %s:%d...\n",syst.host, syst.portno);
if(!client->connect())
{
printf("[E]: Connection failed.\n");
printf("Can't connect to server.");
return 1;
}
printf("Connection was successfully established!\n");
std::thread thr(client_fnc,ref(syst),ref(*client));
thr.detach();
while (true)
{
syst.line_get(myline);
syst.signs_get(mysigns);
syst.engine_get(engine);
/* take new obj */
curObj = queue.waitForNewObject(curObj);
unsigned char* buff = new unsigned char[curObj->obj->size()];
for (int i = 0; i < curObj->obj->size(); ++i)
buff[i] = (*(curObj->obj))[i];
streamImage = loadImageFromMemory(buff, sizeof(unsigned char) * curObj->obj->size());
delete[] buff;
/* Input */
SDL_Event evt;
nk_input_begin(ctx);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_QUIT) {
shutdown(&wi);
return 0;
}
nk_sdl_handle_event(&evt);
}
nk_input_end(ctx);
/* GUI */
if (nk_begin(ctx, "Stream", nk_rect(0, 0, WINDOW_WIDTH - 300, WINDOW_HEIGHT), NK_WINDOW_TITLE))
{
nk_layout_row_static(ctx, WINDOW_HEIGHT - 50, WINDOW_WIDTH - 322, 1);
nk_image(ctx, streamImage);
}
nk_end(ctx);
if (nk_begin(ctx, "Info", nk_rect(WINDOW_WIDTH - 300, 0, 300, WINDOW_HEIGHT), NK_WINDOW_TITLE))
{
for (unsigned i = 0; i < mysigns.size(); ++i)
{
switch (mysigns[i].sign)
{
case sign_none:
break;
case sign_crosswalk:
nk_layout_row_static(ctx, 100, 100, 1);
nk_image(ctx, crosswalkSign);
break;
case sign_stop:
nk_layout_row_static(ctx, 100, 100, 1);
nk_image(ctx, stopSign);
break;
case sign_mainroad:
nk_layout_row_static(ctx, 100, 100, 1);
nk_image(ctx, mainRoadSign);
break;
case sign_giveway:
nk_layout_row_static(ctx, 100, 100, 1);
nk_image(ctx, giveWaySign);
break;
case sign_trafficlight_red:
nk_layout_row_static(ctx, 100, 100, 1);
nk_image(ctx, redLight);
break;
case sign_trafficlight_yellow:
nk_layout_row_static(ctx, 100, 100, 1);
nk_image(ctx, yellowLight);
break;
case sign_trafficlight_green:
nk_layout_row_static(ctx, 100, 100, 1);
nk_image(ctx, greenLight);
break;
case sign_starttrafficlight_red:
break;
case sign_starttrafficlight_green:
break;
default:
break;
}
}
}
nk_end(ctx);
curObj->free();
render(&wi);
}
shutdown(&wi);
syst.setExitState();
return 0;
}