void init_world_area(World_Area* area, Memory_Arena* arena) { init_simulator(&area->sim, World_Area_Entity_Capacity, arena); init_tilemap(&area->map, World_Area_Tilemap_Width, World_Area_Tilemap_Height, arena); area->entities = Arena_Push_Array(arena, Entity, World_Area_Entity_Capacity); area->entities_count = 0; area->entities_capacity = World_Area_Entity_Capacity; area->next_entity_id = 0; area->entities_dirty = false; }
/* == FUNCTION mdlInitializeSizes ============================================= * Initialize IO sizes for the S-Function port interface. * * The port widths are re-set after the AUTOSAR model has been queried, leave * as dynamically sized. * * NOTE: This is the first function call performed by Simulink during model * initialization. Because of this, we perform ARSim initialization here. */ static void mdlInitializeSizes(SimStruct *S) { // Easier to spot a restart this way. fprintf(stderr, "******************************************" "******************************************\n\n"); debug("( trace )"); ssSetNumSFcnParams(S, 1); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; } if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED); if (!ssSetNumOutputPorts(S, 1)) return; ssSetOutputPortWidth(S, 0, DYNAMICALLY_SIZED); ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); ssSetOptions(S, SS_OPTION_CALL_TERMINATE_ON_EXIT); init_simulator(S); }
int main(int argc, char *argv[]) { uint32_t tick_rate=1; int positional_args=0; //defaults args.step_out_file = stderr; args.block_out_file = stdout; args.grbl_out_file = stdout; args.comment_char = '#'; args.step_time = 0.0; // Get the minimum time step for printing stepper values. // If not given or the command line cannot be parsed to a float than // step_time= 0.0; This means to not print stepper values at all progname = argv[0]; while (argc>1) { argv++;argc--; if (argv[0][0] == '-'){ switch(argv[0][1]){ case 'c': //set Comment char args.comment_char = argv[0][2]; break; case 'n': //No comment char on grbl responses args.comment_char = 0; break; case 't': //Tick rate argv++;argc--; tick_rate = atof(*argv); break; case 'b': //Block file argv++;argc--; args.block_out_file = fopen(*argv,"w"); break; case 's': //Step out file. argv++;argc--; args.step_out_file = fopen(*argv,"w"); break; case 'g': //Grbl output argv++;argc--; args.grbl_out_file = fopen(*argv,"w"); break; case 'r': //step_time for Reporting argv++;argc--; args.step_time= atof(*argv); break; case 'h': return usage(NULL); default: return usage(*argv); } } else { //handle old positional argument interface positional_args++; switch(positional_args){ case 1: args.step_time= atof(*argv); break; case 2: //block out and grbl out to same file, like before. args.block_out_file = fopen(*argv,"w"); args.grbl_out_file = args.block_out_file; break; default: return usage(*argv); } } } // Make sure the output streams are flushed immediately. // This is important when using the simulator inside another application in parallel // to the real grbl. // Theoretically flushing could be limited to complete lines. Unfortunately Windows // does not know line buffered streams. So for now we stick to flushing every character. //setvbuf(stdout, NULL, _IONBF, 1); //setvbuf(stderr, NULL, _IONBF, 1); //( Files are now closed cleanly when sim gets EOF or CTRL-F.) platform_init(); init_simulator(tick_rate); //launch a thread with the original grbl code. plat_thread_t*th = platform_start_thread(avr_main_thread); if (!th){ printf("Fatal: Unable to start hardware thread.\n"); exit(-5); } //All the stream io and interrupt happen in this thread. sim_loop(); platform_kill_thread(th); //need force kill since original main has no return. // Graceful exit shutdown_simulator(0); platform_terminate(); exit(EXIT_SUCCESS); }