fixed framerate checks
This commit is contained in:
parent
b7b5b69914
commit
e6e372c019
43
View.cpp
43
View.cpp
|
@ -260,7 +260,7 @@ void View::SDL_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
window = SDL_CreateWindow("viz1090", SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), screen_width, screen_height, flags);
|
window = SDL_CreateWindow("viz1090", SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), screen_width, screen_height, flags);
|
||||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
mapTexture = SDL_CreateTexture(renderer,
|
mapTexture = SDL_CreateTexture(renderer,
|
||||||
SDL_PIXELFORMAT_ARGB8888,
|
SDL_PIXELFORMAT_ARGB8888,
|
||||||
SDL_TEXTUREACCESS_TARGET,
|
SDL_TEXTUREACCESS_TARGET,
|
||||||
|
@ -411,9 +411,9 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
|
||||||
{
|
{
|
||||||
float body = 8.0 * screen_uiscale;
|
float body = 8.0 * screen_uiscale;
|
||||||
float wing = 6.0 * screen_uiscale;
|
float wing = 6.0 * screen_uiscale;
|
||||||
float wingThick = 0.35;
|
float wingThick = 0.5;
|
||||||
float tail = 3.0 * screen_uiscale;
|
float tail = 3.0 * screen_uiscale;
|
||||||
float tailThick = 0.5;
|
float tailThick = 0.15;
|
||||||
float bodyWidth = screen_uiscale;
|
float bodyWidth = screen_uiscale;
|
||||||
|
|
||||||
float vec[3];
|
float vec[3];
|
||||||
|
@ -435,15 +435,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]);
|
||||||
|
|
||||||
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);
|
//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);
|
||||||
|
|
||||||
x1 = x + round(15*vec[0]);
|
x1 = x + round(1*vec[0]);
|
||||||
y1 = y + round(15*vec[1]);
|
y1 = y + round(1*vec[1]);
|
||||||
x2 = x + round(30*vec[0]);
|
x2 = x + round(10*vec[0]);
|
||||||
y2 = y + round(30*vec[1]);
|
y2 = y + round(10*vec[1]);
|
||||||
|
|
||||||
lineRGBA(renderer,x1,y1,x2,y2,255,255,255,SDL_ALPHA_OPAQUE);
|
lineRGBA(renderer,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.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 +464,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*.75*vec[0] - tail*out[0]);
|
x1 = x + round(-body*.5*vec[0] - tail*out[0]);
|
||||||
y1 = y + round(-body*.75*vec[1] - tail*out[1]);
|
y1 = y + round(-body*.5*vec[1] - tail*out[1]);
|
||||||
x2 = x + round(-body*.75*vec[0] + tail*out[0]);
|
x2 = x + round(-body*.5*vec[0] + tail*out[0]);
|
||||||
y2 = y + round(-body*.75*vec[1] + tail*out[1]);
|
y2 = y + round(-body*.5*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);
|
||||||
}
|
}
|
||||||
|
@ -1110,6 +1110,7 @@ void View::registerMouseMove(int x, int y) {
|
||||||
//
|
//
|
||||||
|
|
||||||
void View::draw() {
|
void View::draw() {
|
||||||
|
drawStartTime = now();
|
||||||
|
|
||||||
int targetFrameTime = 15;
|
int targetFrameTime = 15;
|
||||||
|
|
||||||
|
@ -1118,11 +1119,11 @@ void View::draw() {
|
||||||
// }
|
// }
|
||||||
// highFramerate = false;
|
// highFramerate = false;
|
||||||
|
|
||||||
// if (elapsed(lastFrameTime) < targetFrameTime) {
|
if (lastFrameTime < targetFrameTime) {
|
||||||
// SDL_Delay(static_cast<Uint32>(targetFrameTime - elapsed(lastFrameTime)));
|
SDL_Delay(static_cast<Uint32>(targetFrameTime - lastFrameTime));
|
||||||
// }
|
}
|
||||||
|
|
||||||
SDL_Delay(targetFrameTime);
|
//SDL_Delay(targetFrameTime);
|
||||||
|
|
||||||
moveMapToTarget();
|
moveMapToTarget();
|
||||||
zoomMapToTarget();
|
zoomMapToTarget();
|
||||||
|
@ -1145,7 +1146,7 @@ void View::draw() {
|
||||||
|
|
||||||
if(fps) {
|
if(fps) {
|
||||||
char fps[60] = " ";
|
char fps[60] = " ";
|
||||||
snprintf(fps,40,"%.1f", 1000.0 / elapsed(lastFrameTime));
|
snprintf(fps,40,"%.1f", 1000.0 / lastFrameTime);
|
||||||
|
|
||||||
|
|
||||||
int left = 5;
|
int left = 5;
|
||||||
|
@ -1153,11 +1154,9 @@ void View::draw() {
|
||||||
drawStatusBox(&left, &top, "fps", fps, style.white);
|
drawStatusBox(&left, &top, "fps", fps, style.white);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Delay(33);
|
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if (elapsed(lastFrameTime) < targetFrameTime) {
|
//if (elapsed(lastFrameTime) < targetFrameTime) {
|
||||||
|
@ -1165,7 +1164,7 @@ void View::draw() {
|
||||||
//std::this_thread::sleep_for(fmilliseconds{100.0f});
|
//std::this_thread::sleep_for(fmilliseconds{100.0f});
|
||||||
//}
|
//}
|
||||||
|
|
||||||
lastFrameTime = now();
|
lastFrameTime = elapsed(drawStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
View::View(AppData *appData){
|
View::View(AppData *appData){
|
||||||
|
|
6
View.h
6
View.h
|
@ -151,9 +151,9 @@ class View {
|
||||||
|
|
||||||
float currentLon;
|
float currentLon;
|
||||||
float currentLat;
|
float currentLat;
|
||||||
std::chrono::high_resolution_clock::time_point lastFrameTime;
|
float lastFrameTime;
|
||||||
std::chrono::high_resolution_clock::time_point drawStartTime;
|
std::chrono::high_resolution_clock::time_point drawStartTime;
|
||||||
std::chrono::high_resolution_clock::time_point lastRedraw;
|
std::chrono::high_resolution_clock::time_point lastRedraw;
|
||||||
|
|
||||||
Map map;
|
Map map;
|
||||||
|
|
||||||
|
|
4
run.sh
4
run.sh
|
@ -1,2 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
startx ./viz1090 --screensize 360 360 --fullscreen --server adsb --lat 47.6 --lon -122.3
|
export DISPLAY=:0
|
||||||
|
../dump1090/dump1090 --fix --aggressive --net --quiet &
|
||||||
|
startx ./viz1090 --fps --fullscreen --screensize 240 320 --lat 47.6 --lon -122.3
|
||||||
|
|
Loading…
Reference in a new issue