From 7c3c3eb088a0cfa244955d254d93db705969aadd Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Sun, 1 Mar 2026 19:09:49 +0100 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20En=20la=20carrega=20no=20s'estava?= =?UTF-8?q?=20agafant=20l'altura=20correcta=20dels=20sectors.=20-=20[FIX]?= =?UTF-8?q?=20La=20linea=20de=20pintat=20de=20cada=20columna=20recomen?= =?UTF-8?q?=C3=A7a=20des=20de=20l'ulti,a=20intersecci=C3=B3=20calculada=20?= =?UTF-8?q?(evita=20bucles=20infinits=20habituals)=20-=20[FIX]=20Si=20en?= =?UTF-8?q?=20drawColumn()=20la=20intersecci=C3=B3=20ocorre=20en=20el=20pu?= =?UTF-8?q?nt=20d'oritge,=20ignorar=20eixa=20pared=20(evita=20bucles=20inf?= =?UTF-8?q?inits=20esporadics)=20-=20[NEW]=20Guarda=20de=20textures=20no?= =?UTF-8?q?=20trobades=20al=20carregar=20-=20[NEW]=20Guarda=20de=20bucle?= =?UTF-8?q?=20infinit=20en=20drawColumn()=20-=20[NEW]=20Agafa=20l'altura?= =?UTF-8?q?=20del=20sector=20al=20que=20s'entra=20(en=20el=20futur,=20nome?= =?UTF-8?q?s=20entrar=20si=20l'altura=20no=20es=20massa=20major)=20-=20[DB?= =?UTF-8?q?G]=20Se=20pinta=20el=20FOV=20en=20el=20minimapa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/main.cpp b/main.cpp index e8c080a..a0f041e 100644 --- a/main.cpp +++ b/main.cpp @@ -42,9 +42,11 @@ int current_sector = 38; int current_sector2 = 38; vec2 position = { 1056.0f, -3616.0f }; +//vec2 position = {975.0f, -3525.0f}; +float orientation = 90.0f; //270.0f; +//float orientation = 180.0f; float height = 32.0f; float real_height = 32.0f; -float orientation = 270.0f; float accel = 500.0f; float speed = 0.0f; @@ -59,6 +61,8 @@ Uint32 *palette; //draw::surface_t *gif; draw::surface_t *spr; +int drawColumn_count = 0; + #pragma pack(push, 1) struct sidedef { int16_t xoffset; @@ -223,8 +227,8 @@ void loadMap(const char* name) uint8_t *s = sectors_lump; for (int i=0;i= 0) continue; - if (get_line_intersection(position, infi, verts[wall.v1], verts[wall.v2], &tmp_result)) + if (get_line_intersection(origin, infi, verts[wall.v1], verts[wall.v2], &tmp_result)) { + if ( (origin.x==tmp_result.x) && (origin.y==tmp_result.y) ) continue; const float d = distance(position, tmp_result);// * SDL_cosf(a_inc*DEG_TO_RAD); if (dportal != last_sector); last_sector = actual_sector; actual_sector = w->portal; - drawColumn(sectors[w->portal], screen_column, wall_start, wall_end, a_inc, infi); + drawColumn_count++; + if (drawColumn_count>50) { + printf("drawColumn() loop overflow. Sectors: %i adn %i\n", last_sector, actual_sector); + SDL_assert(false); + } + drawColumn(sectors[w->portal], screen_column, wall_start, wall_end, a_inc, result, infi); if (lower_wall_height>0.0f) { @@ -517,8 +527,10 @@ bool tryMove(float angle, float speed) { if (w.portal != -1) { newpos.x = position.x + SDL_cosf(angle*DEG_TO_RAD)*dt*speed; - if (get_line_intersection(position, newpos, verts[w.v1], verts[w.v2], NULL) ) + if (get_line_intersection(position, newpos, verts[w.v1], verts[w.v2], NULL) ) { current_sector = w.portal; + real_height = sectors[current_sector].floor_height+32.0f; + } } else { collision=true; } @@ -657,13 +669,15 @@ int main(int argc, char *argv[]) int screen_column = 0; for (float a_inc=-32.0f; a_inc<=32.0f; a_inc+=0.2f) { + drawColumn_count = 0; + last_sector = -1; const float angle = orientation + a_inc; vec2 infi; infi.x = position.x + SDL_cosf(angle*DEG_TO_RAD)*40000; infi.y = position.y + SDL_sinf(angle*DEG_TO_RAD)*40000; //printf("Column %i...\n", screen_column); - drawColumn(s, screen_column, 0, 240, a_inc, infi); + drawColumn(s, screen_column, 0, 240, a_inc, position, infi); screen_column++; } @@ -706,17 +720,34 @@ int main(int argc, char *argv[]) } */ + + // Draw map walls //draw::cls(); int sec = 0; + vec2 normal = { SDL_cosf(orientation*DEG_TO_RAD), SDL_sinf(orientation*DEG_TO_RAD) }; + for (auto &s : sectors) { - if (sec==current_sector2) + //if (sec==current_sector2) for (auto &w : s.walls) { - draw::map::line(verts[w.v1].x, verts[w.v1].y, verts[w.v2].x, verts[w.v2].y, sec==current_sector2?20:4, position.x, position.y); + if (dot(normal, w.normal) >= 0) continue; + draw::map::line(verts[w.v1].x, verts[w.v1].y, verts[w.v2].x, verts[w.v2].y, sec==current_sector?20:4, position.x, position.y); + vec2 nx {(verts[w.v2].x+verts[w.v1].x)/2, (verts[w.v2].y+verts[w.v1].y)/2}; + draw::map::line(nx.x, nx.y, nx.x+w.normal.x*20, nx.y+w.normal.y*20, sec==current_sector?22:3, position.x, position.y); } sec++; } + vec2 infi; + infi.x = position.x + SDL_cosf((orientation + -32.0f)*DEG_TO_RAD)*40000; + infi.y = position.y + SDL_sinf((orientation + -32.0f)*DEG_TO_RAD)*40000; + draw::map::line(position.x, position.y, infi.x, infi.y, 32, position.x, position.y); + infi.x = position.x + SDL_cosf((orientation)*DEG_TO_RAD)*40000; + infi.y = position.y + SDL_sinf((orientation)*DEG_TO_RAD)*40000; + draw::map::line(position.x, position.y, infi.x, infi.y, 42, position.x, position.y); + infi.x = position.x + SDL_cosf((orientation + 32.0f)*DEG_TO_RAD)*40000; + infi.y = position.y + SDL_sinf((orientation + 32.0f)*DEG_TO_RAD)*40000; + draw::map::line(position.x, position.y, infi.x, infi.y, 32, position.x, position.y); // Draw map hero vec2 lookat; @@ -731,6 +762,10 @@ int main(int argc, char *argv[]) draw::putp((i&0xf)*2+1, (i>>4)*2+1, i); draw::putp((i&0xf)*2, (i>>4)*2+1, i); } + + + + draw::render(); fps_count++;