misc fixes for label system. rudimentary LOD to speed up wide map drawing

Former-commit-id: 84c0bc68e284508d9e16ccceb6f7b7dc35dd4b60
Former-commit-id: 4a3065e9d6762bee1f8d854a176022290563fa5f
This commit is contained in:
nathan 2019-09-21 20:46:52 -05:00
parent ebdf5e2575
commit cc3a4f3e88
16 changed files with 208 additions and 97 deletions

7
defs.h
View file

@ -6,11 +6,6 @@
#include "SDL2/SDL_ttf.h" #include "SDL2/SDL_ttf.h"
#include "mapdata.h" #include "mapdata.h"
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480
#define UISCALE 1
#define ROUND_RADIUS 3 //radius of text box corners #define ROUND_RADIUS 3 //radius of text box corners
#define CENTEROFFSET .375 //vertical offset for middle of screen #define CENTEROFFSET .375 //vertical offset for middle of screen
@ -21,3 +16,5 @@
#define TRAIL_TTL_STEP 2 #define TRAIL_TTL_STEP 2
#define FRAMETIME 33 #define FRAMETIME 33
#define PAD 5

171
draw.c
View file

@ -48,6 +48,64 @@ SDL_Color signalToColor(int signal) {
return planeColor; return planeColor;
} }
SDL_Color hsv2SDLColor(double h, double s, double v)
{
double hh, p, q, t, ff;
long i;
SDL_Color out;
if(s <= 0.0) { // < is bogus, just shuts up warnings
out.r = (uint8_t)v;
out.g = (uint8_t)v;
out.b = (uint8_t)v;
return out;
}
hh = h;
if(hh >= 360.0) hh = 0.0;
hh /= 60.0;
i = (long)hh;
ff = hh - i;
p = v * (1.0 - s);
q = v * (1.0 - (s * ff));
t = v * (1.0 - (s * (1.0 - ff)));
switch(i) {
case 0:
out.r = (uint8_t)v;
out.g = (uint8_t)t;
out.b = (uint8_t)p;
break;
case 1:
out.r = (uint8_t)q;
out.g = (uint8_t)v;
out.b = (uint8_t)p;
break;
case 2:
out.r = (uint8_t)p;
out.g = (uint8_t)v;
out.b = (uint8_t)t;
break;
case 3:
out.r = (uint8_t)p;
out.g = (uint8_t)q;
out.b = (uint8_t)v;
break;
case 4:
out.r = (uint8_t)t;
out.g = (uint8_t)p;
out.b = (uint8_t)v;
break;
case 5:
default:
out.r = (uint8_t)v;
out.g = (uint8_t)p;
out.b = (uint8_t)q;
break;
}
return out;
}
int screenDist(double d) { int screenDist(double d) {
double scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height; double scale_factor = (appData.screen_width > appData.screen_height) ? appData.screen_width : appData.screen_height;
@ -276,7 +334,7 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee
x2 = currentX + round(cross_size*vec[0]); x2 = currentX + round(cross_size*vec[0]);
y2 = currentY + round(cross_size*vec[1]); y2 = currentY + round(cross_size*vec[1]);
lineRGBA(appData.renderer,x1,y1,x2,y2,colorVal,colorVal,colorVal,127); thickLineRGBA(appData.renderer,x1,y1,x2,y2,appData.screen_uiscale,colorVal,colorVal,colorVal,127);
//side cross //side cross
x1 = currentX + round(-cross_size*out[0]); x1 = currentX + round(-cross_size*out[0]);
@ -284,7 +342,7 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee
x2 = currentX + round(cross_size*out[0]); x2 = currentX + round(cross_size*out[0]);
y2 = currentY + round(cross_size*out[1]); y2 = currentY + round(cross_size*out[1]);
lineRGBA(appData.renderer,x1,y1,x2,y2,colorVal,colorVal,colorVal,127); thickLineRGBA(appData.renderer,x1,y1,x2,y2,appData.screen_uiscale,colorVal,colorVal,colorVal,127);
} }
} }
@ -306,11 +364,32 @@ void drawGrid()
void drawGeography() { void drawGeography() {
int x1, y1, x2, y2; int x1, y1, x2, y2;
for(int i=1; i<mapPoints_count/2; i++) { int skip = (int)(appData.maxDist / 25.0f);
if(skip < 1) {
skip = 1;
}
for(int i=skip; i<mapPoints_count/2; i+=skip) {
double dx, dy; double dx, dy;
pxFromLonLat(&dx, &dy, mapPoints_relative[(i - 1) * 2], mapPoints_relative[(i - 1) * 2 + 1]); dx = 1;
dy = 1;
for(int j = 0; j < skip; j++) {
if(!mapPoints_relative[(i - skip + j) * 2]) {
dx = 0;
}
if(!mapPoints_relative[(i - skip + j) * 2 + 1]) {
dy = 0;
}
}
if(!dx || !dy) {
continue;
}
pxFromLonLat(&dx, &dy, mapPoints_relative[(i - skip) * 2], mapPoints_relative[(i - skip) * 2 + 1]);
if(!dx || !dy) { if(!dx || !dy) {
continue; continue;
@ -345,7 +424,7 @@ void drawGeography() {
alpha = (alpha < 0) ? 0 : alpha; alpha = (alpha < 0) ? 0 : alpha;
lineRGBA(appData.renderer, x1, y1, x2, y2, alpha * purple.r + (1.0-alpha) * blue.r, alpha * purple.g + (1.0-alpha) * blue.g, alpha * purple.b + (1.0-alpha) * blue.b, 255 * alpha); thickLineRGBA(appData.renderer, x1, y1, x2, y2, appData.screen_uiscale, alpha * purple.r + (1.0-alpha) * blue.r, alpha * purple.g + (1.0-alpha) * blue.g, alpha * purple.b + (1.0-alpha) * blue.b, 255 * alpha);
} }
} }
@ -359,32 +438,36 @@ void drawSignalMarks(struct planeObj *p, int x, int y) {
Uint8 seenFade = (Uint8) (255.0 - (mstime() - p->msSeen) / 4.0); Uint8 seenFade = (Uint8) (255.0 - (mstime() - p->msSeen) / 4.0);
circleRGBA(appData.renderer, x, y - 5, 2 * appData.screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade); circleRGBA(appData.renderer, x + appData.mapFontWidth, y - 5, 2 * appData.screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade);
seenFade = (Uint8) (255.0 - (mstime() - p->msSeenLatLon) / 4.0); seenFade = (Uint8) (255.0 - (mstime() - p->msSeenLatLon) / 4.0);
hlineRGBA(appData.renderer, x + 5 * appData.screen_uiscale, x + 9 * appData.screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade); hlineRGBA(appData.renderer, x + appData.mapFontWidth + 5 * appData.screen_uiscale, x + appData.mapFontWidth + 9 * appData.screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade);
vlineRGBA(appData.renderer, x + 7 * appData.screen_uiscale, y - 2 * appData.screen_uiscale - 5, y + 2 * appData.screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade); vlineRGBA(appData.renderer, x + appData.mapFontWidth + 7 * appData.screen_uiscale, y - 2 * appData.screen_uiscale - 5, y + 2 * appData.screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade);
} }
void drawPlaneText(struct planeObj *p) { void drawPlaneText(struct planeObj *p) {
int maxCharCount = 0;
drawSignalMarks(p, p->x, p->y);
int maxCharCount;
int currentCharCount; int currentCharCount;
int currentLine = 0; int currentLine = 0;
if(p->pressure * appData.screen_width< 0.4f) {
drawSignalMarks(p, p->x, p->y);
char flight[10] = " "; char flight[10] = " ";
maxCharCount = snprintf(flight,10," %s", p->flight); maxCharCount = snprintf(flight,10," %s", p->flight);
if(maxCharCount > 0) { if(maxCharCount > 0) {
drawStringBG(flight, p->x, p->y, appData.mapBoldFont, white, black); drawStringBG(flight, p->x, p->y, appData.mapBoldFont, white, black);
//roundedRectangleRGBA(appData.renderer, p->x, p->y, p->x + maxCharCount * appData.mapFontWidth, p->y + appData.mapFontHeight, ROUND_RADIUS, white.r, white.g, white.b, SDL_ALPHA_OPAQUE);
//drawString(flight, p->x, p->y, appData.mapBoldFont, white);
currentLine++; currentLine++;
} }
}
if(p->pressure * appData.screen_width < 0.2f) {
char alt[10] = " "; char alt[10] = " ";
if (Modes.metric) { if (Modes.metric) {
currentCharCount = snprintf(alt,10," %dm", (int) (p->altitude / 3.2828)); currentCharCount = snprintf(alt,10," %dm", (int) (p->altitude / 3.2828));
@ -416,6 +499,23 @@ void drawPlaneText(struct planeObj *p) {
if(currentCharCount > maxCharCount) { if(currentCharCount > maxCharCount) {
maxCharCount = currentCharCount; maxCharCount = currentCharCount;
} }
}
if(maxCharCount > 0) {
Sint16 vx[4] = {p->cx, p->cx + (p->x - p->cx) / 2, p->x, p->x};
Sint16 vy[4] = {p->cy, p->cy + (p->y - p->cy) / 2, p->y - appData.mapFontHeight, p->y};
if(p->cy > p->y + currentLine * appData.mapFontHeight) {
vy[2] = p->y + currentLine * appData.mapFontHeight + appData.mapFontHeight;
vy[3] = p->y + currentLine * appData.mapFontHeight;
}
bezierRGBA(appData.renderer,vx,vy,4,2,200,200,200,SDL_ALPHA_OPAQUE);
thickLineRGBA(appData.renderer,p->x,p->y,p->x,p->y+currentLine*appData.mapFontHeight,appData.screen_uiscale,200,200,200,SDL_ALPHA_OPAQUE);
}
p->w = maxCharCount * appData.mapFontWidth; p->w = maxCharCount * appData.mapFontWidth;
p->h = currentLine * appData.mapFontHeight; p->h = currentLine * appData.mapFontHeight;
@ -444,12 +544,12 @@ void resolveLabelConflicts() {
//apply damping //apply damping
p->ddox -= 0.7f * p->dox; p->ddox -= 0.07f * p->dox;
p->ddoy -= 0.7f * p->doy; p->ddoy -= 0.07f * p->doy;
//spring back to origin //spring back to origin
p->ddox -= 0.05f * p->ox; p->ddox -= 0.005f * p->ox;
p->ddoy -= 0.05f * p->oy; p->ddoy -= 0.005f * p->oy;
// // //screen edge // // //screen edge
@ -469,9 +569,10 @@ void resolveLabelConflicts() {
p->oy -= (float)(p_bottom - (appData.screen_height - 10 * appData.screen_uiscale)); p->oy -= (float)(p_bottom - (appData.screen_height - 10 * appData.screen_uiscale));
} }
p->pressure = 0;
//check against other labels //check against other labels
while(check_p) { while(check_p) {
if(check_p->addr != p->addr) { if(check_p->addr != p->addr) {
@ -480,6 +581,10 @@ void resolveLabelConflicts() {
int check_top = check_p->y - 5 * appData.screen_uiscale; int check_top = check_p->y - 5 * appData.screen_uiscale;
int check_bottom = check_p->y + check_p->h + 5 * appData.screen_uiscale; int check_bottom = check_p->y + check_p->h + 5 * appData.screen_uiscale;
p->pressure += 1.0f / ((check_p->cx - p->cx) * (check_p->cx - p->cx) + (check_p->cy - p->cy) * (check_p->cy - p->cy));
//if(check_left > (p_right + 10) || check_right < (p_left - 10)) { //if(check_left > (p_right + 10) || check_right < (p_left - 10)) {
if(check_left > p_right || check_right < p_left) { if(check_left > p_right || check_right < p_left) {
check_p = check_p -> next; check_p = check_p -> next;
@ -494,22 +599,22 @@ void resolveLabelConflicts() {
//left collision //left collision
if(check_left > p_left && check_left < p_right) { if(check_left > p_left && check_left < p_right) {
check_p->ddox -= 0.1f * (float)(check_left - p_right); check_p->ddox -= 0.01f * (float)(check_left - p_right);
} }
//right collision //right collision
if(check_right > p_left && check_right < p_right) { if(check_right > p_left && check_right < p_right) {
check_p->ddox -= 0.1f * (float)(check_right - p_left); check_p->ddox -= 0.01f * (float)(check_right - p_left);
} }
//top collision //top collision
if(check_top > p_top && check_top < p_bottom) { if(check_top > p_top && check_top < p_bottom) {
check_p->ddoy -= 0.1f * (float)(check_top - p_bottom); check_p->ddoy -= 0.01f * (float)(check_top - p_bottom);
} }
//bottom collision //bottom collision
if(check_bottom > p_top && check_bottom < p_bottom) { if(check_bottom > p_top && check_bottom < p_bottom) {
check_p->ddoy -= 0.1f * (float)(check_bottom - p_top); check_p->ddoy -= 0.01f * (float)(check_bottom - p_top);
} }
} }
check_p = check_p -> next; check_p = check_p -> next;
@ -543,22 +648,22 @@ void resolveLabelConflicts() {
//left collision //left collision
if(check_left > p_left && check_left < p_right) { if(check_left > p_left && check_left < p_right) {
check_p->ddox -= 0.1f * (float)(check_left - p_right); check_p->ddox -= 0.04f * (float)(check_left - p_right);
} }
//right collision //right collision
if(check_right > p_left && check_right < p_right) { if(check_right > p_left && check_right < p_right) {
check_p->ddox -= 0.1f * (float)(check_right - p_left); check_p->ddox -= 0.04f * (float)(check_right - p_left);
} }
//top collision //top collision
if(check_top > p_top && check_top < p_bottom) { if(check_top > p_top && check_top < p_bottom) {
check_p->ddoy -= 0.1f * (float)(check_top - p_bottom); check_p->ddoy -= 0.04f * (float)(check_top - p_bottom);
} }
//bottom collision //bottom collision
if(check_bottom > p_top && check_bottom < p_bottom) { if(check_bottom > p_top && check_bottom < p_bottom) {
check_p->ddoy -= 0.1f * (float)(check_bottom - p_top); check_p->ddoy -= 0.04f * (float)(check_bottom - p_top);
} }
check_p = check_p -> next; check_p = check_p -> next;
@ -617,9 +722,9 @@ void drawMap() {
drawGrid(); drawGrid();
//for(int i = 0; i < 2; i++) { for(int i = 0; i < 4; i++) {
resolveLabelConflicts(); resolveLabelConflicts();
//} }
//draw all trails first so they don't cover up planes and text //draw all trails first so they don't cover up planes and text
@ -648,6 +753,10 @@ void drawMap() {
planeColor = grey; planeColor = grey;
} else { } else {
planeColor = white; planeColor = white;
//srand(p->addr);
// planeColor = hsv2SDLColor(255.0 * (double)rand()/(double)RAND_MAX, 255.0, 200.0);
//planeColor = signalToColor((int)(255.0f * (float)rand()/(float)RAND_MAX));
//fprintf("%d %d %d\n", planeColor.r, planeColor.g, planeColor.b);
} }
if(p->created == 0) { if(p->created == 0) {
@ -679,17 +788,17 @@ void drawMap() {
if(outOfBounds(x,y)) { if(outOfBounds(x,y)) {
drawPlaneOffMap(x, y, &(p->cx), &(p->cy), planeColor); drawPlaneOffMap(x, y, &(p->cx), &(p->cy), planeColor);
thickLineRGBA(appData.renderer, p->cx, p->cy, p->x+(p->w>>2), p->y, appData.screen_uiscale, 200,200,200,SDL_ALPHA_OPAQUE);
//lineRGBA(appData.renderer, p->cx, p->cy, p->x+(p->w/2), p->y, 200,200,200,SDL_ALPHA_OPAQUE);
} else { } else {
drawPlaneHeading(usex, usey, p->track, planeColor); drawPlaneHeading(usex, usey, p->track, planeColor);
p->cx = usex;// + 5; p->cx = usex;// + 5;
p->cy = usey;// + 10 * appData.screen_uiscale; p->cy = usey;// + 10 * appData.screen_uiscale;
if(p->cx != 0 && p->cy != 0 && p->x != 0 && p->y != 0) { //lineRGBA(appData.renderer, usex, usey, p->x+(p->w/2), p->y, 200,200,200, SDL_ALPHA_OPAQUE);
thickLineRGBA(appData.renderer, usex, usey, p->x+(p->w>>2), p->y, appData.screen_uiscale, 200,200,200, SDL_ALPHA_OPAQUE);
}
} }

View file

@ -1 +1 @@
a17d06a73e34e6e65d1ff9ed411da79667154ca6 5bec8587fd94772a4061e38543ad9846ffb0fc11

BIN
font.o

Binary file not shown.

9
init.c
View file

@ -27,6 +27,13 @@ void init(char *title) {
flags = flags | SDL_WINDOW_FULLSCREEN_DESKTOP; flags = flags | SDL_WINDOW_FULLSCREEN_DESKTOP;
} }
if(appData.screen_width == 0) {
SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);
appData.screen_width = DM.w;
appData.screen_height= DM.h;
}
appData.window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, appData.screen_width, appData.screen_height, flags); appData.window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, appData.screen_width, appData.screen_height, flags);
appData.renderer = SDL_CreateRenderer(appData.window, -1, 0); appData.renderer = SDL_CreateRenderer(appData.window, -1, 0);
appData.texture = SDL_CreateTexture(appData.renderer, appData.texture = SDL_CreateTexture(appData.renderer,
@ -35,7 +42,7 @@ void init(char *title) {
appData.screen_width, appData.screen_height); appData.screen_width, appData.screen_height);
if(appData.fullscreen) { if(appData.fullscreen) {
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother. //\SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother.
SDL_RenderSetLogicalSize(appData.renderer, appData.screen_width, appData.screen_height); SDL_RenderSetLogicalSize(appData.renderer, appData.screen_width, appData.screen_height);
} }

BIN
init.o

Binary file not shown.

View file

@ -1 +1 @@
2305764a62eb8dd80a5f71e908a04bfaa9bc3cc9 b7c0644a5ba34c2548772d880bce685146ce9e95

BIN
list.o

Binary file not shown.

BIN
monokai.o

Binary file not shown.

Binary file not shown.

View file

@ -4,8 +4,6 @@
#include "monokai.h" #include "monokai.h"
#include "SDL2/SDL2_gfxPrimitives.h" #include "SDL2/SDL2_gfxPrimitives.h"
#define PAD 5
void updateStatus() { void updateStatus() {
// struct aircraft *a = Modes.aircrafts; // struct aircraft *a = Modes.aircrafts;
@ -102,12 +100,12 @@ void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color co
int messageWidth = (strlen(message) + ((strlen(message) > 0 ) ? 1 : 0)) * appData.messageFontWidth; int messageWidth = (strlen(message) + ((strlen(message) > 0 ) ? 1 : 0)) * appData.messageFontWidth;
//newline if no message or label //newline if no message or label
if(strlen(label) == 0 && strlen(message) == 0 ) { // if(strlen(label) == 0 && strlen(message) == 0 ) {
boxRGBA(appData.renderer, *left, *top, appData.screen_width - PAD, *top + appData.messageFontHeight,0, 0, 0, 0); // boxRGBA(appData.renderer, *left, *top, appData.screen_width - PAD, *top + appData.messageFontHeight,0, 0, 0, 0);
*left = PAD; // *left = PAD;
*top = *top - appData.messageFontHeight - PAD; // *top = *top - appData.messageFontHeight - PAD;
return; // return;
} // }
if(*left + labelWidth + messageWidth + PAD > appData.screen_width) { if(*left + labelWidth + messageWidth + PAD > appData.screen_width) {
// if(*left + PAD < appData.screen_width) { // if(*left + PAD < appData.screen_width) {
@ -200,8 +198,8 @@ void drawBattery(int *left, int *top, double level) {
void drawStatus() { void drawStatus() {
int left = PAD + 2 * appData.messageFontHeight ; int left = PAD;
int top = appData.screen_height - 2 * appData.messageFontHeight - PAD; int top = appData.screen_height - appData.messageFontHeight - PAD;
char strLoc[20] = " "; char strLoc[20] = " ";
snprintf(strLoc, 20, "%3.3fN %3.3f%c", appData.centerLat, fabs(appData.centerLon),(appData.centerLon > 0) ? 'E' : 'W'); snprintf(strLoc, 20, "%3.3fN %3.3f%c", appData.centerLat, fabs(appData.centerLon),(appData.centerLon > 0) ? 'E' : 'W');

View file

@ -1 +1 @@
30a2da16b88ee34ce3413fff471b01c956184f32 90ec17d3fd60fd6950fbb50080a31747734eec21

View file

@ -77,7 +77,7 @@ struct planeObj {
int x, y, cx, cy, w, h; int x, y, cx, cy, w, h;
float ox, oy, dox, doy, ddox, ddoy; float ox, oy, dox, doy, ddox, ddoy;
float pressure;
}; };
struct planeObj *planes; struct planeObj *planes;

View file

@ -1 +1 @@
8994067f92a4d800070c11716a732a5636bb6e5b 2e266c7f3d943cd7251613fc0eddc9208d5bb05a

View file

@ -71,9 +71,9 @@ void view1090InitConfig(void) {
appData.centerLat = Modes.fUserLat; appData.centerLat = Modes.fUserLat;
// Display options // Display options
appData.screen_uiscale = UISCALE; appData.screen_uiscale = 1;
appData.screen_width = SCREEN_WIDTH; appData.screen_width = 0;
appData.screen_height = SCREEN_HEIGHT; appData.screen_height = 0;
appData.screen_depth = 32; appData.screen_depth = 32;
appData.fullscreen = 0; appData.fullscreen = 0;

View file

@ -1 +1 @@
a549061b45cd62ae3ca46ebf3b8e29c4956b9641 547bceb30b8891c365837c7f01eac3b9c227fa8e