added startup status messages for connection and map loading
This commit is contained in:
parent
e6e372c019
commit
03fd9ec4df
|
@ -45,7 +45,6 @@ class AppData {
|
||||||
//
|
//
|
||||||
|
|
||||||
struct client *c;
|
struct client *c;
|
||||||
bool connected;
|
|
||||||
int fd;
|
int fd;
|
||||||
char pk_buf[8];
|
char pk_buf[8];
|
||||||
|
|
||||||
|
@ -57,6 +56,8 @@ class AppData {
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
AppData();
|
AppData();
|
||||||
|
|
||||||
|
bool connected;
|
||||||
|
|
||||||
AircraftList aircraftList;
|
AircraftList aircraftList;
|
||||||
Modes modes;
|
Modes modes;
|
||||||
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
CXXFLAGS=-O2 -std=c++11 -g
|
CXXFLAGS=-O2 -std=c++11 -g
|
||||||
LIBS= -lm -lSDL2 -lSDL2_ttf -lSDL2_gfx -g
|
LIBS= -lm -lSDL2 -lSDL2_ttf -lSDL2_gfx -lpthread -g
|
||||||
CXX=g++
|
CXX=g++
|
||||||
|
|
||||||
all: viz1090
|
all: viz1090
|
||||||
|
|
67
Map.cpp
67
Map.cpp
|
@ -36,7 +36,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
bool Map::QTInsert(QuadTree *tree, Line *line, int depth) {
|
bool Map::QTInsert(QuadTree *tree, Line *line, int depth) {
|
||||||
|
|
||||||
// if(depth > 25) {
|
// if(depth > 25) {
|
||||||
|
@ -186,7 +186,8 @@ std::vector<Line*> Map::getLines(float screen_lat_min, float screen_lat_max, flo
|
||||||
return getLinesRecursive(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
return getLinesRecursive(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
};
|
};
|
||||||
|
|
||||||
Map::Map() {
|
|
||||||
|
void Map::load() {
|
||||||
FILE *fileptr;
|
FILE *fileptr;
|
||||||
|
|
||||||
if((fileptr = fopen("mapdata.bin", "rb"))) {
|
if((fileptr = fopen("mapdata.bin", "rb"))) {
|
||||||
|
@ -205,9 +206,31 @@ Map::Map() {
|
||||||
fclose(fileptr);
|
fclose(fileptr);
|
||||||
|
|
||||||
printf("Read %d map points.\n",mapPoints_count / 2);
|
printf("Read %d map points.\n",mapPoints_count / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if((fileptr = fopen("airportdata.bin", "rb"))) {
|
||||||
|
fseek(fileptr, 0, SEEK_END);
|
||||||
|
airportPoints_count = ftell(fileptr) / sizeof(float);
|
||||||
|
rewind(fileptr);
|
||||||
|
|
||||||
|
airportPoints = (float *)malloc(airportPoints_count * sizeof(float));
|
||||||
|
if(!fread(airportPoints, sizeof(float), airportPoints_count, fileptr)){
|
||||||
|
printf("Map read error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fileptr);
|
||||||
|
|
||||||
|
printf("Read %d airport points.\n",airportPoints_count / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int total = mapPoints_count / 2 + airportPoints_count / 2;
|
||||||
|
int processed = 0;
|
||||||
|
|
||||||
// load quad tree
|
// load quad tree
|
||||||
|
if(mapPoints_count > 0) {
|
||||||
for(int i = 0; i < mapPoints_count; i+=2) {
|
for(int i = 0; i < mapPoints_count; i+=2) {
|
||||||
if(mapPoints[i] == 0)
|
if(mapPoints[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -248,6 +271,10 @@ Map::Map() {
|
||||||
// printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
|
// printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
|
||||||
|
|
||||||
QTInsert(&root, new Line(currentPoint, nextPoint), 0);
|
QTInsert(&root, new Line(currentPoint, nextPoint), 0);
|
||||||
|
|
||||||
|
processed++;
|
||||||
|
|
||||||
|
loaded = floor(100.0f * (float)processed / (float)total);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("No map file found\n");
|
printf("No map file found\n");
|
||||||
|
@ -255,23 +282,9 @@ Map::Map() {
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
if((fileptr = fopen("airportdata.bin", "rb"))) {
|
|
||||||
fseek(fileptr, 0, SEEK_END);
|
|
||||||
airportPoints_count = ftell(fileptr) / sizeof(float);
|
|
||||||
rewind(fileptr);
|
|
||||||
|
|
||||||
airportPoints = (float *)malloc(airportPoints_count * sizeof(float));
|
|
||||||
if(!fread(airportPoints, sizeof(float), airportPoints_count, fileptr)){
|
|
||||||
printf("Map read error\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fileptr);
|
|
||||||
|
|
||||||
printf("Read %d airport points.\n",airportPoints_count / 2);
|
|
||||||
|
|
||||||
// load quad tree
|
// load quad tree
|
||||||
|
if(airportPoints_count > 0) {
|
||||||
for(int i = 0; i < airportPoints_count; i+=2) {
|
for(int i = 0; i < airportPoints_count; i+=2) {
|
||||||
if(airportPoints[i] == 0)
|
if(airportPoints[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -312,6 +325,10 @@ Map::Map() {
|
||||||
//printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
|
//printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
|
||||||
|
|
||||||
QTInsert(&airport_root, new Line(currentPoint, nextPoint), 0);
|
QTInsert(&airport_root, new Line(currentPoint, nextPoint), 0);
|
||||||
|
|
||||||
|
processed++;
|
||||||
|
|
||||||
|
loaded = floor(100.0f * (float)processed / (float)total);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("No airport file found\n");
|
printf("No airport file found\n");
|
||||||
|
@ -379,7 +396,17 @@ Map::Map() {
|
||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf("done\n");
|
printf("done\n");
|
||||||
|
|
||||||
|
loaded = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map::Map() {
|
||||||
|
loaded = 0;
|
||||||
|
|
||||||
|
mapPoints_count = 0;
|
||||||
|
mapPoints = NULL;
|
||||||
|
|
||||||
|
airportPoints_count = 0;
|
||||||
|
airportPoints = NULL;
|
||||||
}
|
}
|
||||||
|
|
2
Map.h
2
Map.h
|
@ -128,6 +128,8 @@ public:
|
||||||
std::vector<MapLabel*> mapnames;
|
std::vector<MapLabel*> mapnames;
|
||||||
std::vector<MapLabel*> airportnames;
|
std::vector<MapLabel*> airportnames;
|
||||||
|
|
||||||
|
void load();
|
||||||
|
int loaded;
|
||||||
Map();
|
Map();
|
||||||
|
|
||||||
int mapPoints_count;
|
int mapPoints_count;
|
||||||
|
|
80
View.cpp
80
View.cpp
|
@ -233,7 +233,6 @@ void View::font_init() {
|
||||||
//
|
//
|
||||||
|
|
||||||
void View::SDL_init() {
|
void View::SDL_init() {
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
printf("Could not initialize SDL: %s\n", SDL_GetError());
|
printf("Could not initialize SDL: %s\n", SDL_GetError());
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -322,11 +321,34 @@ void View::drawStatusBox(int *left, int *top, std::string label, std::string mes
|
||||||
*left = *left + labelWidth + messageWidth + PAD;
|
*left = *left + labelWidth + messageWidth + PAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::drawCenteredStatusBox(std::string label, std::string message, SDL_Color color) {
|
||||||
|
|
||||||
|
int labelWidth = (label.length() + ((label.length() > 0 ) ? 1 : 0)) * labelFontWidth;
|
||||||
|
int messageWidth = (message.length() + ((message.length() > 0 ) ? 1 : 0)) * messageFontWidth;
|
||||||
|
|
||||||
|
int left = (screen_width - (labelWidth + messageWidth)) / 2;
|
||||||
|
int top = (screen_height - labelFontHeight) / 2;
|
||||||
|
|
||||||
|
drawStatusBox(&left, &top, label, message, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void View::drawStatus() {
|
void View::drawStatus() {
|
||||||
|
|
||||||
int left = PAD;
|
int left = PAD;
|
||||||
int top = screen_height - messageFontHeight - PAD;
|
int top = screen_height - messageFontHeight - PAD;
|
||||||
|
|
||||||
|
if(fps) {
|
||||||
|
char fps[60] = " ";
|
||||||
|
snprintf(fps,40,"%.1f", 1000.0 / lastFrameTime);
|
||||||
|
|
||||||
|
drawStatusBox(&left, &top, "fps", fps, style.white);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!appData->connected) {
|
||||||
|
drawStatusBox(&left,&top,"init", "connecting", style.white);
|
||||||
|
} else {
|
||||||
char strLoc[20] = " ";
|
char strLoc[20] = " ";
|
||||||
snprintf(strLoc, 20, "%3.3fN %3.3f%c", centerLat, fabs(centerLon),(centerLon > 0) ? 'E' : 'W');
|
snprintf(strLoc, 20, "%3.3fN %3.3f%c", centerLat, fabs(centerLon),(centerLon > 0) ? 'E' : 'W');
|
||||||
drawStatusBox(&left, &top, "loc", strLoc, style.buttonColor);
|
drawStatusBox(&left, &top, "loc", strLoc, style.buttonColor);
|
||||||
|
@ -342,7 +364,13 @@ void View::drawStatus() {
|
||||||
char strSig[18] = " ";
|
char strSig[18] = " ";
|
||||||
snprintf(strSig, 18, "%.0f%%", 100.0 * appData->avgSig / 1024.0);
|
snprintf(strSig, 18, "%.0f%%", 100.0 * appData->avgSig / 1024.0);
|
||||||
drawStatusBox(&left, &top, "sAvg", strSig, style.buttonColor);
|
drawStatusBox(&left, &top, "sAvg", strSig, style.buttonColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(map.loaded < 100) {
|
||||||
|
char loaded[20] = " ";
|
||||||
|
snprintf(loaded, 20, "loading map %d%%", map.loaded);
|
||||||
|
drawStatusBox(&left,&top,"init", loaded, style.white);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -413,7 +441,7 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
|
||||||
float wing = 6.0 * screen_uiscale;
|
float wing = 6.0 * screen_uiscale;
|
||||||
float wingThick = 0.5;
|
float wingThick = 0.5;
|
||||||
float tail = 3.0 * screen_uiscale;
|
float tail = 3.0 * screen_uiscale;
|
||||||
float tailThick = 0.15;
|
float tailThick = 0.35;
|
||||||
float bodyWidth = screen_uiscale;
|
float bodyWidth = screen_uiscale;
|
||||||
|
|
||||||
float vec[3];
|
float vec[3];
|
||||||
|
@ -435,15 +463,15 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
|
||||||
x2 = x + round(bodyWidth*out[0]);
|
x2 = x + round(bodyWidth*out[0]);
|
||||||
y2 = y + round(bodyWidth*out[1]);
|
y2 = y + round(bodyWidth*out[1]);
|
||||||
|
|
||||||
//trigonRGBA (renderer, x1, y1, x2, y2, x+round(-body * vec[0]), y+round(-body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
filledTrigonRGBA (renderer, x1, y1, x2, y2, x+round(-body * vec[0]), y+round(-body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
||||||
//trigonRGBA (renderer, x1, y1, x2, y2, x+round(body * vec[0]), y+round(body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
filledTrigonRGBA (renderer, x1, y1, x2, y2, x+round(body * vec[0]), y+round(body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
||||||
|
|
||||||
x1 = x + round(1*vec[0]);
|
//x1 = x + round(8*vec[0]);
|
||||||
y1 = y + round(1*vec[1]);
|
//y1 = y + round(8*vec[1]);
|
||||||
x2 = x + round(10*vec[0]);
|
//x2 = x + round(16*vec[0]);
|
||||||
y2 = y + round(10*vec[1]);
|
//y2 = y + round(16*vec[1]);
|
||||||
|
|
||||||
lineRGBA(renderer,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
//lineRGBA(renderer,x1,y1,x2,y2, style.white.r, style.white.g, style.white.b, SDL_ALPHA_OPAQUE);
|
||||||
|
|
||||||
// x1 = x + round(-body*vec[0] + bodyWidth*out[0]);
|
// x1 = x + round(-body*vec[0] + bodyWidth*out[0]);
|
||||||
// y1 = y + round(-body*vec[1] + bodyWidth*out[1]);
|
// y1 = y + round(-body*vec[1] + bodyWidth*out[1]);
|
||||||
|
@ -464,10 +492,10 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
|
||||||
filledTrigonRGBA(renderer, x1, y1, x2, y2, x+round(body*wingThick*vec[0]), y+round(body*wingThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
filledTrigonRGBA(renderer, x1, y1, x2, y2, x+round(body*wingThick*vec[0]), y+round(body*wingThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
||||||
|
|
||||||
//tail
|
//tail
|
||||||
x1 = x + round(-body*.5*vec[0] - tail*out[0]);
|
x1 = x + round(-body*.75*vec[0] - tail*out[0]);
|
||||||
y1 = y + round(-body*.5*vec[1] - tail*out[1]);
|
y1 = y + round(-body*.75*vec[1] - tail*out[1]);
|
||||||
x2 = x + round(-body*.5*vec[0] + tail*out[0]);
|
x2 = x + round(-body*.75*vec[0] + tail*out[0]);
|
||||||
y2 = y + round(-body*.5*vec[1] + tail*out[1]);
|
y2 = y + round(-body*.75*vec[1] + tail*out[1]);
|
||||||
|
|
||||||
filledTrigonRGBA (renderer, x1, y1, x2, y2, x+round(-body*tailThick*vec[0]), y+round(-body*tailThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
filledTrigonRGBA (renderer, x1, y1, x2, y2, x+round(-body*tailThick*vec[0]), y+round(-body*tailThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
|
||||||
}
|
}
|
||||||
|
@ -1123,10 +1151,9 @@ void View::draw() {
|
||||||
SDL_Delay(static_cast<Uint32>(targetFrameTime - lastFrameTime));
|
SDL_Delay(static_cast<Uint32>(targetFrameTime - lastFrameTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
//SDL_Delay(targetFrameTime);
|
|
||||||
|
|
||||||
moveMapToTarget();
|
moveMapToTarget();
|
||||||
zoomMapToTarget();
|
zoomMapToTarget();
|
||||||
|
|
||||||
drawGeography();
|
drawGeography();
|
||||||
|
|
||||||
for(int i = 0; i < 8; i++) {
|
for(int i = 0; i < 8; i++) {
|
||||||
|
@ -1144,32 +1171,16 @@ void View::draw() {
|
||||||
//drawMouse();
|
//drawMouse();
|
||||||
drawClick();
|
drawClick();
|
||||||
|
|
||||||
if(fps) {
|
|
||||||
char fps[60] = " ";
|
|
||||||
snprintf(fps,40,"%.1f", 1000.0 / lastFrameTime);
|
|
||||||
|
|
||||||
|
|
||||||
int left = 5;
|
|
||||||
int top = 5;
|
|
||||||
drawStatusBox(&left, &top, "fps", fps, style.white);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if (elapsed(lastFrameTime) < targetFrameTime) {
|
|
||||||
//std::this_thread::sleep_for(fmilliseconds{targetFrameTime - elapsed(lastFrameTime)});
|
|
||||||
//std::this_thread::sleep_for(fmilliseconds{100.0f});
|
|
||||||
//}
|
|
||||||
|
|
||||||
lastFrameTime = elapsed(drawStartTime);
|
lastFrameTime = elapsed(drawStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
View::View(AppData *appData){
|
View::View(AppData *appData){
|
||||||
this->appData = appData;
|
this->appData = appData;
|
||||||
|
|
||||||
|
startupState = 0;
|
||||||
|
|
||||||
// Display options
|
// Display options
|
||||||
screen_uiscale = 1;
|
screen_uiscale = 1;
|
||||||
screen_width = 0;
|
screen_width = 0;
|
||||||
|
@ -1190,6 +1201,9 @@ View::View(AppData *appData){
|
||||||
mapRedraw = 1;
|
mapRedraw = 1;
|
||||||
|
|
||||||
selectedAircraft = NULL;
|
selectedAircraft = NULL;
|
||||||
|
|
||||||
|
std::thread t1(&Map::load, &map);
|
||||||
|
t1.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
View::~View() {
|
View::~View() {
|
||||||
|
|
3
View.h
3
View.h
|
@ -84,6 +84,7 @@ class View {
|
||||||
SDL_Rect drawString(std::string text, int x, int y, TTF_Font *font, SDL_Color color);
|
SDL_Rect drawString(std::string text, int x, int y, TTF_Font *font, SDL_Color color);
|
||||||
SDL_Rect drawStringBG(std::string text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor);
|
SDL_Rect drawStringBG(std::string text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor);
|
||||||
void drawStatusBox(int *left, int *top, std::string label, std::string message, SDL_Color color);
|
void drawStatusBox(int *left, int *top, std::string label, std::string message, SDL_Color color);
|
||||||
|
void drawCenteredStatusBox(std::string label, std::string message, SDL_Color color);
|
||||||
void drawStatus();
|
void drawStatus();
|
||||||
void moveLabels(float dx, float dy);
|
void moveLabels(float dx, float dy);
|
||||||
|
|
||||||
|
@ -133,6 +134,8 @@ class View {
|
||||||
|
|
||||||
bool fps;
|
bool fps;
|
||||||
|
|
||||||
|
int startupState;
|
||||||
|
|
||||||
float maxDist;
|
float maxDist;
|
||||||
float currentMaxDist;
|
float currentMaxDist;
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
AppData appData;
|
AppData appData;
|
||||||
View view(&appData);
|
View view(&appData);
|
||||||
|
|
||||||
Input input(&appData,&view);
|
Input input(&appData,&view);
|
||||||
|
|
||||||
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
|
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
|
||||||
|
@ -125,10 +126,10 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
while (go == 1)
|
while (go == 1)
|
||||||
{
|
{
|
||||||
appData.connect();
|
|
||||||
input.getInput();
|
input.getInput();
|
||||||
appData.update();
|
|
||||||
view.draw();
|
view.draw();
|
||||||
|
appData.connect();
|
||||||
|
appData.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
appData.disconnect();
|
appData.disconnect();
|
||||||
|
|
Loading…
Reference in a new issue