- [NEW] Carrega de la posició, orientació i sector inicials des del WAD

This commit is contained in:
2026-03-02 17:14:54 +01:00
parent c486f9e74a
commit 85353d64fb
2 changed files with 37 additions and 2 deletions

View File

@@ -39,6 +39,13 @@ struct sector {
std::vector<wall> walls;
};
struct thing_t {
int16_t x_position;
int16_t y_position;
int16_t angle;
int16_t type;
int16_t flags;
};
std::vector<sector> sectors;
int current_sector = 38;
@@ -68,6 +75,7 @@ draw::surface_t *sky;
int drawColumn_count = 0;
uint8_t *colormap;
thing_t *things;
#pragma pack(push, 1)
struct sidedef {
@@ -80,6 +88,16 @@ struct sidedef {
};
#pragma pack(pop)
const bool is_inside_sector(sector &s, float x, float y)
{
const vec2 infinity = {100000.0f, 100000.0f};
int intersections = 0;
for (auto wall : s.walls) {
if (get_line_intersection(vec2{x,y}, infinity, verts[wall.v1], verts[wall.v2], nullptr)) intersections++;
}
return (intersections%2)!=0;
}
// ------------------------------------------------------------
// Área firmada de un contorno
// ------------------------------------------------------------
@@ -222,6 +240,17 @@ void loadMap(const char* name)
{
int size;
things = (thing_t*)wad::load(name, "THINGS", &size);
const int thing_count = size/10;
for (int i=0;i<thing_count;++i)
if (things[i].type==1) {
position.x = things[i].x_position;
position.y = -things[i].y_position;
orientation = things[i].angle+180;
break;
}
int16_t *vertices = (int16_t *)wad::load(name, "VERTEXES", &size);
const int num_vertices = size/4;
for (int i=0;i<num_vertices;++i)
@@ -297,9 +326,14 @@ void loadMap(const char* name)
free(linedefs_lump);
free(sidedefs_lump);
int sector_index = 0;
for (auto &s : sectors )
{
//order_sector_walls_with_holes(s);
if (is_inside_sector(s, position.x, position.y)) {
current_sector = sector_index;
height = real_height = s.floor_height + 41.0f;
}
for (auto &w : s.walls )
{
@@ -315,6 +349,7 @@ void loadMap(const char* name)
const float tmp = norm.x; norm.x = -norm.y; norm.y = tmp;
w.normal = norm;
}
sector_index++;
}
}
@@ -607,7 +642,7 @@ int main(int argc, char *argv[])
//for(int i=0;i<256;++i) palette[i] = (255-i) | ((255-i)<<8) | ((255-i)<<16);
//createMap();
loadMap("E1M1");
loadMap("E1M3");
SDL_Event e;
bool should_exit = false;

2
util.h
View File

@@ -10,4 +10,4 @@ const bool get_line_intersection(vec2 p0, vec2 p1, vec2 p2, vec2 p3, vec2 *i);
const float distance(vec2 p1, vec2 p2);
const void normalize(vec2 *v);
const float dot(vec2 v1, vec2 v2);
float is_enemy_in_fov(double Ax, double Ay, double orientation_deg, double Bx, double By);
float is_enemy_in_fov(double Ax, double Ay, double orientation_deg, double Bx, double By);