From 6c8abfbade4de37581c5896c9e1fe8157cae0311 Mon Sep 17 00:00:00 2001 From: Adrien Guatto Date: Mon, 1 Dec 2025 16:07:50 +0100 Subject: [PATCH] Corrections projet --- projet/src/city.ept | 12 ++++----- projet/src/map.c | 50 ++++++++---------------------------- projet/src/simulation_loop.c | 9 ++++++- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/projet/src/city.ept b/projet/src/city.ept index b20aa9a..ffd6ef5 100644 --- a/projet/src/city.ept +++ b/projet/src/city.ept @@ -66,13 +66,15 @@ let false); tel +(* The car angle with the road should be in the range -120..120 degree *) node wrong_dir(ph : phase) returns (wrong : bool) -var data : map_data; error : float; ang : float; +var data : map_data; norm, error : float; ang : float; let data = lookup_phase(ph); ang = ph.ph_head *. (pi /. 180.0); + norm = Mathext.sqrt(data.dir_x *. data.dir_x +. data.dir_y *. data.dir_y); error = data.dir_x *. Mathext.cos(ang) +. data.dir_y *. Mathext.sin(ang); - wrong = error <. -. 0.5; + wrong = error <. -. 0.5 *. norm; tel fun aggregate_events(lightRun, speedExcess, exitRoad, collisionEvent, @@ -188,7 +190,7 @@ tel (* Scoring *) node scoringA(e : event; rstatus : status) returns (score : int) -var penalty : int; collision_count : int; +var penalty : int; let score = (10000 fby score) + if Utilities.rising_edge(rstatus = Arrived) then 1000 else 0 @@ -198,9 +200,7 @@ let + (if e.speedExcess then -2 else 0) + (if Utilities.rising_edge(e.exitRoad) then -5000 else 0) + (if Utilities.rising_edge(e.dirEvent) then -2000 else 0) - + (if collision_count = 0 then -500 else 0) - + (if collision_count < 0 then 10 else 0); - collision_count = Utilities.countdown(not e.collisionEvent, 20); + + (if Utilities.rising_edge(e.collisionEvent) then -500 else 0); tel node scoringB(ph : phase) returns (score : int) diff --git a/projet/src/map.c b/projet/src/map.c index b2a08d7..170f1f0 100644 --- a/projet/src/map.c +++ b/projet/src/map.c @@ -683,29 +683,6 @@ bool isOnRoadArc(/* IN */ return true; } -int isOnTLight(int x, int y, int rd, float dir_x, float dir_y) -{ - if (map->tlight_arr == NULL || - map->tlight_sz <= 0) - return -1; - //no traffic light - - for (int i = 0; i < map->tlight_sz; i++) { - tlight_t *tl = &map->tlight_arr[i]; - if (tl->road != rd) - continue; - double d = distance(x, y, tl->tl.ptl_pos.x, tl->tl.ptl_pos.y); - - /* double cosdir = dirCos(tl->tl.ptl_pos.y - y, x - tl->tl.ptl_pos.x, - dir_x, dir_y); */ //MS - double cosdir = dirCos(tl->tl.ptl_pos.x-x, tl->tl.ptl_pos.y-y, - dir_x, dir_y); //EA - if (d < TL_VIEW && cosdir > TL_COSDIR) - return i; - } - return -1; -} - bool isAfterStop(int x, int y, int rid, float dir_x, float dir_y, int* tl) { (*tl) = -1; @@ -822,7 +799,7 @@ isPositionOnPoint(float x, float y, road_t* rd, position_t* p, double pWidth) } } -Globals__color getColorPoint(int rid, float x, float y) { +Globals__color getColorPoint(int rid, float x, float y, int* tl) { // first go through waypoints log_debug("[geometry] looking for waypoints at (%.2f, %.2f) on road %d\n", x, y, rid); @@ -855,6 +832,7 @@ Globals__color getColorPoint(int rid, float x, float y) { // stop points are ruban if (isPositionOnPoint(x, y, rd, &sp->position, RD_SIZE_STOP)) { log_debug("[geometry] (%.2f, %.2f) at stop %d\n", x, y, i); + *tl = sp->sema; return COL_STOP; //one stop by position } @@ -909,28 +887,22 @@ DEFINE_HEPT_FUN(Map, lookup_pos, (Globals__position pos)) { out->data.dir_x = dir_X; out->data.dir_y = dir_Y; out->data.max_speed = map->road_arr[min_rd].max_speed; - /* Update color when a waypoint or stop. */ - col = getColorPoint(rid, x, y); - if (colors_equal(&col, &COL_OUT)) - out->data.color = out->data.color; - else if (colors_equal(&col, &COL_STOP)) { - /* TODO: update red color */ - out->data.color = col; - } - else { - /* TODO: update green color */ - out->data.color = col; - } } } + /* Update color when a waypoint or stop. */ + int tl = -1; + if (min_rd >= 0) { + Globals__color col = getColorPoint(min_rd, x, y, &tl); + if (!colors_equal(&col, &COL_OUT)) + out->data.color = col; + } + /* Compute the return type. */ if (min_rd >= 0) { log_debug("[geometry] (%.2f, %.2f) is on road %d\n", x, y, min_rd); out->data.on_road = true; - int tl = -1; - out->data.tl_number = - isOnTLight(x, y, min_rd, out->data.dir_x, out->data.dir_y); + out->data.tl_number = tl; out->data.tl_required = isAfterStop(x, y, min_rd, out->data.dir_x, out->data.dir_y, &tl); if(out->data.tl_required) { diff --git a/projet/src/simulation_loop.c b/projet/src/simulation_loop.c index 12c3965..2066011 100644 --- a/projet/src/simulation_loop.c +++ b/projet/src/simulation_loop.c @@ -157,7 +157,7 @@ race_result_t simulation_loop(bool show_guide, SDL_WINDOWPOS_UNDEFINED, MAX_X, MAX_Y, - SDL_WINDOW_SHOWN)) == NULL) + SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE)) == NULL) log_fatal("[sdl] could not open window (%s)\n", SDL_GetError()); r = SDL_CreateRenderer(w, -1, SDL_RENDERER_ACCELERATED); @@ -256,6 +256,13 @@ race_result_t simulation_loop(bool show_guide, case SDL_QUIT: quit = true; break; + case SDL_WINDOWEVENT: + if (e.window.event == SDL_WINDOWEVENT_RESIZED) { + float newwidth = e.window.data1; + float newheight = e.window.data2; + SDL_RenderSetScale(r, newwidth / MAX_X, newheight / MAX_Y); + } + break; case SDL_KEYDOWN: switch (e.key.keysym.sym) { case SDLK_q: