Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1664 | pj | 1 | #ifndef _SIM_AREA_HEADER_ |
2 | #include "sim_area.h" |
||
3 | #endif |
||
4 | |||
5 | char airport_name[25]; |
||
6 | atc atcs[MAX_ATCS]; |
||
7 | int INITATC=1; |
||
8 | |||
9 | extern int num; |
||
10 | void paint_sim_area() |
||
11 | { |
||
12 | int i,j; |
||
13 | int temp_atc_id = 0; |
||
14 | char temp[10]; |
||
15 | |||
16 | sem_wait(&graphics_mutex); //take the graphics mutex |
||
17 | for (i=0;i<=XMAX;) |
||
18 | { |
||
19 | //display the zones |
||
20 | grx_line(XMIN+i, YMIN, XMIN+i, YMAX, blue); |
||
21 | if (i<=YMAX) |
||
22 | { |
||
23 | grx_line(XMIN, YMIN+i, XMAX, YMIN+i, blue); |
||
24 | } |
||
25 | |||
26 | //display the ATCs |
||
27 | for (j=0;j<YMAX-YMIN-1;) |
||
28 | { |
||
29 | if (i<XMAX-XMIN-1) |
||
30 | { |
||
31 | //set the ATC data only the first time |
||
32 | if (INITATC==1) |
||
33 | { |
||
34 | atcs[(i+j)/GRID_SIZE].id = (temp_atc_id%4)+(j/GRID_SIZE*4); |
||
35 | atcs[(i+j)/GRID_SIZE].x =XMIN+(GRID_SIZE/2+i); |
||
36 | atcs[(i+j)/GRID_SIZE].y =YMIN+(GRID_SIZE/2+j); |
||
37 | } |
||
38 | //draw the ATCs everytime |
||
39 | grx_circle(XMIN+(GRID_SIZE/2+i), YMIN+(GRID_SIZE/2+j), ATCSIZE, green); |
||
40 | sprintf(temp,"ATC%d",atcs[(i+j)/GRID_SIZE].id); |
||
41 | grx_text(temp,atcs[(i+j)/GRID_SIZE].x-ATCSIZE-5,atcs[(i+j)/GRID_SIZE].y-ATCSIZE/2, green,black); |
||
42 | } |
||
43 | j=j+GRID_SIZE; |
||
44 | } |
||
45 | temp_atc_id++; |
||
46 | i=i+GRID_SIZE; |
||
47 | } |
||
48 | |||
49 | INITATC=0; //now the ATC IDs should not be initialized |
||
50 | |||
51 | for (i=0;i<NUM_OF_AIRPORTS;i++) |
||
52 | { |
||
53 | //we do not use mutual exclusion on airpors because we are only reading it and it is not being modified by any other thread / task |
||
54 | |||
55 | //display airports |
||
56 | grx_box(airports[i].x-airports[i].airportsize, airports[i].y-airports[i].airportsize, airports[i].x+airports[i].airportsize,airports[i].y+airports[i].airportsize, white); |
||
57 | grx_text(airports[i].airportname,airports[i].x-airports[i].airportsize/1.5, airports[i].y-airports[i].airportsize/3, blue, white); |
||
58 | } |
||
59 | sem_post(&graphics_mutex); |
||
60 | |||
61 | } |
||
62 | |||
63 | TASK draw_sim_area(void* arg) |
||
64 | { |
||
65 | do |
||
66 | { |
||
67 | mutex_lock(&mut_STARTSIM); |
||
68 | if (!(STARTSIM==-1 || STARTSIM==0)) |
||
69 | { |
||
70 | paint_sim_area(); |
||
71 | } |
||
72 | mutex_unlock(&mut_STARTSIM); |
||
73 | task_endcycle(); |
||
74 | }while(1); |
||
75 | } |
||
76 | |||
77 | |||
78 | void init_simulation() |
||
79 | { |
||
80 | SOFT_TASK_MODEL sim_area; |
||
81 | PID p; |
||
82 | |||
83 | paint_sim_area(); //paint the simulation area and populate the ATC structure |
||
84 | |||
85 | soft_task_default_model(sim_area); |
||
86 | soft_task_def_level(sim_area,1); |
||
87 | soft_task_def_ctrl_jet (sim_area); |
||
88 | soft_task_def_arg (sim_area, (void *)1); |
||
89 | soft_task_def_period (sim_area, DRAWSIMAREAPERIOD); |
||
90 | soft_task_def_met (sim_area, DRAWSIMAREAWCET); |
||
91 | soft_task_def_usemath (sim_area); |
||
92 | p = task_create("ref_Sim", draw_sim_area, &sim_area, NULL); |
||
93 | |||
94 | if (p == NIL) |
||
95 | { |
||
96 | grx_close(); |
||
97 | perror("Could not create task <Sim_Area>"); |
||
98 | sys_abort(1); |
||
99 | } |
||
100 | task_activate(p); |
||
101 | } |