diff options
author | Laurent Ghigonis <laurent@p1sec.com> | 2012-11-05 03:29:50 +0100 |
---|---|---|
committer | Laurent Ghigonis <laurent@p1sec.com> | 2012-11-05 03:29:50 +0100 |
commit | f2fd04bd5b197e4717c3502813b956fe6bbbcdfc (patch) | |
tree | f9842e15bf04d4aa01d2dbce438e556b3c39231f | |
parent | activate debug and reduce grid size for debug (diff) | |
download | glouglou-f2fd04bd5b197e4717c3502813b956fe6bbbcdfc.tar.xz glouglou-f2fd04bd5b197e4717c3502813b956fe6bbbcdfc.zip |
it works it works !
much performance improvements compaired to the multi evas_object implementation
increase grid size to 200x200
-rw-r--r-- | src/elife_evas_smart.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 3064b4d..563c501 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -23,12 +23,12 @@ #include "elife_evas_smart.h" -#define NCELL_X 10 -#define NCELL_Y 10 +#define NCELL_X 200 +#define NCELL_Y 200 #define INJECT_PROBA 30 #define INITCELL_PROBA 7 #define CONWAY_GROW_DIE 600 -#define DEBUG 1 +#define DEBUG 0 #define MIN(a,b) (((a)<(b))?(a):(b)) #define CELL_GET(grid, x, y) &(grid->cells[(y*grid->w) + x]) @@ -147,7 +147,6 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) struct cell *cell; Evas_Object *o; int i, j; - int *mem; g = xmalloc(sizeof(struct grid)); g->container = container; @@ -159,13 +158,12 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) evas_object_data_set(o, "grid", g); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, grid_mouse_down, g); + evas_object_smart_member_add(o, container); evas_object_show(o); g->image = o; - mem = xmalloc(1); - evas_object_image_data_set(g->image, (void *) mem); - g->mem = mem; + g->mem = NULL; g->w = w; - g->h = w; + g->h = h; g->age = 0; g->mode = mode; g->cells = xmalloc(sizeof(struct cell) * w * h); @@ -174,6 +172,9 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) cell = CELL_GET(g, i, j); cell->x = i; cell->y = j; + cell->r = 0; + cell->g = 0; + cell->b = 0; cell->age = !(rand() % INITCELL_PROBA); } } @@ -249,6 +250,7 @@ grid_evolution(struct grid *grid) cell_redraw(cell, grid); } } + evas_object_image_pixels_dirty_set(grid->image, EINA_TRUE); grid->age++; } @@ -290,15 +292,19 @@ grid_redraw(struct grid *grid, int w, int h) grid->pix_w = w; grid->pix_h = h; grid->cell_pix_w = w / grid->w; - grid->cell_pix_w = h / grid->h; + grid->cell_pix_h = h / grid->h; if (DEBUG) printf("redraw: container %d %d cell %d %d\n", w, h, grid->cell_pix_w, grid->cell_pix_h); evas_object_image_fill_set(grid->image, 0, 0, w, h); evas_object_image_size_set (grid->image, w, h); - grid->mem = realloc(grid->mem, w * h * sizeof(int)); + evas_object_resize(grid->image, w, h); + if (grid->mem) + free(grid->mem); + grid->mem = calloc(w * h, sizeof(int)); if (!grid->mem) - err(1, "could not realloc grid->mem"); + err(1, "could not calloc grid->mem"); + evas_object_image_data_set(grid->image, (void *) grid->mem); for (j=0; j<grid->h; j++) { for (i=0; i<grid->w; i++) { cell = CELL_GET(grid, i, j); @@ -352,9 +358,12 @@ cell_redraw(struct cell *c, struct grid *grid) a = 255; if (r == c->r && g == c->g && b == c->b) return; + c->r = r; + c->g = g; + c->b = b; - x = c->x; - y = c->y; + x = c->x * grid->cell_pix_w; + y = c->y * grid->cell_pix_h; w = grid->cell_pix_w; h = grid->cell_pix_h; for (j=y; j<y+h; j++) { |