fixed ms clock issue using steady_clock -> high_resolution_clock. Changed line drawing to recursive instead of building line list in Map.cpp, seems to be a lot faster.
Former-commit-id: 81ff8167845869b8cf4fdc4ff3158aac84b24ce9
This commit is contained in:
parent
6caca48666
commit
df2ea21cde
|
@ -3,7 +3,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
static uint64_t now() {
|
static uint64_t now() {
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
static uint64_t now() {
|
static uint64_t now() {
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t elapsed(uint64_t ref) {
|
static uint64_t elapsed(uint64_t ref) {
|
||||||
|
|
41
Map.cpp
41
Map.cpp
|
@ -3,51 +3,26 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
bool Map::QTInsert(QuadTree *tree, Line *line, int depth) {
|
bool Map::QTInsert(QuadTree *tree, Line *line, int depth) {
|
||||||
// printf("Inserting %d point poly\n", line->numPoints);
|
|
||||||
|
|
||||||
|
bool startInside = line->start.lat >= tree->lat_min &&
|
||||||
// if (!(line->lat_min >= tree->lat_min &&
|
|
||||||
// line->lat_max <= tree->lat_max &&
|
|
||||||
// line->lon_min >= tree->lon_min &&
|
|
||||||
// line->lon_max <= tree->lon_max)) {
|
|
||||||
// // printf("doesnt fit: %f > %f, %f < %f, %f < %f,%f > %f \n",line->lat_min, tree->lat_min, line->lat_max, tree->lat_max, line->lon_min, tree->lon_min, line->lon_max,tree->lon_max);
|
|
||||||
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (!(line->start.lat >= tree->lat_min &&
|
|
||||||
line->start.lat <= tree->lat_max &&
|
line->start.lat <= tree->lat_max &&
|
||||||
line->start.lon >= tree->lon_min &&
|
line->start.lon >= tree->lon_min &&
|
||||||
line->start.lon <= tree->lon_max) &&
|
line->start.lon <= tree->lon_max;
|
||||||
!(line->end.lat >= tree->lat_min &&
|
|
||||||
|
bool endInside = line->end.lat >= tree->lat_min &&
|
||||||
line->end.lat <= tree->lat_max &&
|
line->end.lat <= tree->lat_max &&
|
||||||
line->end.lon >= tree->lon_min &&
|
line->end.lon >= tree->lon_min &&
|
||||||
line->end.lon <= tree->lon_max)
|
line->end.lon <= tree->lon_max;
|
||||||
) {
|
|
||||||
|
if (!startInside && !endInside) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (startInside != endInside) {
|
||||||
if ((line->start.lat >= tree->lat_min &&
|
|
||||||
line->start.lat <= tree->lat_max &&
|
|
||||||
line->start.lon >= tree->lon_min &&
|
|
||||||
line->start.lon <= tree->lon_max)!=
|
|
||||||
(line->end.lat >= tree->lat_min &&
|
|
||||||
line->end.lat <= tree->lat_max &&
|
|
||||||
line->end.lon >= tree->lon_min &&
|
|
||||||
line->end.lon <= tree->lon_max)
|
|
||||||
) {
|
|
||||||
|
|
||||||
tree->lines.push_back(&(*line));
|
tree->lines.push_back(&(*line));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// //temp maxdepth for debugging
|
|
||||||
// if(depth > 20) {
|
|
||||||
// tree->lines.push_back(*line);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (tree->nw == NULL) {
|
if (tree->nw == NULL) {
|
||||||
tree->nw = new QuadTree;
|
tree->nw = new QuadTree;
|
||||||
|
|
||||||
|
|
69
View.cpp
69
View.cpp
|
@ -640,6 +640,54 @@ void View::drawScaleBars()
|
||||||
lineRGBA(renderer,10,10+5*screen_uiscale,10+scaleBarDist,10+5*screen_uiscale, style.scaleBarColor.r, style.scaleBarColor.g, style. scaleBarColor.b, 255);
|
lineRGBA(renderer,10,10+5*screen_uiscale,10+scaleBarDist,10+5*screen_uiscale, style.scaleBarColor.r, style.scaleBarColor.g, style. scaleBarColor.b, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::drawLinesRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) {
|
||||||
|
if(tree == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tree->lat_min > screen_lat_max || screen_lat_min > tree->lat_max) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tree->lon_min > screen_lon_max || screen_lon_min > tree->lon_max) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawLinesRecursive(tree->nw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
|
|
||||||
|
drawLinesRecursive(tree->sw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
|
|
||||||
|
drawLinesRecursive(tree->ne, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
|
|
||||||
|
drawLinesRecursive(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
|
|
||||||
|
std::vector<Line*>::iterator currentLine;
|
||||||
|
|
||||||
|
for (currentLine = tree->lines.begin(); currentLine != tree->lines.end(); ++currentLine) {
|
||||||
|
int x1,y1,x2,y2;
|
||||||
|
float dx,dy;
|
||||||
|
|
||||||
|
pxFromLonLat(&dx, &dy, (*currentLine)->start.lon, (*currentLine)->start.lat);
|
||||||
|
screenCoords(&x1, &y1, dx, dy);
|
||||||
|
|
||||||
|
pxFromLonLat(&dx, &dy, (*currentLine)->end.lon, (*currentLine)->end.lat);
|
||||||
|
screenCoords(&x2, &y2, dx, dy);
|
||||||
|
|
||||||
|
lineCount++;
|
||||||
|
|
||||||
|
if(outOfBounds(x1,y1) && outOfBounds(x2,y2)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(x1 == x2 && y1 == y2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
lineRGBA(renderer, x1, y1, x2, y2, style.mapInnerColor.r, style.mapInnerColor.g, style.mapInnerColor.b, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void View::drawLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max, int bailTime) {
|
void View::drawLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max, int bailTime) {
|
||||||
std::vector<Line*> lineList = map.getLines(screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
std::vector<Line*> lineList = map.getLines(screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
|
|
||||||
|
@ -682,13 +730,9 @@ void View::drawGeography(int left, int top, int right, int bottom, int bailTime)
|
||||||
latLonFromScreenCoords(&screen_lat_min, &screen_lon_min, left, top);
|
latLonFromScreenCoords(&screen_lat_min, &screen_lon_min, left, top);
|
||||||
latLonFromScreenCoords(&screen_lat_max, &screen_lon_max, right, bottom);
|
latLonFromScreenCoords(&screen_lat_max, &screen_lon_max, right, bottom);
|
||||||
|
|
||||||
// screen_lat_min = 47.4;
|
drawLinesRecursive(&(map.root), screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
// screen_lat_max = 47.8;
|
|
||||||
|
|
||||||
// screen_lon_min = -122.5;
|
//drawLines(screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max, bailTime);
|
||||||
// screen_lon_max = -121.5;
|
|
||||||
|
|
||||||
drawLines(screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max, bailTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::drawSignalMarks(Aircraft *p, int x, int y) {
|
void View::drawSignalMarks(Aircraft *p, int x, int y) {
|
||||||
|
@ -698,15 +742,21 @@ void View::drawSignalMarks(Aircraft *p, int x, int y) {
|
||||||
|
|
||||||
SDL_Color barColor = signalToColor(signalAverage);
|
SDL_Color barColor = signalToColor(signalAverage);
|
||||||
|
|
||||||
Uint8 seenFade = (Uint8) (255.0 - elapsed(p->msSeen) / 4.0);
|
Uint8 seenFade;
|
||||||
|
|
||||||
|
if(elapsed(p->msSeen) < 1024) {
|
||||||
|
seenFade = (Uint8) (255.0 - elapsed(p->msSeen) / 4.0);
|
||||||
|
|
||||||
circleRGBA(renderer, x + mapFontWidth, y - 5, 2 * screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade);
|
circleRGBA(renderer, x + mapFontWidth, y - 5, 2 * screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(elapsed(p->msSeenLatLon) < 1024) {
|
||||||
seenFade = (Uint8) (255.0 - elapsed(p->msSeenLatLon) / 4.0);
|
seenFade = (Uint8) (255.0 - elapsed(p->msSeenLatLon) / 4.0);
|
||||||
|
|
||||||
hlineRGBA(renderer, x + mapFontWidth + 5 * screen_uiscale, x + mapFontWidth + 9 * screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade);
|
hlineRGBA(renderer, x + mapFontWidth + 5 * screen_uiscale, x + mapFontWidth + 9 * screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade);
|
||||||
vlineRGBA(renderer, x + mapFontWidth + 7 * screen_uiscale, y - 2 * screen_uiscale - 5, y + 2 * screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade);
|
vlineRGBA(renderer, x + mapFontWidth + 7 * screen_uiscale, y - 2 * screen_uiscale - 5, y + 2 * screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void View::drawPlaneText(Aircraft *p) {
|
void View::drawPlaneText(Aircraft *p) {
|
||||||
|
@ -715,6 +765,11 @@ void View::drawPlaneText(Aircraft *p) {
|
||||||
|
|
||||||
int currentLine = 0;
|
int currentLine = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if(elapsed(p->msSeenLatLon) < 500) {
|
||||||
|
circleRGBA(renderer, p->cx, p->cy, elapsed(p->msSeenLatLon) * screen_width / (8192), 255,255, 255, 64 - (uint8_t)(64.0 * elapsed(p->msSeenLatLon) / 500.0));
|
||||||
|
}
|
||||||
|
|
||||||
if(p->pressure * screen_width< 0.4f) {
|
if(p->pressure * screen_width< 0.4f) {
|
||||||
drawSignalMarks(p, p->x, p->y);
|
drawSignalMarks(p, p->x, p->y);
|
||||||
|
|
||||||
|
|
1
View.h
1
View.h
|
@ -86,6 +86,7 @@ class View {
|
||||||
void drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor);
|
void drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor);
|
||||||
void drawTrail(Aircraft *p);
|
void drawTrail(Aircraft *p);
|
||||||
void drawScaleBars();
|
void drawScaleBars();
|
||||||
|
void drawLinesRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
|
||||||
void drawLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max, int bailTime);
|
void drawLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max, int bailTime);
|
||||||
void drawGeography(int left, int top, int right, int bottom, int bailTime);
|
void drawGeography(int left, int top, int right, int bottom, int bailTime);
|
||||||
void drawSignalMarks(Aircraft *p, int x, int y);
|
void drawSignalMarks(Aircraft *p, int x, int y);
|
||||||
|
|
Loading…
Reference in a new issue