- [FIX] En la carrega no s'estava agafant l'altura correcta dels sectors.
- [FIX] La linea de pintat de cada columna recomença des de l'ulti,a intersecció calculada (evita bucles infinits habituals) - [FIX] Si en drawColumn() la intersecció ocorre en el punt d'oritge, ignorar eixa pared (evita bucles infinits esporadics) - [NEW] Guarda de textures no trobades al carregar - [NEW] Guarda de bucle infinit en drawColumn() - [NEW] Agafa l'altura del sector al que s'entra (en el futur, nomes entrar si l'altura no es massa major) - [DBG] Se pinta el FOV en el minimapa
This commit is contained in:
69
main.cpp
69
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<num_sectors;++i) {
|
||||
sector sec;
|
||||
sec.floor_height = int16_t(*s); s+=2;
|
||||
sec.ceiling_height = int16_t(*s); s+=2;
|
||||
sec.floor_height = *((int16_t*)s); s+=2;
|
||||
sec.ceiling_height = *((int16_t*)s); s+=2;
|
||||
char txt[9]; txt[8]=0;
|
||||
for (int i=0;i<8;++i) txt[i] = toupper(*(s++));
|
||||
sec.floor_surf = wad::loadFlat(txt);
|
||||
@@ -257,11 +261,11 @@ void loadMap(const char* name)
|
||||
w.portal = portal ? arr[ld2].sector : -1;
|
||||
char txt[9]; txt[8]=0;
|
||||
for (int i=0;i<8;++i) txt[i] = toupper(arr[ld1].middle_texture[i]);
|
||||
if (txt[0]!='-') w.surf = wad::loadTexture(txt);
|
||||
if (txt[0]!='-') { w.surf = wad::loadTexture(txt); SDL_assert(w.surf); }
|
||||
for (int i=0;i<8;++i) txt[i] = toupper(arr[ld1].lower_texture[i]);
|
||||
if (txt[0]!='-') w.lower_surf = wad::loadTexture(txt);
|
||||
if (txt[0]!='-') { w.lower_surf = wad::loadTexture(txt); SDL_assert(w.lower_surf); }
|
||||
for (int i=0;i<8;++i) txt[i] = toupper(arr[ld1].upper_texture[i]);
|
||||
if (txt[0]!='-') w.upper_surf = wad::loadTexture(txt);
|
||||
if (txt[0]!='-') { w.upper_surf = wad::loadTexture(txt); SDL_assert(w.upper_surf); }
|
||||
sectors[arr[ld1].sector].walls.push_back(w);
|
||||
}
|
||||
if (ld2 != -1) {
|
||||
@@ -270,11 +274,11 @@ void loadMap(const char* name)
|
||||
w.portal = portal ? arr[ld1].sector : -1;
|
||||
char txt[9]; txt[8]=0;
|
||||
for (int i=0;i<8;++i) txt[i] = toupper(arr[ld2].middle_texture[i]);
|
||||
if (txt[0]!='-') w.surf = wad::loadTexture(txt);
|
||||
if (txt[0]!='-') { w.surf = wad::loadTexture(txt); SDL_assert(w.surf); }
|
||||
for (int i=0;i<8;++i) txt[i] = toupper(arr[ld2].lower_texture[i]);
|
||||
if (txt[0]!='-') w.lower_surf = wad::loadTexture(txt);
|
||||
if (txt[0]!='-') { w.lower_surf = wad::loadTexture(txt); SDL_assert(w.lower_surf); }
|
||||
for (int i=0;i<8;++i) txt[i] = toupper(arr[ld2].upper_texture[i]);
|
||||
if (txt[0]!='-') w.upper_surf = wad::loadTexture(txt);
|
||||
if (txt[0]!='-') { w.upper_surf = wad::loadTexture(txt); SDL_assert(w.upper_surf); }
|
||||
sectors[arr[ld2].sector].walls.push_back(w);
|
||||
}
|
||||
}
|
||||
@@ -283,7 +287,7 @@ void loadMap(const char* name)
|
||||
|
||||
for (auto &s : sectors )
|
||||
{
|
||||
order_sector_walls_with_holes(s);
|
||||
//order_sector_walls_with_holes(s);
|
||||
|
||||
for (auto &w : s.walls )
|
||||
{
|
||||
@@ -377,7 +381,7 @@ void createMap()
|
||||
*/
|
||||
int actual_sector = -1;
|
||||
int last_sector = -1;
|
||||
void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, vec2 infi)
|
||||
void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, vec2 origin, vec2 infi)
|
||||
{
|
||||
const float angle = orientation + a_inc;
|
||||
vec2 normal = { SDL_cosf(angle*DEG_TO_RAD), SDL_sinf(angle*DEG_TO_RAD) };
|
||||
@@ -388,8 +392,9 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
|
||||
for (auto &wall : s.walls)
|
||||
{
|
||||
if (dot(normal, wall.normal) >= 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 (d<stright_dist) {
|
||||
stright_dist = d;
|
||||
@@ -473,7 +478,12 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v
|
||||
//SDL_assert(w->portal != 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++;
|
||||
|
||||
Reference in New Issue
Block a user