Map gen is now almost perfect, only lack connected subsectors

This commit is contained in:
KP 2024-07-28 02:08:27 -05:00
parent b45a045dea
commit b867a0d631
3 changed files with 3769 additions and 258 deletions

File diff suppressed because it is too large Load diff

View file

@ -216,6 +216,8 @@ void Map::BuildQuad(Sector& sector, Wall& wall, Flat& flat_top, Flat& flat_botto
if (!points.empty()) if (!points.empty())
if (!FloatCmp(points.back().x, Distance({ pos_a.x, pos_a.y }, {pos_b.x, pos_b.y}))) if (!FloatCmp(points.back().x, Distance({ pos_a.x, pos_a.y }, {pos_b.x, pos_b.y})))
points.push_back({ Distance({ pos_a.x, pos_a.y }, {pos_b.x, pos_b.y}), flat_bottom.base_height}); points.push_back({ Distance({ pos_a.x, pos_a.y }, {pos_b.x, pos_b.y}), flat_bottom.base_height});
if (points.empty())
points.push_back({ 0.0f, flat_bottom.base_height});
std::vector<Vec2> top_points; std::vector<Vec2> top_points;
for (const Vertex3D& v: flat_top.triangulated_data) for (const Vertex3D& v: flat_top.triangulated_data)
{ {
@ -227,8 +229,8 @@ void Map::BuildQuad(Sector& sector, Wall& wall, Flat& flat_top, Flat& flat_botto
if (!top_points.empty()) if (!top_points.empty())
if (!FloatCmp(top_points.back().x, 0.0f)) if (!FloatCmp(top_points.back().x, 0.0f))
top_points.push_back({ 0.0f, flat_top.base_height }); top_points.push_back({ 0.0f, flat_top.base_height });
// if (top_points.empty()) if (top_points.empty())
// top_points.push_back({Distance({pos_a.x, pos_a.z}, {pos_b.x, pos_b.z}), flat_top.base_height}); top_points.push_back({Distance({0.0f, 0.0f}, {pos_b.x - pos_a.x, pos_b.z - pos_a.x}), flat_top.base_height});
std::sort(points.begin(), points.end(), [&](Vec2 a, Vec2 b) { return a.x < b.x; }); std::sort(points.begin(), points.end(), [&](Vec2 a, Vec2 b) { return a.x < b.x; });
std::sort(top_points.begin(), top_points.end(), [&](Vec2 a, Vec2 b) { return a.x > b.x; }); std::sort(top_points.begin(), top_points.end(), [&](Vec2 a, Vec2 b) { return a.x > b.x; });
points.insert(points.end(), top_points.begin(), top_points.end()); points.insert(points.end(), top_points.begin(), top_points.end());
@ -285,35 +287,33 @@ void Map::BuildWall(Sector& sector, Wall& wall)
Vec3 b = {wall.end.x, 0.0f, wall.end.y}; Vec3 b = {wall.end.x, 0.0f, wall.end.y};
BuildQuad(sector, wall, sector.floor, sector.ceiling, wall.textures[TEX_FRONT], a, b, false, false, false, wall.uv_offset[TEX_FRONT]); BuildQuad(sector, wall, sector.floor, sector.ceiling, wall.textures[TEX_FRONT], a, b, false, false, false, wall.uv_offset[TEX_FRONT]);
if ((wall.flags & Wall::FLAG_OPENING) && !(wall.flags & Wall::FLAG_JOINED)) if (!(wall.flags & Wall::FLAG_SUBSECTOR_OPENING))
//if (!(wall.flags & Wall::FLAG_JOINED))
{ {
// Build upper and lower walls for sectors connected to other sectors (or sectors within sectors) if ((wall.flags & Wall::FLAG_OPENING) && !(wall.flags & Wall::FLAG_JOINED))
bool flip = wall.portal->floor.base_height < sector.floor.base_height, cflip = flip; {
if (wall.flags & Wall::FLAG_SUBSECTOR_OPENING) // Build upper and lower walls for sectors connected to other sectors (or sectors within sectors)
cflip = true;//cflip ^= 1; bool flip = wall.portal->floor.base_height < sector.floor.base_height;
if (cflip && !FloatCmp(wall.portal->floor.base_height, sector.floor.base_height)) if (flip && !FloatCmp(wall.portal->floor.base_height, sector.floor.base_height))
BuildQuad(sector, wall, sector.floor, wall.portal->floor, wall.textures[TEX_LOWER], a, b, flip, false, false, wall.uv_offset[TEX_LOWER]);
flip = wall.portal->ceiling.base_height < sector.ceiling.base_height;
if (!flip && !FloatCmp(wall.portal->ceiling.base_height, sector.ceiling.base_height))
BuildQuad(sector, wall, sector.ceiling, wall.portal->ceiling, wall.textures[TEX_UPPER], a, b, !flip, false, false, wall.uv_offset[TEX_UPPER]);
wall.flags |= Wall::FLAG_JOINED;
}
}
else
{
if (!(wall.flags & Wall::FLAG_JOINED))
{
KP3D_LOG_INFO("POOP J: {}", sector.id);
bool flip = wall.portal->floor.base_height < sector.floor.base_height;
BuildQuad(sector, wall, sector.floor, wall.portal->floor, wall.textures[TEX_LOWER], a, b, flip, false, false, wall.uv_offset[TEX_LOWER]); BuildQuad(sector, wall, sector.floor, wall.portal->floor, wall.textures[TEX_LOWER], a, b, flip, false, false, wall.uv_offset[TEX_LOWER]);
flip = wall.portal->ceiling.base_height < sector.ceiling.base_height; flip = wall.portal->ceiling.base_height < sector.ceiling.base_height;
cflip = flip;
if (wall.flags & Wall::FLAG_SUBSECTOR_OPENING)
cflip = false;// ^= 1;
if (!cflip && !FloatCmp(wall.portal->ceiling.base_height, sector.ceiling.base_height))
BuildQuad(sector, wall, sector.ceiling, wall.portal->ceiling, wall.textures[TEX_UPPER], a, b, !flip, false, false, wall.uv_offset[TEX_UPPER]); BuildQuad(sector, wall, sector.ceiling, wall.portal->ceiling, wall.textures[TEX_UPPER], a, b, !flip, false, false, wall.uv_offset[TEX_UPPER]);
wall.flags |= Wall::FLAG_JOINED; wall.flags |= Wall::FLAG_JOINED;
// Find the other one this wall is joining to
#if 0
for (Wall& w: wall.portal->walls)
{
// TODO: Check if this is overlapping
//if (wall.flags & Wall::FLAG_OPENING)
if (WallOverlaps(*wall.portal, w) && !(wall.flags & Wall::FLAG_JOINED))
{
w.flags |= Wall::FLAG_JOINED;
}
} }
#endif
} }
} }
@ -341,7 +341,7 @@ void Map::JoinSectors(Sector& sector)
float e = 1.0f / 128.0f; float e = 1.0f / 128.0f;
for (Wall& l : s.walls) for (Wall& l: s.walls)
{ {
//if (l.flags & Wall::FLAG_TOUCHED) //if (l.flags & Wall::FLAG_TOUCHED)
// continue; // continue;
@ -702,12 +702,12 @@ void Map::Rebuild(NormalGenType gen_normals)
if (bail) if (bail)
continue; continue;
if (s.id == 1 || s.id == 5) //if (s.id == 1 || s.id == 5)
{ {
//float yv0 = PerlinNoise2D(steiner_point.x, steiner_point.y, 1.0, 10.0); float yv0 = PerlinNoise2D(steiner_point.x, steiner_point.y, 1.0, 10.0);
//float yv1 = -PerlinNoise2D(steiner_point.x, steiner_point.y, 0.5, 9.0); float yv1 = -PerlinNoise2D(steiner_point.x, steiner_point.y, 0.5, 9.0);
//s.floor.steiner_points.push_back({ steiner_point.x, yv0, steiner_point.y }); s.floor.steiner_points.push_back({ steiner_point.x, yv0, steiner_point.y });
//s.ceiling.steiner_points.push_back({ steiner_point.x, yv1, steiner_point.y }); s.ceiling.steiner_points.push_back({ steiner_point.x, yv1, steiner_point.y });
} }
} }
} }
@ -767,6 +767,7 @@ void Map::Render()
RenderSkybox(); RenderSkybox();
// Map // Map
glDisable(GL_CULL_FACE);
kp3d::Renderer3D::PushShader(kp3d::Renderer3D::GetMapShader()); kp3d::Renderer3D::PushShader(kp3d::Renderer3D::GetMapShader());
kp3d::Renderer3D::DrawMesh(m_mesh, m_transform, true, ShouldHighlight); kp3d::Renderer3D::DrawMesh(m_mesh, m_transform, true, ShouldHighlight);
kp3d::Renderer3D::PopShader(); kp3d::Renderer3D::PopShader();

View file

@ -216,7 +216,7 @@ void Editor::UpdateModeBuild()
s->floor.texture = &m_block; s->floor.texture = &m_block;
s->floor.floor = true; s->floor.floor = true;
s->floor.base_height = 0.0f; s->floor.base_height = 0.0f;
s->ceiling.base_height = 2.0f; s->ceiling.base_height = 4.0f;
s->id = sandbox->map.sectors.size() + 1; s->id = sandbox->map.sectors.size() + 1;
s->parent_id = 0; s->parent_id = 0;
s->inverted = false; s->inverted = false;