geography renders to a seprate texture, only updates when moved

Former-commit-id: 8c6ec13e7e07eede486b4d804517de3212532216
Former-commit-id: f24714e0276678698dffbf4270fb73c16c9a872f
This commit is contained in:
nathan 2020-02-17 22:19:45 -08:00
parent 72763a5ba7
commit 8f3b9d2977
16 changed files with 66 additions and 32 deletions

2
defs.h
View file

@ -15,6 +15,8 @@
#define DISPLAY_ACTIVE 30 #define DISPLAY_ACTIVE 30
#define TRAIL_TTL_STEP 2 #define TRAIL_TTL_STEP 2
#define MIN_MAP_FEATURE 2
#define FRAMETIME 33 #define FRAMETIME 33
#define PAD 5 #define PAD 5

71
draw.c
View file

@ -529,7 +529,7 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou
} }
if((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1) < 100){ if((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1) < MIN_MAP_FEATURE){
currentPoint = currentPoint->next; currentPoint = currentPoint->next;
continue; continue;
} }
@ -538,7 +538,7 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou
double factor = 1.0 - (d1+d2) / (3* appData.maxDist * appData.maxDist); double factor = 1.0 - (d1+d2) / (3* appData.maxDist * appData.maxDist);
SDL_Color lineColor = lerpColor(blue, purple, factor); SDL_Color lineColor = lerpColor(purple, blue, factor);
lineRGBA(appData.renderer, x1, y1, x2, y2, lineColor.r, lineColor.g, lineColor.b, 255); lineRGBA(appData.renderer, x1, y1, x2, y2, lineColor.r, lineColor.g, lineColor.b, 255);
@ -865,17 +865,10 @@ void resolveLabelConflicts() {
} }
void drawMap() { void drawPlanes() {
struct planeObj *p = planes; struct planeObj *p = planes;
time_t now = time(NULL); time_t now = time(NULL);
SDL_Color planeColor; SDL_Color planeColor;
drawGeography();
drawScaleBars();
for(int i = 0; i < 4; i++) {
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
@ -931,10 +924,14 @@ void drawMap() {
} }
if(p == selectedPlane) { if(p == selectedPlane) {
appData.centerLon += 0.1 * (p->lon - appData.centerLon);
appData.centerLat += 0.1 * (p->lat - appData.centerLat);
if(fabs(p->lon - appData.centerLon) > 0.0001 || fabs(p->lat - appData.centerLat) > .0001) {
appData.centerLon += 0.1 * (p->lon - appData.centerLon);
appData.centerLat += 0.1 * (p->lat - appData.centerLat);
appData.mapMoved = 1;
}
thickLineRGBA(appData.renderer, x - 40, y - 40, x - 10, y - 40, 4, pink.r, pink.g, pink.b, 255); thickLineRGBA(appData.renderer, x - 40, y - 40, x - 10, y - 40, 4, pink.r, pink.g, pink.b, 255);
thickLineRGBA(appData.renderer, x - 40, y - 40, x - 40, y - 10, 4, pink.r, pink.g, pink.b, 255); thickLineRGBA(appData.renderer, x - 40, y - 40, x - 40, y - 10, 4, pink.r, pink.g, pink.b, 255);
@ -1004,26 +1001,54 @@ void drawMap() {
// //
void draw() { void draw() {
uint64_t drawStartTime = mstime();
if ((mstime() - appData.lastFrameTime) < FRAMETIME) {
return;
}
appData.lastFrameTime = mstime();
updatePlanes(); updatePlanes();
updateStatus(); updateStatus();
SDL_SetRenderDrawColor( appData.renderer, 0, 15, 30, 0); if(appData.mapMoved) {
SDL_SetRenderTarget(appData.renderer, appData.mapTexture);
SDL_SetRenderDrawColor(appData.renderer, 0, 0, 0, 0);
SDL_RenderClear(appData.renderer);
drawGeography();
drawScaleBars();
SDL_SetRenderTarget(appData.renderer, NULL );
appData.mapMoved = 0;
}
for(int i = 0; i < 4; i++) {
resolveLabelConflicts();
}
//SDL_SetRenderDrawColor( appData.renderer, 0, 15, 30, 0);
SDL_SetRenderDrawColor(appData.renderer, 0, 0, 0, 0);
SDL_RenderClear(appData.renderer); SDL_RenderClear(appData.renderer);
drawMap(); SDL_RenderCopy(appData.renderer, appData.mapTexture, NULL, NULL);
drawPlanes();
drawStatus(); drawStatus();
if(appData.showList) { if(appData.showList) {
drawList(0); drawList(0);
} }
SDL_RenderPresent(appData.renderer); char fps[10] = " ";
snprintf(fps,10," %ffps", 1000.0 / (mstime() - appData.lastFrameTime));
drawStringBG(fps, 0,0, appData.mapFont, grey, black);
SDL_RenderPresent(appData.renderer);
appData.lastFrameTime = mstime();
if ((mstime() - drawStartTime) < FRAMETIME) {
usleep(1000 * (FRAMETIME - (mstime() - drawStartTime)));
}
} }

View file

@ -1 +1 @@
d08aaa37cf2b39ef11671ed4f318ae82fcf0c1dd e35f478e482bb67eed7951d8c622b7fc5ad06aa7

BIN
font.o

Binary file not shown.

6
init.c
View file

@ -37,11 +37,13 @@ void init(char *title) {
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.mapTexture = SDL_CreateTexture(appData.renderer,
SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, SDL_TEXTUREACCESS_TARGET,
appData.screen_width, appData.screen_height); appData.screen_width, appData.screen_height);
appData.mapMoved = 1;
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

@ -47,10 +47,12 @@ void getInput()
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
appData.maxDist *= 1.0 + event.wheel.y / 10.0; appData.maxDist *= 1.0 + event.wheel.y / 10.0;
appData.mapMoved = 1;
break; break;
case SDL_MULTIGESTURE: case SDL_MULTIGESTURE:
appData.maxDist /=1.0 + 4.0*event.mgesture.dDist; appData.maxDist /=1.0 + 4.0*event.mgesture.dDist;
appData.mapMoved = 1;
break; break;
case SDL_FINGERMOTION:; case SDL_FINGERMOTION:;
@ -74,6 +76,7 @@ void getInput()
appData.centerLon += outLon; appData.centerLon += outLon;
appData.centerLat += outLat; appData.centerLat += outLat;
appData.mapMoved = 1;
break; break;

View file

@ -1 +1 @@
71b217637379d15bac063de1731f31a46620dce5 d4947b5d39abcf0073465f4b5683173294132874

BIN
list.o

Binary file not shown.

BIN
monokai.o

Binary file not shown.

Binary file not shown.

View file

@ -1 +1 @@
006a8fe10b2ac3777a05e5056d4166533ad2fae5 9aa844df5159c2a246895c0eb2a306f53d0a36fd

View file

@ -7,7 +7,7 @@ typedef struct AppData
{ {
SDL_Window *window; SDL_Window *window;
SDL_Renderer *renderer; SDL_Renderer *renderer;
SDL_Texture *texture; SDL_Texture *mapTexture;
TTF_Font *mapFont; TTF_Font *mapFont;
TTF_Font *mapBoldFont; TTF_Font *mapBoldFont;
@ -43,6 +43,8 @@ typedef struct AppData
int touchx; int touchx;
int touchy; int touchy;
int mapMoved;
uint64_t lastFrameTime; uint64_t lastFrameTime;
} AppData; } AppData;

View file

@ -1 +1 @@
607b9efc8cc81bbdd0c6f524632fc9b69ab1e244 8796641d884a28c9d0b97396f099bd3333607849

View file

@ -358,7 +358,7 @@ int main(int argc, char **argv) {
} }
modesReadFromClient(c,"",decodeBinMessage); modesReadFromClient(c,"",decodeBinMessage);
usleep(10000); //usleep(10000);
} }
// The user has stopped us, so close any socket we opened // The user has stopped us, so close any socket we opened

View file

@ -1 +1 @@
188de208d70a8a746cda5dd29c243ac3053a9c0c 790297577270307a97648484360f0eeb3de83233