From 0ad9d4be0d7e71a3eb702aa6f1fda7d0d6bf60df Mon Sep 17 00:00:00 2001 From: ariannagavioli Date: Tue, 18 Dec 2018 23:36:04 +0100 Subject: [PATCH] modified: include/task.h modified: src/main.c modified: src/tlgraphics.c modified: src/tlmanager.c modified: src/utils.c --- include/task.h | 2 +- src/main.c | 1 + src/tlgraphics.c | 41 +++++++++++++++++++++++++++-------------- src/tlmanager.c | 2 +- src/utils.c | 12 ++++++------ 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/include/task.h b/include/task.h index bf264fc..4d40641 100644 --- a/include/task.h +++ b/include/task.h @@ -7,7 +7,7 @@ /*Structure that defines the parameters of a real time task*/ typedef struct { pthread_t tid; /* task id*/ - long wcet; /* in microseconds */ + //long wcet; /* in microseconds */ int period; /* in milliseconds */ int deadline; /* relative (ms) */ int priority; /* in [0,99] */ diff --git a/src/main.c b/src/main.c index 38838fe..2b70eca 100644 --- a/src/main.c +++ b/src/main.c @@ -37,6 +37,7 @@ int tl_matrix[N_BLOCKS_X*2 * N_BLOCKS_Y*2]; int main(int argc, char const *argv[]) { + srand (time(NULL)); allegro_init(); //n_blocks = 30; //for now diff --git a/src/tlgraphics.c b/src/tlgraphics.c index 8e5e36c..9d87f79 100644 --- a/src/tlgraphics.c +++ b/src/tlgraphics.c @@ -149,23 +149,36 @@ void drawTLCabins(int* tl_matrix, const int i, const int j, const int someCoeff) int top_right_corner, bottom_right_corner, top_left_corner, bottom_left_corner; - top_right_corner = (getpixel(screen, x_right + STREET_W/2, y_up - STREET_W - 1) == BLOCK_COL - && getpixel(screen, x_right + STREET_W + 1, y_up - STREET_W/2) == BLOCK_COL) ? 0 : 1; + top_right_corner = ((getpixel(screen, x_right + STREET_W/2, y_up - STREET_W - 5) == BLOCK_COL) + && (getpixel(screen, x_right + STREET_W + 5, y_up - STREET_W/2) == BLOCK_COL)) ? 0 : 1; + + bottom_right_corner = ((getpixel(screen, x_right + STREET_W/2, y_low + STREET_W + 5) == BLOCK_COL) + && (getpixel(screen, x_right + STREET_W + 5, y_low + STREET_W/2) == BLOCK_COL)) ? 0 : 1; + + top_left_corner = ((getpixel(screen, x_left - STREET_W/2, y_up - STREET_W - 5) == BLOCK_COL) + && (getpixel(screen, x_left - STREET_W - 5, y_up - STREET_W/2) == BLOCK_COL)) ? 0 : 1; + + bottom_left_corner = ((getpixel(screen, x_left - STREET_W/2, y_low + STREET_W + 5) == BLOCK_COL) + && (getpixel(screen, x_left - STREET_W - 5, y_low + STREET_W/2) == BLOCK_COL)) ? 0 : 1; int top_right_needed, bottom_right_needed, top_left_needed, bottom_left_needed; - top_right_needed = top_right_corner && unique_right && unique_top; + top_right_needed = top_right_corner && unique_top && unique_right; + bottom_right_needed = bottom_right_corner && unique_bottom && unique_right; + top_left_needed = top_left_corner && unique_top && unique_left; + bottom_left_needed = bottom_left_corner && unique_bottom && unique_left; /*top right of the block*/ if(top_right_needed){ + // if(unique_top && unique_right){ if(!(i == N_BLOCKS_X - 1 && j == 0)){ rectfill(screen, x_right - TL_SIZE - BL_BORDER, y_up + TL_SIZE + BL_BORDER, x_right - BL_BORDER, y_up + BL_BORDER, TL_COL); - tl_matrix[j*2*N_BLOCKS_X*2 + i*2 + 1] = TL_GREEN; + tl_matrix[j*2*N_BLOCKS_X*2 + i*2 + 1] = TL_RED*2; /*half a circle on left of the cabinet*/ circlefill(screen, x_right - BL_BORDER - TL_SIZE/2, - y_up + BL_BORDER + TL_SIZE/2, LIGHTS_RAY, TL_GREEN); + y_up + BL_BORDER + TL_SIZE/2, LIGHTS_RAY, TL_RED); rectfill(screen, x_right - TL_SIZE/2 - BL_BORDER, y_up + BL_BORDER, x_right - BL_BORDER, y_up + TL_SIZE + BL_BORDER, TL_COL); rect(screen, x_right - TL_SIZE - BL_BORDER, y_up + TL_SIZE + BL_BORDER, @@ -175,15 +188,15 @@ void drawTLCabins(int* tl_matrix, const int i, const int j, const int someCoeff) else{tl_matrix[j*2*N_BLOCKS_X*2+ i*2 + 1] = -1;} /*bottom right of the block*/ - if(unique_right && unique_bottom){ + if(bottom_right_needed){ if(!(i == N_BLOCKS_X - 1 && j == N_BLOCKS_Y - 1)){ rectfill(screen, x_right - TL_SIZE - BL_BORDER, y_low - BL_BORDER, x_right - BL_BORDER, y_low - TL_SIZE - BL_BORDER, TL_COL); - tl_matrix[(j*2+1)*N_BLOCKS_X*2 + i*2 + 1] = TL_RED; + tl_matrix[(j*2+1)*N_BLOCKS_X*2 + i*2 + 1] = TL_YELLOW; /*half a circle on top of the cabinet*/ circlefill(screen, x_right - BL_BORDER - TL_SIZE/2, - y_low - BL_BORDER - TL_SIZE/2, LIGHTS_RAY, TL_RED); + y_low - BL_BORDER - TL_SIZE/2, LIGHTS_RAY, TL_YELLOW); rectfill(screen, x_right - TL_SIZE - BL_BORDER, y_low - BL_BORDER, x_right - BL_BORDER, y_low - TL_SIZE/2 - BL_BORDER, TL_COL); rect(screen, x_right - TL_SIZE - BL_BORDER, y_low - BL_BORDER, @@ -194,15 +207,15 @@ void drawTLCabins(int* tl_matrix, const int i, const int j, const int someCoeff) else{tl_matrix[(j*2+1)*N_BLOCKS_X*2 + i*2 + 1] = -1;} /*top left of the block*/ - if(unique_left && unique_top){ + if(top_left_needed){ if(i || j){ rectfill(screen, x_left + BL_BORDER, y_up + TL_SIZE + BL_BORDER, x_left + TL_SIZE + BL_BORDER, y_up + BL_BORDER, TL_COL); - tl_matrix[j*2*N_BLOCKS_X*2 + i*2] = TL_RED; + tl_matrix[j*2*N_BLOCKS_X*2 + i*2] = TL_YELLOW; /*half a circle on the bottom of the cabinet*/ circlefill(screen, x_left + BL_BORDER + TL_SIZE/2, - y_up + BL_BORDER + TL_SIZE/2, LIGHTS_RAY, TL_RED); + y_up + BL_BORDER + TL_SIZE/2, LIGHTS_RAY, TL_YELLOW); rectfill(screen, x_left + BL_BORDER, y_up + TL_SIZE/2 + BL_BORDER, x_left + TL_SIZE + BL_BORDER, y_up + BL_BORDER, TL_COL); rect(screen, x_left + BL_BORDER, y_up + TL_SIZE + BL_BORDER, @@ -212,15 +225,15 @@ void drawTLCabins(int* tl_matrix, const int i, const int j, const int someCoeff) else{tl_matrix[j*2*N_BLOCKS_X*2 + i*2] = -1;} /*bottom left of the block*/ - if(unique_left && unique_bottom){ + if(bottom_left_needed){ if(!(i == 0 && j == N_BLOCKS_Y - 1)){ rectfill(screen, x_left + BL_BORDER, y_low - BL_BORDER, x_left + TL_SIZE + BL_BORDER, y_low - TL_SIZE - BL_BORDER, TL_COL); - tl_matrix[(j*2+1)*N_BLOCKS_X*2 + i*2] = TL_GREEN; + tl_matrix[(j*2+1)*N_BLOCKS_X*2 + i*2] = TL_RED*2; /*half a circle on the right of the cabinet*/ circlefill(screen, x_left + BL_BORDER + TL_SIZE/2, - y_low - BL_BORDER - TL_SIZE/2, LIGHTS_RAY, TL_GREEN); + y_low - BL_BORDER - TL_SIZE/2, LIGHTS_RAY, TL_RED); rectfill(screen, x_left + BL_BORDER, y_low - BL_BORDER, x_left + TL_SIZE/2 + BL_BORDER, y_low - TL_SIZE - BL_BORDER, TL_COL); rect(screen, x_left + BL_BORDER, y_low - BL_BORDER, diff --git a/src/tlmanager.c b/src/tlmanager.c index 08af35f..55b94cf 100644 --- a/src/tlmanager.c +++ b/src/tlmanager.c @@ -5,7 +5,7 @@ #include void tl_init() { - sleep(4); + // sleep(4); } void tl_manager(void *arg){ diff --git a/src/utils.c b/src/utils.c index 135587f..861fc2d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -66,12 +66,7 @@ void initRandomMap(int *tl_matrix){ int a, b; srand (time(NULL)); - - for (i = 0; i < N_BLOCKS_X * 2; i++) { - for (j = 0; j < N_BLOCKS_Y * 2; j++) { - tl_matrix[j * N_BLOCKS_X * 2 + i] = 0; - } - } + for(i = 0; i < N_BLOCKS_X; i++){ for(j = 0; j < N_BLOCKS_Y; j++){ @@ -93,6 +88,11 @@ void initRandomMap(int *tl_matrix){ (j * someCoeff) + BLOCK_W + b * STREET_W, BLOCK_COL); + } + } + + for (i = 0; i < N_BLOCKS_X; i++) { + for (j = 0; j < N_BLOCKS_Y; j++) { drawTLCabins(tl_matrix, i, j, someCoeff); } }