main()¶
This function is the backbone of the whole program. It first initialize all the data structures need.
/**** In Defaults.h ****/
struct global_t global;
struct our_t our;
struct const_t constant;
struct stats_t stats;
struct display_t dpy;
/***********************/
Then it will initialize the runtime environment by calling init() function.
/******************** In Initialize.h ********************/
init(&global, &our, &constant, &stats, &dpy, &argc, &argv);
/*********************************************************/
Then we start the simulation. A for loop wraps around most of the functions, where the each iteration of the loop represents a day passing.
for(our.current_day = 0; our.current_day <= constant.total_number_of_days;
our.current_day++)
{
}
Inside the for loop, we first find all data related to the infection.
/****** In Infection.h ******/
find_infected(&our);
share_infected(&global, &our);
/****************************/
Then, if display is enabled, we display the infection status. In other words, we display everyone’s location and their states of infection.
/**************** In Display.h *****************/
#if defined(X_DISPLAY) || defined(TEXT_DISPLAY)
share_display_info(&global, &our);
do_display(&global, &our, &constant, &dpy);
throttle(&constant);
#endif
/***********************************************/
After display, we can call four core functions in Core.h* code file.
/******************* In Core.h ******************/
move(&our, &constant);
susceptible(&global, &our, &constant, &stats);
infected(&our, &constant, &stats);
update_days_infected(&our, &constant);
/************************************************/
This is the end of the loop.
Finally, after the loop, we can display the results and finalize the runtime environment.
/**************** In Finialize.h **************/
show_results(&our, &stats);
cleanup(&global, &our, &constant, &dpy);
/**********************************************/