Finally we dont recalculate numbers if we dont have to. Boring but doesnt peg...

Finally we dont recalculate numbers if we dont have to. Boring but doesnt peg hardware, should impliment some sort of bencmark or whatever.
parent be97187c
No preview for this file type
No preview for this file type
......@@ -121,7 +121,8 @@ render_cl(Array *arr, App *app, ViewInfo view) {
arr->pointer = realloc(arr->pointer, app->win_height * app->win_width * sizeof(Color));
arr->size = app->win_height * app->win_width * sizeof(Color);
}
calculate_set(arr, app->win_height, app->win_width, view);
if (app->needs_recalc)
calculate_set(arr, app->win_height, app->win_width, view);
update_texture(app, arr);
......@@ -150,7 +151,8 @@ main(void)
SDL_TEXTUREACCESS_STREAMING,
SCREEN_WIDTH, SCREEN_HEIGHT),
SCREEN_HEIGHT,
SCREEN_WIDTH
SCREEN_WIDTH,
1
};
ViewInfo view = {
......@@ -200,6 +202,7 @@ main(void)
SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STREAMING,
app.win_width, app.win_height);
app.needs_recalc = 1;
}
break;
case SDL_KEYDOWN:
......@@ -215,6 +218,8 @@ main(void)
view.y_min= view.y_min * 1.1;
view.y_max = view.y_max * 1.1;
view.zoom = view.zoom * 1.1;
app.needs_recalc = 1;
break;
case SDL_SCANCODE_EQUALS:
view.x_min = view.x_min * 0.9;
......@@ -222,6 +227,8 @@ main(void)
view.y_min= view.y_min * 0.9;
view.y_max = view.y_max * 0.9;
view.zoom = view.zoom * 0.9;
app.needs_recalc = 1;
break;
case SDL_SCANCODE_R:
view.x_min = -2.0;
......@@ -229,10 +236,14 @@ main(void)
view.y_min = -1.5;
view.y_max = 1.5;
view.zoom = 1.0;
app.needs_recalc = 1;
break;
}
default:
handle_mouse(event, &mouse, &view);
//returns one if recalc needed
app.needs_recalc = app.needs_recalc == 0 ? handle_mouse(event, &mouse, &view) : 1;
break;
}
}
......@@ -254,7 +265,8 @@ main(void)
render_ui(&ui, app.renderer, view, fps);
SDL_RenderPresent(app.renderer);
SDL_RenderPresent(app.renderer);
app.needs_recalc = 0;
}
//SDL_FreeSurface(app.surfaceA);
free(screen.pointer);
......
......@@ -19,6 +19,7 @@ typedef struct{
SDL_Texture *texture;
int win_height;
int win_width;
short unsigned int needs_recalc;
} App ;
typedef struct{
......
#include "mandelbrot.h"
void
unsigned short int
handle_mouse(SDL_Event event, Mouse* mouse, ViewInfo* view) {
unsigned short int needs_recalc = 0;
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == SDL_BUTTON_LEFT) {
......@@ -34,6 +35,8 @@ handle_mouse(SDL_Event event, Mouse* mouse, ViewInfo* view) {
view->y_max = mouse_imag + (view->y_max - mouse_imag) * zoom_factor;
view->zoom *= (1.0 / zoom_factor);
needs_recalc = 1;
}
break;
......@@ -49,8 +52,10 @@ handle_mouse(SDL_Event event, Mouse* mouse, ViewInfo* view) {
view->x_max = mouse->original_view.x_max - dx * scale_x;
view->y_min = mouse->original_view.y_min - dy * scale_y;
view->y_max = mouse->original_view.y_max - dy * scale_y;
needs_recalc = 1;
}
break;
}
return needs_recalc;
}
......@@ -3,6 +3,6 @@
#include "mandelbrot.h"
#include <SDL2/SDL_events.h>
void handle_mouse(SDL_Event, Mouse*, ViewInfo*);
unsigned short int handle_mouse(SDL_Event, Mouse*, ViewInfo*);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment