Blame |
Last modification |
View Log
| RSS feed
#ifndef _SIM_AREA_HEADER_
#include "sim_area.h"
#endif
char airport_name
[25];
atc atcs
[MAX_ATCS
];
int INITATC
=1;
extern int num
;
void paint_sim_area
()
{
int i
,j
;
int temp_atc_id
= 0;
char temp
[10];
sem_wait
(&graphics_mutex
); //take the graphics mutex
for (i
=0;i
<=XMAX
;)
{
//display the zones
grx_line
(XMIN
+i
, YMIN
, XMIN
+i
, YMAX
, blue
);
if (i
<=YMAX
)
{
grx_line
(XMIN
, YMIN
+i
, XMAX
, YMIN
+i
, blue
);
}
//display the ATCs
for (j
=0;j
<YMAX
-YMIN
-1;)
{
if (i
<XMAX
-XMIN
-1)
{
//set the ATC data only the first time
if (INITATC
==1)
{
atcs
[(i
+j
)/GRID_SIZE
].
id = (temp_atc_id
%4)+(j
/GRID_SIZE
*4);
atcs
[(i
+j
)/GRID_SIZE
].
x =XMIN
+(GRID_SIZE
/2+i
);
atcs
[(i
+j
)/GRID_SIZE
].
y =YMIN
+(GRID_SIZE
/2+j
);
}
//draw the ATCs everytime
grx_circle
(XMIN
+(GRID_SIZE
/2+i
), YMIN
+(GRID_SIZE
/2+j
), ATCSIZE
, green
);
sprintf(temp
,"ATC%d",atcs
[(i
+j
)/GRID_SIZE
].
id);
grx_text
(temp
,atcs
[(i
+j
)/GRID_SIZE
].
x-ATCSIZE
-5,atcs
[(i
+j
)/GRID_SIZE
].
y-ATCSIZE
/2, green
,black
);
}
j
=j
+GRID_SIZE
;
}
temp_atc_id
++;
i
=i
+GRID_SIZE
;
}
INITATC
=0; //now the ATC IDs should not be initialized
for (i
=0;i
<NUM_OF_AIRPORTS
;i
++)
{
//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
//display airports
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
);
grx_text
(airports
[i
].
airportname,airports
[i
].
x-airports
[i
].
airportsize/1.5, airports
[i
].
y-airports
[i
].
airportsize/3, blue
, white
);
}
sem_post
(&graphics_mutex
);
}
TASK draw_sim_area
(void* arg
)
{
do
{
mutex_lock
(&mut_STARTSIM
);
if (!(STARTSIM
==-1 || STARTSIM
==0))
{
paint_sim_area
();
}
mutex_unlock
(&mut_STARTSIM
);
task_endcycle
();
}while(1);
}
void init_simulation
()
{
SOFT_TASK_MODEL sim_area
;
PID p
;
paint_sim_area
(); //paint the simulation area and populate the ATC structure
soft_task_default_model
(sim_area
);
soft_task_def_level
(sim_area
,1);
soft_task_def_ctrl_jet
(sim_area
);
soft_task_def_arg
(sim_area
, (void *)1);
soft_task_def_period
(sim_area
, DRAWSIMAREAPERIOD
);
soft_task_def_met
(sim_area
, DRAWSIMAREAWCET
);
soft_task_def_usemath
(sim_area
);
p
= task_create
("ref_Sim", draw_sim_area
, &sim_area
, NULL
);
if (p
== NIL
)
{
grx_close
();
perror("Could not create task <Sim_Area>");
sys_abort
(1);
}
task_activate
(p
);
}